| | |
| | | package com.consum.base.service.impl; |
| | | |
| | | import static com.walker.db.Sorts.DESC; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import com.consum.base.core.CodeGeneratorEnum; |
| | | import com.consum.base.core.CodeGeneratorService; |
| | | import com.consum.base.core.type.CategoryType; |
| | | import com.consum.base.core.type.StatesType; |
| | | import com.consum.base.core.type.TransferBusinessType; |
| | | import com.consum.base.core.type.TransferStatesType; |
| | | import com.consum.base.core.type.WareHouseType; |
| | | import com.consum.base.core.utils.CurrencyUtil; |
| | | import com.consum.base.core.utils.IdUtil; |
| | | import com.consum.base.core.utils.MapUtils; |
| | |
| | | import com.consum.base.pojo.response.LWHFromTransferExtendVO; |
| | | import com.consum.base.service.BaseWarehouseManagerService; |
| | | import com.consum.base.service.BaseWarehouseService; |
| | | import com.consum.base.service.FinSysTenantServiceImpl; |
| | | import com.consum.base.service.FinSysTenantService; |
| | | import com.consum.base.service.LWhFormTransferService; |
| | | import com.consum.base.service.LWhGoodsService; |
| | | import com.consum.base.service.LWhProcureModelService; |
| | |
| | | @Autowired |
| | | private CodeGeneratorService codeGeneratorService; |
| | | @Autowired |
| | | private FinSysTenantServiceImpl finSysTenantService; |
| | | private FinSysTenantService finSysTenantService; |
| | | @Autowired |
| | | private LWhGoodsService lWhGoodsService; |
| | | @Autowired |
| | |
| | | * @Author 卢庆阳 |
| | | * @Date 2023/10/30 |
| | | */ |
| | | public long add(LWhFormTransferParam param, FinSysTenantUser sysInfo) throws Exception { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public long add(LWhFormTransferParam param, FinSysTenantUser sysInfo,boolean isHaveDoc) throws Exception { |
| | | // 1.新增调拨单记录 |
| | | LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(); |
| | | // 调拨单id |
| | |
| | | |
| | | lWhFormTransfer.setBusinessFormCode(codeGeneratorService.createBusinessFormCode(codeGeneratorEnum)); |
| | | |
| | | Long warehouseId = param.getInWarehouseId(); |
| | | // 调拨类型单据 |
| | | if (businessType == TransferBusinessType.STOCK_TRANSFER.getValue()) { |
| | | // 入库仓库为当前用户的默认仓库 |
| | | // 入库仓库为当前用户的默认仓库中的第一个 |
| | | String tenantId = sysInfo.getTenantId(); |
| | | String tenantName = sysInfo.getTenantName(); |
| | | BaseWarehouse warehouse = baseWarehouseService.getDefaultWarehouseByAgencyId(Long.valueOf(tenantId)); |
| | | BaseWarehouse warehouse = baseWarehouseService.getWarehouseByAgencyId(Long.valueOf(tenantId), null); |
| | | if (warehouse == null) { |
| | | log.error("仓库不存在"); |
| | | throw new Exception("仓库不存在"); |
| | | //throw new Exception("仓库不存在"); |
| | | return -2L; |
| | | } |
| | | lWhFormTransfer.setInWarehouseId(warehouse.getId()); |
| | | lWhFormTransfer.setInWarehouseName(warehouse.getWarehouseName()); |
| | |
| | | List<BaseWarehouseManager> managerList = baseWarehouseManagerService.select(manager); |
| | | if (CollectionUtils.isEmpty(managerList)) { |
| | | log.error("该用户不是库管员"); |
| | | throw new Exception("该用户不是库管员"); |
| | | //throw new Exception("该用户不是库管员"); |
| | | return -1L; |
| | | } |
| | | BaseWarehouseManager baseWarehouseManager = managerList.stream().findFirst().orElse(null); |
| | | Long baseWarehouseId = baseWarehouseManager.getBaseWarehouseId(); |
| | |
| | | baseWarehouse.setId(baseWarehouseId); |
| | | BaseWarehouse warehouse = baseWarehouseService.get(baseWarehouse); |
| | | |
| | | lWhFormTransfer.setInWarehouseType(1); |
| | | lWhFormTransfer.setInWarehouseType(WareHouseType.DEPARTMENT.getValue()); |
| | | lWhFormTransfer.setInWarehouseId(param.getDepartmentId()); |
| | | lWhFormTransfer.setInWarehouseName(param.getDepartmentName()); |
| | | lWhFormTransfer.setInOperatorName(param.getOperatorName()); |
| | | lWhFormTransfer.setInTime(param.getCreateTime()); |
| | | |
| | | lWhFormTransfer.setOutWarehouseType(0); |
| | | if(!isHaveDoc){ |
| | | lWhFormTransfer.setInTime(param.getCreateTime()); |
| | | } |
| | | |
| | | |
| | | lWhFormTransfer.setOutWarehouseType(WareHouseType.TENANT.getValue()); |
| | | lWhFormTransfer.setOutWarehouseId(warehouse.getId()); |
| | | lWhFormTransfer.setOutWarehouseName(warehouse.getWarehouseName()); |
| | | |
| | | lWhFormTransfer.setOutOperatorId(sysInfo.getId()); |
| | | lWhFormTransfer.setOutOperatorName(sysInfo.getUserName()); |
| | | lWhFormTransfer.setOutputTime(param.getCreateTime()); |
| | | |
| | | if(!isHaveDoc) { |
| | | lWhFormTransfer.setOutputTime(param.getCreateTime()); |
| | | } |
| | | lWhFormTransfer.setTel(param.getTel()); |
| | | |
| | | } |
| | |
| | | FinSysTenant finSysTenant = finSysTenantService.get(new FinSysTenant(param.getOutAgencyId())); |
| | | if (finSysTenant == null) { |
| | | log.error("调拨机构不存在"); |
| | | throw new Exception("调拨机构不存在"); |
| | | } |
| | | lWhFormTransfer.setOutAgencyId(finSysTenant.getId()); |
| | | Long outAgencyId = finSysTenant.getId(); |
| | | lWhFormTransfer.setOutAgencyId(outAgencyId); |
| | | lWhFormTransfer.setOutAgencyName(finSysTenant.getName()); |
| | | lWhFormTransfer.setOperatorId(sysInfo.getId()); |
| | | lWhFormTransfer.setOperatorName(sysInfo.getUserName()); |
| | | lWhFormTransfer.setCreateTime(param.getCreateTime()); |
| | | // 0=待出库;1=待接收;2=已入库库:4=已撤销 |
| | | lWhFormTransfer.setStates(0); |
| | | lWhFormTransfer.setStates(TransferStatesType.OUT_PENDING.getValue()); |
| | | lWhFormTransfer.setProcureDoc(param.getProcureDoc()); |
| | | |
| | | int flag1 = this.insert(lWhFormTransfer); |
| | |
| | | if (businessType == TransferBusinessType.STOCK_TRANSFER.getValue()) { |
| | | lWhProcureModel.setBusinessType(2); |
| | | // 根据物品型号查询物品库存 |
| | | int goodsNum = lWhGoodsService.queryGoodsModelNum(0, warehouseId, baseGoodsModelsId, 1, null); |
| | | // 调拨申请时没有仓库id 查询上级机构的所有仓库 |
| | | List<BaseWarehouse> baseWareHouseList = |
| | | baseWarehouseService.getBaseWareHouseList(outAgencyId, StatesType.NORMAL.getValue()); |
| | | List<Long> warehouseIdList = |
| | | baseWareHouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toList()); |
| | | int goodsNum = lWhGoodsService.queryGoodsModelNum(WareHouseType.TENANT.getValue(), warehouseIdList, |
| | | baseGoodsModelsId, 1, null); |
| | | lWhProcureModel.setWorehouseCount(goodsNum); |
| | | } |
| | | if (businessType == TransferBusinessType.DEPARTMENT_PROCURE.getValue()) { |
| | |
| | | paramts.put("goodsTemplateName", |
| | | StringUtils.CHAR_PERCENT + param.getGoodsTemplateName() + StringUtils.CHAR_PERCENT); |
| | | } |
| | | // 物品id |
| | | if (param.getGoodsTemplateId() != null) { |
| | | sql.append("AND bgt.id = :goodsTemplateId "); |
| | | paramts.put("goodsTemplateId", param.getGoodsTemplateId()); |
| | | } |
| | | // 调拨机构 |
| | | if (param.getOutAgencyId() != null) { |
| | | sql.append(" and OUT_AGENCY_ID = :OUT_AGENCY_ID "); |
| | |
| | | paramts.put("inTimeEnd", param.getEndTime() * 1000000 + 240000); |
| | | } |
| | | // 分发部门 |
| | | if (param.getInWarehouseId() != null) { |
| | | if (param.getDepartmentId() != null) { |
| | | sql.append("and ft.IN_WAREHOUSE_ID = :inWarehouseId "); |
| | | paramts.put("inWarehouseId", param.getInWarehouseId()); |
| | | paramts.put("inWarehouseId", param.getDepartmentId()); |
| | | } |
| | | |
| | | sql.append(" ORDER BY ft.CREATE_TIME DESC"); |
| | |
| | | && CategoryType.TYPE_A.getValue().equals(type)) { |
| | | Long procureModelId = goodsModelVO.getId(); |
| | | |
| | | LWhProcureModelUserRecord lWhProcureModelUserRecord = new LWhProcureModelUserRecord(); |
| | | lWhProcureModelUserRecord.setTransBusinessId(id); |
| | | List<LWhProcureModelUserRecord> select = lWhProcureModelUserRecordService |
| | | .select(lWhProcureModelUserRecord, DESC().setField("DEAL_TIME")); |
| | | LWhProcureModelUserRecord record = select.stream().findFirst().orElse(null); |
| | | LWhProcureModelUser lWhProcureModelUser = new LWhProcureModelUser(); |
| | | lWhProcureModelUser.setWhProcureModelId(procureModelId); |
| | | lWhProcureModelUser.setProcureModelUserRecordId(record.getId()); |
| | | List<LWhProcureModelUser> procureModelUserList = |
| | | this.lWhProcureModelUserService.select(lWhProcureModelUser); |
| | | |
| | |
| | | goodsTemplateInfoList.add(goodsTemplateInfoVO); |
| | | } |
| | | result.setFormTransferGoods(goodsTemplateInfoList); |
| | | |
| | | // String sql = "SELECT bgt.id, CATEGORY_ID, CATEGORY_NAME, GOODS_NAME,bgt.CLASSIFICATION type " |
| | | // + "FROM l_wh_procure_model pm LEFT JOIN base_goods_models bgm ON bgm.id = pm.BASE_GOODS_MODELS_ID " |
| | | // + "LEFT JOIN base_goods_template bgt ON bgt.id = bgm.GOODS_TEMPLATES_ID " |
| | | // + "WHERE pm.BUSINESS_ID =:id GROUP BY bgt.id "; |
| | | // Map<String, Object> paramMap = new HashMap<>(); |
| | | // paramMap.put("id", result.getId()); |
| | | // List<Map<String, Object>> procureModelList = this.select(sql, paramMap, new MapperUtil()); |
| | | // |
| | | // String queryRecord = |
| | | // "SELECT * FROM l_wh_procure_model_user_record where TRANS_BUSINESS_ID = :id order by DEAL_TIME desc limit 1"; |
| | | // LWhProcureModelUserRecord lWhProcureModelUserRecord = |
| | | // lWhProcureModelUserRecordService.get(queryRecord, paramMap, new LWhProcureModelUserRecord()); |
| | | // List<FormTransferGoodsVO> formTransferGoods = Lists.newArrayList(); |
| | | // for (Map<String, Object> map : procureModelList) { |
| | | // FormTransferGoodsVO procureTemplateInfoVO = MapUtils.convertMapToObj(map, FormTransferGoodsVO.class); |
| | | // Long baseGoodsTemplateId = procureTemplateInfoVO.getId(); |
| | | // // 查询型号数量 |
| | | // List<GoodsModelVO> goodsModelVOList = Lists.newArrayList(); |
| | | // String sql2 = "SELECT pm.id,pm.BASE_GOODS_MODELS_NAME,bgm.UNIT,COUNTS,total_amount " |
| | | // + "FROM l_wh_procure_model pm LEFT JOIN base_goods_models bgm ON bgm.id = pm.BASE_GOODS_MODELS_ID " |
| | | // + "LEFT JOIN base_goods_template bgt ON bgt.id = bgm.GOODS_TEMPLATES_ID " |
| | | // + "WHERE pm.BUSINESS_ID =:id and bgt.id =:baseGoodsTemplateId"; |
| | | // Map<String, Object> goodsModelParamMap = new HashMap<>(); |
| | | // goodsModelParamMap.put("id", result.getId()); |
| | | // goodsModelParamMap.put("baseGoodsTemplateId", baseGoodsTemplateId); |
| | | // List<Map<String, Object>> modelList = this.select(sql2, goodsModelParamMap, new MapperUtil()); |
| | | // modelList.forEach(item -> { |
| | | // GoodsModelVO goodsModelVO = MapUtils.convertMapToObj(item, GoodsModelVO.class); |
| | | // Integer businessType = result.getBusinessType(); |
| | | // String type = procureTemplateInfoVO.getType(); |
| | | // // 部门分发需要查询使用信息 |
| | | // if (businessType == 1 && "A".equals(type)) { |
| | | // Long procureModelId = goodsModelVO.getId(); |
| | | // LWhProcureModelUser lWhProcureModelUser = new LWhProcureModelUser(); |
| | | // lWhProcureModelUser.setWhProcureModelId(procureModelId); |
| | | // lWhProcureModelUser.setProcureModelUserRecordId(lWhProcureModelUserRecord.getId()); |
| | | // List<LWhProcureModelUser> procureModelUserList = |
| | | // this.lWhProcureModelUserService.select(lWhProcureModelUser); |
| | | // if (!CollectionUtils.isEmpty(procureModelUserList)) { |
| | | // List<DepartGoodsUseInfo> departGoodsUseInfoList = Lists.newArrayList(); |
| | | // procureModelUserList.forEach(useInfo -> { |
| | | // Integer goodsNum = useInfo.getGoodsNum(); |
| | | // Long nowUserPhone = useInfo.getNowUserPhone(); |
| | | // String nowUserName = useInfo.getNowUserName(); |
| | | // DepartGoodsUseInfo departGoodsUseInfo = new DepartGoodsUseInfo(); |
| | | // departGoodsUseInfo.setName(nowUserName); |
| | | // departGoodsUseInfo.setNum(goodsNum); |
| | | // departGoodsUseInfo.setTel(nowUserPhone); |
| | | // departGoodsUseInfoList.add(departGoodsUseInfo); |
| | | // }); |
| | | // goodsModelVO.setUseInfo(departGoodsUseInfoList); |
| | | // } |
| | | // |
| | | // } |
| | | // goodsModelVOList.add(goodsModelVO); |
| | | // procureTemplateInfoVO.setModels(goodsModelVOList); |
| | | // }); |
| | | // formTransferGoods.add(procureTemplateInfoVO); |
| | | // } |
| | | // result.setFormTransferGoods(formTransferGoods); |
| | | |
| | | return result; |
| | | } |
| | |
| | | */ |
| | | public int updateStatus(Long id) { |
| | | LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(id); |
| | | lWhFormTransfer.setStates(4); |
| | | lWhFormTransfer.setStates(TransferStatesType.CANCEL.getValue()); |
| | | return this.update(lWhFormTransfer); |
| | | } |
| | | |
| | |
| | | paramts.put("goodsName", |
| | | StringUtils.CHAR_PERCENT + transferQry.getGoodsTemplateName() + StringUtils.CHAR_PERCENT); |
| | | } |
| | | // 物品id |
| | | if (transferQry.getGoodsTemplateId() != null) { |
| | | sql.append("AND bgt.id =:goodsTemplateId "); |
| | | paramts.put("goodsTemplateId", transferQry.getGoodsTemplateId()); |
| | | } |
| | | // 规格型号 |
| | | if (transferQry.getBaseGoodsModelsId() != null) { |
| | | sql.append("AND bgm.id =:goodsModelId "); |
| | |
| | | } |
| | | // 调拨机构 |
| | | if (transferQry.getOutAgencyId() != null) { |
| | | sql.append("AND OUT_AGENCY_ID = :OUT_AGENCY_ID "); |
| | | paramts.put("OUT_AGENCY_ID", transferQry.getOutAgencyId()); |
| | | sql.append("AND OUT_AGENCY_ID like :OUT_AGENCY_ID "); |
| | | paramts.put("OUT_AGENCY_ID", transferQry.getOutAgencyId() + StringUtils.CHAR_PERCENT); |
| | | } |
| | | // 分发部门 |
| | | if (transferQry.getInWarehouseId() != null) { |
| | | if (transferQry.getDepartmentId() != null) { |
| | | sql.append("and ft.IN_WAREHOUSE_ID = :inWarehouseId "); |
| | | paramts.put("inWarehouseId", transferQry.getInWarehouseId()); |
| | | paramts.put("inWarehouseId", transferQry.getDepartmentId()); |
| | | } |
| | | // 创建人 |
| | | if (StringUtils.isNotEmpty(transferQry.getOperatorName())) { |
| | |
| | | sql.append("AND bgt.GOODS_NAME like :goodsName "); |
| | | params.put("goodsName", StringUtils.CHAR_PERCENT + param.getGoodsTemplateName() + StringUtils.CHAR_PERCENT); |
| | | } |
| | | if (param.getGoodsTemplateId() != null) { |
| | | sql.append("AND bgt.id = :goodsTemplateId "); |
| | | params.put("goodsTemplateId", param.getGoodsTemplateId()); |
| | | } |
| | | if (param.getBaseGoodsModelsId() != null) { |
| | | sql.append("AND bgm.id = :goodsModelId "); |
| | | params.put("goodsModelId", param.getBaseGoodsModelsId()); |
| | | } |
| | | if (param.getOutAgencyId() != null) { |
| | | sql.append("AND ft.OUT_AGENCY_ID like :outAgencyId "); |
| | | params.put("outAgencyId", param.getOutAgencyId()); |
| | | params.put("outAgencyId", param.getOutAgencyId() + StringUtils.CHAR_PERCENT); |
| | | } |
| | | if (param.getOutAgencyId() != null) { |
| | | if (param.getInAgencyId() != null) { |
| | | sql.append("AND ft.IN_AGENCY_ID like :inAgencyId "); |
| | | params.put("inAgencyId", param.getInAgencyId()); |
| | | params.put("inAgencyId", param.getInAgencyId() + StringUtils.CHAR_PERCENT); |
| | | } |
| | | if (StringUtils.isNotEmpty(param.getOperatorName())) { |
| | | sql.append("AND ft.OPERATOR_NAME = :operatorName "); |