Browse Source

1修改首页概况

Xiaojh 4 years ago
parent
commit
5bc86323fc

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayChargeSurveyController.java

@@ -42,7 +42,7 @@ public class PayChargeSurveyController {
     @ResponseBody
     @GetMapping("/tranSurvey")
     @ApiOperation(value = "计费系统-交易概况")
-    public AjaxMessage<PayTransactionSurveyDto> tranSurvey(@ApiParam(value = "账期", required = true,defaultValue = "2020-07") @RequestParam(required = true) String periodDate){
+    public AjaxMessage<PayTransactionSurveyDto> tranSurvey(@ApiParam(value = "账期", required = false) @RequestParam(required = false) String periodDate){
         PayTransactionSurveyDto payTransactionSurvey = payChargeSurveyService.tranSurvey(periodDate);
         return new AjaxMessage<PayTransactionSurveyDto>(ResultStatus.OK, payTransactionSurvey);
     }

+ 33 - 29
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayChargeSurveyServiceImpl.java

@@ -11,6 +11,7 @@ import com.bz.smart_city.entity.pay.PayFeeSuevey;
 import com.bz.smart_city.entity.pay.PayTransactionSurvey;
 import com.bz.smart_city.service.pay.PayChargeSurveyService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -110,7 +111,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             //上一期客户数
             Integer sumLastAccount = accountSurvey != null && accountSurvey.getAccountNumber() != null ? accountSurvey.getAccountNumber() : 0;
             //客户总数较上月比率
-            String lastAccountRate = "";
+            String lastAccountRate = "0.0";
             float num =(float)((sumCurrentAccount - sumLastAccount)/(sumLastAccount != null && sumLastAccount != 0 ? sumLastAccount : 1)*100);
             lastAccountRate = df.format(num);
 
@@ -132,7 +133,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             //上一期水表数
             Integer sumLastMeter = accountSurvey != null && accountSurvey.getMeterNumber() != null ? accountSurvey.getMeterNumber() :0;
             //水表总数较上月比率
-            String lastMeterRate = "";
+            String lastMeterRate = "0.0";
             num =(float)((sumCurrentMeter - sumLastMeter)/(sumLastMeter != null && sumLastMeter != 0 ? sumLastMeter : 1)*100);
             lastMeterRate = df.format(num);
             Integer lastMeterIsUp = num > 0  ? 1 : 0;
@@ -151,7 +152,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             //上一账期开户数
             Integer sumLastCustomer = accountSurvey != null && accountSurvey.getCustomerNumber() != null ? accountSurvey.getCustomerNumber() : 0;
             //水表总数较上月比率
-            String lastCusstomerRate = "";
+            String lastCusstomerRate = "0.0";
             num =(float)((sumCurrentCustomer - sumLastCustomer)/(sumLastCustomer != null && sumLastCustomer != 0 ? sumLastCustomer : 1)*100);
             lastCusstomerRate = df.format(num);
             Integer lastCustomerIsUp = num > 0  ? 1 : 0;
@@ -164,7 +165,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
 
 
             //开户率
-            String customerRate = "";
+            String customerRate = "0.0";
             num =(float)(sumCurrentCustomer/(sumCurrentMeter != null && sumCurrentMeter != 0 ? sumCurrentMeter : 1)*100);
             customerRate = df.format(num);
             customerRate = customerRate.contains("-") ? customerRate.split("-")[1] : customerRate;
@@ -234,6 +235,11 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
         BigInteger customerId = BigInteger.valueOf(loginUser.getCustomerId());
         BigDecimal defc = new BigDecimal("0.0");
         try {
+            List<BaseClosingAccountInfoDto> list = baseClosingAccountInfoMapper.getList(null,null,
+                    siteId,customerId,null);
+            if(StringUtils.isBlank(periodDate)){
+                periodDate = list.get(0).getYear() + "-"+String.format("%02d",list.get(0).getMonth());
+            }
             //判断传过来的时间是否为当前账期,当前账期则查交易明细表,否则查交易记录表
             String[] split = periodDate.split("-");
             String y = split[0];
@@ -256,8 +262,6 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
                 lastMonth = month -1;
             }
 
-            List<BaseClosingAccountInfoDto> list = baseClosingAccountInfoMapper.getList(null,null,
-                    siteId,customerId,null);
             //判断是否为当前账期,当前账期需要查询实时数据,历史账期查询记录表中的数据
             if((year.equals(list.get(0).getYear())) && (month.equals(list.get(0).getMonth()))){
                 //当前账期查询交易明细表
@@ -338,7 +342,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             BigDecimal currentIncome = transactionSurver.getIncomeNumber();//本月收入总数
             BigDecimal lastIncome = transactionSurver.getLastIncomeNumber();//上月收入总数
             BigDecimal income = currentIncome.subtract(lastIncome).divide((lastIncome != null && lastIncome.compareTo(BigDecimal.ZERO)==1 ? lastIncome : defb),2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
-            String lastIncomeRate = "";
+            String lastIncomeRate = "0.0";
             lastIncomeRate = df.format(income);
             Integer lastIncomeIsUp = income.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
             //截取字符串
@@ -383,20 +387,20 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
 
             //饼状态占比率
             BigDecimal current = alipayIncome.add(wechatIncome).add(bankIncome).add(cashIncome);
-            String CashRate = "";
-            String alipayRate = "";
-            String wechatRate = "";
-            String bankRate = "";
-            income = cashIncome.divide(current,2, BigDecimal.ROUND_HALF_UP);
+            String CashRate = "0.0";
+            String alipayRate = "0.0";
+            String wechatRate = "0.0";
+            String bankRate = "0.0";
+            income = cashIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),2, BigDecimal.ROUND_HALF_UP);
             CashRate = df.format(income);
 
-            income = alipayIncome.divide(current,2, BigDecimal.ROUND_HALF_UP);
+            income = alipayIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),2, BigDecimal.ROUND_HALF_UP);
             alipayRate = df.format(income);
 
-            income = wechatIncome.divide(current,2, BigDecimal.ROUND_HALF_UP);
+            income = wechatIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),2, BigDecimal.ROUND_HALF_UP);
             wechatRate = df.format(income);
 
-            income = bankIncome.divide(current,2, BigDecimal.ROUND_HALF_UP);
+            income = bankIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),2, BigDecimal.ROUND_HALF_UP);
             bankRate = df.format(income);
 
             //收入总数
@@ -404,23 +408,23 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             payTransactionSurveyDto.setIncomeNumber(currentIncome);
             payTransactionSurveyDto.setLastIncomeRate(lastIncomeRate);
             //按支付方式
-            payTransactionSurveyDto.setCashIncome(cashIncome);
-            payTransactionSurveyDto.setLastCashRate(lastCashRate);
+            payTransactionSurveyDto.setCashIncome(cashIncome != null ? cashIncome : defc);
+            payTransactionSurveyDto.setLastCashRate( lastCashRate != null ? lastCashRate : "0.0");
             payTransactionSurveyDto.setLastCashIsUp(lastCashIsUp);
-            payTransactionSurveyDto.setWechatIncome(wechatIncome);
-            payTransactionSurveyDto.setLastWechatRate(lastWechatRate);
+            payTransactionSurveyDto.setWechatIncome(wechatIncome != null ? wechatIncome : defc);
+            payTransactionSurveyDto.setLastWechatRate( lastWechatRate != null ? lastWechatRate : "0.0");
             payTransactionSurveyDto.setLastWechatIsUp(lastWechatIsUp);
-            payTransactionSurveyDto.setAlipayIncome(alipayIncome);
-            payTransactionSurveyDto.setLastAlipayRate(lastAlipayRate);
+            payTransactionSurveyDto.setAlipayIncome(alipayIncome != null ? alipayIncome : defc);
+            payTransactionSurveyDto.setLastAlipayRate( lastAlipayRate != null ? lastAlipayRate : "0.0");
             payTransactionSurveyDto.setLastAlipayIsUp(lastAlipayIsUp);
-            payTransactionSurveyDto.setBankIncome(bankIncome);
-            payTransactionSurveyDto.setLastBankRate(lastBankRate);
+            payTransactionSurveyDto.setBankIncome( bankIncome != null ? bankIncome : defc);
+            payTransactionSurveyDto.setLastBankRate( lastBankRate != null ? lastBankRate : "0.0");
             payTransactionSurveyDto.setLastBankIsUp(lastBankIsUp);
             //饼状图
-            payTransactionSurveyDto.setCashRate(CashRate);
-            payTransactionSurveyDto.setAlipayRate(alipayRate);
-            payTransactionSurveyDto.setWechatRate(wechatRate);
-            payTransactionSurveyDto.setBankRate(bankRate);
+            payTransactionSurveyDto.setCashRate(CashRate != null ? CashRate : "0.0");
+            payTransactionSurveyDto.setAlipayRate( alipayRate != null ? alipayRate : "0.0");
+            payTransactionSurveyDto.setWechatRate( wechatRate != null ? wechatRate : "0.0");
+            payTransactionSurveyDto.setBankRate( bankRate != null ? bankRate : "0.0");
             //年月
             payTransactionSurveyDto.setYear(year);
             payTransactionSurveyDto.setMonth(month);
@@ -550,7 +554,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             endDate = (currentYear - 1)+"-"+String.format("%02d",month);
             BigDecimal lastAmount = payChargeSurveyMapper.getAmountInfo(startDate,endDate,siteId,customerId);
             //计算年同比 = 当前总数-去年同期总数│/去年同期总数
-            String lastYearRate = "";
+            String lastYearRate = "0.0";
             BigDecimal number  = currentAmount.subtract(lastAmount).divide((lastAmount != null && lastAmount.compareTo(BigDecimal.ZERO)==1 ? lastAmount : defb),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
             //0下降  1商社
             Integer lastYearIsUp = number.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
@@ -569,7 +573,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             //0下降  1商社
             Integer lastMonthIsUp = number.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
             //保留一位小数
-            String lastMonthRate = "";
+            String lastMonthRate = "0.0";
             lastMonthRate = df.format(number);
             //截取字符串
             lastMonthRate = lastMonthRate.contains("-") ? lastMonthRate.split("-")[1] : lastMonthRate;