|
@@ -0,0 +1,67 @@
|
|
|
+package com.care.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.cache.CacheUtil;
|
|
|
+import cn.hutool.cache.impl.TimedCache;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.care.common.entity.SysDimCode;
|
|
|
+import com.care.service.CommonService;
|
|
|
+import com.care.service.SysDimCodeService;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author ly
|
|
|
+ * @version 1.0.0 创建于 2020-01-05 22:11:57 orgycat Exp.
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class CommonServiceImpl implements CommonService {
|
|
|
+
|
|
|
+ TimedCache<String, Map<String, String>> codeNameMappingTimedCache = CacheUtil.newTimedCache(60 * 60 * 1000L);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysDimCodeService sysDimCodeService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysDimCode> getDimCodeListe(String typeCode){
|
|
|
+ QueryWrapper<SysDimCode> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.lambda().eq(SysDimCode::getTypeCode,typeCode)
|
|
|
+ .eq(SysDimCode::getStatus,"1")
|
|
|
+ .orderByAsc(SysDimCode::getCodeIndex);
|
|
|
+ return sysDimCodeService.list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String convertedCodeName(String typeCode, String code) {
|
|
|
+ if (StringUtils.isEmpty(typeCode) || StringUtils.isEmpty(code)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<String, String> cacheMapping = codeNameMappingTimedCache.get(typeCode, false);
|
|
|
+ if (cacheMapping == null) {
|
|
|
+ cacheMapping = this.processCacheCodeNameMapping(typeCode);
|
|
|
+ }
|
|
|
+ return cacheMapping.get(code);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> processCacheCodeNameMapping(String typeCode) {
|
|
|
+ Map<String, String> courseYearMapping = convertMapping(getDimCodeListe(typeCode));
|
|
|
+ codeNameMappingTimedCache.put(typeCode, courseYearMapping);
|
|
|
+ return courseYearMapping;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> convertMapping(List<SysDimCode> sysDimCodeList) {
|
|
|
+ Map<String, String> mapping = Maps.newHashMap();
|
|
|
+ if (!CollectionUtils.isEmpty(sysDimCodeList)) {
|
|
|
+ for (SysDimCode sysDimCode : sysDimCodeList) {
|
|
|
+ mapping.put(sysDimCode.getDimCode(), sysDimCode.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return mapping;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|