BusDeviceAlarmEntity.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package com.coffee.bus.entity;
  2. import cn.hutool.json.JSONObject;
  3. import com.baomidou.mybatisplus.annotation.FieldStrategy;
  4. import com.baomidou.mybatisplus.annotation.TableField;
  5. import com.baomidou.mybatisplus.annotation.TableName;
  6. import com.coffee.bus.entity.common.CommonDeviceParam;
  7. import com.coffee.bus.enums.DeviceAlarmEnum;
  8. import com.coffee.bus.enums.DeviceStatusEnum;
  9. import com.coffee.bus.enums.DeviceTypeEnum;
  10. import com.coffee.bus.enums.FlowStatusEnum;
  11. import com.coffee.common.entity.TenantGenericEntity;
  12. import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  13. import io.swagger.annotations.ApiModel;
  14. import io.swagger.annotations.ApiModelProperty;
  15. import lombok.Data;
  16. import lombok.EqualsAndHashCode;
  17. import lombok.ToString;
  18. import org.tio.utils.crypto.Md5;
  19. import java.util.Date;
  20. /**
  21. * @author lifang
  22. * @version 1.0.0
  23. * @ClassName BusDeviceAlarmEntity.java
  24. * @Description 设备报警信息
  25. * @createTime 2022年04月08日 16:18:00
  26. */
  27. @EqualsAndHashCode(callSuper = true)
  28. @Data
  29. @TableName(value = "bus_device_alarm",autoResultMap = true)
  30. @ApiModel(value="设备报警信息", description="设备报警信息记录")
  31. @ToString
  32. public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
  33. @ApiModelProperty(value = "设备唯一编码",accessMode = ApiModelProperty.AccessMode.READ_ONLY)
  34. private String deviceId;
  35. @ApiModelProperty(value = "报警时间")
  36. private Date uploadTime;
  37. @ApiModelProperty(value = "报警原因")
  38. private String cause;
  39. @ApiModelProperty(value = "是否为报警信息",hidden = true)
  40. @JsonIgnoreProperties
  41. private Boolean alarm;
  42. @ApiModelProperty(value = "报警记录所绑定的历史记录id,后续用于更新操作",hidden = true)
  43. @JsonIgnoreProperties(allowSetters = true)
  44. private String historyId;
  45. @ApiModelProperty(value = "输注记录")
  46. private String infusionId;
  47. @ApiModelProperty(value = "设备类型")
  48. private DeviceTypeEnum deviceType;
  49. @ApiModelProperty(value = "泵运行状态",accessMode = ApiModelProperty.AccessMode.READ_ONLY)
  50. @TableField(updateStrategy = FieldStrategy.IGNORED)
  51. private DeviceStatusEnum runState;
  52. @ApiModelProperty(value = "报警信息",accessMode = ApiModelProperty.AccessMode.READ_ONLY)
  53. @TableField(updateStrategy = FieldStrategy.IGNORED)
  54. private DeviceAlarmEnum alarmState;
  55. @ApiModelProperty(value = "输注即将结束提醒",accessMode = ApiModelProperty.AccessMode.READ_ONLY)
  56. @TableField(updateStrategy = FieldStrategy.IGNORED)
  57. private Boolean warnWillFinished;
  58. @ApiModelProperty(value = "镇痛不足提醒",accessMode = ApiModelProperty.AccessMode.READ_ONLY)
  59. @TableField(updateStrategy = FieldStrategy.IGNORED)
  60. private Boolean warnAnalgesicPoor;
  61. @ApiModelProperty(value = "电量偏低提醒",accessMode = ApiModelProperty.AccessMode.READ_ONLY)
  62. @TableField(updateStrategy = FieldStrategy.IGNORED)
  63. private Boolean warnLowBattery;
  64. @ApiModelProperty(value = "加减档提示",accessMode = ApiModelProperty.AccessMode.READ_ONLY)
  65. @TableField(updateStrategy = FieldStrategy.IGNORED)
  66. private FlowStatusEnum warnFlow;
  67. public static BusDeviceAlarmEntity parseHistory(BusDeviceHistoryEntity history){
  68. BusDeviceAlarmEntity entity = new BusDeviceAlarmEntity();
  69. entity.setDeviceId(history.getDeviceId());
  70. entity.setUploadTime(history.getUploadTime());
  71. if (history.getAlarm() != null && !DeviceAlarmEnum.None.equals(history.getAlarm())) {
  72. entity.setAlarm(true);
  73. }
  74. entity.setHistoryId(history.getId());
  75. entity.setInfusionId(history.getInfusionId());
  76. entity.setRunState(history.getRunState());
  77. entity.setAlarmState(history.getAlarm());
  78. entity.setWarnWillFinished(history.getWarnWillFinished());
  79. entity.setWarnAnalgesicPoor(history.getWarnAnalgesicPoor());
  80. entity.setWarnLowBattery(history.getWarnLowBattery());
  81. entity.setWarnFlow(history.getWarnFlow());
  82. entity.setTenantId(history.getTenantId());
  83. entity.setDeviceType(history.getType());
  84. return entity;
  85. }
  86. public static BusDeviceAlarmEntity parseRunning(BusInfusionHistoryEntity source){
  87. BusDeviceAlarmEntity entity = new BusDeviceAlarmEntity();
  88. entity.setDeviceId(source.getDeviceId());
  89. entity.setUploadTime(source.getLastUploadTime());
  90. if (source.getAlarm() != null && !DeviceAlarmEnum.None.equals(source.getAlarm())) {
  91. entity.setAlarm(true);
  92. }
  93. entity.setHistoryId(source.getId());
  94. entity.setInfusionId(source.getId());
  95. entity.setRunState(source.getRunState());
  96. entity.setAlarmState(source.getAlarm());
  97. entity.setWarnWillFinished(source.getWarnWillFinished());
  98. entity.setWarnAnalgesicPoor(source.getWarnAnalgesicPoor());
  99. entity.setWarnLowBattery(source.getWarnLowBattery());
  100. entity.setWarnFlow(source.getWarnFlow());
  101. entity.setTenantId(source.getTenantId());
  102. entity.setDeviceType(source.getType());
  103. return entity;
  104. }
  105. public String signParm(){
  106. JSONObject param = new JSONObject(true);
  107. param.putOpt("runState",String.valueOf(this.getRunState()));
  108. param.putOpt("alarmState",String.valueOf(this.getAlarmState()));
  109. param.putOpt("warnWillFinished",String.valueOf(this.getWarnWillFinished()));
  110. param.putOpt("warnAnalgesicPoor",String.valueOf(this.getWarnAnalgesicPoor()));
  111. param.putOpt("warnLowBattery",String.valueOf(this.getWarnLowBattery()));
  112. param.putOpt("warnFlow",String.valueOf(this.getWarnFlow()));
  113. return Md5.getMD5(param.toString());
  114. }
  115. public static boolean alarmOrWarn(CommonDeviceParam history){
  116. if (history.getAlarm() != null && !DeviceAlarmEnum.None.equals(history.getAlarm())) {
  117. return true;
  118. }
  119. if (Boolean.TRUE.equals(history.getWarnAnalgesicPoor())) {
  120. return true;
  121. }
  122. if (Boolean.TRUE.equals(history.getWarnLowBattery())) {
  123. return true;
  124. }
  125. if (Boolean.TRUE.equals(history.getWarnWillFinished())) {
  126. return true;
  127. }
  128. return history.getWarnFlow()!=null;
  129. }
  130. public static BusDeviceAlarmEntity noSignalOf(String deviceId,String infusionId,String historyId,String tenantId,Date uploadTIme){
  131. BusDeviceAlarmEntity result = of(deviceId,infusionId,historyId,tenantId,uploadTIme);
  132. result.setRunState(DeviceStatusEnum.NoSignal);
  133. return result;
  134. }
  135. public static BusDeviceAlarmEntity lowInfusion(String deviceId,String infusionId,String historyId,String tenantId,Date uploadTIme){
  136. BusDeviceAlarmEntity result = of(deviceId,infusionId,historyId,tenantId,uploadTIme);
  137. result.setWarnFlow(FlowStatusEnum.Lowest);
  138. return result;
  139. }
  140. public static BusDeviceAlarmEntity insufficient(String deviceId,String infusionId,String historyId,String tenantId,Date uploadTIme){
  141. BusDeviceAlarmEntity result = of(deviceId,infusionId,historyId,tenantId,uploadTIme);
  142. result.setWarnAnalgesicPoor(true);
  143. return result;
  144. }
  145. private static BusDeviceAlarmEntity of(String deviceId,String infusionId,String historyId,String tenantId,Date uploadTIme){
  146. BusDeviceAlarmEntity result = new BusDeviceAlarmEntity();
  147. result.setRunState(DeviceStatusEnum.Waiting);
  148. result.setInfusionId(infusionId);
  149. result.setTenantId(tenantId);
  150. result.setUploadTime(uploadTIme);
  151. result.setHistoryId(historyId);
  152. result.setAlarm(false);
  153. result.setAlarmState(DeviceAlarmEnum.None);
  154. result.setDeviceId(deviceId);
  155. result.setWarnLowBattery(false);
  156. result.setWarnFlow(FlowStatusEnum.None);
  157. result.setWarnAnalgesicPoor(false);
  158. result.setWarnWillFinished(false);
  159. return result;
  160. }
  161. }