|
@@ -1,16 +1,26 @@
|
|
|
package com.zcxk.smartcity.data.access.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.zcxk.smartcity.data.access.dao.DeviceCommandMapper;
|
|
|
import com.zcxk.smartcity.data.access.dao.DeviceValveRecordMapper;
|
|
|
+import com.zcxk.smartcity.data.access.dto.ConfigDataDto;
|
|
|
+import com.zcxk.smartcity.data.access.entity.Device;
|
|
|
+import com.zcxk.smartcity.data.access.entity.DeviceCommand;
|
|
|
import com.zcxk.smartcity.data.access.entity.DeviceValveRecord;
|
|
|
+import com.zcxk.smartcity.data.access.rabbitmq.model.RabbitCommandResult;
|
|
|
+import com.zcxk.smartcity.data.access.service.ConfigService;
|
|
|
import com.zcxk.smartcity.data.access.service.DeviceValveRecordService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.amqp.rabbit.connection.SimpleResourceHolder;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
public class DeviceValveRecordServiceImpl implements DeviceValveRecordService {
|
|
@@ -19,6 +29,10 @@ public class DeviceValveRecordServiceImpl implements DeviceValveRecordService {
|
|
|
private DeviceValveRecordMapper deviceValveRecordMapper;
|
|
|
@Resource
|
|
|
private DeviceCommandMapper deviceCommandMapper;
|
|
|
+ @Autowired
|
|
|
+ private ConfigService configService;
|
|
|
+ @Autowired
|
|
|
+ private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
@Override
|
|
|
public int insertSelective(DeviceValveRecord record) {
|
|
@@ -37,11 +51,22 @@ public class DeviceValveRecordServiceImpl implements DeviceValveRecordService {
|
|
|
@Transactional
|
|
|
public void updateCommandStatus(JSONObject jsonObject) {
|
|
|
String commandId = jsonObject.getString("relationId");
|
|
|
- String commandStatus = jsonObject.getString("status");
|
|
|
+ String status = jsonObject.getString("status");
|
|
|
String message = jsonObject.getString("message");
|
|
|
- deviceValveRecordMapper.updateCommandStatus(commandId,commandStatus,message);
|
|
|
+ deviceValveRecordMapper.updateCommandStatus(commandId,status,message);
|
|
|
+
|
|
|
+ Integer commandStatus = convertStatus(status);
|
|
|
+ int result = deviceCommandMapper.updateCommandStatus(commandId,commandStatus,message);
|
|
|
+
|
|
|
+ if(commandStatus !=null && commandStatus >0 && result > 0){
|
|
|
+ DeviceCommand deviceCommand = deviceCommandMapper.getDeviceCommand(commandId);
|
|
|
+ if (deviceCommand != null) {
|
|
|
+ if(this.matches(deviceCommand.getCustomerId())){
|
|
|
+ sendMsg(deviceCommand,commandId,commandStatus,message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- deviceCommandMapper.updateCommandStatus(commandId,convertStatus(commandStatus),message);
|
|
|
}
|
|
|
|
|
|
private Integer convertStatus(String commandStatus){
|
|
@@ -65,4 +90,31 @@ public class DeviceValveRecordServiceImpl implements DeviceValveRecordService {
|
|
|
if(StringUtils.equalsIgnoreCase("SENT",commandStatus))return 0;
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ private boolean matches(Integer customerId) {
|
|
|
+ List<ConfigDataDto> configDataList = configService.getConfigData("push_command_result_config");
|
|
|
+ if (configDataList != null && configDataList.size() > 0) {
|
|
|
+ for (ConfigDataDto configDataDto : configDataList) {
|
|
|
+ if(StringUtils.equals(configDataDto.getValue(),customerId.toString())){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendMsg(DeviceCommand deviceCommand,String commandId,Integer commandStatus,String message) {
|
|
|
+ RabbitCommandResult result = new RabbitCommandResult();
|
|
|
+ result.setRelationId(deviceCommand.getRelationId());
|
|
|
+ result.setCustomerId(deviceCommand.getCustomerId());
|
|
|
+ result.setCommandId(commandId);
|
|
|
+ result.setCommandStatus(commandStatus);
|
|
|
+ result.setRemark(message);
|
|
|
+ result.setFinishDate(LocalDateTime.now());
|
|
|
+
|
|
|
+
|
|
|
+ String jsonString = JSON.toJSONString(result);
|
|
|
+
|
|
|
+ rabbitTemplate.convertAndSend("command_result_exchange","command_result_queue", jsonString);
|
|
|
+ }
|
|
|
}
|