|  | @@ -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);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |