ソースを参照

Merge remote-tracking branch 'origin/zsl' into dev

# Conflicts:
#	coffee-admin/src/test/java/com/coffee/admin/BusPatientTest.java
#	coffee-system/src/main/java/com/coffee/bus/mapper/BusDeviceAlarmMapper.java
#	coffee-system/src/main/java/com/coffee/bus/mapper/BusDeviceMapper.java
#	coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceAlarmService.java
#	coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceService.java
15638522405 3 年 前
コミット
ac2508d6e5

+ 23 - 187
coffee-admin/src/test/java/com/coffee/admin/BusPatientTest.java

@@ -1,33 +1,20 @@
 package com.coffee.admin;
 
-import cn.hutool.core.date.DateField;
-import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.EnumUtil;
-import cn.hutool.core.util.RandomUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.coffee.bus.controller.BusDeviceManualController;
-import com.coffee.bus.controller.vo.DeviceManualVo;
-import com.coffee.bus.entity.BusClinicEntity;
-import com.coffee.bus.entity.BusDeviceManualEntity;
-import com.coffee.bus.entity.BusPatientEntity;
-import com.coffee.bus.enums.DeviceManualEnum;
-import com.coffee.bus.his.strategy.all.EqualsStrategyHandler;
-import com.coffee.bus.his.strategy.all.HisAllStrategyHandler;
-import com.coffee.bus.service.LocalBusClinicService;
+import com.coffee.bus.controller.vo.DeviceUse;
+import com.coffee.bus.entity.BusDeviceAlarmEntity;
+import com.coffee.bus.enums.DeviceAlarmEnum;
+import com.coffee.bus.mapper.BusDeviceAlarmMapper;
+import com.coffee.bus.service.LocalBusDeviceAlarmService;
 import com.coffee.bus.service.LocalBusPatientService;
 import com.coffee.bus.service.dto.PatientDeviceRepeatResult;
-import com.coffee.common.enums.SexEnum;
-import org.hibernate.validator.constraints.Length;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
-import java.util.*;
-import java.util.stream.Collectors;
+import java.util.List;
 
 /**
  * @author lifang
@@ -41,190 +28,39 @@ import java.util.stream.Collectors;
 public class BusPatientTest {
     @Autowired
     private LocalBusPatientService patientService;
-
-    @Autowired
-    private LocalBusClinicService clinicService;
-
     @Autowired
-    private EqualsStrategyHandler equalsStrategyHandler;
+    private LocalBusDeviceAlarmService deviceAlarmService;
     @Autowired
-    private BusDeviceManualController manualController;
+    private BusDeviceAlarmMapper deviceAlarmMapper;
+
     @Test
     public  void test(){
         List<PatientDeviceRepeatResult> patientDeviceRepeatResults = patientService.repeatDevice();
-        System.out.println(getName());
         System.out.println(patientDeviceRepeatResults);
     }
 
-    public static List<String> clinicNames= Arrays.asList("阑尾手术","肛门手术","肝脏手术","感冒","发烧","肠其他手术","结肠造口术","回肠造口术","肠造口闭合术","肠固定术","肠的其他修补","阑尾切除术","腹腔镜下阑尾切除术","阑尾切除术","阑尾残端切除术");
-    public static List<String> anaTypes=Arrays.asList("局部麻醉","全麻");
-    public static List<String> analTypes=Arrays.asList("PCIA","PCEA","PCSA","PCNA");
-
     @Test
-    public void save(){
-        for (int i = 0; i < 30; i++) {
-            BusClinicEntity clinic = new BusClinicEntity();
-            clinic.setStartTime(new Date());
-            clinic.setName(clinicNames.get(RandomUtil.randomInt(clinicNames.size()-1)));
-            clinic.setPatientName(getName());
-            clinic.setPatientGender(EnumUtil.likeValueOf(SexEnum.class,RandomUtil.randomInt(1,2)));
-            clinic.setBedNo(String.valueOf(RandomUtil.randomInt(10,100)));
-            clinic.setWard(String.valueOf(RandomUtil.randomInt(10,100)));
-            clinic.setWeight(String.valueOf(RandomUtil.randomInt(90,150)));
-            clinic.setWeight(String.valueOf(RandomUtil.randomInt(150,200)));
-            clinic.setAnaDoctor(getName());
-            clinic.setAnaType(anaTypes.get(RandomUtil.randomInt(anaTypes.size()-1)));
-            clinic.setAnalType(analTypes.get(RandomUtil.randomInt(analTypes.size()-1)));
-            clinic.setSurgeryDoctor(getName());
-            clinic.setConfigPerson(getName());
-            clinic.setPatientCode(String.valueOf(RandomUtil.randomInt(100000,300000)));
-            clinic.setMonitorType(true);
-            clinic.setTenantId("1");
-            BusPatientEntity patient = BusPatientEntity.of(clinic);
-//        patientService.save(patient);
-//        clinicService.save(clinic);
-            patientService.manualEdit(clinic);
+    public  void test1(){
+        List<DeviceUse> deviceUseList = deviceAlarmService.countAlarm();
+        for (DeviceUse d:
+             deviceUseList) {
+            System.out.println(d);
         }
     }
-
-    @Test
-    public void fill(){
-        List<BusClinicEntity> clinicList = clinicService.list(new QueryWrapper<BusClinicEntity>().lambda().eq(BusClinicEntity::getMonitorType, true));
-        Map<String, List<BusClinicEntity>> groupByHospital = clinicList.stream().collect(Collectors.groupingBy(BusClinicEntity::getTenantId));
-        groupByHospital.forEach((tenantId,list)->{
-            Map< String, List<BusClinicEntity>> groupByPatientCode = list.stream().collect(Collectors.groupingBy(BusClinicEntity::getPatientCode));
-            groupByPatientCode.forEach((k,targets)->{
-                List<BusClinicEntity> source = new ArrayList<>();
-                for (BusClinicEntity target : targets) {
-                    BusClinicEntity clinic = new BusClinicEntity();
-                    clinic.setStartTime(target.getStartTime()==null?
-                            RandomUtil.randomDate(DateUtil.beginOfMonth(new Date()), DateField.HOUR,-30,30):target.getStartTime());
-                    clinic.setName(clinicNames.get(RandomUtil.randomInt(clinicNames.size()-1)));
-                    clinic.setPatientName(getName());
-                    clinic.setPatientGender(EnumUtil.likeValueOf(SexEnum.class,RandomUtil.randomInt(1,2)));
-                    clinic.setBedNo(target.getBedNo());
-                    clinic.setWard(target.getWard());
-                    clinic.setWeight(String.valueOf(RandomUtil.randomInt(90,150)));
-                    clinic.setWeight(String.valueOf(RandomUtil.randomInt(150,200)));
-                    clinic.setAnaDoctor(getName());
-                    clinic.setAnaType(anaTypes.get(RandomUtil.randomInt(anaTypes.size()-1)));
-                    clinic.setAnalType(analTypes.get(RandomUtil.randomInt(analTypes.size()-1)));
-                    clinic.setSurgeryDoctor(getName());
-                    clinic.setConfigPerson(getName());
-                    clinic.setPatientCode(target.getPatientCode());
-                    clinic.setMonitorType(true);
-                    clinic.setTenantId("1");
-                    source.add(clinic);
-                }
-                equalsStrategyHandler.handle(source,targets);
-            });
-
-        });
-
-    }
-    public void fillPatientCode(){
-        List<BusPatientEntity> list = patientService.list();
-    }
-
     @Test
-    public void manualSave(){
-        for (int i = 0; i < 30; i++) {
-            DeviceManualVo deviceManualVo = new DeviceManualVo();
-            BusClinicEntity clinic = new BusClinicEntity();
-            clinic.setStartTime(new Date());
-            clinic.setName(clinicNames.get(RandomUtil.randomInt(clinicNames.size()-1)));
-            clinic.setPatientAge(RandomUtil.randomInt(15,50));
-            clinic.setPatientName(getName());
-            clinic.setPatientGender(EnumUtil.likeValueOf(SexEnum.class,RandomUtil.randomInt(1,2)));
-            clinic.setBedNo(String.valueOf(RandomUtil.randomInt(10,100)));
-            clinic.setWard(String.valueOf(RandomUtil.randomInt(10,100)));
-            clinic.setWeight(String.valueOf(RandomUtil.randomInt(90,150)));
-            clinic.setWeight(String.valueOf(RandomUtil.randomInt(150,200)));
-            clinic.setAnaDoctor(getName());
-            clinic.setAnaType(anaTypes.get(RandomUtil.randomInt(anaTypes.size()-1)));
-            clinic.setAnalType(analTypes.get(RandomUtil.randomInt(analTypes.size()-1)));
-            clinic.setSurgeryDoctor(getName());
-            clinic.setConfigPerson(getName());
-            clinic.setPatientCode(String.valueOf(RandomUtil.randomInt(100000,300000)));
-            clinic.setTenantId("1");
-
-            deviceManualVo.setClinic(clinic);
+    public  void test2(){
 
-            BusDeviceManualEntity manual = new BusDeviceManualEntity();
-            manual.setType(DeviceManualEnum.machine);
-            manual.setTotalDose(RandomUtil.randomInt(100));
-            manual.setContinueDose(RandomUtil.randomBigDecimal(BigDecimal.valueOf(10)));
-            manual.setSelfControlDose(RandomUtil.randomBigDecimal(BigDecimal.valueOf(10)));
-            manual.setSelfControlLockTime(RandomUtil.randomInt(100));
-            deviceManualVo.setManual(manual);
-            manualController.save(deviceManualVo);
+        QueryWrapper<BusDeviceAlarmEntity> busDeviceAlarmEntityQueryWrapper = new QueryWrapper<>();
+        BusDeviceAlarmEntity busDeviceAlarmEntity = new BusDeviceAlarmEntity();
 
-//        patientService.save(patient);
-//        clinicService.save(clinic);
-        }
-    }
+        //busDeviceAlarmEntity.setTenantId("1");
+        busDeviceAlarmEntityQueryWrapper.setEntity(busDeviceAlarmEntity);
+        busDeviceAlarmEntity.setAlarm(DeviceAlarmEnum.LowBattery);
 
-    public static void main(String[] args) {
-        System.out.println(getName());
+        System.out.println(busDeviceAlarmEntityQueryWrapper.getEntity().getAlarm());
+        //System.out.println("----------------------------------------"+busDeviceAlarmEntityQueryWrapper.getEntity().getTenantId());
+        System.out.println("=================================="+deviceAlarmMapper.selectCount(busDeviceAlarmEntityQueryWrapper));
     }
 
-    public static String getName(){
-        Random random=new Random(System.currentTimeMillis());
-        /* 598 百家姓 */
-        String[] Surname= {"赵","钱","孙","李","周","吴","郑","王","冯","陈","褚","卫","蒋","沈","韩","杨","朱","秦","尤","许",
-                "何","吕","施","张","孔","曹","严","华","金","魏","陶","姜","戚","谢","邹","喻","柏","水","窦","章","云","苏","潘","葛","奚","范","彭","郎",
-                "鲁","韦","昌","马","苗","凤","花","方","俞","任","袁","柳","酆","鲍","史","唐","费","廉","岑","薛","雷","贺","倪","汤","滕","殷",
-                "罗","毕","郝","邬","安","常","乐","于","时","傅","皮","卞","齐","康","伍","余","元","卜","顾","孟","平","黄","和",
-                "穆","萧","尹","姚","邵","湛","汪","祁","毛","禹","狄","米","贝","明","臧","计","伏","成","戴","谈","宋","茅","庞","熊","纪","舒",
-                "屈","项","祝","董","梁","杜","阮","蓝","闵","席","季","麻","强","贾","路","娄","危","江","童","颜","郭","梅","盛","林","刁","钟",
-                "徐","邱","骆","高","夏","蔡","田","樊","胡","凌","霍","虞","万","支","柯","昝","管","卢","莫","经","房","裘","缪","干","解","应",
-                "宗","丁","宣","贲","邓","郁","单","杭","洪","包","诸","左","石","崔","吉","钮","龚","程","嵇","邢","滑","裴","陆","荣","翁","荀",
-                "羊","于","惠","甄","曲","家","封","芮","羿","储","靳","汲","邴","糜","松","井","段","富","巫","乌","焦","巴","弓","牧","隗","山",
-                "谷","车","侯","宓","蓬","全","郗","班","仰","秋","仲","伊","宫","宁","仇","栾","暴","甘","钭","厉","戎","祖","武","符","刘","景",
-                "詹","束","龙","叶","幸","司","韶","郜","黎","蓟","溥","印","宿","白","怀","蒲","邰","从","鄂","索","咸","籍","赖","卓","蔺","屠",
-                "蒙","池","乔","阴","郁","胥","能","苍","双","闻","莘","党","翟","谭","贡","劳","逄","姬","申","扶","堵","冉","宰","郦","雍","却",
-                "璩","桑","桂","濮","牛","寿","通","边","扈","燕","冀","浦","尚","农","温","别","庄","晏","柴","瞿","阎","充","慕","连","茹","习",
-                "宦","艾","鱼","容","向","古","易","慎","戈","廖","庾","终","暨","居","衡","步","都","耿","满","弘","匡","国","文","寇","广","禄",
-                "阙","东","欧","殳","沃","利","蔚","越","夔","隆","师","巩","厍","聂","晁","勾","敖","融","冷","訾","辛","阚","那","简","饶","空",
-                "曾","毋","沙","乜","养","鞠","须","丰","巢","关","蒯","相","查","后","荆","红","游","郏","竺","权","逯","盖","益","桓","公","仉",
-                "督","岳","帅","缑","亢","况","郈","有","琴","归","海","晋","楚","闫","法","汝","鄢","涂","钦","商","牟","佘","佴","伯","赏","墨",
-                "哈","谯","篁","年","爱","阳","佟","言","福","南","火","铁","迟","漆","官","冼","真","展","繁","檀","祭","密","敬","揭","舜","楼",
-                "疏","冒","浑","挚","胶","随","高","皋","原","种","练","弥","仓","眭","蹇","覃","阿","门","恽","来","綦","召","仪","风","介","巨",
-                "木","京","狐","郇","虎","枚","抗","达","杞","苌","折","麦","庆","过","竹","端","鲜","皇","亓","老","是","秘","畅","邝","还","宾",
-                "闾","辜","纵","侴","万俟","司马","上官","欧阳","夏侯","诸葛","闻人","东方","赫连","皇甫","羊舌","尉迟","公羊","澹台","公冶","宗正",
-                "濮阳","淳于","单于","太叔","申屠","公孙","仲孙","轩辕","令狐","钟离","宇文","长孙","慕容","鲜于","闾丘","司徒","司空","兀官","司寇",
-                "南门","呼延","子车","颛孙","端木","巫马","公西","漆雕","车正","壤驷","公良","拓跋","夹谷","宰父","谷梁","段干","百里","东郭","微生",
-                "梁丘","左丘","东门","西门","南宫","第五","公仪","公乘","太史","仲长","叔孙","屈突","尔朱","东乡","相里","胡母","司城","张廖","雍门",
-                "毋丘","贺兰","綦毋","屋庐","独孤","南郭","北宫","王孙"};
-
-        int index=random.nextInt(Surname.length-1);
-        String name = Surname[index]; //获得一个随机的姓氏
 
-        /* 从常用字中选取一个或两个字作为名 */
-        if(random.nextBoolean()){
-            name+=getChinese()+getChinese();
-        }else {
-            name+=getChinese();
-        }
-        return name;
-    }
-
-    public static String getChinese() {
-        String str = null;
-        int highPos, lowPos;
-        Random random = new Random();
-        highPos = (176 + Math.abs(random.nextInt(71)));//区码,0xA0打头,从第16区开始,即0xB0=11*16=176,16~55一级汉字,56~87二级汉字
-        random = new Random();
-        lowPos = 161 + Math.abs(random.nextInt(94));//位码,0xA0打头,范围第1~94列
-
-        byte[] bArr = new byte[2];
-        bArr[0] = (new Integer(highPos)).byteValue();
-        bArr[1] = (new Integer(lowPos)).byteValue();
-        try {
-            str = new String(bArr, "GB2312");    //区位码组合成汉字
-        } catch (UnsupportedEncodingException e) {
-            e.printStackTrace();
-        }
-        return str;
-    }
 }

+ 2 - 0
coffee-system/src/main/java/com/coffee/bus/controller/BusDeviceController.java

@@ -138,4 +138,6 @@ public class BusDeviceController extends BaseCrudController<BusDeviceEntity, Str
             return R.fail("同步失败");
         }
     }
+
+
 }

+ 1 - 6
coffee-system/src/main/java/com/coffee/bus/mapper/BusDeviceAlarmMapper.java

@@ -1,13 +1,8 @@
 package com.coffee.bus.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.coffee.bus.entity.BusClinicEntity;
 import com.coffee.bus.entity.BusDeviceAlarmEntity;
-import com.coffee.bus.service.dto.AlarmQuery;
 import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
 
 /**
  * @author lifang
@@ -19,5 +14,5 @@ import org.apache.ibatis.annotations.Param;
 @Mapper
 public interface BusDeviceAlarmMapper extends BaseMapper<BusDeviceAlarmEntity> {
 
-    IPage<BusDeviceAlarmEntity> pageQuery(Page<BusDeviceAlarmEntity> page, @Param("query") AlarmQuery query);
+    void selectCount(BusDeviceAlarmEntity busDeviceAlarmEntity);
 }

+ 7 - 14
coffee-system/src/main/java/com/coffee/bus/mapper/BusDeviceMapper.java

@@ -1,11 +1,8 @@
 package com.coffee.bus.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.coffee.bus.entity.BusClinicEntity;
 import com.coffee.bus.entity.BusDeviceEntity;
-import com.coffee.bus.service.dto.DeviceQuery;
-import com.coffee.bus.service.dto.DeviceResult;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -21,18 +18,14 @@ import org.apache.ibatis.annotations.Select;
 public interface BusDeviceMapper extends BaseMapper<BusDeviceEntity> {
 
     /**
-     * 获取设备,无视逻辑删除
-     * @param deviceId
+     * 获取病号最近一场手术信息
+     * @param hospitalId
+     * @param patientCode
      * @return
      */
-    BusDeviceEntity selectOneByDeviceId(String deviceId);
+    @Select("select * from bus_clinic where tenant_id=#{hospitalId} and patient_code=#{patientCode} order by start_time DESC limit 0,1")
+    BusClinicEntity recentClinic(@Param("hospitalId") String hospitalId, @Param("patientCode") String patientCode);
+
 
-    /**
-     * 去掉逻辑删除标志
-     * @param deviceId
-     * @return
-     */
-    Integer notDelete(String deviceId);
 
-    IPage<DeviceResult> pageQuery(Page<DeviceResult> page,@Param("query") DeviceQuery query);
 }

+ 48 - 6
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceAlarmService.java

@@ -1,17 +1,24 @@
 package com.coffee.bus.service;
 
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.coffee.bus.entity.BusClinicEntity;
+import com.coffee.bus.controller.vo.DeviceUse;
 import com.coffee.bus.entity.BusDeviceAlarmEntity;
+import com.coffee.bus.entity.BusHospitalEntity;
+import com.coffee.bus.enums.DeviceAlarmEnum;
 import com.coffee.bus.mapper.BusDeviceAlarmMapper;
-import com.coffee.bus.service.dto.AlarmQuery;
+import com.coffee.bus.mapper.BusHospitalMapper;
 import com.coffee.common.crud.BaseService;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author lifang
  * @version 1.0.0
@@ -22,6 +29,9 @@ import org.springframework.transaction.annotation.Transactional;
 @Service
 @AllArgsConstructor
 public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper, BusDeviceAlarmEntity,String> {
+    private final BusDeviceAlarmMapper deviceAlarmMapper;
+    private final BusHospitalMapper hospitalMapper;
+
     @Override
     public void validateBeforeSave(BusDeviceAlarmEntity entity) {
 
@@ -37,9 +47,7 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
 
     }
 
-    public IPage<BusDeviceAlarmEntity> pageQuery(AlarmQuery query){
-        return this.baseMapper.pageQuery(query.getPage(),query);
-    }
+
     /**
      * 添加报警原因
      * @param id
@@ -56,4 +64,38 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
         }
         this.update(new UpdateWrapper<BusDeviceAlarmEntity>().lambda().eq(BusDeviceAlarmEntity::getId,id).set(BusDeviceAlarmEntity::getCause,cause));
     }
+
+    /**
+     * 查看报警数量
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public List<DeviceUse> countAlarm(){
+        List<BusHospitalEntity> hospitalList = hospitalMapper.selectList(new QueryWrapper<>());
+        List<DeviceUse> deviceUseList = new ArrayList<>();
+
+        for (BusHospitalEntity hospital:
+             hospitalList) {
+            DeviceUse deviceUse = new DeviceUse();
+            deviceUse.setName(hospital.getName());
+            deviceUse.setAddress(hospital.getAddress());
+            Map<DeviceAlarmEnum, Long> deviceAlarms = new HashMap<>();
+            deviceUse.setDeviceAlarms(deviceAlarms);
+
+            QueryWrapper<BusDeviceAlarmEntity> busDeviceAlarmEntityQueryWrapper = new QueryWrapper<>();
+            BusDeviceAlarmEntity busDeviceAlarmEntity = new BusDeviceAlarmEntity();
+            busDeviceAlarmEntityQueryWrapper.setEntity(busDeviceAlarmEntity);
+            busDeviceAlarmEntity.setTenantId(hospital.getId());
+            for (DeviceAlarmEnum alarmEnum:
+                    DeviceAlarmEnum.values()) {
+                busDeviceAlarmEntity.setAlarm(alarmEnum);
+                deviceAlarms.put(alarmEnum,deviceAlarmMapper.selectCount(busDeviceAlarmEntityQueryWrapper));
+            }
+
+
+            deviceUseList.add(deviceUse);
+
+        }
+        return deviceUseList;
+
+    }
 }

+ 2 - 205
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceService.java

@@ -1,33 +1,15 @@
 package com.coffee.bus.service;
 
 import cn.hutool.core.util.StrUtil;
-import com.aliyuncs.iot.model.v20180120.QueryDeviceDetailResponse;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.coffee.aliyun.sdk.AliyunIotSdk;
-import com.coffee.bus.bean.AliIotConfig;
-import com.coffee.bus.entity.BusHospitalEntity;
 import com.coffee.bus.registry.device.DeviceRegistry;
 import com.coffee.bus.entity.BusDeviceEntity;
 import com.coffee.bus.mapper.BusDeviceMapper;
 import com.coffee.bus.registry.device.DeviceOperator;
-import com.coffee.bus.service.dto.DeviceQuery;
-import com.coffee.bus.service.dto.DeviceResult;
 import com.coffee.common.crud.BaseService;
-import com.coffee.common.exception.CustomException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * @author lifang
@@ -43,19 +25,9 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
     @Autowired
     @Lazy
     private DeviceRegistry deviceRegistry;
-
-    @Autowired
-    private BusDeviceMapper deviceMapper;
-
-    @Autowired
-    private AliyunIotSdk aliyunIotSdk;
-
-
     @Override
     public void validateBeforeSave(BusDeviceEntity entity) {
-       if(entity.getTenantId()==null){
-           entity.setTenantId("1");
-       }
+
     }
 
     @Override
@@ -65,8 +37,7 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
 
     @Override
     public void validateBeforeDelete(String id) {
-
-    }
+     }
 
     @Override
     public void postSave(BusDeviceEntity entity) {
@@ -86,9 +57,6 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
         if(entity.getEnable()!=null){
             deviceOperator.setEnable(entity.getEnable());
         }
-        if(StrUtil.isNotEmpty(entity.getTenantId())){
-            deviceOperator.setTenantId(entity.getTenantId());
-        }
     }
 
     @Override
@@ -97,176 +65,5 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
         deviceRegistry.remove(registeredEntity.getDeviceId());
     }
 
-    /**
-     * @author 龙三郎
-     * 根据deviceId删除设备
-     * @param deviceId
-     */
-    public void removeByDeviceId(String deviceId){
-        this.remove(new QueryWrapper<BusDeviceEntity>().lambda()
-                .eq(BusDeviceEntity::getDeviceId,deviceId));
-    }
-
-    /**
-     * @author 龙三郎
-     * 根据deviceId更新设备在线状态
-     * @param device
-     */
-    public boolean updateDevice(BusDeviceEntity device){
-        return this.update(device,new QueryWrapper<BusDeviceEntity>().lambda()
-                .eq(BusDeviceEntity::getDeviceId,device.getDeviceId()));
-    }
-
-    /**
-     * @author 龙三郎
-     * 保存一个设备,系统中存在时就更新,不存在时则插入。
-     * @param entity
-     */
-    public boolean saveDevice(BusDeviceEntity entity) {
-        // 查询设备是否存在,无视逻辑删除
-        BusDeviceEntity device = deviceMapper.selectOneByDeviceId(entity.getDeviceId());
-        // 判断设备是否存在
-        boolean isExists = Objects.nonNull(device);
-        // 设备存在,且处于删除状态,首先去掉逻辑删除标志 ?? 逻辑删除后设备数据是否不再接收
-        if (isExists && device.getIsDelete() == 1){
-            deviceMapper.notDelete(entity.getDeviceId());
-        }
-        // 设备存在
-        if (isExists){
-            // 更新设备
-            return this.updateDevice(entity);
-        }else {
-            // 添加设备
-            return this.save(entity);
-        }
-    }
-
-    /**
-     * @author 龙三郎
-     * 更新一个系统中现有的设备
-     * @param deviceId
-     */
-    public boolean updateDeviceByDeviceId(String deviceId) {
-        // 查询设备是否存在
-        BusDeviceEntity device = getByDeviceId(deviceId);
-        // 设备不存在直接退出
-        if (Objects.isNull(device)){
-            return false;
-        }
-        // 从阿里云物联网查询设备
-        QueryDeviceDetailResponse response = aliyunIotSdk.queryDeviceDetail(deviceId);
-        // 设备存在
-        if (response.getSuccess()){
-            // 更新设备参数
-            device.updateFields(response.getData());
-            // 更新设备
-            return this.updateDevice(device);
-        }else {
-            return false;
-        }
-    }
-
-    /**
-     * @author 龙三郎
-     * 根据deviceId获取设备
-     * @param deviceId
-     * @return
-     */
-    public BusDeviceEntity getByDeviceId(String deviceId) {
-        BusDeviceEntity device = getOne(new QueryWrapper<BusDeviceEntity>().lambda()
-                .eq(BusDeviceEntity::getDeviceId,deviceId));
-        return device;
-    }
-
-    /**
-     * @author 龙三郎
-     * 该方法用于从阿里云同步设备,系统暂时不允许创建非阿里云物联网平台设备。意思是系统中的设备必须存在于阿里云物联网平台。
-     * 通过deviceId从阿里云查询设备,如果设备在阿里云平台不存在,则创建失败,如果存在,则获取设备数据,插入或更新设备数据,表示创建成功。
-     * @param deviceId
-     * @return
-     */
-    public BusDeviceEntity addDevice(String deviceId) {
-        BusDeviceEntity device = new BusDeviceEntity();
-        device.setConfig(new AliIotConfig());
-        // 从阿里云物联网查询设备
-        QueryDeviceDetailResponse response = aliyunIotSdk.queryDeviceDetail(deviceId);
-        // 设备存在
-        if (response.getSuccess()){
-            device.updateFields(response.getData());
-            // 存储设备
-            this.saveDevice(device);
-            return device;
-        }
-        // 不存在返回null
-        return null;
-    }
-
-
-    public IPage<DeviceResult> pageQuery(Page<DeviceResult> page, DeviceQuery query){
-        return this.baseMapper.pageQuery(page,query);
-    }
-    /**
-     * @author 龙三郎
-     * 从阿里云平台获取全部的设备,同步到系统数据库
-     * @return
-     */
-    public int syncAllDevice(){
-        Integer m = 0;
-        // 创建异步执行任务,有返回值
-        CompletableFuture<Integer> cf = CompletableFuture.supplyAsync(()->{
-            AtomicReference<Integer> n = new AtomicReference<>(0);
-            // 同步所有的设备
-            aliyunIotSdk.queryDevice().forEach(item ->{
-                BusDeviceEntity device = new BusDeviceEntity();
-                device.setConfig(new AliIotConfig());
-                // 更新设备属性
-                device.updateFields(item);
-                n.updateAndGet(v -> v + (this.saveDevice(device)?1:0));
-            });
-            return n.get();
-        });
-        //等待子任务执行完成
-        try {
-            m = cf.get();
-        }catch (Exception e){
-            throw new CustomException(e.getMessage());
-        }
-        return m;
-    }
 
-    /**
-     * @author 龙三郎
-     * 根据ids获取指定的设备,更新本地设备
-     * @return
-     */
-    public int syncDevice(List<String> ids) {
-        AtomicReference<Integer> n = new AtomicReference<>(0);
-        // ids不能为空
-        if (Objects.isNull(ids) || ids.size() <= 0){
-            throw new CustomException("设备id不能为空");
-        }
-        // 同步指定的设备
-        ids.forEach(id->{
-            n.updateAndGet(v -> v + (this.updateDeviceByDeviceId(id)?1:0));
-        });
-        return n.get();
-    }
-
-    /**
-     * 描述: 设备医院换绑操作
-     * @author lifang
-     * @date 2022/5/8 21:34
-     * @param deviceIds 换绑的设备id
-     * @param afterTenantId 换绑之后的医院id
-     * @return void
-     */
-    @Transactional(rollbackFor = Exception.class)
-    public void shift(List<String> deviceIds, String afterTenantId) {
-        this.update(new UpdateWrapper<BusDeviceEntity>().lambda()
-                .in(BusDeviceEntity::getDeviceId,deviceIds)
-                .set(BusDeviceEntity::getTenantId,afterTenantId));
-        deviceIds.stream()
-                .map(deviceRegistry::getOperator)
-                .forEach(deviceOperator -> deviceOperator.setTenantId(afterTenantId));
-    }
 }