package com.mortals.xhx.common.utils;

import com.mortals.xhx.module.pj.model.PjEvaluateEntity;
import com.mortals.xhx.module.pj.service.PjEvaluateService;
import com.mortals.xhx.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;

import java.util.List;

/**
 * 发通知第三方
 *
 * @author: zxfei
 * @date: 2022/4/28 10:56
 * @description:
 **/
@Slf4j
public class BatchSavePjTask implements Runnable {

    private PjEvaluateService pjEvaluateService;

    private List<PjEvaluateEntity> list;

    public BatchSavePjTask(List<PjEvaluateEntity> list) {
        this.list = list;
        pjEvaluateService = SpringUtils.getBean(PjEvaluateService.class);
    }

    @Override
    public void run() {
        for (PjEvaluateEntity entity : list) {
            pjEvaluateService.getSite(entity);
        }
        pjEvaluateService.removeDuplicate(list);
        if (ObjectUtils.isEmpty(list)) return;
        log.info("批量保存评价数据:{}", list.size());
        pjEvaluateService.save(list);
    }
}
