AttachmentService.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.fuzamei.service;
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4. import java.util.HashSet;
  5. import java.util.LinkedHashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.Set;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import com.fuzamei.dao.AttachmentDao;
  12. @Service
  13. public class AttachmentService {
  14. @Autowired
  15. private AttachmentDao attachmentDao;
  16. public int generateAtachmentId(){
  17. int same = -1;
  18. Integer attachmentId = null;
  19. //如果有重复的继续查,直到查不出重复的fundId号为止
  20. while(same != 0){
  21. attachmentId=(int)(Math.random()*1000000000); //=========================>>>产生附件id号的机制要改的TODO
  22. same = attachmentDao.queryIfHasTheSameAttachmentId(attachmentId);
  23. }
  24. return attachmentId;
  25. }
  26. /**
  27. *
  28. * @Title: generateMultiAttachmentIds
  29. * @Description: TODO(一次性生成多个附件id值)
  30. * @param @param n
  31. * @param @return 设定文件
  32. * @return List<Integer> 返回类型
  33. * @author ylx
  34. * @date 2018年1月2日 下午8:23:50
  35. * @throws
  36. */
  37. public List<Integer> generateMultiAttachmentIds(int n){
  38. while(true){
  39. Set<Integer> set=new HashSet<Integer>();
  40. for (int i = 0; i < n; i++) {
  41. Integer attachmentId=(int)(Math.random()*1000000000); //=========================>>>产生附件id号的机制要改的TODO
  42. set.add(attachmentId);
  43. }
  44. if(set.size()!=n){
  45. continue;
  46. }
  47. int same = attachmentDao.queryIfHasTheSameAttachmentIdS(set);
  48. if(same==0){
  49. List<Integer> list = new ArrayList<Integer>();
  50. for (Integer integer : set) {
  51. list.add(integer);
  52. }
  53. return list;
  54. }
  55. }
  56. }
  57. }