Commit 2faf6064 by 111-PC\111

[+]代码修改

1 parent d1bd1c5c
......@@ -27,6 +27,18 @@
<artifactId>rest-admin-registry</artifactId>
</dependency>
<dependency>
<groupId>cn.com.glsx</groupId>
<artifactId>rpc-didicb-app-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
......
......@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* <p>Description:
......@@ -30,4 +31,5 @@ public interface SmartSceneMapper extends tk.mybatis.mapper.common.Mapper<SmartS
SmartScene getById(Long id);
Map<String, Object> getBySourceAndUserId(Long id);
}
......@@ -14,4 +14,5 @@ public class ExecuteTaskVo {
private String valType;
private String remoteId;
private String value;
private String deviceName;
}
package com.glsx.smart.service.impl;
import cn.com.glsx.didicb.app.enums.MessagePushResultEnum;
import cn.com.glsx.didicb.app.model.MessageBoxInfo;
import cn.com.glsx.didicb.app.remote.MessageBoxInfoRemote;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import com.glsx.smart.dao.entity.SmartProduct;
import com.glsx.smart.dao.entity.SmartScene;
import com.glsx.smart.dao.entity.SmartSceneData;
......@@ -19,17 +21,19 @@ import com.glsx.smart.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
/**
......@@ -51,12 +55,18 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
@Resource
private SmartProductMapper productMapper;
@DubboReference
private MessageBoxInfoRemote messageBoxInfoRemote;
@Value("${orderIssueurl}")
private String orderIssueurl;
@Value("${instructionInfIssue}")
private String instructionInfIssue;
@Value("${infoUrl}")
private String infoUrl;
@Override
public List<SmartScene> getList(SmartScene record) {
return sceneMapper.getList(record);
......@@ -151,12 +161,19 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
return orderValue;
}
/**
* 下发场景
*
* @param scene 场景
* @return
*/
@Override
public List<OrderResponse> issueOrder(SmartScene scene) {
List<OrderResponse> orderResponseList = new ArrayList<>();
List<SmartSceneData> smartTemplateParamList = sceneDataMapper.getBySceneId(scene.getId());
if (CollectionUtils.isEmpty(smartTemplateParamList)) {
log.info("未查到该场景id的条件{}", scene.getId());
return orderResponseList;
}
// 下发指令
List<SmartSceneData> orders = smartTemplateParamList.stream().filter(index -> index.getParamKey().equals("scene_content_device")).collect(Collectors.toList());
......@@ -187,7 +204,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
if (StringUtils.isBlank(remoteId)) {
String valueType = executeTaskVo.getValType();
ordermap.put("code", executeTaskVo.getOrder());
ordermap.put("value", revertType(valueType, executeTaskVo.getOrderVal()==null?executeTaskVo.getValue():executeTaskVo.getOrderVal()));
ordermap.put("value", revertType(valueType, executeTaskVo.getOrderVal() == null ? executeTaskVo.getValue() : executeTaskVo.getOrderVal()));
maps.add(ordermap);
ordermaps.put("commands", maps);
// 下发普通指令
......@@ -209,12 +226,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
orderResponse.setMessage(responseVo.getMessage());
orderResponse.setCode(Integer.parseInt(responseVo.getCode()));
}
SmartProduct smartProduct = new SmartProduct();
smartProduct.setPlatformProductId(devideId);
List<SmartProduct> byCondition = productMapper.getByCondition(smartProduct);
if (CollectionUtils.isNotEmpty(byCondition)) {
orderResponse.setDeviceName(byCondition.get(0).getProductName());
}
orderResponse.setDeviceName(executeTaskVo.getDeviceName());
orderResponseList.add(orderResponse);
}
}
......@@ -223,6 +235,77 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
log.info("下发异常,{}", e);
}
}
// 下发推送通知(Android设备和ios设备)
issueNotice(scene, orderResponseList);
return orderResponseList;
}
/**
* 推送通知
*
* @param scene 场景
* @param orderResponseList 下发场景返回的消息
*/
private void issueNotice(SmartScene scene, List<OrderResponse> orderResponseList) {
if (CollectionUtils.isNotEmpty(orderResponseList)) {
String content = "";
String title = "收到一条智能消息";
Map<String, Object> map = sceneMapper.getBySourceAndUserId(scene.getId());
String user_id = map.get("user_id")+"";
String scene_name = map.get("scene_name")+"";
Map<String, String> paramMap = new HashMap<>();
paramMap.put("alias", user_id);
paramMap.put("deviceType", map.get("source")+"");
paramMap.put("title", title);
List<OrderResponse> collect = orderResponseList.stream().filter(index -> !index.isResult()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)) {
content = MessageFormat.format("您配置的{0}场景已执行,点击可查看详情。", scene_name);
} else {
content = MessageFormat.format("您配置的{0}场景未顺利执行,点击可查看详情。", scene_name);
}
paramMap.put("body", content);
saveInfo(user_id, title, collect, scene.getId(), scene_name);
try {
JSONObject jsonObject = HttpUtil.sendPost(infoUrl, JSONObject.toJSONString(paramMap), new HashMap<>());
if (jsonObject != null) {
String code = jsonObject.get("code") + "";
if (("200").equals(code)) {
log.info("场景{}下发通知成功", scene.getId());
} else {
log.info("场景{}下发通知失败", jsonObject.get("message"));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 消息推送到app端
*
* @param user_id 用户id
* @param title 标题
* @param orderResponseList 内容
* @param id 场景id
* @param scene_name
*/
private void saveInfo(String user_id, String title, List<OrderResponse> orderResponseList, Long id, String scene_name) {
String context = "";
if (CollectionUtils.isEmpty(orderResponseList)) {
context = MessageFormat.format("您配置的{0}场景已在{1} 成功执行", scene_name, new Date());
}else{
List<String> names = orderResponseList.stream().map(p -> p.getDeviceName()).collect(Collectors.toList());
context = MessageFormat.format("您配置的{0}场景已在{1}触发执行,但因以下设备{2}未能执行成功,请关注以上设备状态", scene_name, new Date(),names);
}
MessageBoxInfo messageBoxInfo = new MessageBoxInfo();
messageBoxInfo.setAccountId(Integer.parseInt(user_id));
messageBoxInfo.setSn("88888888");
messageBoxInfo.setContent(context);
messageBoxInfo.setTitle(title);
messageBoxInfo.setExpandId(id.intValue());
messageBoxInfo.setIsPushSuccess(MessagePushResultEnum.FAILURE.getValue());
messageBoxInfoRemote.insert(messageBoxInfo);
}
}
......@@ -24,7 +24,8 @@
<collection property="iconUrl" column="icon" ofType="com.glsx.smart.dao.entity.SmartScene" fetchType="eager"
select="com.glsx.smart.dao.mapper.SmartSysFileMapper.selectUrlById">
</collection>
<collection property="backPicUrl" column="back_pic" ofType="com.glsx.smart.dao.entity.SmartScene" fetchType="eager"
<collection property="backPicUrl" column="back_pic" ofType="com.glsx.smart.dao.entity.SmartScene"
fetchType="eager"
select="com.glsx.smart.dao.mapper.SmartSysFileMapper.selectUrlById">
</collection>
</resultMap>
......@@ -436,7 +437,7 @@
</insert>
<select id="getList" parameterType="com.glsx.smart.dao.entity.SmartScene" resultMap="DetailResultMap">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from smart_scene t
<where>
<if test="typeKey != null and typeKey != ''">
......@@ -453,8 +454,14 @@
</select>
<select id="getById" parameterType="java.lang.Long" resultMap="DetailResultMap">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from smart_scene
where id = #{id,jdbcType=BIGINT}
where id = #{id,jdbcType=BIGINT}
</select>
<select id="getBySourceAndUserId" resultType="java.util.Map">
select
t2.user_id ,t2.source,t1.scene_name
from smart_scene t1 left join smart_user_relation t2 on t1.user_id=t2.id
where t1.id = #{id,jdbcType=BIGINT}
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!