Commit 2bbe46f8 authored by zhangsen's avatar zhangsen

极光推送方法

parent ae00fdc8
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.fas.business.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.yeejoin.amos.fas.business.constants.FasConstant;
......@@ -16,6 +17,7 @@ import com.yeejoin.amos.fas.business.service.intfc.IPlanVisual3dService;
import com.yeejoin.amos.fas.business.service.model.ToipResponse;
import com.yeejoin.amos.fas.business.util.JSONUtil;
import com.yeejoin.amos.fas.business.util.StringUtil;
import com.yeejoin.amos.fas.business.vo.PlanStepJsonVO;
import com.yeejoin.amos.fas.business.vo.PlanStepVo;
import com.yeejoin.amos.fas.business.vo.TreeSubjectVo;
import com.yeejoin.amos.fas.core.util.CommonResponse;
......@@ -25,6 +27,7 @@ import com.yeejoin.amos.fas.dao.entity.*;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.RoleModel;
import org.apache.commons.io.IOUtils;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
......@@ -32,6 +35,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.emq.EmqKeeper;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
......@@ -90,6 +94,15 @@ public class PlanVisual3dServiceImpl implements IPlanVisual3dService {
@Autowired
private IContingencyPlanInstanceRepository repository;
@Autowired
private EmqKeeper emqKeeper;
@Value("${spring.application.name}")
private String serviceName;
@Value("${station.name}")
private String stationName;
@Override
public List<TreeSubjectVo> getPlanTree() {
......@@ -419,13 +432,8 @@ public class PlanVisual3dServiceImpl implements IPlanVisual3dService {
} catch (IOException e) {
throw new RuntimeException("获取预案相关角色信息失败!");
}
List<Object> list = JSON.parseArray(json);
List<Map<String, String>> result = new ArrayList<Map<String, String>>();
for (Object object : list) {
Map<String, String> ret = (Map<String, String>) object;
result.add(ret);
}
List<String> roleCode = result.stream().map(t -> t.get("roleCode")).distinct().collect(Collectors.toList());
List<PlanStepJsonVO> result = JSONObject.parseArray(json, PlanStepJsonVO.class);
List<String> roleCode = result.stream().map(PlanStepJsonVO::getRoleCode).distinct().collect(Collectors.toList());
List<RoleModel> roleModelList = new ArrayList<>();
for (Long key : user.getOrgRoles().keySet()) {
......@@ -452,13 +460,12 @@ public class PlanVisual3dServiceImpl implements IPlanVisual3dService {
Map<String, String> userInfo = contingencyPlanInstanceMapper.getUserByUserId(user.getUserId());
dto.setPersonImg(userInfo.get("personImg"));
repository.save(dto);
PushMsgParam pushMsgParam = new PushMsgParam();
// TODO: 2022/10/18 接收人需从平台获取
pushMsgParam.setRecivers(Lists.newArrayList(""));
pushMsgParam.setContent(JSONUtil.toJson(dto));
pushMsgParam.setSubject("REPLYMESSAGE");
pushMsgParam.setType(JPushTypeEnum.REPLY_MESSAGE.getCode());
pushFeign.sendMessageone(pushMsgParam);
try {
String topic = String.format("/%s/%s/%s", serviceName, stationName, "plan");
emqKeeper.getMqttClient().publish(topic, JSON.toJSONString(dto).getBytes(), 0, Boolean.FALSE);
} catch (MqttException e) {
e.printStackTrace();
}
}
@Override
......@@ -520,4 +527,26 @@ public class PlanVisual3dServiceImpl implements IPlanVisual3dService {
}
return contingencyInstanceInfoMapper.selectDisposalActionList(type, status, roles, disposalId);
}
@Override
public void sendMessage(String json, String buttonCode) {
String planStepJson = "";
try {
planStepJson = IOUtils.toString(planStepResource.getInputStream(), String.valueOf(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("获取预案相关角色信息失败!");
}
List<PlanStepJsonVO> planStepJsonList = JSONObject.parseArray(planStepJson, PlanStepJsonVO.class);
List<String> collect = planStepJsonList.stream().filter(code -> code.getButtonCode().equals(buttonCode)).map(PlanStepJsonVO::getRoleCode).collect(Collectors.toList());
String roleJoin = String.join(",", collect);
// TODO: 2022/10/19 根据多个角色code查询用户ids
String userIdsJoin = "";
//极光推送
PushMsgParam pushMsgParam = new PushMsgParam();
pushMsgParam.setRecivers(Arrays.asList(userIdsJoin.split(",")));
pushMsgParam.setContent(json);
pushMsgParam.setSubject("REPLYMESSAGE");
pushMsgParam.setType(JPushTypeEnum.REPLY_MESSAGE.getCode());
pushFeign.sendMessageone(pushMsgParam);
}
}
......@@ -104,4 +104,10 @@ public interface IPlanVisual3dService {
List<ContingencyPlanInstance> selectDisposalActionList(String disposalId , List<RoleModel> roleModelList, int dataType);
/**
* 极光推送
* @param json 消息体
* @param buttonCode 按钮编码
*/
void sendMessage(String json, String buttonCode);
}
package com.yeejoin.amos.fas.business.vo;
import lombok.Data;
@Data
public class PlanStepJsonVO {
private String stepCode;
private String stepName;
private String stepStatus;
private String isParallel;
private String roleCode;
private String buttonCode;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment