wangbo 4 years ago
parent
commit
3c6ef58224

+ 51 - 25
sms_water/src/main/java/com/huaxu/controller/AppPageReportController.java

@@ -17,9 +17,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @description
@@ -33,9 +36,6 @@ public class AppPageReportController {
     @Autowired
     private AppPageReportService appPageReportService;
 
-    @Autowired
-    private RevenueService revenueService;
-
     /**
      * App生产总览数据-本月数据
      * @param companyOrgId
@@ -43,48 +43,74 @@ public class AppPageReportController {
      */
     @RequestMapping(value = "getProductionDataForSameMonth",method = RequestMethod.GET)
     @ApiOperation(value = "App总览——生产数据(本月)")
-    public AjaxMessage<List<DeviceWaterSupply>> getProductionDataForMonth(
+    public AjaxMessage<Map<String,Object>> getProductionDataForMonth(
             @ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
-        List<DeviceWaterSupply>  result = new ArrayList<DeviceWaterSupply>();
-        result.addAll(appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,1));
-        result.addAll(appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,1));
-        result.addAll(appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,1));
-        return new AjaxMessage<>(ResultStatus.OK,result);
+        Map<String,Object> map = new HashMap<String,Object>();
+        List<DeviceWaterSupply> makingWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,1);
+        List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,1);
+        map.put("取水量",appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,1));
+        map.put("制水量",makingWaterList);
+        map.put("售水量",sellerWaterList);
+        map.put("产销差",CalculationNrw(makingWaterList,sellerWaterList));
+        return new AjaxMessage<>(ResultStatus.OK,map);
     }
 
-
-
     /**
      * App生产总览数据-本年数据
      * @param companyOrgId
      * @return
      */
     @RequestMapping(value = "getProductionDataForSameYear",method = RequestMethod.GET)
-    @ApiOperation(value = "App总览——生产数据(本)")
-    public AjaxMessage<List<DeviceWaterSupply>> getProductionDataForSameYear(
+    @ApiOperation(value = "App总览——生产数据(本)")
+    public AjaxMessage<Map<String,Object>> getProductionDataForSameYear(
             @ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
         LocalDate localDate = LocalDate.now();
-        List<DeviceWaterSupply>  result = new ArrayList<DeviceWaterSupply>();
-        result.addAll(appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,localDate.getMonthValue()));
-        result.addAll(appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,localDate.getMonthValue()));
-        result.addAll(appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,localDate.getMonthValue()));
-        return new AjaxMessage<>(ResultStatus.OK,result);
+        Map<String,Object> map = new HashMap<String,Object>();
+        List<DeviceWaterSupply> makingWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,localDate.getMonthValue());
+        List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,localDate.getMonthValue());
+        map.put("取水量",appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,localDate.getMonthValue()));
+        map.put("制水量",makingWaterList);
+        map.put("售水量",sellerWaterList);
+        map.put("产销差",CalculationNrw(makingWaterList,sellerWaterList));
+
+        return new AjaxMessage<>(ResultStatus.OK,map);
     }
 
 
+
     /**
      * App生产总览数据-近一年数据
      * @param companyOrgId
      * @return
      */
     @RequestMapping(value = "getProductionDataFor12Month",method = RequestMethod.GET)
-    @ApiOperation(value = "App总览——生产数据(本月)")
-    public AjaxMessage<List<DeviceWaterSupply>> getProductionDataFor12Month(
+    @ApiOperation(value = "App总览——生产数据(近一年)")
+    public AjaxMessage<Map<String,Object>> getProductionDataFor12Month(
             @ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
-        List<DeviceWaterSupply>  result = new ArrayList<DeviceWaterSupply>();
-        result.addAll(appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,12));
-        result.addAll(appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,12));
-        result.addAll(appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,12));
-        return new AjaxMessage<>(ResultStatus.OK,result);
+        Map<String,Object> map = new HashMap<String,Object>();
+        List<DeviceWaterSupply> makingWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,12);
+        List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,12);
+        map.put("取水量",appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,12));
+        map.put("制水量",makingWaterList);
+        map.put("售水量",sellerWaterList);
+        map.put("产销差",CalculationNrw(makingWaterList,sellerWaterList));
+
+        return new AjaxMessage<>(ResultStatus.OK,map);
+    }
+
+    private BigDecimal CalculationNrw( List<DeviceWaterSupply> makingWaterList,List<DeviceWaterSupply> sellerWaterList){
+        BigDecimal makingWaterAmount = new BigDecimal("0");
+        BigDecimal sellerWaterAmount = new BigDecimal("0");
+        for(DeviceWaterSupply water : makingWaterList){
+            makingWaterAmount.add(water.getAmount());
+        }
+
+        for(DeviceWaterSupply water : sellerWaterList){
+            sellerWaterAmount.add(water.getAmount());
+        }
+
+        BigDecimal nrw = makingWaterAmount.subtract(sellerWaterAmount).multiply(new BigDecimal("100")).divide(makingWaterAmount,2);
+
+        return nrw;
     }
 }

+ 1 - 1
sms_water/src/main/java/com/huaxu/service/impl/HomePageReportServiceImpl.java

@@ -113,7 +113,7 @@ public class HomePageReportServiceImpl implements HomePageReportService {
         deviceWaterSupplyMonth.setDateLabel(localDate.getYear()+"-"+localDate.getMonthValue());
         deviceWaterSupplies.add(0, deviceWaterSupplyMonth);
 
-        for (int i = 0; i < 6; i++) {
+        for (int i = 1; i < month; i++) {
             LocalDate newLocalDate = localDate.plusMonths(-i );
             if (i == deviceWaterSupplies.size()
                     || newLocalDate.getMonthValue() != deviceWaterSupplies.get(i).getMonth().intValue()