From 4b22356c609bbcc7aa7c5bfea1c740ba196973b2 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 09 十月 2024 18:34:47 +0800
Subject: [PATCH] 过程参数用数据点

---
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/ProcessParameterServiceImpl.java     |  130 ++++++++++++++++++++-
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/vo/ShiftUpdateVO.java                             |   22 +++
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.java           |    4 
 smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateStateFeedbackMapper.xml |    6 
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IEfficiencyAnalysisService.java           |    6 +
 smart-man-boot/src/main/java/com/qianwen/smartman/common/config/MdcMqttConfig.java                              |   32 ++++-
 smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.xml       |   14 +-
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IProcessParameterService.java             |    3 
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/dto/ProcessParameterVO.java                       |    4 
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java  |    1 
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ProcessParameterHelperService.java        |  119 +++++++++++++++++++
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/WorkstationWcsController.java          |    5 
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/ShiftController.java                   |    4 
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ISuperAggregateStateService.java          |    8 +
 14 files changed, 325 insertions(+), 33 deletions(-)

diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/common/config/MdcMqttConfig.java b/smart-man-boot/src/main/java/com/qianwen/smartman/common/config/MdcMqttConfig.java
index 632bb43..9c140cf 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/common/config/MdcMqttConfig.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/common/config/MdcMqttConfig.java
@@ -2,6 +2,7 @@
 
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Map;
 import java.util.Random;
 
 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
@@ -113,11 +114,11 @@
         		String payload = (String)message.getPayload();
         		logger.info("鎺ユ敹鍒癿qtt娑堟伅readtime,data={}",payload);//娑堟伅浣撳浣曞畾涔夛紝鏁版嵁鐐瑰悕绉帮紝鍊硷紝鏃堕棿锛岀敤json瀵硅薄浼犺繃鏉�
         		//TelemetryDataMessage result = TelemetryDataUtils.handleTelemetryDataMessage(telemetryDataMessage, workStationItem);
-        		JSONObject data = JSONObject.parseObject(payload);
-        		long workstationId = data.getLong("workstationId");
-        		String name = data.getString("name");//key锛�
-        		long time = data.getLong("time");
-        		String v = data.getString("value");
+        		JSONObject payLoadJson = JSONObject.parseObject(payload);
+        		long workstationId = payLoadJson.getLong("workstationId");
+        		String name = payLoadJson.getString("name");//key锛�
+        		long time = payLoadJson.getLong("time");
+        		String v = payLoadJson.getString("value");
         		
         		//灏嗘暟鎹姞鍏ョ紦瀛�
         		TelemetryDataResponseDTO telemetryDataResponseDTO = new TelemetryDataResponseDTO(v, time);
@@ -126,15 +127,32 @@
                 //鍙戦�亀ebsocket娑堟伅
                 RealTimeDaraResponseJsonWebSocketMessage jsonWebSocketMessage = new RealTimeDaraResponseJsonWebSocketMessage();
                 jsonWebSocketMessage.setId(""+workstationId);
+                /*
                 jsonWebSocketMessage.setData(new HashMap<String, Object>() { // from class: org.springblade.modules.cps.message.consumer.TelemetryDataRealTimeConsumer.1
                     {
                         put(name, telemetryDataResponseDTO);
                     }
                 });
+                */
+                
+                Map<String, Object> map = WorkstationCache.getWorkstationRealTime(workstationId+"");
+                jsonWebSocketMessage.setData(map);
                 //RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
                 MessageDO messageDO = new MessageDO();
-                messageDO.setNeedBroadcast(Boolean.FALSE);
-                messageDO.setMessageText(JSONUtil.toJsonStr(jsonWebSocketMessage));
+                messageDO.setNeedBroadcast(false);
+                String msgtxt =JSONUtil.toJsonStr(jsonWebSocketMessage);
+                logger.info("websockettxt={}",msgtxt);
+                messageDO.setMessageText(msgtxt);
+                /*
+                JSONObject testMsg = new JSONObject();
+                
+                JSONObject msgdata = JSONObject.parseObject(JSONUtil.toJsonStr(map));
+                testMsg.put("data", msgdata);
+                testMsg.put("id", workstationId+"");
+                String msgtxt = testMsg.toJSONString();
+                */
+                
+               
                 messageDistributor.distribute(messageDO);
                 
         	}
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/ShiftController.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/ShiftController.java
index 6a7b94b..5df4e0c 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/ShiftController.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/ShiftController.java
@@ -62,14 +62,14 @@
 
     @PreAuth
     @PutResource
-    @ApiOperation("缂栬緫鐗堟妯″瀷")
+    @ApiOperation("缂栬緫鐝妯″瀷")
     public R<ShiftModelVO> updateShift(@Validated @RequestBody ShiftUpdateVO shiftUpdateVO) {
         return R.data(ShiftConvert.INSTANCE.convert(this.shiftModelService.update(shiftUpdateVO)));
     }
 
     @PreAuth
     @PutResource({"/updateBasic"})
-    @ApiOperation("缂栬緫鐗堟妯″瀷鍩虹淇℃伅")
+    @ApiOperation("缂栬緫鐝妯″瀷鍩虹淇℃伅")
     public R<ShiftModelVO> updateShiftBasic(@RequestBody ShiftUpdateBasicVO shiftUpdateBasicVO) {
         return R.data(ShiftConvert.INSTANCE.convert(this.shiftModelService.updateShiftBasic(shiftUpdateBasicVO)));
     }
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/WorkstationWcsController.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/WorkstationWcsController.java
index ad22a08..5a2300d 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/WorkstationWcsController.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/WorkstationWcsController.java
@@ -38,6 +38,11 @@
         this.machineService = machineService;
     }
 
+    /**
+     * 灏辨槸宸ヤ綅鐣岄潰 閰嶇疆宸ヤ綅閲囬泦 淇濆瓨鐨勶紝杩欎釜搴旇涓嶈浜嗭紝鎴戜滑鏀逛负鏁版嵁鐐归厤缃簡
+     * @param workstationWcsSaveVOList
+     * @return
+     */
     @PreAuth
     @PostResource({"/save"})
     @ApiOperation("鏂板鎴栨洿鏀瑰伐鍐靛弬鏁颁俊鎭�")
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/vo/ShiftUpdateVO.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/vo/ShiftUpdateVO.java
index cf66cf0..8f90fc5 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/vo/ShiftUpdateVO.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/vo/ShiftUpdateVO.java
@@ -14,6 +14,11 @@
     private Long id;
     @ApiModelProperty("鐝鏁伴噺")
     private Integer shiftNumber;
+    @ApiModelProperty("鐝埗鍚嶇О")
+    private String name;
+    @ApiModelProperty("鐝埗棰滆壊")
+    private String colour;
+    
     @ApiModelProperty("鐝鏃ュ紑濮嬫椂闂�")
     private Integer startTime;
     @ApiModelProperty("鐝鏃ョ粨鏉熸椂闂�")
@@ -193,4 +198,21 @@
     public List<ShiftDetailDTO> getShiftDetailDTOList() {
         return this.shiftDetailDTOList;
     }
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getColour() {
+		return colour;
+	}
+
+	public void setColour(String colour) {
+		this.colour = colour;
+	}
+    
 }
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/dto/ProcessParameterVO.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/dto/ProcessParameterVO.java
index 92b7534..04d0235 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/dto/ProcessParameterVO.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/dto/ProcessParameterVO.java
@@ -103,11 +103,13 @@
     }
 
     public Long getRealTime() {
+    	return this.realTime;
+    	/*
     	if(this.time != null) {
     		return this.time.getTime();
     	}else {
     		return null;
-    	}
+    	}*/
     }
 
     public String getCollectItem() {
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.java
index 7752abd..733c37f 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.java
@@ -53,7 +53,7 @@
      * @return
      */
     //ProcessParameterVO oldFirstStatue(@Param("workstationId") String workstationId, @Param("item") String item, @Param("startTime") Long startTime);
-    LastProcessParam lastParameterLessThanTime(@Param("workstationId") Long workstationId, @Param("item") String item, @Param("startTime") Long startTime);
+    //LastProcessParam lastParameterLessThanTime(@Param("workstationId") Long workstationId, @Param("item") String item, @Param("startTime") Long startTime);
     
     /**
      * 
@@ -63,7 +63,7 @@
      * @return
      */
     //ProcessParameterVO oldLastStatue(@Param("workstationId") String workstationId, @Param("item") String item, @Param("endTime") Long endTime);
-    LastProcessParam lastParameterGreaterThanTime(@Param("workstationId") Long workstationId, @Param("item") String item, @Param("endTime") Long endTime);
+    //LastProcessParam lastParameterGreaterThanTime(@Param("workstationId") Long workstationId, @Param("item") String item, @Param("endTime") Long endTime);
     
     
     
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IEfficiencyAnalysisService.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IEfficiencyAnalysisService.java
index 1603ef4..4704fe8 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IEfficiencyAnalysisService.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IEfficiencyAnalysisService.java
@@ -10,6 +10,12 @@
 import com.qianwen.smartman.modules.mdc.vo.StatisticsVO;
 
 public interface IEfficiencyAnalysisService {
+	/**
+	 * 鎵ц鏁堢巼鍒嗘瀽锛岃緭鍑虹粨鏋滃璞�
+	 * @param statisticsAnalysisQueryVO
+	 * @param query
+	 * @return
+	 */
     StatisticsVO efficiencyAnalysis(StatisticsAnalysisQueryVO statisticsAnalysisQueryVO, Query query);
 
     List<ColumnInfoVO> getIntervalDate(QueryIntervalDateVO queryIntervalDateVO);
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IProcessParameterService.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IProcessParameterService.java
index cc856fb..32345b2 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IProcessParameterService.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IProcessParameterService.java
@@ -7,6 +7,7 @@
 import com.qianwen.smartman.modules.cps.dto.WorkstationWcsDmpDTO;
 import com.qianwen.smartman.modules.cps.entity.GlobalWcs;
 import com.qianwen.smartman.modules.mdc.dto.ProcessParameterRealVO;
+import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO;
 import com.qianwen.smartman.modules.mdc.entity.WorkstationCollectData;
 import com.qianwen.smartman.modules.mdc.vo.AllShiftTimeDetail;
 import com.qianwen.smartman.modules.mdc.vo.CollectParamResVO;
@@ -61,4 +62,6 @@
      * @return
      */
     List<WorkstationCollectData> queryLastParameter(long workstationId);
+    
+   
 }
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ISuperAggregateStateService.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ISuperAggregateStateService.java
index 2e62203..fff19f3 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ISuperAggregateStateService.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ISuperAggregateStateService.java
@@ -18,6 +18,14 @@
 	 */
     List<SuperAggregateState> getStatusData(List<Long> workstationIds, StatisticalMethodEnum statisticalMethod, LocalDate startDate, LocalDate endDate);
 
+    /**
+     * 绋煎姩鐜囨暟鎹煡璇�
+     * @param workstationIds
+     * @param statisticalMethod
+     * @param startDate
+     * @param endDate
+     * @return
+     */
     List<SuperAggregateState> getStatusDataWithFeedback(List<Long> workstationIds, StatisticalMethodEnum statisticalMethod, LocalDate startDate, LocalDate endDate);
 
     List<SuperAggregateState> getStatusByCondition(List<Long> workstationIds, LocalDateTime startTime, LocalDateTime endTime);
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ProcessParameterHelperService.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ProcessParameterHelperService.java
new file mode 100644
index 0000000..618c106
--- /dev/null
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/ProcessParameterHelperService.java
@@ -0,0 +1,119 @@
+package com.qianwen.smartman.modules.mdc.service;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO;
+
+@DS("iotdb")
+@Service
+public class ProcessParameterHelperService {
+    private static final Logger log = LoggerFactory.getLogger(ProcessParameterHelperService.class);
+    
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+    
+	@DS("iotdb")
+	public ProcessParameterVO queryLastParameterLessThenTime(long workstationId,String item,Long time) {
+		/**
+		 *tdengine瀹炵幇锛歰ldFirstStatue
+		 * select last(ts) as realTime,
+               last(v)  as value_collect
+        from iot_data.super_collect_data
+        where n = #{item}
+          and ts &lt; #{startTime}
+          and workstation_id = #{workstationId}
+		 */
+		ProcessParameterVO vo = null;
+		String sql ="select max_time(n) as ts,last_value(n) as n,last_value(v) as v,last_value(workstation_id) as workstationId from root.f2.process_param_"+workstationId+"_"+item+" where time<"+time+" limit 1 align by device";
+		List<ProcessParameterVO> list =  jdbcTemplate.query(sql, new RowMapper<ProcessParameterVO>() {
+
+			@Override
+			public ProcessParameterVO mapRow(ResultSet rs, int rowNum) throws SQLException {
+				ProcessParameterVO p = new ProcessParameterVO();
+				Long time = rs.getLong("ts");
+				p.setRealTime(time);
+				p.setCollectItem(rs.getString("n"));
+				p.setValueCollect(rs.getString("v"));
+				
+				return p;
+			}
+			
+		});
+		if(!list.isEmpty()) {
+			vo = list.get(0);
+		}
+		return vo;
+	}
+	
+	/**
+	 * 鑾峰彇宸ヤ綅鏈�鏂板弬鏁板��(閲囬泦鏃堕棿搴斿ぇ浜庢寚瀹氭椂闂�)
+	 * @param workstationId
+	 * @param item  鍙傛暟鍚嶇О,濡侱eviceStatus/Output
+	 * @param time 鎸囧畾鐨勬椂闂�
+	 * @return
+	 */
+	@DS("iotdb")
+	public ProcessParameterVO getLastParameterGreaterThenTime(long workstationId,String item,Long time) {
+		/*
+		 oldLastStatue
+        select last(ts) as realTime,
+               last(v)  as value_collect
+        from iot_data.super_collect_data
+        where n = #{item}
+          and ts &gt; #{endTime}
+          and workstation_id = #{workstationId}
+		 * */
+		/*
+		LastProcessParam lp = this.parameterMapper.lastParameterGreaterThanTime(workstationId,item,time);
+		if(lp == null) {
+			return null;
+		}
+		ProcessParameterVO vo = new ProcessParameterVO();
+		//瑙f瀽json涓哄璞″垪琛�
+		JSONObject paramsObj = JSONObject.parseObject(lp.getParamJson());
+		
+		if(paramsObj.containsKey(item)) {
+			JSONObject itemObj = paramsObj.getJSONObject(item);
+			
+			Long lastTime = itemObj.getLong("time");
+			vo.setTime(new Timestamp(lastTime));
+			vo.setRealTime(lastTime);
+			vo.setValueCollect(itemObj.getString("value"));
+		}
+		
+		return vo;*/
+		
+		ProcessParameterVO vo = null;
+		String sql ="select max_time(n) as ts,last_value(n) as n,last_value(v) as v,last_value(workstation_id) as workstationId from root.f2.process_param_"+workstationId+"_"+item+" where time>"+time+" limit 1 align by device";
+		List<ProcessParameterVO> list =  jdbcTemplate.query(sql, new RowMapper<ProcessParameterVO>() {
+
+			@Override
+			public ProcessParameterVO mapRow(ResultSet rs, int rowNum) throws SQLException {
+				ProcessParameterVO p = new ProcessParameterVO();
+				p.setRealTime(rs.getLong("ts"));
+				p.setCollectItem(rs.getString("n"));
+				p.setValueCollect(rs.getString("v"));
+				
+				return p;
+			}
+			
+		});
+		if(!list.isEmpty()) {
+			vo = list.get(0);
+		}
+		return vo;
+		
+		
+	}
+
+}
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/ProcessParameterServiceImpl.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/ProcessParameterServiceImpl.java
index 0ce4edc..0386232 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/ProcessParameterServiceImpl.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/ProcessParameterServiceImpl.java
@@ -1,7 +1,9 @@
 package com.qianwen.smartman.modules.mdc.service.impl;
 
 import cn.hutool.core.lang.Tuple;
+import cn.hutool.core.util.ObjectUtil;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -49,8 +51,10 @@
 import com.qianwen.smartman.modules.cps.entity.Workstation;
 import com.qianwen.smartman.modules.cps.service.ICalendarService;
 import com.qianwen.smartman.modules.cps.service.IWorkstationService;
+import com.qianwen.smartman.modules.cps.service.WorkstationDatapointsService;
 import com.qianwen.smartman.modules.cps.utils.ThrowFun;
 import com.qianwen.smartman.modules.cps.vo.ShiftTimeDetailVO;
+import com.qianwen.smartman.modules.cps.vo.WorkstationDatapointsVO;
 import com.qianwen.smartman.modules.mdc.dto.GroupWorkDTO;
 import com.qianwen.smartman.modules.mdc.dto.NewParamDTO;
 import com.qianwen.smartman.modules.mdc.dto.ParamDTO;
@@ -65,6 +69,7 @@
 import com.qianwen.smartman.modules.mdc.mapper.SuperCollectJsonMapper;
 import com.qianwen.smartman.modules.mdc.mapper.SuperProcessParameterMapper;
 import com.qianwen.smartman.modules.mdc.service.IProcessParameterService;
+import com.qianwen.smartman.modules.mdc.service.ProcessParameterHelperService;
 import com.qianwen.smartman.modules.mdc.utils.ExcelStrategyUtil;
 import com.qianwen.smartman.modules.mdc.vo.AllShiftTimeDetail;
 import com.qianwen.smartman.modules.mdc.vo.CollectParamResVO;
@@ -99,6 +104,11 @@
     private ICalendarService calendarService;
     @Autowired
     private JdbcTemplate jdbcTemplate;
+    @Autowired
+    private WorkstationDatapointsService dpService;
+    
+    @Autowired
+    private ProcessParameterHelperService helperService;
     /*
     public ProcessParameterServiceImpl(final SuperCollectJsonMapper collectJsonMapper, final IWorkstationService workstationService, final OssBuilder ossBuilder, final SuperProcessParameterMapper parameterMapper, final ICalendarService calendarService) {
         this.collectJsonMapper = collectJsonMapper;
@@ -157,13 +167,45 @@
 
     @Override
     public List<WorkstationWcsDmpDTO> processParam(String workstationId) {
+    	/*
         List<WorkstationWcsDmpDTO> vos =WorkstationCache.getWorkstationWcsList(workstationId).stream().filter((v0) -> {
             return v0.getProcessParameter();
         }).collect(Collectors.toList());
         if (Func.isEmpty(vos)) {
             return Lists.newArrayList();
         }
-        return vos;
+        return vos;*/
+    	
+    	//鑾峰彇灞曠ず鍦ㄨ繃绋嬪弬鏁颁腑鐨勫彉閲�
+        List<WorkstationWcsDmpDTO> dps = new ArrayList<>();
+        if(ObjectUtil.isEmpty(workstationId)) {
+        	return Collections.emptyList(); 
+        }
+        WorkstationDatapointsVO dpVo = dpService.getDatapoints(Long.parseLong(workstationId));
+        if(ObjectUtil.isEmpty(dpVo.getDpConfig())) {
+        	return Collections.emptyList();
+        }
+        
+        JSONArray dpArrJson = JSONArray.parseArray(dpVo.getDpConfig());
+        
+        String dpName;
+        JSONObject dp;
+        for(int i=0; i<dpArrJson.size();i++) {
+        	dp = dpArrJson.getJSONObject(i);
+        	WorkstationWcsDmpDTO dto = new WorkstationWcsDmpDTO();
+        	dto.setDescription(dp.getString("dpLabel"));
+        	
+        	dpName = dp.getString("dpName");
+        	dto.setName(dpName);
+        	
+        	if("DeviceStatus".equals(dpName)) {
+        		dto.setWcsDataType(WcsDataTypeEnums.WcsDataType.STATE.getCode());
+        	}else if("Output".equals(dpName)) {
+        		dto.setWcsDataType(WcsDataTypeEnums.WcsDataType.YIELD.getCode());
+        	}
+        	dps.add(dto);
+        }
+        return dps;
     }
 
     @Override
@@ -221,7 +263,9 @@
     }
 
     private CollectParamResVO<?> getCollectParamResVO(WorkstationWcsDmpDTO dmpDTO, List<ProcessParameterVO> processParameterList) {
-        if (WcsDataTypeEnums.WcsDataType.STATE.getCode().equals(dmpDTO.getWcsDataType())) {
+    	//鐘舵�佺壒娈婂鐞嗭紵
+        //if (WcsDataTypeEnums.WcsDataType.STATE.getCode().equals(dmpDTO.getWcsDataType())) {//yys
+    	if (WcsDataTypeEnums.WcsDataType.STATE.getCode().equals(dmpDTO.getWcsDataType())) {
             Map<String, String> colorMap = Maps.newHashMap();
             Map<String, String> nameMap = Maps.newHashMap();
             Set<String> codes = Sets.newHashSet();
@@ -240,6 +284,7 @@
                     .build();
             //return CollectParamResVO.builder().collectItem(dmpDTO.getDescription()).collectRealItem(dmpDTO.getName()).data(list).build();
         }
+        //绌烘寚閽�
         List<ParamDTO> collect = processParameterList.stream().map(param -> ParamDTO.builder().time(DateUtil.formatDateTime(DateUtil.fromMilliseconds(param.getRealTime().longValue()))).value(param.getValue()).build()).collect(Collectors.toList());
         return CollectParamResVO.<ParamDTO>builder()
           .collectItem(dmpDTO.getDescription())
@@ -274,10 +319,11 @@
     private List<ProcessParameterVO> getProcessParameterList(Date startTime, Date endTime, Long workstationId, WorkstationWcsDmpDTO dmpDTO) {
         ProcessParameterVO firstStatue = oldFirstStatue(startTime, dmpDTO.getName(), workstationId);
         ProcessParameterVO endStatue = oldLastStatue(endTime, dmpDTO.getName(), workstationId);
+        
         List<ProcessParameterVO> processParameterList = oldOneCollectList(startTime, endTime, dmpDTO.getName(), workstationId);
         if (Func.isNotEmpty(processParameterList)) {
             if (Func.notNull(firstStatue) && !firstStatue.getRealTime().equals(Long.valueOf(startTime.getTime()))) {
-                firstStatue.setRealTime(Long.valueOf(startTime.getTime()));
+                firstStatue.setRealTime(startTime.getTime());
                 processParameterList.add(0, firstStatue);
             }
             if (Func.notNull(endStatue) && !endStatue.getRealTime().equals(Long.valueOf(endTime.getTime()))) {
@@ -533,7 +579,7 @@
 
     private ProcessParameterVO oldFirstStatue(Date startTime, String item, Long workstationId) {
         //ProcessParameterVO vo = this.parameterMapper.oldFirstStatue(workstationId, item, Long.valueOf(startTime.getTime()));
-        ProcessParameterVO vo = this.getLastParameterLessThanTime(workstationId, item, startTime.getTime());
+        ProcessParameterVO vo = helperService.queryLastParameterLessThenTime(workstationId, item, startTime.getTime());
         if (Func.notNull(vo)) {
             vo.setCollectItem(item);
         }
@@ -542,7 +588,7 @@
 
     private ProcessParameterVO oldLastStatue(Date endTime, String item, Long workstationId) {
         //ProcessParameterVO vo = this.parameterMapper.oldLastStatue(workstationId, item, Long.valueOf(endTime.getTime()));
-    	ProcessParameterVO vo = this.getLastParameterGreaterThenTime(workstationId, item, Long.valueOf(endTime.getTime()));
+    	ProcessParameterVO vo = helperService.getLastParameterGreaterThenTime(workstationId, item, endTime.getTime());
         if (Func.notNull(vo)) {
             vo.setCollectItem(item);
         }
@@ -550,7 +596,9 @@
     }
 
     private List<ProcessParameterVO> oldOneCollectList(Date startTime, Date endTime, String item, Long workstationId) {
-        return this.parameterMapper.oldOneCollectList(workstationId, item, Long.valueOf(startTime.getTime()), Long.valueOf(endTime.getTime()));
+    	List<ProcessParameterVO> list = this.parameterMapper.oldOneCollectList(workstationId, item, startTime.getTime(), endTime.getTime());
+    	list.forEach(p -> {p.setRealTime(p.getTime().getTime());});
+        return list;
     }
 
     private ProcessParameterResVO entityVO(List<ProcessParameterVO> dtoList, WorkstationWcsDmpDTO wcs, Map<String, WorkstationWcsDmpDTO> collectItemMap) {
@@ -696,8 +744,9 @@
 	 * @param time 鏃堕棿锛屽弬鏁板簲灏忎簬璇ユ椂闂�
 	 * @return
 	 */
-	public ProcessParameterVO getLastParameterLessThanTime(long workstationId,String item,Long time) {
-		//yys
+    /*
+	public ProcessParameterVO getLastParameterLessThanTimeOld_notuse(long workstationId,String item,Long time) {
+		//yys 
 		LastProcessParam lp = this.parameterMapper.lastParameterLessThanTime(workstationId,item,time);
 		if(lp == null) {
 			return null;
@@ -716,6 +765,36 @@
 		}
 		
 		return vo;
+	}*/
+	@DS("iotdb")
+	public ProcessParameterVO queryLastParameterLessThenTime1(long workstationId,String item,Long time) {
+		/**
+		 *tdengine瀹炵幇锛歰ldFirstStatue
+		 * select last(ts) as realTime,
+               last(v)  as value_collect
+        from iot_data.super_collect_data
+        where n = #{item}
+          and ts &lt; #{startTime}
+          and workstation_id = #{workstationId}
+		 */
+		ProcessParameterVO vo = null;
+		String sql ="select max_time(n) as ts,last_value(n) as n,last_value(v) as v,last_value(workstation_id) as workstationId from root.f2.process_param_"+workstationId+"_"+item+" where time<"+time+" align by device limit 1";
+		List<ProcessParameterVO> list =  jdbcTemplate.query(sql, new RowMapper<ProcessParameterVO>() {
+
+			@Override
+			public ProcessParameterVO mapRow(ResultSet rs, int rowNum) throws SQLException {
+				ProcessParameterVO p = new ProcessParameterVO();
+				p.setRealTime(rs.getLong("ts"));
+				p.setValueCollect(rs.getString("v"));
+				
+				return p;
+			}
+			
+		});
+		if(!list.isEmpty()) {
+			vo = list.get(0);
+		}
+		return vo;
 	}
 	
 	/**
@@ -725,8 +804,18 @@
 	 * @param time 鎸囧畾鐨勬椂闂�
 	 * @return
 	 */
-	public ProcessParameterVO getLastParameterGreaterThenTime(long workstationId,String item,Long time) {
-		//yys
+	@DS("iotdb")
+	public ProcessParameterVO getLastParameterGreaterThenTime1(long workstationId,String item,Long time) {
+		/*
+		 oldLastStatue
+        select last(ts) as realTime,
+               last(v)  as value_collect
+        from iot_data.super_collect_data
+        where n = #{item}
+          and ts &gt; #{endTime}
+          and workstation_id = #{workstationId}
+		 * */
+		/*
 		LastProcessParam lp = this.parameterMapper.lastParameterGreaterThanTime(workstationId,item,time);
 		if(lp == null) {
 			return null;
@@ -744,7 +833,28 @@
 			vo.setValueCollect(itemObj.getString("value"));
 		}
 		
+		return vo;*/
+		
+		ProcessParameterVO vo = null;
+		String sql ="select max_time(n) as ts,last_value(n) as n,last_value(v) as v,last_value(workstation_id) as workstationId from root.f2.process_param_"+workstationId+"_"+item+" where time>"+time+" align by device limit 1";
+		List<ProcessParameterVO> list =  jdbcTemplate.query(sql, new RowMapper<ProcessParameterVO>() {
+
+			@Override
+			public ProcessParameterVO mapRow(ResultSet rs, int rowNum) throws SQLException {
+				ProcessParameterVO p = new ProcessParameterVO();
+				p.setRealTime(rs.getLong("ts"));
+				p.setValueCollect(rs.getString("v"));
+				
+				return p;
+			}
+			
+		});
+		if(!list.isEmpty()) {
+			vo = list.get(0);
+		}
 		return vo;
+		
+		
 	}
 
 	@DS("iotdb")
diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java
index be6c444..33c8ae2 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java
@@ -71,7 +71,6 @@
     @Override
     public List<SuperAggregateState> getStatusDataWithFeedback(List<Long> workstationIds, StatisticalMethodEnum statisticalMethod, LocalDate startDate, LocalDate endDate) {
     	//绋煎姩鐜囨煡璇�
-    	 
         List<SuperAggregateState> statusDataList;
         if (StatisticalMethodEnum.SHIFT.equals(statisticalMethod) || StatisticalMethodEnum.DAY.equals(statisticalMethod) || StatisticalMethodEnum.WEEK.equals(statisticalMethod) || StatisticalMethodEnum.MONTH.equals(statisticalMethod)) {
             //statusDataList = this.aggregateStateFeedbackMapper.getStatusDataByFactoryDate(workstationIds, LocalDateTimeUtil.format(startDate, "yyyyMMdd"), LocalDateTimeUtil.format(endDate, "yyyyMMdd"));
diff --git a/smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateStateFeedbackMapper.xml b/smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateStateFeedbackMapper.xml
index 41c7981..24adb30 100644
--- a/smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateStateFeedbackMapper.xml
+++ b/smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateStateFeedbackMapper.xml
@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qianwen.smartman.modules.mdc.mapper.SuperAggregateStateFeedbackMapper">
 
-
+	<!-- 
     <sql id="superAggregateStateColumnSql">
         ts as startTime,
         end_time as endTime,
@@ -22,7 +22,7 @@
         is_plan as isPlan,
         feedback_id as feedbackId
     </sql>
-
+ -->
 	<!-- 淇敼sql寮�濮� -->
 	
 	<sql id="aggregateStateColumnSql">
@@ -44,7 +44,7 @@
         feedback_id as feedbackId
     </sql>
     
-	<!-- 鐢变簬琛ㄦ暟鎹竴鏍凤紙iot_data.super_aggregate_state_with_feedback锛夛紝鎴戜滑涔熸病鏈夊弽棣堬紝鎵�浠ユ殏鏃堕兘鏌ヤ竴涓〃 -->
+	
 	<select id="getStatusData" resultType="com.qianwen.smartman.modules.mdc.entity.SuperAggregateState">
         select
         <include refid="aggregateStateColumnSql"/>
diff --git a/smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.xml b/smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.xml
index 6bec479..82bf9cc 100644
--- a/smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.xml
+++ b/smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.xml
@@ -154,28 +154,28 @@
     
   
      <!-- 鏍规嵁oldFirstStatue 鏀归�犵殑-->
+     <!--
     <select id="lastParameterLessThanTime" resultType="com.qianwen.smartman.modules.mdc.entity.LastProcessParam">
         select workstation_id as workstationId,update_time as updateTime, param_json as paramJson 
         from root.f2.last_process_param
         where n = #{item} 
           and time &lt; #{startTime}
           and workstation_id = #{workstationId}
-    </select>
+    </select> -->
     <!-- 鏍规嵁oldLastStatue鏀圭殑 -->
+    <!-- 
     <select id="lastParameterGreaterThanTime" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
         select workstation_id as workstationId,update_time as updateTime, param_json as paramJson 
         from root.f2.last_process_param
         where n = #{item}
           and ts &gt; #{endTime}
           and workstation_id = #{workstationId}
-    </select>
+    </select> -->
     <select id="oldOneCollectList" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
-        select n as collectItem,v  as valueCollect
-        from root.f2.process_param_*
-        where n = #{item}
-          and time &gt;= #{startTime}
+        select n as collectItem,v as valueCollect
+        from root.f2.process_param_${workstationId}_${item}
+        where time &gt;= #{startTime}
           and time &lt;= #{endTime}
-          and workstation_id = #{workstationId}
         order by time
         align by device
     </select>

--
Gitblit v1.9.3