MerchantRoleService.java 4.72 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.MerchantRoleRequest;
import cn.com.glsx.merchants.model.response.MerchantRoleResponse;
import cn.com.glsx.merchants.remote.MerchantRoleRemote;
import cn.com.glsx.merchants.request.role.RoleDeleteRequest;
import cn.com.glsx.merchants.request.role.RoleListSearchRequest;
import cn.com.glsx.merchants.request.role.RoleInsertRequest;
import cn.com.glsx.merchants.request.role.RoleUpdateRequest;
import cn.com.glsx.merchants.util.Pagination;
import com.github.dozermapper.core.Mapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhouhaibao
 * @version 1.0
 * @description: 角色管理service
 * @date 2021/7/12 17:00
 */
@Slf4j
@Service
public class MerchantRoleService {

    @Autowired
    private Mapper dozerMapper;

    @Resource
    private MerchantRoleRemote roleRemote;

    /**
     * id获取角色管理详情
     *
     * @param id
     * @return
     */
    public MerchantRoleResponse getById(Integer id) {
        RpcResponse<MerchantRoleResponse> response = roleRemote.getByIdRemote(id);
        if(response.isSuccess()){
            return response.getResult();
        }
        throw new RpcServiceException(response.getException().getErrId(),response.getMessage());
    }

    /**
     * 获取角色管理分页数据
     *
     * @param request
     * @return
     */
    public Pagination<MerchantRoleResponse> getRolePage(RoleListSearchRequest request) {
        RpcPagination<MerchantRoleRequest> pagination =
                ConvertRequest.convertPage(request, new MerchantRoleRequest());
        RpcResponse<RpcPagination<MerchantRoleResponse>> response =
                roleRemote.getRolePageRemote(pagination);
        if(response.isSuccess()){
            return ConvertResponse.convertPage(response.getResult(), MerchantRoleResponse.class);
        }
        throw new RpcServiceException(response.getException().getErrId(),response.getMessage());
    }

    /**
     * 获取账户类型数据列表
     *
     * @param request
     * @return
     */
    public List<MerchantRoleResponse> getRoleList(RoleListSearchRequest request) {
        MerchantRoleRequest typeRequest = new MerchantRoleRequest();
        typeRequest.setMerchantId(request.getMerchantId());
        typeRequest.setRoleName(request.getRoleName());
        RpcResponse<List<MerchantRoleResponse>> response =
                roleRemote.getRoleListRemote(typeRequest);
        if(response.isSuccess()){
            return response.getResult();
        }
        throw new RpcServiceException(response.getException().getErrId(),response.getMessage());
    }

    /**
     * id删除角色管理
     *
     * @param request
     * @return
     */
    public Boolean delete(RoleDeleteRequest request) {
        MerchantRoleRequest typeRequest = new MerchantRoleRequest();
        dozerMapper.map(request, typeRequest);
        RpcResponse<Boolean> response = roleRemote.deleteRemote(typeRequest);
        if(response.isSuccess()){
            return response.getResult();
        }
        throw new RpcServiceException(response.getException().getErrId(),response.getMessage());
    }

    /**
     * 新增角色管理数据
     *
     * @param request
     * @return
     */
    public Boolean insert(RoleInsertRequest request) {
        MerchantRoleRequest typeRequest = new MerchantRoleRequest();
        dozerMapper.map(request, typeRequest);
        RpcResponse<Boolean> response = roleRemote.insertRemote(typeRequest);
        if(response.isSuccess()){
            return response.getResult();
        }
        throw new RpcServiceException(response.getException().getErrId(),response.getMessage());
    }

    /**
     * 更新角色管理数据
     *
     * @param request
     * @return
     */
    public Boolean update(RoleUpdateRequest request) {
        MerchantRoleRequest typeRequest = new MerchantRoleRequest();
        dozerMapper.map(request, typeRequest);
        RpcResponse<Boolean> response = roleRemote.updateRemote(typeRequest);
        if(response.isSuccess()){
            return response.getResult();
        }
        throw new RpcServiceException(response.getException().getErrId(),response.getMessage());
    }


}