MerchantDictDataService.java 4.51 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.MerchantDictDataRequest;
import cn.com.glsx.merchants.model.response.MerchantDictDataResponse;
import cn.com.glsx.merchants.remote.MerchantDictDataRemote;
import cn.com.glsx.merchants.request.dictdata.*;
import cn.com.glsx.merchants.response.DictDataResponse;
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: TODO
 * @date 2021/7/13 11:02
 */
@Service
@Slf4j
public class MerchantDictDataService {

    @Autowired
    private MerchantDictDataRemote merchantDictDataRemote;

    @Autowired
    private MerchantUserService merchantUserService;

    @SysLog(value = "保存字典数据", action = OperateType.ADD, module = "字典数据模块")
    public void saveDictData(DictDataSaveRequest dictDataSaveRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantDictDataRemote.saveMerchantDictDataRemote(ConvertRequest.convertRequest(dictDataSaveRequest, new MerchantDictDataRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
        }
    }

    @SysLog(value = "更新字典数据", action = OperateType.EDIT, module = "字典数据模块")
    public void updateDictData(DictDataUpdateRequest DictDataUpdateRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantDictDataRemote.updateMerchantDictDataRemote(ConvertRequest.convertRequest(DictDataUpdateRequest, new MerchantDictDataRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
        }
    }

    public Pagination<DictDataResponse> findDictData(DictDataListSearchRequest DictDataListSearchRequest) {
        RpcPagination<MerchantDictDataRequest> merchantDictDataRequestRpcPagination = ConvertRequest.convertPage(DictDataListSearchRequest, new MerchantDictDataRequest());
        MerchantDictDataRequest condition = merchantDictDataRequestRpcPagination.getCondition();
        condition.setDictType(DictDataListSearchRequest.getType());
        condition.setDictLabel(DictDataListSearchRequest.getName());
        merchantDictDataRequestRpcPagination.setCondition(condition);
        RpcResponse<RpcPagination<MerchantDictDataResponse>> merProductByPageRemote = merchantDictDataRemote.findMerchantDictDataRemote(merchantDictDataRequestRpcPagination);
        if (merProductByPageRemote.isSuccess()) {
            return ConvertResponse.convertPage(merProductByPageRemote.getResult(), DictDataResponse.class);
        }
        throw new RpcServiceException(merProductByPageRemote.getException().getErrId(), merProductByPageRemote.getMessage());
    }

    @SysLog(value = "删除字典数据", action = OperateType.DELETE, module = "字典数据模块")
    public void deleteDictData(DictDataDeleteRequest DictDataDeleteRequest) {
        RpcResponse<Boolean> booleanRpcResponse = merchantDictDataRemote.deleteMerchantDictDataRemote(ConvertRequest.convertRequest(DictDataDeleteRequest, new MerchantDictDataRequest()));
        if (booleanRpcResponse.isFailed()) {
            throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
        }
    }

    public List<DictDataResponse> findAllDictData(DictDataSearchRequest dictDataSearchRequest) {
        RpcResponse<List<MerchantDictDataResponse>> merProductByPageRemote = merchantDictDataRemote.findAllRemote(ConvertRequest.convertRequest(dictDataSearchRequest, new MerchantDictDataRequest()));
        if (merProductByPageRemote.isSuccess()) {
            return ConvertResponse.convertList(merProductByPageRemote.getResult(), DictDataResponse.class);
        }
        throw new RpcServiceException(merProductByPageRemote.getException().getErrId(), merProductByPageRemote.getMessage());
    }
}