Browse Source

2017年12月26日代码提交

maamin1 7 years ago
parent
commit
6663a8f199

+ 1 - 1
ccb_fund_trusteeship/.settings/org.eclipse.core.resources.prefs

@@ -1,4 +1,4 @@
 eclipse.preferences.version=1
 encoding//src/main/resources/conf.properties=UTF-8
-encoding//src/main/resources/parameter.properties=UTF-8
+encoding//src/main/resources/messages.properties=UTF-8
 encoding/<project>=UTF-8

+ 8 - 1
ccb_fund_trusteeship/src/main/java/com/fuzamei/dao/UserDao.java

@@ -2,7 +2,6 @@ package com.fuzamei.dao;
 
 import java.util.List;
 
-import javax.annotation.Resource;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
@@ -22,5 +21,13 @@ public class UserDao {
 		// TODO Auto-generated method stub
 		return userMapper.insertUsers(listUsers);
 	}
+	public int addUserToUser(User user) {
+		// TODO Auto-generated method stub
+		return userMapper.addUserToUser(user);
+	}
+	public int addUserToUserRole(User user) {
+		// TODO Auto-generated method stub
+		return userMapper.addUserToUserRole(user);
+	}
 
 }

+ 51 - 12
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/User.java

@@ -3,24 +3,36 @@ package com.fuzamei.entity;
 
 import java.io.Serializable;
 
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 
-import org.hibernate.validator.constraints.NotEmpty;
+import org.hibernate.validator.constraints.NotBlank;
+
 
 
 public class User implements Serializable{
 	private int id;	//主键
+	@NotNull(message = "用户编号不能为空字符串或者null",groups = {USERID.class})
 	private int user_id;	//用户id
-	@NotEmpty(message = "{user.user_name.notnull.message}")
-	private String user_name;	//用户名称
-	@Size(min = 6,max = 8,message = "密码必须为6到8位的数字")
+	@NotBlank(message = "用户名不能为空字符串或者null",groups = {ACCOUNT.class})
+	private String account;	//用户名称
+	@Size(min = 6,max = 8,message = "密码必须为6到10位",groups = {PASSWORD.class})
 	private String password;	//用户密码
+	@NotBlank(message = "随机数不能为空字符串或者null",groups = {RANDOM.class})
 	private String random;		//随机数
 	private String public_key;	//公钥
 	private String private_key;	//私钥
 	private String organization_name;	//机构名称
+	@NotBlank(message = "用户名称不能为空字符串或者null",groups = {PERSONNAME.class})
 	private String person_name;			//人员名称
+	@NotNull(message = "用户角色id不能为空字符串或者null",groups = {ROLEID.class})
 	private int role_id;				//角色id
+	@NotBlank(message = "用户角色名称不能为空字符串或者null",groups = {ROLENAME.class})
+	private String role_name;			//角色名称
+	@NotBlank(message = "签名不能为空字符串或者null",groups = {SIGN.class})
+	private String sign;			//注册时候的签名
+	
 	public int getId() {
 		return id;
 	}
@@ -33,11 +45,11 @@ public class User implements Serializable{
 	public void setUser_id(int user_id) {
 		this.user_id = user_id;
 	}
-	public String getUser_name() {
-		return user_name;
+	public String getAccount() {
+		return account;
 	}
-	public void setUser_name(String user_name) {
-		this.user_name = user_name;
+	public void setAccount(String account) {
+		this.account = account;
 	}
 	public String getPassword() {
 		return password;
@@ -81,13 +93,40 @@ public class User implements Serializable{
 	public void setRole_id(int role_id) {
 		this.role_id = role_id;
 	}
+	public String getRole_name() {
+		return role_name;
+	}
+	public void setRole_name(String role_name) {
+		this.role_name = role_name;
+	}
+	public String getSign() {
+		return sign;
+	}
+	public void setSign(String sign) {
+		this.sign = sign;
+	}
+
 	@Override
 	public String toString() {
-		return "User [id=" + id + ", user_id=" + user_id + ", user_name=" + user_name + ", password=" + password
+		return "User [id=" + id + ", user_id=" + user_id + ", account=" + account + ", password=" + password
 				+ ", random=" + random + ", public_key=" + public_key + ", private_key=" + private_key
 				+ ", organization_name=" + organization_name + ", person_name=" + person_name + ", role_id=" + role_id
-				+ "]";
-	}
-	
+				+ ", role_name=" + role_name + ", sign=" + sign + "]";
+	}
+	//顺序控制
+	public interface USERID{};
+	public interface ACCOUNT{};
+	public interface PASSWORD{};
+	public interface RANDOM{};
+	public interface PERSONNAME{};
+	public interface ROLEID{};
+	public interface ROLENAME{};
+	public interface SIGN{};
+	//该组用于用户登录
+	@GroupSequence({ACCOUNT.class, PASSWORD.class}) 
+	public interface GroupA{}
+	//该组用于添加用户
+	@GroupSequence({USERID.class, ROLEID.class,ROLENAME.class,ACCOUNT.class,PASSWORD.class,PERSONNAME.class,RANDOM.class}) 
+	public interface GroupB{};
 	
 }

+ 4 - 1
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapperInterface/UserInterface.java

@@ -2,11 +2,14 @@ package com.fuzamei.mapperInterface;
 
 import java.util.List;
 
-import org.apache.ibatis.annotations.Param;
 
 import com.fuzamei.entity.User;
 public interface UserInterface {
 	public int getUserCount(User user);
 
 	public int insertUsers(List<User> listUsers);
+
+	public int addUserToUser(User user);
+
+	public int addUserToUserRole(User user);
 }

+ 37 - 8
ccb_fund_trusteeship/src/main/java/com/fuzamei/service/UserService.java

@@ -1,8 +1,7 @@
 package com.fuzamei.service;
 
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
 
 import javax.annotation.Resource;
@@ -13,7 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
 import com.fuzamei.dao.UserDao;
 import com.fuzamei.entity.User;
 import com.fuzamei.utils.JSONUtil;
-import com.fuzamei.utils.UserUtil;
+import com.fuzamei.utils.blockchain.KeyUtils;
 /**
  * 
 * <b>Description:用户登录的service层</b><br> 
@@ -63,16 +62,46 @@ public class UserService {
 	public Map<String, Object> initUserList() {
 		// TODO Auto-generated method stub
 		//封装用户信息到listUsers中
-		List<User> listUsers = UserUtil.getUserList();	
+		/*List<User> listUsers = UserUtil.getUserList();	
 		List<Map<String,Object>> list = UserUtil.getUserRoleList();
 		//将用户信息插入到t_user表中
 		int insertUserCount = userDao.insertUsers(listUsers);
 		if(insertUserCount == 18){	//一共有18个角色
 			
-		}
-		
-		
-		//
+		}*/
 		return null;
 	}
+	/**
+	 * 
+	* <b>Description:添加用户</b><br> 
+	* @param user
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2017年12月26日 下午5:45:31
+	* <br><b>Version:</b> 1.0
+	 */
+	@Transactional
+	public Map<String, Object> addUser(User user) {
+		Map<String,Object> resultMap = new HashMap<String,Object>();
+		// TODO 将公私钥生成出来
+		String password = user.getPassword();
+		String random = user.getRandom();
+		String private_key = KeyUtils.getPrivateKey(password, random);
+		String public_key = KeyUtils.getPublicKey(private_key);
+		user.setPrivate_key(private_key);
+		user.setPublic_key(public_key);
+		// TODO 用户添加到本地数据库
+		int userCount = userDao.addUserToUser(user);
+		int userRoleCount = userDao.addUserToUserRole(user);
+		if((userCount == 1)&&(userRoleCount == 1)){
+			//区块链操作开始
+			//区块链操作结束
+			resultMap = JSONUtil.getJsonMap(200, false, "用户添加成功", null);
+		}
+		else{
+			throw new RuntimeException();
+		}
+		return resultMap;
+	}
 }

+ 1 - 1
ccb_fund_trusteeship/src/main/java/com/fuzamei/utils/UserUtil.java

@@ -115,7 +115,7 @@ public class UserUtil {
 			 * 此处需要进行区块链操作
 			 */
 			user.setUser_id(user_id);
-			user.setUser_name(account);
+			user.setAccount(account);
 			user.setPassword(password);
 			user.setRandom(random);
 			user.setPrivate_key(private_key);

+ 17 - 37
ccb_fund_trusteeship/src/main/java/com/fuzamei/web/UserAction.java

@@ -1,13 +1,11 @@
 package com.fuzamei.web;
 
-import java.io.IOException;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.annotation.Resource;
-import javax.validation.Valid;
 
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.FieldError;
@@ -17,10 +15,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fuzamei.entity.User;
+import com.fuzamei.entity.User.GroupA;
+import com.fuzamei.entity.User.GroupB;
 import com.fuzamei.service.UserService;
 import com.fuzamei.utils.JSONUtil;
 
@@ -52,18 +49,14 @@ public class UserAction {
 	* <br><b>Version:</b> 1.0
 	 */
 	@RequestMapping(value = "/login",method = RequestMethod.POST)
-	public Map<String,Object> login(@Validated @RequestBody User user,BindingResult result){
-		System.out.println("进入用户登录login方法……"+user.getUser_name());
+	public Map<String,Object> login(@Validated(GroupA.class) @RequestBody User user,BindingResult result){
+		System.out.println("进入用户登录login方法……"+user.getAccount());
 		Map<String,Object> resultMap = new LinkedHashMap<String,Object>();	//存放最终返回结果
 		try {
 			if(result.hasErrors()){
 				List<FieldError> errors = result.getFieldErrors();
-				for(FieldError fe : errors){
-					String errorField = fe.getField();	//得到出错的字段
-					String errorMessage = fe.getDefaultMessage();
-					System.out.println("----出错的字段:"+errorField+">>>字段错误信息:"+errorMessage);
-				}
-				System.out.println("未通过校验……"+result.getErrorCount());
+				resultMap = JSONUtil.getJsonMap(12431, false, errors.get(0).getDefaultMessage(),null);
+				return resultMap;
 			}
 			resultMap = userService.login(user);
 		} catch (Exception e) {
@@ -99,33 +92,20 @@ public class UserAction {
 	* <br><b>Version:</b> 1.0
 	 */
 	@RequestMapping(value = "/addUser",method = RequestMethod.POST)
-	public Map<String,Object> addUser(@RequestBody String data){
+	public Map<String,Object> addUser(@Validated(GroupB.class) @RequestBody User user,BindingResult result){
 		System.out.println("添加用户……");
-		Map<String,Object> resultMap = new HashMap<String,Object>();
-		Map<String,Object> paramMap = new HashMap<String,Object>();
-		User user = null;
-		ObjectMapper objMapper = new ObjectMapper();
+		Map<String,Object> resultMap = new HashMap<String,Object>();	//存放最终返回结果
 		try {
-			user = objMapper.readValue(data, User.class);
-		} catch (JsonParseException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-			resultMap = JSONUtil.getJsonMap(12431, false, "json解析错误", null);
-		} catch (JsonMappingException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-			resultMap = JSONUtil.getJsonMap(12431, false, "参数错误", null);
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+			if(result.hasErrors()){
+				resultMap = JSONUtil.getJsonMap(12431, false, result.getFieldErrors().get(0).getDefaultMessage(), null);
+				return resultMap;
+			}
+			resultMap = userService.addUser(user);
+		} catch (Exception e) {
+			// TODO: handle exception
+			resultMap = JSONUtil.getJsonMap(12431, false, "添加用户失败", null);
 		}
-		//参数判断
-//		if(()||()){
-//			
-//		}
-		
-		
-		
+		System.out.println("添加用户结束……");
 		return resultMap;
 	}
 }

+ 4 - 0
ccb_fund_trusteeship/src/main/resources/messages.properties

@@ -0,0 +1,4 @@
+#定义所有错误信息
+user.user_id.notnull.message=用户id不能为空
+user.user_id.notempty.message=用户id不能为空
+user.username.notnull.message=用户名不能为空

+ 0 - 4
ccb_fund_trusteeship/src/main/resources/parameter.properties

@@ -1,4 +0,0 @@
-#定义所有错误信息
-user.user_id.notnull.message = 用户id不能为空
-user.user_id.notempty.message = 用户id不能为空
-user.user_name.notnull.message = 用户名不能为空

+ 1 - 1
ccb_fund_trusteeship/src/main/webapp/WEB-INF/web.xml

@@ -46,7 +46,7 @@
     </init-param>
     <init-param>
       <param-name>contextConfigLocation</param-name>
-      <param-value>classpath:parameter.properties</param-value>
+      <param-value>classpath:messages.properties</param-value>
     </init-param>
   </servlet>
   <servlet-mapping>