Browse Source

20210609修复消息的异常

pt
zy_Java 4 years ago
parent
commit
64670b473d
  1. 6
      recovery/src/main/java/com/ccsens/recovery/bean/message/RecoveryWithStartDrill.java
  2. 11
      recovery/src/main/java/com/ccsens/recovery/bean/po/RecipeProjectDecompose.java
  3. 60
      recovery/src/main/java/com/ccsens/recovery/bean/po/RecipeProjectDecomposeExample.java
  4. 18
      recovery/src/main/java/com/ccsens/recovery/service/PatientService.java
  5. 4
      recovery/src/main/resources/application.yml
  6. 25
      recovery/src/main/resources/mapper_raw/RecipeProjectDecomposeMapper.xml
  7. 246
      util/src/main/java/com/ccsens/util/bean/message/common/InMessage.java
  8. 34
      util/src/main/java/com/ccsens/util/bean/message/common/MessageConstant.java

6
recovery/src/main/java/com/ccsens/recovery/bean/message/RecoveryWithStartDrill.java

@ -19,6 +19,12 @@ public class RecoveryWithStartDrill extends BaseMessageDto{
private Long recordId;
//游戏id
private Long gameId;
//项目id
private Long projectId;
//任务详情id
private Long taskDetailId;
//插件名
private String pluginName = "start_training";
}
private RecoveryWithStartDrill.Data data;

11
recovery/src/main/java/com/ccsens/recovery/bean/po/RecipeProjectDecompose.java

@ -18,6 +18,8 @@ public class RecipeProjectDecompose implements Serializable {
private Byte recStatus;
private Long robotTaskId;
private static final long serialVersionUID = 1L;
public Long getId() {
@ -76,6 +78,14 @@ public class RecipeProjectDecompose implements Serializable {
this.recStatus = recStatus;
}
public Long getRobotTaskId() {
return robotTaskId;
}
public void setRobotTaskId(Long robotTaskId) {
this.robotTaskId = robotTaskId;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@ -89,6 +99,7 @@ public class RecipeProjectDecompose implements Serializable {
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", recStatus=").append(recStatus);
sb.append(", robotTaskId=").append(robotTaskId);
sb.append("]");
return sb.toString();
}

60
recovery/src/main/java/com/ccsens/recovery/bean/po/RecipeProjectDecomposeExample.java

@ -524,6 +524,66 @@ public class RecipeProjectDecomposeExample {
addCriterion("rec_status not between", value1, value2, "recStatus");
return (Criteria) this;
}
public Criteria andRobotTaskIdIsNull() {
addCriterion("robot_task_id is null");
return (Criteria) this;
}
public Criteria andRobotTaskIdIsNotNull() {
addCriterion("robot_task_id is not null");
return (Criteria) this;
}
public Criteria andRobotTaskIdEqualTo(Long value) {
addCriterion("robot_task_id =", value, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdNotEqualTo(Long value) {
addCriterion("robot_task_id <>", value, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdGreaterThan(Long value) {
addCriterion("robot_task_id >", value, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdGreaterThanOrEqualTo(Long value) {
addCriterion("robot_task_id >=", value, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdLessThan(Long value) {
addCriterion("robot_task_id <", value, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdLessThanOrEqualTo(Long value) {
addCriterion("robot_task_id <=", value, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdIn(List<Long> values) {
addCriterion("robot_task_id in", values, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdNotIn(List<Long> values) {
addCriterion("robot_task_id not in", values, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdBetween(Long value1, Long value2) {
addCriterion("robot_task_id between", value1, value2, "robotTaskId");
return (Criteria) this;
}
public Criteria andRobotTaskIdNotBetween(Long value1, Long value2) {
addCriterion("robot_task_id not between", value1, value2, "robotTaskId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

18
recovery/src/main/java/com/ccsens/recovery/service/PatientService.java

@ -119,10 +119,13 @@ public class PatientService implements IPatientService{
//查找患者
Patient patient = patientDao.selectByPrimaryKey(param.getPatientId());
if(ObjectUtil.isNull(patient)){
log.info("未找到患者");
return null;
}
RecipeProject recipeProject = recipeProjectMapper.selectByPrimaryKey(param.getRecipeProjectId());
if(ObjectUtil.isNull(recipeProject)){
//查找分解后的处方项
RecipeProjectDecompose projectDecompose = projectDecomposeMapper.selectByPrimaryKey(param.getRecipeProjectId());
if(ObjectUtil.isNull(projectDecompose)){
log.info("未找到处方项");
return null;
}
//存储一条训练记录
@ -143,16 +146,17 @@ public class PatientService implements IPatientService{
data.setPatientId(param.getPatientId());
data.setRecordId(recRecord.getId());
data.setGameId(param.getGameId());
data.setProjectId(patient.getProjectId());
data.setTaskDetailId(projectDecompose.getTaskId());
recoveryWithStartDrill.setData(data);
//查询患者当前关联的机器人
//查询接收者
Set<String> userIdSet = new HashSet<>();
userIdSet.add(param.getPatientId().toString());
RecoveryRobot recoveryRobot = patientDao.getRobotByPatientId(param.getPatientId());
if(ObjectUtil.isNotNull(recoveryRobot)){
userIdSet.add(recoveryRobot.getUserid().toString());
}
// RecoveryRobot recoveryRobot = patientDao.getRobotByPatientId(param.getPatientId());
// if(ObjectUtil.isNotNull(recoveryRobot)){
// userIdSet.add(recoveryRobot.getUserid().toString());
// }
//封装成inMessage
MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User);
messageRule.setAckRule(MessageRule.AckRule.NONE);

4
recovery/src/main/resources/application.yml

@ -1,6 +1,6 @@
spring:
profiles:
active: dev
include: util-dev,common
active: prod
include: util-prod,common

25
recovery/src/main/resources/mapper_raw/RecipeProjectDecomposeMapper.xml

@ -9,6 +9,7 @@
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="rec_status" jdbcType="TINYINT" property="recStatus" />
<result column="robot_task_id" jdbcType="BIGINT" property="robotTaskId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -69,7 +70,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, recipe_project_id, task_id, operator, create_time, update_time, rec_status
id, recipe_project_id, task_id, operator, create_time, update_time, rec_status, robot_task_id
</sql>
<select id="selectByExample" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecomposeExample" resultMap="BaseResultMap">
select
@ -104,10 +105,10 @@
<insert id="insert" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecompose">
insert into t_recipe_project_decompose (id, recipe_project_id, task_id,
operator, create_time, update_time,
rec_status)
rec_status, robot_task_id)
values (#{id,jdbcType=BIGINT}, #{recipeProjectId,jdbcType=BIGINT}, #{taskId,jdbcType=BIGINT},
#{operator,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{recStatus,jdbcType=TINYINT})
#{recStatus,jdbcType=TINYINT}, #{robotTaskId,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecompose">
insert into t_recipe_project_decompose
@ -133,6 +134,9 @@
<if test="recStatus != null">
rec_status,
</if>
<if test="robotTaskId != null">
robot_task_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -156,6 +160,9 @@
<if test="recStatus != null">
#{recStatus,jdbcType=TINYINT},
</if>
<if test="robotTaskId != null">
#{robotTaskId,jdbcType=BIGINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecomposeExample" resultType="java.lang.Long">
@ -188,6 +195,9 @@
<if test="record.recStatus != null">
rec_status = #{record.recStatus,jdbcType=TINYINT},
</if>
<if test="record.robotTaskId != null">
robot_task_id = #{record.robotTaskId,jdbcType=BIGINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -201,7 +211,8 @@
operator = #{record.operator,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
rec_status = #{record.recStatus,jdbcType=TINYINT}
rec_status = #{record.recStatus,jdbcType=TINYINT},
robot_task_id = #{record.robotTaskId,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -227,6 +238,9 @@
<if test="recStatus != null">
rec_status = #{recStatus,jdbcType=TINYINT},
</if>
<if test="robotTaskId != null">
robot_task_id = #{robotTaskId,jdbcType=BIGINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
@ -237,7 +251,8 @@
operator = #{operator,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
rec_status = #{recStatus,jdbcType=TINYINT}
rec_status = #{recStatus,jdbcType=TINYINT},
robot_task_id = #{robotTaskId,jdbcType=BIGINT}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>

246
util/src/main/java/com/ccsens/util/bean/message/common/InMessage.java

@ -1,105 +1,141 @@
package com.ccsens.util.bean.message.common;
import cn.hutool.core.date.DateUtil;
import com.ccsens.util.JacksonUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Data;
import java.util.Set;
/**
* @author wei
*/
@Data
public class InMessage {
/**
* 消息ID
*/
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private String id;
/**
* 发送时间(s)
* Notice: 指的是服务器收到发送请求的时间不是服务器发出消息的时间
*/
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long time;
/**
* 消息来自于那个域
*/
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private MessageConstant.DomainType fromDomain;
/**
* 发送者信息
*/
private String from;
/**
* 消息要发送到哪个域
*/
private MessageConstant.DomainType toDomain = MessageConstant.DomainType.User;
/**
* 调用者信息
* User netty,无需配置
* Queue 配置Queue Name
* Rest : 配置URL发送方式
* Server 无需配置
*/
private MessageConstant.InvokerMessage invokerMessage;
/**
* 接受者信息列表
*/
private Set<String> tos;
/**
* 消息的标示符通常是由用户传过来的消息ID该消息在用户系统中的ID
*/
private String unikey;
/**
* 发送规则
* DeSerialize but not serialize @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
*/
private MessageRule rule;
/**
* 发送内容
* 如果toDomain是Server 代表消息是发给当前服务器的必须是MessageSysData的子类型
* 其他格式不限由用户指定
*/
private String data;
public InMessage(){
this.time = DateUtil.currentSeconds();
}
public static InMessage newToServerMessage(MessageConstant.DomainType fromDomain,ServerMessage serverMessage) throws JsonProcessingException {
InMessage inMessage = new InMessage();
inMessage.setFromDomain(fromDomain);
inMessage.setToDomain(MessageConstant.DomainType.Server);
inMessage.setData(JacksonUtil.beanToJson(serverMessage));
return inMessage;
}
public static InMessage newToQueueMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException {
InMessage inMessage = new InMessage();
inMessage.setToDomain(MessageConstant.DomainType.Queue);
inMessage.setFrom(from);
inMessage.setTos(tos);
inMessage.setUnikey(unikey);
inMessage.setRule(rule);
inMessage.setData(data);
return inMessage;
}
public static InMessage newToUserMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException {
InMessage inMessage = new InMessage();
inMessage.setToDomain(MessageConstant.DomainType.User);
inMessage.setFrom(from);
inMessage.setTos(tos);
inMessage.setUnikey(unikey);
inMessage.setRule(rule);
inMessage.setData(data);
return inMessage;
}
//TODO
//添加方便链式调用的构造方法,类似builder
}
package com.ccsens.util.bean.message.common;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.ccsens.util.JacksonUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author wei
*/
@Data
public class InMessage {
/**
* 消息ID
*/
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private String id;
/**
* 发送时间(s)
* Notice: 指的是服务器收到发送请求的时间不是服务器发出消息的时间
*/
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long time;
/**
* 消息来自于那个域
*/
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private MessageConstant.DomainType fromDomain;
/**
* 发送者信息
*/
private String from;
/**
* 消息要发送到哪个域
*/
private MessageConstant.DomainType toDomain = MessageConstant.DomainType.User;
/**
* 调用者信息
* User netty,无需配置
* Queue 配置Queue Name
* Rest : 配置URL发送方式
* Server 无需配置
*/
private MessageConstant.InvokerMessage invokerMessage;
/**
* 接受者信息列表
*/
private Set<String> tos;
/**
* 消息的标示符通常是由用户传过来的消息ID该消息在用户系统中的ID
*/
private String unikey;
/**
* 发送规则
* DeSerialize but not serialize @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
*/
private MessageRule rule;
/**
* 发送内容
* 如果toDomain是Server 代表消息是发给当前服务器的必须是MessageSysData的子类型
* 其他格式不限由用户指定
*/
private String data;
public InMessage(){
this.time = DateUtil.currentSeconds();
}
public static InMessage newToServerMessage(MessageConstant.DomainType fromDomain,ServerMessage serverMessage) throws JsonProcessingException {
InMessage inMessage = new InMessage();
inMessage.setFromDomain(fromDomain);
inMessage.setToDomain(MessageConstant.DomainType.Server);
inMessage.setData(JacksonUtil.beanToJson(serverMessage));
return inMessage;
}
public static InMessage newToQueueMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException {
InMessage inMessage = new InMessage();
inMessage.setToDomain(MessageConstant.DomainType.Queue);
inMessage.setFrom(from);
inMessage.setTos(tos);
inMessage.setUnikey(unikey);
inMessage.setRule(rule);
inMessage.setData(data);
return inMessage;
}
public static InMessage newToUserMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException {
InMessage inMessage = new InMessage();
inMessage.setToDomain(MessageConstant.DomainType.User);
inMessage.setFrom(from);
inMessage.setTos(tos);
inMessage.setUnikey(unikey);
inMessage.setRule(rule);
inMessage.setData(data);
return inMessage;
}
//TODO
//添加方便链式调用的构造方法,类似builder
@Data
@ApiModel("接收消息者")
public static class To{
private Long id;
public To() {
}
public To(Long id) {
this.id = id;
}
}
/**
* 将userids列表转成tos格式
* @param userIds
* @return
*/
public static Set<String> transTos(List<Long> userIds) {
Set<String> sets = new HashSet<>();
if (CollectionUtil.isEmpty(userIds)) {
return sets;
}
userIds.forEach(userId -> {
To to = new To(userId);
sets.add(JSONObject.toJSONString(to));
});
return sets;
}
}

34
util/src/main/java/com/ccsens/util/bean/message/common/MessageConstant.java

@ -281,4 +281,38 @@ public class MessageConstant {
}
}
public enum GameClientMessageType{
//客户端心跳
Heart(0x00),
//客户端认证
Auth(0x01),
//客户端收到消息ACK
Ack(0x02),
//滑动
Count(0x03),
//状态改变
ChangeStatus(0x04)
;
public int value;
GameClientMessageType(int value){
this.value = value;
}
/**
* 从int到enum的转换函数
* @param value 枚举int值
* @return 对应的枚举找不到则返回null
*/
public static GameClientMessageType valueOf(int value) {
for(GameClientMessageType type : values()){
if(type.value == value){
return type;
}
}
return null;
}
}
}

Loading…
Cancel
Save