CommentsJob.java 4.19 KB
package com.cnlive.shenhe.job;

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Component
public class CommentsJob {
    private static Logger logger = LoggerFactory.getLogger(CommentsJob.class);
    @Autowired
    SitesServiceImpl sitesService;
    @Autowired
    AuditPass Pass;
    @Autowired
    CommentsServiceImpl commentsService;

    @Autowired
    UsersServiceImpl usersService;


    @Scheduled(fixedRate = 60 * 1000)
    public void updateComments() {

        //遍历免审的spid去更改状态值
        ShyComments shyComments = new ShyComments();
            shyComments.setShenhe_type(CommonConst.AUDIT_TYPE_FREE);// 审核类型为免审
            shyComments.setState(CommonConst.AUDIT_INTT);
            List<ShyComments> commentsList = commentsService.findshyComments(shyComments);
            if (commentsList.size() > 0) {
                for (ShyComments comments : commentsList) {
                	commentsService.updateState(comments.getId().toString(), CommonConst.AUDIT_SUCCESS, "","白名单","白名单通过");
//                    //封装json数据传参进行回调
//                    JSONObject json1 = new JSONObject();
//                    json1.put("activity_id", comments.getActivity_id());
//                    json1.put("state", 3);
//                    json1.put("attr_tags", "");
//                    json1.put("msg", "白名单通过");
//                    JSONObject result = new JSONObject();
//                    try {
//                        result = Pass.commentPass(json1, comments.getCallback());
//                        Integer errorCode = result.getInteger("errorCode");
//                        if (0 == errorCode) {
//                            int i = commentsService.updateComment(comments.getId(), CommonConst.AUDIT_SUCCESS, json1.getString("msg"));
//                            if (i != 1) {
//                                logger.error("评论审核回调失败,activity_id:{},errorCode:{},errorMessage:{}", comments.getActivity_id(), errorCode, result.getString("errorMessage"));
//                            }
//                        } else {
//                            commentsService.updateComment(comments.getId(), CommonConst.AUDIT_CALLBACK_FAIL, "白名单回调失败");
//                            logger.error("评论审核回调失败,activity_id:{},errorCode:{},errorMessage:{}", comments.getActivity_id(), errorCode, result.getString("errorMessage"));
//                        }
//                    } catch (Exception e) {
//                        logger.error("评论回调失败,activity_id:{}", comments.getActivity_id(),e);
//                    }
                }
            }
    }
    
    /**
     * 自动退领
     */
    @Scheduled(cron="0 0 0 * * ? ")//每天0点执行
    public void autoRetReceive() {
    	logger.info("评论自动退领的进入.....");
    	ShyComments shyComments = new ShyComments();
    	shyComments.setState(CommonConst.AUDIT_INTT);//审核状态:未审核
    	shyComments.setReceive(CommonConst.RECEIVE_AFTER);//已领取
    	List<ShyComments> commentsList = commentsService.findshyComments(shyComments);
        if (commentsList.size() > 0) {
            for (ShyComments comments : commentsList) {
            	logger.info("自动退领的comments_id:"+comments.getId());
            	comments.setReceive(CommonConst.RECEIVE_BEFORE);//未领取
            	comments.setReceive_user_id(null);
            	commentsService.updateshyComments1(comments);
            }
    	}
    }
    
    
    
}