|
|
@@ -0,0 +1,217 @@
|
|
|
+package com.coffee.bus.device;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.coffee.bus.bean.DeviceBasicInfo;
|
|
|
+import com.coffee.common.enums.SexEnum;
|
|
|
+import com.coffee.common.redis.RedisUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author lifang
|
|
|
+ * @version 1.0.0
|
|
|
+ * @ClassName DeviceOperator.java
|
|
|
+ * @Description 设备注册操作
|
|
|
+ * @createTime 2022年04月01日 17:14:00
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+public class DeviceOperator {
|
|
|
+ private final DeviceBasicInfo deviceBasicInfo;
|
|
|
+
|
|
|
+ private final RedisUtils redisUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 该操作是否有效,即判断该操作是否存在设备id
|
|
|
+ */
|
|
|
+ private final boolean validate;
|
|
|
+
|
|
|
+ public static DeviceOperator of(DeviceBasicInfo deviceBasicInfo,RedisUtils redisUtils){
|
|
|
+ return new DeviceOperator(deviceBasicInfo,redisUtils,StrUtil.isNullOrUndefined(deviceBasicInfo.getDeviceId()));
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 清除缓存
|
|
|
+ */
|
|
|
+ public DeviceOperator clear(){
|
|
|
+ if(!validate)return this;
|
|
|
+ redisUtils.del(deviceBasicInfo.getDeviceId());
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 将自身同步至redis
|
|
|
+ * @param
|
|
|
+ */
|
|
|
+ public DeviceOperator sysn(){
|
|
|
+ if(!validate)return this;
|
|
|
+ redisUtils.hmset(this.getDeviceId(),getMap());
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOperator updateEnable(Integer enable){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setEnable(enable);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"enable",enable);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOperator updateTenantId(String tenantId){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setTenantId(tenantId);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"tenantId",tenantId);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public DeviceOperator updateRunId(String runId){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setId(runId);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"id",runId);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOperator updateStartTime(Date startTime){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setStartTime(startTime);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"startTime",startTime);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public DeviceOperator updateRegisterTime(Date registerTime){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setRegisterTime(registerTime);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"registerTime",registerTime);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public DeviceOperator updatePatientCode(String patientCode){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setPatientCode(patientCode);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"patientCode",patientCode);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public DeviceOperator updatePatientName(String patientName){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setPatientName(patientName);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"patientName",patientName);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public DeviceOperator updateGender(SexEnum gender){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setGender(gender);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"gender",gender);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public DeviceOperator updateBedNo(String bedNo){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setBedNo(bedNo);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"bedNo",bedNo);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public DeviceOperator updateWard(String ward){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setWard(ward);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"ward",ward);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public DeviceOperator updateRemark(String remark){
|
|
|
+ if(!validate)return this;
|
|
|
+ deviceBasicInfo.setRemark(remark);
|
|
|
+ redisUtils.hset(deviceBasicInfo.getDeviceId(),"remark",remark);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String getDeviceId(){
|
|
|
+ return deviceBasicInfo.getDeviceId();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getAlias(){
|
|
|
+ return deviceBasicInfo.getAlias();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getTenantId(){
|
|
|
+ return deviceBasicInfo.getTenantId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取正在运行设备绑定id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getRunId(){
|
|
|
+ return deviceBasicInfo.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Date getStartTime(){
|
|
|
+ return deviceBasicInfo.getStartTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Date getRegisterTime(){
|
|
|
+ return deviceBasicInfo.getRegisterTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getPatientCode(){
|
|
|
+ return deviceBasicInfo.getPatientCode();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getPatientName(){
|
|
|
+ return deviceBasicInfo.getPatientName();
|
|
|
+ }
|
|
|
+
|
|
|
+ public SexEnum getGender(){
|
|
|
+ return deviceBasicInfo.getGender();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getBedNo(){
|
|
|
+ return deviceBasicInfo.getBedNo();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getWard(){
|
|
|
+ return deviceBasicInfo.getWard();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getRemark(){
|
|
|
+ return deviceBasicInfo.getRemark();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断设备在系统中是否存在
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean isExist(){
|
|
|
+ return deviceBasicInfo!=null&& !StrUtil.isEmpty(deviceBasicInfo.getDeviceId()) ;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断设备在医院中是否可以使用
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean canUse(){
|
|
|
+ return isExist()&&deviceBasicInfo.getEnable()!=null&&deviceBasicInfo.getEnable()==1 ;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String,Object> getMap(){
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+}
|