Browse Source

会员管理DEBUG

Antiloveg 9 years ago
parent
commit
28be893d6e

+ 15 - 39
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -13,6 +13,7 @@ import java.net.URLConnection;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.junit.Test;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Controller;
@@ -141,50 +142,28 @@ public class PublicController extends BaseController {
 		return res;
 	}
 
-	@RequestMapping(value = "/downLoadPicture", method = RequestMethod.POST)
-	public void downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request,
-			boolean isPrivate) {
-		String filename = (path.split("/")[(path.split("/").length - 1)]).split(".")[0];
-		response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
-
-		// 设置文件MIME类型
-		response.setContentType("multipart/form-data");
-		/*
-		 * 解决各浏览器的中文乱码问题
-		 */
-		String userAgent = request.getHeader("User-Agent");
+	@RequestMapping(value = "/downLoadPicture", method = RequestMethod.GET)
+	public void downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request
+			) {
+		//String filename = (path.split("/")[(path.split("/").length - 1)]);
+		String filename =Long.toString(System.nanoTime())+".jpg"; 
 		InputStream in = null;
 		OutputStream out = null;
-		int connectTimeout = 30 * 1000; // 连接超时:30s
-		int readTimeout = 1 * 1000 * 1000; // IO超时:1min
-		byte[] buffer = new byte[8 * 1024]; // IO缓冲区:8KB
+		byte[] buffer = new byte[8 * 1024];
 		String fileSaveRootPath = "";
-
+		//下载权限判断
+		
 		try {
-
-			if (isPrivate) {
 				fileSaveRootPath = uploadPrivatePath + path;
 				File file = new File(fileSaveRootPath);
 				in = new FileInputStream(file);
-			} else {
-				fileSaveRootPath =" http://"+ staticHost + "upload" + path;
-				URL url = new URL(fileSaveRootPath);
-				URLConnection conn = url.openConnection();
-				conn.setConnectTimeout(connectTimeout);
-				conn.setReadTimeout(readTimeout);
-				conn.connect();
-				in = conn.getInputStream();
-			}
 			out = response.getOutputStream();
 			// 设置文件MIME类型
-			response.setContentType("multipart/form-data");
-			/*
-			 * 解决各浏览器的中文乱码问题
-			 */
-			userAgent = request.getHeader("User-Agent");
-			byte[] bytes1 = userAgent.contains("MSIE") ? filename.getBytes() : filename.getBytes("UTF-8"); // fileName.getBytes("UTF-8")处理safari的乱码问题
-			filename = new String(bytes1, "ISO-8859-1"); // 各浏览器基本都支持ISO编码
-			response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
+		    //response.setContentType("multipart/form-data");
+			//response.setContentType("application/x-msdownload");
+			//response.setContentType("application/x-jpg");
+			response.setContentType("application/octet-stream");
+			response.setHeader("Content-Disposition", "attachment; filename=" + filename);
 			for (;;) {
 				int bytes = in.read(buffer);
 				if (bytes == -1) {
@@ -192,10 +171,6 @@ public class PublicController extends BaseController {
 				}
 				out.write(buffer, 0, bytes);
 			}
-		} catch (MalformedURLException e) {
-			LoggerUtils.fmtError(getClass(), e, "URL协议、格式或者路径错误:%s", e.getMessage());
-		} catch (FileNotFoundException e) {
-			LoggerUtils.fmtError(getClass(), e, "文件未找到:%s", e.getMessage());
 		} catch (IOException e) {
 			LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
 		} finally {
@@ -223,5 +198,6 @@ public class PublicController extends BaseController {
 	        return file.delete();  
 	    }  
 	}
+	
 
 }

+ 4 - 0
src/main/java/com/goafanti/common/dao/UserMapper.java

@@ -1,6 +1,8 @@
 package com.goafanti.common.dao;
 
 import com.goafanti.common.model.User;
+import com.goafanti.common.model.UserInfo;
+import com.goafanti.user.bo.UserPageHomeBo;
 
 
 public interface UserMapper {
@@ -17,4 +19,6 @@ public interface UserMapper {
     int updateByPrimaryKey(User record);
 
 	User selectByMobieAndType(java.lang.String mobile, Integer type);
+
+	UserPageHomeBo selectUserPageHomeBoByUserId(String uid);
 }

+ 14 - 0
src/main/java/com/goafanti/common/mapper/UserMapper.xml

@@ -13,6 +13,16 @@
     <result column="type" jdbcType="INTEGER" property="type" />
   </resultMap>
   
+  <resultMap type="com.goafanti.user.bo.UserPageHomeBo" id="UserPageHomeBo">
+    <id column="id" jdbcType="VARCHAR" property="id" />
+    <result column="uid" jdbcType="VARCHAR" property="uid"/>
+    <result column="lvl" jdbcType="INTEGER" property="lvl"/>
+    <result column="nickname" jdbcType="VARCHAR" property="nickname"/>
+    <result column="email" jdbcType="VARCHAR" property="email"/>
+    <result column="number" jdbcType="INTEGER" property="number"/>
+    <result column="type" jdbcType="INTEGER" property="type"/>
+    <result column="person_portrait_url" jdbcType="VARCHAR" property="personPortraitUrl"/>
+  </resultMap>
   
   
   <sql id="Base_Column_List">
@@ -148,6 +158,10 @@
     where mobile = #{0} and type=#{1}
   </select>
   
+  <select id="selectUserPageHomeBoByUserId" resultMap="UserPageHomeBo" parameterType="java.lang.String">
+   select u.lvl,u.nickname,u.email,u.number,u.type,i.person_portrait_url, i.id ,i.uid from user u LEFT JOIN user_info  i 
+   on u.id = i.uid where i.uid = #{uid,jdbcType = VARCHAR}
+  </select>
   
   
   

+ 4 - 0
src/main/java/com/goafanti/user/bo/OrgProBo.java

@@ -7,6 +7,10 @@ public class OrgProBo {
       private OrganizationInfo info;
       private OrganizationProperties pro;
       
+    public OrgProBo(){
+    	
+    }
+      
     public OrgProBo(OrganizationInfo info,OrganizationProperties pro){
     	this.info = info;
     	this.pro =pro;

+ 86 - 0
src/main/java/com/goafanti/user/bo/UserPageHomeBo.java

@@ -0,0 +1,86 @@
+package com.goafanti.user.bo;
+
+public class UserPageHomeBo {
+     private String id;
+     private String uid;
+     /**
+      * 用户等级
+      */
+     private Integer lvl;
+     
+     /**
+      * 用户昵称
+      */
+     private String nickname;
+     
+     /**
+      * 邮箱
+      */
+     private String email;
+     
+     /**
+      * 用户编号
+      */
+     private Integer number;
+     
+     /**
+      * 帐号类型
+      */
+     private Integer type;
+     
+     /**
+      * 用户头像URL
+      */
+     private String personPortraitUrl;
+     
+	public String getId() {
+		return id;
+	}
+	public void setId(String id) {
+		this.id = id;
+	}
+	public String getUid() {
+		return uid;
+	}
+	public void setUid(String uid) {
+		this.uid = uid;
+	}
+	public Integer getLvl() {
+		return lvl;
+	}
+	public void setLvl(Integer lvl) {
+		this.lvl = lvl;
+	}
+	public String getNickname() {
+		return nickname;
+	}
+	public void setNickname(String nickname) {
+		this.nickname = nickname;
+	}
+	public String getEmail() {
+		return email;
+	}
+	public void setEmail(String email) {
+		this.email = email;
+	}
+	public Integer getNumber() {
+		return number;
+	}
+	public void setNumber(Integer number) {
+		this.number = number;
+	}
+	public Integer getType() {
+		return type;
+	}
+	public void setType(Integer type) {
+		this.type = type;
+	}
+	public String getPersonPortraitUrl() {
+		return personPortraitUrl;
+	}
+	public void setPersonPortraitUrl(String personPortraitUrl) {
+		this.personPortraitUrl = personPortraitUrl;
+	}
+     
+     
+}

+ 29 - 4
src/main/java/com/goafanti/user/controller/UserApiController.java

@@ -8,7 +8,6 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.SecurityUtils;
 import org.springframework.stereotype.Controller;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -38,6 +37,7 @@ import com.goafanti.user.bo.OrgProBo;
 import com.goafanti.user.bo.UidAndTypeBo;
 import com.goafanti.user.bo.UserIdentityBo;
 import com.goafanti.user.bo.UserInfoBo;
+import com.goafanti.user.bo.UserPageHomeBo;
 import com.goafanti.user.service.OrganizationIdentityService;
 import com.goafanti.user.service.OrganizationInfoService;
 import com.goafanti.user.service.OrganizationPropertiesService;
@@ -179,6 +179,16 @@ public class UserApiController extends BaseApiController {
 		res.setData(handleFile(res, "/avatar/", false, req, ""));
 		return res;
 	}
+	
+	/**
+	 * 公共可替换
+	 */
+	@RequestMapping(value="/avatar/uploadReplace",method = RequestMethod.POST)
+	public Result avatarReplace(HttpServletRequest req ,String sign) {
+		Result res = new Result();
+		res.setData(handleFile(res, "/avatar/", false, req, sign));
+		return res;
+	}
 
 	/**
 	 * 认证
@@ -189,7 +199,6 @@ public class UserApiController extends BaseApiController {
 	@RequestMapping(value = "/identity/upload", method = RequestMethod.POST)
 	public Result identityFile(HttpServletRequest req, String sign) {
 		Result res = new Result();
-		res.setData(sign);
 		res.setData(handleFile(res, "/identity/", true, req, sign));
 		return res;
 	}
@@ -210,8 +219,8 @@ public class UserApiController extends BaseApiController {
 	private String handleFile(Result res, String path, boolean isPrivate, HttpServletRequest req, String sign) {
 		List<MultipartFile> files = getFiles(req);
 		String fileName = "";
-		if (isPrivate) {
-			fileName = path + TokenManager.getUserId() + sign + ".jpg";// /identity/12345idcard1.jpg
+		if (isPrivate || sign != "") {
+			fileName = path + TokenManager.getUserId() + sign + ".jpg";
 		} else {
 			fileName = path + System.nanoTime() + ".jpg";
 		}
@@ -539,6 +548,22 @@ public class UserApiController extends BaseApiController {
 		ub.setUid(u.getId());
 		return ub;
 	}
+	
+	
+	/**
+	 * 首页
+	 * @return
+	 */
+	@RequestMapping(value ="/homePage",method = RequestMethod.GET)
+	public Result homePage(){
+		Result res = new Result();
+		if(TokenManager.isLogin()){
+			UserPageHomeBo userPageHomeBo = userService.selectUserPageHomeBoByUserId(TokenManager.getUserId());
+			res.setData(userPageHomeBo);
+		}
+		return res;
+		
+	}
 
 	/**
 	 * 登陆后返回用户基本信息

+ 1 - 0
src/main/java/com/goafanti/user/service/UserInfoService.java

@@ -13,4 +13,5 @@ public interface UserInfoService {
 
 	UserInfoBo selectUserInfoBoByUserId(String uid);
 
+
 }

+ 4 - 0
src/main/java/com/goafanti/user/service/UserService.java

@@ -1,6 +1,8 @@
 package com.goafanti.user.service;
 
 import com.goafanti.common.model.User;
+import com.goafanti.common.model.UserInfo;
+import com.goafanti.user.bo.UserPageHomeBo;
 
 
 public interface UserService {
@@ -17,4 +19,6 @@ public interface UserService {
 	
 	User insertRegister(User user,String companyName,String contacts,String uid);
 
+	UserPageHomeBo selectUserPageHomeBoByUserId(String userId);
+
 }

+ 1 - 0
src/main/java/com/goafanti/user/service/impl/UserInfoServiceImpl.java

@@ -32,4 +32,5 @@ public class UserInfoServiceImpl implements UserInfoService{
 		return userInfoMapper.selectUserInfoBoByUserId(uid);
 	}
 
+
 }

+ 7 - 0
src/main/java/com/goafanti/user/service/impl/UserServiceImpl.java

@@ -12,6 +12,8 @@ import com.goafanti.common.dao.UserMapper;
 import com.goafanti.common.model.OrganizationIdentity;
 import com.goafanti.common.model.OrganizationInfo;
 import com.goafanti.common.model.User;
+import com.goafanti.common.model.UserInfo;
+import com.goafanti.user.bo.UserPageHomeBo;
 import com.goafanti.user.service.UserService;
 
 
@@ -75,6 +77,11 @@ public class UserServiceImpl implements UserService {
 		return userMapper.updateByPrimaryKey(u);
 	}
 
+	@Override
+	public UserPageHomeBo selectUserPageHomeBoByUserId(String uid) {
+		return userMapper.selectUserPageHomeBoByUserId(uid);
+	}
+
 
 
 

+ 1 - 0
src/main/resources/spring/spring-shiro.xml

@@ -22,6 +22,7 @@
 	    <constructor-arg index="2" value="${jedis.port}"  name="port" type="int"/>
 	    <constructor-arg index="3" value="${jedis.timeout}"  name="timeout" type="int"/>
 	    <constructor-arg index="4" value="${jedis.password}"  name="password" type="java.lang.String"/>
+	  
 	</bean>
 	
 	<!-- 会话Session ID生成器 -->

+ 2 - 1
src/main/webapp/WEB-INF/html/upload.html

@@ -61,10 +61,11 @@
     	$('#myfile').on('change', function(evt){
     		var formdata = new FormData();
             formdata.append("files", evt.target.files[0]);
+            formdata.append("sign","asd")
     		
     		$.ajax({
                 type: 'post',
-                url: "/aft/api/user/avatar/upload",
+                url: "/aft/api/user/avatar/uploadReplace",
                 contentType: false,
                 processData: false,
                 data: formdata