| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.PageData; |
| | |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.core.wx.WxMiniConfig; |
| | | import com.doumee.dao.business.WxBillDetailMapper; |
| | | import com.doumee.dao.business.WxBillMapper; |
| | | import com.doumee.dao.business.model.WxBill; |
| | | import com.doumee.dao.business.model.WxBillDetail; |
| | | import com.doumee.service.business.WxBillService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | import com.github.binarywang.wxpay.bean.result.WxPayBillInfo; |
| | | import com.github.binarywang.wxpay.bean.result.WxPayBillResult; |
| | | import com.github.binarywang.wxpay.exception.WxPayException; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Serviceå®ç° |
| | |
| | | |
| | | @Autowired |
| | | private WxBillMapper wxBillMapper; |
| | | @Autowired |
| | | private WxBillDetailMapper wxBillDetailMapper; |
| | | @Override |
| | | public String create(WxBill wxBill) { |
| | | wxBillMapper.insert(wxBill); |
| | |
| | | return wxBillMapper.selectCount(wrapper); |
| | | } |
| | | @Override |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public void getWxBill() { |
| | | // è·å交æè´¦åæ°æ® |
| | | WxPayDownloadBillRequest request = new WxPayDownloadBillRequest(); |
| | | String billDate = DateUtil.beforeDateToStr(1); |
| | | request.setBillDate(billDate); |
| | | request.setBillType("SUCCESS"); |
| | | WxPayBillResult response = null; |
| | | try { |
| | | // è·å交æè´¦åæ°æ® |
| | | WxPayDownloadBillRequest request = new WxPayDownloadBillRequest(); |
| | | String billDate = DateUtil.beforeDateToStr(1); |
| | | request.setBillDate(billDate); |
| | | request.setBillType("ALL"); |
| | | WxPayBillResult response = WxMiniConfig.wxPayService.downloadBill(request); |
| | | if(response !=null){ |
| | | List<WxPayBillInfo> detailList = response.getBillInfoList(); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR); |
| | | } |
| | | response = WxMiniConfig.wxPayService.downloadBill(request); |
| | | }catch (WxPayException e){ |
| | | |
| | | } catch (WxPayException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | request.setBillType("REFUND"); |
| | | //请æ±é款å交æè®°å½æ±æ»æ°æ® |
| | | WxPayBillResult responseRefund = null; |
| | | try { |
| | | responseRefund = WxMiniConfig.wxPayService.downloadBill(request); |
| | | }catch (WxPayException e){ |
| | | |
| | | } |
| | | WxBill bill = new WxBill(); |
| | | //æ¥æä½ä¸ºä¸»é® |
| | | bill.setId(billDate); |
| | | bill.setSumBill(0); |
| | | bill.setSumTotalFee(new BigDecimal(0.00)); |
| | | bill.setSumSuccessFee(new BigDecimal(0.00)); |
| | | bill.setSumRefundFee(new BigDecimal(0.00)); |
| | | bill.setSumCouponRefundFee(new BigDecimal(0.00)); |
| | | bill.setSumApplyRefundFee(new BigDecimal(0.00)); |
| | | bill.setSumCmmsAmt(new BigDecimal(0.00)); |
| | | bill.setSumRefundBill(0); |
| | | bill.setSumRefundCmmsAmt(new BigDecimal(0.00)); |
| | | List<WxBillDetail> detailList = new ArrayList<>(); |
| | | if(response !=null){ |
| | | // List<WxPayBillInfo> detailList = response.getBillInfoList(); |
| | | int totalRefund = 0; |
| | | BigDecimal totalRefundAmt = new BigDecimal(0.00); |
| | | bill.setSumBill(Integer.parseInt(response.getTotalRecord())); |
| | | //è®¢åæ»éé¢ |
| | | bill.setSumTotalFee(formatStringToDecimal(response.getTotalAmount())); |
| | | //åºç»è®¢åæ»éé¢ |
| | | bill.setSumSuccessFee(formatStringToDecimal(response.getTotalFee())); |
| | | //鿬¾æ»éé¢ |
| | | bill.setSumRefundFee(formatStringToDecimal(response.getTotalFee())); |
| | | //鿬¾æ»éé¢ |
| | | bill.setSumApplyRefundFee(formatStringToDecimal(response.getTotalAppliedRefundFee())); |
| | | //äº¤ææ»æç»è´¹éé¢ |
| | | bill.setSumCmmsAmt(formatStringToDecimal(response.getTotalPoundageFee())); |
| | | detailList.addAll(getDetialModelByInfo(bill,response.getBillInfoList())); |
| | | } |
| | | if(responseRefund != null){ |
| | | //鿬¾åæ»æ°ç´¯è®¡è¿å
¥ |
| | | // bill.setSumBill(bill.getSumBill()+(Integer.parseInt(response.getTotalRecord())); |
| | | bill.setSumRefundBill(Integer.parseInt(responseRefund.getTotalRecord()));//鿬¾çè®¢åæ° |
| | | bill.setSumRefundCmmsAmt(formatStringToDecimal(responseRefund.getTotalPoundageFee()));//鿬¾æ»æç»è´¹ |
| | | bill.setSumCouponRefundFee(formatStringToDecimal(responseRefund.getTotalCouponFee()));//鿬¾æ»æç»è´¹ |
| | | detailList.addAll(getDetialModelByInfo(bill,responseRefund.getBillInfoList())); |
| | | } |
| | | wxBillMapper.delete(new UpdateWrapper<WxBill>().lambda().eq( WxBill::getId, bill.getId())); |
| | | wxBillDetailMapper.delete(new UpdateWrapper<WxBillDetail>().lambda().eq( WxBillDetail::getPid, bill.getId())); |
| | | wxBillMapper.insert(bill); |
| | | if(detailList.size()>0){ |
| | | wxBillDetailMapper.insertBatch(detailList); |
| | | } |
| | | } |
| | | |
| | | private List<WxBillDetail> getDetialModelByInfo(WxBill bill, List<WxPayBillInfo> billInfoList) { |
| | | List<WxBillDetail> detailList = new ArrayList<>(); |
| | | if(billInfoList!=null){ |
| | | for (int i = 0; i <billInfoList.size(); i++) { |
| | | WxPayBillInfo info =billInfoList.get(i); |
| | | WxBillDetail detail = new WxBillDetail(); |
| | | detail.setId(UUID.randomUUID().toString()); |
| | | detail.setPid(bill.getId()); |
| | | detail.setBillDate(DateUtil.getDateFromString2(info.getTradeTime()));//äº¤ææ¶é´ |
| | | detail.setAppid(info.getAppId());//å
¬ä¼è´¦å·ID |
| | | detail.setMchId(info.getMchId());//åæ·å· |
| | | detail.setSubMchid(info.getSubMchId());//ç¹çº¦åæ·å· |
| | | detail.setDeviceInfo(info.getDeviceInfo());//è®¾å¤ |
| | | |
| | | detail.setTransactionId(info.getTransactionId());//微信订åå· |
| | | detail.setOutTradeNo(info.getOutTradeNo());//åæ·è®¢åå· |
| | | detail.setOpenid(info.getOpenId());//ç¨æ·æ è¯ |
| | | detail.setBillType(info.getTradeType());//交æç±»å |
| | | detail.setBillStatus(info.getTradeState());//交æç¶æ |
| | | detail.setBankType(info.getBankType());//仿¬¾é¶è¡ |
| | | detail.setFeeType(info.getFeeType());//è´§å¸ç§ç±» |
| | | detail.setSettlementTotalFee(formatStringToDecimal(info.getTotalFee()));//åºç»è®¢åéé¢ |
| | | detail.setCouponFee(formatStringToDecimal(info.getCouponFee()));//代éå¸éé¢ |
| | | detail.setRefundId(info.getRefundId());//å¾®ä¿¡éæ¬¾åå· |
| | | detail.setOutRefundNo(info.getOutRefundNo());//忷鿬¾åå· |
| | | detail.setRefundFee(formatStringToDecimal(info.getSettlementRefundFee()));//鿬¾éé¢ |
| | | detail.setCouponRefundFee(formatStringToDecimal(info.getCouponRefundFee()));//å
å¼å¸é款éé¢ |
| | | detail.setRefundType(info.getRefundChannel());//鿬¾ç±»å |
| | | detail.setRefundSuccessStatus(info.getRefundState());//鿬¾ç¶æ |
| | | detail.setBody(info.getBody());//åååç§° |
| | | detail.setAttach(info.getAttach());//åæ·æ°æ®å
|
| | | detail.setCmmsAmt(formatStringToDecimal(info.getPoundage()));//æç»è´¹ |
| | | detail.setRate(formatStringToDecimal(info.getPoundageRate().replace("%", "")));//è´¹ç |
| | | detail.setTotalFee(formatStringToDecimal(info.getTotalAmount()));//订åéé¢ |
| | | detail.setApplyRefundFee(formatStringToDecimal(info.getAppliedRefundAmount()));//ç³è¯·é款éé¢ |
| | | detail.setRateRemark(info.getFeeRemark());//è´¹ç夿³¨ |
| | | detail.setRefundSuccessDate(DateUtil.getDateFromString2(info.getRefundSuccessTime()));//æå鿬¾æ¶é´ |
| | | detail.setRefundApplyDate(DateUtil.getDateFromString2(info.getRefundTime())); //ç³è¯·é款æ¶é´ |
| | | |
| | | detailList.add(detail); |
| | | } |
| | | } |
| | | return detailList; |
| | | } |
| | | |
| | | public static BigDecimal formatStringToDecimal(String str){ |
| | | if(str == null){ |
| | | return new BigDecimal(0.00); |
| | | } |
| | | return new BigDecimal(Double.parseDouble(str)); |
| | | } |
| | | } |