Commit 3731de6d by 111-PC\111

[+]代码规范

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