|
@@ -1,17 +1,21 @@
|
|
|
package org.jeecg.modules.webaccess.service;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.modules.system.entity.SysDictItem;
|
|
|
import org.jeecg.modules.system.service.ISysDictItemService;
|
|
|
import org.jeecg.modules.webaccess.dto.CirculateDTO;
|
|
|
import org.jeecg.modules.webaccess.dto.SectionDTO;
|
|
|
import org.jeecg.modules.webaccess.dto.WaLogDTO;
|
|
|
import org.jeecg.modules.webaccess.entity.GuanDashboardParam;
|
|
|
+import org.jeecg.modules.webaccess.entity.GuanRAlarm;
|
|
|
import org.jeecg.modules.webaccess.entity.GuanTest;
|
|
|
import org.jeecg.modules.webaccess.mapper.GuanDashboardParamMapper;
|
|
|
+import org.jeecg.modules.webaccess.mapper.GuanRAlarmMapper;
|
|
|
import org.jeecg.modules.webaccess.mapper.GuanTestMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpEntity;
|
|
@@ -35,6 +39,7 @@ import java.util.jar.JarEntry;
|
|
|
* 调用webaccess的接口
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class WebAccessService {
|
|
|
// @Autowired
|
|
|
// private RestTemplate restTemplate;
|
|
@@ -48,10 +53,15 @@ public class WebAccessService {
|
|
|
@Autowired
|
|
|
private GuanTestMapper guanTestMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GuanRAlarmMapper guanRAlarmMapper;
|
|
|
+
|
|
|
+
|
|
|
//region <<字典获取webaccess信息>>
|
|
|
/**
|
|
|
* 获取webaccess的API信息
|
|
|
- * @param itemtext(group:组合API,single:单独某个信息,login:登录信息)
|
|
|
+ * @param itemtext 字典项名称
|
|
|
+ * @param type 获取类型(group:组合API,single:单独某个信息,login:登录信息)
|
|
|
* @return
|
|
|
*/
|
|
|
private String getDictItemDesc(String itemtext, String type) {
|
|
@@ -72,6 +82,17 @@ public class WebAccessService {
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取字典值
|
|
|
+ * @param itemtext(group:组合API,single:单独某个信息,login:登录信息)
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getDictItemValue(String itemtext) {
|
|
|
+ SysDictItem dictItem = sysDictItemService.selectItemsByDictcodeAndItemtext("webaccess", itemtext);
|
|
|
+
|
|
|
+ return dictItem.getItemValue();
|
|
|
+ }
|
|
|
//endregion
|
|
|
|
|
|
//region <<webaccess API>>
|
|
@@ -766,12 +787,13 @@ public class WebAccessService {
|
|
|
* 获取预制曲线
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<CirculateDTO> getYzcx() {
|
|
|
+ public List<CirculateDTO> getYzcx(List<String> duans) {
|
|
|
+ List<CirculateDTO> circulates = new ArrayList<>();
|
|
|
// 获取4个内部循环定义信息(启始段、结束段、次数)
|
|
|
- List<CirculateDTO> circulates = getNbxh();
|
|
|
+ circulates = getNbxh();
|
|
|
|
|
|
// 获取循环详细信息(温度、湿度、时间)
|
|
|
- getCxsd(circulates);
|
|
|
+ getCxsd(circulates, duans);
|
|
|
|
|
|
circulates.remove(circulates.size() - 1);
|
|
|
|
|
@@ -781,9 +803,10 @@ public class WebAccessService {
|
|
|
/**
|
|
|
* 获取循环详细信息(温度、湿度、时间)
|
|
|
* @param circulates 循环信息
|
|
|
+ * @param duans 段标识
|
|
|
* @return
|
|
|
*/
|
|
|
- private void getCxsd(List<CirculateDTO> circulates) {
|
|
|
+ private void getCxsd(List<CirculateDTO> circulates, List<String> duans) {
|
|
|
Integer allSecond = 0; // 累加的秒
|
|
|
|
|
|
// 循环获取信息
|
|
@@ -796,6 +819,9 @@ public class WebAccessService {
|
|
|
|
|
|
List<SectionDTO> sections = new ArrayList<>();
|
|
|
for (int i = circulates.get(j).getBeginsec(); i <= circulates.get(j).getEndsec(); i++) {
|
|
|
+ // 段标识
|
|
|
+ duans.add(i + "");
|
|
|
+
|
|
|
int xb = i + 1; // 下标
|
|
|
String cxd = (xb < 10 ? "0" + xb : "" + xb);
|
|
|
|
|
@@ -808,21 +834,23 @@ public class WebAccessService {
|
|
|
|
|
|
// 温度
|
|
|
tags.clear();
|
|
|
- waLogDTO.setTagname("程序温度设定区域" + cxd);
|
|
|
+ waLogDTO.setTagname("程序温度设定" + cxd);
|
|
|
tags.add(waLogDTO);
|
|
|
waparams = generateGetObject(tags);
|
|
|
- section.setTemperature(Float.parseFloat(getTagNameValues(waparams)));
|
|
|
+ Float temperature = Float.parseFloat(getTagNameValues(waparams));
|
|
|
+ section.setTemperature(temperature);
|
|
|
|
|
|
// 湿度
|
|
|
tags.clear();
|
|
|
- waLogDTO.setTagname("程序湿度设定区域" + cxd);
|
|
|
+ waLogDTO.setTagname("程序湿度设定" + cxd);
|
|
|
tags.add(waLogDTO);
|
|
|
waparams = generateGetObject(tags);
|
|
|
- section.setHumidity(Float.parseFloat(getTagNameValues(waparams)));
|
|
|
+ Float humidity = Float.parseFloat(getTagNameValues(waparams));
|
|
|
+ section.setHumidity(humidity);
|
|
|
|
|
|
// 分
|
|
|
tags.clear();
|
|
|
- waLogDTO.setTagname("程序时间设定区域_分" + cxd);
|
|
|
+ waLogDTO.setTagname("程序时间设定分" + cxd);
|
|
|
tags.add(waLogDTO);
|
|
|
waparams = generateGetObject(tags);
|
|
|
Integer minute = Integer.parseInt(getTagNameValues(waparams));
|
|
@@ -830,35 +858,38 @@ public class WebAccessService {
|
|
|
|
|
|
// 秒
|
|
|
tags.clear();
|
|
|
- waLogDTO.setTagname("程序时间设定区域_秒" + cxd);
|
|
|
+ waLogDTO.setTagname("程序时间设定秒" + cxd);
|
|
|
tags.add(waLogDTO);
|
|
|
waparams = generateGetObject(tags);
|
|
|
Integer second = Integer.parseInt(getTagNameValues(waparams));
|
|
|
section.setSecond(second);
|
|
|
|
|
|
- // 时间
|
|
|
- Long hourl = TimeUnit.SECONDS.toHours(allSecond);
|
|
|
- String hours = hourl + "";
|
|
|
- if (hourl == 0) {
|
|
|
- hours = "00";
|
|
|
- } else if (hourl > 0 && hourl < 10) {
|
|
|
- hours = "0" + hourl;
|
|
|
- }
|
|
|
- Long minutel = TimeUnit.SECONDS.toMinutes(allSecond % 3600);
|
|
|
- String minutes = minutel + "";
|
|
|
- if (minutel == 0) {
|
|
|
- minutes = "00";
|
|
|
- } else if (minutel > 0 && minutel < 10) {
|
|
|
- minutes = "0" + minutel;
|
|
|
+ // 虚拟一个开头,不然线不对
|
|
|
+ if (allSecond == 0) {
|
|
|
+ SectionDTO firstsection = new SectionDTO();
|
|
|
+ firstsection.setSecname(-1);
|
|
|
+ firstsection.setTemperature(temperature);
|
|
|
+ firstsection.setHumidity(humidity);
|
|
|
+ // 时间
|
|
|
+ firstsection.setTime("00:00");
|
|
|
+ allSecond += minute * 60 + second;
|
|
|
+
|
|
|
+ sections.add(firstsection);
|
|
|
}
|
|
|
- section.setTime(hours + ":" + minutes);
|
|
|
|
|
|
+ // 时间
|
|
|
+ section.setTime(generateTime(allSecond));
|
|
|
allSecond += minute * 60 + second;
|
|
|
|
|
|
sections.add(section);
|
|
|
}
|
|
|
if (sections != null && sections.size() > 0) {
|
|
|
- circulates.get(j).setBegintime(sections.get(0).getTime());
|
|
|
+ if (j == 0) {
|
|
|
+ circulates.get(j).setBegintime(sections.get(0).getTime());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ circulates.get(j).setBegintime(circulates.get(j - 1).getSections().get(circulates.get(j - 1).getSections().size() - 1).getTime());
|
|
|
+ }
|
|
|
circulates.get(j).setEndtime(sections.get(sections.size() - 1).getTime());
|
|
|
}
|
|
|
circulates.get(j).setSections(sections);
|
|
@@ -867,6 +898,28 @@ public class WebAccessService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 组合
|
|
|
+ */
|
|
|
+ private String generateTime(Integer allSecond) {
|
|
|
+ Long hourl = TimeUnit.SECONDS.toHours(allSecond);
|
|
|
+ String hours = hourl + "";
|
|
|
+ if (hourl == 0) {
|
|
|
+ hours = "00";
|
|
|
+ } else if (hourl > 0 && hourl < 10) {
|
|
|
+ hours = "0" + hourl;
|
|
|
+ }
|
|
|
+ Long minutel = TimeUnit.SECONDS.toMinutes(allSecond % 3600);
|
|
|
+ String minutes = minutel + "";
|
|
|
+ if (minutel == 0) {
|
|
|
+ minutes = "00";
|
|
|
+ } else if (minutel > 0 && minutel < 10) {
|
|
|
+ minutes = "0" + minutel;
|
|
|
+ }
|
|
|
+
|
|
|
+ return hours + ":" + minutes;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取4个内部循环定义信息(启始段、结束段、次数)
|
|
|
* @return
|
|
|
*/
|
|
@@ -1013,6 +1066,16 @@ public class WebAccessService {
|
|
|
* 获取最新一条报警信息
|
|
|
* @return
|
|
|
*/
|
|
|
+ public GuanRAlarm getLastAlarm() {
|
|
|
+ GuanRAlarm rAlarm = guanRAlarmMapper.selectTop1Alarm();
|
|
|
+
|
|
|
+ return rAlarm;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取最新一条报警信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public JSONArray getDashboardLastAlarm() {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
// 先获取报警信息数量
|
|
@@ -1049,4 +1112,52 @@ public class WebAccessService {
|
|
|
return jsonArray;
|
|
|
}
|
|
|
//endregion
|
|
|
+
|
|
|
+ //region <<组合获取到的大屏展示数据>>
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组合获取到的大屏展示数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String organizeDashData() {
|
|
|
+
|
|
|
+ log.info(String.format(" 获取设备实时值! 时间:" + DateUtils.getTimestamp()));
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+
|
|
|
+ // 设备实时值
|
|
|
+ JSONArray tagArray = getDashboardTagNameValues();
|
|
|
+ jsonObject.put("设备实时值", tagArray);
|
|
|
+
|
|
|
+ // 设备历史值
|
|
|
+ JSONArray logArray = getDashboardDataLog();
|
|
|
+ jsonObject.put("设备历史值", logArray);
|
|
|
+
|
|
|
+ // 最新一条报警信息
|
|
|
+ GuanRAlarm rAlarm = getLastAlarm();
|
|
|
+ jsonObject.put("最新一条报警信息", rAlarm);
|
|
|
+
|
|
|
+ // 预制曲线
|
|
|
+ List<String> duans = new ArrayList<>();
|
|
|
+ List<CirculateDTO> yzqxList = getYzcx(duans);
|
|
|
+ jsonObject.put("预制曲线", yzqxList);
|
|
|
+ jsonObject.put("预制曲线线段", duans);
|
|
|
+
|
|
|
+ return jsonObject.toString();
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ // region <<获取工艺流程图地址>>
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取工艺流程图地址
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getFlowUrl() {
|
|
|
+ String itemValue = getDictItemValue("2D3D页面");
|
|
|
+ String url = getDictItemDesc(itemValue + "D页面", "single");
|
|
|
+
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+ // endregion
|
|
|
}
|