MerchantMissionService.java 6.11 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.request.mission.*;
import cn.com.glsx.merchants.util.Pagination;
import cn.com.glsx.stoassistant.model.request.mission.PlatformMerchantMissionInfoRequest;
import cn.com.glsx.stoassistant.model.request.mission.PlatformMerchantMissionListRequest;
import cn.com.glsx.stoassistant.model.request.mission.PlatformMerchantStaffMissionRequest;
import cn.com.glsx.stoassistant.model.response.mission.PlatformMerchantMissionInfoResponse;
import cn.com.glsx.stoassistant.model.response.mission.PlatformMerchantMissionListResponse;
import cn.com.glsx.stoassistant.model.response.mission.PlatformMerchantStaffMissionDetailResponse;
import cn.com.glsx.stoassistant.remote.PlatformMerchantMissionRemote;
import cn.com.glsx.stoassistant.remote.PlatformMerchantStaffMissionRemote;
import com.rop.AbstractRopRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MerchantMissionService {

    @Autowired
    private PlatformMerchantMissionRemote platformMerchantMissionRemote;

    @Autowired
    private PlatformMerchantStaffMissionRemote platformMerchantStaffMissionRemote;

    public Boolean createMission(CreatedMissionRopRequest createdMissionRopRequest) {
        PlatformMerchantMissionInfoRequest param = ConvertRequest.convertRequest(createdMissionRopRequest, new PlatformMerchantMissionInfoRequest());
        RpcResponse<Boolean> rpcResponse = platformMerchantMissionRemote.createMission(param);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public Boolean updateMission(UpdateMissionRopRequest updateMissionRopRequest) {
        PlatformMerchantMissionInfoRequest param = ConvertRequest.convertRequest(updateMissionRopRequest, new PlatformMerchantMissionInfoRequest());
        RpcResponse<Boolean> rpcResponse = platformMerchantMissionRemote.updateMission(param);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public Boolean updateStatusMission(UpdateStatusMissionRopRequest updateStatusMissionRopRequest) {
        PlatformMerchantMissionInfoRequest param = ConvertRequest.convertRequest(updateStatusMissionRopRequest, new PlatformMerchantMissionInfoRequest());
        RpcResponse<Boolean> rpcResponse = platformMerchantMissionRemote.updateStatusMission(param);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public PlatformMerchantMissionInfoResponse findMissionDeail(MissionDetailRopRequest missionDetailRopRequest) {
        PlatformMerchantMissionInfoRequest param = ConvertRequest.convertRequest(missionDetailRopRequest, new PlatformMerchantMissionInfoRequest());
        RpcResponse<PlatformMerchantMissionInfoResponse> rpcResponse = platformMerchantMissionRemote.findMissionDeail(param);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public Pagination<PlatformMerchantMissionInfoResponse> findMissionList(MissionPageRopRequest missionDetailRopRequest) {
        RpcPagination<PlatformMerchantMissionListRequest> param = ConvertRequest.convertPage(missionDetailRopRequest, new PlatformMerchantMissionListRequest());
        RpcResponse<RpcPagination<PlatformMerchantMissionInfoResponse>> rpcResponse = platformMerchantMissionRemote.findMissionList(param);
        if (rpcResponse.isSuccess()) {
            return ConvertResponse.convertPage(rpcResponse.getResult(), PlatformMerchantMissionInfoResponse.class);
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public Pagination<PlatformMerchantStaffMissionDetailResponse> findStaffMissionPageList(MissionStaffPageRopRequest missionDetailRopRequest) {
        RpcPagination<PlatformMerchantStaffMissionRequest> param = ConvertRequest.convertPage(missionDetailRopRequest, new PlatformMerchantStaffMissionRequest());
        RpcResponse<RpcPagination<PlatformMerchantStaffMissionDetailResponse>> rpcResponse = platformMerchantStaffMissionRemote.findStaffMissionPageList(param);
        if (rpcResponse.isSuccess()) {
            return ConvertResponse.convertPage(rpcResponse.getResult(), PlatformMerchantStaffMissionDetailResponse.class);
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public String getStaffMissionLink(MissionStaffLinkRequest missionStaffLinkRequest) {
        PlatformMerchantStaffMissionRequest param = ConvertRequest.convertRequest(missionStaffLinkRequest, new PlatformMerchantStaffMissionRequest());
        RpcResponse<String> rpcResponse = platformMerchantStaffMissionRemote.getStaffMissionLink(param);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public PlatformMerchantMissionListResponse staticMission(AbstractRopRequest abstractRopRequest) {
        RpcResponse<PlatformMerchantMissionListResponse> rpcResponse = platformMerchantMissionRemote.staticMission();
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }
}