chb %!s(int64=7) %!d(string=hai) anos
pai
achega
3ac025976f

+ 16 - 13
saicLogistics/src/main/java/com/fuzamei/mapper/UserMapper.xml

@@ -16,10 +16,7 @@
 		select * from users where user_id = #{userIdb} or  username = #{username}
 	</select>
 	
-	<!--先去数据库查询 看是否已有的账号不能在修改了  -->
-	<select id="findUserByuserIdandusername" parameterType="com.fuzamei.entity.User" resultType = "int">
-		select count(*) from users where username = #{username}
-	</select>
+
 	<!--根据用户id  查询角色名称  --><!-- ??????????待待删??? -->
 	<select id="selectRoleNameByuserId">
 		select r.role_name from   users y left  join  role r on r.role_id=y.role_id  where user_id=1003
@@ -76,15 +73,21 @@
 		 </where>)te 
 	</select>
 	
-	<!--根据用户id修改角色,账号,密码,名称  -->
-	<update id="updateAccountByUserId" parameterType="com.fuzamei.entity.User">
-		update users set  
-		<if test="username!=null">
-			username=#{username},
-		</if>
-		password=#{password} , person_name=#{personName},update_time=#{updateTime} where user_id=#{userIdb}
-	</update>
-	  
+	<!--根据用户id修改,账号,密码,名称  -->
+ 	<update id="updateAccountByUserId" parameterType="com.fuzamei.entity.User">
+		update users set username=#{username},password=#{password} , person_name=#{personName},update_time=#{updateTime} where user_id=#{userIdb}
+	</update> 
+	
+	<!--根据用户id修改,账号,密码,名称222  -->
+<!-- 	<update id="updateAccountByUserId" parameterType="com.fuzamei.entity.User">
+		update users set password=#{password} , person_name=#{personName},update_time=#{updateTime} where user_id=#{userIdb}
+	</update>  -->
+	
+	<!--先去数据库查询 看是否已有的账号不能在修改了  -->
+	<select id="findUserByuserIdandusername" parameterType="com.fuzamei.entity.User" resultType = "int">
+		select count(*) from users where  username = #{username} and user_id!=#{userIdb}
+	</select>
+	
 	<!--参数类型为1001,1002,1003等, 批量删除 -->
 	<delete id="deleteFromUserId" parameterType="string">
 		delete  from   users   where  user_id in 

+ 4 - 4
saicLogistics/src/main/java/com/fuzamei/service/serviceImpl/UserServiceImpl.java

@@ -144,12 +144,12 @@ public class UserServiceImpl  implements  UserService {
 		user.setOperationTime(currentTime);//操作时间
 		user.setHash(hash);//操作hash
 		userMapper.insertOperationHistoryOfDelete(user);//插入到操作记录表去
-		ProtobufBean protobufBean = blockChainUtil.getProtobufBean(user.getSign());
+		/*ProtobufBean protobufBean = blockChainUtil.getProtobufBean(user.getSign());
 		String result = blockChainUtil.sendPostParam(protobufBean);
-		boolean flag = blockChainUtil.vilaResult(result);
-		//boolean flag = blockChainUtil.sendBlockChain(user.getSign());//发送签名直接转发到区块链
+		boolean flag = blockChainUtil.vilaResult(result);*/
+		boolean flag = blockChainUtil.sendBlockChain(user.getSign());//发送签名直接转发到区块链
 		if(!flag) {
-			 throw new RuntimeException("区块链操作失败:"+result);	
+			 throw new RuntimeException("区块链操作失败:");	
 		}
 	}
 

+ 66 - 0
saicLogistics/src/main/java/com/fuzamei/util/HexStringUtil.java

@@ -0,0 +1,66 @@
+/**
+ * 
+ */
+package com.fuzamei.util;
+
+/**
+ * FileName: HexStringUtil.java
+ * @Description :TODO
+ * @author 创建人 王斌
+ * @date 创建时间 2017-12-6上午11:41:37
+ * @version v1.0
+ *
+ * Modification  History:
+ * Date              Author           Version        
+ * -------------------------------------------------
+ * 2017-12-6           王斌                                          @version          
+ *
+ * Why & What is modified:
+ */
+public class HexStringUtil {
+	
+	/**
+	 * 字符串转换成为16进制(无需Unicode编码)
+	 * @param str
+	 * @return
+	 */
+	public static String stringToHexString(String str) {
+	    char[] chars = "0123456789ABCDEF".toCharArray();
+	    StringBuilder sb = new StringBuilder();
+	    byte[] bs = str.getBytes();
+	    int bit;
+	    for (int i = 0; i < bs.length; i++) {
+	        bit = (bs[i] & 0x0f0) >> 4;
+	        sb.append(chars[bit]);
+	        bit = bs[i] & 0x0f;
+	        sb.append(chars[bit]);
+	        // sb.append(' ');
+	    }
+	    return sb.toString().trim();
+	}
+  
+    /**
+     * 16进制直接转换成为字符串(无需Unicode解码)
+     * @param hexStr
+     * @return
+     */
+    public static String hexStringToString(String hexStr) {
+        String str = "0123456789ABCDEF";
+        char[] hexs = hexStr.toCharArray();
+        byte[] bytes = new byte[hexStr.length() / 2];
+        int n;
+        for (int i = 0; i < bytes.length; i++) {
+            n = str.indexOf(hexs[2 * i]) * 16;
+            n += str.indexOf(hexs[2 * i + 1]);
+            bytes[i] = (byte) (n & 0xff);
+        }
+        return new String(bytes);
+    }
+    public static void main(String[] args) {
+    	
+    	String str = "MEUCIGNHfjvt";
+    	System.out.println(str.length()+"字符串转换成16进制-->数");
+    	String result = hexStringToString("706C6174666F726D206578697375");
+    	System.out.println(result+"16进制转换成String");
+	}
+}

+ 43 - 2
saicLogistics/src/main/java/com/fuzamei/util/blockchain/BlockChainUtil.java

@@ -3,12 +3,14 @@
  */
 package com.fuzamei.util.blockchain;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.springframework.stereotype.Component;
 
 import com.alibaba.fastjson.JSON;
 import com.fuzamei.http.HttpRequest;
+import com.fuzamei.util.HexStringUtil;
 import com.fuzamei.util.JSONUtil;
 import com.fuzamei.util.ReadConfUtil;
 
@@ -121,7 +123,46 @@ public class BlockChainUtil {
 		protobufBean.setSignature(signMap.get("signdata").toString());
 		return protobufBean;
 	}
-	public static void main(String[] args) {
-		
+	
+	/**
+	 * 解析错误信息  
+	 * @param qianming
+	 * @return
+	 */
+	public Map<String, Object> sendBlockChain2(String qianming){
+		Map<String, Object> map = new HashMap<String, Object>();
+		boolean flag = false;	//区块链成功返回true,失败返回false,默认返回false
+		String fruit = "";
+		ProtobufBean protobufBean = new ProtobufBean();		//签名对象  
+		Map<String, Object> mma = JSONUtil.jsonToMap(qianming);
+		long instructionId = Long
+				.parseLong(mma.get("sid").toString());
+		protobufBean.setInstructionId(instructionId);
+		protobufBean.setSignature(mma.get("signdata").toString());
+		String result = sendPostParam(protobufBean);
+		System.out.println(result);
+		flag = vilaResult(result);	//区块链返回过来的结果
+		Map<String, Object> signMap = JSONUtil.jsonToMap(result);
+		Map<String, Object> resultMap = JSONUtil.jsonToMap(signMap.get("result").toString());
+		Map<String, Object> check_tx = JSONUtil.jsonToMap(resultMap.get("check_tx").toString());
+		Map<String, Object> deliver_tx = JSONUtil.jsonToMap(resultMap.get("deliver_tx").toString());
+		if(check_tx.get("data") != null){
+			if(!"".equals(check_tx.get("data").toString())){
+				String hexStr = check_tx.get("data").toString();
+				fruit = HexStringUtil.hexStringToString(hexStr);
+			}
+		}
+		if(deliver_tx.get("data") != null){
+			if(!"".equals(deliver_tx.get("data").toString())){
+				String hexStr = deliver_tx.get("data").toString();
+				fruit = HexStringUtil.hexStringToString(hexStr);
+			}
+		}
+		map.put("flag", flag);
+		map.put("data", fruit);
+		return map;
 	}
+	
+	
+	
 }

+ 4 - 4
saicLogistics/src/main/java/com/fuzamei/web/UserAction.java

@@ -129,18 +129,18 @@ public class UserAction {
 		try {
 			 Integer user_id = ValidationUtil.checkAndAssignInt(req.getHeader("Authorization").split("&")[1]);
 			 user.setUserId(user_id);
-			 UserDetail userDetail = userAuthoricationService.queryUserAuthority(user_id, Roles.ADMIN);
+			 userAuthoricationService.queryUserAuthority(user_id, Roles.ADMIN);
 			 Integer userIdb = ValidationUtil.checkAndAssignInt(user.getUserIdb());//被操作人Id
-			 userAuthoricationService.queryUserAuthority(userIdb, Roles.PLANNER,Roles.SUPPLIER,Roles.CARRIER,Roles.STOCKER);
+			 userAuthoricationService.queryUserAuthority(userIdb, Roles.PLANNER,Roles.SUPPLIER,Roles.CARRIER,Roles.STOCKER);//这里是判断除了管理员自己外不能修改
 			 ValidationUtil.checkBlankAndAssignString(user.getUsername());//校验账号
 			 ValidationUtil.checkBlankAndAssignString(user.getPassword(),RegexConstant.PWD_REGEX);//校验密码
 			 ValidationUtil.checkBlankAndAssignString(user.getPersonName());//校验名称
 			 ValidationUtil.checkBlankAndAssignString(user.getSign());//校验签名
-			 if(userDetail.getUsername().equals(user.getUsername())) {//-------------------------TODO
+			 /*if(userDetail.getUsername().equals(user.getUsername())) {//-------------------------TODO
 				 user.setUsername(null);
 				 userService.updateAccountByUserId(user);
 				 return JSONUtil.getJsonMap(200, true, HintMSG.OPERATION_SUCCESS, null);
-			 }
+			 }*/
 			 int num = userService.findUserByuserIdandusername(user);
 			 if(num!=0) throw new RuntimeException("该账号名已存在");
 			 userService.updateAccountByUserId(user);

+ 1 - 1
saicLogistics/src/main/resources/spring-mvc.xml

@@ -35,7 +35,7 @@
 	<tx:annotation-driven transaction-manager="transactionManager"
 		proxy-target-class="true" />
 	<!-- 对token拦截验证 (为方便测试,测试环境给注释掉) -->
-	<mvc:interceptors>
+ 	<mvc:interceptors>
 		<mvc:interceptor> 
 			<mvc:mapping path="/**" />
 			<mvc:exclude-mapping path="/login"/>