bug修复
This commit is contained in:
parent
88bb491a55
commit
4f2d287367
|
|
@ -8,6 +8,7 @@ import com.nflg.mobilebroken.admin.pojo.dto.BaseAreaEditDTO;
|
||||||
import com.nflg.mobilebroken.admin.pojo.query.BaseAreaQuery;
|
import com.nflg.mobilebroken.admin.pojo.query.BaseAreaQuery;
|
||||||
import com.nflg.mobilebroken.admin.service.AdminBaseAreaService;
|
import com.nflg.mobilebroken.admin.service.AdminBaseAreaService;
|
||||||
import com.nflg.mobilebroken.common.constant.STATE;
|
import com.nflg.mobilebroken.common.constant.STATE;
|
||||||
|
import com.nflg.mobilebroken.common.exception.NflgException;
|
||||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||||
import com.nflg.mobilebroken.common.pojo.PageData;
|
import com.nflg.mobilebroken.common.pojo.PageData;
|
||||||
import com.nflg.mobilebroken.common.pojo.vo.TBaseAreaVO;
|
import com.nflg.mobilebroken.common.pojo.vo.TBaseAreaVO;
|
||||||
|
|
@ -17,6 +18,7 @@ import com.nflg.mobilebroken.repository.entity.TBaseArea;
|
||||||
import com.nflg.mobilebroken.repository.service.ITBaseAreaService;
|
import com.nflg.mobilebroken.repository.service.ITBaseAreaService;
|
||||||
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
|
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.ttzero.excel.reader.Col;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
@ -120,6 +122,22 @@ public class BaseAreaController extends ControllerBase {
|
||||||
@ApiMark(moduleName = "区域管理", apiName = "删除")
|
@ApiMark(moduleName = "区域管理", apiName = "删除")
|
||||||
public ApiResult<Boolean> del(@RequestBody List<Long> ids){
|
public ApiResult<Boolean> del(@RequestBody List<Long> ids){
|
||||||
VUtils.trueThrow(CollUtil.isEmpty(ids)).throwMessage(STATE.ParamErr,"请选择要删除的行");
|
VUtils.trueThrow(CollUtil.isEmpty(ids)).throwMessage(STATE.ParamErr,"请选择要删除的行");
|
||||||
|
//检查下面是否有
|
||||||
|
List<TBaseArea> delNodes = baseAreaService.getBaseMapper().selectByIds(ids);
|
||||||
|
List<String> hasChildNodes=new ArrayList<>();
|
||||||
|
List<Long> childIds=new ArrayList<>();
|
||||||
|
for ( TBaseArea delNode: delNodes) {
|
||||||
|
childIds.clear();
|
||||||
|
adminBaseAreaService.getAllChildIds( Convert.convert(TBaseAreaVO.class,delNode) ,childIds);
|
||||||
|
if(CollUtil.isNotEmpty(childIds)){
|
||||||
|
hasChildNodes.add(delNode.getAreaName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(CollUtil.isNotEmpty(hasChildNodes)){
|
||||||
|
throw new NflgException(STATE.ParamErr,StrUtil.join(",", hasChildNodes)+" 存在子级区域,请先删除子级");
|
||||||
|
}
|
||||||
|
|
||||||
baseAreaService.getBaseMapper().deleteByIds(ids);
|
baseAreaService.getBaseMapper().deleteByIds(ids);
|
||||||
// baseAreaService.delByIds(ids, AdminUserUtil.getUserNo(), AdminUserUtil.getUserName());
|
// baseAreaService.delByIds(ids, AdminUserUtil.getUserNo(), AdminUserUtil.getUserName());
|
||||||
return ApiResult.success(true);
|
return ApiResult.success(true);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ package com.nflg.mobilebroken.admin.controller;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.nflg.mobilebroken.admin.annotation.ApiMark;
|
import com.nflg.mobilebroken.admin.annotation.ApiMark;
|
||||||
import com.nflg.mobilebroken.admin.constant.Constant;
|
import com.nflg.mobilebroken.admin.constant.Constant;
|
||||||
|
|
@ -21,7 +22,9 @@ import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||||
import com.nflg.mobilebroken.common.util.EecExcelUtil;
|
import com.nflg.mobilebroken.common.util.EecExcelUtil;
|
||||||
import com.nflg.mobilebroken.common.util.UniqueSequenceGenerator;
|
import com.nflg.mobilebroken.common.util.UniqueSequenceGenerator;
|
||||||
import com.nflg.mobilebroken.common.util.VUtils;
|
import com.nflg.mobilebroken.common.util.VUtils;
|
||||||
|
import com.nflg.mobilebroken.repository.entity.AppUser;
|
||||||
import com.nflg.mobilebroken.repository.entity.TBaseCustomer;
|
import com.nflg.mobilebroken.repository.entity.TBaseCustomer;
|
||||||
|
import com.nflg.mobilebroken.repository.service.IAppUserService;
|
||||||
import com.nflg.mobilebroken.repository.service.ITBaseCustomerService;
|
import com.nflg.mobilebroken.repository.service.ITBaseCustomerService;
|
||||||
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
|
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
@ -35,6 +38,8 @@ import java.io.IOException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户管理
|
* 客户管理
|
||||||
|
|
@ -49,6 +54,9 @@ public class CustomerController extends ControllerBase {
|
||||||
@Resource
|
@Resource
|
||||||
AdminCustomerService adminCustomerService;
|
AdminCustomerService adminCustomerService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
IAppUserService appUserService;
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("getList")
|
@PostMapping("getList")
|
||||||
@ApiMark(moduleName = "客户管理", apiName = "获取客户列表")
|
@ApiMark(moduleName = "客户管理", apiName = "获取客户列表")
|
||||||
|
|
@ -117,7 +125,20 @@ public class CustomerController extends ControllerBase {
|
||||||
public ApiResult<Boolean> del(@RequestBody List<Long> ids){
|
public ApiResult<Boolean> del(@RequestBody List<Long> ids){
|
||||||
VUtils.trueThrow(CollUtil.isEmpty(ids)).throwMessage(STATE.ParamErr,"请选择要删除的行");
|
VUtils.trueThrow(CollUtil.isEmpty(ids)).throwMessage(STATE.ParamErr,"请选择要删除的行");
|
||||||
|
|
||||||
baseCustomerService.delByIds(ids, AdminUserUtil.getUserNo(), AdminUserUtil.getUserName());
|
//
|
||||||
|
List<AppUser> appUserUsed = appUserService.lambdaQuery().in(AppUser::getCompanyId, ids).list();
|
||||||
|
if(CollUtil.isNotEmpty(appUserUsed)){
|
||||||
|
Set<String> userCompanyIds = appUserUsed.stream().map(u -> u.getCompanyId()).collect(Collectors.toSet());
|
||||||
|
List<TBaseCustomer> checkResult = baseCustomerService.lambdaQuery().in(TBaseCustomer::getId, userCompanyIds).list();
|
||||||
|
if(CollUtil.isNotEmpty(checkResult)){
|
||||||
|
Set<String> collect = checkResult.stream().map(u -> u.getAgencyCompanyName()).collect(Collectors.toSet());
|
||||||
|
if(CollUtil.isNotEmpty(collect)){
|
||||||
|
throw new NflgException(STATE.ParamErr, StrUtil.join(",", collect)+"已在代理商账号中使用,无法删除");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
baseCustomerService.getBaseMapper().deleteByIds(ids);
|
||||||
|
// baseCustomerService.delByIds(ids, AdminUserUtil.getUserNo(), AdminUserUtil.getUserName());
|
||||||
return ApiResult.success(true);
|
return ApiResult.success(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,14 @@ package com.nflg.mobilebroken.admin.controller;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.nflg.mobilebroken.admin.annotation.ApiMark;
|
import com.nflg.mobilebroken.admin.annotation.ApiMark;
|
||||||
import com.nflg.mobilebroken.admin.pojo.dto.DepartmentDTO;
|
import com.nflg.mobilebroken.admin.pojo.dto.DepartmentDTO;
|
||||||
import com.nflg.mobilebroken.admin.pojo.query.DepartmentQuery;
|
import com.nflg.mobilebroken.admin.pojo.query.DepartmentQuery;
|
||||||
import com.nflg.mobilebroken.admin.pojo.vo.BaseDepartmentVO;
|
import com.nflg.mobilebroken.admin.pojo.vo.BaseDepartmentVO;
|
||||||
import com.nflg.mobilebroken.admin.service.AdminDepartmentService;
|
import com.nflg.mobilebroken.admin.service.AdminDepartmentService;
|
||||||
|
import com.nflg.mobilebroken.common.constant.STATE;
|
||||||
|
import com.nflg.mobilebroken.common.exception.NflgException;
|
||||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||||
import com.nflg.mobilebroken.common.pojo.PageData;
|
import com.nflg.mobilebroken.common.pojo.PageData;
|
||||||
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||||
|
|
@ -101,6 +104,19 @@ public class DepartmentController extends ControllerBase {
|
||||||
@ApiMark(moduleName = "部门管理", apiName = "删除")
|
@ApiMark(moduleName = "部门管理", apiName = "删除")
|
||||||
public ApiResult<Boolean> add(@RequestBody List<Long> ids ){
|
public ApiResult<Boolean> add(@RequestBody List<Long> ids ){
|
||||||
VUtils.trueThrowBusinessError(CollUtil.isEmpty(ids)).throwMessage("请选择要删除的数据");
|
VUtils.trueThrowBusinessError(CollUtil.isEmpty(ids)).throwMessage("请选择要删除的数据");
|
||||||
|
List<TBaseDepartment> delDepartments = departmentService.getBaseMapper().selectByIds(ids);
|
||||||
|
List<String> hasChildDeptNames=new ArrayList<>();
|
||||||
|
List<Long> childIds=new ArrayList<>();
|
||||||
|
for (TBaseDepartment dept :delDepartments) {
|
||||||
|
childIds.clear();
|
||||||
|
adminDepartmentService.getAllChildIds(dept,childIds);
|
||||||
|
if(CollUtil.isNotEmpty(childIds)){
|
||||||
|
hasChildDeptNames.add(dept.getDeptName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(CollUtil.isNotEmpty(hasChildDeptNames)){
|
||||||
|
throw new NflgException(STATE.ParamErr, StrUtil.join(",", hasChildDeptNames)+" 存在子集,请先删除子级");
|
||||||
|
}
|
||||||
departmentService.del(ids);
|
departmentService.del(ids);
|
||||||
return ApiResult.success(true);
|
return ApiResult.success(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.nflg.mobilebroken.admin.service;
|
package com.nflg.mobilebroken.admin.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
|
@ -16,10 +17,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -32,24 +30,30 @@ public class AdminBaseAreaService {
|
||||||
public ApiResult<PageData<TBaseAreaVO>> getList(@RequestBody BaseAreaQuery query){
|
public ApiResult<PageData<TBaseAreaVO>> getList(@RequestBody BaseAreaQuery query){
|
||||||
Page<TBaseAreaVO> result = baseAreaService.getList(new Page<>(query.getPage(),query.getPageSize()), query);
|
Page<TBaseAreaVO> result = baseAreaService.getList(new Page<>(query.getPage(),query.getPageSize()), query);
|
||||||
List<TBaseAreaVO> dataResult = Convert.toList(TBaseAreaVO.class, result.getRecords());
|
List<TBaseAreaVO> dataResult = Convert.toList(TBaseAreaVO.class, result.getRecords());
|
||||||
if(StrUtil.isNotBlank(query.getAreaCodeOrName())){
|
if(StrUtil.isNotBlank(query.getAreaCodeOrName()) || Objects.nonNull(query.getAreaState())){
|
||||||
List<TBaseAreaVO> allAreaList = Convert.toList(TBaseAreaVO.class,baseAreaService.lambdaQuery().eq(TBaseArea::getDelIs,0).list()) ;
|
List<TBaseAreaVO> allAreaList = Convert.toList(TBaseAreaVO.class,baseAreaService.lambdaQuery()
|
||||||
|
.eq(TBaseArea::getDelIs,0)
|
||||||
|
.list()) ;
|
||||||
Map<Long, TBaseAreaVO> collect = allAreaList.stream().collect(Collectors.toMap(TBaseAreaVO::getId, Function.identity()));
|
Map<Long, TBaseAreaVO> collect = allAreaList.stream().collect(Collectors.toMap(TBaseAreaVO::getId, Function.identity()));
|
||||||
List<TBaseAreaVO> allParents=new ArrayList<>();
|
List<TBaseAreaVO> allParents=new ArrayList<>();
|
||||||
for (TBaseAreaVO data:dataResult){
|
for (TBaseAreaVO data:dataResult){
|
||||||
allParents.addAll(getAllParents(data, collect));
|
allParents.addAll(getAllParents(data, collect));
|
||||||
|
|
||||||
}
|
}
|
||||||
allParents.addAll(dataResult);
|
allParents.addAll(dataResult);
|
||||||
|
allParents=allParents.stream().distinct().collect(Collectors.toList());
|
||||||
return ApiResult.success(buildTree(allParents),query,result.getTotal());
|
return ApiResult.success(buildTree(allParents),query,result.getTotal());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (TBaseAreaVO data:dataResult){
|
for (TBaseAreaVO data:dataResult){
|
||||||
initNodeChildren(data);
|
initNodeChildren(data,query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ApiResult.success(dataResult,query,result.getTotal());
|
return ApiResult.success(dataResult,query,result.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<Long> getAllChildIds(TBaseAreaVO node, List<Long> ids) {
|
public List<Long> getAllChildIds(TBaseAreaVO node, List<Long> ids) {
|
||||||
List<TBaseAreaVO> immediateChildren = findChildDepartmentsByParentId(node.getId());
|
List<TBaseAreaVO> immediateChildren = findChildDepartmentsByParentId(node.getId());
|
||||||
ids.addAll(immediateChildren.stream().map(u->u.getId()).collect(Collectors.toSet()));
|
ids.addAll(immediateChildren.stream().map(u->u.getId()).collect(Collectors.toSet()));
|
||||||
|
|
@ -59,11 +63,14 @@ public class AdminBaseAreaService {
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initNodeChildren(TBaseAreaVO node) {
|
private void initNodeChildren(TBaseAreaVO node,BaseAreaQuery query) {
|
||||||
List<TBaseAreaVO> immediateChildren = findChildDepartmentsByParentId(node.getId());
|
List<TBaseAreaVO> immediateChildren = findChildDepartmentsByParentId(node.getId());
|
||||||
|
if(query!=null && query.getAreaState()!=null){
|
||||||
|
immediateChildren=immediateChildren.stream().filter(u->query.getAreaState().equals(u.getAreaState())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
node.setChildren(immediateChildren);
|
node.setChildren(immediateChildren);
|
||||||
for (TBaseAreaVO child : immediateChildren) {
|
for (TBaseAreaVO child : immediateChildren) {
|
||||||
initNodeChildren(child);
|
initNodeChildren(child,query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +101,7 @@ public class AdminBaseAreaService {
|
||||||
private List<TBaseAreaVO> buildTree(List<TBaseAreaVO> nodes) {
|
private List<TBaseAreaVO> buildTree(List<TBaseAreaVO> nodes) {
|
||||||
// 使用Map存储id到Node的映射,便于快速查找父节点
|
// 使用Map存储id到Node的映射,便于快速查找父节点
|
||||||
Map<Long, TBaseAreaVO> idToNodeMap = nodes.stream()
|
Map<Long, TBaseAreaVO> idToNodeMap = nodes.stream()
|
||||||
.collect(Collectors.toMap(TBaseAreaVO::getId, Function.identity()));
|
.collect(Collectors.toMap(TBaseAreaVO::getId,area->area, (existing, replacement) -> existing));
|
||||||
|
|
||||||
List<TBaseAreaVO> roots = new ArrayList<>();
|
List<TBaseAreaVO> roots = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<sql id="whr">
|
<sql id="whr">
|
||||||
<if test="query.areaCodeOrName!=null and query.areaCodeOrName!=''">
|
<if test="query.areaCodeOrName!=null and query.areaCodeOrName!=''">
|
||||||
and (area_code =#{query.areaCodeOrName} or area_name = #{query.areaCodeOrName} )
|
and area_name like concat('%', #{query.areaCodeOrName} ,'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="query.areaState!=null">
|
<if test="query.areaState!=null">
|
||||||
and area_state=#{query.areaState}
|
and area_state=#{query.areaState}
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
</sql>
|
</sql>
|
||||||
<select id="getList" resultType="com.nflg.mobilebroken.common.pojo.vo.TBaseAreaVO">
|
<select id="getList" resultType="com.nflg.mobilebroken.common.pojo.vo.TBaseAreaVO">
|
||||||
select * from t_base_area where del_is=0
|
select * from t_base_area where del_is=0
|
||||||
<if test="query.areaCodeOrName==null or query.areaCodeOrName==''">
|
<if test="(query.areaCodeOrName==null or query.areaCodeOrName=='') and query.areaState==null ">
|
||||||
and parent_area_row_id=0
|
and parent_area_row_id=0
|
||||||
</if>
|
</if>
|
||||||
<include refid="whr" />
|
<include refid="whr" />
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<select id="getList" resultType="com.nflg.mobilebroken.repository.entity.TBaseCustomer">
|
<select id="getList" resultType="com.nflg.mobilebroken.repository.entity.TBaseCustomer">
|
||||||
select * from t_base_customer where del_is=0
|
select * from t_base_customer where del_is=0
|
||||||
<include refid="whr"/>
|
<include refid="whr"/> order by data_create_time desc
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue