生产计划的下发状态逻辑调整+能耗统计查询sql优化
| | |
| | | EnergyStatisticsDto energyStatisticsDto = new EnergyStatisticsDto(); |
| | | //计算总耗用量+总能耗费用 |
| | | Map<String, BigDecimal> map=energyConsumptionDetailMapper.calculateEnergy(energyStatisticsVo); |
| | | |
| | | energyStatisticsDto.setTotalEnergyConsumption(map.get("totalEnergyConsumption")); |
| | | energyStatisticsDto.setTotalEnergyCost(map.get("totalEnergyCost")); |
| | | //平均用量 |
| | |
| | | // 最后一个计划,分配剩余方数 |
| | | BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume); |
| | | plan.setStatus(1); |
| | | if (lastRemainingVolume.compareTo(BigDecimal.ZERO) <= 0) { |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume)); |
| | | if (plan.getAssignedQuantity().compareTo(plan.getVolume()) >= 0) { |
| | | plan.setStatus(2); |
| | | } |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume)); |
| | | productOrderPlan.setAssignedQuantity(lastRemainingVolume); |
| | | productionPlanMapper.updateById(plan); |
| | | productOrderPlanMapper.insert(productOrderPlan); |
| | |
| | | </where> |
| | | </select> |
| | | <select id="calculateEnergy" resultType="java.util.Map"> |
| | | select SUM(COALESCE(ecd.dosage,0)) totalEnergyConsumption, |
| | | SUM(COALESCE(ecd.dosage,0) * COALESCE(e.unit_price,0)) totalEnergyCost |
| | | select COALESCE(t.totalEnergyConsumption, 0) AS totalEnergyConsumption, |
| | | COALESCE(t.totalEnergyCost, 0) AS totalEnergyCost |
| | | from (select SUM(ecd.dosage) totalEnergyConsumption, |
| | | SUM(ecd.dosage * e.unit_price) totalEnergyCost |
| | | from energy_consumption_detail ecd |
| | | left join energy e on ecd.energy_id = e.id |
| | | where ecd.meter_reading_date between #{c.startDate} and #{c.endDate} |
| | | <if test="c.type != null and c.type != ''"> |
| | | and ecd.type =#{c.type} |
| | | </if> |
| | | )t |
| | | </select> |
| | | <select id="energyConsumptionTypeProportion" |
| | | resultType="com.ruoyi.energy.dto.EnergyConsumptionTypeDto"> |
| | |
| | | <if test="c.model != null and c.model != '' "> |
| | | AND pms.model LIKE CONCAT('%',#{c.model},'%') |
| | | </if> |
| | | <if test="c.status != null"> |
| | | AND pp.status =#{c.status} |
| | | </if> |
| | | <if test="c.applyNo != null and c.applyNo != '' "> |
| | | AND pp.apply_no LIKE CONCAT('%',#{c.applyNo},'%') |
| | | </if> |
| | |
| | | </foreach> |
| | | ORDER BY pp.id ASC |
| | | </select> |
| | | </mapper> |
| | | </mapper> |