1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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<Integer> 返回类型
- * @author ylx
- * @date 2018年1月2日 下午8:23:50
- * @throws
- */
- public List<Integer> generateMultiAttachmentIds(int n){
- while(true){
- Set<Integer> set=new HashSet<Integer>();
- 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<Integer> list = new ArrayList<Integer>();
- for (Integer integer : set) {
- list.add(integer);
- }
- return list;
- }
- }
-
- }
- }
|