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-wms-java/src/main/java/com/glxp/api/controller/thrsys/ThrDeptController.java

168 lines
7.4 KiB
Java

package com.glxp.api.controller.thrsys;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
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.entity.thrsys.ThrDeptEntity;
import com.glxp.api.entity.thrsys.ThrInvWarehouseEntity;
import com.glxp.api.req.system.DeleteRequest;
import com.glxp.api.req.thrsys.FilterThrDeptRequest;
import com.glxp.api.req.thrsys.FilterThrSubInvWarehouseRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.service.thrsys.ThrDeptService;
import com.glxp.api.service.thrsys.ThrInvWarehouseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
/**
* 第三方仓库信息接口
*/
@Slf4j
@RestController
public class ThrDeptController {
@Resource
ThrDeptService thrDeptService;
@Resource
ThrInvWarehouseService thrInvWarehouseService;
@GetMapping("spms/thrsys/warehouse/filter")
public BaseResponse filterInvWarehouse(FilterThrDeptRequest filterThrDeptRequest) {
List<ThrDeptEntity> thrInvWarehouseEntities = thrDeptService.filterThrInvWarehouse(filterThrDeptRequest);
PageInfo<ThrDeptEntity> pageInfo;
pageInfo = new PageInfo<>(thrInvWarehouseEntities);
PageSimpleResponse<ThrDeptEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(thrInvWarehouseEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@GetMapping("spms/thrsys/warehouse/filterAll")
public BaseResponse filterAllInvWarehouse(FilterThrDeptRequest filterThrDeptRequest) {
filterThrDeptRequest.setPid(0);
List<ThrDeptEntity> thrInvWarehouseEntities = thrDeptService.filterThrInvWarehouse(filterThrDeptRequest);
return ResultVOUtils.success(thrInvWarehouseEntities);
}
@PostMapping("/spms/thrsys/warehouse/save")
public BaseResponse save(@RequestBody @Valid ThrDeptEntity thrDeptEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
if (thrDeptEntity.getPid() == null) {//仓库
thrDeptEntity.setPid(0); // 默认设置
FilterThrDeptRequest filterThrDeptRequest = new FilterThrDeptRequest();
filterThrDeptRequest.setPid(thrDeptEntity.getPid());
} else {//货位
FilterThrDeptRequest filterThrDeptRequest = new FilterThrDeptRequest();
filterThrDeptRequest.setPid(thrDeptEntity.getPid());
ThrDeptEntity pEntity = thrDeptService.selectById(thrDeptEntity.getPid() + "");
thrDeptEntity.setAdvanceType(pEntity.getAdvanceType());
thrDeptEntity.setLevel(pEntity.getLevel());
thrDeptEntity.setPcode(pEntity.getPcode());
}
thrDeptEntity.setUpdateTime(new Date());
boolean b = thrDeptService.insertInvWarehouse(thrDeptEntity);
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success("添加成功!");
}
@PostMapping("/spms/thrsys/warehouse/edit")
public BaseResponse edit(@RequestBody @Valid ThrDeptEntity thrDeptEntity,
BindingResult bindingResult,FilterThrSubInvWarehouseRequest filterThrSubInvWarehouseRequest,FilterThrDeptRequest filterThrDeptRequest) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
if (thrDeptEntity.getId() == null) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
String id = Integer.toString(thrDeptEntity.getId());
ThrDeptEntity thrDeptEntity1 = thrDeptService.selectById(id);
//查询该部门下的仓库
filterThrSubInvWarehouseRequest.setParentId(thrDeptEntity1.getCode());
List<ThrInvWarehouseEntity> thrDept = thrInvWarehouseService.filterThrInvWarehouse(filterThrSubInvWarehouseRequest);
for (ThrInvWarehouseEntity thrInvWarehouseEntity : thrDept) {
thrInvWarehouseEntity.setParentId(thrDeptEntity.getCode());
//修改仓库
thrInvWarehouseService.updateThrInvWarehouse(thrInvWarehouseEntity);
}
//判断部门是否存在
filterThrDeptRequest.setCode(thrDeptEntity.getCode());
filterThrDeptRequest.setName(thrDeptEntity.getName());
filterThrDeptRequest.setThirdSysFk(thrDeptEntity.getThirdSysFk());
List<ThrDeptEntity> thrDeptEntities = thrDeptService.filterThrInvWarehouse(filterThrDeptRequest);
if(thrDeptEntities.size()==0){
thrDeptEntity.setPid(null); // 不能修改父级 pid
thrDeptEntity.setUpdateTime(new Date());
boolean b = thrDeptService.updateInvWarehouse(thrDeptEntity);
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success();
}else{
return ResultVOUtils.error(ResultEnum.DATA_REPEAT);
}
}
@PostMapping("/spms/thrsys/warehouse/delete")
public BaseResponse delete(@RequestBody DeleteRequest deleteRequest) {
if (deleteRequest.getId() == null) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
return thrDeptService.deleteInvById(deleteRequest.getId());
}
/**
* 下载第三方系统的仓库
*/
@GetMapping("/spms/thrsys/warehouse/download")
public BaseResponse downloadThirdWarehouse(String thirdSysFk) {
if (StrUtil.isBlank(thirdSysFk)) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
return thrDeptService.downloadThirdWarehouse(thirdSysFk);
}
@GetMapping("/spms/sub/inv/warehouse/filterThridInv")
public BaseResponse filterInvWarehouse(FilterThrSubInvWarehouseRequest filterThrSubInvWarehouseRequest) {
// todo
// InvWarehouseEntity invWarehouseEntity = invWarehouseService.selectByCode(filterThrSubInvWarehouseRequest.getParentId());
// Object thirdId = ReflectUtil.getFieldValue(invWarehouseEntity, filterThrSubInvWarehouseRequest.getThirdSysFk());
// if (thirdId == null) {
// return ResultVOUtils.error(500, "请先关联仓库对应的第三方仓库,再关联分库!");
// }
// filterThrSubInvWarehouseRequest.setParentId((String) thirdId);
List<ThrInvWarehouseEntity> thrInvWarehouseEntities = thrInvWarehouseService.filterThrInvWarehouse(filterThrSubInvWarehouseRequest);
PageInfo<ThrInvWarehouseEntity> pageInfo;
pageInfo = new PageInfo<>(thrInvWarehouseEntities);
PageSimpleResponse<ThrInvWarehouseEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(thrInvWarehouseEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
}