2021与蓝度共同重构项目,服务端
liuhaonan
2022-03-22 db79eca1d06cc0f3cfb5aae710262aedfb95577e
c3m退款实现
已添加1个文件
已修改4个文件
已重命名4个文件
236 ■■■■ 文件已修改
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/C3mOrderController.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/UsrPayConfigController.java 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxFastPayService.java 67 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxPayConfiguration.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxPayProperties.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3mChargingChargeService.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3mOrderService.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/utils/AliPayUtils.java 50 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/C3mOrderController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,41 @@
package com.sandu.ximon.admin.controller;
import com.sandu.common.domain.ResponseVO;
import com.sandu.common.util.ResponseUtil;
import com.sandu.ximon.admin.service.C3mOrderService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
 * @Author liuhaonan
 * @Date 2022/3/22 14:10
 * @Version 1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/v1/c3mOrder")
public class C3mOrderController {
    private final C3mOrderService c3mOrderService;
    /**
     * é€€æ¬¾
     *
     * @param params
     * @return
     */
    @PostMapping("/refond")
    public ResponseVO<Object> refond(@RequestBody Map params) {
//        c3mOrderService.orderRefund( (String)params.get("outTradeNo"),
//                (Double)params.get("refundAmount"));
        return ResponseUtil.success(c3mOrderService.orderRefund((String) params.get("outTradeNo"),
                (Double) params.get("refundAmount")));
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/UsrPayConfigController.java
@@ -8,7 +8,7 @@
import com.sandu.ximon.admin.param.AlipayConfigParam;
import com.sandu.ximon.admin.param.WxpayConfigParam;
import com.sandu.ximon.admin.pay.alipay.UsrAlipayConfigService;
import com.sandu.ximon.admin.pay.alipay.UsrWxPayConfigService;
import com.sandu.ximon.admin.pay.wxpay.UsrWxPayConfigService;
import com.sandu.ximon.dao.domain.AliConfigEntity;
import com.sandu.ximon.dao.domain.WxConfigEntity;
import lombok.AllArgsConstructor;
@@ -31,6 +31,7 @@
    /**
     * æ”¯ä»˜å®é…ç½®æ·»åŠ 
     *
     * @param configParam
     * @return
     */
@@ -41,17 +42,19 @@
    /**
     * æ”¯ä»˜å®é…ç½®æ›´æ”¹
     *
     * @param configId
     * @param configParam
     * @return
     */
    @PostMapping("/updateAliPayConfig/{configId}")
    public ResponseVO<Object> updateAliPayConfig(@PathVariable Integer configId, @RequestBody AlipayConfigParam configParam) {
        return ResponseUtil.success(alipayConfigService.updateAliPayConfig(configId,configParam));
        return ResponseUtil.success(alipayConfigService.updateAliPayConfig(configId, configParam));
    }
    /**
     * æ”¯ä»˜å®é…ç½®åˆ é™¤
     *
     * @param configId
     * @return
     */
@@ -61,7 +64,6 @@
    }
    /**
     *
     * @param poleId
     * @return
     */
@@ -71,17 +73,18 @@
    }
    /**
     *配置详情
     * é…ç½®è¯¦æƒ…
     *
     * @param configId
     * @return
     */
    @GetMapping("/getAliPayConfigById/{configId}")
    public ResponseVO<Object> getAliPayConfigById(@PathVariable Integer configId) {
        if(configId==null){
        if (configId == null) {
            throw new BusinessException("id能为空");
        }
        AliConfigEntity byId = alipayConfigService.getById(configId);
        if(byId==null){
        if (byId == null) {
            throw new BusinessException("配置id错误或配置不存在");
        }
        return ResponseUtil.success(byId);
@@ -91,15 +94,13 @@
    @GetMapping("/aliConfigList")
    public ResponseVO<Object> aliConfigList(BaseConditionVO baseConditionVO
            , @RequestParam(value = "keyword", required = false) String keyword) {
        return ResponseUtil.success(alipayConfigService.configList(baseConditionVO,keyword));
        return ResponseUtil.success(alipayConfigService.configList(baseConditionVO, keyword));
    }
    /**
     * wx配置添加
     *
     * @param configParam
     * @return
     */
@@ -110,17 +111,19 @@
    /**
     * wx配置更改
     *
     * @param configId
     * @param configParam
     * @return
     */
    @PostMapping("/updateWxPayConfig/{configId}")
    public ResponseVO<Object> updateAliPayConfig(@PathVariable Long configId, @RequestBody WxpayConfigParam configParam) {
        return ResponseUtil.success(wxPayConfigService.updateWxPayConfig(configId,configParam));
        return ResponseUtil.success(wxPayConfigService.updateWxPayConfig(configId, configParam));
    }
    /**
     * wx配置删除
     *
     * @param configId
     * @return
     */
@@ -130,7 +133,6 @@
    }
    /**
     *
     * @param poleId
     * @return
     */
@@ -140,17 +142,18 @@
    }
    /**
     *配置详情
     * é…ç½®è¯¦æƒ…
     *
     * @param configId
     * @return
     */
    @GetMapping("/getWxPayConfigById/{configId}")
    public ResponseVO<Object> getWxPayConfigById(@PathVariable Integer configId) {
        if(configId==null){
        if (configId == null) {
            throw new BusinessException("id能为空");
        }
        WxConfigEntity byId = wxPayConfigService.getById(configId);
        if(byId==null){
        if (byId == null) {
            throw new BusinessException("配置id错误或配置不存在");
        }
        return ResponseUtil.success(byId);
@@ -161,13 +164,8 @@
    public ResponseVO<Object> WxConfigList(BaseConditionVO baseConditionVO
            , @RequestParam(value = "keyword", required = false) String keyword) {
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        return ResponseUtil.success(wxPayConfigService.configList(baseConditionVO,keyword));
        return ResponseUtil.success(wxPayConfigService.configList(baseConditionVO, keyword));
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxFastPayService.java
ÎļþÃû´Ó sandu-common/src/main/java/com/sandu/common/third/pay/wx/WxFastPayService.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package com.sandu.common.third.pay.wx;
package com.sandu.ximon.admin.pay.wx;
import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil;
@@ -13,15 +13,15 @@
import com.github.binarywang.wxpay.service.WxPayService;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.util.IpUtil;
import com.sandu.common.util.ResponseUtil;
import com.sandu.ximon.admin.pay.wxpay.UsrWxPayConfigService;
import com.sandu.ximon.dao.domain.WxConfigEntity;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * @author chenjiantian
@@ -32,6 +32,9 @@
@AllArgsConstructor
public class WxFastPayService {
    private final com.github.binarywang.wxpay.service.WxPayService wxPayService;
    //private final WxPayProperties wxPayProperties;
    public static final String WECHAT_ORDER_PAY_CALLBACK_URL = "http://49.235.239.118:20012/callback/pay/wechatCallback";
    /**
     * app支付
@@ -121,7 +124,7 @@
     * @param callbackUrl
     * @return
     */
    public boolean refundOrder(WxPayService wxPayService, String orderId,String refundSn, Integer refundFee, String callbackUrl) {
    public boolean refundOrder(WxPayService wxPayService, String orderId, String refundSn, Integer refundFee, String callbackUrl) {
        WxPayRefundRequest refundRequest = new WxPayRefundRequest();
        refundRequest.setOutTradeNo(orderId);
        refundRequest.setOutRefundNo(refundSn);
@@ -142,11 +145,12 @@
        }
    }
    /**
     * ç”ŸæˆäºŒç»´ç ä»˜æ¬¾
     */
    public String generateQRCodePay(WxPayService wxPayService, String body,
                                                String orderId, int totalFee, String callbackUrl) {
                                    String orderId, int totalFee, String callbackUrl) {
        WxPayUnifiedOrderRequest wxPayUnifiedOrderRequest = new WxPayUnifiedOrderRequest();
        wxPayUnifiedOrderRequest.setBody(body);
        wxPayUnifiedOrderRequest.setOutTradeNo(orderId);
@@ -173,4 +177,51 @@
            throw new BusinessException("微信支付失败," + e.getErrCodeDes());
        }
    }
    /**
     * é€€æ¬¾
     * @param totalAmount
     * @param refundAmount
     * @param outTradeNo
     * @param poleId
     * @return
     */
    public boolean refund(Double totalAmount, Double refundAmount, String outTradeNo, Long poleId) {
        WxConfigEntity wxConfig = UsrWxPayConfigService.getBean().getConfigByPoleId(poleId);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String refundNo = sdf.format(new Date());
        WxPayRefundRequest refundRequest = new WxPayRefundRequest();
        refundRequest.setOutTradeNo(outTradeNo);
        refundRequest.setOutRefundNo(refundNo);
        refundRequest.setTotalFee(Integer.valueOf(parseWxAmount((totalAmount + ""))));
        refundRequest.setRefundFee(Integer.valueOf(parseWxAmount((refundAmount + ""))));
        try {
            WxPayRefundResult wxPayRefundResult = wxPayService.refund(refundRequest);
            if (WxPayConstants.ResultCode.SUCCESS.equals(wxPayRefundResult.getResultCode())) {
                return true;
            } else {
                log.error("微信退款失败,{}", wxPayRefundResult.getErrCodeDes());
                throw new BusinessException("微信退款失败," + wxPayRefundResult.getErrCodeDes());
            }
        } catch (WxPayException e) {
            log.error("微信退款失败,{}", e.getErrCodeDes());
            throw new BusinessException("微信退款失败," + e.getErrCodeDes());
        }
    }
    /**
     * è½¬æ¢ä¸ºå¾®ä¿¡é‡‘额(分)
     *
     * @param normalAmount 0.01元
     * @return
     */
    public static String parseWxAmount(String normalAmount) {
        //  ä¿ç•™2位小数
        double totalAmountDouble = Double.parseDouble(new DecimalFormat("#.00").format(
                Double.parseDouble(normalAmount)));
        String amount = (totalAmountDouble * 100) + "";
        amount = amount.substring(0, amount.indexOf("."));
        return amount;
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxPayConfiguration.java
ÎļþÃû´Ó sandu-common/src/main/java/com/sandu/common/third/pay/wx/WxPayConfiguration.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package com.sandu.common.third.pay.wx;
package com.sandu.ximon.admin.pay.wx;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxPayProperties.java
ÎļþÃû´Ó sandu-common/src/main/java/com/sandu/common/third/pay/wx/WxPayProperties.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package com.sandu.common.third.pay.wx;
package com.sandu.ximon.admin.pay.wx;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java
ÎļþÃû´Ó ximon-admin/src/main/java/com/sandu/ximon/admin/pay/alipay/UsrWxPayConfigService.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package com.sandu.ximon.admin.pay.alipay;
package com.sandu.ximon.admin.pay.wxpay;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3mChargingChargeService.java
@@ -45,6 +45,11 @@
        return true;
    }
    /**
     * æ’入费率
     * @param c3
     * @return
     */
    public boolean initCharge(C3mChargingChargeParam c3) {
        C3mChargingCharge charge = new C3mChargingCharge();
        BeanUtil.copyProperties(c3, charge);
@@ -53,6 +58,10 @@
        return save(charge);
    }
    /**
     * è‡ªåŠ¨æ’å…¥é»˜è®¤è´¹çŽ‡
     * @param c3Id
     */
    public void initCharge(Integer c3Id) {
        List<C3mChargingCharge> chargeList = getChargeByC3Id(c3Id);
        if (chargeList.size() == 0) {
ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3mOrderService.java
@@ -1,7 +1,9 @@
package com.sandu.ximon.admin.service;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.third.pay.wx.WxFastPayService;
import com.sandu.ximon.admin.pay.wx.WxFastPayService;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.AliPayUtils;
import com.sandu.ximon.dao.domain.C3mOrder;
import com.sandu.ximon.dao.enums.OrderStatus;
@@ -24,8 +26,13 @@
    private final C3mOrderMapper c3mOrderMapper;
    private final WxFastPayService fastPayService;
    public boolean orderRefund(String outTradeNo, Double refundAmount, Long userId, String username) {
    public boolean orderRefund(String outTradeNo, Double refundAmount/*, Long userId, String username*/) {
        Long userId = SecurityUtils.getUserId();
        String username = SecurityUtils.getUsername();
        C3mOrder orderByOutTradeNo = c3mOrderMapper.getOrderByOutTradeNo(outTradeNo);
        if (orderByOutTradeNo.getTotalAmount() < refundAmount) {
            throw new BusinessException("退款金额错误,不能大于付款金额");
        }
        if (null == orderByOutTradeNo) {
            return false;
        } else {
@@ -47,12 +54,12 @@
                    C3mOrder.getRefundAmount());
        } else if (C3mOrder.getOrderType().equals(OrderType.WXPAY.getCode())) {
            //  è¿›è¡Œå¾®ä¿¡é€€æ¬¾
//            b = WxPayUtils.getBean().wxRefund(
//                    C3mOrder.getTotalAmount(),
//                    C3mOrder.getRefundAmount(),
//                    C3mOrder.getOutTradeNo(),
//                    C3mOrder.getPoleId()
//            );
            b = fastPayService.refund(
                    C3mOrder.getTotalAmount(),
                    C3mOrder.getRefundAmount(),
                    C3mOrder.getOutTradeNo(),
                    C3mOrder.getPoleId()
            );
        }
        C3mOrder.setRefundTimestamp(new Date().getTime());
        C3mOrder.setRefundMsg(msg);
ximon-admin/src/main/java/com/sandu/ximon/admin/utils/AliPayUtils.java
@@ -11,8 +11,8 @@
import com.sandu.ximon.admin.config.AlipayConfig;
import com.sandu.ximon.admin.pay.alipay.UsrAlipayConfigService;
import com.sandu.ximon.dao.domain.AliConfigEntity;
import com.sandu.ximon.dao.domain.WxConfigEntity;
import lombok.AllArgsConstructor;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -23,23 +23,23 @@
    public static boolean alipayQuery(String out_trade_no, Long streetlightId) {
        AliConfigEntity WxConfigEntity = UsrAlipayConfigService.getBean().getConfigByPoleId(streetlightId);// èŽ·å–å®¢æˆ·çš„æ”¯ä»˜å®é…ç½®
        String checkStr = ConfigCheckUtils.checkAlipayConfig(WxConfigEntity);
        if( checkStr != null){
        AliConfigEntity aliConfigEntity = UsrAlipayConfigService.getBean().getConfigByPoleId(streetlightId);// èŽ·å–å®¢æˆ·çš„æ”¯ä»˜å®é…ç½®
        String checkStr = ConfigCheckUtils.checkAlipayConfig(aliConfigEntity);
        if (checkStr != null) {
            LogUtils.error("查询失败");
            return false;
        }
        //获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl,
                WxConfigEntity.getAppId(), WxConfigEntity.getPrivateKey(),
                AlipayConfig.format, AlipayConfig.charset, WxConfigEntity.
                aliConfigEntity.getAppId(), aliConfigEntity.getPrivateKey(),
                AlipayConfig.format, AlipayConfig.charset, aliConfigEntity.
                getPublicKey(), AlipayConfig.sign_type);
        //设置请求参数
        AlipayTradeQueryRequest alipayRequest = new AlipayTradeQueryRequest();
        //商户订单号,商户网站订单系统中唯一订单号
        alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\"}");
        alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\"}");
        //请求
        String result = null;
@@ -48,19 +48,19 @@
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        Map map = (Map) new Gson().fromJson(result,Map.class).get("alipay_trade_query_response");
        Map map = (Map) new Gson().fromJson(result, Map.class).get("alipay_trade_query_response");
        if (map.get("sub_msg") != null) {
            if ("交易不存在".equals(map.get("sub_msg"))) {
                return false;
            }
        }
        if(map.get("trade_status")==null){
        if (map.get("trade_status") == null) {
            return false;
        }
        if("TRADE_SUCCESS".equals(map.get("trade_status"))){
        if ("TRADE_SUCCESS".equals(map.get("trade_status"))) {
//            String payTime = (String) map.get("send_pay_date");
            return true;
        }else if("TRADE_CLOSED".equals(map.get("trade_status"))){
        } else if ("TRADE_CLOSED".equals(map.get("trade_status"))) {
            LogUtils.error("交易已关闭(支付宝)");
            return false;
        }
@@ -68,32 +68,32 @@
    }
    /**
     * æ”¯ä»˜å®é€€æ¬¾æŽ¥å£
     *
     * @return
     */
    public static boolean alipayrefund(Long streetlightId,
                                String out_trade_no,
                                Double refundAmount) {
                                       String out_trade_no,
                                       Double refundAmount) {
        //LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"退款操作",null,"{ è¿›è¡Œæ”¯ä»˜å®é€€æ¬¾:"+out_trade_no+" }");
        //退款金额,不能大于订单总金额
        String refund_amount = refundAmount+"";
        String refund_amount = refundAmount + "";
        //退款的原因说明
        String refund_reason = "充电桩退款";
        //标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传。
        String  out_request_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String out_request_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        AliConfigEntity WxConfigEntity = UsrAlipayConfigService.getBean().getConfigByPoleId(streetlightId);   //找到是哪个客户的充电桩  å°±é€€æ¬¾ç»™è°
        String checkStr = ConfigCheckUtils.checkAlipayConfig(WxConfigEntity);
        if( checkStr != null){
        AliConfigEntity AliConfigEntity = UsrAlipayConfigService.getBean().getConfigByPoleId(streetlightId);   //找到是哪个客户的充电桩  å°±é€€æ¬¾ç»™è°
        String checkStr = ConfigCheckUtils.checkAlipayConfig(AliConfigEntity);
        if (checkStr != null) {
            return false;
        }
        // SDK å…¬å…±è¯·æ±‚类,包含公共请求参数,以及封装了签名与验签,开发者无需关注签名与验签
        AlipayClient client = new DefaultAlipayClient(AlipayConfig.gatewayUrl, WxConfigEntity.getAppId(),
                WxConfigEntity.getPrivateKey(), AlipayConfig.format,
                AlipayConfig.charset, WxConfigEntity.getPublicKey(), AlipayConfig.sign_type);
        AlipayClient client = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AliConfigEntity.getAppId(),
                AliConfigEntity.getPrivateKey(), AlipayConfig.format,
                AlipayConfig.charset, AliConfigEntity.getPublicKey(), AlipayConfig.sign_type);
        AlipayTradeRefundRequest alipay_request = new AlipayTradeRefundRequest();
        AlipayTradeRefundModel model = new AlipayTradeRefundModel();
        model.setOutTradeNo(out_trade_no);
@@ -110,13 +110,13 @@
            e.printStackTrace();
        }
//        System.out.println(alipay_response.getBody());
        if("10000".equals(alipay_response.getCode())){
        if ("10000".equals(alipay_response.getCode())) {
            //  é€€æ¬¾æˆåŠŸ
         //   LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"退款操作",null,"{ è¿›è¡Œæ”¯ä»˜å®é€€æ¬¾(成功):"+out_trade_no+",退款金额:"+refundAmount+" }");
            //   LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"退款操作",null,"{ è¿›è¡Œæ”¯ä»˜å®é€€æ¬¾(成功):"+out_trade_no+",退款金额:"+refundAmount+" }");
            return true;
        }
        //保存退款金额和退款单号,将订单状态置为完成(RFERROR),保存到数据库
      //  LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"退款操作",null,"{ è¿›è¡Œæ”¯ä»˜å®é€€æ¬¾(失败):"+out_trade_no+",退款金额:"+refundAmount+",reason: "+ JSON.toJSONString(alipay_response)+" }");
        //  LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"退款操作",null,"{ è¿›è¡Œæ”¯ä»˜å®é€€æ¬¾(失败):"+out_trade_no+",退款金额:"+refundAmount+",reason: "+ JSON.toJSONString(alipay_response)+" }");
        return false;
    }