Commit 2856d284 authored by 张森's avatar 张森

30546 运行趋势页签接口开发

parent fb999bba
package com.yeejoin.equipmanage.common.entity.vo;
import lombok.Data;
@Data
public class EquipTrendInfoVo {
private String id;
private String iotCode;
private String name;
private String maxNum;
private String minNum;
private String unit;
}
package com.yeejoin.equipmanage.common.entity.vo;
import lombok.Data;
import java.util.List;
@Data
public class EquipTrendResultVo {
private List<String> legends;
private String yAxisName;
private List<String> xAxisData;
private List<List<String>> yAxisData;
private List<List<String>> threshold;
}
......@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex;
import com.yeejoin.equipmanage.common.entity.FormInstanceEquip;
import com.yeejoin.equipmanage.common.entity.vo.EquipTrendResultVo;
import com.yeejoin.equipmanage.common.enums.IndexStatusEnum;
import com.yeejoin.equipmanage.common.utils.*;
import com.yeejoin.equipmanage.config.PersonIdentify;
......@@ -72,6 +73,9 @@ public class SupervisionConfigureController extends AbstractBaseController {
@Autowired
private FormInstanceEquipMapper formInstanceEquipMapper;
@Autowired
private IEquipmentSpecificSerivce equipmentSpecificService;
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
......@@ -823,4 +827,50 @@ public class SupervisionConfigureController extends AbstractBaseController {
Map<String, Object> list = supervisionVideoService.getPressurePumpPage(bizOrgCode, id, startTime, endTime, pageNum, pageSize, timeSort, stateSort);
return CommonResponseUtil.success(list);
}
@PersonIdentify
@RequestMapping(value = "/operatingTrendIot", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "设备平台运行趋势 设备相关API", produces = "application/json;charset=UTF-8", notes = "设备平台运行趋势 设备相关API")
public ResponseModel operatingTrendIot(@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "bizOrgCode", required = false) String bizOrgCode,
@RequestParam(value = "equipCode", required = false) String equipCode,
@RequestParam(value = "indexKey", required = false) String indexKey) {
if (ObjectUtils.isEmpty(bizOrgCode)) {
ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
if (!ValidationUtil.isEmpty(personIdentity)) {
bizOrgCode = personIdentity.getBizOrgCode();
if (bizOrgCode == null) {
return CommonResponseUtil.success(null);
}
}
}
EquipTrendResultVo equipTrendResultVo = equipmentSpecificService.operatingTrendIot(startTime, endTime, bizOrgCode, equipCode, indexKey);
return CommonResponseUtil.success(equipTrendResultVo);
}
@PersonIdentify
@RequestMapping(value = "/operatingTrendWater", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "设备平台运行趋势 稳压泵启动频次趋势API", produces = "application/json;charset=UTF-8", notes = "设备平台运行趋势 稳压泵启动频次趋势API")
public ResponseModel operatingTrendPressurePump(@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "bizOrgCode", required = false) String bizOrgCode,
@RequestParam(value = "equipCode", required = false) String equipCode,
@RequestParam(value = "indexKey", required = false) String indexKey) {
if (ObjectUtils.isEmpty(bizOrgCode)) {
ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
if (!ValidationUtil.isEmpty(personIdentity)) {
bizOrgCode = personIdentity.getBizOrgCode();
if (bizOrgCode == null) {
return CommonResponseUtil.success(null);
}
}
}
EquipTrendResultVo equipTrendResultVo = equipmentSpecificService.operatingTrendPressurePump(startTime, endTime, bizOrgCode, equipCode, indexKey);
return CommonResponseUtil.success(equipTrendResultVo);
}
}
......@@ -15,7 +15,7 @@ import java.util.Map;
* @author DELL
*/
//@FeignClient(name = "${iot.vehicle.track}", path = "iot", configuration = {FeignConfiguration.class})
@FeignClient(name = "AMOS-API-IOT", path = "iot", configuration = { FeignConfiguration.class })
@FeignClient(name = "AMOS-API-IOT-ZS", path = "iot", configuration = { FeignConfiguration.class })
public interface IotFeign {
@RequestMapping(value = "/v1/livedata/list", method = RequestMethod.GET, consumes = "application/json")
......
......@@ -346,4 +346,5 @@ public interface EquipmentSpecificMapper extends BaseMapper<EquipmentSpecific> {
Integer selectEquipmentCountBySystemId(@Param("systemId") Long systemId);
List<EquipTrendInfoVo> getEquipListByCode(@Param("code") String code, @Param("indexKey") String indexKey, @Param("bizOrgCode") String bizOrgCode);
}
......@@ -329,4 +329,8 @@ public interface IEquipmentSpecificSerivce extends IService<EquipmentSpecific> {
Page<Map<String, Object>> getFireEquipListByDefineCode(String code, String equipStatus, String bizOrgCode, Page<Map<String, Object>> pageBean);
void updateCarStatus(String status, String carId);
EquipTrendResultVo operatingTrendIot(String startTime, String endTime, String bizOrgCode, String equipCode, String indexKey);
EquipTrendResultVo operatingTrendPressurePump(String startTime, String endTime, String bizOrgCode, String equipCode, String indexKey);
}
......@@ -27,11 +27,13 @@ import com.yeejoin.equipmanage.common.entity.dto.EquipmentSpecificDTO;
import com.yeejoin.equipmanage.common.entity.vo.*;
import com.yeejoin.equipmanage.common.enums.*;
import com.yeejoin.equipmanage.common.exception.BaseException;
import com.yeejoin.equipmanage.common.utils.CommonResponseUtil;
import com.yeejoin.equipmanage.common.utils.DateUtils;
import com.yeejoin.equipmanage.common.utils.QRCodeUtil;
import com.yeejoin.equipmanage.common.utils.StringUtil;
import com.yeejoin.equipmanage.common.vo.*;
import com.yeejoin.equipmanage.fegin.IdxFeign;
import com.yeejoin.equipmanage.fegin.IotFeign;
import com.yeejoin.equipmanage.fegin.SystemctlFeign;
import com.yeejoin.equipmanage.mapper.*;
import com.yeejoin.equipmanage.remote.RemoteSecurityService;
......@@ -63,9 +65,14 @@ import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import static org.apache.poi.Version.getProduct;
import static org.typroject.tyboot.core.foundation.context.RequestContext.getAppKey;
import static org.typroject.tyboot.core.foundation.context.RequestContext.getToken;
import static org.typroject.tyboot.core.foundation.utils.DateTimeUtil.ISO8601_DATE_HOUR_MIN_SEC;
/**
......@@ -374,6 +381,9 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
@Value("${equipment.pressurepump.start}")
private String pressurePumpStart;
@Autowired
IotFeign iotFeign;
private StockBill buildStockBills(EquipmentSpecific equipmentSpecific, ReginParams reginParams, AgencyUserModel agencyUserModel) {
StockBill stockBill = new StockBill();
stockBill.setCreatorId(Long.valueOf(agencyUserModel.getUserId()));
......@@ -2250,4 +2260,206 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
return pageBean;
}
@Override
public EquipTrendResultVo operatingTrendIot(String startTime, String endTime, String bizOrgCode, String equipCode, String indexKey) {
List<EquipTrendInfoVo> equipList = equipmentSpecificMapper.getEquipListByCode(equipCode, indexKey, bizOrgCode);
List<String> allTimeList = new ArrayList<>();
ResponseModel entity = null;
//返回数据组装定义
List<String> legends = new ArrayList<>();
List<List<String>> threshold = new ArrayList<>();
Map<String, Map<String, String>> dateValueMapInfo = new HashMap<>();
EquipTrendResultVo equipTrendResultVo = new EquipTrendResultVo();
for (EquipTrendInfoVo equipInfo : equipList) {
//返回数据组装
List<String> maxMinInfo = new ArrayList<>();
maxMinInfo.add(equipInfo.getMinNum());
maxMinInfo.add(equipInfo.getMaxNum());
threshold.add(maxMinInfo);
legends.add(equipInfo.getName());
equipTrendResultVo.setYAxisName(equipInfo.getUnit());
//iot数据查询组装
String prefix = null;
String suffix = null;
String iotCode = equipInfo.getIotCode();
if (StringUtil.isNotEmpty(iotCode) && iotCode.length() > 8) {
prefix = iotCode.substring(0, 8);
suffix = iotCode.substring(8);
} else {
throw new BadRequest("装备物联编码不存在或编码错误,请确认!");
}
try {
entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), startTime, endTime, prefix, suffix, indexKey);
} catch (Exception e) {
throw new RuntimeException("调用AMOS-API-IOT服务失败,请检查服务是否正常!");
}
if (200 == entity.getStatus() && !ObjectUtils.isEmpty(entity.getResult())) {
String json = JSON.toJSONString(entity.getResult());
List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json);
Map<String, String> timeAndValue = new HashMap<>();
for (Map<String, String> mapList : listObject) {
if (mapList.containsKey(indexKey)) {
timeAndValue.put(mapList.get("time"), mapList.get(indexKey));
allTimeList.add(mapList.get("time"));
}
}
dateValueMapInfo.put(equipInfo.getId(), timeAndValue);
}
}
allTimeList = allTimeList.stream().distinct().collect(Collectors.toList());
equipTrendResultVo.setLegends(legends);
equipTrendResultVo.setThreshold(threshold);
List<List<String>> yaxisList = new ArrayList<>();
for (EquipTrendInfoVo info : equipList) {
//key:时间 value:数值
Map<String, String> dateValueDataMap = dateValueMapInfo.get(info.getId());
List<String> values = new ArrayList<>();
String lastValue = "0";
List<String> allTimeListNew = new ArrayList<>();
for (int i = 0; i < allTimeList.size(); i++) {
if (!ObjectUtils.isEmpty(dateValueDataMap) && dateValueDataMap.containsKey(allTimeList.get(i))) {
lastValue = dateValueDataMap.get(allTimeList.get(i));
}
values.add(lastValue);
try {
allTimeListNew.add(change(allTimeList.get(i)));
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
yaxisList.add(values);
equipTrendResultVo.setXAxisData(allTimeListNew);
}
equipTrendResultVo.setYAxisData(yaxisList);
return equipTrendResultVo;
}
@Override
public EquipTrendResultVo operatingTrendPressurePump(String startTime, String endTime, String bizOrgCode, String equipCode, String indexKey) {
List<EquipTrendInfoVo> equipList = equipmentSpecificMapper.getEquipListByCode(equipCode, indexKey, bizOrgCode);
List<String> allTimeList = new ArrayList<>();
ResponseModel entity = null;
//返回数据组装定义
List<String> legends = new ArrayList<>();
List<List<String>> threshold = new ArrayList<>();
Map<String, Map<String, String>> dateValueMapInfo = new HashMap<>();
EquipTrendResultVo equipTrendResultVo = new EquipTrendResultVo();
for (EquipTrendInfoVo equipInfo : equipList) {
//返回数据组装
List<String> maxMinInfo = new ArrayList<>();
maxMinInfo.add(equipInfo.getMinNum());
maxMinInfo.add(equipInfo.getMaxNum());
threshold.add(maxMinInfo);
legends.add(equipInfo.getName());
equipTrendResultVo.setYAxisName(equipInfo.getUnit());
//iot数据查询组装
String prefix = null;
String suffix = null;
String iotCode = equipInfo.getIotCode();
if (StringUtil.isNotEmpty(iotCode) && iotCode.length() > 8) {
prefix = iotCode.substring(0, 8);
suffix = iotCode.substring(8);
} else {
throw new BadRequest("装备物联编码不存在或编码错误,请确认!");
}
try {
entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), startTime, endTime, prefix, suffix, indexKey);
} catch (Exception e) {
throw new RuntimeException("调用AMOS-API-IOT服务失败,请检查服务是否正常!");
}
if (200 == entity.getStatus() && !ObjectUtils.isEmpty(entity.getResult())) {
String json = JSON.toJSONString(entity.getResult());
List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json);
Map<String, String> timeAndValue = new HashMap<>();
for (Map<String, String> mapList : listObject) {
if (mapList.containsKey(indexKey)) {
timeAndValue.put(mapList.get("time"), mapList.get(indexKey));
allTimeList.add(mapList.get("time"));
}
}
dateValueMapInfo.put(equipInfo.getId(), timeAndValue);
}
}
allTimeList = allTimeList.stream().distinct().collect(Collectors.toList());
equipTrendResultVo.setLegends(legends);
equipTrendResultVo.setThreshold(threshold);
List<List<String>> yaxisList = new ArrayList<>();
for (EquipTrendInfoVo info : equipList) {
//key:时间 value:数值
Map<String, String> dateValueDataMap = dateValueMapInfo.get(info.getId());
List<String> values = new ArrayList<>();
String lastValue = "0";
List<String> allTimeListNew = new ArrayList<>();
for (int i = 0; i < allTimeList.size(); i++) {
if (!ObjectUtils.isEmpty(dateValueDataMap) && dateValueDataMap.containsKey(allTimeList.get(i))) {
lastValue = dateValueDataMap.get(allTimeList.get(i));
}
values.add(lastValue);
try {
allTimeListNew.add(change(allTimeList.get(i)));
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
yaxisList.add(values);
equipTrendResultVo.setXAxisData(allTimeListNew);
}
equipTrendResultVo.setYAxisData(yaxisList);
return equipTrendResultVo;
}
private String change(String time) throws ParseException {
Date date1 = null;
try {
String strDate = time.substring(0, 19);
SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_DATE_HOUR_MIN_SEC);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
date1 = sdf.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
return DateTimeUtil.format(date1, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
}
// 格式化器,用于输出时间
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH");
/**
* 获取给定时间段内每个整点的时间列表
*
* @param startTime 开始时间(包含)
* @param endTime 结束时间(不包含其下一个整点)
* @return 整点时间列表
*/
public static List<String> getHourlyTimes(LocalDateTime startTime, LocalDateTime endTime) {
List<String> hourlyTimes = new ArrayList<>();
// 将开始时间调整为当前小时的起始点
LocalDateTime currentTime = startTime.truncatedTo(java.time.temporal.ChronoUnit.HOURS);
// 循环直到超过结束时间(不包含结束时间的下一个整点)
while (!currentTime.isAfter(endTime)) {
hourlyTimes.add(currentTime.format(formatter));
currentTime = currentTime.plusHours(1);
}
return hourlyTimes;
}
}
......@@ -2997,4 +2997,40 @@
</if>
</select>
<select id="getEquipListByCode" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipTrendInfoVo">
SELECT
a.id,
a.iot_code AS iotCode,
a.`name` AS `name`,
<if test="equipCode == '92011000'">
max( CASE WHEN b.field_name = 'maxPressure' THEN b.field_value END ) AS maxNum,
max( CASE WHEN b.field_name = 'minPressure' THEN b.field_value END ) AS minNum,
concat('压力(', ifnull(c.unit, 'Mpa'), ')') as unit
</if>
<if test="(equipCode == '92032000' and indexKey == 'CAFS_WaterTank_WaterTankLevel') or (equipCode == '92031900')">
max( CASE WHEN b.field_name = 'maxLevel' THEN b.field_value END ) AS maxNum,
max( CASE WHEN b.field_name = 'minLevel' THEN b.field_value END ) AS minNum,
concat('液位(', ifnull(c.unit, 'M'), ')') as unit
</if>
<if test="equipCode == '92032000' and indexKey == 'CAFS_WaterTank_EffluentFlow'">
max( CASE WHEN b.field_name = 'maxLevel' THEN b.field_value END ) AS maxNum,
max( CASE WHEN b.field_name = 'minLevel' THEN b.field_value END ) AS minNum,
concat('出口流量(', ifnull(c.unit, 'L/S'), ')') as unit
</if>
<if test="equipCode == '92010800'">
'频次(次/小时)' as unit
</if>
FROM
`wl_equipment_specific` AS a
LEFT JOIN wl_form_instance_equip b ON a.id = b.instance_id
LEFT JOIN ( SELECT * FROM wl_equipment_specific_index WHERE equipment_index_key = #{indexKey} ) c ON a.id = c.equipment_specific_id
<where>
a.`equipment_code` LIKE concat(#{code}, '%')
<if test="bizOrgCode != null and bizOrgCode != ''">
AND a.biz_org_code LIKE concat(#{bizOrgCode}, '%')
</if>
</where>
GROUP BY
a.id
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment