Browse Source

登录生成token

wwh 1 year ago
parent
commit
2fa01ddb4b

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

@@ -120,6 +120,32 @@ public class LoginController {
         return  token;
         return  token;
     }
     }
 
 
-
+    @RequestMapping("/logoutClient")
+    public Result logoutClient(HttpServletRequest req, @RequestBody Map<String, String> map) {
+        String accountName = map.get("accountName");
+        String password = map.get("password");
+        String remoteHost = req.getRemoteHost();
+        Result result = iLoginService.loginMultilevel(accountName, password);
+        if (result.getCode() == 10000) {
+            SysAccountMultilevel data = (SysAccountMultilevel) result.getData();
+            AccessToken accessToken = new AccessToken();
+            accessToken.setAccountName(accountName);
+            accessToken.setUserName(data.getUserName());
+            accessToken.setFarmId(data.getFarmIds());
+            accessToken.setType(data.getType());
+            accessToken.setId(data.getId());
+            String token = TokenSign.sign(accountName,data.getId(),data.getFarmIds());
+            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);
+        } else {
+            return result;
+        } 
+    }
 
 
 }
 }

+ 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);
+//        }
+//    }
+//}

File diff suppressed because it is too large
+ 529 - 529
huimv-admin/src/main/java/com/huimv/admin/timer/ProtTimer.java


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

@@ -1,188 +1,188 @@
-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.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(23);
-                        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(23);
-                        prodStockService.save(prodStock);
-                    }
-
-                }
-            }
-        }
-    }
-
-
-    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();
-    }
-
-}
+//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.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(23);
+//                        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(23);
+//                        prodStockService.save(prodStock);
+//                    }
+//
+//                }
+//            }
+//        }
+//    }
+//
+//
+//    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();
+//    }
+//
+//}