MerchantFunctionService.java 4.1 KB
package cn.com.glsx.merchants.service;/**
 * @author zhouhaibao
 * @date 2021/7/12
 */

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.MerchantProductFunctionRequest;
import cn.com.glsx.merchants.model.response.MerchantProductFunctionResponse;
import cn.com.glsx.merchants.remote.MerchantProductFunctionRemote;
import cn.com.glsx.merchants.request.function.FunctionDeleteRequest;
import cn.com.glsx.merchants.request.function.FunctionListSearchRequest;
import cn.com.glsx.merchants.request.function.FunctionSaveRequest;
import cn.com.glsx.merchants.request.function.FunctionUpdateRequest;
import cn.com.glsx.merchants.response.FunctionResponse;
import cn.com.glsx.merchants.util.Pagination;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.common.enums.OperateType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhouhaibao
 * @version 1.0
 * @description: TODO
 * @date 2021/7/12 11:40
 */
@Service
@Slf4j
public class MerchantFunctionService {

    @Autowired
    private MerchantProductFunctionRemote merchantProductFunctionRemote;

    @SysLog(value = "保存功能", action = OperateType.ADD, module = "功能模块")
    public void saveMerchantFunction(FunctionSaveRequest functionSaveRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductFunctionRemote.saveMerchantProductFunctionRemote(ConvertRequest.convertRequest(functionSaveRequest, new MerchantProductFunctionRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
        }
    }

    public static void main(String[] args) {
        FunctionSaveRequest functionSaveRequest = new FunctionSaveRequest();
        functionSaveRequest.setProductId(123);
        MerchantProductFunctionRequest merchantProductFunctionRequest = ConvertRequest.convertRequest(functionSaveRequest, new MerchantProductFunctionRequest());
        System.out.println(merchantProductFunctionRequest);
    }

    @SysLog(value = "修改功能", action = OperateType.EDIT, module = "功能模块")
    public void updateMerchantFunction(FunctionUpdateRequest functionUpdateRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductFunctionRemote.updateMerchantProductFunctionRemote(ConvertRequest.convertRequest(functionUpdateRequest, new MerchantProductFunctionRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
        }
    }

    public Pagination<FunctionResponse> findMerchantFunction(FunctionListSearchRequest functionListSearchRequest) {
        RpcResponse<RpcPagination<MerchantProductFunctionResponse>> merProductByPageRemote = merchantProductFunctionRemote.findMerProFunctionByPageRemote(ConvertRequest.convertPage(functionListSearchRequest, new MerchantProductFunctionRequest()));
        if (merProductByPageRemote.isSuccess()) {
            return ConvertResponse.convertPage(merProductByPageRemote.getResult(), FunctionResponse.class);
        }
        throw new RpcServiceException(merProductByPageRemote.getException().getErrId(), merProductByPageRemote.getMessage());
    }

    public void deleteMerchantFunction(FunctionDeleteRequest functionDeleteRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductFunctionRemote.deleteMerchantProductFunctionRemote(ConvertRequest.convertRequest(functionDeleteRequest, new MerchantProductFunctionRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
        }
    }
}