package com.wechat.global;

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

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.wechat.dao.RedisDPResp;
import com.wechat.dao.RedisHotelBrandDao;
import com.wechat.dao.RedisHotelCompanyDao;
import com.wechat.dao.RedisHotelSubBrandDao;
import com.wechat.dao.RedisLVResp;
import com.wechat.dao.RedisPhoneCodeResp;
import com.wechat.dao.RedisProvinceCityDao;
import com.wechat.global.base.dao.RedisWithExpiryTimeDao;
import com.wechat.model.dto.HotelBrandDto;
import com.wechat.model.dto.HotelSubBrandDto;
import com.wechat.model.dto.Province;
import com.wechat.model.responseDto.DPResp;
import com.wechat.model.responseDto.HotelCompanyResp;
import com.wechat.model.responseDto.LVResp;
import com.wechat.model.responseDto.PhoneCodeResp;
import com.wechat.service.AreaService;
import com.wechat.service.CommonService;
import com.wechat.service.MdeHotelBrandService;
import com.wechat.service.MdeHotelCompanyService;
import com.wechat.service.MdeHotelSubBrandService;

/**
 * 应用程序初始化类
 * 加载 基础数据到redis缓存中, 提高系统速度
 * @author tangwc
 *
 */
@Component
public class Init {//implements InitializingBean 
	
	@Value("#{configProperties['upload.base.path']}")
	private String basePackagePath;
	
	@Value("#{configProperties['url.base']}")
	private String domainUrl;
	@Value("#{configProperties['base_data_expired_second']}")
	private String base_data_expired_second;

	@Resource
	private CommonService commonService;

	@Autowired
	private AreaService areaService;

	@Autowired
	private MdeHotelBrandService mdeHotelBrandService;
	@Autowired
	private MdeHotelSubBrandService mdeHotelSubBrandService;
	@Autowired
	private MdeHotelCompanyService mdeHotelCompanyService;
	
	@Autowired
	private RedisWithExpiryTimeDao redisDao;
	@Autowired
	private RedisProvinceCityDao redisProvinceCityDao;
	@Autowired
	private RedisHotelBrandDao redisHotelBrandDao;
	@Autowired
	private RedisHotelSubBrandDao redisHotelSubBrandDao;
	@Autowired
	private RedisHotelCompanyDao redisHotelCompanyDao;
	@Autowired
	private RedisLVResp redisLVResp;
	@Autowired
	private RedisDPResp redisDPResp;
	@Autowired
	private RedisPhoneCodeResp redisPhoneCodeResp;
	
	public void init() {
		List<HotelCompanyResp> hotelCompanys = mdeHotelCompanyService.getAllHotelCompanyInternational();// 不区分语言酒店公司
		List<LVResp> schoolList = commonService.getSchoolList("cn");// 学校列表不区分语言
		
		String lang = "en";
		String departmentsAndPositions_en = commonService.getDepartmentsAndPositions(lang);// 部门职位
		List<Province> provinceCityArea_en = areaService.getAllArea(lang);// 省市区
		List<Province> provinceCity_en = areaService.getAllProvinceAndCity(lang);// 省市
		List<HotelBrandDto> hotelBrands_en = mdeHotelBrandService.getAllHotelInternational(lang);// 酒店主品牌
		List<HotelSubBrandDto> hotelSubBrands_en = mdeHotelSubBrandService.getAllHotelSubBrandInternational(lang);// 酒店子品牌
		List<LVResp> schoolList_en = schoolList;// 学校列表
		List<DPResp> workYear_en = commonService.getDictByType("job_year",lang);// 工作年限
		List<DPResp> workStatus_en = commonService.getDictByType("work_status",lang);// 工作状态
		List<DPResp> orderStatus_en = commonService.getDictByType("order_status",lang);// 订单状态
		List<DPResp> cvStatus_en = commonService.getDictByType("cv_status",lang);// 简历投递状态
		List<DPResp> education_en = commonService.getDictByType("education",lang);// 学历
		List<DPResp> international_en = commonService.getDictByType("international",lang);// 国际区分
		List<PhoneCodeResp> phoneCode_en = commonService.getPhoneCode("phone_code", lang);// 国家码
		
		lang = "cn";
		String departmentsAndPositions_cn = commonService.getDepartmentsAndPositions(lang);// 部门职位
		List<Province> provinceCityArea_cn = areaService.getAllArea(lang);// 省市区
		List<Province> provinceCity_cn = areaService.getAllProvinceAndCity(lang);// 省市
		List<HotelBrandDto> hotelBrands_cn = mdeHotelBrandService.getAllHotelInternational(lang);// 酒店主品牌
		List<HotelSubBrandDto> hotelSubBrands_cn = mdeHotelSubBrandService.getAllHotelSubBrandInternational(lang);// 酒店子品牌
		List<LVResp> schoolList_cn = schoolList;// 学校列表
		List<DPResp> workYear_cn = commonService.getDictByType("job_year",lang);// 工作年限
		List<DPResp> workStatus_cn = commonService.getDictByType("work_status",lang);// 工作状态
		List<DPResp> orderStatus_cn = commonService.getDictByType("order_status",lang);// 订单状态
		List<DPResp> cvStatus_cn = commonService.getDictByType("cv_status",lang);// 简历投递状态
		List<DPResp> education_cn = commonService.getDictByType("education",lang);// 学历
		List<DPResp> international_cn = commonService.getDictByType("international",lang);// 国际区分
		List<PhoneCodeResp> phoneCode_cn = commonService.getPhoneCode("phone_code", lang);// 国家码
		
		redisDao.insert("departmentsAndPositions_en", departmentsAndPositions_en, Integer.valueOf(base_data_expired_second));// 
		redisDao.insert("departmentsAndPositions_cn", departmentsAndPositions_cn, Integer.valueOf(base_data_expired_second));// 
		
		ArrayList<Province> arrayList = new ArrayList<Province>();
		for(Province p:provinceCityArea_en) arrayList.add(p);
		redisProvinceCityDao.insertMessageInfo("provinceCityArea_en", arrayList);
		arrayList.clear();
		for(Province p:provinceCityArea_cn) arrayList.add(p);
		redisProvinceCityDao.insertMessageInfo("provinceCityArea_cn", arrayList);
		arrayList = null;
		
		ArrayList<Province> arrayList1 = new ArrayList<Province>();
		for(Province p:provinceCity_en) arrayList1.add(p);
		redisProvinceCityDao.insertMessageInfo("provinceCity_en", arrayList1);
		arrayList1.clear();
		for(Province p:provinceCity_cn) arrayList1.add(p);
		redisProvinceCityDao.insertMessageInfo("provinceCity_cn", arrayList1);
		arrayList1 = null;
		
		ArrayList<HotelBrandDto> arrayList2 = new ArrayList<HotelBrandDto>();
		for(HotelBrandDto p:hotelBrands_en) arrayList2.add(p);
		redisHotelBrandDao.insertMessageInfo("hotelBrands_en", arrayList2);
		arrayList2.clear();
		for(HotelBrandDto p:hotelBrands_cn) arrayList2.add(p);
		redisHotelBrandDao.insertMessageInfo("hotelBrands_cn", arrayList2);
		arrayList2 = null;
		
		ArrayList<HotelSubBrandDto> arrayList3 = new ArrayList<HotelSubBrandDto>();
		for(HotelSubBrandDto p:hotelSubBrands_en) arrayList3.add(p);
		redisHotelSubBrandDao.insertMessageInfo("hotelSubBrands_en", arrayList3);
		arrayList3.clear();
		for(HotelSubBrandDto p:hotelSubBrands_cn) arrayList3.add(p);
		redisHotelSubBrandDao.insertMessageInfo("hotelSubBrands_cn", arrayList3);
		arrayList3 = null;
		
		ArrayList<HotelCompanyResp> arrayList4 = new ArrayList<HotelCompanyResp>();
		for(HotelCompanyResp p:hotelCompanys) arrayList4.add(p);
		redisHotelCompanyDao.insertMessageInfo("hotelCompanys", arrayList4);
		arrayList4 = null;
		
		ArrayList<LVResp> arrayList5 = new ArrayList<LVResp>();
		for(LVResp p:schoolList_en) arrayList5.add(p);
		redisLVResp.insertMessageInfo("schoolList_en", arrayList5);
		arrayList5.clear();
		for(LVResp p:schoolList_cn) arrayList5.add(p);
		redisLVResp.insertMessageInfo("schoolList_cn", arrayList5);
		arrayList5 = null;
		
		ArrayList<DPResp> arrayList6 = new ArrayList<DPResp>();
		for(DPResp p:workYear_en) arrayList6.add(p);
		redisDPResp.insertMessageInfo("workYear_en", arrayList6);
		arrayList6.clear();
		for(DPResp p:workYear_cn) arrayList6.add(p);
		redisDPResp.insertMessageInfo("workYear_cn", arrayList6);
		arrayList6 = null;
		
		ArrayList<DPResp> arrayList7 = new ArrayList<DPResp>();
		for(DPResp p:workStatus_en) arrayList7.add(p);
		redisDPResp.insertMessageInfo("workStatus_en", arrayList7);
		arrayList7.clear();
		for(DPResp p:workStatus_cn) arrayList7.add(p);
		redisDPResp.insertMessageInfo("workStatus_cn", arrayList7);
		arrayList7 = null;
		
		ArrayList<DPResp> arrayList8 = new ArrayList<DPResp>();
		for(DPResp p:orderStatus_en) arrayList8.add(p);
		redisDPResp.insertMessageInfo("orderStatus_en", arrayList8);
		arrayList8.clear();
		for(DPResp p:orderStatus_cn) arrayList8.add(p);
		redisDPResp.insertMessageInfo("orderStatus_cn", arrayList8);
		arrayList8 = null;
		
		ArrayList<DPResp> arrayList9 = new ArrayList<DPResp>();
		for(DPResp p:cvStatus_en) arrayList9.add(p);
		redisDPResp.insertMessageInfo("cvStatus_en", arrayList9);
		arrayList9.clear();
		for(DPResp p:cvStatus_cn) arrayList9.add(p);
		redisDPResp.insertMessageInfo("cvStatus_cn", arrayList9);
		arrayList9 = null;
		
		ArrayList<DPResp> arrayList10 = new ArrayList<DPResp>();
		for(DPResp p:education_en) arrayList10.add(p);
		redisDPResp.insertMessageInfo("education_en", arrayList10);
		arrayList10.clear();
		for(DPResp p:education_cn) arrayList10.add(p);
		redisDPResp.insertMessageInfo("education_cn", arrayList10);
		arrayList10 = null;
		
		ArrayList<DPResp> arrayList11 = new ArrayList<DPResp>();
		for(DPResp p:international_en) arrayList11.add(p);
		redisDPResp.insertMessageInfo("international_en", arrayList11);
		arrayList11.clear();
		for(DPResp p:international_cn) arrayList11.add(p);
		redisDPResp.insertMessageInfo("international_cn", arrayList11);
		arrayList11 = null;
		
		ArrayList<PhoneCodeResp> arrayList12 = new ArrayList<PhoneCodeResp>();
		for(PhoneCodeResp p:phoneCode_en) arrayList12.add(p);
		redisPhoneCodeResp.insertMessageInfo("phoneCode_en", arrayList12);
		arrayList12.clear();
		for(PhoneCodeResp p:phoneCode_cn) arrayList12.add(p);
		redisPhoneCodeResp.insertMessageInfo("phoneCode_cn", arrayList12);
		arrayList12 = null;
		
	}

}
