BusDeviceAlarmEntity.java 8.4 KB

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