Selaa lähdekoodia

调整首页接口
重新天气接口
重写基地,地块统计接口
新增种植作物占比top查询接口

liuyaowen 1 vuosi sitten
vanhempi
commit
21450de601

+ 113 - 283
src/main/java/com/yunfeiyun/agmp/fms/controller/FmsConsoleController.java

@@ -3,8 +3,11 @@ package com.yunfeiyun.agmp.fms.controller;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.github.pagehelper.PageHelper;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
+import com.yunfeiyun.agmp.common.core.controller.BaseController;
 import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.enums.CommonEnums;
 import com.yunfeiyun.agmp.common.enums.FmsMessageResVoType;
 import com.yunfeiyun.agmp.common.enums.TaskStatus;
@@ -12,13 +15,11 @@ 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.fms.domain.FmsBlock;
-import com.yunfeiyun.agmp.fms.domain.FmsLand;
-import com.yunfeiyun.agmp.fms.domain.FmsSolar;
-import com.yunfeiyun.agmp.fms.domain.WmsWarehouse;
+import com.yunfeiyun.agmp.fms.domain.*;
 import com.yunfeiyun.agmp.fms.domain.reqvo.*;
 import com.yunfeiyun.agmp.fms.domain.resvo.*;
 import com.yunfeiyun.agmp.fms.domain.vo.FmsSolarVo;
+import com.yunfeiyun.agmp.fms.mapper.FmsCropMapper;
 import com.yunfeiyun.agmp.fms.service.*;
 import com.yunfeiyun.agmp.fms.util.DataAuthUtil;
 import org.slf4j.Logger;
@@ -31,6 +32,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -39,6 +41,7 @@ import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.time.temporal.WeekFields;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 首页Controller
@@ -47,7 +50,7 @@ import java.util.*;
  */
 @RestController
 @RequestMapping("/fms/console")
-public class FmsConsoleController {
+public class FmsConsoleController extends BaseController {
     private static final Logger log = LoggerFactory.getLogger(FmsConsoleController.class);
     @Resource
     private IFmsSolarService iFmsSolarService;
@@ -67,13 +70,12 @@ public class FmsConsoleController {
     private IFmsTaskpickService fmsTaskpickService;
     @Autowired
     private DataAuthUtil dataAuthUtil;
-
-
     @Autowired
     private IWmsWarehouseService wmsWarehouseService;
-
     @Autowired
     private WeatherService weatherService;
+    @Resource
+    private IFmsCropService fmsCropService;
 
     /**
      * 查询节气信息
@@ -81,29 +83,11 @@ public class FmsConsoleController {
     @PreAuthorize("@ss.hasPermi('fms:console:weather:info')")
     @GetMapping("/weather/info")
     public AjaxResult weatherInfo(ScreenDataReqVo reqVo) {
-        FmsWeatherInfoResVo fmsWeatherInfoResVo = new FmsWeatherInfoResVo();
-        FmsSolarVo 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) {
@@ -116,57 +100,73 @@ public class FmsConsoleController {
                     weatherList.add(weatherResVo);
                 }
             }
-            resultMap.put("weather", weatherList);
+            return AjaxResult.success(weatherList);
         }catch (Exception e){
             log.error("获取天气信息失败", e);
             throw new BizException(ErrorCode.FMS_WEATHER_SEARCH_FAILED);
         }
+    }
+
 
+    /**
+     *  首页数据查询
+     */
+    @PreAuthorize("@ss.hasPermi('fms:console:console:data')")
+    @GetMapping(value = "/console/data")
+    public AjaxResult consoleData() {
+        FmsConsoleStatResVo fmsConsoleStatResVo = new FmsConsoleStatResVo();
         boolean b = SecurityUtils.isValidate();
+        List<String> landIds;
+        List<String> blockIds;
         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);
+            landIds = dataAuthUtil.landListOfBlock();
+            if (landIds.isEmpty()) {
+                return AjaxResult.success(fmsConsoleStatResVo);
             }
+            blockIds = dataAuthUtil.blockList();
+        }else {
+            landIds = null;
+            blockIds = null;
         }
+        // 拼装基地统计数据
+        appendLandStat(fmsConsoleStatResVo,landIds);
+        // 拼装地块统计数据
+        appendBlockStat(fmsConsoleStatResVo,blockIds);
+        // 拼装种植统计数据
+        appendPlanStat(fmsConsoleStatResVo,blockIds);
+        return AjaxResult.success();
+    }
 
-        /* 获取基地统计信息 */
-        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());
+    @PreAuthorize("@ss.hasPermi('fms:console:console:data')")
+    @GetMapping(value = "/crop/plan/area/top")
+    public TableDataInfo cropPlanAreaTop() {
+        boolean b = SecurityUtils.isValidate();
+        List<String> blockIds;
+        if (b) {
+            blockIds = dataAuthUtil.blockList();
+            if (blockIds.isEmpty()) {
+                return getDataTable(blockIds);
+            }
+        }else {
+            blockIds = null;
         }
-
-        return AjaxResult.success(resultMap);
+        List<FmsCropPlanAreaResVo> fmsCropPlanAreaResVos = fmsPlanService.selectCropPlanAreaTop(blockIds);
+        List<String> cropIds = fmsCropPlanAreaResVos.stream().map(FmsCropPlanAreaResVo::getCropId).collect(Collectors.toList());
+        List<FmsCrop> fmsCropList = fmsCropService.selectFmsCropListByCropIds(cropIds);
+        Map<String,FmsCrop> cropMap = fmsCropList.stream().collect(Collectors.toMap(FmsCrop::getCropId,item->item));
+        for(FmsCropPlanAreaResVo fmsCropPlanAreaResVo : fmsCropPlanAreaResVos){
+            FmsCrop fmsCrop = cropMap.get(fmsCropPlanAreaResVo.getCropId());
+            if(null != fmsCrop){
+                fmsCropPlanAreaResVo.setCropName(fmsCrop.getCropName());
+                fmsCropPlanAreaResVo.setCropType(fmsCrop.getCropType());
+            }
+        }
+        return getDataTable(fmsCropPlanAreaResVos);
     }
 
 
+
+
     /**
      * 获取基地统计信息
      */
@@ -279,228 +279,58 @@ public class FmsConsoleController {
         return AjaxResult.success(jsonArray);
     }
 
-
-
-    public void getLandStat(ScreenDataReqVo reqVo, Map<String, Object> resultMap, boolean isValid) {
-        /* 获取基地统计信息 */
-        FmsLand fmsLand = new FmsLand();
-        fmsLand.setLandId(reqVo.getLandId());
-
-        if (isValid) {
-            //true需要进行权限校验。下拉框基地列表查询需要包含分配的基地以及分配地块所属基地
-            List<String> strings = dataAuthUtil.landListOfBlock();
-            if (strings.isEmpty()) {
-                FmsLandTotalResVo fmsLandTotalResVo = new FmsLandTotalResVo();
-                fmsLandTotalResVo.setBlockUsageRate("0");
-                fmsLandTotalResVo.setLandAreaSum("0");
-                fmsLandTotalResVo.setCount("0");
-                fmsLandTotalResVo.setBlockAreaSum("0");
-                fmsLandTotalResVo.setPlanAreaSum("0");
-                fmsLandTotalResVo.setLandBlockcountSum("0");
-                fmsLandTotalResVo.setLandDevcountSum("0");
-                String jsonString = JSONObject.toJSONString(fmsLandTotalResVo);
-                resultMap.put("landTotal", JSONObject.parseObject(jsonString));
-                return;
-            }
-            List<String> strings2 = dataAuthUtil.blockList();
-            fmsLand.setDataFilter(true);
-            fmsLand.setBlockIds(strings2);
-        }
-
-        FmsLandTotalResVo fmsLandTotalResVo = fmsLandService.selectFmsLandTotal(fmsLand);
-
-        BigDecimal blockArea = fmsBlockService.selectSumAreaByLandId(fmsLand);
-        fmsLandTotalResVo.setBlockAreaSum(blockArea == null ? "0" : blockArea.toString());
-        FmsPlanReqVo fmsPlanReqVo = new FmsPlanReqVo();
-        fmsPlanReqVo.setLandId(fmsLand.getLandId());
-        fmsPlanReqVo.setPlanStatus(CommonEnums.PLAN_STATUS_START.getCode());
-        BigDecimal planArea = fmsPlanService.selectSumPlanArea(fmsPlanReqVo);
-        fmsLandTotalResVo.setPlanAreaSum(planArea == null ? "0" : planArea.toString());
-        int count = fmsPlanService.selectCountFmsPlan(fmsPlanReqVo);
-        fmsLandTotalResVo.setPlanCropTypeNum(String.valueOf(count));
-
-        if(null != planArea&&null != blockArea){
-            BigDecimal divide = planArea.multiply(new BigDecimal(100)).divide(blockArea, 2, BigDecimal.ROUND_HALF_UP);
-            fmsLandTotalResVo.setBlockUsageRate(divide.toString());
-        }else {
-            fmsLandTotalResVo.setBlockUsageRate("0");
-        }
-        String jsonString = JSONObject.toJSONString(fmsLandTotalResVo);
-        resultMap.put("landTotal", JSONObject.parseObject(jsonString));
-    }
-
-    public void getTaskStat(ScreenDataReqVo reqVo, Map<String, Object> resultMap, boolean isValid) {
-        Map<String, Object> countMap = new HashMap<>();
-        FmsTaskListReqVo reqVo1 = new FmsTaskListReqVo();
-        reqVo1.setLandId(reqVo.getLandId());
-        reqVo1.setBlockId(reqVo.getBlockId());
-
-        if (isValid) {
-            List<String> strings = dataAuthUtil.blockList();
-            if (strings.isEmpty()) {
-                countMap.put("count1", new JSONArray());
-                countMap.put("count2", new JSONArray());
-                countMap.put("count3", new JSONArray());
-                resultMap.put("taskTypeCount", countMap);
-                return;
-            }
-            reqVo1.setDataFilter(true);
-            reqVo1.setBlockIds(strings);
-        }
-
-
-//        reqVo.setTaskAuditstatus(TaskStatus.COMPLETED.getCode());
-//        reqVo.setTaskAudittype(CommonEnums.TASK_AUDIT_TYPE_DOWN.getCode() + "," + CommonEnums.TASK_AUDIT_TYPE_UP.getCode());
-        reqVo1.setStartDate(LocalDateTime.now().with(WeekFields.of(Locale.FRANCE).dayOfWeek(), 1).with(LocalTime.MIN).format(DateTimeFormatter.ofPattern(CommonEnums.PATTERN_DATETIME.getCode())));
-        reqVo1.setEndDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern(CommonEnums.PATTERN_DATETIME.getCode())));
-        List<FmsTaskTypeCountResVo> typeCounts1 = fmsTaskService.selectCountFmsTaskByType(reqVo1);
-        reqVo1.setStartDate(LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN).format(DateTimeFormatter.ofPattern(CommonEnums.PATTERN_DATETIME.getCode())));
-        reqVo1.setEndDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern(CommonEnums.PATTERN_DATETIME.getCode())));
-        List<FmsTaskTypeCountResVo> typeCounts2 = fmsTaskService.selectCountFmsTaskByType(reqVo1);
-        reqVo1.setStartDate(LocalDateTime.now().with(TemporalAdjusters.firstDayOfYear()).with(LocalTime.MIN).format(DateTimeFormatter.ofPattern(CommonEnums.PATTERN_DATETIME.getCode())));
-        reqVo1.setEndDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern(CommonEnums.PATTERN_DATETIME.getCode())));
-        List<FmsTaskTypeCountResVo> typeCounts3 = fmsTaskService.selectCountFmsTaskByType(reqVo1);
-
-        String count1 = JSONObject.toJSONString(typeCounts1);
-        String count2 = JSONObject.toJSONString(typeCounts2);
-        String count3 = JSONObject.toJSONString(typeCounts3);
-        countMap.put("count1", JSON.parseArray(count1));
-        countMap.put("count2", JSON.parseArray(count2));
-        countMap.put("count3", JSON.parseArray(count3));
-        resultMap.put("taskTypeCount", countMap);
+    /**
+     * 拼装基地统计数据
+     * @param fmsConsoleStatResVo 被拼装的数据对象
+     * @param landIds 基地标识,用于数据过滤
+     * */
+    private void appendLandStat(FmsConsoleStatResVo fmsConsoleStatResVo,List<String> landIds){
+        FmsLand fmsLandQuery = new FmsLand();
+        fmsLandQuery.setLandIds(landIds);
+        List<FmsLand> fmsLandList = fmsLandService.selectFmsLandList(fmsLandQuery);
+        // 计算基地总数
+        fmsConsoleStatResVo.setLandTotalNum(new BigDecimal(fmsLandList.size()));
+        // 计算基地总面积
+        fmsConsoleStatResVo.setLandTotalArea(fmsLandList.stream().map(FmsLand::getLandArea).reduce(BigDecimal.ZERO,BigDecimal::add));
     }
-
-    public void getPlanStat(ScreenDataReqVo reqVo, Map<String, Object> resultMap, boolean isValid) {
-        FmsPlanReqVo reqVo2 = new FmsPlanReqVo();
-        reqVo2.setLandId(reqVo.getLandId());
-        reqVo2.setBlockId(reqVo.getBlockId());
-        reqVo2.setPlanStatus(CommonEnums.PLAN_STATUS_START.getCode());
-        reqVo2.setTid(SecurityUtils.getTid());
-        if (isValid) {
-            List<String> strings = dataAuthUtil.blockList();
-            reqVo2.setDataFilter(true);
-            reqVo2.setBlockIds(strings);
-        }
-
-        List<FmsPlanResVo> fmsPlanResVos = fmsPlanService.selectPlanByCropNameAndType(reqVo2);
-        BigDecimal total = new BigDecimal("0");
-        for (FmsPlanResVo fmsPlanResVo : fmsPlanResVos) {
-            total = total.add(fmsPlanResVo.getPlanArea());
-        }
-        JSONArray jsonArray = new JSONArray();
-        for (FmsPlanResVo fmsPlanResVo : fmsPlanResVos) {
-            BigDecimal divide = fmsPlanResVo.getPlanArea().multiply(new BigDecimal(100)).divide(total, 2, BigDecimal.ROUND_HALF_UP);
-            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(fmsPlanResVo));
-            jsonObject.put("rate", divide);
-            jsonArray.add(jsonObject);
-        }
-
-        resultMap.put("fmsPlanStat", jsonArray);
+    /**
+     * 拼装地块统计数据
+     * @param fmsConsoleStatResVo 被拼装的数据对象
+     * @param blockIds 地块标识,用于数据过滤
+     * */
+    private void appendBlockStat(FmsConsoleStatResVo fmsConsoleStatResVo,List<String> blockIds){
+        FmsBlock fmsBlockQuery = new FmsBlock();
+        fmsBlockQuery.setBlockIds(blockIds);
+        List<FmsBlock> fmsBlockList = fmsBlockService.selectFmsBlockList(fmsBlockQuery);
+        // 计算地块总数
+        fmsConsoleStatResVo.setBlockTotalNum(new BigDecimal(fmsBlockList.size()));
+        // 计算地块总面积
+        fmsConsoleStatResVo.setBlockTotalArea(fmsBlockList.stream().map(FmsBlock::getBlockArea).reduce(BigDecimal.ZERO,BigDecimal::add));
     }
-
-
-
-    private Map<String, Object> getMoney(SelectOfTssStatReqVo reqVo) {
-        Double incomeTotal = 0.0;// 总收入
-        Double payTotal = 0.0;// 总支出()
-
-        Double wlSum = 0.0;// 物流费用
-
-        Double nzSum = 0.0;// 农资费用
-        Double njSum = 0.0;// 农机费用
-        Double rgSum = 0.0;// 人工费用
-
-        Double jgSum = 0.0;// 加工费用
-        Double bzSum = 0.0;// 包装费用
-        Double csSum = 0.0;// 采收费用
-        // 物流费用
-        /*Map<String, Object> orderMap = spmOrderService.selectMoneyOfTssTrace(reqVo);
-        if (orderMap != null) {
-            incomeTotal = Double.parseDouble(orderMap.get("incomeSum").toString());
-            wlSum = Double.parseDouble(orderMap.get("wlSum").toString());
-        }*/
-
-        // 农产品费用(采收,加工,包装)
-        /*List<Map<String, Object>> goodsList = spmOrderService.selectFinishgoodsMoneyOfTssTrace(reqVo);
-        if (goodsList != null) {
-            for (Map<String, Object> goodsMap : goodsList) {
-                if ("0".equals(goodsMap.get("finishgoodsType").toString())) {// 采收产品
-                    csSum = Double.parseDouble((goodsMap.get("sum") == null) ? "0" : goodsMap.get("sum").toString());
-                } else if ("1".equals(goodsMap.get("finishgoodsType").toString())) {// 加工产品
-                    jgSum = Double.parseDouble((goodsMap.get("sum") == null) ? "0" : goodsMap.get("sum").toString());
-                } else if ("2".equals(goodsMap.get("finishgoodsType").toString())) {// 包装产品
-                    bzSum = Double.parseDouble((goodsMap.get("sum") == null) ? "0" : goodsMap.get("sum").toString());
-                }
-            }
-        }*/
-
-        // 农活费用(人工,农机,农资)
-        Map<String, Object> farmMap = fmsTaskService.selectSumTaskrcdMoney(reqVo);
-        if (farmMap != null) {
-            rgSum = Double.parseDouble((farmMap.get("rgSum") == null) ? "0" : farmMap.get("rgSum").toString());
-            nzSum = Double.parseDouble((farmMap.get("nzSum") == null) ? "0" : farmMap.get("nzSum").toString());
-            njSum = Double.parseDouble((farmMap.get("njSum") == null) ? "0" : farmMap.get("njSum").toString());
+    /**
+     * 拼装种植统计数据
+     * @param fmsConsoleStatResVo 被拼装的数据对象
+     * @param blockIds 地块标识,用于数据过滤
+     * */
+    private void appendPlanStat(FmsConsoleStatResVo fmsConsoleStatResVo,List<String> blockIds){
+        FmsPlan fmsPlanQuery = new FmsPlan();
+        fmsPlanQuery.setBlockIds(blockIds);
+        List<FmsPlan> fmsPlanList = fmsPlanService.selectFmsPlanList(fmsPlanQuery);
+        Set<String> blockIdSet = new HashSet<>();
+        Set<String> cropIdSet = new HashSet<>();
+        BigDecimal planArea = new BigDecimal("0");
+        for(FmsPlan fmsPlan : fmsPlanList){
+            blockIdSet.add(fmsPlan.getBlockId());
+            cropIdSet.add(fmsPlan.getCropId());
+            planArea.add(fmsPlan.getPlanArea());
         }
-
-        // 总支出
-        payTotal = payTotal + wlSum + csSum + jgSum + bzSum + nzSum + njSum + rgSum;
-
-        Map<String, Object> resultMap = new HashMap<>();
-        resultMap.put("incomeTotal", incomeTotal);
-        resultMap.put("payTotal", payTotal);
-        resultMap.put("wlSum", wlSum);
-        resultMap.put("nzSum", nzSum);
-        resultMap.put("njSum", njSum);
-        resultMap.put("rgSum", rgSum);
-        resultMap.put("jgSum", jgSum);
-        resultMap.put("bzSum", bzSum);
-        resultMap.put("csSum", csSum);
-        List<Map<String, Object>> payMxList = new ArrayList<Map<String, Object>>();
-        Map<String, Object> mxMap = null;
-        mxMap = new HashMap<>();
-        mxMap.put("key", "wlSum");
-        mxMap.put("title", "物流");
-        mxMap.put("value", wlSum);
-        payMxList.add(mxMap);
-
-        mxMap = new HashMap<>();
-        mxMap.put("key", "nzSum");
-        mxMap.put("title", "农资");
-        mxMap.put("value", nzSum);
-        payMxList.add(mxMap);
-
-        mxMap = new HashMap<>();
-        mxMap.put("key", "njSum");
-        mxMap.put("title", "农机");
-        mxMap.put("value", njSum);
-        payMxList.add(mxMap);
-
-        mxMap = new HashMap<>();
-        mxMap.put("key", "rgSum");
-        mxMap.put("title", "人工");
-        mxMap.put("value", rgSum);
-        payMxList.add(mxMap);
-
-        mxMap = new HashMap<>();
-        mxMap.put("key", "bzSum");
-        mxMap.put("title", "包装");
-        mxMap.put("value", bzSum);
-        payMxList.add(mxMap);
-
-        mxMap = new HashMap<>();
-        mxMap.put("key", "jgSum");
-        mxMap.put("title", "加工");
-        mxMap.put("value", jgSum);
-        payMxList.add(mxMap);
-
-        mxMap = new HashMap<>();
-        mxMap.put("key", "csSum");
-        mxMap.put("title", "采收");
-        mxMap.put("value", csSum);
-        payMxList.add(mxMap);
-        resultMap.put("payMxList", payMxList);
-
-        return resultMap;
+        // 计算种植作物种类
+        fmsConsoleStatResVo.setCropTypeNum(new BigDecimal(cropIdSet.size()));
+        // 计算已使用的地块数量
+        fmsConsoleStatResVo.setBlockUsedNum(new BigDecimal(blockIdSet.size()));
+        // 计算未使用的地块数量
+        fmsConsoleStatResVo.setBlockUnUsedNum(fmsConsoleStatResVo.getBlockTotalNum().subtract(fmsConsoleStatResVo.getBlockUsedNum()));
+        // 计算地块使用率
+        fmsConsoleStatResVo.setBlockUsageRate(planArea.divide(fmsConsoleStatResVo.getBlockTotalArea(),2, RoundingMode.HALF_UP));
     }
-
 }

+ 17 - 0
src/main/java/com/yunfeiyun/agmp/fms/domain/resvo/FmsConsoleStatResVo.java

@@ -0,0 +1,17 @@
+package com.yunfeiyun.agmp.fms.domain.resvo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class FmsConsoleStatResVo {
+    private BigDecimal landTotalNum;
+    private BigDecimal landTotalArea;
+    private BigDecimal blockTotalNum;
+    private BigDecimal blockTotalArea;
+    private BigDecimal cropTypeNum;
+    private BigDecimal blockUsageRate;
+    private BigDecimal blockUsedNum;
+    private BigDecimal blockUnUsedNum;
+}

+ 11 - 0
src/main/java/com/yunfeiyun/agmp/fms/domain/resvo/FmsCropPlanAreaResVo.java

@@ -0,0 +1,11 @@
+package com.yunfeiyun.agmp.fms.domain.resvo;
+
+import lombok.Data;
+
+@Data
+public class FmsCropPlanAreaResVo {
+    private String cropId;
+    private String cropName;
+    private String cropType;
+    private String planArea;
+}

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/fms/mapper/FmsCropMapper.java

@@ -73,4 +73,6 @@ public interface FmsCropMapper
      * @return 结果
      */
     public int deleteFmsCropByCropIds(@Param("array") String[] cropIds, @Param("tid") String tid);
+
+    List<FmsCrop> selectFmsCropListByCropIds(@Param("cropIds") List<String> cropIds);
 }

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/fms/mapper/FmsLandMapper.java

@@ -95,4 +95,6 @@ public interface FmsLandMapper
     List<String> selectUserManagerWarehouseLandIds(@Param("userId") String userId, @Param("tid") String tid);
 
     public List<FmsLandListByDeviceBindResVo> selectFmsLandListByDeviceBind(String tid);
+
+    List<String> selectLandIdByUser(@Param("userId") String userId,@Param("tid") String tid);
 }

+ 3 - 0
src/main/java/com/yunfeiyun/agmp/fms/mapper/FmsPlanMapper.java

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.fms.mapper;
 import com.yunfeiyun.agmp.fms.domain.FmsPlan;
 import com.yunfeiyun.agmp.fms.domain.dto.FmsPlanByWarnSchedulerDto;
 import com.yunfeiyun.agmp.fms.domain.reqvo.FmsPlanReqVo;
+import com.yunfeiyun.agmp.fms.domain.resvo.FmsCropPlanAreaResVo;
 import com.yunfeiyun.agmp.fms.domain.resvo.FmsPlanListOfTaskStatusResVo;
 import com.yunfeiyun.agmp.fms.domain.resvo.FmsPlanResVo;
 import org.apache.ibatis.annotations.Param;
@@ -111,4 +112,6 @@ public interface FmsPlanMapper
     public List<FmsPlanListOfTaskStatusResVo> selectPlanListOfTaskStatus(Map<String, Object> param);
 
     List<String> selectBlockManagerByPlanId(@Param("planId") String planId, @Param("tid") String tid);
+
+    List<FmsCropPlanAreaResVo> selectCropPlanAreaTop(@Param("blockIds") List<String> blockIds);
 }

+ 2 - 1
src/main/java/com/yunfeiyun/agmp/fms/mapper/FmsSolarMapper.java

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.fms.mapper;
 import com.yunfeiyun.agmp.fms.domain.FmsSolar;
 import com.yunfeiyun.agmp.fms.domain.vo.FmsSolarVo;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.security.core.parameters.P;
 
 import java.util.List;
 
@@ -108,7 +109,7 @@ public interface FmsSolarMapper
      * @param date 日期(yyyy-MM-dd)
      * @return 节气
      * */
-    public FmsSolarVo getFmsSolarByDate(String startDate);
+    public FmsSolarVo getFmsSolarByDate(@Param("solarStartdate") String solarStartdate,@Param("tid") String tid);
 
 
     public FmsSolarVo selectFmsSolarinfoBySolarId(@Param("solarId") String solarId, @Param("tid") String tid);

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/fms/service/IFmsCropService.java

@@ -68,4 +68,6 @@ public interface IFmsCropService
      * @return 结果
      */
     public int deleteFmsCropByCropId(String cropId, String tid);
+
+    List<FmsCrop> selectFmsCropListByCropIds(List<String> cropIds);
 }

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/fms/service/IFmsLandService.java

@@ -72,6 +72,7 @@ public interface IFmsLandService
     public int deleteFmsLandByLandId(String landId, String tid);
 
     List<String> selectUserManagerWarehouseLandIds(String userId, String tid);
+    List<String> selectLandIdByUser(String userId,String tid);
 
     <T> void appendLandNameByTid(List<T> data);
 

+ 3 - 0
src/main/java/com/yunfeiyun/agmp/fms/service/IFmsPlanService.java

@@ -4,6 +4,7 @@ import com.yunfeiyun.agmp.fms.domain.FmsBlock;
 import com.yunfeiyun.agmp.fms.domain.FmsPlan;
 import com.yunfeiyun.agmp.fms.domain.dto.FmsPlanByWarnSchedulerDto;
 import com.yunfeiyun.agmp.fms.domain.reqvo.FmsPlanReqVo;
+import com.yunfeiyun.agmp.fms.domain.resvo.FmsCropPlanAreaResVo;
 import com.yunfeiyun.agmp.fms.domain.resvo.FmsPlanDocumentResVo;
 import com.yunfeiyun.agmp.fms.domain.resvo.FmsPlanListOfTaskStatusResVo;
 import com.yunfeiyun.agmp.fms.domain.resvo.FmsPlanResVo;
@@ -111,4 +112,6 @@ public interface IFmsPlanService
      * @return 种植计划集合
      */
     public List<FmsPlanByWarnSchedulerDto> selectPlanListByWarnScheduler(String planEnddate, String tid);
+
+    List<FmsCropPlanAreaResVo> selectCropPlanAreaTop(List<String> blockIds);
 }

+ 6 - 0
src/main/java/com/yunfeiyun/agmp/fms/service/impl/FmsCropServiceImpl.java

@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -166,5 +167,10 @@ public class FmsCropServiceImpl implements IFmsCropService
         return fmsCropMapper.deleteFmsCropByCropId(cropId,tid);
     }
 
+    @Override
+    public List<FmsCrop> selectFmsCropListByCropIds(List<String> cropIds) {
+        return fmsCropMapper.selectFmsCropListByCropIds(cropIds);
+    }
+
 
 }

+ 5 - 0
src/main/java/com/yunfeiyun/agmp/fms/service/impl/FmsLandServiceImpl.java

@@ -155,6 +155,11 @@ public class FmsLandServiceImpl implements IFmsLandService
     }
 
     @Override
+    public List<String> selectLandIdByUser(String userId, String tid) {
+        return fmsLandMapper.selectLandIdByUser(userId,tid);
+    }
+
+    @Override
     public <T> void appendLandNameByTid(List<T> data) {
         if(data.isEmpty()){
             return;

+ 6 - 0
src/main/java/com/yunfeiyun/agmp/fms/service/impl/FmsPlanServiceImpl.java

@@ -14,6 +14,7 @@ import com.yunfeiyun.agmp.fms.domain.FmsPlan;
 import com.yunfeiyun.agmp.fms.domain.dto.FmsPlanByWarnSchedulerDto;
 import com.yunfeiyun.agmp.fms.domain.reqvo.FmsPlanReqVo;
 import com.yunfeiyun.agmp.fms.domain.reqvo.FmsTaskrcdListReqVo;
+import com.yunfeiyun.agmp.fms.domain.resvo.FmsCropPlanAreaResVo;
 import com.yunfeiyun.agmp.fms.domain.resvo.FmsPlanDocumentResVo;
 import com.yunfeiyun.agmp.fms.domain.resvo.FmsPlanListOfTaskStatusResVo;
 import com.yunfeiyun.agmp.fms.domain.resvo.FmsPlanResVo;
@@ -430,6 +431,11 @@ public class FmsPlanServiceImpl implements IFmsPlanService {
         return fmsPlanMapper.selectPlanListByWarnScheduler(planEnddate,tid);
     }
 
+    @Override
+    public List<FmsCropPlanAreaResVo> selectCropPlanAreaTop(List<String> blockIds) {
+        return fmsPlanMapper.selectCropPlanAreaTop(blockIds);
+    }
+
     private String dateStrAdd(String data,Integer days){
         Calendar calendar = Calendar.getInstance();
         try {

+ 2 - 2
src/main/java/com/yunfeiyun/agmp/fms/service/impl/FmsSolarServiceImpl.java

@@ -113,9 +113,9 @@ public class FmsSolarServiceImpl implements IFmsSolarService
 
     @Override
     public FmsSolarVo getNowSolar(String date, String tid) {
-        FmsSolarVo fmsSolar = fmsSolarMapper.getFmsSolarByDate(date);
+        FmsSolarVo fmsSolar = fmsSolarMapper.getFmsSolarByDate(date,tid);
         if(null == fmsSolar){
-            return fmsSolarMapper.getFmsSolarByDate(null);
+            return fmsSolarMapper.getFmsSolarByDate(null,tid);
         }
         return fmsSolar;
     }

+ 3 - 4
src/main/java/com/yunfeiyun/agmp/fms/util/DataAuthUtil.java

@@ -45,16 +45,15 @@ public class DataAuthUtil
      * 查询基地列表(包含所分配的基地以及所分配地块所属的基地)
      */
     public List<String> landListOfBlock() {
-        List<FmsLand> fmsLands = fmsBlockMapper.selectFmsLandByBlockIds(this.blockList().toArray(new String[]{}),SecurityUtils.getTid());
-        return fmsLands.stream().map(FmsLand::getLandId).collect(Collectors.toList());
+        return fmsLandService.selectLandIdByUser(SecurityUtils.getUserId(),SecurityUtils.getTid());
     }
 
+
     /**
      * 查询分配的地块列表
      */
     public List<String> blockList() {
-        List<String> blockIds = fmsBlockService.userBindList(SecurityUtils.getUserId(),SecurityUtils.getTid());
-        return blockIds;
+        return fmsBlockService.userBindList(SecurityUtils.getUserId(),SecurityUtils.getTid());
     }
 
     public boolean checkRole(String roleKey){

+ 12 - 0
src/main/resources/mapper/FmsCropMapper.xml

@@ -131,4 +131,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
         and tid = #{tid}
     </delete>
+
+    <select id="selectFmsCropListByCropIds" resultType="com.yunfeiyun.agmp.fms.domain.FmsCrop">
+        <include refid="selectFmsCropVo"/>
+        <where>
+            <if test="cropIds != null and cropIds.size() != 0">
+                cropId in
+                <foreach collection="cropIds" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+    </select>
 </mapper>

+ 12 - 0
src/main/resources/mapper/FmsLandMapper.xml

@@ -263,4 +263,16 @@
         ) AS t ON f.landId = t.landId
         GROUP BY f.landId
     </select>
+
+    <select id="selectLandIdByUser" resultType="java.lang.String">
+        select
+        DISTINCT(fl.landId)
+        from FmsLand fl
+        INNER JOIN
+        FmsBlock fb on fb.landId = fl.landId
+        where fb.blockId in
+        (
+          select blockId from FmsBlockUser where userId = #{userId} and tid = #{tid}
+        )
+    </select>
 </mapper>

+ 19 - 0
src/main/resources/mapper/FmsPlanMapper.xml

@@ -491,4 +491,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where fp.planId = #{planId}
         <if test="tid != null and tid !='' and tid != '-1'">and fp.tid = #{tid}</if>
     </select>
+
+    <select id="selectCropPlanAreaTop" resultType="com.yunfeiyun.agmp.fms.domain.resvo.FmsCropPlanAreaResVo">
+        SELECT
+        sum( planArea ) planArea,
+        cropId
+        FROM
+        FmsPlan
+        <where>
+            <if test="blockIds != null and blockIds.size() != 0">
+                and blockId in
+                <foreach collection="blockIds" item="item" index="index" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+        GROUP BY cropId
+        ORDER BY sum( planArea ) DESC
+
+    </select>
 </mapper>