package com.xintong.visualinspection.visuallnspection_fjq.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xintong.visualinspection.bean.CheckTaskPeriod;
import com.xintong.visualinspection.bean.FwqDeptStatistic;
import com.xintong.visualinspection.bean.FwqStatisticsBean;
import com.xintong.visualinspection.service.CommonService;
import com.xintong.visualinspection.service.ThreadTaskService_F;
import com.xintong.visualinspection.visuallnspection_fjq.dao.FwqCheckDeptStatisticsDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;

import java.util.List;

/**
 * 文件名：ThreadTaskServiceImpl
 * 版本信息：日期：2018/5/11 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 *
 * @author huangcheng
 * @since 2018/5/11
 */
@com.alibaba.dubbo.config.annotation.Service(
        version = "1.0.0",
        application = "${dubbo.application.id}",
        protocol = "${dubbo.protocol.id}",
        registry = "${dubbo.registry.id}"
)
public class ThreadTaskServiceImpl implements ThreadTaskService_F {

    private static final Logger logger = LoggerFactory.getLogger(ThreadTaskServiceImpl.class);

    @Autowired
    private FwqCheckDeptStatisticsDao fwqCheckDeptStatisticsDao;

    @Reference(version = "1.0.0",
            application = "${dubbo.application.id}",
            registry = "${dubbo.registry.address}")
    private CommonService commonService;


    @Override
    @Async("threadExecutor")
    public void saveDeptStatic(List<FwqStatisticsBean> statisticsBos, Long starttime, Long endtime) {

        CheckTaskPeriod period = commonService.getCheckTaskPeriod(starttime, endtime);

        if (period == null) {
            return;
        }
        for (FwqStatisticsBean s : statisticsBos) {
            FwqDeptStatistic ss = new FwqDeptStatistic();
            ss.setScore(Double.parseDouble(s.getScore_avg()));
            ss.setIntegral(statisticsBos.size() - s.getCompany_ranking2() + 1);
            ss.setDept_id(s.getDept_id());
            ss.setPeriod_id(period.getId());
            fwqCheckDeptStatisticsDao.saveandupdate(ss);
        }
    }
}
