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

1首页概况-交易明细

Xiaojh преди 4 години
родител
ревизия
9aaf126934

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

@@ -7,6 +7,8 @@ import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto;
 import com.bz.smart_city.dto.pay.PayChargeSurveyDto;
+import com.bz.smart_city.dto.pay.PayTransactionSurveyDto;
+import com.bz.smart_city.entity.pay.PayTransactionSurvey;
 import com.bz.smart_city.entity.pay.archives.CustomerListInfo;
 import com.bz.smart_city.service.pay.PayChargeSurveyService;
 import io.swagger.annotations.Api;
@@ -34,11 +36,18 @@ public class PayChargeSurveyController {
     private PayChargeSurveyService payChargeSurveyService;
 
     @PostMapping("/accountSurvey")
-    @ApiOperation(value = "计费系统-客户概")
+    @ApiOperation(value = "计费系统-客户概")
     public AjaxMessage<PayChargeSurveyDto> accountSurvey(){
 
         PayChargeSurveyDto payChargeSurveyDto = payChargeSurveyService.accountSurvey();
 
         return new AjaxMessage<PayChargeSurveyDto>(ResultStatus.OK, payChargeSurveyDto);
     }
+
+    @PostMapping("/tranSurvey")
+    @ApiOperation(value = "计费系统-交易概况")
+    public AjaxMessage<PayTransactionSurveyDto> tranSurvey(@ApiParam(value = "账期", required = true,defaultValue = "2020-07") @RequestParam(required = true) String periodDate){
+        PayTransactionSurveyDto payTransactionSurvey = payChargeSurveyService.tranSurvey(periodDate);
+        return new AjaxMessage<PayTransactionSurveyDto>(ResultStatus.OK, payTransactionSurvey);
+    }
 }

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

@@ -2,6 +2,7 @@ package com.bz.smart_city.dao.pay;
 
 import com.bz.smart_city.dto.pay.PayChangePeriodDto;
 import com.bz.smart_city.entity.pay.PayAccountSurvey;
+import com.bz.smart_city.entity.pay.PayTransactionSurvey;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -33,4 +34,18 @@ public interface PayChargeSurveyMapper {
 
     public PayAccountSurvey getlastAccount(@Param("periodDate")String startDate,
                                            @Param("siteId")BigInteger siteId, @Param("customerId")BigInteger customerId);
+
+    public BigDecimal getCurrentTran(@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);
+
+    public void insertTransaction(PayTransactionSurvey payTransactionSurvey);
+
+    public List<PayTransactionSurvey> getCurrentTranRocord(@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);
 }

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

@@ -0,0 +1,48 @@
+package com.bz.smart_city.dto.pay;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@Data
+@ApiModel("交易概况DTO")
+public class PayTransactionSurveyDto {
+    @ApiModelProperty(value = "收入总数")
+    private BigDecimal incomeNumber;
+    @ApiModelProperty(value = "较上月比率")
+    private String lastIncomeRate;
+    @ApiModelProperty(value = "现金")
+    private BigDecimal cashIncome;
+    @ApiModelProperty(value = "较上月比率")
+    private String lastCashRate;
+    @ApiModelProperty(value = "微信支付")
+    private BigDecimal wechatIncome;
+    @ApiModelProperty(value = "较上月比率")
+    private String lastWechatRate;
+    @ApiModelProperty(value = "支付宝支付")
+    private BigDecimal alipayIncome;
+    @ApiModelProperty(value = "较上月比率")
+    private String lastAlipayRate;
+    @ApiModelProperty(value = "银行收入")
+    private BigDecimal bankIncome;
+    @ApiModelProperty(value = "较上月比率")
+    private String lastBankRate;
+    @ApiModelProperty(value = "账期年")
+    private Integer year;
+    @ApiModelProperty(value = "账期月")
+    private Integer month;
+    @ApiModelProperty(value = "账期")
+    private LocalDateTime periodDate;
+    private String periodDates;
+    @ApiModelProperty(value = "现金占比率")
+    private String CashRate;
+    @ApiModelProperty(value = "支付宝占比率")
+    private String alipayRate;
+    @ApiModelProperty(value = "微信占比率")
+    private String wechatRate;
+    @ApiModelProperty(value = "银行占比率")
+    private String bankRate;
+}

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

@@ -0,0 +1,41 @@
+package com.bz.smart_city.entity.pay;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+
+@Data
+@ApiModel("用水量统计表")
+public class PayAmountSurvey {
+    @ApiModelProperty(value = "id", position = 1)
+    private BigInteger id;
+    @ApiModelProperty(value = "水量统计", position = 2)
+    private BigInteger amountNumber;
+    @ApiModelProperty(value = "账期年", position = 3)
+    private String year;
+    @ApiModelProperty(value = "账期月", position = 4)
+    private String month;
+    @ApiModelProperty(value = "创建者", hidden = true)
+    private BigInteger createBy;
+    @ApiModelProperty(value = "修改者", hidden = true)
+    private BigInteger updateBy;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间", hidden = true)
+    private LocalDateTime createDate = LocalDateTime.now();
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间", hidden = true)
+    private LocalDateTime updateDate = LocalDateTime.now();
+    @ApiModelProperty(value = "备注", hidden = true)
+    private String remarks;
+    @ApiModelProperty(value = "删除标识", hidden = true)
+    private String delFlag;
+    @ApiModelProperty(value = "站点ID", hidden = true)
+    private BigInteger siteId;
+    @ApiModelProperty(value = "水司ID", hidden = true)
+    private BigInteger customerId;
+
+}

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

@@ -0,0 +1,63 @@
+package com.bz.smart_city.entity.pay;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+
+@Data
+@ApiModel("交易概况表")
+public class PayTransactionSurvey {
+    @ApiModelProperty(value = "id")
+    private String id;
+    @ApiModelProperty(value = "收入总数")
+    private BigDecimal incomeNumber;
+    @ApiModelProperty(value = "上一账期收入总数")
+    private BigDecimal lastIncomeNumber;
+    @ApiModelProperty(value = "现金")
+    private BigDecimal cashIncome;
+    @ApiModelProperty(value = "上一账期现金汇总")
+    private BigDecimal lastCashIncome;
+    @ApiModelProperty(value = "微信支付")
+    private BigDecimal wechatIncome;
+    @ApiModelProperty(value = "上一账期微信支付汇总")
+    private BigDecimal lastWechatIncome;
+    @ApiModelProperty(value = "支付宝支付")
+    private BigDecimal alipayIncome;
+    @ApiModelProperty(value = "上一账期支付宝汇总")
+    private BigDecimal lastAlipayIncome;
+    @ApiModelProperty(value = "银行收入")
+    private BigDecimal bankIncome;
+    @ApiModelProperty(value = "上一账期银行汇总")
+    private BigDecimal lastBankIncome;
+    @ApiModelProperty(value = "账期年")
+    private Integer year;
+    @ApiModelProperty(value = "账期月")
+    private Integer month;
+    @ApiModelProperty(value = "账期")
+    private LocalDateTime periodDate;
+    @ApiModelProperty(value = "支付方式")
+    private Integer payway;
+    @ApiModelProperty(value = "创建者", hidden = true)
+    private String createBy;
+    @ApiModelProperty(value = "修改者", hidden = true)
+    private String updateBy;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间", hidden = true)
+    private LocalDateTime createDate = LocalDateTime.now();
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间", hidden = true)
+    private LocalDateTime updateDate = LocalDateTime.now();
+    @ApiModelProperty(value = "备注", hidden = true)
+    private String remarks;
+    @ApiModelProperty(value = "删除标识", hidden = true)
+    private String delFlag;
+    @ApiModelProperty(value = "站点ID", hidden = true)
+    private BigInteger siteId;
+    @ApiModelProperty(value = "水司ID", hidden = true)
+    private BigInteger customerId;
+}

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

@@ -12,12 +12,14 @@ import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto;
 import com.bz.smart_city.dto.pay.PayBaseConfigDto;
 import com.bz.smart_city.entity.pay.PayAccountSurvey;
+import com.bz.smart_city.entity.pay.PayTransactionSurvey;
 import com.bz.smart_city.service.pay.BaseClosingAccountInfoService;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
@@ -125,16 +127,20 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
                     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());
+                        //历史交易数据
+                        this.insertTransaction(list.get(i).getYear(),list.get(i).getMonth());
                     }
                 }
             }else if(count > 0){
                 //存储本期未结账数据
-                this.insertAccountNumber(year,month);
+                //this.insertAccountNumber(year,month);
+                //本期交易未结账数据
+                this.insertTransaction(year,month);
             }
 
             // 更新本账期
-            String msg2 = year + "年" + String.format("%02d", month) + "月已经结账";
+            /*String msg2 = year + "年" + String.format("%02d", month) + "月已经结账";
             baseClosingAccountInfoDto.setEndTime(new Date());
             baseClosingAccountInfoDto.setRemarks(msg2);
             baseClosingAccountInfoDto.setState(1);
@@ -158,7 +164,7 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
                 baseClosingAccountInfoDto.setMonth(1);
             }
             baseClosingAccountInfoDto.setName(baseClosingAccountInfoDto.getYear()+"年"+String.format("%02d", baseClosingAccountInfoDto.getMonth())+"月");
-            this.add(baseClosingAccountInfoDto);
+            this.add(baseClosingAccountInfoDto);*/
         }else{
             message.setStatus(-707);
             message.setMsg(msg);
@@ -168,6 +174,7 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
         return message;
     }
 
+    //添加客户概况信息
     public void insertAccountNumber(Integer year,Integer month){
         LoginUser loginUser = UserUtil.getCurrentUser();
 
@@ -177,57 +184,173 @@ public class BaseClosingAccountInfoServiceImpl implements BaseClosingAccountInfo
         //查询上月总数
         Integer lastYear = null;
         Integer lastMonth = null;
-        if(month == 1){
-            lastYear = year-1;
-            lastMonth = 12;
-        }else{
-            lastYear = year;
-            lastMonth = month -1;
+        try {
+            if(month == 1){
+                lastYear = year-1;
+                lastMonth = 12;
+            }else{
+                lastYear = year;
+                lastMonth = month -1;
+            }
+
+            //根据账期查找历史客户数(仅统计状态为欠费与正常的客户总数之和)
+            Integer accountNumber = payChargeSurveyMapper.getAccountNumber
+                    (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+            //根据账期查找历史水表数(仅统计状态为已开户的水表总数)
+            Integer meterNumber = payChargeSurveyMapper.getMeterNumber
+                    (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+            //根据账期查找历史开户数(仅统计状态为正常的开户总数)
+            Integer customerNumber = payChargeSurveyMapper.getCustomerNumber
+                    (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+
+            //上一账期汇总
+            PayAccountSurvey lastAccount = payChargeSurveyMapper.getlastNumber(lastYear,lastMonth,
+                    BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+
+            PayAccountSurvey account = new PayAccountSurvey();
+            if(lastAccount != null){
+                //上月总数赋值
+                account.setLastAccountNumber(lastAccount.getAccountNumber() != null ? lastAccount.getAccountNumber() : 0);
+                account.setLastMeterNumber(lastAccount.getMeterNumber() != null ? lastAccount.getMeterNumber() : 0);
+                account.setLastCustomerNumber(lastAccount.getCustomerNumber() != null ? lastAccount.getCustomerNumber() : 0);
+            }else{
+                account.setLastAccountNumber( 0);
+                account.setLastMeterNumber( 0);
+                account.setLastCustomerNumber( 0);
+            }
+            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            LocalDateTime ldt = LocalDateTime.parse(start+" 00:00:00",df);
+            account.setPeriodDate(ldt);
+            account.setId(Util.createUUIDId());
+            account.setAccountNumber(accountNumber);
+            account.setMeterNumber(meterNumber);
+            account.setCustomerNumber(customerNumber);
+            account.setYear(year);
+            account.setMonth(month);
+            account.setDelFlag("0");
+            account.setRemarks("");
+            account.setCreateBy(loginUser.getCreateBy());
+            account.setCreateDate(LocalDateTime.now());
+            account.setUpdateBy(loginUser.getCreateBy());
+            account.setUpdateDate(LocalDateTime.now());
+            account.setSiteId(BigInteger.valueOf(loginUser.getSiteId()));
+            account.setCustomerId(BigInteger.valueOf(loginUser.getCustomerId()));
+            //保存记录
+            payChargeSurveyMapper.insertAccountNumber(account);
+        }catch (Exception e) {
+            e.printStackTrace();
         }
+    }
 
-        //根据账期查找历史客户数(仅统计状态为欠费与正常的客户总数之和)
-        Integer accountNumber = payChargeSurveyMapper.getAccountNumber
-                (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
-        //根据账期查找历史水表数(仅统计状态为已开户的水表总数)
-        Integer meterNumber = payChargeSurveyMapper.getMeterNumber
-                (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
-        //根据账期查找历史开户数(仅统计状态为正常的开户总数)
-        Integer customerNumber = payChargeSurveyMapper.getCustomerNumber
-                (start,end,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
-
-        PayAccountSurvey lastAccount = payChargeSurveyMapper.getlastNumber(lastYear,lastMonth,
-                BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
-
-        PayAccountSurvey account = new PayAccountSurvey();
-        if(lastAccount != null){
-            //上月总数赋值
-            account.setLastAccountNumber(lastAccount.getAccountNumber() != null ? lastAccount.getAccountNumber() : 0);
-            account.setLastMeterNumber(lastAccount.getMeterNumber() != null ? lastAccount.getMeterNumber() : 0);
-            account.setLastCustomerNumber(lastAccount.getCustomerNumber() != null ? lastAccount.getCustomerNumber() : 0);
-        }else{
-            account.setLastAccountNumber( 0);
-            account.setLastMeterNumber( 0);
-            account.setLastCustomerNumber( 0);
+    /**
+     * 添加交易汇总数据
+     * @param year
+     * @param month
+     */
+    public void insertTransaction(Integer year,Integer month){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        BigInteger siteId = BigInteger.valueOf(loginUser.getSiteId());
+        BigInteger customerId = BigInteger.valueOf(loginUser.getCustomerId());
+        String start = year+"-"+(String.format("%02d",month))+"-01";
+        String end = year+"-"+(String.format("%02d",month))+"-31";
+        //查询上月总数
+        Integer lastYear = null;
+        Integer lastMonth = null;
+
+         PayTransactionSurvey transactionSurver= new PayTransactionSurvey();
+        try {
+            if(month == 1){
+                lastYear = year-1;
+                lastMonth = 12;
+            }else{
+                lastYear = year;
+                lastMonth = month -1;
+            }
+            //根据账期查找历史数据(现金、微信支付、支付宝、银行)
+            BigDecimal bigDecimalStr = new BigDecimal("0.0");
+            BigDecimal cuttentAmount = payChargeSurveyMapper.getCurrentTran(year,month,siteId,customerId);
+            cuttentAmount = cuttentAmount != null ? cuttentAmount : bigDecimalStr;
+            //上一账期
+            BigDecimal lastAmount = payChargeSurveyMapper.getCurrentTran(lastYear,lastMonth,siteId,customerId);
+            lastAmount = lastAmount != null ? lastAmount : bigDecimalStr;
+            //当前账期按支付方式划分
+            List<PayTransactionSurvey> tranList = payChargeSurveyMapper.getPayAmountList(year,month,siteId,customerId);
+            //上一账期按支付方式划分
+            List<PayTransactionSurvey> lasttranList = payChargeSurveyMapper.getPayAmountList(lastYear,lastMonth,siteId,customerId);
+
+            transactionSurver.setIncomeNumber(cuttentAmount);
+            transactionSurver.setLastIncomeNumber(lastAmount);
+            BigDecimal cashIncome = bigDecimalStr;//现金
+            BigDecimal wechatIncome = bigDecimalStr;//微信
+            BigDecimal alipayIncome = bigDecimalStr;//支付宝
+            BigDecimal bankIncome = bigDecimalStr;//银行
+            //当前账期
+            for(int i=0; i<tranList.size(); i++){
+                Integer payway = tranList.get(i).getPayway();
+                if(payway == 1){
+                    //支付宝
+                    alipayIncome = tranList.get(i).getIncomeNumber();
+                }else if(payway == 2){
+                    //微信
+                    wechatIncome = tranList.get(i).getIncomeNumber();
+                }else if (payway == 3) {
+                    //银行
+                    bankIncome = tranList.get(i).getIncomeNumber();
+                }else if (payway == 4) {
+                    //现金
+                    cashIncome = tranList.get(i).getIncomeNumber();
+                }
+            }
+            transactionSurver.setAlipayIncome(alipayIncome);
+            transactionSurver.setWechatIncome(wechatIncome);
+            transactionSurver.setBankIncome(bankIncome);
+            transactionSurver.setCashIncome(cashIncome);
+            BigDecimal lastAlipayIncome = bigDecimalStr;
+            BigDecimal lastWechatIncome = bigDecimalStr;
+            BigDecimal lastBankIncome = bigDecimalStr;
+            BigDecimal lastCashIncome = bigDecimalStr;
+            //上一账期
+            for(int i=0; i<lasttranList.size(); i++){
+                Integer payway = lasttranList.get(i).getPayway();
+                if(payway == 1){
+                    //支付宝
+                    lastAlipayIncome = lasttranList.get(i).getIncomeNumber();
+                }else if(payway == 2){
+                    //微信
+                    lastWechatIncome = lasttranList.get(i).getIncomeNumber();
+                }else if (payway == 3) {
+                    //银行
+                    lastBankIncome = lasttranList.get(i).getIncomeNumber();
+                }else if (payway == 4) {
+                    //现金
+                    lastCashIncome = lasttranList.get(i).getIncomeNumber();
+                }
+            }
+            transactionSurver.setLastAlipayIncome(lastCashIncome);
+            transactionSurver.setLastWechatIncome(lastWechatIncome);
+            transactionSurver.setLastBankIncome(lastBankIncome);
+            transactionSurver.setLastCashIncome(lastCashIncome);
+
+            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            LocalDateTime ldt = LocalDateTime.parse(start+" 00:00:00",df);
+            transactionSurver.setPeriodDate(ldt);
+            transactionSurver.setId(Util.createUUIDId());
+            transactionSurver.setYear(year);
+            transactionSurver.setMonth(month);
+            transactionSurver.setDelFlag("0");
+            transactionSurver.setRemarks("");
+            transactionSurver.setCreateBy(loginUser.getCreateBy());
+            transactionSurver.setCreateDate(LocalDateTime.now());
+            transactionSurver.setUpdateBy(loginUser.getCreateBy());
+            transactionSurver.setUpdateDate(LocalDateTime.now());
+            transactionSurver.setSiteId(BigInteger.valueOf(loginUser.getSiteId()));
+            transactionSurver.setCustomerId(BigInteger.valueOf(loginUser.getCustomerId()));
+
+            payChargeSurveyMapper.insertTransaction(transactionSurver);
+
+        }catch (Exception e) {
+            e.printStackTrace();
         }
-        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-        LocalDateTime ldt = LocalDateTime.parse(start+" 00:00:00",df);
-        account.setPeriodDate(ldt);
-        account.setId(Util.createUUIDId());
-        account.setAccountNumber(accountNumber);
-        account.setMeterNumber(meterNumber);
-        account.setCustomerNumber(customerNumber);
-        account.setYear(year);
-        account.setMonth(month);
-        account.setDelFlag("0");
-        account.setRemarks("");
-        account.setCreateBy(loginUser.getCreateBy());
-        account.setCreateDate(LocalDateTime.now());
-        account.setUpdateBy(loginUser.getCreateBy());
-        account.setUpdateDate(LocalDateTime.now());
-        account.setSiteId(BigInteger.valueOf(loginUser.getSiteId()));
-        account.setCustomerId(BigInteger.valueOf(loginUser.getCustomerId()));
-        //保存记录
-        payChargeSurveyMapper.insertAccountNumber(account);
     }
 
     @Override

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

@@ -7,7 +7,9 @@ import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto;
 import com.bz.smart_city.dto.pay.PayChangePeriodDto;
 import com.bz.smart_city.dto.pay.PayChargeSurveyDto;
+import com.bz.smart_city.dto.pay.PayTransactionSurveyDto;
 import com.bz.smart_city.entity.pay.PayAccountSurvey;
+import com.bz.smart_city.entity.pay.PayTransactionSurvey;
 import com.bz.smart_city.service.pay.PayChargeSurveyService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -37,7 +39,7 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
 
     public static void main(String[] args) {
       try {
-          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月日
+          /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月日
           Calendar startDate = Calendar.getInstance();//起始年月
           startDate.setTime(sdf.parse("2020-07-01"));
           startDate.add(Calendar.YEAR, -1); //月份减1;
@@ -45,7 +47,13 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
 
           Date lastStartMonth = startDate.getTime(); //结果
           String lastStart = sdf.format(lastStartMonth);
-          System.out.println("时间:"+lastStart);
+          System.out.println("时间:"+lastStart);*/
+          DecimalFormat df = new DecimalFormat("0.0");
+          BigDecimal currentIncome = new BigDecimal("100");
+          BigDecimal lastIncome = new BigDecimal("80");
+          BigDecimal income = currentIncome.subtract(lastIncome).divide(lastIncome).multiply(new BigDecimal("100"));
+          String a = df.format(income);
+          System.out.println("收入费率:"+a);
       }catch (Exception e) {
           e.printStackTrace();
       }
@@ -166,4 +174,187 @@ public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
         }
         return payChargeSurveyDto;
     }
+
+
+    public PayTransactionSurveyDto tranSurvey(String periodDate){
+        PayTransactionSurveyDto payTransactionSurveyDto = new PayTransactionSurveyDto();
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        BigInteger siteId = BigInteger.valueOf(loginUser.getSiteId());
+        BigInteger customerId = BigInteger.valueOf(loginUser.getCustomerId());
+        BigDecimal defc = new BigDecimal("0.0");
+        try {
+            //判断传过来的时间是否为当前账期,当前账期则查交易明细表,否则查交易记录表
+            String[] split = periodDate.split("-");
+            String y = split[0];
+            String m = split[1];
+            Integer year = Integer.valueOf(y);
+            Integer month = Integer.valueOf(m);
+
+            //本月
+            BigDecimal cashIncome = defc;//现金
+            BigDecimal wechatIncome = defc;//微信支付
+            BigDecimal alipayIncome = defc; //支付宝
+            BigDecimal bankIncome = defc;//银行
+            Integer lastYear = null;
+            Integer lastMonth = null;
+            if(Integer.valueOf(month) == 1){
+                lastYear = year-1;
+                lastMonth = 12;
+            }else{
+                lastYear = year;
+                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()))){
+                //当前账期查询交易明细表
+                List<PayTransactionSurvey> tranList = payChargeSurveyMapper.getCurrentTranRocord(year,month,siteId,customerId);
+                for(int i=0; i<tranList.size(); i++){
+                    Integer payway = tranList.get(i).getPayway();
+                    if(payway == 1){
+                        //支付宝
+                        alipayIncome = tranList.get(i).getIncomeNumber();
+                    }else if(payway == 2){
+                        //微信
+                        wechatIncome = tranList.get(i).getIncomeNumber();
+                    }else if (payway == 3) {
+                        //银行
+                        bankIncome = tranList.get(i).getIncomeNumber();
+                    }else if (payway == 4) {
+                        //现金
+                        cashIncome = tranList.get(i).getIncomeNumber();
+                    }
+                }
+                BigDecimal currentIncome = alipayIncome.add(wechatIncome).add(bankIncome).add(cashIncome);//当前账期收入总数
+                //查找上月收入
+                PayTransactionSurvey lastTran = payChargeSurveyMapper.getLastTranRocord(lastYear,lastMonth,siteId,customerId);
+                BigDecimal lastIncome = lastTran.getIncomeNumber();//上月总数
+                PayTransactionSurvey payTransactionSurvey = new PayTransactionSurvey();
+                payTransactionSurvey.setIncomeNumber(currentIncome);
+                payTransactionSurvey.setLastIncomeNumber(lastIncome);
+                payTransactionSurvey.setCashIncome(cashIncome);
+                payTransactionSurvey.setLastCashIncome(lastTran.getCashIncome() != null ? lastTran.getCashIncome() : defc);
+                payTransactionSurvey.setWechatIncome(wechatIncome);
+                payTransactionSurvey.setLastWechatIncome(lastTran.getWechatIncome() != null ? lastTran.getWechatIncome() : defc);
+                payTransactionSurvey.setAlipayIncome(alipayIncome);
+                payTransactionSurvey.setLastAlipayIncome(lastTran.getAlipayIncome() != null ? lastTran.getAlipayIncome() : defc);
+                payTransactionSurvey.setBankIncome(bankIncome);
+                payTransactionSurvey.setLastBankIncome(lastTran.getBankIncome() != null ? lastTran.getBankIncome() : defc);
+                payTransactionSurvey.setYear(year);
+                payTransactionSurvey.setMonth(month);
+                payTransactionSurveyDto = this.tranCompute(payTransactionSurvey);
+            }else {
+                //查询交易记录表
+                PayTransactionSurvey transactionSurver = payChargeSurveyMapper.getLastTranRocord(year,month,siteId,customerId);
+                transactionSurver.setYear(year);
+                transactionSurver.setMonth(month);
+                payTransactionSurveyDto = this.tranCompute(transactionSurver);
+
+            }
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return payTransactionSurveyDto;
+    }
+
+
+    public PayTransactionSurveyDto tranCompute(PayTransactionSurvey transactionSurver){
+        PayTransactionSurveyDto payTransactionSurveyDto = new PayTransactionSurveyDto();
+        Integer year = transactionSurver.getYear();
+        Integer month = transactionSurver.getMonth();
+        DecimalFormat df = new DecimalFormat("0.0");
+        BigDecimal defc = new BigDecimal("0.0");
+        BigDecimal defb = new BigDecimal("1.0");
+
+        //计算较上月比率
+        String lastCashRate = "";//现金比率
+        String lastWechatRate = "";//微信比率
+        String lastAlipayRate = "";//支付宝比率
+        String lastBankRate = "";//银行比率
+
+        //本月
+        BigDecimal cashIncome = defc;//现金
+        BigDecimal wechatIncome = defc;//微信支付
+        BigDecimal alipayIncome = defc; //支付宝
+        BigDecimal bankIncome = defc;//银行
+        //上月
+        BigDecimal lastcashIncome = defc;//现金
+        BigDecimal lastwechatIncome = defc;//微信支付
+        BigDecimal lastalipayIncome = defc; //支付宝
+        BigDecimal lastbankIncome = defc;//银行
+        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 = "";
+            lastIncomeRate = df.format(income);
+
+            //按支付方式
+            cashIncome = transactionSurver.getCashIncome();//本月现金收入
+            lastcashIncome = transactionSurver.getLastCashIncome();//上月现金收入
+            wechatIncome = transactionSurver.getWechatIncome();//本月微信
+            lastwechatIncome = transactionSurver.getLastWechatIncome();//上月微信
+            alipayIncome = transactionSurver.getAlipayIncome();//本月支付宝
+            lastalipayIncome = transactionSurver.getLastAlipayIncome();//上月支付宝
+            bankIncome = transactionSurver.getBankIncome();//本账期银行
+            lastbankIncome = transactionSurver.getLastBankIncome();//上期银行
+            //现金
+            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);
+
+            //微信
+            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);
+
+            //支付宝
+            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);
+
+            //银行
+            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);
+
+            //饼状态占比率
+            currentIncome = alipayIncome.add(wechatIncome).add(bankIncome).add(cashIncome);
+            String CashRate = "";
+            String alipayRate = "";
+            String wechatRate = "";
+            String bankRate = "";
+            income = cashIncome.divide(currentIncome,2, BigDecimal.ROUND_HALF_UP);
+            CashRate = df.format(income);
+
+            income = alipayIncome.divide(currentIncome,2, BigDecimal.ROUND_HALF_UP);
+            alipayRate = df.format(income);
+
+            income = wechatIncome.divide(currentIncome,2, BigDecimal.ROUND_HALF_UP);
+            wechatRate = df.format(income);
+
+            income = bankIncome.divide(currentIncome,2, BigDecimal.ROUND_HALF_UP);
+            bankRate = df.format(income);
+
+            //收入总数
+            payTransactionSurveyDto.setIncomeNumber(currentIncome);
+            payTransactionSurveyDto.setLastIncomeRate(lastIncomeRate);
+            //按支付方式
+            payTransactionSurveyDto.setCashIncome(cashIncome);
+            payTransactionSurveyDto.setLastCashRate(lastCashRate);
+            payTransactionSurveyDto.setWechatIncome(wechatIncome);
+            payTransactionSurveyDto.setLastWechatRate(lastWechatRate);
+            payTransactionSurveyDto.setAlipayIncome(alipayIncome);
+            payTransactionSurveyDto.setLastAlipayRate(lastAlipayRate);
+            payTransactionSurveyDto.setBankIncome(bankIncome);
+            payTransactionSurveyDto.setLastBankRate(lastBankRate);
+            payTransactionSurveyDto.setCashRate(CashRate);
+            payTransactionSurveyDto.setAlipayRate(alipayRate);
+            payTransactionSurveyDto.setWechatRate(wechatRate);
+            payTransactionSurveyDto.setBankRate(bankRate);
+            payTransactionSurveyDto.setYear(year);
+            payTransactionSurveyDto.setMonth(month);
+            payTransactionSurveyDto.setPeriodDates(year+"-"+String.format("%02d",month));
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return payTransactionSurveyDto;
+    }
 }

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

@@ -1,9 +1,13 @@
 package com.bz.smart_city.service.pay;
 
 import com.bz.smart_city.dto.pay.PayChargeSurveyDto;
+import com.bz.smart_city.dto.pay.PayTransactionSurveyDto;
+import com.bz.smart_city.entity.pay.PayTransactionSurvey;
 
 public interface PayChargeSurveyService {
     public Integer getAccountCount();
 
     public PayChargeSurveyDto accountSurvey();
+
+    public PayTransactionSurveyDto tranSurvey(String periodDate);
 }

+ 160 - 0
smart-city-platform/src/main/resources/mapper/pay/PayChargeSurveyMapper.xml

@@ -187,4 +187,164 @@
             </if>
         </where>
     </select>
+
+    <select id="getCurrentTran" resultType="java.math.BigDecimal">
+        select
+            sum(transamount)
+        from pay_pay_transactiondetails a
+        <where>
+            <!-- 排除退款跟预存抵扣-->
+            a.state =  1 and a.payway != 5
+            <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="getPayAmountList" 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)
+            else sum(transamount) end as "incomeNumber",
+            payway
+        from pay_pay_transactiondetails a
+        <where>
+            a.payway != 5 and a.state =  1
+            <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>
+
+    <insert id="insertTransaction">
+        insert into pay_transaction_survey
+        (
+            id,
+            income_number,
+            last_income_number,
+            cash_income,
+            last_cash_income,
+            wechat_income,
+            last_wechat_income,
+            alipay_income,
+            last_alipay_income,
+            bank_income,
+            last_bank_income,
+            year,
+            month,
+            period_date,
+            site_id,
+            customer_id,
+            create_by,
+            create_date,
+            update_by,
+            update_date,
+            remarks,
+            del_flag
+        )
+        values
+        (
+            #{id},
+            #{incomeNumber},
+            #{lastIncomeNumber},
+            #{cashIncome},
+            #{lastCashIncome},
+            #{wechatIncome},
+            #{lastWechatIncome},
+            #{alipayIncome},
+            #{lastAlipayIncome},
+            #{bankIncome},
+            #{lastBankIncome},
+            #{year},
+            #{month},
+            #{periodDate},
+            #{siteId},
+            #{customerId},
+            #{createBy},
+            #{createDate},
+            #{updateBy},
+            #{updateDate},
+            #{remarks},
+            #{delFlag}
+        )
+    </insert>
+
+    <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"
+        from pay_pay_transactiondetails a
+        <where>
+            a.payway != 5 and a.state =  1
+            <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="getLastTranRocord" resultType="com.bz.smart_city.entity.pay.PayTransactionSurvey">
+        select
+            income_number as "incomeNumber",
+            last_income_number as "lastIncomeNumber",
+            cash_income as "cashIncome",
+            last_cash_income as "lastCashIncome",
+            wechat_income as "wechatIncome",
+            last_wechat_income as "lastWechatIncome",
+            alipay_income as "alipayIncome",
+            last_alipay_income as "lastAlipayIncome",
+            bank_income as "bankIncome",
+            last_bank_income as "lastBankIncome",
+            year as "year",
+            month as "month"
+        from pay_transaction_survey a
+        <where>
+            <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>
+    </select>
 </mapper>