提交 75ae2ffa 编写于 作者: 武汉红喜's avatar 武汉红喜

optimise

上级 f952e0eb
......@@ -16,25 +16,6 @@
<description>Utils公共模块</description>
<dependencies>
<!-- 图片压缩工具 -->
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
......@@ -44,18 +25,6 @@
<artifactId>httpmime</artifactId>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>${json-lib.version}</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
......@@ -68,41 +37,9 @@
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
......
......@@ -22,6 +22,7 @@
<module>whatsmars-earth-web</module>
<module>whatsmars-earth-support-web</module>
<module>whatsmars-earth-manager</module>
<module>whatsmars-earth-common</module>
</modules>
<properties>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>whatsmars-earth</artifactId>
<groupId>org.hongxi</groupId>
<version>Rocket.S1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>whatsmars-earth-common</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>Earth Utils 公共模块</description>
<dependencies>
<!-- 图片压缩工具 -->
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>${json-lib.version}</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.hongxi.whatsmars.common.mongo;
package org.hongxi.whatsmars.earth.common.mongo;
import org.hongxi.whatsmars.common.mongo.object.MongoDBConfig;
import org.hongxi.whatsmars.common.ImageSizeEnum;
import org.hongxi.whatsmars.common.mongo.object.MongoDBCredential;
import org.hongxi.whatsmars.common.mongo.object.MongoDBDriver;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
......@@ -13,6 +9,10 @@ import com.mongodb.gridfs.GridFSInputFile;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.hongxi.whatsmars.earth.common.ImageSizeEnum;
import org.hongxi.whatsmars.earth.common.mongo.object.MongoDBConfig;
import org.hongxi.whatsmars.earth.common.mongo.object.MongoDBCredential;
import org.hongxi.whatsmars.earth.common.mongo.object.MongoDBDriver;
import org.imgscalr.Scalr;
import javax.imageio.ImageIO;
......
package org.hongxi.whatsmars.common.mongo;
package org.hongxi.whatsmars.earth.common.mongo;
import org.hongxi.whatsmars.common.mongo.object.MongoDBConfig;
import org.hongxi.whatsmars.common.mongo.object.MongoDBCredential;
import org.hongxi.whatsmars.common.mongo.object.MongoDBDriver;
import com.mongodb.client.ListCollectionsIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import org.hongxi.whatsmars.earth.common.mongo.object.MongoDBConfig;
import org.hongxi.whatsmars.earth.common.mongo.object.MongoDBCredential;
import org.hongxi.whatsmars.earth.common.mongo.object.MongoDBDriver;
import java.util.ArrayList;
import java.util.List;
......
package org.hongxi.whatsmars.common.mongo.object;
package org.hongxi.whatsmars.earth.common.mongo.object;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
......
package org.hongxi.whatsmars.common.mongo.object;
package org.hongxi.whatsmars.earth.common.mongo.object;
import com.mongodb.DB;
import com.mongodb.Mongo;
......
package org.hongxi.whatsmars.common.mongo.serializer;
package org.hongxi.whatsmars.earth.common.mongo.serializer;
import org.apache.commons.lang.time.DateUtils;
import org.codehaus.jackson.JsonParser;
......
package org.hongxi.whatsmars.common.mongo.serializer;
package org.hongxi.whatsmars.earth.common.mongo.serializer;
import org.apache.commons.lang.time.DateFormatUtils;
import org.codehaus.jackson.JsonGenerator;
......
package org.hongxi.whatsmars.common.pojo;
package org.hongxi.whatsmars.earth.common.pojo;
import java.util.HashMap;
import java.util.Map;
......
package org.hongxi.whatsmars.earth.common.util;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.SecureRandom;
public class DESUtils {
private static final String DES = "DES";
private static final String PADDING = "DES/ECB/PKCS5Padding";
private static final String DEFAULT_ENCODING = "utf-8";
public final static String encrypt(String code, String key) {
try {
return Base64.encodeBase64String(encrypt(code.getBytes(DEFAULT_ENCODING), key
.getBytes(DEFAULT_ENCODING)));
} catch (Exception e) {
//
}
return null;
}
public static byte[] encrypt(byte[] src, byte[] key) throws Exception {
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(PADDING);
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
return cipher.doFinal(src);
}
public final static String decrypt(String data, String key) {
try {
//base64,default-charset is UTF-8
return new String(decrypt(Base64.decodeBase64(data),
key.getBytes(DEFAULT_ENCODING)), DEFAULT_ENCODING);
} catch (Exception e) {
//
}
return null;
}
public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(PADDING);
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
return cipher.doFinal(src);
}
}
package org.hongxi.whatsmars.common.util;
package org.hongxi.whatsmars.earth.common.util;
import java.util.HashMap;
import java.util.Map;
......
package org.hongxi.whatsmars.common.util;
package org.hongxi.whatsmars.earth.common.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......
package org.hongxi.whatsmars.common.util;
package org.hongxi.whatsmars.earth.common.util;
import org.hongxi.whatsmars.common.pojo.Result;
import org.codehaus.jackson.map.ObjectMapper;
import org.hongxi.whatsmars.earth.common.pojo.Result;
/**
* qing
......
package org.hongxi.whatsmars.common.util;
package org.hongxi.whatsmars.earth.common.util;
import java.text.NumberFormat;
import java.util.HashMap;
......
package org.hongxi.whatsmars.common.util;
package org.hongxi.whatsmars.earth.common.util;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.common.pojo.ResultCode;
import net.sf.json.JSONObject;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.pojo.ResultCode;
import java.util.Map;
......
package org.hongxi.whatsmars.common.util;
package org.hongxi.whatsmars.earth.common.util;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
......
......@@ -18,7 +18,7 @@
<dependencies>
<dependency>
<groupId>org.hongxi</groupId>
<artifactId>whatsmars-common</artifactId>
<artifactId>whatsmars-earth-common</artifactId>
<version>Rocket.S1</version>
</dependency>
<dependency>
......
package org.hongxi.whatsmars.earth.service;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.pojo.Result;
/**
* Created by shenhongxi on 2016/4/1.
*/
public interface AccountService {
public Result hello(String name);
Result hello(String name);
}
package org.hongxi.whatsmars.earth.service;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import org.hongxi.whatsmars.earth.domain.query.OrganizationQuery;
/**
......@@ -8,6 +8,6 @@ import org.hongxi.whatsmars.earth.domain.query.OrganizationQuery;
*/
public interface OrganizationService {
public Result list(OrganizationQuery query);
Result list(OrganizationQuery query);
}
package org.hongxi.whatsmars.earth.service.impl;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import org.hongxi.whatsmars.earth.dao.AccountDao;
import org.hongxi.whatsmars.earth.service.AccountService;
import org.springframework.stereotype.Service;
......
package org.hongxi.whatsmars.earth.service.impl;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.common.pojo.ResultCode;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.pojo.ResultCode;
import org.hongxi.whatsmars.earth.dao.OrganizationDao;
import org.hongxi.whatsmars.earth.service.OrganizationService;
import org.hongxi.whatsmars.earth.domain.pojo.Organization;
......
......@@ -93,11 +93,6 @@
<artifactId>aspectjtools</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
</dependencies>
<build>
......
package org.hongxi.whatsmars.earth.support.web.controller;
import org.hongxi.whatsmars.common.CommonConstants;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.common.pojo.ResultCode;
import org.hongxi.whatsmars.common.util.DESUtils;
import org.hongxi.whatsmars.common.util.ResultHelper;
import org.hongxi.whatsmars.earth.common.CommonConstants;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.pojo.ResultCode;
import org.hongxi.whatsmars.earth.common.util.DESUtils;
import org.hongxi.whatsmars.earth.common.util.ResultHelper;
import org.hongxi.whatsmars.earth.support.web.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
......
package org.hongxi.whatsmars.earth.support.web.service;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
......
package org.hongxi.whatsmars.earth.support.web.service.impl;
import org.hongxi.whatsmars.common.ImageSizeEnum;
import org.hongxi.whatsmars.common.mongo.GridFSClient;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.common.pojo.ResultCode;
import org.hongxi.whatsmars.earth.common.ImageSizeEnum;
import org.hongxi.whatsmars.earth.common.mongo.GridFSClient;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.pojo.ResultCode;
import org.hongxi.whatsmars.earth.support.web.service.FileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -26,7 +26,7 @@ public class FileServiceImpl implements FileService {
private GridFSClient gridFSClient;
@Override
public Result uploadFile(InputStream inputStream, String format,String uid) {
public Result uploadFile(InputStream inputStream, String format, String uid) {
Result result = new Result();
try {
String filename = gridFSClient.saveFile(inputStream,format,uid);
......
package org.hongxi.whatsmars.earth.web.controller;
import org.hongxi.whatsmars.common.util.DESUtils;
import org.hongxi.whatsmars.earth.common.util.DESUtils;
import org.hongxi.whatsmars.earth.domain.constants.Constants;
import org.hongxi.whatsmars.earth.domain.misc.SystemConfig;
import org.apache.commons.lang.RandomStringUtils;
......@@ -25,7 +25,7 @@ public class BaseController {
* @param response 生成token,path为当前页面的路径,比如:/teacher
* @return
*/
public String createToken(HttpServletRequest request,HttpServletResponse response) {
protected String createToken(HttpServletRequest request,HttpServletResponse response) {
String token = RandomStringUtils.random(32,true,true);
Cookie cookie = new Cookie(TOKEN_KEY,DESUtils.encrypt(token,Constants.HTTP_ENCRYPT_KEY));
......@@ -42,7 +42,7 @@ public class BaseController {
* @param response
* @return
*/
public void removeToken(HttpServletRequest request,HttpServletResponse response) {
protected void removeToken(HttpServletRequest request,HttpServletResponse response) {
Cookie cookie = new Cookie(TOKEN_KEY,null);
cookie.setDomain(systemConfig.getCookieDomain());
cookie.setMaxAge(0);//立即过期
......@@ -55,7 +55,7 @@ public class BaseController {
* @param request
* @return
*/
public String getToken(HttpServletRequest request) {
protected String getToken(HttpServletRequest request) {
Cookie[] cookies = request.getCookies();
if(cookies == null) {
return null;
......@@ -75,7 +75,7 @@ public class BaseController {
* @param request
* @return
*/
public String getClientIP(HttpServletRequest request) {
protected String getClientIP(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
......@@ -95,7 +95,7 @@ public class BaseController {
* @param request
* @return
*/
public String getCurrentValidateCode(HttpServletRequest request) {
protected String getCurrentValidateCode(HttpServletRequest request) {
Cookie[] cookies = request.getCookies();
if(cookies == null) {
return null;
......
package org.hongxi.whatsmars.earth.web.controller;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import org.hongxi.whatsmars.earth.domain.enums.OrganizationLevelEnum;
import org.hongxi.whatsmars.earth.domain.enums.OrganizationStatusEnum;
import org.hongxi.whatsmars.earth.domain.enums.UserTypeEnum;
import org.hongxi.whatsmars.earth.service.OrganizationService;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.earth.domain.permission.Permission;
import org.hongxi.whatsmars.earth.domain.query.OrganizationQuery;
import org.apache.commons.lang.StringUtils;
......
......@@ -2,8 +2,8 @@ package org.hongxi.whatsmars.earth.web.controller;
import com.itextpdf.text.log.Logger;
import com.itextpdf.text.log.LoggerFactory;
import org.hongxi.whatsmars.common.pojo.Result;
import org.hongxi.whatsmars.common.util.ResultHelper;
import org.hongxi.whatsmars.earth.common.pojo.Result;
import org.hongxi.whatsmars.earth.common.util.ResultHelper;
import org.hongxi.whatsmars.earth.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
......
package org.hongxi.whatsmars.earth.web.controller;
import com.itextpdf.text.log.Logger;
import com.itextpdf.text.log.LoggerFactory;
import org.hongxi.whatsmars.common.result.Result;
import org.hongxi.whatsmars.common.result.ResultHelper;
import org.hongxi.whatsmars.earth.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
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 org.hongxi.whatsmars.earth.domain.pojo.User;
/**
* Created by javahongxi on 2017/10/22.
*/
@RestController
@RequestMapping("/test")
public class NewController {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private UserService userService;
// localhost:8080/test/add.jhtml
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result add(@RequestParam(name = "name") String username,
@RequestParam(required = false) String nickname,
@RequestParam(required = false, defaultValue = "1") Integer gender,
@RequestParam Integer age) {
try {
User user = new User();
user.setUsername(username);
user.setNickname(nickname);
user.setGender(gender);
user.setAge(age);
userService.add(user);
} catch (Exception e) {
logger.error("##########test add error", e);
return ResultHelper.newErrorResult();
}
return ResultHelper.newSuccessResult();
}
}
package org.hongxi.whatsmars.earth.web.converter;
import org.hongxi.whatsmars.common.util.DateUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.convert.converter.Converter;
import java.util.Date;
import java.util.regex.Pattern;
/**
* Created by zhaozhong on 2016/9/6.
*/
public class StringToDateConverter implements Converter<String, Date> {
private Pattern dateTimePattern = Pattern.compile(DateUtils.DATETIME_FORMAT_REGEX);
private Pattern shortDatePattern = Pattern.compile(DateUtils.SHORTDATE_FORMAT_REGEX);
private Pattern shortDate2Pattern = Pattern.compile(DateUtils.SHORTDATE_FORMAT2_REGEX);
private Pattern datePattern = Pattern.compile(DateUtils.DATE_FORMAT_REGEX);
private Pattern date2Pattern = Pattern.compile(DateUtils.DATE_FORMAT2_REGEX);
@Override
public Date convert(String source) {
if (StringUtils.isNotEmpty(source)) {
if(shortDatePattern.matcher(source).matches()) {
return DateUtils.getDateFormat(source, DateUtils.DATE_SHORT_FORMAT);
}else if(datePattern.matcher(source).matches()) {
return DateUtils.getDateFormat(source, DateUtils.DATEFORMAT);
}else if(dateTimePattern.matcher(source).matches()) {
return DateUtils.getDateFormat(source, DateUtils.DATETIMEFORMAT);
}else if(shortDate2Pattern.matcher(source).matches()) {
return DateUtils.getDateFormat(source, DateUtils.DATE_SHORT_FORMAT2);
}else if(date2Pattern.matcher(source).matches()) {
return DateUtils.getDateFormat(source, DateUtils.DATEFORMAT2);
}
}
return null;
}
}
package org.hongxi.whatsmars.earth.web.interceptor;
import org.hongxi.whatsmars.common.util.DESUtils;
import org.hongxi.whatsmars.earth.common.util.DESUtils;
import org.hongxi.whatsmars.earth.domain.misc.LoginContext;
import org.hongxi.whatsmars.earth.domain.misc.LoginContextHolder;
import org.hongxi.whatsmars.earth.domain.misc.SystemConfig;
......
......@@ -28,16 +28,6 @@
</mvc:message-converters>
</mvc:annotation-driven>
<!--加上下面这个对 mvc:resources 有影响-->
<!--<bean id="conversionService"
class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="com.whatsmars.earth.web.converter.StringToDateConverter"/>
</list>
</property>
</bean>-->
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:resources mapping="/js/**" location="/js/"/>
<mvc:resources mapping="/images/**" location="/images/"/>
......
......@@ -18,8 +18,4 @@
<key>moneyUtils</key>
<class>org.hongxi.whatsmars.earth.domain.util.CalculatorUtils</class>
</tool>
<tool>
<key>numberFormatUtils</key>
<class>org.hongxi.whatsmars.common.util.NumberFormatUtils</class>
</tool>
</toolbox>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册