| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.business.dto.ProductionMasterDto; |
| | | import com.ruoyi.business.entity.OfficialInventory; |
| | | import com.ruoyi.business.entity.Production; |
| | | import com.ruoyi.business.entity.ProductionInventory; |
| | | import com.ruoyi.business.entity.ProductionMaster; |
| | |
| | | import com.ruoyi.business.mapper.ProductionMapper; |
| | | import com.ruoyi.business.mapper.ProductionMasterMapper; |
| | | import com.ruoyi.business.service.ProductionMasterService; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | BigDecimal totalTotalCost = BigDecimal.ZERO; |
| | | BigDecimal totalEquipmentDepreciation = BigDecimal.ZERO; |
| | | int totalProductionQuantity = 0; |
| | | StringBuilder coalBuilder = new StringBuilder("["); // 优化字符串拼接 |
| | | StringBuilder coalBuilder = new StringBuilder(); |
| | | |
| | | for (Production production : productionMasterDto.getProductionList()) { |
| | | totalPurchasePrice = totalPurchasePrice.add(production.getPurchasePrice()); |
| | |
| | | totalTotalCost = totalTotalCost.add(production.getTotalCost()); |
| | | totalEquipmentDepreciation = totalEquipmentDepreciation.add(production.getEquipmentDepreciation()); |
| | | totalProductionQuantity += production.getProductionQuantity(); |
| | | coalBuilder.append(production.getCoal()).append(","); |
| | | if (coalBuilder.length() > 0) { |
| | | coalBuilder.append(","); // 在元素之间添加逗号 |
| | | } |
| | | coalBuilder.append(production.getCoal()); |
| | | } |
| | | |
| | | // 处理coal字符串拼接 |
| | | String coalStr = coalBuilder.length() > 1 ? |
| | | coalBuilder.deleteCharAt(coalBuilder.length()-1).append("]").toString() : "[]"; |
| | | String coalStr = coalBuilder.toString(); // 直接获取拼接结果 |
| | | |
| | | // 2. 创建主表对象 |
| | | ProductionMaster productionMaster = new ProductionMaster(); |
| | |
| | | productionMasterMapper.insert(productionMaster); |
| | | masterId = productionMaster.getId(); // 获取新生成的ID |
| | | } else { |
| | | // 删除关联子表数据(使用更高效的in删除) |
| | | // 删除关联子表数据 |
| | | productionMapper.delete(new LambdaQueryWrapper<Production>() |
| | | .eq(Production::getProductionMasterId, masterId)); |
| | | |
| | |
| | | |
| | | productionMasterMapper.updateById(productionMaster); |
| | | } |
| | | |
| | | //库存更新 |
| | | for (ProductionInventory productionInventory : productionMasterDto.getProductionInventoryList()) { |
| | | OfficialInventory officialInventory = officialInventoryMapper.selectById(productionInventory.getOfficialId()); |
| | | BigDecimal subtract = officialInventory.getInventoryQuantity().subtract(new BigDecimal(productionInventory.getUsedQuantity())); |
| | | if (subtract.compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new BaseException("库存不足"); |
| | | } |
| | | officialInventory.setInventoryQuantity(subtract); |
| | | officialInventoryMapper.updateById(officialInventory); |
| | | } |
| | | |
| | | // 4. 批量插入子表数据 |
| | | batchInsertProductions(masterId, productionMasterDto.getProductionList()); |
| | | batchInsertInventories(masterId, productionMasterDto.getProductionInventoryList()); |