@ -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 ;