You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-spms-java/src/main/java/com/glxp/api/controller/auth/DeptController.java

337 lines
14 KiB
Java

package com.glxp.api.controller.auth;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.annotation.Log;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.BusinessType;
import com.glxp.api.controller.BaseController;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.auth.DeptEntity;
import com.glxp.api.entity.auth.InvWarehouseEntity;
import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.req.auth.FilterInvWarehouseRequest;
import com.glxp.api.req.system.DeleteRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.auth.DeptService;
import com.glxp.api.service.auth.InvWarehouseService;
import com.glxp.api.service.system.SystemParamConfigService;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.*;
@RestController
public class DeptController extends BaseController {
@Resource
DeptService deptService;
@Resource
CustomerService customerService;
@Resource
SystemParamConfigService systemParamConfigService;
@Resource
InvWarehouseService invWarehouseService;
@AuthRuleAnnotation("")
@GetMapping("spms/inv/warehouse/filter")
public BaseResponse filterInvWarehouse(FilterInvWarehouseRequest filterInvWarehouseRequest) {
List<DeptEntity> invWarehouseEntities = deptService.filterInvWarehouse(filterInvWarehouseRequest);
PageInfo<DeptEntity> pageInfo = new PageInfo<>(invWarehouseEntities);
PageSimpleResponse<DeptEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(invWarehouseEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("spms/inv/warehouse/filterAll")
public BaseResponse filterAllInvWarehouse(FilterInvWarehouseRequest filterInvWarehouseRequest) {
filterInvWarehouseRequest.setPid(0);
filterInvWarehouseRequest.setStatus(1);
List<DeptEntity> invWarehouseEntities = deptService.filterInvWarehouse(filterInvWarehouseRequest);
return ResultVOUtils.success(invWarehouseEntities);
}
@AuthRuleAnnotation("")
@GetMapping("spms/inv/warehouse/filterNext")
public BaseResponse filterNext(FilterInvWarehouseRequest filterInvWarehouseRequest) {
filterInvWarehouseRequest.setPid(0);
filterInvWarehouseRequest.setStatus(1);
List<DeptEntity> invWarehouseEntities = deptService.filterGroupInvWarehouse(filterInvWarehouseRequest);
return ResultVOUtils.success(invWarehouseEntities);
}
@AuthRuleAnnotation("")
@GetMapping("spms/inv/warehouse/filterByUser")
public BaseResponse filterByUser(FilterInvWarehouseRequest filterInvWarehouseRequest) {
if (isHosUser()) {
AuthAdmin authAdmin = customerService.getUserBean();
filterInvWarehouseRequest.setUserId(authAdmin.getId());
}else {
}
filterInvWarehouseRequest.setPid(0);
filterInvWarehouseRequest.setStatus(1);
List<DeptEntity> mInvWarehouseEntities = deptService.filterAllByUser(filterInvWarehouseRequest);
return ResultVOUtils.success(mInvWarehouseEntities);
}
@AuthRuleAnnotation("")
@GetMapping("spms/inv/warehouse/filterAllLocInv")
public BaseResponse filterAllLocInv(FilterInvWarehouseRequest filterInvWarehouseRequest) {
filterInvWarehouseRequest.setPid(0);
filterInvWarehouseRequest.setStatus(1);
List<DeptEntity> invWarehouseEntities = deptService.filterInvWarehouse(filterInvWarehouseRequest);
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("corp_innor_inv");
List<DeptEntity> temps = new ArrayList<>();
if (systemParamConfigEntity.getParamValue().equals("1")) {
for (DeptEntity deptEntity : invWarehouseEntities) {
if (!deptEntity.getCode().equals(filterInvWarehouseRequest.getLocInvCode())) {
temps.add(deptEntity);
}
}
return ResultVOUtils.success(temps);
} else {
DeptEntity curEntity = deptService.selectByCode(filterInvWarehouseRequest.getLocInvCode());
for (DeptEntity deptEntity : invWarehouseEntities) {
if (!StrUtil.isEmpty(curEntity.getPcode()) && curEntity.getPcode().equals(deptEntity.getCode())) {
temps.add(deptEntity);
} else if (!StrUtil.isEmpty(deptEntity.getPcode()) && deptEntity.getPcode().equals(curEntity.getCode())) {
temps.add(deptEntity);
}
}
return ResultVOUtils.success(temps);
}
}
@AuthRuleAnnotation("")
@GetMapping("spms/inv/warehouse/filterUplLocInv")
public BaseResponse filterUplLocInv(FilterInvWarehouseRequest filterInvWarehouseRequest) {
filterInvWarehouseRequest.setPid(0);
filterInvWarehouseRequest.setStatus(1);
List<DeptEntity> invWarehouseEntities;
AuthAdmin authAdmin = customerService.getUserBean();
filterInvWarehouseRequest.setUserId(authAdmin.getId());
filterInvWarehouseRequest.setPid(0);
List<DeptEntity> mInvWarehouseEntities = deptService.filterAllByUser(filterInvWarehouseRequest);
Map<String, DeptEntity> invWarehouseEntityMap = new HashMap<>();
if (mInvWarehouseEntities.size() > 0) {
for (DeptEntity deptEntity : mInvWarehouseEntities) {
invWarehouseEntityMap.put(deptEntity.getCode(), deptEntity);
if (!"0".equals(deptEntity.getPcode())) {
DeptEntity temp = deptService.selectByCode(deptEntity.getPcode());
invWarehouseEntityMap.put(temp.getCode(), temp);
}
}
}
invWarehouseEntities = new ArrayList<>();
for (DeptEntity deptEntity : invWarehouseEntityMap.values()) {
invWarehouseEntities.add(deptEntity);
}
return ResultVOUtils.success(invWarehouseEntities);
}
@AuthRuleAnnotation("")
@GetMapping("spms/inv/warehouse/filterAllByUser")
public BaseResponse filterAllByUser(FilterInvWarehouseRequest filterInvWarehouseRequest) {
List<DeptEntity> invWarehouseEntities;
AuthAdmin authAdmin = customerService.getUserBean();
if (authAdmin.getCustomerId().equals("110")) {
filterInvWarehouseRequest.setUserId(authAdmin.getId());
} else {
filterInvWarehouseRequest.setUserId(null);
filterInvWarehouseRequest.setSpUse(true);
}
filterInvWarehouseRequest.setPid(0);
invWarehouseEntities = deptService.filterAllByUser(filterInvWarehouseRequest);
return ResultVOUtils.success(invWarehouseEntities);
}
@AuthRuleAnnotation("")
@PostMapping("/spms/inv/warehouse/save")
@Log(title = "用户管理", businessType = BusinessType.INSERT)
public BaseResponse save(@RequestBody @Valid DeptEntity deptEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
List<DeptEntity> deptEntityList = deptService.selectByNameList(deptEntity.getName());
if (deptEntityList != null && deptEntityList.size() > 0) {
for (DeptEntity obj : deptEntityList) {
if (obj.getName().equals(deptEntity.getName()) && !obj.getId().equals(deptEntity.getId())) {
return ResultVOUtils.error(500, "已存在相同名称的仓库,无法继续添加!");
}
}
}
//顶级部门
if (deptEntity.getPid() == null || deptEntity.getPid() == 0) {
deptEntity.setPid(0); // 默认设置
FilterInvWarehouseRequest filterInvWarehouseRequest = new FilterInvWarehouseRequest();
filterInvWarehouseRequest.setPid(deptEntity.getPid());
DeptEntity codeEntity = deptService.selectMaxCode(filterInvWarehouseRequest);
deptEntity.setCode(Integer.parseInt(codeEntity.getCode()) + 1 + "");
deptEntity.setPcode("0");
deptEntity.setLevel(1);
//限制只有一个根节点
FilterInvWarehouseRequest levelRequest = new FilterInvWarehouseRequest();
filterInvWarehouseRequest.setStatus(deptEntity.getStatus());
filterInvWarehouseRequest.setLevel(1);
List<DeptEntity> invWarehouseEntities = deptService.filterInvWarehouse(levelRequest);
if (CollUtil.isNotEmpty(invWarehouseEntities)) {
return ResultVOUtils.error(500, "已存在相同类型的一级部门,无法继续添加!");
}
} else {
//子级部门
FilterInvWarehouseRequest filterInvWarehouseRequest = new FilterInvWarehouseRequest();
filterInvWarehouseRequest.setPid(deptEntity.getPid());
DeptEntity codeEntity = deptService.selectMaxCode(filterInvWarehouseRequest);
DeptEntity pEntity = deptService.selectById(deptEntity.getPid() + "");
if (codeEntity == null) {
int code = Integer.parseInt(pEntity.getCode()) * 1000;
deptEntity.setCode(code + "");
} else {
deptEntity.setCode(Integer.parseInt(codeEntity.getCode()) + 1 + "");
}
deptEntity.setAdvanceType(pEntity.getAdvanceType());
deptEntity.setLevel(pEntity.getLevel() + 1);
deptEntity.setPcode(deptEntity.getPcode());
}
deptEntity.setUpdateTime(new Date());
boolean b = deptService.insertInvWarehouse(deptEntity);
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success("添加成功!");
}
@AuthRuleAnnotation("")
@PostMapping("/spms/inv/warehouse/edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
public BaseResponse edit(@RequestBody @Valid DeptEntity deptEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
if (deptEntity.getId() == null) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
List<DeptEntity> deptEntityList = deptService.selectByNameList(deptEntity.getName());
if (deptEntityList != null && deptEntityList.size() > 0) {
for (DeptEntity obj : deptEntityList) {
if (obj.getName().equals(deptEntity.getName()) && !obj.getId().equals(deptEntity.getId())) {
return ResultVOUtils.error(500, "已存在相同名称的仓库,无法继续添加!");
}
}
}
deptEntity.setPid(null); // 不能修改父级 pid
deptEntity.setUpdateTime(new Date());
boolean b = deptService.updateInvWarehouse(deptEntity);
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success();
}
@AuthRuleAnnotation("")
@PostMapping("/spms/inv/warehouse/delete")
@Log(title = "用户管理", businessType = BusinessType.DELETE)
public BaseResponse delete(@RequestBody DeleteRequest deleteRequest) {
if (deleteRequest.getId() == null) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
//todo 代码未迁移完,后续记得修改
// DeptEntity deptEntity = deptService.selectById(deleteRequest.getId());
// InvProductDetailEntity invProductDetailEntity = invProductDetailService.isExit(deptEntity.getCode());
// if (invProductDetailEntity != null) {
// return ResultVOUtils.error(500, "该仓库已有库存,不能删除!");
// }
//
// List<InvSubWarehouseEntity> invSubWarehouseEntities = invSubWarehouseService.findByParentId(deptEntity.getCode());
// if (CollUtil.isNotEmpty(invSubWarehouseEntities)) {
// return ResultVOUtils.error(500, "删除失败,请先移除该部门关联仓库信息!");
// }
boolean b = deptService.deleteById(deleteRequest.getId());
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success("删除成功!");
}
@AuthRuleAnnotation("")
@PostMapping("/spms/inv/warehouse/disable")
public BaseResponse disable(@RequestBody DeptEntity request) {
if (request.getCode() == null) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
//todo 代码未迁移完,后续记得修改
// List<InvSubWarehouseEntity> invSubWarehouseEntities = invSubWarehouseService.findByParentId(request.getCode());
// if (CollUtil.isNotEmpty(invSubWarehouseEntities)) {
// return ResultVOUtils.error(500, "请先移除该仓库关联的分库!");
// }
return ResultVOUtils.success("禁用成功!");
}
@AuthRuleAnnotation("")
@PostMapping("/spms/inv/warehouse/selectByCode")
public BaseResponse selectByCode(@RequestBody DeptEntity request) {
if (request == null) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
String byCode = invWarehouseService.selectParentIdByCode(request.getCode());
return ResultVOUtils.success(byCode);
}
@AuthRuleAnnotation("")
@PostMapping("/spms/inv/warehouse/selectInvById")
public BaseResponse selectInvById(@RequestBody List<String> InvList) {
if (InvList.size() == 0) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
//先得到部门编码
List<String> String = deptService.selectByIdCode(InvList);
List<InvWarehouseEntity> list = invWarehouseService.selectInvById(String);
return ResultVOUtils.success(list);
}
}