Commit a6397f3e authored by 王鹿鹿's avatar 王鹿鹿

任务 7881 7859

parent eb0ba2d2
...@@ -2,11 +2,11 @@ package com.yeejoin.equipmanage.common.utils; ...@@ -2,11 +2,11 @@ package com.yeejoin.equipmanage.common.utils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.ParsePosition; import java.text.ParsePosition;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.*;
import java.util.Date;
/** /**
* @description: 时间工具类 * @description: 时间工具类
...@@ -17,13 +17,25 @@ public class DateUtils { ...@@ -17,13 +17,25 @@ public class DateUtils {
public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static final String MINUTE_PATTERN = "yyyy-MM-dd HH:mm"; public static final String MINUTE_PATTERN = "yyyy-MM-dd HH:mm";
public static final String HOUR_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String HOUR_PATTERN = "yyyy-MM-dd HH";
public static final String DATE_PATTERN = "yyyy-MM-dd"; public static final String DATE_PATTERN = "yyyy-MM-dd";
public static final String MONTH_PATTERN = "yyyy-MM"; public static final String MONTH_PATTERN = "yyyy-MM";
public static final String YEAR_PATTERN = "yyyy"; public static final String YEAR_PATTERN = "yyyy";
public static final String MINUTE_ONLY_PATTERN = "mm"; public static final String MINUTE_ONLY_PATTERN = "mm";
public static final String HOUR_ONLY_PATTERN = "HH"; public static final String HOUR_ONLY_PATTERN = "HH";
public static final String DATE_TIME_T_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; public static final String DATE_TIME_T_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public static final String[] TWENTY_FOUR = new String[]{" 00:00:00"," 01:00:00"," 02:00:00",
" 03:00:00"," 04:00:00"," 05:00:00"," 06:00:00"," 07:00:00"," 08:00:00"," 09:00:00"," 10:00:00"," 11:00:00"," 12:00:00"," 13:00:00",
" 14:00:00"," 15:00:00"," 16:00:00"," 17:00:00"," 18:00:00"," 19:00:00"," 20:00:00"," 21:00:00"," 22:00:00"," 23:00:00"};
/**
* 获取 当前年、半年、季度、月、日、小时 开始结束时间
*/
private static final SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
private static final SimpleDateFormat longHourSdf = new SimpleDateFormat("yyyy-MM-dd HH");
private static final SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final Calendar calendar = Calendar.getInstance();
private static final SimpleDateFormat shortDateNew = new SimpleDateFormat("yyyy/M/d");
/** /**
* 获取当前时间 * 获取当前时间
* *
...@@ -163,6 +175,46 @@ public class DateUtils { ...@@ -163,6 +175,46 @@ public class DateUtils {
return content; return content;
} }
/**
* 暂时不操作原生截取做下转换
*
* @param str
* @return
* @throws ParseException
*/
public static String dateToStringMonth(String str) {
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN);
Date parse = null;
String content = null;
try {
parse = sdf.parse(str);
content = DateUtils.dateFormat(parse, DateUtils.MONTH_PATTERN);
} catch (ParseException e) {
e.printStackTrace();
}
return content;
}
/**
* 暂时不操作原生截取做下转换
*
* @param str
* @return
* @throws ParseException
*/
public static String dateToStringY(String str) {
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN);
Date parse = null;
String content = null;
try {
parse = sdf.parse(str);
content = DateUtils.dateFormat(parse, DateUtils.YEAR_PATTERN);
} catch (ParseException e) {
e.printStackTrace();
}
return content;
}
/* /*
* 将时间戳转换为时间 * 将时间戳转换为时间
...@@ -594,4 +646,237 @@ public class DateUtils { ...@@ -594,4 +646,237 @@ public class DateUtils {
return cal.getTime(); return cal.getTime();
} }
/**
* 判断一个时间是否在一个时间段内
*
* @param nowTime 当前时间
* @param beginTime 开始时间
* @param endTime 结束时间
*/
public static boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Calendar begin = Calendar.getInstance();
begin.setTime(beginTime);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
return date.after(begin) && date.before(end);
}
/**
* 获得本天的开始时间,即2012-01-01 00:00:00
*
* @return
*/
public static Date getCurrentDayStartTime(Date date) {
try {
date = shortSdf.parse(shortSdf.format(date) + " 00:00:00");
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
* 获得本天的结束时间,即2012-01-01 23:59:59
*
* @return
*/
public static Date getCurrentDayEndTime(Date date) {
try {
date = longSdf.parse(shortSdf.format(date) + " 23:59:59");
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
public static List<Date> findDaysStr(String cntDateBeg, String cntDateEnd) {
List<Date> list = new ArrayList<>();
//拆分成数组
String[] dateBegs = cntDateBeg.split("-");
String[] dateEnds = cntDateEnd.split("-");
//开始时间转换成时间戳
Calendar start = Calendar.getInstance();
start.set(Integer.valueOf(dateBegs[0]), Integer.valueOf(dateBegs[1]) - 1, Integer.valueOf(dateBegs[2]));
Long startTIme = start.getTimeInMillis();
//结束时间转换成时间戳
Calendar end = Calendar.getInstance();
end.set(Integer.valueOf(dateEnds[0]), Integer.valueOf(dateEnds[1]) - 1, Integer.valueOf(dateEnds[2]));
Long endTime = end.getTimeInMillis();
//定义一个一天的时间戳时长
Long oneDay = 1000 * 60 * 60 * 24L;
Long time = startTIme;
//循环得出
while (time <= endTime) {
list.add(DateUtils.getCurrentDayStartTime(new Date(time)));
time += oneDay;
}
return list;
}
/**
* 获取当前月自然周数,并返回每周开始日期和每周结束日期
* @param date 2013-9 : 1-1,2-8,9-15,16-22,23-29,30-30
* @return
* @throws Exception
*/
public static List<String> getWeeks(String date){
List<String> dates = new ArrayList<>();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
Date date1 = null;
try {
date1 = dateFormat.parse(date);
} catch (ParseException e) {
System.out.println("获取当前月自然周,日期格式转换错误!11");
e.printStackTrace();
}
Calendar calendar = new GregorianCalendar();
calendar.setTime(date1);
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int count = 0;
for (int i = 1; i <= days; i++) {
DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
Date date2 = null;
try {
date2 = dateFormat1.parse(date + "-" + i);
} catch (ParseException e) {
System.out.println("获取当前月自然周,日期格式转换错误!22");
e.printStackTrace();
}
calendar.clear();
calendar.setTime(date2);
int k = new Integer(calendar.get(Calendar.DAY_OF_WEEK));
int startDay = 0;
int endDay = 0;
// 若当天是周日
if (k == 1) {
count++;
if (i - 6 <= 1) {
startDay = 1;
} else {
startDay = i - 6;
}
endDay = i;
}
// 若是本月最好一天,且不是周日
if (k != 1 && i == days) {
count++;
startDay = i - k + 2;
endDay = i;
}
if(startDay != 0 && endDay != 0){
dates.add(startDay + "-" + endDay);
}
}
return dates;
}
/**
* 获取当前月自然周数,并返回每周开始日期和每周结束日期
* @param date 2013-9 : 1-1,2-8,9-15,16-22,23-29,30-30
* @return
* @throws Exception
*/
public static List<String> getWeeksMap(String date){
List<String> dates = new ArrayList<>();
String year = date.substring(0,4);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
Date date1 = null;
try {
date1 = dateFormat.parse(date);
} catch (ParseException e) {
System.out.println("获取当前月自然周,日期格式转换错误!11");
e.printStackTrace();
}
Calendar calendar = new GregorianCalendar();
calendar.setTime(date1);
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int count = 0;
for (int i = 1; i <= days; i++) {
DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
Date date2 = null;
try {
date2 = dateFormat1.parse(date + "-" + i);
} catch (ParseException e) {
System.out.println("获取当前月自然周,日期格式转换错误!22");
e.printStackTrace();
}
calendar.clear();
calendar.setTime(date2);
int k = new Integer(calendar.get(Calendar.DAY_OF_WEEK));
int startDay = 0;
int endDay = 0;
// 若当天是周日
if (k == 1) {
count++;
if (i - 6 <= 1) {
startDay = 1;
} else {
startDay = i - 6;
}
endDay = i;
}
// 若是本月最好一天,且不是周日
if (k != 1 && i == days) {
count++;
startDay = i - k + 2;
endDay = i;
}
if(startDay != 0 && endDay != 0){
String s = year + "第" + getWeekOfYear(date2) + "周" + "(" + date.substring(5) + "月" + startDay +
"日至" + date.substring(5) + "月" + endDay + "日" +")";
dates.add(s);
}
}
return dates;
}
/**
* 获取一年的第几周
*
* @param date
* @return
*/
public static int getWeekOfYear(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int week_of_year = c.get(Calendar.WEEK_OF_YEAR);
return week_of_year;
}
/**
* 获得本月的开始时间,即2012-01-01 00:00:00
*
* @return
*/
public static Date getCurrentMonthStartTime(Date date) throws Exception {
Calendar c = Calendar.getInstance();
c.setTime(date);
Date now = null;
c.set(Calendar.DATE, 1);
now = shortSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00");
return now;
}
/**
* 当前月的结束时间,即2012-01-31 23:59:59
*
* @return
*/
public static Date getCurrentMonthEndTime(Date date) throws Exception {
Calendar c = Calendar.getInstance();
c.setTime(date);
Date now = null;
c.set(Calendar.DATE, 1);
c.add(Calendar.MONTH, 1);
c.add(Calendar.DATE, -1);
now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59");
return now;
}
} }
package com.yeejoin.equipmanage.common.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IotIndexItemVo {
private String id;
private String key;
private String name;
}
package com.yeejoin.equipmanage.common.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IotIndexResItemVo {
private String key;
private String name;
private int[] data;
}
package com.yeejoin.equipmanage.common.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IotIndexResMinotFinalVo {
private Long id;
private String[] name;
private String[] nameKey;
private String unit;
private List<String> times;
private List<IotIndexItemVo> items;
private List<IotIndexResItemVo> iotData;
}
package com.yeejoin.equipmanage.common.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IotIndexResMinotVo {
private Long id;
private String name;
private String nameKey;
private String unit;
private List<String> times;
private List<IotDataVO> iotData;
}
...@@ -22,6 +22,7 @@ import com.yeejoin.equipmanage.service.impl.TopographyService; ...@@ -22,6 +22,7 @@ import com.yeejoin.equipmanage.service.impl.TopographyService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -752,7 +753,7 @@ public class TopographyController extends AbstractBaseController { ...@@ -752,7 +753,7 @@ public class TopographyController extends AbstractBaseController {
} }
ResponseModel entity = null; ResponseModel entity = null;
try { try {
entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), beginDate, endDate, prefix, suffix); entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), beginDate, endDate, prefix, suffix, null);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -761,7 +762,7 @@ public class TopographyController extends AbstractBaseController { ...@@ -761,7 +762,7 @@ public class TopographyController extends AbstractBaseController {
String json = JSON.toJSONString(entity.getResult()); String json = JSON.toJSONString(entity.getResult());
List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json); List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json);
List<IotDataVO> iotDatalist = new ArrayList<>(); List<IotDataVO> iotDatalist = new ArrayList<>();
for(Map<String, String> mapList : listObject) { for (Map<String, String> mapList : listObject) {
for (Map.Entry entry : mapList.entrySet()) { for (Map.Entry entry : mapList.entrySet()) {
if (!"name".equals(entry.getKey()) && !"deviceName".equals(entry.getKey())) { if (!"name".equals(entry.getKey()) && !"deviceName".equals(entry.getKey())) {
IotDataVO iotDataVO = new IotDataVO(); IotDataVO iotDataVO = new IotDataVO();
...@@ -774,12 +775,12 @@ public class TopographyController extends AbstractBaseController { ...@@ -774,12 +775,12 @@ public class TopographyController extends AbstractBaseController {
List<IotDataVO> timeList = iotDatalist.stream().filter(x -> "time".equals(x.getKey())).collect(Collectors.toList()); List<IotDataVO> timeList = iotDatalist.stream().filter(x -> "time".equals(x.getKey())).collect(Collectors.toList());
List<EquipmentSpecificIndex> indexes = equipmentSpecificIndexMapper.getEquipmentSpeIndexByIotCode(iotCode); List<EquipmentSpecificIndex> indexes = equipmentSpecificIndexMapper.getEquipmentSpeIndexByIotCode(iotCode);
if (0 <indexes.size()) { if (0 < indexes.size()) {
int j = 0; int j = 0;
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
for (int i=0; i<timeList.size(); i++) { for (int i = 0; i < timeList.size(); i++) {
TopographyIotVo iotVo = new TopographyIotVo(); TopographyIotVo iotVo = new TopographyIotVo();
List<TopographyIotDataVO> lists = new ArrayList<>(); List<TopographyIotDataVO> lists = new ArrayList<>();
// if (i == 0) { // if (i == 0) {
...@@ -805,8 +806,8 @@ public class TopographyController extends AbstractBaseController { ...@@ -805,8 +806,8 @@ public class TopographyController extends AbstractBaseController {
SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_DATE_HOUR_MIN_SEC); SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_DATE_HOUR_MIN_SEC);
SimpleDateFormat sdf1 = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN); SimpleDateFormat sdf1 = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN);
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date1=sdf.parse(strDate); Date date1 = sdf.parse(strDate);
String time= DateTimeUtil.format(date1, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC); String time = DateTimeUtil.format(date1, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
iotVo.setTime(sdf1.parse(time)); iotVo.setTime(sdf1.parse(time));
} catch (Exception e) { } catch (Exception e) {
...@@ -834,21 +835,44 @@ public class TopographyController extends AbstractBaseController { ...@@ -834,21 +835,44 @@ public class TopographyController extends AbstractBaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "根据节点id查询当前节点物联指标趋势", notes = "根据节点id查询当前节点物联指标趋势") @ApiOperation(httpMethod = "GET", value = "根据节点id查询当前节点物联指标趋势", notes = "根据节点id查询当前节点物联指标趋势")
public ResponseModel getEquipmentIndexTrendInfo(@RequestParam(required = false) String id, public ResponseModel getEquipmentIndexTrendInfo(@RequestParam(required = false) String id,
@RequestParam(required = false) String equipSpeId, @RequestParam(required = false) String equipSpeId,
@RequestParam(required = false) String beginDate, @RequestParam(required = false) String beginDate,
@RequestParam(required = false) String endDate) throws ParseException { @RequestParam(required = false) String fieldKey,
@RequestParam(required = false) String isTrend,
@RequestParam(required = false) String endDate) throws ParseException {
String eqpId; String eqpId;
if (StringUtil.isNotEmpty(equipSpeId)) {
eqpId = equipSpeId; String iotCode = null;
if(null != fieldKey || null != isTrend) {
EquipmentSpecific equipmentSpecific = equipmentSpecificService.getById(equipSpeId);
iotCode = equipmentSpecific.getIotCode();
List<EquipmentIndex> equipmentSpecifics = equipmentIndexService.getPerfQutoaIotList(Long.valueOf(equipSpeId));
if (equipmentSpecifics.size() == 0) {
return CommonResponseUtil.success();
}
if ("true".equals(isTrend)) {
fieldKey = equipmentSpecifics.stream().filter(equipmentIndex -> equipmentIndex.getIsTrend()).map(EquipmentIndex::getPerfQuotaDefinitionId).collect(Collectors.joining(","));
}
} else { } else {
TopographyNodeDetailDTO detailDTO = topographyNodeDetailService.queryByNodeid(id); if (StringUtil.isNotEmpty(equipSpeId)) {
if (null == detailDTO || !StringUtil.isNotEmpty(detailDTO.getEqpId())) { eqpId = equipSpeId;
throw new RuntimeException("节点信息错误或此节点下未绑定装备!"); } else {
TopographyNodeDetailDTO detailDTO = topographyNodeDetailService.queryByNodeid(id);
if (null == detailDTO || !StringUtil.isNotEmpty(detailDTO.getEqpId())) {
throw new RuntimeException("节点信息错误或此节点下未绑定装备!");
}
eqpId = detailDTO.getEqpId();
} }
eqpId = detailDTO.getEqpId();
EquipmentSpecific equipmentSpecific = equipmentSpecificService.getById(eqpId);
iotCode = equipmentSpecific.getIotCode();
} }
EquipmentSpecific equipmentSpecific = equipmentSpecificService.getById(eqpId);
String iotCode = equipmentSpecific.getIotCode();
String prefix = null; String prefix = null;
String suffix = null; String suffix = null;
if (iotCode.length() > 8) { if (iotCode.length() > 8) {
...@@ -859,7 +883,7 @@ public class TopographyController extends AbstractBaseController { ...@@ -859,7 +883,7 @@ public class TopographyController extends AbstractBaseController {
} }
ResponseModel entity = null; ResponseModel entity = null;
try { try {
entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), beginDate, endDate, prefix, suffix); entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), beginDate, endDate, prefix, suffix, fieldKey);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -867,8 +891,8 @@ public class TopographyController extends AbstractBaseController { ...@@ -867,8 +891,8 @@ public class TopographyController extends AbstractBaseController {
String json = JSON.toJSONString(entity.getResult()); String json = JSON.toJSONString(entity.getResult());
List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json); List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json);
List<IotDataVO> vos = new ArrayList<>(); List<IotDataVO> vos = new ArrayList<>();
for(Map<String, String> mapList : listObject){ for (Map<String, String> mapList : listObject) {
for (Map.Entry entry : mapList.entrySet()){ for (Map.Entry entry : mapList.entrySet()) {
if (!"name".equals(entry.getKey()) && !"deviceName".equals(entry.getKey())) { if (!"name".equals(entry.getKey()) && !"deviceName".equals(entry.getKey())) {
IotDataVO vo = new IotDataVO(); IotDataVO vo = new IotDataVO();
vo.setKey(String.valueOf(entry.getKey())); vo.setKey(String.valueOf(entry.getKey()));
...@@ -887,18 +911,18 @@ public class TopographyController extends AbstractBaseController { ...@@ -887,18 +911,18 @@ public class TopographyController extends AbstractBaseController {
SimpleDateFormat sdf1 = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN); SimpleDateFormat sdf1 = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN);
logger.info("返回时间===================================(" + vo.getValue() + ") ======================================="); logger.info("返回时间===================================(" + vo.getValue() + ") =======================================");
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date=sdf.parse(strDate); Date date = sdf.parse(strDate);
// String time= sdf.format(date); // String time= sdf.format(date);
String time= DateTimeUtil.format(date, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC); String time = DateTimeUtil.format(date, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
dates.add(sdf1.parse(time)); dates.add(sdf1.parse(time));
logger.info("返回时间===================================(" + sdf1.parse(time) + ") ======================================="); logger.info("返回时间===================================(" + sdf1.parse(time) + ") =======================================");
} }
List<EquipmentSpecificIndex> indexes = equipmentSpecificIndexMapper.getEquipmentSpeIndexByIotCodeAndTrend(iotCode); List<EquipmentSpecificIndex> indexes = equipmentSpecificIndexMapper.getEquipmentSpeIndexByIotCodeAndTrend(iotCode);
if (0 <indexes.size()) { if (0 < indexes.size()) {
List<TopographyIotIndexTrendVo> list = new ArrayList<>(); List<TopographyIotIndexTrendVo> list = new ArrayList<>();
vos.forEach(iotDataVO -> { vos.forEach(iotDataVO -> {
indexes.forEach(x -> { indexes.forEach(x -> {
if (x.getNameKey().equals(iotDataVO.getKey())) { if (x.getNameKey().equals(iotDataVO.getKey())) {
TopographyIotIndexTrendVo vo = new TopographyIotIndexTrendVo(); TopographyIotIndexTrendVo vo = new TopographyIotIndexTrendVo();
vo.setId(x.getId()); vo.setId(x.getId());
...@@ -926,7 +950,7 @@ public class TopographyController extends AbstractBaseController { ...@@ -926,7 +950,7 @@ public class TopographyController extends AbstractBaseController {
List<IotIndexResVo> res = new ArrayList<>(); List<IotIndexResVo> res = new ArrayList<>();
for (String s : mapIndex.keySet()) { for (String s : mapIndex.keySet()) {
IotIndexResVo vo = new IotIndexResVo(); IotIndexResVo vo = new IotIndexResVo();
LambdaQueryWrapper <EquipmentIndex> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<EquipmentIndex> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(EquipmentIndex::getId, mapIndex.get(s)); queryWrapper.eq(EquipmentIndex::getId, mapIndex.get(s));
EquipmentIndex index = iEquipmentIndexService.getOne(queryWrapper); EquipmentIndex index = iEquipmentIndexService.getOne(queryWrapper);
vo.setIotData(map.get(s)); vo.setIotData(map.get(s));
...@@ -949,6 +973,337 @@ public class TopographyController extends AbstractBaseController { ...@@ -949,6 +973,337 @@ public class TopographyController extends AbstractBaseController {
} }
/***
*
* 根据设备id获取当前设备的物联指标趋势
*
* **/
@RequestMapping(value = "/equipment/trenIot", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "根据设备id获取当前设备的物联指标趋势", notes = "根据设备id获取当前设备的物联指标趋势")
public ResponseModel getEquipmentIndexTrendIotInfo(@RequestParam(required = false) String totalType,
@RequestParam(required = false) String equipId,
@RequestParam(required = false) String fieldKey,
@RequestParam(required = false) String isTrend,
@RequestParam(required = false) String beginDate,
@RequestParam(required = false) String endDate) throws Exception {
EquipmentSpecific equipmentSpecific = equipmentSpecificService.getById(equipId);
String iotCode = equipmentSpecific.getIotCode();
List<EquipmentIndex> equipmentSpecifics = equipmentIndexService.getPerfQutoaIotList(Long.valueOf(equipId));
if (equipmentSpecifics.size() == 0) {
return CommonResponseUtil.success();
}
String allKeys;
String names;
Map<String, String> map = new HashMap<>();
List<IotIndexItemVo> iotIndexItemVos = new ArrayList<>();
equipmentSpecifics.stream().forEach((e)->{
IotIndexItemVo itemVo = new IotIndexItemVo();
map.put(e.getPerfQuotaDefinitionId(),e.getPerfQuotaName());
itemVo.setKey(e.getPerfQuotaDefinitionId());
itemVo.setName(e.getPerfQuotaName());
iotIndexItemVos.add(itemVo);
});
if ( "true".equals(isTrend)) {
allKeys = equipmentSpecifics.stream().filter(equipmentIndex -> equipmentIndex.getIsTrend()).map(EquipmentIndex::getPerfQuotaDefinitionId).collect(Collectors.joining(","));
names = equipmentSpecifics.stream().filter(equipmentIndex -> equipmentIndex.getIsTrend()).map(EquipmentIndex::getPerfQuotaName).collect(Collectors.joining(","));
} else {
allKeys = equipmentSpecifics.stream().filter(equipmentIndex -> !equipmentIndex.getIsTrend()).map(EquipmentIndex::getPerfQuotaDefinitionId).collect(Collectors.joining(","));
names = equipmentSpecifics.stream().filter(equipmentIndex -> !equipmentIndex.getIsTrend()).map(EquipmentIndex::getPerfQuotaName).collect(Collectors.joining(","));
}
String parmfieldKey = "";
String parmfieldName = "";
if(StringUtils.isEmpty(fieldKey) ) {
parmfieldKey = allKeys;
} else {
parmfieldKey = fieldKey;
for(String s: fieldKey.split(",") ) {
parmfieldName = parmfieldName + map.get(s) + ",";
}
}
String prefix = null;
String suffix = null;
if (iotCode.length() > 8) {
prefix = iotCode.substring(0, 8);
suffix = iotCode.substring(8);
} else {
return CommonResponseUtil.failure("装备物联编码错误,请确认!");
}
ResponseModel entity = null;
String[] filedKeyArr = parmfieldKey.split(",");
List<IotIndexResMinotVo> res = new ArrayList<>();
IotIndexResMinotFinalVo indexResMinotFinalVo = new IotIndexResMinotFinalVo();
List<Date> datesFinal = new ArrayList<>();
for (String st : filedKeyArr) {
try {
entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), beginDate, endDate, prefix, suffix, st);
} catch (Exception e) {
e.printStackTrace();
}
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);
List<IotDataVO> vos = new ArrayList<>();
Map<String, String> timeAndValue = new HashMap<>();
for (Map<String, String> mapList : listObject) {
for (Map.Entry entry : mapList.entrySet()) {
if (!"name".equals(entry.getKey()) && !"deviceName".equals(entry.getKey())) {
IotDataVO vo = new IotDataVO();
vo.setKey(String.valueOf(entry.getKey()));
vo.setValue(String.valueOf(entry.getValue()));
vos.add(vo);
}
}
if (mapList.containsKey(st)) {
timeAndValue.put(mapList.get("time"), mapList.get(st));
}
}
List<IotDataVO> timeList = vos.stream().filter(x -> x.getKey().equals("time")).collect(Collectors.toList());
List<String> dates = new ArrayList<>();
for (IotDataVO vo : timeList) {
String value = String.valueOf(vo.getValue());
dates.add(value);
}
List<IotDataVO> dataList = new ArrayList<>();
if (isTrend.equals("true")) {
// 处理遥测
} else {
// 处理遥信
// 时间处理
if (totalType.equals("hour")) {
handle(datesFinal, dates, beginDate, st, dataList, timeAndValue);
} else if (totalType.equals("day")) {
handleDay(datesFinal, beginDate, endDate, st, dates, dataList, timeAndValue);
} else if (totalType.equals("week")) {
handWeek(beginDate, st,dates,dataList,timeAndValue);
} else {
handMonth(beginDate, st,dates,dataList,timeAndValue);
}
IotIndexResMinotVo iotIndexResVo = new IotIndexResMinotVo();
iotIndexResVo.setIotData(dataList);
res.add(iotIndexResVo);
}
}
}
if(totalType.equals("week") || totalType.equals("month") || totalType.equals("hour") || totalType.equals("day")) {
List<String> times = null;
if(totalType.equals("week")) {
times = DateUtils.getWeeksMap(DateUtils.dateToStringMonth(beginDate));
} else if(totalType.equals("month")) {
String year = beginDate.substring(0,4);
times = new ArrayList<>();
for(int i =1; i <= 12; i++) {
if(i < 10) {
String m = year + "-" + "0" + i;
times.add(m);
} else {
String m = year + "-" + i;
times.add(m);
}
}
} else if(totalType.equals("hour") || totalType.equals("day")) {
times = new ArrayList<>();
if(totalType.equals("hour")) {
String[] arr = DateUtils.TWENTY_FOUR;
Date date = DateUtils.dateParse(beginDate,DateUtils.DATE_PATTERN);
String dateDayT = DateUtils.dateFormat(date, DateUtils.DATE_PATTERN);
if (datesFinal.size() == 0) {
for (String str : arr) {
String dateDay = dateDayT;
dateDay = dateDay + str;
datesFinal.add(DateUtils.dateParse(dateDay, DateUtils.DATE_TIME_PATTERN));
}
}
} else {
if (datesFinal.size() == 0) {
datesFinal.addAll(DateUtils.findDaysStr(DateUtils.dateToString(beginDate), DateUtils.dateToString(endDate)));
}
}
for (Date date : datesFinal) {
times.add(DateUtils.convertDateToString(date, totalType.equals("hour") ? DateUtils.HOUR_PATTERN : DateUtils.DATE_PATTERN));
}
}
List<IotIndexResItemVo> iotData = new ArrayList<>();
for(IotIndexResMinotVo s : res) {
IotIndexResItemVo itemVo = new IotIndexResItemVo();
List<Integer> list = new ArrayList<>();
for (IotDataVO v: s.getIotData()) {
list.add(Integer.parseInt(v.getValue().toString()));
itemVo.setName(map.get(v.getKey()));
itemVo.setKey(v.getKey());
}
itemVo.setData(list.stream().mapToInt(i->i).toArray());
iotData.add(itemVo);
}
indexResMinotFinalVo.setTimes(times);
indexResMinotFinalVo.setNameKey(StringUtils.isEmpty(fieldKey) ? allKeys.split(",") : fieldKey.split(","));
indexResMinotFinalVo.setName(StringUtils.isEmpty(fieldKey) ? names.split(",") : parmfieldName.split(","));
indexResMinotFinalVo.setItems(iotIndexItemVos);
indexResMinotFinalVo.setIotData(iotData);
}
return CommonResponseUtil.success(indexResMinotFinalVo);
}
private void handMonth( String beginDate, String nameKey, List<String> dates, List<IotDataVO> dataList, Map<String, String> timeAndValue) throws Exception {
for(int i =1; i <= 12; i++) {
int num = 0;
Date bDate = DateUtils.getCurrentMonthStartTime(DateUtils.dateParse(DateUtils.dateToStringY(beginDate) + "-" + i,DateUtils.MONTH_PATTERN));
Date dDate = DateUtils.getCurrentMonthEndTime(DateUtils.dateParse(DateUtils.dateToStringY(beginDate) + "-" + i,DateUtils.MONTH_PATTERN));
for (String dat : dates) {
if (DateUtils.belongCalendar(dateParse(dat), bDate, dDate)) {
if (null != timeAndValue.get(dat)) {
num++;
}
}
}
IotDataVO iotDataVO = new IotDataVO();
iotDataVO.setKey(nameKey);
iotDataVO.setValue(num);
dataList.add(iotDataVO);
}
}
private void handWeek( String beginDate, String nameKey, List<String> dates, List<IotDataVO> dataList, Map<String, String> timeAndValue) throws Exception {
List<String> weeks = DateUtils.getWeeks(DateUtils.dateToStringMonth(beginDate));
for(String s:weeks) {
int num = 0;
String[] arr = s.split("-");
Date bDate;
Date dDate;
String sStr = "";
String eStr = "";
if(Integer.parseInt(arr[0]) < 10 ) {
sStr = "0" + arr[0];
} else {
sStr = arr[1];
}
if(Integer.parseInt(arr[1]) < 10 ) {
eStr = "0" + arr[1];
} else {
eStr = arr[1];
}
if(arr[0].equals(arr[1])) {
bDate = DateUtils.dateParse(DateUtils.dateToStringMonth(beginDate) + "-" + sStr + " 00:00:00" ,DateUtils.DATE_TIME_PATTERN);
dDate = DateUtils.dateParse(DateUtils.dateToStringMonth(beginDate) + "-" + eStr + " 23:59:59"
,DateUtils.DATE_PATTERN);
} else {
bDate = DateUtils.dateParse(DateUtils.dateToStringMonth(beginDate) + "-" + sStr + " 00:00:00",DateUtils.DATE_TIME_PATTERN);
dDate = DateUtils.dateParse(DateUtils.dateToStringMonth(beginDate) + "-" + eStr + " 00:00:00",DateUtils.DATE_TIME_PATTERN);
}
for (String dat : dates) {
if (DateUtils.belongCalendar(dateParse(dat), bDate, dDate)) {
if (null != timeAndValue.get(dat)) {
num++;
}
}
}
IotDataVO iotDataVO = new IotDataVO();
iotDataVO.setKey(nameKey);
iotDataVO.setValue(num);
dataList.add(iotDataVO);
}
}
private void handleDay(List<Date> datesFinal, String beginDate, String endDate, String nameKey, List<String> dates, List<IotDataVO> dataList, Map<String, String> timeAndValue
) throws ParseException {
if (datesFinal.size() == 0) {
datesFinal.addAll(DateUtils.findDaysStr(DateUtils.dateToString(beginDate), DateUtils.dateToString(endDate)));
}
if (timeAndValue.size() > 0) {
finalHandle(datesFinal, nameKey, dates, dataList, timeAndValue);
}
}
private void handle(List<Date> datesFinal, List<String> dates, String beginDate, String nameKey, List<IotDataVO> dataList,
Map<String, String> timeAndValue) throws ParseException {
String[] arr = DateUtils.TWENTY_FOUR;
Date date = DateUtils.dateParse(beginDate,DateUtils.DATE_PATTERN);
String dateDayT = DateUtils.dateFormat(date, DateUtils.DATE_PATTERN);
if (datesFinal.size() == 0) {
for (String str : arr) {
String dateDay = dateDayT;
dateDay = dateDay + str;
datesFinal.add(DateUtils.dateParse(dateDay, DateUtils.DATE_TIME_PATTERN));
}
}
if (timeAndValue.size() > 0) {
finalHandle(datesFinal, nameKey, dates, dataList, timeAndValue);
}
}
private void finalHandle(List<Date> datesFinal, String nameKey, List<String> dates, List<IotDataVO> dataList, Map<String, String> timeAndValue) throws ParseException {
for (int i = 0; i < datesFinal.size(); i++) {
int num = 0;
for (String dat : dates) {
if (i == datesFinal.size() - 1) {
if (DateUtils.belongCalendar(dateParse(dat), datesFinal.get(i),
DateUtils.getCurrentDayEndTime(datesFinal.get(i)))) {
if (null != timeAndValue.get(dat)) {
num++;
}
}
} else {
if (DateUtils.belongCalendar(dateParse(dat), datesFinal.get(i), datesFinal.get(i + 1))) {
if (null != timeAndValue.get(dat)) {
num++;
}
}
}
}
IotDataVO iotDataVO = new IotDataVO();
iotDataVO.setKey(nameKey);
iotDataVO.setValue(num);
dataList.add(iotDataVO);
}
}
private Date dateParse(String value) throws ParseException {
String strDate = value.substring(0, 19);
SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_DATE_HOUR_MIN_SEC);
SimpleDateFormat sdf1 = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = sdf.parse(strDate);
String time = DateTimeUtil.format(date, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
return sdf1.parse(time);
}
} }
...@@ -22,6 +22,7 @@ public interface IotFeign { ...@@ -22,6 +22,7 @@ public interface IotFeign {
@RequestParam(value = "timeStart") String beginDate, @RequestParam(value = "timeStart") String beginDate,
@RequestParam(value = "timeEnd") String endDate, @RequestParam(value = "timeEnd") String endDate,
@RequestParam(value = "productKey") String productKey, @RequestParam(value = "productKey") String productKey,
@RequestParam(value = "deviceName") String deviceName); @RequestParam(value = "deviceName") String deviceName,
@RequestParam(required = false, value = "fieldKey") String fieldKey);
} }
...@@ -63,5 +63,7 @@ public interface EquipmentIndexMapper extends BaseMapper<EquipmentIndex> { ...@@ -63,5 +63,7 @@ public interface EquipmentIndexMapper extends BaseMapper<EquipmentIndex> {
List<EquipmentIndexVO> getEquipmentIndexByIot(); List<EquipmentIndexVO> getEquipmentIndexByIot();
List<EquipmentIndex> getPerfQutoaIotList(Long id);
List<String> getGruopName(Long equipmentId); List<String> getGruopName(Long equipmentId);
} }
...@@ -63,4 +63,12 @@ public interface IEquipmentIndexService extends IService<EquipmentIndex> { ...@@ -63,4 +63,12 @@ public interface IEquipmentIndexService extends IService<EquipmentIndex> {
List<String> getGruopName(Long equipmentId); List<String> getGruopName(Long equipmentId);
/**
* 分页查询
* @param id
* @return
*/
List<EquipmentIndex> getPerfQutoaIotList(Long id);
} }
...@@ -77,6 +77,11 @@ public class EquipmentIndexImpl extends ServiceImpl<EquipmentIndexMapper, Equipm ...@@ -77,6 +77,11 @@ public class EquipmentIndexImpl extends ServiceImpl<EquipmentIndexMapper, Equipm
} }
@Override @Override
public List<EquipmentIndex> getPerfQutoaIotList(Long id) {
return this.baseMapper.getPerfQutoaIotList(id);
}
@Override
public EquipmentIndexVO getOnePrefQuota(Long id) { public EquipmentIndexVO getOnePrefQuota(Long id) {
return this.baseMapper.getOnePrefQuota(id); return this.baseMapper.getOnePrefQuota(id);
} }
......
...@@ -223,4 +223,10 @@ ...@@ -223,4 +223,10 @@
GROUP BY GROUP BY
group_name group_name
</select> </select>
<select id="getPerfQutoaIotList" resultType="com.yeejoin.equipmanage.common.entity.EquipmentIndex">
select id,name as perfQuotaName, name_key as perfQuotaDefinitionId,is_trend as isTrend from wl_equipment_index s where equipment_id = (
select equipment_id from wl_equipment_detail wei where id = (
select equipment_detail_id from wl_equipment_specific where id = #{id})
)
</select>
</mapper> </mapper>
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