提交 7f427f9a 编写于 作者: 武汉红喜's avatar 武汉红喜

init

上级 e1c84072
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*/src/main/webapp/WEB-INF/classes
.project
.classpath
*.MF
*git*
whatsmars-*/.settings
whatsmars-*/target
whatsmars-*/bin
.settings
*.iws
*.iml
*.ipr
.idea/*
profile/production.properties
profile/test.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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.whatsmars</groupId>
<artifactId>whatsmars-mars001</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>whatsmars-mars001-common</module>
<module>whatsmars-mars001-domain</module>
<module>whatsmars-mars001-dao</module>
<module>whatsmars-mars001-service</module>
<module>whatsmars-mars001-web</module>
</modules>
<properties>
<spring.version>3.2.11.RELEASE</spring.version>
<ibatis.version>3.2.7</ibatis.version>
<rootdir>${basedir}</rootdir>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<!-- -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.32</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.struts</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!--<scm>
<connection>scm:git:git@git.whatsmars.com:whatsmars/mars001.git</connection>
<url>scm:git:git@git.whatsmars.com:whatsmars/mars001.git</url>
<developerConnection>scm:git:git@git.whatsmars.com:whatsmars/mars001.git</developerConnection>
</scm>-->
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<?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-mars001</artifactId>
<groupId>com.whatsmars</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>whatsmars-mars001-common</artifactId>
<packaging>jar</packaging>
<name>whatsmars-mars001-common</name>
<url>http://maven.apache.org</url>
<build>
<finalName>whatsmars-mars001-common</finalName>
</build>
<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>
<version>3.0.0</version>
</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>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</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>
<version>18.0</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</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>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.6</version>
</dependency>-->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.whatsmars.mars001.common;
/**
* Created by liuguanqing on 15/4/16.
*/
public class CommonConstants {
public static final String FS_SECURITY_KEY = "ELO7hccMHrZr3D6NrgwSOEwFycWh1Y9u";
}
package com.whatsmars.mars001.common;
/**
* Created by liuguanqing on 15/4/20.
*/
public enum ImageSizeEnum {
PIXELS_200(200, "x2"),
PIXELS_400(400, "x4"),
PIXELS_600(600, "x6"),
PIXELS_800(800, "x8"),
PIXELS_MAX(1024, "xm");//最大1024
public int size;
public String path;
ImageSizeEnum(int size, String path) {
this.size = size;
this.path = path;
}
public static ImageSizeEnum valueOfPath(String path) {
if(path == null) {
return null;
}
for(ImageSizeEnum e : ImageSizeEnum.values()) {
if(e.path.equalsIgnoreCase(path)) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.common.mail;
import org.apache.commons.mail.*;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
/**
* Created by liuguanqing on 15/4/11.
*/
public class EmailSenderClient {
private String hostName;//发送端Host
private int smtpPort;//发送端口
private String username;
private String password;
private String fromAddress;//发送邮件的发送地址
private boolean sslOn = true;
private static final String DEFAULT_CHARSET = "utf-8";
public void setHostName(String hostName) {
this.hostName = hostName;
}
public void setSmtpPort(int smtpPort) {
this.smtpPort = smtpPort;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setFromAddress(String fromAddress) {
this.fromAddress = fromAddress;
}
public void setSslOn(boolean sslOn) {
this.sslOn = sslOn;
}
public void sendEmail(Email email) throws Exception {
email.setAuthentication(username, password);
email.setCharset(DEFAULT_CHARSET);
email.setFrom(fromAddress);
email.setSSLOnConnect(sslOn);
email.setHostName(hostName);
email.setSmtpPort(smtpPort);
email.send();
}
public void sendTextEmail(String targetAddress,String title,String content) throws Exception {
Email email = new SimpleEmail();
email.setMsg(content);
email.setSubject(title);
email.addTo(targetAddress);
sendEmail(email);
}
/**
* content为html,此方法将会对html进行转义。
* @param targetAddress
* @param title
* @param content
* @throws Exception
*/
public void sendHtmlEmail(String targetAddress,String title,String content) throws Exception {
HtmlEmail email = new HtmlEmail();
email.setSubject(title);
email.setHtmlMsg(content);
email.addTo(targetAddress);
sendEmail(email);
}
/**
* 发送多媒体邮件,可以携带附件信息
* @param urls 附件的URL,key为附件的名称
*/
public void sendMultipartEmail(String targetAddress,String title,String content,Map<String,URL> urls) throws Exception {
MultiPartEmail email = new MultiPartEmail();
for(Map.Entry<String,URL> entry : urls.entrySet()) {
email.attach(entry.getValue(),entry.getKey(),EmailAttachment.ATTACHMENT);
}
email.setSubject(title);
email.addTo(targetAddress);
email.setMsg(content);
sendEmail(email);
}
public static void main(String[] args) throws Exception{
EmailSenderClient client = new EmailSenderClient();
client.setSmtpPort(25);
client.setHostName("smtp.qq.com");
client.setUsername("service@xuehaodai.com");
client.setPassword("xuehaodai99");//您的邮箱密码
client.setSslOn(true);
client.setFromAddress("service@xuehaodai.com");
String targetAddress = "shift_alt_ctrl@163.com";
//client.sendTextEmail("shift_alt_ctrl@163.com","测试邮件","是否可以收到邮件!");
Map<String,URL> attaches = new HashMap<String, URL>();
attaches.put("logo",new URL("http://www.baidu.com/img/bd_logo1.png"));
attaches.put("logo2",new URL("http://commons.apache.org/proper/commons-email/images/commons-logo.png"));
client.sendMultipartEmail(targetAddress, "测试邮件", "test", attaches);
System.out.println("发送成功!");
}
}
package com.whatsmars.mars001.common.mongo;
import com.whatsmars.mars001.common.ImageSizeEnum;
import com.whatsmars.mars001.common.mongo.object.MongoDBConfig;
import com.whatsmars.mars001.common.mongo.object.MongoDBCredential;
import com.whatsmars.mars001.common.mongo.object.MongoDBDriver;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile;
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.imgscalr.Scalr;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.zip.Adler32;
/**
* Author: qing
* Date: 14-10-11
*/
public class GridFSClient extends MongoDBClient{
private GridFS _gridFS = null;
private Object lock = new Object();
protected static final String[] IMAGE_FORMAT = {"jpg","jpeg","png"};
public void setMongoDBDriver(MongoDBDriver mongoDBDriver) {
this.mongoDBDriver = mongoDBDriver;
}
public GridFS getInstance() {
if(_gridFS != null) {
return _gridFS;
}
synchronized (lock) {
if(_gridFS != null) {
return _gridFS;
}
_gridFS = new GridFS(mongoDBDriver.getDB(this.databaseName));
return _gridFS;
}
}
public void close() {
mongoDBDriver.close();
}
/**
*
* @param inputStream 文件流
* @param format 文件格式,“pdf”,“png”等,不包含后缀符号“.”
* @return
*/
public String saveFile(InputStream inputStream,String format,String uid) {
try {
GridFS gridFS = getInstance();
//随机生成文件名称,多次重试
String filename = this.randomFileName();
//如果有文件重复,则重新生成filename
while (true) {
GridFSDBFile _current = gridFS.findOne(filename);
//如果文件不存在,则保存操作
if (_current == null) {
break;
}
filename = this.randomFileName();
}
GridFSInputFile file = gridFS.createFile(inputStream, filename);
if(format != null) {
file.put("format", format);
}
if(uid != null) {
file.put("uid",uid);
}
file.put("content-type","application/octet-stream");
file.save();
return concat(filename,format);
}catch (Exception e) {
throw new RuntimeException(e);
} finally {
try{
inputStream.close();
}catch (Exception ex) {
//
}
}
}
private String concat(String filename,String format) {
if(format == null) {
return filename;
}
if(format.startsWith(".")) {
return filename + format;
}
return filename + "." + format;
}
private String randomFileName() {
return RandomStringUtils.random(32, true, true).toLowerCase();
}
public void delete(String filename) {
GridFS gridFS = getInstance();
gridFS.remove(filename);
}
public InputStream getFile(String filename) {
GridFS gridFS = getInstance();
GridFSDBFile _current = gridFS.findOne(filename);
if(_current == null) {
return null;
}
return _current.getInputStream();
}
public InputStream getImage(String filename,String path) throws Exception{
//获取最大边,等比缩放
if(ImageSizeEnum.valueOfPath(path) == null) {
return null;
}
GridFS gridFS = getInstance();
GridFSDBFile _current = gridFS.findOne(filename);
if(_current == null) {
return null;
}
int size = ImageSizeEnum.valueOfPath(path).size;
int max = (Integer)_current.get("max");//图片的实际尺寸
InputStream result = null;
//裁剪
if(size < max) {
InputStream inputStream = _current.getInputStream();
BufferedImage image = ImageIO.read(inputStream);
inputStream.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BufferedImage thumbnail = Scalr.resize(image, size);//保留最大尺寸
String format = (String) _current.get("format");
ImageIO.write(thumbnail, format, bos);
result = new ByteArrayInputStream(bos.toByteArray());
} else {
result = _current.getInputStream();
}
return result;
}
/**
*
* @param inputStream 输入流
* @return
* @throws Exception
*/
public String saveImage(InputStream inputStream,String uid) throws Exception{
BundleEntry bundleEntry = this.drain(inputStream);
if(bundleEntry == null) {
throw new RuntimeException("file isn't a image!");
}
ByteArrayInputStream bis = bundleEntry.inputStream;
String _currentFileName = this.isExistedImage(bundleEntry);
//如果文件md5已存在
if(_currentFileName != null) {
return _currentFileName;
}
String format = bundleEntry.format;
GridFS gridFS = getInstance();
String filename = this.randomFileName();
//检测文件名称
while(true){
GridFSDBFile _current = gridFS.findOne(filename);
//如果文件不存在,则保存操作
if (_current == null) {
break;
}
//否则,重新生成文件名称
filename = randomFileName();
}
//图片处理
bis.reset();
//保存原图
GridFSInputFile _inputFile = gridFS.createFile(bis, filename);
if(uid != null) {
_inputFile.put("uid", uid);
}
_inputFile.put("max",bundleEntry.max);
_inputFile.put("crc",bundleEntry.crc);
_inputFile.put("format",format);
_inputFile.put("md5_source",bundleEntry.md5);
_inputFile.save();
return concat(filename,format);
}
private String isExistedImage(BundleEntry entry) {
GridFS gridFS = getInstance();
DBObject query = new BasicDBObject();
query.put("crc",entry.crc);
query.put("md5_source",entry.md5);
GridFSDBFile _current = gridFS.findOne(query);
//根据MD5值查询,检测是否存在
if(_current == null) {
return null;
}
String format = (String)_current.get("format");
if(format.startsWith(".")) {
return _current.getFilename() + format;
}
return _current.getFilename() + "." + format;
}
/**
* 因为图片的stream需要reset,所以需要将流全部汲取
* @param inputStream
* @return
* @throws Exception
*/
protected BundleEntry drain(InputStream inputStream) throws Exception{
//
ByteArrayOutputStream bos = new ByteArrayOutputStream();
//计算源文件的md5、crc,以防止图片的重复上传
Adler32 crc = new Adler32();
try{
while(true) {
int _c = inputStream.read();
if(_c == -1) {
break;
}
bos.write(_c);
crc.update(_c);
}
}catch (Exception e) {
throw new RuntimeException(e);
} finally {
inputStream.close();
}
//第一步:图片格式
List<String> formats = new ArrayList<String>();//
ImageInputStream imageInputStream = ImageIO.createImageInputStream(new ByteArrayInputStream(bos.toByteArray()));
imageInputStream.mark();
try {
Iterator<ImageReader> it = ImageIO.getImageReaders(imageInputStream);
while (it.hasNext()) {
ImageReader reader = it.next();
String format = reader.getFormatName().toLowerCase();
if(ArrayUtils.contains(IMAGE_FORMAT, format)) {
formats.add(format);
}
}
}catch (Exception ex) {
//
}
//如果格式不合法,则直接返回
if(formats.isEmpty()) {
try {
imageInputStream.close();
} catch (Exception e) {
//
}
return null;
}
String md5 = DigestUtils.md5Hex(bos.toByteArray());//求原始图片的MD5,和crc
System.out.println("md5:" + md5);
imageInputStream.reset();
BufferedImage image = ImageIO.read(imageInputStream);
//获取最大边,等比缩放
int max = Math.max(image.getHeight(), image.getWidth());
bos = new ByteArrayOutputStream();
//如果尺寸超过最大值,则resize
if(max > ImageSizeEnum.PIXELS_MAX.size) {
max = ImageSizeEnum.PIXELS_MAX.size;
}
String format = formats.get(0);
BufferedImage thumbnail = Scalr.resize(image, max);//保留最大尺寸
ImageIO.write(thumbnail, format, bos);
return new BundleEntry(new ByteArrayInputStream(bos.toByteArray()),md5,crc.getValue(),format,max);
}
protected class BundleEntry {
String md5;
long crc;
String format;
int max;
ByteArrayInputStream inputStream;
BundleEntry(ByteArrayInputStream inputStream,String md5,long crc,String format,int max) {
this.md5 = md5;
this.crc = crc;
this.inputStream = inputStream;
this.format = format;
this.max = max;
}
}
public static void main(String[] args) throws Exception{
MongoDBDriver mongoDBDriver = new MongoDBDriver();
try {
GridFSClient client = new GridFSClient();
MongoDBConfig mongoDBConfig = new MongoDBConfig();
//mongoDBConfig.setAddresses("61.172.238.149:27017");
mongoDBConfig.setAddresses("61.172.240.58:27017");
List<MongoDBCredential> credentials = new ArrayList<MongoDBCredential>();
MongoDBCredential credential = new MongoDBCredential();
credential.setDatabaseName("ixhong-fs");
credential.setUsername("xuehaodai");
//credential.setPassword("haodai.com");
credential.setPassword("passwordisfs");
credentials.add(credential);
mongoDBConfig.setCredentials(credentials);
mongoDBDriver.setConfiguration(mongoDBConfig);
mongoDBDriver.init();
client.setDatabaseName("ixhong-fs");
client.setMongoDBDriver(mongoDBDriver);
testUpload(client);
//testClear(client.getInstance());
//testGetImage(client.getInstance(),"xhgcguccxumuyl9hzdombgfvzgriv7rf",null);
} catch (Exception e) {
e.printStackTrace();
} finally {
mongoDBDriver.close();
}
}
protected static void testClear(GridFS gridFS) {
DBCursor cursor = gridFS.getFileList();
while (cursor.hasNext()) {
DBObject dbObject = cursor.next();
String filename = (String)cursor.next().get("filename");
System.out.println(filename);
System.out.println(dbObject.toString());
gridFS.remove(filename);
}
cursor.close();
}
protected static void testUpload(GridFSClient client) throws Exception{
FileInputStream inputStream = new FileInputStream(new File("/data/tmp/222222222.jpg"));
try {
String filename = client.saveImage(inputStream, null);
System.out.println(filename);
String source = filename.substring(0,filename.lastIndexOf("."));
System.out.println(source);
InputStream result = client.getImage(source, "x4");
if(result == null) {
System.out.println("not found!");
}
//vejibw36famkscjyksgke7bugzonnyan
FileOutputStream outputStream = new FileOutputStream("/data/tmp/" + filename);
while (true) {
int i = result.read();
if( i == -1) {
break;
}
outputStream.write(i);
}
outputStream.flush();
outputStream.close();
result.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
inputStream.close();
}
}
protected static void testGetImage(GridFS gridFS,String filename,String path) {
DBObject query = new BasicDBObject();
query.put("md5_source","9e131ae4ed7337d4712650229b827725");
GridFSDBFile file = gridFS.findOne(query);
if(file != null) {
System.out.println(file.getFilename());
}
}
}
package com.whatsmars.mars001.common.mongo;
import com.whatsmars.mars001.common.mongo.object.MongoDBConfig;
import com.whatsmars.mars001.common.mongo.object.MongoDBCredential;
import com.whatsmars.mars001.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 java.util.ArrayList;
import java.util.List;
/**
* Author: qing
* Date: 14-10-11
*/
public class MongoDBClient {
protected MongoDBDriver mongoDBDriver;
protected String databaseName;
public void setMongoDBDriver(MongoDBDriver mongoDBDriver) {
this.mongoDBDriver = mongoDBDriver;
}
public void setDatabaseName(String databaseName) {
this.databaseName = databaseName;
}
public MongoCollection<Document> getCollection(String collectionName) {
MongoDatabase db = mongoDBDriver.getDatabase(this.databaseName);
return db.getCollection(collectionName);
}
public MongoDatabase getDatabase() {
return mongoDBDriver.getDatabase(this.databaseName);
}
public static void main(String[] args) throws Exception{
MongoDBDriver mongoDBDriver = new MongoDBDriver();
try{
MongoDBConfig mongoDBConfig = new MongoDBConfig();
//mongoDBConfig.setAddresses("61.172.238.149:27017");
mongoDBConfig.setAddresses("61.172.240.61:27017");
List<MongoDBCredential> credentials = new ArrayList<MongoDBCredential>();
MongoDBCredential credential = new MongoDBCredential();
credential.setDatabaseName("ixhong-common");
credential.setUsername("xuehaodai");
//credential.setPassword("haodai.com");
credential.setPassword("passwordiscommon");
credentials.add(credential);
mongoDBConfig.setCredentials(credentials);
mongoDBDriver.setConfiguration(mongoDBConfig);
mongoDBDriver.init();
MongoDBClient client = new MongoDBClient();
client.setDatabaseName("ixhong-common");
client.setMongoDBDriver(mongoDBDriver);
ListCollectionsIterable<Document> documents = client.getDatabase().listCollections();
MongoCursor<Document> it = documents.iterator();
while (it.hasNext()) {
Document item = it.next();
System.out.println(item.toJson());
}
it.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
mongoDBDriver.close();
}
}
}
package com.whatsmars.mars001.common.mongo.object;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import java.util.ArrayList;
import java.util.List;
/**
* Author: qing
* Date: 14-10-12
*/
public class MongoDBConfig {
private String addresses;
private List<MongoDBCredential> credentials;
public String getAddresses() {
return addresses;
}
public void setAddresses(String addresses) {
this.addresses = addresses;
}
public List<MongoDBCredential> getCredentials() {
return credentials;
}
public void setCredentials(List<MongoDBCredential> credentials) {
this.credentials = credentials;
}
public List<MongoCredential> buildCredentials() {
List<MongoCredential> mongoCredentials = new ArrayList<MongoCredential>();
for(MongoDBCredential item : this.credentials) {
MongoCredential credential = MongoCredential.createCredential(item.getUsername(),item.getDatabaseName(),item.getPassword().toCharArray());
mongoCredentials.add(credential);
}
return mongoCredentials;
}
public List<ServerAddress> buildAddresses() throws Exception{
List<ServerAddress> serverAddresses = new ArrayList<ServerAddress>();
String[] sources = addresses.split(";");
for(String item : sources) {
String[] hp = item.split(":");
serverAddresses.add(new ServerAddress(hp[0],Integer.valueOf(hp[1])));
}
return serverAddresses;
}
}
package com.whatsmars.mars001.common.mongo.object;
/**
* Author: qing
* Date: 14-10-15
*/
public class MongoDBCredential {
private String databaseName;
private String username;
private String password;
public String getDatabaseName() {
return databaseName;
}
public void setDatabaseName(String databaseName) {
this.databaseName = databaseName;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.whatsmars.mars001.common.mongo.object;
import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.client.MongoDatabase;
import org.apache.commons.lang.StringUtils;
import java.util.Properties;
/**
* Author: qing
* Date: 14-10-10
*/
public class MongoDBDriver {
private Properties properties;
/**
*/
private MongoClient mongo = null;
/**
*/
private Integer connectionsPerHost = 32;
private Integer threadsAllowedToBlockForConnectionMultiplier = 5;
private Integer maxWaitTime = 30000;
private Integer connectTimeout = 30000;
private Integer socketTimeout = 30000;
private Integer maxConnectionIdle = 6000;
private MongoDBConfig configuration;
public void setProperties(Properties properties) {
this.properties = properties;
}
public void setConfiguration(MongoDBConfig configuration) {
this.configuration = configuration;
}
public void init() throws Exception{
if(properties != null){
String perHost = properties.getProperty("mongodb.driver.connectionsPerHost");
////////////
if(StringUtils.isNotBlank(perHost)){
connectionsPerHost = Integer.valueOf(perHost);
}
////////////
String multiplier = properties.getProperty("mongodb.driver.threadsAllowedToBlockForConnectionMultiplier");
if(StringUtils.isNotBlank(multiplier)){
threadsAllowedToBlockForConnectionMultiplier = Integer.valueOf(multiplier);
}
/////////////
String waitTime = properties.getProperty("mongodb.driver.maxWaitTime");
if(StringUtils.isNotBlank(waitTime)){
maxWaitTime = Integer.valueOf(waitTime);
}
////////////
String ctimeout = properties.getProperty("mongodb.driver.connectTimeout");
if(StringUtils.isNotBlank(ctimeout)){
connectTimeout = Integer.valueOf(ctimeout);
}
////////////
String stimeout = properties.getProperty("mongodb.driver.socketTimeout");
if(StringUtils.isNotBlank(stimeout)){
socketTimeout = Integer.valueOf(stimeout);
}
////////////
String mci = properties.getProperty("mongodb.driver.maxConnectionIdle");
if(StringUtils.isNotBlank(mci)){
maxConnectionIdle = Integer.valueOf(mci);
}
}
////init,db check and connected.
execute();
}
private void execute() throws Exception{
MongoClientOptions.Builder builder = MongoClientOptions.builder();
builder.connectionsPerHost(this.connectionsPerHost);
builder.threadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier);
builder.socketKeepAlive(true);
builder.maxWaitTime(this.maxWaitTime);
builder.connectTimeout(this.connectTimeout);
builder.socketTimeout(this.socketTimeout);
builder.maxConnectionIdleTime(maxConnectionIdle);
MongoClientOptions options = builder.build();
this.mongo = new MongoClient(configuration.buildAddresses(), configuration.buildCredentials(),options);
}
public void close() {
mongo.close();
}
public Mongo getMongo() {
return mongo;
}
public MongoDatabase getDatabase(String dbName) {
return mongo.getDatabase(dbName);
}
/**
* old api
* @param dbName
* @return
*/
public DB getDB(String dbName) {
return mongo.getDB(dbName);
}
}
\ No newline at end of file
package com.whatsmars.mars001.common.mongo.object;
import org.bson.types.ObjectId;
public class ObjectIdCreator{
public static String creator(){
return new ObjectId().toString();
}
}
package com.whatsmars.mars001.common.mongo.serializer;
import org.apache.commons.lang.time.DateUtils;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.JsonToken;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
public class CustomDateDeserializer extends JsonDeserializer<Date> {
private static final String[] pattern = { "yyyy-MM-dd HH:mm:ss" };
@Override
public Date deserialize(JsonParser arg0, DeserializationContext arg1)
throws IOException, JsonProcessingException {
if (JsonToken.VALUE_STRING.equals(arg0.getCurrentToken())) {
try {
return DateUtils.parseDate(arg0.getText(), pattern);
} catch (ParseException e) {
e.printStackTrace();
}
}
return null;
}
}
package com.whatsmars.mars001.common.mongo.serializer;
import org.apache.commons.lang.time.DateFormatUtils;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
import java.util.Date;
public class CustomDateSerializer extends JsonSerializer<Date> {
private static final String pattern = "yyyy-MM-dd HH:mm:ss";
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeString(DateFormatUtils.format(value, pattern));
}
}
\ No newline at end of file
package com.whatsmars.mars001.common.pojo;
import java.util.HashMap;
import java.util.Map;
public class Result {
private boolean success = false;
private String message;
private ResultCode resultCode = ResultCode.SYSTEM_ERROR;
private Map<String,Object> model = new HashMap<String,Object>(32);
private String responseUrl;//响应的URL,需要跳转的URL;
public void setResponseUrl(String responseUrl) {
this.responseUrl = responseUrl;
}
public String getResponseUrl() {
return responseUrl;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
if(success){
resultCode = ResultCode.SUCCESS;
}
}
public ResultCode getResultCode() {
return resultCode;
}
public void setResultCode(ResultCode resultCode) {
this.resultCode = resultCode;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Result(){}
public Result(boolean success){
this.success = success;
}
public Result addModel(String key,Object value){
this.model.put(key, value);
return this;
}
public Result addModel(Map<String,Object> kv){
if(kv != null)
this.model.putAll(kv);
return this;
}
public Object getModel(String key) {
return this.model.get(key);
}
public Map<String,Object> getAll(){
return this.model;
}
}
package com.whatsmars.mars001.common.pojo;
public class ResultCode {
public String code;
public String message;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
private ResultCode(String code,String message){
this.code = code;
this.message = message;
}
public static final ResultCode SUCCESS = new ResultCode("S00000", "成功");
public static final ResultCode SYSTEM_ERROR = new ResultCode("E00001","系统错误");
public static final ResultCode PARAMETER_ERROR = new ResultCode("E00004","请求参数错误");
public static final ResultCode IMAGE_FORMAT_ERROR = new ResultCode("E00002","图片格式不合法");
public static final ResultCode FILE_EXISTS_ERROR = new ResultCode("E00003","文件已经存在");
public static final ResultCode FILE_NOT_EXISTS_ERROR = new ResultCode("E00005","文件不存在");
public static final ResultCode VALIDATE_FAILURE = new ResultCode("E00006","验证失败");//验证失败
public static final ResultCode NOT_LOGIN = new ResultCode("E00007","您还未登陆");
public static final ResultCode EXPIRED = new ResultCode("E00008","表单过期,请刷新");//token过期
public static final ResultCode PERMISSION_DENIED = new ResultCode("E00009","权限不足");
public static final ResultCode SMS_TIMES_LIMIT = new ResultCode("E00010","短信发送次数超过限制");
public static final ResultCode SMS_SENDING_INTERVAL_LIMIT = new ResultCode("E00011","短信发送时间间隔过短");
}
package com.whatsmars.mars001.common.util;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
/**
* Created by shenhongxi on 15/5/27.
*/
public class AESUtils {
private static final String PADDING = "AES/ECB/PKCS5Padding";
private static final String DEFAULT_ENCODING = "utf-8";
/**
* 加密
*
* @param data
* 需要加密的内容
* @param key
* 加密密码
* @return
*/
public static byte[] encrypt(byte[] data, byte[] key) {
if(key.length!=16){
throw new RuntimeException("Invalid AES key length (must be 16 bytes)");
}
try {
SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec seckey = new SecretKeySpec(enCodeFormat,"AES");
Cipher cipher = Cipher.getInstance(PADDING);// 创建密码器
cipher.init(Cipher.ENCRYPT_MODE, seckey);// 初始化
byte[] result = cipher.doFinal(data);
return result; // 加密
} catch (Exception e){
throw new RuntimeException("encrypt fail!", e);
}
}
/**
* 解密
*
* @param data
* 待解密内容
* @param key
* 解密密钥
* @return
*/
public static byte[] decrypt(byte[] data, byte[] key) {
if(key.length!=16){
throw new RuntimeException("Invalid AES key length (must be 16 bytes)");
}
try {
SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec seckey = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance(PADDING);// 创建密码器
cipher.init(Cipher.DECRYPT_MODE, seckey);// 初始化
byte[] result = cipher.doFinal(data);
return result; // 加密
} catch (Exception e){
throw new RuntimeException("decrypt fail!", e);
}
}
public static String encryptToBase64(String data, String key){
try {
byte[] valueByte = encrypt(data.getBytes(DEFAULT_ENCODING), key.getBytes(DEFAULT_ENCODING));
return new Base64().encodeToString(valueByte);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("encrypt fail!", e);
}
}
public static String decryptFromBase64(String data, String key){
try {
byte[] originalData = new Base64().decode(data.getBytes());
byte[] valueByte = decrypt(originalData, key.getBytes(DEFAULT_ENCODING));
return new String(valueByte, DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("decrypt fail!", e);
}
}
public static String encryptWithKeyBase64(String data, String key){
try {
byte[] valueByte = encrypt(data.getBytes(DEFAULT_ENCODING), new Base64().decode(key.getBytes()));
return new String(new Base64().encode(valueByte));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("encrypt fail!", e);
}
}
public static String decryptWithKeyBase64(String data, String key){
try {
byte[] originalData = new Base64().decode(data.getBytes());
byte[] valueByte = decrypt(originalData, new Base64().decode(key.getBytes()));
return new String(valueByte, DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("decrypt fail!", e);
}
}
public static byte[] genarateRandomKey(){
KeyGenerator keygen = null;
try {
keygen = KeyGenerator.getInstance(PADDING);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(" genarateRandomKey fail!", e);
}
SecureRandom random = new SecureRandom();
keygen.init(random);
Key key = keygen.generateKey();
return key.getEncoded();
}
public static String genarateRandomKeyWithBase64(){
return new String(new Base64().encode(genarateRandomKey()));
}
}
package com.whatsmars.mars001.common.util;
import javax.mail.PasswordAuthentication;
/**
* Created by Administrator on 2015/4/10 0010.
*/
public class Authenticator extends javax.mail.Authenticator {
String userName=null;
String password=null;
public Authenticator(){
}
public Authenticator(String username, String password) {
this.userName = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userName, password);
}
}
package com.whatsmars.mars001.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);
}
public static void main(String[] args) {
}
}
package com.whatsmars.mars001.common.util;
import java.util.HashMap;
import java.util.Map;
/**
* Created by jenny on 4/13/15.
* 根据邮箱获取域名,找到邮箱登陆页
*/
public class EmailUtils {
private static final String MAIL_126 = "http://mail.126.com/";
private static final String MAIL_163 = "http://mail.163.com/";
private static final String MAIL_QQ = "https://mail.qq.com/cgi-bin/loginpage";
private static final String MAIL_SINA = "http://mail.sina.com.cn/";
private static final String MAIL_HOTMAIL = "http://hotmail.msn.com/";
private static final String MAIL_GMAIL = "http://mail.google.com/";
private static final String MAIL_YAHOO = "https://login.yahoo.com/config/mail?.src=ym&.intl=hk";
private static final String MAIL_ALIYUN = "https://mail.aliyun.com/";
private static final String MAIL_139 = "http://mail.10086.cn/";
private static final String MAIL_189 = "http://webmail30.189.cn/w2/";
private static final String MAIL_SOHU = "http://mail.sohu.com/";
private static final Map <String ,String> EMAIL_MAP = new HashMap<String,String>();
static {
EMAIL_MAP.put("126.com", MAIL_126);
EMAIL_MAP.put("163.com", MAIL_163);
EMAIL_MAP.put("qq.com", MAIL_QQ);
EMAIL_MAP.put("sina.cn", MAIL_SINA);
EMAIL_MAP.put("sina.com", MAIL_SINA);
EMAIL_MAP.put("hotmail.com", MAIL_HOTMAIL);
EMAIL_MAP.put("gmail.com", MAIL_GMAIL);
EMAIL_MAP.put("yahoo.com", MAIL_YAHOO);
EMAIL_MAP.put("aliyun.com", MAIL_ALIYUN);
EMAIL_MAP.put("139.com", MAIL_139);
EMAIL_MAP.put("189.cn", MAIL_189);
EMAIL_MAP.put("sohu.com", MAIL_SOHU);
}
public static String getEmailLoginPage(String email){
int index = email.lastIndexOf("@");
if(index == -1) {
return null;
}
return EMAIL_MAP.get(email.substring(index + 1));
}
}
package com.whatsmars.mars001.common.util;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Author: qing
* Date: 14-10-18
*/
public class HttpUtils {
private static final CloseableHttpClient httpClient;
public static final String CHARSET = "UTF-8";
static {
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(6000)
.setSocketTimeout(6000)
.build();
httpClient = HttpClientBuilder.create()
.setDefaultRequestConfig(config)
.build();
}
public static String httpGet(String url) throws Exception {
return httpGet(url,null);
}
public static String httpGet(String url,Map<String,String> params) throws Exception {
return httpGet(url,params,CHARSET);
}
public static String httpGet(String url,Map<String,String> params,String charset) throws Exception {
if(params != null && !params.isEmpty()){
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
for(Map.Entry<String,String> entry : params.entrySet()){
Object value = entry.getValue();
if(value != null){
pairs.add(new BasicNameValuePair(entry.getKey(),value.toString()));
}
}
String queryString = EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
if(url.indexOf("?") > 0) {
url += "&" + queryString;
} else {
url += "?" + queryString;
}
}
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response = httpClient.execute(httpGet);
try {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
httpGet.abort();
throw new RuntimeException("HttpClient,error status code :" + statusCode);
}
HttpEntity entity = response.getEntity();
String result = null;
if (entity != null) {
result = EntityUtils.toString(entity, charset);
}
EntityUtils.consume(entity);
return result;
} finally {
response.close();
}
}
public static String httpPost(String url,HttpEntity requestEntity) throws Exception {
return httpPost(url,null,requestEntity);
}
/**
* 发送body为form格式
* @param url
* @return
* @throws Exception
*/
public static String httpPost(String url,Map<String,String> params,HttpEntity requestEntity) throws Exception{
if(params != null && !params.isEmpty()) {
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> entry : params.entrySet()) {
String value = entry.getValue();
if (value != null) {
pairs.add(new BasicNameValuePair(entry.getKey(), value));
}
}
String queryString = EntityUtils.toString(new UrlEncodedFormEntity(pairs, CHARSET));
if(url.indexOf("?") > 0) {
url += "&" + queryString;
} else {
url += "?" + queryString;
}
}
HttpPost httpPost = new HttpPost(url);
if(requestEntity != null) {
httpPost.setEntity(requestEntity);
}
CloseableHttpResponse response = httpClient.execute(httpPost);
try {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
httpPost.abort();
throw new RuntimeException("HttpClient,error status code :" + statusCode);
}
HttpEntity entity = response.getEntity();
String result = null;
if (entity != null) {
result = EntityUtils.toString(entity, "utf-8");
}
EntityUtils.consume(entity);
return result;
} finally {
response.close();
}
}
/**
* 发送body为输入流
* sample
*/
public static String postBodyAsStream(String url,InputStream inputStream, String encoding) throws Exception{
HttpPost httpPost = new HttpPost(url);
HttpEntity body = new InputStreamEntity(inputStream);
httpPost.setEntity(body);
CloseableHttpResponse response = httpClient.execute(httpPost);
try {
HttpEntity entity = response.getEntity();
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
httpPost.abort();
throw new RuntimeException("HttpClient,error status code :" + statusCode);
}
String result = null;
if (entity != null) {
result = EntityUtils.toString(entity, encoding);
}
EntityUtils.consume(entity);
return result;
} finally {
response.close();
}
}
public static String postBodyAsMultipart(String url,Map<String,ContentBody> contentBodies) throws Exception {
return postBodyAsMultipart(url,contentBodies,CHARSET);
}
/**
* 发送body为multipart form
* sample
*/
public static String postBodyAsMultipart(String url,Map<String,ContentBody> contentBodies,String charset) throws Exception{
HttpPost httpPost = new HttpPost(url);
MultipartEntityBuilder mb = MultipartEntityBuilder.create();
mb.setCharset(Charset.forName(charset));
for(Map.Entry<String,ContentBody> entry : contentBodies.entrySet()) {
mb.addPart(entry.getKey(),entry.getValue());
}
httpPost.setEntity(mb.build());
CloseableHttpResponse response = httpClient.execute(httpPost);
try {
HttpEntity entity = response.getEntity();
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
httpPost.abort();
throw new RuntimeException("HttpClient,error status code :" + statusCode);
}
String result = null;
if (entity != null) {
result = EntityUtils.toString(entity, "utf-8");
}
EntityUtils.consume(entity);
return result;
} finally {
response.close();
}
}
public static InputStream httpGetStream(String url,Map<String,String> params) throws Exception {
if(params != null && !params.isEmpty()){
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
for(Map.Entry<String,String> entry : params.entrySet()){
Object value = entry.getValue();
if(value != null){
pairs.add(new BasicNameValuePair(entry.getKey(),value.toString()));
}
}
String queryString = EntityUtils.toString(new UrlEncodedFormEntity(pairs, CHARSET));
if(url.indexOf("?") > 0) {
url += "&" + queryString;
} else {
url += "?" + queryString;
}
}
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response = httpClient.execute(httpGet);
try {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
httpGet.abort();
throw new RuntimeException("HttpClient,error status code :" + statusCode);
}
HttpEntity entity = response.getEntity();
if (entity != null && entity.isStreaming()) {
return entity.getContent();
}
return null;
} finally {
//response.close();
}
}
public static String buildUrl(String url, Map<String, String> params, String charset){
try {
if(params != null && !params.isEmpty()){
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
for(Map.Entry<String,String> entry : params.entrySet()){
Object value = entry.getValue();
if(value != null){
pairs.add(new BasicNameValuePair(entry.getKey(),value.toString()));
}
}
String queryString = EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
if(url.indexOf("?") > 0) {
url += "&" + queryString;
} else {
url += "?" + queryString;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return url;
}
public static void main(String[] args) throws Exception {
String url = "http://stat.xuehaodai.com/ds/x2/f00qvewaxsqdnrzazhhyguhduc7wd8sv.png";
InputStream inputStream = HttpUtils.httpGetStream(url, null);
try {
FileOutputStream fileOutputStream = new FileOutputStream(new File("/Users/liuguanqing/Documents/test22222.png"));
while (true) {
int i = inputStream.read();
if( i == -1) {
break;
}
fileOutputStream.write((byte)i);
}
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
inputStream.close();
}
}
}
package com.whatsmars.mars001.common.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @author cuichengrui
* Date 2015/4/28
* 身份证工具类
*/
public class IdCardUtils {
/** 中国公民身份证号码最小长度。 */
public static final int CHINA_ID_MIN_LENGTH = 15;
/** 中国公民身份证号码最大长度。 */
public static final int CHINA_ID_MAX_LENGTH = 18;
/** 省、直辖市代码表 */
public static final String cityCode[] = {
"11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41",
"42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65", "71",
"81", "82", "91"
};
/** 每位加权因子 */
public static final int power[] = {
7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2
};
/** 第18位校检码 */
public static final String verifyCode[] = {
"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"
};
/** 最低年限 */
public static final int MIN = 1930;
public static Map<String, String> cityCodes = new HashMap<String, String>();
/** 台湾身份首字母对应数字 */
public static Map<String, Integer> twFirstCode = new HashMap<String, Integer>();
/** 香港身份首字母对应数字 */
public static Map<String, Integer> hkFirstCode = new HashMap<String, Integer>();
static {
cityCodes.put("11", "北京");
cityCodes.put("12", "天津");
cityCodes.put("13", "河北");
cityCodes.put("14", "山西");
cityCodes.put("15", "内蒙古");
cityCodes.put("21", "辽宁");
cityCodes.put("22", "吉林");
cityCodes.put("23", "黑龙江");
cityCodes.put("31", "上海");
cityCodes.put("32", "江苏");
cityCodes.put("33", "浙江");
cityCodes.put("34", "安徽");
cityCodes.put("35", "福建");
cityCodes.put("36", "江西");
cityCodes.put("37", "山东");
cityCodes.put("41", "河南");
cityCodes.put("42", "湖北");
cityCodes.put("43", "湖南");
cityCodes.put("44", "广东");
cityCodes.put("45", "广西");
cityCodes.put("46", "海南");
cityCodes.put("50", "重庆");
cityCodes.put("51", "四川");
cityCodes.put("52", "贵州");
cityCodes.put("53", "云南");
cityCodes.put("54", "西藏");
cityCodes.put("61", "陕西");
cityCodes.put("62", "甘肃");
cityCodes.put("63", "青海");
cityCodes.put("64", "宁夏");
cityCodes.put("65", "新疆");
cityCodes.put("71", "台湾");
cityCodes.put("81", "香港");
cityCodes.put("82", "澳门");
cityCodes.put("91", "国外");
twFirstCode.put("A", 10);
twFirstCode.put("B", 11);
twFirstCode.put("C", 12);
twFirstCode.put("D", 13);
twFirstCode.put("E", 14);
twFirstCode.put("F", 15);
twFirstCode.put("G", 16);
twFirstCode.put("H", 17);
twFirstCode.put("J", 18);
twFirstCode.put("K", 19);
twFirstCode.put("L", 20);
twFirstCode.put("M", 21);
twFirstCode.put("N", 22);
twFirstCode.put("P", 23);
twFirstCode.put("Q", 24);
twFirstCode.put("R", 25);
twFirstCode.put("S", 26);
twFirstCode.put("T", 27);
twFirstCode.put("U", 28);
twFirstCode.put("V", 29);
twFirstCode.put("X", 30);
twFirstCode.put("Y", 31);
twFirstCode.put("W", 32);
twFirstCode.put("Z", 33);
twFirstCode.put("I", 34);
twFirstCode.put("O", 35);
hkFirstCode.put("A", 1);
hkFirstCode.put("B", 2);
hkFirstCode.put("C", 3);
hkFirstCode.put("R", 18);
hkFirstCode.put("U", 21);
hkFirstCode.put("Z", 26);
hkFirstCode.put("X", 24);
hkFirstCode.put("W", 23);
hkFirstCode.put("O", 15);
hkFirstCode.put("N", 14);
}
/**
* 将15位身份证号码转换为18位
*
* @param idCard
* 15位身份编码
* @return 18位身份编码
*/
public static String conver15CardTo18(String idCard) {
String idCard18 = "";
if (idCard.length() != CHINA_ID_MIN_LENGTH) {
return null;
}
if (isNum(idCard)) {
// 获取出生年月日
String birthday = idCard.substring(6, 12);
Date birthDate = null;
try {
birthDate = new SimpleDateFormat("yyMMdd").parse(birthday);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar cal = Calendar.getInstance();
if (birthDate != null)
cal.setTime(birthDate);
// 获取出生年(完全表现形式,如:2010)
String sYear = String.valueOf(cal.get(Calendar.YEAR));
idCard18 = idCard.substring(0, 6) + sYear + idCard.substring(8);
// 转换字符数组
char[] cArr = idCard18.toCharArray();
if (cArr != null) {
int[] iCard = convertCharToInt(cArr);
int iSum17 = getPowerSum(iCard);
// 获取校验位
String sVal = getCheckCode18(iSum17);
if (sVal.length() > 0) {
idCard18 += sVal;
} else {
return null;
}
}
} else {
return null;
}
return idCard18;
}
/**
* 验证身份证是否合法
*/
public static boolean validateCard(String idCard) {
String card = idCard.trim();
if (validateIdCard18(card)) {
return true;
}
if (validateIdCard15(card)) {
return true;
}
String[] cardval = validateIdCard10(card);
if (cardval != null) {
if (cardval[2].equals("true")) {
return true;
}
}
return false;
}
/**
* 验证18位身份编码是否合法
*
* @param idCard 身份编码
* @return 是否合法
*/
public static boolean validateIdCard18(String idCard) {
boolean bTrue = false;
if (idCard.length() == CHINA_ID_MAX_LENGTH) {
// 前17位
String code17 = idCard.substring(0, 17);
// 第18位
String code18 = idCard.substring(17, CHINA_ID_MAX_LENGTH);
if (isNum(code17)) {
char[] cArr = code17.toCharArray();
if (cArr != null) {
int[] iCard = convertCharToInt(cArr);
int iSum17 = getPowerSum(iCard);
// 获取校验位
String val = getCheckCode18(iSum17);
if (val.length() > 0) {
if (val.equalsIgnoreCase(code18)) {
bTrue = true;
}
}
}
}
}
return bTrue;
}
/**
* 验证15位身份编码是否合法
*
* @param idCard
* 身份编码
* @return 是否合法
*/
public static boolean validateIdCard15(String idCard) {
if (idCard.length() != CHINA_ID_MIN_LENGTH) {
return false;
}
if (isNum(idCard)) {
String proCode = idCard.substring(0, 2);
if (cityCodes.get(proCode) == null) {
return false;
}
String birthCode = idCard.substring(6, 12);
Date birthDate = null;
try {
birthDate = new SimpleDateFormat("yy").parse(birthCode.substring(0, 2));
} catch (ParseException e) {
e.printStackTrace();
}
Calendar cal = Calendar.getInstance();
if (birthDate != null)
cal.setTime(birthDate);
if (!validateDate(cal.get(Calendar.YEAR), Integer.valueOf(birthCode.substring(2, 4)),
Integer.valueOf(birthCode.substring(4, 6)))) {
return false;
}
} else {
return false;
}
return true;
}
/**
* 验证10位身份编码是否合法
*
* @param idCard 身份编码
* @return 身份证信息数组
* <p>
* [0] - 台湾、澳门、香港 [1] - 性别(男M,女F,未知N) [2] - 是否合法(合法true,不合法false)
* 若不是身份证件号码则返回null
* </p>
*/
public static String[] validateIdCard10(String idCard) {
String[] info = new String[3];
String card = idCard.replaceAll("[\\(|\\)]", "");
if (card.length() != 8 && card.length() != 9 && idCard.length() != 10) {
return null;
}
if (idCard.matches("^[a-zA-Z][0-9]{9}$")) { // 台湾
info[0] = "台湾";
System.out.println("11111");
String char2 = idCard.substring(1, 2);
if (char2.equals("1")) {
info[1] = "M";
System.out.println("MMMMMMM");
} else if (char2.equals("2")) {
info[1] = "F";
System.out.println("FFFFFFF");
} else {
info[1] = "N";
info[2] = "false";
System.out.println("NNNN");
return info;
}
info[2] = validateTWCard(idCard) ? "true" : "false";
} else if (idCard.matches("^[1|5|7][0-9]{6}\\(?[0-9A-Z]\\)?$")) { // 澳门
info[0] = "澳门";
info[1] = "N";
// TODO
} else if (idCard.matches("^[A-Z]{1,2}[0-9]{6}\\(?[0-9A]\\)?$")) { // 香港
info[0] = "香港";
info[1] = "N";
info[2] = validateHKCard(idCard) ? "true" : "false";
} else {
return null;
}
return info;
}
/**
* 验证台湾身份证号码
*
* @param idCard
* 身份证号码
* @return 验证码是否符合
*/
public static boolean validateTWCard(String idCard) {
String start = idCard.substring(0, 1);
String mid = idCard.substring(1, 9);
String end = idCard.substring(9, 10);
Integer iStart = twFirstCode.get(start);
Integer sum = iStart / 10 + (iStart % 10) * 9;
char[] chars = mid.toCharArray();
Integer iflag = 8;
for (char c : chars) {
sum = sum + Integer.valueOf(c + "") * iflag;
iflag--;
}
return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.valueOf(end) ? true : false;
}
/**
* 验证香港身份证号码(存在Bug,部份特殊身份证无法检查)
* <p>
* 身份证前2位为英文字符,如果只出现一个英文字符则表示第一位是空格,对应数字58 前2位英文字符A-Z分别对应数字10-35
* 最后一位校验码为0-9的数字加上字符"A","A"代表10
* </p>
* <p>
* 将身份证号码全部转换为数字,分别对应乘9-1相加的总和,整除11则证件号码有效
* </p>
*
* @param idCard 身份证号码
* @return 验证码是否符合
*/
public static boolean validateHKCard(String idCard) {
String card = idCard.replaceAll("[\\(|\\)]", "");
Integer sum = 0;
if (card.length() == 9) {
sum = (Integer.valueOf(card.substring(0, 1).toUpperCase().toCharArray()[0]) - 55) * 9
+ (Integer.valueOf(card.substring(1, 2).toUpperCase().toCharArray()[0]) - 55) * 8;
card = card.substring(1, 9);
} else {
sum = 522 + (Integer.valueOf(card.substring(0, 1).toUpperCase().toCharArray()[0]) - 55) * 8;
}
String mid = card.substring(1, 7);
String end = card.substring(7, 8);
char[] chars = mid.toCharArray();
Integer iflag = 7;
for (char c : chars) {
sum = sum + Integer.valueOf(c + "") * iflag;
iflag--;
}
if (end.toUpperCase().equals("A")) {
sum = sum + 10;
} else {
sum = sum + Integer.valueOf(end);
}
return (sum % 11 == 0) ? true : false;
}
/**
* 将字符数组转换成数字数组
*
* @param ca
* 字符数组
* @return 数字数组
*/
public static int[] convertCharToInt(char[] ca) {
int len = ca.length;
int[] iArr = new int[len];
try {
for (int i = 0; i < len; i++) {
iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
return iArr;
}
/**
* 将身份证的每位和对应位的加权因子相乘之后,再得到和值
*
* @param iArr
* @return 身份证编码。
*/
public static int getPowerSum(int[] iArr) {
int iSum = 0;
if (power.length == iArr.length) {
for (int i = 0; i < iArr.length; i++) {
for (int j = 0; j < power.length; j++) {
if (i == j) {
iSum = iSum + iArr[i] * power[j];
}
}
}
}
return iSum;
}
/**
* 将power和值与11取模获得余数进行校验码判断
*
* @param iSum
* @return 校验位
*/
public static String getCheckCode18(int iSum) {
String sCode = "";
switch (iSum % 11) {
case 10:
sCode = "2";
break;
case 9:
sCode = "3";
break;
case 8:
sCode = "4";
break;
case 7:
sCode = "5";
break;
case 6:
sCode = "6";
break;
case 5:
sCode = "7";
break;
case 4:
sCode = "8";
break;
case 3:
sCode = "9";
break;
case 2:
sCode = "x";
break;
case 1:
sCode = "0";
break;
case 0:
sCode = "1";
break;
}
return sCode;
}
/**
* 根据身份编号获取年龄
*
* @param idCard
* 身份编号
* @return 年龄
*/
public static int getAgeByIdCard(String idCard) {
int iAge = 0;
if (idCard.length() == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
String year = idCard.substring(6, 10);
Calendar cal = Calendar.getInstance();
int iCurrYear = cal.get(Calendar.YEAR);
iAge = iCurrYear - Integer.valueOf(year);
return iAge;
}
/**
* 根据身份编号获取生日
*
* @param idCard 身份编号
* @return 生日(yyyy-MM-dd)
*/
public static String getBirthByIdCard(String idCard) {
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
return idCard.substring(6, 10)+"-"+idCard.substring(10,12)+"-"+idCard.substring(12,14);
}
/**
* 根据身份编号获取生日年
*
* @param idCard 身份编号
* @return 生日(yyyy)
*/
public static Short getYearByIdCard(String idCard) {
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
return Short.valueOf(idCard.substring(6, 10));
}
/**
* 根据身份编号获取生日月
*
* @param idCard
* 身份编号
* @return 生日(MM)
*/
public static Short getMonthByIdCard(String idCard) {
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
return Short.valueOf(idCard.substring(10, 12));
}
/**
* 根据身份编号获取生日天
*
* @param idCard
* 身份编号
* @return 生日(dd)
*/
public static Short getDateByIdCard(String idCard) {
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
return Short.valueOf(idCard.substring(12, 14));
}
/**
* 根据身份编号获取性别
*
* @param idCard 身份编号
* @return 性别(M-男,F-女,N-未知)
*/
public static String getGenderByIdCard(String idCard) {
String sGender = "N";
if (idCard.length() == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
String sCardNum = idCard.substring(16, 17);
if (Integer.parseInt(sCardNum) % 2 != 0) {
sGender = "M";
} else {
sGender = "F";
}
return sGender;
}
/**
* 根据身份编号获取户籍省份
*
* @param idCard 身份编码
* @return 省级编码。
*/
public static String getProvinceByIdCard(String idCard) {
int len = idCard.length();
String sProvince = null;
String sProvinNum = "";
if (len == CHINA_ID_MIN_LENGTH || len == CHINA_ID_MAX_LENGTH) {
sProvinNum = idCard.substring(0, 2);
}
sProvince = cityCodes.get(sProvinNum);
return sProvince;
}
/**
* 数字验证
*
* @param val
* @return 提取的数字。
*/
public static boolean isNum(String val) {
return val == null || "".equals(val) ? false : val.matches("^[0-9]*$");
}
/**
* 验证小于当前日期 是否有效
*
* @param iYear
* 待验证日期(年)
* @param iMonth
* 待验证日期(月 1-12)
* @param iDate
* 待验证日期(日)
* @return 是否有效
*/
public static boolean validateDate(int iYear, int iMonth, int iDate) {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int datePerMonth;
if (iYear < MIN || iYear >= year) {
return false;
}
if (iMonth < 1 || iMonth > 12) {
return false;
}
switch (iMonth) {
case 4:
case 6:
case 9:
case 11:
datePerMonth = 30;
break;
case 2:
boolean dm = ((iYear % 4 == 0 && iYear % 100 != 0) || (iYear % 400 == 0))
&& (iYear > MIN && iYear < year);
datePerMonth = dm ? 29 : 28;
break;
default:
datePerMonth = 31;
}
return (iDate >= 1) && (iDate <= datePerMonth);
}
}
package com.whatsmars.mars001.common.util;
import com.whatsmars.mars001.common.pojo.Result;
import org.codehaus.jackson.map.ObjectMapper;
/**
* qing
* JSON字符串与java object之间的互相转换
*
*/
public class JSONConverterUtils {
/**
* if not static,performance will be cost so much;but if you have self config,
* please get your own instance;
*/
private static final ObjectMapper mapper = new ObjectMapper();
public static <T> T converter(String json, Class<T> clazz) {
try {
return mapper.readValue(json, clazz);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String converter(Object obj) {
try{
return mapper.writeValueAsString(obj);
}catch(Exception e){
throw new RuntimeException(e);
}
}
public static void main(String[] args){
Result result = new Result();
result.setSuccess(true);
result.setResponseUrl("/test.jhtml");
result.addModel("test","test");
String json = JSONConverterUtils.converter(result);
System.out.println(json);
}
}
package com.whatsmars.mars001.common.util;
import java.text.NumberFormat;
import java.util.HashMap;
public class MoneyFormatUtils {
public static final String EMPTY = "";
public static final String ZERO = "零";
public static final String ONE = "壹";
public static final String TWO = "贰";
public static final String THREE = "叁";
public static final String FOUR = "肆";
public static final String FIVE = "伍";
public static final String SIX = "陆";
public static final String SEVEN = "柒";
public static final String EIGHT = "捌";
public static final String NINE = "玖";
public static final String TEN = "拾";
public static final String HUNDRED = "佰";
public static final String THOUSAND = "仟";
public static final String TEN_THOUSAND = "万";
public static final String HUNDRED_MILLION = "亿";
public static final String YUAN = "元";
public static final String JIAO = "角";
public static final String FEN = "分";
public static final String DOT = ".";
private static MoneyFormatUtils formatter = null;
private HashMap chineseNumberMap = new HashMap();
private HashMap chineseMoneyPattern = new HashMap();
private NumberFormat numberFormat = NumberFormat.getInstance();
private MoneyFormatUtils() {
numberFormat.setMaximumFractionDigits(4);
numberFormat.setMinimumFractionDigits(2);
numberFormat.setGroupingUsed(false);
chineseNumberMap.put("0", ZERO);
chineseNumberMap.put("1", ONE);
chineseNumberMap.put("2", TWO);
chineseNumberMap.put("3", THREE);
chineseNumberMap.put("4", FOUR);
chineseNumberMap.put("5", FIVE);
chineseNumberMap.put("6", SIX);
chineseNumberMap.put("7", SEVEN);
chineseNumberMap.put("8", EIGHT);
chineseNumberMap.put("9", NINE);
chineseNumberMap.put(DOT, DOT);
chineseMoneyPattern.put("1", TEN);
chineseMoneyPattern.put("2", HUNDRED);
chineseMoneyPattern.put("3", THOUSAND);
chineseMoneyPattern.put("4", TEN_THOUSAND);
chineseMoneyPattern.put("5", TEN);
chineseMoneyPattern.put("6", HUNDRED);
chineseMoneyPattern.put("7", THOUSAND);
chineseMoneyPattern.put("8", HUNDRED_MILLION);
}
public static MoneyFormatUtils getInstance() {
if (formatter == null)
formatter = new MoneyFormatUtils();
return formatter;
}
public String format(String moneyStr) {
checkPrecision(moneyStr);
String result;
result = convertToChineseNumber(moneyStr);
result = addUnitsToChineseMoneyString(result);
return result;
}
public String format(double moneyDouble) {
return format(numberFormat.format(moneyDouble));
}
public String format(int moneyInt) {
return format(numberFormat.format(moneyInt));
}
public String format(long moneyLong) {
return format(numberFormat.format(moneyLong));
}
public String format(Number moneyNum) {
return format(numberFormat.format(moneyNum));
}
private String convertToChineseNumber(String moneyStr) {
String result;
StringBuffer cMoneyStringBuffer = new StringBuffer();
for (int i = 0; i < moneyStr.length(); i++) {
cMoneyStringBuffer.append(chineseNumberMap.get(moneyStr.substring(i, i + 1)));
}
// 拾佰仟万亿等都是汉字里面才有的单位,加上它们
int indexOfDot = cMoneyStringBuffer.indexOf(DOT);
int moneyPatternCursor = 1;
for (int i = indexOfDot - 1; i > 0; i--) {
cMoneyStringBuffer.insert(i, chineseMoneyPattern.get(EMPTY + moneyPatternCursor));
moneyPatternCursor = moneyPatternCursor == 8 ? 1 : moneyPatternCursor + 1;
}
String fractionPart = cMoneyStringBuffer.substring(cMoneyStringBuffer.indexOf("."));
cMoneyStringBuffer.delete(cMoneyStringBuffer.indexOf("."), cMoneyStringBuffer.length());
while (cMoneyStringBuffer.indexOf("零拾") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零拾"), cMoneyStringBuffer.indexOf("零拾") + 2, ZERO);
}
while (cMoneyStringBuffer.indexOf("零佰") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零佰"), cMoneyStringBuffer.indexOf("零佰") + 2, ZERO);
}
while (cMoneyStringBuffer.indexOf("零仟") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零仟"), cMoneyStringBuffer.indexOf("零仟") + 2, ZERO);
}
while (cMoneyStringBuffer.indexOf("零万") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零万"), cMoneyStringBuffer.indexOf("零万") + 2, TEN_THOUSAND);
}
while (cMoneyStringBuffer.indexOf("零亿") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零亿"), cMoneyStringBuffer.indexOf("零亿") + 2, HUNDRED_MILLION);
}
while (cMoneyStringBuffer.indexOf("零零") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零零"), cMoneyStringBuffer.indexOf("零零") + 2, ZERO);
}
if (cMoneyStringBuffer.lastIndexOf(ZERO) == cMoneyStringBuffer.length() - 1)
cMoneyStringBuffer.delete(cMoneyStringBuffer.length() - 1, cMoneyStringBuffer.length());
cMoneyStringBuffer.append(fractionPart);
result = cMoneyStringBuffer.toString();
return result;
}
private String addUnitsToChineseMoneyString(String moneyStr) {
String result;
StringBuffer cMoneyStringBuffer = new StringBuffer(moneyStr);
int indexOfDot = cMoneyStringBuffer.indexOf(DOT);
cMoneyStringBuffer.replace(indexOfDot, indexOfDot + 1, YUAN);
cMoneyStringBuffer.insert(cMoneyStringBuffer.length() - 1, JIAO);
cMoneyStringBuffer.insert(cMoneyStringBuffer.length(), FEN);
if (cMoneyStringBuffer.indexOf("零角零分") != -1){
// 没有零头,加整
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零角零分"), cMoneyStringBuffer.length(), "整");
}else if(cMoneyStringBuffer.indexOf("零分") != -1){
// 没有零分,加整
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零分"), cMoneyStringBuffer.length(), "整");
}else {
if (cMoneyStringBuffer.indexOf("零角") != -1)
cMoneyStringBuffer.delete(cMoneyStringBuffer.indexOf("零角"), cMoneyStringBuffer.indexOf("零角") + 2);
// tmpBuffer.append("整");
}
result = cMoneyStringBuffer.toString();
return result;
}
private void checkPrecision(String moneyStr) {
int fractionDigits = moneyStr.length() - moneyStr.indexOf(DOT) - 1;
if (fractionDigits > 2)
throw new RuntimeException("金额" + moneyStr + "的小数位多于两位。"); //精度不能比分低
}
public static void main(String args[]) {
System.out.println(getInstance().format(new Double(15000.26)));
}
}
\ No newline at end of file
package com.whatsmars.mars001.common.util;
import java.math.BigDecimal;
/**
* Created by jenny on 6/4/15.
*/
public class NumberFormatUtils {
/**
* double类型的数据保留num位小数
* @param value
* @param num
* @return
*/
public static double format(Double value,int num){
if (value == Double.valueOf(value).intValue()){
return Double.valueOf(value).intValue();
}else {
BigDecimal bigDecimal = new BigDecimal(Double.toString(value));
return bigDecimal.setScale(num, BigDecimal.ROUND_HALF_UP).doubleValue();
}
}
}
package com.whatsmars.mars001.common.util;
import com.whatsmars.mars001.common.pojo.Result;
import com.whatsmars.mars001.common.pojo.ResultCode;
import net.sf.json.JSONObject;
import java.util.Map;
/**
* Author: qing
* Date: 14-10-14
*/
public class ResultHelper {
/**
* 页面渲染
* @param result
* @return
*/
public static String renderAsJson(Result result) {
JSONObject source = new JSONObject();
source.put("code",result.getResultCode().code);
source.put("message",result.getResultCode().getMessage());
if(result.getMessage() != null) {
source.put("message",result.getMessage());
}
//渲染实际的数据
Map<String,Object> model = result.getAll();
String responseUrl = result.getResponseUrl();
if(responseUrl != null) {
model.put("_redirect_url",responseUrl);
}
source.put("data",model);
return source.toString();
}
public static String renderAsJson(ResultCode resultCode) {
return renderAsJson(resultCode,null);
}
/**
* 直接跳转URL
* @param responseUrl
* @return
*/
public static String renderAsJson(String responseUrl) {
Result result = new Result();
result.setSuccess(true);
result.setResponseUrl(responseUrl);
return renderAsJson(result);
}
/**
* 直接提示信息
* @param resultCode
* @param message
* @return
*/
public static String renderAsJson(ResultCode resultCode,String message) {
JSONObject source = new JSONObject();
source.put("code",resultCode.code);
if(message == null) {
source.put("message", resultCode.getMessage());
}else {
source.put("message",message);
}
return source.toString();
}
}
package com.whatsmars.mars001.common.util;
/**
* Created by shenhongxi on 15/5/8.
*/
public class UnicodeUtils {
public static String native2ascii(String code) {
char[] chars = code.toCharArray();
int charValue = 0;
String result = "";
for(int i = 0; i < chars.length; i++){
charValue = (int) code.charAt(i);
if (charValue <= 256) {
// result += "& "+Integer.toHexString(charValue)+";";
result += "\\"+Integer.toHexString(charValue);
}else{
// result += "&#x"+Integer.toHexString(charValue)+";";
result += "\\u"+Integer.toHexString(charValue);
}
}
return result;
}
public static String ascii2native(String code) {
char aChar;
int len = code.length();
StringBuffer outBuffer = new StringBuffer(len);
for (int x = 0; x < len;) {
aChar = code.charAt(x++);
if (aChar == '\\') {
aChar = code.charAt(x++);
if (aChar == 'u') {
// Read the xxxx
int value = 0;
for (int i = 0; i < 4; i++) {
aChar = code.charAt(x++);
switch (aChar) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
value = (value << 4) + aChar - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
value = (value << 4) + 10 + aChar - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
value = (value << 4) + 10 + aChar - 'A';
break;
default:
throw new IllegalArgumentException(
"Malformed \\uxxxx encoding.");
}
}
outBuffer.append((char) value);
} else {
if (aChar == 't')
aChar = '\t';
else if (aChar == 'r')
aChar = '\r';
else if (aChar == 'n')
aChar = '\n';
else if (aChar == 'f')
aChar = '\f';
outBuffer.append(aChar);
}
} else
outBuffer.append(aChar);
}
return outBuffer.toString();
}
public static void main(String[] args) {
String result = native2ascii("中国");
String _result = ascii2native(result);
System.out.println(result);
System.out.println(_result);
}
}
package com.whatsmars.mars001.common.util;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
* Created by jenny on 4/15/15.
*/
public class ValidateCodeUtils {
private static final int WIDTH = 85;
private static final int HEIGHT = 40;
/**
* 生成验证码图片
* @return key为code字符串,value位图片
*/
public static Map.Entry<String,BufferedImage> generate() {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); //在内存中创建图象
Graphics2D g = image.createGraphics(); //获取图形上下文
//设定背景色
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, WIDTH, HEIGHT);
g.setFont(new Font("Times New Roman", Font.PLAIN, 18)); //设定字体
//随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
g.setColor(getRandColor(160, 200));
Random random = new Random(); //生成随机类
for (int i = 0; i < 155; i++) {
int x = random.nextInt(WIDTH);
int y = random.nextInt(HEIGHT);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x, y, x + xl, y + yl);
}
StringBuffer sb = new StringBuffer(); //取随机产生的认证码(4位数字)
for (int i = 0; i < 4; i++) {
String code = String.valueOf(random.nextInt(10));
sb.append(code);
//将认证码显示到图象中
g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
g.drawString(code, 13 * i + 18, 27);
}
Map<String,BufferedImage> map = new HashMap<String, BufferedImage>();
map.put(sb.toString(),image);
return map.entrySet().iterator().next();
}
/*
* 给定范围获得随机颜色
*/
private static Color getRandColor(int fc, int bc) {
Random random = new Random();
if (fc > 255) {
fc = 255;
}
if (bc > 255) {
bc = 255;
}
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
}
}
package com.whatsmars.mars001.common.util;
import org.apache.commons.lang.StringUtils;
import java.util.regex.Pattern;
/**
* Created by jenny on 4/10/15.
* 校验数据格式是否正确
*/
public class ValidateUtils {
private static final String EMAIL = "^[a-z0-9]([a-z0-9]*[-_\\.\\+]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\\.][a-z]{2,3}([\\.][a-z]{2,4})?$";
private static final String CARD_ID = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}(\\d|X|x)$";
private static final String CHINA_TEXT="[\\u4e00-\\u9fa5]+";
private static final String PHONE_CHINA_TELECOM = "^1[3578][01379]\\d{8}$";
private static final String PHONE_CHINA_UNION = "^1[34578][01256]\\d{8}$";
private static final String PHONE_CHINA_MOBILE = "^(134[012345678]\\d{7}|1[34578][012356789]\\d{8})$";
/**
* validate Email
*
* @param email
* @return
*/
public static boolean validateEmail(String email) {
if (StringUtils.isBlank(email)) {
return false;
}
return Pattern.matches(EMAIL, email);
}
/**
*
* @param phone
* @return
*/
public static boolean validatePhone(String phone) {
if (StringUtils.isBlank(phone)) {
return false;
}
return Pattern.matches(PHONE_CHINA_TELECOM, phone) || Pattern.matches(PHONE_CHINA_UNION, phone) || Pattern.matches(PHONE_CHINA_MOBILE, phone);
}
/**
* 检测身份证格式是否正确
* @param cardId
* @return
*/
public static boolean validateCardId(String cardId) {
if (StringUtils.isBlank(cardId)) {
return false;
}
return Pattern.matches(CARD_ID, cardId);
}
/**
* 验证字符串是否是中文
* @param chinaText
* @return
*/
public static boolean validateChineseText(String chinaText){
if(StringUtils.isBlank(chinaText)){
return false;
}
return Pattern.matches(CHINA_TEXT,chinaText);
}
/**
* 正则表达式:验证非零的正整数
* @param str
* @return
*/
public static boolean validateNonZeroPositiveInteger(String str)
{
Pattern pattern= Pattern.compile("^[0-9]*$");
java.util.regex.Matcher match=pattern.matcher(str);
if(match.matches()==false)
{
return false;
}
else
{
return true;
}
}
/**
* 正则表达式:验证是否为所要求的金额类型
* 正浮点数
* @param str
* @return
*/
public static boolean validateCurrency(String str)
{
Pattern pattern= Pattern.compile("^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
java.util.regex.Matcher match=pattern.matcher(str);
if(match.matches()==false)
{
return false;
}
else
{
return true;
}
}
/**
* 密码格式不能是纯字母或纯数字
* @param str
* @return
*/
public static boolean validatePassword(String str) {
if(str.matches("[a-zA-Z]+") || str.matches("[0-9]+")) {
return false;
}
return true;
}
}
package com.whatsmars.mars001.common.util;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.runtime.log.NullLogChute;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
/**
* Created by cuichengrui on 2015/5/26.
* 使用 Velocity 模板引擎快速生成文本或文件
*/
public class VelocityUtils {
private static final String CHARSET_UTF8 = "UTF-8";
private static final Velocity velocity = new Velocity();
static {
//设置从classpath中加载模板文件
velocity.setProperty(Velocity.RESOURCE_LOADER, "class");
velocity.setProperty("class.resource.loader.class","org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());
velocity.setProperty(Velocity.INPUT_ENCODING, CHARSET_UTF8);
velocity.setProperty(Velocity.OUTPUT_ENCODING, CHARSET_UTF8);
velocity.init();
}
public static String render(String vm, Map<String,Object> model) {
VelocityContext context = new VelocityContext();
for (Map.Entry<String, Object> entry : model.entrySet()){
context.put(entry.getKey(), entry.getValue());
}
try {
Template template = velocity.getTemplate(vm);
StringWriter sw = new StringWriter();
BufferedWriter writer = new BufferedWriter(sw);
template.merge(context, writer);
writer.flush();
writer.close();
return sw.toString();
} catch (IOException e) {
throw new RuntimeException("velocity to text error.");
}
}
public static void main(String[] args) {
String text = render("contract_loan.vm",new HashMap<String, Object>());
System.out.println(text);
}
}
<?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-mars001</artifactId>
<groupId>com.whatsmars</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>whatsmars-mars001-dao</artifactId>
<packaging>jar</packaging>
<name>whatsmars-mars001-dao</name>
<url>http://maven.apache.org</url>
<build>
<finalName>whatsmars-mars001-dao</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>com.whatsmars</groupId>
<artifactId>whatsmars-mars001-domain</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${ibatis.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.whatsmars.mars001.dao;
/**
* Created by shenhongxi on 2016/4/1.
*/
public interface AccountDao {
public String hello(String name);
}
package com.whatsmars.mars001.dao.impl;
import com.whatsmars.mars001.dao.AccountDao;
/**
* Created by shenhongxi on 2016/4/1.
*/
public class AccountDaoImpl extends BaseDao implements AccountDao {
public String hello(String name) {
return "Hello, " + name;
}
}
package com.whatsmars.mars001.dao.impl;
import org.apache.ibatis.session.SqlSession;
/**
* Author: qing
* Date: 14-10-12
*/
public abstract class BaseDao {
protected SqlSession sqlSession;
public void setSqlSession(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="lazyLoadingEnabled" value="false" />
<setting name="logImpl" value="LOG4J"/>
</settings>
<typeAliases>
<typeAlias type="com.ixhong.domain.pojo.LenderAccountDO" alias="LenderAccountDO"/>
</typeAliases>
<mappers>
<mapper resource="sqlmap/Lender-account-mapper.xml"/>
</mappers>
</configuration>
\ No newline at end of file
<?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="LenderAccountMapper">
</mapper>
\ No newline at end of file
<?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-mars001</artifactId>
<groupId>com.whatsmars</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>whatsmars-mars001-domain</artifactId>
<packaging>jar</packaging>
<name>whatsmars-mars001-domain</name>
<url>http://maven.apache.org</url>
<build>
<finalName>whatsmars-mars001-domain</finalName>
</build>
<dependencies>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.whatsmars.mars001.domain.constants;
public class Constants {
public static final String HTTP_ENCRYPT_KEY ="yc2JffcREheFQlYFIAY5f9sY7uflgBTo";
public static final int COOKIE_MAX_AGE = 24 * 60 * 60;//7 days
public static final String TEACHER_DEFAULT_PASSWORD = "xuehaodai123_";
public static final String VALIDATE_CODE_COOKIE_KEY = "_validate_code_";
//mongodb中存储admin的操作日志
public static final String MONGO_ADMIN_OPERATION_COLLECTION = "xhd-admin-operation";
//mongodb中存储organization的操作日志
public static final String MONGO_ORGANIZATION_OPERATION_COLLECTION = "xhd-organization-operation";
//mongodb中存储
public static final String MONGO_EMAIL_SEND_ERROR_COLLECTION = "xhd-email-send-error";
//发短信记录表
public static final String MONGO_SMS_SEND_OPERATION_COLLECTION = "xhd-sms-send-operation";
//学生账户操作记录
public static final String MONGO_STUDENT_ACCOUNT_FLOW = "student-account-flow";
//投资人账户操作记录
public static final String MONGO_LENDER_ACCOUNT_FLOW = "lender-account-flow";
//机构账户操作记录
public static final String MONGO_ORGANIZATION_ACCOUNT_FLOW = "organization-account-flow";
//学好贷账户操作记录
public static final String MONGO_ADMIN_ACCOUNT_FLOW = "admin-account-flow";
public static final String PHONE_VALIDATE_CODE_COOKIE_KEY = "_phone_validate_code_";
//发送短信 对学生用【阳光E学】签名 对投资人用【学好贷】签名
public static final String SMS_SEND_URL = "http://117.79.237.29:8061/mdsmssend.ashx";
public static final String SMS_SEND_SN = "SDK-SKY-010-02698";
public static final String SMS_SEND_PASSWORD = "85A1D86BFCA3A598C1F9C357070994EB";
public static final String[] DATE_PATTERN = new String[]{"yyyy-MM-dd"};
public static final String[] DATE_TIME_PATTERN = new String[]{"yyyy-MM-dd HH:mm:ss"};
public static final String DATE_PATTERN_CHINESE = "yyyy年MM月dd日";
public static final String[] FILE_FORMAT = {".pdf", ".doc", ".docx", ".xls", ".xlsx", ".jpg", ".jpeg", ".png", ".html", ".htm"};
public static final String[] IMAGE_FORMAT = {".jpg", ".jpeg", ".png"};
//系统中所用的文件或图片(从管理后台上传,/upload/upload.jhtml)
//机构资料-数据查询授权书
public static final String AUTHORIZATION_FILE = "http://stat.xuehaodai.com/ds/5fu9t2l2t3wziqlgctrmjfoedirf7x6k.pdf";
//邮件头部 LOGO
public static final String EMAIL_LOGO = "http://stat.xuehaodai.com/ds/dkh4eeiwz1wqbiszgvrdwmsmsl5gkv9m.png";
//协议文档
public static final String LOAN_PROTOCOL_FILE = "http://stat.xuehaodai.com/ds/2ou1puzlibhlwbgj4wqshq8ulh3hwrmb.pdf";
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 6/11/15.
*/
public enum AdminFlowTypeEnum {
RECHARGE(0, "充值"),
WITHDRAW(1, "提现"),
//借款人还款,学好贷收到服务费
RECEIVE_FEE(9, "收到服务费"),
//投资人充值,学好贷支付充值费用
RECHARGE_FEE(10, "支付充值费用"),
//借款人逾期且机构保证金不足,平台垫付本息
ADMIN_ADVANCE_AMOUNT(13, "平台垫付本息"),
//平台或机构垫付后借款人还款,平台收到逾期罚金
RECEIVE_FINE(14, "收到逾期罚金"),
//平台垫付后借款人还款
RECEIVE_AFTER_ADVANCE(16, "平台垫付后收款");
public Integer code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
AdminFlowTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static AdminFlowTypeEnum value(int code){
for(AdminFlowTypeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by duanxiangchao on 2015/6/11.
*/
public enum AdvanceTypeEnum {
ORGANIZATION(0, "机构垫付"),
PLATFORM(1, "学好贷平台垫付");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
AdvanceTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static AdvanceTypeEnum value(int code){
for(AdvanceTypeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by chenguang on 2015/6/29 0029.
*/
public enum ArticleTypeEnum {
NOTICE(1, "最新公告"),
MEDIA(2, "媒体报道");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
ArticleTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static ArticleTypeEnum value(int code){
for(ArticleTypeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 6/26/15.
*/
public enum BailDegreeNum {
JUNIOR_LOWER(4,"大专以下"),
JUNIOR(5,"大专"),
UNDERGRADUATE(6,"本科及以上");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
BailDegreeNum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static BailDegreeNum value(int code){
for(BailDegreeNum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by cuichengrui on 15/4/24.
*/
public enum BiddingStatusEnum {
ORGANIZATION_AUDITING(10,"机构待审核","机构待审核"),
ORGANIZATION_AUDITED_FAILURE(1,"机构审核拒绝通过","借款失败"),
ADMIN_AUDITING(20,"学好贷发标待审","学好贷审核中"),
ADMIN_AUDITED_FAILURE(2,"学好贷发标审拒绝通过","借款失败"),
ONGOING(30,"投标中","学好贷审核中"),
FAILURE(3,"流标","借款失败"),
FULL_ADMIN_AUDITING(40,"学好贷满标待审","等待签约放款"),
FULL_ADMIN_AUDITED_FAILURE(4,"学好贷满标审拒绝通过","借款失败"),
STAGING(50,"还款中","借款成功,还款中"),
PAID_OFF(60,"还款成功","已还清");
public int code;
public String meaning;
public String meaningOfUser;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
public String getMeaningOfUser() {
return meaningOfUser;
}
BiddingStatusEnum(int code, String meaning,String meaningOfUser) {
this.code = code;
this.meaning = meaning;
this.meaningOfUser = meaningOfUser;
}
public static BiddingStatusEnum value(int code) {
for(BiddingStatusEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
import java.util.HashMap;
import java.util.Map;
/**
* Created by duanxiangchao on 2015/5/18.
*/
public enum BillStageStatusEnum {
NO_PAID(10,"等待还款"),//未出账单
PENDING(1, "等待还款"),//已出账单
PAID(20, "已还");
public Integer code;
public String meaning;
public static Map<String,String> lenderMap = new HashMap<String, String>();
static {
lenderMap.put(NO_PAID.code.toString(),"待收");
lenderMap.put(PENDING.code.toString(),"待收");
lenderMap.put(PAID.code.toString(),"已收");
}
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
BillStageStatusEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static BillStageStatusEnum value(int code){
for(BillStageStatusEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
public static Map<String,String> getLenderMap(){
return lenderMap;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum CensusAddressEnum {
LOCAL(1, "本地"),
REMOTE(2, "外地");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
CensusAddressEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static CensusAddressEnum value(int code){
for(CensusAddressEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum CensusTypeEnum {
VILLAGE(0, "农村"),
CITY(1, "城市");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
CensusTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static CensusTypeEnum value(int code){
for(CensusTypeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by shenhongxi on 15/4/28.
*/
public enum ChainTypeEnum {
CHAIN_STORE(1,"直营"),
FRANCHISEE(2,"加盟"),
OTHER(3,"其他");
public int code;
public String meaning;
ChainTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static ChainTypeEnum value(int code) {
for(ChainTypeEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum ChildNumberEnum {
ZERO(0,"无"),
ONE(1, "一个"),
TWO(2, "两个"),
MORE(3, "三个以上");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
ChildNumberEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static ChildNumberEnum value(int code){
for(ChildNumberEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by cuichengrui on 15/4/10.
*/
public enum CourseStatusEnum {
COURSE_CHECKING(0,"待审核"),
COURSE_CHECKED_SUCCESS(10,"已通过"),
COURSE_CHECKED_FAILURE(20,"未通过"),
COURSE_DISABLED(30,"已停用");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
CourseStatusEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static CourseStatusEnum value(int code) {
for(CourseStatusEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum DegreeEnum {
JUNIOR_HIGH_SCHOOL(0,"初中(含)及以下"),
HIGH_SCHOOL(1, "高中"),
TECHNICAL_SCHOOL(2, "技校"),
POLYTECHNIC_SCHOOL(3, "中专"),
VOCATIONAL_SCHOOL(4,"职高"),
JUNIOR_COLLEGE(5,"大专"),
UNDERGRADUATE(6,"本科"),
POSTGRADUATE(7,"研究生(含)及以上");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
DegreeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static DegreeEnum value(int code){
for(DegreeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
* 就业状态
*/
public enum EmploymentStatusEnum {
STUDYING(0, "在读"),
WORKED(1, "就业"),
OTHER(2, "其他");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
EmploymentStatusEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static EmploymentStatusEnum value(int code){
for(EmploymentStatusEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by chenguang on 2015/4/24 0024.
* 收费
*/
public enum FeeEnum {
BELOW_2W(0.5d, "%/每月","借款管理费,两万元以下"),//借款管理费,两万以下
ABOVE_2W(0.24d, "%/每月","借款管理费,两万元以上"),//借款管理费,两万以上
RECHARGE(0.2d, "%/充值金额","充值手续费"),
WITHDRAWALS(2, "元/每笔","提现手续费");
public double code;
public String meaning;
public String name;
public double getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
public String getName() {
return name;
}
FeeEnum(double code, String meaning, String name) {
this.code = code;
this.meaning = meaning;
this.name = name;
}
public static FeeEnum value(double code){
for(FeeEnum e:values()){
if(e.code == code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by cuichengrui on 2015/6/2.
*/
public enum FlowStatusEnum {
FAILURE(0, "失败"),
SUCCESS(1, "成功"),
ONGOING(2, "处理中");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
FlowStatusEnum(int code,String meaning) {
this.code = code;
this.meaning = meaning;
}
public static FlowStatusEnum value(int code) {
for(FlowStatusEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum GenderEnum {
MALE(0, "男"),
FEMALE(1, "女");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
GenderEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static GenderEnum value(int code){
for(GenderEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum GracePeriodEnum {
THREE(3,"三个月"),
SIX(6, "六个月"),
NINE(9,"九个月"),
TWELVE(12, "十二个月");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
GracePeriodEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static GracePeriodEnum value(int code){
for(GracePeriodEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/26/15.
*/
public enum GraduateStatusEnum {
OWNER(1, "在读"),
RENT(2, "毕业"),
PARENTS(3, "肄业");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
GraduateStatusEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static GraduateStatusEnum value(int code){
for(GraduateStatusEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/26/15.
*/
public enum HouseTypeEnum {
OWNER(1, "自有住房"),
PARENTS(2, "父母住房"),
RENT(3, "租房"),
OTHERS(4,"其他亲友住房");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
HouseTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static HouseTypeEnum value(int code){
for(HouseTypeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
import java.util.HashMap;
import java.util.Map;
/**
* Created by jenny on 6/11/15.
*/
public enum LenderFlowTypeEnum {
RECHARGE(0, "充值"),
WITHDRAW(1, "提现"),
//理财人收到还款
RECEIVE(3, "收到还款"),
//理财人投资冻结
FREEZE(4, "投标冻结"),
//理财人流标退款
REFUND(5,"流标退款"),
//理财人满标时投资成功,扣除投资人冻结余额
BID_SUCCESS(6, "投资成功"),
//投资人提现,学好贷收取提现手续费
WITHDRAW_FEE(11, "提现手续费");
public Integer code;
public String meaning;
public static Map<String,String> map = new HashMap<String, String>();
static {
map.put((RECHARGE.code.toString()),RECHARGE.meaning);
map.put(WITHDRAW.code.toString(),WITHDRAW.meaning);
map.put(RECEIVE.code.toString(),RECEIVE.meaning);
map.put(FREEZE.code.toString(),FREEZE.meaning);
map.put(REFUND.code.toString(),REFUND.meaning);
map.put(BID_SUCCESS.code.toString(),BID_SUCCESS.meaning);
map.put(WITHDRAW_FEE.code.toString(),WITHDRAW_FEE.meaning);
}
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
LenderFlowTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static LenderFlowTypeEnum value(int code){
for(LenderFlowTypeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
public static Map getMap(){
return map;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum MarryStatusEnum {
UNMARRIED(0, "未婚"),
MARRIED(1, "已婚"),
DIVORCED(3, "离异");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
MarryStatusEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static MarryStatusEnum value(int code){
for(MarryStatusEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum MonthLimitEnum {
SIX(6, "六个月"),
TWELVE(12, "十二个月"),
EIGHTEEN(18, "十八个月"),
TWENTY_FOUR(24, "二十四个月");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
MonthLimitEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static MonthLimitEnum value(int code){
for(MonthLimitEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by chenguang on 2015/4/29 0029.
* mongodb日志操作的类型
*/
public enum OperationsLogTypeEnum {
AUDIT_ORGANIZATION(1, "机构资质审核"),
UPDATE_BAIL_PERCENT(2, "保证金比例修改"),
AUDIT_COURSE(3, "课程审核"),
STUDENT_ORGANIZATION_AUDIT(4,"机构审核学生信息"),
BIDDING_ADMIN_AUDIT(5,"管理员发标审核"),
BIDDING_FULL_ADMIN_AUDIT(6,"管理员满标审核"),
STUDENT_ACCOUNT_FLOW(7,"学生账户流水"),
LENDER_ACCOUNT_FLOW(8,"投资人账户流水"),
ORGANIZATION_ACCOUNT_FLOW(9,"机构账户流水"),
ADMIN_ACCOUNT_FLOW(10,"学好贷平台流水");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
OperationsLogTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static OperationsLogTypeEnum value(int code) {
for(OperationsLogTypeEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by shenhongxi on 15/4/28.
* 机构复检类型(频率)
*/
public enum OrganizationCheckTypeEnum {
QUARTER(1,"每季"),
MONTH(2,"每月");
public int code;
public String meaning;//意义
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
OrganizationCheckTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static OrganizationCheckTypeEnum value(int code) {
for(OrganizationCheckTypeEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 6/11/15.
*/
public enum OrganizationFlowTypeEnum {
RECHARGE(0, "充值"),
WITHDRAW(1, "提现"),
//满标审核通过钱转给机构
FULL_BIDDING_TRANSFER(7 , "满标转账"),
//满标审核通过扣除机构保证金
BAIL(8, "扣除保证金"),
//借款人逾期,机构垫付
ORGANIZATION_ADVANCE_AMOUNT(12, "机构垫付本息"),
//机构垫付后借款人还款
ORGANIZATION_RECEIVE_AFTER_ADVANCE(15, "机构垫付后收款");
public Integer code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
OrganizationFlowTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static OrganizationFlowTypeEnum value(int code){
for(OrganizationFlowTypeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by shenhongxi on 15/4/12.
*/
public enum OrganizationFoundTypeEnum {
COMPANY(1,"公司"),
PRIVATE_SCHOOL(2,"民办学校"),
PUBLIC_SCHOOL(3,"公办学校");
public int code;
public String meaning;//意义
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
OrganizationFoundTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static OrganizationFoundTypeEnum value(int code) {
for(OrganizationFoundTypeEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by shenhongxi on 15/6/29.
* 机构类别
*/
public enum OrganizationLevelEnum {
A(1,"A类"),
B(2,"B类");
public int code;
public String meaning;//意义
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
OrganizationLevelEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static OrganizationLevelEnum value(int code) {
for(OrganizationLevelEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by shenhongxi on 15/4/12.
* 机构资产类型
*/
public enum OrganizationPropertyTypeEnum {
PRIVATE(1,"自有"),
RENT(2,"租用");
public int code;
public String meaning;//意义
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
OrganizationPropertyTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static OrganizationPropertyTypeEnum value(int code) {
for(OrganizationPropertyTypeEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by liuguanqing on 15/4/7.
*/
public enum OrganizationStatusEnum {
EMAIL_VALIDATING(0,"邮箱验证中"),
MATERIAL_NOT_SUBMITTED(10,"资料尚未提交"),
MATERIAL_AUDITING(20,"资料审核中"),
MATERIAL_AUDITED_SUCCESS(30,"资料审核通过"),
MATERIAL_AUDITED_FAILED(40,"资料审核不通过");
public int code;
public String meaning;
OrganizationStatusEnum(int code,String meaning) {
this.code = code;
this.meaning = meaning;
}
public static OrganizationStatusEnum value(int code) {
for(OrganizationStatusEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by gongzaifei on 15/6/3.
*/
public enum OrganizationWithdrawStatusEnum {
AUDITING(0,"审核中"),
AUDITING_SUCCESS(1,"审核通过"),
AUDITING_FAILED(2,"审核不通过"),
SUCCESS(3,"打款成功"),
FAILED(4,"打款失败");
public int code;
public String meaning;
OrganizationWithdrawStatusEnum(int code,String meaning){
this.code = code;
this.meaning = meaning;
}
public static OrganizationWithdrawStatusEnum value(int code){
for(OrganizationWithdrawStatusEnum statusEnum : values()){
if(statusEnum.code == code){
return statusEnum;
}
}
return null;
}
public int getCode(){
return code;
}
public String getMeaning(){
return meaning;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by duanxiangchao on 2015/5/9.
*/
public enum PhoneCodeEnum {
REGISTER(1,"注册手机验证码"),
FIND_PASSWORD(2,"找回密码"),
UPDATE_PHONE(3,"更改手机号");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
PhoneCodeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static PhoneCodeEnum value(int code){
for(PhoneCodeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/22/15.
*/
public enum RelativesEnum {
FATHER(1, "父亲"),
MOTHER(2, "母亲"),
MATE(3,"配偶"),
RELATIVES(4, "其他亲属");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
RelativesEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static RelativesEnum value(int code){
for(RelativesEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 6/11/15.
*/
public enum StudentFlowTypeEnum {
RECHARGE(0, "充值"),
WITHDRAW(1, "提现"),
//借款人还款
REPAYMENT(2, "还款");
public Integer code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
StudentFlowTypeEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static StudentFlowTypeEnum value(int code){
for(StudentFlowTypeEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 24/4/7.
*/
public enum StudentStatusEnum {
INIT(10,"资料尚未提交"),
AUDITING(20,"资料审核中"),
SUCCESS(30,"资料审核通过"),
FAILURE(40,"资料审核不通过");
public int code;
public String meaning;
StudentStatusEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static StudentStatusEnum value(int code) {
for(StudentStatusEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by liuguanqing on 15/4/7.
* 教师状态
*/
public enum TeacherStatusEnum {
INIT(0,"初始状态"),
SUCCESS(1,"正常状态");
public int code;
public String meaning;
TeacherStatusEnum(int code,String meaning) {
this.code = code;
this.meaning = meaning;
}
public static TeacherStatusEnum value(int code) {
for(TeacherStatusEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by liuguanqing on 15/4/3.
*/
public enum UserTypeEnum {
INVESTOR(1,"投资人"),
STUDENT(2,"借款人"),
ORGANIZATION(3,"机构"),
TEACHER(4,"教师"),
ADMIN(5,"管理员");
public int code;
public String meaning;//意义
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
UserTypeEnum(int code,String meaning) {
this.code = code;
this.meaning = meaning;
}
public static UserTypeEnum value(int code) {
for(UserTypeEnum e : values()) {
if(e.code == code) {
return e;
}
}
return null;
}
}
package com.whatsmars.mars001.domain.enums;
/**
* Created by jenny on 4/26/15.
*/
public enum WorkStatusEnum {
IN_PREPARE(1, "离开学校准备工作"),
AT_SCHOOL(2, "在校学习"),
IN_WORK(3, "固定在职工作");
public int code;
public String meaning;
public int getCode() {
return code;
}
public String getMeaning() {
return meaning;
}
WorkStatusEnum(int code, String meaning) {
this.code = code;
this.meaning = meaning;
}
public static WorkStatusEnum value(int code){
for(WorkStatusEnum e:values()){
if(e.code==code){
return e;
}
}
return null;
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册