From cc5fdf04f963ee2d6b328c2485b89c0c827dba26 Mon Sep 17 00:00:00 2001 From: wangjingsheng Date: Tue, 15 Mar 2022 11:12:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A8=A1=E5=9E=8B=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pms/ocp/common/constants/ResultCode.java | 1 + .../controller/ModelClassifyController.java | 27 +++++- .../pms/ocp/service/ModelClassifyService.java | 12 ++- .../impl/ModelClassifyServiceImpl.java | 96 +++++++++++++------ 4 files changed, 102 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/pms/ocp/common/constants/ResultCode.java b/src/main/java/com/pms/ocp/common/constants/ResultCode.java index cf05925..a4e292f 100644 --- a/src/main/java/com/pms/ocp/common/constants/ResultCode.java +++ b/src/main/java/com/pms/ocp/common/constants/ResultCode.java @@ -87,6 +87,7 @@ public enum ResultCode { ROLE_EXIST(10007, "角色定义已存在!"), CODE_EXIST(10008, "编码已存在!"), NAME_EXIST(10009, "名称已存在!"), + NO_DELETE(10010, "无法删除,有关联数据!"), USER_ORGANIZATION_LEVEL_ERROR(10023, "用户组织机构关联层级有误!"), USER_ORGANIZATION_INFO_ERROR(10024,"用户组织机构信息有误!"), TOKEN_INVALID(9997, "登录失效,请重新登录!"), diff --git a/src/main/java/com/pms/ocp/controller/ModelClassifyController.java b/src/main/java/com/pms/ocp/controller/ModelClassifyController.java index 29bca8a..5624c5e 100644 --- a/src/main/java/com/pms/ocp/controller/ModelClassifyController.java +++ b/src/main/java/com/pms/ocp/controller/ModelClassifyController.java @@ -1,12 +1,14 @@ package com.pms.ocp.controller; import com.github.pagehelper.PageInfo; +import com.pms.ocp.common.constants.ResultCode; import com.pms.ocp.model.entity.ModelClassify; import com.pms.ocp.model.vo.OcpModelGroupVO; import com.pms.ocp.model.vo.ResponseVO; import com.pms.ocp.service.ModelClassifyService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -30,7 +32,6 @@ public class ModelClassifyController { /** * 模型分类导航 * - * @param searchCondition 分类名称 * @return pms.ocp.model.vo.ResponseVO * @author huxiuwu * @date 2022/3/9 @@ -51,9 +52,9 @@ public class ModelClassifyController { @ApiOperation("右侧子类详情列表") @GetMapping("/subclassDetailsList") public ResponseVO subclassDetailsList(@RequestParam int currentPage, - @RequestParam int pageSize, - @RequestParam(required = false,defaultValue = "") String parentGroupCode, - @RequestParam(required = false,defaultValue = "") String subclassGroupName + @RequestParam int pageSize, + @RequestParam(required = false, defaultValue = "") String parentGroupCode, + @RequestParam(required = false, defaultValue = "") String subclassGroupName ) { return modelClassifyService.subclassDetailsList(currentPage, pageSize, parentGroupCode, subclassGroupName); } @@ -85,4 +86,20 @@ public class ModelClassifyController { public ResponseVO update(@RequestBody List list) { return modelClassifyService.update(list); } -} + + /** + * 删除模型分类 + **/ + @ApiOperation("删除模型分类") + @PostMapping("/delete") + public ResponseVO delete(@ApiParam(value = "模型分类编号") @RequestParam(required = false, defaultValue = "") String objId, + @ApiParam(value = "模型分类编码") @RequestParam(required = false, defaultValue = "") String modelGroupCode, + @ApiParam(value = "模型分类归属公司编码") @RequestParam(required = false, defaultValue = "") String groupCompanyCode) { + + Integer integer = modelClassifyService.deleteModelClassify(objId, modelGroupCode, groupCompanyCode); + if (integer.intValue() == -1) { + ResponseVO.ok(ResultCode.NO_DELETE); + } + return ResponseVO.ok(integer); + } +} \ No newline at end of file diff --git a/src/main/java/com/pms/ocp/service/ModelClassifyService.java b/src/main/java/com/pms/ocp/service/ModelClassifyService.java index 7975b41..a9d4b01 100644 --- a/src/main/java/com/pms/ocp/service/ModelClassifyService.java +++ b/src/main/java/com/pms/ocp/service/ModelClassifyService.java @@ -16,7 +16,17 @@ public interface ModelClassifyService { ResponseVO insert(List list); - ResponseVO subclassDetailsList(int currentPage,int pageSize,String parentGroupCode,String subclassGroupName); + ResponseVO subclassDetailsList(int currentPage, int pageSize, String parentGroupCode, String subclassGroupName); ResponseVO update(List list); + + /** + * 删除模型分类 + * + * @param objId + * @param modelCode + * @param groupCompanyCode + * @return + */ + Integer deleteModelClassify(String objId, String modelCode, String groupCompanyCode); } diff --git a/src/main/java/com/pms/ocp/service/impl/ModelClassifyServiceImpl.java b/src/main/java/com/pms/ocp/service/impl/ModelClassifyServiceImpl.java index 15cd98d..78bcf29 100644 --- a/src/main/java/com/pms/ocp/service/impl/ModelClassifyServiceImpl.java +++ b/src/main/java/com/pms/ocp/service/impl/ModelClassifyServiceImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.pms.ocp.common.constants.CodeEnum; import com.pms.ocp.common.utils.PageUtil; import com.pms.ocp.mapper.ModelClassifyMapper; +import com.pms.ocp.model.entity.Model; import com.pms.ocp.model.entity.ModelClassify; import com.pms.ocp.model.vo.OcpModelGroupVO; import com.pms.ocp.model.vo.ResponseVO; @@ -54,29 +55,31 @@ public class ModelClassifyServiceImpl implements ModelClassifyService { /** * 右侧子类详情列表 - * 这边是右侧详情页,需求是点击右侧导航树上的分类显示该分类的所有子集, - * 所以第一次查询查询到所有并将其转换为key为其分类编码,value为其本身 - * 的map.第二次是根据搜素框的值进行模糊查询 + * 这边是右侧详情页,需求是点击右侧导航树上的分类显示该分类的所有子集, + * 所以第一次查询查询到所有并将其转换为key为其分类编码,value为其本身 + * 的map.第二次是根据搜素框的值进行模糊查询 + * * @return pms.ocp.model.vo.ResponseVO * @author huxiuwu * @date 2022/3/9 > **/ @Override - public ResponseVO subclassDetailsList(int currentPage,int pageSize,String parentGroupCode,String subclassGroupName) { + public ResponseVO subclassDetailsList(int currentPage, int pageSize, String parentGroupCode, String subclassGroupName) { //查询所有 - List ocpModelGroupVOList = this.selectByCondition(null,null); + List ocpModelGroupVOList = this.selectByCondition(null, null); //将查询到所有数据的list转换为key为分类code,value为本身的map Map groupByCode = ocpModelGroupVOList.stream().collect(Collectors.toMap(OcpModelGroupVO::getModelGroupCode, Function.identity(), (key1, key2) -> key2)); //根据key获取前端传入code的对象 OcpModelGroupVO ocpModelGroupVO = groupByCode.get(parentGroupCode); //模糊查询 - List dimConditionList = this.selectByCondition(null,subclassGroupName); + List dimConditionList = this.selectByCondition(null, subclassGroupName); //递归获取模糊查询后属于parentGroupCode子集 List childrenList = findChildren(dimConditionList, ocpModelGroupVO, new LinkedList<>()); - PageUtil pageUtil = new PageUtil<>(); - pageUtil.pageUtil(currentPage,pageSize,childrenList); + PageUtil pageUtil = new PageUtil<>(); + pageUtil.pageUtil(currentPage, pageSize, childrenList); return ResponseVO.ok(pageUtil); } + /** * 修改 * @@ -113,36 +116,39 @@ public class ModelClassifyServiceImpl implements ModelClassifyService { /** * 获取父节点下的所有子节点放入list中 - * @author huxiuwu - * @date 2022/3/9 + * * @param * @param * @param * @return void + * @author huxiuwu + * @date 2022/3/9 **/ - private List findChildren(List groupList, OcpModelGroupVO parent,List childList) { + private List findChildren(List groupList, OcpModelGroupVO parent, List childList) { for (OcpModelGroupVO vo : groupList) { //遍历出父id等于参数的id,add进子节点集合 - if (parent!= null + if (parent != null && parent.getModelGroupCode() .equals(vo.getModelGroupPcode()) && !"".equals(parent.getModelGroupCode())) { //递归遍历下一级 - vo.setModelGroupPName(parent.getModelGroupName()); - if (!childList.remove(vo)){ - childList.add(vo); - } - findChildren(groupList, vo, childList); + vo.setModelGroupPName(parent.getModelGroupName()); + if (!childList.remove(vo)) { + childList.add(vo); + } + findChildren(groupList, vo, childList); } } return childList; } + /** * 构建树节点 - * @author huxiuwu - * @date 2022/3/10 + * * @param treeNodes 需要构建的list * @return List + * @author huxiuwu + * @date 2022/3/10 **/ private List build(List treeNodes) { List result = new ArrayList<>(); @@ -155,7 +161,7 @@ public class ModelClassifyServiceImpl implements ModelClassifyService { //得到自己的父类 OcpModelGroupVO parent = nodeMap.get(node.getModelGroupPcode()); if (parent != null && (node.getModelGroupPcode().equals(parent.getModelGroupCode())) - && (!"".equals(node.getModelGroupPcode())|| !"".equals(parent.getModelGroupCode()))) { + && (!"".equals(node.getModelGroupPcode()) || !"".equals(parent.getModelGroupCode()))) { //防止每次都new list或者只是使用该对象就new对象浪费内存或者覆盖上一次记录 if (parent.getChildrenList() == null) { parent.setChildrenList(new LinkedList<>()); @@ -172,33 +178,67 @@ public class ModelClassifyServiceImpl implements ModelClassifyService { } /** - * + * @param parent 父类 + * @param treeNodes 需要遍历list * @author huxiuwu * @date 2022/3/10 - * @param parent 父类 - * @param treeNodes 需要遍历list **/ private void addLevel(OcpModelGroupVO parent, List treeNodes) { int level = parent.getLevel(); parent.setLevel(level++); for (OcpModelGroupVO treeNode : treeNodes) { - if (treeNode != null && parent.getModelGroupCode().equals(treeNode.getModelGroupPcode())){ - addLevel(treeNode,treeNodes); + if (treeNode != null && parent.getModelGroupCode().equals(treeNode.getModelGroupPcode())) { + addLevel(treeNode, treeNodes); } } } + /** * 生成构造器 - * @author huxiuwu - * @date 2022/3/10 + * * @param searchCondition * @return List + * @author huxiuwu + * @date 2022/3/10 **/ private List selectByCondition(String... searchCondition) { QueryWrapper queryWrapper = new QueryWrapper<>(); //根据是否传入搜索条件创建构造器进行查询 queryWrapper.eq(StringUtils.isNotEmpty(searchCondition[0]), "model_group_pcode", searchCondition[0]) - .like(StringUtils.isNotEmpty(searchCondition[1]),"model_group_name", searchCondition[1]).orderBy(false,false,"group_ctime"); + .like(StringUtils.isNotEmpty(searchCondition[1]), "model_group_name", searchCondition[1]).orderBy(false, false, "group_ctime"); return classifyMapper.selectList(queryWrapper); } + + /** + * 删除模型分类 + * + * @param objId + * @param modelGroupCode + * @param groupCompanyCode + * @return + */ + @Override + public Integer deleteModelClassify(String objId, String modelGroupCode, String groupCompanyCode) { + + QueryWrapper queryWrapper = new QueryWrapper(); + + if (StringUtils.isNotEmpty(modelGroupCode)) { + queryWrapper.lambda().eq(OcpModelGroupVO::getModelGroupPcode, modelGroupCode); + } + + List opList = classifyMapper.selectList(queryWrapper); + + if (opList.isEmpty()) { + if (StringUtils.isNotEmpty(objId)) { + queryWrapper.lambda().eq(OcpModelGroupVO::getObjId, objId); + } + + if (StringUtils.isNotEmpty(groupCompanyCode)) { + queryWrapper.lambda().eq(OcpModelGroupVO::getGroupCompanyCode, groupCompanyCode); + } + return classifyMapper.delete(queryWrapper); + } + return -1; + + } } -- 2.26.0