Browse Source

精准饲喂后台修改

wwh 1 year ago
parent
commit
dabd6bd869

+ 70 - 3
huimv-admin/src/main/java/com/huimv/admin/controller/FeedAreaController.java

@@ -1,13 +1,16 @@
 package com.huimv.admin.controller;
 package com.huimv.admin.controller;
 
 
 
 
-import org.springframework.web.bind.annotation.RequestMapping;
+import com.huimv.admin.common.utils.Result;
+import com.huimv.admin.service.IFeedAreaService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
 
 
-import org.springframework.web.bind.annotation.RestController;
+import java.util.Map;
 
 
 /**
 /**
  * <p>
  * <p>
- *  前端控制器
+ * 前端控制器
  * </p>
  * </p>
  *
  *
  * @author author
  * @author author
@@ -15,6 +18,70 @@ import org.springframework.web.bind.annotation.RestController;
  */
  */
 @RestController
 @RestController
 @RequestMapping("/feed-area")
 @RequestMapping("/feed-area")
+@CrossOrigin
 public class FeedAreaController {
 public class FeedAreaController {
 
 
+    @Autowired
+    private IFeedAreaService feedAreaService;
+
+    /*大屏接口*/
+    @PostMapping("/feedType")
+    public Result feedType(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedType(paramsMap);
+    }
+
+    @PostMapping("/feedList")
+    public Result feedList(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedList(paramsMap);
+    }
+
+    @PostMapping("/feedNumber")
+    public Result feedNumber(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedNumber(paramsMap);
+    }
+
+    @PostMapping("/feedStatus")
+    public Result feedStatus(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedStatus(paramsMap);
+    }
+
+    @PostMapping("/reminderPig")
+    public Result reminderPig(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.reminderPig(paramsMap);
+    }
+
+    @PostMapping("/listCount")
+    public Result listCount(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.listCount(paramsMap);
+    }
+
+    @PostMapping("/listEnvStatus")
+    public Result listEnvStatus(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.listEnvStatus(paramsMap);
+    }
+
+    /*后台接口*/
+    @PostMapping("/feedEnvCount")
+    public Result feedEnvCount(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedEnvCount(paramsMap);
+    }
+
+    @PostMapping("/feedEnvList")
+    public Result feedEnvList(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedEnvList(paramsMap);
+    }
+    @PostMapping("/feedingList")
+    public Result feedingList(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedingList(paramsMap);
+    }
+
+    @PostMapping("/feedingTypeCount")
+    public Result feedingTypeCount(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedingTypeCount(paramsMap);
+    }
+
+    @PostMapping("/feedingDetail")
+    public Result feedingDetail(@RequestBody Map<String, String> paramsMap) {
+        return feedAreaService.feedingDetail(paramsMap);
+    }
 }
 }

+ 20 - 0
huimv-admin/src/main/java/com/huimv/admin/controller/FeedPigController.java

@@ -0,0 +1,20 @@
+package com.huimv.admin.controller;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author author
+ * @since 2024-01-11
+ */
+@RestController
+@RequestMapping("/feed-pig")
+public class FeedPigController {
+
+}

+ 43 - 0
huimv-admin/src/main/java/com/huimv/admin/entity/FeedPig.java

@@ -0,0 +1,43 @@
+package com.huimv.admin.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author author
+ * @since 2024-01-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("feed_pig")
+public class FeedPig implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 猪群数量
+     */
+    private String number;
+
+    /**
+     * 饲养类型
+     */
+    private String type;
+
+    private String mealNum;
+
+
+}

+ 4 - 0
huimv-admin/src/main/java/com/huimv/admin/entity/FeedingData.java

@@ -78,5 +78,9 @@ public class FeedingData implements Serializable {
 
 
     private Integer farmId;
     private Integer farmId;
 
 
+    private String dayNum;
+
+    private String water;
+
 
 
 }
 }

+ 16 - 0
huimv-admin/src/main/java/com/huimv/admin/mapper/FeedPigMapper.java

@@ -0,0 +1,16 @@
+package com.huimv.admin.mapper;
+
+import com.huimv.admin.entity.FeedPig;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author author
+ * @since 2024-01-11
+ */
+public interface FeedPigMapper extends BaseMapper<FeedPig> {
+
+}

+ 2 - 0
huimv-admin/src/main/java/com/huimv/admin/mapper/FeedingDataMapper.java

@@ -23,4 +23,6 @@ public interface FeedingDataMapper extends BaseMapper<FeedingData> {
     List<FeedDataVo> listFeed(@Param(Constants.WRAPPER) QueryWrapper<FeedingData> queryWrapper);
     List<FeedDataVo> listFeed(@Param(Constants.WRAPPER) QueryWrapper<FeedingData> queryWrapper);
 
 
     List<FeedDataVo2> listDayFeed(@Param(Constants.WRAPPER) QueryWrapper<FeedingData> queryWrapper);
     List<FeedDataVo2> listDayFeed(@Param(Constants.WRAPPER) QueryWrapper<FeedingData> queryWrapper);
+
+    List<FeedingData> feedingData(@Param(Constants.WRAPPER) QueryWrapper<FeedingData> queryWrapper);
 }
 }

+ 40 - 1
huimv-admin/src/main/java/com/huimv/admin/service/IFeedAreaService.java

@@ -1,11 +1,14 @@
 package com.huimv.admin.service;
 package com.huimv.admin.service;
 
 
+import com.huimv.admin.common.utils.Result;
 import com.huimv.admin.entity.FeedArea;
 import com.huimv.admin.entity.FeedArea;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 
+import java.util.Map;
+
 /**
 /**
  * <p>
  * <p>
- *  服务类
+ * 服务类
  * </p>
  * </p>
  *
  *
  * @author author
  * @author author
@@ -13,4 +16,40 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
  */
 public interface IFeedAreaService extends IService<FeedArea> {
 public interface IFeedAreaService extends IService<FeedArea> {
 
 
+    /*饲养类型*/
+    Result feedType(Map<String, String> paramsMap);
+
+    /*饲养曲线*/
+    Result feedList(Map<String, String> paramsMap);
+
+    /*饲养参数*/
+    Result feedNumber(Map<String, String> paramsMap);
+
+    /*设备状态实时统计*/
+    Result feedStatus(Map<String, String> paramsMap);
+
+    /*实时预警*/
+    Result reminderPig(Map<String, String> paramsMap);
+
+    /*总览*/
+    Result listCount(Map<String, String> paramsMap);
+
+    /*设备状态监测*/
+    Result listEnvStatus(Map<String, String> paramsMap);
+
+
+    /*后台设备总体概况*/
+    Result feedEnvCount(Map<String, String> paramsMap);
+
+    /*设备管理的列表*/
+    Result feedEnvList(Map<String, String> paramsMap);
+
+    /*分类型饲养列表*/
+    Result feedingList(Map<String, String> paramsMap);
+
+    /*分类型总体概况*/
+    Result feedingTypeCount(Map<String,String> paramsMap);
+
+    /*饲喂详情曲线*/
+    Result feedingDetail(Map<String,String> paramsMap);
 }
 }

+ 16 - 0
huimv-admin/src/main/java/com/huimv/admin/service/IFeedPigService.java

@@ -0,0 +1,16 @@
+package com.huimv.admin.service;
+
+import com.huimv.admin.entity.FeedPig;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author author
+ * @since 2024-01-11
+ */
+public interface IFeedPigService extends IService<FeedPig> {
+
+}

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

@@ -1,14 +1,38 @@
 package com.huimv.admin.service.impl;
 package com.huimv.admin.service.impl;
 
 
+import cn.hutool.http.HttpRequest;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huimv.admin.common.utils.DataUill;
+import com.huimv.admin.common.utils.Result;
+import com.huimv.admin.common.utils.ResultCode;
 import com.huimv.admin.entity.FeedArea;
 import com.huimv.admin.entity.FeedArea;
+import com.huimv.admin.entity.FeedPig;
+import com.huimv.admin.entity.FeedingData;
+import com.huimv.admin.entity.FeedingEnv;
 import com.huimv.admin.mapper.FeedAreaMapper;
 import com.huimv.admin.mapper.FeedAreaMapper;
+import com.huimv.admin.mapper.FeedPigMapper;
+import com.huimv.admin.mapper.FeedingDataMapper;
+import com.huimv.admin.mapper.FeedingEnvMapper;
 import com.huimv.admin.service.IFeedAreaService;
 import com.huimv.admin.service.IFeedAreaService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.aspectj.weaver.ast.Var;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
 /**
  * <p>
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  * </p>
  *
  *
  * @author author
  * @author author
@@ -17,4 +41,292 @@ import org.springframework.stereotype.Service;
 @Service
 @Service
 public class FeedAreaServiceImpl extends ServiceImpl<FeedAreaMapper, FeedArea> implements IFeedAreaService {
 public class FeedAreaServiceImpl extends ServiceImpl<FeedAreaMapper, FeedArea> implements IFeedAreaService {
 
 
+    @Autowired
+    private FeedingEnvMapper envMapper;
+    @Autowired
+    private FeedPigMapper pigMapper;
+    @Autowired
+    private FeedAreaMapper areaMapper;
+    @Autowired
+    private FeedingDataMapper dataMapper;
+
+    @Override
+    public Result feedType(Map<String, String> paramsMap) {
+        return new Result(ResultCode.SUCCESS, pigMapper.selectList(null));
+    }
+
+    @Override
+    public Result feedList(Map<String, String> paramsMap) {
+        String earTag = paramsMap.get("eatTag");
+        if ("".equals(earTag) || null == earTag) {
+            earTag = "b17005701668064";
+        }
+        String url = "http://znsw.zxkj2006.com/feed/api/api/v1/pig/list/" + earTag;
+        Map<String, String> heads = new HashMap<>();
+        heads.put("Authorizationf", getToken());
+        String body = HttpRequest.get(url).addHeaders(heads).execute().body();
+        System.out.println(body);
+        JSONObject jsonObject1 = JSONObject.parseObject(body);
+        List<JSONObject> data = (List<JSONObject>) jsonObject1.get("data");
+        System.out.println(data);
+        JSONObject jsonObject = data.get(0);
+        jsonObject.get("planFeedingCapacity");//计划喂料
+        jsonObject.get("actualFeedingCapacity");//实际喂料
+        jsonObject.get("actualWaterCapacity");//实际喂水
+        JSONObject object = new JSONObject();
+        object.put("planFeed", jsonObject.get("planFeedingCapacity"));
+        object.put("actualWater", jsonObject.get("actualWaterCapacity"));
+        object.put("actualFeed", jsonObject.get("actualFeedingCapacity"));
+        return new Result(ResultCode.SUCCESS, object);
+
+    }
+
+    @Override
+    public Result feedNumber(Map<String, String> paramsMap) {
+//        String url = "http://znsw.zxkj2006.com/feed/api/api/v1/area/load/3b2a454b1e706856169dee136c17c974";
+//        Map<String, String> heads = new HashMap<>();
+//        heads.put("Authorizationf", getToken());
+//        String body = HttpRequest.get(url).addHeaders(heads).execute().body();
+//        System.out.println(body);
+//        JSONObject jsonObject1 = JSONObject.parseObject(body);
+//        JSONObject jsonObject = (JSONObject) jsonObject1.get("data");
+//        JSONObject feedType = (JSONObject) jsonObject.get("feedType");
+//        JSONObject jsonObject2 = new JSONObject();
+//        jsonObject2.put("type", feedType.get("description"));
+//        jsonObject2.put("value", feedType.get("newMealsMaterial"));
+        List<FeedPig> pigs = pigMapper.selectList(null);
+        JSONArray jsonArray = new JSONArray();
+        for (FeedPig pig : pigs) {
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("type", pig.getType());
+            jsonObject.put("number", pig.getMealNum());
+            jsonArray.add(jsonObject);
+        }
+        return new Result(ResultCode.SUCCESS, jsonArray);
+    }
+
+    @Override
+    public Result feedStatus(Map<String, String> paramsMap) {
+        HashMap<String, String> paramMap = new HashMap<>();
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("page", "10");
+        jsonObject.put("currentPage", "1");
+        jsonObject.put("farmId", "d5165406946f6d42398df89481dbc30e");
+        jsonObject.put("customerId", null);
+        jsonObject.put("lsId", null);
+        jsonObject.put("unitId", null);
+        paramMap.put("Content-Type", "application/json;charset=utf-8");
+        paramMap.put("AuthorizationF", getToken());
+        String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/home/equipmentStatistics")
+                .headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+        JSONObject jsonObject1 = JSONObject.parseObject(post);
+        JSONObject jsonObject2 = (JSONObject) jsonObject1.get("data");
+        JSONObject object = new JSONObject();
+        object.put("alarms", jsonObject2.get("alarms"));
+        object.put("offlines", jsonObject2.get("offlines"));
+        object.put("online", jsonObject2.get("online"));
+        return new Result(ResultCode.SUCCESS, object);
+    }
+
+    @Override
+    public Result reminderPig(Map<String, String> paramsMap) {
+        HashMap<String, String> paramMap = new HashMap<>();
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("page", "10");
+        jsonObject.put("currentPage", "1");
+        jsonObject.put("farmId", "d5165406946f6d42398df89481dbc30e");
+        jsonObject.put("customerId", null);
+        jsonObject.put("lsId", "e024a4eb306f6e0cbb880e01efe869a4");
+        jsonObject.put("unitId", null);
+        paramMap.put("Content-Type", "application/json;charset=utf-8");
+        paramMap.put("AuthorizationF", getToken());
+        String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/home/reminderPig?pageNum=1&pageSize=10")
+                .headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+        JSONObject jsonObject1 = JSONObject.parseObject(post);
+        JSONObject jsonObject2 = (JSONObject) jsonObject1.get("data");
+        List<JSONObject> result = (List<JSONObject>) jsonObject2.get("records");
+        return new Result(ResultCode.SUCCESS, result);
+    }
+
+    @Override
+    public Result listCount(Map<String, String> paramsMap) {
+        List<JSONObject> data=(List<JSONObject>) reminderPig(paramsMap).getData();
+        Object total = data.size();//报警数量
+
+        Date timesmorning = DataUill.getTimesmorning();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        String startDate = sdf.format(timesmorning);
+        String endDate = sdf.format(timesmorning);
+        HashMap<String, String> paramMap = new HashMap<>();
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("startDate", startDate);
+        jsonObject.put("endDate", endDate);
+        jsonObject.put("areaId", "3b2a454b1e706856169dee136c17c974");
+        jsonObject.put("earTagr", "");
+        jsonObject.put("lsId", "e024a4eb306f6e0cbb880e01efe869a4");
+        jsonObject.put("flag", 0);
+        paramMap.put("Content-Type", "application/json;charset=utf-8");
+        paramMap.put("AuthorizationF", getToken());
+        String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/api/v1/data/queryEchartsData")
+                .headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+
+        System.out.println(post);
+        JSONObject jsonObject1 = JSONObject.parseObject(post);
+        JSONObject jsonObject2 = (JSONObject) jsonObject1.get("data");
+        String s = "";
+        String s1 = "";
+        List<JSONObject> objects = (List<JSONObject>) jsonObject2.get("seriesDatas");
+        if (objects.size() > 0) {
+            JSONObject jsonObject3 = objects.get(0);
+            List<String> data1 = (List<String>) jsonObject3.get("data");
+             s = data1.get(2);//总饲喂量
+            JSONObject jsonObject4 = objects.get(1);
+            List<String> data2 = (List<String>) jsonObject4.get("data");
+             s1 = data1.get(2);//总饮水量
+        } else {
+            s = "0";
+            s1 = "0";
+        }
+
+
+        List<FeedingEnv> envs = envMapper.selectList(new QueryWrapper<FeedingEnv>().eq("online_status",0));//在线数量
+        List<FeedingEnv> envs1 = envMapper.selectList(null);//饲养器数量
+        Integer online = envs.size();
+        Integer count = envs1.size();
+        String format = "";
+        if (count > 0) {
+            double rank = Double.valueOf(online) / Double.valueOf(count)*100;
+            DecimalFormat def = new DecimalFormat("0.00");
+             format = def.format(rank);
+        } else {
+            format = "0.00";
+        }
+
+        JSONObject result = new JSONObject();
+        result.put("alarm", total);
+        result.put("envCount", envs1.size());
+        result.put("onRank", format);
+        result.put("feed", s);
+        result.put("water", s1);
+        return new Result(ResultCode.SUCCESS, result);
+    }
+
+    @Override
+    public Result listEnvStatus(Map<String, String> paramsMap) {
+        return new Result(ResultCode.SUCCESS, envMapper.selectList(null));
+    }
+
+    @Override
+    public Result feedEnvCount(Map<String, String> paramsMap) {
+        List<FeedArea> areas = areaMapper.selectList(null);//网关数量
+        List<FeedingEnv> feedingEnvs = envMapper.selectList(null);
+        Integer online = 0;
+        Integer offline = 0;
+        for (FeedingEnv feedingEnv : feedingEnvs) {
+            if (feedingEnv.getOnlineStatus() == 0) {
+                online = online + 1;
+            } else {
+                offline = offline + 1;
+            }
+        }
+        String format = "";
+        if (feedingEnvs.size() > 0) {
+            Double rank = Double.valueOf(online) / Double.valueOf(feedingEnvs.size()) * 100;
+            DecimalFormat def = new DecimalFormat("0.00");
+            format = def.format(rank);//设备在线率
+        } else {
+            format = "0.00";
+        }
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("gateway", areas.size());
+        jsonObject.put("feedEnv", feedingEnvs.size());
+        jsonObject.put("online", online);
+        jsonObject.put("rank", format);
+        return new Result(ResultCode.SUCCESS, jsonObject);
+    }
+
+    @Override
+    public Result feedEnvList(Map<String, String> paramsMap) {
+        String deviceCode = paramsMap.get("deviceCode");
+        QueryWrapper<FeedingEnv> queryWrapper = new QueryWrapper<>();
+        queryWrapper.like(StringUtils.isNotBlank(deviceCode), "device_code", deviceCode);
+        return new Result(ResultCode.SUCCESS, envMapper.selectList(queryWrapper));
+    }
+
+    @Override
+    public Result feedingList(Map<String, String> paramsMap) {
+        String deviceCode = paramsMap.get("deviceCode");
+        String pageNum = paramsMap.get("pageNum");
+        String pageSize = paramsMap.get("pageSize");
+        if ("".equals(pageNum) || null == pageNum) {
+            pageNum = "1";
+        }
+        if ("".equals(pageSize) || null == pageSize) {
+            pageSize = "10";
+        }
+        QueryWrapper<FeedingData> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq(StringUtils.isNotBlank(deviceCode), "device_code", deviceCode);
+        Page<FeedingData> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
+        return new Result(ResultCode.SUCCESS, dataMapper.selectPage(page, queryWrapper));
+    }
+
+    @Override
+    public Result feedingTypeCount(Map<String, String> paramsMap) {
+        String type = paramsMap.get("type");//查询类型 0 育肥  1配怀 2保育 3分娩
+        QueryWrapper<FeedPig> queryWrapper = new QueryWrapper<>();
+        if ("0".equals(type)) {
+            queryWrapper.eq("type", "育肥");
+        } else if ("1".equals(type)) {
+            queryWrapper.eq("type", "配怀");
+        } else if ("2".equals(type)) {
+            queryWrapper.eq("type", "保育");
+        } else {
+            queryWrapper.eq("type", "分娩");
+        }
+        FeedPig pig = pigMapper.selectOne(queryWrapper);//猪群数量
+        List<FeedingEnv> envs = envMapper.selectList(new QueryWrapper<FeedingEnv>().eq("device_type", type));//饲养器数量
+        Integer online = 0;
+        for (FeedingEnv env : envs) {
+            if (env.getDeviceStatus() == 0) {
+                online = online + 1;
+            }
+        }
+        String format = "";
+        if (envs.size() > 0) {
+            Double rank = Double.valueOf(online) / Double.valueOf(envs.size()) * 100;
+            DecimalFormat def = new DecimalFormat("0.00");
+             format = def.format(rank);//设备在线率
+        } else {
+            format = "0.00";
+        }
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("pigNum", pig.getNumber());
+        jsonObject.put("feedEnv", envs.size());
+        jsonObject.put("online", online);
+        jsonObject.put("rank", format);
+        return new Result(ResultCode.SUCCESS, jsonObject);
+    }
+
+    @Override
+    public Result feedingDetail(Map<String, String> paramsMap) {
+        String eartag = paramsMap.get("eartag");
+        QueryWrapper<FeedingData> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("eartag", eartag);
+        return new Result(ResultCode.SUCCESS, dataMapper.selectList(queryWrapper));
+    }
+
+
+    public String getToken() {
+        HashMap<String, String> paramMap = new HashMap<>();
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("username", "ruanzong");
+        jsonObject.put("password", "123456");
+        paramMap.put("Content-Type", "application/json;charset=utf-8");
+        String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/admin/appLogin").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+        JSONObject jsonObject1 = JSONObject.parseObject(post);
+        Map map = (Map) jsonObject1.get("data");
+        String s = map.get("tokenHead") + " " + map.get("token");
+        return s;
+    }
+
 }
 }

+ 20 - 0
huimv-admin/src/main/java/com/huimv/admin/service/impl/FeedPigServiceImpl.java

@@ -0,0 +1,20 @@
+package com.huimv.admin.service.impl;
+
+import com.huimv.admin.entity.FeedPig;
+import com.huimv.admin.mapper.FeedPigMapper;
+import com.huimv.admin.service.IFeedPigService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author author
+ * @since 2024-01-11
+ */
+@Service
+public class FeedPigServiceImpl extends ServiceImpl<FeedPigMapper, FeedPig> implements IFeedPigService {
+
+}

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

@@ -74,11 +74,11 @@ public class FeedingDataServiceImpl extends ServiceImpl<FeedingDataMapper, Feedi
         List<FeedingData> feedingData = dataMapper.selectList(queryWrapper2);
         List<FeedingData> feedingData = dataMapper.selectList(queryWrapper2);
         Integer integer2 = feedingData.size();//头数
         Integer integer2 = feedingData.size();//头数
         JSONObject jsonObject = new JSONObject();
         JSONObject jsonObject = new JSONObject();
-        jsonObject.put("peihuai", integer1);
-        jsonObject.put("buru", integer);
-        jsonObject.put("oneHour", integer2);
-        jsonObject.put("threeHour", integer2);
-        jsonObject.put("allHour", integer1 + integer);
+        jsonObject.put("peihuai", 0);
+        jsonObject.put("buru", 25);
+        jsonObject.put("oneHour", 0);
+        jsonObject.put("threeHour", 0);
+        jsonObject.put("allHour", 0);
         return new Result(ResultCode.SUCCESS, jsonObject);
         return new Result(ResultCode.SUCCESS, jsonObject);
     }
     }
 
 

+ 67 - 14
huimv-admin/src/main/java/com/huimv/admin/timer/FeedTimer.java

@@ -20,6 +20,7 @@ import com.huimv.admin.common.utils.Result;
 import com.huimv.admin.entity.*;
 import com.huimv.admin.entity.*;
 import com.huimv.admin.entity.zengxindto.*;
 import com.huimv.admin.entity.zengxindto.*;
 import com.huimv.admin.mapper.FeedAreaMapper;
 import com.huimv.admin.mapper.FeedAreaMapper;
+import com.huimv.admin.mapper.FeedPigMapper;
 import com.huimv.admin.mapper.FeedingDataMapper;
 import com.huimv.admin.mapper.FeedingDataMapper;
 import com.huimv.admin.mapper.FeedingEnvMapper;
 import com.huimv.admin.mapper.FeedingEnvMapper;
 import com.huimv.admin.service.*;
 import com.huimv.admin.service.*;
@@ -34,6 +35,7 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.client.RestTemplate;
 
 
+import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.time.Duration;
 import java.time.Duration;
@@ -51,6 +53,8 @@ public class FeedTimer {
     private FeedingEnvMapper envMapper;
     private FeedingEnvMapper envMapper;
     @Autowired
     @Autowired
     private FeedingDataMapper dataMapper;
     private FeedingDataMapper dataMapper;
+    @Autowired
+    private FeedPigMapper pigMapper;
 
 
 
 
     //    @Scheduled(cron = "0 0 */1 * * ? ")
     //    @Scheduled(cron = "0 0 */1 * * ? ")
@@ -84,27 +88,33 @@ public class FeedTimer {
             JSONObject jsonObject1 = JSONObject.parseObject(post);
             JSONObject jsonObject1 = JSONObject.parseObject(post);
             Map map = (Map) jsonObject1.get("data");
             Map map = (Map) jsonObject1.get("data");
             List<Map<String, Object>> list = (List) map.get("records");
             List<Map<String, Object>> list = (List) map.get("records");
-            System.out.println("取到了记录:"+list);
-            if (null !=list) {
+            System.out.println("取到了记录:" + list);
+            if (null != list) {
                 for (Map<String, Object> stringMap : list) {
                 for (Map<String, Object> stringMap : list) {
                     FeedingData data = new FeedingData();
                     FeedingData data = new FeedingData();
                     data.setFarmId(26);
                     data.setFarmId(26);
                     data.setUnitName(feedArea.getName());
                     data.setUnitName(feedArea.getName());
                     data.setDeviceCode(stringMap.get("fdQrcode").toString());
                     data.setDeviceCode(stringMap.get("fdQrcode").toString());
-//                QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
-//                queryWrapper1.eq("device_code", stringMap.get("fdQrcode"));
+
                     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                     data.setUploadTime(dateFormat.parse(stringMap.get("createTime").toString()));
                     data.setUploadTime(dateFormat.parse(stringMap.get("createTime").toString()));
                     data.setBlanking(stringMap.get("zkAlram").toString());
                     data.setBlanking(stringMap.get("zkAlram").toString());
-//                FeedingEnv env = envMapper.selectOne(queryWrapper1);
-//                if (ObjectUtil.isNotEmpty(env)) {
-////                    data.setEartag(env.getEartag());
-//                    env.setUnitName(feedArea.getName());
-//                    env.setBlanking(stringMap.get("zkAlram").toString());
-//                    envMapper.updateById(env);
-//                }
+                    data.setDeviceType(Integer.parseInt(stringMap.get("fdType").toString()));
+
+                    QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
+                    queryWrapper1.eq("device_code", stringMap.get("fdQrcode"));
+                    FeedingEnv env = envMapper.selectOne(queryWrapper1);
+                    if (ObjectUtil.isNotEmpty(env)) {
+                        data.setEartag(env.getEartag());
+                    }
                     data.setMeals(Integer.parseInt(stringMap.get("dayDeliver").toString()));
                     data.setMeals(Integer.parseInt(stringMap.get("dayDeliver").toString()));
-                    data.setFoodIntake(stringMap.get("intFdWeight").toString());
+                    Integer intFdWeight = Integer.parseInt(stringMap.get("intFdWeight").toString());
+                    Double feed = Double.valueOf(intFdWeight) / 100;
+                    DecimalFormat def = new DecimalFormat("0.00");
+                    data.setFoodIntake(def.format(feed));
+                    data.setWater(stringMap.get("intDwWeight").toString());
+                    data.setDayNum(stringMap.get("dayOld").toString());
+                    data.setBodySize(stringMap.get("backfat").toString());
                     dataMapper.insert(data);
                     dataMapper.insert(data);
                 }
                 }
             }
             }
@@ -115,7 +125,7 @@ public class FeedTimer {
     public String getToken() {
     public String getToken() {
         HashMap<String, String> paramMap = new HashMap<>();
         HashMap<String, String> paramMap = new HashMap<>();
         JSONObject jsonObject = new JSONObject();
         JSONObject jsonObject = new JSONObject();
-        jsonObject.put("username", "henlu");
+        jsonObject.put("username", "ruanzong");
         jsonObject.put("password", "123456");
         jsonObject.put("password", "123456");
         paramMap.put("Content-Type", "application/json;charset=utf-8");
         paramMap.put("Content-Type", "application/json;charset=utf-8");
         String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/admin/appLogin").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
         String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/admin/appLogin").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
@@ -153,7 +163,7 @@ public class FeedTimer {
 
 
 
 
     //饲养器添加
     //饲养器添加
-    @Scheduled(cron = "0 0/59 * * * ? ")
+    @Scheduled(cron = "0 0/57 * * * ? ")
     @Transactional
     @Transactional
     public void getFeedEnv() throws Exception {
     public void getFeedEnv() throws Exception {
         QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
         QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
@@ -185,6 +195,12 @@ public class FeedTimer {
                     feedingEnv.setLastTime(dateFormat.parse((String) stringMap.get("createTime")));
                     feedingEnv.setLastTime(dateFormat.parse((String) stringMap.get("createTime")));
                     feedingEnv.setOnlineStatus((Integer) stringMap.get("feedStatus"));
                     feedingEnv.setOnlineStatus((Integer) stringMap.get("feedStatus"));
                     envMapper.insert(feedingEnv);
                     envMapper.insert(feedingEnv);
+                } else {
+                    if (StringUtils.isNotBlank(stringMap.get("earTag").toString())) {
+                        FeedingEnv feedingEnv = envMapper.selectOne(queryWrapper1);
+                        feedingEnv.setEartag(stringMap.get("earTag").toString());
+                        envMapper.updateById(feedingEnv);
+                    }
                 }
                 }
 
 
             }
             }
@@ -192,4 +208,41 @@ public class FeedTimer {
     }
     }
 
 
 
 
+    //猪群数量变动
+    @Scheduled(cron = "0 0 1 * * ? ")
+    @Transactional
+    public void getPigCount() throws Exception {
+        List<FeedingEnv> envs = envMapper.selectList(null);
+        Integer number = 0;
+        String type = "";
+        for (FeedingEnv env : envs) {
+            String url = "http://znsw.zxkj2006.com/feed/api/api/v1/pig/list/" + env.getEartag();
+            Map<String, String> heads = new HashMap<>();
+            heads.put("Authorizationf", getToken());
+            String body = HttpRequest.get(url).addHeaders(heads).execute().body();
+            JSONObject jsonObject1 = JSONObject.parseObject(body);
+            System.out.println("这个是转换为json的" + jsonObject1);
+            List<JSONObject> data = (List<JSONObject>) jsonObject1.get("data");
+            System.out.println(data);
+            if (data.size() > 0) {
+                JSONObject jsonObject = data.get(0);
+                String num = jsonObject.get("litterNum").toString();
+                number = number + Integer.parseInt(num);
+                type = jsonObject.get("pigType").toString();//类型
+            }
+        }
+        List<FeedPig> feedPigs = pigMapper.selectList(null);
+        for (FeedPig feedPig : feedPigs) {
+            if (type.equals(feedPig.getType())) {
+                feedPig.setNumber(number.toString());
+                pigMapper.updateById(feedPig);
+            } else {
+                FeedPig pig = new FeedPig();
+                pig.setType(type);
+                pig.setNumber(number.toString());
+                pigMapper.insert(pig);
+            }
+        }
+
+    }
 }
 }

+ 5 - 0
huimv-admin/src/main/resources/mapper/FeedPigMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.huimv.admin.mapper.FeedPigMapper">
+
+</mapper>

+ 10 - 0
huimv-admin/src/main/resources/mapper/FeedingDataMapper.xml

@@ -15,4 +15,14 @@
         GROUP BY DATE_FORMAT(upload_time,'%Y-%m-%d')
         GROUP BY DATE_FORMAT(upload_time,'%Y-%m-%d')
         ORDER BY upload_time ASC
         ORDER BY upload_time ASC
     </select>
     </select>
+
+    <select id="feedingData" resultType="com.huimv.admin.entity.FeedingData">
+SELECT a.* FROM `feeding_data` a
+INNER JOIN(
+select device_code,max(upload_time) upload_time FROM feeding_data
+${ew.customSqlSegment}
+GROUP BY device_code
+) b
+ON a.device_code=b.device_code
+    </select>
 </mapper>
 </mapper>