LiveCodeController.java 3.51 KB
package cn.com.glsx.stoassistant.controller;

import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.stoassistant.request.GroupAllocRequest;
import cn.com.glsx.stoassistant.request.LiveCodeRequest;
import cn.com.glsx.stoassistant.response.GroupAllocResponse;
import cn.com.glsx.stoassistant.response.LiveCodeResponse;
import cn.com.glsx.stoassistant.service.LiveCodeService;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 活码管理
 */
@Slf4j
@Api("活码管理")
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
//@RestController
public class LiveCodeController {

    @Autowired
    private LiveCodeService liveCodeService;

    /**
     * 获取群活码(车主扫码分配真实企微群)
     */
    @ServiceMethod(method = "scrm.api.stoassistant.livecode.get", needInSession = NeedInSessionType.YES)
    @ApiOperation("获取群活码")
//    @PostMapping("/scrm.api.stoassistant.livecode.get/1.0.0")
    public RopResponse<LiveCodeResponse> getLiveCode(LiveCodeRequest request) {
        try {
            if (request == null || request.getReportUuidId() == null || request.getReportUuidId().trim().isEmpty()) {
                return RopResponse.error("AI收车报告唯一ID不能为空");
            }

            LiveCodeResponse response = liveCodeService.getLiveCode(request);
            return RopResponse.success(response);
        } catch (Exception e) {
            log.error("获取群活码失败", e);
            return RopResponse.error(e.getMessage());
        }
    }

    /**
     * 扫码分配空闲企微群
     */
    @ServiceMethod(method = "scrm.api.stoassistant.livecode.allocate", needInSession = NeedInSessionType.YES)
    @ApiOperation("扫码分配空闲企微群")
//    @PostMapping("/scrm.api.stoassistant.livecode.allocate/1.0.0")
    public RopResponse<GroupAllocResponse> allocateGroup(GroupAllocRequest request) {
        try {
            if (request == null) {
                return RopResponse.error("请求参数不能为空");
            }
            if (request.getLiveCode() == null || request.getLiveCode().trim().isEmpty()) {
                return RopResponse.error("活码编码不能为空");
            }
            if (request.getOpenid() == null || request.getOpenid().trim().isEmpty()) {
                return RopResponse.error("微信openid不能为空");
            }
            if (request.getSignature() == null || request.getSignature().trim().isEmpty()) {
                return RopResponse.error("签名不能为空");
            }
            if (request.getNonce() == null || request.getNonce().trim().isEmpty()) {
                return RopResponse.error("随机字符串不能为空");
            }
            if (request.getSaUserId() == null || request.getSaUserId().trim().isEmpty()) {
                return RopResponse.error("销售顾问ID不能为空");
            }

            GroupAllocResponse response = liveCodeService.allocateGroup(request);
            return RopResponse.success(response);
        } catch (Exception e) {
            log.error("扫码分配群失败", e);
            return RopResponse.error(e.getMessage());
        }
    }
}