ylx 7 lat temu
rodzic
commit
062df00c47

+ 30 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/dao/UserAuthoricationDao.java

@@ -0,0 +1,30 @@
+package com.fuzamei.dao;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Repository;
+
+import com.fuzamei.mapperInterface.UserAuthoricationMapper;
+
+/**
+ * 
+ * @author ylx
+ * @describe 用于查询用户的信息的dao层类
+ */
+@Repository
+public class UserAuthoricationDao {
+	
+	@Autowired
+	private UserAuthoricationMapper userAuthoricationMapper;
+	
+	//根据用户的id号查询用户的角色信息 
+	public List<String> queryUserRoleNames(int userId){
+		return userAuthoricationMapper.queryUserRolenames(userId);
+	}
+	
+	//根据用户的id号查询用户的权限信息 
+	public List<String> queryUserPermissionNames(int userId){
+		return userAuthoricationMapper.queryUserPermissionNames(userId);
+	}
+}

+ 123 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/OperationHistoryBO.java

@@ -0,0 +1,123 @@
+package com.fuzamei.entity;
+
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+
+import org.hibernate.validator.constraints.NotEmpty;
+import org.hibernate.validator.constraints.Range;
+/**
+5      * Bean Validation 中内置的 constraint       
+6      * @Null   被注释的元素必须为 null       
+7      * @NotNull    被注释的元素必须不为 null       
+8      * @AssertTrue     被注释的元素必须为 true       
+9      * @AssertFalse    被注释的元素必须为 false       
+10      * @Min(value)     被注释的元素必须是一个数字,其值必须大于等于指定的最小值       
+11      * @Max(value)     被注释的元素必须是一个数字,其值必须小于等于指定的最大值       
+12      * @DecimalMin(value)  被注释的元素必须是一个数字,其值必须大于等于指定的最小值       
+13      * @DecimalMax(value)  被注释的元素必须是一个数字,其值必须小于等于指定的最大值       
+14      * @Size(max=, min=)   被注释的元素的大小必须在指定的范围内       
+15      * @Digits (integer, fraction)     被注释的元素必须是一个数字,其值必须在可接受的范围内       
+16      * @Past   被注释的元素必须是一个过去的日期       
+17      * @Future     被注释的元素必须是一个将来的日期       
+18      * @Pattern(regex=,flag=)  被注释的元素必须符合指定的正则表达式       
+19      * Hibernate Validator 附加的 constraint       
+20      * @NotBlank(message =)   验证字符串非null,且长度必须大于0       
+21      * @Email  被注释的元素必须是电子邮箱地址       
+22      * @Length(min=,max=)  被注释的字符串的大小必须在指定的范围内       
+23      * @NotEmpty   被注释的字符串的必须非空       
+24      * @Range(min=,max=,message=)  被注释的元素必须在合适的范围内 
+25      */
+/*@NotNull 和 @NotEmpty  和@NotBlank 区别
+@NotEmpty 用在集合类上面
+@NotBlank 用在String上面
+@NotNull    用在基本类型上
+如果在基本类型上面用NotEmpty或者NotBlank 会出现上面的错*/
+/**
+ * 
+ * @author ylx
+ * @version 1.0
+ * @descible 操作记录模块中查询的操作接受的实体类信息
+ */
+public class OperationHistoryBO {
+	@NotNull(message="用户id号不能为空")
+	@Min(value=0,message="必须是一个大于0的数字")
+	private Integer userId;
+	
+	@NotNull(message="页数不能为空")
+	@Range(min=1,max=Integer.MAX_VALUE,message="页数最小值应该为1")
+	private Integer page;
+	
+	private String account;
+	
+	private String role;
+	
+	private String type;
+	
+	private Long startTime;
+	
+	private Long endTime;
+
+	public Integer getUserId() {
+		return userId;
+	}
+
+	public void setUserId(Integer userId) {
+		this.userId = userId;
+	}
+
+	public Integer getPage() {
+		return page;
+	}
+
+	public void setPage(Integer page) {
+		this.page = page;
+	}
+
+	public String getAccount() {
+		return account;
+	}
+
+	public void setAccount(String account) {
+		this.account = account;
+	}
+
+	public String getRole() {
+		return role;
+	}
+
+	public void setRole(String role) {
+		this.role = role;
+	}
+
+	public String getType() {
+		return type;
+	}
+
+	public void setType(String type) {
+		this.type = type;
+	}
+
+	public Long getStartTime() {
+		return startTime;
+	}
+
+	public void setStartTime(Long startTime) {
+		this.startTime = startTime;
+	}
+
+	public Long getEndTime() {
+		return endTime;
+	}
+
+	public void setEndTime(Long endTime) {
+		this.endTime = endTime;
+	}
+
+	@Override
+	public String toString() {
+		return "OperationHistoryBO [userId=" + userId + ", page=" + page + ", account=" + account + ", role=" + role
+				+ ", type=" + type + ", startTime=" + startTime + ", endTime=" + endTime + "]";
+	}
+	
+}

+ 60 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapper/UserAuthoricationMapper.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fuzamei.mapperInterface.UserAuthoricationMapper"> 
+	
+	<!-- 根据用户的id号查询用户的角色信息 -->
+	<select id="queryUserRolenames" resultType="string">
+		select 
+			t_role.role_name
+		from 
+			(select 
+				user_role.role_id
+			from 
+				t_user 
+			left join 
+				user_role
+			on
+				t_user.user_id=user_role.user_id
+			where t_user.user_id=#{userId}) temp
+		left join 
+			t_role
+		on 
+			temp.role_id=t_role.role_id
+	</select>
+	
+	<!-- 根据用户的id号查询用户的权限信息 -->
+	<select id="queryUserPermissionNames" resultType="string">
+		select 
+			t_permission.authority_name
+		from 
+			(select 
+				role_permission.authority_id 
+			from 
+				(select 
+					t_role.role_id,
+					t_role.role_name
+				from 
+					(select 
+						user_role.role_id
+					from 
+						t_user 
+					left join 
+						user_role
+					on
+						t_user.user_id=user_role.user_id
+					where t_user.user_id=#{userId}) temp
+				left join 
+					t_role
+				on 
+					temp.role_id=t_role.role_id) temp 
+			left join 
+				role_permission
+			on 
+				temp.role_id=role_permission.role_id) temp 
+		left join 
+			t_permission
+		on 
+			temp.authority_id=t_permission.authority_id
+	</select>
+	
+</mapper>

+ 12 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapperInterface/UserAuthoricationMapper.java

@@ -0,0 +1,12 @@
+package com.fuzamei.mapperInterface;
+
+import java.util.List;
+
+public interface UserAuthoricationMapper {
+
+	List<String> queryUserRolenames(int userId);//根据用户的id号查询用户的角色信息
+
+	List<String> queryUserPermissionNames(int userId);//根据用户的id号查询用户的权限信息
+	
+	
+}

+ 37 - 1
ccb_fund_trusteeship/src/main/java/com/fuzamei/service/OperationHistoryService.java

@@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
 
 import com.fuzamei.dao.OperationHistoryDao;
 import com.fuzamei.entity.OperationHistory;
+import com.fuzamei.entity.OperationHistoryBO;
 import com.fuzamei.utils.DateUtil;
 import com.fuzamei.utils.PageDTO;
 
@@ -28,7 +29,7 @@ public class OperationHistoryService {
 	 * startTime @param @param endTime @param @return 设定文件 @return PageDTO
 	 * 返回类型 @author ylx @date 2017年12月14日 下午8:09:43 @throws
 	 */
-	public PageDTO queryOperationHistoryInformation(Map<String, Object> map) {
+/*	public PageDTO queryOperationHistoryInformation(Map<String, Object> map) {
 		int page = 1; // 默认页是第一页
 		String account = ""; // 账号默认空值
 		String role = ""; // 操作角色默认空值
@@ -101,6 +102,41 @@ public class OperationHistoryService {
 		pageDto.setTotal(count);
 		pageDto.setRows(informationList);
 		return pageDto;
+	}*/
+
+	/**
+	 * 
+	* @Title: queryOperationHistoryInformation
+	* @Description: TODO(controller层通过对象的形式传入信息查询)
+	* @param @param operationHistoryBO
+	* @param @return    设定文件
+	* @return PageDTO    返回类型
+	* @author ylx
+	* @date 2017年12月26日 下午4:26:44
+	* @throws
+	 */
+	public PageDTO queryOperationHistoryInformation(OperationHistoryBO operationHistoryBO) {
+		Integer userId = operationHistoryBO.getUserId();
+		Integer page = operationHistoryBO.getPage();
+		String account = operationHistoryBO.getAccount();
+		String role = operationHistoryBO.getRole(); // 操作角色默认空值
+		String type = operationHistoryBO.getType(); // 操作类型默认空值
+		Long startTime = operationHistoryBO.getStartTime(); // 开始时间默认0
+		Long endTime = operationHistoryBO.getEndTime(); // 结束时间
+		PageDTO pageDto = new PageDTO(); // 创建分页对象
+		Map<String, Object> mapToDao = new LinkedHashMap<String, Object>();
+		mapToDao.put("startPage", (page - 1) * ROW_NUM);
+		mapToDao.put("account", account);
+		mapToDao.put("role", role);
+		mapToDao.put("type", type);
+		mapToDao.put("startTime", startTime);
+		mapToDao.put("endTime", endTime);
+		mapToDao.put("rowNum", ROW_NUM); //默认每页显示数据是10条,可根据需求修改分页数量
+		List<OperationHistory> informationList = operationHistoryDao.queryOperationHistoryInformation(mapToDao); //去dao层取分页的数据
+		int count = operationHistoryDao.findAllInformation();	//查询总信息条数
+		pageDto.setTotal(count);
+		pageDto.setRows(informationList);
+		return pageDto;
 	}
 
 }

+ 79 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/utils/IoUtil.java

@@ -0,0 +1,79 @@
+package com.fuzamei.utils;
+
+import java.io.*;
+
+/**
+ * 
+ * @author wangtao
+ * @description IO工具包
+ * @createTime 2017-12-6 15:22:02
+ *
+ */
+public class IoUtil {
+
+	private IoUtil(){
+		throw new AssertionError("不能实例化 IoUtil");
+	}
+	/**
+	 * 读取输入流为 字节数组
+	 * @param inputStream 输入流
+	 * @param bufferSize 缓存大小
+	 * @return
+	 * @throws IOException
+	 */
+	public static byte[] read(InputStream inputStream, int bufferSize) throws IOException {
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		byte[] buffer = new byte[bufferSize];
+		for (int num = inputStream.read(buffer); num != -1; num = inputStream.read(buffer)) {
+			baos.write(buffer, 0, num);
+		}
+		baos.flush();
+		return baos.toByteArray();
+	}
+	/**
+	 * 读取输入流为字节数组
+	 * @param inputStream 输入流
+	 * @return
+	 * @throws IOException
+	 */
+	public static byte[] read(InputStream inputStream) throws IOException {
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		for (int num = inputStream.read(buffer); num != -1; num = inputStream.read(buffer)) {
+			baos.write(buffer, 0, num);
+		}
+		baos.flush();
+		return baos.toByteArray();
+	}
+	/**
+	 * 写入文件到指定路径
+	 * @param filePath 文件保存路径
+	 * @param data 文件数据
+	 * @throws IOException
+	 */
+	public static void write(String filePath, byte[] data) throws IOException {
+		FileOutputStream outputStream = new FileOutputStream(filePath);
+		outputStream.write(data);
+		outputStream.flush();
+		outputStream.close();
+	}
+	/**
+	 * 以行为单位读取文件,常用于读面向行的格式化文件
+	 * @param filePath 文件路径
+	 * @return 文件内容字符串
+	 * @throws IOException
+	 */
+	public static String readFileByLines(String filePath) throws IOException {
+		StringBuilder sbld = new StringBuilder();
+        File file = new File(filePath);
+		BufferedReader reader = new BufferedReader(new FileReader(file));
+    	String tempString = null;
+        // 一次读入一行,直到读入null为文件结束
+        while ((tempString = reader.readLine()) != null) {
+        	sbld.append(tempString);
+        }
+        reader.close();
+        return sbld.toString();
+    }
+
+}

+ 84 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/utils/OtherUtil.java

@@ -0,0 +1,84 @@
+/**
+ * FileName: OtherUtil
+ * Author: wangtao
+ * Date: 2017/12/15 11:35
+ * Description:
+ */
+package com.fuzamei.utils;
+
+import java.text.StringCharacterIterator;
+import java.util.Map;
+
+/**
+ *
+ *
+ * @author wangtao
+ * @create 2017/12/15
+ *
+ */
+
+public class OtherUtil {
+
+    private OtherUtil() {
+        throw new AssertionError("不能实例化 OtherUtil");
+    }
+
+    /**
+     * 字符串替换,src中的key转换为value
+     * @param src
+     * @param map
+     * @return
+     */
+    public static String replace(String src, Map<String, String> map){
+        if (src != null && src.trim().length() != 0) {
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                src = src.replace(entry.getKey(), entry.getValue());
+            }
+        }
+        return src;
+    }
+    /**
+     * 对src转义编码,src中的key转换为value
+     * @param src
+     * @param map
+     * @return
+     */
+    public static String escape(String src, Map<String, String> map) {
+        if (src != null && src.trim().length() != 0) {
+            StringBuffer sb = new StringBuffer();
+            StringCharacterIterator sci = new StringCharacterIterator(src);
+            for (char c = sci.first(); !Character.isSpaceChar(c); c = sci.next()) {
+                String ch = String.valueOf(c);
+                if (map.containsKey(ch)) {
+                    ch = (String) map.get(ch);
+                }
+                sb.append(ch);
+            }
+            return sb.toString();
+        } else {
+            return "";
+        }
+    }
+    /**
+     * 获取XML字符串中的节点
+     * @param xmlString
+     * @param nodeName
+     * @return
+     */
+    public static String getNodeText(String xmlString, String nodeName) {
+        String beginName = "<" + nodeName + ">";
+        String endName = "</" + nodeName + ">";
+        int beginIndex = xmlString.indexOf(beginName);
+        if (beginIndex == -1) {
+            return "";
+        } else {
+            int endIndex = xmlString.indexOf(endName);
+            if (endIndex == -1) {
+                return "";
+            } else {
+                String nodeValue = xmlString.substring(beginIndex + beginName.length(), endIndex);
+                return nodeValue;
+            }
+        }
+    }
+}

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

@@ -0,0 +1,46 @@
+package com.fuzamei.utils;
+
+import java.util.Random;
+
+/**
+ * 随机数相关方法
+ * @author wangtao
+ * @time 2017年11月16日
+ *
+ */
+public final class RandomUtil {
+
+	private RandomUtil(){
+		throw new AssertionError("不能实例化 RandomUtil");
+	}
+	
+	private static final Random RANDOM = new Random();
+	
+	/**
+	 * 获取指定长度的随机数
+	 * @param length 位数 长度
+	 * @return
+	 */
+	public static String getRandomNumber(int length) {
+		String string;
+		for (string = String.valueOf(Math.abs(RANDOM.nextLong())); string.length() < length; 
+				string = string + String.valueOf(Math.abs(RANDOM.nextLong()))) {
+			;
+		}
+		return string.substring(0, length);
+	}
+	/**
+	 * 获取指定长度的字符串
+	 * @param length
+	 * @return
+	 */
+	public static String getRandomString(int length) {
+		String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+		StringBuilder sb = new StringBuilder();
+		for(int i = 0; i < length; i++) {
+			sb.append(str.charAt(RANDOM.nextInt(str.length())));
+		}
+		return sb.toString();
+	}
+
+}

+ 51 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/utils/ValidationUtil.java

@@ -0,0 +1,51 @@
+package com.fuzamei.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+
+/**
+ * 
+ * @author ylx
+ * @describe 针对hibernate-validator的实体类进行数据校验的工具类
+ */
+public class ValidationUtil {
+	
+	/**
+	 * 
+	* @Title: validate
+	* @Description: TODO(校验一个实体类的所有校验失败信息)
+	* @param @param bo
+	* @param @return    设定文件
+	* @return List<String>    返回的是数据校验的所有校验失败信息,封装在一个list中作为返回值
+	* @author ylx
+	* @date 2017年12月26日 下午3:48:40
+	* @throws
+	* 
+	 */
+	public static <T> List<String> validate(T bo){
+		ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+		Validator validator = factory.getValidator();
+		Set<ConstraintViolation<T>> validateSet = validator.validate(bo);
+		List<String> list=new ArrayList<String>();
+		for (ConstraintViolation<T> validate : validateSet) {
+			list.add(validate.getMessage());
+		}
+		return list;	//包含所有校验出错的信息
+		
+		/*使用hibernate validator出现上面的错误, 需要 注意
+
+		@NotNull 和 @NotEmpty  和@NotBlank 区别
+
+		@NotEmpty 用在集合类上面
+		@NotBlank 用在String上面
+		@NotNull    用在基本类型上*/
+	}
+	
+	
+}

+ 28 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/web/BusinessDeclareAction.java

@@ -7,12 +7,19 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URLEncoder;
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.validation.ConstraintViolation;
+import javax.validation.Valid;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 
 import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,6 +28,9 @@ import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.FieldError;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -28,6 +38,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.multipart.MultipartFile;
 
+import com.alibaba.fastjson.JSON;
 import com.fuzamei.entity.BusinessCheck;
 import com.fuzamei.service.BusinessDeclareService;
 import com.fuzamei.utils.JSONUtil;
@@ -323,6 +334,23 @@ public class BusinessDeclareAction {
 	}
 	
 	
+	/*@RequestMapping(value="/test")
+	@ResponseBody
+	public Map<String, Object> test(@RequestBody String data){
+		try {
+			TestBO testBO = JSON.parseObject(data, TestBO.class);
+			List<String> list=validate(testBO);
+			if(!list.isEmpty()){
+				throw new RuntimeException(list.get(0));
+			}
+			return JSONUtil.getJsonMap(200, true, "成功",null);
+		} catch (Exception e) {
+			return JSONUtil.getJsonMap(200, true, "失败:"+e.getMessage(),null);
+		}
+	}*/
+	
+	
+	
 	
 	/**
 	 * 上传文件功能模块

+ 20 - 10
ccb_fund_trusteeship/src/main/java/com/fuzamei/web/OperationHistoryAction.java

@@ -4,6 +4,7 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Scanner;
 
@@ -15,9 +16,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import com.alibaba.fastjson.JSON;
+import com.fuzamei.entity.OperationHistoryBO;
 import com.fuzamei.service.OperationHistoryService;
 import com.fuzamei.utils.JSONUtil;
 import com.fuzamei.utils.PageDTO;
+import com.fuzamei.utils.ValidationUtil;
 
 
 @Controller
@@ -34,6 +38,7 @@ public class OperationHistoryAction {
 	* @param @param data--前台传递过来的application/json数据
 	* 				传递过来的参数json格式为:
 					{
+						"userId":"xxx",
 						"page":"1",			
 						"account":"",
 						"role":"",
@@ -50,18 +55,23 @@ public class OperationHistoryAction {
 	@RequestMapping(value="/queryOperationHistoryInformation",method=RequestMethod.POST)
 	@ResponseBody
 	public Map<String,Object> queryOperationHistoryInformation(@RequestBody String data){
-		
-		System.out.println("查询操作记录信息....");
-		
-		Map<String, Object> map = JSONUtil.jsonToMap(data);		//将前端传过来的json数据转化为map对象,并将map对象传入service层进行数据校验
-		
-		PageDTO pageDto = operationHistoryService.queryOperationHistoryInformation(map);
-		
-		return JSONUtil.getJsonMap(200, true, "操作成功", pageDto);
+		try {
+			System.out.println("查询操作记录信息....");
+//			Map<String, Object> map = JSONUtil.jsonToMap(data);		//将前端传过来的json数据转化为map对象,并将map对象传入service层进行数据校验
+//			PageDTO pageDto = operationHistoryService.queryOperationHistoryInformation(map);	
+
+			OperationHistoryBO operationHistoryBO = JSON.parseObject(data, OperationHistoryBO.class);
+			List<String> validateList = ValidationUtil.validate(operationHistoryBO);
+			if(!validateList.isEmpty()){
+				throw new RuntimeException(validateList.get(0));	//抛出校验失败异常
+			}
+			PageDTO pageDto = operationHistoryService.queryOperationHistoryInformation(operationHistoryBO);
+			return JSONUtil.getJsonMap(200, true, "查询成功", pageDto);
+		} catch (Exception e) {
+			return JSONUtil.getJsonMap(500, false, "查询失败:"+e.getMessage(), null);
+		}
 	}
 	
-	
-	
 	/*//算数据库中bigint的时间用的
 	public static void main(String[] args) throws ParseException {
 		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");