package com.xhpc.payment.controller;

import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.utils.DateUtils;
import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.utils.WXPayUtil;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.payment.domain.XhpcAppUser;
import com.xhpc.payment.domain.XhpcRefundAudit;
import com.xhpc.payment.domain.XhpcRefundOrder;
import com.xhpc.payment.mapper.XhpcUserAccountStatementMapper;
import com.xhpc.payment.service.IXhpcRefundAuditService;
import com.xhpc.payment.service.IXhpcRefundOrderService;
import com.xhpc.payment.service.impl.XhpcUserAccountStatementServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.security.KeyStore;
import java.util.List;
import java.util.Map;

@EnableScheduling
@RestController
@RequestMapping("/refund/audit")
@Api(value = "退款审核接口", tags = "退款审核接口")
public class XhpcRefundAuditController extends BaseController {

    @Autowired
    private IXhpcRefundAuditService iXhpcRefundAuditService;

    @Autowired
    private IXhpcRefundOrderService iXhpcRefundOrderService;

    @Autowired
    private XhpcUserAccountStatementMapper xhpcUserAccountStatementMapper;

    @Autowired
    private XhpcUserAccountStatementServiceImpl xhpcUserAccountStatementService;

    @Autowired
    private Environment environment;

    private static final Logger logger = LoggerFactory.getLogger(XhpcRefundAuditController.class);
    /**
     * 退款审核
     *
     * @param xhpcRefundAudit
     * @return
     */
    @PostMapping("/examine")
    @ApiOperation(value = "退款审核")
    @Transactional
    public AjaxResult info(@RequestBody XhpcRefundAudit xhpcRefundAudit) {

        return getAjaxResult(xhpcRefundAudit);
    }

    private AjaxResult getAjaxResult(XhpcRefundAudit xhpcRefundAudit) {

        Long refundOrderId = xhpcRefundAudit.getRefundOrderId();
        Map<String, Object> map = iXhpcRefundOrderService.info(refundOrderId);

        if (null == map) {
            AjaxResult.error(HttpStatus.DATA_ERROR, "退款订单不存在");
        }
        String status = StringUtils.valueOf(map.get("status"));
        if (StatusConstants.REFUND_ORDER_STATUS_WAIT != Integer.parseInt(status)) {
            AjaxResult.error(HttpStatus.DATA_ERROR, "退款订单状态不能审核");
        }
        String examineStatus = StringUtils.valueOf(map.get("examineStatus"));
        if (StatusConstants.REFUND_ORDER_STATUS_WAIT != Integer.parseInt(examineStatus)) {
            AjaxResult.error(HttpStatus.DATA_ERROR, "退款订单状态不能审核");
        }
        AjaxResult ajaxResult = iXhpcRefundAuditService.insert(xhpcRefundAudit);
        if (StringUtils.isNotNull(ajaxResult)) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ajaxResult;
        }
        String userId = StringUtils.valueOf(map.get("userId"));
        XhpcAppUser xhpcAppUser = new XhpcAppUser();
        xhpcAppUser.setAppUserId(Long.parseLong(userId));
        xhpcAppUser.setIsRefundApplication(0);
        int refundApplication = xhpcUserAccountStatementMapper.updateAppUserRefundApplication(xhpcAppUser);
        if (refundApplication == 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        if (StatusConstants.REFUND_ORDER_STATUS_SUCCESS == xhpcRefundAudit.getStatus()) {
            String amount = "-" + StringUtils.valueOf(map.get("amount"));
            xhpcUserAccountStatementService.add(xhpcRefundAudit.getRefundOrderId(), amount, userId, StatusConstants.FLOWING_WATER_REFUND);
            String type = StringUtils.valueOf(map.get("type"));
            if (StatusConstants.OPERATION_WX_TYPE.equals(type)) {
               return enterpriseCheckOut(xhpcRefundAudit);
            }
            if (StatusConstants.OPERATION_ALI_PAY_TYPE.equals(type)) {
               return zhbCheckOut(xhpcRefundAudit);
            }
        }
        updateXhpcRefundOrder(refundOrderId,2);
        return AjaxResult.success();
    }

    /**
     * 取消申请
     *
     * @param map
     * @return
     */
    @PostMapping("/cancelExamine")
    @ApiOperation(value = "取消申请")
    @Transactional
    public AjaxResult cancelExamine(@RequestBody Map<String, Object> map) {
        String userId = StringUtils.valueOf(map.get("userId"));
        if (StringUtils.isEmpty(userId)) {
            return AjaxResult.error(HttpStatus.NOT_NULL, "用户id不能为空");
        }
        Map<String, Object> refundOrder = iXhpcRefundOrderService.getNotRefundOrder(Long.parseLong(userId));
        if (StringUtils.isNull(refundOrder)) {
            return AjaxResult.error(HttpStatus.DATA_ERROR, "退款订单不存在");
        }
        String refundOrderId = StringUtils.valueOf(refundOrder.get("refundOrderId"));
        XhpcRefundOrder xhpcRefundOrder = new XhpcRefundOrder();
        xhpcRefundOrder.setRefundOrderId(Long.parseLong(refundOrderId));
        xhpcRefundOrder.setExamineStatus(1);
        xhpcRefundOrder.setStatus(StatusConstants.REFUND_ORDER_STATUS_CANCEL);
        int updateStatus = iXhpcRefundOrderService.updateStatus(xhpcRefundOrder);
        if (updateStatus == 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        XhpcAppUser xhpcAppUser = new XhpcAppUser();
        xhpcAppUser.setAppUserId(Long.parseLong(userId));
        xhpcAppUser.setIsRefundApplication(0);
        xhpcUserAccountStatementMapper.updateAppUserRefundApplication(xhpcAppUser);
        return AjaxResult.success();
    }

    /**
     * 退款审核页列表
     */
    //@PreAuthorize(hasPermi = "refund:audit:list")
    @GetMapping("/list")
    public TableDataInfo page(@RequestParam Long refundOrderId) {
        List<Map<String, Object>> list = iXhpcRefundAuditService.list(refundOrderId);
        return getDataTable(list);
    }


    /**
     * 企业退款
     *
     * @return
     */
    public AjaxResult enterpriseCheckOut(@RequestBody XhpcRefundAudit xhpcRefundAudit) {
        //只有审核通过才能退款
        Long refundOrderId = xhpcRefundAudit.getRefundOrderId();
        Map<String, Object> xhpcRefundOrder = iXhpcRefundOrderService.info(xhpcRefundAudit.getRefundOrderId());

        if (StringUtils.isNull(xhpcRefundOrder)) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.DATA_ERROR, "订单不存在");
        }
        String examineStatus = StringUtils.valueOf(xhpcRefundOrder.get("examineStatus"));
        if (!"1".equals(examineStatus)) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单状态不能退款");
        }

        String status = StringUtils.valueOf(xhpcRefundOrder.get("status"));
        if (!"0".equals(status)) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单状态不能退款");
        }

        CloseableHttpClient httpClient = null;
        try {
            //证书的地址
            //String certPath = ConfigListener.getConf().get("certPath");
            //System.out.println("certPath:"+certPath);
            httpClient = initCert();
        } catch (Exception e) {
            e.printStackTrace();

        }
        String orderOutNumber = StringUtils.valueOf(xhpcRefundOrder.get("refundOrderNumber"));
        String openId = StringUtils.valueOf(xhpcRefundOrder.get("openId"));
        Double amount = Double.parseDouble(StringUtils.valueOf(xhpcRefundOrder.get("amount")));
        //退款金额单位为分
        Double value = amount * 100;
        Integer refund_fee = value.intValue();
        if (refund_fee <= 0) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单金额出错");
        }
        String userId = StringUtils.valueOf(xhpcRefundOrder.get("userId"));
        Map<String, Object> appUserInfo = xhpcUserAccountStatementMapper.appUserInfo(Long.parseLong(userId));
        String balance = StringUtils.valueOf(appUserInfo.get("balance"));

        if (StringUtils.isNull(appUserInfo)) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.DATA_ERROR, "用户不存在");
        }
        BigDecimal surplus = BigDecimal.valueOf(Double.valueOf(balance)).subtract(BigDecimal.valueOf(amount));
        if (surplus.compareTo(BigDecimal.ZERO) == -1) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.ERROR_STATUS, "余额不足");
        }
        String result = "";
        HttpPost httpPost = new HttpPost(environment.getProperty("WXTRANSFERS"));
        StringEntity postEntity = new StringEntity(creatXMLParam(orderOutNumber, refund_fee.toString(), "退款申请", openId), "UTF-8");
        httpPost.addHeader("Content-Type", "text/xml");
        httpPost.setEntity(postEntity);
        try {
            HttpResponse response = null;
            try {
                response = httpClient.execute(httpPost);
            } catch (IOException e) {
                e.printStackTrace();
            }
            HttpEntity entity = response.getEntity();
            try {
                result = EntityUtils.toString(entity, "UTF-8");
            } catch (IOException e) {
                e.printStackTrace();
            }
        } finally {
            httpPost.abort();
        }
        return parseXml(result, xhpcRefundAudit.getRefundOrderId(), BigDecimal.valueOf(amount), userId);
    }


    /**
     * 加载证书
     *
     * @param
     * @throws Exception
     */
    private CloseableHttpClient initCert() throws Exception {
        String path = "apiclient_cert.p12";
        //File file = new File(this.getClass().getResource("/").getPath() + path);
        //线上地址
        File file = new File("/www/wwwroot/scxhua.cn/xhpc-payment/" + path);
        // 证书密码，默认为商户ID
        String key = environment.getProperty("MCHID");
        // 指定读取证书格式为PKCS12
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        // 读取本机存放的PKCS12证书文件
        FileInputStream instream = new FileInputStream(file);
        try {
            // 指定PKCS12的密码(商户ID)
            keyStore.load(instream, key.toCharArray());
        } finally {
            instream.close();
        }
        SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, key.toCharArray()).build();
        SSLConnectionSocketFactory sslsf =
                new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
                        SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
        return HttpClients.custom().setSSLSocketFactory(sslsf).build();
    }

    /**
     * 生成xml格式  添加参数时，按照abcd26个字母顺序添加
     *
     * @param openid           用户openid
     * @param partner_trade_no 商户退款单号
     * @param amount           退款金额
     * @param refund_desc      退款原因
     * @return
     */
    private String creatXMLParam(String partner_trade_no, String amount, String refund_desc, String openid) {
        String param = "";
        //随机字符串
        String nonceStr = WXPayUtil.generateNonceStr();
        //退款金额
        param += "amount=" + amount;
        //校验用户姓名选项
        param += "&check_name=" + "NO_CHECK";
        //退款原因
        param += "&desc=" + refund_desc;
        param += "&mch_appid=" + environment.getProperty("APPID");
        //商户id
        param += "&mchid=" + environment.getProperty("MCHID");
        //随机字符串
        param += "&nonce_str=" + nonceStr;
        //用户openid
        param += "&openid=" + openid;
        //商户退款单号 一个订单唯一
        param += "&partner_trade_no=" + partner_trade_no;
        //生成签名  添加key值
        String stringSignTemp = param + "&key=" + environment.getProperty("KEY");
        //签名  不参与签名  默认MD5算法
        String sign = StringUtils.md5(stringSignTemp);
        String xmlString = "<xml>\n" +
                "   <amount>" + amount + "</amount>\n" +
                "   <check_name>" + "NO_CHECK" + "</check_name>\n" +
                "   <desc>" + refund_desc + "</desc>\n" +
                "   <mch_appid>" + environment.getProperty("APPID") + "</mch_appid>\n" +
                "   <mchid>" + environment.getProperty("MCHID") + "</mchid>\n" +
                "   <nonce_str>" + nonceStr + "</nonce_str>\n" +
                "   <openid>" + openid + "</openid>\n" +
                "   <partner_trade_no>" + partner_trade_no + "</partner_trade_no>\n" +
                "   <sign>" + sign + "</sign>\n" +
                "</xml> ";
        return xmlString;
    }

    /**
     * 解析xml字符串
     *
     * @param result 请求后的结果
     * @return
     */
    private AjaxResult parseXml(String result, Long id, BigDecimal amount, String userId) {

        try {
            Map<String, String> map = WXPayUtil.xmlToMap(result);
            String result_code = map.get("result_code");
            if ("FAIL".equals(result_code)) {
                return AjaxResult.error(map.get("err_code_des"));
            } else {
                //退款成功修改订单
                Map<String, Object> appUserInfo = xhpcUserAccountStatementMapper.appUserInfo(Long.parseLong(userId));
                if (StringUtils.isNotNull(appUserInfo)) {
                    String balance = StringUtils.valueOf(appUserInfo.get("balance"));
                    //减少用户余额
                    XhpcAppUser xhpcAppUser = new XhpcAppUser();
                    xhpcAppUser.setAppUserId(Long.parseLong(userId));
                    BigDecimal surplus =new BigDecimal(balance).subtract(amount);
                    xhpcAppUser.setBalance(surplus);
                    xhpcUserAccountStatementMapper.updateAppUserBalance(xhpcAppUser);
                    updateXhpcRefundOrder(id,1);
                }
                return AjaxResult.success("退款成功");
            }
        } catch (Exception e) {
            AjaxResult.error(e.getMessage());
            e.printStackTrace();
        }
        updateXhpcRefundOrder(id,1);
        return AjaxResult.error();
    }

    /**
     * 25       * 支付宝转账到用户账号
     * 26       * @throws IOException
     * 27
     */
    public  AjaxResult zhbCheckOut(@RequestBody XhpcRefundAudit xhpcRefundAudit){
        //修改订单状态
        Long refundOrderId = xhpcRefundAudit.getRefundOrderId();
        //只有审核通过才能退款
        Map<String, Object> xhpcRefundOrder = iXhpcRefundOrderService.info(xhpcRefundAudit.getRefundOrderId());

        if (StringUtils.isNull(xhpcRefundOrder)) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.DATA_ERROR, "订单不存在");
        }
        String examineStatus = StringUtils.valueOf(xhpcRefundOrder.get("examineStatus"));
        if (!"1".equals(examineStatus)) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单状态不能退款");
        }
        String status = StringUtils.valueOf(xhpcRefundOrder.get("status"));
        if (!"0".equals(status)) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单状态不能退款");
        }
        String orderOutNumber = StringUtils.valueOf(xhpcRefundOrder.get("refundOrderNumber"));
        String uid = StringUtils.valueOf(xhpcRefundOrder.get("alipayId"));
        String money = StringUtils.valueOf(xhpcRefundOrder.get("amount"));
        Double amount = Double.parseDouble(StringUtils.valueOf(xhpcRefundOrder.get("amount")));
        //退款金额单位为分
        Double value = amount * 100;
        Integer refund_fee = value.intValue();
        if (refund_fee <= 0) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单金额出错");
        }
        String userId = StringUtils.valueOf(xhpcRefundOrder.get("userId"));
        Map<String, Object> appUserInfo = xhpcUserAccountStatementMapper.appUserInfo(Long.parseLong(userId));
        String balance = StringUtils.valueOf(appUserInfo.get("balance"));

        if (StringUtils.isNull(appUserInfo)) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.DATA_ERROR, "用户不存在");
        }
        BigDecimal surplus = BigDecimal.valueOf(Double.valueOf(balance)).subtract(BigDecimal.valueOf(amount));
        if (surplus.compareTo(BigDecimal.ZERO) == -1) {
            updateXhpcRefundOrder(refundOrderId,2);
            return AjaxResult.error(HttpStatus.ERROR_STATUS, "余额不足");
        }
        try {
            String orderNumber = "alipay" + DateUtils.timePath();
            /** 初始化 **/
            CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
            /** 支付宝网关 **/
            certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
            /** 应用id，如何获取请参考：https://opensupport.alipay.com/support/helpcenter/190/201602493024 **/
            certAlipayRequest.setAppId(environment.getProperty("ALIPAYAPPID"));
            /** 应用私钥, 如何获取请参考：https://opensupport.alipay.com/support/helpcenter/207/201602471154?ant_source=antsupport  **/
            certAlipayRequest.setPrivateKey(environment.getProperty("ALIPAYPRIVATEKEY"));
            /** 应用公钥证书路径，下载后保存位置的绝对路径  **/
            certAlipayRequest.setCertPath(environment.getProperty("CERTPATH"));
            /** 支付宝公钥证书路径，下载后保存位置的绝对路径 **/
            certAlipayRequest.setAlipayPublicCertPath(environment.getProperty("PUBLICCERTPATH"));
            /** 支付宝根证书路径，下载后保存位置的绝对路径 **/
            certAlipayRequest.setRootCertPath(environment.getProperty("ROOTCRETPATH"));
            /** 设置签名类型 **/
            certAlipayRequest.setSignType("RSA2");
            /** 设置请求格式，固定值json **/
            certAlipayRequest.setFormat("json");
            /** 设置编码格式 **/
            certAlipayRequest.setCharset("UTF-8");

            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
            /** 实例化具体API对应的request类，类名称和接口名称对应,当前调用接口名称：alipay.fund.trans.uni.transfer(单笔转账接口) **/
            AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
            /** 设置业务参数，具体接口参数传值以文档说明为准：https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.uni.transfer/ **/
            AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
            /** 商户端的唯一订单号，对于同一笔转账请求，商户需保证该订单号唯一 **/
            model.setOutBizNo(orderNumber);
            /** 转账金额，TRANS_ACCOUNT_NO_PWD产品取值最低0.1  **/
            model.setTransAmount(money);
            /** 产品码，单笔无密转账到支付宝账户固定为：TRANS_ACCOUNT_NO_PWD **/
            model.setProductCode("TRANS_ACCOUNT_NO_PWD");
            /** 场景码，单笔无密转账到支付宝账户固定为：DIRECT_TRANSFER  **/
            model.setBizScene("DIRECT_TRANSFER");
            /** 转账业务的标题，用于在支付宝用户的账单里显示 **/
            model.setOrderTitle("转账标题");
            Participant participant = new Participant();
            /** 参与方的唯一标识,收款支付宝账号或者支付宝吧账号唯一会员ID **/
            participant.setIdentity(uid);
            /** 参与方的标识类型：ALIPAY_USER_ID 支付宝的会员ID  **/
            participant.setIdentityType("ALIPAY_USER_ID");
            model.setPayeeInfo(participant);
            /** 业务备注  **/
            model.setRemark("单笔转账--"+orderOutNumber);
            request.setBizModel(model);
            AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
            /** 获取接口调用结果，如果调用失败，可根据返回错误信息到该文档寻找排查方案：https://opensupport.alipay.com/support/helpcenter/107 **/
        if (response.isSuccess()) {
            Map<String, Object> appUserInfo1 = xhpcUserAccountStatementMapper.appUserInfo(Long.parseLong(userId));
            //退款成功修改订单
            if (StringUtils.isNotNull(appUserInfo1)) {
                String balance1 = StringUtils.valueOf(appUserInfo1.get("balance"));
                //减少用户余额
                XhpcAppUser xhpcAppUser = new XhpcAppUser();
                xhpcAppUser.setAppUserId(Long.parseLong(userId));
                BigDecimal surplus1 =new BigDecimal(balance1).subtract(BigDecimal.valueOf(amount));
                xhpcAppUser.setBalance(surplus1);
                xhpcUserAccountStatementMapper.updateAppUserBalance(xhpcAppUser);

                updateXhpcRefundOrder(refundOrderId,1);
            }
            return AjaxResult.success("退款成功");
        } else {
            System.out.println("调用失败");

        }
        }catch (Exception e){
            e.printStackTrace();
        }
        updateXhpcRefundOrder(refundOrderId,2);

        return AjaxResult.error("退款失败");
    }

    public void updateXhpcRefundOrder(Long refundOrderId,Integer status){
        XhpcRefundOrder refundOrder =new XhpcRefundOrder();
        refundOrder.setRefundOrderId(refundOrderId);
        refundOrder.setStatus(status);
        iXhpcRefundOrderService.update(refundOrder);
    }


    /**
     * 定时任务，每5分钟，扫描一次，退款订单金额小于100，自动审核通过
     *
     */
    @Scheduled(cron = "0 */5 * * * ?")
    @GetMapping("/moneyPage")
    public void moneyPage(){
        logger.info("++++++++++++111自动审核异常111++++++++++++++++");
        try {
            List<Long> list = iXhpcRefundOrderService.moneyPage();
            if(list !=null && list.size()>0){
                for (int i = 0; i <list.size() ; i++) {
                    Long aLong = list.get(i);
                    XhpcRefundAudit xhpcRefundAudit =new XhpcRefundAudit();
                    xhpcRefundAudit.setRefundOrderId(aLong);
                    xhpcRefundAudit.setStatus(1);
                    xhpcRefundAudit.setRemark("自动审核通过");
                    getAjaxResult(xhpcRefundAudit);
                }
            }
        }catch (Exception e){
            logger.info("++++++++++++自动审核异常++++++++++++++++");
            e.printStackTrace();
            //后期可以增加短信通知
        }
    }

}
