Przeglądaj źródła

App总览-生产数据-环比

wangbo 4 lat temu
rodzic
commit
4c683b3bf1

+ 13 - 10
sms_water/src/main/java/com/huaxu/controller/AppPageReportController.java

@@ -105,7 +105,7 @@ public class AppPageReportController {
     @ApiOperation(value = "App总览——生产数据-取水环比(本月)")
     public AjaxMessage<Object> getSameMonthComparison(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
         LocalDate now = LocalDate.now();
-        LocalDate last = now.minusMonths(-1);
+        LocalDate last = now.minusMonths(1);
         Map<String,Object> map = new HashMap<String,Object>();
 
         List<DeviceWaterSupply> sameMakingWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水源",4, now.getYear(),now.getMonthValue(),1, now.getYear(),now.getMonthValue(),now.getDayOfMonth());
@@ -121,7 +121,7 @@ public class AppPageReportController {
         map.put("makingComparison",appPageReportService.CalculationComparison(sameSupplyWaterList,lastSupplyWaterList));
 
         List<DeviceWaterSupply> sameSellerWaterList = appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,2);
-        BigDecimal comparison = sameSellerWaterList.get(0).getAmount() ==BigDecimal.ZERO ? BigDecimal.ZERO : sameSellerWaterList.get(0).getAmount().multiply(new BigDecimal(100)).divide(sameSellerWaterList.get(1).getAmount(),2);
+        BigDecimal comparison = sameSellerWaterList.get(0).getAmount().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sameSellerWaterList.get(0).getAmount().multiply(new BigDecimal(100)).divide(sameSellerWaterList.get(1).getAmount(),2);
         map.put("sellerComparison",comparison);
         return new AjaxMessage<>(ResultStatus.OK,map);
     }
@@ -130,7 +130,7 @@ public class AppPageReportController {
     @ApiOperation(value = "App总览——生产数据-取水环比、供水环比、售水环比(本年)")
     public AjaxMessage<Object> getWaterIntakeComparison(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
         LocalDate now = LocalDate.now();
-        LocalDate last = now.minusYears(-1);
+        LocalDate last = now.minusYears(1);
         Map<String,Object> map = new HashMap<String,Object>();
         List<DeviceWaterSupply> sameMakingWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水源",4, now.getYear(),1,1, now.getYear(),now.getMonthValue(),now.getDayOfMonth());
         List<DeviceWaterSupply> lastMakingWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水源",4, last.getYear(),1,1, last.getYear(),12,31);
@@ -142,14 +142,14 @@ public class AppPageReportController {
         BigDecimal lastSellerAmount = new BigDecimal(0);
 
         for( int i =0 ;i<sellerWaterList.size(); i++){
-            if(i<now.getMonthValue()){
+            if(i>=12){
                 sameSellerAmount = sameSellerAmount.add(sellerWaterList.get(i).getAmount());
             }
             else{
                 lastSellerAmount = lastSellerAmount.add(sellerWaterList.get(i).getAmount());
             }
         }
-        BigDecimal comparison = lastSellerAmount ==BigDecimal.ZERO ? BigDecimal.ZERO : sameSellerAmount.multiply(new BigDecimal(100)).divide(lastSellerAmount,2);
+        BigDecimal comparison = lastSellerAmount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sameSellerAmount.multiply(new BigDecimal(100)).divide(lastSellerAmount,2);
         map.put("intakeComparison",appPageReportService.CalculationComparison(sameMakingWaterList,lastMakingWaterList));
         map.put("makingComparison",appPageReportService.CalculationComparison(sameSupplyWaterList,lastSupplyWaterList));
         map.put("sellerComparison",comparison);
@@ -160,11 +160,14 @@ public class AppPageReportController {
     @ApiOperation(value = "App总览——生产数据-取水环比、供水环比、售水环比(近一年)")
     public AjaxMessage<Object> getLast12YearComparison(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
         LocalDate now = LocalDate.now();
-        LocalDate last = now.minusYears(-1);
+        LocalDate last = now.minusMonths(11);
+
         Map<String,Object> map = new HashMap<String,Object>();
-        List<DeviceWaterSupply> sameMakingWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水源",4, now.getYear(),1,1, now.getYear(),now.getMonthValue(),now.getDayOfMonth());
-        List<DeviceWaterSupply> lastMakingWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水源",4, last.getYear(),1,1, last.getYear(),12,31);
-        List<DeviceWaterSupply> sameSupplyWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水厂",3, now.getYear(),1,1, now.getYear(),now.getMonthValue(),now.getDayOfMonth());
+        List<DeviceWaterSupply> sameMakingWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水源",4, last.getYear(),last.getMonthValue(),last.getDayOfMonth(), now.getYear(),now.getMonthValue(),now.getDayOfMonth());
+        List<DeviceWaterSupply> sameSupplyWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水厂",3, last.getYear(),last.getMonthValue(),last.getDayOfMonth(),now.getYear(),now.getMonthValue(),now.getDayOfMonth());
+        LocalDate last2 = last.minusDays(1);
+        LocalDate last3 = last2.minusMonths(11);
+        List<DeviceWaterSupply> lastMakingWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水源",4, last3.getYear(),last2.getMonthValue(),last2.getDayOfMonth(), last.getYear(),12,31);
         List<DeviceWaterSupply> lastSupplyWaterList = appPageReportService.deviceWaterReportForDay(companyOrgId,"水厂",3, last.getYear(),1,1, last.getYear(),12,31);
         List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,now.getMonthValue()+12);
 
@@ -179,7 +182,7 @@ public class AppPageReportController {
                 lastSellerAmount = lastSellerAmount.add(sellerWaterList.get(i).getAmount());
             }
         }
-        BigDecimal comparison = lastSellerAmount ==BigDecimal.ZERO ? BigDecimal.ZERO : sameSellerAmount.multiply(new BigDecimal(100)).divide(lastSellerAmount,2);
+        BigDecimal comparison = lastSellerAmount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sameSellerAmount.multiply(new BigDecimal(100)).divide(lastSellerAmount,2);
         map.put("intakeComparison",appPageReportService.CalculationComparison(sameMakingWaterList,lastMakingWaterList));
         map.put("makingComparison",appPageReportService.CalculationComparison(sameSupplyWaterList,lastSupplyWaterList));
         map.put("sellerComparison",comparison);

+ 1 - 1
sms_water/src/main/java/com/huaxu/dao/HomePageReportMapper.java

@@ -36,7 +36,7 @@ public interface HomePageReportMapper {
                                                       @Param("month")Integer month);
 
 
-    List<DeviceWaterSupply> deviceWaterReportForDay(@Param("companyOrgId")Integer companyOrgId,
+    List<DeviceWaterSupply> getDeviceWaterForDay(@Param("companyOrgId")Integer companyOrgId,
                                                  @Param("sceneType")String sceneType, @Param("parmType")Integer parmType,
                                                  @Param("tenantId")String tenantId, @Param("userType")String userType,
                                                  @Param("permissonType")Integer permissonType,

+ 0 - 5
sms_water/src/main/java/com/huaxu/service/AppPageReportService.java

@@ -1,10 +1,8 @@
 package com.huaxu.service;
 
-import com.huaxu.dto.MonthRevenueDto;
 import com.huaxu.dto.generalView.DeviceWaterSupply;
 
 import java.math.BigDecimal;
-import java.time.LocalDate;
 import java.util.List;
 import java.util.Map;
 
@@ -20,9 +18,6 @@ public interface AppPageReportService {
     //App数据总览-生产数据-环比-查询时间段内的取水量供水量
     List<DeviceWaterSupply> deviceWaterReportForDay(Integer companyOrgId, String sceneType, Integer parmType, Integer startYear, Integer startMonth, Integer startDay, Integer endYear, Integer endMonth, Integer endDay) ;
 
-    //App数据总览-生产数据-环比
-    //Map<String,Object> getComparison(Integer companyOrgId, LocalDate now, LocalDate last);
-
     BigDecimal CalculationComparison(List<DeviceWaterSupply> sameWaterList, List<DeviceWaterSupply> lastWaterList);
 
     void CalculationNrw(List<DeviceWaterSupply> supplyWaterList, List<DeviceWaterSupply> makingWaterList,List<DeviceWaterSupply> sellerWaterList,Map<String,Object> map);

+ 3 - 26
sms_water/src/main/java/com/huaxu/service/impl/AppPageReportServiceImpl.java

@@ -38,9 +38,6 @@ public class AppPageReportServiceImpl implements AppPageReportService {
     @Resource
     private HomePageReportMapper homePageReportMapper;
 
-//    @Resource
-//    private RevenueMapper revenueMapper;
-
     /**
      * App 总览 前N个月的售水量
      * @param companyOrgId
@@ -128,7 +125,7 @@ public class AppPageReportServiceImpl implements AppPageReportService {
     public List<DeviceWaterSupply> deviceWaterReportForDay(Integer companyOrgId, String sceneType, Integer parmType, Integer startYear, Integer startMonth, Integer startDay, Integer endYear, Integer endMonth, Integer endDay) {
         LoginUser loginUser = UserUtil.getCurrentUser();
         String tenantId = loginUser.getTenantId();
-        List<DeviceWaterSupply> deviceWaterSupplyList = homePageReportMapper.deviceWaterReportForDay(companyOrgId,
+        List<DeviceWaterSupply> deviceWaterSupplyList = homePageReportMapper.getDeviceWaterForDay(companyOrgId,
                 sceneType,parmType ,
                 tenantId,loginUser.getType(),
                 loginUser.getPermissonType(),
@@ -142,26 +139,6 @@ public class AppPageReportServiceImpl implements AppPageReportService {
         return deviceWaterSupplyList;
     }
 
-//    @Override
-//    public Map<String, Object> getComparison(Integer companyOrgId,LocalDate now, LocalDate last) {
-//
-//        Map<String,Object> map = new HashMap<>();
-//        List<DeviceWaterSupply> sameMakingWaterList = deviceWaterReportForDay(companyOrgId,"水源",4, now.getYear(),now.getMonthValue(),1, now.getYear(),now.getMonthValue(),now.getDayOfMonth());
-//
-//        List<DeviceWaterSupply> lastMakingWaterList = deviceWaterReportForDay(companyOrgId,"水源",4, last.getYear(),last.getMonthValue(),1, last.getYear(),last.getMonthValue(),last.getDayOfMonth());
-//
-//        List<DeviceWaterSupply> sameSupplyWaterList = deviceWaterReportForDay(companyOrgId,"水厂",3, now.getYear(),now.getMonthValue(),1, now.getYear(),now.getMonthValue(),now.getDayOfMonth());
-//
-//        List<DeviceWaterSupply> lastSupplyWaterList = deviceWaterReportForDay(companyOrgId,"水厂",3, last.getYear(),last.getMonthValue(),1, last.getYear(),last.getMonthValue(),last.getDayOfMonth());
-//
-//        map.put("intakeComparison",CalculationComparison(sameMakingWaterList,lastMakingWaterList));
-//
-//        map.put("makingComparison",CalculationComparison(sameSupplyWaterList,lastSupplyWaterList));
-//
-//
-//        return map;
-//    }
-
     /**
      * @Author wangbo
      * @Description 计算产销差
@@ -184,7 +161,7 @@ public class AppPageReportServiceImpl implements AppPageReportService {
         for(DeviceWaterSupply water : sellerWaterList){
             sellerWaterAmount = sellerWaterAmount.add(water.getAmount());
         }
-        BigDecimal nrw = makingWaterAmount ==BigDecimal.ZERO ? BigDecimal.ZERO : makingWaterAmount.subtract(sellerWaterAmount).multiply(new BigDecimal(100)).divide(makingWaterAmount,2);
+        BigDecimal nrw = makingWaterAmount.compareTo(BigDecimal.ZERO) == 0  ? BigDecimal.ZERO : makingWaterAmount.subtract(sellerWaterAmount).multiply(new BigDecimal(100)).divide(makingWaterAmount,2);
         map.put("totalIntake",supplyWaterAmount);
         map.put("totalMaking",makingWaterAmount);
         map.put("totallSeller",sellerWaterAmount);
@@ -207,7 +184,7 @@ public class AppPageReportServiceImpl implements AppPageReportService {
         for(DeviceWaterSupply water : lastWaterList){
             lastWaterAmount = lastWaterAmount.add(water.getAmount());
         }
-        BigDecimal comparison = lastWaterAmount ==BigDecimal.ZERO ? BigDecimal.ZERO : sameWaterAmount.multiply(new BigDecimal(100)).divide(lastWaterAmount,2);
+        BigDecimal comparison = lastWaterAmount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sameWaterAmount.multiply(new BigDecimal(100)).divide(lastWaterAmount,2);
         return comparison;
     }
 

+ 2 - 2
sms_water/src/main/resources/mapper/HomePageReportMapper.xml

@@ -486,8 +486,8 @@
             and s.COMPANY_ORG_ID = #{companyOrgId}
         </if>
         and dp.PARM_TYPE = #{parmType} and st.SCENE_TYPE_NAME = #{sceneType}
-        and r.year &gt;= #{startYear} and r.month &gt;= #{startMonth} and r.day &gt;= #{startDay}
-        and r.year &lt;= #{endYear} and r.moth &lt;= #{endMonth} and r.day &lt;= #{endDay}
+        and r.year*365 + r.month*30 +r.day >= #{startYear}*365 + #{startMonth} *30 + #{startDay}
+        and r.year*365 + r.month*30 +r.day &lt;= #{endYear}*365 + #{endMonth} *30 + #{endDay}
         <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
             <if test="permissonType == 5 or permissonType == 2">
                 and ( s.DEPT_ORG_ID in