Jelajahi Sumber

Merge remote-tracking branch 'origin/dev' into dev

zk 2 tahun lalu
induk
melakukan
77f49ee538

+ 1 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/constant/HttpStatus.java

@@ -124,6 +124,7 @@ public class HttpStatus {
     public static final String USER_DEPT_NOT_EXISTS = "未查询到用户-机构关联信息";
     public static final String MENU_NOT_EXISTS = "未查询到菜单信息";
     public static final String PARENT_MENU_NOT_EXISTS = "未查询到父菜单信息";
+    public static final String PARENT_UNIT_NOT_EXISTS = "未查询到父级单位信息";
 
     /**自定义提示消息*/
     public static final String PASSWD_ERROR = "密码不正确";

+ 12 - 2
sckw-modules/sckw-product/src/main/java/com/sckw/product/controller/KwpGoodsController.java

@@ -1,6 +1,10 @@
 package com.sckw.product.controller;
 
+import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.excel.easyexcel.RequestHolder;
+import com.sckw.excel.utils.ExcelUtil;
+import com.sckw.product.model.GoodsListExport;
 import com.sckw.product.model.vo.req.*;
 import com.sckw.product.service.KwpGoodsService;
 import jakarta.servlet.http.HttpServletResponse;
@@ -107,8 +111,14 @@ public class KwpGoodsController {
      * @return: com.sckw.core.web.response.HttpResult
      */
     @PostMapping(value = "/export", produces = MediaType.APPLICATION_JSON_VALUE)
-    public void export(@RequestBody ExportGoodsListParam params, HttpServletResponse response) {
-        kwpGoodsService.export(params,response);
+    public HttpResult export(@RequestBody ExportGoodsListParam params) {
+        HttpServletResponse response = RequestHolder.getResponse();
+        List<GoodsListExport> list = kwpGoodsService.export(params);
+        if (CollectionUtils.isNotEmpty(list)) {
+            ExcelUtil.download(response, GoodsListExport.class, list);
+            return HttpResult.ok();
+        }
+        return HttpResult.error("没有可导出的数据");
     }
 
 

+ 4 - 2
sckw-modules/sckw-product/src/main/java/com/sckw/product/model/GoodsListExport.java

@@ -5,6 +5,8 @@ import com.sckw.excel.annotation.ExcelContext;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+
 /**
  * @desc: 商品列表导出对象
  * @author: yzc
@@ -12,8 +14,8 @@ import lombok.experimental.Accessors;
  */
 @Data
 @Accessors(chain = true)
-@ExcelContext(sheetName = "商品列表信息",fileName = "商品列表信息")
-public class GoodsListExport {
+@ExcelContext(fileName = "商品列表信息", sheetName = "商品列表信息")
+public class GoodsListExport implements Serializable {
 
     @ExcelProperty(value = "上架状态", index = 0)
     private String statusLabel;

+ 6 - 8
sckw-modules/sckw-product/src/main/java/com/sckw/product/service/KwpGoodsService.java

@@ -17,7 +17,6 @@ import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.excel.utils.DateUtil;
-import com.sckw.excel.utils.ExcelUtil;
 import com.sckw.product.dao.KwpGoodsMapper;
 import com.sckw.product.enums.GoodsStatusEnum;
 import com.sckw.product.model.*;
@@ -27,7 +26,6 @@ import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.model.dto.res.EntCacheResDto;
 import com.sckw.system.api.model.dto.res.SysAreaCacheResDto;
 import com.sckw.system.api.model.dto.res.UserCacheResDto;
-import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
@@ -458,9 +456,12 @@ public class KwpGoodsService {
      * @Param params:
      * @return: void
      */
-    public void export(ExportGoodsListParam params, HttpServletResponse response) {
+    public List<GoodsListExport> export(ExportGoodsListParam params) {
         PageResult pageResult = select(BeanUtils.copyProperties(params, SelectGoodsListParam.class), false);
         List<GoodsList> goodsLists = pageResult.getList();
+        if (CollectionUtils.isEmpty(goodsLists)) {
+            return Collections.emptyList();
+        }
         List<GoodsListExport> list = new ArrayList<>();
         goodsLists.forEach(e -> {
             GoodsListExport export = BeanUtils.copyProperties(e, GoodsListExport.class);
@@ -470,11 +471,8 @@ public class KwpGoodsService {
                     .setAddedTime(Objects.isNull(e.getShelfTime()) ? null : DateUtil.getDateTime(e.getShelfTime()));
             list.add(export);
         });
-        try {
-            ExcelUtil.download(response, GoodsListExport.class, list);
-        } catch (Exception e) {
-            throw new BusinessException("导出商品列表异常", e.getMessage());
-        }
+        return list;
+
     }
 
     /**

+ 88 - 88
sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsDeptController.java

@@ -1,88 +1,88 @@
-//package com.sckw.system.controller;
-//
-//import com.sckw.core.exception.SystemException;
-//import com.sckw.core.web.constant.HttpStatus;
-//import com.sckw.core.web.response.HttpResult;
-//import com.sckw.system.model.KwsDept;
-//import com.sckw.system.service.KwsDeptService;
-//import jakarta.validation.Valid;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.web.bind.annotation.*;
-//
-///**
-// * 组织机构
-// * @author zk
-// * @date 2023-05-31
-// */
-//@RestController
-//@RequestMapping("/kwsDept")
-//public class KwsDeptController {
-//
-//    @Autowired
-//    private KwsDeptService kwsDeptService;
-//
-//    /**
-//     * @param id 主键ID
-//     * @return
-//     * @description 根据主键查询
-//     * @author zk
-//     * @date 2023/5/30
-//     **/
-//    @GetMapping("/detail")
-//    public HttpResult selectByKey(Long id) throws SystemException {
-//        KwsDept sysDict = kwsDeptService.selectByKey(id);
-//        return HttpResult.ok(sysDict);
-//    }
-//
-//    /**
-//     * @param params
-//     * @return
-//     * @description 分页查询
-//     * @author zk
-//     * @date 2023/5/30
-//     **/
-//    @PostMapping("/findDeptTree")
-//    public HttpResult findPage(@RequestBody KwsDept params) throws SystemException {
-//        return HttpResult.ok(kwsDeptService.findTree(params));
-//    }
-//
-//    /**
-//     * @param params {name 机构名称、company 是否公司}
-//     * @return
-//     * @description 新增
-//     * @author zk
-//     * @date 2023/5/30
-//     **/
-//    @PostMapping("/add")
-//    public HttpResult add(@Valid @RequestBody KwsDept params) throws SystemException {
-//        kwsDeptService.add(params);
-//        return HttpResult.ok(HttpStatus.MSG_003);
-//    }
-//
-//    /**
-//     * @param params {id 主键ID、name 机构名称、company 是否公司}
-//     * @return
-//     * @description 更新
-//     * @author zk
-//     * @date 2023/5/30
-//     **/
-//    @PostMapping("/update")
-//    public HttpResult update(@RequestBody KwsDept params) throws SystemException {
-//        kwsDeptService.update(params);
-//        return HttpResult.ok(HttpStatus.MSG_005);
-//    }
-//
-//    /**
-//     * @param ids {ids:主键ID(多个以逗号隔开)}
-//     * @return
-//     * @description 删除
-//     * @author zk
-//     * @date 2023/5/30
-//     **/
-//    @PostMapping("/dels")
-//    public HttpResult del(@RequestParam String ids) throws SystemException {
-//        kwsDeptService.deleteByKey(ids);
-//        return HttpResult.ok(HttpStatus.MSG_008);
-//    }
-//
-//}
+package com.sckw.system.controller;
+
+import com.sckw.core.exception.SystemException;
+import com.sckw.core.web.constant.HttpStatus;
+import com.sckw.core.web.response.HttpResult;
+import com.sckw.system.model.KwsDept;
+import com.sckw.system.service.KwsDeptService;
+import jakarta.validation.Valid;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 组织机构
+ * @author zk
+ * @date 2023-05-31
+ */
+@RestController
+@RequestMapping("/kwsDept")
+public class KwsDeptController {
+
+    @Autowired
+    private KwsDeptService kwsDeptService;
+
+    /**
+     * @param id 主键ID
+     * @return
+     * @description 根据主键查询
+     * @author zk
+     * @date 2023/5/30
+     **/
+    @GetMapping("/detail")
+    public HttpResult selectByKey(Long id) throws SystemException {
+        KwsDept sysDict = kwsDeptService.selectByKey(id);
+        return HttpResult.ok(sysDict);
+    }
+
+    /**
+     * @param params
+     * @return
+     * @description 分页查询
+     * @author zk
+     * @date 2023/5/30
+     **/
+    @PostMapping("/findDeptTree")
+    public HttpResult findPage(@RequestBody KwsDept params) throws SystemException {
+        return HttpResult.ok(kwsDeptService.findTree(params));
+    }
+
+    /**
+     * @param params {name 机构名称、company 是否公司}
+     * @return
+     * @description 新增
+     * @author zk
+     * @date 2023/5/30
+     **/
+    @PostMapping("/add")
+    public HttpResult add(@Valid @RequestBody KwsDept params) throws SystemException {
+        kwsDeptService.add(params);
+        return HttpResult.ok(HttpStatus.MSG_003);
+    }
+
+    /**
+     * @param params {id 主键ID、name 机构名称、company 是否公司}
+     * @return
+     * @description 更新
+     * @author zk
+     * @date 2023/5/30
+     **/
+    @PostMapping("/update")
+    public HttpResult update(@RequestBody KwsDept params) throws SystemException {
+        kwsDeptService.update(params);
+        return HttpResult.ok(HttpStatus.MSG_005);
+    }
+
+    /**
+     * @param ids {ids:主键ID(多个以逗号隔开)}
+     * @return
+     * @description 删除
+     * @author zk
+     * @date 2023/5/30
+     **/
+    @PostMapping("/dels")
+    public HttpResult del(@RequestParam String ids) throws SystemException {
+        kwsDeptService.deleteByKey(ids);
+        return HttpResult.ok(HttpStatus.MSG_008);
+    }
+
+}

+ 2 - 10
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteSystemServiceImpl.java

@@ -232,11 +232,7 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
         if (CollectionUtils.isEmpty(entCacheResDtos)) {
             return null;
         }
-        Map<Long, EntCacheResDto> entMap = new HashMap<>();
-        for (EntCacheResDto ent:entCacheResDtos) {
-            entMap.put(ent.getId(), ent);
-        }
-        return entMap;
+        return entCacheResDtos.stream().collect(Collectors.toMap(EntCacheResDto::getId, x -> x, (oldValue, newValue) -> newValue));
     }
 
     @Override
@@ -304,11 +300,7 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
         if (CollectionUtils.isEmpty(userCacheResDtos)) {
             return null;
         }
-        Map<Long, UserCacheResDto> entMap = new HashMap<>();
-        for (UserCacheResDto ent:userCacheResDtos) {
-            entMap.put(ent.getId(), ent);
-        }
-        return entMap;
+        return userCacheResDtos.stream().collect(Collectors.toMap(UserCacheResDto::getId, x -> x, (oldValue, newValue) -> newValue));
     }
 
     @Override

+ 102 - 1
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/res/KwsDeptResVo.java

@@ -1,7 +1,16 @@
 package com.sckw.system.model.vo.res;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.sckw.core.utils.LongToStringUtils;
 import com.sckw.system.model.KwsDept;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
 import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -10,7 +19,99 @@ import java.util.List;
  * @date 2023-06-01
  */
 @Data
-public class KwsDeptResVo extends KwsDept {
+public class KwsDeptResVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 2368611167836464517L;
+    /**
+     * 主键
+     */
+    @JsonSerialize(using = LongToStringUtils.class)
+    private Long id;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    /**
+     * 状态:0正常/1锁定
+     */
+    private Integer status = 0;
+
+    /**
+     * 创建人
+     */
+    @JsonSerialize(using = LongToStringUtils.class)
+    private Long createBy;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 更新人
+     */
+    @JsonSerialize(using = LongToStringUtils.class)
+    private Long updateBy;
+
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 删除标识(0正常/-1删除)
+     */
+    private Integer delFlag = 0;
+    /**
+     * 机构类型(1系统管理机构、2平台企业机构)
+     */
+    private Integer systemType;
+
+    /**
+     * 企业id
+     */
+    @JsonSerialize(using = LongToStringUtils.class)
+    private Long entId;
+
+    /**
+     * 机构名称
+     */
+    private String name;
+
+    /**
+     * 是否是公司(0 机构部门/1 公司)
+     */
+    private Integer company;
+
+    /**
+     * 上级机构ID,一级机构为0
+     */
+    @JsonSerialize(using = LongToStringUtils.class)
+    private Long parentId;
+
+    /**
+     * 上级机构名
+     */
+    private String parentName;
+
+    /**
+     * 所有上级机构id
+     */
+    private String parentIds;
+
+    /**
+     * 机构层级(1更目录、...递增)
+     */
+    private Integer level;
+
+    /**
+     * 排序
+     */
+    private Integer sort;
 
     /**
      * 下级菜单

+ 16 - 4
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsDeptService.java

@@ -14,12 +14,14 @@ import com.sckw.system.model.KwsDept;
 import com.sckw.system.model.KwsUserDept;
 import com.sckw.system.model.pojo.FindDeptUserPojo;
 import com.sckw.system.model.vo.res.KwsDeptResVo;
+import org.checkerframework.checker.units.qual.K;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * 组织机构service接口
@@ -46,18 +48,28 @@ public class KwsDeptService {
      */
     public void add(KwsDept params) {
         Long deptId = new IdWorker(1).nextId();
-        if (StringUtils.isNotBlank(params.getParentId())) {
+        if (Objects.nonNull(params.getParentId()) && params.getParentId().compareTo(0L) != 0) {
             KwsDept kwsDept = kwsDeptDao.selectByKey(params.getParentId());
-            if (kwsDept != null) {
-                params.setParentIds(kwsDept.getParentIds() + Global.COMMA + deptId);
-                params.setLevel(kwsDept.getLevel() != null ? kwsDept.getLevel() + 1 : 1);
+            if (Objects.isNull(kwsDept)) {
+                throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.PARENT_UNIT_NOT_EXISTS);
             }
+            params.setParentIds(kwsDept.getParentIds() + Global.COMMA + deptId);
+            params.setLevel(kwsDept.getLevel() != null ? kwsDept.getLevel() + 1 : 1);
         } else {
             params.setParentId(Long.parseLong(Global.PID));
             params.setParentIds(String.valueOf(deptId));
         }
 
+        //查该父级机构有多少子机构,sort依次增加
+        KwsDept kwsDeptParam = new KwsDept();
+        kwsDeptParam.setParentId(params.getParentId());
+        List<KwsDeptResVo> list = kwsDeptDao.findList(kwsDeptParam);
+        int sort = 1;
+        if (CollectionUtils.isNotEmpty(list)) {
+            sort = list.get(0).getSort() + 1;
+        }
         params.setId(deptId);
+        params.setSort(sort);
         if (kwsDeptDao.insert(params) <= 0) {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
         }

+ 7 - 2
sckw-modules/sckw-system/src/main/resources/mapper/KwsDeptDao.xml

@@ -190,9 +190,11 @@
 
   <select id="findList" resultType="com.sckw.system.model.vo.res.KwsDeptResVo" parameterType="com.sckw.system.model.KwsDept" >
     select
-      id, system_type systemType, ent_id entId, name, company, parent_id parentId, level, sort, remark,
-      status, create_by createBy, create_time createTime, update_by updateBy, update_time updateTime
+    sd.id, sd.system_type systemType, sd.ent_id entId, sd.name, sd.company, sd.parent_id parentId, sd.level, sd.sort, sd.remark,
+    sd.status, sd.create_by createBy, sd.create_time createTime, sd.update_by updateBy, sd.update_time updateTime,
+    sd2.name parentName
     from kws_dept sd
+    left join kws_dept sd2 on sd.parent_id = sd2.id and sd2.del_flag=0
     where sd.del_flag = 0
     <if test="systemType != null and systemType != ''">
       and sd.system_type = #{systemType, jdbcType=VARCHAR}
@@ -209,6 +211,9 @@
     <if test="company != null">
       and sd.company = #{company}
     </if>
+    <if test="parentId != null">
+      and sd.parent_id = #{parentId}
+    </if>
     ORDER BY level, sort
   </select>