Browse Source

20210609修复消息的异常

pt
zy_Java 5 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; private Long recordId;
//游戏id //游戏id
private Long gameId; private Long gameId;
//项目id
private Long projectId;
//任务详情id
private Long taskDetailId;
//插件名
private String pluginName = "start_training";
} }
private RecoveryWithStartDrill.Data data; 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 Byte recStatus;
private Long robotTaskId;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public Long getId() { public Long getId() {
@ -76,6 +78,14 @@ public class RecipeProjectDecompose implements Serializable {
this.recStatus = recStatus; this.recStatus = recStatus;
} }
public Long getRobotTaskId() {
return robotTaskId;
}
public void setRobotTaskId(Long robotTaskId) {
this.robotTaskId = robotTaskId;
}
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -89,6 +99,7 @@ public class RecipeProjectDecompose implements Serializable {
sb.append(", createTime=").append(createTime); sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime); sb.append(", updateTime=").append(updateTime);
sb.append(", recStatus=").append(recStatus); sb.append(", recStatus=").append(recStatus);
sb.append(", robotTaskId=").append(robotTaskId);
sb.append("]"); sb.append("]");
return sb.toString(); 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"); addCriterion("rec_status not between", value1, value2, "recStatus");
return (Criteria) this; 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 { 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()); Patient patient = patientDao.selectByPrimaryKey(param.getPatientId());
if(ObjectUtil.isNull(patient)){ if(ObjectUtil.isNull(patient)){
log.info("未找到患者");
return null; 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; return null;
} }
//存储一条训练记录 //存储一条训练记录
@ -143,16 +146,17 @@ public class PatientService implements IPatientService{
data.setPatientId(param.getPatientId()); data.setPatientId(param.getPatientId());
data.setRecordId(recRecord.getId()); data.setRecordId(recRecord.getId());
data.setGameId(param.getGameId()); data.setGameId(param.getGameId());
data.setProjectId(patient.getProjectId());
data.setTaskDetailId(projectDecompose.getTaskId());
recoveryWithStartDrill.setData(data); recoveryWithStartDrill.setData(data);
//查询患者当前关联的机器人
//查询接收者 //查询接收者
Set<String> userIdSet = new HashSet<>(); Set<String> userIdSet = new HashSet<>();
userIdSet.add(param.getPatientId().toString()); userIdSet.add(param.getPatientId().toString());
RecoveryRobot recoveryRobot = patientDao.getRobotByPatientId(param.getPatientId()); // RecoveryRobot recoveryRobot = patientDao.getRobotByPatientId(param.getPatientId());
if(ObjectUtil.isNotNull(recoveryRobot)){ // if(ObjectUtil.isNotNull(recoveryRobot)){
userIdSet.add(recoveryRobot.getUserid().toString()); // userIdSet.add(recoveryRobot.getUserid().toString());
} // }
//封装成inMessage //封装成inMessage
MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User); MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User);
messageRule.setAckRule(MessageRule.AckRule.NONE); messageRule.setAckRule(MessageRule.AckRule.NONE);

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

@ -1,6 +1,6 @@
spring: spring:
profiles: profiles:
active: dev active: prod
include: util-dev,common 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="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="rec_status" jdbcType="TINYINT" property="recStatus" /> <result column="rec_status" jdbcType="TINYINT" property="recStatus" />
<result column="robot_task_id" jdbcType="BIGINT" property="robotTaskId" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -69,7 +70,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <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> </sql>
<select id="selectByExample" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecomposeExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecomposeExample" resultMap="BaseResultMap">
select select
@ -104,10 +105,10 @@
<insert id="insert" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecompose"> <insert id="insert" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecompose">
insert into t_recipe_project_decompose (id, recipe_project_id, task_id, insert into t_recipe_project_decompose (id, recipe_project_id, task_id,
operator, create_time, update_time, operator, create_time, update_time,
rec_status) rec_status, robot_task_id)
values (#{id,jdbcType=BIGINT}, #{recipeProjectId,jdbcType=BIGINT}, #{taskId,jdbcType=BIGINT}, values (#{id,jdbcType=BIGINT}, #{recipeProjectId,jdbcType=BIGINT}, #{taskId,jdbcType=BIGINT},
#{operator,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{operator,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{recStatus,jdbcType=TINYINT}) #{recStatus,jdbcType=TINYINT}, #{robotTaskId,jdbcType=BIGINT})
</insert> </insert>
<insert id="insertSelective" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecompose"> <insert id="insertSelective" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecompose">
insert into t_recipe_project_decompose insert into t_recipe_project_decompose
@ -133,6 +134,9 @@
<if test="recStatus != null"> <if test="recStatus != null">
rec_status, rec_status,
</if> </if>
<if test="robotTaskId != null">
robot_task_id,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@ -156,6 +160,9 @@
<if test="recStatus != null"> <if test="recStatus != null">
#{recStatus,jdbcType=TINYINT}, #{recStatus,jdbcType=TINYINT},
</if> </if>
<if test="robotTaskId != null">
#{robotTaskId,jdbcType=BIGINT},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecomposeExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="com.ccsens.recovery.bean.po.RecipeProjectDecomposeExample" resultType="java.lang.Long">
@ -188,6 +195,9 @@
<if test="record.recStatus != null"> <if test="record.recStatus != null">
rec_status = #{record.recStatus,jdbcType=TINYINT}, rec_status = #{record.recStatus,jdbcType=TINYINT},
</if> </if>
<if test="record.robotTaskId != null">
robot_task_id = #{record.robotTaskId,jdbcType=BIGINT},
</if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
@ -201,7 +211,8 @@
operator = #{record.operator,jdbcType=BIGINT}, operator = #{record.operator,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP}, create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,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"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -227,6 +238,9 @@
<if test="recStatus != null"> <if test="recStatus != null">
rec_status = #{recStatus,jdbcType=TINYINT}, rec_status = #{recStatus,jdbcType=TINYINT},
</if> </if>
<if test="robotTaskId != null">
robot_task_id = #{robotTaskId,jdbcType=BIGINT},
</if>
</set> </set>
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
@ -237,7 +251,8 @@
operator = #{operator,jdbcType=BIGINT}, operator = #{operator,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=TIMESTAMP}, create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,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} where id = #{id,jdbcType=BIGINT}
</update> </update>
</mapper> </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; package com.ccsens.util.bean.message.common;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.collection.CollectionUtil;
import com.ccsens.util.JacksonUtil; import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonProperty; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException; import com.ccsens.util.JacksonUtil;
import lombok.Data; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.Set; import io.swagger.annotations.ApiModel;
import lombok.Data;
/**
* @author wei import java.util.HashSet;
*/ import java.util.List;
@Data import java.util.Set;
public class InMessage {
/** /**
* 消息ID * @author wei
*/ */
@JsonProperty(access = JsonProperty.Access.READ_ONLY) @Data
private String id; public class InMessage {
/** /**
* 发送时间(s) * 消息ID
* Notice: 指的是服务器收到发送请求的时间不是服务器发出消息的时间 */
*/ @JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonProperty(access = JsonProperty.Access.READ_ONLY) private String id;
private Long time; /**
/** * 发送时间(s)
* 消息来自于那个域 * Notice: 指的是服务器收到发送请求的时间不是服务器发出消息的时间
*/ */
@JsonProperty(access = JsonProperty.Access.READ_ONLY) @JsonProperty(access = JsonProperty.Access.READ_ONLY)
private MessageConstant.DomainType fromDomain; private Long time;
/** /**
* 发送者信息 * 消息来自于那个域
*/ */
private String from; @JsonProperty(access = JsonProperty.Access.READ_ONLY)
/** private MessageConstant.DomainType fromDomain;
* 消息要发送到哪个域 /**
*/ * 发送者信息
private MessageConstant.DomainType toDomain = MessageConstant.DomainType.User; */
/** private String from;
* 调用者信息 /**
* User netty,无需配置 * 消息要发送到哪个域
* Queue 配置Queue Name */
* Rest : 配置URL发送方式 private MessageConstant.DomainType toDomain = MessageConstant.DomainType.User;
* Server 无需配置 /**
*/ * 调用者信息
private MessageConstant.InvokerMessage invokerMessage; * User netty,无需配置
* Queue 配置Queue Name
/** * Rest : 配置URL发送方式
* 接受者信息列表 * Server 无需配置
*/ */
private Set<String> tos; private MessageConstant.InvokerMessage invokerMessage;
/**
* 消息的标示符通常是由用户传过来的消息ID该消息在用户系统中的ID /**
*/ * 接受者信息列表
private String unikey; */
/** private Set<String> tos;
* 发送规则 /**
* DeSerialize but not serialize @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) * 消息的标示符通常是由用户传过来的消息ID该消息在用户系统中的ID
*/ */
private MessageRule rule; private String unikey;
/** /**
* 发送内容 * 发送规则
* 如果toDomain是Server 代表消息是发给当前服务器的必须是MessageSysData的子类型 * DeSerialize but not serialize @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
* 其他格式不限由用户指定 */
*/ private MessageRule rule;
private String data; /**
* 发送内容
* 如果toDomain是Server 代表消息是发给当前服务器的必须是MessageSysData的子类型
public InMessage(){ * 其他格式不限由用户指定
this.time = DateUtil.currentSeconds(); */
} private String data;
public static InMessage newToServerMessage(MessageConstant.DomainType fromDomain,ServerMessage serverMessage) throws JsonProcessingException {
InMessage inMessage = new InMessage();
inMessage.setFromDomain(fromDomain); public InMessage(){
inMessage.setToDomain(MessageConstant.DomainType.Server); this.time = DateUtil.currentSeconds();
inMessage.setData(JacksonUtil.beanToJson(serverMessage)); }
return inMessage; public static InMessage newToServerMessage(MessageConstant.DomainType fromDomain,ServerMessage serverMessage) throws JsonProcessingException {
} InMessage inMessage = new InMessage();
inMessage.setFromDomain(fromDomain);
public static InMessage newToQueueMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException { inMessage.setToDomain(MessageConstant.DomainType.Server);
InMessage inMessage = new InMessage(); inMessage.setData(JacksonUtil.beanToJson(serverMessage));
inMessage.setToDomain(MessageConstant.DomainType.Queue); return inMessage;
inMessage.setFrom(from); }
inMessage.setTos(tos);
inMessage.setUnikey(unikey); public static InMessage newToQueueMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException {
inMessage.setRule(rule); InMessage inMessage = new InMessage();
inMessage.setData(data); inMessage.setToDomain(MessageConstant.DomainType.Queue);
return inMessage; inMessage.setFrom(from);
} inMessage.setTos(tos);
public static InMessage newToUserMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException { inMessage.setUnikey(unikey);
InMessage inMessage = new InMessage(); inMessage.setRule(rule);
inMessage.setToDomain(MessageConstant.DomainType.User); inMessage.setData(data);
inMessage.setFrom(from); return inMessage;
inMessage.setTos(tos); }
inMessage.setUnikey(unikey); public static InMessage newToUserMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException {
inMessage.setRule(rule); InMessage inMessage = new InMessage();
inMessage.setData(data); inMessage.setToDomain(MessageConstant.DomainType.User);
return inMessage; inMessage.setFrom(from);
} inMessage.setTos(tos);
inMessage.setUnikey(unikey);
inMessage.setRule(rule);
//TODO inMessage.setData(data);
//添加方便链式调用的构造方法,类似builder 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