From c16d957e8e51e40ab4a64fbd1359859690d2510d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BD=90=E5=A4=A9=E5=A4=A7=E5=9C=A3?= <17615834396@163.com> Date: Tue, 2 Apr 2024 10:25:38 +0800 Subject: [PATCH] bug --- .../store/service/impl/StoreServiceImpl.java | 21 ++- .../dept/controller/SysDeptController.java | 13 +- .../system/dept/service/ISysDeptService.java | 32 ++-- .../dept/service/impl/SysDeptServiceImpl.java | 178 ++++++++++++++++-- 4 files changed, 210 insertions(+), 34 deletions(-) diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/service/impl/StoreServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/service/impl/StoreServiceImpl.java index 89cdf841a..0401c3441 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/service/impl/StoreServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/service/impl/StoreServiceImpl.java @@ -3,6 +3,7 @@ package com.fuint.business.store.service.impl; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fuint.business.order.mapper.AllOrderInfoMapper; @@ -386,9 +387,13 @@ public class StoreServiceImpl extends ServiceImpl implem MtStore mtStore = mtStoreMapper.selectById(Integer.parseInt(flag)); // 找到对应的站长deptId LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(); - lambdaQueryWrapper.eq(TDuty::getCode,"z001"); - TDuty tDuty = tDutyMapper.selectOne(lambdaQueryWrapper); - + /* lambdaQueryWrapper.eq(TDuty::getCode,"z001");*/ + lambdaQueryWrapper.eq(TDuty::getStoreId,mtStore.getContractDeptId()); + List tDuties = tDutyMapper.selectList(lambdaQueryWrapper); + TDuty tDuty = new TDuty(); + if(ObjectUtils.isNotEmpty(tDuties)){ + tDuty = tDuties.get(0); + } // 查找对应的用户信息 TAccount tAccount = new TAccount(); tAccount.setDeptId(mtStore.getContractDeptId()); @@ -425,8 +430,16 @@ public class StoreServiceImpl extends ServiceImpl implem MtStore mtStore = mtStoreMapper.selectById(Integer.parseInt(flag)); // 找到对应的站长deptId LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(); + /* lambdaQueryWrapper.eq(TDuty::getCode,"z001");*/ + lambdaQueryWrapper.eq(TDuty::getStoreId,mtStore.getContractDeptId()); + List tDuties = tDutyMapper.selectList(lambdaQueryWrapper); + TDuty tDuty = new TDuty(); + if(ObjectUtils.isNotEmpty(tDuties)){ + tDuty = tDuties.get(0); + } + /*LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.eq(TDuty::getCode,"z001"); - TDuty tDuty = tDutyMapper.selectOne(lambdaQueryWrapper); + TDuty tDuty = tDutyMapper.selectOne(lambdaQueryWrapper);*/ // 查找对应的用户信息 diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/controller/SysDeptController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/controller/SysDeptController.java index 8a6a48f67..303302a67 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/controller/SysDeptController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/controller/SysDeptController.java @@ -66,7 +66,8 @@ public class SysDeptController extends BaseController @GetMapping(value = "/{deptId}") public ResponseObject getInfo(@PathVariable Long deptId) { - List sysDepts = deptService.selectDeptLists(deptId); + //List sysDepts = deptService.selectDeptLists(deptId); + List sysDepts = deptService.selectDeptListss(deptId); SysDept sysDept = deptService.selectDeptById(deptId); if (ObjectUtil.isNotEmpty(sysDept)) sysDept.setStoreNums(sysDepts.size()); List sysDepts1 = deptService.selectDeptList(new SysDept()); @@ -97,6 +98,16 @@ public class SysDeptController extends BaseController return getSuccessResult(row); } + /** + * 获取可创建油站数 + */ + @PostMapping("/getMaxNumber") + public ResponseObject getMaxNumber(@Validated @RequestBody SysDept dept) throws Exception { + + int maxNumber = deptService.getMaxNumber(dept); + return getSuccessResult(maxNumber); + } + /** * 修改部门 */ diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/ISysDeptService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/ISysDeptService.java index 9ec750adf..1d9ccbf47 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/ISysDeptService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/ISysDeptService.java @@ -9,24 +9,28 @@ import java.util.List; /** * 部门管理 服务层 - * + * * @author ruoyi */ public interface ISysDeptService extends IService { /** * 查询部门管理数据 - * + * * @param dept 部门信息 * @return 部门信息集合 */ public List selectDeptList(SysDept dept); List selectDeptLists(Long parentId); + List selectDept(Long parentId); + List selectDeptByDeptId(Long parentId); + List selectDeptListss(Long parentId); + List selectDeptListsss(Long parentId); /** * 查询部门树结构信息 - * + * * @param dept 部门信息 * @return 部门树信息集合 */ @@ -34,7 +38,7 @@ public interface ISysDeptService extends IService /** * 构建前端所需要树结构 - * + * * @param depts 部门列表 * @return 树结构列表 */ @@ -42,7 +46,7 @@ public interface ISysDeptService extends IService /** * 构建前端所需要下拉树结构 - * + * * @param depts 部门列表 * @return 下拉树结构列表 */ @@ -58,7 +62,7 @@ public interface ISysDeptService extends IService /** * 根据部门ID查询信息 - * + * * @param deptId 部门ID * @return 部门信息 */ @@ -66,7 +70,7 @@ public interface ISysDeptService extends IService /** * 根据ID查询所有子部门(正常状态) - * + * * @param deptId 部门ID * @return 子部门数 */ @@ -80,7 +84,7 @@ public interface ISysDeptService extends IService int selectStatusByParentId(Long parentId); /** * 是否存在部门子节点 - * + * * @param deptId 部门ID * @return 结果 */ @@ -88,7 +92,7 @@ public interface ISysDeptService extends IService /** * 查询部门是否存在用户 - * + * * @param deptId 部门ID * @return 结果 true 存在 false 不存在 */ @@ -96,7 +100,7 @@ public interface ISysDeptService extends IService /** * 校验部门名称是否唯一 - * + * * @param dept 部门信息 * @return 结果 */ @@ -111,7 +115,7 @@ public interface ISysDeptService extends IService /** * 新增保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @@ -119,7 +123,7 @@ public interface ISysDeptService extends IService /** * 修改保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @@ -127,7 +131,7 @@ public interface ISysDeptService extends IService /** * 删除部门管理信息 - * + * * @param deptId 部门ID * @return 结果 */ @@ -136,4 +140,6 @@ public interface ISysDeptService extends IService long getCountdown(); boolean isTopLevelNodes(Integer deptId); + + int getMaxNumber(SysDept dept); } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/impl/SysDeptServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/impl/SysDeptServiceImpl.java index 02bd9de2c..5c0deca22 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/impl/SysDeptServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/impl/SysDeptServiceImpl.java @@ -43,7 +43,7 @@ import java.util.stream.Collectors; /** * 部门管理 服务实现 - * + * * @author ruoyi */ @Service @@ -59,7 +59,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 查询部门管理数据 - * + * * @param dept 部门信息 * @return 部门信息集合 */ @@ -83,9 +83,44 @@ public class SysDeptServiceImpl extends ServiceImpl imple return baseMapper.selectList(queryWrapper); } + @Override + public List selectDept(Long parentId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("dept_id",parentId); + queryWrapper.eq("if_delete","0"); + return baseMapper.selectList(queryWrapper); + } + + @Override + public List selectDeptByDeptId(Long parentId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("dept_id",parentId); + queryWrapper.eq("if_delete","0"); + return baseMapper.selectList(queryWrapper); + } + + @Override + public List selectDeptListss(Long parentId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + /*queryWrapper.eq("parent_id",parentId);*/ + queryWrapper.eq("dept_type","3"); + queryWrapper.eq("if_delete","0"); + queryWrapper.like("ancestors",parentId); + return baseMapper.selectList(queryWrapper); + } + + @Override + public List selectDeptListsss(Long parentId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + /*queryWrapper.eq("parent_id",parentId);*/ + queryWrapper.eq("if_delete","0"); + queryWrapper.like("ancestors",parentId); + return baseMapper.selectList(queryWrapper); + } + /** * 查询部门树结构信息 - * + * * @param dept 部门信息 * @return 部门树信息集合 */ @@ -98,7 +133,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 构建前端所需要树结构 - * + * * @param depts 部门列表 * @return 树结构列表 */ @@ -125,7 +160,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 构建前端所需要下拉树结构 - * + * * @param depts 部门列表 * @return 下拉树结构列表 */ @@ -151,7 +186,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 根据部门ID查询信息 - * + * * @param deptId 部门ID * @return 部门信息 */ @@ -163,7 +198,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 根据ID查询所有子部门(正常状态) - * + * * @param deptId 部门ID * @return 子部门数 */ @@ -185,7 +220,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 是否存在子节点 - * + * * @param deptId 部门ID * @return 结果 */ @@ -198,7 +233,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 查询部门是否存在用户 - * + * * @param deptId 部门ID * @return 结果 true 存在 false 不存在 */ @@ -211,7 +246,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 校验部门名称是否唯一 - * + * * @param dept 部门信息 * @return 结果 */ @@ -241,7 +276,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple private LJUserGradeService userGradeService; /** * 新增保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @@ -256,13 +291,27 @@ public class SysDeptServiceImpl extends ServiceImpl imple throw new ServiceException("部门停用,不允许新增"); } dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); - List sysDepts = this.selectDeptLists(dept.getParentId()); + List sysDepts = this.selectDeptListss(dept.getParentId()); if (ObjectUtils.isNotEmpty(info) && ObjectUtils.isNotEmpty(info.getStoreNum()) && CollectionUtil.isNotEmpty(sysDepts) && sysDepts.size()>=info.getStoreNum()) { throw new Exception("已到达最大的油站数量,不可添加!"); } } + if (ObjectUtils.isNotEmpty(dept) && ObjectUtils.isNotEmpty(dept.getDeptType()) && dept.getDeptType().equals("1")){ + List sysDepts = this.selectDept(dept.getParentId()); + for (SysDept sysDept : sysDepts) { + if (ObjectUtils.isNotEmpty(sysDept) && ObjectUtils.isNotEmpty(sysDept.getDeptType()) && sysDept.getDeptType().equals("1")){ + List sysDeptss = this.selectDeptByDeptId(sysDept.getParentId()); + for (SysDept deptss : sysDeptss) { + if (ObjectUtils.isNotEmpty(deptss) && deptss.getDeptType().equals("1")){ + throw new Exception("不可再添加代理!"); + } + } + } + } + } + int insert = baseMapper.insert(dept); //处理店铺 if(StringUtils.isNotEmpty(dept.getDeptType())){ @@ -343,7 +392,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 修改保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @@ -393,7 +442,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 修改该部门的父级部门状态 - * + * * @param dept 当前部门 */ private void updateParentDeptStatusNormal(SysDept dept) @@ -405,7 +454,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 修改子元素关系 - * + * * @param deptId 被修改的部门ID * @param newAncestors 新的父ID集合 * @param oldAncestors 旧的父ID集合 @@ -425,7 +474,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple /** * 删除部门管理信息 - * + * * @param deptId 部门ID * @return 结果 */ @@ -508,4 +557,101 @@ public class SysDeptServiceImpl extends ServiceImpl imple } return false; } + + @Override + public int getMaxNumber(SysDept dept) { + int maxNumber = 0; + int middleNumber = 0; + int finalNumber = 0; + int middleNumber01 = 0; + int middleNumber02 = 0; + //递归拿到最高节点 + SysDept recursion = recursion(dept); + if (ObjectUtils.isNotEmpty(recursion) && ObjectUtils.isNotEmpty(recursion.getStoreNum())) { + maxNumber = recursion.getStoreNum(); + } + + + if (ObjectUtils.isNotEmpty(dept.getDeptId())){ + //上级 + List sysDepts1 = this.selectDeptByDeptId(dept.getParentId()); + if (ObjectUtils.isNotEmpty(sysDepts1) && sysDepts1.get(0).getDeptId() != 100) { + maxNumber = sysDepts1.get(0).getStoreNum(); + //本身 + List sysDepts = this.selectDeptByDeptId(dept.getDeptId()); + middleNumber01 = sysDepts.get(0).getStoreNum(); + //同级 + List sysDepts2 = this.selectDeptLists(dept.getParentId()); + for (SysDept sysDept : sysDepts2) { + middleNumber += sysDept.getStoreNum(); + } + middleNumber02 = middleNumber - middleNumber01; + if (middleNumber02 + dept.getStoreNum() > maxNumber){ + finalNumber = maxNumber - middleNumber02; + }else { + finalNumber = dept.getStoreNum(); + } + }else { + finalNumber = dept.getStoreNum(); + } + return finalNumber; + }else { + //上级 + List sysDepts1 = this.selectDeptByDeptId(dept.getParentId()); + if (ObjectUtils.isNotEmpty(sysDepts1) && sysDepts1.get(0).getDeptId() != 100){ + maxNumber = sysDepts1.get(0).getStoreNum(); + //同级 + List sysDepts2 = this.selectDeptLists(dept.getParentId()); + if (ObjectUtils.isNotEmpty(sysDepts2)) { + for (SysDept sysDept : sysDepts2) { + middleNumber += sysDept.getStoreNum(); + } + middleNumber01 = dept.getStoreNum(); + if (middleNumber + middleNumber01 > maxNumber){ + return maxNumber-middleNumber; + }else { + return middleNumber01; + } + }else { + if (maxNumber > dept.getStoreNum()){ + finalNumber = dept.getStoreNum(); + }else { + finalNumber = maxNumber; + } + } + }else { + finalNumber = dept.getStoreNum(); + } + return finalNumber; + } + + + /*List sysDepts = this.selectDeptListsss(recursion.getDeptId()); + int size = sysDepts.size(); + for (SysDept sysDept : sysDepts) { + if (ObjectUtils.isNotEmpty(sysDept) && ObjectUtils.isNotEmpty(sysDept.getStoreNum()) && sysDept.getParentId() != 100) { + SysDept sysDept1 = sysDepts.get(size - 1); + middleNumber01 = dept.getStoreNum(); + middleNumber += sysDept.getStoreNum(); + } + } + finalNumber = maxNumber - middleNumber - middleNumber01; + if (finalNumber<0){ + finalNumber = maxNumber- middleNumber; + return finalNumber; + }else { + return dept.getStoreNum(); + }*/ + } + + public SysDept recursion (SysDept dept){ + List sysDepts = this.selectDept(dept.getParentId()); + if (ObjectUtils.isNotEmpty(sysDepts) && ObjectUtils.isNotEmpty(sysDepts.get(0).getParentId())) { + if (sysDepts.get(0).getParentId() == 100) { + return sysDepts.get(0); + } + return recursion(sysDepts.get(0)); + } + return new SysDept(); + } }