ActivityDetectionServiceImpl.java 2.45 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.dto.detection.GetCheckHistoryDTO;
import com.subsidy.dto.detection.VerifyDTO;
import com.subsidy.model.ActivityDetectionDO;
import com.subsidy.mapper.ActivityDetectionMapper;
import com.subsidy.service.ActivityDetectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ActivityDetectionUtils;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.activity.GetCheckHistoryVO;
import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultResponse;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 活跃度检测表 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2022-07-13
 */
@Service
public class ActivityDetectionServiceImpl extends ServiceImpl<ActivityDetectionMapper, ActivityDetectionDO> implements ActivityDetectionService {

    public String verify(VerifyDTO verifyDTO, HttpServletRequest request){

        try{
            DescribeCaptchaResultResponse resp = ActivityDetectionUtils.activityDetection(request,verifyDTO.getRandStr());
            // 输出json格式的字符串回包
            ActivityDetectionDO activityDetectionDO = new ActivityDetectionDO();
            activityDetectionDO.setClassId(verifyDTO.getClassId());
            activityDetectionDO.setMemberId(verifyDTO.getMemberId());
            activityDetectionDO.setRequestId(resp.getRequestId());
            if (resp.getCaptchaCode()==1){
                //成功
                activityDetectionDO.setStatus(1);
                this.baseMapper.insert(activityDetectionDO);
                return ConstantUtils.SUCCESS_VERIFY;
            }else {
                //失败
                activityDetectionDO.setStatus(0);
                this.baseMapper.insert(activityDetectionDO);
                return ConstantUtils.FAIL_VERIFY;
            }
        } catch (Exception e) {
//            System.out.println(e.toString());
        }
        return ConstantUtils.SUCCESS_VERIFY;
    }

    public IPage<GetCheckHistoryVO> getCheckHistory(GetCheckHistoryDTO getCheckHistoryDTO){
        Page pager = new Page(getCheckHistoryDTO.getPageNum(), getCheckHistoryDTO.getPageSize());
        return this.baseMapper.getCheckHistory(pager,getCheckHistoryDTO.getClassId(),getCheckHistoryDTO.getMemberId());
    }

}