| | |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.consum.base.util.ExcelStyleUtil; |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import com.consum.base.BaseController; |
| | | import com.consum.base.core.WhBusinessEnum; |
| | | import com.consum.base.core.type.StatesType; |
| | |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | import com.walker.infrastructure.utils.DateUtils; |
| | | import com.walker.web.ResponseValue; |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
| | | import cn.hutool.core.util.ReflectUtil; |
| | |
| | | @ApiOperation(value = "单据新增", notes = "单据新增") |
| | | @ApiImplicitParam(name = "param", value = "单据新增", required = true, dataType = "LWhFormTransferParam") |
| | | @PostMapping("/add") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ResponseValue add() throws Exception { |
| | | LWhFormTransferParam param = CommonUtil.getObjFromReqBody(LWhFormTransferParam.class); |
| | | LWhFormTransferParam param2 = new LWhFormTransferParam(); |
| | |
| | | if (CollectionUtils.isEmpty(transferGoods)) { |
| | | return ResponseValue.error("调拨单不能为空"); |
| | | } |
| | | long id = this.lWhFormTransferService.add(param, this.getSysInfo()); |
| | | long id = this.lWhFormTransferService.add(param, this.getSysInfo(), StrUtil.isEmpty(param.getProcureDoc())); |
| | | if(id == -1L){ |
| | | return ResponseValue.error("您不是库管员"); |
| | | } |
| | | if(id == -2L){ |
| | | return ResponseValue.error("仓库不存在"); |
| | | } |
| | | |
| | | Integer transferBusinessType = param.getTransferBusinessType(); |
| | | // 部门分发业务需要处理 |
| | | if (transferBusinessType == 1) { |
| | | // todo 拆分 新逻辑 |
| | | if (transferBusinessType == 1 && !StrUtil.isEmpty(param.getProcureDoc())) { |
| | | // 先出库,再入库 |
| | | // 出库前 设置出库仓库 |
| | | List<LWhProcureModel> modelByForm = lWhProcureModelService.getModelByForm(WhBusinessEnum.BUMENFENFA, id); |
| | | Set<Long> baseModelIds = |
| | | modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); |
| | | modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); |
| | | |
| | | FinSysTenantUser sysTenantUser = this.getSysInfo(); |
| | | String agencyId = sysTenantUser.getTenantId(); |
| | | List<BaseWarehouse> baseWarehouseList = |
| | | baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); |
| | | baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); |
| | | Set<Long> wareHouseIds = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toSet()); |
| | | // 通过调拨单中的型号id查询出该型号物品所在的仓库位置 |
| | | List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds,null); |
| | | List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds, null); |
| | | GoodsInfoDTO goodsInfoDTO = goodsInfoDTOS.stream().findFirst().orElse(null); |
| | | if (ObjectUtils.isEmpty(goodsInfoDTO)) { |
| | | return ResponseValue.error("该型号没有库存可使用"); |
| | |
| | | lWhFormTransfer.setOutWarehouseId(wareHouseId); |
| | | lWhFormTransfer.setOutWarehouseName(warehouseName); |
| | | lWhFormTransferService.update(lWhFormTransfer); |
| | | lWhFormTransferCoreService.doTransferOutPutNew(id, getCurrentUser(), WhBusinessEnum.BUMENFENFA); |
| | | |
| | | Long l = lWhFormTransferCoreService.doTransferOutPutNew(id, getCurrentUser(), WhBusinessEnum.BUMENFENFA); |
| | | if(l == -1L){ |
| | | return ResponseValue.error("仓库数量不足"); |
| | | } |
| | | lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser(), param.getOperatorName()); |
| | | } |
| | | |
| | | return ResponseValue.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 上传分发单(流程修改) |
| | | * |
| | | * @param idStr 调拨单id json |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "调拨单id", required = true, dataType = "Long"),}) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @PostMapping("import") |
| | | public ResponseValue upload(@RequestBody String idStr) throws Exception { |
| | | Map<String, Object> map = JSONObject.parseObject(idStr, Map.class); |
| | | String type = map.get("type").toString(); |
| | | Long id = Convert.toLong(map.get("idStr")); |
| | | String procureDoc = map.get("procureDoc").toString(); |
| | | // [调拨] |
| | | if ("0".equals(type)) { |
| | | // 修改 |
| | | LWhFormTransfer addLWhFormTransfer = new LWhFormTransfer(); |
| | | addLWhFormTransfer.setId(id); |
| | | addLWhFormTransfer.setProcureDoc(procureDoc); |
| | | int update = lWhFormTransferService.update(addLWhFormTransfer); |
| | | if (update < 1) { |
| | | return ResponseValue.error(); |
| | | } |
| | | return ResponseValue.success(); |
| | | } |
| | | |
| | | // [分发] |
| | | Long opTime = Convert.toLong(map.get("opTime")); |
| | | // 修改表的文件逻辑 |
| | | LWHFromTransferExtendVO lwhFromTransferExtendVO = lWhFormTransferService.getById(id); |
| | | // 修改 |
| | | LWhFormTransfer addLWhFormTransfer = new LWhFormTransfer(); |
| | | addLWhFormTransfer.setId(id); |
| | | addLWhFormTransfer.setProcureDoc(procureDoc); |
| | | addLWhFormTransfer.setInTime(opTime); |
| | | addLWhFormTransfer.setOutputTime(opTime); |
| | | int update = lWhFormTransferService.update(addLWhFormTransfer); |
| | | if (update < 1) { |
| | | return ResponseValue.error(); |
| | | } |
| | | // 主分发逻辑 |
| | | // 先出库,再入库 |
| | | // 出库前 设置出库仓库 |
| | | List<LWhProcureModel> modelByForm = lWhProcureModelService.getModelByForm(WhBusinessEnum.BUMENFENFA, id); |
| | | Set<Long> baseModelIds = |
| | | modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); |
| | | FinSysTenantUser sysTenantUser = this.getSysInfo(); |
| | | String agencyId = sysTenantUser.getTenantId(); |
| | | List<BaseWarehouse> baseWarehouseList = |
| | | baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); |
| | | Set<Long> wareHouseIds = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toSet()); |
| | | // 通过调拨单中的型号id查询出该型号物品所在的仓库位置 |
| | | List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds, null); |
| | | GoodsInfoDTO goodsInfoDTO = goodsInfoDTOS.stream().findFirst().orElse(null); |
| | | if (ObjectUtils.isEmpty(goodsInfoDTO)) { |
| | | return ResponseValue.error("该型号没有库存可使用"); |
| | | } |
| | | Long wareHouseId = goodsInfoDTO.getWarehouseId(); |
| | | String warehouseName = goodsInfoDTO.getWarehouseName(); |
| | | LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(id); |
| | | lWhFormTransfer.setOutWarehouseId(wareHouseId); |
| | | lWhFormTransfer.setOutWarehouseName(warehouseName); |
| | | lWhFormTransferService.update(lWhFormTransfer); |
| | | lWhFormTransferCoreService.doTransferOutPutNew(id, getCurrentUser(), WhBusinessEnum.BUMENFENFA); |
| | | lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser(), lwhFromTransferExtendVO.getOperatorName()); |
| | | return ResponseValue.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @Description 列表查询(调拨明细) |
| | | * @Author 卢庆阳 |
| | | * @Date 2023/10/30 |
| | | * <p> |
| | | * 1.查询调拨单 |
| | | * <p> |
| | | * 2.查询物品型号 |
| | | * <p> |
| | | * 1.查询调拨单 |
| | | * <p> |
| | | * 2.查询物品型号 |
| | | */ |
| | | @ApiOperation(value = "单据列表查询", notes = "单据列表查询") |
| | | @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "int"), |
| | | @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "int"), |
| | | @ApiImplicitParam(name = "param", value = "条件参数", required = true, dataType = "TransferQry"),}) |
| | | @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "int"), |
| | | @ApiImplicitParam(name = "param", value = "条件参数", required = true, dataType = "TransferQry"),}) |
| | | @GetMapping("/list") |
| | | public ResponseValue queryFormTransferList() { |
| | | TransferQry param = CommonUtil.getObjFromReq(TransferQry.class); |
| | |
| | | |
| | | // 查询型号数量 |
| | | List<GoodsTemplateCountVO> goodsTemplateCount = |
| | | lWhProcureModelService.getGoodsTemplateCountByBusinessId(item.getId()); |
| | | lWhProcureModelService.getGoodsTemplateCountByBusinessId(item.getId()); |
| | | formTransferVO.setFromTransferTemplateInfoList(goodsTemplateCount); |
| | | |
| | | result.add(formTransferVO); |
| | |
| | | |
| | | List<LWhProcureModel> modelByForm = lWhProcureModelService.getModelByForm(WhBusinessEnum.DIAOBO, id); |
| | | Set<Long> baseModelIds = |
| | | modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); |
| | | modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); |
| | | |
| | | FinSysTenantUser sysTenantUser = this.getSysInfo(); |
| | | String agencyId = sysTenantUser.getTenantId(); |
| | | List<BaseWarehouse> baseWarehouseList = |
| | | baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); |
| | | baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); |
| | | Set<Long> wareHouseIds = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toSet()); |
| | | |
| | | // 通过调拨单中的型号id查询出该型号物品所在的仓库位置 |
| | | List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds,1); |
| | | List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds, 1); |
| | | GoodsInfoDTO goodsInfoDTO = goodsInfoDTOS.stream().findFirst().orElse(null); |
| | | if (ObjectUtils.isEmpty(goodsInfoDTO)) { |
| | | return ResponseValue.error("该型号没有库存可使用"); |
| | |
| | | |
| | | @ApiOperation(value = "调拨单导出", notes = "调拨单导出") |
| | | @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "调拨单id", required = true, dataType = "Long"), |
| | | @ApiImplicitParam(name = "type", value = "导出类型 1 入库 2 出库", required = true, dataType = "Integer"),}) |
| | | @ApiImplicitParam(name = "type", value = "导出类型 1 入库 2 出库", required = true, dataType = "Integer"),}) |
| | | @GetMapping("/list/export") |
| | | public ResponseValue<String> export(Long id, Integer type, HttpServletResponse response) throws Exception { |
| | | |
| | | TemplateExportParams params; |
| | | String fileName; |
| | | if (type == 1) { |
| | | if (type == 0) { |
| | | params = new TemplateExportParams("import/调拨入库单.xls"); |
| | | fileName = "调拨入库单"; |
| | | }else if (type == 1) { |
| | | params = new TemplateExportParams("import/调拨入库单1.xls"); |
| | | fileName = "调拨入库单"; |
| | | } else { |
| | | params = new TemplateExportParams("import/调拨出库单.xls"); |
| | | fileName = "调拨出库单"; |
| | | } |
| | | params.setHeadingStartRow(2); |
| | | params.setStyle(ExcelStyleUtil.class); |
| | | List<TransferExcelTemplate> export = this.lWhFormTransferService.export(id, type); |
| | | |
| | | int countNum = |
| | | export.stream().filter(item -> item.getNum() != null).mapToInt(TransferExcelTemplate::getNum).sum(); |
| | | export.stream().filter(item -> item.getNum() != null).mapToInt(TransferExcelTemplate::getNum).sum(); |
| | | double totalAmount = export.stream().filter(item -> item.getTotalAmount() != null) |
| | | .mapToDouble(TransferExcelTemplate::getAmount).sum(); |
| | | .mapToDouble(TransferExcelTemplate::getAmount).sum(); |
| | | Optional<TransferExcelTemplate> first = export.stream().findFirst(); |
| | | TransferExcelTemplate entity = first.get(); |
| | | String businessFormCode = entity.getBusinessFormCode(); |
| | |
| | | param.setOutAgencyId(Long.valueOf(tenantId)); |
| | | } |
| | | GenericPager<Map<String, Object>> transferInfoDetailsVoGenericPager = |
| | | this.lWhFormTransferService.queryTransferInfo(param); |
| | | this.lWhFormTransferService.queryTransferInfo(param); |
| | | return ResponseValue.success(transferInfoDetailsVoGenericPager); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | Map<Long, List<ProcureModelInfoParam>> collect = param.getRecordInfoList().stream() |
| | | .collect(Collectors.groupingBy(ProcureModelInfoParam::getBaseGoodModelId)); |
| | | .collect(Collectors.groupingBy(ProcureModelInfoParam::getBaseGoodModelId)); |
| | | for (Map.Entry<Long, List<ProcureModelInfoParam>> entry : collect.entrySet()) { |
| | | Long baseGoodModelId = entry.getKey(); |
| | | |
| | |
| | | // 设置一下在用数量 |
| | | Long oldProcureModelId = item.getOldProcureModelId(); |
| | | LWhProcureModelUser oldInfo = |
| | | lWhProcureModelUserService.get(new LWhProcureModelUser(oldProcureModelId)); |
| | | lWhProcureModelUserService.get(new LWhProcureModelUser(oldProcureModelId)); |
| | | lWhProcureModelUser.setUseCount(oldInfo.getUseCount()); |
| | | procureModelUserList.add(lWhProcureModelUser); |
| | | } |
| | |
| | | } |
| | | |
| | | List<GoodsUseRecordVO> goodsUseRecordList = useRecordDTOList.stream() |
| | | .collect(Collectors.groupingBy(UseRecordDTO::getId)).entrySet().stream().map(entry -> { |
| | | Long id = entry.getKey(); |
| | | List<UseRecordDTO> useRecordList = entry.getValue(); |
| | | UseRecordDTO useRecordDto = useRecordList.get(0); |
| | | .collect(Collectors.groupingBy(UseRecordDTO::getId)).entrySet().stream().map(entry -> { |
| | | Long id = entry.getKey(); |
| | | List<UseRecordDTO> useRecordList = entry.getValue(); |
| | | UseRecordDTO useRecordDto = useRecordList.get(0); |
| | | |
| | | GoodsUseRecordVO goodsUseRecordVO = new GoodsUseRecordVO(); |
| | | goodsUseRecordVO.setId(id); |
| | | goodsUseRecordVO.setUpdateUserName(useRecordDto.getUpdateUserName()); |
| | | goodsUseRecordVO.setUpdateTime(useRecordDto.getUpdateTime()); |
| | | GoodsUseRecordVO goodsUseRecordVO = new GoodsUseRecordVO(); |
| | | goodsUseRecordVO.setId(id); |
| | | goodsUseRecordVO.setUpdateUserName(useRecordDto.getUpdateUserName()); |
| | | goodsUseRecordVO.setUpdateTime(useRecordDto.getUpdateTime()); |
| | | |
| | | List<UseRecordSkuVO> useRecordSkuList = |
| | | useRecordList.stream().collect(Collectors.groupingBy(UseRecordDTO::getProcureModelId)).values() |
| | | .stream().map(recordList -> { |
| | | UseRecordDTO useRecordDTO = recordList.get(0); |
| | | UseRecordSkuVO useRecordSkuVO = new UseRecordSkuVO(); |
| | | useRecordSkuVO.setBaseGoodModelId(useRecordDTO.getBaseGoodsModelsId()); |
| | | useRecordSkuVO.setBaseGoodModelName(useRecordDTO.getBaseGoodsModelsName()); |
| | | useRecordSkuVO.setUnit(useRecordDTO.getUnit()); |
| | | useRecordSkuVO.setProcureModelId(useRecordDTO.getProcureModelId()); |
| | | List<UseRecordSkuVO> useRecordSkuList = |
| | | useRecordList.stream().collect(Collectors.groupingBy(UseRecordDTO::getProcureModelId)).values() |
| | | .stream().map(recordList -> { |
| | | UseRecordDTO useRecordDTO = recordList.get(0); |
| | | UseRecordSkuVO useRecordSkuVO = new UseRecordSkuVO(); |
| | | useRecordSkuVO.setBaseGoodModelId(useRecordDTO.getBaseGoodsModelsId()); |
| | | useRecordSkuVO.setBaseGoodModelName(useRecordDTO.getBaseGoodsModelsName()); |
| | | useRecordSkuVO.setUnit(useRecordDTO.getUnit()); |
| | | useRecordSkuVO.setProcureModelId(useRecordDTO.getProcureModelId()); |
| | | |
| | | List<RecordUserInfoVO> recordUserInfoList = recordList.stream().map(userInfo -> { |
| | | RecordUserInfoVO recordUserInfoVO = new RecordUserInfoVO(); |
| | | recordUserInfoVO.setOldProcureModelId(userInfo.getOldProcureModelId()); |
| | | recordUserInfoVO.setUseName(userInfo.getUseName()); |
| | | recordUserInfoVO.setPhone(userInfo.getPhone()); |
| | | recordUserInfoVO.setNum(userInfo.getNum()); |
| | | return recordUserInfoVO; |
| | | }).collect(Collectors.toList()); |
| | | List<RecordUserInfoVO> recordUserInfoList = recordList.stream().map(userInfo -> { |
| | | RecordUserInfoVO recordUserInfoVO = new RecordUserInfoVO(); |
| | | recordUserInfoVO.setOldProcureModelId(userInfo.getOldProcureModelId()); |
| | | recordUserInfoVO.setUseName(userInfo.getUseName()); |
| | | recordUserInfoVO.setPhone(userInfo.getPhone()); |
| | | recordUserInfoVO.setNum(userInfo.getNum()); |
| | | return recordUserInfoVO; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | useRecordSkuVO.setRecordUserInfos(recordUserInfoList); |
| | | return useRecordSkuVO; |
| | | }).collect(Collectors.toList()); |
| | | useRecordSkuVO.setRecordUserInfos(recordUserInfoList); |
| | | return useRecordSkuVO; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | goodsUseRecordVO.setRecordSkuDtoList(useRecordSkuList); |
| | | return goodsUseRecordVO; |
| | | goodsUseRecordVO.setRecordSkuDtoList(useRecordSkuList); |
| | | return goodsUseRecordVO; |
| | | |
| | | }).sorted(Comparator.comparing(GoodsUseRecordVO::getUpdateTime, Comparator.nullsFirst(Long::compareTo)) |
| | | .reversed()) |
| | | .collect(Collectors.toList()); |
| | | }).sorted(Comparator.comparing(GoodsUseRecordVO::getUpdateTime, Comparator.nullsFirst(Long::compareTo)) |
| | | .reversed()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return ResponseValue.success(goodsUseRecordList); |
| | | } |
| | | |
| | | @ApiOperation(value = "查询部门下的分发单", notes = "查询部门下的分发单") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "agencyId", value = "机构id", required = true, dataType = "Long", paramType = "query")}) |
| | | @ApiImplicitParam(name = "agencyId", value = "机构id", required = true, dataType = "Long", paramType = "query")}) |
| | | @GetMapping("/query/transfList") |
| | | public ResponseValue queryDepartmentTransferOrderList() { |
| | | |