Gaokun Wang 3 долоо хоног өмнө
parent
commit
b8eeef81d9

+ 90 - 0
eco-nexus-core/nexus-core-biz/src/main/java/org/eco/vip/nexus/core/controller/dict/DictController.java

@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2025 GaoKunW
+ *
+ */
+
+package org.eco.vip.nexus.core.controller.dict;
+
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.hutool.core.lang.tree.Tree;
+import jakarta.annotation.Resource;
+import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotEmpty;
+import org.eco.vip.nexus.core.domain.dict.pojo.DictBO;
+import org.eco.vip.nexus.core.domain.dict.pojo.DictVO;
+import org.eco.vip.nexus.core.service.dict.IDictService;
+import org.eco.vip.orm.pojo.CommonResult;
+import org.eco.vip.orm.pojo.PageResult;
+import org.eco.vip.security.annotation.PermissionsResource;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+import static org.eco.vip.orm.pojo.CommonResult.fail;
+import static org.eco.vip.orm.pojo.CommonResult.success;
+
+/**
+ * @description DictController
+ *
+ * @author GaoKunW
+ * @date 2025/7/16 14:08
+ */
+@RestController
+@RequestMapping("/system/dict")
+@Validated
+@PermissionsResource("dict")
+public class DictController {
+    @Resource
+    private IDictService dictService;
+
+    @GetMapping("/page")
+    public CommonResult<PageResult<DictVO>> page(DictBO dictBO) {
+        return success(dictService.selectPage(dictBO));
+    }
+
+    @GetMapping("/list")
+    public CommonResult<List<DictVO>> list(DictBO dictBO) {
+        return success(dictService.selectList(dictBO));
+    }
+
+    @GetMapping("/tree")
+    public CommonResult<List<Tree<String>>> tree() {
+        return success(dictService.tree());
+    }
+
+    @PostMapping("/add")
+    @SaCheckPermission("system:dict:add")
+    public CommonResult<String> add(@RequestBody @Valid DictBO dictBO) {
+        boolean result = dictService.insert(dictBO);
+        if (!result) {
+            return fail("新增失败!");
+        }
+        return success();
+    }
+
+    @PostMapping("/edit")
+    public CommonResult<String> edit(@RequestBody @Valid DictBO dictBO) {
+        boolean result = dictService.update(dictBO);
+        if (!result) {
+            return fail("更新失败!");
+        }
+        return success();
+    }
+
+    @DeleteMapping("/delete")
+    @SaCheckPermission("system:dict:delete")
+    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空") List<String> ids) {
+        boolean result = dictService.delete(ids);
+        if (!result) {
+            return fail("删除失败!");
+        }
+        return success();
+    }
+}

+ 1 - 1
eco-nexus-core/nexus-core-biz/src/main/java/org/eco/vip/nexus/core/controller/org/OrgController.java

@@ -72,7 +72,7 @@ public class OrgController {
     public CommonResult<String> edit(@RequestBody @Valid OrgBO orgBO) {
         boolean result = orgService.update(orgBO);
         if (!result) {
-            return fail("新组织失败!");
+            return fail("新组织失败!");
         }
         return success();
     }

+ 60 - 0
eco-nexus-core/nexus-core-biz/src/main/java/org/eco/vip/nexus/core/domain/dict/Dict.java

@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2025 GaoKunW
+ *
+ */
+
+package org.eco.vip.nexus.core.domain.dict;
+
+
+import com.mybatisflex.annotation.Id;
+import com.mybatisflex.annotation.Table;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.eco.vip.orm.domain.BaseEntity;
+
+/**
+ * @description Dict
+ *
+ * @author GaoKunW
+ * @date 2025/7/16 14:10
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Table("system_dict_t")
+public class Dict extends BaseEntity {
+    /**
+     * 唯一标识
+     */
+    @Id
+    private String dictId;
+
+    /**
+     * 父ID
+     */
+    private String parentId;
+
+    /**
+     * 标签
+     */
+    private String dictLabel;
+
+    /**
+     * 值
+     */
+    private String dictValue;
+
+    /**
+     * 分类
+     */
+    private String category;
+
+    /**
+     * 回显样式
+     */
+    private String callbackShowStyle;
+
+    /**
+     * 顺序
+     */
+    private Integer orderNum;
+}

+ 64 - 0
eco-nexus-core/nexus-core-biz/src/main/java/org/eco/vip/nexus/core/domain/dict/pojo/DictBO.java

@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2025 GaoKunW
+ *
+ */
+
+package org.eco.vip.nexus.core.domain.dict.pojo;
+
+
+import io.github.linpeilie.annotations.AutoMapper;
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.eco.vip.nexus.core.domain.dict.Dict;
+import org.eco.vip.orm.domain.BaseBO;
+
+/**
+ * @description DictBO
+ *
+ * @author GaoKunW
+ * @date 2025/7/16 14:10
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = Dict.class, reverseConvertGenerate = false)
+public class DictBO extends BaseBO {
+
+    /**
+     * 唯一标识
+     */
+    private String dictId;
+
+    /**
+     * 父ID
+     */
+    @NotBlank(message = "parentId不能为空")
+    private String parentId;
+
+    /**
+     * 标签
+     */
+    @NotBlank(message = "dictLabel不能为空")
+    private String dictLabel;
+
+    /**
+     * 值
+     */
+    @NotBlank(message = "dictValue不能为空")
+    private String dictValue;
+
+    /**
+     * 分类
+     */
+    private String category;
+
+    /**
+     * 回显样式
+     */
+    private String callbackShowStyle;
+
+    /**
+     * 顺序
+     */
+    private Integer orderNum;
+}

+ 60 - 0
eco-nexus-core/nexus-core-biz/src/main/java/org/eco/vip/nexus/core/domain/dict/pojo/DictVO.java

@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2025 GaoKunW
+ *
+ */
+
+package org.eco.vip.nexus.core.domain.dict.pojo;
+
+
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.eco.vip.nexus.core.domain.dict.Dict;
+import org.eco.vip.orm.domain.BaseEntity;
+
+/**
+ * @description DictVO
+ *
+ * @author GaoKunW
+ * @date 2025/7/16 14:10
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = Dict.class, reverseConvertGenerate = false)
+public class DictVO extends BaseEntity {
+
+    /**
+     * 唯一标识
+     */
+    private String dictId;
+
+    /**
+     * 父ID
+     */
+    private String parentId;
+
+    /**
+     * 标签
+     */
+    private String dictLabel;
+
+    /**
+     * 值
+     */
+    private String dictValue;
+
+    /**
+     * 分类
+     */
+    private String category;
+
+    /**
+     * 回显样式
+     */
+    private String callbackShowStyle;
+
+    /**
+     * 顺序
+     */
+    private Integer orderNum;
+}

+ 21 - 0
eco-nexus-core/nexus-core-biz/src/main/java/org/eco/vip/nexus/core/mapper/DictMapper.java

@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2025 GaoKunW
+ *
+ */
+
+package org.eco.vip.nexus.core.mapper;
+
+
+import com.mybatisflex.core.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.eco.vip.nexus.core.domain.dict.Dict;
+
+/**
+ * @description DictMapper
+ *
+ * @author GaoKunW
+ * @date 2025/7/16 14:09
+ */
+@Mapper
+public interface DictMapper extends BaseMapper<Dict> {
+}

+ 104 - 0
eco-nexus-core/nexus-core-biz/src/main/java/org/eco/vip/nexus/core/service/dict/DictService.java

@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2025 GaoKunW
+ *
+ */
+
+package org.eco.vip.nexus.core.service.dict;
+
+
+import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.core.lang.tree.TreeNode;
+import com.mybatisflex.core.paginate.Page;
+import com.mybatisflex.core.query.QueryWrapper;
+import jakarta.annotation.Resource;
+import org.eco.vip.nexus.core.domain.dict.Dict;
+import org.eco.vip.nexus.core.domain.dict.pojo.DictBO;
+import org.eco.vip.nexus.core.domain.dict.pojo.DictVO;
+import org.eco.vip.nexus.core.mapper.DictMapper;
+import org.eco.vip.orm.constant.Constants;
+import org.eco.vip.orm.domain.PageQuery;
+import org.eco.vip.orm.exception.BusinessException;
+import org.eco.vip.orm.pojo.PageResult;
+import org.eco.vip.orm.service.BaseService;
+import org.eco.vip.orm.utils.JsonUtils;
+import org.eco.vip.orm.utils.MapstructUtils;
+import org.eco.vip.orm.utils.ObjUtils;
+import org.eco.vip.orm.utils.StrUtils;
+import org.eco.vip.orm.utils.TreeUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.eco.vip.nexus.core.domain.dict.table.DictTableDef.DICT;
+
+/**
+ * @description DictService
+ *
+ * @author GaoKunW
+ * @date 2025/7/16 14:11
+ */
+@Service
+public class DictService extends BaseService<DictMapper, Dict> implements IDictService {
+
+    @Resource
+    private DictMapper dictMapper;
+
+    private QueryWrapper buildQueryWrapper(DictBO dictBO) {
+        return super.buildBaseQueryWrapper()
+                .and(DICT.DICT_ID.eq(dictBO.getDictId()))
+                .and(DICT.DICT_LABEL.eq(dictBO.getDictLabel()))
+                .and(DICT.DICT_VALUE.eq(dictBO.getDictValue()))
+                .and(DICT.STATUS.eq(dictBO.getStatus()))
+                .and(DICT.PARENT_ID.eq(dictBO.getParentId()).or(DICT.DICT_ID.eq(dictBO.getParentId())));
+    }
+
+    @Override
+    public PageResult<DictVO> selectPage(DictBO dictBO) {
+        QueryWrapper queryWrapper = buildQueryWrapper(dictBO);
+        Page<DictVO> page = dictMapper.paginateWithRelationsAs(PageQuery.build(), queryWrapper, DictVO.class);
+        return PageResult.build(page);
+    }
+
+    @Override
+    public List<DictVO> selectList(DictBO dictBO) {
+        QueryWrapper queryWrapper = buildQueryWrapper(dictBO);
+        return dictMapper.selectListWithRelationsByQueryAs(queryWrapper, DictVO.class);
+    }
+
+    @Override
+    public List<Tree<String>> tree() {
+        QueryWrapper wrapper = QueryWrapper.create().orderBy(Dict::getOrderNum).asc();
+        List<Dict> list = this.list(wrapper);
+        return TreeUtils.build(list.stream().map(dict ->
+                new TreeNode<>(dict.getDictId(), dict.getParentId(), dict.getDictLabel(), dict.getOrderNum()).setExtra(JsonUtils.parseObj(dict))
+        ).collect(Collectors.toList()), "0");
+    }
+
+    @Override
+    public boolean insert(DictBO dictBO) {
+        DictVO dictVO = selectById(dictBO.getParentId());
+        if (ObjUtils.isNotNull(dictVO) && !StrUtils.equals(Constants.NORMAL, dictVO.getStatus())) {
+            throw new BusinessException("父级停用,不允许新增");
+        }
+        Dict dict = MapstructUtils.convert(dictBO, Dict.class);
+        return this.save(dict);
+    }
+
+    @Override
+    public boolean update(DictBO dictBO) {
+        Dict dict = MapstructUtils.convert(dictBO, Dict.class);
+        return this.updateById(dict);
+    }
+
+    @Override
+    public boolean delete(List<String> ids) {
+        return this.removeByIds(ids);
+    }
+
+    @Override
+    public DictVO selectById(String id) {
+        QueryWrapper queryWrapper = query().where(DICT.DICT_ID.eq(id));
+        return this.getOneAs(queryWrapper, DictVO.class);
+    }
+}

+ 74 - 0
eco-nexus-core/nexus-core-biz/src/main/java/org/eco/vip/nexus/core/service/dict/IDictService.java

@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2025 GaoKunW
+ *
+ */
+
+package org.eco.vip.nexus.core.service.dict;
+
+
+import cn.hutool.core.lang.tree.Tree;
+import org.eco.vip.nexus.core.domain.dict.Dict;
+import org.eco.vip.nexus.core.domain.dict.pojo.DictBO;
+import org.eco.vip.nexus.core.domain.dict.pojo.DictVO;
+import org.eco.vip.orm.pojo.PageResult;
+import org.eco.vip.orm.service.IBaseService;
+
+import java.util.List;
+
+/**
+ * @description IDictService
+ *
+ * @author GaoKunW
+ * @date 2025/7/16 14:11
+ */
+public interface IDictService extends IBaseService<Dict> {
+
+    /**
+     * @description: 分页查询
+     * @param dictBO 参数
+     * @return PageResult<OrgVO>
+     **/
+    PageResult<DictVO> selectPage(DictBO dictBO);
+
+    /**
+     * @description: 查询
+     * @param dictBO 参数
+     * @return List<OrgVO>
+     **/
+    List<DictVO> selectList(DictBO dictBO);
+
+    /**
+     * @description: 查询树
+     * @return List<Tree < String>>
+     **/
+    List<Tree<String>> tree();
+
+    /**
+     * @description: 新增
+     * @param dictBO 参数
+     * @return boolean 是否成功
+     **/
+    boolean insert(DictBO dictBO);
+
+    /**
+     * @description: 更新
+     * @param dictBO 参数
+     * @return boolean 是否成功
+     **/
+    boolean update(DictBO dictBO);
+
+    /**
+     * @description: 删除
+     * @param ids ids
+     * @return boolean 是否成功
+     **/
+    boolean delete(List<String> ids);
+
+    /**
+     * 根据ID查询信息
+     *
+     * @param id ID
+     * @return 字典信息
+     */
+    DictVO selectById(String id);
+}

+ 1 - 0
eco-start/src/main/resources/db/mysql/V1_0_0_1__sys-init-ddl.sql

@@ -326,6 +326,7 @@ CREATE TABLE `system_dict_t`
     `dict_label`   varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '字典标签',
     `dict_value`   varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '字典值',
     `category`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '分类',
+    `callback_show_style` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '回显样式',
     `order_num`    int NULL DEFAULT NULL COMMENT '显示顺序',
     `tenant_id`    varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '租户编号',
     `status`       varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '状态(1正常 0停用)',