Browse Source

新增 首页获取农事统计分析接口

zhaiyifei 11 months ago
parent
commit
3838b30fe8

+ 115 - 2
src/main/java/com/yunfeiyun/agmp/fms/controller/FmsConsoleController.java

@@ -12,7 +12,6 @@ import com.yunfeiyun.agmp.common.exception.BizException;
 import com.yunfeiyun.agmp.common.service.WeatherService;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.SecurityUtils;
-import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.fms.domain.FmsBlock;
 import com.yunfeiyun.agmp.fms.domain.FmsLand;
 import com.yunfeiyun.agmp.fms.domain.FmsSolar;
@@ -28,6 +27,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.time.DayOfWeek;
@@ -74,7 +74,120 @@ public class FmsConsoleController {
     @Autowired
     private WeatherService weatherService;
 
+    public void getWeather(ScreenDataReqVo reqVo, Map<String, Object> resultMap) {
+        FmsWeatherInfoResVo fmsWeatherInfoResVo = null;
+        try {
+            JSONObject resultObj = weatherService.getProjectWeather();
+            fmsWeatherInfoResVo = JSONObject.parseObject(resultObj.toString(), FmsWeatherInfoResVo.class);
+            Map<String, Object> map = new HashMap<>();
+            List<FmsWeatherInfoResVo> weatherList = new ArrayList<>();
+            JSONArray data = resultObj.getJSONArray("data");
+            if (data != null) {
+                for (int i = 0; i < data.size(); i++) {
+                    String str = data.getString(i);
+                    FmsWeatherInfoResVo weatherResVo = JSONObject.parseObject(str, FmsWeatherInfoResVo.class);
+                    weatherResVo.setCity(fmsWeatherInfoResVo.getCity());
+                    weatherResVo.setZoneProvincezh(map.get("zoneProvincezh") == null ? "" : map.get("zoneProvincezh").toString());
+                    weatherResVo.setZoneCapitalzh(map.get("zoneCapitalzh") == null ? "" : map.get("zoneCapitalzh").toString());
+                    weatherList.add(weatherResVo);
+                }
+            }
+            resultMap.put("weather", weatherList);
+        }catch (Exception e){
+            throw new BizException(ErrorCode.FMS_WEATHER_SEARCH_FAILED);
+        }
+    }
+
+    /**
+     * 查询节气信息
+     */
+    @PreAuthorize("@ss.hasPermi('fms:console:weather:info')")
+    @GetMapping("/weather/info")
+    public AjaxResult weatherInfo(ScreenDataReqVo reqVo) {
+
+        FmsWeatherInfoResVo fmsWeatherInfoResVo = new FmsWeatherInfoResVo();
+        FmsSolar fmsSolar = iFmsSolarService.getNowSolar(DateUtils.dateTimeNow(), SecurityUtils.getTid());
+        fmsWeatherInfoResVo.setSolarName(fmsSolar.getSolarName());
+        fmsWeatherInfoResVo.setSolarRemark(fmsSolar.getSolarRemark());
+        fmsWeatherInfoResVo.setSolarDigest(fmsSolar.getSolarDigest());
+        return AjaxResult.success(fmsWeatherInfoResVo);
+    }
+
+
+    /**
+     *  首页数据查询
+     */
+    @PreAuthorize("@ss.hasPermi('fms:console:console:data')")
+    @GetMapping(value = "/console/data")
+    public AjaxResult consoleData(ScreenDataReqVo reqVo) {
+        Map<String, Object> resultMap = new HashMap<>();
+
+        try {
+            JSONObject resultObj = weatherService.getProjectWeather("7");
+            String city = resultObj.getString("city");
+            String province = resultObj.getString("province");
+            String district = resultObj.getString("district");
+
+            List<FmsWeatherInfoResVo> weatherList = new ArrayList<>();
+            JSONArray data = resultObj.getJSONArray("data");
+            if (data != null) {
+                for (int i = 0; i < data.size(); i++) {
+                    String str = data.getString(i);
+                    FmsWeatherInfoResVo weatherResVo = JSONObject.parseObject(str, FmsWeatherInfoResVo.class);
+                    weatherResVo.setCity(city);
+                    weatherResVo.setZoneProvincezh(province);
+                    weatherResVo.setZoneCapitalzh(district);
+                    weatherList.add(weatherResVo);
+                }
+            }
+            resultMap.put("weather", weatherList);
+        }catch (Exception e){
+            throw new BizException(ErrorCode.FMS_WEATHER_SEARCH_FAILED);
+        }
+
+        boolean b = SecurityUtils.isValidate();
+        if (b) {
+            List<String> strings = dataAuthUtil.landListOfBlock();
+            if (strings.isEmpty()) {
+                resultMap.put("landTotal", new ArrayList<>());
+                Map<String, Object> countMap = new HashMap<>();
+                countMap.put("count1", new ArrayList<>());
+                countMap.put("count2", new ArrayList<>());
+                countMap.put("count3", new ArrayList<>());
+                resultMap.put("taskTypeCount", countMap);
+                resultMap.put("fmsPlanStat", new ArrayList<>());
+                return AjaxResult.success(resultMap);
+            }
+        }
+
+        /* 获取基地统计信息 */
+        getLandStat(reqVo, resultMap, b);
+
+        /* 获取农事任务统计信息 */
+        getTaskStat(reqVo, resultMap, b);
 
+        /* 当前种植状态 */
+         getPlanStat(reqVo, resultMap, b);
+
+        //取收入支出數據
+        SelectOfTssStatReqVo reqVo1 = new SelectOfTssStatReqVo();
+        reqVo1.setStartTime(DateUtils.dateTimeNow(DateUtils.YYYY));
+        Map<String, Object> moneyMap = getMoney(reqVo1);
+        resultMap.put("totalExpenditure", moneyMap.get("payTotal"));
+        resultMap.put("orderPriceSum", moneyMap.get("incomeTotal"));
+
+        resultMap.put("warehouseNumber", "0");
+
+        WmsWarehouseListReqVo wmsWarehouseListReqVo = new WmsWarehouseListReqVo();
+        wmsWarehouseListReqVo.setWarehouseType("");
+        List<WmsWarehouse> wmsWarehouseList = wmsWarehouseService.selectWmsWarehouseList(wmsWarehouseListReqVo);
+
+        if(wmsWarehouseList!=null){
+            resultMap.put("warehouseNumber", "" + wmsWarehouseList.size());
+        }
+
+        return AjaxResult.success(resultMap);
+    }
 
 
     /**
@@ -247,7 +360,7 @@ public class FmsConsoleController {
 
         if (isValid) {
             List<String> strings = dataAuthUtil.blockList();
-            if (strings.size() == 0) {
+            if (strings.isEmpty()) {
                 countMap.put("count1", new JSONArray());
                 countMap.put("count2", new JSONArray());
                 countMap.put("count3", new JSONArray());

+ 0 - 2
src/main/java/com/yunfeiyun/agmp/fms/util/DataAuthUtil.java

@@ -36,7 +36,6 @@ public class DataAuthUtil
      */
     public List<String> landList() {
         FmsLand fmsLand = new FmsLand();
-        fmsLand.setTid(SecurityUtils.getTid());
         List<FmsLand> fmsLands = fmsLandService.selectFmsLandList(fmsLand);
         List<String> list = new ArrayList<>();
         for (FmsLand land : fmsLands) {
@@ -52,7 +51,6 @@ public class DataAuthUtil
 
         List<String> list = this.landList();
         FmsBlock fmsBlock = new FmsBlock();
-        fmsBlock.setTid(SecurityUtils.getTid());
         List<FmsBlock> blocks = fmsBlockService.selectFmsBlockList(fmsBlock);
         for (FmsBlock block : blocks) {
             list.add(block.getLandId());

+ 1 - 1
src/main/resources/mapper/FmsBlockMapper.xml

@@ -358,7 +358,7 @@
     <select id="selectFmsBlockListByLandManager" resultType="com.yunfeiyun.agmp.fms.domain.FmsBlock">
         select * from FmsBlock
         where landId in (
-        select landId from FmsLand where landManager = #{userId}
+            select landId from FmsLand where landManager = #{userId} and tid = #{tid}
         )
     </select>
 

+ 16 - 17
src/main/resources/mapper/FmsLandMapper.xml

@@ -67,24 +67,23 @@
 
     <select id="selectFmsLandTotal" parameterType="FmsLand" resultType="FmsLandTotalResVo">
         SELECT count(1) count, sum(landArea) landAreaSum, sum(landBlockcountSum) landBlockcountSum,
-        (
-        SELECT COUNT(tmnlandId) FROM TmnLand tl
-        LEFT JOIN IotDevice idv on idv.devBid = tl.tmnId
-        <where>
-            idv.devDelstatus = '0' and tl.tid = #{tid}
-            <if test="landId != null  and landId != ''">and tl.landId = #{landId}</if>
-            <if test="dataFilter == true and landIds !=null and landIds.size()>0">
-                and tl.landId in
-                <foreach collection="landIds" item="landId" index="index" open="(" close=")" separator=",">
-                    #{landId}
-                </foreach>
-            </if>
-        </where>
-        ) landDevcountSum
+            (
+                SELECT COUNT(tmnlandId) FROM TmnLand tl
+                LEFT JOIN IotDevice idv on idv.devBid = tl.tmnId
+                <where>
+                    idv.devDelstatus = '0' and tl.tid = #{tid}
+                    <if test="landId != null  and landId != ''">and tl.landId = #{landId}</if>
+                    <if test="dataFilter == true and landIds !=null and landIds.size()>0">
+                        and tl.landId in
+                        <foreach collection="landIds" item="landId" index="index" open="(" close=")" separator=",">
+                            #{landId}
+                        </foreach>
+                    </if>
+                </where>
+            ) landDevcountSum
         from FmsLand fl
-        LEFT JOIN (
-        select count(blockId) as landBlockcountSum,landId from FmsBlock GROUP BY landId
-        ) fb on fb.landId = fl.landId
+            LEFT JOIN (select count(blockId) as landBlockcountSum,landId from FmsBlock GROUP BY landId ) fb on
+                fb.landId = fl.landId
         <where>
             fl.tid = #{tid}
             <if test="landId != null  and landId != ''">and fl.landId = #{landId}</if>