package com.fuzamei.service; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.fuzamei.dao.AttachmentDao; @Service public class AttachmentService { @Autowired private AttachmentDao attachmentDao; public int generateAtachmentId(){ int same = -1; Integer attachmentId = null; //如果有重复的继续查,直到查不出重复的fundId号为止 while(same != 0){ attachmentId=(int)(Math.random()*1000000000); //=========================>>>产生附件id号的机制要改的TODO same = attachmentDao.queryIfHasTheSameAttachmentId(attachmentId); } return attachmentId; } /** * * @Title: generateMultiAttachmentIds * @Description: TODO(一次性生成多个附件id值) * @param @param n * @param @return 设定文件 * @return List 返回类型 * @author ylx * @date 2018年1月2日 下午8:23:50 * @throws */ public List generateMultiAttachmentIds(int n){ while(true){ Set set=new HashSet(); for (int i = 0; i < n; i++) { Integer attachmentId=(int)(Math.random()*1000000000); //=========================>>>产生附件id号的机制要改的TODO set.add(attachmentId); } if(set.size()!=n){ continue; } int same = attachmentDao.queryIfHasTheSameAttachmentIdS(set); if(same==0){ List list = new ArrayList(); for (Integer integer : set) { list.add(integer); } return list; } } } }