This commit is contained in:
齐天大圣 2024-04-02 10:25:38 +08:00
parent ee9fd4904b
commit c16d957e8e
4 changed files with 210 additions and 34 deletions

View File

@ -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<MtStoreMapper, MtStore> implem
MtStore mtStore = mtStoreMapper.selectById(Integer.parseInt(flag));
// 找到对应的站长deptId
LambdaQueryWrapper<TDuty> 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<TDuty> 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<MtStoreMapper, MtStore> implem
MtStore mtStore = mtStoreMapper.selectById(Integer.parseInt(flag));
// 找到对应的站长deptId
LambdaQueryWrapper<TDuty> lambdaQueryWrapper = Wrappers.lambdaQuery();
/* lambdaQueryWrapper.eq(TDuty::getCode,"z001");*/
lambdaQueryWrapper.eq(TDuty::getStoreId,mtStore.getContractDeptId());
List<TDuty> tDuties = tDutyMapper.selectList(lambdaQueryWrapper);
TDuty tDuty = new TDuty();
if(ObjectUtils.isNotEmpty(tDuties)){
tDuty = tDuties.get(0);
}
/*LambdaQueryWrapper<TDuty> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(TDuty::getCode,"z001");
TDuty tDuty = tDutyMapper.selectOne(lambdaQueryWrapper);
TDuty tDuty = tDutyMapper.selectOne(lambdaQueryWrapper);*/
// 查找对应的用户信息

View File

@ -66,7 +66,8 @@ public class SysDeptController extends BaseController
@GetMapping(value = "/{deptId}")
public ResponseObject getInfo(@PathVariable Long deptId)
{
List<SysDept> sysDepts = deptService.selectDeptLists(deptId);
//List<SysDept> sysDepts = deptService.selectDeptLists(deptId);
List<SysDept> sysDepts = deptService.selectDeptListss(deptId);
SysDept sysDept = deptService.selectDeptById(deptId);
if (ObjectUtil.isNotEmpty(sysDept)) sysDept.setStoreNums(sysDepts.size());
List<SysDept> 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);
}
/**
* 修改部门
*/

View File

@ -9,24 +9,28 @@ import java.util.List;
/**
* 部门管理 服务层
*
*
* @author ruoyi
*/
public interface ISysDeptService extends IService<SysDept>
{
/**
* 查询部门管理数据
*
*
* @param dept 部门信息
* @return 部门信息集合
*/
public List<SysDept> selectDeptList(SysDept dept);
List<SysDept> selectDeptLists(Long parentId);
List<SysDept> selectDept(Long parentId);
List<SysDept> selectDeptByDeptId(Long parentId);
List<SysDept> selectDeptListss(Long parentId);
List<SysDept> selectDeptListsss(Long parentId);
/**
* 查询部门树结构信息
*
*
* @param dept 部门信息
* @return 部门树信息集合
*/
@ -34,7 +38,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 构建前端所需要树结构
*
*
* @param depts 部门列表
* @return 树结构列表
*/
@ -42,7 +46,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 构建前端所需要下拉树结构
*
*
* @param depts 部门列表
* @return 下拉树结构列表
*/
@ -58,7 +62,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 根据部门ID查询信息
*
*
* @param deptId 部门ID
* @return 部门信息
*/
@ -66,7 +70,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 根据ID查询所有子部门正常状态
*
*
* @param deptId 部门ID
* @return 子部门数
*/
@ -80,7 +84,7 @@ public interface ISysDeptService extends IService<SysDept>
int selectStatusByParentId(Long parentId);
/**
* 是否存在部门子节点
*
*
* @param deptId 部门ID
* @return 结果
*/
@ -88,7 +92,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 查询部门是否存在用户
*
*
* @param deptId 部门ID
* @return 结果 true 存在 false 不存在
*/
@ -96,7 +100,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 校验部门名称是否唯一
*
*
* @param dept 部门信息
* @return 结果
*/
@ -111,7 +115,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 新增保存部门信息
*
*
* @param dept 部门信息
* @return 结果
*/
@ -119,7 +123,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 修改保存部门信息
*
*
* @param dept 部门信息
* @return 结果
*/
@ -127,7 +131,7 @@ public interface ISysDeptService extends IService<SysDept>
/**
* 删除部门管理信息
*
*
* @param deptId 部门ID
* @return 结果
*/
@ -136,4 +140,6 @@ public interface ISysDeptService extends IService<SysDept>
long getCountdown();
boolean isTopLevelNodes(Integer deptId);
int getMaxNumber(SysDept dept);
}

View File

@ -43,7 +43,7 @@ import java.util.stream.Collectors;
/**
* 部门管理 服务实现
*
*
* @author ruoyi
*/
@Service
@ -59,7 +59,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 查询部门管理数据
*
*
* @param dept 部门信息
* @return 部门信息集合
*/
@ -83,9 +83,44 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
return baseMapper.selectList(queryWrapper);
}
@Override
public List<SysDept> selectDept(Long parentId) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("dept_id",parentId);
queryWrapper.eq("if_delete","0");
return baseMapper.selectList(queryWrapper);
}
@Override
public List<SysDept> selectDeptByDeptId(Long parentId) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("dept_id",parentId);
queryWrapper.eq("if_delete","0");
return baseMapper.selectList(queryWrapper);
}
@Override
public List<SysDept> 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<SysDept> 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<SysDeptMapper,SysDept> imple
/**
* 构建前端所需要树结构
*
*
* @param depts 部门列表
* @return 树结构列表
*/
@ -125,7 +160,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 构建前端所需要下拉树结构
*
*
* @param depts 部门列表
* @return 下拉树结构列表
*/
@ -151,7 +186,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 根据部门ID查询信息
*
*
* @param deptId 部门ID
* @return 部门信息
*/
@ -163,7 +198,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 根据ID查询所有子部门正常状态
*
*
* @param deptId 部门ID
* @return 子部门数
*/
@ -185,7 +220,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 是否存在子节点
*
*
* @param deptId 部门ID
* @return 结果
*/
@ -198,7 +233,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 查询部门是否存在用户
*
*
* @param deptId 部门ID
* @return 结果 true 存在 false 不存在
*/
@ -211,7 +246,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 校验部门名称是否唯一
*
*
* @param dept 部门信息
* @return 结果
*/
@ -241,7 +276,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
private LJUserGradeService userGradeService;
/**
* 新增保存部门信息
*
*
* @param dept 部门信息
* @return 结果
*/
@ -256,13 +291,27 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
throw new ServiceException("部门停用,不允许新增");
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
List<SysDept> sysDepts = this.selectDeptLists(dept.getParentId());
List<SysDept> 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<SysDept> sysDepts = this.selectDept(dept.getParentId());
for (SysDept sysDept : sysDepts) {
if (ObjectUtils.isNotEmpty(sysDept) && ObjectUtils.isNotEmpty(sysDept.getDeptType()) && sysDept.getDeptType().equals("1")){
List<SysDept> 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<SysDeptMapper,SysDept> imple
/**
* 修改保存部门信息
*
*
* @param dept 部门信息
* @return 结果
*/
@ -393,7 +442,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 修改该部门的父级部门状态
*
*
* @param dept 当前部门
*/
private void updateParentDeptStatusNormal(SysDept dept)
@ -405,7 +454,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 修改子元素关系
*
*
* @param deptId 被修改的部门ID
* @param newAncestors 新的父ID集合
* @param oldAncestors 旧的父ID集合
@ -425,7 +474,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> imple
/**
* 删除部门管理信息
*
*
* @param deptId 部门ID
* @return 结果
*/
@ -508,4 +557,101 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper,SysDept> 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<SysDept> sysDepts1 = this.selectDeptByDeptId(dept.getParentId());
if (ObjectUtils.isNotEmpty(sysDepts1) && sysDepts1.get(0).getDeptId() != 100) {
maxNumber = sysDepts1.get(0).getStoreNum();
//本身
List<SysDept> sysDepts = this.selectDeptByDeptId(dept.getDeptId());
middleNumber01 = sysDepts.get(0).getStoreNum();
//同级
List<SysDept> 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<SysDept> sysDepts1 = this.selectDeptByDeptId(dept.getParentId());
if (ObjectUtils.isNotEmpty(sysDepts1) && sysDepts1.get(0).getDeptId() != 100){
maxNumber = sysDepts1.get(0).getStoreNum();
//同级
List<SysDept> 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<SysDept> 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<SysDept> 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();
}
}