Browse Source

用户模块所有代码提交

maamin1 7 years ago
parent
commit
306746fe87

+ 88 - 2
ccb_fund_trusteeship/src/main/java/com/fuzamei/dao/UserDao.java

@@ -1,19 +1,37 @@
 package com.fuzamei.dao;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
-
+import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
 
+import com.fuzamei.entity.AccountInfo;
+import com.fuzamei.entity.Role;
+import com.fuzamei.entity.Token;
 import com.fuzamei.entity.User;
+import com.fuzamei.mapperInterface.AccountInfoInterface;
+import com.fuzamei.mapperInterface.RoleInterface;
+import com.fuzamei.mapperInterface.TokenInterface;
+import com.fuzamei.mapperInterface.UserAccountInterface;
 import com.fuzamei.mapperInterface.UserInterface;
+import com.fuzamei.utils.PageDTO;
 
 @Repository(value = "userDao")
 public class UserDao {
 	@Autowired
 	private UserInterface userMapper;
-	public int getUserCount(User user) {
+	@Autowired
+	private AccountInfoInterface accountInfoInterface;
+	@Autowired
+	private UserAccountInterface userAccountInterface;
+	@Autowired
+	private RoleInterface roleInterface;
+	@Autowired
+	private TokenInterface tokenInterface;
+	public List<User> getUserCount(User user) {
 		// TODO 获取该用户的count
 		return userMapper.getUserCount(user);
 	}
@@ -37,6 +55,74 @@ public class UserDao {
 		// TODO Auto-generated method stub
 		return userMapper.updataRoleById(user);
 	}
+	public PageDTO getUsers(User user,int page,int rows) {
+		// TODO Auto-generated method stub
+		PageDTO pageDTO = new PageDTO();
+		int count = 0;
+		List<User> users = new ArrayList<User>();
+		int startNum = (page-1)*rows;
+		Map<String,Object> mapParam = new HashMap<String,Object>();
+		mapParam.put("role_name", user.getRole_name());
+		mapParam.put("account", user.getAccount());
+		mapParam.put("person_name", user.getPerson_name());
+		mapParam.put("startNum", startNum);
+		mapParam.put("endNum", rows);
+//		return userMapper.getUsers(user);
+		try{
+			users =  userMapper.getUsersByPage(mapParam);
+			count = userMapper.getUsers(mapParam);
+		}catch (Exception e) {
+			// TODO: handle exception
+			e.printStackTrace();
+		}
+		pageDTO.setTotal(count);
+		pageDTO.setRows(users);
+		return pageDTO;
+	}
+	public User findUserById(User user) {
+		// TODO Auto-generated method stub
+		return userMapper.findUserById(user);
+	}
+	public List<AccountInfo> getAllAccount() {
+		// TODO Auto-generated method stub
+		return accountInfoInterface.getAllAccount();
+	}
+	public int insertAccountInfo(List<Map<String, Object>> accountList) {
+		// TODO Auto-generated method stub
+		return accountInfoInterface.insertAccountInfo(accountList);
+	}
+	public int insertUserAccount(List<Map<String, Object>> accountList) {
+		// TODO Auto-generated method stub
+		return userAccountInterface.insertUserAccount(accountList);
+	}
+	public List<Role> getAllRoles() {
+		// TODO Auto-generated method stub
+		return roleInterface.getAllRoles();
+	}
+	public User findUserById(String userId) {
+		// TODO Auto-generated method stub
+		return userMapper.findUserById1(userId);
+	}
+	public Token getTokenById(Token token) {
+		// TODO Auto-generated method stub
+		return tokenInterface.getTokenById(token);
+	}
+	public int insertToken(Token token) {
+		// TODO Auto-generated method stub
+		return tokenInterface.insertToken(token);
+	}
+	public int updateToken(Token token) {
+		// TODO Auto-generated method stub
+		return tokenInterface.updateToken(token);
+	}
+	public List<AccountInfo> getAccountInfoByUser(String userId) {
+		// TODO Auto-generated method stub
+		return accountInfoInterface.getAccountInfoByUser(userId);
+	}
+	public int updateBatchAccountById(Map<String, Map<String, Object>> parameter, List<String> cloumn) {
+		// TODO Auto-generated method stub
+		return accountInfoInterface.updateBatchAccountById(parameter, cloumn);
+	}
 	
 
 }

+ 6 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/AccountInfo.java

@@ -36,4 +36,10 @@ public class AccountInfo {
 	public void setMoney(Double money) {
 		this.money = money;
 	}
+	@Override
+	public String toString() {
+		return "AccountInfo [id=" + id + ", account_id=" + account_id + ", account_name=" + account_name
+				+ ", account_type=" + account_type + ", money=" + money + "]";
+	}
+	
 }

+ 30 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/Role.java

@@ -0,0 +1,30 @@
+package com.fuzamei.entity;
+
+public class Role {
+	private int id;
+	private int roleId;
+	private String roleName;
+	public int getId() {
+		return id;
+	}
+	public void setId(int id) {
+		this.id = id;
+	}
+	public int getRoleId() {
+		return roleId;
+	}
+	public void setRoleId(int roleId) {
+		this.roleId = roleId;
+	}
+	public String getRoleName() {
+		return roleName;
+	}
+	public void setRoleName(String roleName) {
+		this.roleName = roleName;
+	}
+	@Override
+	public String toString() {
+		return "Role [id=" + id + ", roleId=" + roleId + ", roleName=" + roleName + "]";
+	}
+	
+}

+ 30 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/Token.java

@@ -0,0 +1,30 @@
+package com.fuzamei.entity;
+
+public class Token {
+	private int id;
+	private int userId;
+	private String token;
+	public int getId() {
+		return id;
+	}
+	public void setId(int id) {
+		this.id = id;
+	}
+	public int getUserId() {
+		return userId;
+	}
+	public void setUserId(int userId) {
+		this.userId = userId;
+	}
+	public String getToken() {
+		return token;
+	}
+	public void setToken(String token) {
+		this.token = token;
+	}
+	@Override
+	public String toString() {
+		return "Token [id=" + id + ", userId=" + userId + ", token=" + token + "]";
+	}
+	
+}

+ 20 - 3
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/User.java

@@ -2,6 +2,8 @@ package com.fuzamei.entity;
 
 
 
+import java.util.List;
+
 import javax.validation.GroupSequence;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
@@ -28,14 +30,18 @@ public class User{
 	@NotNull(message = "用户角色id不能为空字符串或者null",groups = {ROLEID.class})
 	private int role_id;				//角色id
 	@NotBlank(message = "用户角色名称不能为空字符串或者null",groups = {ROLENAME.class})
+	@NotNull(message = "用户角色名称不能为空字符串或者null",groups = {ROLENAMEA.class})
 	private String role_name;			//角色名称
 	@NotBlank(message = "签名不能为空字符串或者null",groups = {SIGN.class})
 	private String sign;			//注册时候的签名
+	@NotNull(message = "用户添加时间不能为空字符串或者null",groups = {CREATETIME.class})
 	private long create_time;		//创建时间
+	@NotNull(message = "用户更新时间不能为空字符串或者null",groups = {UPDATETIME.class})
 	private long update_time;		//更新时间
 	
 	private double account_balance;//账户余额
 	private String drawing_account;//划款账户
+	private List<Object> drawing_accountList;
 	
 	
 	public double getAccount_balance() {
@@ -137,13 +143,21 @@ public class User{
 		this.update_time = update_time;
 	}
 	
+	public List<Object> getDrawing_accountList() {
+		return drawing_accountList;
+	}
+	public void setDrawing_accountList(List<Object> drawing_accountList) {
+		this.drawing_accountList = drawing_accountList;
+	}
+	
 	@Override
 	public String toString() {
 		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 + ", create_time=" + create_time + ", update_time="
-				+ update_time + "]";
+				+ update_time + ", account_balance=" + account_balance + ", drawing_account=" + drawing_account
+				+ ", drawing_accountList=" + drawing_accountList + "]";
 	}
 
 	//顺序控制
@@ -155,11 +169,14 @@ public class User{
 	public interface ROLEID{};
 	public interface ROLENAME{};
 	public interface SIGN{};
+	public interface ROLENAMEA{};
+	public interface CREATETIME{};
+	public interface UPDATETIME{};
 	//该组用于用户登录
-	@GroupSequence({ACCOUNT.class, PASSWORD.class}) 
+	@GroupSequence({USERID.class,ACCOUNT.class, PASSWORD.class}) 
 	public interface GroupA{}
 	//该组用于添加用户
-	@GroupSequence({USERID.class, ROLEID.class,ROLENAME.class,ACCOUNT.class,PASSWORD.class,PERSONNAME.class,RANDOM.class}) 
+	@GroupSequence({USERID.class, ROLEID.class,ROLENAME.class,ACCOUNT.class,PASSWORD.class,PERSONNAME.class,RANDOM.class,SIGN.class,CREATETIME.class,UPDATETIME.class}) 
 	public interface GroupB{};
 	
 }

+ 36 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapper/AccountInfoMapper.xml

@@ -0,0 +1,36 @@
+<?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.AccountInfoInterface">
+	<select id="getAllAccount" resultType="com.fuzamei.entity.AccountInfo">
+		select * from account_info;
+	</select>
+	<insert id="insertAccountInfo" parameterType="java.util.List">
+		insert into account_info(account_id,account_name,account_type)values
+		<foreach collection="list" item="item" index="index" separator=",">
+			(#{item.account_id},
+			#{item.account_name},
+			#{item.account_type})
+		</foreach>
+	</insert>
+	<select id="getAccountInfoByUser" parameterType="java.lang.String" resultType="com.fuzamei.entity.AccountInfo">
+		select account_id,account_name from account_info where account_id in(
+			select account_id from user_account where user_id = #{userId}
+		);
+	</select>
+	<update id="updateBatchAccountById">
+		update 
+				account_info 
+			set
+			<foreach collection="cloumn" item = "cloumnItem" index = "cloumnIndex" separator=",">
+				${cloumnItem} = 
+				<foreach collection="parameter.keys" item="item" index="index" open="case account_id" close="end" separator=" ">
+					when ${item} then #{parameter.[${item}].[${cloumnItem}]}
+				</foreach>
+			</foreach>
+			where 
+				account_id in 
+			<foreach collection="parameter.keys" item="key" open="(" close=")" separator=",">
+				#{key}
+			</foreach>
+	</update>
+</mapper>

+ 7 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapper/RoleMapper.xml

@@ -0,0 +1,7 @@
+<?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.RoleInterface">
+	<select id="getAllRoles" resultType="com.fuzamei.entity.Role">
+		select role_id as roleId,role_name as roleName from t_role;
+	</select>
+</mapper>

+ 13 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapper/TokenMapper.xml

@@ -0,0 +1,13 @@
+<?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.TokenInterface">
+	<select id="getTokenById" parameterType="com.fuzamei.entity.Token" resultType="com.fuzamei.entity.Token">
+		select * from token where user_id = #{userId};
+	</select>
+	<insert id="insertToken" parameterType="com.fuzamei.entity.Token">
+		insert into token(user_id,token)values(#{userId},#{token});
+	</insert>
+	<update id="updateToken" parameterType="com.fuzamei.entity.Token">
+		update token set token = #{token} where user_id = #{userId};
+	</update>
+</mapper>

+ 11 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapper/UserAccountMapper.xml

@@ -0,0 +1,11 @@
+<?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.UserAccountInterface">
+	<insert id="insertUserAccount" parameterType="java.util.List">
+		insert into user_account(user_id,account_id)values
+		<foreach collection="list" item="item" index="index" separator=",">
+			(#{item.user_id},
+			#{item.account_id})
+		</foreach>
+	</insert>
+</mapper>

+ 107 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapper/UserMapper.xml

@@ -0,0 +1,107 @@
+<?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.UserInterface">
+	<select id="getUserCount" parameterType="com.fuzamei.entity.User" resultType="com.fuzamei.entity.User">
+		SELECT
+			a.user_id,
+			b.role_id,
+			c.role_name,
+			a.account,
+			a.password,
+			a.person_name,
+			a.account_balance,
+			a.random
+		FROM
+			t_user a
+		LEFT JOIN user_role b ON a.user_id = b.user_id
+		LEFT JOIN t_role c ON b.role_id = c.role_id 
+		where a.account = #{account} and a.password = #{password};
+	</select>
+	<insert id="insertUsers">
+		INSERT INTO t_user (
+			user_id,
+			user_name,
+			password,
+			random,
+			public_key,
+			private_key,
+			organization_name,
+			person_name
+		)
+		VALUES
+		<foreach collection="list" item = "item" index="index" separator=",">
+			(#{item.user_id},
+			#{item.user_name},
+			#{item.password},
+			#{item.random},
+			#{item.public_key},
+			#{item.private_key},
+			#{item.organization_name},
+			#{item.person_name})
+		</foreach>
+	</insert>
+	<insert id="addUserToUser" parameterType="com.fuzamei.entity.User">
+		insert into t_user(user_id,account,password,person_name,random,public_key,private_key,account_balance,create_time,update_time)values(#{user_id},#{account},#{password},#{person_name},#{random},#{public_key},#{private_key},#{account_balance},#{create_time},#{update_time});
+	</insert>
+	<insert id="addUserToUserRole" parameterType="com.fuzamei.entity.User">
+		insert into user_role(user_id,role_id)values(#{user_id},#{role_id});
+	</insert>
+	<update id="updateUserById" parameterType="com.fuzamei.entity.User">
+		update t_user set account = #{account},password = #{password},person_name = #{person_name},account_balance = #{account_balance},update_time = #{update_time} where user_id = #{user_id};
+	</update>
+	<update id="updataRoleById" parameterType="com.fuzamei.entity.User">
+		update user_role set role_id = #{role_id} where user_id = #{user_id};
+	</update>
+	<select id="getUsers" parameterType="java.util.Map" resultType="int">
+		SELECT
+			count(1)
+		FROM
+			t_user a
+		LEFT JOIN user_role b ON a.user_id = b.user_id
+		LEFT JOIN t_role c ON b.role_id = c.role_id
+		<where>
+			<if test="role_name!=null and role_name!=''">
+				and c.role_name = #{role_name}
+			</if>
+			<if test="account!=null and account!=''">
+				and a.account = #{account}
+			</if>
+			<if test="person_name!=null and person_name!=''">
+				and a.person_name = #{person_name}
+			</if>
+		</where>
+	</select>
+	<select id="getUsersByPage" parameterType="java.util.Map" resultType="com.fuzamei.entity.User">
+		SELECT
+			a.user_id,
+			c.role_name,
+			a.account,
+			a.password,
+			a.person_name,
+			a.create_time,
+			a.update_time
+		FROM
+			t_user a
+		LEFT JOIN user_role b ON a.user_id = b.user_id
+		LEFT JOIN t_role c ON b.role_id = c.role_id
+		<where>
+			<if test="role_name!=null and role_name!=''">
+				and c.role_name = #{role_name}
+			</if>
+			<if test="account!=null and account!=''">
+				and a.account = #{account}
+			</if>
+			<if test="person_name!=null and person_name!=''">
+				and a.person_name = #{person_name}
+			</if>
+		</where>
+		limit #{startNum},#{endNum};
+	</select>
+	<select id="findUserById" parameterType="com.fuzamei.entity.User" resultType = "com.fuzamei.entity.User">
+		select * from t_user where user_id = #{user_id};
+	</select>
+	<select id="findUserById1" parameterType="java.lang.String" resultType = "com.fuzamei.entity.User">
+		select a.user_id,b.role_id,c.role_name,a.account,a.password,a.person_name,a.account_balance from t_user a LEFT JOIN user_role b ON a.user_id = b.user_id LEFT JOIN t_role c ON b.role_id = c.role_id
+		 where a.user_id = #{user_id};
+	</select>
+</mapper>

+ 10 - 2
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapperInterface/UserInterface.java

@@ -1,11 +1,11 @@
 package com.fuzamei.mapperInterface;
 
 import java.util.List;
-
+import java.util.Map;
 
 import com.fuzamei.entity.User;
 public interface UserInterface {
-	public int getUserCount(User user);
+	public List<User> getUserCount(User user);
 
 	public int insertUsers(List<User> listUsers);
 
@@ -18,4 +18,12 @@ public interface UserInterface {
 	public int updateUserById(User user);
 
 	public int updataRoleById(User user);
+
+	public int getUsers(Map<String,Object> user);
+
+	public List<User> getUsersByPage(Map<String,Object> user);
+
+	public User findUserById(User user);
+
+	public User findUserById1(String userId);
 }

+ 168 - 15
ccb_fund_trusteeship/src/main/java/com/fuzamei/service/UserService.java

@@ -1,18 +1,26 @@
 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 java.util.UUID;
 
 import javax.annotation.Resource;
-import javax.management.RuntimeErrorException;
 
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.fuzamei.dao.UserDao;
+import com.fuzamei.entity.AccountInfo;
+import com.fuzamei.entity.Role;
+import com.fuzamei.entity.Token;
 import com.fuzamei.entity.User;
 import com.fuzamei.utils.JSONUtil;
+import com.fuzamei.utils.PageDTO;
 import com.fuzamei.utils.blockchain.KeyUtils;
 /**
  * 
@@ -40,13 +48,33 @@ public class UserService {
 	* <br><b>Date:</b> 2017年12月25日 上午10:36:10
 	* <br><b>Version:</b> 1.0
 	 */
+	@Transactional
 	public Map<String, Object> login(User user) {
 		// TODO 检查用户的用户名、密码和随机数,能不能对应得上
 		Map<String,Object> resultMap = new LinkedHashMap<String,Object>();
-		int count = userDao.getUserCount(user);
+		List<User> userInfo = userDao.getUserCount(user);
 		resultMap = JSONUtil.getJsonMap(12431, false, "用户登录失败", null);
-		if(count == 1){
-			resultMap = JSONUtil.getJsonMap(200, true, "用户登录成功", null);
+		Token token1 = new Token();
+		if(userInfo.size() == 1){
+			String tokenRandom = UUID.randomUUID().toString().replace("-", "");
+			//更新token
+			token1.setUserId(user.getUser_id());
+			token1.setToken(tokenRandom);
+			Token token = userDao.getTokenById(token1);
+			if(token == null){
+				int tokenCount = userDao.insertToken(token1);
+				if(tokenCount != 1){
+					throw new RuntimeException();
+				}
+			}
+			else{
+				int updateCount = userDao.updateToken(token1);
+				if(updateCount != 1){
+					throw new RuntimeException();
+				}
+			}
+			
+			resultMap = JSONUtil.getJsonMap(200, true, "用户登录成功", userInfo);
 		}
 		return resultMap;
 	}
@@ -85,41 +113,166 @@ public class UserService {
 	@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);
+		String accounts = user.getDrawing_account();
+		String sign = user.getSign();
+		int userId = user.getUser_id();
+		List<Map<String,Object>> accountList = new ArrayList<Map<String,Object>>();
+		int accountSize = 0;
+		int accountInfoCount = 0;
+		int userAccountCount = 0;
 		user.setPrivate_key(private_key);
 		user.setPublic_key(public_key);
-		long currentTime = System.currentTimeMillis();
-		user.setCreate_time(currentTime);
-		user.setUpdate_time(currentTime);
-		// TODO 用户添加到本地数据库
+		User user1 = userDao.findUserById(user);
+		if(user1 != null){
+			resultMap = JSONUtil.getJsonMap(200, false, "用户已存在,不能重复添加", null);
+			return resultMap;
+		}
+		//查询数据库所有账户
+		List<AccountInfo> accountInfo = userDao.getAllAccount();
+		Map<String,Object> accountIdMap = new HashMap<String,Object>();
+		for(int i = 0; i < accountInfo.size(); i ++){
+			accountIdMap.put(accountInfo.get(i).getAccount_id().toString(), "value");
+		}
+		//用户添加到本地数据库
 		int userCount = userDao.addUserToUser(user);
 		int userRoleCount = userDao.addUserToUserRole(user);
-		if((userCount == 1)&&(userRoleCount == 1)){
-			//区块链操作开始
-			//区块链操作结束
-			resultMap = JSONUtil.getJsonMap(200, false, "用户添加成功", null);
+		//将账户文本款中参数按照“,”进行分隔
+		if((accounts != null)&&(!"".equals(accounts))){
+			String[] accountArray =accounts.split(",");	
+			accountSize = accountArray.length;
+			for(int i = 0; i < accountSize; i ++){
+				String account_name = accountArray[i];
+				String accontId = String.valueOf((int)((Math.random()*9+1)*100000));	
+				Map<String,Object> map = new HashMap<String,Object>();
+				map.put("user_id", userId);
+				map.put("account_id", accontId);
+				map.put("account_name", account_name);
+				map.put("account_type", "划转账户");
+				if(accountIdMap.get(accontId) == null){
+					accountList.add(map);
+				}
+			}
+		}
+		if(accountList.size() != 0){
+			accountInfoCount = userDao.insertAccountInfo(accountList);
+			userAccountCount = userDao.insertUserAccount(accountList);
+		}
+		if((userCount == 1)&&(userRoleCount == 1)&&(accountInfoCount == accountSize)&&(userAccountCount == accountSize)){
+			/** 正式环境要放开注释 **/
+//			ProtobufBean protobufBean = BlockChainUtil.getProtobufBean(sign);
+//			String result = BlockChainUtil.sendPostParam(protobufBean);
+//			boolean flag = BlockChainUtil.vilaResult(result);
+			boolean flag = true;
+			if(!flag){
+				throw new RuntimeException();
+			}
+			resultMap = JSONUtil.getJsonMap(200, true, "用户添加成功", null);
 		}
 		else{
 			throw new RuntimeException();
 		}
 		return resultMap;
 	}
+	/**
+	 * 
+	* <b>Description:编辑用户信息</b><br> 
+	* @param user
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月9日 上午11:24:47
+	* <br><b>Version:</b> 1.0
+	 */
 	@Transactional
 	public Map<String, Object> editUser(User user) {
 		Map<String,Object> resultMap = new HashMap<String,Object>();
 		// TODO Auto-generated method stub
+		List<Object> accounts = user.getDrawing_accountList();
+		List<AccountInfo> accountList = new ArrayList<AccountInfo>();
+		Map<String, Map<String, Object>> mapTT = new HashMap<String, Map<String,Object>>();
+		List<String> cloumn = new ArrayList<String>();
+		if((accounts != null)&&(!"".equals(accounts))){
+			String accountsString = JSONArray.toJSONString(accounts);
+			accountList = JSONArray.parseArray(accountsString, AccountInfo.class);
+			System.out.println(">>>"+accountList);
+			for(int i = 0;i < accountList.size(); i ++){
+				Map<String,Object> parameter = new HashMap<String,Object>();
+				String accountId = String.valueOf(accountList.get(i).getAccount_id());
+				String accountName = accountList.get(i).getAccount_name();
+				parameter.put("account_id", accountId);
+				parameter.put("account_name", accountName);
+				mapTT.put(accountId, parameter);
+			}
+			cloumn.add("account_id");
+			cloumn.add("account_name");
+		}
+		int updateAccountCount = userDao.updateBatchAccountById(mapTT, cloumn);
 		int countUser = userDao.updateUserById(user);
 		int countRole = userDao.updataRoleById(user);
-		if((countUser == 1)&&(countRole == 1)){
-			resultMap = JSONUtil.getJsonMap(200, false, "用户信息修改成功", null);
+		if((countUser == 1)&&(countRole == 1)&&(updateAccountCount == accountList.size())){
+			resultMap = JSONUtil.getJsonMap(200, true, "用户信息修改成功", null);
 		}
 		else{
 			throw new RuntimeException("blockchain error!");
 		}
 		return resultMap;
 	}
+	/**
+	 * 
+	* <b>Description:查询所有用户信息</b><br> 
+	* @param user
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月9日 上午11:27:53
+	* <br><b>Version:</b> 1.0
+	 */
+	public PageDTO getUsers(User user,int page,int rows) {
+		return userDao.getUsers(user,page,rows);
+	}
+	/**
+	 * 
+	* <b>Description:获取所有角色信息列表</b><br> 
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月10日 下午4:43:54
+	* <br><b>Version:</b> 1.0
+	 */
+	public List<Role> getAllRoles() {
+		// TODO Auto-generated method stub
+		return userDao.getAllRoles();
+	}
+	/**
+	 * 
+	* <b>Description:通过用户id查询用户信息(包括用户的账户信息)</b><br> 
+	* @param userId
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月10日 下午5:21:59
+	* <br><b>Version:</b> 1.0
+	 */
+	public Map<String,Object> findUserById(String userId) {
+		// TODO Auto-generated method stub
+//		return userDao.findUserById(userId);
+		Map<String,Object> map = new LinkedHashMap<String,Object>();
+		User user = new User();
+		List<AccountInfo> accountInfo = new ArrayList<AccountInfo>();
+		try {
+			user = userDao.findUserById(userId);
+			accountInfo = userDao.getAccountInfoByUser(userId);
+		} catch (Exception e) {
+			// TODO: handle exception
+			e.printStackTrace();
+		}
+		map.put("user", user);
+		map.put("accountData", accountInfo);
+		return map;
+	}
 }

+ 1 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/servlet/ConfigLoadListener.java

@@ -41,6 +41,7 @@ public class ConfigLoadListener implements ServletContextListener{
 	 */
 	@Override
 	public void contextInitialized(ServletContextEvent arg0) {
+		System.out.println("--------------------");
 		// TODO Auto-generated method stub
 		/*ProtobufBean protobufBean = ProtobufUtils.initPlatform();	
 		String result = BlockChainUtil.sendPostParam(protobufBean);

+ 43 - 110
ccb_fund_trusteeship/src/main/java/com/fuzamei/utils/blockchain/BlockChainUtil.java

@@ -12,70 +12,29 @@ import com.fuzamei.http.HttpRequest;
 import com.fuzamei.utils.JSONUtil;
 import com.fuzamei.utils.ReadConfUtil;
 
-/** 
-
- * @ClassName: BlockChainUtil 
-
- * @Description: TODO(这里用一句话描述这个类的作用) 
-
- * @author maamin 
-
- * @date 2017-8-21 下午1:35:52 
-
+/**
  * 
- 
-
+* <b>Description:区块链的操作类</b><br> 
+* @Note
+* <b>Author:maamin
+* @version 1.0
+* @Note
+* <b>ProjectName:</b> ccb_fund_trusteeship
+* <br><b>PackageName:</b> com.fuzamei.utils.blockchain
+* <br><b>ClassName:</b> BlockChainUtil
+* <br><b>Date:</b> 2018年1月10日 下午4:20:50
  */
 @Component
 public class BlockChainUtil {
-/**
-	
-	* @Title: sendPost 
-	
-	* @Description: TODO(像区块链发送数据) 
-	
-	* @param @return    signdata:注册的签名
-	
-	* @return String    返回类型 
-	
-	* @throws
-	 */
-	/*public static boolean sendPostParam(ProtobufBean protobufBean){
-		HttpRequest httpRequest = new HttpRequest();
-		boolean flag = false;
-		String signdata = protobufBean.getSignature();
-		 String[] params = new String[1];
-         params[0] = signdata;
-         String jsonstr = JSON.toJSONString(new RequestAccountBean("2.0", "broadcast_tx_commit", null, params));
-         try {
-			String result =  httpRequest.sendPost("http://114.55.0.107:46657", jsonstr);
-			System.out.println("区块链反馈的结果:"+result);
-			if(result!=null){	//成功
-				flag =  true;
-			}
-			else{
-				flag = false;
-			}
-		} catch (Exception e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-			flag = false;
-		}
-         return flag;
-	}*/
 	/**
 	 * 
-	
-	* @Title: sendPostParam 
-	
-	* @Description: TODO(放回区块链的结果) 
-	
-	* @param @param protobufBean
-	* @param @return    设定文件 
-	
-	* @return String    返回类型 
-	
-	* @throws
+	* <b>Description:将签名转发给区块链</b><br> 
+	* @param protobufBean
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月10日 下午4:21:20
+	* <br><b>Version:</b> 1.0
 	 */
 	public static String  sendPostParam(ProtobufBean protobufBean){
 		HttpRequest httpRequest = new HttpRequest();
@@ -87,7 +46,6 @@ public class BlockChainUtil {
          String jsonstr = JSON.toJSONString(new RequestAccountBean("2.0", "broadcast_tx_commit", null, params));
          try {
 			result =  httpRequest.sendPost(blockUrl, jsonstr);
-			System.out.println("----------区块链返回的结果-------"+result);
 		} catch (Exception e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
@@ -96,62 +54,22 @@ public class BlockChainUtil {
 	}
 	/**
 	 * 
-	
-	* @Title: getHash 
-	
-	* @Description: TODO(从区块链返回的结果中得到hash值,错误,返回error的信息)----使用与最早的区块链解析的结果,ip为107 
-	* 判断逻辑:
-	* 先判断error,存在值,不用管,表示请求就错误了
-	* error为空,在判断code是否为0,为0表示成功,否则表示失败
-	
-	* @param @param jsonData
-	* @param @return    设定文件 
-	
-	* @return String    返回类型 
-	
-	* @throws
-	 */
-	/*public static boolean vilaResult(String jsonData){
-		boolean flag = false;
-		//json字符串转换成Map
-		Map<String,Object> map = (Map<String,Object>)JSON.parse(jsonData);
-		//先拿到error的值
-		String errorValue = map.get("error").toString();
-		if(!"".equals(errorValue)){	//失败
-			flag = false;
-		}
-		else{	//
-			//取出code,判断是否为0
-			String result = map.get("result").toString();
-			if(result.indexOf("\"code\":0")>-1){	//成功
-				flag = true;
-			}
-			else{
-				flag = false;
-			}
-		}
-		return flag;
-	}*/
-	/**
-	 * 
-	* @Title: vilaResult
-	* @Description: TODO 判断区块链返回的是否成功---该方法适用于新合约
-	* @param @param jsonData
-	* @param @return
-	* @return boolean
-	* @author: Ma Amin
-	* @date: 2017-9-11 下午3:07:15
+	* <b>Description:验证区块链返回的结果是否成功,true:成功,false:失败</b><br> 
+	* @param jsonData
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月10日 下午4:22:37
+	* <br><b>Version:</b> 1.0
 	 */
 	public static boolean vilaResult(String jsonData){
 		boolean flag = false;
 		Map<String,Object> map = JSONUtil.jsonToMap(jsonData);	//总的map
-		//得到第一个code的值
 		String result = map.get("result").toString();	//得到result节点
 		Map<String,Object> resultMap = JSONUtil.jsonToMap(result);
 		String check_tx = resultMap.get("check_tx").toString();
 		Map<String,Object> check_txMap = JSONUtil.jsonToMap(check_tx);
 		String code1 = check_txMap.get("code").toString();
-		//得到第二个code的值
 		String deliver_tx = resultMap.get("deliver_tx").toString();
 		Map<String,Object> deliver_txMap = JSONUtil.jsonToMap(deliver_tx);
 		String code2 = deliver_txMap.get("code").toString();
@@ -163,7 +81,7 @@ public class BlockChainUtil {
 	/**
 	 * 
 	* @Title: sendBlockChain
-	* @Description: TODO 发送签名到区块链
+	* @Description: TODO 发送签名直接转发到区块链
 	* @param @param qianming
 	* @param @return
 	* @return boolean
@@ -180,15 +98,30 @@ public class BlockChainUtil {
 		protobufBean.setSignature(mma.get("signdata").toString());
 		String result = sendPostParam(protobufBean);
 		boolean flag2 = vilaResult(result);	//区块链返回过来的结果
-		
 		if(flag2){
 			flag = true;
 		}
 		return flag;
 		
 	}
-	
-	
+	/**
+	 * 
+	* <b>Description:通过sign拿到protobufBean</b><br> 
+	* @param sign
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月10日 下午4:19:21
+	* <br><b>Version:</b> 1.0
+	 */
+	public static ProtobufBean getProtobufBean(String sign){
+		ProtobufBean protobufBean = new ProtobufBean();
+		Map<String, Object> signMap = JSONUtil.jsonToMap(sign);
+		long instructionId = Long.parseLong(signMap.get("sid").toString());
+		protobufBean.setInstructionId(instructionId);
+		protobufBean.setSignature(signMap.get("signdata").toString());
+		return protobufBean;
+	}
 	public static void main(String[] args) {
 		
 	}

+ 83 - 2
ccb_fund_trusteeship/src/main/java/com/fuzamei/web/UserAction.java

@@ -1,11 +1,13 @@
 package com.fuzamei.web;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.FieldError;
@@ -13,13 +15,16 @@ 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;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.fuzamei.entity.Role;
 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;
+import com.fuzamei.utils.PageDTO;
 
 /**
  * 
@@ -38,6 +43,9 @@ import com.fuzamei.utils.JSONUtil;
 public class UserAction {
 	@Resource(name = "userService")
 	private UserService userService;
+	int page = 1;
+	int rows = 10;
+	HttpServletRequest request;
 	/**
 	 * 
 	* <b>Description:用户登录方法</b><br> 
@@ -103,6 +111,7 @@ public class UserAction {
 			resultMap = userService.addUser(user);
 		} catch (Exception e) {
 			// TODO: handle exception
+			e.printStackTrace();
 			resultMap = JSONUtil.getJsonMap(12431, false, "添加用户失败", null);
 		}
 		System.out.println("添加用户结束……");
@@ -120,7 +129,7 @@ public class UserAction {
 	 */
 	@RequestMapping(value = "/editUser",method = RequestMethod.POST)
 	public Map<String,Object> editUser(@Validated(GroupB.class) @RequestBody User user,BindingResult result){
-		Map<String,Object> resultMap = new HashMap<String,Object>();	//存放最终的结果
+		Map<String,Object> resultMap = new HashMap<String,Object>();
 		if(result.hasErrors()){
 			resultMap = JSONUtil.getJsonMap(12431, false,result.getFieldErrors().get(0).getDefaultMessage() , null);
 			return resultMap;
@@ -129,7 +138,79 @@ public class UserAction {
 			resultMap = userService.editUser(user);
 		}catch(Exception e){
 //			System.out.println("错误信息:"+e.getMessage());
-			resultMap = JSONUtil.getJsonMap(12431, false, "编辑用户信息失败:", null);
+			resultMap = JSONUtil.getJsonMap(12431, false, "编辑用户信息失败", null);
+		}
+		return resultMap;
+	}
+	/**
+	 * 
+	* <b>Description:查询用户信息</b><br> 
+	* @param user
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月9日 上午11:07:46
+	* <br><b>Version:</b> 1.0
+	 */
+	@RequestMapping(value = "/getUsers",method = RequestMethod.POST)
+	public Map<String,Object> getUsers(@RequestBody User user){
+		System.out.println("查询用户列表信息……");
+		Map<String,Object> resultMap = new HashMap<String,Object>();
+		PageDTO pageDTO = new PageDTO();
+		try {
+			pageDTO = userService.getUsers(user,page,rows);
+			resultMap = JSONUtil.getJsonMap(200, true, "查询用户信息成功", pageDTO);
+		} catch (Exception e) {
+			// TODO: handle exception
+			e.printStackTrace();
+			resultMap = JSONUtil.getJsonMap(12431, false, "查询用户信息报错", null);
+		}
+		return resultMap;
+	}
+	/**
+	 * 
+	* <b>Description:获取所有角色信息</b><br> 
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月10日 下午5:36:10
+	* <br><b>Version:</b> 1.0
+	 */
+	@RequestMapping(value = "/getAllRoles",method = RequestMethod.GET)
+	public Map<String,Object> getAllRoles(){
+		Map<String,Object> resultMap = new LinkedHashMap<String,Object>();
+		List<Role> roles = new ArrayList<Role>();
+		try {
+			roles = userService.getAllRoles();
+			resultMap = JSONUtil.getJsonMap(200, true, "获取角色信息成功", roles);
+		} catch (Exception e) {
+			// TODO: handle exception
+			e.printStackTrace();
+			resultMap = JSONUtil.getJsonMap(12431, false, "获取角色信息失败", roles);
+		}
+		return resultMap;
+	}
+	/**
+	 * 
+	* <b>Description:通过id查询用户信息</b><br> 
+	* @param userId
+	* @return
+	* @Note
+	* <b>Author:maamin
+	* <br><b>Date:</b> 2018年1月10日 下午5:36:21
+	* <br><b>Version:</b> 1.0
+	 */
+	@RequestMapping(value = "/findUserById",method = RequestMethod.GET)
+	public Map<String,Object> findUserById(@RequestParam(value = "userId") String userId){
+		Map<String,Object> resultMap = new LinkedHashMap<String,Object>();
+		Map<String,Object> result = new LinkedHashMap<String,Object>();
+		try {
+			result = userService.findUserById(userId);
+			resultMap = JSONUtil.getJsonMap(200, true, "查询用户信息成功", result);
+		} catch (Exception e) {
+			// TODO: handle exception
+			e.printStackTrace();
+			resultMap = JSONUtil.getJsonMap(12431, false, "查询用户信息失败", result);
 		}
 		return resultMap;
 	}