ソースを参照

华统小程序流程修改3

wwh 1 年間 前
コミット
da6001eaa8

+ 133 - 24
huimv-admin/src/main/java/com/huimv/admin/controller/LoginController.java

@@ -1,26 +1,29 @@
 package com.huimv.admin.controller;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.huimv.admin.common.utils.IpTools;
+import com.huimv.admin.common.utils.*;
 import com.huimv.admin.entity.SysAccountMultilevel;
+import com.huimv.admin.entity.dto.WeCahtVo;
 import com.huimv.admin.service.ILoginService;
 import com.huimv.admin.service.ISysAccountMultilevelService;
 import com.huimv.admin.session.AccessToken;
 import com.huimv.admin.common.exception.ExceptionEnum;
 import com.huimv.admin.common.exception.MiException;
 import com.huimv.admin.common.token.TokenSign;
-import com.huimv.admin.common.utils.Result;
-import com.huimv.admin.common.utils.ResultCode;
-import com.huimv.admin.common.utils.VerifyUtil;
-import net.sf.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -34,6 +37,8 @@ public class LoginController {
     ILoginService iLoginService;
     @Autowired
     private ISysAccountMultilevelService accountMultilevelService;
+    @Autowired
+    private UploadImage uploadImage;
 
     @RequestMapping("/test")
     public String logout() {
@@ -49,7 +54,7 @@ public class LoginController {
     private RedisTemplate<String, String> redisTemplate;
 
     @GetMapping("/send")
-    public void createImg(HttpServletRequest request, HttpServletResponse response)  {
+    public void createImg(HttpServletRequest request, HttpServletResponse response) {
         try {
             //设置响应类型,告诉浏览器输出的内容为图片
             response.setContentType("image/jpeg");
@@ -63,16 +68,16 @@ public class LoginController {
             System.out.println(code);
             //将生成的随机验证码存放到redis中
             String remoteHost = request.getRemoteHost();
-            redisTemplate.opsForValue().set(remoteHost,code,300, TimeUnit.SECONDS);
+            redisTemplate.opsForValue().set(remoteHost, code, 300, TimeUnit.SECONDS);
         } catch (Exception e) {
-            System.out.println("获取验证码异常:"+e);
+            System.out.println("获取验证码异常:" + e);
             throw new MiException(ExceptionEnum.VERIFCATION_FAID);
         }
     }
 
     //登录-多牧场
     @PostMapping(value = "/loginMultilevel")
-    public Result loginMultilevel(HttpServletRequest req, @RequestBody Map<String, String> map)  {
+    public Result loginMultilevel(HttpServletRequest req, @RequestBody Map<String, String> map) {
 
 
         String accountName = map.get("accountName");
@@ -90,7 +95,7 @@ public class LoginController {
 //        }
         // 未对密码加密
         Result result = iLoginService.loginMultilevel(accountName, password);
-        if(result.getCode() == 10000){
+        if (result.getCode() == 10000) {
 
             SysAccountMultilevel accountEntity = (SysAccountMultilevel) result.getData();
             Integer id = accountEntity.getId();
@@ -99,29 +104,29 @@ public class LoginController {
             accessToken.setCreated(new Date());
             accessToken.setAccountName(accountName);
             accessToken.setFarmId(accountEntity.getFarmIds());
-            String token = TokenSign.sign(accountName,id,accountEntity.getFarmIds(),null,null);
+            String token = TokenSign.sign(accountName, id, accountEntity.getFarmIds(), null, null);
             accessToken.setToken(token);
 
             accessToken.setId(id);
             accessToken.setLoginIp(remoteHost);
             accessToken.setType(accountEntity.getType());
             Integer lastFarmId = accountEntity.getLastFarmId();
-            if (ObjectUtil.isEmpty(lastFarmId)){
+            if (ObjectUtil.isEmpty(lastFarmId)) {
                 lastFarmId = Integer.parseInt(accountEntity.getFarmIds().split(",")[0]);
             }
             accessToken.setLastFarmId(lastFarmId);
             accessToken.setUserName(accountEntity.getUserName());
 
-            return new Result(ResultCode.SUCCESS,accessToken);
+            return new Result(ResultCode.SUCCESS, accessToken);
         }
-        return  result;
+        return result;
     }
 
     //测试-token
     @PostMapping(value = "/getToken")
-    public String getToken(HttpServletRequest req)  {
-        String token =  TokenSign.sign("superadmin",1,null,null,null);
-        return  token;
+    public String getToken(HttpServletRequest req) {
+        String token = TokenSign.sign("superadmin", 1, null, null, null);
+        return token;
     }
 
     @RequestMapping("/logoutClient")
@@ -139,22 +144,22 @@ public class LoginController {
             accessToken.setFarmId(data.getFarmIds());
             accessToken.setType(data.getType());
             accessToken.setId(data.getId());
-            String token = TokenSign.sign(accountName,data.getId(),data.getFarmIds(),data.getWorkLocationId(),data.getType());
+            String token = TokenSign.sign(accountName, data.getId(), data.getFarmIds(), data.getWorkLocationId(), data.getType());
             accessToken.setToken(token);
             Integer lastFarmId = data.getLastFarmId();
-            if (ObjectUtil.isEmpty(lastFarmId)){
+            if (ObjectUtil.isEmpty(lastFarmId)) {
                 lastFarmId = Integer.parseInt(data.getFarmIds().split(",")[0]);
             }
             accessToken.setLastFarmId(lastFarmId);
             accessToken.setLoginIp(remoteHost);
-            return new Result(ResultCode.SUCCESS,accessToken);
+            return new Result(ResultCode.SUCCESS, accessToken);
         } else {
             return result;
-        } 
+        }
     }
 
 
-    @RequestMapping("/logoutWeChat")
+/*    @RequestMapping("/logoutWeChat")
     public Result logoutWeChat(HttpServletRequest req, @RequestBody Map<String, String> map) {
         String remark = map.get("remark");
         QueryWrapper<SysAccountMultilevel> queryWrapper = new QueryWrapper<>();
@@ -191,7 +196,7 @@ public class LoginController {
             accessToken.setToken(token);
         }
         return new Result(ResultCode.SUCCESS,accessToken);
-  /*      String accountName = map.get("accountName");
+  *//*      String accountName = map.get("accountName");
         String password = map.get("password");
         String remoteHost = req.getRemoteHost();
         Result result = iLoginService.loginMultilevel(accountName, password);
@@ -214,7 +219,111 @@ public class LoginController {
             return new Result(ResultCode.SUCCESS,accessToken);
         } else {
             return result;
-        }*/
+        }*//*
+    }*/
+
+    @GetMapping("/logoutWeChat")
+    public Result logoutWeChat(HttpServletRequest req, @RequestParam String jsCode) {
+        String remoteHost = req.getRemoteHost();
+        Map<String, Object> paramsMap = new HashMap<>();
+        paramsMap.put("appid", "wxa28e45fe5cb10ff1");
+        paramsMap.put("secret", "c16e584ec6e69fd35edd98ec21ec5e94");
+        paramsMap.put("js_code", jsCode);
+        paramsMap.put("grant_type", "authorization_code");
+        String result = HttpUtil.get("https://api.weixin.qq.com/sns/jscode2session", paramsMap);
+        System.out.println(result);
+        JSONObject jsonObject = JSON.parseObject(result);
+        System.out.println(jsonObject);
+        String openid = (String) jsonObject.get("openid");
+        String sessionKey = (String) jsonObject.get("session_key");
+        System.out.println("拿到了openid" + openid);
+        System.out.println("拿到了sessionKey" + sessionKey);
+        QueryWrapper<SysAccountMultilevel> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("wechat_id", openid);
+        SysAccountMultilevel data = accountMultilevelService.getOne(queryWrapper);
+        WeCahtVo weCahtVo = new WeCahtVo();
+        weCahtVo.setOpenId(openid);
+        weCahtVo.setSessionKey(sessionKey);
+        if (ObjectUtil.isEmpty(data)) {
+            return new Result(ResultCode.FAIL, weCahtVo);
+        } else {
+            AccessToken accessToken = new AccessToken();
+            accessToken.setSysAccountMultilevel(data);
+            accessToken.setAccountName(data.getAccount());
+            accessToken.setUserName(data.getUserName());
+            accessToken.setFarmId(data.getFarmIds());
+            accessToken.setType(data.getType());
+            accessToken.setId(data.getId());
+            String token = TokenSign.sign(data.getAccount(), data.getId(), data.getFarmIds(), data.getWorkLocationId(), 7);
+            accessToken.setToken(token);
+            Integer lastFarmId = data.getLastFarmId();
+            if (ObjectUtil.isEmpty(lastFarmId)) {
+                lastFarmId = Integer.parseInt(data.getFarmIds().split(",")[0]);
+            }
+            accessToken.setLastFarmId(lastFarmId);
+            accessToken.setLoginIp(remoteHost);
+            return new Result(ResultCode.SUCCESS, accessToken);
+        }
     }
 
+    @PostMapping("/register")
+    public Result addAdmission(HttpServletRequest req, @RequestParam("userName") String userName,
+                               @RequestParam("phone") String phone,
+                               @RequestParam("workName") String workName,
+                               @RequestParam("papersType") String papersType,
+                               @RequestParam("papersCode") String papersCode,
+                               @RequestParam(value = "imgUrl", required = false) MultipartFile imgUrl,
+                               @RequestParam("openId") String openId) throws IOException {
+        String remoteHost = req.getRemoteHost();
+        QueryWrapper<SysAccountMultilevel> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("phone", phone).or().eq("papers_code", papersCode);
+        if (ObjectUtil.isNotEmpty(accountMultilevelService.getOne(queryWrapper))) {
+            return new Result(10001, "该手机号或身份证号已被使用!", false);
+        }
+        if (!PhoneNumberValidator.isValidPhoneNumber(phone)) {
+            return new Result(10001,"手机号格式错误!",false);
+        }
+        if (papersType.equals("0")){
+            if (!IDCardValidator.isValidIDCard(papersCode)){
+                return new Result(10001,"身份证号格式错误!",false);
+            }
+        }
+        SysAccountMultilevel sysAccountMultilevel = new SysAccountMultilevel();
+        sysAccountMultilevel.setUserName(userName);
+        sysAccountMultilevel.setPapersCode(papersCode);
+        sysAccountMultilevel.setPhone(phone);
+        sysAccountMultilevel.setAccount(phone);
+        sysAccountMultilevel.setPid(0);
+        sysAccountMultilevel.setPids("0");
+        sysAccountMultilevel.setPassword("123456");
+        sysAccountMultilevel.setWorkName(workName);
+        sysAccountMultilevel.setAccountStatus(1);
+        sysAccountMultilevel.setFarmIds("25");
+        sysAccountMultilevel.setLastFarmId(25);
+        sysAccountMultilevel.setPapersType(papersType);
+        sysAccountMultilevel.setWechatId(openId);
+        sysAccountMultilevel.setType(7);
+        String imageCom = uploadImage.getImageCom(imgUrl);
+        if (imageCom.equals("上传失败")) {
+            return new Result(10001, "图片上传失败!", false);
+        }
+        sysAccountMultilevel.setImgUrl(imageCom);
+        accountMultilevelService.save(sysAccountMultilevel);
+        AccessToken accessToken = new AccessToken();
+        accessToken.setSysAccountMultilevel(sysAccountMultilevel);
+        accessToken.setAccountName(sysAccountMultilevel.getAccount());
+        accessToken.setUserName(sysAccountMultilevel.getUserName());
+        accessToken.setFarmId(sysAccountMultilevel.getFarmIds());
+        accessToken.setType(sysAccountMultilevel.getType());
+        accessToken.setId(sysAccountMultilevel.getId());
+        String token = TokenSign.sign(sysAccountMultilevel.getAccount(), sysAccountMultilevel.getId(), sysAccountMultilevel.getFarmIds(), sysAccountMultilevel.getWorkLocationId(), sysAccountMultilevel.getType());
+        accessToken.setToken(token);
+        Integer lastFarmId = sysAccountMultilevel.getLastFarmId();
+        if (ObjectUtil.isEmpty(lastFarmId)) {
+            lastFarmId = Integer.parseInt(sysAccountMultilevel.getFarmIds().split(",")[0]);
+        }
+        accessToken.setLastFarmId(lastFarmId);
+        accessToken.setLoginIp(remoteHost);
+        return new Result(ResultCode.SUCCESS, accessToken);
+    }
 }

+ 1 - 0
huimv-admin/src/main/java/com/huimv/admin/entity/SysAccountMultilevel.java

@@ -59,5 +59,6 @@ public class SysAccountMultilevel extends Model {
     //证件类型 0身份证 ,1护照
     private String papersType;
     private String papersCode;
+    private String wechatId;
 
 }

+ 10 - 0
huimv-admin/src/main/java/com/huimv/admin/entity/dto/WeCahtVo.java

@@ -0,0 +1,10 @@
+package com.huimv.admin.entity.dto;
+
+import lombok.Data;
+
+@Data
+public class WeCahtVo {
+
+    private String openId;
+    private String sessionKey;
+}

+ 1 - 1
huimv-admin/src/main/java/com/huimv/admin/service/impl/BillCleanServiceImpl.java

@@ -72,7 +72,7 @@ public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean
         }
         Page<BillClean> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
         QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("farm_id", farmId).eq("vistit_type", type);
+        queryWrapper.eq("farm_id", farmId).eq("vistit_type", type).orderByDesc("sub_date");
         if ("1".equals(data)) {
             queryWrapper.in("bill_status", 0, 1, 2);
         }

+ 1 - 1
huimv-admin/src/main/java/com/huimv/admin/service/impl/BillPcrServiceImpl.java

@@ -83,7 +83,7 @@ public class BillPcrServiceImpl extends ServiceImpl<BillPcrMapper, BillPcr> impl
         }
         Page<BillPcr> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
         QueryWrapper<BillPcr> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("farm_id", farmId).eq("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
+        queryWrapper.eq("farm_id", farmId).eq("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest)).orderByDesc("sub_date");
         if ("0".equals(type)) {
             queryWrapper.in("bill_status", 0, 1, 2, 3);
         }

+ 44 - 14
huimv-admin/src/main/java/com/huimv/admin/service/impl/BillPersonnelAdmissionServiceImpl.java

@@ -276,26 +276,35 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
     @Override
     public Result listPrc(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         String type = paramsMap.get("type");//类型
+        String pageNum = paramsMap.get("pageNum");
+        String pageSize = paramsMap.get("pageSize");
+        if ("".equals(pageNum) || null == pageNum) {
+            pageNum = "1";
+        }
+        if ("".equals(pageSize) || null == pageSize) {
+            pageSize = "20";
+        }
+        Page<BillPcr> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
         if ("".equals(type) || null == type) {
             type = "0";
         }
         String farmId = paramsMap.get("farmId");
         QueryWrapper<BillPcr> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("farm_id", farmId).eq("pcr_type", 1).eq("test_location_id",TokenSign.getWorkIdByJwtToken(httpServletRequest));
+
+        queryWrapper.eq("farm_id", farmId).eq("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest)).orderByDesc("sub_date");
         if ("0".equals(type)) {
-            queryWrapper.in("bill_status", 0, 1, 2, 3);
+            queryWrapper.in("pcr_type",  1, 2, 3);
         }
         if ("1".equals(type)) {
-            queryWrapper.eq("bill_status", 0);
+            queryWrapper.eq("pcr_type", 1);
         }
         if ("2".equals(type)) {
-            queryWrapper.eq("bill_status", 1);
+            queryWrapper.eq("pcr_type", 2);
         }
         if ("3".equals(type)) {
-            queryWrapper.in("bill_status", 2, 3);
+            queryWrapper.eq("pcr_type",  3);
         }
-        List<BillPcr> billPcrs = pcrMapper.selectList(queryWrapper);
-        return new Result(ResultCode.SUCCESS, billPcrs);
+        return new Result(ResultCode.SUCCESS,  pcrMapper.selectPage(page,queryWrapper));
     }
 
     @Override
@@ -310,7 +319,7 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
         String type = paramsMap.get("type");
         String id = paramsMap.get("id");
         String data = paramsMap.get("data");
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
         if (StringUtils.isBlank(data)) {
             data = sdf.format(new Date());
         }
@@ -331,6 +340,7 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
             if (billPcr.getDestId() > billPcr.getTestLocationId()) { //说明当前不是目的地
                 if ("1".equals(type)) {
                     billPcr.setBillStatus(1);
+                    billPcr.setPcrType(2);
                     billPcr.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                     billPcr.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                     billPcr.setTestLocation(baseLocation.getLocationName());
@@ -369,6 +379,7 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
                     return new Result(10000, "修改成功!", true);
                 } else {
                     billPcr.setBillStatus(2);
+                    billPcr.setPcrType(3);
                     billPcr.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                     billPcr.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                     billPcr.setTestLocation(baseLocation.getLocationName());
@@ -391,6 +402,7 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
             } else {
                 if ("1".equals(type)) {
                     billPcr.setBillStatus(1);
+                    billPcr.setPcrType(2);
                     billPcr.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                     billPcr.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                     billPcr.setTestLocation(baseLocation.getLocationName());
@@ -417,6 +429,7 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
                     baseProcess.setCurrentStatus(substring + "2");
                     baseProcess.setProcessType(2);
                     billPcr.setBillStatus(2);
+                    billPcr.setPcrType(3);
                     billPcr.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                     billPcr.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                     billPcr.setTestLocation(baseLocation.getLocationName());
@@ -436,12 +449,21 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
     @Override
     public Result listIsolate(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         String type = paramsMap.get("type");//类型
+        String pageNum = paramsMap.get("pageNum");
+        String pageSize = paramsMap.get("pageSize");
+        if ("".equals(pageNum) || null == pageNum) {
+            pageNum = "1";
+        }
+        if ("".equals(pageSize) || null == pageSize) {
+            pageSize = "20";
+        }
+        Page<BillIsolate> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
         if ("".equals(type) || null == type) {
             type = "0";
         }
         String farmId = paramsMap.get("farmId");
         QueryWrapper<BillIsolate> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("farm_id", farmId).eq("isolate_location_id",TokenSign.getWorkIdByJwtToken(httpServletRequest));
+        queryWrapper.eq("farm_id", farmId).eq("isolate_location_id",TokenSign.getWorkIdByJwtToken(httpServletRequest)).orderByDesc("sub_date");
         if ("0".equals(type)) {
             queryWrapper.in("bill_status", 0, 1, 2, 3);
         }
@@ -454,7 +476,7 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
         if ("3".equals(type)) {
             queryWrapper.in("bill_status", 2, 3);
         }
-        return new Result(ResultCode.SUCCESS, isolateMapper.selectList(queryWrapper));
+        return new Result(ResultCode.SUCCESS, isolateMapper.selectPage(page,queryWrapper));
     }
 
     @Override
@@ -469,11 +491,10 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
         Date startDate = billIsolate.getIsolateStartDate();
         Integer dayNum = billIsolate.getIsolateDayNum();//隔离天数
         Date endDate = DataUill.getNextDay(startDate, dayNum);
-        isolate.setIsolateLocation(billIsolate.getIsolateLocation());
-        isolate.setIsolateLocationId(billIsolate.getIsolateLocationId());
         isolate.setIsolateStartDate(startDate);
         isolate.setIsolateEndDate(endDate);
         isolate.setIsolateDayNum(dayNum);
+        isolate.setBillStatus(1);
         isolateMapper.updateById(isolate);
         return new Result(10000, "提交成功!", true);
     }
@@ -559,12 +580,21 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
     @Override
     public Result listClean(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         String type = paramsMap.get("type");//类型
+        String pageNum = paramsMap.get("pageNum");
+        String pageSize = paramsMap.get("pageSize");
+        if ("".equals(pageNum) || null == pageNum) {
+            pageNum = "1";
+        }
+        if ("".equals(pageSize) || null == pageSize) {
+            pageSize = "20";
+        }
+        Page<BillClean> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
         if ("".equals(type) || null == type) {
             type = "0";
         }
         String farmId = paramsMap.get("farmId");
         QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("farm_id", farmId).eq("test_location_id",TokenSign.getWorkIdByJwtToken(httpServletRequest));
+        queryWrapper.eq("farm_id", farmId).eq("test_location_id",TokenSign.getWorkIdByJwtToken(httpServletRequest)).orderByDesc("sub_date");
         if ("0".equals(type)) {
             queryWrapper.in("bill_status", 0, 1, 2);
         }
@@ -577,7 +607,7 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
         if ("3".equals(type)) {
             queryWrapper.eq("bill_status", 2);
         }
-        return new Result(ResultCode.SUCCESS,  cleanMapper.selectList(queryWrapper));
+        return new Result(ResultCode.SUCCESS,  cleanMapper.selectPage(page,queryWrapper));
 
     }
 }

+ 103 - 103
huimv-admin/src/main/java/com/huimv/admin/timer/CarmeraTimer.java

@@ -1,103 +1,103 @@
-//package com.huimv.admin.timer;
-//
-//import cn.hutool.core.codec.Base64;
-//import cn.hutool.core.util.ObjectUtil;
-//import cn.hutool.json.JSONUtil;
-//import com.alibaba.fastjson.JSON;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-//import com.huimv.admin.common.utils.Digests;
-//import com.huimv.admin.common.utils.HttpClientSSLUtils;
-//import com.huimv.admin.entity.EnvData;
-//import com.huimv.admin.entity.EnvDevice;
-//import com.huimv.admin.entity.EnvWarningInfo;
-//import com.huimv.admin.entity.EnvWarningThreshold;
-//import com.huimv.admin.entity.hkwsdto.CameraDto1;
-//import com.huimv.admin.entity.hkwsdto.HkvsCameraDto;
-//import com.huimv.admin.entity.zengxindto.*;
-//import com.huimv.admin.service.*;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.http.*;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.transaction.annotation.Transactional;
-//import org.springframework.web.client.RestTemplate;
-//
-//import java.lang.invoke.MethodHandleProxies;
-//import java.time.LocalDate;
-//import java.time.LocalDateTime;
-//import java.time.LocalTime;
-//import java.util.Date;
-//import java.util.HashMap;
-//import java.util.List;
-//import java.util.Map;
-//
-//@Configuration
-//@EnableScheduling
-//public class CarmeraTimer {
-//    private static final String APPKEY = "1c9ee657";
-//    private static final String SECRET = "a5d723941c804a429447e71db2707ce8";
-//    private static final String OPENAPI_IP_PORT_HTTP = "http://61.153.248.106:100";
-//    private static final String OPENAPI_IP_PORT_HTTPS = "https://61.153.248.106:4430";
-//    private static final String ITF_ADDRESS_GET_CAMERAS = "/openapi/service/vss/res/getCameras";
-//    private static final String OP_USER_UUID = "5b2eb534696b11e89c2e438f92627767";
-//
-//    @Autowired
-//    private ICameraBaseService cameraBaseService;
-//        //数据库账号密码加密
-//    //更新摄像头状态
-//    @Scheduled(cron = "0 0/10 * * * ? ")
-//    private void updateCameraOnlin() throws Exception {
-//        String cameras = testGetCameras();
-//        HkvsCameraDto hkvsCameraDto = JSONUtil.toBean(cameras, HkvsCameraDto.class);
-//        if (ObjectUtil.isNotEmpty(hkvsCameraDto) && hkvsCameraDto.getErrorCode() ==0 ){
-//            List<CameraDto1> list = hkvsCameraDto.getData().getList();
-//            if (ObjectUtil.isNotEmpty(list)){
-//                cameraBaseService.updateCameraOnlin(list);
-//            }
-//            System.out.println("更新成功");
-//        }else {
-//            System.out.println("摄像头信息为空");
-//        }
-//    }
-//    /**
-//     * HTTP方式
-//     * 分页获取监控点信息 测试
-//     * @return
-//     * @throws Exception
-//     */
-//    private static String testGetCameras() throws Exception{
-//        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_CAMERAS;
-//        Map<String, Object> map = new HashMap<String, Object>();
-//        map.put("appkey", APPKEY);//设置APPKEY
-//        map.put("time", System.currentTimeMillis());//设置时间参数
-//        map.put("pageNo", 1);//设置分页参数
-//        map.put("pageSize", 1000);//设置分页参数
-//        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
-//        String params = JSON.toJSONString(map);
-//        System.out.println(" ====== getCameras请求参数:【" + params + "】");
-//        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
-//        System.out.println(" ====== getCameras请求返回结果:【{" + data + "}】");
-//        return data;
-//    }
-//
-//
-//    public static void main(String[] args) {
-//        RestTemplate restTemplate = new RestTemplate();
-//        String envUrl = "https://dnqyt.envchina.com/api/public/station-data";
-//        LocalDate previousDay = LocalDate.now().minusDays(1);
-//        LocalDateTime previousDayStart = LocalDateTime.of(previousDay, LocalTime.MIN);
-//
-//        String sgToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJkYW9ub25nIiwidWlkIjozLCJ1biI6IlpYUUxZWktKMjMwN0EyIiwiZXhwIjoxNjg5MDcwNTYxLCJqdGkiOiIzIn0.BEFESZrKOwBej4rxOfoj7qPcHGomh6KN7xbXdjOB__w";
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.add("token",sgToken);
-//        headers.setContentType(MediaType.APPLICATION_JSON);
-//        HttpEntity<Map<String, Object>> formEntity = new HttpEntity<Map<String, Object>>(headers);
-//
-//        String urlWithParams = envUrl + "?type=D&mn=33330424001391" + "&startTime=" + "2023-07-10 00:00:00" + "&endTime=" + "2023-07-10 00:00:00";
-//        ResponseEntity<String> result = restTemplate.exchange(urlWithParams, HttpMethod.GET,formEntity,String.class);
-//        System.out.println(result);
-//    }
-//
-//}
+package com.huimv.admin.timer;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.huimv.admin.common.utils.Digests;
+import com.huimv.admin.common.utils.HttpClientSSLUtils;
+import com.huimv.admin.entity.EnvData;
+import com.huimv.admin.entity.EnvDevice;
+import com.huimv.admin.entity.EnvWarningInfo;
+import com.huimv.admin.entity.EnvWarningThreshold;
+import com.huimv.admin.entity.hkwsdto.CameraDto1;
+import com.huimv.admin.entity.hkwsdto.HkvsCameraDto;
+import com.huimv.admin.entity.zengxindto.*;
+import com.huimv.admin.service.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.*;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
+
+import java.lang.invoke.MethodHandleProxies;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Configuration
+@EnableScheduling
+public class CarmeraTimer {
+    private static final String APPKEY = "1c9ee657";
+    private static final String SECRET = "a5d723941c804a429447e71db2707ce8";
+    private static final String OPENAPI_IP_PORT_HTTP = "http://61.153.248.106:100";
+    private static final String OPENAPI_IP_PORT_HTTPS = "https://61.153.248.106:4430";
+    private static final String ITF_ADDRESS_GET_CAMERAS = "/openapi/service/vss/res/getCameras";
+    private static final String OP_USER_UUID = "5b2eb534696b11e89c2e438f92627767";
+
+    @Autowired
+    private ICameraBaseService cameraBaseService;
+        //数据库账号密码加密
+    //更新摄像头状态
+    @Scheduled(cron = "0 0/10 * * * ? ")
+    private void updateCameraOnlin() throws Exception {
+        String cameras = testGetCameras();
+        HkvsCameraDto hkvsCameraDto = JSONUtil.toBean(cameras, HkvsCameraDto.class);
+        if (ObjectUtil.isNotEmpty(hkvsCameraDto) && hkvsCameraDto.getErrorCode() ==0 ){
+            List<CameraDto1> list = hkvsCameraDto.getData().getList();
+            if (ObjectUtil.isNotEmpty(list)){
+                cameraBaseService.updateCameraOnlin(list);
+            }
+            System.out.println("更新成功");
+        }else {
+            System.out.println("摄像头信息为空");
+        }
+    }
+    /**
+     * HTTP方式
+     * 分页获取监控点信息 测试
+     * @return
+     * @throws Exception
+     */
+    private static String testGetCameras() throws Exception{
+        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_CAMERAS;
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("appkey", APPKEY);//设置APPKEY
+        map.put("time", System.currentTimeMillis());//设置时间参数
+        map.put("pageNo", 1);//设置分页参数
+        map.put("pageSize", 1000);//设置分页参数
+        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
+        String params = JSON.toJSONString(map);
+        System.out.println(" ====== getCameras请求参数:【" + params + "】");
+        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
+        System.out.println(" ====== getCameras请求返回结果:【{" + data + "}】");
+        return data;
+    }
+
+
+    public static void main(String[] args) {
+        RestTemplate restTemplate = new RestTemplate();
+        String envUrl = "https://dnqyt.envchina.com/api/public/station-data";
+        LocalDate previousDay = LocalDate.now().minusDays(1);
+        LocalDateTime previousDayStart = LocalDateTime.of(previousDay, LocalTime.MIN);
+
+        String sgToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJkYW9ub25nIiwidWlkIjozLCJ1biI6IlpYUUxZWktKMjMwN0EyIiwiZXhwIjoxNjg5MDcwNTYxLCJqdGkiOiIzIn0.BEFESZrKOwBej4rxOfoj7qPcHGomh6KN7xbXdjOB__w";
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("token",sgToken);
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        HttpEntity<Map<String, Object>> formEntity = new HttpEntity<Map<String, Object>>(headers);
+
+        String urlWithParams = envUrl + "?type=D&mn=33330424001391" + "&startTime=" + "2023-07-10 00:00:00" + "&endTime=" + "2023-07-10 00:00:00";
+        ResponseEntity<String> result = restTemplate.exchange(urlWithParams, HttpMethod.GET,formEntity,String.class);
+        System.out.println(result);
+    }
+
+}

+ 138 - 138
huimv-admin/src/main/java/com/huimv/admin/timer/EnergyTimer.java

@@ -1,138 +1,138 @@
-//package com.huimv.admin.timer;
-//
-//import cn.hutool.core.date.DateTime;
-//import cn.hutool.core.date.DateUtil;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.huimv.admin.common.utils.NumberUtils;
-//import com.huimv.admin.entity.*;
-//import com.huimv.admin.mapper.*;
-//import org.apache.commons.lang.time.DateUtils;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//
-//import java.text.DecimalFormat;
-//import java.util.Date;
-//import java.util.List;
-//
-//@Configuration
-//@EnableScheduling
-//public class EnergyTimer {
-//
-//    @Autowired
-//    private EnergyEnvDeviceMapper deviceMapper;
-//    @Autowired
-//    private EnergyDataMapper dataMapper;
-//    @Autowired
-//    private BasePigpenMapper basePigpenMapper;
-//    @Autowired
-//    private EnergyWarningThresholdMapper warningThresholdMapper;
-//    @Autowired
-//    private EnergyWarningInfoMapper infoMapper;
-//
-//    //    能耗数据
-//    @Scheduled(cron = "0 0 */1 * * ? ")
-////    @Scheduled(cron = "0 */1 * * * ? ")
-//    private void getShenChan() throws Exception {
-//        List<EnergyEnvDevice> energyEnvDevices = deviceMapper.selectList(null);
-//
-//        for (EnergyEnvDevice energyEnvDevice : energyEnvDevices) {
-//            QueryWrapper<BasePigpen> basePigpenQueryWrapper = new QueryWrapper<>();
-//            basePigpenQueryWrapper.eq("id", energyEnvDevice.getUnitId()).eq("farm_id", energyEnvDevice.getFarmId());
-//            BasePigpen basePigpen1 = basePigpenMapper.selectOne(basePigpenQueryWrapper);
-//            QueryWrapper<BasePigpen> queryWrapper = new QueryWrapper<>();
-//            queryWrapper.eq("id", basePigpen1.getParentId());
-//            BasePigpen basePigpen = basePigpenMapper.selectOne(queryWrapper);
-//
-//            String feed = NumberUtils.getNumFloat2(6.00,6.50);
-//            String water = NumberUtils.getNumFloat2(0.08,0.15);
-////            String gas = NumberUtils.getNum(200, 280, 1);
-//            String gas = "0";
-//            String electricity = NumberUtils.getNumFloat2(1.0, 1.45 );
-//
-//            EnergyData energyData = new EnergyData();
-//            energyData.setCreateDate(new Date());
-//            energyData.setFarmId(energyEnvDevice.getFarmId());
-//            energyData.setUnitId(energyEnvDevice.getUnitId());
-//            energyData.setFeedValue(feed);
-//            energyData.setWaterValue(water);
-//            energyData.setGasValue(gas);
-//            energyData.setElectricityValue(electricity);
-//            dataMapper.insert(energyData);
-//
-//            QueryWrapper<EnergyWarningThreshold> wrapper = new QueryWrapper<>();
-//            wrapper.eq("other1", basePigpen.getStageCode()).eq("farm_id",energyEnvDevice.getFarmId());
-//            EnergyWarningThreshold threshold = warningThresholdMapper.selectOne(wrapper);
-//
-//            QueryWrapper<EnergyData> dataQueryWrapper = new QueryWrapper<>();
-//            dataQueryWrapper.eq("farm_id", energyEnvDevice.getFarmId()).eq("unit_id", energyEnvDevice.getUnitId());
-//            DateTime dateTime = DateUtil.beginOfDay(new Date());
-//            dataQueryWrapper.ge("create_date", dateTime);
-//            EnergyData energyData1 = dataMapper.listDataCount(dataQueryWrapper);
-//
-//            if (Float.parseFloat(energyData1.getWaterValue())+Float.parseFloat(water) >Float.parseFloat(threshold.getMaxWater())) {
-//                float waterCount = Float.parseFloat(energyData1.getWaterValue()) + Float.parseFloat(water);
-//                DecimalFormat df = new DecimalFormat("#.00");
-//                String format = df.format(waterCount);
-//                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
-//                warningInfo.setWarningType(1);
-//                warningInfo.setWarningContent("今日累计用水量" + format + "t,超过阈值");
-//                warningInfo.setUnitName(basePigpen1.getBuildName());
-//                warningInfo.setUnitId(energyEnvDevice.getUnitId());
-//                warningInfo.setDeviceId(energyEnvDevice.getId());
-//                warningInfo.setDate(new Date());
-//                warningInfo.setFarmId(energyEnvDevice.getFarmId());
-//                warningInfo.setUserIds(threshold.getUserIds());
-//                infoMapper.insert(warningInfo);
-//            }
-//            if (Float.parseFloat(energyData1.getElectricityValue())+Float.parseFloat(electricity) >Float.parseFloat(threshold.getMaxElectricity())) {
-//                float electricityCount = Float.parseFloat(energyData1.getElectricityValue()) + Float.parseFloat(electricity);
-//                DecimalFormat df = new DecimalFormat("#.00");
-//                String format = df.format(electricityCount);
-//                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
-//                warningInfo.setWarningType(2);
-//                warningInfo.setWarningContent("今日累计用电量" + format + "kw/h,超过阈值");
-//                warningInfo.setUnitName(basePigpen1.getBuildName());
-//                warningInfo.setUnitId(energyEnvDevice.getUnitId());
-//                warningInfo.setDeviceId(energyEnvDevice.getId());
-//                warningInfo.setDate(new Date());
-//                warningInfo.setFarmId(energyEnvDevice.getFarmId());
-//                warningInfo.setUserIds(threshold.getUserIds());
-//                infoMapper.insert(warningInfo);
-//            }
-//            if (Float.parseFloat(energyData1.getFeedValue())+Float.parseFloat(feed) >Float.parseFloat(threshold.getMaxFeed())) {
-//                float feedCount = Float.parseFloat(energyData1.getFeedValue()) + Float.parseFloat(feed);
-//                DecimalFormat df = new DecimalFormat("#.00");
-//                String format = df.format(feedCount);
-//                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
-//                warningInfo.setWarningType(3);
-//                warningInfo.setWarningContent("今日累计用料量" + format + "kg,超过阈值");
-//                warningInfo.setUnitName(basePigpen.getBuildName());
-//                warningInfo.setUnitId(energyEnvDevice.getUnitId());
-//                warningInfo.setDeviceId(energyEnvDevice.getId());
-//                warningInfo.setDate(new Date());
-//                warningInfo.setFarmId(energyEnvDevice.getFarmId());
-//                warningInfo.setUserIds(threshold.getUserIds());
-//                infoMapper.insert(warningInfo);
-//            }
-//            if (Float.parseFloat(energyData1.getGasValue())+Float.parseFloat(gas) >Float.parseFloat(threshold.getMaxGas())) {
-//                float gasCount = Float.parseFloat(energyData1.getGasValue()) + Float.parseFloat(gas);
-//                DecimalFormat df = new DecimalFormat("#.00");
-//                String format = df.format(gasCount);
-//                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
-//                warningInfo.setWarningType(4);
-//                warningInfo.setWarningContent("今日累计用气量" + format + "m³,超过阈值");
-//                warningInfo.setUnitName(basePigpen.getBuildName());
-//                warningInfo.setUnitId(energyEnvDevice.getUnitId());
-//                warningInfo.setDeviceId(energyEnvDevice.getId());
-//                warningInfo.setDate(new Date());
-//                warningInfo.setFarmId(energyEnvDevice.getFarmId());
-//                warningInfo.setUserIds(threshold.getUserIds());
-//                infoMapper.insert(warningInfo);
-//            }
-//
-//        }
-//
-//    }
-//}
+package com.huimv.admin.timer;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.common.utils.NumberUtils;
+import com.huimv.admin.entity.*;
+import com.huimv.admin.mapper.*;
+import org.apache.commons.lang.time.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.text.DecimalFormat;
+import java.util.Date;
+import java.util.List;
+
+@Configuration
+@EnableScheduling
+public class EnergyTimer {
+
+    @Autowired
+    private EnergyEnvDeviceMapper deviceMapper;
+    @Autowired
+    private EnergyDataMapper dataMapper;
+    @Autowired
+    private BasePigpenMapper basePigpenMapper;
+    @Autowired
+    private EnergyWarningThresholdMapper warningThresholdMapper;
+    @Autowired
+    private EnergyWarningInfoMapper infoMapper;
+
+    //    能耗数据
+    @Scheduled(cron = "0 0 */1 * * ? ")
+//    @Scheduled(cron = "0 */1 * * * ? ")
+    private void getShenChan() throws Exception {
+        List<EnergyEnvDevice> energyEnvDevices = deviceMapper.selectList(null);
+
+        for (EnergyEnvDevice energyEnvDevice : energyEnvDevices) {
+            QueryWrapper<BasePigpen> basePigpenQueryWrapper = new QueryWrapper<>();
+            basePigpenQueryWrapper.eq("id", energyEnvDevice.getUnitId()).eq("farm_id", energyEnvDevice.getFarmId());
+            BasePigpen basePigpen1 = basePigpenMapper.selectOne(basePigpenQueryWrapper);
+            QueryWrapper<BasePigpen> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("id", basePigpen1.getParentId());
+            BasePigpen basePigpen = basePigpenMapper.selectOne(queryWrapper);
+
+            String feed = NumberUtils.getNumFloat2(6.00,6.50);
+            String water = NumberUtils.getNumFloat2(0.08,0.15);
+//            String gas = NumberUtils.getNum(200, 280, 1);
+            String gas = "0";
+            String electricity = NumberUtils.getNumFloat2(1.0, 1.45 );
+
+            EnergyData energyData = new EnergyData();
+            energyData.setCreateDate(new Date());
+            energyData.setFarmId(energyEnvDevice.getFarmId());
+            energyData.setUnitId(energyEnvDevice.getUnitId());
+            energyData.setFeedValue(feed);
+            energyData.setWaterValue(water);
+            energyData.setGasValue(gas);
+            energyData.setElectricityValue(electricity);
+            dataMapper.insert(energyData);
+
+            QueryWrapper<EnergyWarningThreshold> wrapper = new QueryWrapper<>();
+            wrapper.eq("other1", basePigpen.getStageCode()).eq("farm_id",energyEnvDevice.getFarmId());
+            EnergyWarningThreshold threshold = warningThresholdMapper.selectOne(wrapper);
+
+            QueryWrapper<EnergyData> dataQueryWrapper = new QueryWrapper<>();
+            dataQueryWrapper.eq("farm_id", energyEnvDevice.getFarmId()).eq("unit_id", energyEnvDevice.getUnitId());
+            DateTime dateTime = DateUtil.beginOfDay(new Date());
+            dataQueryWrapper.ge("create_date", dateTime);
+            EnergyData energyData1 = dataMapper.listDataCount(dataQueryWrapper);
+
+            if (Float.parseFloat(energyData1.getWaterValue())+Float.parseFloat(water) >Float.parseFloat(threshold.getMaxWater())) {
+                float waterCount = Float.parseFloat(energyData1.getWaterValue()) + Float.parseFloat(water);
+                DecimalFormat df = new DecimalFormat("#.00");
+                String format = df.format(waterCount);
+                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
+                warningInfo.setWarningType(1);
+                warningInfo.setWarningContent("今日累计用水量" + format + "t,超过阈值");
+                warningInfo.setUnitName(basePigpen1.getBuildName());
+                warningInfo.setUnitId(energyEnvDevice.getUnitId());
+                warningInfo.setDeviceId(energyEnvDevice.getId());
+                warningInfo.setDate(new Date());
+                warningInfo.setFarmId(energyEnvDevice.getFarmId());
+                warningInfo.setUserIds(threshold.getUserIds());
+                infoMapper.insert(warningInfo);
+            }
+            if (Float.parseFloat(energyData1.getElectricityValue())+Float.parseFloat(electricity) >Float.parseFloat(threshold.getMaxElectricity())) {
+                float electricityCount = Float.parseFloat(energyData1.getElectricityValue()) + Float.parseFloat(electricity);
+                DecimalFormat df = new DecimalFormat("#.00");
+                String format = df.format(electricityCount);
+                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
+                warningInfo.setWarningType(2);
+                warningInfo.setWarningContent("今日累计用电量" + format + "kw/h,超过阈值");
+                warningInfo.setUnitName(basePigpen1.getBuildName());
+                warningInfo.setUnitId(energyEnvDevice.getUnitId());
+                warningInfo.setDeviceId(energyEnvDevice.getId());
+                warningInfo.setDate(new Date());
+                warningInfo.setFarmId(energyEnvDevice.getFarmId());
+                warningInfo.setUserIds(threshold.getUserIds());
+                infoMapper.insert(warningInfo);
+            }
+            if (Float.parseFloat(energyData1.getFeedValue())+Float.parseFloat(feed) >Float.parseFloat(threshold.getMaxFeed())) {
+                float feedCount = Float.parseFloat(energyData1.getFeedValue()) + Float.parseFloat(feed);
+                DecimalFormat df = new DecimalFormat("#.00");
+                String format = df.format(feedCount);
+                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
+                warningInfo.setWarningType(3);
+                warningInfo.setWarningContent("今日累计用料量" + format + "kg,超过阈值");
+                warningInfo.setUnitName(basePigpen.getBuildName());
+                warningInfo.setUnitId(energyEnvDevice.getUnitId());
+                warningInfo.setDeviceId(energyEnvDevice.getId());
+                warningInfo.setDate(new Date());
+                warningInfo.setFarmId(energyEnvDevice.getFarmId());
+                warningInfo.setUserIds(threshold.getUserIds());
+                infoMapper.insert(warningInfo);
+            }
+            if (Float.parseFloat(energyData1.getGasValue())+Float.parseFloat(gas) >Float.parseFloat(threshold.getMaxGas())) {
+                float gasCount = Float.parseFloat(energyData1.getGasValue()) + Float.parseFloat(gas);
+                DecimalFormat df = new DecimalFormat("#.00");
+                String format = df.format(gasCount);
+                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
+                warningInfo.setWarningType(4);
+                warningInfo.setWarningContent("今日累计用气量" + format + "m³,超过阈值");
+                warningInfo.setUnitName(basePigpen.getBuildName());
+                warningInfo.setUnitId(energyEnvDevice.getUnitId());
+                warningInfo.setDeviceId(energyEnvDevice.getId());
+                warningInfo.setDate(new Date());
+                warningInfo.setFarmId(energyEnvDevice.getFarmId());
+                warningInfo.setUserIds(threshold.getUserIds());
+                infoMapper.insert(warningInfo);
+            }
+
+        }
+
+    }
+}

+ 372 - 372
huimv-admin/src/main/java/com/huimv/admin/timer/EnvTimer.java

@@ -1,372 +1,372 @@
-//package com.huimv.admin.timer;
-//
-//
-//import cn.hutool.core.codec.Base64;
-//import cn.hutool.core.date.DateTime;
-//import cn.hutool.core.date.DateUtil;
-//import cn.hutool.core.util.ObjectUtil;
-//import cn.hutool.http.HttpUtil;
-//import cn.hutool.json.JSONUtil;
-//import com.alibaba.fastjson.JSON;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-//import com.huimv.admin.common.utils.HttpClientSSLUtils;
-//import com.huimv.admin.common.utils.NumberUtils;
-//import com.huimv.admin.entity.*;
-//import com.huimv.admin.entity.dto.WeatherDto;
-//import com.huimv.admin.entity.dto.WeatherLives;
-//import com.huimv.admin.entity.zengxindto.*;
-//import com.huimv.admin.service.*;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.http.HttpEntity;
-//import org.springframework.http.HttpHeaders;
-//import org.springframework.http.HttpMethod;
-//import org.springframework.http.ResponseEntity;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.transaction.annotation.Transactional;
-//import org.springframework.web.client.RestTemplate;
-//
-//import javax.servlet.http.HttpServletRequest;
-//import java.text.NumberFormat;
-//import java.util.Date;
-//import java.util.HashMap;
-//import java.util.List;
-//import java.util.Map;
-//
-//@Configuration
-//@EnableScheduling
-//public class EnvTimer {
-//
-//    @Autowired
-//    private RestTemplate restTemplate;
-//    @Autowired
-//    private IEnvDeviceService envDeviceService;
-//    @Autowired
-//    private IEnvDeviceOnlineService envDeviceOnlineService;
-//    @Autowired
-//    private IFarmService farmService;
-//
-//    @Autowired
-//    private IBasePigpenService basePigpenService;
-//
-//    @Autowired
-//    private IEnvDataService envDataService;
-//    @Autowired
-//    private IEnvWarningThresholdService envWarningThresholdService;
-//
-//    @Autowired
-//    private IEnvWarningInfoService envWarningInfoService;
-//    //环控数据
-//    String username = "华统";
-//    String password = "888888";
-//    String passwordMD5 = "21218cca77804d2ba1922c33e0151105";
-//    String baseurl = "https://yzwlw.loongk.com/";
-//
-//    @Scheduled(cron = "0 0/11 * * * ? ")
-////    @Scheduled(cron = "0 * * * * ? ")
-//    @Transactional
-//    public void getHuanKong() throws Exception {
-//        //目前是这家
-//        Integer farmId = 21;
-//        String encode = loginOnly();
-////        System.out.println("encode" + encode);
-//        //获取阈值
-//        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.add("Authorization", encode);
-//        HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
-//        //TODO 只有一家,先拿全部
-//        List<EnvDevice> list = envDeviceService.list();
-//        for (EnvDevice envDevice : list) {
-//            if (ObjectUtil.isNotEmpty(envDevice) && StringUtils.isNotBlank(envDevice.getDeviceCode())) {
-//                System.out.println(envDevice.getDeviceCode());
-//                String shishiBody = "";
-//                try {
-//                    ResponseEntity<String> exchange = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackDatas/" + envDevice.getDeviceCode(), HttpMethod.GET, requestEntity, String.class);
-//                    shishiBody = exchange.getBody();
-//                } catch (Exception e) {
-//                    System.out.println(e);
-//                }
-//
-//                if (StringUtils.isBlank(shishiBody)) {
-//                    System.out.println(new Date() + "实时数据" + shishiBody);
-//                    continue;
-//                }
-//                ShackDatasDto shackDatasDto = JSONUtil.toBean(shishiBody, ShackDatasDto.class);
-//
-//                ShackDatasDataDto data = shackDatasDto.getData();
-//                if (ObjectUtil.isEmpty(data)){
-//                    continue;
-//                }
-//                String onLine = shackDatasDto.getData().getOnLine();
-//                if ("N".equals(onLine)) {
-//                    envDevice.setDeviceStatus(0);
-//                } else {
-//                    envDevice.setDeviceStatus(1);
-//                }
-//                envDeviceService.updateById(envDevice);
-//                List<ShackDatasSensor> sensorDatas = shackDatasDto.getData().getSensorDatas();
-//                EnvData envData = new EnvData();
-//                for (ShackDatasSensor sensorData : sensorDatas) {
-//                    if (sensorData.getId().equals(envDevice.getOhter1())) {
-//                        String val = sensorData.getVal();
-//                        //TODO 预警
-//                        saveTemWarning(val, envWarningThreshold, envDevice, farmId);
-//                        envData.setEnvTemp(val);
-//                    }
-//                    if (sensorData.getId().equals(envDevice.getOhter2())) {
-//                        String val = sensorData.getVal();
-//                        //TODO 预警
-//                        saveHumWarning(val, envWarningThreshold, envDevice, farmId);
-//                        envData.setEnvHum(val);
-//                    }
-//                }
-//                envData.setCreateTime(new Date());
-//                envData.setDeviceId(envDevice.getDeviceCode());
-//                envData.setFarmId(farmId);
-//                envData.setUnitId(envDevice.getUnitId());
-//                envDataService.save(envData);
-//            }
-//        }
-//    }
-//
-//    @Scheduled(cron = "0 0/12 * * * ?")
-//    @Transactional
-//    public void getHuanKongs()  {
-//        Integer farmId = 21;
-//        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
-//
-//        List<BasePigpen> list = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId).eq("f_type", 3).ne("id", 178).ne("id", 181));
-////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
-////        String result = HttpUtil.get(url);
-////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
-////        List<WeatherLives> lives = weatherDto.getLives();
-////        WeatherLives weatherLives = lives.get(0);
-////        int humidity = Integer.parseInt(weatherLives.getHumidity());
-////        int temperature = Integer.parseInt(weatherLives.getTemperature());
-//
-//        for (BasePigpen basePigpen : list) {
-//            EnvData envData = new EnvData();
-//            envData.setCreateTime(new Date());
-//            envData.setFarmId(farmId);
-//            envData.setUnitId(basePigpen.getId());
-//            EnvDevice envDevice = new EnvDevice();
-//            envDevice.setUnitName(basePigpen.getBuildName());
-//            envDevice.setUnitId(basePigpen.getId());
-//            envDevice.setFarmId(farmId);
-//
-//            String tem = NumberUtils.getNum(17, 23, 1);
-//            String hum = NumberUtils.getNum(65, 80, 0);
-//            saveTemWarning(tem, envWarningThreshold, envDevice, farmId);
-//            envData.setEnvTemp(tem);
-//            saveHumWarning(hum, envWarningThreshold, envDevice, farmId);
-//            envData.setEnvHum(hum);
-//            envDataService.save(envData);
-//        }
-//        Integer farmId1 = 23;
-//        EnvWarningThreshold envWarningThreshold1 = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId1));
-//
-//        List<BasePigpen> list1 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId1).eq("f_type", 3).ne("id", 225));
-////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
-////        String result = HttpUtil.get(url);
-////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
-////        List<WeatherLives> lives = weatherDto.getLives();
-////        WeatherLives weatherLives = lives.get(0);
-////        int humidity = Integer.parseInt(weatherLives.getHumidity());
-////        int temperature = Integer.parseInt(weatherLives.getTemperature());
-//
-//        for (BasePigpen basePigpen : list1) {
-//            EnvData envData = new EnvData();
-//            envData.setCreateTime(new Date());
-//            envData.setFarmId(farmId1);
-//            envData.setUnitId(basePigpen.getId());
-//            EnvDevice envDevice = new EnvDevice();
-//            envDevice.setUnitName(basePigpen.getBuildName());
-//            envDevice.setUnitId(basePigpen.getId());
-//            envDevice.setFarmId(farmId1);
-//
-//            String tem = NumberUtils.getNum(17, 23, 1);
-//            String hum = NumberUtils.getNum(65, 80, 0);
-//            saveTemWarning(tem, envWarningThreshold1, envDevice, farmId1);
-//            envData.setEnvTemp(tem);
-//            saveHumWarning(hum, envWarningThreshold1, envDevice, farmId1);
-//            envData.setEnvHum(hum);
-//            envDataService.save(envData);
-//        }
-//        Integer farmId2 = 24;
-//        EnvWarningThreshold envWarningThreshold2 = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId2));
-//
-//        List<BasePigpen> list2 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId2).eq("f_type", 3).ne("id", 217));
-////        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
-////        String result = HttpUtil.get(url);
-////        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
-////        List<WeatherLives> lives = weatherDto.getLives();
-////        WeatherLives weatherLives = lives.get(0);
-////        int humidity = Integer.parseInt(weatherLives.getHumidity());
-////        int temperature = Integer.parseInt(weatherLives.getTemperature());
-//
-//        for (BasePigpen basePigpen : list2) {
-//            EnvData envData = new EnvData();
-//            envData.setCreateTime(new Date());
-//            envData.setFarmId(farmId2);
-//            envData.setUnitId(basePigpen.getId());
-//            EnvDevice envDevice = new EnvDevice();
-//            envDevice.setUnitName(basePigpen.getBuildName());
-//            envDevice.setUnitId(basePigpen.getId());
-//            envDevice.setFarmId(farmId2);
-//
-//            String tem = NumberUtils.getNum(17, 23, 1);
-//            String hum = NumberUtils.getNum(65, 80, 0);
-//            saveTemWarning(tem, envWarningThreshold2, envDevice, farmId2);
-//            envData.setEnvTemp(tem);
-//            saveHumWarning(hum, envWarningThreshold2, envDevice, farmId2);
-//            envData.setEnvHum(hum);
-//            envDataService.save(envData);
-//        }
-//    }
-//
-//    public void saveHumWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
-//        if (StringUtils.isNotBlank(val)) {
-//            String maxHum;
-//            String minHum;
-//            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxHum())) {
-//                maxHum = "90";
-//            } else {
-//                maxHum = envWarningThreshold.getMaxHum();
-//            }
-//            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinHum())) {
-//                minHum = "0";
-//            } else {
-//                minHum = envWarningThreshold.getMinHum();
-//            }
-//            if (Double.parseDouble(maxHum) < Double.parseDouble(val)) {
-//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
-//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
-//                envWarningInfo.setDate(new Date());
-//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
-//                envWarningInfo.setFarmId(envDevice.getFarmId());
-//                envWarningInfo.setUnitId(envDevice.getUnitId());
-//                envWarningInfo.setUnitName(envDevice.getUnitName());
-//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
-//                envWarningInfo.setWarningContent("当前湿度为" + val + "%超过阈值,请及时检查");
-//                envWarningInfo.setWarningType(2);
-//                envWarningInfoService.save(envWarningInfo);
-//            }
-//            if (Double.parseDouble(minHum) > Double.parseDouble(val)) {
-//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
-//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
-//                envWarningInfo.setDate(new Date());
-//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
-//                envWarningInfo.setFarmId(envDevice.getFarmId());
-//                envWarningInfo.setUnitId(envDevice.getUnitId());
-//                envWarningInfo.setUnitName(envDevice.getUnitName());
-//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
-//                envWarningInfo.setWarningContent("当前湿度为" + val + "%低于阈值,请及时检查");
-//                envWarningInfo.setWarningType(2);
-//                envWarningInfoService.save(envWarningInfo);
-//            }
-//        }
-//    }
-//
-//    private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
-//        if (StringUtils.isNotBlank(val)) {
-//            String maxTem;
-//            String minTem;
-//            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxTem())) {
-//                maxTem = "40";
-//            } else {
-//                maxTem = envWarningThreshold.getMaxTem();
-//            }
-//            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinTem())) {
-//                minTem = "0";
-//            } else {
-//                minTem = envWarningThreshold.getMinTem();
-//            }
-//            System.out.println("maxTem:" + Double.parseDouble(maxTem) + "  minTem:" + Double.parseDouble(minTem) + "   val:" + Double.parseDouble(val));
-//            if (Double.parseDouble(maxTem) < Double.parseDouble(val)) {
-//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
-//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
-//                envWarningInfo.setDate(new Date());
-//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
-//                envWarningInfo.setFarmId(envDevice.getFarmId());
-//                envWarningInfo.setUnitId(envDevice.getUnitId());
-//                envWarningInfo.setUnitName(envDevice.getUnitName());
-//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
-//                envWarningInfo.setWarningContent("当前温度为" + val + "°超过阈值,请及时检查");
-//                envWarningInfo.setWarningType(1);
-//                envWarningInfoService.save(envWarningInfo);
-//            }
-//            if (Double.parseDouble(minTem) > Double.parseDouble(val)) {
-//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
-//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
-//                envWarningInfo.setDate(new Date());
-//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
-//                envWarningInfo.setFarmId(envDevice.getFarmId());
-//                envWarningInfo.setUnitId(envDevice.getUnitId());
-//                envWarningInfo.setUnitName(envDevice.getUnitName());
-//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
-//                envWarningInfo.setWarningContent("当前温度为" + val + "°低于阈值,请及时检查");
-//                envWarningInfo.setWarningType(1);
-//                envWarningInfoService.save(envWarningInfo);
-//            }
-//        }
-//    }
-//
-//    private String loginOnly() throws Exception {
-//        Map<String, Object> map = new HashMap<String, Object>();
-//        String s = HttpClientSSLUtils.doPost(baseurl + "/mobile/login?username=" + username + "&password=" + passwordMD5, JSON.toJSONString(map));
-//        LoginOnlyDto loginDto = JSONUtil.toBean(s, LoginOnlyDto.class);
-//        LonginOnlyDtoToken token = loginDto.getData().getToken();
-//        return Base64.encode(token.getUserId() + "_" + token.getToken());
-//    }
-//
-//    @Scheduled(cron = "0 0 0 * * ? ")
-//    public void update() throws Exception {
-//        Date date = new Date();
-//        DateTime beginOfMonth = DateUtil.beginOfMonth(date);
-//        List<Farm> list = farmService.list();
-//        for (Farm farm : list) {
-//            Integer farmId = farm.getId();
-//            QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
-//            queryWrapper.eq("farm_id", farmId);
-//            Integer count = envDeviceService.count(queryWrapper);
-//            QueryWrapper<EnvDevice> queryWrapper1 = new QueryWrapper<>();
-//            queryWrapper1.eq("device_status", 0);
-//            Integer count1 = envDeviceService.count(queryWrapper1);//离线
-//            Integer OnDeviceCount = count - count1;//在线
-//            //创建一个数值格式化对象
-//            NumberFormat numberFormat = NumberFormat.getInstance();
-//            //设置精确到小数点后两位
-//            numberFormat.setMaximumFractionDigits(2);
-//            String onDeviceRate = numberFormat.format((float) OnDeviceCount / (float) count * 100);
-//
-//            EnvDeviceOnline envDeviceOnline = envDeviceOnlineService.getOne(new QueryWrapper<EnvDeviceOnline>().eq("farm_id", farmId).ge("creat_time", beginOfMonth));
-//            if (ObjectUtil.isEmpty(envDeviceOnline)) {
-//                envDeviceOnline = new EnvDeviceOnline();
-//                envDeviceOnline.setCreatTime(date);
-//                envDeviceOnline.setDeviceOff(count1);
-//                envDeviceOnline.setDeviceOn(OnDeviceCount);
-//                envDeviceOnline.setFarmId(farmId + "");
-//                envDeviceOnline.setOnlineRate(onDeviceRate);
-//                envDeviceOnline.setNowMonth(beginOfMonth.month());
-//                envDeviceOnline.setNowYear(beginOfMonth.year());
-//                envDeviceOnlineService.save(envDeviceOnline);
-//            } else {
-//                envDeviceOnline = new EnvDeviceOnline();
-//                envDeviceOnline.setCreatTime(date);
-//                envDeviceOnline.setDeviceOff(count1);
-//                envDeviceOnline.setDeviceOn(OnDeviceCount);
-//                envDeviceOnline.setFarmId(farmId + "");
-//                envDeviceOnline.setOnlineRate(onDeviceRate);
-//                envDeviceOnline.setNowMonth(beginOfMonth.month());
-//                envDeviceOnline.setNowYear(beginOfMonth.year());
-//                envDeviceOnlineService.updateById(envDeviceOnline);
-//            }
-//
-//        }
-//
-//    }
-//
-//}
+package com.huimv.admin.timer;
+
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.huimv.admin.common.utils.HttpClientSSLUtils;
+import com.huimv.admin.common.utils.NumberUtils;
+import com.huimv.admin.entity.*;
+import com.huimv.admin.entity.dto.WeatherDto;
+import com.huimv.admin.entity.dto.WeatherLives;
+import com.huimv.admin.entity.zengxindto.*;
+import com.huimv.admin.service.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
+
+import javax.servlet.http.HttpServletRequest;
+import java.text.NumberFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Configuration
+@EnableScheduling
+public class EnvTimer {
+
+    @Autowired
+    private RestTemplate restTemplate;
+    @Autowired
+    private IEnvDeviceService envDeviceService;
+    @Autowired
+    private IEnvDeviceOnlineService envDeviceOnlineService;
+    @Autowired
+    private IFarmService farmService;
+
+    @Autowired
+    private IBasePigpenService basePigpenService;
+
+    @Autowired
+    private IEnvDataService envDataService;
+    @Autowired
+    private IEnvWarningThresholdService envWarningThresholdService;
+
+    @Autowired
+    private IEnvWarningInfoService envWarningInfoService;
+    //环控数据
+    String username = "华统";
+    String password = "888888";
+    String passwordMD5 = "21218cca77804d2ba1922c33e0151105";
+    String baseurl = "https://yzwlw.loongk.com/";
+
+    @Scheduled(cron = "0 0/11 * * * ? ")
+//    @Scheduled(cron = "0 * * * * ? ")
+    @Transactional
+    public void getHuanKong() throws Exception {
+        //目前是这家
+        Integer farmId = 21;
+        String encode = loginOnly();
+//        System.out.println("encode" + encode);
+        //获取阈值
+        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Authorization", encode);
+        HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
+        //TODO 只有一家,先拿全部
+        List<EnvDevice> list = envDeviceService.list();
+        for (EnvDevice envDevice : list) {
+            if (ObjectUtil.isNotEmpty(envDevice) && StringUtils.isNotBlank(envDevice.getDeviceCode())) {
+                System.out.println(envDevice.getDeviceCode());
+                String shishiBody = "";
+                try {
+                    ResponseEntity<String> exchange = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackDatas/" + envDevice.getDeviceCode(), HttpMethod.GET, requestEntity, String.class);
+                    shishiBody = exchange.getBody();
+                } catch (Exception e) {
+                    System.out.println(e);
+                }
+
+                if (StringUtils.isBlank(shishiBody)) {
+                    System.out.println(new Date() + "实时数据" + shishiBody);
+                    continue;
+                }
+                ShackDatasDto shackDatasDto = JSONUtil.toBean(shishiBody, ShackDatasDto.class);
+
+                ShackDatasDataDto data = shackDatasDto.getData();
+                if (ObjectUtil.isEmpty(data)){
+                    continue;
+                }
+                String onLine = shackDatasDto.getData().getOnLine();
+                if ("N".equals(onLine)) {
+                    envDevice.setDeviceStatus(0);
+                } else {
+                    envDevice.setDeviceStatus(1);
+                }
+                envDeviceService.updateById(envDevice);
+                List<ShackDatasSensor> sensorDatas = shackDatasDto.getData().getSensorDatas();
+                EnvData envData = new EnvData();
+                for (ShackDatasSensor sensorData : sensorDatas) {
+                    if (sensorData.getId().equals(envDevice.getOhter1())) {
+                        String val = sensorData.getVal();
+                        //TODO 预警
+                        saveTemWarning(val, envWarningThreshold, envDevice, farmId);
+                        envData.setEnvTemp(val);
+                    }
+                    if (sensorData.getId().equals(envDevice.getOhter2())) {
+                        String val = sensorData.getVal();
+                        //TODO 预警
+                        saveHumWarning(val, envWarningThreshold, envDevice, farmId);
+                        envData.setEnvHum(val);
+                    }
+                }
+                envData.setCreateTime(new Date());
+                envData.setDeviceId(envDevice.getDeviceCode());
+                envData.setFarmId(farmId);
+                envData.setUnitId(envDevice.getUnitId());
+                envDataService.save(envData);
+            }
+        }
+    }
+
+    @Scheduled(cron = "0 0/12 * * * ?")
+    @Transactional
+    public void getHuanKongs()  {
+        Integer farmId = 21;
+        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
+
+        List<BasePigpen> list = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId).eq("f_type", 3).ne("id", 178).ne("id", 181));
+//        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
+//        String result = HttpUtil.get(url);
+//        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
+//        List<WeatherLives> lives = weatherDto.getLives();
+//        WeatherLives weatherLives = lives.get(0);
+//        int humidity = Integer.parseInt(weatherLives.getHumidity());
+//        int temperature = Integer.parseInt(weatherLives.getTemperature());
+
+        for (BasePigpen basePigpen : list) {
+            EnvData envData = new EnvData();
+            envData.setCreateTime(new Date());
+            envData.setFarmId(farmId);
+            envData.setUnitId(basePigpen.getId());
+            EnvDevice envDevice = new EnvDevice();
+            envDevice.setUnitName(basePigpen.getBuildName());
+            envDevice.setUnitId(basePigpen.getId());
+            envDevice.setFarmId(farmId);
+
+            String tem = NumberUtils.getNum(17, 23, 1);
+            String hum = NumberUtils.getNum(65, 80, 0);
+            saveTemWarning(tem, envWarningThreshold, envDevice, farmId);
+            envData.setEnvTemp(tem);
+            saveHumWarning(hum, envWarningThreshold, envDevice, farmId);
+            envData.setEnvHum(hum);
+            envDataService.save(envData);
+        }
+        Integer farmId1 = 23;
+        EnvWarningThreshold envWarningThreshold1 = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId1));
+
+        List<BasePigpen> list1 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId1).eq("f_type", 3).ne("id", 225));
+//        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
+//        String result = HttpUtil.get(url);
+//        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
+//        List<WeatherLives> lives = weatherDto.getLives();
+//        WeatherLives weatherLives = lives.get(0);
+//        int humidity = Integer.parseInt(weatherLives.getHumidity());
+//        int temperature = Integer.parseInt(weatherLives.getTemperature());
+
+        for (BasePigpen basePigpen : list1) {
+            EnvData envData = new EnvData();
+            envData.setCreateTime(new Date());
+            envData.setFarmId(farmId1);
+            envData.setUnitId(basePigpen.getId());
+            EnvDevice envDevice = new EnvDevice();
+            envDevice.setUnitName(basePigpen.getBuildName());
+            envDevice.setUnitId(basePigpen.getId());
+            envDevice.setFarmId(farmId1);
+
+            String tem = NumberUtils.getNum(17, 23, 1);
+            String hum = NumberUtils.getNum(65, 80, 0);
+            saveTemWarning(tem, envWarningThreshold1, envDevice, farmId1);
+            envData.setEnvTemp(tem);
+            saveHumWarning(hum, envWarningThreshold1, envDevice, farmId1);
+            envData.setEnvHum(hum);
+            envDataService.save(envData);
+        }
+        Integer farmId2 = 24;
+        EnvWarningThreshold envWarningThreshold2 = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId2));
+
+        List<BasePigpen> list2 = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId2).eq("f_type", 3).ne("id", 217));
+//        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
+//        String result = HttpUtil.get(url);
+//        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
+//        List<WeatherLives> lives = weatherDto.getLives();
+//        WeatherLives weatherLives = lives.get(0);
+//        int humidity = Integer.parseInt(weatherLives.getHumidity());
+//        int temperature = Integer.parseInt(weatherLives.getTemperature());
+
+        for (BasePigpen basePigpen : list2) {
+            EnvData envData = new EnvData();
+            envData.setCreateTime(new Date());
+            envData.setFarmId(farmId2);
+            envData.setUnitId(basePigpen.getId());
+            EnvDevice envDevice = new EnvDevice();
+            envDevice.setUnitName(basePigpen.getBuildName());
+            envDevice.setUnitId(basePigpen.getId());
+            envDevice.setFarmId(farmId2);
+
+            String tem = NumberUtils.getNum(17, 23, 1);
+            String hum = NumberUtils.getNum(65, 80, 0);
+            saveTemWarning(tem, envWarningThreshold2, envDevice, farmId2);
+            envData.setEnvTemp(tem);
+            saveHumWarning(hum, envWarningThreshold2, envDevice, farmId2);
+            envData.setEnvHum(hum);
+            envDataService.save(envData);
+        }
+    }
+
+    public void saveHumWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
+        if (StringUtils.isNotBlank(val)) {
+            String maxHum;
+            String minHum;
+            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxHum())) {
+                maxHum = "90";
+            } else {
+                maxHum = envWarningThreshold.getMaxHum();
+            }
+            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinHum())) {
+                minHum = "0";
+            } else {
+                minHum = envWarningThreshold.getMinHum();
+            }
+            if (Double.parseDouble(maxHum) < Double.parseDouble(val)) {
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(envDevice.getFarmId());
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前湿度为" + val + "%超过阈值,请及时检查");
+                envWarningInfo.setWarningType(2);
+                envWarningInfoService.save(envWarningInfo);
+            }
+            if (Double.parseDouble(minHum) > Double.parseDouble(val)) {
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(envDevice.getFarmId());
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前湿度为" + val + "%低于阈值,请及时检查");
+                envWarningInfo.setWarningType(2);
+                envWarningInfoService.save(envWarningInfo);
+            }
+        }
+    }
+
+    private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
+        if (StringUtils.isNotBlank(val)) {
+            String maxTem;
+            String minTem;
+            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxTem())) {
+                maxTem = "40";
+            } else {
+                maxTem = envWarningThreshold.getMaxTem();
+            }
+            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinTem())) {
+                minTem = "0";
+            } else {
+                minTem = envWarningThreshold.getMinTem();
+            }
+            System.out.println("maxTem:" + Double.parseDouble(maxTem) + "  minTem:" + Double.parseDouble(minTem) + "   val:" + Double.parseDouble(val));
+            if (Double.parseDouble(maxTem) < Double.parseDouble(val)) {
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(envDevice.getFarmId());
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前温度为" + val + "°超过阈值,请及时检查");
+                envWarningInfo.setWarningType(1);
+                envWarningInfoService.save(envWarningInfo);
+            }
+            if (Double.parseDouble(minTem) > Double.parseDouble(val)) {
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(envDevice.getFarmId());
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前温度为" + val + "°低于阈值,请及时检查");
+                envWarningInfo.setWarningType(1);
+                envWarningInfoService.save(envWarningInfo);
+            }
+        }
+    }
+
+    private String loginOnly() throws Exception {
+        Map<String, Object> map = new HashMap<String, Object>();
+        String s = HttpClientSSLUtils.doPost(baseurl + "/mobile/login?username=" + username + "&password=" + passwordMD5, JSON.toJSONString(map));
+        LoginOnlyDto loginDto = JSONUtil.toBean(s, LoginOnlyDto.class);
+        LonginOnlyDtoToken token = loginDto.getData().getToken();
+        return Base64.encode(token.getUserId() + "_" + token.getToken());
+    }
+
+    @Scheduled(cron = "0 0 0 * * ? ")
+    public void update() throws Exception {
+        Date date = new Date();
+        DateTime beginOfMonth = DateUtil.beginOfMonth(date);
+        List<Farm> list = farmService.list();
+        for (Farm farm : list) {
+            Integer farmId = farm.getId();
+            QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("farm_id", farmId);
+            Integer count = envDeviceService.count(queryWrapper);
+            QueryWrapper<EnvDevice> queryWrapper1 = new QueryWrapper<>();
+            queryWrapper1.eq("device_status", 0);
+            Integer count1 = envDeviceService.count(queryWrapper1);//离线
+            Integer OnDeviceCount = count - count1;//在线
+            //创建一个数值格式化对象
+            NumberFormat numberFormat = NumberFormat.getInstance();
+            //设置精确到小数点后两位
+            numberFormat.setMaximumFractionDigits(2);
+            String onDeviceRate = numberFormat.format((float) OnDeviceCount / (float) count * 100);
+
+            EnvDeviceOnline envDeviceOnline = envDeviceOnlineService.getOne(new QueryWrapper<EnvDeviceOnline>().eq("farm_id", farmId).ge("creat_time", beginOfMonth));
+            if (ObjectUtil.isEmpty(envDeviceOnline)) {
+                envDeviceOnline = new EnvDeviceOnline();
+                envDeviceOnline.setCreatTime(date);
+                envDeviceOnline.setDeviceOff(count1);
+                envDeviceOnline.setDeviceOn(OnDeviceCount);
+                envDeviceOnline.setFarmId(farmId + "");
+                envDeviceOnline.setOnlineRate(onDeviceRate);
+                envDeviceOnline.setNowMonth(beginOfMonth.month());
+                envDeviceOnline.setNowYear(beginOfMonth.year());
+                envDeviceOnlineService.save(envDeviceOnline);
+            } else {
+                envDeviceOnline = new EnvDeviceOnline();
+                envDeviceOnline.setCreatTime(date);
+                envDeviceOnline.setDeviceOff(count1);
+                envDeviceOnline.setDeviceOn(OnDeviceCount);
+                envDeviceOnline.setFarmId(farmId + "");
+                envDeviceOnline.setOnlineRate(onDeviceRate);
+                envDeviceOnline.setNowMonth(beginOfMonth.month());
+                envDeviceOnline.setNowYear(beginOfMonth.year());
+                envDeviceOnlineService.updateById(envDeviceOnline);
+            }
+
+        }
+
+    }
+
+}

+ 448 - 448
huimv-admin/src/main/java/com/huimv/admin/timer/GasTimer.java

@@ -1,448 +1,448 @@
-//package com.huimv.admin.timer;
-//
-//
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.huimv.admin.common.utils.NumberUtils;
-//import com.huimv.admin.entity.GasData;
-//import com.huimv.admin.entity.GasThreshold;
-//import com.huimv.admin.entity.GasWarningInfo;
-//import com.huimv.admin.mapper.GasDataMapper;
-//import com.huimv.admin.mapper.GasThresholdMapper;
-//import com.huimv.admin.mapper.GasWarningInfoMapper;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//
-//import java.util.Date;
-//
-//@Configuration
-//@EnableScheduling
-//public class  GasTimer {
-//
-//    @Autowired
-//    private GasDataMapper gasDataMapper;
-//    @Autowired
-//    private GasWarningInfoMapper warningInfoMapper;
-//    @Autowired
-//    private GasThresholdMapper thresholdMapper;
-//
-//    @Scheduled(cron = "0 0 */1 * * ? ")
-//    private void getShenChan() throws Exception {
-//
-//        String type = NumberUtils.getNum(1, 5, 0);//loc_type
-//        for (int i = 1; i < 13; i++) {
-//
-//            String nh3n = NumberUtils.getNumFloat(0.0, 10.5);//NH3N
-//            String jlm = NumberUtils.getNumFloat(0.0, 10.5);//jlm
-//            String elht = NumberUtils.getNumFloat(0.0, 10.5);//elht
-//            String ejel = NumberUtils.getNumFloat(0.0, 10.5);//ejel
-//            String h2s = NumberUtils.getNumFloat(0.0, 10.5);//h2s
-//            String byx = NumberUtils.getNumFloat(0.0, 20.5);//byx
-//            String ch3 = NumberUtils.getNumFloat(0.0, 10.5);//ch3
-//            String sja = NumberUtils.getNumFloat(0.0,10.5);//sja
-//
-//
-//            GasData gasData = new GasData();
-//            gasData.setNh3N(nh3n);
-//            gasData.setJlm(jlm);
-//            gasData.setElht(elht);
-//            gasData.setEjel(ejel);
-//            gasData.setH2s(h2s);
-//            gasData.setByx(byx);
-//            gasData.setCh3sh(ch3);
-//            gasData.setSja(sja);
-//            if (i > 8) {
-//                gasData.setLoctionType(i - 8);//浦江
-//                gasData.setFarmId(23);
-//            } else if (i > 4) {
-//                gasData.setLoctionType(i - 4);//东阳
-//                gasData.setFarmId(24);
-//            } else {
-//                gasData.setLoctionType(i);
-//                gasData.setFarmId(21);
-//            }
-//            gasData.setCreateTime(new Date());
-//
-//
-//            QueryWrapper<GasThreshold> queryWrapper = new QueryWrapper<>();
-//            GasWarningInfo warningInfo = new GasWarningInfo();
-//            if (i==1||i==5||i==9) {
-//                String cq = NumberUtils.getNumFloat(0.0, 1000.5);//cq
-//                gasData.setCq(cq);
-//                if (i == 1) {
-//                    queryWrapper.eq("farm_id", 21).eq("gas_type", 1);
-//                } else if (i == 5) {
-//                    queryWrapper.eq("farm_id", 24).eq("gas_type", 1);
-//                } else {
-//                    queryWrapper.eq("farm_id", 23).eq("gas_type", 1);
-//                }
-//                GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
-//                if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
-//                    warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(0);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
-//                    warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(1);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
-//                    warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(2);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
-//                    warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(3);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
-//                    warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(4);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
-//                    warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(5);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
-//                    warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(6);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
-//                    warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(7);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
-//                    warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(8);
-//                    warningInfo.setBuildLocation("屋顶");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//
-//            } else if (i==2||i==6||i==10) {
-//                String cq = NumberUtils.getNumFloat(0.0, 5000.5);//cq
-//                gasData.setCq(cq);
-//                if (i == 2) {
-//                    queryWrapper.eq("farm_id", 21).eq("gas_type", 2);
-//                } else if (i == 6) {
-//                    queryWrapper.eq("farm_id", 24).eq("gas_type", 2);
-//                } else {
-//                    queryWrapper.eq("farm_id", 23).eq("gas_type", 2);
-//                }
-//                GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
-//                if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
-//                    warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(0);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
-//                    warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(1);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
-//                    warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(2);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
-//                    warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(3);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
-//                    warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(4);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//
-//                }
-//                if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
-//                    warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(5);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
-//                    warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(6);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
-//                    warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(7);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
-//                    warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(8);
-//                    warningInfo.setBuildLocation("厂界上");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//
-//            } else if (i==3||i==7||i==11) {
-//                String cq = NumberUtils.getNumFloat(0.0, 1000.5);//cq
-//                gasData.setCq(cq);
-//                if (i == 3) {
-//                    queryWrapper.eq("farm_id", 21).eq("gas_type", 3);
-//                } else if (i == 7) {
-//                    queryWrapper.eq("farm_id", 24).eq("gas_type", 3);
-//                } else {
-//                    queryWrapper.eq("farm_id", 23).eq("gas_type", 3);
-//                }
-//                GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
-//                if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
-//                    warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(0);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
-//                    warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(1);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
-//                    warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(2);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
-//                    warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(3);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
-//                    warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(4);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//
-//                }
-//                if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
-//                    warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(5);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
-//                    warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(6);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
-//                    warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(7);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
-//                    warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(8);
-//                    warningInfo.setBuildLocation("厂界下");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//
-//            } else if (i==4||i==8||i==12) {
-//                String cq = NumberUtils.getNumFloat(0.0, 10000.5);//cq
-//                gasData.setCq(cq);
-//                if (i == 4) {
-//                    queryWrapper.eq("farm_id", 21).eq("gas_type", 4);
-//                } else if (i == 8) {
-//                    queryWrapper.eq("farm_id", 24).eq("gas_type", 4);
-//                } else {
-//                    queryWrapper.eq("farm_id", 23).eq("gas_type", 4);
-//                }
-//                GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
-//                if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
-//                    warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(0);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
-//                    warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(1);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
-//                    warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(2);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
-//                    warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(3);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
-//                    warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(4);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
-//                    warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(5);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
-//                    warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(6);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
-//                    warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(7);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//                if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
-//                    warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
-//                    warningInfo.setWarningType(8);
-//                    warningInfo.setBuildLocation("厂界居民");
-//                    warningInfo.setDate(new Date());
-//                    warningInfo.setFarmId(gasThreshold.getFarmId());
-//                    warningInfo.setUserIds(gasThreshold.getUserIds());
-//                    warningInfoMapper.insert(warningInfo);
-//                }
-//
-//            }
-//            gasDataMapper.insert(gasData);
-//        }
-//    }
-//}
+package com.huimv.admin.timer;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.common.utils.NumberUtils;
+import com.huimv.admin.entity.GasData;
+import com.huimv.admin.entity.GasThreshold;
+import com.huimv.admin.entity.GasWarningInfo;
+import com.huimv.admin.mapper.GasDataMapper;
+import com.huimv.admin.mapper.GasThresholdMapper;
+import com.huimv.admin.mapper.GasWarningInfoMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.util.Date;
+
+@Configuration
+@EnableScheduling
+public class  GasTimer {
+
+    @Autowired
+    private GasDataMapper gasDataMapper;
+    @Autowired
+    private GasWarningInfoMapper warningInfoMapper;
+    @Autowired
+    private GasThresholdMapper thresholdMapper;
+
+    @Scheduled(cron = "0 0 */1 * * ? ")
+    private void getShenChan() throws Exception {
+
+        String type = NumberUtils.getNum(1, 5, 0);//loc_type
+        for (int i = 1; i < 13; i++) {
+
+            String nh3n = NumberUtils.getNumFloat(0.0, 10.5);//NH3N
+            String jlm = NumberUtils.getNumFloat(0.0, 10.5);//jlm
+            String elht = NumberUtils.getNumFloat(0.0, 10.5);//elht
+            String ejel = NumberUtils.getNumFloat(0.0, 10.5);//ejel
+            String h2s = NumberUtils.getNumFloat(0.0, 10.5);//h2s
+            String byx = NumberUtils.getNumFloat(0.0, 20.5);//byx
+            String ch3 = NumberUtils.getNumFloat(0.0, 10.5);//ch3
+            String sja = NumberUtils.getNumFloat(0.0,10.5);//sja
+
+
+            GasData gasData = new GasData();
+            gasData.setNh3N(nh3n);
+            gasData.setJlm(jlm);
+            gasData.setElht(elht);
+            gasData.setEjel(ejel);
+            gasData.setH2s(h2s);
+            gasData.setByx(byx);
+            gasData.setCh3sh(ch3);
+            gasData.setSja(sja);
+            if (i > 8) {
+                gasData.setLoctionType(i - 8);//浦江
+                gasData.setFarmId(23);
+            } else if (i > 4) {
+                gasData.setLoctionType(i - 4);//东阳
+                gasData.setFarmId(24);
+            } else {
+                gasData.setLoctionType(i);
+                gasData.setFarmId(21);
+            }
+            gasData.setCreateTime(new Date());
+
+
+            QueryWrapper<GasThreshold> queryWrapper = new QueryWrapper<>();
+            GasWarningInfo warningInfo = new GasWarningInfo();
+            if (i==1||i==5||i==9) {
+                String cq = NumberUtils.getNumFloat(0.0, 1000.5);//cq
+                gasData.setCq(cq);
+                if (i == 1) {
+                    queryWrapper.eq("farm_id", 21).eq("gas_type", 1);
+                } else if (i == 5) {
+                    queryWrapper.eq("farm_id", 24).eq("gas_type", 1);
+                } else {
+                    queryWrapper.eq("farm_id", 23).eq("gas_type", 1);
+                }
+                GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
+                if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
+                    warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(0);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
+                    warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(1);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
+                    warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(2);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
+                    warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(3);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
+                    warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(4);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
+                    warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(5);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
+                    warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(6);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
+                    warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(7);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
+                    warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(8);
+                    warningInfo.setBuildLocation("屋顶");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+
+            } else if (i==2||i==6||i==10) {
+                String cq = NumberUtils.getNumFloat(0.0, 5000.5);//cq
+                gasData.setCq(cq);
+                if (i == 2) {
+                    queryWrapper.eq("farm_id", 21).eq("gas_type", 2);
+                } else if (i == 6) {
+                    queryWrapper.eq("farm_id", 24).eq("gas_type", 2);
+                } else {
+                    queryWrapper.eq("farm_id", 23).eq("gas_type", 2);
+                }
+                GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
+                if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
+                    warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(0);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
+                    warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(1);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
+                    warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(2);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
+                    warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(3);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
+                    warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(4);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+
+                }
+                if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
+                    warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(5);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
+                    warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(6);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
+                    warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(7);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
+                    warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(8);
+                    warningInfo.setBuildLocation("厂界上");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+
+            } else if (i==3||i==7||i==11) {
+                String cq = NumberUtils.getNumFloat(0.0, 1000.5);//cq
+                gasData.setCq(cq);
+                if (i == 3) {
+                    queryWrapper.eq("farm_id", 21).eq("gas_type", 3);
+                } else if (i == 7) {
+                    queryWrapper.eq("farm_id", 24).eq("gas_type", 3);
+                } else {
+                    queryWrapper.eq("farm_id", 23).eq("gas_type", 3);
+                }
+                GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
+                if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
+                    warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(0);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
+                    warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(1);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
+                    warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(2);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
+                    warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(3);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
+                    warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(4);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+
+                }
+                if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
+                    warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(5);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
+                    warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(6);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
+                    warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(7);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
+                    warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(8);
+                    warningInfo.setBuildLocation("厂界下");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+
+            } else if (i==4||i==8||i==12) {
+                String cq = NumberUtils.getNumFloat(0.0, 10000.5);//cq
+                gasData.setCq(cq);
+                if (i == 4) {
+                    queryWrapper.eq("farm_id", 21).eq("gas_type", 4);
+                } else if (i == 8) {
+                    queryWrapper.eq("farm_id", 24).eq("gas_type", 4);
+                } else {
+                    queryWrapper.eq("farm_id", 23).eq("gas_type", 4);
+                }
+                GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
+                if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
+                    warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(0);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
+                    warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(1);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
+                    warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(2);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
+                    warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(3);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
+                    warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(4);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
+                    warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(5);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
+                    warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(6);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
+                    warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(7);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+                if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
+                    warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
+                    warningInfo.setWarningType(8);
+                    warningInfo.setBuildLocation("厂界居民");
+                    warningInfo.setDate(new Date());
+                    warningInfo.setFarmId(gasThreshold.getFarmId());
+                    warningInfo.setUserIds(gasThreshold.getUserIds());
+                    warningInfoMapper.insert(warningInfo);
+                }
+
+            }
+            gasDataMapper.insert(gasData);
+        }
+    }
+}

ファイルの差分が大きいため隠しています
+ 529 - 529
huimv-admin/src/main/java/com/huimv/admin/timer/ProtTimer.java


+ 190 - 190
huimv-admin/src/main/java/com/huimv/admin/timer/ShenChanTimer.java

@@ -1,198 +1,198 @@
-//package com.huimv.admin.timer;
-//
-//
-//import cn.hutool.core.codec.Base64;
-//import cn.hutool.core.date.DateTime;
-//import cn.hutool.core.date.DateUtil;
-//import cn.hutool.core.util.ObjectUtil;
-//import cn.hutool.json.JSONObject;
-//import cn.hutool.json.JSONUtil;
-//import com.alibaba.fastjson.JSON;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-//import com.huimv.admin.common.utils.Digests;
-//import com.huimv.admin.common.utils.HttpClientSSLUtils;
-//import com.huimv.admin.entity.*;
-//import com.huimv.admin.entity.zengxindto.*;
-//import com.huimv.admin.service.*;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.http.*;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.transaction.annotation.Transactional;
-//import org.springframework.web.bind.annotation.GetMapping;
-//import org.springframework.web.client.RestTemplate;
-//
-//import java.time.LocalDate;
-//import java.util.*;
-//
-//@Configuration
-//@EnableScheduling
-//public class ShenChanTimer {
-//
-//    //生产数据
-//    @Autowired
-//    private RestTemplate restTemplate;
-//    @Autowired
-//    private IProdStockService prodStockService;
-//
-//
-//    @Scheduled(cron = "0 0 */4 * * ? ")
-////    @Scheduled(cron = "0 * * * * ?")
-//    @GetMapping("/test")
-//    private void getShenChan() throws Exception {
-//        Integer farmId = 21;
-//        List<Integer> farmIds = new ArrayList();
-//        farmIds.add(21);
-//        farmIds.add(23);
-//        farmIds.add(24);
-//        String time = LocalDate.now().toString();
-//        String token = login();
-////        System.out.println("token"+token);
-//        DateTime dateTime = DateUtil.beginOfDay(new Date());
-//        System.out.println(token);
-//
-//        String url = "http://test.htpig.cn/rest/db/storedproc";
-//        Map<String, Object> map = new HashMap<String, Object>();
-//        map.put("db_name","MSSQL");
-//        map.put("proc_name","rep_yz_kc_hz");
-//        map.put("method","open_proc");
-//        HashMap<String, Object> maps = new HashMap<>();
-//        List list = new ArrayList();
-//        maps.put("name","@fdate");
-//        maps.put("value",time);
-//        list.add(maps);
-//
-//        map.put("params",list);
-//        String params = JSON.toJSONString(map);
-//        System.out.println(" ====== getStock请求参数:【" + params + "】");
-//        String data = HttpClientSSLUtils.doPost(url+"?token="+token+"&data=", params);
-//        ProdStockDto prodStockDto = JSONUtil.toBean(data, ProdStockDto.class);
-//        List<List<Object>> stockData = prodStockDto.getData();
-//        System.out.println(prodStockDto.toString());
-//        for (Integer id : farmIds) {
-//            ProdStock prodStock = prodStockService.getOne(new QueryWrapper<ProdStock>().ge("creat_time",dateTime).eq("farm_id", id).orderByDesc("creat_time").last("limit 1"));
-//
-//            for (List stock : stockData) {
-//                if ("正康".equals(stock.get(0))){
-//                    if (ObjectUtil.isNotEmpty(prodStock)){
+package com.huimv.admin.timer;
+
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.huimv.admin.common.utils.Digests;
+import com.huimv.admin.common.utils.HttpClientSSLUtils;
+import com.huimv.admin.entity.*;
+import com.huimv.admin.entity.zengxindto.*;
+import com.huimv.admin.service.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.*;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.client.RestTemplate;
+
+import java.time.LocalDate;
+import java.util.*;
+
+@Configuration
+@EnableScheduling
+public class ShenChanTimer {
+
+    //生产数据
+    @Autowired
+    private RestTemplate restTemplate;
+    @Autowired
+    private IProdStockService prodStockService;
+
+
+    @Scheduled(cron = "0 0 */4 * * ? ")
+//    @Scheduled(cron = "0 * * * * ?")
+    @GetMapping("/test")
+    private void getShenChan() throws Exception {
+        Integer farmId = 21;
+        List<Integer> farmIds = new ArrayList();
+        farmIds.add(21);
+        farmIds.add(23);
+        farmIds.add(24);
+        String time = LocalDate.now().toString();
+        String token = login();
+//        System.out.println("token"+token);
+        DateTime dateTime = DateUtil.beginOfDay(new Date());
+        System.out.println(token);
+
+        String url = "http://test.htpig.cn/rest/db/storedproc";
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("db_name","MSSQL");
+        map.put("proc_name","rep_yz_kc_hz");
+        map.put("method","open_proc");
+        HashMap<String, Object> maps = new HashMap<>();
+        List list = new ArrayList();
+        maps.put("name","@fdate");
+        maps.put("value",time);
+        list.add(maps);
+
+        map.put("params",list);
+        String params = JSON.toJSONString(map);
+        System.out.println(" ====== getStock请求参数:【" + params + "】");
+        String data = HttpClientSSLUtils.doPost(url+"?token="+token+"&data=", params);
+        ProdStockDto prodStockDto = JSONUtil.toBean(data, ProdStockDto.class);
+        List<List<Object>> stockData = prodStockDto.getData();
+        System.out.println(prodStockDto.toString());
+        for (Integer id : farmIds) {
+            ProdStock prodStock = prodStockService.getOne(new QueryWrapper<ProdStock>().ge("creat_time",dateTime).eq("farm_id", id).orderByDesc("creat_time").last("limit 1"));
+
+            for (List stock : stockData) {
+                if ("正康".equals(stock.get(0))){
+                    if (ObjectUtil.isNotEmpty(prodStock)){
+                        prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
+                        prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
+                        prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
+                        prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
+                        prodStock.setCreatTime(new Date());
+                        prodStock.setFarmId(21);
+                        prodStockService.updateById(prodStock);
+                    }else {
+                        prodStock = new ProdStock();
+                        prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
+                        prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
+                        prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
+                        prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
+                        prodStock.setMzcl(100);
+                        prodStock.setGzcl(200);
+                        prodStock.setBrzcl(452);
+                        prodStock.setHbzcl(100);
+                        prodStock.setRszcl(30);
+                        prodStock.setBrmzcl(20);
+                        prodStock.setKhzcl(212);
+                        prodStock.setSpzcl(1020);
+                        prodStock.setCreatTime(new Date());
+                        prodStock.setFarmId(21);
+                        prodStockService.save(prodStock);
+                    }
+
+                }
+
+                if ("东阳".equals(stock.get(0))){
+                    if (ObjectUtil.isNotEmpty(prodStock)){
+//                    prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
+                        prodStock.setZzcl(5433);
+//                    prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
+                        prodStock.setByzcl(6760);
+//                    prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
+                        prodStock.setYfzcl(4361);
+//                    prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
+                        prodStock.setZcl(16554);
+                        prodStock.setCreatTime(new Date());
+                        prodStock.setFarmId(24);
+                        prodStockService.updateById(prodStock);
+                        System.out.println("东阳--》");
+                    }else {
+                        prodStock = new ProdStock();
+                        //                    prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
+                        prodStock.setZzcl(5433);
+//                    prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
+                        prodStock.setByzcl(6760);
+//                    prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
+                        prodStock.setYfzcl(4361);
+//                    prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
+                        prodStock.setZcl(16554);
+                        prodStock.setMzcl(100);
+                        prodStock.setGzcl(200);
+                        prodStock.setBrzcl(452);
+                        prodStock.setHbzcl(100);
+                        prodStock.setRszcl(30);
+                        prodStock.setBrmzcl(20);
+                        prodStock.setKhzcl(212);
+                        prodStock.setSpzcl(1020);
+                        prodStock.setCreatTime(new Date());
+                        prodStock.setFarmId(24);
+                        prodStockService.save(prodStock);
+                        System.out.println("东阳");
+                    }
+                }
+                if ("浦江".equals(stock.get(0))){
+                    if (ObjectUtil.isNotEmpty(prodStock)){
 //                        prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
+                        prodStock.setZzcl(9980);
 //                        prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
+                        prodStock.setByzcl(16384);
 //                        prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
+                        prodStock.setYfzcl(32999);
 //                        prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
-//                        prodStock.setCreatTime(new Date());
-//                        prodStock.setFarmId(21);
-//                        prodStockService.updateById(prodStock);
-//                    }else {
-//                        prodStock = new ProdStock();
+                        prodStock.setZcl(66381);
+                        prodStock.setCreatTime(new Date());
+                        prodStock.setFarmId(23);
+                        prodStockService.updateById(prodStock);
+                        System.out.println("浦江--》");
+                    }else {
+                        prodStock = new ProdStock();
 //                        prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
+                        prodStock.setZzcl(9980);
 //                        prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
+                        prodStock.setByzcl(16384);
 //                        prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
+                        prodStock.setYfzcl(32999);
 //                        prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
-//                        prodStock.setMzcl(100);
-//                        prodStock.setGzcl(200);
-//                        prodStock.setBrzcl(452);
-//                        prodStock.setHbzcl(100);
-//                        prodStock.setRszcl(30);
-//                        prodStock.setBrmzcl(20);
-//                        prodStock.setKhzcl(212);
-//                        prodStock.setSpzcl(1020);
-//                        prodStock.setCreatTime(new Date());
-//                        prodStock.setFarmId(21);
-//                        prodStockService.save(prodStock);
-//                    }
-//
-//                }
-//
-//                if ("东阳".equals(stock.get(0))){
-//                    if (ObjectUtil.isNotEmpty(prodStock)){
-////                    prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
-//                        prodStock.setZzcl(5433);
-////                    prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
-//                        prodStock.setByzcl(6760);
-////                    prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
-//                        prodStock.setYfzcl(4361);
-////                    prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
-//                        prodStock.setZcl(16554);
-//                        prodStock.setCreatTime(new Date());
-//                        prodStock.setFarmId(24);
-//                        prodStockService.updateById(prodStock);
-//                        System.out.println("东阳--》");
-//                    }else {
-//                        prodStock = new ProdStock();
-//                        //                    prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
-//                        prodStock.setZzcl(5433);
-////                    prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
-//                        prodStock.setByzcl(6760);
-////                    prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
-//                        prodStock.setYfzcl(4361);
-////                    prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
-//                        prodStock.setZcl(16554);
-//                        prodStock.setMzcl(100);
-//                        prodStock.setGzcl(200);
-//                        prodStock.setBrzcl(452);
-//                        prodStock.setHbzcl(100);
-//                        prodStock.setRszcl(30);
-//                        prodStock.setBrmzcl(20);
-//                        prodStock.setKhzcl(212);
-//                        prodStock.setSpzcl(1020);
-//                        prodStock.setCreatTime(new Date());
-//                        prodStock.setFarmId(24);
-//                        prodStockService.save(prodStock);
-//                        System.out.println("东阳");
-//                    }
-//                }
-//                if ("浦江".equals(stock.get(0))){
-//                    if (ObjectUtil.isNotEmpty(prodStock)){
-////                        prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
-//                        prodStock.setZzcl(9980);
-////                        prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
-//                        prodStock.setByzcl(16384);
-////                        prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
-//                        prodStock.setYfzcl(32999);
-////                        prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
-//                        prodStock.setZcl(66381);
-//                        prodStock.setCreatTime(new Date());
-//                        prodStock.setFarmId(23);
-//                        prodStockService.updateById(prodStock);
-//                        System.out.println("浦江--》");
-//                    }else {
-//                        prodStock = new ProdStock();
-////                        prodStock.setZzcl(Integer.parseInt(stock.get(11).toString()));
-//                        prodStock.setZzcl(9980);
-////                        prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
-//                        prodStock.setByzcl(16384);
-////                        prodStock.setYfzcl(Integer.parseInt(stock.get(14).toString()));
-//                        prodStock.setYfzcl(32999);
-////                        prodStock.setZcl(Integer.parseInt(stock.get(15).toString()));
-//                        prodStock.setZcl(66381);
-//                        prodStock.setMzcl(100);
-//                        prodStock.setGzcl(200);
-//                        prodStock.setBrzcl(452);
-//                        prodStock.setHbzcl(100);
-//                        prodStock.setRszcl(30);
-//                        prodStock.setBrmzcl(20);
-//                        prodStock.setKhzcl(212);
-//                        prodStock.setSpzcl(1020);
-//                        prodStock.setCreatTime(new Date());
-//                        prodStock.setFarmId(23);
-//                        prodStockService.save(prodStock);
-//                        System.out.println("浦江--》");
-//                    }
-//
-//                }
-//            }
-//        }
-//    }
-//
-//
-//    private String login() throws Exception {
-//        StockLoginDto stockLoginDto = restTemplate.getForObject("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL", StockLoginDto.class);
-//        if (stockLoginDto.getStatus() != 0){
-//            return null;
-//        }
-//        return stockLoginDto.getToken();
-//    }
-//
-//}
+                        prodStock.setZcl(66381);
+                        prodStock.setMzcl(100);
+                        prodStock.setGzcl(200);
+                        prodStock.setBrzcl(452);
+                        prodStock.setHbzcl(100);
+                        prodStock.setRszcl(30);
+                        prodStock.setBrmzcl(20);
+                        prodStock.setKhzcl(212);
+                        prodStock.setSpzcl(1020);
+                        prodStock.setCreatTime(new Date());
+                        prodStock.setFarmId(23);
+                        prodStockService.save(prodStock);
+                        System.out.println("浦江--》");
+                    }
+
+                }
+            }
+        }
+    }
+
+
+    private String login() throws Exception {
+        StockLoginDto stockLoginDto = restTemplate.getForObject("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL", StockLoginDto.class);
+        if (stockLoginDto.getStatus() != 0){
+            return null;
+        }
+        return stockLoginDto.getToken();
+    }
+
+}