add - ems产线能耗占比统计、耗能趋势分析、产线单耗对比、产品单耗对比接口

master
yinq 2 months ago
parent 9ae8aec358
commit f57e85c9bf

@ -18,6 +18,8 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Service
@ -133,29 +135,21 @@ public class RecordDnbInstantServiceImpl implements IRecordDnbInstantService {
if (StringUtils.isEmpty(recordDnbInstant.getMonitorSubset())) {
return recordDnbInstantMapper.instantList(new RecordDnbInstant());
}
List<RecordDnbInstant> dnbInstantList = new ArrayList<>();
BaseMonitorInfo monitorInfo = new BaseMonitorInfo();
monitorInfo.setParentId(Long.valueOf(recordDnbInstant.getMonitorSubset()));
monitorInfo.setParams(null);
recordDnbInstant.setParams(null);
List<BaseMonitorInfo> baseMonitorInfos = baseMonitorInfoService.selectBaseMonitorInfoList(monitorInfo);
for (BaseMonitorInfo baseMonitorInfo : baseMonitorInfos) {
RecordDnbInstant dnbInstant = new RecordDnbInstant();
dnbInstant.setMonitorId(baseMonitorInfo.getMonitorId());
dnbInstant.setMonitorName(baseMonitorInfo.getMonitorName());
RecordDnbInstant baseDnbInstant = new RecordDnbInstant();
baseDnbInstant.setMonitorSubset(baseMonitorInfo.getMonitorId());
List<RecordDnbInstant> dnbInstantListOld = recordDnbInstantMapper.instantList(baseDnbInstant);
if (dnbInstantListOld.size() > 0) {
BigDecimal zxyg = dnbInstantListOld.stream().map(RecordDnbInstant::getZxyg).reduce(BigDecimal.ZERO, BigDecimal::add);
Date collectTime = dnbInstantListOld.stream().map(RecordDnbInstant::getCollectTime).max(Date::compareTo).orElse(null);
dnbInstant.setZxyg(zxyg);
dnbInstant.setCollectTime(collectTime);
}
dnbInstantList.add(dnbInstant);
}
List<String> monitorIdList = baseMonitorInfos.stream().map(BaseMonitorInfo::getMonitorId).collect(Collectors.toList());
if (monitorIdList.size() > 0){
RecordDnbInstant instant = new RecordDnbInstant();
Map<String, Object> params = instant.getParams();
params.put("monitorIdList", monitorIdList);
List<RecordDnbInstant> dnbInstantList = recordDnbInstantMapper.instantList(instant);
return dnbInstantList;
}
return null;
}
/**
*
@ -176,7 +170,9 @@ public class RecordDnbInstantServiceImpl implements IRecordDnbInstantService {
baseDnbInstant.setParams(null);
List<BaseMonitorInfo> baseMonitorInfos = baseMonitorInfoService.selectBaseMonitorInfoList(monitorInfo);
if (baseMonitorInfos.size() > 0) {
List<RecordDnbInstant> dnbInstantListOld = recordDnbInstantMapper.instantList(baseDnbInstant);
RecordDnbInstant instant = new RecordDnbInstant();
instant.setMonitorId(baseDnbInstant.getMonitorSubset());
List<RecordDnbInstant> dnbInstantListOld = recordDnbInstantMapper.instantList(instant);
dnbInstant.setMonitorId(baseMonitorInfos.get(0).getMonitorId());
dnbInstant.setMonitorName(baseMonitorInfos.get(0).getMonitorName());
if (dnbInstantListOld.size() > 0) {

@ -1,7 +1,9 @@
package com.op.energy.report.controller;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.web.page.TableDataInfo;
import com.op.energy.report.domain.ReportOrderEnergyDTO;
import com.op.energy.report.service.IEnergyPreviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -25,7 +27,6 @@ public class energyPreviewController extends BaseController {
@Autowired
private IEnergyPreviewService energyPreviewService;
/**
*
*
@ -63,5 +64,52 @@ public class energyPreviewController extends BaseController {
return prefix + "/waterIndex";
}
/**
* 线
* @param paramMap
* @return
*/
@ResponseBody
@GetMapping("/productionLineEnergyConsumption")
public AjaxResult productionLineEnergyConsumption(@RequestParam(required = false) Map paramMap) {
Map<String, Object> result = energyPreviewService.productionLineEnergyConsumption(paramMap);
return AjaxResult.success(result);
}
/**
*
* @param paramMap
* @return
*/
@ResponseBody
@GetMapping("/energyConsumptionTrendAnalysis")
public AjaxResult energyConsumptionTrendAnalysis(@RequestParam(required = false) Map paramMap) {
Map<String, Object> result = energyPreviewService.energyConsumptionTrendAnalysis(paramMap);
return AjaxResult.success(result);
}
/**
* 线
* @param energyDTO
* @return
*/
@ResponseBody
@GetMapping("/linesConsumptionComparison")
public AjaxResult linesConsumptionComparison(ReportOrderEnergyDTO energyDTO) {
Map<String, Object> result = energyPreviewService.linesConsumptionComparison(energyDTO);
return AjaxResult.success(result);
}
/**
*
* @param energyDTO
* @return
*/
@ResponseBody
@GetMapping("/productConsumptionComparison")
public AjaxResult productLinesConsumptionComparison(ReportOrderEnergyDTO energyDTO) {
Map<String, Object> result = energyPreviewService.productConsumptionComparison(energyDTO);
return AjaxResult.success(result);
}
}

@ -80,4 +80,10 @@ public interface ReportPointDnbMapper {
List<Map<String, String>> energyStatisticsData(Map map);
public List<ReportOrderEnergyDTO> OrderEnergyList(ReportOrderEnergyDTO reportOrderEnergyDTO);
List<Map<String, String>> productionLineEnergyConsumption(Map paramMap);
List<ReportOrderEnergyDTO> linesConsumptionComparison(ReportOrderEnergyDTO energyDTO);
List<ReportOrderEnergyDTO> productConsumptionComparison(ReportOrderEnergyDTO energyDTO);
}

@ -1,5 +1,7 @@
package com.op.energy.report.service;
import com.op.energy.report.domain.ReportOrderEnergyDTO;
import java.util.List;
import java.util.Map;
@ -77,4 +79,32 @@ public interface IEnergyPreviewService {
* @return
*/
public List<Map<String, String>> energyConsumptionByTime(Map paramMap);
/**
* 线
* @param paramMap
* @return
*/
Map<String, Object> productionLineEnergyConsumption(Map paramMap);
/**
*
* @param paramMap
* @return
*/
Map<String, Object> energyConsumptionTrendAnalysis(Map paramMap);
/**
* 线
* @param energyDTO
* @return
*/
Map<String, Object> linesConsumptionComparison(ReportOrderEnergyDTO energyDTO);
/**
*
* @param energyDTO
* @return
*/
Map<String, Object> productConsumptionComparison(ReportOrderEnergyDTO energyDTO);
}

@ -10,15 +10,25 @@ import com.op.energy.base.mapper.BaseTypeRelationMapper;
import com.op.energy.base.service.IBaseMonitorInfoService;
import com.op.energy.base.utils.DateUtils;
import com.op.energy.base.utils.sortReportUitls;
import com.op.energy.record.domain.RecordDnbInstant;
import com.op.energy.record.mapper.RecordDnbInstantMapper;
import com.op.energy.report.domain.ReportOrderEnergyDTO;
import com.op.energy.report.domain.ReportPointDnb;
import com.op.energy.report.domain.ReportPointWater;
import com.op.energy.report.mapper.ReportPointDnbMapper;
import com.op.energy.report.mapper.ReportPointWaterMapper;
import com.op.energy.report.service.IDataAnalysisService;
import com.op.energy.report.service.IEnergyPreviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.op.energy.base.utils.DateUtils.YYYY_MM_DD_HH_MM_SS;
/**
* Service
@ -43,6 +53,9 @@ public class EnergyPreviewServiceImpl implements IEnergyPreviewService {
@Autowired
private BaseBuildInfoMapper baseBuildInfoMapper;
@Autowired
private RecordDnbInstantMapper recordDnbInstantMapper;
/**
*
*
@ -615,4 +628,217 @@ public class EnergyPreviewServiceImpl implements IEnergyPreviewService {
result.put("valueList", valueList);
return result;
}
/**
* 线
*
* @param paramMap
* @return
*/
@Override
@DS("#header.poolName")
public Map<String, Object> productionLineEnergyConsumption(Map paramMap) {
HashMap<String, Object> result = new HashMap<>();
List<Map<String, String>> energyList = reportPointDnbMapper.productionLineEnergyConsumption(paramMap);
result.put("energyList", energyList);
return result;
}
/**
*
*
* @param paramMap
* @return
*/
@Override
@DS("#header.poolName")
public Map<String, Object> energyConsumptionTrendAnalysis(Map paramMap) {
HashMap<String, Object> result = new HashMap<>();
List<Map<String, String>> energyList = new ArrayList<>();
List<String> timeList = new ArrayList<>();
List<Long> monitorIdLists = new ArrayList<>();
LinkedHashMap<String, List<Float>> monitorInfoMap = new LinkedHashMap<>();
if (!paramMap.containsKey("type") || !paramMap.containsKey("energyType") ||
String.valueOf(paramMap.get("startTime")).equals("") || String.valueOf(paramMap.get("endTime")).equals("")) {
return result;
}
String energyType = String.valueOf(paramMap.get("energyType"));
//小时 天 月 年
String type = String.valueOf(paramMap.get("type"));
BaseBuildInfo baseBuildInfo = new BaseBuildInfo();
List<BaseBuildInfo> buildInfoList = baseBuildInfoMapper.selectBaseBuildInfoList(baseBuildInfo);
if (paramMap.containsKey("monitorIds")) {
String monitorIds = String.valueOf(paramMap.get("monitorIds"));
if (monitorIds.contains(",")) {
monitorIdLists = Arrays.stream(monitorIds.split(","))
.map(String::trim)
.map(Long::valueOf)
.collect(Collectors.toList());
} else {
if (!monitorIds.isEmpty()) {
monitorIdLists.add(Long.parseLong(monitorIds));
}
}
}
switch (type) {
case "month":
timeList = DateUtils.getSortedMonthList(DateUtils.getDatesBetween(String.valueOf(paramMap.get("startTime")), String.valueOf(paramMap.get("endTime"))), type);
break;
case "year":
timeList = DateUtils.getSortedMonthList(DateUtils.getDatesBetween(String.valueOf(paramMap.get("startTime")), String.valueOf(paramMap.get("endTime"))), type);
break;
case "hour":
timeList = DateUtils.getHourlyIntervals(String.valueOf(paramMap.get("startTime")), String.valueOf(paramMap.get("endTime")));
break;
case "day":
timeList = DateUtils.getDatesBetween(String.valueOf(paramMap.get("startTime")), String.valueOf(paramMap.get("endTime")));
break;
}
List<List<Float>> lists = new ArrayList<>();
for (Long buildOId : monitorIdLists) {
List<Float> monitorValueList = new ArrayList<>();
List<String> monitorNameList = buildInfoList.stream().filter(e -> e.getObjid().equals(buildOId))
.map(BaseBuildInfo::getBuildName).collect(Collectors.toList());
BaseTypeRelation relation = new BaseTypeRelation();
relation.setType(0L);
relation.setRelationId(buildOId);
List<BaseTypeRelation> baseTypeRelations = baseTypeRelationMapper.selectBaseTypeRelationList(relation);
List<String> collect = baseTypeRelations.stream().map(BaseTypeRelation::getMonitorId).collect(Collectors.toList());
paramMap.put("monitorIdList", collect);
if (energyType.equals("2")) {
ReportPointDnb pointDnb = new ReportPointDnb();
pointDnb.setParams(paramMap);
List<ReportPointDnb> pointDnbList = reportPointDnbMapper.selectReportPointDnbList(pointDnb);
for (ReportPointDnb reportPointDnb : pointDnbList) {
Map<String, String> map = new HashMap<>();
map.put("recordTime", DateUtils.parseDateToStr("yyyy-MM-dd HH", reportPointDnb.getBeginTime()));
map.put("expend", reportPointDnb.getExpend().toString());
energyList.add(map);
}
} else if (energyType.equals("3")) {
ReportPointWater reportPointWater = new ReportPointWater();
reportPointWater.setParams(paramMap);
List<ReportPointWater> reportPointWaters = reportPointWaterMapper.selectReportPointWaterList(reportPointWater);
for (ReportPointWater pointWater : reportPointWaters) {
Map<String, String> map = new HashMap<>();
map.put("recordTime", DateUtils.parseDateToStr("yyyy-MM-dd HH", pointWater.getBeginTime()));
map.put("expend", pointWater.getExpend().toString());
energyList.add(map);
}
}
timeList.forEach(date -> {
float expend = 0.00f;
for (Map<String, String> map : energyList) {
String recordTime = String.valueOf(map.get("recordTime"));
if (type.equals("month")) {
recordTime = recordTime.substring(0, 7);
} else if (type.equals("year")) {
recordTime = recordTime.substring(0, 4);
} else if (type.equals("hour")) {
date = date.substring(0, 13);
} else if (type.equals("day")) {
recordTime = recordTime.substring(0, 10);
}
if (date.equals(recordTime)) {
expend += Float.parseFloat(String.valueOf(map.get("expend")));
}
}
BigDecimal decimal = new BigDecimal(Float.toString(expend));
decimal = decimal.setScale(2, RoundingMode.HALF_UP);
monitorValueList.add(decimal.floatValue());
});
if (monitorNameList.size() != 0) {
monitorInfoMap.put(monitorNameList.get(0), monitorValueList);
}
lists.add(monitorValueList);
}
if (lists.size() != 0) {
List<Float> sumLineList = IntStream.range(0, lists.get(0).size())
.mapToObj(i -> lists.stream()
.map(list -> list.get(i))
.reduce(0f, Float::sum))
.map(f -> Math.round(f * 100.0) / 100.0f)
.collect(Collectors.toList());
result.put("sumLineList", sumLineList);
}
List<String> monitorNameList = new ArrayList<>();
for (String monitorName : monitorInfoMap.keySet()) {
monitorNameList.add(monitorName);
}
result.put("monitorNameList", monitorNameList);
result.put("timeList", timeList);
result.put("monitorInfoMap", monitorInfoMap);
return result;
}
/**
* 线
*
* @param energyDTO
* @return
*/
@Override
@DS("#header.poolName")
public Map<String, Object> linesConsumptionComparison(ReportOrderEnergyDTO energyDTO) {
HashMap<String, Object> result = new HashMap<>();
LinkedHashMap<String, BigDecimal> dataMap = new LinkedHashMap<>();
List<ReportOrderEnergyDTO> reportOrderEnergyDTOList = reportPointDnbMapper.linesConsumptionComparison(energyDTO);
if (reportOrderEnergyDTOList != null && reportOrderEnergyDTOList.size() > 0) {
for (ReportOrderEnergyDTO orderEnergyDTO : reportOrderEnergyDTOList) {
RecordDnbInstant recordDnbInstant = new RecordDnbInstant();
String startWorkTime = DateUtils.parseDateToStr(YYYY_MM_DD_HH_MM_SS, orderEnergyDTO.getStartWorkTime());
String endWorkTime = DateUtils.parseDateToStr(YYYY_MM_DD_HH_MM_SS, orderEnergyDTO.getEndWorkTime());
String electricityNo = orderEnergyDTO.getElectricityNo();
Map<String, Object> map = new HashMap<>();
recordDnbInstant.setMonitorId(electricityNo);
map.put("beginCollectTime", startWorkTime);
map.put("endCollectTime", endWorkTime);
recordDnbInstant.setParams(map);
List<RecordDnbInstant> recordDnbInstantList = recordDnbInstantMapper.selectRecordDnbInstantByTime(recordDnbInstant);
if (recordDnbInstantList.size() == 2) {
BigDecimal kw = recordDnbInstantList.get(0).getKw().subtract(recordDnbInstantList.get(1).getKw()).abs();
BigDecimal decimal = kw.divide(new BigDecimal(orderEnergyDTO.getTotalQuantityFeedback()), 2, RoundingMode.HALF_UP);
dataMap.put(orderEnergyDTO.getEquipmentName(), decimal);
}
}
}
result.put("data", dataMap);
return result;
}
/**
*
* @param energyDTO
* @return
*/
@Override
@DS("#header.poolName")
public Map<String, Object> productConsumptionComparison(ReportOrderEnergyDTO energyDTO) {
HashMap<String, Object> result = new HashMap<>();
LinkedHashMap<String, BigDecimal> dataMap = new LinkedHashMap<>();
List<ReportOrderEnergyDTO> reportOrderEnergyDTOList = reportPointDnbMapper.productConsumptionComparison(energyDTO);
if (reportOrderEnergyDTOList != null && reportOrderEnergyDTOList.size() > 0) {
for (ReportOrderEnergyDTO orderEnergyDTO : reportOrderEnergyDTOList) {
RecordDnbInstant recordDnbInstant = new RecordDnbInstant();
String startWorkTime = DateUtils.parseDateToStr(YYYY_MM_DD_HH_MM_SS, orderEnergyDTO.getStartWorkTime());
String endWorkTime = DateUtils.parseDateToStr(YYYY_MM_DD_HH_MM_SS, orderEnergyDTO.getEndWorkTime());
String electricityNo = orderEnergyDTO.getElectricityNo();
Map<String, Object> map = new HashMap<>();
recordDnbInstant.setMonitorId(electricityNo);
map.put("beginCollectTime", startWorkTime);
map.put("endCollectTime", endWorkTime);
recordDnbInstant.setParams(map);
List<RecordDnbInstant> recordDnbInstantList = recordDnbInstantMapper.selectRecordDnbInstantByTime(recordDnbInstant);
if (recordDnbInstantList.size() == 2) {
BigDecimal kw = recordDnbInstantList.get(0).getKw().subtract(recordDnbInstantList.get(1).getKw()).abs();
BigDecimal decimal = kw.divide(new BigDecimal(orderEnergyDTO.getTotalQuantityFeedback()), 2, RoundingMode.HALF_UP);
dataMap.put(orderEnergyDTO.getProductName(), decimal);
}
}
}
result.put("data", dataMap);
return result;
}
}

@ -41,7 +41,7 @@
WITH OrderedRecords AS (
SELECT
rdi.*,
rdi.zxyg * bmi.ct AS kw,
rdi.zxyg * isnull(bmi.ct,1) AS kw,
bmi.ct,
ROW_NUMBER() OVER (ORDER BY rdi.collect_time ASC) AS RowAsc,
ROW_NUMBER() OVER (ORDER BY rdi.collect_time DESC) AS RowDesc

@ -380,4 +380,74 @@
</foreach>
</delete>
<select id="productionLineEnergyConsumption" resultType="java.util.Map">
select bbi.build_name buildName, sum(rpd.expend) expend
from base_build_info bbi
left join base_type_relation btr on btr.relation_id = bbi.objid
left join base_monitor_info m on m.monitor_id = btr.monitor_id
left join report_point_dnb rpd on m.monitor_id = rpd.monitor_id
where m.monitor_id is not null
<if test="unitId != null and unitId != ''">and bbi.grade = #{unitId}</if>
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and rpd.begin_time between #{beginTime} and #{endTime}
</if>
group by bbi.build_name
order by expend desc
</select>
<select id="linesConsumptionComparison" resultMap="ReportOrderEnergyDTOResult">
select be.equipment_name equipment_name,
SUM(mrw.total_quantity_feedback) total_quantity_feedback,
MIN(pow.start_work_time) start_work_time,
MAX(pow.end_work_time) end_work_time,
be.attr2 AS electricity_no
FROM pro_order_workorder pow
LEFT JOIN base_equipment be ON pow.workorder_name = be.equipment_code
LEFT JOIN (SELECT workorder_code,
SUM(quantity_feedback) AS total_quantity_feedback
FROM mes_report_work
GROUP BY workorder_code) mrw ON pow.workorder_code = mrw.workorder_code
WHERE pow.status = 'w3'
AND pow.parent_order = '0'
AND pow.del_flag = '0'
AND pow.end_work_time IS NOT NULL
AND be.equipment_name IS NOT NULL
AND be.attr2 IS NOT NULL
<if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''">
AND pow.product_date between #{params.beginTime} and #{params.endTime}
</if>
<if test="workorderCode != null and workorderCode != ''">and pow.workorder_code like concat('%', #{workorderCode}, '%')</if>
<if test="productCode != null and productCode != ''">and pow.product_code like concat('%', #{productCode}, '%')</if>
<if test="productName != null and productName != ''">and pow.product_name like concat('%', #{productName}, '%')</if>
GROUP BY be.equipment_name, be.attr2
ORDER BY be.equipment_name
</select>
<select id="productConsumptionComparison" resultMap="ReportOrderEnergyDTOResult">
select pow.product_name product_name,
SUM(mrw.total_quantity_feedback) total_quantity_feedback,
MIN(pow.start_work_time) start_work_time,
MAX(pow.end_work_time) end_work_time,
be.attr2 AS electricity_no
FROM pro_order_workorder pow
LEFT JOIN base_equipment be ON pow.workorder_name = be.equipment_code
LEFT JOIN (SELECT workorder_code,
SUM(quantity_feedback) AS total_quantity_feedback
FROM mes_report_work
GROUP BY workorder_code) mrw ON pow.workorder_code = mrw.workorder_code
WHERE pow.status = 'w3'
AND pow.parent_order = '0'
AND pow.del_flag = '0'
AND pow.end_work_time IS NOT NULL
AND be.equipment_name IS NOT NULL
AND be.attr2 IS NOT NULL
<if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''">
AND pow.product_date between #{params.beginTime} and #{params.endTime}
</if>
<if test="workorderCode != null and workorderCode != ''">and pow.workorder_code like concat('%', #{workorderCode}, '%')</if>
<if test="workorderName != null and workorderName != ''">and pow.workorder_name like concat('%', #{workorderName}, '%')</if>
<if test="equipmentName != null and equipmentName != ''">and be.equipment_name like concat('%', #{equipmentName}, '%')</if>
GROUP BY pow.product_name, be.attr2
ORDER BY pow.product_name
</select>
</mapper>

Loading…
Cancel
Save