MchAppService.java 2.0 KB
Newer Older
terrfly's avatar
terrfly 已提交
1 2 3
package com.jeequan.jeepay.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4 5
import com.jeequan.jeepay.core.constants.ApiCodeEnum;
import com.jeequan.jeepay.core.constants.CS;
terrfly's avatar
terrfly 已提交
6
import com.jeequan.jeepay.core.entity.MchApp;
7 8 9 10
import com.jeequan.jeepay.core.entity.MchPayPassage;
import com.jeequan.jeepay.core.entity.PayInterfaceConfig;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.core.exception.BizException;
terrfly's avatar
terrfly 已提交
11
import com.jeequan.jeepay.service.mapper.MchAppMapper;
12
import org.springframework.beans.factory.annotation.Autowired;
terrfly's avatar
terrfly 已提交
13
import org.springframework.stereotype.Service;
14
import org.springframework.transaction.annotation.Transactional;
terrfly's avatar
terrfly 已提交
15 16 17 18 19 20 21 22 23 24 25 26

/**
 * <p>
 * 商户应用表 服务实现类
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2021-06-15
 */
@Service
public class MchAppService extends ServiceImpl<MchAppMapper, MchApp> {

27 28 29 30 31 32 33 34 35 36 37 38
    @Autowired private PayOrderService payOrderService;
    @Autowired private MchPayPassageService mchPayPassageService;
    @Autowired private PayInterfaceConfigService payInterfaceConfigService;

    @Transactional(rollbackFor = Exception.class)
    public void removeByAppId(String appId) {

        // 1.查看当前应用是否存在交易数据
        int payCount = payOrderService.count(PayOrder.gw().eq(PayOrder::getAppId, appId));
        if (payCount > 0) throw new BizException("该应用已存在交易数据,不可删除");

        // 2.删除应用关联的支付通道
39
        mchPayPassageService.remove(MchPayPassage.gw().eq(MchPayPassage::getAppId, appId));
40 41

        // 3.删除应用配置的支付参数
42
        payInterfaceConfigService.remove(PayInterfaceConfig.gw()
43 44 45 46 47
                .eq(PayInterfaceConfig::getInfoId, appId)
                .eq(PayInterfaceConfig::getInfoType, CS.INFO_TYPE_MCH_APP)
        );

        // 4.删除当前应用
48
        if (!removeById(appId)) {
49 50 51
            throw new BizException(ApiCodeEnum.SYS_OPERATION_FAIL_DELETE);
        }
    }
terrfly's avatar
terrfly 已提交
52
}