李春阳 il y a 1 an
Parent
commit
a6fbdec095

+ 13 - 0
api-common/src/main/java/api/common/pojo/param/system/DictDeleteParam.java

@@ -0,0 +1,13 @@
+package api.common.pojo.param.system;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+public class DictDeleteParam {
+
+    @NotBlank(message = "参数dictId不能为空")
+    private String dictId;
+
+}

+ 19 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/adapter/controller/DictController.java

@@ -2,6 +2,7 @@ package com.css.simulation.resource.server.adapter.controller;
 
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.system.DictParam;
+import api.common.pojo.po.system.DictPO;
 import api.common.pojo.vo.system.DictVO;
 import com.css.simulation.resource.server.app.service.DictService;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -57,4 +58,22 @@ public class DictController {
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, dictService.getDictMapsByTypes(param));
     }
 
+    /**
+     * 通过 id 删除 dict
+     */
+    @RequestMapping("/deleteDictById")
+    @PreAuthorize("@AuthorityCheck.admin()")
+    public ResponseBodyVO<String> deleteDictById(@RequestBody @Validated DictPO param) {
+        return dictService.deleteDictById(param);
+    }
+
+    /**
+     * 新增 dict
+     */
+    @RequestMapping("/createDictByType")
+    @PreAuthorize("@AuthorityCheck.admin()")
+    public ResponseBodyVO<String> createDictByType(@RequestBody @Validated DictPO param) {
+        return dictService.createDictByType(param);
+    }
+
 }

+ 0 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/server/adapter/controller/MenuController.java

@@ -4,9 +4,7 @@ import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.vo.system.MenuVO;
 import com.css.simulation.resource.server.app.service.MenuService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;

+ 23 - 6
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/DictService.java

@@ -8,11 +8,12 @@ import api.common.pojo.vo.system.DictVO;
 import api.common.util.JsonUtil;
 import api.common.util.ObjectUtil;
 import api.common.util.StringUtil;
-import com.css.simulation.resource.server.infra.feign.service.RedisService;
 import com.css.simulation.resource.server.infra.db.mysql.mapper.DictMapper;
+import com.css.simulation.resource.server.infra.feign.service.RedisService;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.*;
@@ -164,12 +165,28 @@ public class DictService {
         return dictMap;
     }
 
-    public void deleteSystemDictByCodeAndType(DictPO dictPO) {
-        dictMapper.deleteSystemDictByCodeAndType(dictPO);
-    }
-
-    public void createSystemDict(DictPO dictPO) {
+    @Transactional
+    public ResponseBodyVO<String> createDictByType(DictPO dictPO) {
         dictPO.setId(StringUtil.getRandomUUID());
+        DictPO tempPo = dictMapper.getDictByDictType(dictPO);
+        int tempOrder = 1;
+        if (tempPo != null) {
+            tempOrder = tempPo.getDictOrder() + 1;
+        }
+        dictPO.setDictOrder(tempOrder);
+        dictPO.setIsDeleted("0");
         dictMapper.createSystemDict(dictPO);
+        DictParam param = new DictParam();
+        param.setDictTypes(dictPO.getDictType());
+        refreshDicts(param);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
+    }
+
+    public ResponseBodyVO<String> deleteDictById(DictPO param) {
+        dictMapper.deleteDictById(param);
+        DictParam deleteParam = new DictParam();
+        deleteParam.setDictTypes(param.getDictType());
+        refreshDicts(deleteParam);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
     }
 }

+ 2 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infra/db/mysql/mapper/DictMapper.java

@@ -17,7 +17,7 @@ public interface DictMapper {
     void createSystemDict(DictPO po);
     void updateSystemDict(DictPO po);
     int deleteSystemDict(DictPO po);
-    int deleteSystemDictByCodeAndType(DictPO po);
-
+    int deleteDictById(DictPO po);
     String getDictByDictCode(DictPO po);
+    DictPO getDictByDictType(DictPO po);
 }

+ 10 - 4
simulation-resource-server/src/main/resources/mysql/mapper/DictMapper.xml

@@ -101,14 +101,12 @@
         and is_deleted='0'
     </update>
 
-    <update id="deleteSystemDictByCodeAndType" parameterType="api.common.pojo.po.system.DictPO">
+    <update id="deleteDictById" parameterType="api.common.pojo.po.system.DictPO">
         update system_dict set
                                is_deleted ='1',
                                modify_time = #{modifyTime,jdbcType=TIMESTAMP},
                                modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
-        where dict_code = #{dictCode,jdbcType=VARCHAR}
-          and dict_type = #{dictType,jdbcType=VARCHAR}
-          and is_deleted='0'
+        where id = #{id,jdbcType=VARCHAR} and is_deleted='0'
     </update>
 
     <select id="getDictByDictCode"  resultType="java.lang.String" parameterType="api.common.pojo.po.system.DictPO" >
@@ -119,4 +117,12 @@
         and dict_code = #{dictCode,jdbcType=VARCHAR}
         and dict_type='carType'
     </select>
+
+    <select id="getDictByDictType"  resultType="api.common.pojo.po.system.DictPO" parameterType="api.common.pojo.po.system.DictPO" >
+        select
+           id, dict_order
+        from system_dict
+        where is_deleted = '0'
+          and dict_type = #{dictType,jdbcType=VARCHAR} order by dict_order desc limit 1
+    </select>
 </mapper>