CommentsJob.java 3.25 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.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 = 30 * 60 * 1000)
    public void syncComments() {

        //收集免审的spid
        List<ShySites> sitesList = sitesService.findAll();
        ArrayList<Integer> sites = new ArrayList<Integer>();
        for (ShySites shySites : sitesList) {
            if (CommonUtils.isNotEmpty(shySites.getWrite_business())) {
                String[] business = shySites.getWrite_business().split(",");
                List<String> asList = Arrays.asList(business);
                if (asList.contains(CommonConst.BUSINESS_COMMENT + "")) {
                    sites.add(shySites.getSpid());
                }
            }
        }
        //遍历免审的spid去更改状态值
        ShyComments shyComments = new ShyComments();
        for (int spid : sites) {
            shyComments.setSpid(spid);
            List<ShyComments> commentsList = commentsService.findshyComments(shyComments);
            if (commentsList.size() > 0) {
                for (ShyComments comments : commentsList) {
                    //封装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());
                    } catch (Exception e) {
                        logger.error("评论回调失败,activity_id:{}", comments.getActivity_id());
                    }
                    comments.setState(CommonConst.AUDIT_SUCCESS);
                    int i = commentsService.updateComment(comments.getId(), CommonConst.AUDIT_SUCCESS, json1.getString("msg"));
                    if (i > 0) {
                        logger.info("评论修改成功");
                        System.out.println("评论修改成功");
                    } else {
                        logger.info("评论修改失败");
                        System.out.println("评论修改失败");

                    }
                }
            }
        }
    }
}