MerchantMenuService.java 6.23 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.BuildMenuRpcParam;
import cn.com.glsx.merchants.model.request.MerchantProductMenuRequest;
import cn.com.glsx.merchants.model.response.MerchantProductMenuResponse;
import cn.com.glsx.merchants.remote.MerchantProductMenuRemote;
import cn.com.glsx.merchants.request.menu.*;
import cn.com.glsx.merchants.response.MenuResponse;
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;

import java.util.List;

/**
 * @author zhouhaibao
 * @version 1.0
 * @description: 商户菜单service
 * @date 2021/7/12 10:33
 */
@Service
@Slf4j
public class MerchantMenuService {

    @Autowired
    private MerchantProductMenuRemote merchantProductMenuRemote;

    public List<MenuResponse> findMerProMenuTreeRemote(MenuSearchRequest menuSearchRequest) {
        RpcResponse<List<MerchantProductMenuResponse>> merProMenuTreeRemote = merchantProductMenuRemote.findMerProMenuTreeRemote(ConvertRequest.convertRequest(menuSearchRequest, new MerchantProductMenuRequest()));
        if (merProMenuTreeRemote.isSuccess()) {
            List<MenuResponse> menuResponseList = ConvertResponse.convertList(merProMenuTreeRemote.getResult(), MenuResponse.class);
            return menuResponseList;
        }
        throw new RpcServiceException(merProMenuTreeRemote.getException().getErrId(),merProMenuTreeRemote.getMessage());
    }

    @SysLog(value = "保存菜单", action = OperateType.ADD, module = "菜单模块")
    public void saveMerchantProductMenuRemote(MenuSaveRequest menuSaveRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductMenuRemote.saveMerchantProductMenuRemote(ConvertRequest.convertRequest(menuSaveRequest, new MerchantProductMenuRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(),booleanRpcResponse.getMessage());
        }
    }

    public Pagination<MenuResponse> findMerProMenuByPageRemote(MenuListSearchRequest menuListSearchRequest) {
        RpcResponse<RpcPagination<MerchantProductMenuResponse>> merProductByPageRemote = merchantProductMenuRemote.findMerProMenuByPageRemote(ConvertRequest.convertPage(menuListSearchRequest, new MerchantProductMenuRequest()));
        if (merProductByPageRemote.isSuccess()) {
            return ConvertResponse.convertPage(merProductByPageRemote.getResult(), MenuResponse.class);
        }
        throw new RpcServiceException(merProductByPageRemote.getException().getErrId(),merProductByPageRemote.getMessage());
    }

    @SysLog(value = "更新菜单", action = OperateType.EDIT, module = "菜单模块")
    public void updateMerchantProductMenuRemote(MenuUpdateRequest menuUpdateRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductMenuRemote.updateMerchantProductMenuRemote(ConvertRequest.convertRequest(menuUpdateRequest, new MerchantProductMenuRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(),booleanRpcResponse.getMessage());
        }
    }

    @SysLog(value = "删除菜单", action = OperateType.DELETE, module = "菜单模块")
    public void deleteMerchantProductMenuRemote(MenuDeleteRequest menuDeleteRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductMenuRemote.deleteMerchantProductMenuRemote(ConvertRequest.convertRequest(menuDeleteRequest, new MerchantProductMenuRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(),booleanRpcResponse.getMessage());
        }
    }
    @Deprecated
    public void buildMenuAndFunction(BuildMenuParam param) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductMenuRemote.buildMenuAndFunction(ConvertRequest.convertRequest(param, new BuildMenuRpcParam()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(),booleanRpcResponse.getMessage());
        }
    }

    public void rebuildVersionMenu(BuildMenuParam param) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductMenuRemote.rebuildVersionMenu(ConvertRequest.convertRequest(param, new BuildMenuRpcParam()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(),booleanRpcResponse.getMessage());
        }
    }

    public void buildVersionMenuFunctionNew(BuildMenuParam param) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductMenuRemote.buildVersionMenuFunctionNew(ConvertRequest.convertRequest(param, new BuildMenuRpcParam()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(),booleanRpcResponse.getMessage());
        }
    }

    public void updateVersionMenuAndFunction(BuildMenuParam param) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductMenuRemote.updateVersionMenuAndFunction(ConvertRequest.convertRequest(param, new BuildMenuRpcParam()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(),booleanRpcResponse.getMessage());
        }
    }

    public void deleteVersionMenuAndFunction(BuildMenuParam param) {
        RpcResponse<Boolean> booleanRpcResponse = merchantProductMenuRemote.deleteVersionMenuAndFunction(ConvertRequest.convertRequest(param, new BuildMenuRpcParam()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(),booleanRpcResponse.getMessage());
        }
    }
}