Bläddra i källkod

完成字典管理开发

sptkw 2 år sedan
förälder
incheckning
8000647b6e

+ 2 - 8
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotProductController.java

@@ -28,9 +28,6 @@ public class IotProductController {
 
     /**
      * 分页查询产品数据
-     *
-     * @param productPage
-     * @return
      */
     @PostMapping("/list")
     public Result<Object> list(@RequestBody @Validated ProductPage productPage) {
@@ -39,9 +36,6 @@ public class IotProductController {
 
     /**
      * 新增产品
-     *
-     * @param iotProductPara
-     * @return
      */
     @PostMapping("/save")
     public Result<Object> save(@RequestBody @Validated IotProductPara iotProductPara) {
@@ -146,8 +140,8 @@ public class IotProductController {
      * @param iotUrlPara
      * @return
      */
-    @PostMapping("/save")
-    public Result<Object> save(@RequestBody @Valid IotUrlPara iotUrlPara) {
+    @PostMapping("/saveUrl")
+    public Result<Object> saveUrl(@RequestBody @Valid IotUrlPara iotUrlPara) {
         return Result.ok(iotUrlService.saveUrl(iotUrlPara), "保存成功");
     }
 

+ 45 - 8
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/controller/DictController.java

@@ -1,17 +1,20 @@
 package com.middle.platform.system.biz.controller;
 
 import com.middle.platform.common.modle.BasePara;
+import com.middle.platform.common.utils.PageRes;
 import com.middle.platform.common.utils.Result;
-import com.middle.platform.system.biz.entity.SysUser;
+import com.middle.platform.system.biz.pojo.req.SysDictItemPara;
 import com.middle.platform.system.biz.pojo.req.SysDictPara;
+import com.middle.platform.system.biz.pojo.res.SysDictItemVo;
 import com.middle.platform.system.biz.service.SysDictItemService;
 import com.middle.platform.system.biz.service.SysDictService;
+import jakarta.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-
 /**
+ * 字典分类(字典表) 和 字典详情(字典项)
+ *
  * @author xucaiqin
  * @date 2023-12-15 08:46:49
  */
@@ -40,21 +43,55 @@ public class DictController {
      * @param basePara 分页参数
      * @return
      */
-    @PostMapping("/list")
+    @GetMapping("/list")
     public Result<Object> list(BasePara basePara) {
         return Result.ok(sysDictService.list(basePara));
     }
 
+
+//    ------------------------- 以下是字典项 -------------------------------
+
+
     /**
      * 分页查询字典项
      *
      * @param dictId   字典id
      * @param basePara 分页参数
-     * @return
      */
     @GetMapping("/queryItem")
-    public Result<List<SysUser>> getItem(@RequestParam("dictId") Long dictId, BasePara basePara) {
-        sysDictItemService.list(dictId,basePara);
-        return Result.ok();
+    public Result<PageRes<SysDictItemVo>> getItem(@RequestParam("dictId") Long dictId, BasePara basePara) {
+        return Result.ok(sysDictItemService.list(dictId, basePara));
+    }
+
+
+    /**
+     * 新增字典项
+     *
+     * @author Aick Spt
+     * @date 2023-12-22 17:11
+     */
+    @PostMapping(name = "新增字典项", path = "/saveItem")
+    public Result<Object> saveItem(@RequestBody SysDictItemPara sysDictItemPara) {
+        return Result.ok(sysDictItemService.saveItemOne(sysDictItemPara), "保存成功");
     }
+
+
+    /**
+     * 删除字典项
+     */
+    @DeleteMapping("/remove")
+    public Result<Object> remove(@RequestParam("id") @NotNull(message = "id不能为空") Long id) {
+        return Result.ok(sysDictItemService.remove(id), "删除成功");
+    }
+
+
+    /**
+     * 修改字典项
+     */
+    @PostMapping("/update")
+    public Result<Object> update(@RequestBody SysDictItemPara sysDictItemPara) {
+        return Result.ok(sysDictItemService.update(sysDictItemPara), "保存成功");
+    }
+
+
 }

+ 6 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/mapper/SysDictItemMapper.java

@@ -17,4 +17,10 @@ public interface SysDictItemMapper extends BaseMapper<SysDictItem> {
     DictCache queryOne(@Param("dictType") String dictType, @Param("value") String value);
 
     List<DictCache> queryList(@Param("dictType") String dictType);
+
+    int delete(@Param("id") Long id);
+
+    SysDictItem getById(@Param("id") Long id);
+
+    int update(SysDictItem sysDictItem);
 }

+ 55 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/pojo/req/SysDictItemPara.java

@@ -0,0 +1,55 @@
+package com.middle.platform.system.biz.pojo.req;
+
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 字典项
+ *
+ * @author Aick Spt
+ * @date 2023-12-22 16:59
+ */
+@Getter
+@Setter
+public class SysDictItemPara {
+
+    private Long id;
+
+    /**
+     * 字典ID
+     */
+    @NotNull(message = "字典ID不能为空")
+    private Long dictId;
+
+    /**
+     * 值
+     */
+    @NotBlank(message = "值不能为空")
+    private String value;
+
+    /**
+     * 标签
+     */
+    @NotBlank(message = "标签不能为空")
+    private String label;
+
+    /**
+     * 字典类型 冗余字段
+     */
+    @NotBlank(message = "字典类型不能为空")
+    private String type;
+
+    /**
+     * 描述
+     */
+    private String desc;
+
+    /**
+     * 排序(升序)
+     */
+    private Integer sort;
+
+
+}

+ 41 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/service/SysDictItemService.java

@@ -1,5 +1,6 @@
 package com.middle.platform.system.biz.service;
 
+import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -10,6 +11,7 @@ import com.middle.platform.system.api.pojo.DictCache;
 import com.middle.platform.system.api.pojo.DictDto;
 import com.middle.platform.system.biz.entity.SysDictItem;
 import com.middle.platform.system.biz.mapper.SysDictItemMapper;
+import com.middle.platform.system.biz.pojo.req.SysDictItemPara;
 import com.middle.platform.system.biz.pojo.res.SysDictItemVo;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.BeanUtils;
@@ -84,4 +86,43 @@ public class SysDictItemService {
     public DictCache query(String dictType, String value) {
         return sysDictItemMapper.queryOne(dictType, value);
     }
+
+
+    /**
+     * 新增字典项
+     *
+     * @author Aick Spt
+     * @date 2023-12-22 17:10
+     */
+    public int saveItemOne(SysDictItemPara sysDictItemPara) {
+        sysDictItemPara.setId(null);
+        if (sysDictItemPara.getSort() == null) {
+            sysDictItemPara.setSort(1);
+        }
+        if (sysDictItemPara.getDesc() == null) {
+            sysDictItemPara.setDesc(sysDictItemPara.getLabel());
+        }
+        SysDictItem sysDictItem = new SysDictItem();
+        BeanUtil.copyProperties(sysDictItemPara, sysDictItem);
+        return sysDictItemMapper.insert(sysDictItem);
+    }
+
+
+    public int remove(Long id) {
+        return sysDictItemMapper.delete(id);
+    }
+
+
+    public int update(SysDictItemPara sysDictItemPara) {
+        Long id = sysDictItemPara.getId();
+        if (id == null) {
+            throw new RuntimeException("ID必填");
+        }
+        SysDictItem sysDictItem = sysDictItemMapper.getById(id);
+        if (Objects.isNull(sysDictItem)) {
+            throw new RuntimeException("数据不存在");
+        }
+        BeanUtil.copyProperties(sysDictItemPara, sysDictItem);
+        return sysDictItemMapper.update(sysDictItem);
+    }
 }

+ 39 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/resources/mapper/SysDictItemMapper.xml

@@ -59,4 +59,43 @@
             and sdi.del_flag = 0
         </where>
     </select>
+
+    <!--  根据ID删除  -->
+    <update id="delete">
+        update sys_dict_item set del_flag = 1 where id = #{id,jdbcType=BIGINT}
+    </update>
+
+    <select id="getById" resultMap="BaseResultMap">
+        select *
+        from sys_dict_item sdi
+        where del_flag = 0
+          and id = #{id,jdbcType=BIGINT}
+    </select>
+
+    <update id="update">
+        update sys_dict_item
+        <set>
+            <if test="dictId != null">
+                `dict_id` = #{dictId,jdbcType=BIGINT},
+            </if>
+            <if test="value != null">
+                `value` = #{value,jdbcType=VARCHAR},
+            </if>
+            <if test="label != null">
+                `label` = #{label,jdbcType=VARCHAR},
+            </if>
+            <if test="type != null">
+                `type` = #{type,jdbcType=VARCHAR},
+            </if>
+            <if test="desc != null">
+                `desc` = #{desc,jdbcType=VARCHAR},
+            </if>
+            <if test="sort != null">
+                `sort` = #{sort,jdbcType=INTEGER}
+            </if>
+        </set>
+        <where>
+            id = #{id,jdbcType=BIGINT}
+        </where>
+    </update>
 </mapper>