MerchantWithdrawalPointsConfigService.java 5.87 KB
package cn.com.glsx.stoassistant.service.withdrawal;

import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import cn.com.glsx.scrm.system.dto.LoginUserDTO;
import cn.com.glsx.stoassistant.convert.ConvertRequest;
import cn.com.glsx.stoassistant.convert.MerchantWithdrawalPointsConfigConverter;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantWithdrawalPointsConfigCheckRpcRequest;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantWithdrawalPointsConfigDeleteRpcRequest;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantWithdrawalPointsConfigSaveRpcRequest;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantWithdrawalPointsConfigSearchRpcRequest;
import cn.com.glsx.stoassistant.model.response.withdrawal.MerchantWithdrawalPointsConfigResponse;
import cn.com.glsx.stoassistant.remote.MerchantWithdrawalPointsConfigRemote;
import cn.com.glsx.stoassistant.request.withdrawal.MerchantWithdrawalPointsConfigCheckRopRequest;
import cn.com.glsx.stoassistant.request.withdrawal.MerchantWithdrawalPointsConfigDeleteRopRequest;
import cn.com.glsx.stoassistant.request.withdrawal.MerchantWithdrawalPointsConfigSaveRopRequest;
import cn.com.glsx.stoassistant.request.withdrawal.MerchantWithdrawalPointsConfigSearchRopRequest;
import cn.com.glsx.stoassistant.utils.Pagination;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.rop.util.RopThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author yelq
 * @Version 1.0
 * @Description: 提现白名单
 * @Date 2023/8/10 17:48
 */
@Slf4j
@Service
public class MerchantWithdrawalPointsConfigService {

    @Autowired
    private MerchantWithdrawalPointsConfigRemote merchantWithdrawalPointsConfigRemote;
    public RpcPagination<MerchantWithdrawalPointsConfigResponse> withdrawalOfPointsPage(MerchantWithdrawalPointsConfigSearchRopRequest request) {
        RpcPagination<MerchantWithdrawalPointsConfigSearchRpcRequest> requestDTO = ConvertRequest.convertPage(request, new MerchantWithdrawalPointsConfigSearchRpcRequest());
        RpcResponse<RpcPagination<MerchantWithdrawalPointsConfigResponse>> rpcResponse = merchantWithdrawalPointsConfigRemote.withdrawalOfPointsPage(requestDTO);
        if (rpcResponse.isSuccess()){
            return rpcResponse.getResult();
        }
        log.error("白名单列表查询失败:{}", JSON.toJSONString(rpcResponse));
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
    }

    public MerchantWithdrawalPointsConfigResponse withdrawalOfPointsMerchantCheck(MerchantWithdrawalPointsConfigCheckRopRequest request) {
        MerchantWithdrawalPointsConfigCheckRpcRequest requestDTO = ConvertRequest.convertRequest(request, new MerchantWithdrawalPointsConfigCheckRpcRequest());
        if (requestDTO.getSelectMerchantId()==null){
            //未传参默认拿登录参数中的门店号
            requestDTO.setSelectMerchantId(request.getMerchantId());
        }
        RpcResponse<MerchantWithdrawalPointsConfigResponse> response = merchantWithdrawalPointsConfigRemote.withdrawalOfPointsMerchantCheck(requestDTO);
        if (response.isSuccess()){
            return response.getResult();
        }
        log.error("积分提现门店白名单配置校验失败:{}", JSON.toJSONString(response));
        throw new RpcServiceException(response.getException().getErrId(), response.getException().getMessage());
    }

    public Boolean withdrawalOfPointsMerchantListSave(MerchantWithdrawalPointsConfigSaveRopRequest request) {
        MerchantWithdrawalPointsConfigSaveRpcRequest requestDTO = MerchantWithdrawalPointsConfigConverter.INSTANCE.toMerchantWithdrawalPointsConfigSaveRpcRequest(request);
        try {
            if (request.getCreatedBy()==null){
                //运营端登录配置,获取登录信息
                LoginUserDTO loginUser = RopThreadLocal.getLoginUser(LoginUserDTO.class);
                requestDTO.setCreatedBy(loginUser.getId());
            }
        } catch (Exception e) {
            log.info("获取登录信息失败:",e);
        }
        RpcResponse<Boolean> response = merchantWithdrawalPointsConfigRemote.withdrawalOfPointsMerchantListSave(requestDTO);
        if (response.isSuccess()){
            return response.getResult();
        }
        log.error("积分提现门店白名单配置失败:{}", JSON.toJSONString(response));
        throw new RpcServiceException(response.getException().getErrId(), response.getException().getMessage());
    }

    public Boolean withdrawalOfPointsMerchantListDelete(MerchantWithdrawalPointsConfigDeleteRopRequest request) {
        MerchantWithdrawalPointsConfigDeleteRpcRequest requestDTO = MerchantWithdrawalPointsConfigConverter.INSTANCE.toMerchantWithdrawalPointsConfigDeleteRpcRequest(request);
        try {
            if (request.getCreatedBy()==null){
                //运营端登录配置,获取登录信息
                LoginUserDTO loginUser = RopThreadLocal.getLoginUser(LoginUserDTO.class);
                requestDTO.setCreatedBy(loginUser.getId());
            }
        } catch (Exception e) {
            log.info("获取登录信息失败:",e);
        }
        RpcResponse<Boolean> response = merchantWithdrawalPointsConfigRemote.withdrawalOfPointsMerchantListDelete(requestDTO);
        if (response.isSuccess()){
            return response.getResult();
        }
        log.error("积分提现门店白名单删除失败:{}", JSON.toJSONString(response));
        throw new RpcServiceException(response.getException().getErrId(), response.getException().getMessage());
    }
}