|
@@ -0,0 +1,328 @@
|
|
|
+package com.huimv.env.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.huimv.common.utils.DateUtil;
|
|
|
+import com.huimv.common.utils.Result;
|
|
|
+import com.huimv.common.utils.ResultCode;
|
|
|
+import com.huimv.env.dao.entity.*;
|
|
|
+import com.huimv.env.dao.repo.*;
|
|
|
+import com.huimv.env.service.IEnvironmentService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Project : huimv.shiwan
|
|
|
+ * @Package : com.huimv.biosafety.uface.controller
|
|
|
+ * @Description : TODO
|
|
|
+ * @Version : 1.0
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Create : 2020-12-25
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class EnvironmentServiceImpl implements IEnvironmentService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DaZsdaEntityRepository zsdaEntityRepo;
|
|
|
+ @Autowired
|
|
|
+ private DaLqdaEntityRepository lqdaEntityRepo;
|
|
|
+ @Autowired
|
|
|
+ private SjHkAqEntityRepository aqEntityRepo;
|
|
|
+ @Autowired
|
|
|
+ private SjHkSdEntityRepository sdEntityRepo;
|
|
|
+ @Autowired
|
|
|
+ private SjHkWdEntityRepository wdEntityRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DS("slave")
|
|
|
+ public Result getLastEnvData(int mcid) {
|
|
|
+ //--读取所有猪舍
|
|
|
+ List<DaZsdaEntity> zsdsList = zsdaEntityRepo.getAllZs(mcid);
|
|
|
+// System.out.println("zsdsList.size>>"+zsdsList.size());
|
|
|
+ if (zsdsList.size() == 0) {
|
|
|
+ //返回出错
|
|
|
+ return new Result(10001, "牧场id(" + mcid + ")中的猪舍为0", false);
|
|
|
+ }
|
|
|
+ List zsidList = new ArrayList();
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+ zsidList.add(zsdaEntity.getID());
|
|
|
+ }
|
|
|
+// System.out.println("zsSb>>"+zsidList.toString());
|
|
|
+ //--读取所有栏期
|
|
|
+ List<DaLqdaEntity> lqdaEntityList = lqdaEntityRepo.getLqid(zsidList);
|
|
|
+// System.out.println("栏期length>>"+lqdaEntityList.size());
|
|
|
+ if (lqdaEntityList.size() == 0) {
|
|
|
+ //返回出错.
|
|
|
+ return new Result(10002, "这个牧场(" + mcid + ")中的猪舍暂无相关任何栏期", false);
|
|
|
+ }
|
|
|
+ List lqidList = new ArrayList();
|
|
|
+ for (DaLqdaEntity lqdaEntity : lqdaEntityList) {
|
|
|
+ lqidList.add(lqdaEntity.getID());
|
|
|
+ }
|
|
|
+// System.out.println("lqidList>>"+lqidList.toString());
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+ int zsid = zsdaEntity.getID();
|
|
|
+// String zsmc = zsdaEntity.getZSMC();
|
|
|
+ for (DaLqdaEntity lqdaEntity : lqdaEntityList) {
|
|
|
+ if (lqdaEntity.getZSID() == zsid) {
|
|
|
+ zsdaEntity.setLqid(lqdaEntity.getID());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String todayDate = new DateUtil().formatDate(new Date());
|
|
|
+ System.out.println("" + lqidList.toString());
|
|
|
+// //--读取最新氨气
|
|
|
+ List<SjHkAqEntity> aqList = aqEntityRepo.getLastAq(lqidList, todayDate);
|
|
|
+// System.out.println("aqList.size>>"+aqList.size());
|
|
|
+
|
|
|
+ //--读取最新湿度
|
|
|
+ List<SjHkSdEntity> sdList = sdEntityRepo.getLastSd(lqidList, todayDate);
|
|
|
+// System.out.println("sdList.size>>"+sdList.size());
|
|
|
+
|
|
|
+ //--读取最新温度
|
|
|
+ List<SjHkWdEntity> wdList = wdEntityRepo.getLastWd(lqidList, todayDate);
|
|
|
+// System.out.println("wdList.size>>"+wdList.size());
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+// System.out.println(zsdaEntity.getZSMC()+","+zsdaEntity.getLqid());
|
|
|
+ // 温度
|
|
|
+ for (SjHkWdEntity wdEntity : wdList) {
|
|
|
+ if (wdEntity.getLQID() == zsdaEntity.getLqid()) {
|
|
|
+ zsdaEntity.setDqwd(wdEntity.getDQWD());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 湿度
|
|
|
+ for (SjHkSdEntity sdEntity : sdList) {
|
|
|
+ if (sdEntity.getLQID() == zsdaEntity.getLqid()) {
|
|
|
+ zsdaEntity.setDqsd(sdEntity.getDQSD());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 氨气
|
|
|
+ for (SjHkAqEntity aqEntity : aqList) {
|
|
|
+ if (aqEntity.getLQID() == zsdaEntity.getLqid()) {
|
|
|
+ zsdaEntity.setDqaq(aqEntity.getDQAQ());
|
|
|
+// System.out.println("dqaq>>"+aqEntity.getDQAQ());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray envJa = new JSONArray();
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+ JSONObject envJo = new JSONObject();
|
|
|
+ envJa.add(envJo);
|
|
|
+// System.out.println(""+zsdaEntity.toString());
|
|
|
+ envJo.put("id", zsdaEntity.getID());
|
|
|
+ envJo.put("position", zsdaEntity.getZSMC());
|
|
|
+ // 温度
|
|
|
+ if (zsdaEntity.getDqwd() == null) {
|
|
|
+ envJo.put("temp", "");
|
|
|
+ } else {
|
|
|
+ envJo.put("temp", zsdaEntity.getDqwd());
|
|
|
+ }
|
|
|
+ // 湿度
|
|
|
+ if (zsdaEntity.getDqsd() == null) {
|
|
|
+ envJo.put("humidity", "");
|
|
|
+ } else {
|
|
|
+ envJo.put("humidity", zsdaEntity.getDqsd());
|
|
|
+ }
|
|
|
+ // 氨气
|
|
|
+ if (zsdaEntity.getDqaq() == null) {
|
|
|
+ envJo.put("ammonia", "");
|
|
|
+ } else {
|
|
|
+ envJo.put("ammonia", zsdaEntity.getDqaq());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS, envJa);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getLastEnvData2
|
|
|
+ * @Description :
|
|
|
+ * @Params : [mcid]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2020/12/28
|
|
|
+ * @Time : 21:01
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @DS("slave")
|
|
|
+ public Result getLastEnvData2(int mcid) {
|
|
|
+ //--读取所有猪舍
|
|
|
+ List<DaZsdaEntity> zsdsList = zsdaEntityRepo.getAllZs(mcid);
|
|
|
+// System.out.println("zsdsList.size>>"+zsdsList.size());
|
|
|
+ if (zsdsList.size() == 0) {
|
|
|
+ //返回出错
|
|
|
+ return new Result(10001, "牧场id(" + mcid + ")中的猪舍为0", false);
|
|
|
+ }
|
|
|
+ List zsidList = new ArrayList();
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+ zsidList.add(zsdaEntity.getID());
|
|
|
+ }
|
|
|
+// System.out.println("zsSb>>"+zsidList.toString());
|
|
|
+ //--读取所有栏期
|
|
|
+ List<DaLqdaEntity> lqdaEntityList = lqdaEntityRepo.getLqid(zsidList);
|
|
|
+// System.out.println("栏期length>>"+lqdaEntityList.size());
|
|
|
+ if (lqdaEntityList.size() == 0) {
|
|
|
+ //返回出错.
|
|
|
+ return new Result(10002, "这个牧场(" + mcid + ")中的猪舍暂无相关任何栏期", false);
|
|
|
+ }
|
|
|
+ List lqidList = new ArrayList();
|
|
|
+ for (DaLqdaEntity lqdaEntity : lqdaEntityList) {
|
|
|
+ lqidList.add(lqdaEntity.getID());
|
|
|
+ }
|
|
|
+// System.out.println("lqidList>>"+lqidList.toString());
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+ int zsid = zsdaEntity.getID();
|
|
|
+// String zsmc = zsdaEntity.getZSMC();
|
|
|
+ for (DaLqdaEntity lqdaEntity : lqdaEntityList) {
|
|
|
+ if (lqdaEntity.getZSID() == zsid) {
|
|
|
+ zsdaEntity.setLqid(lqdaEntity.getID());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String todayDate = new DateUtil().formatDate(new Date());
|
|
|
+ System.out.println("" + lqidList.toString());
|
|
|
+
|
|
|
+ JSONArray envJa = new JSONArray();
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+ int lqid = zsdaEntity.getLqid();
|
|
|
+ System.out.println("lqid>>" + lqid);
|
|
|
+ JSONObject envJo = new JSONObject();
|
|
|
+ envJa.add(envJo);
|
|
|
+ envJo.put("id",zsdaEntity.getID());
|
|
|
+ envJo.put("zsmc",zsdaEntity.getZSMC());
|
|
|
+ //--读取最新氨气
|
|
|
+ SjHkAqEntity aqEntity = aqEntityRepo.getLastAq(lqid, todayDate);
|
|
|
+ System.out.println("aqEntity>>" + aqEntity);
|
|
|
+ if (aqEntity != null) {
|
|
|
+ envJo.put("ammonia", aqEntity.getDQAQ());
|
|
|
+ } else {
|
|
|
+ envJo.put("ammonia", "");
|
|
|
+ }
|
|
|
+ //--读取最新湿度
|
|
|
+ SjHkSdEntity sdEntity = sdEntityRepo.getLastSd(lqid, todayDate);
|
|
|
+ if (sdEntity != null) {
|
|
|
+ envJo.put("humidity", sdEntity.getDQSD());
|
|
|
+ } else {
|
|
|
+ envJo.put("humidity", "");
|
|
|
+ }
|
|
|
+ //--读取最新温度
|
|
|
+ SjHkWdEntity wdEntity = wdEntityRepo.getLastWd(lqid, todayDate);
|
|
|
+ if (wdEntity != null) {
|
|
|
+ envJo.put("temp", wdEntity.getDQWD());
|
|
|
+ } else {
|
|
|
+ envJo.put("temp", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS, envJa);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getZsda
|
|
|
+ * @Description :
|
|
|
+ * @Params : [mcid]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2020/12/28
|
|
|
+ * @Time : 21:01
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @DS("slave")
|
|
|
+ public Result getZsda(int mcid) {
|
|
|
+ //--读取所有猪舍
|
|
|
+ List<DaZsdaEntity> zsdsList = zsdaEntityRepo.getAllZs(mcid);
|
|
|
+// System.out.println("zsdsList.size>>"+zsdsList.size());
|
|
|
+ if (zsdsList.size() == 0) {
|
|
|
+ //返回出错
|
|
|
+ return new Result(10001, "牧场id(" + mcid + ")中的猪舍为0", false);
|
|
|
+ }
|
|
|
+ List zsidList = new ArrayList();
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+ zsidList.add(zsdaEntity.getID());
|
|
|
+ }
|
|
|
+// System.out.println("zsSb>>"+zsidList.toString());
|
|
|
+ //--读取所有栏期
|
|
|
+ List<DaLqdaEntity> lqdaEntityList = lqdaEntityRepo.getLqid(zsidList);
|
|
|
+// System.out.println("栏期length>>"+lqdaEntityList.size());
|
|
|
+ if (lqdaEntityList.size() == 0) {
|
|
|
+ //返回出错.
|
|
|
+ return new Result(10002, "这个牧场(" + mcid + ")中的猪舍暂无相关任何栏期", false);
|
|
|
+ }
|
|
|
+ List lqidList = new ArrayList();
|
|
|
+// for (DaLqdaEntity lqdaEntity : lqdaEntityList) {
|
|
|
+// lqidList.add(lqdaEntity.getID());
|
|
|
+// }
|
|
|
+// System.out.println("lqidList>>"+lqidList.toString());
|
|
|
+ JSONArray zsJa = new JSONArray();
|
|
|
+ for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
+ int zsid = zsdaEntity.getID();
|
|
|
+ JSONObject zsJo = new JSONObject();
|
|
|
+ zsJa.add(zsJo);
|
|
|
+ zsJo.put("zsid", zsid);
|
|
|
+ zsJo.put("zsmc", zsdaEntity.getZSMC());
|
|
|
+ for (DaLqdaEntity lqdaEntity : lqdaEntityList) {
|
|
|
+ if (lqdaEntity.getZSID() == zsid) {
|
|
|
+ zsJo.put("lqid", zsdaEntity.getID());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS, zsJa);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getLastEnvByLq
|
|
|
+ * @Description :
|
|
|
+ * @Params : [lqid]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2020/12/28
|
|
|
+ * @Time : 21:01
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @DS("slave")
|
|
|
+ public Result getLastEnvByLq(Integer lqid) {
|
|
|
+ String todayDate = new DateUtil().formatDate(new Date());
|
|
|
+// JSONArray envJa = new JSONArray();
|
|
|
+ JSONObject envJo = new JSONObject();
|
|
|
+// envJa.add(envJo);
|
|
|
+ envJo.put("lqid",lqid);
|
|
|
+ //--读取最新氨气
|
|
|
+ SjHkAqEntity aqEntity = aqEntityRepo.getLastAq(lqid, todayDate);
|
|
|
+ System.out.println("aqEntity>>" + aqEntity);
|
|
|
+ if (aqEntity != null) {
|
|
|
+ envJo.put("ammonia", aqEntity.getDQAQ());
|
|
|
+ } else {
|
|
|
+ envJo.put("ammonia", "");
|
|
|
+ }
|
|
|
+ //--读取最新湿度
|
|
|
+ SjHkSdEntity sdEntity = sdEntityRepo.getLastSd(lqid, todayDate);
|
|
|
+ if (sdEntity != null) {
|
|
|
+ envJo.put("humidity", sdEntity.getDQSD());
|
|
|
+ } else {
|
|
|
+ envJo.put("humidity", "");
|
|
|
+ }
|
|
|
+ //--读取最新温度
|
|
|
+ SjHkWdEntity wdEntity = wdEntityRepo.getLastWd(lqid, todayDate);
|
|
|
+ if (wdEntity != null) {
|
|
|
+ envJo.put("temp", wdEntity.getDQWD());
|
|
|
+ } else {
|
|
|
+ envJo.put("temp", "");
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS, envJo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|