2023-05-30 14:07:36 优化完善获取设备状态列表接口,增加设备当前实时温度数据!

master
魔神煜修罗皇 2 years ago
parent aed2729a2b
commit 6cf8d965a3
  1. 9
      psdc-business/src/main/java/com/psdc/mapper/PsdcThermometerRtdataMapper.java
  2. 38
      psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java
  3. 15
      psdc-business/src/main/resources/mapper/business/PsdcElectricRtdataMapper.xml
  4. 12
      psdc-business/src/main/resources/mapper/business/PsdcThermometerRtdataMapper.xml

@ -66,4 +66,13 @@ public interface PsdcThermometerRtdataMapper{
* @return 影响行数
*/
int deleteById(Integer thermometerRtdataId);
/**
* 根据设备Id查询单设备实时温度数据
* @param deviceId
* @param upDateHour
* @return
*/
PsdcThermometerDataRes selTempByDevId(@Param(value = "deviceId") Integer deviceId,
@Param(value = "upDateHour") String upDateHour);
}

@ -4,18 +4,17 @@ import com.psdc.entity.PsdcControlLog;
import com.psdc.entity.PsdcDevice;
import com.psdc.entity.PsdcScene;
import com.psdc.entity.res.PsdcDeviceInfoRes;
import com.psdc.entity.res.PsdcThermometerDataRes;
import com.psdc.entity.vo.DeviceStatusVo;
import com.psdc.entity.vo.ModelVo;
import com.psdc.enums.ControlKeyEnum;
import com.psdc.exception.ControlException;
import com.psdc.mapper.PsdcControlLogMapper;
import com.psdc.mapper.PsdcDeviceMapper;
import com.psdc.mapper.PsdcModelMapper;
import com.psdc.mapper.PsdcSceneMapper;
import com.psdc.mapper.*;
import com.psdc.mqtt.MyMQTTClient;
import com.psdc.service.IPsdcDeviceService;
import com.psdc.utils.SecurityUtils;
import com.psdc.utils.poi.ExcelUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@ -24,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ -46,6 +46,11 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
@Resource
private PsdcModelMapper psdcModelMapper;
@Resource
private PsdcThermometerRtdataMapper thermometerRtdataMapper;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
/**
* 通过ID查询单条数据
*
@ -59,6 +64,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
/**
* 根据用户id查询设备列表
*
* @return 设备列表
*/
public List<PsdcDevice> queryByUserId(Integer parent) {
@ -76,15 +82,33 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
}
public List<DeviceStatusVo> queryDeviceStatus() {
Date data = new Date();
List<PsdcDevice> psdcDevices = psdcDeviceMapper.selDevicesByUserId(SecurityUtils.getUserId());
for (PsdcDevice pd : psdcDevices) {
String deviceModel = pd.getDeviceModel();
Integer deviceId = pd.getDeviceId();
List<Map> ary = new ArrayList<>();
List<ModelVo> list = psdcModelMapper.selDevIsControlByModelName(deviceModel);
for (ModelVo mv : list) {
PsdcThermometerDataRes thermometerDataRes = thermometerRtdataMapper.selTempByDevId(deviceId, sdf.format(data));
Map<String, Object> map = new HashMap<>();
Double tempValue = 0.0;
map.put("controlElement", mv.getRelationField());
map.put("controlRemark", mv.getIoDesc());
if (null != thermometerDataRes) {
switch (mv.getRelationField()) {
case "intemp":
tempValue = thermometerDataRes.getThermometerValueIn();
break;
case "outtemp":
tempValue = thermometerDataRes.getThermometerValueOut();
break;
case "temp":
tempValue = thermometerDataRes.getThermometerValue();
break;
}
}
map.put("tempValue", tempValue);
ary.add(map);
}
pd.setControl_elements(ary);
@ -215,6 +239,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
/**
* 控制设备启动停止
*
* @param deviceId 主键
* @param runStatus 状态
* @return 条数
@ -311,7 +336,6 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
}
//TODO 发送MQTT指令
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,value,controlMethod,2,"控制成功",controlBy));
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,value,controlMethod,3,"等待终端响应超时",controlBy));
@ -323,6 +347,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
/**
* 执行策略
*
* @param strategyCode 策略码
* @return
*/
@ -342,8 +367,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
Boolean flag = Boolean.FALSE;
//TODO 发送MQTT指令
flag = Boolean.TRUE;
if (flag)
{
if (flag) {
//发送成功
int insert = psdcControlLogMapper.insert(new PsdcControlLog(psdcScene.getDeviceId(), deviceName, psdcScene.getDeviceSn(), controlContext, controlValue, 3, 2, "控制成功", SecurityUtils.getUsername()));
success = success + insert;

@ -55,7 +55,8 @@
<!-- 通过ID查询单条数据 -->
<select id="queryById" resultMap="PsdcElectricRtdataMap2">
Select TotP, TotWh, ptr.thermometer_value, ptr.thermometer_value_in, ptr.thermometer_value_out, pd.device_runstatus
Select TotP, TotWh, ptr.thermometer_value, ptr.thermometer_value_in, ptr.thermometer_value_out,
pd.device_runstatus
From psdc_device pd
Left Join psdc_electric_rtdata per On per.device_id = pd.device_id
Left Join psdc_thermometer_rtdata ptr On ptr.device_id = pd.device_id
@ -339,9 +340,13 @@ totwh}
<!--新增数据-->
<insert id="insert">
insert into psdc_electric_rtdata(electric_rtdata_id,device_id,update_time,Ua,Ub,Uc,Ia,Ib,Ic,Pa,Pb,Pc,TotP,Qa,Qb,Qc,TotQ,PFa,PFb,PFc,TotPF,SupWh,RtlWh,SupQh,RtlQh,Sa,Sb,Sc,TotS,
insert into psdc_electric_rtdata(electric_rtdata_id, device_id, update_time, Ua, Ub, Uc, Ia, Ib, Ic, Pa, Pb, Pc,
TotP, Qa, Qb, Qc, TotQ, PFa, PFb, PFc, TotPF, SupWh, RtlWh, SupQh, RtlQh, Sa,
Sb, Sc, TotS,
TotWh, TotWh_1, TotWh_2, TotWh_3, TotWh_4, HZ, Uab, Ubc, Uca, CombWh, CombQh)
values (#{electricRtdataId},#{deviceId},#{updateTime},#{ua},#{ub},#{uc},#{ia},#{ib},#{ic},#{pa},#{pb},#{pc},#{totp},#{qa},#{qb},#{qc},#{totq},#{pfa},#{pfb},#{pfc},#{totpf},#{supwh},#{rtlwh},#{supqh},#{rtlqh},#{sa},#{sb},#{sc},#{tots},#{
values (#{electricRtdataId}, #{deviceId}, #{updateTime}, #{ua}, #{ub}, #{uc}, #{ia}, #{ib}, #{ic}, #{pa}, #{pb},
#{pc}, #{totp}, #{qa}, #{qb}, #{qc}, #{totq}, #{pfa}, #{pfb}, #{pfc}, #{totpf}, #{supwh}, #{rtlwh},
#{supqh}, #{rtlqh}, #{sa}, #{sb}, #{sc}, #{tots}, #{
totwh}, #{totwh1}, #{totwh2}, #{totwh3}, #{totwh4}, #{hz}, #{uab}, #{ubc}, #{uca}, #{combwh}, #{combqh})
</insert>
@ -479,6 +484,8 @@ totwh},
<!--通过主键删除-->
<delete id="deleteById">
delete from psdc_electric_rtdata where electric_rtdata_id = #{electricRtdataId}
delete
from psdc_electric_rtdata
where electric_rtdata_id = #{electricRtdataId}
</delete>
</mapper>

@ -97,6 +97,18 @@
</where>
</select>
<select id="selTempByDevId" resultMap="PsdcThermometerRtdataMap2">
Select device_id, thermometer_value, thermometer_value_in, thermometer_value_out From psdc_thermometer_rtdata
<where>
<if test="deviceId != null and deviceId != ''">
And device_id = ${deviceId}
</if>
<if test="upDateHour != null and upDateHour != ''">
And DATE_FORMAT(update_time,'%Y-%m-%d %H') = #{upDateHour}
</if>
</where>
</select>
<!--新增数据-->
<insert id="insert" >
insert into psdc_thermometer_rtdata(thermometer_rtdata_id,device_id,thermometer_value,thermometer_value_in,thermometer_value_out,update_time)

Loading…
Cancel
Save