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/ThrInvWarehouseController.java

136 lines
6.0 KiB
Java

package com.glxp.api.controller.thrsys;
import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
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.FilterThrSubInvWarehouseRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.thrsys.ThrInvWarehouseResponse;
import com.glxp.api.service.thrsys.ThrDeptService;
import com.glxp.api.service.thrsys.ThrInvWarehouseService;
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.ArrayList;
import java.util.Date;
import java.util.List;
@RestController
public class ThrInvWarehouseController {
@Resource
ThrInvWarehouseService thrInvWarehouseService;
@Resource
ThrDeptService thrDeptService;
@GetMapping("/thirdSys/sub/inv/warehouse/filter")
public BaseResponse filterInvWarehouse(FilterThrSubInvWarehouseRequest filterThrSubInvWarehouseRequest) {
List<ThrInvWarehouseResponse> ThrInvWarehouseResponses = thrInvWarehouseService.filterThrInvWarehouseResponse(filterThrSubInvWarehouseRequest);
PageInfo<ThrInvWarehouseResponse> pageInfo;
pageInfo = new PageInfo<>(ThrInvWarehouseResponses);
PageSimpleResponse<ThrInvWarehouseResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(ThrInvWarehouseResponses);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("/thirdSys/sub/inv/warehouse/filterAll")
public BaseResponse filterAllInvWarehouse(FilterThrSubInvWarehouseRequest filterThrSubInvWarehouseRequest) {
List<ThrInvWarehouseEntity> invSubWarehouseEntities = thrInvWarehouseService.filterThrInvWarehouse(filterThrSubInvWarehouseRequest);
return ResultVOUtils.success(invSubWarehouseEntities);
}
@AuthRuleAnnotation("")
@PostMapping("/thirdSys/sub/inv/warehouse/save")
public BaseResponse save(@RequestBody @Valid ThrInvWarehouseEntity invSubWarehouseEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
//先判断是否存在
List<ThrInvWarehouseEntity> ThrInvWarehouseEntityList = new ArrayList<>();
List<ThrInvWarehouseEntity> thrInvWarehouseEntities = thrInvWarehouseService.selectByPid(invSubWarehouseEntity.getParentId());
for (ThrInvWarehouseEntity thrInvWarehouseEntity : thrInvWarehouseEntities) {
if((invSubWarehouseEntity.getCode().equals(thrInvWarehouseEntity.getCode()) && invSubWarehouseEntity.getName().equals(thrInvWarehouseEntity.getName()))){
//添加集合中
ThrInvWarehouseEntityList.add(thrInvWarehouseEntity);
}
}
if(ThrInvWarehouseEntityList.size()==0){
invSubWarehouseEntity.setId(IdUtil.getSnowflake(6, 1).nextId() + "");
boolean b = thrInvWarehouseService.insertThrInvWarehouse(invSubWarehouseEntity);
ThrDeptEntity thrDeptEntity = thrDeptService.selectByCode(invSubWarehouseEntity.getParentId(), invSubWarehouseEntity.getThirdSysFk());
thrDeptEntity.setUpdateTime(new Date());
thrDeptService.updateInvWarehouse(thrDeptEntity);
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success("添加成功!");
}else{
return ResultVOUtils.error(ResultEnum.DATA_REPEAT);
}
}
@AuthRuleAnnotation("")
@PostMapping("/thirdSys/sub/inv/warehouse/edit")
public BaseResponse edit(@RequestBody @Valid ThrInvWarehouseEntity invSubWarehouseEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
if (invSubWarehouseEntity.getId() == null) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
boolean b = thrInvWarehouseService.updateThrInvWarehouse(invSubWarehouseEntity);
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
ThrDeptEntity thrDeptEntity = thrDeptService.selectByCode(invSubWarehouseEntity.getParentId(), invSubWarehouseEntity.getThirdSysFk());
thrDeptEntity.setUpdateTime(new Date());
thrDeptService.updateInvWarehouse(thrDeptEntity);
return ResultVOUtils.success("修改成功!");
}
@AuthRuleAnnotation("")
@PostMapping("/thirdSys/sub/inv/warehouse/delete")
public BaseResponse delete(@RequestBody DeleteRequest deleteRequest) {
if (deleteRequest.getId() == null) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
ThrInvWarehouseEntity thrInvWarehouseEntity = thrInvWarehouseService.selectById(deleteRequest.getId());
ThrDeptEntity thrDeptEntity = thrDeptService.selectByCode(thrInvWarehouseEntity.getParentId(), thrInvWarehouseEntity.getThirdSysFk());
thrDeptEntity.setUpdateTime(new Date());
thrDeptService.updateInvWarehouse(thrDeptEntity);
boolean b = thrInvWarehouseService.deleteById(deleteRequest.getId());
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success("刪除成功!");
}
}