浏览代码

增加转码类

lilt085163@126.com 3 年之前
父节点
当前提交
ca357702b6

+ 44 - 0
src/main/java/com/care/bigscreen/controller/CommonController.java

@@ -0,0 +1,44 @@
+package com.care.bigscreen.controller;
+
+import com.care.service.CommonService;
+import com.care.util.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * @author javadoc
+ * @version 1.0
+ * @description 系统设置-字典管理模块-前端控制器
+ * @date
+ */
+@Slf4j
+@RestController
+@RequestMapping("/bms/system/common")
+public class CommonController {
+
+    @Autowired
+    CommonService commonService;
+    /**
+     * 字典:字段查重(字典选项代码)
+     * 作用:添加或修改时对必须唯一的字段进行查重
+     *
+     * @param typeCode 收集需要查重的字段参数
+     * @return 返回0表示字段没有重复,非零表示有重复
+     */
+    @GetMapping("/convertedCodeName")
+    public Result<Object> convertedCodeName(@RequestParam("typeCode") String typeCode,@RequestParam("value") String value) {
+        try {
+            String name = commonService.convertedCodeName(typeCode,value);
+                return Result.success("成功",name);
+        } catch (Exception e) {
+            return Result.error("系统错误,查询失败");
+        }
+    }
+
+
+}

+ 24 - 0
src/main/java/com/care/service/CommonService.java

@@ -0,0 +1,24 @@
+package com.care.service;
+
+import com.care.common.entity.SysDimCode;
+
+import java.util.List;
+
+/**
+ * @author ly
+ * @version 1.0.0 创建于 2020-01-05 22:11:46 orgycat Exp.
+ **/
+public interface CommonService {
+
+    /**
+     * 获取KV映射
+     * @param typeCode 类型CODE
+     * @param typeCode 映射CODE
+     * @return 映射
+     * @throws Exception 异常信息
+     */
+    String convertedCodeName(String typeCode, String code);
+
+    List<SysDimCode> getDimCodeListe(String typeCode);
+
+}

+ 67 - 0
src/main/java/com/care/service/impl/CommonServiceImpl.java

@@ -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;
+    }
+
+}