|
@@ -2,29 +2,35 @@ package com.huimv.env.admin.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONException;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.huimv.env.admin.common.utils.Result;
|
|
|
import com.huimv.env.admin.common.utils.ResultCode;
|
|
|
import com.huimv.env.admin.common.utils.ResultUtil;
|
|
|
import com.huimv.env.admin.entity.BasePigpen;
|
|
|
+import com.huimv.env.admin.entity.Gateway;
|
|
|
+import com.huimv.env.admin.entity.Terminal;
|
|
|
import com.huimv.env.admin.entity.dto.BasePigpenDto;
|
|
|
+import com.huimv.env.admin.entity.dto.ListPigpenDto;
|
|
|
import com.huimv.env.admin.entity.vo.TreeBasePigpen;
|
|
|
import com.huimv.env.admin.mapper.BasePigpenMapper;
|
|
|
+import com.huimv.env.admin.mapper.GatewayMapper;
|
|
|
+import com.huimv.env.admin.mapper.TerminalMapper;
|
|
|
import com.huimv.env.admin.service.IBasePigpenService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author author
|
|
@@ -34,7 +40,12 @@ import java.util.stream.Collectors;
|
|
|
public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePigpen> implements IBasePigpenService {
|
|
|
@Autowired
|
|
|
private BasePigpenMapper basePigpenMapper;
|
|
|
-// @Autowired
|
|
|
+ @Autowired
|
|
|
+ private GatewayMapper gatewayMapper;
|
|
|
+ @Autowired
|
|
|
+ private TerminalMapper terminalMapper;
|
|
|
+
|
|
|
+ // @Autowired
|
|
|
// private EnvDeviceMapper envDeviceMapper;
|
|
|
// @Autowired
|
|
|
// private EnergyEnvDeviceMapper energyEnvDeviceMapper;
|
|
@@ -42,7 +53,7 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
|
|
|
@Transactional
|
|
|
public Result addPigpen(BasePigpenDto basePigpenDto) {
|
|
|
Integer num = basePigpenMapper.selectCount(new QueryWrapper<BasePigpen>().eq("build_name", basePigpenDto.getBuildName())
|
|
|
- .eq("farm_id", basePigpenDto.getFarmId()).ne("other3",1));
|
|
|
+ .eq("farm_id", basePigpenDto.getFarmId()).ne("other3", 1));
|
|
|
if (num > 0) {
|
|
|
return new Result(10001, "栋舍名称已存在!", false);
|
|
|
}
|
|
@@ -73,7 +84,7 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
|
|
|
@Transactional
|
|
|
public Result updatePigpen(BasePigpen basePigpen) {
|
|
|
Integer num = basePigpenMapper.selectCount(new QueryWrapper<BasePigpen>().eq("build_name", basePigpen.getBuildName())
|
|
|
- .eq("farm_id", basePigpen.getFarmId()).ne("id", basePigpen.getId()).ne("ohter3",1));
|
|
|
+ .eq("farm_id", basePigpen.getFarmId()).ne("id", basePigpen.getId()).ne("other3", 1));
|
|
|
if (num > 0) {
|
|
|
return new Result(10001, "栋舍名称已存在!", false);
|
|
|
}
|
|
@@ -95,24 +106,12 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
|
|
|
@Transactional
|
|
|
public Result deletePigpen(Map<String, Integer> map) {
|
|
|
Integer integer = map.get("id");
|
|
|
-// Integer count1 = energyEnvDeviceMapper.selectCount(new QueryWrapper<EnergyEnvDevice>().eq("unit_id", integer));
|
|
|
-// Integer integer1 = envDeviceMapper.selectCount(new QueryWrapper<EnvDevice>().eq("unit_id", integer));
|
|
|
-// if (integer1 > 0) {
|
|
|
-// return new Result(10001, "删除失败,该栋舍下有温湿度采集器", false);
|
|
|
-// }
|
|
|
-// if (count1 > 0) {
|
|
|
-// return new Result(10001, "删除失败,该栋舍下有水电表", false);
|
|
|
-// }
|
|
|
+ Integer count = gatewayMapper.selectCount(new QueryWrapper<Gateway>().eq("location_id", integer));
|
|
|
+ if (count > 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()));
|
|
|
-// Integer integer2 = envDeviceMapper.selectCount(new QueryWrapper<EnvDevice>().eq("unit_id", integer));
|
|
|
-// if (count > 0) {
|
|
|
-// return new Result(10001, "删除失败,该栋舍下有温湿度采集器", false);
|
|
|
-// }
|
|
|
-// if (integer2 > 0) {
|
|
|
-// return new Result(10001, "删除失败,该栋舍下有水电表", false);
|
|
|
-// }
|
|
|
basePigpenMapper.deleteById(basePigpen.getId());
|
|
|
}
|
|
|
basePigpenMapper.deleteById(integer);
|
|
@@ -120,6 +119,55 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Result listPigpen(Map<String, Integer> map) {
|
|
|
+ Integer farmId = map.get("farmId");
|
|
|
+ return new Result(ResultCode.SUCCESS, basePigpenMapper.listPigpen(farmId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result deviceCount(Map<String, Integer> map) {
|
|
|
+ Integer id = map.get("id");
|
|
|
+ Integer onGateway = 0;
|
|
|
+ Integer offGateway = 0;
|
|
|
+ Integer onTerminal = 0;
|
|
|
+ Integer offTerminal = 0;
|
|
|
+ Integer infoGateway = 0;
|
|
|
+ Integer infoTerminal = 0;
|
|
|
+ QueryWrapper<Gateway> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("location_id", id);
|
|
|
+ List<Gateway> gateways = gatewayMapper.selectList(queryWrapper);
|
|
|
+ for (Gateway gateway : gateways) {
|
|
|
+ if (gateway.getStatus() == 0) {
|
|
|
+ offGateway++;
|
|
|
+ } else {
|
|
|
+ onGateway++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Integer> idList = new ArrayList<>();
|
|
|
+ gateways.forEach(item->{
|
|
|
+ idList.add(item.getId());
|
|
|
+ });
|
|
|
+ QueryWrapper<Terminal> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.in("gateway_id", idList);
|
|
|
+ List<Terminal> terminals = terminalMapper.selectList(queryWrapper1);
|
|
|
+ for (Terminal terminal : terminals) {
|
|
|
+ if (terminal.getStatus() == 0) {
|
|
|
+ offTerminal++;
|
|
|
+ } else {
|
|
|
+ onTerminal++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("onGateway", onGateway);
|
|
|
+ jsonObject.put("offGateway", offGateway);
|
|
|
+ jsonObject.put("onTerminal", onTerminal);
|
|
|
+ jsonObject.put("offTerminal", offTerminal);
|
|
|
+ jsonObject.put("infoGateway", infoGateway);
|
|
|
+ jsonObject.put("infoTerminal", infoTerminal);
|
|
|
+ return new Result(ResultCode.SUCCESS,jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Result list(String farmCode, String buildName, String stageCode, String type) {
|
|
|
QueryWrapper<BasePigpen> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.like(StringUtils.isNotBlank(buildName), "build_name", buildName);
|
|
@@ -148,6 +196,8 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
|
|
|
baseVo.setFarmCode(basePigpen.getFarmId());
|
|
|
baseVo.setParentId(basePigpen.getParentId());
|
|
|
baseVo.setSort(basePigpen.getSort());
|
|
|
+ baseVo.setLat(basePigpen.getLat());
|
|
|
+ baseVo.setLng(basePigpen.getLng());
|
|
|
baseVo.setStageCode(basePigpen.getStageCode());
|
|
|
baseVo.setPigpenName(basePigpen.getBuildName());
|
|
|
baseVo.setType(basePigpen.getFType());
|
|
@@ -169,4 +219,51 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
|
|
|
});
|
|
|
return roots;
|
|
|
}
|
|
|
+
|
|
|
+ /*数组排序*/
|
|
|
+// public static List<TreeBasePigpen> jsonArraySort(List<BasePigpen> bizBaseAreas, String sortKey, boolean is_desc) {
|
|
|
+// //存放排序结果json数组
|
|
|
+// JSONArray sortedJsonArray = new JSONArray();
|
|
|
+// //用于排序的list
|
|
|
+//
|
|
|
+// List<JSONObject> jsonValues = new ArrayList<JSONObject>();
|
|
|
+// //将参数json数组每一项取出,放入list
|
|
|
+// for (int i = 0; i < bizBaseAreas.size(); i++) {
|
|
|
+// jsonValues.add(jsonArr.getJSONObject(i));
|
|
|
+// }
|
|
|
+// //快速排序,重写compare方法,完成按指定字段比较,完成排序
|
|
|
+// Collections.sort(jsonValues, new Comparator<JSONObject>() {
|
|
|
+// //排序字段
|
|
|
+// private final String KEY_NAME = sortKey;
|
|
|
+//
|
|
|
+// //重写compare方法
|
|
|
+// @Override
|
|
|
+// public int compare(JSONObject a, JSONObject b) {
|
|
|
+// //如果用String接会导致一位数和两位数混合比对的时候不能准确比出来,要用int类型接
|
|
|
+// //String valA = new String();
|
|
|
+// //String valB = new String();
|
|
|
+// Float valA = 0.00f;
|
|
|
+// Float valB = 0.00f;
|
|
|
+// try {
|
|
|
+// valA = Float.parseFloat(a.getString(KEY_NAME));
|
|
|
+// valB = Float.parseFloat(b.getString(KEY_NAME));
|
|
|
+// } catch (JSONException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// //是升序还是降序
|
|
|
+// if (is_desc) {
|
|
|
+// return -valA.compareTo(valB);
|
|
|
+// } else {
|
|
|
+// return -valB.compareTo(valA);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// });
|
|
|
+// //将排序后结果放入结果jsonArray
|
|
|
+// for (int i = 0; i < jsonArr.size(); i++) {
|
|
|
+// sortedJsonArray.add(jsonValues.get(i));
|
|
|
+// }
|
|
|
+//
|
|
|
+// return sortedJsonArray;
|
|
|
+// }
|
|
|
}
|