Explorar o código

整笔缴费(划扣),不足时不扣费

wangli %!s(int64=5) %!d(string=hai) anos
pai
achega
adde41e347
Modificáronse 24 ficheiros con 1753 adicións e 28 borrados
  1. 1 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/model/ResultStatus.java
  2. 125 5
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayFeeController.java
  3. 58 0
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayInvoiceController.java
  4. 18 1
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayPayReceiveContorller.java
  5. 21 1
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayFeeMapper.java
  6. 26 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayInvoiceMapper.java
  7. 61 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/PayInvoiceDto.java
  8. 53 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeAccountInfoDto.java
  9. 23 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeDetaileBill.java
  10. 36 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeDetailed.java
  11. 37 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeInvoice.java
  12. 41 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeReceivableInfo.java
  13. 38 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeReceivedInfo.java
  14. 43 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeWaterusedamount.java
  15. 58 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PrintInvoiceData.java
  16. 46 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayInvoice.java
  17. 12 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java
  18. 365 19
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayFeeServiceImp.java
  19. 174 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayInvoiceServiceImpl.java
  20. 101 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/pay/PayFeeService.java
  21. 64 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/pay/PayinvoiceService.java
  22. 144 0
      smart-city-platform/src/main/resources/mapper/pay/PayInvoiceMapper.xml
  23. 9 2
      smart-city-platform/src/main/resources/mapper/pay/PayPayReceivedMapper.xml
  24. 199 0
      smart-city-platform/src/main/resources/mapper/pay/payFeeMapper.xml

+ 1 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/model/ResultStatus.java

@@ -84,6 +84,7 @@ public enum ResultStatus {
     PAY_ADD_CUSTOMER_UPDATEAMOUNT(-722,"添加开户失败,计算阶梯可用量有误"),
     WATER_PROPERTY_CHENCK_NAME(-723,"该名称已经存在,请修改"),
     ACCOUNT_OPERATOR_EERROR(-724,"操作员信息异常"),
+    PAYFEE_NOT_ENOUGH(-724,"缴费金额不足"),
     CUSTOMER_IS_EXISTED(-3001,"客户名称已存在");
 
     private final int status;

+ 125 - 5
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayFeeController.java

@@ -2,16 +2,18 @@ package com.bz.smart_city.controller.pay;
 
 import com.bz.smart_city.commom.model.AjaxMessage;
 import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.dto.pay.PayInvoiceDto;
+import com.bz.smart_city.dto.pay.PayTransactiondetailsDto;
+import com.bz.smart_city.dto.pay.payfee.*;
 import com.bz.smart_city.service.pay.PayFeeService;
+import com.bz.smart_city.service.pay.PayPayReceivedService;
+import com.bz.smart_city.service.pay.PayTransactiondetailsService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -29,12 +31,17 @@ import java.util.stream.Collectors;
  */
 @RestController
 @RequestMapping("payFee")
-@Api(tags = "计费系统(水查查)—缴费—冲账接口")
+@Api(tags = "计费系统—缴费管理")
 public class PayFeeController {
 
 
     @Autowired
     PayFeeService payFeeService;
+    @Autowired
+    private PayPayReceivedService payPayReceivedService;
+    @Autowired
+    PayTransactiondetailsService payTransactiondetailsService;
+
 
     @PostMapping("/payFee")
     @ApiOperation(value="冲账接口,客户名称、客户编码、应收id不能同时为空")
@@ -66,4 +73,117 @@ public class PayFeeController {
                                                                             userId != null?Integer.parseInt(userId):null)
                 );
     }
+
+
+    @PostMapping("/payFeeCounter")
+    @ApiOperation(value="柜台缴费接口")
+    public AjaxMessage<String> payFeeCounter(
+            @ApiParam(value = "客户id", required = true) @RequestParam(required = true)String accountId,
+            @ApiParam(value = "支付方式", required = true) @RequestParam(required = true)Integer payway,
+            @ApiParam(value = "交易金额", required = true) @RequestParam(required = true)String transAmount,
+            @ApiParam(value = "是否转预存,0否 1是", required = true) @RequestParam(required = true)Integer balancetype
+
+    ){
+        //暂时先默认柜台支付为现金支付,后期区分
+     return new AjaxMessage(ResultStatus.OK, payFeeService.payFeeCounter(accountId,4,new BigDecimal(transAmount),balancetype));
+    }
+
+    @GetMapping("/findPayfeeAccountInfo")
+    @ApiOperation(value="收费界面查询客户信息,客户id是在查询出多用户时,选择某个用户")
+    public AjaxMessage<List<PayfeeAccountInfoDto>> findPayfeeAccountInfo(
+            @ApiParam(value = "开户id,查询多用户时,再次查询用id查询") @RequestParam(required = false)BigInteger id,
+            @ApiParam(value = "查询类型,1客户名称,2客户编码,3电话,4地址") @RequestParam(required = false)Integer queryType ,
+            @ApiParam(value = "查询内容") @RequestParam(required = false)String condition ){
+
+        return new AjaxMessage<List<PayfeeAccountInfoDto>>(ResultStatus.OK, payFeeService.findPayfeeAccountInfo(id, queryType , condition ));
+    }
+
+    @GetMapping("/getPayfeeDetaileBill")
+    @ApiOperation(value="查询账单详情")
+    public AjaxMessage<PayfeeDetaileBill> getPayfeeDetaileBill(
+            @ApiParam(value = "客户id",required = true) @RequestParam(required = true)BigInteger accountId){
+        return new AjaxMessage<PayfeeDetaileBill>(ResultStatus.OK,payFeeService.getPayfeeDetaileBill(accountId));
+
+    }
+
+    @GetMapping("/getPayfeeDetailed")
+    @ApiOperation(value="查询本账期欠费明细")
+    public AjaxMessage<PayfeeDetailed> getPayfeeDetailed(
+            @ApiParam(value = "客户id",required = true) @RequestParam(required = true)BigInteger accountId ){
+        return new AjaxMessage<>(ResultStatus.OK,payFeeService.getPayfeeDetailed(accountId));
+    }
+
+    @GetMapping("/getPayreceiveDebt")
+    @ApiOperation(value="收费页面————欠费信息")
+    public AjaxMessage<List<PayfeeReceivableInfo>> getPayreceiveDebt(
+            @ApiParam(value = "客户id",required = true) @RequestParam(required = true)BigInteger accountId ,
+            @ApiParam(value = "账期年",required = true) @RequestParam(required = true)Integer year
+    ){
+        return new AjaxMessage<>(ResultStatus.OK,payFeeService.getPayreceiveDebt(accountId,year));
+    }
+
+    @GetMapping("/getPayreceiveDebtDetailed")
+    @ApiOperation(value="收费页面————欠费信息详情")
+    public AjaxMessage<List<PayfeeReceivableInfo>> getPayreceiveDebtDetailed(
+            @ApiParam(value = "客户id",required = true) @RequestParam(required = true)BigInteger accountId,
+            @ApiParam(value = "账期年",required = true) @RequestParam(required = true)Integer year,
+            @ApiParam(value = "账期月",required = true) @RequestParam(required = true)Integer month
+    ){
+        return new AjaxMessage<>(ResultStatus.OK,payFeeService.getPayreceiveDebtDetailed(accountId,year,month));
+    }
+
+    @GetMapping("/getPayreceived")
+    @ApiOperation(value="收费页面————实收信息")
+    public AjaxMessage<List<PayfeeReceivedInfo>> getPayreceived(
+            @ApiParam(value = "客户id",required = true) @RequestParam(required = true)BigInteger accountId ,
+            @ApiParam(value = "账期年",required = true) @RequestParam(required = true)Integer year
+    ){
+        return new AjaxMessage<>(ResultStatus.OK,payFeeService.getPayreceived(accountId,year));
+    }
+
+    @GetMapping("/getPayreceivedDetailed")
+    @ApiOperation(value="收费页面————实收信息详情")
+    public AjaxMessage<List<PayfeeReceivedInfo>> getPayreceivedDetailed(
+            @ApiParam(value = "客户id" ,required = true) @RequestParam(required = true)BigInteger accountId,
+            @ApiParam(value = "交易流水号" ,required = true) @RequestParam(required = true)String payseriesno,
+            @ApiParam(value = "账期年",required = true) @RequestParam(required = true)Integer year,
+            @ApiParam(value = "账期月",required = true) @RequestParam(required = true)Integer month
+    ){
+        return new AjaxMessage<>(ResultStatus.OK,payFeeService.getPayreceivedDetailed(accountId,payseriesno,year,month));
+    }
+
+
+    @GetMapping("/getTransDetailed")
+    @ApiOperation(value="收费页面————交易明细详情")
+    public AjaxMessage<List<PayTransactiondetailsDto>> getListByYear(
+            @ApiParam(value = "客户id", required = true) @RequestParam(required = true) BigInteger accountId,
+            @ApiParam(value = "账期年", required = true) @RequestParam(required = true) Integer year
+    ){
+
+        PayTransactiondetailsDto payTransactiondetailsDto =new PayTransactiondetailsDto();
+        payTransactiondetailsDto.setAccountId(accountId);
+        payTransactiondetailsDto.setYear(year);
+        return new AjaxMessage<>(ResultStatus.OK, payTransactiondetailsService.selectTransactionList(payTransactiondetailsDto));
+    }
+
+    @GetMapping("/getWaterusedamount")
+    @ApiOperation(value="收费页面————水量信息")
+    public AjaxMessage<List<PayfeeWaterusedamount>> getWaterusedamount(
+            @ApiParam(value = "客户id" ,required = true) @RequestParam(required = true)BigInteger id,
+            @ApiParam(value = "账期年",required = true) @RequestParam(required = true)Integer year
+    ){
+        return new AjaxMessage<>(ResultStatus.OK,payFeeService.getWaterusedamount(id,year));
+    }
+
+    @GetMapping("/getPayinvoiceInfo")
+    @ApiOperation(value="收费页面————收据信息")
+    public AjaxMessage<List<PayInvoiceDto>> getPayinvoiceInfo(
+            @ApiParam(value = "客户id" ,required = true) @RequestParam(required = true)BigInteger id,
+            @ApiParam(value = "账期年",required = true) @RequestParam(required = true)Integer year
+    ){
+        return new AjaxMessage<>(ResultStatus.OK,payFeeService.getPayinvoiceInfo(id,year));
+    }
 }
+
+
+

+ 58 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayInvoiceController.java

@@ -0,0 +1,58 @@
+package com.bz.smart_city.controller.pay;
+
+import com.bz.smart_city.commom.model.AjaxMessage;
+import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.dto.pay.PayInvoiceDto;
+import com.bz.smart_city.dto.pay.PayMessageTemplateDto;
+import com.bz.smart_city.dto.pay.PayTransactiondetails;
+import com.bz.smart_city.entity.pay.PayInvoice;
+import com.bz.smart_city.service.pay.PayinvoiceService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import java.time.format.DateTimeFormatter;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-30 10:30
+ */
+@RestController
+@RequestMapping("payInvoice")
+@Api(tags = "计费系统—收据管理")
+public class PayInvoiceController {
+
+    @Autowired
+    private PayinvoiceService payinvoiceService;
+
+    @GetMapping("/getMessageTemplate")
+    @ApiOperation("查询收据")
+    public AjaxMessage<Pagination<PayInvoiceDto>> getMessageTemplate(
+            @ApiParam(value = "查询条件", required = false) @RequestParam(required = false) String condition,
+            @ApiParam(value = "收据状态", required = false) @RequestParam(required = false) Integer state,
+            @ApiParam(value = "开票时间开始", required = false) @RequestParam(required = false) String startTime,
+            @ApiParam(value = "开票时间结束", required = false) @RequestParam(required = false) String endTime,
+            @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum,
+            @ApiParam(value = "条数,非必传,默认10条", required = false, defaultValue = "10") @RequestParam(required = false, defaultValue = "10") int pageSize
+
+    ){
+        return new AjaxMessage<>(ResultStatus.OK,payinvoiceService.findListPage(condition, state, startTime, endTime,pageNum,pageSize));
+    }
+
+
+    @PostMapping("/savePrintInfo")
+    @ApiOperation("保存收据打印信息")
+    public AjaxMessage<String> savePrintInfo(
+            @ApiParam(value = "缴费批次号", required = true) @RequestParam(required = true) String payseriesno,
+            @ApiParam(value = "票据号码", required = true) @RequestParam(required = true) String invoiceno
+    ){
+        payinvoiceService.savePrintInfo( payseriesno, invoiceno);
+        return new AjaxMessage<>(ResultStatus.OK);
+    }
+
+}

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

@@ -76,6 +76,7 @@ public class PayPayReceiveContorller {
         @ApiParam(value = "账期年", required = true) @RequestParam(required = true)Integer year,
         @ApiParam(value = "账期月", required = true) @RequestParam(required = true) Integer month,
         @ApiParam(value = "客户编码", required = true) @RequestParam(required = true)String accountnumber,
+        @ApiParam(value = "客户Id", required = true) @RequestParam(required = true)String accountId,
         @ApiParam(value = "状态", required = false) @RequestParam(required = false) Integer state,
         @ApiParam(value = "支付方式", required = false) @RequestParam(required = false) Integer payway,
         @ApiParam(value = "开始日期,2020-04-08", required = false) @RequestParam(required = false) String beginDate,
@@ -102,7 +103,9 @@ public class PayPayReceiveContorller {
 
     @PostMapping("/cancelReceived")
     @ApiOperation(value = "计费系统-取消实收")
-    public AjaxMessage cancelReceived(BigInteger id){
+    public AjaxMessage cancelReceived(
+            @ApiParam(value = "实收id", required = true) @RequestParam(required = true)BigInteger id
+    ){
 
         //回退实收
         //作废第三方支付
@@ -111,4 +114,18 @@ public class PayPayReceiveContorller {
         int result = payPayReceivedService.cancelReceived(id);
         return new AjaxMessage<>(ResultStatus.OK,result);
     }
+
+    @PostMapping("/cancelReceived")
+    @ApiOperation(value = "计费系统-取消实收By流水号")
+    public AjaxMessage cancelReceivedByPayseriesno(
+            @ApiParam(value = "交易流水号", required = true) @RequestParam(required = true)String payseriesno
+    ){
+
+        //回退实收
+        //作废第三方支付
+        //生成负数实收
+        //回退预存账户
+        payPayReceivedService.cancelReceivedByPayseriesno(payseriesno);
+        return new AjaxMessage<>(ResultStatus.OK,1);
+    }
 }

+ 21 - 1
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayFeeMapper.java

@@ -1,6 +1,8 @@
 package com.bz.smart_city.dao.pay;
 
 import com.bz.smart_city.dto.pay.PayCustomRechargeDto;
+import com.bz.smart_city.dto.pay.PayInvoiceDto;
+import com.bz.smart_city.dto.pay.payfee.*;
 import com.bz.smart_city.entity.pay.BaseClosingAccountInfo;
 import com.bz.smart_city.entity.pay.PayReceivable;
 import org.apache.ibatis.annotations.Mapper;
@@ -19,7 +21,7 @@ import java.util.List;
  */
 @Mapper
 public interface PayFeeMapper {
-    PayCustomRechargeDto getCustomInfoByMeterOrAccount(@Param("accountnumber") String accountnumber, @Param("metercode") String metercode,@Param("siteId") BigInteger siteId,@Param("customerId")BigInteger customerId );
+    PayCustomRechargeDto getCustomInfoByMeterOrAccount(@Param("accountId") String accountId, @Param("accountnumber") String accountnumber, @Param("metercode") String metercode,@Param("siteId") BigInteger siteId,@Param("customerId")BigInteger customerId );
 
     void updatePayReceivable(PayReceivable payReceivable);
 
@@ -28,6 +30,24 @@ public interface PayFeeMapper {
     List<PayReceivable> getReceivable(@Param("siteId") Integer siteId, @Param("customerId") Integer customerId, @Param("accountId") BigInteger accountId,@Param("list") List<BigInteger> list);
 
     BaseClosingAccountInfo getLastClosingAccount(@Param("siteId") Integer siteId, @Param("customerId") Integer customerId );
+
     void updateAccountState(@Param("accountId") BigInteger accountId);
 
+    List<PayfeeAccountInfoDto> findPayfeeAccountInfo(@Param("id")BigInteger id,@Param("queryType")Integer queryType ,@Param("condition")String condition,@Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+
+    PayfeeDetaileBill getPayfeeDetaileBill(@Param("accountId") BigInteger accountId);
+
+    PayfeeDetailed getPayfeeDetailed(@Param("accountId")BigInteger accountId ,@Param("year")Integer year ,@Param("month")Integer month);
+
+    List<PayfeeReceivableInfo> getPayreceivableDebt(@Param("accountId")BigInteger accountId , @Param("year")Integer year);
+
+    List<PayfeeReceivableInfo> getPayreceivableDebtDetailed(@Param("accountId")BigInteger accountId , @Param("year")Integer year , @Param("month")Integer month);
+
+    List<PayfeeReceivedInfo> getPayreceived(@Param("accountId")BigInteger accountId , @Param("year")Integer year, @Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+
+    List<PayfeeReceivedInfo> getPayreceivedDetailed(@Param("accountId")BigInteger accountId ,@Param("payseriesno")String payseriesno, @Param("year")Integer year , @Param("month")Integer month, @Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+
+    List<PayfeeWaterusedamount> getWaterusedamount(@Param("accountId")BigInteger accountId , @Param("year")Integer year , @Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+
+    List<PayInvoiceDto> getPayinvoiceInfo(@Param("accountId")BigInteger accountId , @Param("year")Integer year);
 }

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

@@ -0,0 +1,26 @@
+package com.bz.smart_city.dao.pay;
+
+import com.bz.smart_city.dto.pay.PayInvoiceDto;
+import com.bz.smart_city.dto.pay.PayTransactiondetailsDto;
+import com.bz.smart_city.entity.pay.PayInvoice;
+import com.bz.smart_city.entity.pay.PayPayReceived;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigInteger;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-30 8:39
+ */
+@Mapper
+public interface PayInvoiceMapper {
+    void insert(PayInvoice payInvoice);
+    List<PayInvoiceDto> findList(PayInvoiceDto payInvoiceDto);
+
+    List<PayTransactiondetailsDto> findTransByPayseriesno(@Param("payseriesno") String payseriesno, @Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+    List<PayPayReceived> findReceivedByPayseriesno(@Param("payseriesno") String payseriesno , @Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+    void updatePrintInvoiceRecord(@Param("type") Integer type, @Param("payseriesno") String payseriesno, @Param("invoiceId") BigInteger invoiceId,@Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
+}

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

@@ -0,0 +1,61 @@
+package com.bz.smart_city.dto.pay;
+
+import com.bz.smart_city.entity.ProgramItem;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-30 8:18
+ */
+@Data
+public class PayInvoiceDto {
+
+    @ApiModelProperty(value = "收据id")
+    private BigInteger id;
+    @ApiModelProperty(value = "收据号码")
+    private String invoiceno;
+    @ApiModelProperty(value = "客户编号")
+    private String accountnumber;
+    @ApiModelProperty(value = "客户名称")
+    private String accountname;
+    @ApiModelProperty(value = "开票金额")
+    private String invoiceamount;
+    @ApiModelProperty(value = "票据状态,2已使用,3作废")
+    private Integer state;
+    @ApiModelProperty(value = "票据状态")
+    private String stateLabel;
+    @ApiModelProperty(value = "开票日期")
+    private LocalDateTime createDate;
+    @ApiModelProperty(value = "开票人")
+    private String createByName;
+    @ApiModelProperty(value = "作废时间")
+    private LocalDateTime canceltime;
+    @ApiModelProperty(value = "作废人")
+    private BigInteger cancelpersonName;
+
+
+    @ApiModelProperty(value = "数据查询(票据号、户编、户名)",  hidden = true)
+    private String condition;
+    @ApiModelProperty(value = "站点id",  hidden = true)
+    private Integer siteId;
+    @ApiModelProperty(value = "客户id",  hidden = true)
+    private Integer customerId;
+    @ApiModelProperty(value = "开票时间",  hidden = true)
+    private LocalDateTime startTime;
+    @ApiModelProperty(value = "开票时间",  hidden = true)
+    private LocalDateTime endTime;
+
+    //权限项
+    @ApiModelProperty(value = "权限项",  hidden = true)
+    @JsonIgnore
+    private List<ProgramItem> programItems;
+
+}

+ 53 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeAccountInfoDto.java

@@ -0,0 +1,53 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+
+/**
+ * @Author wangli
+ * @Description 缴费界面客户信息展示
+ * @Version 1.0
+ */
+
+@Data
+@ApiModel("缴费界面————客户信息")
+public class PayfeeAccountInfoDto {
+
+
+    @ApiModelProperty(value = "客户信息id")
+    private BigInteger accountId;
+    @ApiModelProperty(value = "开户信息id" )
+    private BigInteger custId;
+    @ApiModelProperty(value = "客户编码" )
+    private String accountnumber;
+    @ApiModelProperty(value = "客户名称" )
+    private String accountname;
+    @ApiModelProperty(value = "手机号" )
+    private String mobilephone;
+    @ApiModelProperty(value = "地址" )
+    private String address;
+    @ApiModelProperty(value = "证件号" )
+    private String idcardno;
+    @ApiModelProperty(value = "公司税号" )
+    private String vatno;
+    @ApiModelProperty(value = "电子邮箱" )
+    private String email;
+    @ApiModelProperty(value = "开户时间" )
+    private LocalDateTime opendate;
+    @ApiModelProperty(value = "水表编码" )
+    private String metercode;
+    @ApiModelProperty(value = "住房类型" )
+    private String housetype;
+    @ApiModelProperty(value = "结算方式" )
+    private String calculateway;
+    @ApiModelProperty(value = "用水性质id" )
+    private BigInteger waterPropertyId;
+    @ApiModelProperty(value = "用水性质名称" )
+    private String waterPropertyName;
+
+
+}

+ 23 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeDetaileBill.java

@@ -0,0 +1,23 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @description 缴费界面账单详情
+ * @auto wangli
+ * @date 2020-07-28
+ */
+
+@Data
+@ApiModel("缴费界面——账单详情")
+public class PayfeeDetaileBill {
+
+    @ApiModelProperty(value = "欠费金额")
+    private Double debt;
+    @ApiModelProperty(value = "用水金额")
+    private Double waterFee;
+    @ApiModelProperty(value = "应缴金额")
+    private Double receivableFee;
+}

+ 36 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeDetailed.java

@@ -0,0 +1,36 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.val;
+
+/**
+ * @description 缴费界面本期应缴明细
+ * @auto wangli
+ * @date 2020-07-28
+ */
+
+@Data
+@ApiModel("缴费界面————本期应缴明细")
+public class PayfeeDetailed {
+
+
+    @ApiModelProperty(value = "客户id")
+    private Double accountId;
+
+    @ApiModelProperty(value = "水费")
+    private Double waterFee1;
+    @ApiModelProperty(value = "二次加压费")
+    private Double waterFee2;
+    @ApiModelProperty(value = "不征税自来水")
+    private Double waterFee3;
+    @ApiModelProperty(value = "污水处理费")
+    private Double waterFee4;
+    @ApiModelProperty(value = "开采费")
+    private Double waterFee5;
+    @ApiModelProperty(value = "违约金")
+    private Double waterFee6;
+
+
+}

+ 37 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeInvoice.java

@@ -0,0 +1,37 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.util.Date;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-30 8:18
+ */
+@Data
+public class PayfeeInvoice {
+
+    @ApiModelProperty(value = "客户id")
+    private BigInteger accountId;
+    @ApiModelProperty(value = "客户名称")
+    private String accountname;
+    @ApiModelProperty(value = "客户编号")
+    private String accountnumber;
+    @ApiModelProperty(value = "收据金额")
+    private String invoiceamount;
+    @ApiModelProperty(value = "收据号码")
+    private String invoiceno;
+    @ApiModelProperty(value = "票据状态")
+    private Integer state;
+    @ApiModelProperty(value = "票据类型")
+    private Integer type;
+    @ApiModelProperty(value = "片区id")
+    private BigInteger officeId;
+    @ApiModelProperty(value = "作废人")
+    private BigInteger cancelperson;
+    @ApiModelProperty(value = "作废时间")
+    private Date canceltime;
+}

+ 41 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeReceivableInfo.java

@@ -0,0 +1,41 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+/**
+ * @description 收费页面欠费信息
+ * @auto wangli
+ * @data 2020-07-29 11:18
+ */
+@Data
+@ApiModel(value = "缴费界面————欠费信息")
+public class PayfeeReceivableInfo {
+
+    @ApiModelProperty(value = "客户id")
+    private BigInteger accountId ;
+    @ApiModelProperty(value = "账期年")
+    private Integer year ;
+    @ApiModelProperty(value = "账期月")
+    private Integer month;
+    @ApiModelProperty(value = "收费项目")
+    private String name;
+    @ApiModelProperty(value = "欠费金额")
+    private BigDecimal debt;
+    @ApiModelProperty(value = "阶梯")
+    private String ladderlevelname;
+    @ApiModelProperty(value = "水价")
+    private BigDecimal price;
+    @ApiModelProperty(value = "结算水量")
+    private BigDecimal payamount;
+    @ApiModelProperty(value = "应收金额")
+    private BigDecimal receivablefee;
+    @ApiModelProperty(value = "创建时间")
+    private Date createDate;
+}

+ 38 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeReceivedInfo.java

@@ -0,0 +1,38 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @description 收费界面实收信息
+ * @auto wangli
+ * @data 2020-07-29 12:12
+ */
+@Data
+@ApiModel(value = "缴费界面——实收信息")
+public class PayfeeReceivedInfo {
+    @ApiModelProperty(value = "收费项目")
+    private String name;
+    @ApiModelProperty(value = "水价阶梯")
+    private String ladderlevelname;
+    @ApiModelProperty(value = "交易流水号")
+    private String payseriesno;
+    @ApiModelProperty(value = "交易金额")
+    private String receivedamount;
+    @ApiModelProperty(value = "支付方式")
+    private String paywayname;
+    @ApiModelProperty(value = "交易状态")
+    private String statename;
+    @ApiModelProperty(value = "创建日期")
+    private String createDate;
+    @ApiModelProperty(value = "是否作废")
+    private String iscanceled;
+    @ApiModelProperty(value = "作废人id")
+    private String canceledrecordId;
+    @ApiModelProperty(value = "作废人")
+    private String cancelperson;
+    @ApiModelProperty(value = "收据id")
+    private String invoiceId;
+
+}

+ 43 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayfeeWaterusedamount.java

@@ -0,0 +1,43 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-29 16:39
+ */
+@Data
+@ApiModel("缴费界面——水量信息")
+public class PayfeeWaterusedamount {
+
+    @ApiModelProperty(value = "水表编码")
+    private String metercode;
+    @ApiModelProperty(value = "上次止度")
+    private BigDecimal lastreading;
+    @ApiModelProperty(value = "上次抄表时间")
+    private Date lastrecorddate;
+    @ApiModelProperty(value = "本次止度")
+    private BigDecimal reading;
+    @ApiModelProperty(value = "本次抄表时间")
+    private Date recorddate;
+    @ApiModelProperty(value = "实际水量")
+    private BigDecimal amount;
+    @ApiModelProperty(value = "结算水量")
+    private BigDecimal payamount;
+    @ApiModelProperty(value = "账期")
+    private String closingName;
+    @ApiModelProperty(value = "状态")
+    private String stateLabel;
+//    @ApiModelProperty(value = "账期年")
+//    private Integer year;
+//    @ApiModelProperty(value = "账期月")
+//    private Integer month;
+    @ApiModelProperty(value = "是否生成应收")
+    private String isReceivable;
+}

+ 58 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PrintInvoiceData.java

@@ -0,0 +1,58 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import com.bz.smart_city.entity.pay.PayPayReceived;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-30 16:18
+ */
+public class PrintInvoiceData {
+
+    @ApiModelProperty(value = "充值日期")
+    private LocalDateTime createDate;	//充值日期
+    @ApiModelProperty(value = "本期余额")
+    private Double remaining;	//本期余额
+    @ApiModelProperty(value = "交易金额\t·实收金额")
+    private Double transamount;	//交易金额	·实收金额
+    @ApiModelProperty(value = "上期金额")
+    private Double lastRemaining;	//上期金额
+    @ApiModelProperty(value = "客户ID")
+    private String accountId;	//客户ID
+    @ApiModelProperty(value = "客户名称")
+    private String accountname;	//客户名称
+    @ApiModelProperty(value = "客户编码")
+    private String accountnumber;	//客户编码
+    @ApiModelProperty(value = "客户地址")
+    private String address;	//客户地址
+    @ApiModelProperty(value = "抄表止度")
+    private Double reading;	//抄表止度
+    @ApiModelProperty(value = "收费日期")
+    private String paydate;	//收费日期
+    @ApiModelProperty(value = "抄表日期")
+    private LocalDateTime recorddate;	//抄表日期
+    @ApiModelProperty(value = "应收金额")
+    private Double receivablefee;	//应收金额
+    @ApiModelProperty(value = "上期止度")
+    private Double lastreading;	//上期止度
+    @ApiModelProperty(value = "收费账期区间")
+    private String dateRange;	//收费账期区间
+    @ApiModelProperty(value = "收费员")
+    private String createUser;	//收费员
+    @ApiModelProperty(value = "水量")
+    private Integer amount;	//水量
+    @ApiModelProperty(value = "单价")
+    private Double price;	//单价
+    @ApiModelProperty(value = "单价1")
+    private Double price1;	//单价1
+    @ApiModelProperty(value = "单价3")
+    private Double price3;	//单价3
+    @ApiModelProperty(value = "单价4")
+    private Double price4;	//单价4
+    @ApiModelProperty(value = "实收信息")
+    private List<PayPayReceived> payReceiveds;
+}

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

@@ -0,0 +1,46 @@
+package com.bz.smart_city.entity.pay;
+
+import com.bz.smart_city.dto.pay.BaseDto;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-30 8:18
+ */
+@Data
+public class PayInvoice extends PayBaseInfo{
+
+    @ApiModelProperty(value = "客户id")
+    private BigInteger accountId;
+    @ApiModelProperty(value = "客户名称")
+    private String accountname;
+    @ApiModelProperty(value = "客户编号")
+    private String accountnumber;
+    @ApiModelProperty(value = "收据金额")
+    private BigDecimal invoiceamount;
+    @ApiModelProperty(value = "收据号码")
+    private String invoiceno;
+    @ApiModelProperty(value = "票据状态")
+    private Integer state;
+    @ApiModelProperty(value = "票据类型")
+    private Integer type;
+    @ApiModelProperty(value = "片区id")
+    private BigInteger officeId;
+    @ApiModelProperty(value = "作废人")
+    private BigInteger cancelperson;
+    @ApiModelProperty(value = "作废时间")
+    private LocalDateTime canceltime;
+    @ApiModelProperty(value = "账期年")
+    private Integer year;
+    @ApiModelProperty(value = "账期月")
+    private Integer month;
+    @ApiModelProperty(value = "id")
+    private BigInteger id;
+}

+ 12 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java

@@ -468,6 +468,18 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
             PayRechargeaccountDto rechargeaccount = payRechargeaccountMapper.findById(null, amountWaterUsedAmount.getAccountId());
             //应收信息 优先级 水费
             List<PayReceivable> payPayReceivables = payPayReceivableMapper.getReceivableByAmountId(amountWaterUsedAmount.getId());
+
+            BigDecimal debts=BigDecimal.ZERO;
+            for(PayReceivable payReceivable: payPayReceivables){
+                debts=debts.add(payReceivable.getDebt());
+            }
+            //预存<欠费 金额不足不划扣
+            if(rechargeaccount.getRemaining().compareTo(debts) == -1){
+                result =2;
+                return result;
+            }
+
+
             if(rechargeaccount!=null&& payPayReceivables!=null && payPayReceivables.size()>0) {
                 BigDecimal remaining = rechargeaccount.getRemaining();
                 if (remaining.compareTo(BigDecimal.ZERO) == 1) {

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

@@ -5,14 +5,10 @@ import com.bz.smart_city.commom.exception.ServiceException;
 import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.commom.util.Util;
-import com.bz.smart_city.dao.pay.PayFeeMapper;
-import com.bz.smart_city.dao.pay.PayPayReceivedMapper;
-import com.bz.smart_city.dao.pay.PaySysDictMapper;
-import com.bz.smart_city.dao.pay.PayTransactiondetailsMapper;
+import com.bz.smart_city.dao.pay.*;
 import com.bz.smart_city.dto.LoginUser;
-import com.bz.smart_city.dto.pay.PayCustomRechargeDto;
-import com.bz.smart_city.dto.pay.PaySysDictSelectDto;
-import com.bz.smart_city.dto.pay.PayTransactiondetails;
+import com.bz.smart_city.dto.pay.*;
+import com.bz.smart_city.dto.pay.payfee.*;
 import com.bz.smart_city.entity.pay.BaseClosingAccountInfo;
 import com.bz.smart_city.entity.pay.PayPayReceived;
 import com.bz.smart_city.entity.pay.PayReceivable;
@@ -52,6 +48,197 @@ public class PayFeeServiceImp implements PayFeeService {
     @Resource
     PaySysDictMapper sysDictMapper;
 
+    @Resource
+    BaseClosingAccountInfoMapper baseClosingAccountInfoMapper;
+
+    public String payFeeCounter( String id,Integer payway,BigDecimal transAmount, Integer balancetype){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+
+        Integer siteId = loginUser.getSiteId();
+
+        Integer customerId = loginUser.getCustomerId();
+
+        Integer userId = loginUser.getId();
+
+        if(siteId ==null || customerId == null || userId == null){
+            throw new ServiceException(ResultStatus.ACCOUNT_OPERATOR_EERROR);
+        }
+        //根据客编或者水编获取客户信息
+        PayCustomRechargeDto payCustomRechargeDto = payFeeMapper.getCustomInfoByMeterOrAccount(id,null,null,BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+
+        List<PayReceivable> payReceivableList =payFeeMapper.getReceivable(loginUser.getSiteId(),loginUser.getCustomerId(),payCustomRechargeDto.getAccountId(),null);
+
+        if(payReceivableList.size() == 0){ //没有应收信息走仅充值
+            return rechargefeeCounter(id, transAmount, payway);
+        }else{
+            BigDecimal debts=BigDecimal.ZERO;
+            for(PayReceivable payReceivable: payReceivableList){
+                debts=debts.add(payReceivable.getDebt());
+            }
+            //预存+实收<欠费 金额不足
+            if(payCustomRechargeDto.getRemaining().add(transAmount).compareTo(debts) == -1){
+                throw new ServiceException(ResultStatus.PAYFEE_NOT_ENOUGH);
+            }
+        }
+
+        //支付方式
+        List<PaySysDictSelectDto> payways = sysDictMapper.getDicts("支付方式",BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+        if(payways.size() == 0){
+            throw new ServiceException(ResultStatus.PAYFEE_QUERY_NO_PAYWAY);
+        }
+        String paywayName = payways.stream().filter(item -> item.getValue().equals(payway.toString())).findFirst().get().getLabel();
+
+//         Map<String,PaySysDictSelectDto> paywayMap = payways.stream().collect(Collectors.toMap(PaySysDictSelectDto::getValue, PaySysDictSelectDto->PaySysDictSelectDto));
+        //收费类型
+        List<PaySysDictSelectDto> feetypes = sysDictMapper.getDicts("收费类型",BigInteger.valueOf(loginUser.getSiteId()),BigInteger.valueOf(loginUser.getCustomerId()));
+        if(payways.size() == 0) {
+            throw new ServiceException(ResultStatus.PAYFEE_QUERY_NO_TRANSTYPE);
+        }
+        Map<String, PaySysDictSelectDto> feetypeMap = feetypes.stream().collect(Collectors.toMap(PaySysDictSelectDto::getValue, PaySysDictSelectDto -> PaySysDictSelectDto));
+        //如果传入时间则用传入的时间做交易时间
+        LocalDateTime localDateTime=LocalDateTime.now();
+
+        //交易金额不可为负数
+        if(transAmount.compareTo(BigDecimal.ZERO)==-1){
+            throw new ServiceException(ResultStatus.PAYFEE_TRANSAMOUNT_BELOW_ZERO);
+        }
+
+        //生成批次号
+        // 微信:W  现金、预存账户:C 银行:B 支付宝:A
+        String payseriesno= Util.getBatchNo(paywayName.equals("微信支付")?"W":paywayName.equals("支付宝")?"A":paywayName.equals("银行")?"B":"C"
+                ,payCustomRechargeDto.getAccountnumber());
+        //获取账期
+        BaseClosingAccountInfo baseClosingAccountInfo=payFeeMapper.getLastClosingAccount(siteId,customerId);
+        if(baseClosingAccountInfo == null){
+            //获取账期信息失败
+            throw new ServiceException(ResultStatus.PAYFEE_QUERY_NO_CLOSINGACCOUNT);
+        }
+        int month =baseClosingAccountInfo.getMonth();
+        int year =baseClosingAccountInfo.getYear();
+        //余额
+        BigDecimal remaining = payCustomRechargeDto.getRemaining();
+        //用作明细记录交易前余额
+        BigDecimal oldRemaining = payCustomRechargeDto.getRemaining();
+        //交易明细最后统一赋值交易前后余额,批量保存
+        List<PayTransactiondetails> transactiondetailsDtoList = new ArrayList();
+        //预存抵扣
+        Iterator<PayReceivable> iterator = payReceivableList.iterator();
+        while(iterator.hasNext()) {
+            //抵扣的应收
+            PayReceivable payReceivable=iterator.next();
+            //账户余额先抵扣
+            if (remaining.compareTo(BigDecimal.ZERO) == 1) {
+                if(payReceivable.getDebt().compareTo(BigDecimal.ZERO) != 1){
+                    //欠费不大于零直接移除
+                    iterator.remove();
+                }else if(remaining.compareTo(payReceivable.getDebt()) != -1){
+                    //预存余额不小于欠费(完全抵扣)
+                    iterator.remove();
+                    remaining = remaining.subtract(payReceivable.getDebt());//修改余额
+                    //生成并保存实收
+                    PayPayReceived payPayReceived = getReceived(payReceivable, year, month, localDateTime,payway,payseriesno,payReceivable.getDebt(),feetypeMap, siteId, customerId, userId );
+                    //生成交易明细
+                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5,paywayName, localDateTime, payCustomRechargeDto, payseriesno, month, year, payReceivable.getDebt().negate(), siteId, customerId, userId );
+                    payTransactiondetails.setReceivedId(payPayReceived.getId());
+                    payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "扣费");
+                    payTransactiondetails.setTranstype(2);
+                    payTransactiondetails.setTranstypeLabel("扣费");
+                    transactiondetailsDtoList.add(payTransactiondetails);
+                    //修改应收
+                    payReceivable.setDebt(BigDecimal.ZERO);
+                    payReceivable.setUpdateDate(localDateTime);
+                    payReceivable.setUpdateBy(BigInteger.valueOf(userId));
+                    payFeeMapper.updatePayReceivable(payReceivable);
+                }else{
+                    //预存余额小于于欠费(部分抵扣)
+                    //生成并保存实收
+                    PayPayReceived payPayReceived = getReceived(payReceivable, year, month, localDateTime,payway,payseriesno,remaining,feetypeMap, siteId, customerId, userId );
+
+                    PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5, paywayName,localDateTime, payCustomRechargeDto, payseriesno, month, year, remaining.negate() , siteId, customerId, userId );
+                    payTransactiondetails.setReceivedId(payPayReceived.getId());
+                    payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "扣费");
+                    payTransactiondetails.setTranstype(2);
+                    payTransactiondetails.setTranstypeLabel("扣费");
+                    transactiondetailsDtoList.add(payTransactiondetails);
+                    //修改应收
+                    payReceivable.setDebt(payReceivable.getDebt().subtract(remaining));
+                    payReceivable.setUpdateDate(localDateTime);
+                    payReceivable.setUpdateBy(BigInteger.valueOf(userId));
+                    payFeeMapper.updatePayReceivable(payReceivable);
+
+                    remaining = BigDecimal.ZERO;//修改余额
+                    break;
+                }
+            }
+        }
+
+        //缴费抵扣
+        Iterator<PayReceivable> iteratorTransAmount = payReceivableList.iterator();
+        while(iteratorTransAmount.hasNext()) {
+            //抵扣的应收
+            PayReceivable payReceivable=iteratorTransAmount.next();
+            //交易金额抵扣
+            if (transAmount.compareTo(BigDecimal.ZERO) == 1) {
+                if(payReceivable.getDebt().compareTo(BigDecimal.ZERO) != 1){
+                    //欠费不大于零直接移除
+                    iteratorTransAmount.remove();
+                }else if(transAmount.compareTo(payReceivable.getDebt()) != -1){
+                    //交易金额不小于欠费(完全抵扣)
+                    iteratorTransAmount.remove();
+                    transAmount = transAmount.subtract(payReceivable.getDebt());//修改剩余交易金额
+
+                    //生成并保存实收
+                    getReceived(payReceivable, year, month, localDateTime,payway,payseriesno,payReceivable.getDebt(),feetypeMap, siteId, customerId, userId );
+                    //修改应收
+                    payReceivable.setDebt(BigDecimal.ZERO);
+                    payReceivable.setUpdateDate(localDateTime);
+                    payReceivable.setUpdateBy(BigInteger.valueOf(userId));
+                    payFeeMapper.updatePayReceivable(payReceivable);
+
+                }else{
+                    //交易金额小于于欠费(部分抵扣)
+                    //生成并保存实收
+                    getReceived(payReceivable, year, month, localDateTime,payway,payseriesno,transAmount,feetypeMap, siteId, customerId, userId );
+                    //修改应收
+                    payReceivable.setDebt(payReceivable.getDebt().subtract(transAmount));
+                    payReceivable.setUpdateDate(localDateTime);
+                    payReceivable.setUpdateBy(BigInteger.valueOf(userId));
+                    payFeeMapper.updatePayReceivable(payReceivable);
+                    transAmount = BigDecimal.ZERO;//修改余额
+                    break;
+                }
+            }
+        }
+        //余额充值或划扣有余额
+        if(balancetype == 1 && transAmount.compareTo(BigDecimal.ZERO) == 1){
+            //修改余额
+            remaining=remaining.add(transAmount);
+            //生成交易明细
+            PayTransactiondetails payTransactiondetails = getPayTransactiondetails(payway, paywayName,localDateTime, payCustomRechargeDto, payseriesno, month, year, transAmount, siteId, customerId, userId  );
+            payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "充值");
+            payTransactiondetails.setTranstype(4);
+            payTransactiondetails.setTranstypeLabel("账户转预存");
+            transactiondetailsDtoList.add(payTransactiondetails);
+        }
+
+        //修改预存账户
+        payFeeMapper.updateRechargeaccount(remaining,BigInteger.valueOf(userId),localDateTime,payCustomRechargeDto.getRechargeId());
+        //更新客户状态
+        payFeeMapper.updateAccountState(payCustomRechargeDto.getAccountId());
+        //赋值交易明细交易前后余额并保存
+        for(PayTransactiondetails payTransactiondetails : transactiondetailsDtoList){
+            payTransactiondetails.setRemaining(oldRemaining);//交易前账户余额
+            payTransactiondetails.setLastrecreamaing(remaining);//交易后账户余额
+        }
+        //批量保存交易明细
+        if(transactiondetailsDtoList.size()>0)
+            payTransactiondetailsMapper.batchInsert(transactiondetailsDtoList);
+        //返回批次号
+        return  payseriesno;
+
+
+    }
+
    /*
     * @Description: 缴纳欠费
     * @auther: wangli
@@ -88,7 +275,7 @@ public class PayFeeServiceImp implements PayFeeService {
        //根据客编或者水编获取客户信息
        PayCustomRechargeDto payCustomRechargeDto = null;
        if(StringUtils.isEmpty(accountnumber) || StringUtils.isEmpty(metercode)){
-           payCustomRechargeDto= payFeeMapper.getCustomInfoByMeterOrAccount(accountnumber,metercode,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
+           payCustomRechargeDto= payFeeMapper.getCustomInfoByMeterOrAccount(null,accountnumber,metercode,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
        }
 
        List<PayReceivable> payReceivableList =null;
@@ -99,7 +286,7 @@ public class PayFeeServiceImp implements PayFeeService {
            payReceivableList=payFeeMapper.getReceivable(siteId,customerId,null,receivableIds);
            //未传客编或者水编,通过应收信息查询客户信息
            if(payReceivableList != null && payReceivableList.size()>0){
-               payCustomRechargeDto = payFeeMapper.getCustomInfoByMeterOrAccount(payReceivableList.get(0).getAccountnumber(),null,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
+               payCustomRechargeDto = payFeeMapper.getCustomInfoByMeterOrAccount(null,payReceivableList.get(0).getAccountnumber(),null,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
            }else{
                //获取客户信息失败
                throw new ServiceException(ResultStatus.PAYFEE_QUERY_NO_CUSTOMER);
@@ -110,6 +297,15 @@ public class PayFeeServiceImp implements PayFeeService {
        }
        if(payReceivableList.size() == 0){ //没有应收信息走仅充值
            return rechargefee( accountnumber,  metercode,  transAmount,  payway ,  transTime,siteId,customerId,userId);
+       }else{
+           BigDecimal debts=BigDecimal.ZERO;
+           for(PayReceivable payReceivable: payReceivableList){
+               debts=debts.add(payReceivable.getDebt());
+           }
+           //预存+实收<欠费 金额不足
+           if(payCustomRechargeDto.getRemaining().add(transAmount).compareTo(debts) == -1){
+               throw new ServiceException(ResultStatus.PAYFEE_NOT_ENOUGH);
+           }
        }
 
         //支付方式
@@ -285,6 +481,63 @@ public class PayFeeServiceImp implements PayFeeService {
 
     }
 
+    /*
+     * @Description: 仅充值
+     * @auther: wangli
+     * @date: 2020-04-28 10:32
+     * @param: accountnumber 客户编码
+     * @param: metercode 水表编码
+     * @param: transAmount 交易金额
+     * @param: payway 支付方式
+     * @param: transTime 交易时间 :为空时取当前时间
+     * @return: payseriesno 交易流水号
+     *
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public String rechargefeeCounter(String  accountId , BigDecimal transAmount, Integer payway ){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+
+        Integer siteId = loginUser.getSiteId();
+
+        Integer customerId = loginUser.getCustomerId();
+
+        Integer userId = loginUser.getId();
+
+        if(siteId ==null || customerId == null || userId == null){
+            throw new ServiceException(ResultStatus.ACCOUNT_OPERATOR_EERROR);
+        }
+        //支付方式
+        List<PaySysDictSelectDto> payways = sysDictMapper.getDicts("支付方式",BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
+        if(payways.size() == 0){
+            throw new ServiceException(ResultStatus.PAYFEE_QUERY_NO_PAYWAY);
+        }
+        String paywayName = payways.stream().filter(item -> item.getValue().equals(payway.toString())).findFirst().get().getLabel();
+
+        //如果传入时间则用传入的时间做交易时间
+        LocalDateTime localDateTime=LocalDateTime.now();
+
+        //交易金额不可为负数
+        if(transAmount.compareTo(BigDecimal.ZERO)==-1){
+            throw new ServiceException(ResultStatus.PAYFEE_TRANSAMOUNT_BELOW_ZERO);
+        }
+
+        //根据客编或者水编获取客户信息
+        PayCustomRechargeDto payCustomRechargeDto = null;
+        if(StringUtils.isEmpty(accountId)){
+            payCustomRechargeDto= payFeeMapper.getCustomInfoByMeterOrAccount(accountId,null,null,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
+        }
+
+        if(payCustomRechargeDto == null ){
+            //获取客户信息失败
+            throw new ServiceException(ResultStatus.PAYFEE_QUERY_NO_CUSTOMER);
+        }
+        //生成批次号
+        // 微信:W  现金、预存账户:C 银行:B 支付宝:A
+        String payseriesno = recharge(transAmount, payway, siteId, customerId, userId, paywayName, localDateTime, payCustomRechargeDto);
+        return payseriesno;
+    }
+
+
     /*
      * @Description: 仅充值
      * @auther: wangli
@@ -334,40 +587,45 @@ public class PayFeeServiceImp implements PayFeeService {
         //根据客编或者水编获取客户信息
         PayCustomRechargeDto payCustomRechargeDto = null;
         if(StringUtils.isEmpty(accountnumber) || StringUtils.isEmpty(metercode)){
-            payCustomRechargeDto= payFeeMapper.getCustomInfoByMeterOrAccount(accountnumber,metercode,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
+            payCustomRechargeDto= payFeeMapper.getCustomInfoByMeterOrAccount(null,accountnumber,metercode,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
         }
 
         if(payCustomRechargeDto == null ){
             //获取客户信息失败
             throw new ServiceException(ResultStatus.PAYFEE_QUERY_NO_CUSTOMER);
         }
+        String payseriesno = recharge(transAmount, payway, siteId, customerId, userId, paywayName, localDateTime, payCustomRechargeDto);
+        return payseriesno;
+    }
+
+    private String recharge(BigDecimal transAmount, Integer payway, Integer siteId, Integer customerId, Integer userId, String paywayName, LocalDateTime localDateTime, PayCustomRechargeDto payCustomRechargeDto) {
         //生成批次号
         // 微信:W  现金、预存账户:C 银行:B 支付宝:A
-        String payseriesno= Util.getBatchNo(paywayName.equals("微信支付")?"W":paywayName.equals("支付宝")?"A":paywayName.equals("银行")?"B":"C"
-                ,payCustomRechargeDto.getAccountnumber());
+        String payseriesno = Util.getBatchNo(paywayName.equals("微信支付") ? "W" : paywayName.equals("支付宝") ? "A" : paywayName.equals("银行") ? "B" : "C"
+                , payCustomRechargeDto.getAccountnumber());
         //获取账期
-        BaseClosingAccountInfo baseClosingAccountInfo=payFeeMapper.getLastClosingAccount(siteId,customerId);
-        if(baseClosingAccountInfo == null){
+        BaseClosingAccountInfo baseClosingAccountInfo = payFeeMapper.getLastClosingAccount(siteId, customerId);
+        if (baseClosingAccountInfo == null) {
             //获取账期信息失败
             throw new ServiceException(ResultStatus.PAYFEE_QUERY_NO_CLOSINGACCOUNT);
         }
-        int month =baseClosingAccountInfo.getMonth();
-        int year =baseClosingAccountInfo.getYear();
+        int month = baseClosingAccountInfo.getMonth();
+        int year = baseClosingAccountInfo.getYear();
         //余额
         BigDecimal remaining = payCustomRechargeDto.getRemaining();
 
         //生成交易明细
-        PayTransactiondetails payTransactiondetails = getPayTransactiondetails(payway, paywayName,localDateTime, payCustomRechargeDto, payseriesno, month, year, transAmount, siteId, customerId, userId );
+        PayTransactiondetails payTransactiondetails = getPayTransactiondetails(payway, paywayName, localDateTime, payCustomRechargeDto, payseriesno, month, year, transAmount, siteId, customerId, userId);
         payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "充值");
         payTransactiondetails.setTranstype(1);
         payTransactiondetails.setTranstypeLabel("充值");
         payTransactiondetails.setRemaining(remaining);//交易前账户余额
-        remaining=remaining.add(transAmount);
+        remaining = remaining.add(transAmount);
         payTransactiondetails.setLastrecreamaing(remaining);//交易后账户余额
         payTransactiondetailsMapper.insert(payTransactiondetails);
 
         //修改预存账户
-        payFeeMapper.updateRechargeaccount(remaining,BigInteger.valueOf(userId),localDateTime,payCustomRechargeDto.getRechargeId());
+        payFeeMapper.updateRechargeaccount(remaining, BigInteger.valueOf(userId), localDateTime, payCustomRechargeDto.getRechargeId());
         //更新客户状态
         payFeeMapper.updateAccountState(payCustomRechargeDto.getAccountId());
         return payseriesno;
@@ -471,4 +729,92 @@ public class PayFeeServiceImp implements PayFeeService {
         payPayReceivedMapper.insert(payReceived);
         return payReceived;
     }
+
+    public List<PayfeeAccountInfoDto> findPayfeeAccountInfo(BigInteger id, Integer queryType , String condition ){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        return payFeeMapper.findPayfeeAccountInfo(id, queryType , condition ,loginUser.getSiteId(),loginUser.getCustomerId());
+    }
+
+    public PayfeeDetaileBill getPayfeeDetaileBill(BigInteger id){
+        if(id == null){
+            return new PayfeeDetaileBill();
+        }
+        return payFeeMapper.getPayfeeDetaileBill(id);
+    }
+
+    public PayfeeDetailed getPayfeeDetailed(BigInteger id  ){
+        if(id == null){
+            return new PayfeeDetailed();
+        }
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        //获取最新账期
+        BaseClosingAccountInfoDto baseClosingAccountInfoDto=baseClosingAccountInfoMapper.getLastClosingAccount(loginUser.getSiteId(),loginUser.getCustomerId());
+       return  payFeeMapper.getPayfeeDetailed(id,baseClosingAccountInfoDto.getYear(),baseClosingAccountInfoDto.getMonth());
+    }
+
+    /**
+     * 查询客户欠费信息
+     * @param accountId
+     * @param year
+     * @return
+     */
+    public List<PayfeeReceivableInfo> getPayreceiveDebt(BigInteger accountId , Integer year){
+        return payFeeMapper.getPayreceivableDebt(accountId,year);
+    }
+
+    /**
+     * 查询账期内欠费详情
+     * @param accountId 客户id
+     * @param year
+     * @param month
+     * @return
+     */
+    public List<PayfeeReceivableInfo> getPayreceiveDebtDetailed(BigInteger accountId , Integer year , Integer month){
+        return payFeeMapper.getPayreceivableDebtDetailed(accountId, year, month);
+    }
+
+    /**
+     * 查询实收信息
+     * @param accountId
+     * @param year
+     * @return
+     */
+    public List<PayfeeReceivedInfo> getPayreceived(BigInteger accountId , Integer year ){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        return payFeeMapper.getPayreceived(accountId, year,  loginUser.getSiteId(), loginUser.getCustomerId());
+    }
+
+    /**
+     * 查询实收明细
+     * @param accountId
+     * @param payseriesno
+     * @param year
+     * @param month
+     * @return
+     */
+    public List<PayfeeReceivedInfo> getPayreceivedDetailed(BigInteger accountId , String payseriesno,Integer year , Integer month){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        return payFeeMapper.getPayreceivedDetailed(accountId, payseriesno, year, month, loginUser.getSiteId(), loginUser.getCustomerId());
+    }
+
+    /**
+     * 查询水量信息
+     * @param accountId
+     * @param year
+     * @return
+     */
+    public List<PayfeeWaterusedamount> getWaterusedamount(BigInteger accountId , Integer year){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        return payFeeMapper.getWaterusedamount(accountId, year,  loginUser.getSiteId(), loginUser.getCustomerId());
+    }
+
+    /**
+     * 查询收据信息
+     * @param accountId
+     * @param year
+     * @return
+     */
+    public List<PayInvoiceDto> getPayinvoiceInfo(BigInteger accountId, Integer year) {
+        return payFeeMapper.getPayinvoiceInfo(accountId, year);
+    }
 }

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

@@ -0,0 +1,174 @@
+package com.bz.smart_city.service.impl.pay;
+
+import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.commom.util.UserUtil;
+import com.bz.smart_city.dao.pay.PayInvoiceMapper;
+import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.dto.pay.PayInvoiceDto;
+import com.bz.smart_city.dto.pay.PayMessagesendrecordDto;
+import com.bz.smart_city.dto.pay.PayTransactiondetails;
+import com.bz.smart_city.dto.pay.PayTransactiondetailsDto;
+import com.bz.smart_city.dto.pay.payfee.PrintInvoiceData;
+import com.bz.smart_city.entity.pay.PayInvoice;
+import com.bz.smart_city.entity.pay.PayPayReceived;
+import com.bz.smart_city.service.pay.PayinvoiceService;
+import com.github.pagehelper.PageHelper;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-30 9:50
+ */
+@Service
+public class PayInvoiceServiceImpl implements PayinvoiceService {
+
+    @Resource
+    private PayInvoiceMapper payInvoiceMapper;
+
+    public void insert(PayInvoice payInvoice) {
+        payInvoiceMapper.insert(payInvoice);
+    }
+
+    public List<PayInvoiceDto> findList(String condition, Integer state, String startTime, String endTime) {
+        LoginUser loginUser= UserUtil.getCurrentUser();
+        PayInvoiceDto payInvoiceDto=new PayInvoiceDto();
+        payInvoiceDto.setCondition(condition);
+        payInvoiceDto.setState(state);
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
+        if(StringUtils.isNotBlank(startTime)){
+            payInvoiceDto.setStartTime( LocalDateTime.parse(startTime,df));
+        }
+        if(StringUtils.isNotBlank(endTime)){
+            payInvoiceDto.setEndTime(LocalDateTime.parse(endTime, df));
+        }
+
+        payInvoiceDto.setSiteId(loginUser.getSiteId());
+        payInvoiceDto.setProgramItems(UserUtil.getCurrentSiteProgramItems(loginUser));
+        payInvoiceDto.setCustomerId(loginUser.getCustomerId());
+
+        return payInvoiceMapper.findList(payInvoiceDto);
+    }
+
+    public Pagination<PayInvoiceDto> findListPage(String condition,Integer state, String startTime, String endTime, int pageNum, int pageSize) {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        //分页
+        PageHelper.startPage(pageNum,pageSize);
+
+        PayInvoiceDto payInvoiceDto=new PayInvoiceDto();
+        payInvoiceDto.setCondition(condition);
+        payInvoiceDto.setState(state);
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
+        if(StringUtils.isNotBlank(startTime)){
+            payInvoiceDto.setStartTime( LocalDateTime.parse(startTime,df));
+        }
+        if(StringUtils.isNotBlank(endTime)){
+            payInvoiceDto.setEndTime(LocalDateTime.parse(endTime, df));
+        }
+        //站点为空则加入用户站点查询
+        if( loginUser !=null){
+            //站点权限
+            payInvoiceDto.setSiteId(loginUser.getSiteId());
+            //客户权限
+            payInvoiceDto.setCustomerId(loginUser.getCustomerId());
+            //数据权限
+            payInvoiceDto.setProgramItems(UserUtil.getCurrentSiteProgramItems(loginUser));
+        }
+
+        List<PayInvoiceDto> list = payInvoiceMapper.findList(payInvoiceDto);
+        return new Pagination<>(list);
+    }
+
+    @Transactional(rollbackFor=Exception.class)
+    public void savePrintInfo(String payseriesno,String invoiceno) {
+        LoginUser loginUser=UserUtil.getCurrentUser();
+               BigDecimal countReceivedamount=BigDecimal.ZERO;
+        PayInvoice invoice=new PayInvoice();
+        invoice.setInvoiceno(invoiceno);
+
+        invoice.setState(2);
+        invoice.setType(2);
+        invoice.setCreateDate(LocalDateTime.now());
+        invoice.setCreateBy(BigInteger.valueOf(loginUser.getId()));
+        invoice.setUpdateBy(BigInteger.valueOf(loginUser.getId()));
+        invoice.setUpdateDate(LocalDateTime.now());
+        invoice.setDelFlag("0");
+        invoice.setSiteId(BigInteger.valueOf(loginUser.getSiteId()));
+        invoice.setCustomerId(BigInteger.valueOf(loginUser.getCustomerId()));
+        invoice.setRemarks("");
+
+        //获取同批次号的交易明细
+        List<PayTransactiondetailsDto> payTransactiondetailsList=payInvoiceMapper.findTransByPayseriesno(payseriesno,loginUser.getSiteId(),loginUser.getCustomerId());
+
+        for(PayTransactiondetailsDto payTransactiondetailsDto:payTransactiondetailsList){
+            //转预存或充值金额
+            if(payTransactiondetailsDto.getPayway()!=4&&(payTransactiondetailsDto.getTranstype()==1||payTransactiondetailsDto.getTranstype()==4)){
+                countReceivedamount = countReceivedamount.add(payTransactiondetailsDto.getTransamount()!=null?payTransactiondetailsDto.getTransamount():BigDecimal.ZERO);
+
+                invoice.setAccountId(payTransactiondetailsDto.getAccountId());
+                invoice.setAccountname(payTransactiondetailsDto.getAccountname());
+                invoice.setAccountnumber(payTransactiondetailsDto.getAccountnumber());
+            }
+        }
+        //获取同批次号的实收信息
+        List<PayPayReceived> Receiveds=payInvoiceMapper.findReceivedByPayseriesno(payseriesno,loginUser.getSiteId(),loginUser.getCustomerId());
+
+        for(PayPayReceived received:Receiveds){
+            //非预存划扣(即支付金额抵扣)
+            if(received.getPayway()!=4){
+                countReceivedamount = countReceivedamount.add(received.getReceivedamount()!=null?received.getReceivedamount():BigDecimal.ZERO);
+
+                invoice.setAccountId(received.getAccountId());
+                invoice.setAccountname(received.getAccountname());
+                invoice.setAccountnumber(received.getAccountnumber());
+            }
+
+        }
+        invoice.setInvoiceamount(countReceivedamount);
+        //插入成功后返回id
+        payInvoiceMapper.insert(invoice);
+        if(payTransactiondetailsList.size()>0){
+            //修改明细的收据信息
+            payInvoiceMapper.updatePrintInvoiceRecord(1, payseriesno, invoice.getId(),loginUser.getSiteId(),loginUser.getCustomerId());
+        }
+        if(Receiveds.size()>0){
+            //修改实收的收据信息
+            payInvoiceMapper.updatePrintInvoiceRecord(2, payseriesno, invoice.getId(),loginUser.getSiteId(),loginUser.getCustomerId());
+        }
+    }
+
+    /**
+     * 仅充值
+     * @param payseriesno
+     * @return
+     */
+    public PrintInvoiceData getPrintDataOfTrans(String payseriesno){
+//        PrintInvoiceData printInvoiceData=printNoticeDao.getPrintDataOfTran(payseriesno);
+//        if(printInvoiceData!=null){
+//            PrintInvoiceData  wateruserdData=printNoticeDao.getLastWaterUsedRecord(printInvoiceData.getAccountId(), printInvoiceData.getCreateDate());
+//            if(wateruserdData!=null){
+//                printInvoiceData.setReading(wateruserdData.getReading());
+//                printInvoiceData.setRecorddate(wateruserdData.getRecorddate());
+//            }
+//            printInvoiceData.setPaydate(printInvoiceData.getCreateDate());
+//        }
+//        return printInvoiceData;
+        return null;
+    }
+    public PrintInvoiceData getPrintDataOfReceived(String payseriesno){
+        return null;
+    }
+
+
+
+
+}

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

@@ -1,5 +1,8 @@
 package com.bz.smart_city.service.pay;
 
+import com.bz.smart_city.dto.pay.PayInvoiceDto;
+import com.bz.smart_city.dto.pay.payfee.*;
+
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.time.LocalDateTime;
@@ -12,5 +15,103 @@ import java.util.List;
  * @Version 1.0
  */
 public interface PayFeeService {
+    /**
+     * @Description: 缴纳欠费
+     * @auther: wangli
+     * @date: 2020-04-22 16:35
+     * @param: accountnumber 客户编码
+     * @param: metercode 水表编码
+     * @param: transAmount 交易金额
+     * @param: payway 支付方式
+     * @param: transTime 交易时间 :为空时取当前时间
+     * @param: receivableIds 应收id
+     * @return: payseriesno 交易流水号
+     *
+     */
     String payFee(String accountnumber , String metercode , BigDecimal transAmount, Integer paytype , LocalDateTime transTime, List<BigInteger> receivableIds,Integer siteId,Integer customerId,Integer userId);
+
+    /**
+     *  柜台缴费
+     * @param id 客户id
+     * @param payway 支付方式
+     * @param transAmount 交易金额
+     * @param balancetype 余额处理 1转预存 2找零
+     */
+     String payFeeCounter( String id,Integer payway,BigDecimal transAmount, Integer balancetype);
+
+    /**
+     * 查询客户信息
+     * @param id 开户id
+     * @param queryType 查询类型 1客户名称,2客户编码,3电话,4地址
+     * @param condition 查询参数
+     * @return
+     */
+    List<PayfeeAccountInfoDto> findPayfeeAccountInfo(BigInteger id, Integer queryType , String condition );
+
+    /**
+     * 收费界面查询账单详情
+     * @param id 客户id
+     * @return
+     */
+    PayfeeDetaileBill getPayfeeDetaileBill(BigInteger id);
+
+    /**
+     * 查询本期欠费详情
+     * @param id 客户id
+     * @return
+     */
+    PayfeeDetailed getPayfeeDetailed(BigInteger id );
+
+    /**
+     * 查询客户欠费信息
+     * @param accountId
+     * @param year
+     * @return
+     */
+    List<PayfeeReceivableInfo> getPayreceiveDebt(BigInteger accountId , Integer year);
+
+    /**
+     * 查询账期内欠费详情
+     * @param accountId 客户id
+     * @param year
+     * @param month
+     * @return
+     */
+    List<PayfeeReceivableInfo> getPayreceiveDebtDetailed(BigInteger accountId , Integer year , Integer month);
+
+    /**
+     * 查询实收信息
+     * @param accountId
+     * @param year
+     * @return
+     */
+    List<PayfeeReceivedInfo> getPayreceived(BigInteger accountId , Integer year );
+
+    /**
+     * 查询实收明细
+     * @param accountId
+     * @param year
+     * @param month
+     * @return
+     */
+    List<PayfeeReceivedInfo> getPayreceivedDetailed(BigInteger accountId ,String payseriesno, Integer year , Integer month);
+
+    /**
+     * 查询水量信息
+     * @param accountId
+     * @param year
+     * @return
+     */
+    List<PayfeeWaterusedamount> getWaterusedamount(BigInteger accountId , Integer year);
+
+    /**
+     * 查询收据信息
+     * @param accountId
+     * @param year
+     * @return
+     */
+    List<PayInvoiceDto> getPayinvoiceInfo(BigInteger accountId, Integer year);
+
+
+
 }

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

@@ -0,0 +1,64 @@
+package com.bz.smart_city.service.pay;
+
+import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.dto.pay.PayInvoiceDto;
+import com.bz.smart_city.dto.pay.PayPayReceivedDto;
+import com.bz.smart_city.dto.pay.PayTransactiondetailsDto;
+import com.bz.smart_city.dto.pay.payfee.PrintInvoiceData;
+import com.bz.smart_city.entity.pay.PayInvoice;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-07-30 9:48
+ */
+public interface PayinvoiceService {
+    /**
+     * 插入收据信息
+     * @param payInvoice
+     */
+    void insert(PayInvoice payInvoice);
+
+    /**
+     * 列表展示查询收据信息
+     * @param condition
+     * @param state
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    List<PayInvoiceDto> findList(String condition, Integer state, String startTime, String endTime) ;
+
+    /**
+     * 分页查询
+     * @param
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    Pagination<PayInvoiceDto> findListPage(String condition,Integer state, String startTime, String endTime, int pageNum, int pageSize);
+
+    /**
+     * 保存打印记录
+     * @param payseriesno   批次号
+     * @param invoiceno 票据号
+     */
+    void savePrintInfo(String payseriesno,String invoiceno);
+
+    /**
+     * 仅充值(payway==4 && transtype ==1)
+     * @param payseriesno
+     * @return
+     */
+    PrintInvoiceData getPrintDataOfTrans(String payseriesno);
+
+    /**
+     * 缴纳欠费(transtype == null || (transtype ==2 ||transtype ==4))
+     * @param payseriesno
+     * @return
+     */
+    PrintInvoiceData getPrintDataOfReceived(String payseriesno);
+}

+ 144 - 0
smart-city-platform/src/main/resources/mapper/pay/PayInvoiceMapper.xml

@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.bz.smart_city.dao.pay.PayInvoiceMapper">
+    <insert id="insert" parameterType="com.bz.smart_city.entity.pay.PayInvoice" useGeneratedKeys="true" keyProperty="id">
+        insert into pay_pay_invoice
+        (
+            site_id,
+            customer_id,
+            create_date,
+            create_by,
+            update_date,
+            update_by,
+            remarks,
+            del_flag,
+
+            account_id,
+            year,
+            month,
+            accountname,
+            accountnumber,
+            invoiceamount,
+            invoiceno,
+            state,
+            type,
+            office_id,
+            cancelperson,
+            canceltime
+        )
+        values(
+            #{siteId},
+            #{customerId},
+            #{createDate},
+            #{createBy},
+            #{updateDate},
+            #{updateBy},
+            #{remarks},
+            #{delFlag},
+
+            #{accountId},
+            #{year},
+            #{month},
+            #{accountname},
+            #{accountnumber},
+            #{invoiceamount},
+            #{invoiceno},
+            #{state},
+            #{type},
+            #{officeId},
+            #{cancelperson},
+            #{canceltime}
+        )
+    </insert>
+
+    <select id="findList" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
+        select
+        a.id,
+        a.invoiceno as "invoiceno",
+        a.accountnumber as "accountnumber",
+        a.accountname as "accountname",
+        a.invoiceamount as "invoiceamount",
+        a.state as "state",
+        (case when a.state=2 then '已使用' else '作废' end ) as "stateLabel",
+        a.create_date as "createDate",
+        (select name from sc_user where id=a.create_by) as "createByName",
+        a.canceltime as "canceltime",
+        (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
+        from pay_pay_invoice a
+        <where>
+            a.type = 1
+            <if test="siteId != null">
+                and a.site_id=#{siteId}
+            </if>
+            <if test="customerId != null">
+                and a.customer_id=#{customerId}
+            </if>
+            <if test="condition != null and condition != '' ">
+                and (
+                    a.invoiceno like concat('%',#{condition},'%')
+                or a.accountnumber like concat('%',#{condition},'%')
+                or a.accountname like concat('%',#{condition},'%')
+                )
+            </if>
+
+            <if test="year != null">
+                and a.state=#{state}
+            </if>
+            <if test="startTime != null">
+                and a.create_date >=#{startTime}
+            </if>
+            <if test="endTime != null">
+                and a.create_date &lt;= #{endTime}
+            </if>
+            <if test="programItems != null and programItems.size() != 0">
+                and   <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
+                <if test="item.dimensionId == 10">
+                    a.${item.dimensionCode} = #{item.dimensionValue}
+                </if>
+            </foreach>
+            </if>
+        </where>
+        order by a.create_date desc
+    </select>
+
+    <select id="findTransByPayseriesno" resultType="com.bz.smart_city.dto.pay.PayTransactiondetailsDto">
+        select
+            id,
+            payway,
+            transtype,
+            transamount,
+            account_id as "accountId",
+            accountname,
+            accountnumber
+        from pay_pay_transactiondetails
+        where payseriesno= #{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
+
+    </select>
+
+    <select id="findReceivedByPayseriesno" resultType="com.bz.smart_city.entity.pay.PayPayReceived">
+        select
+            id,
+            payway,
+            account_id as "accountId",
+            accountname,
+            accountnumber,
+            receivedamount
+        from pay_pay_received
+        where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
+
+    </select>
+
+    <update id="updatePrintInvoiceRecord">
+        <if test="type != null and type == 1">
+            update pay_pay_transactiondetails set invoice_id=#{invoiceId}
+            where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
+        </if>
+
+        <if test="type != null and type == 1">
+            ;update pay_pay_received set invoice_id=#{invoiceId}
+            where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
+        </if>
+
+	</update>
+
+</mapper>

+ 9 - 2
smart-city-platform/src/main/resources/mapper/pay/PayPayReceivedMapper.xml

@@ -75,7 +75,7 @@
             rece.accountname as "accountname",
             max(groy.name) as "watertypename",
             '' as "ladderlevelname",
-            max(rece.payseriesno) as "payseriesno",
+            rece.payseriesno as "payseriesno",
             sum(rece.receivedamount) as "receivedamount",
         (select label from pay_sys_dict where type = '支付方式' and value = min(rece.payway) and site_id = #{siteId} and customer_id =#{customerId}) as "paywayname",
         (select label from pay_sys_dict where type = '交易状态' and value = max(rece.state) and site_id = #{siteId} and customer_id =#{customerId}) as "statename",
@@ -94,6 +94,13 @@
             <if test="customerId != null">
                 and rece.customer_id=#{customerId}
             </if>
+            <if test="year != null">
+                rece.`year`=#{year}
+            </if>
+            <if test="accountId != null">
+                rece.account_id=#{accountId}
+            </if>
+
             <if test="condition != null">
                 and
                 (
@@ -121,7 +128,7 @@
                 </if>
             </foreach>
             </if>
-            group by accountnumber,accountname,rece.year,rece.month
+            group by rece.accountnumber,rece.accountname,rece.year,rece.month,rece.payseriesno
             order by max(rece.create_date) desc
         </where>
 

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

@@ -22,6 +22,9 @@
             <if test="metercode != null and metercode != '' ">
                 and c.metercode =#{metercode}
             </if>
+            <if test="accountId != null and accountId != '' ">
+                and c.account_id =#{accountId}
+            </if>
         </where>
         limit 1
     </select>
@@ -87,4 +90,200 @@
     <update id="updateAccountState">
         call updateAccountState(#{accountId});
     </update>
+
+
+    <select id="findPayfeeAccountInfo" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeAccountInfoDto">
+        select
+            c.id as "custId",
+            a.id as "accountId",
+            c.accountnumber,
+            c.accountname,
+            a.mobilephone,
+            a.address,
+            a.idcardno,
+            c.vatno,
+            a.email,
+            c.opendate,
+            c.metercode,
+            c.housetype,
+            c.calculateway,
+            p.id as "waterPropertyId",
+            p.name as "waterPropertyName"
+        from pay_base_customerandmeterrela c
+        left join pay_base_account a on c.account_id=a.id
+        left join pay_base_waterproperty p on c.waterProperty_id=p.id
+        <where>
+            c.businessstate=1 and c.site_id=#{siteId} and c.customer_id=#{customerId}
+            <if test="id != null and id != ''">
+               and  c.id= #{id}
+            </if>
+            <if test="condition != null and condition != ''">
+                <if test="queryType != null and queryType == 1">
+                    and c.accountname  like concat('%',#{condition},'%')
+                </if>
+                <if test="queryType != null and queryType == 2">
+                    and c.accountnumber like concat('%',#{condition},'%')
+                </if>
+                <if test="queryType != null and queryType == 3">
+                    and a.mobilephone like concat('%',#{condition},'%')
+                </if>
+                <if test="queryType != null and queryType == 4">
+                    and a.address  like concat('%',#{condition},'%')
+                </if>
+            </if>
+        </where>
+
+    </select>
+
+    <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 "waterFee",
+            (select remaining from pay_pay_rechargeaccount where account_id=#{accountId})-sum(debt) as "receivableFee"
+        from pay_pay_receivable
+        where debt>0
+        and 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}
+        and `year`= #{year} and `month`=#{month}
+        group by  account_id
+    </select>
+
+    <select id="getPayreceivableDebt" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
+        select
+            account_id as "accountId",
+            year,
+            month,
+             CONCAT(rece.year,'年',LPAD(rece.month, 2, 0),'月费用') as "name",
+             sum(rece.debt) as "debt",
+             "--" as "ladderlevelname",
+             null as "price",
+             max(rece.payamount) as "payamount",
+             sum(rece.receivablefee) as "receivablefee",
+             max(rece.create_date) as "createDate"
+        from pay_pay_receivable rece
+        where rece.debt > 0
+        and rece.account_id=#{accountId}
+        and `year`=#{year}
+        group by `year`,`month`
+    </select>
+    <select id="getPayreceivableDebtDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
+        select
+            account_id as "accountId",
+            year,
+            month,
+             rece.payitemname as "name",
+             rece.debt as "debt",
+             (case when rece.ladderlevel =  1 then '一阶'
+                        when rece.ladderlevel = 2 then '二阶'
+                        when rece.ladderlevel = 3 then '三阶'
+                        when rece.ladderlevel = 4 then '四阶'
+                        else '' end) as "ladderlevelname",
+             rece.waterbasicprice as "price",
+             rece.payamount,
+             rece.receivablefee,
+             rece.create_date
+        from pay_pay_receivable rece
+        where rece.debt > 0
+        and rece.account_id=#{accountId}
+        and `year`=#{year} and `month`=#{month}
+
+    </select>
+
+
+    <select id="getPayreceivedDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
+        select
+         name as "name",
+         (case when ladderlevel =  1 then '一阶'
+                    when ladderlevel = 2 then '二阶'
+                    when ladderlevel = 3 then '三阶'
+                    when ladderlevel = 4 then '四阶'
+                    else '' end) as "ladderlevelname",
+         payseriesno as "payseriesno",
+         receivedamount,
+         (select label from pay_sys_dict where type = '支付方式' and value = reced.payway and site_id = #{siteId} and customer_id =#{customerId}) as "paywayname",
+         (select label from pay_sys_dict where type = '交易状态' and value = reced.state and site_id = #{siteId} and customer_id =#{customerId}) as "statename",
+         create_date as "createDate",
+         iscanceled,
+          (select name from sc_user where id = reced.cancelperson) as "cancelperson",
+         canceltime,
+         invoice_id as "invoiceId"
+        from pay_pay_received reced
+        where account_id=#{accountId}
+        and `year`=#{year} and `month` = #{month} and payseriesno=#{payseriesno}
+
+    </select>
+
+    <select id="getPayreceived" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
+       select
+             CONCAT(year,'年',LPAD(month, 2, 0),'月费用') as "name" ,
+             '--'as "ladderlevelname",
+             payseriesno as "payseriesno",
+             sum(receivedamount) as "receivedamount",
+             (select label from pay_sys_dict where type = '支付方式' and value =
+                (case when  min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end )
+                 and site_id = #{siteId} and customer_id =#{customerId}) as "paywayname",
+            (select label from pay_sys_dict where type = '交易状态' and value =  max(reced.state) and site_id = #{siteId} and customer_id =#{customerId}) as "statename",
+
+             max(create_date) as "createDate"
+        from pay_pay_received reced
+        where
+         account_id=#{accountId}
+        and `year`=#{year}
+        group by `year`,`month`,payseriesno
+    </select>
+    <select id="getWaterusedamount" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeWaterusedamount">
+        select
+                a.metercode AS "metercode",
+                a.lastreading AS "lastreading",
+                a.lastrecorddate AS "lastrecorddate",
+                a.reading AS "reading",
+                a.recorddate AS "recorddate",
+                a.amount AS "amount",
+                a.payamount AS "payamount",
+                 CONCAT(a.`year`,'年',LPAD(a.month, 2, 0),'月') as "closingName",
+                (select label from pay_sys_dict where type = '水量状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
+                (case when a.state = 2 then '是' else '否' end ) isReceivable
+        from pay_amount_waterusedamount a
+        where a.`year`=#{year} and a.account_id=#{accountId}
+    </select>
+
+    <select id="getPayinvoiceInfo" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
+        select
+        a.id,
+        a.invoiceno as "invoiceno",
+        a.accountnumber as "accountnumber",
+        a.accountname as "accountname",
+        a.invoiceamount as "invoiceamount",
+        a.state as "state",
+        (case when a.state=2 then '已使用' else '作废' end ) as "stateLabel",
+        a.create_date as "createDate",
+        (select name from sc_user where id=a.create_by) as "createByName",
+        a.canceltime as "canceltime",
+        (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
+        from pay_pay_invoice a
+        <where>
+            a.type = 2
+            <if test="accountId != null">
+                and a.account_id=#{accountId}
+            </if>
+            <if test="year != null">
+                and a.year = #{year}
+            </if>
+        </where>
+        order by a.create_date desc
+    </select>
 </mapper>