/**
* 查询前天所有的报废数据
* @return
*/
public Map<String,Object> findAllAudit(){
LOGGER.info("执行该方法的时间"+new SimpleDateFormat("yy-MM--dd HH-mm-ss").format(new Date()));
Map<String,Object> map = new HashMap<String, Object>();
Map<String,String> hashMap = new HashMap<String,String>();
hashMap.put("recordStatusNum","3");
hashMap.put("deleteMark","-1");
try {
List<IllegelAudit> auditList = this.iIllegelAuditService.getAll("selectScrapByStatusAndDeleMark",hashMap);
Integer allCount = (int) Math.ceil(auditList.size()*0.01);
System.out.println("查询的数量"+allCount);*/
map.put("auditList",auditList);
map.put("allCount",allCount);
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
/**
* 每天凌晨的0点10分更新数据
*/
public void updateFlag(){
LOGGER.info("执行该方法的时间"+new SimpleDateFormat("yy-MM--dd HH-mm-ss").format(new Date()));
Map<String,Object> map = findAllAudit();
//取得recordCode的集合
try{
List list = getRandomList((List) map.get("auditList"),(Integer) map.get("allCount"));
Map hashMap = new HashMap();
hashMap.put("codelist",list);
if(list!=null){
this.iIllegelAuditService.update("updateScrapStstus",hashMap);
}
}catch (Exception e){
e.printStackTrace();
}
}
/**
* @function:从list中随机抽取若干不重复元素
* @param paramList:被抽取list
* @param count:抽取元素的个数
* @return:由抽取元素组成的新list
*/
public List getRandomList(List<IllegelAudit> paramList,int count){
if(count==0){
return null;
}
Random random=new Random();
List<Integer> tempList=new ArrayList<Integer>();//临时存放产生的list索引,去除重复的索引
List newList=new ArrayList();//生成新的list集合
int temp=0;
if(count<=1){//如果数据小于1,取一条数据
temp = random.nextInt(paramList.size());
newList.add(paramList.get(temp).getRecordCode());
}else {
for(int i=0;i<Math.ceil(count);i++){
temp=random.nextInt(paramList.size());//初始化一个随机数,将产生的随机数作为被抽list的索引
if(!tempList.contains(temp)){//判断随机抽取的随机数
tempList.add(temp);
newList.add(paramList.get(temp).getRecordCode());
}
else{
i--;
}
}
}
return newList;
}
}