wangbo 3 years ago
parent
commit
5afac4da13

+ 17 - 16
sms_water/src/main/java/com/huaxu/controller/AppPageReportController.java

@@ -157,7 +157,7 @@ public class AppPageReportController {
 
         List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerAmountReportForMonth(companyOrgId,1);
         BigDecimal sum = sellerWaterList.get(0).getGeneralUserAmount().add(sellerWaterList.get(0).getBigUserAmount());
-        BigDecimal generalRate =sum.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:sellerWaterList.get(0).getGeneralUserAmount().multiply(new BigDecimal(100)).divide(sum,3);
+        BigDecimal generalRate =sum.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:sellerWaterList.get(0).getGeneralUserAmount().multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(sum,3);
 
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("totalReceivable", sellerWaterList.get(0).getReceivableAmount());
@@ -167,7 +167,7 @@ public class AppPageReportController {
         map.put("bigUser",sellerWaterList.get(0).getBigUserAmount());
         map.put("generalUserRate",generalRate);
         map.put("bigUserRate",new BigDecimal(100).subtract(generalRate));
-        map.put("recoveryRate", sellerWaterList.get(0).getReceivableAmount().compareTo(BigDecimal.ZERO)==0? 0 : sellerWaterList.get(0).getReceivedAmount().multiply(new BigDecimal(100)).divide(sellerWaterList.get(0).getReceivableAmount(),3));
+        map.put("recoveryRate", sellerWaterList.get(0).getReceivableAmount().compareTo(BigDecimal.ZERO)==0? 0 : sellerWaterList.get(0).getReceivedAmount().multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(sellerWaterList.get(0).getReceivableAmount(),3));
         return new AjaxMessage<>(ResultStatus.OK,map);
     }
 
@@ -188,7 +188,7 @@ public class AppPageReportController {
         map.put("receivableAmount", sellerWaterList.get(0).getReceivableAmount());
         map.put("receivedAmount", sellerWaterList.get(0).getReceivedAmount());
         map.put("sellerAmount",sellerAmountList.get(0).getAmount());
-        map.put("recoveryRate", sellerWaterList.get(0).getReceivableAmount().compareTo(BigDecimal.ZERO)==0? 0 : sellerWaterList.get(0).getReceivedAmount().multiply(new BigDecimal(100)).divide(sellerWaterList.get(0).getReceivableAmount(),3));
+        map.put("recoveryRate", sellerWaterList.get(0).getReceivableAmount().compareTo(BigDecimal.ZERO)==0? 0 : sellerWaterList.get(0).getReceivedAmount().multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(sellerWaterList.get(0).getReceivableAmount(),3));
         return new AjaxMessage<>(ResultStatus.OK,map);
     }
 
@@ -213,10 +213,10 @@ public class AppPageReportController {
             totalReceivedAmount=totalReceivedAmount.add(amount.getReceivedAmount());
             totalGeneralUser=totalGeneralUser.add(amount.getGeneralUserAmount());
             totalBigUser=totalBigUser.add(amount.getBigUserAmount());
-            amount.setRecoveryRate(totalReceivableAmount.compareTo(BigDecimal.ZERO)==0? BigDecimal.ZERO : totalReceivedAmount.multiply(new BigDecimal(100)).divide(totalReceivableAmount,3));
+            amount.setRecoveryRate(totalReceivableAmount.compareTo(BigDecimal.ZERO)==0? BigDecimal.ZERO : totalReceivedAmount.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(totalReceivableAmount,3));
         }
         BigDecimal sum =totalBigUser.add(totalGeneralUser);
-        BigDecimal generalRate =sum.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:totalGeneralUser.multiply(new BigDecimal(100)).divide(sum,2);
+        BigDecimal generalRate =sum.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:totalGeneralUser.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(sum,2);
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("totalReceivable", totalReceivableAmount);
         map.put("totalReceived",totalReceivedAmount);
@@ -225,7 +225,7 @@ public class AppPageReportController {
         map.put("bigUser",totalBigUser);
         map.put("generalUserRate",generalRate);
         map.put("bigUserRate",new BigDecimal(100).subtract(generalRate));
-        map.put("recoveryRate", totalReceivableAmount.compareTo(BigDecimal.ZERO)==0? 0 : totalReceivedAmount.multiply(new BigDecimal(100)).divide(totalReceivableAmount,3));
+        map.put("recoveryRate", totalReceivableAmount.compareTo(BigDecimal.ZERO)==0? 0 : totalReceivedAmount.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(totalReceivableAmount,3));
         return new AjaxMessage<>(ResultStatus.OK,map);
     }
 
@@ -250,12 +250,12 @@ public class AppPageReportController {
             totalReceivedAmount=totalReceivedAmount.add(amount.getReceivedAmount());
             totalGeneralUser=totalGeneralUser.add(amount.getGeneralUserAmount());
             totalBigUser=totalBigUser.add(amount.getBigUserAmount());
-            amount.setRecoveryRate(totalReceivableAmount.compareTo(BigDecimal.ZERO)==0? BigDecimal.ZERO : totalReceivedAmount.multiply(new BigDecimal(100)).divide(totalReceivableAmount,3));
+            amount.setRecoveryRate(totalReceivableAmount.compareTo(BigDecimal.ZERO)==0? BigDecimal.ZERO : totalReceivedAmount.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(totalReceivableAmount,3));
         }
 
         BigDecimal sum =totalBigUser.add(totalGeneralUser);
-        BigDecimal generalRate =sum.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:totalGeneralUser.multiply(new BigDecimal(100)).divide(sum,3);
-        BigDecimal bigUserRate =sum.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:totalBigUser.multiply(new BigDecimal(100)).divide(sum,3);
+        BigDecimal generalRate =sum.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:totalGeneralUser.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(sum,3);
+        BigDecimal bigUserRate =sum.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:totalBigUser.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(sum,3);
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("totalReceivable", totalReceivableAmount);
         map.put("totalReceived",totalReceivedAmount);
@@ -264,7 +264,7 @@ public class AppPageReportController {
         map.put("bigUser",totalBigUser);
         map.put("generalUserRate",generalRate);
         map.put("bigUserRate",bigUserRate);
-        map.put("recoveryRate", totalReceivableAmount.compareTo(BigDecimal.ZERO)==0? 0 : totalReceivedAmount.multiply(new BigDecimal(100)).divide(totalReceivableAmount,3));
+        map.put("recoveryRate", totalReceivableAmount.compareTo(BigDecimal.ZERO)==0? 0 : totalReceivedAmount.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(totalReceivableAmount,3));
         return new AjaxMessage<>(ResultStatus.OK,map);
     }
 
@@ -274,8 +274,9 @@ public class AppPageReportController {
     public AjaxMessage<Object> getSellerComparisonForSameMonth(@ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
 
         List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerAmountReportForMonth(companyOrgId,2);
-        BigDecimal receivableComparison = sellerWaterList.get(0).getReceivableAmount().compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:sellerWaterList.get(1).getReceivableAmount().subtract(sellerWaterList.get(0).getReceivableAmount()).multiply(new BigDecimal(100)).divide(sellerWaterList.get(0).getReceivableAmount(),3);
-        BigDecimal receivedComparison = sellerWaterList.get(0).getReceivedAmount().compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:sellerWaterList.get(1).getReceivedAmount().subtract(sellerWaterList.get(0).getReceivedAmount()).multiply(new BigDecimal(100)).divide(sellerWaterList.get(0).getReceivedAmount(),3);
+        BigDecimal receivableComparison = sellerWaterList.get(0).getReceivableAmount().compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:sellerWaterList.get(1).getReceivableAmount().subtract(sellerWaterList.get(0).getReceivableAmount()).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(sellerWaterList.get(0).getReceivableAmount(),3);
+
+        BigDecimal receivedComparison = sellerWaterList.get(0).getReceivedAmount().compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:sellerWaterList.get(1).getReceivedAmount().subtract(sellerWaterList.get(0).getReceivedAmount()).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(sellerWaterList.get(0).getReceivedAmount(),3);
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("receivableComparison",receivableComparison);
         map.put("receivedComparison",receivedComparison);
@@ -303,8 +304,8 @@ public class AppPageReportController {
             }
         }
 
-        BigDecimal receivedComparison = receivedLastYearComparison.compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:receivedSameYearComparison.subtract(receivedLastYearComparison).multiply(new BigDecimal(100)).divide(receivedLastYearComparison,3);
-        BigDecimal receivableComparison = receivableLastYearComparison.compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:receivableSameYearComparison.subtract(receivableLastYearComparison).multiply(new BigDecimal(100)).divide(receivableLastYearComparison,3);
+        BigDecimal receivedComparison = receivedLastYearComparison.compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:receivedSameYearComparison.subtract(receivedLastYearComparison).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(receivedLastYearComparison,3);
+        BigDecimal receivableComparison = receivableLastYearComparison.compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:receivableSameYearComparison.subtract(receivableLastYearComparison).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(receivableLastYearComparison,3);
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("receivableComparison",receivableComparison);
         map.put("receivedComparison",receivedComparison);
@@ -331,8 +332,8 @@ public class AppPageReportController {
                 receivableLastYearComparison =receivableLastYearComparison.add(sellerWaterList.get(i).getReceivableAmount());
             }
         }
-        BigDecimal receivedComparison = receivedLastYearComparison.compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:receivedSameYearComparison.subtract(receivedLastYearComparison).multiply(new BigDecimal(100)).divide(receivedLastYearComparison,3);
-        BigDecimal receivableComparison = receivableLastYearComparison.compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:receivableSameYearComparison.subtract(receivableLastYearComparison).multiply(new BigDecimal(100)).divide(receivableLastYearComparison,3);
+        BigDecimal receivedComparison = receivedLastYearComparison.compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:receivedSameYearComparison.subtract(receivedLastYearComparison).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(receivedLastYearComparison,3);
+        BigDecimal receivableComparison = receivableLastYearComparison.compareTo(BigDecimal.ZERO)==0 ?BigDecimal.ZERO:receivableSameYearComparison.subtract(receivableLastYearComparison).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(receivableLastYearComparison,3);
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("receivableComparison",receivableComparison);
         map.put("receivedComparison",receivedComparison);

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

@@ -158,7 +158,7 @@ public class AppPageReportServiceImpl implements AppPageReportService {
         for(DeviceWaterSupply water : sellerWaterList){
             sellerWaterAmount = sellerWaterAmount.add(water.getAmount());
         }
-        BigDecimal nrw = makingWaterAmount.compareTo(BigDecimal.ZERO) == 0  ? 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)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(makingWaterAmount,2);
         map.put("totalIntake",supplyWaterAmount);
         map.put("totalMaking",makingWaterAmount);
         map.put("totallSeller",sellerWaterAmount);
@@ -181,7 +181,7 @@ public class AppPageReportServiceImpl implements AppPageReportService {
         for(DeviceWaterSupply water : lastWaterList){
             lastWaterAmount = lastWaterAmount.add(water.getAmount());
         }
-        BigDecimal comparison = lastWaterAmount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sameWaterAmount.subtract(lastWaterAmount).multiply(new BigDecimal(100)).divide(lastWaterAmount,2);
+        BigDecimal comparison = lastWaterAmount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sameWaterAmount.subtract(lastWaterAmount).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(lastWaterAmount,2);
         return comparison;
     }
 
@@ -210,7 +210,7 @@ public class AppPageReportServiceImpl implements AppPageReportService {
         }
 
 
-        BigDecimal comparison = lastWaterAmount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sameWaterAmount.subtract(lastWaterAmount).multiply(new BigDecimal(100)).divide(lastWaterAmount,2);
+        BigDecimal comparison = lastWaterAmount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sameWaterAmount.subtract(lastWaterAmount).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).divide(lastWaterAmount,2);
         return comparison;
     }