Преглед на файлове

Merge remote-tracking branch 'origin/0727' into 0727

zhoujiangyuan преди 4 години
родител
ревизия
ec4b9290d6

+ 1 - 0
smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/service/impl/DeviceDataServiceImpl.java

@@ -515,6 +515,7 @@ public class DeviceDataServiceImpl implements DeviceDataService {
 						record.setValveStatus(1);
 					}else {
 						record.setValveStatus(0);
+						record.setValveButtonStatus(0);
 					}
 				}
 				waterMeterErrorDaysMapper.insertSelective(record);

+ 2 - 2
smart-city-intf/src/main/resources/application-sit.properties

@@ -54,8 +54,8 @@ com.zcxk.kafka.card.topic=sc_card_topic_sit
 spring.kafka.consumer.group-id=iot-hub-sit
 spring.kafka.consumer.auto-offset-reset=latest
 spring.kafka.consumer.enable-auto-commit=true
-com.zcxk.kafka.single.data.topic=sc_single_data_topic
-com.zcxk.kafka.multi.data.topic=sc_multi_data_topic
+com.zcxk.kafka.single.data.topic=sc_single_data_topic_sit
+com.zcxk.kafka.multi.data.topic=sc_single_data_topic_sit
 #\u963F\u91CC\u4E91\u7F51\u7BA1\u5E73\u53F0\u914D\u7F6E\u9879
 aliyun.nms.topic=zoniot-aliyun-ns-test-topic
 aliyun.nms.access.key=LTAI9bq4vr6ClPGW

+ 12 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayChargeSurveyMapper.java

@@ -38,6 +38,9 @@ public interface PayChargeSurveyMapper {
     public BigDecimal getCurrentTran(@Param("year")Integer year,@Param("month")Integer month,
             @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
 
+    public BigDecimal getReceivedCurrent(@Param("year")Integer year,@Param("month")Integer month,
+                                         @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
+
     public List<PayTransactionSurvey> getPayAmountList(@Param("year")Integer year,@Param("month")Integer month,
                                                  @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
 
@@ -46,6 +49,9 @@ public interface PayChargeSurveyMapper {
     public List<PayTransactionSurvey> getCurrentTranRocord(@Param("year")Integer year,@Param("month")Integer month,
                                 @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
 
+    public List<PayTransactionSurvey> getCurrentReceived(@Param("year")Integer year,@Param("month")Integer month,
+                                      @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
+
     public PayTransactionSurvey getLastTranRocord(@Param("year")Integer year,@Param("month")Integer month,
                                                   @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
 
@@ -66,11 +72,17 @@ public interface PayChargeSurveyMapper {
     public BigDecimal getAmountMonth(@Param("year")Integer year,@Param("month")Integer month,
                                      @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
 
+    public BigDecimal getAmountMonthSurvey(@Param("year")Integer year,@Param("month")Integer month,
+                                     @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
+
     public void insertAmount(PayAmountSurvey payAmountSurvey);
 
     public BigDecimal getAmountInfo(@Param("startDate")String startDate,@Param("endDate")String endDate,
                                     @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
 
+    public BigDecimal getAmountSureyInfo(@Param("startDate")String startDate,@Param("endDate")String endDate,
+                                         @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
+
     public List<PayAmountSurveyListDto> getAmountGroupList(@Param("year")Integer year,@Param("month")Integer month,
                                                            @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
 }

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/PayTransactionSurveyDto.java

@@ -14,7 +14,7 @@ public class PayTransactionSurveyDto {
     private BigDecimal incomeNumber;
     @ApiModelProperty(value = "较上月比率")
     private String lastIncomeRate;
-    @ApiModelProperty(value = "收入较上月 0下降 1新增")
+    @ApiModelProperty(value = "收入较上月 0下降 1新增 2持平或除数为0")
     private Integer lastIncomeIsUp;
 
     @ApiModelProperty(value = "现金")

+ 20 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/RecordInfo.java

@@ -0,0 +1,20 @@
+package com.bz.smart_city.entity.pay;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+@ApiModel("计算比率")
+public class RecordInfo {
+    @ApiModelProperty(value = "收入总数")
+    public BigDecimal income;
+    @ApiModelProperty(value = "较上月比率")
+    public String rate;
+    @ApiModelProperty(value = "是否上升、下降")
+    public Integer isUp;
+    @ApiModelProperty(value = "收入总数")
+    public float count;
+}

+ 83 - 11
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/BaseClosingAccountInfoServiceImpl.java

@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Date;
@@ -83,6 +84,8 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
         boolean isOk = true;
         Integer year = baseClosingAccountInfoDto.getYear();
         Integer month  = baseClosingAccountInfoDto.getMonth();
+        Date startTime = baseClosingAccountInfoDto.getStartTime();
+        Date endTime = new Date();
         LoginUser loginUser = UserUtil.getCurrentUser();
         // 判断结账参数,进行结账校验
         String msg = "结账失败:<br/>";
@@ -125,22 +128,25 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
                 //按账期月卡旧数据
                 List<BaseClosingAccountInfoDto> list = baseClosingAccountInfoMapper.getListNumber(null,null,
                         BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()),null);
-                for (int i=0; i<list.size(); i++){
-                    int state = list.get(i).getState();
-                    /*if(state == 1){*/
+                if(list.size() >0){
+                    //如果第一次使用系统则不创建记录
+                    for (int i=0; i<list.size(); i++){
+                        int state = list.get(i).getState();
+                        /*if(state == 1){*/
                         //把历史结账数据存进去,但不包含本期未结账的
-                        this.insertAccountNumber(list.get(i).getYear(),list.get(i).getMonth());
+                        this.insertAccountNumber(list.get(i).getYear(),list.get(i).getMonth(),list.get(i).getStartTime(),list.get(i).getEndTime());
                         //历史交易数据
                         this.insertTransaction(list.get(i).getYear(),list.get(i).getMonth());
                         //历史交易数据
                         this.insertFeeSummary(list.get(i).getYear(),list.get(i).getMonth());
                         //历史水量
                         this.insetAmountInfo(list.get(i).getYear(),list.get(i).getMonth());
-                    /*}*/
+                        /*}*/
+                    }
                 }
             }else if(count > 0){
                 //存储本期未结账数据
-                this.insertAccountNumber(year,month);
+                this.insertAccountNumber(year,month,startTime,endTime);
                 //本期交易未结账数据
                 this.insertTransaction(year,month);
                 //本期交易数据
@@ -151,7 +157,7 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
 
             // 更新本账期
             String msg2 = year + "年" + String.format("%02d", month) + "月已经结账";
-            baseClosingAccountInfoDto.setEndTime(new Date());
+            baseClosingAccountInfoDto.setEndTime(endTime);
             baseClosingAccountInfoDto.setRemarks(msg2);
             baseClosingAccountInfoDto.setState(1);
             baseClosingAccountInfoDto.setUpdateBy(BigInteger.valueOf(loginUser.getId()));
@@ -183,8 +189,14 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
     }
 
     //添加客户概况信息
-    public void insertAccountNumber(Integer year,Integer month){
+    public void insertAccountNumber(Integer year,Integer month,Date startTime,Date endTime){
         LoginUser loginUser = UserUtil.getCurrentUser();
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
+        endTime = endTime != null ? endTime : new Date();
+        String strarDate = "";
+        String endDate = "";
+        strarDate = format.format(startTime);
+        endDate = format.format(endTime);
 
         String start = year+"-"+(String.format("%02d",month))+"-01";
         String end = year+"-"+(String.format("%02d",month))+"-31";
@@ -203,13 +215,13 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
 
             //根据账期查找历史客户数(仅统计状态为欠费与正常的客户总数之和)
             Integer accountNumber = payChargeSurveyMapper.getAccountNumber
-                    (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+                    (strarDate,endDate,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
             //根据账期查找历史水表数(仅统计状态为已开户的水表总数)
             Integer meterNumber = payChargeSurveyMapper.getMeterNumber
-                    (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+                    (strarDate,endDate,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
             //根据账期查找历史开户数(仅统计状态为正常的开户总数)
             Integer customerNumber = payChargeSurveyMapper.getCustomerNumber
-                    (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+                    (strarDate,endDate,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
 
             //上一账期汇总
             PayAccountSurvey lastAccount = payChargeSurveyMapper.getlastNumber(lastYear,lastMonth,
@@ -277,19 +289,30 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
             //根据账期查找历史数据(现金、微信支付、支付宝、银行)
             BigDecimal bigDecimalStr = new BigDecimal("0.0");
             BigDecimal cuttentAmount = payChargeSurveyMapper.getCurrentTran(year,month,siteId,customerId);
+            BigDecimal receivedCurrent = payChargeSurveyMapper.getReceivedCurrent(year,month,siteId,customerId);
+            cuttentAmount = cuttentAmount.add(receivedCurrent);
             cuttentAmount = cuttentAmount != null ? cuttentAmount : bigDecimalStr;
             //上一账期
             BigDecimal lastAmount = payChargeSurveyMapper.getCurrentTran(lastYear,lastMonth,siteId,customerId);
+            BigDecimal lastCurrent = payChargeSurveyMapper.getReceivedCurrent(lastYear,lastMonth,siteId,customerId);
+            lastAmount = lastAmount.add(lastCurrent);
             lastAmount = lastAmount != null ? lastAmount : bigDecimalStr;
             //当前账期按支付方式划分
             List<PayTransactionSurvey> tranList = payChargeSurveyMapper.getPayAmountList(year,month,siteId,customerId);
+            List<PayTransactionSurvey> receList = payChargeSurveyMapper.getCurrentReceived(year,month,siteId,customerId);
+
             //上一账期按支付方式划分
             List<PayTransactionSurvey> lasttranList = payChargeSurveyMapper.getPayAmountList(lastYear,lastMonth,siteId,customerId);
+            List<PayTransactionSurvey> lastreceList = payChargeSurveyMapper.getCurrentReceived(lastYear,lastMonth,siteId,customerId);
 
             BigDecimal cashIncome = bigDecimalStr;//现金
             BigDecimal wechatIncome = bigDecimalStr;//微信
             BigDecimal alipayIncome = bigDecimalStr;//支付宝
             BigDecimal bankIncome = bigDecimalStr;//银行
+            BigDecimal rececashIncome = bigDecimalStr;//现金
+            BigDecimal recewechatIncome = bigDecimalStr;//微信支付
+            BigDecimal recealipayIncome = bigDecimalStr; //支付宝
+            BigDecimal recebankIncome = bigDecimalStr;//银行
             //当前账期
             for(int i=0; i<tranList.size(); i++){
                 Integer payway = tranList.get(i).getPayway();
@@ -307,16 +330,43 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
                     cashIncome = tranList.get(i).getIncomeNumber();
                 }
             }
+            for(int i=0; i<receList.size(); i++){
+                Integer payway = receList.get(i).getPayway();
+                if(payway == 1){
+                    //支付宝
+                    recealipayIncome = receList.get(i).getIncomeNumber();
+                }else if(payway == 2){
+                    //微信
+                    recewechatIncome = receList.get(i).getIncomeNumber();
+                }else if (payway == 3) {
+                    //银行
+                    recebankIncome = receList.get(i).getIncomeNumber();
+                }else if (payway == 4) {
+                    //现金
+                    rececashIncome = receList.get(i).getIncomeNumber();
+                }
+            }
+            alipayIncome = alipayIncome.add(recealipayIncome);
+            wechatIncome = wechatIncome.add(recewechatIncome);
+            bankIncome = bankIncome.add(recebankIncome);
+            cashIncome = cashIncome.add(rececashIncome);
+
             transactionSurver.setIncomeNumber(cuttentAmount);
             transactionSurver.setLastIncomeNumber(lastAmount);
             transactionSurver.setAlipayIncome(alipayIncome);
             transactionSurver.setWechatIncome(wechatIncome);
             transactionSurver.setBankIncome(bankIncome);
             transactionSurver.setCashIncome(cashIncome);
+
             BigDecimal lastAlipayIncome = bigDecimalStr;
             BigDecimal lastWechatIncome = bigDecimalStr;
             BigDecimal lastBankIncome = bigDecimalStr;
             BigDecimal lastCashIncome = bigDecimalStr;
+
+            BigDecimal recelastAlipayIncome = bigDecimalStr;
+            BigDecimal recelastWechatIncome = bigDecimalStr;
+            BigDecimal recelastBankIncome = bigDecimalStr;
+            BigDecimal recelastCashIncome = bigDecimalStr;
             //上一账期
             for(int i=0; i<lasttranList.size(); i++){
                 Integer payway = lasttranList.get(i).getPayway();
@@ -334,6 +384,28 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
                     lastCashIncome = lasttranList.get(i).getIncomeNumber();
                 }
             }
+
+            for(int i=0; i<lastreceList.size(); i++){
+                Integer payway = lastreceList.get(i).getPayway();
+                if(payway == 1){
+                    //支付宝
+                    recelastAlipayIncome = lastreceList.get(i).getIncomeNumber();
+                }else if(payway == 2){
+                    //微信
+                    recelastWechatIncome = lastreceList.get(i).getIncomeNumber();
+                }else if (payway == 3) {
+                    //银行
+                    recelastBankIncome = lastreceList.get(i).getIncomeNumber();
+                }else if (payway == 4) {
+                    //现金
+                    recelastCashIncome = lastreceList.get(i).getIncomeNumber();
+                }
+            }
+            lastAlipayIncome = lastAlipayIncome.add(recelastAlipayIncome);
+            lastWechatIncome = lastWechatIncome.add(recelastWechatIncome);
+            lastBankIncome = lastBankIncome.add(recelastBankIncome);
+            lastCashIncome = lastCashIncome.add(recelastCashIncome);
+
             transactionSurver.setLastAlipayIncome(lastCashIncome);
             transactionSurver.setLastWechatIncome(lastWechatIncome);
             transactionSurver.setLastBankIncome(lastBankIncome);

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

@@ -5,18 +5,17 @@ import com.bz.smart_city.dao.pay.BaseClosingAccountInfoMapper;
 import com.bz.smart_city.dao.pay.PayChargeSurveyMapper;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.pay.*;
-import com.bz.smart_city.entity.pay.PayAccountSurvey;
-import com.bz.smart_city.entity.pay.PayChargeSurvey;
-import com.bz.smart_city.entity.pay.PayFeeSuevey;
-import com.bz.smart_city.entity.pay.PayTransactionSurvey;
+import com.bz.smart_city.entity.pay.*;
 import com.bz.smart_city.service.pay.PayChargeSurveyService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.record.Record;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -55,12 +54,17 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
           String a = df.format(income);
           System.out.println("收入费率:"+a);*/
 
-          String a = "-90.89";
+          /*String a = "-90.89";
           String b = "90.89";
 
           String a1 = a.split("-")[1];
           String b1 = b.split("-")[1];
-          System.out.println("带负数转换:"+a1+";不带负数转换:"+b1);
+          System.out.println("带负数转换:"+a1+";不带负数转换:"+b1);*/
+          /*BigDecimal bigDecima1 = new BigDecimal("194.60");
+          BigDecimal bigDecima2 = new BigDecimal("600.00");
+          BigDecimal divide = bigDecima2.subtract(bigDecima1).divide(bigDecima1,3, RoundingMode.HALF_UP);*/
+
+          //BigDecimal divide = bigDecima1 .divide(bigDecima2,2, RoundingMode.HALF_UP);
       }catch (Exception e) {
           e.printStackTrace();
       }
@@ -86,48 +90,41 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
                     siteId,customerId,null);
             if(list.size() <=0){
                 BaseClosingAccountInfoDto a = new BaseClosingAccountInfoDto();
-                Calendar cal = Calendar.getInstance();
-                int year = cal.get(Calendar.YEAR);
-                int month = cal.get(Calendar.MONTH )+1;
-                a.setYear(year);
-                a.setMonth(month);
-                list.add(a);
+                for(int i=0; i<=1; i++){
+                    Calendar cal = Calendar.getInstance();
+                    int year = cal.get(Calendar.YEAR);
+                    int month = cal.get(Calendar.MONTH )+1;
+                    a.setYear(year);
+                    a.setMonth(month);
+                    a.setStartTime(new Date());
+                    list.add(a);
+                }
             }
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
+            Date startTime = list.get(0).getStartTime();
+            String dateStart = format.format(startTime);
+            String dateEnd = format.format(new Date());
+
             String startPeriod = list.get(0).getYear()+"-"+String.format("%02d", list.get(0).getMonth())+"-01";
             String endPeriod = list.get(0).getYear()+"-"+String.format("%02d", list.get(0).getMonth())+"-31";
 
-            //取上一账期时间
-            Calendar startDate = Calendar.getInstance();//起始年月
-            Calendar enddate = Calendar.getInstance();//起始年月
-            startDate.setTime(sdf.parse(startPeriod));
-            startDate.add(Calendar.MONTH, -1); //月份减1;
-            enddate.setTime(sdf.parse(endPeriod));
-            enddate.add(Calendar.MONTH, -1); //月份减1;
-
-            Date lastStartMonth = startDate.getTime(); //结果
-            Date laseEndMonth = enddate.getTime();
-            String lastStart = sdf.format(lastStartMonth);
-            String lastEnd = sdf.format(laseEndMonth);
-            //System.out.println("当前账期:"+period+";上一账期:"+lastPeriod);
-
             //上一账期汇总
-            PayAccountSurvey accountSurvey = payChargeSurveyMapper.getlastAccount(lastStart,siteId,customerId);
+            String lastDate = list.get(1).getYear() +"-"+String.format("%02d", list.get(1).getMonth())+"-01";
+            PayAccountSurvey accountSurvey = payChargeSurveyMapper.getlastAccount(null,siteId,customerId);
 
             //客户总数计算
             //当前账期以内客户总数
-            Integer sumAccount = payChargeSurveyMapper.getAccountNumber(null,endPeriod,siteId,customerId);
+            Integer sumAccount = payChargeSurveyMapper.getAccountNumber(null,null,siteId,customerId);
             //当前账期客户总数
-            Integer sumCurrentAccount = payChargeSurveyMapper.getAccountNumber(startPeriod,endPeriod,siteId,customerId);
+            Integer sumCurrentAccount = payChargeSurveyMapper.getAccountNumber(dateStart,dateEnd,siteId,customerId);
             //上一期客户数
             Integer sumLastAccount = accountSurvey != null && accountSurvey.getAccountNumber() != null ? accountSurvey.getAccountNumber() : 0;
             //客户总数较上月比率
             String lastAccountRate = "0.0";
-            float num =(float)((sumCurrentAccount - sumLastAccount)/(sumLastAccount != null && sumLastAccount != 0 ? sumLastAccount : 1)*100);
-            lastAccountRate = df.format(num);
-
-            Integer lastAccountIsUp = num > 0  ? 1 : 0;
-            //截取字符串
-            lastAccountRate = lastAccountRate.contains("-") ? lastAccountRate.split("-")[1] : lastAccountRate;
+            RecordInfo info = this.calculationRate(sumAccount,sumLastAccount);
+            float num =info.getCount();
+            Integer lastAccountIsUp = info.getIsUp();
+            lastAccountRate = info.getRate();
 
             //赋值客户总数跟上月比率
             payChargeSurveyDto.setLastAccountIsUp(lastAccountIsUp);
@@ -137,18 +134,18 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
 
             //水表总数计算
             //当前账期以内的水表总数
-            Integer sumMeter = payChargeSurveyMapper.getMeterNumber(null,endPeriod,siteId,customerId);
+            Integer sumMeter = payChargeSurveyMapper.getMeterNumber(null,null,siteId,customerId);
             //当前账期水表数
-            Integer sumCurrentMeter = payChargeSurveyMapper.getMeterNumber(startPeriod,endPeriod,siteId,customerId);
+            Integer sumCurrentMeter = payChargeSurveyMapper.getMeterNumber(dateStart,dateEnd,siteId,customerId);
             //上一期水表数
             Integer sumLastMeter = accountSurvey != null && accountSurvey.getMeterNumber() != null ? accountSurvey.getMeterNumber() :0;
             //水表总数较上月比率
             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;
+            info = this.calculationRate(sumMeter,sumLastMeter);
+            num =info.getCount();
+            Integer lastMeterIsUp = info.getIsUp();
             //截取字符串
-            lastMeterRate = lastMeterRate.contains("-") ? lastMeterRate.split("-")[1] : lastMeterRate;
+            lastMeterRate = info.getRate();
             //赋值水表总数跟上月比率
             payChargeSurveyDto.setLastMeterIsUp(lastMeterIsUp);
             payChargeSurveyDto.setMeterNumber(sumMeter != null ? sumMeter : 0);
@@ -156,18 +153,18 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
 
 
             //开户总数计算
-            Integer sumCustomer = payChargeSurveyMapper.getCustomerNumber(null,endPeriod,siteId,customerId);
+            Integer sumCustomer = payChargeSurveyMapper.getCustomerNumber(null,null,siteId,customerId);
             //当前账期开户数
-            Integer sumCurrentCustomer = payChargeSurveyMapper.getCustomerNumber(startPeriod,endPeriod,siteId,customerId);
+            Integer sumCurrentCustomer = payChargeSurveyMapper.getCustomerNumber(dateStart,dateEnd,siteId,customerId);
             //上一账期开户数
             Integer sumLastCustomer = accountSurvey != null && accountSurvey.getCustomerNumber() != null ? accountSurvey.getCustomerNumber() : 0;
             //水表总数较上月比率
             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;
+            info = this.calculationRate(sumCustomer,sumLastCustomer);
+            num =info.getCount();
+            Integer lastCustomerIsUp = info.getIsUp();
             //截取字符串
-            lastCusstomerRate = lastCusstomerRate.contains("-") ? lastCusstomerRate.split("-")[1] : lastCusstomerRate;
+            lastCusstomerRate = info.getRate();
             //赋值开户总数跟上月比率
             payChargeSurveyDto.setLastCustomerIsUp(lastCustomerIsUp);
             payChargeSurveyDto.setCustomerNumber(sumCustomer != null ? sumCustomer : 0);
@@ -176,7 +173,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
 
             //开户率
             String customerRate = "0.0";
-            num =(float)(sumCurrentCustomer/(sumCurrentMeter != null && sumCurrentMeter != 0 ? sumCurrentMeter : 1)*100);
+            num =((float)sumCustomer/(sumMeter != null && sumMeter != 0 ? sumMeter : 1)*100);
             customerRate = df.format(num);
             customerRate = customerRate.contains("-") ? customerRate.split("-")[1] : customerRate;
             payChargeSurveyDto.setCustomerRate(customerRate != null && customerRate != "" ? customerRate : "0.0");
@@ -215,13 +212,13 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
                     lastYear = lastYear;
                     lastMonth = number;
                 }
-                PayChangePeriodDto info = new PayChangePeriodDto();
-                info.setYear(lastYear);
-                info.setMonth(lastMonth);
-                info.setMeterNumber(0);
-                info.setCustomerNumber(0);
-                info.setAccountNumber(0);
-                pList.add(info);
+                PayChangePeriodDto pinfo = new PayChangePeriodDto();
+                pinfo.setYear(lastYear);
+                pinfo.setMonth(lastMonth);
+                pinfo.setMeterNumber(0);
+                pinfo.setCustomerNumber(0);
+                pinfo.setAccountNumber(0);
+                pList.add(pinfo);
             }
             accountList2.addAll(pList);
             payChargeSurveyDto.setList(accountList2);
@@ -271,6 +268,11 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             BigDecimal wechatIncome = defc;//微信支付
             BigDecimal alipayIncome = defc; //支付宝
             BigDecimal bankIncome = defc;//银行
+
+            BigDecimal rececashIncome = defc;//现金
+            BigDecimal recewechatIncome = defc;//微信支付
+            BigDecimal recealipayIncome = defc; //支付宝
+            BigDecimal recebankIncome = defc;//银行
             Integer lastYear = null;
             Integer lastMonth = null;
             if(Integer.valueOf(month) == 1){
@@ -285,6 +287,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             if((year.equals(list.get(0).getYear())) && (month.equals(list.get(0).getMonth()))){
                 //当前账期查询交易明细表
                 List<PayTransactionSurvey> tranList = payChargeSurveyMapper.getCurrentTranRocord(year,month,siteId,customerId);
+                List<PayTransactionSurvey> receList = payChargeSurveyMapper.getCurrentReceived(year,month,siteId,customerId);
                 for(int i=0; i<tranList.size(); i++){
                     Integer payway = tranList.get(i).getPayway();
                     if(payway == 1){
@@ -301,6 +304,26 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
                         cashIncome = tranList.get(i).getIncomeNumber();
                     }
                 }
+                for(int i=0; i<receList.size(); i++){
+                    Integer payway = receList.get(i).getPayway();
+                    if(payway == 1){
+                        //支付宝
+                        recealipayIncome = receList.get(i).getIncomeNumber();
+                    }else if(payway == 2){
+                        //微信
+                        recewechatIncome = receList.get(i).getIncomeNumber();
+                    }else if (payway == 3) {
+                        //银行
+                        recebankIncome = receList.get(i).getIncomeNumber();
+                    }else if (payway == 4) {
+                        //现金
+                        rececashIncome = receList.get(i).getIncomeNumber();
+                    }
+                }
+                alipayIncome = alipayIncome.add(recealipayIncome);
+                wechatIncome = wechatIncome.add(recewechatIncome);
+                bankIncome = bankIncome.add(recebankIncome);
+                cashIncome = cashIncome.add(rececashIncome);
                 BigDecimal currentIncome = alipayIncome.add(wechatIncome).add(bankIncome).add(cashIncome);//当前账期收入总数
                 //查找上月收入
                 PayTransactionSurvey lastTran = payChargeSurveyMapper.getLastTranRocord(lastYear,lastMonth,siteId,customerId);
@@ -332,7 +355,6 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
         return payTransactionSurveyDto;
     }
 
-
     //计算交易比率
     public PayTransactionSurveyDto tranCompute(PayTransactionSurvey transactionSurver){
         PayTransactionSurveyDto payTransactionSurveyDto = new PayTransactionSurveyDto();
@@ -360,49 +382,50 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
         try {
             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 = "0.0";
-            lastIncomeRate = df.format(income);
-            Integer lastIncomeIsUp = income.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
-            //截取字符串
-            lastIncomeRate = lastIncomeRate.contains("-") ? lastIncomeRate.split("-")[1] : lastIncomeRate;
+
+            RecordInfo info = this.calculationRate(currentIncome,lastIncome);
+            BigDecimal income = info.getIncome();
+            String lastIncomeRate = info.getRate();
+            Integer lastIncomeIsUp = info.getIsUp();
+
 
             //按支付方式
             cashIncome = transactionSurver.getCashIncome();//本账期现金收入
             lastcashIncome = transactionSurver.getLastCashIncome();//上期现金收入
+
             wechatIncome = transactionSurver.getWechatIncome();//本账期微信
             lastwechatIncome = transactionSurver.getLastWechatIncome();//上期微信
+
             alipayIncome = transactionSurver.getAlipayIncome();//本账期支付宝
             lastalipayIncome = transactionSurver.getLastAlipayIncome();//上期支付宝
+
             bankIncome = transactionSurver.getBankIncome();//本账期银行
             lastbankIncome = transactionSurver.getLastBankIncome();//上期银行
+
+
+            info = this.calculationRate(cashIncome,lastcashIncome);
             //现金
-            income = cashIncome.subtract(lastcashIncome).divide((lastcashIncome != null && lastcashIncome.compareTo(BigDecimal.ZERO)==1 ? lastcashIncome : defb),2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
-            lastCashRate = df.format(income);
-            Integer lastCashIsUp = income.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
-            //截取字符串
-            lastCashRate = lastCashRate.contains("-") ? lastCashRate.split("-")[1] : lastCashRate;
+            income = info.getIncome();
+            lastCashRate = info.getRate();
+            Integer lastCashIsUp = info.getIsUp();
 
             //微信
-            income = wechatIncome.subtract(lastwechatIncome).divide((lastwechatIncome != null && lastwechatIncome.compareTo(BigDecimal.ZERO)==1 ? lastwechatIncome : defb),2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
-            lastWechatRate = df.format(income);
-            Integer lastWechatIsUp = income.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
-            //截取字符串
-            lastWechatRate = lastWechatRate.contains("-") ? lastWechatRate.split("-")[1] : lastWechatRate;
+            info = this.calculationRate(wechatIncome,lastwechatIncome);
+            income = info.getIncome();
+            Integer lastWechatIsUp = info.getIsUp();
+            lastWechatRate = info.getRate();
 
             //支付宝
-            income = alipayIncome.subtract(lastalipayIncome).divide((lastalipayIncome != null && lastalipayIncome.compareTo(BigDecimal.ZERO)==1 ? lastalipayIncome : defb), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
-            lastAlipayRate = df.format(income);
-            Integer lastAlipayIsUp = income.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
-            //截取字符串
-            lastAlipayRate = lastAlipayRate.contains("-") ? lastAlipayRate.split("-")[1] : lastAlipayRate;
+            info = this.calculationRate(alipayIncome,lastalipayIncome);
+            income = info.getIncome();
+            Integer lastAlipayIsUp = info.getIsUp();
+            lastAlipayRate = info.getRate();
 
             //银行
-            income = bankIncome.subtract(lastbankIncome).divide((lastbankIncome != null && lastbankIncome.compareTo(BigDecimal.ZERO)==1 ? lastbankIncome : defb),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
-            lastBankRate = df.format(income);
-            Integer lastBankIsUp = income.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
-            //截取字符串
-            lastBankRate = lastBankRate.contains("-") ? lastBankRate.split("-")[1] : lastBankRate;
+            info = this.calculationRate(bankIncome,lastbankIncome);
+            income = info.getIncome();
+            Integer lastBankIsUp = info.getIsUp();
+            lastBankRate = info.getRate();
 
             //饼状态占比率
             BigDecimal current = alipayIncome.add(wechatIncome).add(bankIncome).add(cashIncome);
@@ -410,16 +433,16 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             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);
+            income = cashIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),3, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
             CashRate = df.format(income);
 
-            income = alipayIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),2, BigDecimal.ROUND_HALF_UP);
+            income = alipayIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),3, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
             alipayRate = df.format(income);
 
-            income = wechatIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),2, BigDecimal.ROUND_HALF_UP);
+            income = wechatIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),3, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
             wechatRate = df.format(income);
 
-            income = bankIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),2, BigDecimal.ROUND_HALF_UP);
+            income = bankIncome.divide((current != null && current.compareTo(BigDecimal.ZERO)==1 ? current : defb),3, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
             bankRate = df.format(income);
 
             //收入总数
@@ -454,7 +477,6 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
         return payTransactionSurveyDto;
     }
 
-
     /**
      * 收费概况
      * @return
@@ -568,13 +590,6 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             //上一账期
             Integer lastYear = null;
             Integer lastMonth = null;
-            if(Integer.valueOf(month) == 1){
-                lastYear = year-1;
-                lastMonth = 12;
-            }else{
-                lastYear = year;
-                lastMonth = month -1;
-            }
 
             //先获取本年度结算水量(按自然年)
             Calendar date = Calendar.getInstance();
@@ -589,31 +604,61 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
             //去年同一时间累计用水量
             startDate = (currentYear - 1)+"-"+"01";
             endDate = (currentYear - 1)+"-"+String.format("%02d",month);
-            BigDecimal lastAmount = payChargeSurveyMapper.getAmountInfo(startDate,endDate,siteId,customerId);
+
+            //明天任务,查询汇总表
+            BigDecimal lastAmount = payChargeSurveyMapper.getAmountSureyInfo(startDate+"-01"+" 00:00:00",endDate+"-01"+" 00:00:00",siteId,customerId);
+            //BigDecimal lastAmount = payChargeSurveyMapper.getAmountInfo(startDate,endDate,siteId,customerId);
             //计算年同比 = 当前总数-去年同期总数│/去年同期总数
             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;
-            //保留一位小数
-            lastYearRate = df.format(number);
-            //截取字符串
-            lastYearRate = lastYearRate.contains("-") ? lastYearRate.split("-")[1] : lastYearRate;
+            Integer lastYearIsUp = 0;
+            BigDecimal number = defc;
+            //上期总数大于0则计算
+            if(lastAmount.compareTo(BigDecimal.ZERO) == 1){
+                if(currentAmount.subtract(lastAmount).compareTo(BigDecimal.ZERO) == 0){
+                    //本期减上期持平显示→
+                    lastYearIsUp = 2;
+                    lastYearRate = "→";
+                }else{
+                    number  = currentAmount.subtract(lastAmount).divide((lastAmount != null && lastAmount.compareTo(BigDecimal.ZERO)==1 ? lastAmount : defb),3, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
+                    lastYearIsUp = number.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
+                    //保留一位小数
+                    lastYearRate = df.format(number);
+                    //截取字符串
+                    lastYearRate = lastYearRate.contains("-") ? lastYearRate.split("-")[1] : lastYearRate;
+                }
+            }else{
+                //小于=0不计算增长率
+                //0下降  1上升 2不计算
+                lastYearIsUp = 2;
+                lastYearRate = "-";
+            }
 
             //计算月
             //当前月
             BigDecimal currentMAmount = payChargeSurveyMapper.getAmountMonth(year,month,siteId,customerId);
             //去年同月
-            BigDecimal lastMAmount = payChargeSurveyMapper.getAmountMonth((year-1),month,siteId,customerId);
-            //计算月同比 = 当前总数-上月同期总数│/去年同期总数
-            number  = currentMAmount.subtract(lastMAmount).divide((lastMAmount != null && lastMAmount.compareTo(BigDecimal.ZERO)==1 ? lastMAmount : defb),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
-            //0下降  1商社
-            Integer lastMonthIsUp = number.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
-            //保留一位小数
+            BigDecimal lastMAmount = payChargeSurveyMapper.getAmountMonthSurvey((year-1),month,siteId,customerId);
+            Integer lastMonthIsUp = 0;
             String lastMonthRate = "0.0";
-            lastMonthRate = df.format(number);
-            //截取字符串
-            lastMonthRate = lastMonthRate.contains("-") ? lastMonthRate.split("-")[1] : lastMonthRate;
+            if(lastMAmount.compareTo(BigDecimal.ZERO) == 1){
+                if(currentMAmount.subtract(lastMAmount).compareTo(BigDecimal.ZERO) == 0){
+                    lastMonthIsUp = 2;
+                    lastMonthRate = "→";
+                }else{
+                    //计算月同比 = 当前总数-上月同期总数│/去年同期总数
+                    number  = currentMAmount.subtract(lastMAmount).divide((lastMAmount != null && lastMAmount.compareTo(BigDecimal.ZERO)==1 ? lastMAmount : defb),3, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
+                    //0下降  1商社
+                    lastMonthIsUp = number.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
+                    //保留一位小数
+                    lastMonthRate = df.format(number);
+                    //截取字符串
+                    lastMonthRate = lastMonthRate.contains("-") ? lastMonthRate.split("-")[1] : lastMonthRate;
+                }
+            }else{
+                lastMonthIsUp = 2;
+                lastMonthRate = "-";
+            }
+
 
             //最近一年数据
             List<PayAmountSurveyListDto> cList = new ArrayList<PayAmountSurveyListDto>();
@@ -660,7 +705,88 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
         return payAmountSurveyDto;
     }
 
+    /**
+     * 计算较上月 Integer
+     * @param currentAmount
+     * @param lastAmount
+     * @return
+     */
+    public RecordInfo calculationRate(Integer currentAmount ,Integer lastAmount){
+        RecordInfo info = new RecordInfo();
+        Integer lastIncomeIsUp = 2;
+        String lastIncomeRate = "-";
+        BigDecimal income = new BigDecimal("0.0");
+        DecimalFormat df = new DecimalFormat("0.0");
+        float num = 0;
+        try {
+            if(lastAmount >0){
+                if(currentAmount - lastAmount <=0){
+                    //本期减上期持平显示→
+                    lastIncomeIsUp = 2;
+                    lastIncomeRate = "→";
+                }else{
+                    num =((float)(currentAmount - lastAmount)/(lastAmount != null && lastAmount != 0 ? lastAmount : 1)*100);
+                    lastIncomeRate = df.format(num);
+                    lastIncomeIsUp = num > 0  ? 1 : 0;
+                    //截取字符串
+                    lastIncomeRate = lastIncomeRate.contains("-") ? lastIncomeRate.split("-")[1] : lastIncomeRate;
+                }
+            }else{
+                //小于=0不计算增长率
+                //0下降  1上升 2不计算
+                lastIncomeIsUp = 2;
+                lastIncomeRate = "-";
+            }
+            info.setCount(num);
+            info.setIsUp(lastIncomeIsUp);
+            info.setRate(lastIncomeRate);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return info;
+    }
 
-
+    /**
+     *  计算较上月 BigDecimal
+     * @param currentIncome
+     * @param lastIncome
+     * @return
+     */
+    public RecordInfo calculationRate(BigDecimal currentIncome,BigDecimal lastIncome){
+        RecordInfo info = new RecordInfo();
+        Integer lastIncomeIsUp = 2;
+        String lastIncomeRate = "-";
+        BigDecimal income = new BigDecimal("0.0");
+        BigDecimal defc = new BigDecimal("0.0");
+        BigDecimal defb = new BigDecimal("1.0");
+        DecimalFormat df = new DecimalFormat("0.0");
+        try{
+            if(lastIncome.compareTo(BigDecimal.ZERO) == 1){
+                if(currentIncome.subtract(lastIncome).compareTo(BigDecimal.ZERO) == 0){
+                    //本期减上期持平显示→
+                    lastIncomeIsUp = 2;
+                    lastIncomeRate = "→";
+                }else{
+                    income  = currentIncome.subtract(lastIncome).divide((lastIncome != null && lastIncome.compareTo(BigDecimal.ZERO)==1 ? lastIncome : defb),3, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
+                    lastIncomeIsUp = income.compareTo(BigDecimal.ZERO) == 1 ? 1 : 0;
+                    //保留一位小数
+                    lastIncomeRate = df.format(income);
+                    //截取字符串
+                    lastIncomeRate = lastIncomeRate.contains("-") ? lastIncomeRate.split("-")[1] : lastIncomeRate;
+                }
+            }else{
+                //小于=0不计算增长率
+                //0下降  1上升 2不计算
+                lastIncomeIsUp = 2;
+                lastIncomeRate = "-";
+            }
+            info.setIncome(income);
+            info.setIsUp(lastIncomeIsUp);
+            info.setRate(lastIncomeRate);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return info;
+    }
 
 }

+ 4 - 4
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayFeeServiceImp.java

@@ -142,7 +142,7 @@ public class PayFeeServiceImp implements PayFeeService {
                     //生成并保存实收
                     PayPayReceived payPayReceived = getReceived(payReceivable, year, month, localDateTime,5,payseriesno,payReceivable.getDebt(),feetypeMap, siteId, customerId, userId );
                     //生成交易明细
-                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5,paywayName, localDateTime, payCustomRechargeDto, payseriesno, month, year, payReceivable.getDebt().negate(), siteId, customerId, userId );
+                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5,"预存账户", localDateTime, payCustomRechargeDto, payseriesno, month, year, payReceivable.getDebt().negate(), siteId, customerId, userId );
                     payTransactiondetails.setReceivedId(payPayReceived.getId());
                     payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "扣费");
                     payTransactiondetails.setTranstype(2);
@@ -160,7 +160,7 @@ public class PayFeeServiceImp implements PayFeeService {
 
                     PayPayReceived payPayReceived = getReceived(payReceivable, year, month, localDateTime,5,payseriesno,remaining,feetypeMap, siteId, customerId, userId );
 
-                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5, paywayName,localDateTime, payCustomRechargeDto, payseriesno, month, year, remaining.negate() , siteId, customerId, userId );
+                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5, "预存账户",localDateTime, payCustomRechargeDto, payseriesno, month, year, remaining.negate() , siteId, customerId, userId );
                     payTransactiondetails.setReceivedId(payPayReceived.getId());
                     payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "扣费");
                     payTransactiondetails.setTranstype(2);
@@ -386,7 +386,7 @@ public class PayFeeServiceImp implements PayFeeService {
                     //生成并保存实收
                     PayPayReceived payPayReceived = getReceived(payReceivable, year, month, localDateTime,5,payseriesno,payReceivable.getDebt(),feetypeMap, siteId, customerId, userId );
                     //生成交易明细
-                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5,paywayName, localDateTime, payCustomRechargeDto, payseriesno, month, year, payReceivable.getDebt().negate(), siteId, customerId, userId );
+                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5,"预存账户", localDateTime, payCustomRechargeDto, payseriesno, month, year, payReceivable.getDebt().negate(), siteId, customerId, userId );
                     payTransactiondetails.setReceivedId(payPayReceived.getId());
                     payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "扣费");
                     payTransactiondetails.setTranstype(2);
@@ -402,7 +402,7 @@ public class PayFeeServiceImp implements PayFeeService {
                     //生成并保存实收
                     PayPayReceived payPayReceived = getReceived(payReceivable, year, month, localDateTime,5,payseriesno,remaining,feetypeMap, siteId, customerId, userId );
 
-                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5, paywayName,localDateTime, payCustomRechargeDto, payseriesno, month, year, remaining.negate() , siteId, customerId, userId );
+                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5, "预存账户",localDateTime, payCustomRechargeDto, payseriesno, month, year, remaining.negate() , siteId, customerId, userId );
                     payTransactiondetails.setReceivedId(payPayReceived.getId());
                     payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "扣费");
                     payTransactiondetails.setTranstype(2);

+ 16 - 14
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayInvoiceServiceImpl.java

@@ -119,16 +119,16 @@ public class PayInvoiceServiceImpl implements PayinvoiceService {
             if(payTransactiondetails.getInvoiceId()!=null){
                 throw new ServiceException(ResultStatus.PAY_INVOICE_EXISTED);
             }
+            invoice.setAccountId(payTransactiondetails.getAccountId());
+            invoice.setAccountname(payTransactiondetails.getAccountname());
+            invoice.setAccountnumber(payTransactiondetails.getAccountnumber());
+            invoice.setOfficeId(payTransactiondetails.getOfficeId());
+            invoice.setYear(payTransactiondetails.getYear());
+            invoice.setMonth(payTransactiondetails.getMonth());
             //转预存或充值金额
             if(payTransactiondetails.getPayway()!=5&&(payTransactiondetails.getTranstype()==1||payTransactiondetails.getTranstype()==4)){
                 countReceivedamount = countReceivedamount.add(payTransactiondetails.getTransamount()!=null?payTransactiondetails.getTransamount():BigDecimal.ZERO);
 
-                invoice.setAccountId(payTransactiondetails.getAccountId());
-                invoice.setAccountname(payTransactiondetails.getAccountname());
-                invoice.setAccountnumber(payTransactiondetails.getAccountnumber());
-                invoice.setOfficeId(payTransactiondetails.getOfficeId());
-                invoice.setYear(payTransactiondetails.getYear());
-                invoice.setMonth(payTransactiondetails.getMonth());
             }
         }
         //获取同批次号的实收信息
@@ -138,16 +138,16 @@ public class PayInvoiceServiceImpl implements PayinvoiceService {
             if(received.getInvoiceId()!=null){
                 throw new ServiceException(ResultStatus.PAY_INVOICE_EXISTED);
             }
+            invoice.setAccountId(received.getAccountId());
+            invoice.setAccountname(received.getAccountname());
+            invoice.setAccountnumber(received.getAccountnumber());
+            invoice.setOfficeId(received.getOfficeId());
+            invoice.setYear(received.getYear());
+            invoice.setMonth(received.getMonth());
             //非预存划扣(即支付金额抵扣)
             if(received.getPayway()!=5){
                 countReceivedamount = countReceivedamount.add(received.getReceivedamount()!=null?received.getReceivedamount():BigDecimal.ZERO);
 
-                invoice.setAccountId(received.getAccountId());
-                invoice.setAccountname(received.getAccountname());
-                invoice.setAccountnumber(received.getAccountnumber());
-                invoice.setOfficeId(received.getOfficeId());
-                invoice.setYear(received.getYear());
-                invoice.setMonth(received.getMonth());
             }
 
         }
@@ -240,13 +240,15 @@ public class PayInvoiceServiceImpl implements PayinvoiceService {
 
 
         BigDecimal receivedFee=BigDecimal.ZERO;
-        BigDecimal debt=BigDecimal.ZERO;
+        BigDecimal debt=BigDecimal.ZERO;//缴纳的欠费
+        BigDecimal autoReceivedamount=BigDecimal.ZERO;//划扣的欠费
         //计算出缴纳的欠费金额
         for(PrintReceivedInfo receivedInfo:payfeeInfoPrint){
             debt=debt.add(receivedInfo.getReceivedamount());
+            autoReceivedamount=autoReceivedamount.add(receivedInfo.getAutoReceivedamount());
         }
         //计算出实收金额
-        receivedFee= debt.add(printInvoiceData.getRemaining()).subtract(printInvoiceData.getLastRemaining());
+        receivedFee= debt.add(autoReceivedamount).add(printInvoiceData.getRemaining()).subtract(printInvoiceData.getLastRemaining());
         printInvoiceData.setReceivablefee(debt);
         printInvoiceData.setTransamount(receivedFee);
         printInvoiceData.setPrintReceivedInfo(payfeeInfoPrint);

+ 2 - 0
smart-city-platform/src/main/resources/mapper/DeviceDataDimMapper.xml

@@ -260,6 +260,7 @@
 			left join sc_device d on (ddd.device_id = d.id)
 		WHERE
 			d.sys_id != -99
+         and d.sys_id != 55
 		 and ddd.send_time >= #{beginDate ,jdbcType=TIMESTAMP } 
 		 and ddd.send_time <![CDATA[ < ]]> #{endDate ,jdbcType=TIMESTAMP } 
 		 and ddd.device_id IN ( 
@@ -289,6 +290,7 @@
 			left join sc_device_type dt on (d.device_type = dt.id)
 		WHERE
 			 d.sys_id != -99
+         and d.sys_id != 55
 		 and ddd.send_time >= #{beginDate ,jdbcType=TIMESTAMP } 
 		 and ddd.send_time <![CDATA[ < ]]> #{endDate ,jdbcType=TIMESTAMP } 
 		 and ddd.device_id IN ( 

+ 1 - 0
smart-city-platform/src/main/resources/mapper/DeviceMapper.xml

@@ -938,6 +938,7 @@
         left join sc_device_manufacturer f on (dt.manufacturer_id = f.id)
         where d.`status` = 1
         and d.sys_id != -99
+        and d.sys_id != 55
         and d.id in (
         SELECT
         dd.device_id

+ 127 - 36
smart-city-platform/src/main/resources/mapper/pay/PayChargeSurveyMapper.xml

@@ -51,24 +51,28 @@
     </select>
 
     <select id="getMeterNumber" resultType="java.lang.Integer">
-        select
-            count(de.id)
-        from sc_device de
-        left join pay_base_customerandmeterrela customer  on de.account_id = customer.account_id
+        select count(1)
+        from  sc_device scd
+        left join sc_install_list scinstall on scd.id = scinstall.device_id  and scinstall.customer_id=#{customerId}
+        left JOIN sc_device_type sdt on sdt.id = scd.device_type
+        left join sc_device_manufacturer sdm on sdm.id = sdt.manufacturer_id and sdm.`status`=1
+        left join pay_base_account pba on pba.id = scd.account_id  and pba.site_id=#{siteId} and pba.customer_id=#{customerId}
+        left join pay_base_customerandmeterrela ppr on ppr.metercode = scd.metercode and ppr.site_id=#{siteId} and ppr.customer_id=#{customerId}
+        left join
+        (SELECT a.watermeter_id,a.reading FROM pay_amount_waterusedamount_day AS a,
+        (SELECT b.watermeter_id, MAX(b.read_date) AS read_date FROM pay_amount_waterusedamount_day AS b
+        where b.reading is not null and b.customer_id=#{customerId} and b.site_id=#{siteId}
+        GROUP BY b.watermeter_id)
+        AS c WHERE a.watermeter_id=c.watermeter_id AND a.read_date = c.read_date)  rd on rd.watermeter_id = scd.id
         <where>
-            customer.businessstate = '1'
-            <if test="startDate != null and startDate != ''">
-                and convert(de.date_create,DATETIME) &gt;=#{startDate}
-            </if>
-            <if test="endDate != null and endDate != ''">
-                and convert(de.date_create,DATETIME) &lt;=#{endDate}
-            </if>
-            <if test="siteId != null">
-                and customer.site_id =#{siteId}
+            scd.customer_id =#{customerId} and scd.account_id is not null
+            <if test="startDate != null">
+                and scinstall.date_create &gt;=#{startDate}
             </if>
-            <if test="customerId != null">
-                and customer.customer_id =#{customerId}
+            <if test="endDate != null">
+                and scinstall.date_create &lt;=#{endDate}
             </if>
+            and(scinstall.is_accepted = 1 or scinstall.is_accepted = 2)
         </where>
     </select>
 
@@ -165,15 +169,9 @@
 
     <select id="getlastAccount" resultType="com.bz.smart_city.entity.pay.PayAccountSurvey">
         select
-            a.id as "id",
-            a.account_number as "accountNumber",
-            a.last_account_number as "lastAccountNumber",
-            a.meter_number as "meterNumber",
-            a.last_meter_number as "lastMeterNumber",
-            a.customer_number as "customerNumber",
-            a.last_customer_number as "lastCustomerNumber",
-            a.year as "year",
-            a.month as "month"
+            IFNULL(sum(a.account_number),0) as "accountNumber",
+            IFNULL(sum(a.meter_number),0) as "meterNumber",
+            IFNULL(sum(a.customer_number),0) as "customerNumber"
         from pay_account_survey a
         <where>
             <if test="periodDate != null">
@@ -190,11 +188,35 @@
 
     <select id="getCurrentTran" resultType="java.math.BigDecimal">
         select
-            sum(transamount)
+            IFNULL(sum(transamount),0)
         from pay_pay_transactiondetails a
         <where>
             <!-- 排除退款跟预存抵扣-->
-            a.state =  1 and a.payway != 5
+            a.state =  1 and canceledrecord_id is null and iscanceled = 0
+            and (a.payway = 1 or a.payway = 2 or a.payway=3 or a.payway = 4)
+            <if test="siteId != null">
+                and a.site_id =#{siteId}
+            </if>
+            <if test="customerId != null">
+                and a.customer_id =#{customerId}
+            </if>
+            <if test="year != null">
+                and a.year =#{year}
+            </if>
+            <if test="month != null">
+                and a.month =#{month}
+            </if>
+        </where>
+    </select>
+
+    <select id="getReceivedCurrent" resultType="java.math.BigDecimal">
+        select
+            IFNULL(sum(receivedamount),0)
+        from pay_pay_received a
+        <where>
+            <!-- 排除退款跟预存抵扣-->
+            canceledrecord_id is null and iscanceled = 0
+            and (a.payway = 1 or a.payway = 2 or a.payway=3 or a.payway = 4)
             <if test="siteId != null">
                 and a.site_id =#{siteId}
             </if>
@@ -220,7 +242,7 @@
             payway
         from pay_pay_transactiondetails a
         <where>
-            a.payway != 5 and a.state =  1
+            a.payway != 5 and a.state =  1 and canceledrecord_id is null and iscanceled = 0
             <if test="year != null">
                 and a.year =#{year}
             </if>
@@ -292,15 +314,42 @@
 
     <select id="getCurrentTranRocord" resultType="com.bz.smart_city.entity.pay.PayTransactionSurvey">
         select
-        case when a.payway =  1 then sum(transamount)
-        when a.payway = 2 then sum(transamount)
-        when a.payway = 3 then sum(transamount)
-        when a.payway = 4 then sum(transamount)
-        end as "incomeNumber",
-        payway as "payway"
+            case when a.payway =  1 then sum(transamount)
+            when a.payway = 2 then sum(transamount)
+            when a.payway = 3 then sum(transamount)
+            when a.payway = 4 then sum(transamount)
+            end as "incomeNumber",
+            payway as "payway"
         from pay_pay_transactiondetails a
         <where>
-            a.payway != 5 and a.state =  1
+            a.payway != 5 and a.state =  1 and canceledrecord_id is null and iscanceled = 0
+            <if test="year != null">
+                and a.year =#{year}
+            </if>
+            <if test="month != null">
+                and a.month =#{month}
+            </if>
+            <if test="siteId != null">
+                and a.site_id =#{siteId}
+            </if>
+            <if test="customerId != null">
+                and a.customer_id =#{customerId}
+            </if>
+        </where>
+        GROUP BY a.payway
+    </select>
+
+    <select id="getCurrentReceived" resultType="com.bz.smart_city.entity.pay.PayTransactionSurvey">
+        select
+            case when a.payway =  1 then sum(receivedamount)
+            when a.payway = 2 then sum(receivedamount)
+            when a.payway = 3 then sum(receivedamount)
+            when a.payway = 4 then sum(receivedamount)
+            end as "incomeNumber",
+            payway as "payway"
+        from pay_pay_received a
+        <where>
+            a.payway != 5 and a.state =  1 and canceledrecord_id is null and iscanceled = 0
             <if test="year != null">
                 and a.year =#{year}
             </if>
@@ -370,8 +419,12 @@
     </select>
 
     <select id="getSumReceived" resultType="java.math.BigDecimal">
-        select IFNULL(sum(payamount),0) from pay_pay_received a
+        select IFNULL(sum(receivedamount),0) from pay_pay_received a
         <where>
+            a.payway != 5
+            AND a.state = 1
+            AND canceledrecord_id IS NULL
+            AND iscanceled = 0
             <if test="year != null">
                 and a.year =#{year}
             </if>
@@ -390,7 +443,7 @@
     <select id="getSumPrestore" resultType="java.math.BigDecimal">
         select IFNULL(sum(transamount),0) from pay_pay_transactiondetails a
         <where>
-            transtype = '4'
+            (transtype = '1' or transtype = '4')  and canceledrecord_id is null and iscanceled = 0
             <if test="year != null">
                 and a.year =#{year}
             </if>
@@ -494,6 +547,25 @@
             </if>
         </where>
     </select>
+    <select id="getAmountSureyInfo" resultType="java.math.BigDecimal">
+        select
+            IFNULL(sum(amount_number),0)
+        from pay_amount_survey a
+        <where>
+            <if test="startDate != null">
+                and CONVERT( a.period_date, DATETIME )  &gt;=#{startDate}
+            </if>
+            <if test="endDate != null">
+                and CONVERT( a.period_date, DATETIME )  &lt;=#{endDate}
+            </if>
+            <if test="siteId != null">
+                and a.site_id =#{siteId}
+            </if>
+            <if test="customerId != null">
+                and a.customer_id =#{customerId}
+            </if>
+        </where>
+    </select>
 
     <select id="getAmountMonth" resultType="java.math.BigDecimal">
         select
@@ -514,6 +586,25 @@
             </if>
         </where>
     </select>
+    <select id="getAmountMonthSurvey" resultType="java.math.BigDecimal">
+        select
+            IFNULL(sum(amount_number),0)
+        from pay_amount_survey a
+        <where>
+            <if test="siteId != null">
+                and a.site_id =#{siteId}
+            </if>
+            <if test="customerId != null">
+                and a.customer_id =#{customerId}
+            </if>
+            <if test="year != null">
+                and a.year =#{year}
+            </if>
+            <if test="month != null">
+                and a.month =#{month}
+            </if>
+        </where>
+    </select>
 
     <select id="getAmountGroupList" resultType="com.bz.smart_city.dto.pay.PayAmountSurveyListDto">
         select

+ 3 - 3
smart-city-platform/src/main/resources/mapper/pay/PayTransactiondetailsMapper.xml

@@ -391,7 +391,7 @@
             ,max(cancelperson) cancelperson
             ,max(invoice_id) as "invoiceId"
             from pay_pay_received
-            where canceledrecord_id is null
+            where canceledrecord_id is null and payway !=5
                 and site_id=#{siteId} and customer_id = #{customerId}
                 <if test="beginTime != null">
                     and create_date >= #{beginTime}
@@ -495,8 +495,8 @@
                                 ,min(canceltime) canceltime
                                 ,min(cancelperson) cancelperson
                             from pay_pay_received
-                            where canceledrecord_id is null
-                         and site_id=#{siteId} and customer_id = #{customerId}
+                            where canceledrecord_id is null and payway !=5
+                                and site_id=#{siteId} and customer_id = #{customerId}
                             group by office_id,payseriesno
                     ) r on r.payseriesno = a.payseriesno
         left join sc_user u on ifnull(r.cancelperson,t.cancelperson) = u.id

+ 18 - 18
smart-city-platform/src/main/resources/mapper/pay/payFeeMapper.xml

@@ -140,28 +140,28 @@
 
     <select id="getPayfeeDetaileBill" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetaileBill">
         select
-            sum(debt) debt ,
-            sum(debt)-(select remaining from pay_pay_rechargeaccount where account_id=#{accountId}) as "receivableFee",
-            (select remaining from pay_pay_rechargeaccount where account_id=#{accountId})-sum(debt) as "waterFee"
-        from pay_pay_receivable
-        where debt>0
-        and account_id=#{accountId}
-
+            IFNULL(sum(r.debt),0) debt ,
+            (case when (IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0)) &lt;=0 then 0
+            else (IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0) )end) as "receivableFee",
+            IFNULL(max(remaining),0)-IFNULL(sum(r.debt),0) as "waterFee"
+        from pay_pay_rechargeaccount a
+        left join pay_pay_receivable r on a.account_id=r.account_id
+        where a.account_id = #{accountId}
     </select>
 
     <select id="getPayfeeDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetailed">
         select
-            account_id as "acountID",
-            sum(case when feetype=1 then debt else 0 end) waterFee1,
-            sum(case when feetype=2 then debt else 0 end) waterFee2,
-            sum(case when feetype=3 then debt else 0 end) waterFee3,
-            sum(case when feetype=4 then debt else 0 end) waterFee4,
-            sum(case when feetype=5 then debt else 0 end) waterFee5,
-            sum(case when feetype=6 then debt else 0 end) waterFee6
-        from pay_pay_receivable
-        where debt>0
-        and account_id=#{accountId}
-        group by  account_id
+            r.account_id as "accountId",
+            IFNULL(sum(case when r.feetype=1 then r.debt else 0 end),0) waterFee1,
+            IFNULL(sum(case when r.feetype=2 then r.debt else 0 end),0) waterFee2,
+            IFNULL(sum(case when r.feetype=3 then r.debt else 0 end),0) waterFee3,
+            IFNULL(sum(case when r.feetype=4 then r.debt else 0 end),0) waterFee4,
+            IFNULL(sum(case when r.feetype=5 then r.debt else 0 end),0) waterFee5,
+            IFNULL(sum(case when r.feetype=6 then r.debt else 0 end),0) waterFee6
+        from pay_pay_rechargeaccount a
+        left join pay_pay_receivable r on a.account_id=r.account_id
+        where a.account_id=#{accountId}
+        group by  a.account_id
     </select>
 
     <select id="getPayreceivableDebt" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">