| | |
| | | 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); |
| | |
| | | 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 列表查询(调拨明细) |
| | |
| | | |
| | | 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 = |