Browse Source

用户添加+上传附件重复数据

user5 4 years atrás
parent
commit
30419e00a2

+ 2 - 2
src/main/java/com/jeeplus/common/oss/OSSClientUtil.java

@@ -765,8 +765,8 @@ public class OSSClientUtil {
                 cons = aliDownloadUrl;
             }
             String key = file.split(cons+"/")[1];
-            // 指定过期时间为60分钟
-            Date expiration = new Date(new Date().getTime() + 1000 * 60 * 60 );
+            // 指定过期时间为24小时
+            Date expiration = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 );
             url = ossClient.generatePresignedUrl(bucketName, key, expiration);
 
         } catch (Exception e) {

+ 2 - 2
src/main/java/com/jeeplus/modules/sys/security/SystemAuthorizingRealm.java

@@ -80,7 +80,7 @@ public class SystemAuthorizingRealm extends AuthorizingRealm {
 			if (logger.isDebugEnabled()){
 				logger.debug("login submit, active session size: {}, username: {}", activeSessionSize, token.getUsername());
 			}*/
-			boolean mobile = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_MOBILE_PARAM);
+			/*boolean mobile = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_MOBILE_PARAM);
 			// 校验登录验证码
 			if (!mobile && LoginController.isValidateCodeLogin(token.getUsername(), false, false)){
 				Session session = UserUtils.getSession();
@@ -94,7 +94,7 @@ public class SystemAuthorizingRealm extends AuthorizingRealm {
 //					}
 					throw new AuthenticationException("msg:验证码错误, 请重试.");
 				}
-			}
+			}*/
 
 			// 校验用户名密码
 			User user = getSystemService().getUserByLoginName(token.getUsername());

+ 12 - 3
src/main/java/com/jeeplus/modules/sys/service/UserService.java

@@ -341,9 +341,18 @@ public class UserService extends BaseController {
                         }
                         String path = new StringBuilder("/headImg/")
                                 .append(userName+System.currentTimeMillis()).toString();
-                        BOSClientUtil bosClientUtil = new BOSClientUtil();
-                        String uploadPath = bosClientUtil.upload(path, inputStream);
-                        user.setPhoto(uploadPath);
+                        String filePath = new StringBuilder("attachment-file/headImg/").toString();
+                        String uploadPath = "";
+                        //头像图片上传
+                        // 文件存储方式(0:本地服务器存储。1:百度云存储;2:阿里云存储)
+                        if("1".equals(uploadMode)){
+                            BOSClientUtil bosClientUtil = new BOSClientUtil();
+                            uploadPath = bosClientUtil.upload(path, inputStream);
+                        }else if("2".equals(uploadMode)){
+                            OSSClientUtil ossClientUtil = new OSSClientUtil();
+                            uploadPath = ossClientUtil.uploadFile2OSS(inputStream,filePath,userName+picNamePhoto);
+                        }
+                        user.setPhoto(uploadPath+userName+picNamePhoto);
                         FileUtils.delFile(Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL  +time);
                     } catch (IOException e) {
                         e.printStackTrace();

+ 22 - 0
src/main/java/com/jeeplus/modules/sys/utils/UserUtils.java

@@ -3,6 +3,8 @@
  */
 package com.jeeplus.modules.sys.utils;
 
+import com.jeeplus.common.config.Global;
+import com.jeeplus.common.oss.OSSClientUtil;
 import com.jeeplus.common.persistence.Page;
 import com.jeeplus.common.service.BaseService;
 import com.jeeplus.common.sms.SMSUtils;
@@ -47,6 +49,15 @@ import java.util.regex.Pattern;
  */
 public class UserUtils {
 
+	/**
+	 * 阿里云文件服务器前缀
+	 */
+	private final static String aliyunUrl = Global.getConfig("aliyunUrl");
+	/**
+	 * 百度云文件服务器前缀
+	 */
+	private final static String bosUrl = Global.getConfig("bosUrl");
+
 	private static UserDao userDao = SpringContextHolder.getBean(UserDao.class);
 	private static RoleDao roleDao = SpringContextHolder.getBean(RoleDao.class);
 	private static MenuDao menuDao = SpringContextHolder.getBean(MenuDao.class);
@@ -237,6 +248,17 @@ public class UserUtils {
 		if (user == null){
 			return null;
 		}
+		OSSClientUtil ossUtil = new OSSClientUtil();
+		if(StringUtils.isNotBlank(user.getPhoto())){
+			switch (Global.getConfig("remoteServer.uploadMode")){
+				case "1":
+					user.setPhoto(ossUtil.getFileTemporaryLookUrl(bosUrl + user.getPhoto()));
+					break;
+				case "2":
+					user.setPhoto(ossUtil.getFileTemporaryLookUrl(aliyunUrl + user.getPhoto()));
+					break;
+			}
+		}
 		List<Role> roleList = roleDao.findList(new Role(user));
 		user.setRoleList(roleList);
 		CacheUtils.put(USER_CACHE, USER_CACHE_ID_ + user.getId(), user);

+ 15 - 3
src/main/java/com/jeeplus/modules/sys/web/UserController.java

@@ -47,6 +47,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 import redis.clients.jedis.Jedis;
+import sun.net.www.content.image.png;
 
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
@@ -766,12 +767,23 @@ public class UserController extends BaseController {
     @RequestMapping(value = "imageUpload")
     public String imageUpload( HttpServletRequest request, HttpServletResponse response,MultipartFile file) throws IllegalStateException, IOException {
         User currentUser = UserUtils.getUser();
+        String imgName = currentUser.getName()+System.currentTimeMillis();
         if(file != null && file.getSize()>0){
             String path = new StringBuilder("/headImg/")
-                    .append(currentUser.getName()+System.currentTimeMillis()).append(".png").toString();
+                    .append(imgName).append(".png").toString();
+            String filePath = new StringBuilder("attachment-file/headImg/").toString();
             InputStream inputStream = file.getInputStream();
-            BOSClientUtil bosClientUtil = new BOSClientUtil();
-            String url = bosClientUtil.upload(path, inputStream);
+            /*BOSClientUtil bosClientUtil = new BOSClientUtil();
+            String url = bosClientUtil.upload(path, inputStream);*/
+            String url = "";
+            if("1".equals(uploadMode)){
+                BOSClientUtil bosClientUtil = new BOSClientUtil();
+                url = bosClientUtil.upload(path, inputStream);
+            }else if("2".equals(uploadMode)){
+                OSSClientUtil ossClientUtil = new OSSClientUtil();
+                ossClientUtil.uploadFile2OSS(inputStream,filePath,imgName);
+                url = "/" + filePath+imgName+".png";
+            }
             currentUser.setPhoto(url);
             currentUser.setDefaultPhoto("1");
             systemService.updateUserInfo(currentUser);

+ 18 - 18
src/main/resources/mappings/modules/projectAccessory/ProjectTemplateDao.xml

@@ -1,9 +1,9 @@
 <?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.jeeplus.modules.projectAccessory.dao.ProjectTemplateDao">
-    
+
 	<sql id="workReviewStandardColumns">
-		a.id AS "id",
+		distinct (a.id) AS "id",
 		a.create_by AS "createBy.id",
 		a.create_date AS "createDate",
 		a.update_by AS "updateBy.id",
@@ -18,17 +18,17 @@
 		a.company_id AS "companyId",
 		a.index_num AS "indexNum"
 	</sql>
-	
-    
+
+
 	<select id="get" resultType="com.jeeplus.modules.projectAccessory.entity.ProjectTemplateInfo" >
-		SELECT 
+		SELECT
 			<include refid="workReviewStandardColumns"/>
 		FROM project_template_structure_info a
 		WHERE a.id = #{id}
 	</select>
-	
+
 	<select id="findList" resultType="com.jeeplus.modules.projectAccessory.entity.ProjectTemplateInfo" >
-		SELECT 
+		SELECT
 			<include refid="workReviewStandardColumns"/>
 		FROM project_template_structure_info a
 		<where>
@@ -103,14 +103,14 @@
 		where a.parent_id =#{parentId}
 		and a.id not in(select attach_id from project_accessory_relation_info where project_type = #{projectType} and attach_type = #{parentId} and id != #{id})
 	</select>
-	
+
 	<select id="findAllList" resultType="com.jeeplus.modules.projectAccessory.entity.ProjectTemplateInfo" >
-		SELECT 
+		SELECT
 			<include refid="workReviewStandardColumns"/>
 		FROM project_template_structure_info a
 		<where>
 			a.del_flag = #{DEL_FLAG_NORMAL}
-		</where>		
+		</where>
 		<choose>
 			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
 				ORDER BY ${page.orderBy}
@@ -120,7 +120,7 @@
 			</otherwise>
 		</choose>
 	</select>
-	
+
 	<insert id="insert">
 		INSERT INTO project_template_structure_info(
 			id,
@@ -154,7 +154,7 @@
 			#{indexNum}
 		)
 	</insert>
-	
+
 	<update id="update">
 		UPDATE project_template_structure_info SET
 			update_by = #{updateBy.id},
@@ -169,22 +169,22 @@
 			index_num = #{indexNum}
 		WHERE id = #{id}
 	</update>
-	
-	
+
+
 	<!--物理删除-->
 	<update id="delete">
 		DELETE FROM project_template_structure_info
 		WHERE id = #{id} OR find_in_set(#{id},parent_ids)
 	</update>
-	
+
 	<!--逻辑删除-->
 	<update id="deleteByLogic">
 		UPDATE project_template_structure_info SET
 			del_flag = #{DEL_FLAG_DELETE}
 		WHERE id = #{id} OR find_in_set(#{id},parent_ids)
 	</update>
-	
-	
+
+
 	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
 	<select id="findUniqueByProperty" resultType="com.jeeplus.modules.projectAccessory.entity.ProjectTemplateInfo" statementType="STATEMENT">
 		select * FROM project_template_structure_info  where ${propertyName} = '${value}'
@@ -301,4 +301,4 @@
 			</otherwise>
 		</choose>
 	</select>
-</mapper>
+</mapper>