浏览代码

首页数据

PLF 5 年之前
父节点
当前提交
5363b680a0

+ 7 - 0
pom.xml

@@ -103,6 +103,13 @@
             <version>2.3</version>
             <version>2.3</version>
         </dependency>
         </dependency>
 
 
+        <!--  jsoup 对 HTML 文档进行解析和操作 -->
+        <dependency>
+            <groupId>org.jsoup</groupId>
+            <artifactId>jsoup</artifactId>
+            <version>1.9.2</version>
+        </dependency>
+
         <!--短信-->
         <!--短信-->
         <dependency>
         <dependency>
             <groupId>caimei</groupId>
             <groupId>caimei</groupId>

+ 1 - 1
src/main/java/com/caimei/modules/shiro/controller/ShiroController.java

@@ -31,7 +31,7 @@ public class ShiroController {
         //用户信息
         //用户信息
         CmMallAdminUser user = shiroService.findByUsername(adminUser.getAccount(), adminUser.getOrganizeID());
         CmMallAdminUser user = shiroService.findByUsername(adminUser.getAccount(), adminUser.getOrganizeID());
         //账号不存在、密码错误
         //账号不存在、密码错误
-        if (user == null || !user.getPassword().equals(MD5Util.md5(adminUser.getPassword()))) {
+        if (user == null || !user.getPassword().equals(MD5Util.md5(adminUser.getPassword() + user.getSalt()))) {
             return jsonModel.error("账号或密码有误");
             return jsonModel.error("账号或密码有误");
         } else {
         } else {
             //生成token
             //生成token

+ 9 - 0
src/main/java/com/caimei/modules/shiro/entity/CmMallAdminUser.java

@@ -6,6 +6,7 @@ import java.util.Set;
 public class CmMallAdminUser {
 public class CmMallAdminUser {
     private Integer id;
     private Integer id;
     private String account;
     private String account;
+    private String accountName;
     private String password;
     private String password;
     private Integer organizeID;
     private Integer organizeID;
     private String salt;
     private String salt;
@@ -14,6 +15,14 @@ public class CmMallAdminUser {
     private Set<Role> roles;
     private Set<Role> roles;
     private String oldPassword;
     private String oldPassword;
 
 
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public void setAccountName(String accountName) {
+        this.accountName = accountName;
+    }
+
     public String getSalt() {
     public String getSalt() {
         return salt;
         return salt;
     }
     }

+ 42 - 1
src/main/java/com/caimei/modules/shiro/service/impl/ShiroServiceImpl.java

@@ -4,7 +4,13 @@ import com.caimei.modules.shiro.dao.UserDao;
 import com.caimei.modules.shiro.entity.CmMallAdminUser;
 import com.caimei.modules.shiro.entity.CmMallAdminUser;
 import com.caimei.modules.shiro.entity.CmMallOrganize;
 import com.caimei.modules.shiro.entity.CmMallOrganize;
 import com.caimei.modules.shiro.service.ShiroService;
 import com.caimei.modules.shiro.service.ShiroService;
+import com.caimei.utils.Encodes;
 import com.caimei.utils.TokenEncryptUtils;
 import com.caimei.utils.TokenEncryptUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
@@ -28,7 +34,7 @@ public class ShiroServiceImpl implements ShiroService {
     }
     }
 
 
     @Override
     @Override
-    public String createToken(CmMallAdminUser user) throws Exception {
+    public String createToken(CmMallAdminUser user) {
         // 获取当前时间戳(10位整数)
         // 获取当前时间戳(10位整数)
         int time = (int) (System.currentTimeMillis() / 1000 + 3600 * 12);
         int time = (int) (System.currentTimeMillis() / 1000 + 3600 * 12);
         String token = TokenEncryptUtils.encoded(time + "#,#" + user.getId() + "#,#" + user.getPassword());
         String token = TokenEncryptUtils.encoded(time + "#,#" + user.getId() + "#,#" + user.getPassword());
@@ -52,7 +58,42 @@ public class ShiroServiceImpl implements ShiroService {
 
 
     @Override
     @Override
     public void updateOrganizeInfo(CmMallOrganize mallOrganize) {
     public void updateOrganizeInfo(CmMallOrganize mallOrganize) {
+        if (mallOrganize.getIntroduction() != null) {
+            mallOrganize.setIntroduction(alter(mallOrganize.getIntroduction()));
+        }
+        if (mallOrganize.getAfterSale() != null) {
+            mallOrganize.setAfterSale(alter(mallOrganize.getAfterSale()));
+        }
+        if (mallOrganize.getShoppingNotes() != null) {
+            mallOrganize.setShoppingNotes(alter(mallOrganize.getShoppingNotes()));
+        }
         mallOrganize.setUpdateTime(new Date().toString());
         mallOrganize.setUpdateTime(new Date().toString());
         userDao.updateOrganizeInfo(mallOrganize);
         userDao.updateOrganizeInfo(mallOrganize);
     }
     }
+
+    public String alter(String introduction) {
+        introduction = StringUtils.replace(introduction, "<body", "<div");
+        introduction = StringUtils.replace(introduction, "</body>", "</div>");
+        Document doc = Jsoup.parse(introduction);
+        Elements links = doc.getElementsByTag("img");
+        for (Element link : links) {
+            String linkSrc = link.attr("src");
+            String linkSrcOld = link.attr("src");
+            if (StringUtils.isNotBlank(linkSrc) && !linkSrc.contains("http:") && !linkSrc.contains("https:") && !linkSrc.contains("uploadFile/ueditor")) {//不包含http开头的
+                linkSrc = Encodes.urlDecode(linkSrc);
+                /*String realPath = UploadImageUtils.getAbsolutePath(linkSrc);
+                int pointerIndex = realPath.lastIndexOf(".");
+                ImageUploadInfo saveImageSerivce = new ImageUploadInfo();
+                try {
+                    saveImageSerivce = ImagePathUtils.saveImageSerivce(realPath, pointerIndex, realPath);
+                    String src = photoServer + saveImageSerivce.getSource();
+                    introduction = StringUtils.replace(introduction, linkSrcOld, src);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    //logger.error("图片上传错误:" + e.toString(), e);
+                }*/
+            }
+        }
+        return introduction;
+    }
 }
 }

+ 110 - 0
src/main/java/com/caimei/utils/Encodes.java

@@ -0,0 +1,110 @@
+/**
+ * Copyright (c) 2005-2012 springside.org.cn
+ */
+package com.caimei.utils;
+
+import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.tomcat.util.codec.binary.Base64;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
+/**
+ * 封装各种格式的编码解码工具类.
+ * 1.Commons-Codec的 hex/base64 编码
+ * 2.自制的base62 编码
+ * 3.Commons-Lang的xml/html escape
+ * 4.JDK提供的URLEncoder
+ * @author calvin
+ * @version 2013-01-15
+ */
+public class Encodes {
+
+	private static final String DEFAULT_URL_ENCODING = "UTF-8";
+	private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
+
+	/**
+	 * Base64编码.
+	 */
+	public static String encodeBase64(byte[] input) {
+		return new String(Base64.encodeBase64(input));
+	}
+	
+	/**
+	 * Base64编码.
+	 */
+	public static String encodeBase64(String input) {
+		try {
+			return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
+		} catch (UnsupportedEncodingException e) {
+			return "";
+		}
+	}
+
+	/**
+	 * Base64解码.
+	 */
+	public static byte[] decodeBase64(String input) {
+		return Base64.decodeBase64(input.getBytes());
+	}
+	
+	/**
+	 * Base64解码.
+	 */
+	public static String decodeBase64String(String input) {
+		try {
+			return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING);
+		} catch (UnsupportedEncodingException e) {
+			return "";
+		}
+	}
+
+	/**
+	 * Base62编码。
+	 */
+	public static String encodeBase62(byte[] input) {
+		char[] chars = new char[input.length];
+		for (int i = 0; i < input.length; i++) {
+			chars[i] = BASE62[((input[i] & 0xFF) % BASE62.length)];
+		}
+		return new String(chars);
+	}
+
+	/**
+	 * Html 转码.
+	 */
+	public static String escapeHtml(String html) {
+		return StringEscapeUtils.escapeHtml4(html);
+	}
+
+	/**
+	 * Html 解码.
+	 */
+	public static String unescapeHtml(String htmlEscaped) {
+		return StringEscapeUtils.unescapeHtml4(htmlEscaped);
+	}
+
+	/**
+	 * URL 编码, Encode默认为UTF-8. 
+	 */
+	public static String urlEncode(String part) {
+		try {
+			return URLEncoder.encode(part, DEFAULT_URL_ENCODING);
+		} catch (UnsupportedEncodingException e) {
+			throw Exceptions.unchecked(e);
+		}
+	}
+
+	/**
+	 * URL 解码, Encode默认为UTF-8. 
+	 */
+	public static String urlDecode(String part) {
+
+		try {
+			return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
+		} catch (UnsupportedEncodingException e) {
+			throw Exceptions.unchecked(e);
+		}
+	}
+}

+ 72 - 0
src/main/java/com/caimei/utils/Exceptions.java

@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2005-2012 springside.org.cn
+ */
+package com.caimei.utils;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * 关于异常的工具类.
+ * @author calvin
+ * @version 2013-01-15
+ */
+public class Exceptions {
+
+	/**
+	 * 将CheckedException转换为UncheckedException.
+	 */
+	public static RuntimeException unchecked(Exception e) {
+		if (e instanceof RuntimeException) {
+			return (RuntimeException) e;
+		} else {
+			return new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * 将ErrorStack转化为String.
+	 */
+	public static String getStackTraceAsString(Throwable e) {
+		if (e == null){
+			return "";
+		}
+		StringWriter stringWriter = new StringWriter();
+		e.printStackTrace(new PrintWriter(stringWriter));
+		return stringWriter.toString();
+	}
+
+	/**
+	 * 判断异常是否由某些底层的异常引起.
+	 */
+	public static boolean isCausedBy(Exception ex, Class<? extends Exception>... causeExceptionClasses) {
+		Throwable cause = ex.getCause();
+		while (cause != null) {
+			for (Class<? extends Exception> causeClass : causeExceptionClasses) {
+				if (causeClass.isInstance(cause)) {
+					return true;
+				}
+			}
+			cause = cause.getCause();
+		}
+		return false;
+	}
+
+	/**
+	 * 在request中获取异常类
+	 * @param request
+	 * @return 
+	 */
+	public static Throwable getThrowable(HttpServletRequest request){
+		Throwable ex = null;
+		if (request.getAttribute("exception") != null) {
+			ex = (Throwable) request.getAttribute("exception");
+		} else if (request.getAttribute("javax.servlet.error.exception") != null) {
+			ex = (Throwable) request.getAttribute("javax.servlet.error.exception");
+		}
+		return ex;
+	}
+	
+}

+ 1 - 1
src/main/resources/mapper/CmOrderRemarkMapper.xml

@@ -9,7 +9,7 @@
 		a.remarks AS "remarks",
 		a.remarks AS "remarks",
 		a.createBy AS "createBy",
 		a.createBy AS "createBy",
 		a.createDate AS "createDate",
 		a.createDate AS "createDate",
-		su.account AS  "sysUserName"
+		su.accountName AS  "sysUserName"
 	</sql>
 	</sql>
 
 
     <select id="get" resultType="com.caimei.modules.order.entity.CmOrderRemark">
     <select id="get" resultType="com.caimei.modules.order.entity.CmOrderRemark">