Jelajahi Sumber

新增字典增加唯一判断

yuejiaying 4 tahun lalu
induk
melakukan
68efbed093

+ 1 - 0
common/src/main/java/com/huaxu/model/ResultStatus.java

@@ -101,6 +101,7 @@ public enum ResultStatus {
     PHONE_NUMBER_NOT_FOUND_WECHAT_ERROR(900014, "您微信绑定的手机号尚未注册,请使用平台注册账号进行登录。"),
 
     EXSIT_IS_PARENT_ERROR(800001,"存在下级信息不能删除"),
+    EXSIT_IS_DICTCODE_ERROR(800002,"存在相同字典编码不能新增"),
 
     SYSTEM_ERROR(999999, "系统错误"),
     PARAM_ERROR(700001, "参数缺失"),

+ 4 - 0
user_center/src/main/java/com/huaxu/controller/DictController.java

@@ -58,6 +58,10 @@ public class DictController {
     @RequestMapping(value = "insert", method = RequestMethod.POST)
     @ApiOperation(value = "插入数据字典配置列表")
     public AjaxMessage<Integer> insert(@ApiParam(value = "数据字典配置", required = true) @RequestBody Dict dict) {
+        if(dictService.countByCodePid(dict)>0)
+        {
+            return new AjaxMessage<>(ResultStatus.EXSIT_IS_DICTCODE_ERROR);
+        }
         LoginUser currentUser = UserUtil.getCurrentUser();
         if(currentUser!=null) {
             dict.setCreateBy(currentUser.getUsername());

+ 7 - 0
user_center/src/main/java/com/huaxu/dao/DictMapper.java

@@ -81,4 +81,11 @@ public interface DictMapper {
 
     IPage<Dict> selectPage(IPage<Dict> page, Dict dict);
 
+    /**
+     * 字典编码和父配置ID数量
+     *
+     * @return 数据总数
+     */
+    int countByCodePid(Dict dict);
+
 }

+ 6 - 0
user_center/src/main/java/com/huaxu/service/DictService.java

@@ -77,4 +77,10 @@ public interface DictService {
     int count();
 
     IPage<Dict> selectPage(Dict app, IPage<Dict> page);
+    /**
+     * 字典编码和父配置ID数量
+     *
+     * @return 数据总数
+     */
+    int countByCodePid(Dict dict);
 }

+ 10 - 0
user_center/src/main/java/com/huaxu/service/impl/DictServiceImpl.java

@@ -116,4 +116,14 @@ public class DictServiceImpl implements DictService {
     public IPage<Dict> selectPage(Dict dict, IPage<Dict> page) {
         return this.dictMapper.selectPage(page, dict);
     }
+
+    /**
+     * 字典编码和父配置ID数量
+     *
+     * @return 数据总数
+     */
+    @Override
+    public int countByCodePid(Dict dict) {
+        return this.dictMapper.countByCodePid(dict);
+    }
 }

+ 16 - 0
user_center/src/main/resources/mapper/DictMapper.xml

@@ -176,4 +176,20 @@
         </where>
         order by DICT_NAME,DICT_VALUE
     </select>
+    <!-- 字典编码和父配置ID数量 -->
+    <select id="countByCodePid" resultType="int">
+        select count(*) from uims_dict
+        <where>
+            <if test="dictCode != null and dictCode != ''">
+                and DICT_CODE = #{dictCode}
+            </if>
+            <if test="parentDictId != null and parentDictId != ''">
+                and PARENT_DICT_ID = #{parentDictId}
+            </if>
+            <if test="parentDictId == null">
+                and PARENT_DICT_ID IS NULL
+            </if>
+            and STATUS =1
+        </where>
+    </select>
 </mapper>