BusDeviceAlarmEntity.java 7.4 KB

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