BatchMomentService.java 4.67 KB
package cn.com.glsx.entmicro.service.wechatcloudcontrol;

import cn.com.glsx.entmicro.convert.ConvertRequest;
import cn.com.glsx.entmicro.convert.ConvertResponse;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.batchmoment.AttachmentRpcRequest;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.batchmoment.BatchMomentCreateRpcRequest;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.batchmoment.BatchMomentQueryRpcRequest;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.batchmoment.BatchMomentStaffRecordQueryRpcRequest;
import cn.com.glsx.entmicro.model.response.wechatcloudcontrol.batchmoment.BatchMomentRpcResponse;
import cn.com.glsx.entmicro.model.response.wechatcloudcontrol.batchmoment.BatchMomentStaffRecordRpcResponse;
import cn.com.glsx.entmicro.remote.BatchMomentRemote;
import cn.com.glsx.entmicro.request.wechatcloudcontrol.batchmoment.BatchMomentCreateRopRequest;
import cn.com.glsx.entmicro.request.wechatcloudcontrol.batchmoment.BatchMomentQueryRopRequest;
import cn.com.glsx.entmicro.request.wechatcloudcontrol.batchmoment.BatchMomentStaffRecordQueryRopRequest;
import cn.com.glsx.entmicro.response.wechatcloudcontrol.batchmoment.BatchMomentRopResponse;
import cn.com.glsx.entmicro.response.wechatcloudcontrol.batchmoment.BatchMomentStaffRecordRopResponse;
import cn.com.glsx.entmicro.utils.Pagination;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author yelq
 * @Version 1.0
 * @Description: 朋友圈群发
 * @Date 2022/9/16 17:35
 */
@Service
@Slf4j
public class BatchMomentService {

    @Autowired
    private BatchMomentRemote batchMomentRemote;

    /**
     * 朋友圈群发任务创建
     *
     * @param ropRequest
     * @return
     */
    public Boolean batchMomentSave(BatchMomentCreateRopRequest ropRequest) {
        BatchMomentCreateRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new BatchMomentCreateRpcRequest());
        if (ropRequest.getAttachmentList() != null && !ropRequest.getAttachmentList().isEmpty()) {
            rpcRequest.setAttachmentList(ConvertRequest.convertListRequest(ropRequest.getAttachmentList(), AttachmentRpcRequest.class));
        }
        RpcResponse<Boolean> response = batchMomentRemote.batchMomentSave(rpcRequest);
        if (response.isSuccess()) {
            return response.getResult();
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 朋友圈群发任务多条件分页查询
     *
     * @param request
     * @return
     */
    public Pagination<BatchMomentRopResponse> batchMomentConditionPage(BatchMomentQueryRopRequest request) {
        RpcPagination<BatchMomentQueryRpcRequest> pagination = ConvertRequest.convertPage(request, new BatchMomentQueryRpcRequest());
        RpcResponse<RpcPagination<BatchMomentRpcResponse>> response = batchMomentRemote.batchMomentConditionPage(pagination);
        if (response.isSuccess()) {
            Pagination<BatchMomentRopResponse> res = ConvertResponse.convertPage(response.getResult(), BatchMomentRopResponse.class);
            return res;
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 发送记录分页查询
     *
     * @param request
     * @return
     */
    public Pagination<BatchMomentStaffRecordRopResponse> batchMomentStaffRecordPage(BatchMomentStaffRecordQueryRopRequest request) {
        RpcPagination<BatchMomentStaffRecordQueryRpcRequest> pagination = ConvertRequest.convertPage(request, new BatchMomentStaffRecordQueryRpcRequest());
        RpcResponse<RpcPagination<BatchMomentStaffRecordRpcResponse>> response = batchMomentRemote.batchMomentStaffRecordPage(pagination);
        if (response.isSuccess()) {
            Pagination<BatchMomentStaffRecordRopResponse> res = ConvertResponse.convertPage(response.getResult(), BatchMomentStaffRecordRopResponse.class);
            return res;
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 发送记录分页查询
     *
     * @param request
     * @return
     */
    public Boolean stopBatchMomentSend(BatchMomentStaffRecordQueryRopRequest request) {
        RpcResponse<Boolean> response = batchMomentRemote.stopBatchMomentSend(request.getId());
        if (response.isSuccess()) {
            return response.getResult();
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }
}