PaymentController.java 8.06 KB
package cn.com.glsx.entmicro.controller.payment;

import cn.com.glsx.entmicro.request.payment.*;
import cn.com.glsx.entmicro.service.payment.PaymentService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.platform.payment.dto.response.CreatePaymentResponseDTO;
import cn.com.glsx.platform.payment.dto.response.CreateTradeResponseDTO;
import cn.com.glsx.platform.payment.dto.response.PaymentPageResponseDTO;
import cn.com.glsx.platform.payment.model.PaymentAppInfo;
import cn.com.glsx.scrm.proxy.model.merchant.MerchantRopResponse;
import com.rop.AbstractRopRequest;
import com.rop.annotation.IgnoreSignType;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.oreframework.boot.autoconfigure.rop.metadata.RopProperty;
import org.oreframework.boot.autoconfigure.rop.util.RopClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;
import java.util.List;

/**
 * @author fanfr
 * @Description: 支付配置
 * @date 2022/12/02 13:57
 */
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.NO)
@Api("支付配置接口")
@Slf4j
public class PaymentController {


    @Autowired
    private PaymentService paymentService;
    /**
     * 上传证书文件
     * @param request
     * @return
     */
    @ServiceMethod(method = "entmicro.api.payment.uploadCert", needInSession = NeedInSessionType.YES, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("上传证书文件")
    public RopResponse<String> uploadCert( UploadCertFileRequest request) {
        try {
            String url = paymentService.uploadCert(request);
            return RopResponse.success(url);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__uploadCert__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    @ServiceMethod(method = "entmicro.api.payment.createPayment", needInSession = NeedInSessionType.YES, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("创建支付账号")
    public RopResponse<HashMap<String, CreatePaymentResponseDTO>> createPayment(CreatePaymentRequest request) {
        try {
            HashMap<String, CreatePaymentResponseDTO> response = paymentService.createPayment(request);
            return RopResponse.success(response);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__createPayment__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    @ServiceMethod(method = "entmicro.api.payment.pageListPayment", needInSession = NeedInSessionType.YES, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("支付账号列表分页查询")
    public RopResponse<RpcPagination<PaymentPageResponseDTO>> pageListPayment(PaymentQueryRequest request) {
        try {
            RpcPagination<PaymentPageResponseDTO> response = paymentService.pageListPayment(request);
            return RopResponse.success(response);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__createPayment__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    @ServiceMethod(method = "entmicro.api.payment.deleteById", needInSession = NeedInSessionType.YES, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("删除支付账号")
    public RopResponse<Boolean> deleteById(PaymentQueryRequest request) {
        try {
            Boolean aBoolean = paymentService.deleteById(request);
            return RopResponse.success(aBoolean);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__createPayment__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    @ServiceMethod(method = "entmicro.api.payment.createWeappQrcode", needInSession = NeedInSessionType.YES, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("生成小程序码")
    public RopResponse<String> createWeappQrcode(WeappQrcodeRequest request) {
        log.info("createWeappQrcode :{}", request);
        try {
            String url = paymentService.createWeappQrcode(request);
            return RopResponse.success(url);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__createWeappQrcode__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    @ServiceMethod(method = "entmicro.api.payment.getSceneById", needInSession = NeedInSessionType.NO, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("获取小程序码参数")
    public RopResponse<String> getSceneById(SceneRequest request) {
        log.info("getSceneById :{}", request);
        try {
            String scene = paymentService.getSceneById(request);
            return RopResponse.success(scene);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__getSceneById__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    @ServiceMethod(method = "entmicro.api.payment.createBizQrCode", needInSession = NeedInSessionType.YES, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("生成公众号码")
    public RopResponse<String> createBizQrCode(BizQrCodeReqeust request) {
        log.info("createBizQrcode :{}", request);
        String bizQrCode = paymentService.createBizQrCode(request);
        if (StringUtils.isNotBlank(bizQrCode)) {
            return RopResponse.success(bizQrCode);
        }
        return RopResponse.error(DefaultErrorEnum.SERVICE_ERROR);

    }

    @ServiceMethod(method = "entmicro.api.payment.createTrade", needInSession = NeedInSessionType.NO, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("创建交易订单")
    public RopResponse<CreateTradeResponseDTO> createTrade(CreateTradeRequest request) {
        try {
            CreateTradeResponseDTO trade = paymentService.createTrade(request);
            return RopResponse.success(trade);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__createTrade__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    @ServiceMethod(method = "entmicro.api.payment.listMerchant", needInSession = NeedInSessionType.YES, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("查询商户列表")
    public RopResponse<List<MerchantRopResponse>> listMerchant(MerchantPageRequest request) {
        try {
            List<MerchantRopResponse> response = paymentService.listMerchant(request);
            return RopResponse.success(response);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__listMerchant__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    @ServiceMethod(method = "entmicro.api.payment.listAppInfo", needInSession = NeedInSessionType.NO, ignoreSign = IgnoreSignType.YES)
    @ApiOperation("查询App列表")
    public RopResponse<List<PaymentAppInfo>> listAppInfo(AbstractRopRequest request) {
        try {
            List<PaymentAppInfo> response = paymentService.listAppInfo();
            return RopResponse.success(response);
        } catch (RpcServiceException e) {
            log.info("=======PaymentController__invoke__listAppInfo__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }



}