package cn.superdesk.uniorder.executor.scheduler.task;

import lombok.extern.slf4j.Slf4j;

import java.util.TimerTask;

/**
 * @Description: TODO 待重构 这个是前人留下来的问题
 * @Author: linjinyu
 * @CreateDate: 2020/12/2 下午6:44
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020/12/2 下午6:44
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Deprecated
@Slf4j
public class StatisticsJob extends TimerTask {

	@Override
	public void run() {

//		try {
//			SimpleDateFormat sdf2  = new SimpleDateFormat("yyyyMMddHHmmss");
//			Date             dtNow = DateUtil.date();
//
//			int hour = Integer.parseInt(sdf2.format(dtNow).substring(8, 10));
//
//			if (hour == 23 || hour == 17) {
//				System.out.println(sdf2.format(dtNow) + ":>>>>>----开始执行统计......");
//			} else {
//				System.out.println(sdf2.format(dtNow) + ":>>>>>----未在统计时间内......");
//				return;
//			}
//
//
//			UnifiedStatisticsVirtDubboConsumerService jobDubboService = (UnifiedStatisticsVirtDubboConsumerService) SpringContextHolder.getBean("unifiedStatisticsVirtDubboConsumerService");
//
//			Date             dtnow = DateUtil.date();
//			SimpleDateFormat sdf   = new SimpleDateFormat("yyyy-MM");
//
//			String dtstr = sdf.format(dtnow);
//
//			//SysConfig vconfig = jobDubboService.getConfigData("VIRTTJ");
//			int year  = Integer.parseInt(dtstr.substring(0, 4));//vconfig.getValueInt();//
//			int month = Integer.parseInt(dtstr.substring(5));// Integer.parseInt(vconfig.getValueStr1())+1;//
//
//			if (month == 13) {
//				month = 1;
//				year = year + 1;
//			}
//
//
//			Map<String, Object> queryMap = new HashMap<>();
//			queryMap.put("year", year);
//			queryMap.put("month", month);

		/****************************************** StatisticsJobVirtOrderStatistical start ******************************************/

//			List<UnifiedStatisticsVirt> ls = jobDubboService.queryVirtOrderStatistical(queryMap);
//
//			if (ls != null && ls.size() > 0) {
//				for (UnifiedStatisticsVirt item : ls) {
//					jobDubboService.storeVirtOrderStatistical(item, year, month);
//				}
//			}

//			/****************************************** StatisticsJobVirtRefundOrderStatistical start ******************************************/
//
//			// 退货统计 TODO 待验证
//			List<UnifiedStatisticsVirt> return_ls = jobDubboService.queryVirtRefundOrderStatistical(queryMap);
//
//			if (return_ls != null && return_ls.size() > 0) {
//
//				for (UnifiedStatisticsVirt item : return_ls) {
//
//					Map<String, Object> queryStatistics = new HashMap<>();
//					queryStatistics.put("virtId", item.getVirtId());
//					queryStatistics.put("sYear", year);
//					queryStatistics.put("sMonth", month);
//					queryStatistics.put("serviceNo", item.getServiceNo());
//					List<UnifiedStatisticsVirt> statisticsVirts = jobDubboService.findAll(queryStatistics);
//
//					if (statisticsVirts != null && statisticsVirts.size() > 0) {
//
//						// update
//						UnifiedStatisticsVirt update = statisticsVirts.get(0);
//
//						/****************************************** mark by linjinyu at 20201125 重构 start ******************************************/
//						update.setOrderRefundAmount(item.getOrderRefundAmount());
//						update.setOrderRefundCostAmount(item.getOrderRefundCostAmount());
//
//						update.setGoodsRefundAmount(item.getGoodsRefundAmount());
//						update.setGoodsRefundCostAmount(item.getGoodsRefundCostAmount());
//
//						/****************************************** mark by linjinyu at 20201125 重构   end ******************************************/
//
//						jobDubboService.updateStatisticsVirt(update);
//
//					} else {
//
//						// insert
//						UnifiedStatisticsVirt add = new UnifiedStatisticsVirt();
//
//						add.setVirtId(item.getVirtId());
//						add.setServiceNo(item.getServiceNo());
//
//						add.setQuantity(0);
//
//						add.setSMonth(month);
//						add.setSYear(year);
//
//
//						/****************************************** mark by linjinyu at 20201125 重构 start ******************************************/
//
//						add.setOrderAmount(new BigDecimal("0"));
//						add.setOrderCostAmount(new BigDecimal("0"));
//						add.setOrderRefundAmount(item.getOrderRefundAmount());
//						add.setOrderRefundCostAmount(item.getOrderRefundCostAmount());
//						add.setOrderTransportAmount(new BigDecimal("0"));
//
//						add.setGoodsAmount(new BigDecimal("0"));
//						add.setGoodsCostAmount(new BigDecimal("0"));
//						add.setGoodsRefundAmount(item.getGoodsRefundAmount());
//						add.setGoodsRefundCostAmount(item.getGoodsRefundCostAmount());
//						add.setGoodsTransportAmount(new BigDecimal("0"));
//
//						/****************************************** mark by linjinyu at 20201125 重构   end ******************************************/
//
//						add.setPayableAmount(new BigDecimal(0));
//
//						add.setCreateTime(DateUtil.date());
//
//						jobDubboService.insertStatisticsVirt(add);
//					}
//				}
//			}

		//更新时间
//			vconfig.setValueInt(year);
//			vconfig.setValueStr1(month+"");
//			jobDubboService.updateConfig(vconfig);
		//更新区域结构名称 0312 一次
//			SysConfig config = jobDubboService.getConfigData("UPDATEAREA");
//			if(config.getValueInt()==2){
//
//				List<UnifiedAreaCity> unifiedAreaCities = jobDubboService.findAllAreaCity();
//				for (UnifiedAreaCity item :
//						unifiedAreaCities) {
//					jobDubboService.updateAreaCity(item);
//				}
//				config.setValueInt(1);
//				jobDubboService.updateConfig(config);
//			}

//			dtNow = DateUtil.date();
//			System.out.println(sdf2.format(dtNow) + ":>>>>>----预警信息统计......");


//			/****************************************** StatisticsJobWarningOrderAmount start ******************************************/
//			// 信用金额
//			List<WarningOrderAmountVo> warningOrderAmountVoList = jobDubboService.getWarningOrderAmount(queryMap);
//
//			UnifiedWarningDubboConsumerService warningDubboService = (UnifiedWarningDubboConsumerService) SpringContextHolder.getBean("unifiedWarningDubboConsumerService");
//
//			if (warningOrderAmountVoList != null && warningOrderAmountVoList.size() > 0) {
//
//				for (WarningOrderAmountVo warningOrderAmountVo : warningOrderAmountVoList) {
//
//					UnifiedWarning unifiedWarning = new UnifiedWarning();
//
//					unifiedWarning.setCreateTime(DateUtil.date());
//					unifiedWarning.setCreateUserId(1L);
//					unifiedWarning.setCreditPass(warningOrderAmountVo.getAmount().subtract(warningOrderAmountVo.getCredit()));
//					unifiedWarning.setState(2);
//					unifiedWarning.setVirtId(warningOrderAmountVo.getVirtId());
//					unifiedWarning.setWarningType(2);
//
//					warningDubboService.addObj(unifiedWarning);
//				}
//			}

//			/****************************************** StatisticsJobWarningOrderInvoice start ******************************************/
//
//			// 发票逾期
//			List<WarningOrderInvVo> warningOrderInvVoList = warningDubboService.queryWarningOrderInvoice(queryMap);
//
//			if (warningOrderInvVoList != null && warningOrderInvVoList.size() > 0) {
//
//				for (WarningOrderInvVo warningOrderInvVo : warningOrderInvVoList) {
//
//					UnifiedWarning unifiedWarning = new UnifiedWarning();
//
//					unifiedWarning.setCreateTime(DateUtil.date());
//					unifiedWarning.setCreateUserId(1L);
//					unifiedWarning.setInvNo(warningOrderInvVo.getInvoiceNumber());
//					unifiedWarning.setState(2);
//					unifiedWarning.setVirtId(warningOrderInvVo.getVirtId());
//					unifiedWarning.setWarningType(1);
//
//					warningDubboService.addObj(unifiedWarning);
//				}
//			}
//		} catch (Exception e) {
//			log.error("统计错误:{}", ExceptionUtils.getMessage(e));
//			e.printStackTrace();
//		} finally {
//			System.gc();
//		}
	}

}
