| | |
| | | import com.ruoyi.business.entity.*; |
| | | import com.ruoyi.business.mapper.*; |
| | | import com.ruoyi.business.service.ProductionMasterService; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | |
| | | private final CoalInfoMapper coalInfoMapper; |
| | | |
| | | private final PendingInventoryMapper pendingInventoryMapper; |
| | | |
| | | private final ProductionSchedulingMapper productionSchedulingMapper; |
| | | |
| | | @Override |
| | | public IPage<ProductionMasterDto> selectPMList(Page page, ProductionMasterDto productionMasterDto) { |
| | |
| | | |
| | | pending.setRegistrantId(p.getProducerId()); |
| | | pending.setRegistrationDate(LocalDate.now()); |
| | | |
| | | pending.setCode(generateCode(p.getType())); |
| | | pending.setType(p.getType()); |
| | | pendingInventoryMapper.insert(pending); |
| | | } |
| | | } |
| | | |
| | | private String generateCode(Integer type) { |
| | | LocalDate now = LocalDate.now(); |
| | | String year = now.format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
| | | String s = ""; |
| | | //生成编码 |
| | | switch (type){ |
| | | case 1: |
| | | s = "CP"; |
| | | break; |
| | | case 2: |
| | | s = "YL"; |
| | | break; |
| | | } |
| | | // 查询当天待入库新增条数 |
| | | Long count = pendingInventoryMapper.selectCount(new LambdaQueryWrapper<PendingInventory>() |
| | | .apply("date_trunc('day', create_time) = date_trunc('day', now())")); |
| | | return s + year + String.format("%03d", count + 1); |
| | | } |
| | | |
| | | @Override |
| | |
| | | .collect(Collectors.toList()); |
| | | productionInventoryMapper.deleteBatchIds(inventoryIds); |
| | | } |
| | | List<Production> productions = productionMapper.selectList(new LambdaQueryWrapper<Production>() |
| | | .in(Production::getProductionMasterId, idList)); |
| | | |
| | | // 删除生产报工记录 |
| | | productionSchedulingMapper.delete( |
| | | new LambdaQueryWrapper<ProductionScheduling>() |
| | | .in(ProductionScheduling::getProductionId, productions.stream().map(Production::getId).collect(Collectors.toList())) |
| | | ); |
| | | |
| | | // 删除生产明细 |
| | | productionMapper.delete( |
| | | new LambdaQueryWrapper<Production>() |
| | | .in(Production::getProductionMasterId, idList) |
| | | ); |
| | | |
| | | |
| | | // 5. 删除主记录 |
| | | return productionMasterMapper.deleteBatchIds(idList); |
| | |
| | | |
| | | return productionIdsToDelete.size(); |
| | | } |
| | | |
| | | @Override |
| | | public Object randomScheduling(LoginUser loginUser) { |
| | | List<OfficialInventory> officialInventories = officialInventoryMapper.selectList(null); |
| | | if(CollectionUtils.isEmpty(officialInventories)){ |
| | | throw new BaseException("没有可调度的库存"); |
| | | } |
| | | Random random = new Random(); |
| | | // 在官方库存中随机选择一个 |
| | | OfficialInventory officialInventory = officialInventories.get(random.nextInt(officialInventories.size())); |
| | | List<ProductionInventory> productionInventories = new ArrayList<>(); |
| | | ProductionInventory productionInventory = new ProductionInventory(); |
| | | productionInventory.setOfficialId(officialInventory.getId()); |
| | | productionInventory.setCoalId(officialInventory.getCoalId()); |
| | | productionInventory.setInventoryQuantity(officialInventory.getInventoryQuantity().intValue()); |
| | | productionInventory.setUsedQuantity(random.nextInt(officialInventory.getInventoryQuantity().intValue()) + 1); |
| | | productionInventories.add(productionInventory); |
| | | List<Production> productions = new ArrayList<>(); |
| | | Production production = new Production(); |
| | | production.setCoalId(officialInventory.getCoalId()); |
| | | // 1-500随机生成 |
| | | production.setEnergyConsumptionCost(BigDecimal.valueOf(random.nextInt(500) + 1)); |
| | | production.setEquipmentDepreciation(BigDecimal.valueOf(random.nextInt(500) + 1)); |
| | | production.setLaborCost(BigDecimal.valueOf(random.nextInt(500) + 1)); |
| | | production.setProductionQuantity(BigDecimal.valueOf(random.nextInt(500) + 1)); |
| | | production.setPurchasePrice(BigDecimal.valueOf(random.nextInt(500) + 1)); |
| | | |
| | | // 求和 |
| | | BigDecimal add = production.getEquipmentDepreciation() |
| | | .add(production.getEnergyConsumptionCost()) |
| | | .add(production.getLaborCost()) |
| | | .add(production.getPurchasePrice()) |
| | | .add(production.getProductionQuantity()); |
| | | production.setTotalCost(add); |
| | | production.setType(2); |
| | | production.setProducerId(loginUser.getUserId()); |
| | | production.setProducer(loginUser.getUsername()); |
| | | productions.add(production); |
| | | ProductionMasterDto productionMasterDto = new ProductionMasterDto(); |
| | | productionMasterDto.setProductionList(productions); |
| | | productionMasterDto.setProductionInventoryList(productionInventories); |
| | | return addOrEditPM(productionMasterDto); |
| | | } |
| | | } |