kangwei:设备运行台时问题修改
正在显示
3 个修改的文件
包含
129 行增加
和
17 行删除
... | @@ -27,6 +27,10 @@ public class JSUtils { | ... | @@ -27,6 +27,10 @@ public class JSUtils { |
27 | String expression = obj1+ "-" + obj2; | 27 | String expression = obj1+ "-" + obj2; |
28 | return executeExpression(expression,"0.00"); | 28 | return executeExpression(expression,"0.00"); |
29 | } | 29 | } |
30 | public static String subtract(Object obj1 , Object obj2,Object obj3){ | ||
31 | String expression = obj1+ "-" + obj2 + "-" + obj3 ; | ||
32 | return executeExpression(expression,"0.00"); | ||
33 | } | ||
30 | public static String multiply(Object obj1 , Object obj2){ | 34 | public static String multiply(Object obj1 , Object obj2){ |
31 | String expression = obj1+ "*" + obj2; | 35 | String expression = obj1+ "*" + obj2; |
32 | return executeExpression(expression,"0.00"); | 36 | return executeExpression(expression,"0.00"); | ... | ... |
1 | package com.skua.modules.algorithm.vo; | 1 | package com.skua.modules.algorithm.vo; |
2 | 2 | ||
3 | import com.skua.core.util.ConvertUtils; | ||
4 | import com.skua.tool.util.JSUtils; | ||
3 | import io.swagger.annotations.ApiModel; | 5 | import io.swagger.annotations.ApiModel; |
4 | import io.swagger.annotations.ApiModelProperty; | 6 | import io.swagger.annotations.ApiModelProperty; |
5 | import lombok.Data; | 7 | import lombok.Data; |
8 | import netscape.javascript.JSUtil; | ||
6 | 9 | ||
7 | @Data | 10 | @Data |
8 | @ApiModel(value="指挥中心:运行负荷率分析:处理水量详情", description="指挥中心:运行负荷率分析:处理水量详情)") | 11 | @ApiModel(value="指挥中心:运行负荷率分析:处理水量详情", description="指挥中心:运行负荷率分析:处理水量详情)") |
... | @@ -25,35 +28,35 @@ public class WaterTreatmentVO { | ... | @@ -25,35 +28,35 @@ public class WaterTreatmentVO { |
25 | private Double dayCsl; | 28 | private Double dayCsl; |
26 | 29 | ||
27 | @ApiModelProperty(value = "环比:处理水量比例") | 30 | @ApiModelProperty(value = "环比:处理水量比例") |
28 | private Double hbcslbl; | 31 | private String hbcslbl; |
29 | @ApiModelProperty(value = "同比:处理水量比例") | 32 | @ApiModelProperty(value = "同比:处理水量比例") |
30 | private Double tbcslbl; | 33 | private String tbcslbl; |
31 | 34 | ||
32 | @ApiModelProperty(value = "负荷率") | 35 | @ApiModelProperty(value = "负荷率") |
33 | private Double fhl; | 36 | private String fhl; |
34 | 37 | ||
35 | @ApiModelProperty(value = "排名") | 38 | @ApiModelProperty(value = "排名") |
36 | private Integer rank; | 39 | private Integer rank; |
37 | 40 | ||
38 | private long monthDayNum = 30; | 41 | private long monthDayNum = 30; |
39 | 42 | ||
40 | public Double getFhl() { | 43 | public String getFhl() { |
41 | if(this.getCSL() != null && this.getProScale() != null && this.getProScale().doubleValue() > 0 ){ | 44 | if(this.getCSL() != null && this.getProScale() != null && this.getProScale().doubleValue() > 0 ){ |
42 | fhl = this.getCSL()*100 / (this.getProScale() * this.getMonthDayNum() ); | 45 | fhl = JSUtils.format( this.getCSL()*100 / (this.getProScale() * this.getMonthDayNum() ) ); |
43 | } | 46 | } |
44 | return fhl; | 47 | return fhl; |
45 | } | 48 | } |
46 | 49 | ||
47 | public Double getHbcslbl() { | 50 | public String getHbcslbl() { |
48 | if(this.getCSL() != null && this.getHbcsl() != null && this.getHbcsl().doubleValue() > 0){ | 51 | if(this.getCSL() != null && this.getHbcsl() != null && this.getHbcsl().doubleValue() > 0){ |
49 | hbcslbl = (this.getCSL() - this.getHbcsl()) * 100 / this.getHbcsl() ; | 52 | hbcslbl = JSUtils.format( (this.getCSL() - this.getHbcsl()) * 100 / this.getHbcsl()); |
50 | } | 53 | } |
51 | return hbcslbl; | 54 | return hbcslbl; |
52 | } | 55 | } |
53 | 56 | ||
54 | public Double getTbcslbl() { | 57 | public String getTbcslbl() { |
55 | if(this.getCSL() != null && this.getTbcsl() != null && this.getTbcsl().doubleValue() > 0){ | 58 | if(this.getCSL() != null && this.getTbcsl() != null && this.getTbcsl().doubleValue() > 0){ |
56 | tbcslbl = (this.getCSL() - this.getTbcsl())*100 / this.getTbcsl() ; | 59 | tbcslbl = JSUtils.format( (this.getCSL() - this.getTbcsl())*100 / this.getTbcsl()); |
57 | } | 60 | } |
58 | return tbcslbl; | 61 | return tbcslbl; |
59 | } | 62 | } | ... | ... |
... | @@ -12,10 +12,12 @@ import com.skua.modules.equipment.vo.EquipmentRealTimeVO; | ... | @@ -12,10 +12,12 @@ import com.skua.modules.equipment.vo.EquipmentRealTimeVO; |
12 | import com.skua.modules.erp.vo.MetricInfoVO; | 12 | import com.skua.modules.erp.vo.MetricInfoVO; |
13 | import com.skua.modules.erp.vo.RealTimeHistoryDataVO; | 13 | import com.skua.modules.erp.vo.RealTimeHistoryDataVO; |
14 | import com.skua.modules.guest.util.DateUtil; | 14 | import com.skua.modules.guest.util.DateUtil; |
15 | import com.skua.tool.util.JSUtils; | ||
15 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
16 | import io.swagger.annotations.ApiOperation; | 17 | import io.swagger.annotations.ApiOperation; |
17 | import org.apache.commons.lang.StringUtils; | 18 | import org.apache.commons.lang.StringUtils; |
18 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | import org.springframework.beans.factory.annotation.Value; | ||
19 | import org.springframework.dao.DataAccessException; | 21 | import org.springframework.dao.DataAccessException; |
20 | import org.springframework.jdbc.core.BeanPropertyRowMapper; | 22 | import org.springframework.jdbc.core.BeanPropertyRowMapper; |
21 | import org.springframework.jdbc.core.JdbcTemplate; | 23 | import org.springframework.jdbc.core.JdbcTemplate; |
... | @@ -23,6 +25,9 @@ import org.springframework.web.bind.annotation.GetMapping; | ... | @@ -23,6 +25,9 @@ import org.springframework.web.bind.annotation.GetMapping; |
23 | import org.springframework.web.bind.annotation.RequestMapping; | 25 | import org.springframework.web.bind.annotation.RequestMapping; |
24 | import org.springframework.web.bind.annotation.RequestParam; | 26 | import org.springframework.web.bind.annotation.RequestParam; |
25 | import org.springframework.web.bind.annotation.RestController; | 27 | import org.springframework.web.bind.annotation.RestController; |
28 | |||
29 | import java.text.ParseException; | ||
30 | import java.text.SimpleDateFormat; | ||
26 | import java.util.*; | 31 | import java.util.*; |
27 | 32 | ||
28 | @Api(tags="设备-设备运行台时报表") | 33 | @Api(tags="设备-设备运行台时报表") |
... | @@ -30,16 +35,20 @@ import java.util.*; | ... | @@ -30,16 +35,20 @@ import java.util.*; |
30 | @RequestMapping("/test/metricInfo") | 35 | @RequestMapping("/test/metricInfo") |
31 | public class TestMetricInfoController { | 36 | public class TestMetricInfoController { |
32 | 37 | ||
38 | @Value("${skua.collectionFrequency:}") | ||
39 | private String collectionFrequency; | ||
40 | |||
33 | @Autowired | 41 | @Autowired |
34 | private IFactoryInfoService iFactoryInfoService; | 42 | private IFactoryInfoService iFactoryInfoService; |
35 | 43 | ||
36 | 44 | ||
37 | @AutoLog(value = "设备-设备运行台时报表") | 45 | @AutoLog(value = "设备-设备运行台时报表") |
38 | @ApiOperation(value = "设备-设备运行台时报表", notes = "设备-设备运行台时报表") | 46 | @ApiOperation(value = "设备-设备运行台时报表(timeType:1 当日数据,=2表示月数据;=3表示年数据)", notes = "设备-设备运行台时报表") |
39 | @GetMapping(value = "/realTimeHistoryData") | 47 | @GetMapping(value = "/realTimeHistoryData") |
40 | public Result<RealTimeHistoryDataVO> equipRealTimeHistoryDataCtrl(@RequestParam(value = "departId") String departId, | 48 | public Result<RealTimeHistoryDataVO> equipRealTimeHistoryDataCtrl(@RequestParam(value = "departId") String departId, |
41 | @RequestParam(value = "startTime") String startTime, | 49 | @RequestParam(value = "startTime") String startTime, |
42 | @RequestParam(value = "endTime") String endTime) { | 50 | @RequestParam(value = "endTime") String endTime, |
51 | @RequestParam(value = "timeType",defaultValue = "1")String timeType) { | ||
43 | if(StringUtils.isEmpty(startTime)){ | 52 | if(StringUtils.isEmpty(startTime)){ |
44 | startTime = DateUtil.getCurrentDate() ; | 53 | startTime = DateUtil.getCurrentDate() ; |
45 | } | 54 | } |
... | @@ -52,7 +61,6 @@ public class TestMetricInfoController { | ... | @@ -52,7 +61,6 @@ public class TestMetricInfoController { |
52 | if(endTime != null && endTime.length() < 19){ | 61 | if(endTime != null && endTime.length() < 19){ |
53 | endTime = endTime+" 23:59:59"; | 62 | endTime = endTime+" 23:59:59"; |
54 | } | 63 | } |
55 | |||
56 | Result<RealTimeHistoryDataVO> result = new Result<>(); | 64 | Result<RealTimeHistoryDataVO> result = new Result<>(); |
57 | RealTimeHistoryDataVO realTimeHistoryDataVO = new RealTimeHistoryDataVO(); | 65 | RealTimeHistoryDataVO realTimeHistoryDataVO = new RealTimeHistoryDataVO(); |
58 | //String fields = "TCSWSCLC_PLC300_Tag182,TCSWSCLC_PLC300_Tag185"; | 66 | //String fields = "TCSWSCLC_PLC300_Tag182,TCSWSCLC_PLC300_Tag185"; |
... | @@ -68,7 +76,7 @@ public class TestMetricInfoController { | ... | @@ -68,7 +76,7 @@ public class TestMetricInfoController { |
68 | for(MetricInfoVO metricInfoVO : metricInfoVOList){ | 76 | for(MetricInfoVO metricInfoVO : metricInfoVOList){ |
69 | String equipmentName = metricInfoVO.getEquipmentName().replaceAll("[^\\u4e00-\\u9fa5]", ""); | 77 | String equipmentName = metricInfoVO.getEquipmentName().replaceAll("[^\\u4e00-\\u9fa5]", ""); |
70 | String equipmentCode = ChineseInital.getAllFirstLetter(equipmentName)+"_"+ RandomUtil.randomNumbers(2); | 78 | String equipmentCode = ChineseInital.getAllFirstLetter(equipmentName)+"_"+ RandomUtil.randomNumbers(2); |
71 | metricInfoVO.setEquipmentName(equipmentName ); | 79 | //metricInfoVO.setEquipmentName(equipmentName ); |
72 | metricInfoVO.setEquipmentCode(equipmentCode ); | 80 | metricInfoVO.setEquipmentCode(equipmentCode ); |
73 | if(StringUtils.isNotEmpty(metricInfoVO.getGzExpress())){ | 81 | if(StringUtils.isNotEmpty(metricInfoVO.getGzExpress())){ |
74 | fields += metricInfoVO.getGzExpress()+","; | 82 | fields += metricInfoVO.getGzExpress()+","; |
... | @@ -85,9 +93,10 @@ public class TestMetricInfoController { | ... | @@ -85,9 +93,10 @@ public class TestMetricInfoController { |
85 | if (fields.endsWith(",")) { | 93 | if (fields.endsWith(",")) { |
86 | fields = fields.substring(0, fields.length() - 1); | 94 | fields = fields.substring(0, fields.length() - 1); |
87 | } | 95 | } |
88 | List<Map<String, Object>> pgDataList = iFactoryInfoService.queryFactoryInfos(departId, fields, startTime, endTime, "1"); | 96 | List<Map<String, Object>> pgDataList = queryFactoryInfos(departId, fields, startTime, endTime, timeType); |
89 | 97 | ||
90 | List<Map<String, Object>> dataList = null; | 98 | List<Map<String, Object>> dataList = null; |
99 | |||
91 | if(pgDataList != null ) { | 100 | if(pgDataList != null ) { |
92 | dataList = new ArrayList<>(pgDataList.size()); | 101 | dataList = new ArrayList<>(pgDataList.size()); |
93 | Map<String, Object> dataMap = null; | 102 | Map<String, Object> dataMap = null; |
... | @@ -95,11 +104,19 @@ public class TestMetricInfoController { | ... | @@ -95,11 +104,19 @@ public class TestMetricInfoController { |
95 | String equipmentCode = null; | 104 | String equipmentCode = null; |
96 | for (Map<String, Object> paramMap : pgDataList) { | 105 | for (Map<String, Object> paramMap : pgDataList) { |
97 | dataMap = new HashMap<>(); | 106 | dataMap = new HashMap<>(); |
107 | dataMap.put("time",paramMap.get("time") ); | ||
108 | if(timeType.equals( "1")){ | ||
98 | dataMap.put("time",DateUtils.formatTime(Long.parseLong(paramMap.get("time") + "000")) ); | 109 | dataMap.put("time",DateUtils.formatTime(Long.parseLong(paramMap.get("time") + "000")) ); |
110 | } | ||
99 | for(MetricInfoVO metricInfoVO : metricInfoVOList){ | 111 | for(MetricInfoVO metricInfoVO : metricInfoVOList){ |
100 | dataMap.put( metricInfoVO.getEquipmentCode()+"_YX" , ConvertUtils.getString(paramMap.get(metricInfoVO.getYxExpress())));//运行 | 112 | dataMap.put( metricInfoVO.getEquipmentCode()+"_YX" , JSUtils.format(paramMap.get(metricInfoVO.getYxExpress()),"0.00"));//运行 |
101 | dataMap.put( metricInfoVO.getEquipmentCode()+"_GZ" , ConvertUtils.getString(paramMap.get(metricInfoVO.getGzExpress())));//故障 | 113 | dataMap.put( metricInfoVO.getEquipmentCode()+"_GZ" , JSUtils.format(paramMap.get(metricInfoVO.getGzExpress()),"0.00"));//故障 |
102 | dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,60 - ConvertUtils.getDouble(paramMap.get(metricInfoVO.getYxExpress()),0) - ConvertUtils.getDouble(paramMap.get(metricInfoVO.getGzExpress()) ,0) );//暂停 | 114 | //时数据 |
115 | if (timeType.equals("1")) dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停 | ||
116 | //日数据 | ||
117 | if (timeType.equals("2")) dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 24*60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停 | ||
118 | //月数据 | ||
119 | if (timeType.equals("3")) dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 30*24*60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停 | ||
103 | } | 120 | } |
104 | 121 | ||
105 | dataList.add( dataMap ); | 122 | dataList.add( dataMap ); |
... | @@ -138,4 +155,92 @@ public class TestMetricInfoController { | ... | @@ -138,4 +155,92 @@ public class TestMetricInfoController { |
138 | return result; | 155 | return result; |
139 | } | 156 | } |
140 | 157 | ||
158 | public List<Map<String, Object>> queryFactoryInfos(String departId, String fields, String startTime, String endTime, String tableType) { | ||
159 | String fieldSqlPart = ""; | ||
160 | String[] fieldsArr = fields.split(","); | ||
161 | |||
162 | for(int i = 0; i < fieldsArr.length; ++i) { | ||
163 | fieldSqlPart = fieldSqlPart + ",'" + fieldsArr[i] + "'"; | ||
164 | } | ||
165 | |||
166 | if (!StringUtils.isEmpty(fieldSqlPart)) { | ||
167 | fieldSqlPart = fieldSqlPart.substring(1); | ||
168 | } | ||
169 | |||
170 | JdbcTemplate pgDB = (JdbcTemplate)SpringContextUtils.getBean("pg-db"); | ||
171 | JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master"); | ||
172 | List<Map<String, Object>> result = new ArrayList(); | ||
173 | List<Map<String, Object>> factoryDesign = masterDB.queryForList("select * from sys_factory_device where depart_id = '" + departId + "'"); | ||
174 | if (factoryDesign != null && factoryDesign.size() != 0) { | ||
175 | String countTableName = ConvertUtils.getString(((Map)factoryDesign.get(0)).get("device_id")); | ||
176 | String sql = null; | ||
177 | //时数据 | ||
178 | if (tableType.equals("1")) { | ||
179 | sql = "select ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>=? and ts <? "; | ||
180 | } | ||
181 | //日数据 | ||
182 | if (tableType.equals("2")) { | ||
183 | sql = "select aaa.date as time , aaa.monitorId ,SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) )as monitorValue from ("; | ||
184 | sql += "select to_char(to_timestamp(ts::INT8)::DATE,'YYYY-MM-DD') as date, ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>=? and ts <? "; | ||
185 | sql += " )aaa group by aaa.date ,aaa.monitorId order by aaa.date asc"; | ||
186 | } | ||
187 | //月数据 | ||
188 | if (tableType.equals("3")) { | ||
189 | sql = "select aaa.date as time , aaa.monitorId ,SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) )as monitorValue from ("; | ||
190 | sql += "select to_char(to_timestamp(ts::INT8)::DATE,'YYYY-MM') as date, ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>=? and ts <? "; | ||
191 | sql += " )aaa group by aaa.date ,aaa.monitorId order by aaa.date asc"; | ||
192 | } | ||
193 | try { | ||
194 | String tsStartTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(startTime, "yyyy-MM-dd HH:mm:ss")) / 1000L); | ||
195 | String tsEndTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(endTime, "yyyy-MM-dd HH:mm:ss")) / 1000L); | ||
196 | List dataList = null; | ||
197 | try { | ||
198 | dataList = pgDB.queryForList(sql, new Object[]{tsStartTime, tsEndTime}); | ||
199 | } catch (DataAccessException var23) { | ||
200 | Object pgDbSlaveObject = SpringContextUtils.getBean("pg-db-slave"); | ||
201 | if (pgDbSlaveObject != null) { | ||
202 | pgDB = (JdbcTemplate)pgDbSlaveObject; | ||
203 | dataList = pgDB.queryForList(sql, new Object[]{tsStartTime, tsEndTime}); | ||
204 | } | ||
205 | } | ||
206 | this.dataRowToCellByTime(result, dataList); | ||
207 | } catch (Exception var24) { | ||
208 | var24.printStackTrace(); | ||
209 | } | ||
210 | |||
211 | return result; | ||
212 | } else { | ||
213 | return result; | ||
214 | } | ||
215 | } | ||
216 | private List<Map<String, Object>> dataRowToCellByTime(List<Map<String, Object>> result, List<Map<String, Object>> dataList) { | ||
217 | List<String> orderTsList = new ArrayList(); | ||
218 | Map<String, Map<String, Object>> resultMap = new HashMap(); | ||
219 | Iterator var5 = dataList.iterator(); | ||
220 | |||
221 | while(true) { | ||
222 | while(var5.hasNext()) { | ||
223 | Map<String, Object> tempMap = (Map)var5.next(); | ||
224 | String key = tempMap.get("time").toString(); | ||
225 | Map<String, Object> fieldDataMap = (Map)resultMap.get(key); | ||
226 | if (fieldDataMap != null && fieldDataMap.size() != 0) { | ||
227 | fieldDataMap.put(tempMap.get("monitorId").toString(), tempMap.get("monitorValue")); | ||
228 | } else { | ||
229 | orderTsList.add(key); | ||
230 | fieldDataMap = new HashMap(); | ||
231 | fieldDataMap.put(tempMap.get("monitorId").toString(), tempMap.get("monitorValue")); | ||
232 | resultMap.put(key, fieldDataMap); | ||
233 | } | ||
234 | } | ||
235 | var5 = orderTsList.iterator(); | ||
236 | while(var5.hasNext()) { | ||
237 | String order = (String)var5.next(); | ||
238 | Map<String, Object> map = (Map)resultMap.get(order); | ||
239 | map.put("time", order); | ||
240 | result.add(map); | ||
241 | } | ||
242 | |||
243 | return result; | ||
244 | } | ||
245 | } | ||
141 | } | 246 | } | ... | ... |
-
请 注册 或 登录 后发表评论