BatchMessagingService.java 8.58 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.dto.activityreport.ScrmActivityReportLogDTO;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.activityreport.ActivityReportLogSearchRpcRequest;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.batchmessaging.BatchMessagingMerchantRpcRequest;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.batchmessaging.BatchMessagingQueryRpcRequest;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.batchmessaging.BatchMessagingRpcRequest;
import cn.com.glsx.entmicro.model.request.wechatcloudcontrol.batchmessaging.BatchMessagingUserRpcRequest;
import cn.com.glsx.entmicro.model.response.wechatcloudcontrol.batchmessaging.BatchMessagingGroupResponse;
import cn.com.glsx.entmicro.model.response.wechatcloudcontrol.batchmessaging.BatchMessagingMerchantResponse;
import cn.com.glsx.entmicro.model.response.wechatcloudcontrol.batchmessaging.BatchMessagingRecordOfSendResponse;
import cn.com.glsx.entmicro.model.response.wechatcloudcontrol.batchmessaging.BatchMessagingRecordResponse;
import cn.com.glsx.entmicro.remote.BatchMessagingRemote;
import cn.com.glsx.entmicro.request.wechatcloudcontrol.ActivityReportLog.ActivityReportLogSearchRopRequest;
import cn.com.glsx.entmicro.request.wechatcloudcontrol.batchmessaging.*;
import cn.com.glsx.entmicro.response.wechatcloudcontrol.batchmessaging.BatchMessagingMerchantVO;
import cn.com.glsx.entmicro.response.wechatcloudcontrol.batchmessaging.BatchMessagingRecordOfSendVO;
import cn.com.glsx.entmicro.response.wechatcloudcontrol.batchmessaging.BatchMessagingRecordVO;
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.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.entmicro.utils.RopHttpUtil;
import cn.com.glsx.worktool.model.response.ScrmWorktoolGroupResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

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

/**
 * @Description
 * @author chizw
 * @create 2022/9/19 16:14
 * @version ver.1.0.0
 */
@Service
@Slf4j
public class BatchMessagingService {

    @Resource
    private BatchMessagingRemote batchMessagingRemote;

    @Autowired
    private Environment env;

    /**
     * 企微高级群发任务创建
     * @param ropRequest
     * @return
     */
    public Boolean createBatchMessagingTask(BatchMessagingCreateRopRequest ropRequest) {
        BatchMessagingRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new BatchMessagingRpcRequest());
        RpcResponse<Boolean> response = batchMessagingRemote.createBatchMessagingTask(rpcRequest);
        if (response.isSuccess()) {
            return response.getResult();
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 查看预计群发人数
     * @param ropRequest
     * @return
     */
    public Integer getEstimateCustomerCount(BatchMessagingCreateRopRequest ropRequest) {
        BatchMessagingRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new BatchMessagingRpcRequest());
        RpcResponse<Integer> response = batchMessagingRemote.getEstimateCustomerCount(rpcRequest);
        if (response.isSuccess()) {
            return response.getResult();
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 企微高级群发查询创建门店
     * @param ropRequest
     * @return
     */
    public List<BatchMessagingMerchantVO> findBatchMessagingMerchantList(BatchMessagingMerchantRopRequest ropRequest) {
        BatchMessagingMerchantRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new BatchMessagingMerchantRpcRequest());
        RpcResponse<List<BatchMessagingMerchantResponse>> response = batchMessagingRemote.findBatchMessagingMerchantList(rpcRequest);
        if (response.isSuccess()) {
            return ConvertResponse.convertList(response.getResult(), BatchMessagingMerchantVO.class);
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 企微高级群发查询群发记录
     * @param ropRequest
     * @return
     */
    public Pagination<BatchMessagingRecordVO> queryBatchMessaging(BatchMessagingRecordRopRequest ropRequest) {
        BatchMessagingQueryRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new BatchMessagingQueryRpcRequest());
        RpcResponse<RpcPagination<BatchMessagingRecordResponse>> response = batchMessagingRemote.queryBatchMessaging(rpcRequest);
        if (response.isSuccess()) {
            return ConvertResponse.convertPage(response.getResult(), BatchMessagingRecordVO.class);
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 企微高级群发查询群发发送记录
     * @param ropRequest
     * @return
     */
    public Pagination<BatchMessagingRecordOfSendVO> queryBatchMessagingOfSend(BatchMessagingRecordOfSendRopRequest ropRequest) {
        BatchMessagingQueryRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new BatchMessagingQueryRpcRequest());
        RpcResponse<RpcPagination<BatchMessagingRecordOfSendResponse>> response = batchMessagingRemote.queryBatchMessagingOfSend(rpcRequest);
        if (response.isSuccess()) {
            return ConvertResponse.convertPage(response.getResult(), BatchMessagingRecordOfSendVO.class);
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 获取企微群列表
     * @param ropRequest
     * @return
     */
    public List<BatchMessagingGroupResponse> getBatchMessagingGroupList(BatchMessagingUserRopRequest ropRequest) {
        BatchMessagingUserRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new BatchMessagingUserRpcRequest());
        RpcResponse<List<BatchMessagingGroupResponse>> response = batchMessagingRemote.getBatchMessagingGroupList(rpcRequest);
        if (response.isSuccess()) {
            return ConvertResponse.convertList(response.getResult(), BatchMessagingGroupResponse.class);
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 群发记录停止发送
     * @param ropRequest
     * @return
     */
    public Boolean stopBatchMessagingSend(BatchMessagingRecordOfSendRopRequest ropRequest) {
        RpcResponse<Boolean> response = batchMessagingRemote.stopBatchMessagingSend(ropRequest.getMsgId());
        if (response.isSuccess()) {
            return response.getResult();
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    /**
     * 查询喜报战报推送日志分页列表
     * @param ropRequest
     * @return
     */
    public Pagination<ScrmActivityReportLogDTO> getActivityReportLogPage(ActivityReportLogSearchRopRequest ropRequest) {
        ActivityReportLogSearchRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new ActivityReportLogSearchRpcRequest());
        RpcResponse<RpcPagination<ScrmActivityReportLogDTO>> response = batchMessagingRemote.getActivityReportLogPage(rpcRequest);
        if (response.isSuccess()) {
            return ConvertResponse.convertPage(response.getResult(), ScrmActivityReportLogDTO.class);
        }
        throw new RpcServiceException(response.getError(), response.getMessage());
    }

    public RpcResponse<List<ScrmWorktoolGroupResponse>> getNewReportGroupList() {
        // 获取请求url
        String requestUrl = env.getProperty("dj.new.report.group.push.url");
        if (StringUtils.isBlank(requestUrl)) {
            log.error("新版群推送url配置为空");
            return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR, "新版群推送url配置为空");
        }
        log.info("requestUrl:{}", requestUrl);
        try {
            // 获取群列表
            List<ScrmWorktoolGroupResponse> groupList = RopHttpUtil.getGroupList(requestUrl);
            return RpcResponse.success(groupList);
        } catch (Exception e) {
            log.error("获取群列表失败", e);
            return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR, "获取群列表失败: " + e.getMessage());
        }
    }

}