MerchantLogService.java 3.2 KB
package cn.com.glsx.merchants.service;

import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.convert.ConvertRequest;
import cn.com.glsx.merchants.convert.ConvertResponse;
import cn.com.glsx.merchants.model.request.MerchantLogRequest;
import cn.com.glsx.merchants.model.response.MerchantLogResponse;
import cn.com.glsx.merchants.remote.MerchantLogRemote;
import cn.com.glsx.merchants.request.log.LogRequest;
import cn.com.glsx.merchants.request.log.LogSearchRequest;
import cn.com.glsx.merchants.request.log.MerchantAndStaffLogRopRequest;
import cn.com.glsx.merchants.response.LogResponse;
import cn.com.glsx.merchants.util.Pagination;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhouhaibao
 * @version 1.0
 * @description: 日志服务
 * @date 2021/7/14 16:27
 */
@Service
@Slf4j
public class MerchantLogService {

    @Autowired
    private MerchantLogRemote merchantLogRemote;

    public MerchantLogResponse saveMerchantLog(LogRequest logRequest) {
        RpcResponse<MerchantLogResponse> booleanRpcResponse = merchantLogRemote.saveMerchantLogRemote(ConvertRequest.convertRequest(logRequest, new MerchantLogRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
        } else {
            return booleanRpcResponse.getResult();
        }
    }

    public void updateMerchantLog(LogRequest logRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantLogRemote.updateMerchantLogRemote(ConvertRequest.convertRequest(logRequest, new MerchantLogRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
        }
    }

    public Pagination<LogResponse> findLog(LogSearchRequest logSearchRequest) {
        RpcResponse<RpcPagination<MerchantLogResponse>> merProductByPageRemote = merchantLogRemote.findMerchantLogRemote(ConvertRequest.convertPage(logSearchRequest, new MerchantLogRequest()));
        if (merProductByPageRemote.isSuccess()) {
            return ConvertResponse.convertPage(merProductByPageRemote.getResult(), LogResponse.class);
        }
        throw new RpcServiceException(merProductByPageRemote.getException().getErrId(), merProductByPageRemote.getMessage());
    }

    public Pagination<LogResponse> findMerchantAndStaffLog(MerchantAndStaffLogRopRequest ropRequest) {
        RpcResponse<RpcPagination<MerchantLogResponse>> merProductByPageRemote = merchantLogRemote.findMerchantLogForScrm(ConvertRequest.convertPage(ropRequest, new MerchantLogRequest()));
        if (merProductByPageRemote.isSuccess()) {
            return ConvertResponse.convertPage(merProductByPageRemote.getResult(), LogResponse.class);
        }
        throw new RpcServiceException(merProductByPageRemote.getException().getErrId(), merProductByPageRemote.getMessage());
    }
}