init
This commit is contained in:
parent
095a1af9b9
commit
528e09dbdd
27
.gitignore
vendored
Normal file
27
.gitignore
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# compiled output
|
||||||
|
/web/dist
|
||||||
|
/web/tmp
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/web/node_modules
|
||||||
|
/web/bower_components
|
||||||
|
|
||||||
|
# misc
|
||||||
|
/web/.sass-cache
|
||||||
|
/web/connect.lock
|
||||||
|
/web/coverage/*
|
||||||
|
/web/libpeerconnection.log
|
||||||
|
/web/npm-debug.log
|
||||||
|
/web/testem.log
|
||||||
|
|
||||||
|
.*
|
||||||
|
!.editorconfig
|
||||||
|
!.ember-cli
|
||||||
|
!.jshintrc
|
||||||
|
!.travis.yml
|
||||||
|
!.watchmanconfig
|
||||||
|
!.gitignore
|
||||||
|
!.gitkeep
|
||||||
|
*.iml
|
7
server/.gitignore
vendored
Normal file
7
server/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.*
|
||||||
|
!.gitignore
|
||||||
|
!.gitosc
|
||||||
|
!.gitkeep
|
||||||
|
*.iml
|
||||||
|
target/
|
||||||
|
bin/
|
14
server/.gitosc/ISSUE_TEMPLATE.en.md
Normal file
14
server/.gitosc/ISSUE_TEMPLATE.en.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
## What was the cause of the issue?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Steps to reproduce
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Error information
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
17
server/.gitosc/PULL_REQUEST_TEMPLATE.en.md
Normal file
17
server/.gitosc/PULL_REQUEST_TEMPLATE.en.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
## Which issue is associated with the pull request?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Describe modification
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Test case
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
1
server/README.md
Normal file
1
server/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
#flaginfo-web-parent
|
1
server/crm/README.md
Normal file
1
server/crm/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Ambition Admin API
|
32
server/crm/deploy
Executable file
32
server/crm/deploy
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# get real path of softlink
|
||||||
|
get_real_path() {
|
||||||
|
local f="$1"
|
||||||
|
while [ -h "$f" ]; do
|
||||||
|
ls=`ls -ld "$f"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
f="$link"
|
||||||
|
else
|
||||||
|
f=`dirname "$f"`/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
eval "$2"="'$f'"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_real_path "$0" prg_path
|
||||||
|
echo "Script Path [$prg_path]"
|
||||||
|
PROJECT_HOME=$(dirname $prg_path)
|
||||||
|
echo "Project Home [$PROJECT_HOME]"
|
||||||
|
cd "$PROJECT_HOME"
|
||||||
|
mvn clean package -Pprod -DskipTests
|
||||||
|
|
||||||
|
sleep 3
|
||||||
|
SERVICE_HOME=/data/program/ambition/admin-api
|
||||||
|
echo "Service Home [$SERVICE_HOME]"
|
||||||
|
|
||||||
|
$SERVICE_HOME/bin/stop.sh
|
||||||
|
mv $SERVICE_HOME/lib/main.jar $SERVICE_HOME/main_prev.jar
|
||||||
|
mv $PROJECT_HOME/target/admin-api.jar $SERVICE_HOME/lib/main.jar
|
||||||
|
$SERVICE_HOME/bin/start.sh
|
77
server/crm/pom.xml
Normal file
77
server/crm/pom.xml
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?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>
|
||||||
|
<artifactId>crm</artifactId>
|
||||||
|
<name>Ambition CRM</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>web-parent</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../web-parent</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.finalName>admin-api</project.build.finalName>
|
||||||
|
<start-class>com.pudonghot.ambition.admin.AmbitionAdminCloud</start-class>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>util</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>mapper</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>file-disk</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-service-support</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-shiro-spring-boot</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Test Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>prod</id>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.pudonghot.ambition.admin;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 05, 2017 14:40:30
|
||||||
|
*/
|
||||||
|
@EnableAutoConfiguration(exclude = {
|
||||||
|
RedisAutoConfiguration.class,
|
||||||
|
DataSourceAutoConfiguration.class})
|
||||||
|
@ComponentScan("com.pudonghot.ambition.admin")
|
||||||
|
public class AmbitionAdminCloud {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args start args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AmbitionAdminCloud.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
package com.pudonghot.ambition.admin.auth;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import org.apache.shiro.session.Session;
|
||||||
|
import org.apache.shiro.subject.Subject;
|
||||||
|
import me.chyxion.tigon.shiro.model.AuthUser;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import me.chyxion.tigon.shiro.AuthCallback;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import me.chyxion.tigon.shiro.model.AuthInfo;
|
||||||
|
import org.apache.shiro.web.subject.WebSubject;
|
||||||
|
import org.apache.shiro.authc.AuthenticationInfo;
|
||||||
|
import org.apache.shiro.authc.AuthenticationToken;
|
||||||
|
import org.apache.shiro.authc.AuthenticationException;
|
||||||
|
import com.pudonghot.ambition.admin.service.AdminLoginLogService;
|
||||||
|
import com.pudonghot.ambition.util.HttpServletRequestUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import com.pudonghot.ambition.admin.service.AdminAuthFailedLogService;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminLoginLogFormForCreate;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminAuthFailedLogFormForCreate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Apr 7, 2015 4:24:08 PM
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class AuthCallbackSupport implements AuthCallback {
|
||||||
|
@Autowired
|
||||||
|
private AdminLoginLogService authLogService;
|
||||||
|
@Autowired
|
||||||
|
private AdminAuthFailedLogService authLogFailedService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onSuccessfulLogin(AuthenticationToken token,
|
||||||
|
AuthenticationInfo info, Subject subject) {
|
||||||
|
|
||||||
|
WebSubject ws = (WebSubject) subject;
|
||||||
|
Session session = ws.getSession(false);
|
||||||
|
HttpServletRequest request = (HttpServletRequest) ws.getServletRequest();
|
||||||
|
|
||||||
|
AuthUser<ViewModel<Admin>> authUser = new AuthUser<ViewModel<Admin>>();
|
||||||
|
String ip = HttpServletRequestUtils.getClientIP(request);
|
||||||
|
authUser.setAttr("ip", ip);
|
||||||
|
String userAgent = request.getHeader("User-Agent");
|
||||||
|
authUser.setAttr("userAgent", userAgent);
|
||||||
|
ViewModel<Admin> user = (ViewModel<Admin>) ((AuthInfo) info).getExtra();
|
||||||
|
final String userId = user.getData().getId();
|
||||||
|
authUser.setUserId(userId);
|
||||||
|
authUser.setUser(user);
|
||||||
|
log.info("Save Auth User [{}] To Session [{}].", user, session.getId());
|
||||||
|
authUser.save(session);
|
||||||
|
|
||||||
|
AdminLoginLogFormForCreate alForm = new AdminLoginLogFormForCreate();
|
||||||
|
alForm.setAdminId(userId);
|
||||||
|
alForm.setIp(ip);
|
||||||
|
alForm.setUserAgent(userAgent);
|
||||||
|
alForm.setCreatedBy(userId);
|
||||||
|
authLogService.create(alForm);
|
||||||
|
// HttpServletResponse response = (HttpServletResponse) ws.getServletResponse();
|
||||||
|
log.info("User [{}] Logined.", userId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onFailedLogin(AuthenticationToken token,
|
||||||
|
AuthenticationException ae, Subject subject) {
|
||||||
|
String loginId = (String) token.getPrincipal();
|
||||||
|
String password = new String((char[]) token.getCredentials());
|
||||||
|
log.info("Login Id [{}] Password [{}] Login Failed.", loginId, password);
|
||||||
|
|
||||||
|
WebSubject ws = (WebSubject) subject;
|
||||||
|
HttpServletRequest request = (HttpServletRequest) ws.getServletRequest();
|
||||||
|
AdminAuthFailedLogFormForCreate form = new AdminAuthFailedLogFormForCreate();
|
||||||
|
form.setLoginId(loginId);
|
||||||
|
form.setPassword(password);
|
||||||
|
form.setIp(HttpServletRequestUtils.getClientIP(request));
|
||||||
|
form.setUserAgent(request.getHeader("User-Agent"));
|
||||||
|
authLogFailedService.create(form);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void beforeLogout(Subject subject) {
|
||||||
|
final WebSubject ws = (WebSubject) subject;
|
||||||
|
final Session session = ws.getSession(false);
|
||||||
|
if (session != null) {
|
||||||
|
log.warn("Session [{}] Logout.", session);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.warn("No Session Found In Subject [{}], Ignore.", subject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package com.pudonghot.ambition.admin.auth;
|
||||||
|
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import me.chyxion.tigon.shiro.AuthRealm;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import me.chyxion.tigon.shiro.model.Credential;
|
||||||
|
import com.pudonghot.ambition.admin.service.AdminService;
|
||||||
|
import org.apache.shiro.authc.LockedAccountException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Apr 7, 2015 4:14:20 PM
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class AuthRealmSupport extends AuthRealm {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AdminService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Credential credential(Object principal) {
|
||||||
|
Credential credential = null;
|
||||||
|
final ViewModel<Admin> adminViewModel = userService.loginFind((String) principal);
|
||||||
|
if (adminViewModel != null) {
|
||||||
|
Admin admin = adminViewModel.getData();
|
||||||
|
if (!admin.isEnabled()) {
|
||||||
|
throw new LockedAccountException("账户已禁用,请联系管理员");
|
||||||
|
}
|
||||||
|
credential = new Credential(
|
||||||
|
admin.getPassword(),
|
||||||
|
admin.getId()).setExtra(adminViewModel);
|
||||||
|
}
|
||||||
|
return credential;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean credentialMatch(Object password, Credential credential) {
|
||||||
|
return userService.validatePassword(
|
||||||
|
((ViewModel<Admin>) credential.getExtra()).getData().getId(),
|
||||||
|
new String((char[])password));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,175 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import org.apache.commons.lang3.CharEncoding;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import com.pudonghot.ambition.common.Constants;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import me.chyxion.tigon.exception.InvalidParamException;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Jun 30, 2016 3:28:06 PM
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Validated
|
||||||
|
public abstract class AbstractBaseController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* build sql like value
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String like(String value) {
|
||||||
|
return "%" + value + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* decode param and build sql like value
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String decodeLike(String value) {
|
||||||
|
return like(decodeParam(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param request
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected InputStream getInputStream(HttpServletRequest request, String name) {
|
||||||
|
return getInputStream(getMultipartFile(request, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected byte[] getBytes(HttpServletRequest request, String name) {
|
||||||
|
return getBytes(getInputStream(request, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected byte[] getBytes(MultipartFile file) {
|
||||||
|
return getBytes(getInputStream(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ins
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected byte[] getBytes(InputStream ins) {
|
||||||
|
try {
|
||||||
|
return ins != null ? IOUtils.toByteArray(ins) : null;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Read Stream Bytes Error Caused", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param request
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected MultipartFile getMultipartFile(HttpServletRequest request, String name) {
|
||||||
|
MultipartFile file = null;
|
||||||
|
if (request instanceof MultipartHttpServletRequest) {
|
||||||
|
file = ((MultipartHttpServletRequest) request).getFile(name);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected InputStream getInputStream(MultipartFile file) {
|
||||||
|
try {
|
||||||
|
return file == null || file.isEmpty() ?
|
||||||
|
null : file.getInputStream();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Read Multipart File Stream Error Caused", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String decodeParam(String param) {
|
||||||
|
if (StringUtils.isNotBlank(param)) {
|
||||||
|
try {
|
||||||
|
log.debug("Decode Param [{}].", param);
|
||||||
|
param = URLDecoder.decode(param, CharEncoding.UTF_8);
|
||||||
|
log.debug("Decode Param Result [{}].", param);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Decode [" + param + "] Error Caused", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param values
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getNotBlankValue(String ... values) {
|
||||||
|
for (String value : values) {
|
||||||
|
if (StringUtils.isNotBlank(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param os
|
||||||
|
* @param deviceType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getPlatformByOsAndDeviceType(String os, String deviceType) {
|
||||||
|
String platform = null;
|
||||||
|
if (Constants.PHONE.equalsIgnoreCase(deviceType) &&
|
||||||
|
Constants.Android.equalsIgnoreCase(os)) {
|
||||||
|
platform = Constants.AndroidPhone;
|
||||||
|
}
|
||||||
|
else if (Constants.PHONE.equalsIgnoreCase(deviceType) &&
|
||||||
|
Constants.iOS.equalsIgnoreCase(os)) {
|
||||||
|
platform = Constants.iPhone;
|
||||||
|
}
|
||||||
|
else if (Constants.PAD.equalsIgnoreCase(deviceType) &&
|
||||||
|
Constants.Android.equalsIgnoreCase(os)) {
|
||||||
|
platform = Constants.AndroidPad;
|
||||||
|
}
|
||||||
|
else if (Constants.PAD.equalsIgnoreCase(deviceType) &&
|
||||||
|
Constants.iOS.equalsIgnoreCase(os)) {
|
||||||
|
platform = Constants.iPad;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new InvalidParamException(
|
||||||
|
"Unknown Request Device Type [{}] OS [{}]", deviceType, os) ;
|
||||||
|
}
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import me.chyxion.tigon.model.ListResult;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import com.pudonghot.ambition.admin.service.AdminService;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminFormForCreate;
|
||||||
|
import com.pudonghot.ambition.form.update.AdminFormForUpdate;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 09, 2017 21:54:00
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/admin")
|
||||||
|
public class AdminController
|
||||||
|
extends BaseQueryController<Admin> {
|
||||||
|
|
||||||
|
@RequestMapping("/list")
|
||||||
|
public ListResult<ViewModel<Admin>> list(
|
||||||
|
@Min(0)
|
||||||
|
@RequestParam(value = "start", defaultValue = "0")
|
||||||
|
int start,
|
||||||
|
@Min(1)
|
||||||
|
@Max(512)
|
||||||
|
@RequestParam(value = "limit", defaultValue = "16")
|
||||||
|
int limit,
|
||||||
|
@RequestParam(value = "search", required = false)
|
||||||
|
String search) {
|
||||||
|
return listViewModels(start, limit, search);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||||
|
public ViewModel<Admin> create(
|
||||||
|
@Valid AdminFormForCreate form,
|
||||||
|
HttpServletRequest request) {
|
||||||
|
return ((AdminService) queryService)
|
||||||
|
.create(form, getAvatar(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||||
|
public ViewModel<Admin> update(
|
||||||
|
@Valid AdminFormForUpdate form,
|
||||||
|
HttpServletRequest request) {
|
||||||
|
return ((AdminService) queryService)
|
||||||
|
.update(form, getAvatar(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/profile")
|
||||||
|
public ViewModel<Admin> profile() {
|
||||||
|
return queryService.findViewModel(getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/upload-avatar")
|
||||||
|
public ViewModel<Admin> uploadAvatar(
|
||||||
|
@RequestParam("avatar") MultipartFile avatar) {
|
||||||
|
return ((AdminService) queryService).update(
|
||||||
|
getUserId(), getInputStream(avatar));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/update-password")
|
||||||
|
public ViewModel<Admin> uploadPassword(@RequestParam("password") String password) {
|
||||||
|
return ((AdminService) queryService).updatePassword(getUserId(), password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected String[] searchCols() {
|
||||||
|
return new String[] {Admin.NAME,
|
||||||
|
Admin.LOGIN_ID,
|
||||||
|
Admin.MOBILE,
|
||||||
|
Admin.EMAIL,
|
||||||
|
Admin.NOTE};
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputStream getAvatar(HttpServletRequest request) {
|
||||||
|
return getInputStream(request, "avatar");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import me.chyxion.tigon.shiro.service.AuthService;
|
||||||
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import com.pudonghot.ambition.admin.service.AdminService;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 09, 2017 22:31:58
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@Controller
|
||||||
|
public class AuthController {
|
||||||
|
@Autowired
|
||||||
|
private AdminService adminService;
|
||||||
|
@Autowired
|
||||||
|
private AuthService authService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/auth/login", method = RequestMethod.POST)
|
||||||
|
public ViewModel<Admin> login(
|
||||||
|
@NotBlank(message = "Param 'loginId' Could Not Be Blank")
|
||||||
|
@RequestParam("loginId")
|
||||||
|
String loginId,
|
||||||
|
@NotBlank(message = "Param 'password' Could Not Be Blank")
|
||||||
|
@RequestParam("password")
|
||||||
|
String password,
|
||||||
|
@RequestParam(value = "rememberMe", defaultValue = "false")
|
||||||
|
boolean rememberMe) {
|
||||||
|
return adminService.findViewModel((String) authService.login(
|
||||||
|
loginId, password, rememberMe).getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* logout
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/auth/logout", method = RequestMethod.POST)
|
||||||
|
public void logout() {
|
||||||
|
authService.logout();
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/auth/info")
|
||||||
|
public ViewModel<Admin> info() {
|
||||||
|
return adminService.findViewModel((String) authService.getAuthUser().getUserId());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import me.chyxion.tigon.shiro.model.AuthUser;
|
||||||
|
import me.chyxion.tigon.shiro.service.AuthService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Jun 2, 2016 12:52:10 PM
|
||||||
|
*/
|
||||||
|
public class BaseController extends AbstractBaseController {
|
||||||
|
@Autowired
|
||||||
|
protected AuthService authService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get auth user id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getUserId() {
|
||||||
|
return (String) getAuthUser().getUserId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get auth user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected AuthUser<ViewModel<Admin>> getAuthUser() {
|
||||||
|
return authService.<ViewModel<Admin>>getAuthUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected ViewModel<Admin> getUser() {
|
||||||
|
return getAuthUser().getUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param paramValue
|
||||||
|
* @param xHeaderValue
|
||||||
|
* @param headerValue
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getParamOrHeader(
|
||||||
|
String paramValue,
|
||||||
|
String xHeaderValue,
|
||||||
|
String headerValue,
|
||||||
|
String name) {
|
||||||
|
String value = getNotBlankValue(paramValue, xHeaderValue, headerValue);
|
||||||
|
Assert.state(StringUtils.isNotBlank(value),
|
||||||
|
"Request Header Or Param [" + name + "] Could Not Be Blank");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.apache.commons.beanutils.BeanUtils;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
|
import me.chyxion.tigon.shiro.service.AuthService;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.bind.annotation.InitBinder;
|
||||||
|
import com.pudonghot.ambition.form.create.BaseFormForCreate;
|
||||||
|
import com.pudonghot.ambition.form.update.BaseFormForUpdate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.context.request.ServletWebRequest;
|
||||||
|
import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* May 17, 2016 2:49:31 PM
|
||||||
|
*/
|
||||||
|
@Order(32)
|
||||||
|
@ControllerAdvice(annotations = {Controller.class, RestController.class})
|
||||||
|
public class BaseControllerAdvice {
|
||||||
|
private static final Logger log =
|
||||||
|
LoggerFactory.getLogger(BaseControllerAdvice.class);
|
||||||
|
@Autowired
|
||||||
|
private AuthService authService;
|
||||||
|
private ByteArrayMultipartFileEditor bamfe =
|
||||||
|
new ByteArrayMultipartFileEditor() {
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setValue(Object value) {
|
||||||
|
super.setValue(value instanceof MultipartFile ||
|
||||||
|
value instanceof byte[] ? value : null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@InitBinder
|
||||||
|
public void registerCustomEditors(WebDataBinder binder, ServletWebRequest request)
|
||||||
|
throws IllegalAccessException, InvocationTargetException {
|
||||||
|
Object target = binder.getTarget();
|
||||||
|
String userId = getUserId();
|
||||||
|
if (target instanceof BaseFormForCreate) {
|
||||||
|
log.debug("Base Form [{}] For Create Found, Set Created By [{}].", target, userId);
|
||||||
|
((BaseFormForCreate) target).setCreatedBy(userId);
|
||||||
|
}
|
||||||
|
else if (target instanceof BaseFormForUpdate) {
|
||||||
|
log.debug("Base Form [{}] For Update Found, Set Updated By [{}].", target, userId);
|
||||||
|
((BaseFormForUpdate) target).setUpdatedBy(userId);
|
||||||
|
}
|
||||||
|
else if (target != null) {
|
||||||
|
log.debug("Set Form [{}] Created/Updated By [{}].", target, userId);
|
||||||
|
BeanUtils.copyProperty(target, "createdBy", userId);
|
||||||
|
BeanUtils.copyProperty(target, "updatedBy", userId);
|
||||||
|
}
|
||||||
|
// PropertyEditorSupport
|
||||||
|
binder.registerCustomEditor(byte[].class, bamfe);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --
|
||||||
|
// inner methods
|
||||||
|
|
||||||
|
String getUserId() {
|
||||||
|
return authService.isAuthenticated() ?
|
||||||
|
(String) authService.getAuthUser().getUserId() : null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import me.chyxion.tigon.model.BaseModel;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import me.chyxion.tigon.form.BaseFormForUpdateApi;
|
||||||
|
import me.chyxion.tigon.service.BaseCrudByFormService;
|
||||||
|
import com.pudonghot.ambition.form.create.BaseFormForCreate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* May 4, 2016 6:09:54 PM
|
||||||
|
*/
|
||||||
|
public class BaseCruController<
|
||||||
|
Model extends BaseModel<String>,
|
||||||
|
FC extends BaseFormForCreate,
|
||||||
|
FU extends BaseFormForUpdateApi<String>>
|
||||||
|
extends BaseQueryController<Model> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected BaseCrudByFormService<String, Model, FC, FU> crudService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||||
|
public ViewModel<Model> create(@Valid FC form) {
|
||||||
|
return crudService.create(form);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||||
|
public ViewModel<Model> update(@Valid FU form) {
|
||||||
|
return crudService.update(form);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import me.chyxion.tigon.model.BaseModel;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import me.chyxion.tigon.form.BaseFormForUpdateApi;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import com.pudonghot.ambition.form.create.BaseFormForCreate;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* May 4, 2016 6:09:54 PM
|
||||||
|
*/
|
||||||
|
public class BaseCrudController<
|
||||||
|
Model extends BaseModel<String>,
|
||||||
|
FC extends BaseFormForCreate,
|
||||||
|
FU extends BaseFormForUpdateApi<String>>
|
||||||
|
extends BaseCruController<Model, FC, FU> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||||
|
public void delete(
|
||||||
|
@NotNull
|
||||||
|
@RequestParam("id")
|
||||||
|
String id) {
|
||||||
|
crudService.delete(id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import me.chyxion.tigon.model.M2;
|
||||||
|
import me.chyxion.tigon.mybatis.Search;
|
||||||
|
import me.chyxion.tigon.model.BaseModel;
|
||||||
|
import me.chyxion.tigon.model.ListResult;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import me.chyxion.tigon.service.BaseQueryService;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* May 10, 2016 4:50:58 PM
|
||||||
|
*/
|
||||||
|
public class BaseQueryController<Model extends BaseModel<String>>
|
||||||
|
extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected BaseQueryService<String, Model> queryService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list view models
|
||||||
|
* @param start
|
||||||
|
* @param limit
|
||||||
|
* @param paramSearch
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected ListResult<ViewModel<Model>> listViewModels(
|
||||||
|
final int start,
|
||||||
|
final int limit,
|
||||||
|
final String paramSearch) {
|
||||||
|
return listViewModels(search(start, limit), paramSearch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list view models
|
||||||
|
* @param search search
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected ListResult<ViewModel<Model>> listViewModels(
|
||||||
|
Search search, String paramSearch) {
|
||||||
|
if (StringUtils.isNotBlank(paramSearch)) {
|
||||||
|
final Search orSearch = new Search();
|
||||||
|
String decodedLikeSearch = decodeLike(paramSearch);
|
||||||
|
for (String col : searchCols()) {
|
||||||
|
orSearch.or(new Search().like(col, decodedLikeSearch));
|
||||||
|
}
|
||||||
|
search.and(orSearch);
|
||||||
|
}
|
||||||
|
return list(search);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find model by id
|
||||||
|
* @param id model id
|
||||||
|
* @return model
|
||||||
|
*/
|
||||||
|
@RequestMapping("/find")
|
||||||
|
public ViewModel<Model> find(@NotNull @RequestParam("id") String id) {
|
||||||
|
return queryService.findViewModel(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return models count
|
||||||
|
*/
|
||||||
|
@RequestMapping("/count")
|
||||||
|
public int count() {
|
||||||
|
return queryService.count(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list view mdoels
|
||||||
|
* @param search
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected ListResult<ViewModel<Model>> list(Search search) {
|
||||||
|
return queryService.listViewModelsPage(search);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return limit offset search
|
||||||
|
* @param start start
|
||||||
|
* @param limit limit
|
||||||
|
* @return search
|
||||||
|
*/
|
||||||
|
protected Search search(int start, int limit) {
|
||||||
|
return new Search().offset(start).limit(limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return simple search cols
|
||||||
|
*/
|
||||||
|
protected String[] searchCols() {
|
||||||
|
return new String[]{ M2.NOTE };
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 10, 2017 23:15:01
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class SiteController {
|
||||||
|
|
||||||
|
@RequestMapping("/")
|
||||||
|
public void index() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/int")
|
||||||
|
public int i() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.pudonghot.ambition.admin.service;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import me.chyxion.tigon.service.BaseCrudService;
|
||||||
|
import com.pudonghot.ambition.model.AdminAuthFailedLog;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminAuthFailedLogFormForCreate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* May 14, 2016 3:10:38 PM
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
public interface AdminAuthFailedLogService extends BaseCrudService<String, AdminAuthFailedLog> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create auth log
|
||||||
|
* @param form
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
ViewModel<AdminAuthFailedLog> create(@Valid AdminAuthFailedLogFormForCreate form);
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.pudonghot.ambition.admin.service;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import me.chyxion.tigon.service.BaseCrudService;
|
||||||
|
import com.pudonghot.ambition.model.AdminLoginLog;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminLoginLogFormForCreate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* May 14, 2016 3:10:38 PM
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
public interface AdminLoginLogService extends BaseCrudService<String, AdminLoginLog> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create auth log
|
||||||
|
* @param form
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
ViewModel<AdminLoginLog> create(@Valid AdminLoginLogFormForCreate form);
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
package com.pudonghot.ambition.admin.service;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import me.chyxion.tigon.service.BaseCrudService;
|
||||||
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminFormForCreate;
|
||||||
|
import com.pudonghot.ambition.form.update.AdminFormForUpdate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* May 4, 2016 1:18:42 PM
|
||||||
|
*/
|
||||||
|
public interface AdminService
|
||||||
|
extends BaseCrudService<String, Admin> {
|
||||||
|
String AVATAR_FOLDER = "admin_avatar";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find user by login id
|
||||||
|
* @param loginId
|
||||||
|
* @return admin view model
|
||||||
|
*/
|
||||||
|
ViewModel<Admin> loginFind(@NotBlank String loginId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param adminId
|
||||||
|
* @param password
|
||||||
|
* @return true if password is correct
|
||||||
|
*/
|
||||||
|
boolean validatePassword(
|
||||||
|
@NotNull String adminId,
|
||||||
|
@NotBlank String password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create admin
|
||||||
|
* @param form form
|
||||||
|
* @param avatar avatar
|
||||||
|
* @return admin view model
|
||||||
|
*/
|
||||||
|
ViewModel<Admin> create(
|
||||||
|
@NotNull
|
||||||
|
@Valid
|
||||||
|
AdminFormForCreate form,
|
||||||
|
InputStream avatar);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update admin
|
||||||
|
* @param form form
|
||||||
|
* @param avatar avatar
|
||||||
|
* @return admin view model
|
||||||
|
*/
|
||||||
|
ViewModel<Admin> update(
|
||||||
|
@NotNull
|
||||||
|
@Valid
|
||||||
|
AdminFormForUpdate form,
|
||||||
|
InputStream avatar);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param adminId
|
||||||
|
* @param avatar
|
||||||
|
* @return admin view model
|
||||||
|
*/
|
||||||
|
@NotNull ViewModel<Admin> update(
|
||||||
|
@NotBlank String adminId,
|
||||||
|
@NotNull InputStream avatar);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param adminId admin id
|
||||||
|
* @param password password
|
||||||
|
* @return admin view model
|
||||||
|
*/
|
||||||
|
@NotNull ViewModel<Admin> updatePassword(
|
||||||
|
@NotBlank String adminId,
|
||||||
|
@NotBlank String password);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.pudonghot.ambition.admin.service.support;
|
||||||
|
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import com.pudonghot.ambition.model.AdminAuthFailedLog;
|
||||||
|
import com.pudonghot.ambition.mapper.AdminAuthFailedLogMapper;
|
||||||
|
import com.pudonghot.ambition.admin.service.AdminAuthFailedLogService;
|
||||||
|
import me.chyxion.tigon.service.support.BaseCrudServiceSupport;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminAuthFailedLogFormForCreate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* May 14, 2016 3:23:37 PM
|
||||||
|
*/
|
||||||
|
public class AdminAuthFailedServiceSupport
|
||||||
|
extends BaseCrudServiceSupport<String, AdminAuthFailedLog, AdminAuthFailedLogMapper>
|
||||||
|
implements AdminAuthFailedLogService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ViewModel<AdminAuthFailedLog> create(AdminAuthFailedLogFormForCreate form) {
|
||||||
|
return create(form.copy(new AdminAuthFailedLog()));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.pudonghot.ambition.admin.service.support;
|
||||||
|
|
||||||
|
import com.pudonghot.ambition.admin.service.AdminLoginLogService;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import com.pudonghot.ambition.model.AdminLoginLog;
|
||||||
|
import com.pudonghot.ambition.mapper.AdminLoginLogMapper;
|
||||||
|
import me.chyxion.tigon.service.support.BaseCrudServiceSupport;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminLoginLogFormForCreate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* May 14, 2016 3:23:37 PM
|
||||||
|
*/
|
||||||
|
public class AdminLoginLogServiceSupport
|
||||||
|
extends BaseCrudServiceSupport<String, AdminLoginLog, AdminLoginLogMapper>
|
||||||
|
implements AdminLoginLogService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ViewModel<AdminLoginLog> create(AdminLoginLogFormForCreate form) {
|
||||||
|
return create(form.copy(new AdminLoginLog()));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,161 @@
|
|||||||
|
package com.pudonghot.ambition.admin.service.support;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import me.chyxion.tigon.mybatis.Search;
|
||||||
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import me.chyxion.tigon.sequence.IdSequence;
|
||||||
|
import com.pudonghot.ambition.file.ImageTool;
|
||||||
|
import com.pudonghot.ambition.util.Sha512Utils;
|
||||||
|
import com.pudonghot.ambition.mapper.AdminMapper;
|
||||||
|
import com.pudonghot.ambition.file.AmbitionFileApi;
|
||||||
|
import com.pudonghot.ambition.admin.service.AdminService;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import com.pudonghot.ambition.form.create.AdminFormForCreate;
|
||||||
|
import com.pudonghot.ambition.form.update.AdminFormForUpdate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import me.chyxion.tigon.service.support.BaseCrudByFormServiceSupport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Sep 22, 2015 10:45:41 AM
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class AdminServiceSupport
|
||||||
|
extends BaseCrudByFormServiceSupport<String, Admin,
|
||||||
|
AdminFormForCreate, AdminFormForUpdate, AdminMapper>
|
||||||
|
implements AdminService {
|
||||||
|
@Autowired
|
||||||
|
private AmbitionFileApi fileApi;
|
||||||
|
@Autowired
|
||||||
|
private ImageTool imageTool;
|
||||||
|
@Value("${default.admin.avatar.size:512}")
|
||||||
|
private int defaultAvatarSize;
|
||||||
|
@Autowired
|
||||||
|
private IdSequence idSeq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ViewModel<Admin> create(AdminFormForCreate form, InputStream avatar) {
|
||||||
|
final ViewModel<Admin> viewModel = super.create(form);
|
||||||
|
final Admin admin = viewModel.getData();
|
||||||
|
if (avatar != null) {
|
||||||
|
uploadAvatar(admin.getId(), avatar);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
uploadAvatar(admin.getId(),
|
||||||
|
admin.getName(),
|
||||||
|
admin.getGender());
|
||||||
|
}
|
||||||
|
return viewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public ViewModel<Admin> update(AdminFormForUpdate form, InputStream avatar) {
|
||||||
|
ViewModel<Admin> viewModel = update(form);
|
||||||
|
if (avatar != null) {
|
||||||
|
fileApi.uploadImage(imageTool.cropToSquare(avatar, defaultAvatarSize),
|
||||||
|
AVATAR_FOLDER, String.valueOf(form.getId()));
|
||||||
|
}
|
||||||
|
return viewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean validatePassword(String adminId, String password) {
|
||||||
|
final Admin admin = mapper.find(adminId);
|
||||||
|
return hashPassword(admin.getId(), password)
|
||||||
|
.equals((admin.getPassword()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ViewModel<Admin> loginFind(String loginId) {
|
||||||
|
log.info("Find Admin By [{}].", loginId);
|
||||||
|
Admin user = null;
|
||||||
|
for (String field : new String[] {Admin.LOGIN_ID, Admin.MOBILE, Admin.EMAIL}) {
|
||||||
|
user = mapper.find(new Search(field, loginId).eq(Admin.ENABLED, true));
|
||||||
|
if (user != null) {
|
||||||
|
log.info("Found Admin [{}] By [{}].", user, field);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return user != null ? toViewModel(user) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public ViewModel<Admin> update(String adminId, InputStream avatar) {
|
||||||
|
final Admin admin = mapper.find(adminId);
|
||||||
|
Assert.state(admin != null, "No Admin [" + adminId + "] Found");
|
||||||
|
admin.setUpdatedBy(adminId);
|
||||||
|
admin.setDateUpdated(new Date());
|
||||||
|
mapper.update(admin);
|
||||||
|
fileApi.uploadImage(imageTool.cropToSquare(avatar, defaultAvatarSize),
|
||||||
|
AVATAR_FOLDER, String.valueOf(adminId));
|
||||||
|
return toViewModel(admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ViewModel<Admin> updatePassword(String userId, String password) {
|
||||||
|
final Admin admin = mapper.find(userId);
|
||||||
|
Assert.state(admin != null, "No Admin [" + userId + "] Found");
|
||||||
|
final String passwordSalt = idSeq.get();
|
||||||
|
admin.setPassword(hashPassword(passwordSalt, password));
|
||||||
|
return update(admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void processViewModel(ViewModel<Admin> viewModel, Admin model) {
|
||||||
|
super.processViewModel(viewModel, model);
|
||||||
|
if (model != null) {
|
||||||
|
viewModel.setAttr("avatar", urlCacheClear(model,
|
||||||
|
fileApi.getUrl(AVATAR_FOLDER, String.valueOf(model.getId()))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String uploadAvatar(final String userId, final String name, final String gender) {
|
||||||
|
return fileApi.uploadAvatar(AVATAR_FOLDER, String.valueOf(userId), name, gender);
|
||||||
|
}
|
||||||
|
|
||||||
|
String uploadAvatar(String id, InputStream avatar) {
|
||||||
|
String avatarUrl = null;
|
||||||
|
if (avatar != null) {
|
||||||
|
avatarUrl = fileApi.uploadImage(
|
||||||
|
imageTool.cropToSquare(avatar, defaultAvatarSize),
|
||||||
|
AVATAR_FOLDER, String.valueOf(id));
|
||||||
|
}
|
||||||
|
return avatarUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String hashPassword(final String passwordSalt, final String password) {
|
||||||
|
return Sha512Utils.encode(password, passwordSalt);
|
||||||
|
}
|
||||||
|
}
|
25
server/crm/src/main/resources/application.properties
Normal file
25
server/crm/src/main/resources/application.properties
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
server.port=8088
|
||||||
|
|
||||||
|
# MySQL
|
||||||
|
db.url=jdbc:mysql://127.0.0.1:43306/pudong_hot?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
||||||
|
db.user=root
|
||||||
|
db.password=696@2^~)oZ@^#*Q
|
||||||
|
|
||||||
|
# Redis
|
||||||
|
redis.host=127.0.0.1
|
||||||
|
redis.port=46379
|
||||||
|
redis.password=0211
|
||||||
|
|
||||||
|
# AliYun Account
|
||||||
|
ali.access.key=K4oM0OVHbLS1cInv
|
||||||
|
ali.access.secret=qjweLLtV1YLoAJQWI3CwFytG78UkTQ
|
||||||
|
|
||||||
|
# OSS
|
||||||
|
ali.oss.bucket=ambition
|
||||||
|
ali.oss.host.internal=oss-cn-shanghai.aliyuncs.com
|
||||||
|
|
||||||
|
# Session Redis prefix
|
||||||
|
shiro.session.redis.prefix=ADMIN_AUTH_SESSION
|
||||||
|
|
||||||
|
spring.http.multipart.max-file-size=1024MB
|
||||||
|
spring.http.multipart.max-request-size=1024MB
|
25
server/crm/src/main/resources/application_dev.properties
Normal file
25
server/crm/src/main/resources/application_dev.properties
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
server.port=8088
|
||||||
|
|
||||||
|
# MySQL
|
||||||
|
db.url=jdbc:mysql://127.0.0.1:43306/pudong_hot?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
||||||
|
db.user=root
|
||||||
|
db.password=696@2^~)oZ@^#*Q
|
||||||
|
|
||||||
|
# Redis
|
||||||
|
redis.host=127.0.0.1
|
||||||
|
redis.port=46379
|
||||||
|
redis.password=0211
|
||||||
|
|
||||||
|
# AliYun Account
|
||||||
|
ali.access.key=K4oM0OVHbLS1cInv
|
||||||
|
ali.access.secret=qjweLLtV1YLoAJQWI3CwFytG78UkTQ
|
||||||
|
|
||||||
|
# OSS
|
||||||
|
ali.oss.bucket=ambition
|
||||||
|
ali.oss.host.internal=oss-cn-shanghai.aliyuncs.com
|
||||||
|
|
||||||
|
# Session Redis prefix
|
||||||
|
shiro.session.redis.prefix=ADMIN_AUTH_SESSION
|
||||||
|
|
||||||
|
spring.http.multipart.max-file-size=1024MB
|
||||||
|
spring.http.multipart.max-request-size=1024MB
|
23
server/crm/src/main/resources/application_prod.properties
Normal file
23
server/crm/src/main/resources/application_prod.properties
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
server.port=8100
|
||||||
|
# MySQL
|
||||||
|
db.url=jdbc:mysql://localhost:3306/pudong_hot?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
||||||
|
db.user=root
|
||||||
|
db.password=696@2^~)oZ@^#*Q
|
||||||
|
|
||||||
|
# Redis
|
||||||
|
redis.host=127.0.0.1
|
||||||
|
redis.port=6379
|
||||||
|
redis.password=0211
|
||||||
|
|
||||||
|
# AliYun Account
|
||||||
|
ali.access.key=K4oM0OVHbLS1cInv
|
||||||
|
ali.access.secret=qjweLLtV1YLoAJQWI3CwFytG78UkTQ
|
||||||
|
|
||||||
|
# OSS
|
||||||
|
ali.oss.bucket=ambition
|
||||||
|
|
||||||
|
# Session Redis prefix
|
||||||
|
shiro.session.redis.prefix=ADMIN_AUTH_SESSION
|
||||||
|
|
||||||
|
spring.http.multipart.max-file-size=1024MB
|
||||||
|
spring.http.multipart.max-request-size=1024MB
|
38
server/crm/src/main/resources/log4j2.xml
Normal file
38
server/crm/src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN">
|
||||||
|
<Properties>
|
||||||
|
<Property name="log.level">DEBUG</Property>
|
||||||
|
<Property name="log.dir">.logs</Property>
|
||||||
|
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||||
|
</Properties>
|
||||||
|
<Appenders>
|
||||||
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout pattern="${pattern}" />
|
||||||
|
</Console>
|
||||||
|
<RollingFile name="File"
|
||||||
|
fileName="${log.dir}/${project.artifactId}.log"
|
||||||
|
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-%d{yyyy-MM-dd}-%i.log">
|
||||||
|
<PatternLayout pattern="${pattern}" />
|
||||||
|
<Policies>
|
||||||
|
<TimeBasedTriggeringPolicy />
|
||||||
|
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||||
|
</Policies>
|
||||||
|
<DefaultRolloverStrategy max="32" />
|
||||||
|
</RollingFile>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Logger name="org.springframework" level="INFO" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Logger name="org.apache" level="WARN" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Logger name="org.hibernate.validator" level="WARN" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Root level="${log.level}" additivity="false">
|
||||||
|
<AppenderRef ref="File" level="${log.level}" />
|
||||||
|
<AppenderRef ref="Console" level="${log.level}" />
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
38
server/crm/src/main/resources/log4j2_dev.xml
Normal file
38
server/crm/src/main/resources/log4j2_dev.xml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN">
|
||||||
|
<Properties>
|
||||||
|
<Property name="log.level">DEBUG</Property>
|
||||||
|
<Property name="log.dir">.logs</Property>
|
||||||
|
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||||
|
</Properties>
|
||||||
|
<Appenders>
|
||||||
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout pattern="${pattern}" />
|
||||||
|
</Console>
|
||||||
|
<RollingFile name="File"
|
||||||
|
fileName="${log.dir}/${project.artifactId}.log"
|
||||||
|
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-%d{yyyy-MM-dd}-%i.log">
|
||||||
|
<PatternLayout pattern="${pattern}" />
|
||||||
|
<Policies>
|
||||||
|
<TimeBasedTriggeringPolicy />
|
||||||
|
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||||
|
</Policies>
|
||||||
|
<DefaultRolloverStrategy max="32" />
|
||||||
|
</RollingFile>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Logger name="org.springframework" level="INFO" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Logger name="org.apache" level="WARN" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Logger name="org.hibernate.validator" level="WARN" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Root level="${log.level}" additivity="false">
|
||||||
|
<AppenderRef ref="File" level="${log.level}" />
|
||||||
|
<AppenderRef ref="Console" level="${log.level}" />
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
37
server/crm/src/main/resources/log4j2_prod.xml
Normal file
37
server/crm/src/main/resources/log4j2_prod.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN">
|
||||||
|
<Properties>
|
||||||
|
<Property name="log.level">INFO</Property>
|
||||||
|
<Property name="log.dir">/data/program/logs/${project.artifactId}</Property>
|
||||||
|
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||||
|
</Properties>
|
||||||
|
<Appenders>
|
||||||
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout pattern="${pattern}" />
|
||||||
|
</Console>
|
||||||
|
<RollingFile name="File"
|
||||||
|
fileName="${log.dir}/${project.artifactId}.log"
|
||||||
|
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-%d{yyyy-MM-dd}-%i.log">
|
||||||
|
<PatternLayout pattern="${pattern}" />
|
||||||
|
<Policies>
|
||||||
|
<TimeBasedTriggeringPolicy />
|
||||||
|
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||||
|
</Policies>
|
||||||
|
<DefaultRolloverStrategy max="32" />
|
||||||
|
</RollingFile>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Logger name="org.springframework" level="INFO" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Logger name="org.apache" level="WARN" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Logger name="org.hibernate.validator" level="WARN" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Root level="${log.level}" additivity="false">
|
||||||
|
<AppenderRef ref="File" level="${log.level}" />
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
3
server/crm/src/main/resources/shiro/auth.properties
Normal file
3
server/crm/src/main/resources/shiro/auth.properties
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/auth/login=anon
|
||||||
|
/=anon
|
||||||
|
/**=user
|
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:p="http://www.springframework.org/schema/p"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
<!--<bean class="com.alibaba.druid.pool.DruidDataSource"-->
|
||||||
|
<!--init-method="init" -->
|
||||||
|
<!--destroy-method="close" -->
|
||||||
|
<!--p:url="${db.url}"-->
|
||||||
|
<!--p:username="${db.user}" -->
|
||||||
|
<!--p:password="${db.password}" />-->
|
||||||
|
</beans>
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.pudonghot.ambition.admin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br />
|
||||||
|
* chyxion@163.com <br />
|
||||||
|
* Sep 1, 2015 2:34:08 PM
|
||||||
|
*/
|
||||||
|
public class TestDriver {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.pudonghot.ambition.admin.controller;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.pudonghot.ambition.admin.AmbitionAdminCloud;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import me.chyxion.tigon.webmvc.test.ControllerTestTool;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 10, 2017 23:15:16
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = AmbitionAdminCloud.class)
|
||||||
|
public class SiteControllerTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ControllerTestTool t;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIndex() {
|
||||||
|
t.print(t.get("/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRaw() {
|
||||||
|
t.print(t.get("/raw"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInt() {
|
||||||
|
t.print(t.get("/int"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPost() {
|
||||||
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
|
params.put("id", "id");
|
||||||
|
params.put("name", "Shaun Chyxion");
|
||||||
|
params.put("gender", "");
|
||||||
|
t.print(t.post("/post", params));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.pudonghot.ambition.admin.service;
|
||||||
|
|
||||||
|
import com.pudonghot.ambition.admin.AmbitionAdminCloud;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Donghuang <br>
|
||||||
|
* donghuang@wacai.com <br>
|
||||||
|
* Apr 24, 2017 11:33 PM
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = AmbitionAdminCloud.class)
|
||||||
|
public class EmployeeServiceTest {
|
||||||
|
@Autowired
|
||||||
|
private EmployeeService employeeService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListEmployee() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
8
server/crm/src/test/resources/spring/spring-test.xml
Normal file
8
server/crm/src/test/resources/spring/spring-test.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
<!-- Scan Controllers -->
|
||||||
|
<bean class="me.chyxion.tigon.webmvc.test.ControllerTestTool" />
|
||||||
|
</beans>
|
23
server/deploy
Executable file
23
server/deploy
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# get real path of softlink
|
||||||
|
get_real_path() {
|
||||||
|
local f="$1"
|
||||||
|
while [ -h "$f" ]; do
|
||||||
|
ls=`ls -ld "$f"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
f="$link"
|
||||||
|
else
|
||||||
|
f=`dirname "$f"`/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
eval "$2"="'$f'"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_real_path "$0" prg_path
|
||||||
|
echo "Script Path [$prg_path]"
|
||||||
|
PROJECT_HOME=$(dirname $prg_path)
|
||||||
|
echo "Project Home [$PROJECT_HOME]"
|
||||||
|
cd "$PROJECT_HOME"
|
||||||
|
mvn clean install -DskipTests
|
1
server/file-api/README.md
Normal file
1
server/file-api/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
#umsapp-file-api
|
52
server/file-api/pom.xml
Normal file
52
server/file-api/pom.xml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?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>
|
||||||
|
<artifactId>file-api</artifactId>
|
||||||
|
<name>Ambition File Api</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>ambition</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion</groupId>
|
||||||
|
<artifactId>image-combine</artifactId>
|
||||||
|
<version>0.0.1-RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-sequence</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Test Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,220 @@
|
|||||||
|
package com.pudonghot.ambition.file;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.4
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 24, 2015 1:22:40 PM
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
public interface AmbitionFileApi {
|
||||||
|
String META_FORMAT = "format";
|
||||||
|
String META_DOWNLOAD_NAME = "downloadName";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get object url
|
||||||
|
* @param folder
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String getUrl(String folder, @NotBlank String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get object raw url
|
||||||
|
* @param folder
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String getRawUrl(String folder, @NotBlank String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get object url
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String getUrl(@NotBlank String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload File To OSS
|
||||||
|
* @param file File
|
||||||
|
* @param name File Name [optional], Such As "foobar.doc",
|
||||||
|
* A UUID Will Be The Name, If Name Not Specified,
|
||||||
|
* @return File Link [http://umsapp.oss-cn-hangzhou.aliyuncs.com/echat-dev/foobar.png]
|
||||||
|
*/
|
||||||
|
@NotBlank String upload(@NotNull File file, String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload File To OSS
|
||||||
|
* @param file File
|
||||||
|
* @param folder Custom Folder
|
||||||
|
* @param name File Name [optional], Such As "foobar.doc",
|
||||||
|
* A UUID Will Be The Name, If Name Not Specified,
|
||||||
|
* @param contentType Content Type [Optional]
|
||||||
|
* @param format File Format [Optional]
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String upload(@NotNull File file, String folder, String name, String contentType, String format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload Stream To OSS
|
||||||
|
* @param ins Input Stream
|
||||||
|
* @param name File Name [optional], Such As "foobar.png",
|
||||||
|
* A UUID Will Be The Name, If Name Not Specified,
|
||||||
|
* @return File Link [http://umsapp.oss-cn-hangzhou.aliyuncs.com/echat-dev/foobar.png]
|
||||||
|
*/
|
||||||
|
@NotBlank String upload(@NotNull InputStream ins, @Min(1) long contentLength, String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload Stream To OSS
|
||||||
|
* @param ins Input Stream
|
||||||
|
* @param folder Custom Folder
|
||||||
|
* @param name File Name [optional], Such As "foobar.doc",
|
||||||
|
* A UUID Will Be The Name, If Name Not Specified,
|
||||||
|
* @param contentType Content Type [Optional]
|
||||||
|
* @param format File Format [Optional]
|
||||||
|
*/
|
||||||
|
@NotBlank String upload(@NotNull InputStream ins,
|
||||||
|
@Min(1) long contentLength,
|
||||||
|
String folder,
|
||||||
|
String name,
|
||||||
|
String contentType,
|
||||||
|
String format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload Stream To OSS
|
||||||
|
* @param ins Input Stream
|
||||||
|
* @param contentLength
|
||||||
|
* @param folder Custom Folder
|
||||||
|
* @param name File Name [optional], Such As "foobar.doc",
|
||||||
|
* A UUID Will Be The Name, If Name Not Specified,
|
||||||
|
* @param contentType Content Type [Optional]
|
||||||
|
* @param format File Format [Optional]
|
||||||
|
* @param downloadName File Download Name [Optional]
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String upload(@NotNull InputStream ins,
|
||||||
|
@Min(1) long contentLength,
|
||||||
|
String folder,
|
||||||
|
String name,
|
||||||
|
String contentType,
|
||||||
|
String format,
|
||||||
|
String downloadName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get File From OSS
|
||||||
|
* @param name File Name such as "foobar.xls"
|
||||||
|
* @return file link [http://umsapp.oss-cn-hangzhou.aliyuncs.com/echat-dev/foobar.xls]
|
||||||
|
*/
|
||||||
|
File getFile(@NotBlank String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get InputStream
|
||||||
|
*/
|
||||||
|
InputStream getInputStream(@NotBlank String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Content Length
|
||||||
|
*/
|
||||||
|
long getContentLength(@NotBlank String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check obj exists
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean exist(@NotBlank String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete File From OSS
|
||||||
|
* @param name File Name such as "foobar.xls"
|
||||||
|
*/
|
||||||
|
void delete(@NotBlank String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Base Path
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String basePath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge Images To One By URIs Provided
|
||||||
|
* @param members
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotNull byte[] combineAvatars(@NotNull List<String> members);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload Member Avatar
|
||||||
|
* @param memberId
|
||||||
|
* @param name
|
||||||
|
* @param gender F/M/S
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String uploadAvatar(@NotBlank String memberId, @NotBlank String name, String gender);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload Member Avatar
|
||||||
|
* @param folder
|
||||||
|
* @param memberId
|
||||||
|
* @param name
|
||||||
|
* @param gender
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String uploadAvatar(@NotBlank String folder, @NotNull String memberId, @NotBlank String name, String gender);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get member avatar url
|
||||||
|
* @param memberId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String getAvatarUrl(@NotBlank String memberId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Member Avatar
|
||||||
|
* @param memberId
|
||||||
|
* @param insAvatar
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String uploadAvatar(@NotBlank String memberId, @NotNull InputStream insAvatar);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param memberId
|
||||||
|
* @param bytesAvatar
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String uploadAvatar(@NotBlank String memberId, @NotNull byte[] bytesAvatar);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload Image
|
||||||
|
* @param ins
|
||||||
|
* @param folder
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String uploadImage(@NotNull InputStream ins, String folder, String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param image
|
||||||
|
* @param folder
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String uploadImage(@NotNull byte[] image, String folder, String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload Image
|
||||||
|
* @param folder
|
||||||
|
* @param ins
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NotBlank String uploadImage(@NotNull InputStream ins, String folder);
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
package com.pudonghot.ambition.file;
|
||||||
|
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.2
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 24, 2015 2:53:08 PM
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
public interface ImageTool {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* combine images
|
||||||
|
* @param images
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
BufferedImage combine(@NotNull Collection<BufferedImage> images);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get image type of input stream
|
||||||
|
* @param ins
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String imageType(@NotNull InputStream ins);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get image type of input stream
|
||||||
|
* @param bytes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String imageType(@NotNull byte[] bytes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param size
|
||||||
|
* @param text
|
||||||
|
* @param canvasBgColor
|
||||||
|
* @param circleColor
|
||||||
|
* @param fontColor
|
||||||
|
* @param font
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
byte[] genCircleTextImage(
|
||||||
|
int size, @NotBlank String text,
|
||||||
|
Color canvasBgColor, Color circleColor,
|
||||||
|
Color fontColor, Font font);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param size
|
||||||
|
* @param text
|
||||||
|
* @param bgColor
|
||||||
|
* @param circleColor
|
||||||
|
* @param fontColor
|
||||||
|
* @param font
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
byte[] genFillCircleTextImage(
|
||||||
|
int size, @NotBlank String text,
|
||||||
|
Color bgColor, Color circleColor,
|
||||||
|
Color fontColor, Font font);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gen member avatar
|
||||||
|
* @param name
|
||||||
|
* @param gender
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
byte[] genAvatar(@NotBlank String name, String gender);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gen member avatar
|
||||||
|
* @param name
|
||||||
|
* @param gender
|
||||||
|
* @param size
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
byte[] genAvatar(@NotBlank String name, String gender, int size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param imageBytes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
byte[] toJpegBytes(@NotNull byte[] imageBytes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param insImage
|
||||||
|
* @param maxSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
byte[] cropToSquare(@NotNull InputStream insImage, int maxSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bytesImage
|
||||||
|
* @param maxSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
byte[] cropToSquare(@NotNull byte[] bytesImage, int maxSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bytesImage
|
||||||
|
* @param maxSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
BufferedImage cropToSquare(BufferedImage bytesImage, int maxSize);
|
||||||
|
}
|
@ -0,0 +1,248 @@
|
|||||||
|
package com.pudonghot.ambition.file.support;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import me.chyxion.tigon.sequence.IdSequence;
|
||||||
|
import com.pudonghot.ambition.file.ImageTool;
|
||||||
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
import com.pudonghot.ambition.file.AmbitionFileApi;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Sep 14, 2016 3:31:52 PM
|
||||||
|
*/
|
||||||
|
public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||||
|
private static final Logger log =
|
||||||
|
LoggerFactory.getLogger(AbstractAmbitionFileApi.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected ImageTool imageTool;
|
||||||
|
@Autowired
|
||||||
|
protected IdSequence idSeq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String upload(File file, String folder, String name, String contentType, String format) {
|
||||||
|
log.debug("Upload Input Stream To OSS With File [{}].", name);
|
||||||
|
if (StringUtils.isBlank(name)) {
|
||||||
|
name = idSeq.get();
|
||||||
|
String fileExt = FilenameUtils.getExtension(file.getName());
|
||||||
|
if (StringUtils.isNotBlank(fileExt)
|
||||||
|
&& StringUtils.isBlank(format)) {
|
||||||
|
format = fileExt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return upload(new FileInputStream(file),
|
||||||
|
file.length(),
|
||||||
|
folder,
|
||||||
|
name,
|
||||||
|
contentType,
|
||||||
|
format);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Upload File Error Caused, File Not Found", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String upload(File file, String name) {
|
||||||
|
return upload(file, null, name, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String upload(InputStream in, long contentLength, String name) {
|
||||||
|
return upload(in, contentLength, null, name, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String upload(InputStream in,
|
||||||
|
long contentLength,
|
||||||
|
String folder, String name,
|
||||||
|
String contentType, String fileFormat) {
|
||||||
|
return upload(in, contentLength, folder, name, contentType, fileFormat, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] combineAvatars(List<String> members) {
|
||||||
|
List<BufferedImage> images = new LinkedList<BufferedImage>();
|
||||||
|
for (String memberId : members) {
|
||||||
|
InputStream imageInput = null;
|
||||||
|
try {
|
||||||
|
imageInput = getInputStream("avatar/" + memberId);
|
||||||
|
images.add(ImageIO.read(imageInput));
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
uploadAvatar(memberId, "U", "");
|
||||||
|
log.error("Read Member [{}] Avatar Error Caused", memberId, e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(imageInput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!images.isEmpty()) {
|
||||||
|
ByteArrayOutputStream baos = null;
|
||||||
|
try {
|
||||||
|
baos = new ByteArrayOutputStream();
|
||||||
|
ImageIO.write(imageTool.combine(images), "png", baos);
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Write Image File Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(baos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"No Image Found In Members " + members);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getUrl(String name) {
|
||||||
|
return getUrl(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String uploadAvatar(String memberId, String name, String gender) {
|
||||||
|
return uploadAvatar(avatarFolder(), memberId, name, gender);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String uploadAvatar(String folder, String memberId, String name, String gender) {
|
||||||
|
byte[] bytesAvatar = imageTool.genAvatar(name, gender);
|
||||||
|
return upload(new ByteArrayInputStream(bytesAvatar),
|
||||||
|
bytesAvatar.length,
|
||||||
|
folder,
|
||||||
|
memberId,
|
||||||
|
MimeTypeUtils.IMAGE_PNG_VALUE, "png");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String uploadAvatar(String memberId, InputStream ins) {
|
||||||
|
return uploadImage(ins, avatarFolder(), memberId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getAvatarUrl(String memberId) {
|
||||||
|
return getUrl(avatarFolder(), memberId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String uploadImage(InputStream ins, String folder, String name) {
|
||||||
|
byte[] bytesFile = null;
|
||||||
|
try {
|
||||||
|
bytesFile = IOUtils.toByteArray(ins);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Upload Image Read Input Stream Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(ins);
|
||||||
|
}
|
||||||
|
return uploadImage(bytesFile, folder, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String uploadImage(byte[] bytesFile, String folder, String name) {
|
||||||
|
String format = imageTool.imageType(new ByteArrayInputStream(bytesFile));
|
||||||
|
if (StringUtils.isNotBlank(format)) {
|
||||||
|
if (!ArrayUtils.contains(new String[] {"png", "jpg", "jpeg"}, format)) {
|
||||||
|
log.info("Image File Type Is Not JPG Or PNG, Convert To JPG.");
|
||||||
|
bytesFile = imageTool.toJpegBytes(bytesFile);
|
||||||
|
format = "jpg";
|
||||||
|
}
|
||||||
|
log.info("Upload Image With Folder [{}], Name [{}], Format [{}].", folder, name, format);
|
||||||
|
return upload(
|
||||||
|
new ByteArrayInputStream(bytesFile),
|
||||||
|
bytesFile.length,
|
||||||
|
folder, name, "image/" + format, format);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Unsupported Image File Format [" + format + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ins
|
||||||
|
* @param folder
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String uploadImage(InputStream ins, String folder) {
|
||||||
|
return uploadImage(ins, folder, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String uploadAvatar(String memberId, byte[] bytesAvatar) {
|
||||||
|
return uploadImage(bytesAvatar, avatarFolder(), memberId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --
|
||||||
|
// private methods
|
||||||
|
|
||||||
|
protected String avatarFolder() {
|
||||||
|
return "avatar";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,464 @@
|
|||||||
|
package com.pudonghot.ambition.file.support;
|
||||||
|
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Shape;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import org.imgscalr.Scalr;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.imageio.IIOImage;
|
||||||
|
import java.awt.AlphaComposite;
|
||||||
|
import java.awt.geom.Ellipse2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.imgscalr.Scalr.Method;
|
||||||
|
import javax.imageio.ImageReader;
|
||||||
|
import javax.imageio.ImageWriter;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import javax.imageio.ImageWriteParam;
|
||||||
|
import me.chyxion.image.ImageCombine;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import com.pudonghot.ambition.file.ImageTool;
|
||||||
|
import javax.imageio.stream.ImageInputStream;
|
||||||
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
|
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Jun 25, 2015 12:19:44 PM
|
||||||
|
*/
|
||||||
|
public class ImageToolSupport implements ImageTool {
|
||||||
|
private static final Logger log =
|
||||||
|
LoggerFactory.getLogger(ImageToolSupport.class);
|
||||||
|
private ImageCombine ic = new ImageCombine();
|
||||||
|
// gender color
|
||||||
|
@Value("${gender.male.bg.color:#5EC9F6}")
|
||||||
|
private String genderMaleColor;
|
||||||
|
@Value("${gender.female.bg.color:#66CCCC}")
|
||||||
|
private String genderFemaleColor;
|
||||||
|
@Value("${gender.unknown.bg.color:#D7D2D5}")
|
||||||
|
private String genderUnknownColor;
|
||||||
|
@Value("${image.gen.default.size:512}")
|
||||||
|
private int defaultImageSize;
|
||||||
|
@Value("${image.combine.default.size:256}")
|
||||||
|
private int defaultCombineImageSize;
|
||||||
|
|
||||||
|
private final Font FONT_DEFAULT;
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
FONT_DEFAULT = Font.createFont(Font.TRUETYPE_FONT,
|
||||||
|
ImageToolSupport.class.getResourceAsStream("/fonts/w3.otf"))
|
||||||
|
.deriveFont(Font.PLAIN, 316.416F);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Init Font Error Caused", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BufferedImage combine(Collection<BufferedImage> images) {
|
||||||
|
Assert.notEmpty(images, "Images Could Not Be Empty");
|
||||||
|
Iterator<BufferedImage> it = images.iterator();
|
||||||
|
BufferedImage imageRtn = null;
|
||||||
|
if (images.size() == 1) {
|
||||||
|
imageRtn = resize(ic.cropToCircle(it.next()), defaultCombineImageSize);
|
||||||
|
}
|
||||||
|
else if (images.size() == 2) {
|
||||||
|
imageRtn = ic.combine(it.next(), it.next(), defaultCombineImageSize);
|
||||||
|
}
|
||||||
|
else if (images.size() == 3) {
|
||||||
|
imageRtn = ic.combine(it.next(),
|
||||||
|
it.next(), it.next(), defaultCombineImageSize);
|
||||||
|
}
|
||||||
|
else if (images.size() == 4) {
|
||||||
|
imageRtn = ic.combine(it.next(),
|
||||||
|
it.next(), it.next(), it.next(), defaultCombineImageSize);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
imageRtn = ic.combine(it.next(),
|
||||||
|
it.next(), it.next(), it.next(), it.next(), defaultCombineImageSize);
|
||||||
|
}
|
||||||
|
return imageRtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String imageType(InputStream ins) {
|
||||||
|
ImageInputStream iis = null;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
iis = ImageIO.createImageInputStream(ins);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
log.warn("Read Image Input Stream [{}] Error Caused.", ins, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
|
||||||
|
String format = null;
|
||||||
|
if (iter.hasNext()) {
|
||||||
|
ImageReader reader = iter.next();
|
||||||
|
try {
|
||||||
|
format = reader.getFormatName().toLowerCase();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
log.warn("Get Image Format Name Error Caused.", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
reader.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.info("Input Stream [{}] Is Not Image Input Stream.", ins);
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(iis);
|
||||||
|
IOUtils.closeQuietly(ins);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String imageType(byte[] bytes) {
|
||||||
|
return imageType(new ByteArrayInputStream(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] toJpegBytes(byte [] imageBytes) {
|
||||||
|
ByteArrayInputStream bais = null;
|
||||||
|
ByteArrayOutputStream baos = null;
|
||||||
|
ImageOutputStream imageOut = null;
|
||||||
|
try {
|
||||||
|
ImageWriter writer =
|
||||||
|
ImageIO.getImageWritersByFormatName("jpeg").next();
|
||||||
|
// instantiate an ImageWriteParam object with default compression options
|
||||||
|
ImageWriteParam iwp = writer.getDefaultWriteParam();
|
||||||
|
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
|
// an integer between 0 and 1
|
||||||
|
// 1 specifies minimum compression and maximum quality
|
||||||
|
iwp.setCompressionQuality(1);
|
||||||
|
baos = new ByteArrayOutputStream();
|
||||||
|
imageOut = new MemoryCacheImageOutputStream(baos);
|
||||||
|
writer.setOutput(imageOut);
|
||||||
|
bais = new ByteArrayInputStream(imageBytes);
|
||||||
|
writer.write(null, new IIOImage(ImageIO.read(bais), null, null), iwp);
|
||||||
|
writer.dispose();
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Convert Image To JPEG Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(imageOut);
|
||||||
|
IOUtils.closeQuietly(baos);
|
||||||
|
IOUtils.closeQuietly(bais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] genFillCircleTextImage(
|
||||||
|
final int size,
|
||||||
|
final String text,
|
||||||
|
Color canvasBgColor,
|
||||||
|
final Color circleBgColor,
|
||||||
|
final Color fontColor,
|
||||||
|
final Font font) {
|
||||||
|
|
||||||
|
return genImage(size, canvasBgColor, new ImageOp() {
|
||||||
|
@Override
|
||||||
|
public void process(Graphics2D g2d) {
|
||||||
|
fillCircle(size, g2d, circleBgColor);
|
||||||
|
drawCentralText(size, g2d, font, fontColor, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] genCircleTextImage(
|
||||||
|
final int size,
|
||||||
|
final String text,
|
||||||
|
Color canvasBgColor,
|
||||||
|
final Color circleColor,
|
||||||
|
final Color fontColor,
|
||||||
|
final Font font) {
|
||||||
|
|
||||||
|
return genImage(size, canvasBgColor, new ImageOp() {
|
||||||
|
@Override
|
||||||
|
public void process(Graphics2D g2d) {
|
||||||
|
drawCircle(size, g2d, circleColor);
|
||||||
|
drawCentralText(size, g2d, font, fontColor, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] genAvatar(String name, String gender) {
|
||||||
|
return genAvatar(name, gender, defaultImageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] genAvatar(String name, String gender, int size) {
|
||||||
|
Color circleBgColor = null;
|
||||||
|
if ("M".equalsIgnoreCase(gender)) {
|
||||||
|
circleBgColor = Color.decode(genderMaleColor);
|
||||||
|
}
|
||||||
|
else if ("F".equalsIgnoreCase(gender)) {
|
||||||
|
circleBgColor = Color.decode(genderFemaleColor);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
circleBgColor = Color.decode(genderUnknownColor);
|
||||||
|
}
|
||||||
|
return genFillCircleTextImage(size,
|
||||||
|
name.trim().substring(0, 1),
|
||||||
|
null, circleBgColor, Color.WHITE, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --
|
||||||
|
// protected methods
|
||||||
|
|
||||||
|
byte[] genImage(int size, Color bgColor, ImageOp op) {
|
||||||
|
if (size < 1) {
|
||||||
|
size = defaultImageSize;
|
||||||
|
log.debug("No Valid Image Size Specified, Use Default Size [{}].", size);
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage image =
|
||||||
|
new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics2D g2d = (Graphics2D) image.getGraphics();
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
|
if (bgColor != null) {
|
||||||
|
g2d.setColor(bgColor);
|
||||||
|
g2d.fillRect(0, 0, size, size);
|
||||||
|
}
|
||||||
|
// set background transparent
|
||||||
|
else {
|
||||||
|
g2d.setComposite(AlphaComposite.Clear);
|
||||||
|
g2d.fillRect(0, 0, size, size);
|
||||||
|
g2d.setComposite(AlphaComposite.Src);
|
||||||
|
}
|
||||||
|
if (op != null) {
|
||||||
|
op.process(g2d);
|
||||||
|
}
|
||||||
|
g2d.dispose();
|
||||||
|
image.flush();
|
||||||
|
return imageToBytes(image, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawCentralText(int size, Graphics2D g2d, Font font, Color fontColor, String text) {
|
||||||
|
log.debug("Draw Central Text [{}].", text);
|
||||||
|
if (font == null) {
|
||||||
|
log.debug("No Font Specified, Use Default.");
|
||||||
|
font = FONT_DEFAULT;
|
||||||
|
}
|
||||||
|
// draw text
|
||||||
|
font = font.deriveFont(Font.PLAIN, size * 0.618F);
|
||||||
|
g2d.setFont(font);
|
||||||
|
g2d.setColor(fontColor);
|
||||||
|
// set text to center
|
||||||
|
Shape outline = font.createGlyphVector(
|
||||||
|
g2d.getFontMetrics().getFontRenderContext(),
|
||||||
|
text).getOutline();
|
||||||
|
// the shape returned is located at the left side of the baseline,
|
||||||
|
// this means we need to re-align it to the top left corner.
|
||||||
|
// We also want to set it the the center of the screen while we are there
|
||||||
|
g2d.fill(AffineTransform.getTranslateInstance(
|
||||||
|
-outline.getBounds().getX() + size / 2 - outline.getBounds().width / 2,
|
||||||
|
-outline.getBounds().getY() + size / 2 - outline.getBounds().height / 2)
|
||||||
|
.createTransformedShape(outline));
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage resize(BufferedImage image, int size) {
|
||||||
|
if (size == image.getWidth() &&
|
||||||
|
size == image.getHeight()) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
return Scalr.resize(image, Method.AUTOMATIC, size, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawCircle(int size, Graphics2D g2d, Color color) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
// line stroke log2(size)
|
||||||
|
float lineWidth = (float) Math.ceil(Math.log(size) / Math.log(2));
|
||||||
|
g2d.setStroke(new BasicStroke(lineWidth));
|
||||||
|
int r = (int) (size / 2 - lineWidth - 4);
|
||||||
|
int c = size / 2 - r;
|
||||||
|
g2d.drawOval(c, c, 2 * r, 2 * r);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fillCircle(int size, Graphics2D g2d, Color color) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
int r = (int) (size / 2 - 4);
|
||||||
|
int c = size / 2 - r;
|
||||||
|
g2d.fillOval(c, c, 2 * r, 2 * r);
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage circleImage(BufferedImage image) {
|
||||||
|
int w = image.getWidth();
|
||||||
|
int h = image.getHeight();
|
||||||
|
BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics2D g2 = output.createGraphics();
|
||||||
|
|
||||||
|
// This is what we want, but it only does hard-clipping, i.e. aliasing
|
||||||
|
// g2.setClip(new RoundRectangle2D ...)
|
||||||
|
|
||||||
|
// so instead fake soft-clipping by first drawing the desired clip shape
|
||||||
|
// in fully opaque white with antialiasing enabled...
|
||||||
|
g2.setComposite(AlphaComposite.Src);
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
g2.setColor(Color.WHITE);
|
||||||
|
// g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius));
|
||||||
|
int border = 2;
|
||||||
|
g2.fill(new Ellipse2D.Double(border, border, w - border * 2, h - border * 2));
|
||||||
|
|
||||||
|
// ... then compositing the image on top,
|
||||||
|
// using the white shape from above as alpha source
|
||||||
|
g2.setComposite(AlphaComposite.SrcAtop);
|
||||||
|
g2.drawImage(image, 0, 0, null);
|
||||||
|
|
||||||
|
g2.dispose();
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
static interface ImageOp {
|
||||||
|
void process(Graphics2D g2d);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] cropToSquare(InputStream insImage, int maxSize) {
|
||||||
|
try {
|
||||||
|
return cropToSquare(IOUtils.toByteArray(insImage), maxSize);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Read Image Stream Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(insImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] cropToSquare(byte[] bytesImage, int maxSize) {
|
||||||
|
String imageType = imageType(bytesImage);
|
||||||
|
Assert.state(StringUtils.isNotBlank(imageType), "Invalid Image");
|
||||||
|
|
||||||
|
InputStream insImage = null;
|
||||||
|
try {
|
||||||
|
insImage = new ByteArrayInputStream(bytesImage);
|
||||||
|
return imageToBytes(cropToSquare(ImageIO.read(insImage)), imageType);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Process Image Bytes Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(insImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BufferedImage cropToSquare(BufferedImage image, int maxSize) {
|
||||||
|
image = cropToSquare(image);
|
||||||
|
if (image.getWidth() > maxSize) {
|
||||||
|
image = resize(image, maxSize);
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* crop image to square by shorter side
|
||||||
|
* @param image image to crop
|
||||||
|
* @return result image
|
||||||
|
*/
|
||||||
|
BufferedImage cropToSquare(final BufferedImage image) {
|
||||||
|
int width = image.getWidth();
|
||||||
|
int height = image.getHeight();
|
||||||
|
if (width == height) {
|
||||||
|
log.info("Crop Image To Square, Image [{}]x[{}] Is Square Aready, Ignore.", width, height);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
int size = height > width ? width : height;
|
||||||
|
log.info("Crop Image To Square [{}]x[{}].", size, size);
|
||||||
|
BufferedImage imageRtn =
|
||||||
|
new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
|
||||||
|
Graphics2D g2d = imageRtn.createGraphics();
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
g2d.setComposite(AlphaComposite.Src);
|
||||||
|
g2d.drawImage(image, (int) (Math.ceil(size - width) / 2.0),
|
||||||
|
(int) Math.ceil((size - height) / 2.0), null);
|
||||||
|
g2d.dispose();
|
||||||
|
imageRtn.flush();
|
||||||
|
return imageRtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] imageToBytes(BufferedImage image, String format) {
|
||||||
|
ByteArrayOutputStream baos =
|
||||||
|
new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
ImageIO.write(image,
|
||||||
|
StringUtils.isNotBlank(format) ?
|
||||||
|
format : "png", baos);
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Write Image Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(baos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
server/file-api/src/main/resources/fonts/w3.otf
Normal file
BIN
server/file-api/src/main/resources/fonts/w3.otf
Normal file
Binary file not shown.
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
<bean class="com.pudonghot.ambition.file.support.ImageToolSupport" />
|
||||||
|
</beans>
|
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br />
|
||||||
|
* chyxion@163.com <br />
|
||||||
|
* Mar 24, 2015 4:00:39 PM
|
||||||
|
*/
|
||||||
|
package com.pudonghot.ambition.file.oss;
|
15
server/file-api/src/test/resources/log4j.properties
Normal file
15
server/file-api/src/test/resources/log4j.properties
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
log4j.rootLogger=debug, console
|
||||||
|
|
||||||
|
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.console.Encoding=utf-8
|
||||||
|
log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
||||||
|
|
||||||
|
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.file.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
||||||
|
log4j.appender.file.File=${log.dir}/${project.artifactId}-test.log
|
||||||
|
log4j.appender.file.Encoding=utf-8
|
||||||
|
|
||||||
|
log4j.logger.org.apache=info
|
||||||
|
log4j.logger.org.springframework=info
|
@ -0,0 +1 @@
|
|||||||
|
# Config Dev
|
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/context
|
||||||
|
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||||
|
<context:property-placeholder location="classpath:spring/config.properties" />
|
||||||
|
<bean class="org.springframework.jdbc.core.JdbcTemplate">
|
||||||
|
<constructor-arg>
|
||||||
|
<bean class="com.alibaba.druid.pool.DruidDataSource"
|
||||||
|
init-method="init"
|
||||||
|
destroy-method="close"
|
||||||
|
p:url="${db.url}"
|
||||||
|
p:username="${db.user}"
|
||||||
|
p:password="${db.password}"
|
||||||
|
p:maxActive="16" />
|
||||||
|
</constructor-arg>
|
||||||
|
</bean>
|
||||||
|
</beans>
|
71
server/file-disk/pom.xml
Normal file
71
server/file-disk/pom.xml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?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>
|
||||||
|
<artifactId>file-disk</artifactId>
|
||||||
|
<name>Ambition File Disk</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>ambition</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>file-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-sequence</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-beans</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Test Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,360 @@
|
|||||||
|
package com.pudonghot.ambition.file.oss;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import com.aliyun.oss.OSSClient;
|
||||||
|
import com.aliyun.oss.OSSErrorCode;
|
||||||
|
import com.aliyun.oss.OSSException;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import com.aliyun.oss.model.OSSObject;
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.springframework.util.MimeType;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import com.aliyun.oss.model.ObjectMetadata;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import org.apache.commons.lang3.CharEncoding;
|
||||||
|
import com.aliyun.oss.model.GetObjectRequest;
|
||||||
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
import com.pudonghot.ambition.file.AmbitionFileApi;
|
||||||
|
import com.aliyun.oss.model.CannedAccessControlList;
|
||||||
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import com.pudonghot.ambition.file.support.AbstractAmbitionFileApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.4
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 24, 2015 1:23:00 PM
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class OSSFileSupport
|
||||||
|
extends AbstractAmbitionFileApi
|
||||||
|
implements AmbitionFileApi {
|
||||||
|
|
||||||
|
@Value("${ali.oss.host:oss-cn-shanghai.aliyuncs.com}")
|
||||||
|
private String ossHost;
|
||||||
|
@Value("${ali.oss.host.internal:oss-cn-shanghai-internal.aliyuncs.com}")
|
||||||
|
private String ossHostInternal;
|
||||||
|
@Value("${ali.oss.bucket}")
|
||||||
|
private String ossBucket;
|
||||||
|
@Value("${ali.oss.folder:}")
|
||||||
|
private String ossFolder;
|
||||||
|
@Value("${ali.access.key}")
|
||||||
|
private String ossAccount;
|
||||||
|
@Value("${ali.access.secret}")
|
||||||
|
private String ossSecret;
|
||||||
|
protected OSSClient ossClient;
|
||||||
|
@Value("${site.file.base.path:}")
|
||||||
|
private String basePath;
|
||||||
|
private String ossBasePath;
|
||||||
|
private String ossInternalBasePath;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
void init() {
|
||||||
|
log.info("Init OSS [{}].", ossHostInternal);
|
||||||
|
ossClient = new OSSClient("http://" + ossHostInternal, ossAccount, ossSecret);
|
||||||
|
// create bucket if it does not exist
|
||||||
|
if (!ossClient.doesBucketExist(ossBucket)) {
|
||||||
|
log.info("OSS Bucket [{}] Does Not Exist, Try To Create.", ossBucket);
|
||||||
|
ossClient.createBucket(ossBucket);
|
||||||
|
ossClient.setBucketAcl(ossBucket,
|
||||||
|
CannedAccessControlList.PublicRead);
|
||||||
|
}
|
||||||
|
// create folder if does not exist
|
||||||
|
if (StringUtils.isNotBlank(ossFolder)) {
|
||||||
|
try {
|
||||||
|
if (!ossFolder.endsWith("/")) {
|
||||||
|
ossFolder += "/";
|
||||||
|
}
|
||||||
|
ossClient.getObjectMetadata(ossBucket, ossFolder);
|
||||||
|
}
|
||||||
|
catch (OSSException e) {
|
||||||
|
if (OSSErrorCode.NO_SUCH_KEY.equals(e.getErrorCode())) {
|
||||||
|
log.info("OSS Foler [{}] Does Not Exist, Try To Create.", ossFolder);
|
||||||
|
InputStream bin = new ByteArrayInputStream(new byte[0]);
|
||||||
|
ObjectMetadata objectMeta = new ObjectMetadata();
|
||||||
|
objectMeta.setContentLength(0);
|
||||||
|
try {
|
||||||
|
ossClient.putObject(ossBucket, ossFolder, bin, objectMeta);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(bin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ossBasePath = "http://" + ossBucket + "." + ossHost + "/" + ossFolder;
|
||||||
|
log.info("Init OSS Base Path [{}].", ossBasePath);
|
||||||
|
ossInternalBasePath = "http://" + ossBucket + "." + ossHostInternal + "/" + ossFolder;
|
||||||
|
log.info("Init OSS Internal Base Path [{}].", ossBasePath);
|
||||||
|
if (StringUtils.isBlank(basePath)) {
|
||||||
|
basePath = ossBasePath;
|
||||||
|
}
|
||||||
|
log.info("Init File Base Path [{}].", basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String upload(InputStream in,
|
||||||
|
long contentLength,
|
||||||
|
String folder,
|
||||||
|
String name,
|
||||||
|
String contentType,
|
||||||
|
String fileFormat,
|
||||||
|
String downloadName) {
|
||||||
|
Assert.state(in != null, "Upload Input Stream Could Not Be Null");
|
||||||
|
log.info("Upload Input Stream To OSS With Folder [{}] Name [{}] Content Type [{}] Content Length [{}] Format [{}] Download Name [{}].",
|
||||||
|
folder, name, contentType, contentLength, fileFormat, downloadName);
|
||||||
|
boolean useFolder = true;
|
||||||
|
if (StringUtils.isNotBlank(name)) {
|
||||||
|
log.debug("Name [{}] Is Not Blank.", name);
|
||||||
|
if (name.startsWith(ossBasePath)) {
|
||||||
|
log.debug("Name Starts With Base Path [{}], Trim.", ossBasePath);
|
||||||
|
name = name.replaceFirst(ossBasePath, "");
|
||||||
|
useFolder = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = idSeq.get();
|
||||||
|
log.debug("No File Name Specified, Use UUID Name [{}].", name);
|
||||||
|
}
|
||||||
|
if (useFolder) {
|
||||||
|
log.debug("Name Does Not Start With Base Path [{}], Prepend Folder.", ossBasePath);
|
||||||
|
if (StringUtils.isNotBlank(folder)) {
|
||||||
|
log.debug("Custom Folder [{}] Given.", folder);
|
||||||
|
if (!folder.endsWith("/")) {
|
||||||
|
folder += "/";
|
||||||
|
}
|
||||||
|
name = folder + name;
|
||||||
|
log.debug("Prepend Custom And Date Folder, Name Result [{}].", name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = DateFormatUtils.format(new Date(), "yyyyMMdd") + "/" + name;
|
||||||
|
log.debug("No Custom Fould Found, Prepend Date Folder [{}].", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectMetadata objMeta = new ObjectMetadata();
|
||||||
|
// content type
|
||||||
|
objMeta.setContentType(StringUtils.isNotBlank(contentType) ?
|
||||||
|
contentType : ContentType.DEFAULT_BINARY.toString());
|
||||||
|
// custom file format
|
||||||
|
if (StringUtils.isNotBlank(fileFormat)) {
|
||||||
|
Map<String, String> meta = new HashMap<String, String>();
|
||||||
|
meta.put(META_FORMAT, fileFormat);
|
||||||
|
objMeta.setUserMetadata(meta);
|
||||||
|
}
|
||||||
|
// download name
|
||||||
|
if (StringUtils.isNotBlank(downloadName)) {
|
||||||
|
try {
|
||||||
|
downloadName = URLEncoder.encode(downloadName, CharEncoding.UTF_8);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Update File [" + name + "] Encde Download Name [" +
|
||||||
|
downloadName + "] Error Caused", e);
|
||||||
|
}
|
||||||
|
// String dispo =
|
||||||
|
// new StringBuilder("attachment; filename=\"")
|
||||||
|
// .append(downloadName)
|
||||||
|
// .append("\"; filename*=utf-8''")
|
||||||
|
// .append(downloadName)
|
||||||
|
// .toString();
|
||||||
|
|
||||||
|
String dispo =
|
||||||
|
new StringBuilder("attachment; filename*=utf-8''")
|
||||||
|
.append(downloadName)
|
||||||
|
.toString();
|
||||||
|
log.debug("Set Upload File Content-Disposition [{}].", dispo);
|
||||||
|
objMeta.setContentDisposition(dispo);
|
||||||
|
}
|
||||||
|
objMeta.setContentLength(contentLength);
|
||||||
|
try {
|
||||||
|
ossClient.putObject(ossBucket, ossFolder + name, in, objMeta);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Update File [" + name + "] Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(in);
|
||||||
|
}
|
||||||
|
name = basePath() + name;
|
||||||
|
log.info("Upload File Result [{}].", name);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public File getFile(String name) {
|
||||||
|
OSSObject obj = null;
|
||||||
|
try {
|
||||||
|
obj = ossClient.getObject(
|
||||||
|
new GetObjectRequest(ossBucket, urlToName(name)));
|
||||||
|
}
|
||||||
|
catch (OSSException e) {
|
||||||
|
if (!OSSErrorCode.NO_SUCH_KEY.equals(e.getErrorCode())) {
|
||||||
|
log.info("Get File Error Caused.", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
log.info("Get File Of [{}].", name);
|
||||||
|
ObjectMetadata md = obj.getObjectMetadata();
|
||||||
|
Map<String, String> userMd = md.getUserMetadata();
|
||||||
|
String format = null;
|
||||||
|
if (userMd != null && !userMd.isEmpty()) {
|
||||||
|
format = userMd.get(META_FORMAT);
|
||||||
|
log.info("User Meta File Format [{}] Found.", format);
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(format)) {
|
||||||
|
String contentType = md.getContentType();
|
||||||
|
log.info("No User Meta File Format Found, Get Object Content Type [{}].", contentType);
|
||||||
|
if (StringUtils.isNotBlank(contentType)) {
|
||||||
|
MimeType mt = MimeTypeUtils.parseMimeType(contentType);
|
||||||
|
format = mt.getSubtype();
|
||||||
|
log.info("Get Object Content Type Subtype [{}].", format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileName = idSeq.get();
|
||||||
|
if (StringUtils.isNotBlank(format)) {
|
||||||
|
fileName += "." + format;
|
||||||
|
}
|
||||||
|
File file = new File(FileUtils.getTempDirectory(), fileName);
|
||||||
|
file.deleteOnExit();
|
||||||
|
InputStream fin = null;
|
||||||
|
OutputStream fout = null;
|
||||||
|
try {
|
||||||
|
fin = obj.getObjectContent();
|
||||||
|
fout = new FileOutputStream(file);
|
||||||
|
IOUtils.copy(fin, fout);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Download File [" + name + "] Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(fin);
|
||||||
|
IOUtils.closeQuietly(fout);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public InputStream getInputStream(String name) {
|
||||||
|
return ossClient.getObject(
|
||||||
|
new GetObjectRequest(ossBucket, urlToName(name)))
|
||||||
|
.getObjectContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public long getContentLength(String name) {
|
||||||
|
return ossClient.getObject(
|
||||||
|
new GetObjectRequest(ossBucket, urlToName(name)))
|
||||||
|
.getObjectMetadata().getContentLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean exist(String name) {
|
||||||
|
try {
|
||||||
|
ossClient.getObjectMetadata(ossBucket, urlToName(name));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (OSSException e) {
|
||||||
|
if (!OSSErrorCode.NO_SUCH_KEY.equals(e.getErrorCode())) {
|
||||||
|
log.info("Check OSS Object Exists Error Caused.", e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delete(String name) {
|
||||||
|
if (StringUtils.isNotBlank(name)) {
|
||||||
|
log.info("Delete File [{}].", name);
|
||||||
|
ossClient.deleteObject(ossBucket, urlToName(name));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.info("Delete File, File Name Or URL Is Blank, Ignore.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String basePath() {
|
||||||
|
return basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getUrl(String folder, String name) {
|
||||||
|
return getUrl(folder, name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getRawUrl(String folder, String name) {
|
||||||
|
return getUrl(folder, name, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --
|
||||||
|
// private methods
|
||||||
|
String urlToName(String url) {
|
||||||
|
return ossFolder + url.replace(basePath, "")
|
||||||
|
.replace(ossBasePath, "")
|
||||||
|
.replace(ossInternalBasePath, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
String getUrl(String folder, String name, boolean raw) {
|
||||||
|
String url = raw ? ossBasePath : basePath;
|
||||||
|
if (StringUtils.isNotBlank(folder)) {
|
||||||
|
url += folder;
|
||||||
|
}
|
||||||
|
if (!url.endsWith("/")) {
|
||||||
|
url += "/";
|
||||||
|
}
|
||||||
|
url += name;
|
||||||
|
log.debug("Get Url [{}] Of Folder [{}] And Name [{}].", url, folder, name);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
<bean class="com.pudonghot.ambition.file.oss.OSSFileSupport" />
|
||||||
|
</beans>
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.pudonghot.ambition.file.oss;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 18, 2017 20:02:13
|
||||||
|
*/
|
||||||
|
public class TestDriver {
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br />
|
||||||
|
* chyxion@163.com <br />
|
||||||
|
* Mar 24, 2015 4:00:39 PM
|
||||||
|
*/
|
||||||
|
package com.pudonghot.ambition.file.oss;
|
15
server/file-disk/src/test/resources/log4j.properties
Normal file
15
server/file-disk/src/test/resources/log4j.properties
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
log4j.rootLogger=debug, console
|
||||||
|
|
||||||
|
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.console.Encoding=utf-8
|
||||||
|
log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
||||||
|
|
||||||
|
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.file.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
||||||
|
log4j.appender.file.File=${log.dir}/${project.artifactId}-test.log
|
||||||
|
log4j.appender.file.Encoding=utf-8
|
||||||
|
|
||||||
|
log4j.logger.org.apache=info
|
||||||
|
log4j.logger.org.springframework=info
|
22
server/file-disk/src/test/resources/spring/config.properties
Normal file
22
server/file-disk/src/test/resources/spring/config.properties
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Config Dev
|
||||||
|
|
||||||
|
oss.host.internal=oss-cn-hangzhou.aliyuncs.com
|
||||||
|
|
||||||
|
# OSS SIT
|
||||||
|
#ali.access.key=fkNUAQTZkBFFEn8r
|
||||||
|
#ali.access.password=bPEEP8mxpGlMs7CL3EvQUGfTAPsm8i
|
||||||
|
#oss.bucket=echat-uat
|
||||||
|
# oss.folder=echat_uat/
|
||||||
|
# oss.folder=echat_dev/
|
||||||
|
#oss.bucket=echat-sit
|
||||||
|
#oss.folder=echat_sit/
|
||||||
|
|
||||||
|
# OSS Prod
|
||||||
|
ali.access.key=kiEjn4z5uVejyiPy
|
||||||
|
ali.access.password=sgNYMjJ7X9rGRP09ps2bPgqkjCEffN
|
||||||
|
oss.bucket=echat-prod
|
||||||
|
oss.folder=echat_prod/
|
||||||
|
|
||||||
|
db.url=jdbc:mysql://127.0.0.1:3308/echat_prod
|
||||||
|
db.user=echat_user
|
||||||
|
db.password=echat_user402
|
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:p="http://www.springframework.org/schema/p"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/context
|
||||||
|
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||||
|
<context:property-placeholder location="classpath:spring/config.properties" />
|
||||||
|
<bean class="org.springframework.jdbc.core.JdbcTemplate">
|
||||||
|
<constructor-arg>
|
||||||
|
<bean class="com.alibaba.druid.pool.DruidDataSource"
|
||||||
|
init-method="init"
|
||||||
|
destroy-method="close"
|
||||||
|
p:url="${db.url}"
|
||||||
|
p:username="${db.user}"
|
||||||
|
p:password="${db.password}"
|
||||||
|
p:maxActive="16" />
|
||||||
|
</constructor-arg>
|
||||||
|
</bean>
|
||||||
|
</beans>
|
71
server/file-oss/pom.xml
Normal file
71
server/file-oss/pom.xml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?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>
|
||||||
|
<artifactId>file-oss</artifactId>
|
||||||
|
<name>Ambition File OSS</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>ambition</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>file-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-sequence</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-beans</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Test Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,360 @@
|
|||||||
|
package com.pudonghot.ambition.file.oss;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import com.aliyun.oss.OSSClient;
|
||||||
|
import com.aliyun.oss.OSSErrorCode;
|
||||||
|
import com.aliyun.oss.OSSException;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import com.aliyun.oss.model.OSSObject;
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.springframework.util.MimeType;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import com.aliyun.oss.model.ObjectMetadata;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import org.apache.commons.lang3.CharEncoding;
|
||||||
|
import com.aliyun.oss.model.GetObjectRequest;
|
||||||
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
import com.pudonghot.ambition.file.AmbitionFileApi;
|
||||||
|
import com.aliyun.oss.model.CannedAccessControlList;
|
||||||
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import com.pudonghot.ambition.file.support.AbstractAmbitionFileApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.4
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 24, 2015 1:23:00 PM
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class OSSFileSupport
|
||||||
|
extends AbstractAmbitionFileApi
|
||||||
|
implements AmbitionFileApi {
|
||||||
|
|
||||||
|
@Value("${ali.oss.host:oss-cn-shanghai.aliyuncs.com}")
|
||||||
|
private String ossHost;
|
||||||
|
@Value("${ali.oss.host.internal:oss-cn-shanghai-internal.aliyuncs.com}")
|
||||||
|
private String ossHostInternal;
|
||||||
|
@Value("${ali.oss.bucket}")
|
||||||
|
private String ossBucket;
|
||||||
|
@Value("${ali.oss.folder:}")
|
||||||
|
private String ossFolder;
|
||||||
|
@Value("${ali.access.key}")
|
||||||
|
private String ossAccount;
|
||||||
|
@Value("${ali.access.secret}")
|
||||||
|
private String ossSecret;
|
||||||
|
protected OSSClient ossClient;
|
||||||
|
@Value("${site.file.base.path:}")
|
||||||
|
private String basePath;
|
||||||
|
private String ossBasePath;
|
||||||
|
private String ossInternalBasePath;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
void init() {
|
||||||
|
log.info("Init OSS [{}].", ossHostInternal);
|
||||||
|
ossClient = new OSSClient("http://" + ossHostInternal, ossAccount, ossSecret);
|
||||||
|
// create bucket if it does not exist
|
||||||
|
if (!ossClient.doesBucketExist(ossBucket)) {
|
||||||
|
log.info("OSS Bucket [{}] Does Not Exist, Try To Create.", ossBucket);
|
||||||
|
ossClient.createBucket(ossBucket);
|
||||||
|
ossClient.setBucketAcl(ossBucket,
|
||||||
|
CannedAccessControlList.PublicRead);
|
||||||
|
}
|
||||||
|
// create folder if does not exist
|
||||||
|
if (StringUtils.isNotBlank(ossFolder)) {
|
||||||
|
try {
|
||||||
|
if (!ossFolder.endsWith("/")) {
|
||||||
|
ossFolder += "/";
|
||||||
|
}
|
||||||
|
ossClient.getObjectMetadata(ossBucket, ossFolder);
|
||||||
|
}
|
||||||
|
catch (OSSException e) {
|
||||||
|
if (OSSErrorCode.NO_SUCH_KEY.equals(e.getErrorCode())) {
|
||||||
|
log.info("OSS Foler [{}] Does Not Exist, Try To Create.", ossFolder);
|
||||||
|
InputStream bin = new ByteArrayInputStream(new byte[0]);
|
||||||
|
ObjectMetadata objectMeta = new ObjectMetadata();
|
||||||
|
objectMeta.setContentLength(0);
|
||||||
|
try {
|
||||||
|
ossClient.putObject(ossBucket, ossFolder, bin, objectMeta);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(bin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ossBasePath = "http://" + ossBucket + "." + ossHost + "/" + ossFolder;
|
||||||
|
log.info("Init OSS Base Path [{}].", ossBasePath);
|
||||||
|
ossInternalBasePath = "http://" + ossBucket + "." + ossHostInternal + "/" + ossFolder;
|
||||||
|
log.info("Init OSS Internal Base Path [{}].", ossBasePath);
|
||||||
|
if (StringUtils.isBlank(basePath)) {
|
||||||
|
basePath = ossBasePath;
|
||||||
|
}
|
||||||
|
log.info("Init File Base Path [{}].", basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String upload(InputStream in,
|
||||||
|
long contentLength,
|
||||||
|
String folder,
|
||||||
|
String name,
|
||||||
|
String contentType,
|
||||||
|
String fileFormat,
|
||||||
|
String downloadName) {
|
||||||
|
Assert.state(in != null, "Upload Input Stream Could Not Be Null");
|
||||||
|
log.info("Upload Input Stream To OSS With Folder [{}] Name [{}] Content Type [{}] Content Length [{}] Format [{}] Download Name [{}].",
|
||||||
|
folder, name, contentType, contentLength, fileFormat, downloadName);
|
||||||
|
boolean useFolder = true;
|
||||||
|
if (StringUtils.isNotBlank(name)) {
|
||||||
|
log.debug("Name [{}] Is Not Blank.", name);
|
||||||
|
if (name.startsWith(ossBasePath)) {
|
||||||
|
log.debug("Name Starts With Base Path [{}], Trim.", ossBasePath);
|
||||||
|
name = name.replaceFirst(ossBasePath, "");
|
||||||
|
useFolder = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = idSeq.get();
|
||||||
|
log.debug("No File Name Specified, Use UUID Name [{}].", name);
|
||||||
|
}
|
||||||
|
if (useFolder) {
|
||||||
|
log.debug("Name Does Not Start With Base Path [{}], Prepend Folder.", ossBasePath);
|
||||||
|
if (StringUtils.isNotBlank(folder)) {
|
||||||
|
log.debug("Custom Folder [{}] Given.", folder);
|
||||||
|
if (!folder.endsWith("/")) {
|
||||||
|
folder += "/";
|
||||||
|
}
|
||||||
|
name = folder + name;
|
||||||
|
log.debug("Prepend Custom And Date Folder, Name Result [{}].", name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = DateFormatUtils.format(new Date(), "yyyyMMdd") + "/" + name;
|
||||||
|
log.debug("No Custom Fould Found, Prepend Date Folder [{}].", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectMetadata objMeta = new ObjectMetadata();
|
||||||
|
// content type
|
||||||
|
objMeta.setContentType(StringUtils.isNotBlank(contentType) ?
|
||||||
|
contentType : ContentType.DEFAULT_BINARY.toString());
|
||||||
|
// custom file format
|
||||||
|
if (StringUtils.isNotBlank(fileFormat)) {
|
||||||
|
Map<String, String> meta = new HashMap<String, String>();
|
||||||
|
meta.put(META_FORMAT, fileFormat);
|
||||||
|
objMeta.setUserMetadata(meta);
|
||||||
|
}
|
||||||
|
// download name
|
||||||
|
if (StringUtils.isNotBlank(downloadName)) {
|
||||||
|
try {
|
||||||
|
downloadName = URLEncoder.encode(downloadName, CharEncoding.UTF_8);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Update File [" + name + "] Encde Download Name [" +
|
||||||
|
downloadName + "] Error Caused", e);
|
||||||
|
}
|
||||||
|
// String dispo =
|
||||||
|
// new StringBuilder("attachment; filename=\"")
|
||||||
|
// .append(downloadName)
|
||||||
|
// .append("\"; filename*=utf-8''")
|
||||||
|
// .append(downloadName)
|
||||||
|
// .toString();
|
||||||
|
|
||||||
|
String dispo =
|
||||||
|
new StringBuilder("attachment; filename*=utf-8''")
|
||||||
|
.append(downloadName)
|
||||||
|
.toString();
|
||||||
|
log.debug("Set Upload File Content-Disposition [{}].", dispo);
|
||||||
|
objMeta.setContentDisposition(dispo);
|
||||||
|
}
|
||||||
|
objMeta.setContentLength(contentLength);
|
||||||
|
try {
|
||||||
|
ossClient.putObject(ossBucket, ossFolder + name, in, objMeta);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Update File [" + name + "] Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(in);
|
||||||
|
}
|
||||||
|
name = basePath() + name;
|
||||||
|
log.info("Upload File Result [{}].", name);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public File getFile(String name) {
|
||||||
|
OSSObject obj = null;
|
||||||
|
try {
|
||||||
|
obj = ossClient.getObject(
|
||||||
|
new GetObjectRequest(ossBucket, urlToName(name)));
|
||||||
|
}
|
||||||
|
catch (OSSException e) {
|
||||||
|
if (!OSSErrorCode.NO_SUCH_KEY.equals(e.getErrorCode())) {
|
||||||
|
log.info("Get File Error Caused.", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
log.info("Get File Of [{}].", name);
|
||||||
|
ObjectMetadata md = obj.getObjectMetadata();
|
||||||
|
Map<String, String> userMd = md.getUserMetadata();
|
||||||
|
String format = null;
|
||||||
|
if (userMd != null && !userMd.isEmpty()) {
|
||||||
|
format = userMd.get(META_FORMAT);
|
||||||
|
log.info("User Meta File Format [{}] Found.", format);
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(format)) {
|
||||||
|
String contentType = md.getContentType();
|
||||||
|
log.info("No User Meta File Format Found, Get Object Content Type [{}].", contentType);
|
||||||
|
if (StringUtils.isNotBlank(contentType)) {
|
||||||
|
MimeType mt = MimeTypeUtils.parseMimeType(contentType);
|
||||||
|
format = mt.getSubtype();
|
||||||
|
log.info("Get Object Content Type Subtype [{}].", format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileName = idSeq.get();
|
||||||
|
if (StringUtils.isNotBlank(format)) {
|
||||||
|
fileName += "." + format;
|
||||||
|
}
|
||||||
|
File file = new File(FileUtils.getTempDirectory(), fileName);
|
||||||
|
file.deleteOnExit();
|
||||||
|
InputStream fin = null;
|
||||||
|
OutputStream fout = null;
|
||||||
|
try {
|
||||||
|
fin = obj.getObjectContent();
|
||||||
|
fout = new FileOutputStream(file);
|
||||||
|
IOUtils.copy(fin, fout);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Download File [" + name + "] Error Caused", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
IOUtils.closeQuietly(fin);
|
||||||
|
IOUtils.closeQuietly(fout);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public InputStream getInputStream(String name) {
|
||||||
|
return ossClient.getObject(
|
||||||
|
new GetObjectRequest(ossBucket, urlToName(name)))
|
||||||
|
.getObjectContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public long getContentLength(String name) {
|
||||||
|
return ossClient.getObject(
|
||||||
|
new GetObjectRequest(ossBucket, urlToName(name)))
|
||||||
|
.getObjectMetadata().getContentLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean exist(String name) {
|
||||||
|
try {
|
||||||
|
ossClient.getObjectMetadata(ossBucket, urlToName(name));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (OSSException e) {
|
||||||
|
if (!OSSErrorCode.NO_SUCH_KEY.equals(e.getErrorCode())) {
|
||||||
|
log.info("Check OSS Object Exists Error Caused.", e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delete(String name) {
|
||||||
|
if (StringUtils.isNotBlank(name)) {
|
||||||
|
log.info("Delete File [{}].", name);
|
||||||
|
ossClient.deleteObject(ossBucket, urlToName(name));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.info("Delete File, File Name Or URL Is Blank, Ignore.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String basePath() {
|
||||||
|
return basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getUrl(String folder, String name) {
|
||||||
|
return getUrl(folder, name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getRawUrl(String folder, String name) {
|
||||||
|
return getUrl(folder, name, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --
|
||||||
|
// private methods
|
||||||
|
String urlToName(String url) {
|
||||||
|
return ossFolder + url.replace(basePath, "")
|
||||||
|
.replace(ossBasePath, "")
|
||||||
|
.replace(ossInternalBasePath, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
String getUrl(String folder, String name, boolean raw) {
|
||||||
|
String url = raw ? ossBasePath : basePath;
|
||||||
|
if (StringUtils.isNotBlank(folder)) {
|
||||||
|
url += folder;
|
||||||
|
}
|
||||||
|
if (!url.endsWith("/")) {
|
||||||
|
url += "/";
|
||||||
|
}
|
||||||
|
url += name;
|
||||||
|
log.debug("Get Url [{}] Of Folder [{}] And Name [{}].", url, folder, name);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
<bean class="com.pudonghot.ambition.file.oss.OSSFileSupport" />
|
||||||
|
</beans>
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.pudonghot.ambition.file.oss;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Shaun Chyxion <br>
|
||||||
|
* chyxion@163.com <br>
|
||||||
|
* Mar 18, 2017 20:02:13
|
||||||
|
*/
|
||||||
|
public class TestDriver {
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Shaun Chyxion <br />
|
||||||
|
* chyxion@163.com <br />
|
||||||
|
* Mar 24, 2015 4:00:39 PM
|
||||||
|
*/
|
||||||
|
package com.pudonghot.ambition.file.oss;
|
15
server/file-oss/src/test/resources/log4j.properties
Normal file
15
server/file-oss/src/test/resources/log4j.properties
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
log4j.rootLogger=debug, console
|
||||||
|
|
||||||
|
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.console.Encoding=utf-8
|
||||||
|
log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
||||||
|
|
||||||
|
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.file.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
||||||
|
log4j.appender.file.File=${log.dir}/${project.artifactId}-test.log
|
||||||
|
log4j.appender.file.Encoding=utf-8
|
||||||
|
|
||||||
|
log4j.logger.org.apache=info
|
||||||
|
log4j.logger.org.springframework=info
|
22
server/file-oss/src/test/resources/spring/config.properties
Normal file
22
server/file-oss/src/test/resources/spring/config.properties
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Config Dev
|
||||||
|
|
||||||
|
oss.host.internal=oss-cn-hangzhou.aliyuncs.com
|
||||||
|
|
||||||
|
# OSS SIT
|
||||||
|
#ali.access.key=fkNUAQTZkBFFEn8r
|
||||||
|
#ali.access.password=bPEEP8mxpGlMs7CL3EvQUGfTAPsm8i
|
||||||
|
#oss.bucket=echat-uat
|
||||||
|
# oss.folder=echat_uat/
|
||||||
|
# oss.folder=echat_dev/
|
||||||
|
#oss.bucket=echat-sit
|
||||||
|
#oss.folder=echat_sit/
|
||||||
|
|
||||||
|
# OSS Prod
|
||||||
|
ali.access.key=kiEjn4z5uVejyiPy
|
||||||
|
ali.access.password=sgNYMjJ7X9rGRP09ps2bPgqkjCEffN
|
||||||
|
oss.bucket=echat-prod
|
||||||
|
oss.folder=echat_prod/
|
||||||
|
|
||||||
|
db.url=jdbc:mysql://127.0.0.1:3308/echat_prod
|
||||||
|
db.user=echat_user
|
||||||
|
db.password=echat_user402
|
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:p="http://www.springframework.org/schema/p"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/context
|
||||||
|
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||||
|
<context:property-placeholder location="classpath:spring/config.properties" />
|
||||||
|
<bean class="org.springframework.jdbc.core.JdbcTemplate">
|
||||||
|
<constructor-arg>
|
||||||
|
<bean class="com.alibaba.druid.pool.DruidDataSource"
|
||||||
|
init-method="init"
|
||||||
|
destroy-method="close"
|
||||||
|
p:url="${db.url}"
|
||||||
|
p:username="${db.user}"
|
||||||
|
p:password="${db.password}"
|
||||||
|
p:maxActive="16" />
|
||||||
|
</constructor-arg>
|
||||||
|
</bean>
|
||||||
|
</beans>
|
1
server/mapper/README.md
Normal file
1
server/mapper/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
#umsapp-ota-db
|
202
server/mapper/pom.xml
Normal file
202
server/mapper/pom.xml
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
<?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>
|
||||||
|
<artifactId>mapper</artifactId>
|
||||||
|
<name>Ambition Mapper</name>
|
||||||
|
<packaging>${packaging}</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>ambition</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.pudonghot.ambition</groupId>
|
||||||
|
<artifactId>model</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-mybatis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-mybatis-redis-cache</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis-spring</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Data Source -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- JDBC Driver -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Test And Optional Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.el</groupId>
|
||||||
|
<artifactId>javax.el-api</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjrt</artifactId>
|
||||||
|
<version>1.8.0</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjweaver</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cglib</groupId>
|
||||||
|
<artifactId>cglib</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<activation>
|
||||||
|
<property>
|
||||||
|
<name>dev</name>
|
||||||
|
<value>true</value>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<maven.tomcat.port>8088</maven.tomcat.port>
|
||||||
|
<log.dir>${project.basedir}/.log</log.dir>
|
||||||
|
<log.level>DEBUG</log.level>
|
||||||
|
<log.appender>
|
||||||
|
<![CDATA[
|
||||||
|
<AppenderRef ref="File" level="${log.level}" />
|
||||||
|
<AppenderRef ref="Console" level="${log.level}" />
|
||||||
|
]]>
|
||||||
|
</log.appender>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-codegen</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-props-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
|
<artifactId>tigon-webmvc-war</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.tomcat.maven</groupId>
|
||||||
|
<artifactId>tomcat7-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>dep</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>spring/spring-ambition-db.xml</include>
|
||||||
|
<include>mybatis/**</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>db/**</exclude>
|
||||||
|
<exclude>codegen/**</exclude>
|
||||||
|
<exclude>log4j2.xml</exclude>
|
||||||
|
<exclude>config_*.properties</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/webapp</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/**</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
9
server/mapper/run
Executable file
9
server/mapper/run
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export MAVEN_OPTS="-noverify -agentpath:/usr/local/JRebel/6.3.2/lib/libjrebel64.dylib -Drebel.dirs=target -Drebel.disable_update=true -Ddev=true"
|
||||||
|
set JAVA_OPTS=$MAVEN_OPTS
|
||||||
|
mvn -Pdev clean tomcat7:run
|
||||||
|
unset JAVA_OPTS
|
||||||
|
unset MAVEN_OPTS
|
||||||
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import me.chyxion.tigon.mybatis.Table;
|
||||||
|
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||||
|
import com.pudonghot.ambition.model.AdminAuthFailedLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:57:44 PM
|
||||||
|
*/
|
||||||
|
public interface AdminAuthFailedLogMapper extends BaseMapper<String, AdminAuthFailedLog> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import me.chyxion.tigon.mybatis.Table;
|
||||||
|
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||||
|
import com.pudonghot.ambition.model.AdminLoginLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:57:29 PM
|
||||||
|
*/
|
||||||
|
@Table("ph_admin_login_log")
|
||||||
|
public interface AdminLoginLogMapper extends BaseMapper<String, AdminLoginLog> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import me.chyxion.tigon.mybatis.Table;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 11, 2017 1:31:44 PM
|
||||||
|
*/
|
||||||
|
public interface AdminMapper extends BaseMapper<String, Admin> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
# CodeGen Config
|
||||||
|
base.cols=enabled,note,date_created,date_updated,created_by,updated_by
|
||||||
|
base.package=com.pudonghot.ambition
|
||||||
|
super.base.model.name=M3<Long, Long>
|
||||||
|
super.base.model.full.name=me.chyxion.tigon.model.M3
|
||||||
|
table.prefix=ph
|
10
server/mapper/src/main/resources/config_dev.properties
Normal file
10
server/mapper/src/main/resources/config_dev.properties
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Config Dev
|
||||||
|
|
||||||
|
# Database
|
||||||
|
db.url=jdbc:mysql://127.0.0.1:43306/pudong_hot?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
||||||
|
db.user=root
|
||||||
|
db.password=696@2^~)oZ@^#*Q
|
||||||
|
|
||||||
|
redis.host=127.0.0.1
|
||||||
|
redis.port=46379
|
||||||
|
redis.password=0211
|
38
server/mapper/src/main/resources/log4j2_dev.xml
Normal file
38
server/mapper/src/main/resources/log4j2_dev.xml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN">
|
||||||
|
<Properties>
|
||||||
|
<Property name="log.level">DEBUG</Property>
|
||||||
|
<Property name="log.dir">.logs</Property>
|
||||||
|
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||||
|
</Properties>
|
||||||
|
<Appenders>
|
||||||
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout pattern="${pattern}" />
|
||||||
|
</Console>
|
||||||
|
<RollingFile name="File"
|
||||||
|
fileName="${log.dir}/${project.artifactId}.log"
|
||||||
|
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-%d{yyyy-MM-dd}-%i.log">
|
||||||
|
<PatternLayout pattern="${pattern}" />
|
||||||
|
<Policies>
|
||||||
|
<TimeBasedTriggeringPolicy />
|
||||||
|
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||||
|
</Policies>
|
||||||
|
<DefaultRolloverStrategy max="32" />
|
||||||
|
</RollingFile>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Logger name="org.springframework" level="INFO" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Logger name="org.apache" level="WARN" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Logger name="org.hibernate.validator" level="WARN" additivity="false">
|
||||||
|
<AppenderRef ref="File" />
|
||||||
|
</Logger>
|
||||||
|
<Root level="${log.level}" additivity="false">
|
||||||
|
<AppenderRef ref="File" level="${log.level}" />
|
||||||
|
<AppenderRef ref="Console" level="${log.level}" />
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:57:44 PM
|
||||||
|
*/
|
||||||
|
-->
|
||||||
|
<!DOCTYPE mapper PUBLIC
|
||||||
|
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.pudonghot.ambition.mapper.AdminAuthFailedLogMapper">
|
||||||
|
</mapper>
|
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:57:29 PM
|
||||||
|
*/
|
||||||
|
-->
|
||||||
|
<!DOCTYPE mapper PUBLIC
|
||||||
|
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.pudonghot.ambition.mapper.AdminLoginLogMapper">
|
||||||
|
</mapper>
|
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 11, 2017 1:31:44 PM
|
||||||
|
*/
|
||||||
|
-->
|
||||||
|
<!DOCTYPE mapper PUBLIC
|
||||||
|
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.pudonghot.ambition.mapper.AdminMapper">
|
||||||
|
<cache type="me.chyxion.tigon.mybatis.cache.RedisCache" />
|
||||||
|
</mapper>
|
28
server/mapper/src/main/resources/mybatis/mybatis-config.xml
Normal file
28
server/mapper/src/main/resources/mybatis/mybatis-config.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?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="cacheEnabled" value="true" />
|
||||||
|
<!-- 查询时,关闭关联对象即时加载以提高性能 -->
|
||||||
|
<setting name="lazyLoadingEnabled" value="false" />
|
||||||
|
<!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指定),不会加载关联表的所有字段,以提高性能 -->
|
||||||
|
<setting name="aggressiveLazyLoading" value="true" />
|
||||||
|
<setting name="safeRowBoundsEnabled" value="true" />
|
||||||
|
<setting name="mapUnderscoreToCamelCase" value="true" />
|
||||||
|
<!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->
|
||||||
|
<setting name="multipleResultSetsEnabled" value="true" />
|
||||||
|
<!-- 允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 -->
|
||||||
|
<setting name="useGeneratedKeys" value="true" />
|
||||||
|
<!-- 允许使用列标签代替列名 -->
|
||||||
|
<setting name="useColumnLabel" value="true" />
|
||||||
|
<!-- 数据库超过24000秒仍未响应则超时 -->
|
||||||
|
<setting name="defaultStatementTimeout" value="24000" />
|
||||||
|
<!-- Batch Execute -->
|
||||||
|
<setting name="defaultExecutorType" value="BATCH" />
|
||||||
|
<!-- 给予被嵌套的resultMap以字段-属性的映射支持 -->
|
||||||
|
<setting name="autoMappingBehavior" value="FULL" />
|
||||||
|
</settings>
|
||||||
|
|
||||||
|
</configuration>
|
@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:p="http://www.springframework.org/schema/p"
|
||||||
|
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||||
|
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/aop
|
||||||
|
http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||||
|
http://www.springframework.org/schema/tx
|
||||||
|
http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||||
|
<aop:aspectj-autoproxy proxy-target-class="true" />
|
||||||
|
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
|
||||||
|
init-method="init"
|
||||||
|
destroy-method="close"
|
||||||
|
p:url="${db.url}"
|
||||||
|
p:username="${db.user}"
|
||||||
|
p:password="${db.password}"
|
||||||
|
p:maxActive="16" />
|
||||||
|
<!-- Transaction -->
|
||||||
|
<bean name="transactionManager"
|
||||||
|
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||||
|
<property name="dataSource" ref="dataSource" />
|
||||||
|
</bean>
|
||||||
|
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||||
|
<!-- MyBatis SqlSessionFactory -->
|
||||||
|
<bean id="redisCacheConfig" class="me.chyxion.tigon.mybatis.cache.RedisCacheConfig" />
|
||||||
|
<bean id="sqlSessionFactory"
|
||||||
|
class="me.chyxion.tigon.mybatis.TigonSqlSessionFactoryBean"
|
||||||
|
depends-on="redisCacheConfig"
|
||||||
|
p:dataSource-ref="dataSource"
|
||||||
|
p:typeAliasesPackage="com.pudonghot.ambition.model"
|
||||||
|
p:configLocation="classpath:mybatis/mybatis-config.xml"
|
||||||
|
p:mapperLocations="classpath*:mybatis/mappers/**/*-mapper.xml" />
|
||||||
|
<!-- MyBatis Mappers Auto Scan -->
|
||||||
|
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
|
||||||
|
p:basePackage="com.pudonghot.ambition.mapper"
|
||||||
|
p:sqlSessionFactoryBeanName="sqlSessionFactory" />
|
||||||
|
|
||||||
|
<bean class="org.springframework.jdbc.core.JdbcTemplate">
|
||||||
|
<constructor-arg ref="dataSource" />
|
||||||
|
</bean>
|
||||||
|
<bean class="me.chyxion.tigon.mybatis.cache.support.CacheToolSupport" />
|
||||||
|
</beans>
|
10
server/mapper/src/main/resources/spring/spring-app.xml
Normal file
10
server/mapper/src/main/resources/spring/spring-app.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/context
|
||||||
|
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||||
|
<!--<context:component-scan base-package="cn.com.flaginfo.umsapp.ota" /> -->
|
||||||
|
</beans>
|
@ -0,0 +1,77 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import com.pudonghot.ambition.mapper.AdminAuthFailedLogMapper;
|
||||||
|
import com.pudonghot.ambition.model.AdminAuthFailedLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:57:44 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class AdminAuthFailedLogMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private AdminAuthFailedLogMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
AdminAuthFailedLog m = new AdminAuthFailedLog();
|
||||||
|
String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setLoginId("s");
|
||||||
|
m.setPassword("s");
|
||||||
|
m.setIp("s");
|
||||||
|
m.setUserAgent("s");
|
||||||
|
m.setExt("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
AdminAuthFailedLog m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals("s", m.getLoginId());
|
||||||
|
Assert.assertEquals("s", m.getPassword());
|
||||||
|
Assert.assertEquals("s", m.getIp());
|
||||||
|
Assert.assertEquals("s", m.getUserAgent());
|
||||||
|
Assert.assertEquals("s", m.getExt());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setLoginId("S");
|
||||||
|
m.setPassword("S");
|
||||||
|
m.setIp("S");
|
||||||
|
m.setUserAgent("S");
|
||||||
|
m.setExt("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals("S", m.getLoginId());
|
||||||
|
Assert.assertEquals("S", m.getPassword());
|
||||||
|
Assert.assertEquals("S", m.getIp());
|
||||||
|
Assert.assertEquals("S", m.getUserAgent());
|
||||||
|
Assert.assertEquals("S", m.getExt());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import com.pudonghot.ambition.mapper.AdminLoginLogMapper;
|
||||||
|
import com.pudonghot.ambition.model.AdminLoginLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:57:29 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class AdminLoginLogMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private AdminLoginLogMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
AdminLoginLog m = new AdminLoginLog();
|
||||||
|
String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setAdminId(1L);
|
||||||
|
m.setUserAgent("s");
|
||||||
|
m.setIp("s");
|
||||||
|
m.setExt("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
AdminLoginLog m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals(1L, m.getAdminId());
|
||||||
|
Assert.assertEquals("s", m.getUserAgent());
|
||||||
|
Assert.assertEquals("s", m.getIp());
|
||||||
|
Assert.assertEquals("s", m.getExt());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setAdminId(2L);
|
||||||
|
m.setUserAgent("S");
|
||||||
|
m.setIp("S");
|
||||||
|
m.setExt("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals(2L, m.getAdminId());
|
||||||
|
Assert.assertEquals("S", m.getUserAgent());
|
||||||
|
Assert.assertEquals("S", m.getIp());
|
||||||
|
Assert.assertEquals("S", m.getExt());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import com.pudonghot.ambition.model.Admin;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 11, 2017 1:31:44 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class AdminMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private AdminMapper mapper;
|
||||||
|
@Autowired
|
||||||
|
private AppMapper appMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
Admin m = new Admin();
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setLoginId("s");
|
||||||
|
m.setPasswordSalt("s");
|
||||||
|
m.setPassword("s");
|
||||||
|
m.setMobile("s");
|
||||||
|
m.setEmail("s");
|
||||||
|
m.setName("s");
|
||||||
|
m.setGender("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindNextId() {
|
||||||
|
System.err.println(appMapper.nextId());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:58:53 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class AppAuthFailedLogMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private AppAuthFailedLogMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
AppAuthFailedLog m = new AppAuthFailedLog();
|
||||||
|
String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setMobile("s");
|
||||||
|
m.setPassword("s");
|
||||||
|
m.setPlatform("s");
|
||||||
|
m.setDeviceId("s");
|
||||||
|
m.setDeviceName("s");
|
||||||
|
m.setOsVersion("s");
|
||||||
|
m.setIp("s");
|
||||||
|
m.setExt("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
AppAuthFailedLog m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals("s", m.getMobile());
|
||||||
|
Assert.assertEquals("s", m.getPassword());
|
||||||
|
Assert.assertEquals("s", m.getPlatform());
|
||||||
|
Assert.assertEquals("s", m.getDeviceId());
|
||||||
|
Assert.assertEquals("s", m.getDeviceName());
|
||||||
|
Assert.assertEquals("s", m.getOsVersion());
|
||||||
|
Assert.assertEquals("s", m.getIp());
|
||||||
|
Assert.assertEquals("s", m.getExt());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setMobile("S");
|
||||||
|
m.setPassword("S");
|
||||||
|
m.setPlatform("S");
|
||||||
|
m.setDeviceId("S");
|
||||||
|
m.setDeviceName("S");
|
||||||
|
m.setOsVersion("S");
|
||||||
|
m.setIp("S");
|
||||||
|
m.setExt("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals("S", m.getMobile());
|
||||||
|
Assert.assertEquals("S", m.getPassword());
|
||||||
|
Assert.assertEquals("S", m.getPlatform());
|
||||||
|
Assert.assertEquals("S", m.getDeviceId());
|
||||||
|
Assert.assertEquals("S", m.getDeviceName());
|
||||||
|
Assert.assertEquals("S", m.getOsVersion());
|
||||||
|
Assert.assertEquals("S", m.getIp());
|
||||||
|
Assert.assertEquals("S", m.getExt());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:58:41 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class AppLoginLogMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private AppLoginLogMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
AppLoginLog m = new AppLoginLog();
|
||||||
|
String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setUserId(1L);
|
||||||
|
m.setPlatform("s");
|
||||||
|
m.setDeviceId("s");
|
||||||
|
m.setDeviceName("s");
|
||||||
|
m.setOsVersion("s");
|
||||||
|
m.setIp("s");
|
||||||
|
m.setExt("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
AppLoginLog m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals(1L, m.getUserId());
|
||||||
|
Assert.assertEquals("s", m.getPlatform());
|
||||||
|
Assert.assertEquals("s", m.getDeviceId());
|
||||||
|
Assert.assertEquals("s", m.getDeviceName());
|
||||||
|
Assert.assertEquals("s", m.getOsVersion());
|
||||||
|
Assert.assertEquals("s", m.getIp());
|
||||||
|
Assert.assertEquals("s", m.getExt());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setUserId(2L);
|
||||||
|
m.setPlatform("S");
|
||||||
|
m.setDeviceId("S");
|
||||||
|
m.setDeviceName("S");
|
||||||
|
m.setOsVersion("S");
|
||||||
|
m.setIp("S");
|
||||||
|
m.setExt("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals(2L, m.getUserId());
|
||||||
|
Assert.assertEquals("S", m.getPlatform());
|
||||||
|
Assert.assertEquals("S", m.getDeviceId());
|
||||||
|
Assert.assertEquals("S", m.getDeviceName());
|
||||||
|
Assert.assertEquals("S", m.getOsVersion());
|
||||||
|
Assert.assertEquals("S", m.getIp());
|
||||||
|
Assert.assertEquals("S", m.getExt());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 13, 2017 10:58:46 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class AppLogoutLogMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private AppLogoutLogMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
AppLogoutLog m = new AppLogoutLog();
|
||||||
|
String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setUserId(1L);
|
||||||
|
m.setIp("s");
|
||||||
|
m.setExt("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
AppLogoutLog m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals(1L, m.getUserId());
|
||||||
|
Assert.assertEquals("s", m.getIp());
|
||||||
|
Assert.assertEquals("s", m.getExt());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setUserId(2L);
|
||||||
|
m.setIp("S");
|
||||||
|
m.setExt("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals(2L, m.getUserId());
|
||||||
|
Assert.assertEquals("S", m.getIp());
|
||||||
|
Assert.assertEquals("S", m.getExt());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 10, 2017 1:30:16 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class AuthLogMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Apr 9, 2017 3:49:19 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class ContactMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private ContactMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
Contact m = new Contact();
|
||||||
|
// String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setCorpId(1);
|
||||||
|
m.setMobile("s");
|
||||||
|
m.setName("s");
|
||||||
|
m.setNamePinyin("s");
|
||||||
|
m.setGender("s");
|
||||||
|
m.setEmail("s");
|
||||||
|
m.setWechat("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
Contact m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals(1, m.getCorpId());
|
||||||
|
Assert.assertEquals("s", m.getMobile());
|
||||||
|
Assert.assertEquals("s", m.getName());
|
||||||
|
Assert.assertEquals("s", m.getNamePinyin());
|
||||||
|
Assert.assertEquals("s", m.getGender());
|
||||||
|
Assert.assertEquals("s", m.getEmail());
|
||||||
|
Assert.assertEquals("s", m.getWechat());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setCorpId(2);
|
||||||
|
m.setMobile("S");
|
||||||
|
m.setName("S");
|
||||||
|
m.setNamePinyin("S");
|
||||||
|
m.setGender("S");
|
||||||
|
m.setEmail("S");
|
||||||
|
m.setWechat("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals(2, m.getCorpId());
|
||||||
|
Assert.assertEquals("S", m.getMobile());
|
||||||
|
Assert.assertEquals("S", m.getName());
|
||||||
|
Assert.assertEquals("S", m.getNamePinyin());
|
||||||
|
Assert.assertEquals("S", m.getGender());
|
||||||
|
Assert.assertEquals("S", m.getEmail());
|
||||||
|
Assert.assertEquals("S", m.getWechat());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 10, 2017 1:30:54 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class CorpMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private CorpMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Apr 9, 2017 3:49:09 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class DeptContactMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private DeptContactMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
DeptContact m = new DeptContact();
|
||||||
|
// String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setDeptId(1L);
|
||||||
|
m.setContactId(1L);
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
DeptContact m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals(1, m.getDeptId());
|
||||||
|
Assert.assertEquals(1, m.getContactId());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setDeptId(2);
|
||||||
|
m.setContactId(2);
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals(2, m.getDeptId());
|
||||||
|
Assert.assertEquals(2, m.getContactId());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Apr 9, 2017 3:49:04 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class DeptMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private DeptMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
Dept m = new Dept();
|
||||||
|
// String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setName("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
Dept m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals("s", m.getName());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setName("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals("S", m.getName());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Apr 9, 2017 3:49:13 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class DeptPathMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private DeptPathMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
DeptPath m = new DeptPath();
|
||||||
|
// String id = "id";
|
||||||
|
// m.setId(id);
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setAncestor(1L);
|
||||||
|
m.setDescendant(1L);
|
||||||
|
m.setPathLength(1);
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
DeptPath m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals(1, m.getAncestor());
|
||||||
|
Assert.assertEquals(1, m.getDescendant());
|
||||||
|
Assert.assertEquals(1, m.getPathLength());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setAncestor(2);
|
||||||
|
m.setDescendant(2);
|
||||||
|
m.setPathLength(2);
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals(2, m.getAncestor());
|
||||||
|
Assert.assertEquals(2, m.getDescendant());
|
||||||
|
Assert.assertEquals(2, m.getPathLength());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 10, 2017 1:31:13 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class EmployeeMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private EmployeeMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Apr 9, 2017 9:07:23 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class SiteVisitLogMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private SiteVisitLogMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
SiteVisitLog m = new SiteVisitLog();
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setCorpId(1L);
|
||||||
|
m.setEmployeeId(1L);
|
||||||
|
m.setUrl("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
SiteVisitLog m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals(1, m.getCorpId());
|
||||||
|
Assert.assertEquals(1, m.getEmployeeId());
|
||||||
|
Assert.assertEquals("s", m.getUrl());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setCorpId(2);
|
||||||
|
m.setEmployeeId(2);
|
||||||
|
m.setUrl("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals(2, m.getCorpId());
|
||||||
|
Assert.assertEquals(2, m.getEmployeeId());
|
||||||
|
Assert.assertEquals("S", m.getUrl());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 10, 2017 1:31:41 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class TinyAppGroupMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private TinyAppGroupMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 10, 2017 1:31:25 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class TinyAppMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private TinyAppMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Apr 9, 2017 9:07:30 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class TinyAppVisitLogMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private TinyAppVisitLogMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
// String id = String.valueOf(new Date().getTime());
|
||||||
|
// init model
|
||||||
|
TinyAppVisitLog m = new TinyAppVisitLog();
|
||||||
|
m.setDateCreated(new Date());
|
||||||
|
m.setCorpId(1L);
|
||||||
|
m.setEmployeeId(1L);
|
||||||
|
m.setTinyAppId(1L);
|
||||||
|
m.setUrl("s");
|
||||||
|
mapper.insert(m);
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
/*
|
||||||
|
// Your Test Logics
|
||||||
|
TinyAppVisitLog m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertEquals(1, m.getCorpId());
|
||||||
|
Assert.assertEquals(1, m.getEmployeeId());
|
||||||
|
Assert.assertEquals(1, m.getTinyAppId());
|
||||||
|
Assert.assertEquals("s", m.getUrl());
|
||||||
|
// update
|
||||||
|
m.setDateUpdated(new Date());
|
||||||
|
m.setCorpId(2);
|
||||||
|
m.setEmployeeId(2);
|
||||||
|
m.setTinyAppId(2);
|
||||||
|
m.setUrl("S");
|
||||||
|
mapper.update(m);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
// asserts
|
||||||
|
Assert.assertEquals(id, m1.getId());
|
||||||
|
Assert.assertNotNull(m1.getDateUpdated());
|
||||||
|
Assert.assertEquals(2, m.getCorpId());
|
||||||
|
Assert.assertEquals(2, m.getEmployeeId());
|
||||||
|
Assert.assertEquals(2, m.getTinyAppId());
|
||||||
|
Assert.assertEquals("S", m.getUrl());
|
||||||
|
// list
|
||||||
|
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||||
|
// delete
|
||||||
|
mapper.delete(id);
|
||||||
|
m1 = mapper.find(id);
|
||||||
|
Assert.assertNull(m1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.pudonghot.ambition.mapper;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 0.0.1
|
||||||
|
* @author Auto Generated <br>
|
||||||
|
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||||
|
* Mar 5, 2017 5:09:42 PM
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||||
|
public class UserMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||||
|
@Autowired
|
||||||
|
private UserMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapperTest() {
|
||||||
|
System.out.println(mapper.list(null));
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user