ylx 7 years ago
parent
commit
650b573991

+ 47 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/Attachment.java

@@ -0,0 +1,47 @@
+package com.fuzamei.entity;
+
+public class Attachment {
+	private Integer id;						//主键id
+	private Integer attachment_id;			//附件id
+	private String attachment_name;			//附件名
+	private String url;						//附件url地址
+	private Integer upload_person_id;		//上传人userId
+	private Long create_time;				//创建时间
+	public Integer getId() {
+		return id;
+	}
+	public void setId(Integer id) {
+		this.id = id;
+	}
+	public Integer getAttachment_id() {
+		return attachment_id;
+	}
+	public void setAttachment_id(Integer attachment_id) {
+		this.attachment_id = attachment_id;
+	}
+	public String getAttachment_name() {
+		return attachment_name;
+	}
+	public void setAttachment_name(String attachment_name) {
+		this.attachment_name = attachment_name;
+	}
+	public String getUrl() {
+		return url;
+	}
+	public void setUrl(String url) {
+		this.url = url;
+	}
+	public Integer getUpload_person_id() {
+		return upload_person_id;
+	}
+	public void setUpload_person_id(Integer upload_person_id) {
+		this.upload_person_id = upload_person_id;
+	}
+	public Long getCreate_time() {
+		return create_time;
+	}
+	public void setCreate_time(Long create_time) {
+		this.create_time = create_time;
+	}
+	
+}

+ 19 - 62
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/ProjectFile.java

@@ -1,5 +1,7 @@
 package com.fuzamei.entity;
 
+import java.util.List;
+
 /**
  * 查询项目文档的实体类
  * 
@@ -7,86 +9,41 @@ package com.fuzamei.entity;
  *
  */
 public class ProjectFile {
-	private Integer project_id;
-	private String project_name;
-	private Integer project_file_id;
-	private String attachment_name;
-	private String url;
-	private Integer upload_person_id;
-	private String create_time;
-	private String update_time;
-	private String hash;
-
+	private Integer id;						//主键id
+	private Integer project_id;				//项目id号
+	private String project_name;			//项目名称
+	private String update_time;				//更新时间
+	private List<Attachment> attachments;	//附件集合
+	public Integer getId() {
+		return id;
+	}
+	public void setId(Integer id) {
+		this.id = id;
+	}
 	public Integer getProject_id() {
 		return project_id;
 	}
-
 	public void setProject_id(Integer project_id) {
 		this.project_id = project_id;
 	}
-
 	public String getProject_name() {
 		return project_name;
 	}
-
 	public void setProject_name(String project_name) {
 		this.project_name = project_name;
 	}
-
-	public Integer getProject_file_id() {
-		return project_file_id;
-	}
-
-	public void setProject_file_id(Integer project_file_id) {
-		this.project_file_id = project_file_id;
-	}
-
-	public String getAttachment_name() {
-		return attachment_name;
-	}
-
-	public void setAttachment_name(String attachment_name) {
-		this.attachment_name = attachment_name;
-	}
-
-	public String getUrl() {
-		return url;
-	}
-
-	public void setUrl(String url) {
-		this.url = url;
-	}
-
-	public Integer getUpload_person_id() {
-		return upload_person_id;
-	}
-
-	public void setUpload_person_id(Integer upload_person_id) {
-		this.upload_person_id = upload_person_id;
-	}
-
-	public String getCreate_time() {
-		return create_time;
-	}
-
-	public void setCreate_time(String create_time) {
-		this.create_time = create_time;
-	}
-
 	public String getUpdate_time() {
 		return update_time;
 	}
-
 	public void setUpdate_time(String update_time) {
 		this.update_time = update_time;
 	}
-
-	public String getHash() {
-		return hash;
+	public List<Attachment> getAttachments() {
+		return attachments;
 	}
-
-	public void setHash(String hash) {
-		this.hash = hash;
+	public void setAttachments(List<Attachment> attachments) {
+		this.attachments = attachments;
 	}
-
+	
+	
 }

+ 33 - 15
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapper/ProjectFileMapper.xml

@@ -4,34 +4,52 @@
 -->               
 <mapper namespace="com.fuzamei.mapperInterface.ProjectFileMapper"> 
 	<!-- 根据操作记录给的条件查询分页数据 -->
-	<select id="queryProjectFileInformation" resultType="com.fuzamei.entity.ProjectFile">
+	<select id="queryProjectFileInformation" resultMap="ProjectFileRM">
 		select 
+			pf.id,
 			pf.project_id,
 			pf.project_name,
-			att.attachment_name,
 			pf.update_time,
-			pf.hash,
-			att.url
+			att.id as id2,
+			att.attachment_id,
+			att.attachment_name,
+			att.url,
+			att.upload_person_id,
+			att.create_time
 		from 
-			project_file pf 
+			(select 
+				*
+			 from 
+				project_file
+			 <where>
+				<if test="projectName!='' and projectName!=null">
+					project_name=#{projectName}
+				</if>
+				<if test="startTime!=null and endTime!=null">
+					and update_time between #{startTime} and #{endTime}
+				</if>
+			</where>) pf
 		left join 
-			attachment att 
+			project_file_id pfi
 		on 
-			pf.project_file_id = att.attachment_id
-		<where>
-			<if test="projectName!='' and projectName!=null">
-				pf.project_name=#{projectName}
-			</if>
-			<if test="startTime!=null and endTime!=null">
-				and pf.update_time between #{startTime} and #{endTime}
-			</if>
-		</where>
+			pf.project_id=pfi.project_id
+		left join 
+			attachment att
+		on 
+			att.attachment_id=pfi.project_file_id
 		order by 
 			pf.id asc 
 		limit 
 			#{startPage},#{rowNum}
 	</select>
 	
+	<resultMap type="com.fuzamei.entity.ProjectFile" id="ProjectFileRM" autoMapping="true">
+		<id column="id" property="id"/>
+		<collection property="attachments" autoMapping="true" javaType="com.fuzamei.entity.Attachment">
+			<id column="id2" property="id"/>
+		</collection>
+	</resultMap>
+	
 	<!-- 分页用查询总记录条数 -->
 	<select id="findAllInformation" resultType="int">
 		select 

+ 3 - 2
ccb_fund_trusteeship/src/main/java/com/fuzamei/service/AttachmentService.java

@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.fuzamei.dao.AttachmentDao;
+import com.fuzamei.utils.RandomUtil;
 
 @Service
 public class AttachmentService {
@@ -24,7 +25,7 @@ public class AttachmentService {
 		Integer attachmentId = null;
 		//如果有重复的继续查,直到查不出重复的fundId号为止
 		while(same != 0){
-			attachmentId=(int)(Math.random()*1000000000);								//=========================>>>产生附件id号的机制要改的TODO
+			attachmentId=RandomUtil.getRandomInteger(10);								//=========================>>>产生附件id号的机制要改的TODO
 			same = attachmentDao.queryIfHasTheSameAttachmentId(attachmentId);
 		}
 		return attachmentId;
@@ -45,7 +46,7 @@ public class AttachmentService {
 		while(true){
 			Set<Integer> set=new HashSet<Integer>();
 			for (int i = 0; i < n; i++) {
-				Integer attachmentId=(int)(Math.random()*1000000000);								//=========================>>>产生附件id号的机制要改的TODO
+				Integer attachmentId=RandomUtil.getRandomInteger(10);								//=========================>>>产生附件id号的机制要改的TODO
 				set.add(attachmentId);
 			}
 			if(set.size()!=n){

+ 115 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/utils/RandomUtil.java

@@ -1,6 +1,7 @@
 package com.fuzamei.utils;
 
 import java.util.Random;
+import java.util.UUID;
 
 /**
  * 随机数相关方法
@@ -16,6 +17,15 @@ public final class RandomUtil {
 	
 	private static final Random RANDOM = new Random();
 	
+	private static final String STRS="aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789";
+	private static final int LEN4STRS = 62;
+	
+	private static final String STR="abcdefghijklmnopqrstuvwxyz0123456789";
+	private static final int LEN4STR = 36;
+	
+	private static final String DIG="0123456789";
+	private static final int LEN4DIG = 10;
+	
 	/**
 	 * 获取指定长度的随机数
 	 * @param length 位数 长度
@@ -43,4 +53,109 @@ public final class RandomUtil {
 		return sb.toString();
 	}
 
+	
+	/**
+	 * @describe 获取随机的uuid,除去"-"
+	 * @author ylx
+	 * @return
+	 */
+	public static final String getUUidRandom(){
+		return UUID.randomUUID().toString().replaceAll("-", "");
+	}
+	
+	/**
+	 * @describe 根据传入的参数生成特定长度的随机字符串(数字和小写字符)
+	 * @author ylx
+	 * @param length 产生随机字符串的长度
+	 * @param withUpperCase 如果是true说明要带入大写字母,false不带入大写字母
+	 * @return
+	 */
+	public static final String getRandomString(int length,boolean withUpperCase){
+		StringBuilder sb=new StringBuilder();
+		String temp = STR;
+		int len = LEN4STR;
+		if(withUpperCase){
+			temp = STRS;
+			len = LEN4STRS; 
+		}
+		for (int i = 0; i < length; i++) {
+			char c =temp.charAt((int)(Math.random()*len));
+			sb.append(c);
+		}
+		return sb.toString();
+	}
+	
+	/**
+	 * @describe 根据传入的参数生成特定长度的随机字符串(数字)
+	 * @author ylx
+	 * @param length
+	 * @return
+	 */
+	public static final String getRandomDigits(int length){
+		StringBuilder sb=new StringBuilder();
+		for (int i = 0; i < length; i++) {
+			char c =DIG.charAt((int)(Math.random()*LEN4DIG));
+			sb.append(c);
+		}
+		return sb.toString();
+	}
+	
+	/**
+	 * @author ylx
+	 * @param digits int类型数字的位数,不能超过10位,也不能小于1,否则会报异常
+	 * @return
+	 */
+	public static final int getRandomInteger(int digits){
+		if(digits<1 || digits>10){
+			throw new RuntimeException("out of integer's range");
+		}
+		int base = (int)Math.pow(10, digits-1);
+		int randomSufix = (int) (Math.random()*base*9);
+		switch (digits) {
+		case 1:
+			base=0;
+			randomSufix = (int) (Math.random()*10);
+			break;
+		case 10:
+			randomSufix = (int) (Math.random()*(Integer.MAX_VALUE-base+1));
+			break;
+		default:
+			break;
+		}
+		return base+randomSufix;
+	}
+	
+	/**
+	 * @author ylx
+	 * @param digits long类型数字的位数,不能超过19位,也不能小于1,否则会报异常
+	 * @return 
+	 */
+	public static final long getRandomLong(int digits){
+		if(digits<1 || digits>19){
+			throw new RuntimeException("out of long's range");
+		}
+		long base = (long)Math.pow(10, digits-1);
+		long randomSufix = (long) (Math.random()*base*9);
+		switch (digits) {
+		case 1:
+			base=0;
+			randomSufix = (int) (Math.random()*10);
+			break;
+		case 19:
+			randomSufix = (long) (Math.random()*(Long.MAX_VALUE-base+1));
+			break;
+		default:
+			break;
+		}
+		return base+randomSufix;
+	}
+	
+	public static void main(String[] args) {
+		for (int i = 0; i < 100; i++) {
+			
+			System.out.println(getRandomLong(19));
+		}
+	}
+	
+	
 }