package com.glxp.api.controller.auth; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; 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.auth.AuthAdmin; import com.glxp.api.entity.auth.DeptEntity; import com.glxp.api.entity.auth.InvWarehouseEntity; import com.glxp.api.entity.auth.WarehouseUserEntity; import com.glxp.api.entity.system.SystemParamConfigEntity; import com.glxp.api.req.auth.FilterInvLinkDataRequest; import com.glxp.api.req.auth.FilterInvSubWarehouseRequest; import com.glxp.api.req.auth.FilterInvWarehouseRequest; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.req.system.FilterBasicThirdSysRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.auth.InvSubWarehouseResponse; import com.glxp.api.res.auth.InvWarehouseThirdSysResponse; import com.glxp.api.res.auth.WarehouseUserResponse; 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.auth.WarehouseUserService; import com.glxp.api.service.system.SystemParamConfigService; import org.springframework.beans.BeanUtils; 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 InvWarehouseController { @Resource InvWarehouseService invWarehouseService; @Resource DeptService deptService; @Resource CustomerService customerService; @Resource private WarehouseUserService warehouseUserService; @Resource private SystemParamConfigService systemParamConfigService; @AuthRuleAnnotation("") @GetMapping("spms/sub/inv/warehouse/filter") public BaseResponse filterInvWarehouse(FilterInvSubWarehouseRequest filterInvSubWarehouseRequest) { List responses = invWarehouseService.filterInvSubWarehouseResponse(filterInvSubWarehouseRequest); PageInfo pageInfo = new PageInfo<>(responses); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(responses); return ResultVOUtils.success(pageSimpleResponse); } @AuthRuleAnnotation("") @GetMapping("spms/sub/inv/warehouse/findByInv") public BaseResponse findByInv(FilterInvWarehouseRequest filterInvWarehouseRequest) { // if (StrUtil.isEmpty(filterInvWarehouseRequest.getPcode()) || filterInvWarehouseRequest.getUserId() == null) { // return ResultVOUtils.error(500, "用户或仓库不能未空!"); // } AuthAdmin authAdmin = customerService.getUserBean(); if (StrUtil.isNotEmpty(filterInvWarehouseRequest.getPcode())) { if (filterInvWarehouseRequest.getFilter() == null || filterInvWarehouseRequest.getFilter() == 1 || filterInvWarehouseRequest.getFilter() == 2) { if (authAdmin.getCustomerId() == 110) { filterInvWarehouseRequest.setUserId(authAdmin.getId().intValue()); } else { filterInvWarehouseRequest.setSpUse(true); } } } else { if (filterInvWarehouseRequest.getFilter() == 3 && filterInvWarehouseRequest.getFilter() != null) { filterInvWarehouseRequest.setUserId(authAdmin.getId().intValue()); } else { //走这边表示单据选择的是往来单位里面调出调入的库 //判断单据类型是1就是设置单据需要需要查询除自己以外的分库 SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("corp_innor_inv"); if (systemParamConfigEntity.getParamValue().equals("0")) { //不允许调拨 // 查询总库信息 InvWarehouseEntity invWarehouseEntity = invWarehouseService.filterGroupInvSubAndcode(filterInvWarehouseRequest.getCode()); //查询仓库信息 if (invWarehouseEntity != null) { DeptEntity deptEntity = deptService.selectByCodeAll(invWarehouseEntity.getParentId()); filterInvWarehouseRequest.setSuperiorCode(deptEntity.getCode()); filterInvWarehouseRequest.setSuperiorPcode(deptEntity.getPcode()); filterInvWarehouseRequest.setCode(null); } else { return ResultVOUtils.error(999, "分库编号为空!"); } } else { //允许调拨 //查询总库信息 InvWarehouseEntity invWarehouseEntity = invWarehouseService.filterGroupInvSubAndcode(filterInvWarehouseRequest.getCode()); filterInvWarehouseRequest.setWarehouseCode(invWarehouseEntity.getParentId()); filterInvWarehouseRequest.setCode(null); } } } List invSubWarehouseEntities = invWarehouseService.filterGroupInvSub(filterInvWarehouseRequest); return ResultVOUtils.success(invSubWarehouseEntities); } @AuthRuleAnnotation("") @GetMapping("spms/sub/inv/warehouse/filterSub") public BaseResponse filterSub(FilterInvWarehouseRequest filterInvWarehouseRequest) { // if (StrUtil.isEmpty(filterInvWarehouseRequest.getPcode()) || filterInvWarehouseRequest.getUserId() == null) { // return ResultVOUtils.error(500, "用户或仓库不能未空!"); // } AuthAdmin authAdmin = customerService.getUserBean(); InvWarehouseEntity invWarehouseEntity = invWarehouseService.filterGroupInvSubAndcode(filterInvWarehouseRequest.getCode()); filterInvWarehouseRequest.setSubordinateCode(invWarehouseEntity.getParentId()); filterInvWarehouseRequest.setCode(null); List invSubWarehouseEntities = invWarehouseService.filterGroupInvSubDown(filterInvWarehouseRequest); return ResultVOUtils.success(invSubWarehouseEntities); } @AuthRuleAnnotation("") @PostMapping("/spms/sub/inv/warehouse/save") public BaseResponse save(@RequestBody @Valid InvWarehouseEntity invWarehouseEntity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } boolean checkResult = invWarehouseService.checkDuplicateName(invWarehouseEntity.getParentId(), invWarehouseEntity.getName()); if (checkResult) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "分库名称重复!"); } FilterInvSubWarehouseRequest filterInvWarehouseRequest = new FilterInvSubWarehouseRequest(); filterInvWarehouseRequest.setParentId(invWarehouseEntity.getParentId()); InvWarehouseEntity codeEntity = invWarehouseService.selectMaxCode(filterInvWarehouseRequest); DeptEntity pEntity = deptService.selectByCode(invWarehouseEntity.getParentId()); if (codeEntity == null) { int code = Integer.parseInt(pEntity.getCode()) * 1000; invWarehouseEntity.setCode(code + ""); } else { invWarehouseEntity.setCode(Integer.parseInt(codeEntity.getCode()) + 1 + ""); } DeptEntity updateEntity = new DeptEntity(); updateEntity.setId(pEntity.getId()); updateEntity.setUpdateTime(new Date()); deptService.updateInvWarehouse(updateEntity); invWarehouseEntity.setId(IdUtil.getSnowflake(6, 1).nextId() + ""); boolean b = invWarehouseService.insertInvSubWarehouse(invWarehouseEntity); if (!b) { return ResultVOUtils.error(ResultEnum.NOT_NETWORK); } return ResultVOUtils.success("添加成功!"); } @AuthRuleAnnotation("") @PostMapping("/spms/sub/inv/warehouse/edit") public BaseResponse edit(@RequestBody @Valid InvWarehouseEntity invWarehouseEntity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } if (invWarehouseEntity.getId() == null) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } boolean b = invWarehouseService.updateInvSubWarehouse(invWarehouseEntity); DeptEntity pEntity = deptService.selectByCode(invWarehouseEntity.getParentId()); pEntity.setUpdateTime(new Date()); deptService.updateInvWarehouse(pEntity); if (!b) { return ResultVOUtils.error(ResultEnum.NOT_NETWORK); } return ResultVOUtils.success("修改成功!"); } @AuthRuleAnnotation("") @PostMapping("/spms/sub/inv/warehouse/delete") public BaseResponse delete(@RequestBody DeleteRequest deleteRequest) { if (deleteRequest.getId() == null) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } InvWarehouseEntity invWarehouseEntity = invWarehouseService.findById(deleteRequest.getId()); //todo 代码未迁移完,记得回来修改 // Integer userCount = warehouseUserService.countUserBySubInvCode(invWarehouseEntity.getCode()); // if (userCount > 0) { // return ResultVOUtils.error(500, "请先移除该仓库关联用户!"); // } // // List warehouseBussinessTypeEntities = warehouseBussinessTypeService.getListByCode(invWarehouseEntity.getCode()); // if (!warehouseBussinessTypeEntities.isEmpty()) { // return ResultVOUtils.error(500, "请先移除该仓库关联用户和单据类型!"); // } // // //判断此分库中是否还有库存 // InvWarehouseEntity invSubWarehouse = invWarehouseService.findById(deleteRequest.getId()); // Integer count = invProductService.countByWarehouseCode(null, invSubWarehouse.getCode()); // if (count > 0) { // return ResultVOUtils.error(500, "此分库存在库存,不能删除!"); // } // // //判断此分库下是否有货位 // List spaceList = invSpaceService.findBySubWarehouseCode(invSubWarehouse.getCode()); // if (CollUtil.isNotEmpty(spaceList)) { // return ResultVOUtils.error(500, "请先移除此分库下的货位!"); // } boolean b = invWarehouseService.deleteById(deleteRequest.getId()); if (!b) { return ResultVOUtils.error(ResultEnum.NOT_NETWORK); } return ResultVOUtils.success(); } @AuthRuleAnnotation("") @GetMapping("/spms/sub/inv/warehouse/thridSys/detail") public BaseResponse getThirdSysDetail(FilterInvSubWarehouseRequest request) { if (null == request || null == request.getId()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } FilterBasicThirdSysRequest sysRequest = new FilterBasicThirdSysRequest(); sysRequest.setEnabled(true); List list = invWarehouseService.getThirdSysDetail(request.getId()); PageInfo pageInfo; pageInfo = new PageInfo<>(list); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(list); return ResultVOUtils.success(pageSimpleResponse); } @AuthRuleAnnotation("") @PostMapping("/spms/sub/inv/warehouse/bindThrWarehouse") public BaseResponse bindThrWarehouse(String id, String thridWarehouseId, String sysId) { if (null == id || null == thridWarehouseId || StrUtil.isBlank(sysId)) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } invWarehouseService.bindThrWarehouse(id, thridWarehouseId, sysId); return ResultVOUtils.success(); } /** * 解绑第三方仓库ID * * @param id * @return */ @AuthRuleAnnotation("") @PostMapping("/spms/sub/inv/warehouse/unbindThrWarehouse") public BaseResponse unbindThrWarehouse(String id, String sysId) { if (null == id || StrUtil.isBlank(sysId)) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } invWarehouseService.unbindThrWarehouse(id, sysId); return ResultVOUtils.success(); } /** * 查询分仓列表 * * @param filterInvWarehouseRequest * @return */ @AuthRuleAnnotation("") @GetMapping("/spms/sub/inv/warehouse/filterSubInvList") public BaseResponse filterSubInvList(FilterInvWarehouseRequest filterInvWarehouseRequest) { List responses = invWarehouseService.filterSubInvList(filterInvWarehouseRequest); return ResultVOUtils.success(responses); } /** * 根据仓位码获取关联用户数据 */ @AuthRuleAnnotation("") @PostMapping("/warehouse/inout/warehouseUserList") public BaseResponse getWarehouseUserList(@RequestBody @Valid FilterInvLinkDataRequest filterInvLinkDataRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } List warehouseUserEntities = warehouseUserService.getWarehouseUserList(filterInvLinkDataRequest); PageInfo pageInfo = new PageInfo<>(warehouseUserEntities); List result = new ArrayList<>(); if (CollUtil.isNotEmpty(pageInfo.getList())) { pageInfo.getList().forEach(warehouseUserEntity -> { WarehouseUserResponse warehouseUserResponse = new WarehouseUserResponse(); BeanUtils.copyProperties(warehouseUserEntity, warehouseUserResponse); warehouseUserResponse.setUserid(warehouseUserEntity.getUserid() + ""); result.add(warehouseUserResponse); }); } PageSimpleResponse response = new PageSimpleResponse<>(); response.setList(result); response.setTotal(pageInfo.getTotal()); return ResultVOUtils.success(response); } }