Преглед на файлове

修改环控同步设备

523096025 преди 2 години
родител
ревизия
14a3ed6db5

+ 0 - 1
huimv-admin/src/main/java/com/huimv/admin/controller/BasePigpenController.java

@@ -26,7 +26,6 @@ public class BasePigpenController {
     @Autowired
     private IBasePigpenService basePigpenService;
 
-
     @PostMapping( "/addPigpen")
     public Result addPigpen(@RequestBody BasePigpenDto basePigpenDto) {
         return basePigpenService.addPigpen(basePigpenDto);

+ 13 - 0
huimv-admin/src/main/java/com/huimv/admin/controller/EnvDeviceController.java

@@ -2,6 +2,7 @@ package com.huimv.admin.controller;
 
 
 import com.huimv.admin.common.utils.Result;
+import com.huimv.admin.entity.EnvDevice;
 import com.huimv.admin.service.IEnvDeviceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.CrossOrigin;
@@ -67,4 +68,16 @@ public class EnvDeviceController {
     public Result listDeviceCount(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
         return envDeviceService.listDeviceCount(httpServletRequest,paramsMap);
     }
+
+    @RequestMapping("/bandingUnitId")
+    public Result bandingUnitId(HttpServletRequest httpServletRequest, @RequestBody EnvDevice envDevice) {
+        return envDeviceService.bandingUnitId(httpServletRequest,envDevice);
+    }
+    @RequestMapping("/unBandingUnitId")
+    public Result unBandingUnitId(HttpServletRequest httpServletRequest, @RequestBody EnvDevice envDevice) {
+        envDevice.setUnitId(0);
+        envDevice.setUnitName("");
+        envDeviceService.updateById(envDevice);
+        return new Result(10000,"解绑成功",true);
+    }
 }

+ 1 - 1
huimv-admin/src/main/java/com/huimv/admin/controller/EnvDeviceSync.java

@@ -19,7 +19,7 @@ public class EnvDeviceSync {
 
     @PostMapping("/sync")
     @Transactional
-    public Result sync(@RequestBody Map<String, Integer> params) throws Exception {
+    public Result sync(@RequestBody Map<String, String> params) throws Exception {
         return  envDeviceService.sync(params);
 
     }

+ 3 - 1
huimv-admin/src/main/java/com/huimv/admin/service/IEnvDeviceService.java

@@ -32,5 +32,7 @@ public interface IEnvDeviceService extends IService<EnvDevice> {
 
     Result listDeviceCount(HttpServletRequest httpServletRequest, Map<String, String> paramsMap);
 
-    Result sync(Map<String, Integer> params) throws Exception;
+    Result sync(Map<String, String> params) throws Exception;
+
+    Result bandingUnitId(HttpServletRequest httpServletRequest, EnvDevice envDevice);
 }

+ 13 - 2
huimv-admin/src/main/java/com/huimv/admin/service/impl/BasePigpenServiceImpl.java

@@ -5,13 +5,16 @@ import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.NumberUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.extension.api.R;
 import com.huimv.admin.common.utils.Result;
 import com.huimv.admin.common.utils.ResultCode;
 import com.huimv.admin.common.utils.ResultUtil;
 import com.huimv.admin.entity.BasePigpen;
+import com.huimv.admin.entity.EnvDevice;
 import com.huimv.admin.entity.dto.BasePigpenDto;
 import com.huimv.admin.entity.vo.TreeBasePigpen;
 import com.huimv.admin.mapper.BasePigpenMapper;
+import com.huimv.admin.mapper.EnvDeviceMapper;
 import com.huimv.admin.service.IBasePigpenService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +38,8 @@ import java.util.stream.Collectors;
 public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePigpen> implements IBasePigpenService {
     @Autowired
     private BasePigpenMapper basePigpenMapper;
+    @Autowired
+    private EnvDeviceMapper envDeviceMapper;
 
     @Override
     @Transactional
@@ -87,8 +92,16 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
     @Transactional
     public Result deletePigpen(Map<String, Integer> map) {
         Integer integer = map.get("id");
+        Integer integer1 = envDeviceMapper.selectCount(new QueryWrapper<EnvDevice>().eq("unit_id", integer));
+        if (integer1 > 0){
+            return new Result(10001,"删除失败,该栋舍下有采集器",false);
+        }
         List<BasePigpen> other2 = basePigpenMapper.selectList(new QueryWrapper<BasePigpen>().like("other2", integer));
         for (BasePigpen basePigpen : other2) {
+            Integer count = envDeviceMapper.selectCount(new QueryWrapper<EnvDevice>().eq("unit_id", basePigpen.getId()));
+            if (count > 0){
+                return new Result(10001,"删除失败,该栋舍下有采集器",false);
+            }
             basePigpenMapper.deleteById(basePigpen);
         }
         basePigpenMapper.deleteById(integer);
@@ -103,13 +116,11 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
         queryWrapper.eq(StringUtils.isNotBlank(farmCode),"farm_id", farmCode);
         //创建排序
         List<BasePigpen> basePigpens = basePigpenMapper.selectList(queryWrapper);
-
         //将结果List改为树
         List<TreeBasePigpen> treeBasePigpens = parseBizBaseArea(basePigpens);
         return new Result(ResultCode.SUCCESS,treeBasePigpens);
     }
 
-
     /**
      * 查询结果 转换成树形结构
      * @param bizBaseAreas 原始数据

+ 15 - 5
huimv-admin/src/main/java/com/huimv/admin/service/impl/EnvDeviceServiceImpl.java

@@ -306,8 +306,8 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
 
     @Override
     @Transactional
-    public Result sync(Map<String, Integer> params) throws Exception {
-        Integer farmId = params.get("farmId");
+    public Result sync(Map<String, String> params) throws Exception {
+        String farmId = params.get("farmId");
         //获取所有栏舍
         Map<String, Object> map = new HashMap<String, Object>();
         String s = HttpClientSSLUtils.doPost("https://yzwlw.loongk.com/mobile/login?username=江西增鑫&password=21218cca77804d2ba1922c33e0151105", JSON.toJSONString(map));
@@ -321,7 +321,7 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
         List<DataShacks> shacks = loginDto.getData().getShacks();
         // 不能删除,需做比较
         List<String> zengXinDeviceId = shacks.stream().map(DataShacks::getId).collect(Collectors.toList());
-        List<String> huatongDeviceId = envDeviceMapper.selectDeviceCodeByfarmId(farmId);
+        List<String> huatongDeviceId = envDeviceMapper.selectDeviceCodeByfarmId(Integer.parseInt(farmId));
 
         CopyOnWriteArrayList<String> zengXinDeviceIdCopy = ListUtil.toCopyOnWriteArrayList(zengXinDeviceId);
         CopyOnWriteArrayList<String> huatongDeviceIdCopy = ListUtil.toCopyOnWriteArrayList(huatongDeviceId);
@@ -343,7 +343,17 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
         return new Result(10000,"同步成功",false);
     }
 
-    private void syncConfig(String shackId,HttpEntity httpEntity,Integer farmId) {
+    @Override
+    public Result bandingUnitId(HttpServletRequest httpServletRequest, EnvDevice envDevice) {
+        Integer unitId = envDevice.getUnitId();
+        int count = this.count(new QueryWrapper<EnvDevice>().eq("unit_id", unitId));
+        if (count>0){
+            return new Result(10001,"绑定失败,该栋舍已有设备",false);
+        }
+        return new Result(10000,"绑定成功",true);
+    }
+    //添加新的设备
+    private void syncConfig(String shackId,HttpEntity httpEntity,String farmId) {
         ResponseEntity<String> exchangePeizhi = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackConfig/"+shackId, HttpMethod.GET, httpEntity, String.class);
         String peizhibody = exchangePeizhi.getBody();
         ShackConfigDto shackConfigDto = JSONUtil.toBean(peizhibody, ShackConfigDto.class);
@@ -351,7 +361,7 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
         List<ShackConfigDataSensors> sensors = data.getSensors();
         if (ObjectUtil.isNotEmpty(sensors)){
             EnvDevice envDevice =new EnvDevice();
-            envDevice.setFarmId(farmId);
+            envDevice.setFarmId(Integer.parseInt(farmId));
             envDevice.setDeviceBrand("增鑫");
             envDevice.setDeviceCode(data.getId());
             envDevice.setDeviceName(data.getName());