Lihong@123456 5 years ago
parent
commit
bb94c80671
  1. 6
      wisdomcar/pom.xml
  2. 47
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/dto/Message/CarRecordMessageDto.java
  3. 11
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/po/FirstAidRecord.java
  4. 60
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/po/FirstAidRecordExample.java
  5. 11
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/po/Step.java
  6. 60
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/po/StepExample.java
  7. 7
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/Message/CarRecordMessageVo.java
  8. 2
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/RfidVo.java
  9. 17
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/StepVo.java
  10. 7
      wisdomcar/src/main/java/com/ccsens/wisdomcar/persist/dao/StepDao.java
  11. 209
      wisdomcar/src/main/java/com/ccsens/wisdomcar/rabbitMQ/RabbitController.java
  12. 163
      wisdomcar/src/main/java/com/ccsens/wisdomcar/service/RecordService.java
  13. 4
      wisdomcar/src/main/resources/application.yml
  14. 22
      wisdomcar/src/main/resources/mapper_dao/StepDao.xml
  15. 27
      wisdomcar/src/main/resources/mapper_raw/FirstAidRecordMapper.xml
  16. 25
      wisdomcar/src/main/resources/mapper_raw/StepMapper.xml

6
wisdomcar/pom.xml

@ -21,11 +21,7 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<!--util 工具类-->
<dependency>
<artifactId>util</artifactId>
<groupId>com.ccsens</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.ccsens</groupId>
<artifactId>util</artifactId>

47
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/dto/Message/CarRecordMessageDto.java

@ -10,11 +10,15 @@ public class CarRecordMessageDto {
/**
* 平车编号
*/
private String carNumber;
private String authId;
/**
* 类型 0开始 1体重 2rfid, 3称重一 4称重二 5称重三 6称重四 7震动 8溶栓 9团注 10维持
*/
private byte type;
private Byte type;
/**
*
*/
private int addr;
/**
* 类型对应的值
*/
@ -24,4 +28,43 @@ public class CarRecordMessageDto {
*/
private Long time;
public byte getType(){
if(this.type != null){
return type;
}
switch (addr){
case 3:
return 0;
case 16:
case 17:
return 1;
case 18:
return 8;
case 19:
return 9;
case 20:
return 10;
case 21:
case 22:
case 23:
return 7;
case 25:
case 26:
return 3;
case 27:
case 28:
return 4;
case 29:
case 30:
return 5;
case 31:
case 32:
return 6;
case 24:
return 2;
default:
return this.type;
}
}
}

11
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/po/FirstAidRecord.java

@ -14,6 +14,8 @@ public class FirstAidRecord implements Serializable {
private Long beginTime;
private Long stepId;
private Date createdAt;
private Date updatedAt;
@ -62,6 +64,14 @@ public class FirstAidRecord implements Serializable {
this.beginTime = beginTime;
}
public Long getStepId() {
return stepId;
}
public void setStepId(Long stepId) {
this.stepId = stepId;
}
public Date getCreatedAt() {
return createdAt;
}
@ -97,6 +107,7 @@ public class FirstAidRecord implements Serializable {
sb.append(", type=").append(type);
sb.append(", value=").append(value);
sb.append(", beginTime=").append(beginTime);
sb.append(", stepId=").append(stepId);
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append(", recStatus=").append(recStatus);

60
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/po/FirstAidRecordExample.java

@ -415,6 +415,66 @@ public class FirstAidRecordExample {
return (Criteria) this;
}
public Criteria andStepIdIsNull() {
addCriterion("step_id is null");
return (Criteria) this;
}
public Criteria andStepIdIsNotNull() {
addCriterion("step_id is not null");
return (Criteria) this;
}
public Criteria andStepIdEqualTo(Long value) {
addCriterion("step_id =", value, "stepId");
return (Criteria) this;
}
public Criteria andStepIdNotEqualTo(Long value) {
addCriterion("step_id <>", value, "stepId");
return (Criteria) this;
}
public Criteria andStepIdGreaterThan(Long value) {
addCriterion("step_id >", value, "stepId");
return (Criteria) this;
}
public Criteria andStepIdGreaterThanOrEqualTo(Long value) {
addCriterion("step_id >=", value, "stepId");
return (Criteria) this;
}
public Criteria andStepIdLessThan(Long value) {
addCriterion("step_id <", value, "stepId");
return (Criteria) this;
}
public Criteria andStepIdLessThanOrEqualTo(Long value) {
addCriterion("step_id <=", value, "stepId");
return (Criteria) this;
}
public Criteria andStepIdIn(List<Long> values) {
addCriterion("step_id in", values, "stepId");
return (Criteria) this;
}
public Criteria andStepIdNotIn(List<Long> values) {
addCriterion("step_id not in", values, "stepId");
return (Criteria) this;
}
public Criteria andStepIdBetween(Long value1, Long value2) {
addCriterion("step_id between", value1, value2, "stepId");
return (Criteria) this;
}
public Criteria andStepIdNotBetween(Long value1, Long value2) {
addCriterion("step_id not between", value1, value2, "stepId");
return (Criteria) this;
}
public Criteria andCreatedAtIsNull() {
addCriterion("created_at is null");
return (Criteria) this;

11
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/po/Step.java

@ -12,6 +12,8 @@ public class Step implements Serializable {
private Integer sequence;
private Byte stepType;
private Date createdAt;
private Date updatedAt;
@ -52,6 +54,14 @@ public class Step implements Serializable {
this.sequence = sequence;
}
public Byte getStepType() {
return stepType;
}
public void setStepType(Byte stepType) {
this.stepType = stepType;
}
public Date getCreatedAt() {
return createdAt;
}
@ -86,6 +96,7 @@ public class Step implements Serializable {
sb.append(", name=").append(name);
sb.append(", code=").append(code);
sb.append(", sequence=").append(sequence);
sb.append(", stepType=").append(stepType);
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append(", recStatus=").append(recStatus);

60
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/po/StepExample.java

@ -365,6 +365,66 @@ public class StepExample {
return (Criteria) this;
}
public Criteria andStepTypeIsNull() {
addCriterion("step_type is null");
return (Criteria) this;
}
public Criteria andStepTypeIsNotNull() {
addCriterion("step_type is not null");
return (Criteria) this;
}
public Criteria andStepTypeEqualTo(Byte value) {
addCriterion("step_type =", value, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeNotEqualTo(Byte value) {
addCriterion("step_type <>", value, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeGreaterThan(Byte value) {
addCriterion("step_type >", value, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeGreaterThanOrEqualTo(Byte value) {
addCriterion("step_type >=", value, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeLessThan(Byte value) {
addCriterion("step_type <", value, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeLessThanOrEqualTo(Byte value) {
addCriterion("step_type <=", value, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeIn(List<Byte> values) {
addCriterion("step_type in", values, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeNotIn(List<Byte> values) {
addCriterion("step_type not in", values, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeBetween(Byte value1, Byte value2) {
addCriterion("step_type between", value1, value2, "stepType");
return (Criteria) this;
}
public Criteria andStepTypeNotBetween(Byte value1, Byte value2) {
addCriterion("step_type not between", value1, value2, "stepType");
return (Criteria) this;
}
public Criteria andCreatedAtIsNull() {
addCriterion("created_at is null");
return (Criteria) this;

7
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/Message/CarRecordMessageVo.java

@ -32,6 +32,10 @@ public class CarRecordMessageVo extends BaseMessageDto {
* 流程
*/
private String step;
/**
* 流程
*/
private Byte stepType;
}
private Data data;
@ -40,7 +44,7 @@ public class CarRecordMessageVo extends BaseMessageDto {
setTime(System.currentTimeMillis());
}
public CarRecordMessageVo(String carNumber,int type,String value,Long time,String step){
public CarRecordMessageVo(String carNumber,int type,String value,Long time,String step,Byte stepType){
this();
Data d = new Data();
d.setCarNumber(carNumber);
@ -48,6 +52,7 @@ public class CarRecordMessageVo extends BaseMessageDto {
d.setValue(value);
d.setTime(time);
d.setStep(step);
d.setStepType(stepType);
setData(d);
}
}

2
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/RfidVo.java

@ -23,4 +23,6 @@ public class RfidVo {
@ApiModelProperty("医院id")
private byte hospitalId;
}
}

17
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/StepVo.java

@ -0,0 +1,17 @@
package com.ccsens.wisdomcar.bean.vo;
import lombok.Data;
/**
* @author
*/
@Data
public class StepVo {
@Data
public static class Step{
private Long id;
private String stepCode;
private byte stepType;
}
}

7
wisdomcar/src/main/java/com/ccsens/wisdomcar/persist/dao/StepDao.java

@ -1,5 +1,6 @@
package com.ccsens.wisdomcar.persist.dao;
import com.ccsens.wisdomcar.bean.vo.StepVo;
import com.ccsens.wisdomcar.persist.mapper.StepMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@ -15,7 +16,9 @@ public interface StepDao extends StepMapper {
* @param value rfid
* @return 返回流程的code
*/
String getCodeByRfId(@Param("rfid") String value);
StepVo.Step getCodeByRfId(@Param("rfid") String value);
String getCodeByStepOne();
StepVo.Step getCodeByStepOne();
String getRecordByCarIdAndType(@Param("carId") Long carId, @Param("type") byte type);
}

209
wisdomcar/src/main/java/com/ccsens/wisdomcar/rabbitMQ/RabbitController.java

@ -1,55 +1,154 @@
//package com.ccsens.wisdomcar.rabbitMQ;
//
//import cn.hutool.core.collection.CollectionUtil;
//import cn.hutool.core.util.ObjectUtil;
//import com.alibaba.fastjson.JSONObject;
//import com.ccsens.util.bean.message.common.OutMessage;
//import com.ccsens.util.bean.message.common.OutMessageSet;
//import com.ccsens.util.config.RabbitMQConfig;
//import com.ccsens.wisdomcar.bean.dto.Message.CarRecordMessageDto;
//import com.ccsens.wisdomcar.service.IRecordService;
//import lombok.extern.slf4j.Slf4j;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.Set;
//
//@Slf4j
//@Component
//@RabbitListener(queues = RabbitMQConfig.WISDOM_CAR)
//public class RabbitController {
// @Resource
// private IRecordService recordService;
//
// private Logger logger = LoggerFactory.getLogger(RabbitController.class);
//
// @RabbitHandler
// public void process(String messageJson) {
// logger.info("平车上传消息数据: {}",messageJson);
// OutMessageSet outMessageSet = JSONObject.parseObject(messageJson,OutMessageSet.class);
// if(ObjectUtil.isNull(outMessageSet)){
// return;
// }
// Set<OutMessage> messageSet = outMessageSet.getMessageSet();
// if (CollectionUtil.isEmpty(messageSet)) {
// return;
// }
// messageSet.forEach(outMessage -> {
// CarRecordMessageDto carRecordMessageDto = JSONObject.parseObject(outMessage.getData(),CarRecordMessageDto.class);
// if(ObjectUtil.isNull(carRecordMessageDto)){
// return;
// }
// try {
// recordService.disposeMessage(carRecordMessageDto);
// } catch (Exception e) {
// log.error("处理平车信息异常",e);
// e.printStackTrace();
// }
// });
// }
//
//}
package com.ccsens.wisdomcar.rabbitMQ;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.bean.message.common.OutMessage;
import com.ccsens.util.bean.message.common.OutMessageSet;
import com.ccsens.util.config.RabbitMQConfig;
import com.ccsens.wisdomcar.bean.dto.Message.CarRecordMessageDto;
import com.ccsens.wisdomcar.service.IRecordService;
import com.ccsens.wisdomcar.util.Constant;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
@Slf4j
@Component
@RabbitListener(queues = RabbitMQConfig.WISDOM_CAR)
public class RabbitController {
@Resource
private IRecordService recordService;
@Resource
private RedisUtil redisUtil;
private Logger logger = LoggerFactory.getLogger(RabbitController.class);
@RabbitHandler
public void process(String messageJson) {
logger.info("平车上传消息数据: {}",messageJson);
OutMessageSet outMessageSet = JSONObject.parseObject(messageJson,OutMessageSet.class);
if(ObjectUtil.isNull(outMessageSet)){
return;
}
Set<OutMessage> messageSet = outMessageSet.getMessageSet();
if (CollectionUtil.isEmpty(messageSet)) {
return;
}
List<CarRecordMessageDto> carRecordMessageDtoList = new ArrayList<>();
Map<Integer ,Long> map = new HashMap<>();
messageSet.forEach(outMessage -> {
CarRecordMessageDto carRecordMessageDto = JSONObject.parseObject(outMessage.getData(),CarRecordMessageDto.class);
if(ObjectUtil.isNull(carRecordMessageDto)){
return;
}
switch (carRecordMessageDto.getType()){
case Constant.CAR_RECORD_WEIGHT:
getWeight(carRecordMessageDtoList, map, carRecordMessageDto,16);
break;
case Constant.WEIGHT_SENSOR_1:
// getWeight(carRecordMessageDtoList, map, carRecordMessageDto,25);
break;
case Constant.WEIGHT_SENSOR_2:
// getWeight(carRecordMessageDtoList, map, carRecordMessageDto,27);
break;
case Constant.WEIGHT_SENSOR_3:
// getWeight(carRecordMessageDtoList, map, carRecordMessageDto,29);
break;
case Constant.WEIGHT_SENSOR_4:
// getWeight(carRecordMessageDtoList, map, carRecordMessageDto,31);
break;
case Constant.SHAKE_SENSOR:
log.info("倾角传感器:{}",carRecordMessageDto);
long shakeValue = getShakeValue(carRecordMessageDto);
map.put(carRecordMessageDto.getAddr(),shakeValue);
if(map.get(21) != null && map.get(22) != null && map.get(23) != null ){
String value = map.get(21) + "," + map.get(22) + "," + map.get(23);
carRecordMessageDto.setValue(value);
carRecordMessageDtoList.add(carRecordMessageDto);
}
break;
case Constant.THROMBOLYTIC:
case Constant.BOLUS_DOSE:
case Constant.MAINTENANCE_DOSE:
BigDecimal value1 = BigDecimal.valueOf(Double.parseDouble(carRecordMessageDto.getValue())).divide(BigDecimal.valueOf(100),2,BigDecimal.ROUND_HALF_DOWN);
carRecordMessageDto.setValue(value1.toString());
carRecordMessageDtoList.add(carRecordMessageDto);
break;
default:
carRecordMessageDtoList.add(carRecordMessageDto);
break;
}
});
carRecordMessageDtoList.forEach(carRecordMessageDto -> {
try {
log.info("处理后的平车消息:{}",carRecordMessageDto);
recordService.disposeMessage(carRecordMessageDto);
} catch (Exception e) {
e.printStackTrace();
}
});
}
private long getShakeValue(CarRecordMessageDto carRecordMessageDto) {
String key = Constant.FIRST_AID + carRecordMessageDto.getAuthId() + carRecordMessageDto.getAddr();
long value = 0L;
//redis查找该平车上一次的倾角数据
Object o = redisUtil.get(key);
if(ObjectUtil.isNull(o)){
//如果没有依次存入redis,value值都是0
redisUtil.set(key,carRecordMessageDto.getValue());
carRecordMessageDto.setValue(0+"");
}else {
//如果有,用当前的值减去上次的数据,得到的是新的value
value = Long.parseLong(carRecordMessageDto.getValue()) - Long.parseLong(o.toString());
}
return value;
}
private void getWeight(List<CarRecordMessageDto> carRecordMessageDtoList, Map<Integer, Long> map, CarRecordMessageDto carRecordMessageDto,int highAddr) {
boolean flag = carRecordMessageDto.getAddr() == highAddr;
Long weight = getWeight(map, carRecordMessageDto, flag ? highAddr + 1 : highAddr,flag);
log.info("计算后的重量:{}",weight);
if(weight == null){
return;
}
carRecordMessageDto.setValue(weight.toString());
carRecordMessageDtoList.add(carRecordMessageDto);
}
private Long getWeight(Map<Integer, Long> map, CarRecordMessageDto carRecordMessageDto,int value2,boolean firstHigh) {
log.info("value = {},,firstHigh={}",value2,firstHigh);
if(map.get(value2) == null){
map.put(carRecordMessageDto.getAddr(),Long.parseLong(carRecordMessageDto.getValue()));
return null;
}else {
long weight1 = Long.parseLong(carRecordMessageDto.getValue());
long weight2 = map.get(value2);
log.info("准备计算重量:{},,,{}",weight1,weight2);
if(firstHigh){
log.info("weight1 << 16 + weight2:{}",weight1 << 16 | weight2);
return weight1 << 16 | weight2;
}else {
log.info("weight2 << 16 + weight1:{}",weight2 << 16 | weight1);
return weight2 << 16 | weight1;
}
}
}
}

163
wisdomcar/src/main/java/com/ccsens/wisdomcar/service/RecordService.java

@ -12,6 +12,7 @@ import com.ccsens.util.bean.message.common.MessageRule;
import com.ccsens.wisdomcar.bean.dto.Message.CarRecordMessageDto;
import com.ccsens.wisdomcar.bean.po.*;
import com.ccsens.wisdomcar.bean.vo.Message.CarRecordMessageVo;
import com.ccsens.wisdomcar.bean.vo.StepVo;
import com.ccsens.wisdomcar.persist.dao.StepDao;
import com.ccsens.wisdomcar.persist.mapper.*;
import com.ccsens.wisdomcar.util.Constant;
@ -21,6 +22,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
@ -58,24 +60,19 @@ public class RecordService implements IRecordService{
if(ObjectUtil.isNull(carRecordMessageDto)){
return;
}
log.info("接受信息:{}",carRecordMessageDto);
//查找平车信息
WisdomCar wisdomCar = null;
WisdomCarExample wisdomCarExample = new WisdomCarExample();
wisdomCarExample.createCriteria().andCarNumberEqualTo(carRecordMessageDto.getCarNumber());
wisdomCarExample.createCriteria().andCarNumberEqualTo(carRecordMessageDto.getAuthId());
List<WisdomCar> wisdomCars = wisdomCarMapper.selectByExample(wisdomCarExample);
if(CollectionUtil.isNotEmpty(wisdomCars)){
wisdomCar = wisdomCars.get(0);
}
if(ObjectUtil.isNull(wisdomCar)){
log.info("找不到平车id");
return;
}
WisdomCarRecord wisdomCarRecord = new WisdomCarRecord();
wisdomCarRecord.setId(snowflake.nextId());
wisdomCarRecord.setCarId(wisdomCars.get(0).getId());
wisdomCarRecord.setType(carRecordMessageDto.getType());
wisdomCarRecord.setValue(carRecordMessageDto.getValue());
wisdomCarRecord.setTime(carRecordMessageDto.getTime());
wisdomCarRecordMapper.insertSelective(wisdomCarRecord);
//查找医院大屏的userId(暂时查找主屏幕)
Set<String> userIdSet = new HashSet<>();
@ -85,111 +82,135 @@ public class RecordService implements IRecordService{
if(CollectionUtil.isNotEmpty(screenList)){
screenList.forEach(screen -> userIdSet.add(screen.getUserId().toString()));
}
//如果是称重信息,制造测试数据发送大屏
boolean f = false;
if(carRecordMessageDto.getType() == Constant.CAR_RECORD_WEIGHT){
String value = stepDao.getRecordByCarIdAndType(wisdomCars.get(0).getId(),carRecordMessageDto.getType());
if(!carRecordMessageDto.getValue().equals(value)){
f = true;
}
}
WisdomCarRecord wisdomCarRecord = new WisdomCarRecord();
wisdomCarRecord.setId(snowflake.nextId());
wisdomCarRecord.setCarId(wisdomCars.get(0).getId());
wisdomCarRecord.setType(carRecordMessageDto.getType());
wisdomCarRecord.setValue(carRecordMessageDto.getValue());
wisdomCarRecord.setTime(carRecordMessageDto.getTime());
wisdomCarRecordMapper.insertSelective(wisdomCarRecord);
//获取流程
String step = null;
StepVo.Step step = null;
if(carRecordMessageDto.getType() == Constant.CAR_RECORD_WEIGHT){
step = stepDao.getCodeByStepOne();
//处理体重数据
int weightInt = Integer.parseInt(carRecordMessageDto.getValue());
BigDecimal weight = BigDecimal.valueOf(weightInt).divide(BigDecimal.valueOf(1000),2,BigDecimal.ROUND_HALF_DOWN);
carRecordMessageDto.setValue(weight+"");
if(f){
log.info("处理称重信息");
doseAndSensorMessage(carRecordMessageDto, userIdSet);
}
}
if(carRecordMessageDto.getType() == Constant.CAR_RECORD_START){
step = stepDao.getCodeByStepOne();
}
if(carRecordMessageDto.getType() == Constant.CAR_RECORD_RFID){
step = stepDao.getCodeByRfId(carRecordMessageDto.getValue());
}
//发送消息
sendRecordMessage(carRecordMessageDto,userIdSet,step);
//如果是称重信息,制造测试数据发送大屏
sendRecordMessage(carRecordMessageDto,userIdSet,step == null?null:step.getStepCode(),step == null?null:step.getStepType());
if(carRecordMessageDto.getType() == Constant.CAR_RECORD_WEIGHT){
doseAndSensorMessage(carRecordMessageDto, userIdSet);
}
// //如果是称重信息,制造测试数据发送大屏
// if(carRecordMessageDto.getType() == Constant.CAR_RECORD_WEIGHT){
//
// String value = stepDao.getRecordByCarIdAndType(wisdomCars.get(0).getId(),carRecordMessageDto.getType());
// BigDecimal weight = BigDecimal.valueOf(Double.parseDouble(value)).divide(BigDecimal.valueOf(1000),2,BigDecimal.ROUND_HALF_DOWN);
// if(!carRecordMessageDto.getValue().equals(weight.toString())){
// log.info("处理称重信息");
// doseAndSensorMessage(carRecordMessageDto, userIdSet);
// }
// }
//新建急救表存储信息
saveAidRecord(carRecordMessageDto, wisdomCar.getId());
saveAidRecord(carRecordMessageDto, wisdomCar.getId(),step);
}
private void doseAndSensorMessage(CarRecordMessageDto carRecordMessageDto, Set<String> userIdSet) throws Exception {
//体重 单位g
int weightInt = Integer.parseInt(carRecordMessageDto.getValue());
// /*剂量数据*/
// //计算剂量信息 总剂量 = 重量 * 0.9,团注剂量=总剂量*10%,维持剂量=总剂量*90%,均保留两位小数(重量为kg,消息发送的重量为g,需处理)
// String dosage;
// BigDecimal weight = BigDecimal.valueOf(weightInt).divide(BigDecimal.valueOf(1000),2,BigDecimal.ROUND_HALF_UP);
// //总剂量
// BigDecimal totalDose = weight.multiply(BigDecimal.valueOf(0.9)).setScale(2, BigDecimal.ROUND_HALF_UP);
// //团注剂量
// BigDecimal dose1 = totalDose.multiply(BigDecimal.valueOf(0.1)).setScale(2, BigDecimal.ROUND_HALF_UP);
// //维持剂量
// BigDecimal dose2 = totalDose.subtract(dose1);
// dosage = totalDose + "," + dose1 + "," + dose2;
// //发送消息
// CarRecordMessageDto dosageRecord = new CarRecordMessageDto();
// BeanUtil.copyProperties(carRecordMessageDto,dosageRecord);
// dosageRecord.setType(Constant.CAR_RECORD_DOSAGE);
// dosageRecord.setValue(dosage);
// //发送消息
// sendRecordMessage(dosageRecord,userIdSet);
BigDecimal weightInt = BigDecimal.valueOf(Double.parseDouble(carRecordMessageDto.getValue()));
BigDecimal sensor1 = BigDecimal.valueOf(0);
BigDecimal sensor2 = BigDecimal.valueOf(0);
BigDecimal sensor3 = BigDecimal.valueOf(0);
BigDecimal sensor4 = BigDecimal.valueOf(0);
/*称重传感器数据*/
//获取一个5000以内的平均数
Random random = new Random();
int randomWeight = random.nextInt(5000);
//体重除以4
int aveWeight = weightInt / 4;
int sensor1 = aveWeight - randomWeight;
int sensor2 = aveWeight + randomWeight;
int sensor3 = aveWeight - randomWeight;
int sensor4 = weightInt - sensor1 - sensor2 - sensor3;
if(!weightInt.equals(BigDecimal.valueOf(0))){
//获取一个5000以内的平均数
Random random = new Random();
BigDecimal randomWeight1 = BigDecimal.valueOf(random.nextInt(5000)).divide(BigDecimal.valueOf(1000),2,BigDecimal.ROUND_HALF_DOWN);
BigDecimal randomWeight2 = BigDecimal.valueOf(random.nextInt(5000)).divide(BigDecimal.valueOf(1000),2,BigDecimal.ROUND_HALF_DOWN);
//体重除以4
BigDecimal aveWeight = weightInt.divide(BigDecimal.valueOf(4),3,BigDecimal.ROUND_HALF_DOWN);
if(aveWeight.compareTo(BigDecimal.valueOf(5000)) < 1){
BigDecimal divide = aveWeight.multiply(BigDecimal.valueOf(1000)).divide(BigDecimal.valueOf(3), 2, BigDecimal.ROUND_HALF_DOWN);
randomWeight1 = BigDecimal.valueOf(random.nextInt(divide.intValue())).divide(BigDecimal.valueOf(1000),2,BigDecimal.ROUND_HALF_DOWN);
randomWeight2 = BigDecimal.valueOf(random.nextInt(divide.intValue())).divide(BigDecimal.valueOf(1000),2,BigDecimal.ROUND_HALF_DOWN);
}
sensor1 = aveWeight.subtract(randomWeight1);
sensor2 = aveWeight.add(randomWeight1);
sensor3 = aveWeight.subtract(randomWeight2);
sensor4 = weightInt.subtract(sensor1).subtract(sensor2).subtract(sensor3);
if(sensor4.compareTo(BigDecimal.valueOf(0)) < 1){
sensor4 = BigDecimal.valueOf(0);
}
}
//第一个传感器
CarRecordMessageDto sensorMessage1 = new CarRecordMessageDto();
BeanUtil.copyProperties(carRecordMessageDto,sensorMessage1);
sensorMessage1.setType(Constant.WEIGHT_SENSOR_1);
sensorMessage1.setValue(sensor1 + "");
log.info("传感器一数据:{}",sensorMessage1);
//发送消息
sendRecordMessage(sensorMessage1,userIdSet,null);
sendRecordMessage(sensorMessage1,userIdSet,null,null);
//第二个传感器
CarRecordMessageDto sensorMessage2 = new CarRecordMessageDto();
BeanUtil.copyProperties(carRecordMessageDto,sensorMessage2);
sensorMessage2.setType(Constant.WEIGHT_SENSOR_2);
sensorMessage2.setValue(sensor2 + "");
log.info("传感器二数据:{}",sensorMessage2);
//发送消息
sendRecordMessage(sensorMessage2,userIdSet,null);
sendRecordMessage(sensorMessage2,userIdSet,null,null);
//第三个传感器
CarRecordMessageDto sensorMessage3 = new CarRecordMessageDto();
BeanUtil.copyProperties(carRecordMessageDto,sensorMessage3);
sensorMessage3.setType(Constant.WEIGHT_SENSOR_3);
sensorMessage3.setValue(sensor3 + "");
log.info("传感器三数据:{}",sensorMessage3);
//发送消息
sendRecordMessage(sensorMessage3,userIdSet,null);
sendRecordMessage(sensorMessage3,userIdSet,null,null);
//第四个传感器
CarRecordMessageDto sensorMessage4 = new CarRecordMessageDto();
BeanUtil.copyProperties(carRecordMessageDto,sensorMessage4);
sensorMessage4.setType(Constant.WEIGHT_SENSOR_4);
sensorMessage4.setValue(sensor4 + "");
log.info("传感器四数据:{}",sensorMessage4);
//发送消息
sendRecordMessage(sensorMessage4,userIdSet,null);
// /*震动传感器数据*/
// //随机生成坐标
// int shakeX = random.nextInt(65535);
// int shakeY = random.nextInt(65535);
// int shakeZ = random.nextInt(65535);
// //震动传感器
// CarRecordMessageDto shakeMessage = new CarRecordMessageDto();
// BeanUtil.copyProperties(carRecordMessageDto,shakeMessage);
// shakeMessage.setType(Constant.SHAKE_SENSOR);
// shakeMessage.setValue(shakeX + "," + shakeY + "," + shakeZ);
// //发送消息
// sendRecordMessage(shakeMessage,userIdSet);
// return dosage;
sendRecordMessage(sensorMessage4,userIdSet,null,null);
}
/**
* 发送消息
*/
private void sendRecordMessage(CarRecordMessageDto carRecordMessageDto,Set<String> userIdSet,String step) throws Exception {
CarRecordMessageVo carRecordMessageVo = new CarRecordMessageVo(carRecordMessageDto.getCarNumber(),carRecordMessageDto.getType(),carRecordMessageDto.getValue(),carRecordMessageDto.getTime(),step);
private void sendRecordMessage(CarRecordMessageDto carRecordMessageDto,Set<String> userIdSet,String stepCode,Byte stepType) throws Exception {
CarRecordMessageVo carRecordMessageVo = new CarRecordMessageVo(carRecordMessageDto.getAuthId(),carRecordMessageDto.getType(),
carRecordMessageDto.getValue(),carRecordMessageDto.getTime(),stepCode,stepType);
MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User);
messageRule.setAckRule(MessageRule.AckRule.NONE);
String s = JacksonUtil.beanToJson(carRecordMessageVo);
InMessage inMessage = InMessage.newToUserMessage(null,userIdSet,null,messageRule,s);
//发送消息
@ -199,7 +220,7 @@ public class RecordService implements IRecordService{
/**
* 添加急救信息和急救记录信息
*/
private void saveAidRecord(CarRecordMessageDto carRecordMessageDto, Long wisdomCarId) {
private void saveAidRecord(CarRecordMessageDto carRecordMessageDto, Long wisdomCarId, StepVo.Step step) {
// 如果是开始信息,新建一条急救表数据
String key = Constant.FIRST_AID + wisdomCarId;
if(carRecordMessageDto.getType() == Constant.CAR_RECORD_START){
@ -212,6 +233,11 @@ public class RecordService implements IRecordService{
firstAidMapper.insertSelective(firstAid);
//存入redis
redisUtil.set(key,firstAid.getId(),Constant.FIRST_AID_REDIS_TIME);
//删除redis内此平车之前的倾角数据
String keyX = Constant.FIRST_AID + carRecordMessageDto.getAuthId() + 21;
String keyY = Constant.FIRST_AID + carRecordMessageDto.getAuthId() + 22;
String keyZ = Constant.FIRST_AID + carRecordMessageDto.getAuthId() + 23;
redisUtil.del(keyX,keyY,keyZ);
return;
}
//redis查询急救表
@ -237,14 +263,14 @@ public class RecordService implements IRecordService{
case Constant.THROMBOLYTIC:
case Constant.BOLUS_DOSE:
case Constant.MAINTENANCE_DOSE:
saveFirstAidRecord(carRecordMessageDto,firstAidId);
saveFirstAidRecord(carRecordMessageDto,firstAidId,step);
break;
default:
}
}
private void saveFirstAidRecord(CarRecordMessageDto carRecordMessageDto, Long firstAidId) {
private void saveFirstAidRecord(CarRecordMessageDto carRecordMessageDto, Long firstAidId, StepVo.Step step) {
String reidKey;
if(carRecordMessageDto.getType() == Constant.CAR_RECORD_RFID){
reidKey = Constant.FIRST_AID + firstAidId + "_" + carRecordMessageDto.getType() + "_" + carRecordMessageDto.getValue();
@ -274,6 +300,7 @@ public class RecordService implements IRecordService{
aidRecord.setFirstAidId(firstAidId);
aidRecord.setBeginTime(carRecordMessageDto.getTime());
aidRecord.setType(carRecordMessageDto.getType());
aidRecord.setStepId(step == null ? null : step.getId());
firstAidRecordMapper.insertSelective(aidRecord);
//添加redis
redisUtil.set(reidKey,aidRecord.getId(),Constant.FIRST_AID_REDIS_TIME);

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

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

22
wisdomcar/src/main/resources/mapper_dao/StepDao.xml

@ -3,9 +3,11 @@
<mapper namespace="com.ccsens.wisdomcar.persist.dao.StepDao">
<select id="getCodeByRfId" resultType="java.lang.String">
<select id="getCodeByRfId" resultType="com.ccsens.wisdomcar.bean.vo.StepVo$Step">
SELECT
s.
s.id,
s.code as stepCode,
s.step_type as stepType
FROM
`t_step` s,
t_rfid r
@ -14,12 +16,24 @@
and r.rfid = #{rfid}
limit 1
</select>
<select id="getCodeByStepOne" resultType="java.lang.String">
<select id="getCodeByStepOne" resultType="com.ccsens.wisdomcar.bean.vo.StepVo$Step">
SELECT
s.code
s.id,
s.code as stepCode,
s.step_type as stepType
FROM
`t_step` s
ORDER BY id
limit 1
</select>
<select id="getRecordByCarIdAndType" resultType="java.lang.String">
SELECT
`value`
FROM `t_wisdom_car_record`
WHERE
car_id = 1
and type = 1
ORDER BY time DESC
limit 1
</select>
</mapper>

27
wisdomcar/src/main/resources/mapper_raw/FirstAidRecordMapper.xml

@ -7,6 +7,7 @@
<result column="type" jdbcType="TINYINT" property="type" />
<result column="value" jdbcType="VARCHAR" property="value" />
<result column="begin_time" jdbcType="BIGINT" property="beginTime" />
<result column="step_id" jdbcType="BIGINT" property="stepId" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="rec_status" jdbcType="TINYINT" property="recStatus" />
@ -70,7 +71,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, first_aid_id, type, value, begin_time, created_at, updated_at, rec_status
id, first_aid_id, type, value, begin_time, step_id, created_at, updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.wisdomcar.bean.po.FirstAidRecordExample" resultMap="BaseResultMap">
select
@ -104,11 +105,13 @@
</delete>
<insert id="insert" parameterType="com.ccsens.wisdomcar.bean.po.FirstAidRecord">
insert into t_first_aid_record (id, first_aid_id, type,
value, begin_time, created_at,
updated_at, rec_status)
value, begin_time, step_id,
created_at, updated_at, rec_status
)
values (#{id,jdbcType=BIGINT}, #{firstAidId,jdbcType=BIGINT}, #{type,jdbcType=TINYINT},
#{value,jdbcType=VARCHAR}, #{beginTime,jdbcType=BIGINT}, #{createdAt,jdbcType=TIMESTAMP},
#{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT})
#{value,jdbcType=VARCHAR}, #{beginTime,jdbcType=BIGINT}, #{stepId,jdbcType=BIGINT},
#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT}
)
</insert>
<insert id="insertSelective" parameterType="com.ccsens.wisdomcar.bean.po.FirstAidRecord">
insert into t_first_aid_record
@ -128,6 +131,9 @@
<if test="beginTime != null">
begin_time,
</if>
<if test="stepId != null">
step_id,
</if>
<if test="createdAt != null">
created_at,
</if>
@ -154,6 +160,9 @@
<if test="beginTime != null">
#{beginTime,jdbcType=BIGINT},
</if>
<if test="stepId != null">
#{stepId,jdbcType=BIGINT},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=TIMESTAMP},
</if>
@ -189,6 +198,9 @@
<if test="record.beginTime != null">
begin_time = #{record.beginTime,jdbcType=BIGINT},
</if>
<if test="record.stepId != null">
step_id = #{record.stepId,jdbcType=BIGINT},
</if>
<if test="record.createdAt != null">
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
</if>
@ -210,6 +222,7 @@
type = #{record.type,jdbcType=TINYINT},
value = #{record.value,jdbcType=VARCHAR},
begin_time = #{record.beginTime,jdbcType=BIGINT},
step_id = #{record.stepId,jdbcType=BIGINT},
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
rec_status = #{record.recStatus,jdbcType=TINYINT}
@ -232,6 +245,9 @@
<if test="beginTime != null">
begin_time = #{beginTime,jdbcType=BIGINT},
</if>
<if test="stepId != null">
step_id = #{stepId,jdbcType=BIGINT},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=TIMESTAMP},
</if>
@ -250,6 +266,7 @@
type = #{type,jdbcType=TINYINT},
value = #{value,jdbcType=VARCHAR},
begin_time = #{beginTime,jdbcType=BIGINT},
step_id = #{stepId,jdbcType=BIGINT},
created_at = #{createdAt,jdbcType=TIMESTAMP},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
rec_status = #{recStatus,jdbcType=TINYINT}

25
wisdomcar/src/main/resources/mapper_raw/StepMapper.xml

@ -6,6 +6,7 @@
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="sequence" jdbcType="INTEGER" property="sequence" />
<result column="step_type" jdbcType="TINYINT" property="stepType" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="rec_status" jdbcType="TINYINT" property="recStatus" />
@ -69,7 +70,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, name, code, sequence, created_at, updated_at, rec_status
id, name, code, sequence, step_type, created_at, updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.wisdomcar.bean.po.StepExample" resultMap="BaseResultMap">
select
@ -103,11 +104,11 @@
</delete>
<insert id="insert" parameterType="com.ccsens.wisdomcar.bean.po.Step">
insert into t_step (id, name, code,
sequence, created_at, updated_at,
rec_status)
sequence, step_type, created_at,
updated_at, rec_status)
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR},
#{sequence,jdbcType=INTEGER}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP},
#{recStatus,jdbcType=TINYINT})
#{sequence,jdbcType=INTEGER}, #{stepType,jdbcType=TINYINT}, #{createdAt,jdbcType=TIMESTAMP},
#{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="com.ccsens.wisdomcar.bean.po.Step">
insert into t_step
@ -124,6 +125,9 @@
<if test="sequence != null">
sequence,
</if>
<if test="stepType != null">
step_type,
</if>
<if test="createdAt != null">
created_at,
</if>
@ -147,6 +151,9 @@
<if test="sequence != null">
#{sequence,jdbcType=INTEGER},
</if>
<if test="stepType != null">
#{stepType,jdbcType=TINYINT},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=TIMESTAMP},
</if>
@ -179,6 +186,9 @@
<if test="record.sequence != null">
sequence = #{record.sequence,jdbcType=INTEGER},
</if>
<if test="record.stepType != null">
step_type = #{record.stepType,jdbcType=TINYINT},
</if>
<if test="record.createdAt != null">
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
</if>
@ -199,6 +209,7 @@
name = #{record.name,jdbcType=VARCHAR},
code = #{record.code,jdbcType=VARCHAR},
sequence = #{record.sequence,jdbcType=INTEGER},
step_type = #{record.stepType,jdbcType=TINYINT},
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
rec_status = #{record.recStatus,jdbcType=TINYINT}
@ -218,6 +229,9 @@
<if test="sequence != null">
sequence = #{sequence,jdbcType=INTEGER},
</if>
<if test="stepType != null">
step_type = #{stepType,jdbcType=TINYINT},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=TIMESTAMP},
</if>
@ -235,6 +249,7 @@
set name = #{name,jdbcType=VARCHAR},
code = #{code,jdbcType=VARCHAR},
sequence = #{sequence,jdbcType=INTEGER},
step_type = #{stepType,jdbcType=TINYINT},
created_at = #{createdAt,jdbcType=TIMESTAMP},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
rec_status = #{recStatus,jdbcType=TINYINT}

Loading…
Cancel
Save