diff --git a/psdc-business/src/main/java/com/psdc/entity/PsdcStrategyLog.java b/psdc-business/src/main/java/com/psdc/entity/PsdcStrategyLog.java index 020ac09..31368e2 100644 --- a/psdc-business/src/main/java/com/psdc/entity/PsdcStrategyLog.java +++ b/psdc-business/src/main/java/com/psdc/entity/PsdcStrategyLog.java @@ -32,12 +32,25 @@ public class PsdcStrategyLog implements Serializable,Cloneable{ private Double inFrontAvgtemp ; /** 执行前室外平均温度 */ private Double outFrontAvgtemp ; + /** 模式策略执行结果 */ + private String strategyRunRes ; /** 执行后室内平均温度 */ private Double inAfterAvgtemp ; /** 执行后室外平均温度 */ private Double outAfterAvgtemp ; + private String allSceneCodes ; // 下属所有策略码 + private String runSceneCodes ; // 已执行策略码 private String runHours; // 策略执行时长 private String oneUseEnergy; // 单位时长用电 private Double sceneUseEnergy; // 总用电量 -} \ No newline at end of file + + public PsdcStrategyLog(Long strategyCode, String startTime, String allSceneCodes,Integer runtimeStatus, Double inFrontAvgtemp, Double outFrontAvgtemp) { + this.strategyCode = strategyCode; + this.startTime = startTime; + this.allSceneCodes = allSceneCodes; + this.runtimeStatus = runtimeStatus; + this.inFrontAvgtemp = inFrontAvgtemp; + this.outFrontAvgtemp = outFrontAvgtemp; + } + } \ No newline at end of file diff --git a/psdc-business/src/main/java/com/psdc/entity/res/AppInfoRes.java b/psdc-business/src/main/java/com/psdc/entity/res/AppInfoRes.java new file mode 100644 index 0000000..f9cdab9 --- /dev/null +++ b/psdc-business/src/main/java/com/psdc/entity/res/AppInfoRes.java @@ -0,0 +1,12 @@ +package com.psdc.entity.res; + +/** + * @Author:戴仕崑 + * @Project:psdc + * @Filename:AppInfoRes + * @Slogan 致敬大师,致敬未来的你 + * @Date:2023/7/4 13:49 + * @Version 1.0 + */ +public class AppInfoRes { +} diff --git a/psdc-business/src/main/java/com/psdc/mapper/PsdcElectricHtdataMapper.java b/psdc-business/src/main/java/com/psdc/mapper/PsdcElectricHtdataMapper.java index 84f80f8..39af0d6 100644 --- a/psdc-business/src/main/java/com/psdc/mapper/PsdcElectricHtdataMapper.java +++ b/psdc-business/src/main/java/com/psdc/mapper/PsdcElectricHtdataMapper.java @@ -47,7 +47,7 @@ public interface PsdcElectricHtdataMapper{ List statisticalGroupByTime(String dateTime); - PsdcElectricHtdata selThisHtDataGroupByTime(@Param(value = "deviceId") Integer deviceId); + List selThisHtDataGroupByTime(@Param(value = "deviceId") Integer deviceId); /** * 统计总行数 diff --git a/psdc-business/src/main/java/com/psdc/mapper/PsdcSceneMapper.java b/psdc-business/src/main/java/com/psdc/mapper/PsdcSceneMapper.java index 3e22ac7..ef2c0cc 100644 --- a/psdc-business/src/main/java/com/psdc/mapper/PsdcSceneMapper.java +++ b/psdc-business/src/main/java/com/psdc/mapper/PsdcSceneMapper.java @@ -114,4 +114,6 @@ public interface PsdcSceneMapper{ List queryScenes(@Param(value = "userId") Long userId, @Param(value = "sceneCode") Long sceneCode); + + List queryScenes2(@Param(value = "sceneCode") Long sceneCode); } \ No newline at end of file diff --git a/psdc-business/src/main/java/com/psdc/mapper/PsdcStrategyLogMapper.java b/psdc-business/src/main/java/com/psdc/mapper/PsdcStrategyLogMapper.java index dbe6f29..1df4ffe 100644 --- a/psdc-business/src/main/java/com/psdc/mapper/PsdcStrategyLogMapper.java +++ b/psdc-business/src/main/java/com/psdc/mapper/PsdcStrategyLogMapper.java @@ -19,6 +19,31 @@ import java.util.List; @Repository public interface PsdcStrategyLogMapper { + Long queryStrategyId(String sceneId); + List selMyStrategyLog(@Param("userId") Long userId); + PsdcStrategyLog selMyNewLog(@Param("userId") Long userId, + @Param("code") Long code); + + PsdcStrategyLog selNewLog(@Param("code") Long code); + + PsdcStrategyLog selMyRunLog(@Param("runSta") Integer runSta); + + /** + * 新增数据 + * + * @param psdcStrategyLog 实例对象 + * @return 影响行数 + */ + Integer InsertStrategyLog(PsdcStrategyLog psdcStrategyLog); + + Integer updateRunRes(@Param("Id") Integer Id, + @Param("endTime") String endTime, + @Param("runtimeStatus") Integer runtimeStatus, + @Param("runSceneCodes") String runSceneCodes, + @Param("strategyRunRes") String strategyRunRes, + @Param("inAfterAvgTemp") Double inAfterAvgTemp, + @Param("outAfterAvgTemp") Double outAfterAvgTemp); + } diff --git a/psdc-business/src/main/java/com/psdc/mqtt/savedata/DataAndPowerSave.java b/psdc-business/src/main/java/com/psdc/mqtt/savedata/DataAndPowerSave.java index 7734870..8b8c62c 100644 --- a/psdc-business/src/main/java/com/psdc/mqtt/savedata/DataAndPowerSave.java +++ b/psdc-business/src/main/java/com/psdc/mqtt/savedata/DataAndPowerSave.java @@ -2,12 +2,19 @@ package com.psdc.mqtt.savedata; import com.alibaba.fastjson2.JSONObject; import com.psdc.entity.*; +import com.psdc.entity.res.AppInfoRes; +import com.psdc.entity.res.PsdcSceneRes; +import com.psdc.entity.res.PsdcThermometerDataRes; import com.psdc.entity.vo.DeviceStatusVo; import com.psdc.mapper.*; +import com.psdc.utils.SecurityUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; /** * @Author:Stone @@ -30,6 +37,10 @@ public class DataAndPowerSave { @Resource PsdcDevicePowerHdata96Mapper devicePowerHtData96Mapper; @Resource + PsdcStrategyLogMapper psdcStrategyLogMapper; + @Resource + PsdcSceneMapper psdcSceneMapper; + @Resource PsdcThermometerRtdataMapper thermometerRtDataMapper; @Resource PsdcThermometerHtdataMapper thermometerHtDataMapper; @@ -40,10 +51,16 @@ public class DataAndPowerSave { @Resource PsdcStatisticsYearMapper statisticsYearMapper; - public Boolean saveDevRtData(JSONObject jsonObject){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH"); + + public Boolean saveDevRtData(JSONObject jsonObject) { Integer deviceId = jsonObject.getInteger("deviceId"); String timestamp = jsonObject.getString("timestamp"); JSONObject params = jsonObject.getJSONObject("params"); + Integer devStatus = 1; + Double InTemp = 0.0; + Double OutTemp = 0.0; + Double NowTemp = 0.0; // 时间处理 String date1 = timestamp.split("T")[0]; @@ -55,6 +72,10 @@ public class DataAndPowerSave { // 根据设备id获取数据,查看设备库中是否有该设备,若没有该设备,则不对该设备的数据进行实时数据库入库操作 DeviceStatusVo deviceStatusVo = deviceMapper.queryDeviceStatusById(deviceId); + if (null != params.getInteger("Sta")) { + devStatus = params.getInteger("Sta"); + } + // 计算点位 double cardNo = (hour * 60 + min) / 15.0; @@ -68,13 +89,13 @@ public class DataAndPowerSave { String valNo = "val" + countNo; if (deviceStatusVo != null) { - if (null != params.getFloat("P")){ + if (null != params.getFloat("P")) { double P = params.getFloat("P"); double TotWh = params.getFloat("TotWh"); PsdcElectricRtdata pert = new PsdcElectricRtdata(); pert.setDeviceId(deviceId); long count1 = electricRtDataMapper.count(pert); - if (count1 > 0){ + if (count1 > 0) { electricRtDataMapper.updateByDevId(deviceId, upDateTime, P, TotWh); } else { pert.setUpdateTime(upDateTime); @@ -86,8 +107,8 @@ public class DataAndPowerSave { peht.setDeviceId(deviceId); long count2 = electricHtDataMapper.count(peht); Double useEnergy; - if (count2 > 0){ - PsdcElectricHtdata htdata = electricHtDataMapper.selThisHtDataGroupByTime(deviceId); + if (count2 > 0) { + PsdcElectricHtdata htdata = electricHtDataMapper.selThisHtDataGroupByTime(deviceId).get(0); useEnergy = TotWh - htdata.getTotwh(); } else { useEnergy = TotWh; @@ -111,15 +132,15 @@ public class DataAndPowerSave { devicePowerHtData96Mapper.updateTodayDevPower(valNo, P, deviceId, samDate); } - if (null != params.getFloat("NowTemp")){ - double InTemp = params.getFloat("InTemp"); - double OutTemp = params.getFloat("OutTemp"); - double NowTemp = params.getFloat("NowTemp"); + if (null != params.getFloat("NowTemp")) { + InTemp = Double.valueOf(params.getFloat("InTemp")); + OutTemp = Double.valueOf(params.getFloat("OutTemp")); + NowTemp = Double.valueOf(params.getFloat("NowTemp")); PsdcThermometerRtdata ptrt = new PsdcThermometerRtdata(); ptrt.setDeviceId(deviceId); long count4 = thermometerRtDataMapper.count(ptrt); - if (count4 > 0){ + if (count4 > 0) { thermometerRtDataMapper.updateByDevId(deviceId, upDateTime, NowTemp, InTemp, OutTemp); } else { ptrt.setUpdateTime(upDateTime); @@ -137,10 +158,66 @@ public class DataAndPowerSave { thermometerHtDataMapper.insert(ptht); } - if (null != params.getInteger("Sta")){ - int devStatus = params.getInteger("Sta"); - deviceMapper.upDevStatus(devStatus(devStatus), deviceId); + deviceMapper.upDevStatus(devStatus(devStatus), deviceId); + + + // 查看是否有正在执行的策略 + PsdcStrategyLog strategyLog = psdcStrategyLogMapper.selMyRunLog(2); + + if (null != strategyLog) { + String[] split = strategyLog.getRunSceneCodes().split(","); + Long runCode = Long.parseLong(split[split.length - 1]); // 正在进行步骤 + String[] split2 = strategyLog.getAllSceneCodes().split(","); + Boolean b1 = false; + Boolean b2 = false; + List list = psdcSceneMapper.queryBySceneCode(Math.toIntExact(runCode)); + if (String.valueOf(deviceId).equals(String.valueOf(list.get(0).getDeviceId()))) { + if (split2.length == split.length) { + for (PsdcScene psc : list) { + b1 = isOk(psc.getSceneKey(), psc.getSceneValue(), devStatus, NowTemp, InTemp, OutTemp); + if (!b1) { + break; + } + } + if (b1){ + String runSta = strategyLog.getStrategyRunRes() + "1"; + Double[] s = getInTemp(date1 + " " + hour, "温度传感器", deviceId); + psdcStrategyLogMapper.updateRunRes(strategyLog.getId(), upDateTime, 1, null, runSta, s[0], s[1]); + + synchronized (AppInfoRes.class) { + AppInfoRes.class.notify(); + } + } + } else { + Integer nextCode = Integer.valueOf(split2[split.length]); + List list2 = psdcSceneMapper.queryScenes2(Long.valueOf(nextCode)); + for (PsdcScene psc : list) { + b1 = isOk(psc.getSceneKey(), psc.getSceneValue(), devStatus, NowTemp, InTemp, OutTemp); + if (!b1) { + break; + } + } + for (PsdcSceneRes psc : list2) { + b2 = isOk2(psc.getIsJudge(), psc.getJudgeDevice(), psc.getJudgeElement(), psc.getJudgeData(), date1); + if (!b2) { + break; + } + } + + if (b1 && b2) { + String runSta = strategyLog.getStrategyRunRes() + "1" + ","; + if (runSta.indexOf("null") >= 0) { + runSta = runSta.substring(4); + } + psdcStrategyLogMapper.updateRunRes(strategyLog.getId(), null, null, null, runSta, null, null); + synchronized (AppInfoRes.class) { + AppInfoRes.class.notify(); + } + } + } + } } + return true; } else { log.info("不存在该设备Id"); @@ -149,8 +226,8 @@ public class DataAndPowerSave { } - private Integer devStatus(int i){ - switch (i){ + private Integer devStatus(int i) { + switch (i) { case 0: return 4; case 1: @@ -160,4 +237,82 @@ public class DataAndPowerSave { } } + private Boolean isOk(String key, String value, Integer devStatus, Double temp, Double inTemp, Double outTemp) { + String s = String.valueOf(devStatus); + switch (key) { + case "open": + if (value.equals(s)) { + return true; + } + case "close": + if (value.equals(s)) { + return true; + } + case "temp": + if (temp >= Double.parseDouble(value)) { + return true; + } + case "intemp": + if (inTemp >= Double.parseDouble(value)) { + return true; + } + case "outtemp": + if (outTemp >= Double.parseDouble(value)) { + return true; + } + default: + return false; + } + } + + private Boolean isOk2(Integer isJudge, Integer judgeDevice, String judgeElement, String judgeData, String today) { + switch (isJudge) { + case 2: + return true; + case 1: + if (null != thermometerRtDataMapper.queryById(judgeDevice, today)) { + PsdcThermometerDataRes query = thermometerRtDataMapper.queryById(judgeDevice, today); + switch (judgeElement) { + case "thermometer_value": + if (query.getThermometerValue() >= Double.parseDouble(judgeData)) ; + return true; + case "thermometer_value_in": + if (query.getThermometerValueIn() >= Double.parseDouble(judgeData)) ; + return true; + case "thermometer_value_out": + if (query.getThermometerValueOut() >= Double.parseDouble(judgeData)) ; + return true; + } + } + default: + return false; + } + } + + public Double[] getInTemp(String dateTime, String s, Integer deviceId) { + Integer userId = deviceMapper.queryById(deviceId).getUserId(); + List dataResList = thermometerRtDataMapper.selWenDu(Long.valueOf(userId), s, dateTime); + Double[] ary = new Double[2]; + Double houseInTemp = 0.0; // 实验室内平均温度 + int countIn = 0; + Double houseOutTemp = 0.0; // 实验室外平均温度 + int countOut = 0; + if (dataResList.size() > 0 && null != dataResList) { + for (PsdcThermometerDataRes dsc : dataResList) { + if (dsc.getInstallAddress().contains("室内")) { + houseInTemp = houseInTemp + dsc.getThermometerValue(); + countIn = countIn + 1; + } + if (dsc.getInstallAddress().contains("室外")) { + houseOutTemp = houseOutTemp + dsc.getThermometerValue(); + countOut = countOut + 1; + } + + } + } + ary[0] = houseInTemp / countIn; + ary[1] = houseOutTemp / countOut; + return ary; + } + } diff --git a/psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java b/psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java index 9a7b2d0..79eb025 100644 --- a/psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java +++ b/psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java @@ -98,6 +98,8 @@ public interface IPsdcDeviceService { */ int setTemperature(Integer deviceId, List data, String controlBym,Integer controlMethod); + Integer setTemperature(Integer deviceId, Integer sceneCode, List data, String controlBym,Integer controlMethod); + Integer sceneControl(List jsonObjectList); /** diff --git a/psdc-business/src/main/java/com/psdc/service/IPsdcStrategyLogService.java b/psdc-business/src/main/java/com/psdc/service/IPsdcStrategyLogService.java index 91006c2..5699c64 100644 --- a/psdc-business/src/main/java/com/psdc/service/IPsdcStrategyLogService.java +++ b/psdc-business/src/main/java/com/psdc/service/IPsdcStrategyLogService.java @@ -1,5 +1,7 @@ package com.psdc.service; +import com.psdc.entity.PsdcStrategyLog; + import java.util.List; /** @@ -13,4 +15,6 @@ import java.util.List; public interface IPsdcStrategyLogService { List selMyStrategyLog(); + + PsdcStrategyLog selMyNewLog(Long code); } diff --git a/psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java b/psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java index 16043a9..5db6af4 100644 --- a/psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java +++ b/psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java @@ -1,9 +1,8 @@ package com.psdc.service.impl; import com.alibaba.fastjson2.JSONObject; -import com.psdc.entity.PsdcControlLog; -import com.psdc.entity.PsdcDevice; -import com.psdc.entity.PsdcScene; +import com.psdc.entity.*; +import com.psdc.entity.res.AppInfoRes; import com.psdc.entity.res.PsdcDeviceInfoRes; import com.psdc.entity.res.PsdcThermometerDataRes; import com.psdc.entity.vo.DeviceStatusVo; @@ -39,17 +38,26 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { @Resource private PsdcControlLogMapper psdcControlLogMapper; + @Resource + private PsdcStrategyLogMapper psdcStrategyLogMapper; + @Resource + private PsdcStrategyMapper psdcStrategyMapper; + @Resource private PsdcSceneMapper psdcSceneMapper; @Resource private PsdcModelMapper psdcModelMapper; + @Resource + PsdcThermometerRtdataMapper psdcThermometerRtdataMapper; @Resource private PsdcThermometerRtdataMapper thermometerRtdataMapper; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH"); + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + /** * 通过ID查询单条数据 * @@ -312,17 +320,59 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { AtomicInteger atomicInteger = new AtomicInteger(0); for (HashMap map : data) { - // 模式策略下属各场景步骤控制指令下发执行日志 + // 模式策略下属各场景步骤控制指令下发执行日志 String controlKey = map.get("controlKey").toString(); String controlValue = map.get("controlValue").toString(); - if (controlValue.equals("1") || controlValue.equals("2")){ + if (controlValue.equals("1") || controlValue.equals("2")) { controlValue = coverStr("r", Integer.parseInt(controlValue)); } String controlContext = ControlKeyEnum.getControlContext(controlKey); // TODO 发送MQTT指令 // MyMQTTClient myMQTTClient = new MyMQTTClient(); - // myMQTTClient.publish(jsonObject.toJSONString(),"/hwj1/dntd/request/action/command",2,false); + // myMQTTClient.publish(jsonObject.toJSONString(), "/hwj1/dntd/request/action/command", 2, false); + // psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,2,"控制成功",controlBy)); + // psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,3,"等待终端响应超时",controlBy)); + // 发送成功 + + psdcControlLogMapper.insert(new PsdcControlLog(deviceId, psdcDevice.getDeviceName(), psdcDevice.getDeviceSn(), controlContext, controlValue, controlMethod, 2, "控制成功", controlBy)); + atomicInteger.incrementAndGet(); + } + return atomicInteger.get(); + } + + @Override + public Integer setTemperature(Integer deviceId, Integer sceneCode, List data, String controlBy, Integer controlMethod) { + + + log.info("策略id:{}", sceneCode); + log.info("设备id:{}", deviceId); + log.info("控制指令:{}", data); + + + PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId); + if (psdcDevice == null) { + psdcControlLogMapper.insert(new PsdcControlLog(deviceId, null, null, "设定温度", null, controlMethod, 3, "未找到该设备", controlBy)); + throw new ControlException("控制失败,未找到该设备"); + } + if (psdcDevice.getIsControl() != 2) { + throw new ControlException("该设备无法控制,请联系管理员"); + } + + AtomicInteger atomicInteger = new AtomicInteger(0); + + for (HashMap map : data) { + // 模式策略下属各场景步骤控制指令下发执行日志 + String controlKey = map.get("controlKey").toString(); + String controlValue = map.get("controlValue").toString(); + if (controlValue.equals("1") || controlValue.equals("2")) { + controlValue = coverStr("r", Integer.parseInt(controlValue)); + } + String controlContext = ControlKeyEnum.getControlContext(controlKey); + + // TODO 发送MQTT指令 + // MyMQTTClient myMQTTClient = new MyMQTTClient(); + // myMQTTClient.publish(jsonObject.toJSONString(), "/hwj1/dntd/request/action/command", 2, false); // psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,2,"控制成功",controlBy)); // psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,3,"等待终端响应超时",controlBy)); // 发送成功 @@ -335,22 +385,86 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService { @Override public Integer sceneControl(List jsonObjectList) { - int count = 0; - for (JSONObject jsonObject : jsonObjectList) { - Integer sceneCode = jsonObject.getInteger("sceneCode"); - List sceneControlCommand = jsonObject.getList("sceneControlCommand", JSONObject.class); - for (JSONObject map : sceneControlCommand) { - // 解析到该策略下的每一个步骤 - Integer deviceId = map.getInteger("deviceId"); - List data = map.getList("data", HashMap.class); - int i = 0; - i = setTemperature(deviceId, data, SecurityUtils.getUsername(), 1); - if (i > 0) { - count++; + Date date = new Date(); + final int[] count = {0}; + int thisCode = jsonObjectList.get(0).getInteger("sceneCode"); + Long code = psdcStrategyLogMapper.queryStrategyId(thisCode + ","); + Double[] ary = getInTemp(date, "温度传感器"); + String userName = SecurityUtils.getUsername(); + PsdcStrategy psdcStrategy = psdcStrategyMapper.queryByUser(SecurityUtils.getUserId(), code).get(0); + + PsdcStrategyLog strategyLog = new PsdcStrategyLog(code, sdf2.format(new Date()), psdcStrategy.getScenes(), 2, ary[0], ary[1]); + psdcStrategyLogMapper.InsertStrategyLog(strategyLog); + + class ThreadTest extends Thread { + Object lock; + + public ThreadTest(Object lock) { + this.lock = lock; + } + + public void run() { + try { + synchronized (lock) { //在执行t1.wait()前,先让当前线程获取a的锁 + for (JSONObject jsonObject : jsonObjectList) { + Integer sceneCode = jsonObject.getInteger("sceneCode"); + PsdcStrategyLog newLog = psdcStrategyLogMapper.selNewLog(code); + // System.out.println("你好 (1) 世界: " + newLog); + List sceneControlCommand = jsonObject.getList("sceneControlCommand", JSONObject.class); + JSONObject map = sceneControlCommand.get(0); + Integer deviceId = map.getInteger("deviceId"); + List data = map.getList("data", HashMap.class); + int i = 0; + i = setTemperature(deviceId, sceneCode, data, userName, 1); + // System.out.println("你好 (2) 世界: " + sceneCode); + String sCode = newLog.getRunSceneCodes() + sceneCode + ","; + if (sCode.indexOf("null") >= 0){ + sCode = sCode.substring(4); + } + // System.out.println("你好 (3) 世界: " + sCode); + psdcStrategyLogMapper.updateRunRes(newLog.getId(), null, null, sCode, null, null, null); + if (i > 0) { + count[0]++; + } + // 线程休眠 + lock.wait(); + } + } + } catch (InterruptedException e) { + e.printStackTrace(); } } } - return count; + + ThreadTest t1 = new ThreadTest(AppInfoRes.class); + t1.start(); + + return 4; + } + + public Double[] getInTemp(Date date, String s) { + List dataResList = psdcThermometerRtdataMapper.selWenDu(SecurityUtils.getUserId(), s, sdf.format(date)); + Double[] ary = new Double[2]; + Double houseInTemp = 0.0; // 实验室内平均温度 + int countIn = 0; + Double houseOutTemp = 0.0; // 实验室外平均温度 + int countOut = 0; + if (dataResList.size() > 0 && null != dataResList) { + for (PsdcThermometerDataRes dsc : dataResList) { + if (dsc.getInstallAddress().contains("室内")) { + houseInTemp = houseInTemp + dsc.getThermometerValue(); + countIn = countIn + 1; + } + if (dsc.getInstallAddress().contains("室外")) { + houseOutTemp = houseOutTemp + dsc.getThermometerValue(); + countOut = countOut + 1; + } + + } + } + ary[0] = houseInTemp / countIn; + ary[1] = houseOutTemp / countOut; + return ary; } /** diff --git a/psdc-business/src/main/java/com/psdc/service/impl/PsdcStrategyLogService.java b/psdc-business/src/main/java/com/psdc/service/impl/PsdcStrategyLogService.java index 37bad5b..68d2914 100644 --- a/psdc-business/src/main/java/com/psdc/service/impl/PsdcStrategyLogService.java +++ b/psdc-business/src/main/java/com/psdc/service/impl/PsdcStrategyLogService.java @@ -70,12 +70,21 @@ public class PsdcStrategyLogService implements IPsdcStrategyLogService { return logList; } + @Override + public PsdcStrategyLog selMyNewLog(Long code) { + return strategyLogMapper.selMyNewLog(SecurityUtils.getUserId(), code); + } + public String jssc(SimpleDateFormat dfs, String start, String end){ try { Double d1 = Double.valueOf(dfs.parse(start).getTime()); Double d2 = Double.valueOf(dfs.parse(end).getTime()); Double between = (d2 - d1)/1000/3600; - return df.format(between); + String s = df.format(between); + if (".".equals(s.substring(0,1))){ + s= "0" + s; + } + return s; } catch (ParseException pe) { pe.printStackTrace(); return "0L"; diff --git a/psdc-business/src/main/resources/mapper/business/PsdcSceneMapper.xml b/psdc-business/src/main/resources/mapper/business/PsdcSceneMapper.xml index 0a1fcc3..22dd01c 100644 --- a/psdc-business/src/main/resources/mapper/business/PsdcSceneMapper.xml +++ b/psdc-business/src/main/resources/mapper/business/PsdcSceneMapper.xml @@ -221,5 +221,12 @@ Group By ps.scene_code - + \ No newline at end of file diff --git a/psdc-business/src/main/resources/mapper/business/PsdcStrategyLogMapper.xml b/psdc-business/src/main/resources/mapper/business/PsdcStrategyLogMapper.xml index 480bd9a..994b8f0 100644 --- a/psdc-business/src/main/resources/mapper/business/PsdcStrategyLogMapper.xml +++ b/psdc-business/src/main/resources/mapper/business/PsdcStrategyLogMapper.xml @@ -8,19 +8,74 @@ + + + + + Insert into psdc_strategy_log(strategy_code,start_time,end_time,all_scene_codes,run_scene_codes,runtime_status,in_front_avgtemp,out_front_avgtemp,in_after_avgtemp,out_after_avgtemp,strategy_run_res) + values (#{strategyCode},#{startTime},#{endTime},#{allSceneCodes},#{runSceneCodes},#{runtimeStatus},#{inFrontAvgtemp},#{outFrontAvgtemp},#{inAfterAvgtemp},#{outAfterAvgtemp},#{strategyRunRes}) + + + + + + + + + + + + Update psdc_strategy_log + + + end_time = #{endTime}, + + + runtime_status = #{runtimeStatus}, + + + strategy_run_res = #{strategyRunRes}, + + + run_scene_codes = #{runSceneCodes}, + + + in_after_avgtemp = #{inAfterAvgTemp}, + + + out_after_avgtemp = #{outAfterAvgTemp}, + + + + + And id = #{Id} + + + \ No newline at end of file diff --git a/psdc-web/src/main/java/com/psdc/controller/control/ManualController.java b/psdc-web/src/main/java/com/psdc/controller/control/ManualController.java index 2a8e960..5fd6680 100644 --- a/psdc-web/src/main/java/com/psdc/controller/control/ManualController.java +++ b/psdc-web/src/main/java/com/psdc/controller/control/ManualController.java @@ -11,14 +11,13 @@ import com.psdc.service.IPsdcDeviceService; import com.psdc.service.IPsdcSceneService; import com.psdc.utils.SecurityUtils; import lombok.extern.slf4j.Slf4j; -import org.aspectj.weaver.loadtime.Aj; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; -import java.util.Map; + @RestController @@ -144,13 +143,13 @@ public class ManualController extends BaseController { count++; } }*/ - if (count.equals(jsonObjectList.size())) { - return AjaxResult.success("控制成功"); - } else { - log.info("控制设备失败。返回数据库实际插入数据:{}",count); - return AjaxResult.error("策略控制执行失败,请联系管理员"); - } - +// if (count.equals(jsonObjectList.size())) { +// return AjaxResult.success("控制成功"); +// } else { +// log.info("控制设备失败。返回数据库实际插入数据:{}",count); +// return AjaxResult.error("策略控制执行失败,请联系管理员"); +// } + return AjaxResult.success("策略正在执行中,请耐心等待,感谢配合!"); } diff --git a/psdc-web/src/main/java/com/psdc/controller/evaluate/PsdcStrategyLogController.java b/psdc-web/src/main/java/com/psdc/controller/evaluate/PsdcStrategyLogController.java index e85fdb6..736e9e9 100644 --- a/psdc-web/src/main/java/com/psdc/controller/evaluate/PsdcStrategyLogController.java +++ b/psdc-web/src/main/java/com/psdc/controller/evaluate/PsdcStrategyLogController.java @@ -28,6 +28,12 @@ public class PsdcStrategyLogController{ List deviceStatusVos = psdcStrategyLogService.selMyStrategyLog(); return AjaxResult.success("策略执行日志列表").put("data",deviceStatusVos); } - + @PreAuthorize("@ss.hasPermi('control:manual:strategy')") + @PostMapping("/{strategyRes}") + public AjaxResult getMyStrategyLog(@RequestParam("strategyCode") Long strategyCode ){ + String s = psdcStrategyLogService.selMyNewLog(strategyCode).getStrategyRunRes(); + AjaxResult ajaxResult = new AjaxResult(200, "查询成功", s); + return ajaxResult; + } } \ No newline at end of file