packagecom.xxx.xx.reve.service;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importcom.xxx.xx.common.service.ParentService;importcom.xxx.xx.redis.service.JedisClient;importcom.xxx.xx.reve.vo.RevenueSt;importcom.xxx.xx.util.PropertieUtil;importnet.sf.json.JSONObject;
@Service
@SuppressWarnings("rawtypes")public class RevenueStServiceImpl2 extends ParentService implementsRevenueStService{private final static Logger logger = LoggerFactory.getLogger(RevenueStServiceImpl.class);
@AutowiredprivateJedisClient jedisClient;//预处理对象转String方法
privateString o2s(Object o) {if(o!=null&&!"".equals(o)&&!"null".equals((o+"").trim().toLowerCase())) {return o+"";
}return null;
}//生成总收入查询参数
privateString genAllIncomeParam(String s) {
StringBuffer sb= newStringBuffer();for (int i = 1; i <= getMonth(s); i++) {
sb.append("SUM(TY_"+i+")+");
}
String s2=sb.toString();
String res= s2.substring(0, s2.length()-1);
logger.info("总收入查询参数:{}",res);returnres;
}//截取字符串获取月份信息 "201912";
privateInteger getMonth(String s) {//截取后两位
s = s.substring(s.length() -2,s.length());char c1 = s.charAt(0);char c2 = s.charAt(1);if ((c1+"").equals("0")) {return Integer.parseInt(c2+"");
}returnInteger.parseInt(s);
}//线程池
private ExecutorService exec = Executors.newFixedThreadPool(Integer.parseInt(PropertieUtil.getConfig("revenue.threadNum")));//redis中缓存队列key
private String redisKeyName = "EVENUE_STATISTICS_LIST";//获取统计数据方法
@SuppressWarnings("unchecked")
@Overridepublic voidgetStatisticsData() {//清空缓存
jedisClient.del(redisKeyName);//普通查询参数
Map param = newHashMap();
param.put("tablename","REVENUE_STATISTICS_RES");//将原表数据备份到历史表
Integer countRevenueNum = this.selectOne("ds2", "reve.countRevenueNum", param);
logger.info("----历史表revenue_statistics_res数据量为{}",countRevenueNum);if (countRevenueNum!=null && countRevenueNum >Integer.parseInt(PropertieUtil.getConfig("revenue.copyLimitNum"))) {//删除历史表
try{this.update("ds2", "reve.dropH