package cn.tsy.idsse.dsds.control.thread;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections4.map.HashedMap;

import cn.hme.framework.helper.spring.SpringHelper;
import cn.hme.framework.helper.thread.ThreadHelper;
import cn.hme.framework.jdbc.provider.builder.SqlQuery;
import cn.tsy.data.idsse.dsds.mapper.sample.SampleDatasetMapper;
import cn.tsy.data.idsse.dsds.mapper.sample.SampleLineMapper;
import cn.tsy.data.idsse.dsds.mapper.sample.SampleStationMapper;
import cn.tsy.data.idsse.dsds.mapper.voyage.VoyageRegMapper;
import cn.tsy.idsse.dsds.helper.DSDSParamHelper;

/**********************
 * 缓存首页的统计数字
 * @author TsySoft
 * @create 2024-09-02 11:13:42
 * @version 1.0.0
 * @email revisit@126.com
 *
 */
public class DSDSReportThread implements Runnable{

	public static Map<String,Object> map = null;
	public DSDSReportThread() {
		map = new HashedMap<String, Object>();
	}
	@Override
	public void run() {
		
		while(true) {
			try {
				this.report();
				}catch(Exception e) {
					
				}
			ThreadHelper.sleepSeconds(DSDSParamHelper.ReportMainTicketSeconds);
		}
	}

	
	private void report() {
		// 数据集
		map.put("DatasetTotal", SpringHelper.getBean(SampleDatasetMapper.class).selectCount(SqlQuery.create()))  ;
		// 样品数量
		map.put("DataTotal", SpringHelper.getBean(SampleLineMapper.class).selectCount(SqlQuery.create()) + SpringHelper.getBean(SampleStationMapper.class).selectCount(SqlQuery.create()) )  ;
		
		List<Map<String,Object>> array = SpringHelper.getBean(VoyageRegMapper.class).totalVoyage(null, null);
		if(array.size()>0) {
			// 航次个数
			map.put("VoyageTotal",array.get(0).get("voyage_total"))  ;
			// 航线天数
			map.put("DayTotal",array.get(0).get("day_total"));
			// 航行里程
			map.put("MileageTotal",array.get(0).get("mileage_total"));
		}
		// 深海勇士
		map.put("ShenHaiTotal",SpringHelper.getBean(SampleDatasetMapper.class).selectCount(SqlQuery.create().eq("platform_name", "深海勇士")));
		// 奋斗者
		map.put("FenDouTotal",SpringHelper.getBean(SampleDatasetMapper.class).selectCount(SqlQuery.create().eq("platform_name", "奋斗者")));

	}
}
