| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.annotation.Java110Cmd; |
| | | import com.java110.core.annotation.Java110Transactional; |
| | | import com.java110.core.context.ICmdDataFlowContext; |
| | | import com.java110.core.event.cmd.Cmd; |
| | | import com.java110.core.event.cmd.CmdEvent; |
| | | import com.java110.core.factory.CommunitySettingFactory; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.allocationStorehouse.AllocationStorehouseDto; |
| | | import com.java110.dto.allocationStorehouseApply.AllocationStorehouseApplyDto; |
| | | import com.java110.dto.allocationStorehouse.AllocationStorehouseApplyDto; |
| | | import com.java110.dto.purchaseApply.PurchaseApplyDto; |
| | | import com.java110.dto.resourceStore.ResourceStoreDto; |
| | | import com.java110.dto.user.UserDto; |
| | | import com.java110.intf.store.*; |
| | | import com.java110.intf.user.IUserV1InnerServiceSMO; |
| | | import com.java110.po.purchase.PurchaseApplyDetailPo; |
| | | import com.java110.po.purchase.PurchaseApplyPo; |
| | | import com.java110.po.purchase.ResourceStorePo; |
| | | import com.java110.po.resourceStoreTimes.ResourceStoreTimesPo; |
| | | import com.java110.store.bmo.purchase.IPurchaseApplyBMO; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.utils.exception.CmdException; |
| | |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import com.java110.utils.util.DateUtil; |
| | | import com.java110.utils.util.StringUtil; |
| | | import com.java110.vo.ResultVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | |
| | | @Autowired |
| | | private IPurchaseApplyBMO purchaseApplyBMOImpl; |
| | | |
| | | @Autowired |
| | | private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IResourceStoreTimesV1InnerServiceSMO resourceStoreTimesV1InnerServiceSMOImpl; |
| | | |
| | | @Override |
| | | public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { |
| | | Assert.hasKeyAndValue(reqJson, "resourceStores", "必填,请填写申请采购的物资"); |
| | |
| | | Assert.hasKeyAndValue(reqJson, "resOrderType", "必填,请填写申请类型"); |
| | | } |
| | | |
| | | /** |
| | | * 紧急采购-仓库物品入库 |
| | | * @param event 事件对象 |
| | | * @param context 数据上文对象 |
| | | * @param reqJson 请求报文 |
| | | * @throws CmdException |
| | | */ |
| | | @Override |
| | | @Java110Transactional |
| | | public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { |
| | | String userId = context.getReqHeaders().get("user-id"); |
| | | String userName = context.getReqHeaders().get("user-name"); |
| | | UserDto userDto = new UserDto(); |
| | | userDto.setUserId(userId); |
| | | userDto.setRow(1); |
| | | userDto.setPage(1); |
| | | List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto); |
| | | |
| | | Assert.listOnlyOne(userDtos,"用户不存在"); |
| | | |
| | | userName = userDtos.get(0).getName(); |
| | | |
| | | String storeId = context.getReqHeaders().get("store-id"); |
| | | PurchaseApplyDto purchaseApplyDto = new PurchaseApplyDto(); |
| | | purchaseApplyDto.setResOrderType(reqJson.getString("resOrderType")); |
| | |
| | | //查询当月紧急采购的次数 |
| | | int count = purchaseApplyInnerServiceSMOImpl.queryPurchaseApplysCount(purchaseApplyDto); |
| | | //取出开关映射的值 |
| | | String value = MappingCache.getValue(DOMAIN_COMMON, URGRNT_NUMBER); |
| | | String value = CommunitySettingFactory.getValue(purchaseApplyDto.getCommunityId(), URGRNT_NUMBER); |
| | | if (StringUtil.isEmpty(value)) { |
| | | value = MappingCache.getValue(DOMAIN_COMMON, URGRNT_NUMBER); |
| | | } |
| | | if (StringUtil.isEmpty(value)) { |
| | | throw new IllegalArgumentException("映射值为空!"); |
| | | } |
| | | int number = Integer.parseInt(value); |
| | | if (count >= number) { |
| | | throw new IllegalArgumentException("本月紧急采购次数已超过" + number + "次,请下月再使用!"); |
| | | ResponseEntity<String> responseEntity = ResultVo.createResponseEntity(ResultVo.CODE_BUSINESS_VERIFICATION, "本月紧急采购次数已超过" + number + "次,请下月再使用!"); |
| | | context.setResponseEntity(responseEntity); |
| | | return; |
| | | } |
| | | PurchaseApplyPo purchaseApplyPo = new PurchaseApplyPo(); |
| | | purchaseApplyPo.setApplyOrderId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_applyOrderId)); |
| | |
| | | resourceStorePo.setResOrderType(PurchaseApplyDto.WAREHOUSING_TYPE_URGENT); |
| | | resourceStorePo.setOperationType(PurchaseApplyDto.WEIGHTED_MEAN_TRUE); |
| | | resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo); |
| | | if (resourceStoreDtos != null && resourceStoreDtos.size() == 1) { |
| | | //生成调拨记录 |
| | | AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto(); |
| | | // 保存至 物品 times表 (调整原仓库 批次) |
| | | ResourceStoreTimesPo resourceStoreTimesPo1 = new ResourceStoreTimesPo(); |
| | | resourceStoreTimesPo1.setApplyOrderId(purchaseApplyPo.getApplyOrderId()); |
| | | resourceStoreTimesPo1.setPrice(purchaseApplyDetailPo.getPrice());//采购价 |
| | | resourceStoreTimesPo1.setResCode(resourceStore.getString("resCode")); |
| | | resourceStoreTimesPo1.setStock("0"); |
| | | resourceStoreTimesPo1.setStoreId(storeId); |
| | | resourceStoreTimesPo1.setShId(resourceStore.getString("shId")); |
| | | resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo1); |
| | | |
| | | AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto(); |
| | | |
| | | if (resourceStoreDtos != null && resourceStoreDtos.size() == 1) {//目标仓库有此物品 |
| | | //生成调拨详情记录 |
| | | allocationStorehouseDto.setAsId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_allocationStorehouseId)); |
| | | allocationStorehouseDto.setbId("-1"); |
| | | allocationStorehouseDto.setShIda(resourceStore.getString("shId")); |
| | | allocationStorehouseDto.setShIdz(resourceStore.getString("shzId"));//小区仓库 |
| | | allocationStorehouseDto.setShIda(resourceStore.getString("shId"));//原仓库 |
| | | allocationStorehouseDto.setShIdz(resourceStore.getString("shzId"));//目标仓库 |
| | | allocationStorehouseDto.setResId(resourceStoreDtos.get(0).getResId()); |
| | | allocationStorehouseDto.setResName(resourceStoreDtos.get(0).getResName()); |
| | | allocationStorehouseDto.setStoreId(storeId); |
| | |
| | | BigDecimal newMiniStock = purchaseQuantity.multiply(miniUnitStock).add(miniStock); |
| | | resourceStorePo1.setMiniStock(String.valueOf(newMiniStock)); |
| | | resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo1); |
| | | |
| | | |
| | | } else if (resourceStoreDtos != null && resourceStoreDtos.size() > 1) { |
| | | throw new IllegalArgumentException("查询商品错误!"); |
| | | } else { |
| | | //生成调拨记录 |
| | | AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto(); |
| | | allocationStorehouseDto.setAsId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_allocationStorehouseId)); |
| | | allocationStorehouseDto.setbId("-1"); |
| | | allocationStorehouseDto.setShIda(resourceStore.getString("shId")); |
| | |
| | | resourceStoreDto1.setMiniStock(String.valueOf(miniStock)); |
| | | resourceStoreInnerServiceSMOImpl.saveResourceStore(resourceStoreDto1); |
| | | } |
| | | // 保存至 物品 times表 (调整目标仓库 批次) |
| | | ResourceStoreTimesPo resourceStoreTimesPo = new ResourceStoreTimesPo(); |
| | | resourceStoreTimesPo.setApplyOrderId(allocationStorehouseDto.getApplyId()); |
| | | resourceStoreTimesPo.setPrice(purchaseApplyDetailPo.getPrice()); |
| | | resourceStoreTimesPo.setResCode(resourceStore.getString("resCode")); |
| | | resourceStoreTimesPo.setStock(purchaseApplyDetailPo.getQuantity()); |
| | | resourceStoreTimesPo.setStoreId(storeId); |
| | | resourceStoreTimesPo.setShId(resourceStore.getString("shzId")); |
| | | resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo); |
| | | } |
| | | purchaseApplyPo.setPurchaseApplyDetailPos(purchaseApplyDetailPos); |
| | | ResponseEntity responseEntity = purchaseApplyBMOImpl.apply(purchaseApplyPo, reqJson); |