Commit 3731de6d by 111-PC\111

[+]代码规范

1 parent 45f34fdd
......@@ -77,9 +77,8 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.3.RELEASE</version>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-feign</artifactId>
</dependency>
</dependencies>
<build>
......
......@@ -4,6 +4,7 @@ import com.glsx.plat.context.EnableRestAdmin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
......@@ -15,6 +16,7 @@ import tk.mybatis.spring.annotation.MapperScan;
*/
@EnableRestAdmin
@EnableDiscoveryClient
@EnableFeignClients
@EnableTransactionManagement
@MapperScan(basePackages = "cn.com.glsx.consumer.mapper")
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
......
......@@ -8,15 +8,19 @@ import cn.com.glsx.consumer.entity.MessageVO;
import cn.com.glsx.consumer.service.InfoService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
@Slf4j
public class TuyaComsumer implements CommandLineRunner {
@Resource
private InfoService infoService;
@Value("${pulsar.serviceUrl}")
private String serviceUrl;
......@@ -35,9 +39,6 @@ public class TuyaComsumer implements CommandLineRunner {
@Value("${pulsar.subscriptionName}")
private String subscriptionName;
@Autowired
private InfoService infoService;
@Override
public void run(String... args) throws Exception {
MqConsumer mqConsumer = MqConsumer.build().serviceUrl(serviceUrl).accessId(accessId).accessKey(accessKey).topic(topic).subscriptionName(subscriptionName)
......
......@@ -8,7 +8,6 @@ import java.util.function.Predicate;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台统一对外接口
*/
public interface ConditionStrategy {
......
......@@ -5,16 +5,13 @@ import cn.com.glsx.consumer.entity.AqaraEventDetail;
import cn.com.glsx.consumer.entity.DeviceStatus;
import cn.com.glsx.consumer.entity.DeviceStatusDetail;
import cn.com.glsx.consumer.entity.DeviceVo;
import cn.com.glsx.consumer.utils.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
......@@ -25,25 +22,25 @@ import java.util.List;
@Service
public class DeviceEventService {
@Autowired
@Resource
private InfoService infoService;
@Autowired
@Resource
private DeviceService deviceService;
/**
* 处理事件消息
*
* @param aqaraEvent
* @param aqaraEvent 入参
*/
public void processDevMessage(AqaraEvent aqaraEvent) {
List<AqaraEventDetail> data = aqaraEvent.getData();
if (CollectionUtils.isNotEmpty(data)) {
data.forEach(index -> {
String event = index.getEvent();
if(event.equals("GW_BIND")||event.equals("SUB_DEV_BIND")){
if(("GW_BIND").equals(event)||("SUB_DEV_BIND").equals(event)){
deviceService.devBind(convertVo(index));
}else if(event.equals("GW_UN_BIND")||event.equals("SUB_DEV_UN_BIND")){
}else if(("GW_UN_BIND").equals(event)||("SUB_DEV_UN_BIND").equals(event)){
deviceService.devUnBind(convertDeleteVo(index));
}
});
......@@ -77,7 +74,7 @@ public class DeviceEventService {
/**
* 处理属性消息
*
* @param aqaraEvent
* @param aqaraEvent 请求入参
*/
public void processResMessage(AqaraEvent aqaraEvent) {
List<AqaraEventDetail> data = aqaraEvent.getData();
......
......@@ -5,18 +5,11 @@ import cn.com.glsx.consumer.entity.DeviceVo;
import cn.com.glsx.consumer.utils.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
/**
* @author zhouhaibao
......@@ -26,7 +19,7 @@ import java.util.List;
@Slf4j
public class DeviceService {
@Autowired
@Resource
private SceneClient sceneClient;
@Value("${getDeviceNameUrl}")
......@@ -53,7 +46,7 @@ public class DeviceService {
}
public String getDeviceName(String devId) {
String name=null;
String name="";
try {
JSONObject jsonObject = HttpUtil.sendGet(getDeviceNameUrl.replace("{device_id}", devId), null, new HashMap<>());
JSONObject message = jsonObject.getJSONObject("message");
......
......@@ -25,9 +25,9 @@ import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -41,44 +41,42 @@ import java.util.stream.Collectors;
@Slf4j
public class InfoService {
@Autowired
@Resource
private SmartDevideStatusMapper smartDevideStatusMapper;
@Autowired
@Resource
private SmartSceneDataMapper smartSceneDataMapper;
@Autowired
@Resource
private DayInfoMapper dayInfoMapper;
@Autowired
@Resource
private ConditionStrategy conditionStrategy;
@Autowired
@Resource
private SceneClient sceneClient;
@Autowired
@Resource
private RedisService redisService;
@Autowired
@Resource
private DeviceService deviceService;
/**
* 处理消息
*
* @param data
* @param data 入参
*/
public void processMessage(String data) {
DeviceStatus deviceStatus = JSONObject.parseObject(data, DeviceStatus.class);
List<SmartDevideStatus> list = buildParams(deviceStatus);
if (CollectionUtils.isNotEmpty(list)) {
list.forEach(index -> {
if (index.getId() == null) {
smartDevideStatusMapper.insert(index);
list.forEach(in -> {
if (in.getId() == null) {
smartDevideStatusMapper.insert(in);
} else {
smartDevideStatusMapper.updateByPrimaryKeySelective(index);
smartDevideStatusMapper.updateByPrimaryKeySelective(in);
}
});
list.forEach(in -> {
// 判断该设备是否在用户场景里面
List<SmartSceneData> smartSceneDataList = smartSceneDataMapper.findSceneDataByDeviceId(in.getDeviceId(), in.getDeviceOrderCode());
if (CollectionUtils.isEmpty(smartSceneDataList)) {
......@@ -87,17 +85,16 @@ public class InfoService {
}
smartSceneDataList.forEach(index -> {
String key = index.getSceneId() + "_" + Contants.SCENE_STATUS;
List<SmartSceneData> sceneDataList = null;
Integer executeCycle = index.getExecuteCycle();
List<SmartSceneData> sceneDataList;
// 判断场景是否触发
if (index.getConditionRule().equals("1")) {
if (1 == index.getConditionRule()) {
sceneDataList = smartSceneDataMapper.findBySceneId(index.getSceneId(), in.getDeviceOrderCode());
} else {
sceneDataList = smartSceneDataMapper.findBySceneId(index.getSceneId(), null);
}
// 判断场景条件是否配置了时间并且是全部条件满足执行的
List<SmartSceneData> scene_condition_time = sceneDataList.stream().filter(inx -> inx.getParamKey().equals("scene_condition_status")).collect(Collectors.toList());
if (list.size() != scene_condition_time.size() && index.getConditionRule().equals("2")) {
List<SmartSceneData> scene_condition_time = sceneDataList.stream().filter(inx -> ("scene_condition_status").equals(inx.getParamKey())).collect(Collectors.toList());
if (list.size() != scene_condition_time.size() && index.getConditionRule() == 2) {
log.info("场景id{}不符合必要条件条件", index.getSceneId());
return;
}
......@@ -106,7 +103,7 @@ public class InfoService {
log.info("场景id{}---{}触发条件", index.getSceneId(), isTrigger ? "符合" : "不符合");
// 温度控制
Object o = redisService.get(key);
if(!in.getFlag()) {
if (!in.getFlag()) {
if (isTrigger) {
if (o == null) {
redisService.set(key, key);
......@@ -114,17 +111,16 @@ public class InfoService {
log.info("场景id{}温湿度已经触发过一次", index.getSceneId());
return;
}
// 下发场景
List<OrderResponse> orderResponses = sceneClient.issueOrder(new SceneRequest(index.getSceneId()));
log.info("场景id{}下发结果{}", index.getSceneId(), orderResponses);
}else{
} else {
// 重新触发的话
redisService.delete(key);
}
}
// 下发场景
List<OrderResponse> orderResponses = sceneClient.issueOrder(new SceneRequest(index.getSceneId()));
log.info("场景id{}下发结果{}", index.getSceneId(), orderResponses);
});
});
}
}
......@@ -137,7 +133,7 @@ public class InfoService {
// 温度特殊处理
if (smartDevideStatus != null) {
String code = index.getCode();
if (code.equals("va_temperature") || code.equals("va_humidity")) {
if (("va_temperature").equals(code) || ("va_humidity").equals(code)) {
smartDevideStatus.setFlag(false);
}
}
......@@ -168,7 +164,12 @@ public class InfoService {
}
//触发条件判断
/**
* 触发条件判断
*
* @param condition 条件
* @return 返回值
*/
private boolean getTriggerResult(SmartSceneData condition) {
if (condition.getExecuteCycle() != 1 && !getExecuteCycle().equals(condition.getExecuteCycle())) {
log.info("当前时间不是触发周期:" + condition.getId());
......@@ -179,7 +180,7 @@ public class InfoService {
log.info("触发条件的value不存在===id:" + condition.getId());
return false;
}
ScenseParamValue paramValue = null;
ScenseParamValue paramValue;
try {
paramValue = JSON.parseObject(JSON.parse(value).toString(), ScenseParamValue.class);
} catch (Exception e) {
......@@ -200,7 +201,7 @@ public class InfoService {
}
String Value = null;
//触发状态值,如果value没有值,则取ordervalue
if (deviceOrderCode.equals("va_temperature") || deviceOrderCode.equals("va_humidity")) {
if (("va_temperature").equals(deviceOrderCode) || ("va_humidity").equals(deviceOrderCode)) {
if (StringUtils.isNotBlank(paramValue.getValue())) {
log.info("温湿度值为{}", paramValue.getValue());
Value = Integer.parseInt(paramValue.getValue()) * 10 + "";
......@@ -225,7 +226,7 @@ public class InfoService {
/**
* 事件消息
*
* @param data
* @param data 入参
*/
public void processEeventMessage(String data) {
DeviceEvent deviceEvent = JSONObject.parseObject(data, DeviceEvent.class);
......@@ -248,17 +249,17 @@ public class InfoService {
private DeviceVo convervo(DeviceEvent deviceEvent) {
DeviceVo deviceVo = new DeviceVo();
DeviceEventDetail bizData = deviceEvent.getBizData();
if(deviceEvent.getBizCode().equals("bindUser")) {
if (("bindUser").equals(deviceEvent.getBizCode())) {
String name = deviceService.getDeviceName(bizData.getDevId());
deviceVo.setDeviceName(name);
}else{
} else {
deviceVo.setDeviceName(bizData.getName());
}
deviceVo.setUid(bizData.getUid());
deviceVo.setPlatformProductId(deviceEvent.getProductKey());
deviceVo.setChannel(1);
deviceVo.setParentId(bizData.getParentDevId());
deviceVo.setType(bizData.getParentDevId()==null?2:1);
deviceVo.setType(bizData.getParentDevId() == null ? 2 : 1);
deviceVo.setDeviceId(bizData.getDevId());
return deviceVo;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!