();
33 | ObjectMapper mapper = new ObjectMapper();
34 | String jsonString = mapper.writeValueAsString(object);
35 | claims.put(PAYLOAD, jsonString);
36 | claims.put(EXP, System.currentTimeMillis() + maxAge);
37 | return signer.sign(claims);
38 | } catch(Exception e) {
39 | return null;
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/service/SpringContextService.java:
--------------------------------------------------------------------------------
1 | package com.zag.service;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.ApplicationContextAware;
6 | import org.springframework.stereotype.Service;
7 |
8 | /**
9 | * Spring容器工具
10 | *
11 | * 该工具类需要先注册成为spring容器中的bean
12 | *
13 | */
14 | @Service
15 | public class SpringContextService implements ApplicationContextAware {
16 |
17 | private static ApplicationContext applicationContext;
18 |
19 | @Override
20 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
21 | SpringContextService.applicationContext = applicationContext;
22 | }
23 |
24 | /**
25 | * 获取Spring容器
26 | *
27 | * @return
28 | */
29 | public static ApplicationContext getContext() {
30 | return applicationContext;
31 | }
32 |
33 | public static T getBean(Class beanType) {
34 | return applicationContext == null ? null : applicationContext.getBean(beanType);
35 | }
36 |
37 | public static Object getBean(String beanName) {
38 | return applicationContext == null ? null : applicationContext.getBean(beanName);
39 | }
40 |
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/service/SystemConfig.java:
--------------------------------------------------------------------------------
1 | package com.zag.service;
2 |
3 | /**
4 | * 动态系统配置,从zookeeper加载,如果加载失败,应该有默认配置
5 | * 搬运自原系统,抽离自SystemConfigMonitor.SignConfig
6 | * @author stone
7 | * @since 2017年8月4日
8 | * @usage
9 | * @reviewer
10 | */
11 | public class SystemConfig {
12 | public final static String ZNODE = "/zag/config/system";
13 |
14 | public SystemConfig(){}
15 | /**
16 | * 是否开启签名
17 | */
18 | private Boolean openSign = true;
19 |
20 | public Boolean getOpenSign() {
21 | return openSign;
22 | }
23 |
24 | public void setOpenSign(Boolean openSign) {
25 | this.openSign = openSign;
26 | }
27 |
28 |
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/service/ex/account/AccountService.java:
--------------------------------------------------------------------------------
1 | package com.zag.service.ex.account;
2 |
3 | import com.zag.enums.TransactionTypeEnums;
4 | import com.zag.vo.BaseRequestVo;
5 | import com.zag.vo.ex.account.Erc20WithdrawReqVo;
6 | import com.zag.vo.ex.account.EthWithdrawReqVo;
7 |
8 | import java.io.IOException;
9 |
10 | /**
11 | * @ProjectName: web3j-zag
12 | * @Package: com.zag.service.ex.account
13 | * @ClassName: ${AccountService}
14 | * @Description: 账户处理
15 | * @Author: skyhuihui
16 | * @CreateDate: 2018/8/24 14:40
17 | * @UpdateUser: Neil.Zhou
18 | * @UpdateDate: 2018/8/24 14:40
19 | * @UpdateRemark: The modified content
20 | * @Version: 1.0
21 | */
22 | public interface AccountService {
23 |
24 | /**
25 | * 获得用户以太坊地址
26 | * @author skyhuihui
27 | * @version V1.0
28 | * @param reqVo
29 | * @return String
30 | */
31 | String findUserAccount(BaseRequestVo reqVo);
32 |
33 | /**
34 | * 以太币提现
35 | * @author skyhuihui
36 | * @version V1.0
37 | * @param reqVo
38 | * @return String
39 | */
40 | String updateUserEthAccount(EthWithdrawReqVo reqVo) throws IOException;
41 |
42 | /**
43 | * erc20代币提现
44 | * @author skyhuihui
45 | * @version V1.0
46 | * @param reqVo
47 | * @return String
48 | */
49 | String updateUserErc20Account(Erc20WithdrawReqVo reqVo) throws IOException;
50 |
51 | /**
52 | * 交易记录保存进数据库(充值,提现等)
53 | * @author skyhuihui
54 | * @version V1.0
55 | * @return void
56 | */
57 | void insertTransaction(TransactionTypeEnums typeEnums, Double amount , String address, String tokenAddress, String hash);
58 | }
59 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/service/ex/account/AccountTxlistService.java:
--------------------------------------------------------------------------------
1 | package com.zag.service.ex.account;
2 |
3 | import java.io.IOException;
4 | import java.math.BigInteger;
5 |
6 | /**
7 | * @ProjectName: web3j-zag
8 | * @Package: com.zag.service.ex.account
9 | * @ClassName: ${AccountTxlistService}
10 | * @Description: 检测账户充币
11 | * @Author: skyhuihui
12 | * @CreateDate: 2018/8/29 13:52
13 | * @UpdateUser: Neil.Zhou
14 | * @UpdateDate: 2018/8/29 13:52
15 | * @UpdateRemark: The modified content
16 | * @Version: 1.0
17 | */
18 | public interface AccountTxlistService {
19 |
20 | /**
21 | * 检测充币
22 | * @author skyhuihui
23 | * @version V1.0
24 | * @return void
25 | */
26 | void txEthErc20List() throws IOException;
27 |
28 | /**
29 | * 检测eth充币
30 | * @author skyhuihui
31 | * @version V1.0
32 | * @return void
33 | */
34 | void txEthList() throws IOException;
35 | }
36 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/service/ex/user/UserService.java:
--------------------------------------------------------------------------------
1 | package com.zag.service.ex.user;
2 |
3 |
4 | import com.zag.vo.ex.user.req.UserAddMailReqVo;
5 | import com.zag.vo.ex.user.req.UserAddPhoneOrMailReqVo;
6 | import com.zag.vo.ex.user.req.UserAddPhoneReqVo;
7 | import com.zag.vo.ex.user.req.UserFindReqVo;
8 | import com.zag.vo.ex.user.resp.UserRespVo;
9 |
10 | /**
11 | * @ProjectName: web3j-zag
12 | * @Package: com.zag.service.ex.user
13 | * @ClassName: UserService
14 | * @Description: 用户service
15 | * @Author: skyhuihui
16 | * @CreateDate: 2018/8/8 10:37
17 | * @UpdateUser: Neil.Zhou
18 | * @UpdateDate: 2018/8/8 10:37
19 | * @UpdateRemark: The modified content
20 | * @Version: 1.0
21 | */
22 | public interface UserService {
23 |
24 | /**
25 | * 添加用户邮箱注册
26 | * @author skyhuihui
27 | * @version V1.0
28 | * @param reqVo
29 | * @return void
30 | */
31 | UserRespVo insertMailUser(UserAddMailReqVo reqVo);
32 |
33 | /**
34 | * 添加用户手机号注册
35 | * @author skyhuihui
36 | * @version V1.0
37 | * @param reqVo
38 | * @return void
39 | */
40 | UserRespVo insertPhoneUser(UserAddPhoneReqVo reqVo);
41 |
42 | /**
43 | * 查询用户 登录
44 | * @author skyhuihui
45 | * @version V1.0
46 | * @param reqVo
47 | * @return UserRespVo
48 | */
49 | UserRespVo findUser(UserFindReqVo reqVo);
50 |
51 | /**
52 | * 查询用户
53 | * @author skyhuihui
54 | * @version V1.0
55 | * @param id
56 | * @return UserRespVo
57 | */
58 | UserRespVo findUserById(Long id);
59 |
60 | /**
61 | * 用户绑定邮箱/手机号 一个邮箱手机号只能用一次
62 | * @author skyhuihui
63 | * @version V1.0
64 | * @param reqVo
65 | * @return UserRespVo
66 | */
67 | UserRespVo addPhoneOrMail(UserAddPhoneOrMailReqVo reqVo);
68 | }
69 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/service/web3/ArticleService.java:
--------------------------------------------------------------------------------
1 | package com.zag.service.web3;
2 |
3 | import com.zag.vo.web3.req.ArticleAddReqVo;
4 | import com.zag.vo.web3.req.ArticleReqVo;
5 | import com.zag.vo.web3.resp.ArticleRespVo;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @ProjectName: web3-zag
11 | * @Package: com.zag.service.web3
12 | * @ClassName: ArticleService
13 | * @Description: article service
14 | * @Author: skyhuihui
15 | * @CreateDate: 2018/8/2 16:43
16 | * @UpdateUser: Neil.Zhou
17 | * @UpdateDate: 2018/8/2 16:43
18 | * @UpdateRemark: The modified content
19 | * @Version: 1.0
20 | */
21 | public interface ArticleService {
22 |
23 | //检索用户文章数据
24 | List selectArticle(ArticleReqVo reqVo);
25 |
26 | //检索用户文章数据
27 | List selectAllArticle(ArticleReqVo reqVo);
28 |
29 | //添加用户文章数据
30 | List insertArticle(ArticleAddReqVo reqVo);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/CollectionSizeValidator.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation;
2 |
3 | import java.util.Collection;
4 |
5 | import javax.validation.ConstraintValidator;
6 | import javax.validation.ConstraintValidatorContext;
7 |
8 | import com.zag.core.exception.BusinessException;
9 | import com.zag.exception.Exceptions;
10 | import com.zag.validation.constraints.CollectionSizeCheck;
11 |
12 | /**
13 | * 集合元素数量检查
14 | *
15 | * @author stone 2017年5月30日
16 | */
17 | public class CollectionSizeValidator implements ConstraintValidator>{
18 |
19 | private int min;
20 | private int max;
21 | private boolean throwable;
22 | private String message;
23 |
24 | @Override
25 | public void initialize(CollectionSizeCheck anno) {
26 | this.max = anno.maxSize();
27 | this.min = anno.minSize();
28 | this.throwable = anno.throwable();
29 | this.message = anno.message();
30 | }
31 |
32 | @Override
33 | public boolean isValid(Collection> value, ConstraintValidatorContext context) {
34 | int size = value.size();
35 | if(size >= min && size <= max){
36 | return true;
37 | }
38 |
39 |
40 | if(throwable){
41 | throw new BusinessException(Exceptions.Global.PARAMETER_ERROR,message);
42 | }else{
43 | return false;
44 | }
45 |
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/IdCardValidator.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation;
2 |
3 | import javax.validation.ConstraintValidator;
4 | import javax.validation.ConstraintValidatorContext;
5 |
6 | import org.apache.commons.lang3.StringUtils;
7 |
8 | import com.zag.core.asserts.BusinessAsserts;
9 | import com.zag.exception.Exceptions;
10 | import com.zag.validation.constraints.IdCard;
11 |
12 | /**
13 | * 身份证号码验证器,验证规则请百度百科 "身份证号码"
14 | *
15 | * @author stone 2017年5月11日
16 | */
17 | public class IdCardValidator implements ConstraintValidator {
18 |
19 | @Override
20 | public void initialize(IdCard constraintAnnotation) {
21 |
22 | }
23 |
24 | private static final int[] factors_17 = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
25 | private static final char[] mod_11 = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' };
26 |
27 | @Override
28 | public boolean isValid(String value, ConstraintValidatorContext context) {
29 | if(StringUtils.isBlank(value)) return true; //空数据不验证
30 | if (value.trim().length() != 18) return false; //非空数据,先校验长度
31 | char[] chararray = value.trim().toCharArray();
32 | int len = chararray.length;
33 | char lastChar = chararray[len - 1];
34 | int sum = 0;
35 | for (int i = 0; i < len - 1; i++) {
36 | int digit = Integer.valueOf("" + chararray[i]);
37 | sum += digit * factors_17[i];
38 | }
39 | BusinessAsserts.isTrue(mod_11[sum % 11] == lastChar, Exceptions.Global.PARAMETER_ERROR,"身份证号码验证失败");
40 | return true;
41 | }
42 | public static void main(String[] args) {
43 | IdCardValidator v = new IdCardValidator();
44 | System.out.println(v.isValid("430421197710177894", null));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/MobileValidator.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation;
2 |
3 | import javax.validation.ConstraintValidator;
4 | import javax.validation.ConstraintValidatorContext;
5 |
6 | import com.zag.validation.constraints.IsMobile;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | import com.zag.core.exception.BusinessException;
10 | import com.zag.exception.Exceptions;
11 |
12 | /**
13 | * 手机号
14 | *
15 | * @author stone 2017年5月17日
16 | */
17 | public class MobileValidator implements ConstraintValidator{
18 |
19 | public static final MobileValidator INSTANCE = new MobileValidator();
20 |
21 | private static final String mobile_regexp = "^((14[0-9])|(13[0-9])|(17[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$";
22 | private boolean required = true;
23 | private String message;
24 | private boolean throwable;
25 | @Override
26 | public void initialize(IsMobile anno) {
27 | message=anno.message();
28 | // type = anno.throwing();
29 | throwable = anno.throwable();
30 | }
31 |
32 | @Override
33 | public boolean isValid(String value, ConstraintValidatorContext context) {
34 | boolean pass = false;
35 | if(required){
36 | pass = StringUtils.isNotBlank(value) && value.matches(mobile_regexp);
37 | }else{
38 | pass = StringUtils.isBlank(value) || value.matches(mobile_regexp);
39 | }
40 | if(!pass && throwable){
41 | throw new BusinessException(Exceptions.User.MOBILE_ERROR,message);
42 | }
43 | return pass;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/NotBlankValidator.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation;
2 |
3 | import javax.validation.ConstraintValidator;
4 | import javax.validation.ConstraintValidatorContext;
5 |
6 | import com.zag.validation.constraints.IsNotBlank;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | import com.zag.core.exception.BusinessException;
10 | import com.zag.exception.Exceptions;
11 |
12 | public class NotBlankValidator implements ConstraintValidator {
13 |
14 | private String message;
15 | // private Exceptions type;
16 | private boolean throwable;
17 | @Override
18 | public void initialize(IsNotBlank anno) {
19 | message=anno.message();
20 | // type = anno.throwing();
21 | throwable = anno.throwable();
22 | }
23 |
24 | @Override
25 | public boolean isValid(String value, ConstraintValidatorContext context) {
26 | if(StringUtils.isBlank(value)){
27 | if(throwable) {
28 | throw new BusinessException(Exceptions.Global.MISSING_REQUIRED_PARAMS,message);
29 | }
30 | return false;
31 | }
32 | return true;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/NotEmptyValidator.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation;
2 |
3 | import javax.validation.ConstraintValidator;
4 | import javax.validation.ConstraintValidatorContext;
5 |
6 | import com.zag.core.exception.BusinessException;
7 | import com.zag.exception.Exceptions;
8 | import com.zag.validation.constraints.IsNotEmpty;
9 |
10 | public class NotEmptyValidator implements ConstraintValidator> {
11 |
12 | private String message;
13 | // private Exceptions type;
14 | private boolean throwable;
15 | @Override
16 | public void initialize(IsNotEmpty anno) {
17 | message=anno.message();
18 | // type = anno.throwing();
19 | throwable = anno.throwable();
20 | }
21 |
22 | @Override
23 | public boolean isValid(Iterable> value, ConstraintValidatorContext context) {
24 | if(value == null || !value.iterator().hasNext()){
25 | if(throwable) {
26 | throw new BusinessException(Exceptions.Global.MISSING_REQUIRED_PARAMS,message);
27 | }
28 | return false;
29 | }
30 | return true;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/NotNullValidator.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation;
2 |
3 | import javax.validation.ConstraintValidator;
4 | import javax.validation.ConstraintValidatorContext;
5 |
6 | import com.zag.core.exception.BusinessException;
7 | import com.zag.exception.Exceptions;
8 | import com.zag.validation.constraints.IsNotNull;
9 |
10 | public class NotNullValidator implements ConstraintValidator {
11 |
12 | private String message;
13 | // private Exceptions type;
14 | private boolean throwable;
15 | @Override
16 | public void initialize(IsNotNull anno) {
17 | message=anno.message();
18 | // type = anno.throwing();
19 | throwable = anno.throwable();
20 | }
21 |
22 | @Override
23 | public boolean isValid(Object value, ConstraintValidatorContext context) {
24 | if(value == null){
25 | if(throwable) {
26 | throw new BusinessException(Exceptions.Global.MISSING_REQUIRED_PARAMS,message);
27 | }
28 | return false;
29 | }
30 | return true;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/StringLengthValidator.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation;
2 |
3 | import javax.validation.ConstraintValidator;
4 | import javax.validation.ConstraintValidatorContext;
5 |
6 | import com.zag.core.exception.BusinessException;
7 | import com.zag.exception.Exceptions;
8 | import com.zag.validation.constraints.StringLength;
9 |
10 | public class StringLengthValidator implements ConstraintValidator{
11 |
12 | private int min;
13 | private int max;
14 | private boolean trim;
15 | private boolean notNull;
16 | private String message;
17 |
18 | @Override
19 | public void initialize(StringLength anno) {
20 | this.min = anno.min();
21 | this.max = anno.max();
22 | this.trim = anno.trim();
23 | this.notNull = anno.notNull();
24 | this.message = anno.message();
25 | }
26 |
27 | @Override
28 | public boolean isValid(String value, ConstraintValidatorContext context) {
29 | if(!notNull && value == null) return true;
30 | if(notNull && value == null) throw new BusinessException(Exceptions.Global.PARAMETER_ERROR,message);
31 | if(trim) value = value.trim();
32 | int len = value.length();
33 | if(len>=min && len <= max) return true;
34 | else throw new BusinessException(Exceptions.Global.PARAMETER_ERROR,message);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/constraints/CollectionSizeCheck.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation.constraints;
2 |
3 | import static java.lang.annotation.ElementType.FIELD;
4 | import static java.lang.annotation.ElementType.METHOD;
5 |
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | import javax.validation.Constraint;
11 | import javax.validation.Payload;
12 |
13 | import com.zag.validation.CollectionSizeValidator;
14 |
15 | /**
16 | * 集合范围检查
17 | *
18 | * @author stone 2017年5月30日
19 | */
20 | @Target({FIELD,METHOD})
21 | @Retention(RetentionPolicy.RUNTIME)
22 | @Constraint(validatedBy=CollectionSizeValidator.class)
23 | public @interface CollectionSizeCheck {
24 |
25 | String message() default "";
26 |
27 | int minSize() default 0;
28 |
29 | int maxSize() default Integer.MAX_VALUE;
30 |
31 | boolean throwable() default true;
32 |
33 | Class>[] groups() default {};
34 |
35 | Class extends Payload>[] payload() default {};
36 | }
37 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/constraints/IdCard.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation.constraints;
2 |
3 | //import java.lang.annotation.ElementType;
4 | import static java.lang.annotation.ElementType.FIELD;
5 | import static java.lang.annotation.ElementType.METHOD;
6 |
7 | import java.lang.annotation.Retention;
8 | import java.lang.annotation.RetentionPolicy;
9 | import java.lang.annotation.Target;
10 |
11 | import javax.validation.Constraint;
12 | import javax.validation.Payload;
13 |
14 | import com.zag.validation.IdCardValidator;
15 |
16 | /**
17 | * 身份证号码验证注解
18 | *
19 | * @author stone 2017年5月11日
20 | */
21 | @Target({FIELD,METHOD})
22 | @Retention(RetentionPolicy.RUNTIME)
23 | @Constraint(validatedBy=IdCardValidator.class)
24 | public @interface IdCard {
25 | String message() default "身份证验证失败";
26 |
27 | Class>[] groups() default {};
28 |
29 | Class extends Payload>[] payload() default {};
30 |
31 | /**
32 | * 当为false时,验证失败不会抛出异常
33 | *
34 | * @return
35 | */
36 | boolean throwable() default true;
37 | }
38 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/constraints/IsMobile.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation.constraints;
2 |
3 | import static java.lang.annotation.ElementType.FIELD;
4 | import static java.lang.annotation.ElementType.METHOD;
5 |
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | import javax.validation.Constraint;
11 | import javax.validation.Payload;
12 |
13 | import com.zag.validation.MobileValidator;
14 |
15 |
16 | @Target({FIELD,METHOD})
17 | @Retention(RetentionPolicy.RUNTIME)
18 | @Constraint(validatedBy=MobileValidator.class)
19 | public @interface IsMobile {
20 | /**
21 | * 验证失败会作为失败消息返回
22 | *
23 | * @return
24 | */
25 | String message() default "手机号不正确";
26 |
27 | /**
28 | * 当为false时,验证失败不会抛出异常
29 | *
30 | * @return
31 | */
32 | boolean throwable() default true;
33 |
34 | Class>[] groups() default {};
35 |
36 | Class extends Payload>[] payload() default {};
37 | /**
38 | * 是否必填,如果为false,在手机号值为空的时候跳过验证
39 | *
40 | * @return
41 | */
42 | boolean required() default true;
43 | }
44 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/constraints/IsNotBlank.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation.constraints;
2 |
3 | import static java.lang.annotation.ElementType.FIELD;
4 | import static java.lang.annotation.ElementType.METHOD;
5 |
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | import javax.validation.Constraint;
11 | import javax.validation.Payload;
12 |
13 | import com.zag.validation.NotBlankValidator;
14 |
15 | /**
16 | * 替换javax.validation的非空注解,验证不通过则抛出异常
17 | *
18 | * @author stone 2017年5月18日
19 | */
20 | @Target({FIELD,METHOD})
21 | @Retention(RetentionPolicy.RUNTIME)
22 | @Constraint(validatedBy=NotBlankValidator.class)
23 | public @interface IsNotBlank {
24 | /**
25 | * 验证失败会作为失败消息返回
26 | *
27 | * @return
28 | */
29 | String message() default "";
30 |
31 | /**
32 | * 当为false时,验证失败不会抛出异常
33 | *
34 | * @return
35 | */
36 | boolean throwable() default true;
37 |
38 | Class>[] groups() default {};
39 |
40 | Class extends Payload>[] payload() default {};
41 | }
42 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/constraints/IsNotEmpty.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation.constraints;
2 |
3 | import static java.lang.annotation.ElementType.FIELD;
4 | import static java.lang.annotation.ElementType.METHOD;
5 |
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | import javax.validation.Constraint;
11 | import javax.validation.Payload;
12 |
13 | import com.zag.validation.NotEmptyValidator;
14 |
15 | @Target({FIELD,METHOD})
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Constraint(validatedBy=NotEmptyValidator.class)
18 | public @interface IsNotEmpty {
19 | /**
20 | * 验证失败会作为失败消息返回
21 | *
22 | * @return
23 | */
24 | String message() default "";
25 |
26 | /**
27 | * 当为false时,验证失败不会抛出异常,默认true
28 | *
29 | * @return
30 | */
31 | boolean throwable() default true;
32 |
33 | Class>[] groups() default {};
34 |
35 | Class extends Payload>[] payload() default {};
36 | }
37 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/constraints/IsNotNull.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation.constraints;
2 |
3 | import static java.lang.annotation.ElementType.FIELD;
4 | import static java.lang.annotation.ElementType.METHOD;
5 |
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | import javax.validation.Constraint;
11 | import javax.validation.Payload;
12 |
13 | import com.zag.validation.NotNullValidator;
14 |
15 | @Target({FIELD,METHOD})
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Constraint(validatedBy=NotNullValidator.class)
18 | public @interface IsNotNull {
19 | /**
20 | * 验证失败会作为失败消息返回
21 | *
22 | * @return
23 | */
24 | String message() default "";
25 |
26 | /**
27 | * 当为false时,验证失败不会抛出异常,默认true
28 | *
29 | * @return
30 | */
31 | boolean throwable() default true;
32 |
33 | Class>[] groups() default {};
34 |
35 | Class extends Payload>[] payload() default {};
36 | }
37 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/validation/constraints/StringLength.java:
--------------------------------------------------------------------------------
1 | package com.zag.validation.constraints;
2 |
3 | import static java.lang.annotation.ElementType.FIELD;
4 | import static java.lang.annotation.ElementType.METHOD;
5 |
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | import javax.validation.Constraint;
11 | import javax.validation.Payload;
12 |
13 | import com.zag.validation.StringLengthValidator;
14 |
15 | @Target({ FIELD, METHOD })
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Constraint(validatedBy = StringLengthValidator.class)
18 | public @interface StringLength {
19 |
20 | int min() default 0;
21 |
22 | int max() default Integer.MAX_VALUE;
23 |
24 | boolean trim() default true;
25 |
26 | /**
27 | * 如果字符串为null,切notNull为fasle,则不进行接下来的检查
28 | * @author stone
29 | * @date 2017年8月6日
30 | * @return
31 | */
32 | boolean notNull() default false;
33 |
34 | String message() default "长度不符合";
35 |
36 | Class>[] groups() default {};
37 |
38 | Class extends Payload>[] payload() default {};
39 | }
40 |
--------------------------------------------------------------------------------
/service/src/main/java/com/zag/view/ExcelView.java:
--------------------------------------------------------------------------------
1 | package com.zag.view;
2 |
3 |
4 | import com.zag.core.util.ExcelUtil;
5 | import org.apache.poi.hssf.usermodel.HSSFWorkbook;
6 | import org.springframework.web.servlet.view.document.AbstractExcelView;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.io.OutputStream;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author zhangcheng
15 | * @date 2016/10/6
16 | * @see
17 | * @reviewer
18 | */
19 | public class ExcelView extends AbstractExcelView {
20 | @Override
21 | public void buildExcelDocument(Map map, HSSFWorkbook hssfWorkbook,
22 | HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
23 | String filename = ExcelUtil.encodeFilename((map.get("filename").toString() + System.currentTimeMillis()).concat(".xls"), httpServletRequest);
24 | httpServletResponse.setContentType("application/vnd.ms-excel");
25 | httpServletResponse.setHeader("Content-disposition", "attachment;filename=" + filename);
26 | OutputStream outputStream = httpServletResponse.getOutputStream();
27 | hssfWorkbook.write(outputStream);
28 | outputStream.flush();
29 | outputStream.close();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/service/src/main/resources/application-service.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/service/src/main/resources/lib/taobao-sdk-java-auto_1455552377940-20160607.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skyhuihui/exchange/7785866ae7a7e21daee9629a793bd9a33ff6f43c/service/src/main/resources/lib/taobao-sdk-java-auto_1455552377940-20160607.jar
--------------------------------------------------------------------------------
/service/src/test/resources/datasource.properties:
--------------------------------------------------------------------------------
1 | # 数据库相关
2 | jdbc.driver = ${jdbc.driver}
3 | jdbc.url = ${jdbc.url}
4 | jdbc.username = ${jdbc.username}
5 | jdbc.password = ${jdbc.password}
6 |
7 | # 池初始化大小
8 | jdbc.initialSize=${jdbc.initialSize}
9 |
10 | # 池最小连接数
11 | jdbc.minIdle=${jdbc.minIdle}
12 |
13 | # 池最大连接数
14 | jdbc.maxIdle= ${jdbc.maxIdle}
15 |
16 | # 池最大连接数
17 | jdbc.maxActive=${jdbc.maxActive}
18 |
19 | # 获取连接等待超时的时间
20 | jdbc.maxWait=${jdbc.maxWait}
21 |
22 | # 对于建立时间超过removeAbandonedTimeout的连接强制关闭
23 | jdbc.removeAbandoned = ${jdbc.removeAbandoned}
24 |
25 | # 指定连接建立多长时间就需要被强制关闭
26 | jdbc.removeAbandonedTimeout= ${jdbc.removeAbandonedTimeout}
27 |
28 | # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
29 | jdbc.timeBetweenEvictionRunsMillis=${jdbc.timeBetweenEvictionRunsMillis}
30 |
31 | # 一个连接在池中最小生存的时间,单位是毫秒
32 | jdbc.minEvictableIdleTimeMillis=${jdbc.minEvictableIdleTimeMillis}
33 |
34 | # 是否打开PSCache
35 | jdbc.poolPreparedStatements=${jdbc.poolPreparedStatements}
36 |
37 | # 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
38 | jdbc.maxOpenPreparedStatements = 100
39 |
40 | # 指定每个连接上PSCache的大小
41 | jdbc.maxPoolPreparedStatementPerConnectionSize=${jdbc.maxPoolPreparedStatementPerConnectionSize}
42 |
43 | # 连接检测
44 | jdbc.validationQuery = SELECT 'x'
45 |
46 | # 连接检测超时时间
47 | jdbc.validationQueryTimeout=3600
48 |
49 | # 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除.
50 | jdbc.testWhileIdle = true
51 |
52 | # 借出连接时不要测试,否则很影响性能
53 | jdbc.testOnBorrow = false
54 | # 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
55 | jdbc.testOnReturn = false
56 | # 属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有:监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall
57 | jdbc.filters = mergeStat,log4j,config
58 |
59 | # 关闭abanded连接时输出错误日志
60 | jdbc.logAbandoned = false
61 |
62 | # JPA是否显示sql
63 | show_sql=${show_sql}
--------------------------------------------------------------------------------
/service/src/test/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | [%thread] %d{MM-dd HH:mm:ss} [%-5level] %class{0}:%line - %msg%n
6 |
7 |
8 |
9 |
10 | logs/${profileName}.log
11 |
12 | [%thread] %d{MM-dd HH:mm:ss} [%-5level] %class{0}:%line - %msg%n
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/web-support/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/web-support/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.zag
9 | zag
10 | 1.0.0
11 |
12 |
13 | web-support
14 | jar
15 |
16 |
17 |
18 | com.zag
19 | core
20 |
21 |
22 |
23 | javax.servlet
24 | javax.servlet-api
25 | provided
26 |
27 |
28 | org.springframework
29 | spring-core
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/BuildRequestHandler.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web;
2 |
3 | import com.zag.core.exception.SystemException;
4 | import com.zag.support.web.assist.IRequestVo;
5 | import org.springframework.core.Ordered;
6 |
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | /**
10 | * 构建请求处理链
11 | * 所有实现必须被mvc容器管理
12 | * 返回较小的order值的实现排在处理链更前方
13 | *
14 | * @author lei
15 | * @usage
16 | * @reviewer
17 | * @since 2017年8月17日
18 | */
19 | public interface BuildRequestHandler extends Ordered {
20 |
21 | void handle(HttpServletRequest request, IRequestVo requestVo) throws SystemException;
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/assist/ClientType.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.assist;
2 |
3 |
4 | import com.zag.core.enums.EnumerableValue;
5 | import com.zag.core.enums.converter.BaseEnumValueConverter;
6 |
7 | /**
8 | * 调用接口的客户端类型
9 | *
10 | * @author stone
11 | * @usage
12 | * @reviewer
13 | * @since 2017年8月2日
14 | */
15 | public enum ClientType implements EnumerableValue {
16 | //ios app
17 | IOS(0, "ios app"),
18 | //安卓app
19 | ANDROID(1, "安卓app"),
20 | //微商城
21 | WECHAT(2, "微商城"),
22 | //浏览器
23 | WEB(3, "浏览器"),
24 |
25 | UNKNOWN(4, "位置");
26 |
27 |
28 | private int value;
29 | private String desc;
30 | ClientType(int value, String desc) {
31 | this.value = value;
32 | this.desc = desc;
33 | }
34 |
35 | @Override
36 | public int getValue() {
37 | return value;
38 | }
39 |
40 | public void setValue(int value) {
41 | this.value = value;
42 | }
43 |
44 | public String getDesc() {
45 | return desc;
46 | }
47 |
48 | public void setDesc(String desc) {
49 | this.desc = desc;
50 | }
51 |
52 | public static class Converter extends BaseEnumValueConverter {
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/assist/ClientTypeAware.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.assist;
2 |
3 | /**
4 | * 请求vo 客户端类型感知 实现本接口的requestVo,
5 | * 在被BaseController处理时,
6 | * 会自动绑定当前请求者的clientType
7 | *
8 | * @author lei
9 | * @usage requestVo实现本接口
10 | * @reviewer
11 | * @since 2017年8月17日
12 | */
13 | public interface ClientTypeAware {
14 |
15 | /**
16 | * 实现本接口的request vo通过此方法绑定请求者的client type
17 | *
18 | * @author lei
19 | * @date 2017年8月17日
20 | */
21 | void setClientType(ClientType clientType);
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/assist/GlobalParams.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.assist;
2 |
3 | import java.io.Serializable;
4 |
5 |
6 | /**
7 | * 全局参数
8 | */
9 | public class GlobalParams implements Serializable {
10 |
11 | /**
12 | *
13 | */
14 | private static final long serialVersionUID = -2980565642013490335L;
15 |
16 | public GlobalParams() {
17 | }
18 |
19 | public GlobalParams(Long id, String name, String type, String userExamineEnums) {
20 | this.id = id;
21 | this.name = name;
22 | this.type = type;
23 | this.userExamineEnums = userExamineEnums;
24 | }
25 |
26 | private Long id;
27 |
28 | private String name;
29 |
30 | private String type;
31 |
32 | private String userExamineEnums;
33 |
34 | public Long getId() {
35 | return id;
36 | }
37 |
38 | public void setId(Long id) {
39 | this.id = id;
40 | }
41 |
42 | public String getName() {
43 | return name;
44 | }
45 |
46 | public void setName(String name) {
47 | this.name = name;
48 | }
49 |
50 | public String getType() {
51 | return type;
52 | }
53 |
54 | public void setType(String type) {
55 | this.type = type;
56 | }
57 |
58 | public String getUserExamineEnums() {
59 | return userExamineEnums;
60 | }
61 |
62 | public void setUserExamineEnums(String userExamineEnums) {
63 | this.userExamineEnums = userExamineEnums;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/assist/GlobalParamsAware.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zag.support.web.assist;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * 全局参数接口
10 | */
11 | public interface GlobalParamsAware extends Serializable {
12 |
13 | GlobalParams getGlobalParams();
14 |
15 | void setGlobalParams(GlobalParams globalParams);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/assist/IPAddressAware.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.assist;
2 |
3 | /**
4 | * 标记一个vo具有ip属性,在构建消息时注入
5 | *
6 | * @author lei 2017年5月9日
7 | */
8 | public interface IPAddressAware {
9 | String getIp();
10 |
11 | void setIp(String ip);
12 | }
13 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/assist/IRequestVo.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.assist;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * rest 请求模型接口
7 | *
8 | * @author lei
9 | * @date 2017/1/17
10 | */
11 | public interface IRequestVo extends GlobalParamsAware, Serializable {
12 | }
13 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/assist/PostInitialization.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.assist;
2 |
3 | /**
4 | * 实现该接口的requestVo将在BaseController处理完数据后调用postInitializing()方法
5 | *
6 | * @author lei
7 | * @usage
8 | * @reviewer
9 | * @since 2017年8月16日
10 | */
11 | public interface PostInitialization {
12 |
13 | void postInitializing();
14 | }
15 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/filter/AccessControlFilter.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.filter;
2 |
3 | import javax.servlet.*;
4 | import javax.servlet.http.HttpServletResponse;
5 | import java.io.IOException;
6 |
7 | /**
8 | * @author lei
9 | * @date 2017/2/8
10 | */
11 | public class AccessControlFilter implements Filter {
12 |
13 | @Override
14 | public void init(FilterConfig filterConfig) throws ServletException {
15 |
16 | }
17 |
18 | @Override
19 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
20 | HttpServletResponse resp = (HttpServletResponse) response;
21 | String allowDomain = "*";
22 | resp.setHeader("Access-Control-Allow-Origin", allowDomain);
23 | resp.setHeader("Access-Control-Allow-Methods", "GET, POST, HEAD, PUT, DELETE, OPTIONS");
24 | resp.setHeader("Access-Control-Max-Age", "3600");
25 | resp.setHeader("Access-Control-Allow-Headers", "Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization,auth");
26 | resp.setHeader("Access-Control-Allow-Credentials","true");
27 | chain.doFilter(request, resp);
28 | }
29 |
30 | @Override
31 | public void destroy() {
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/handler/ClientTypeHandler.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.handler;
2 |
3 | import com.zag.core.exception.SystemException;
4 | import com.zag.support.web.BuildRequestHandler;
5 | import com.zag.support.web.assist.ClientType;
6 | import com.zag.support.web.assist.ClientTypeAware;
7 | import com.zag.support.web.assist.IRequestVo;
8 | import com.zag.support.web.assist.GlobalParams;
9 | import org.apache.commons.lang3.StringUtils;
10 | import org.slf4j.Logger;
11 | import org.slf4j.LoggerFactory;
12 | import org.springframework.stereotype.Component;
13 |
14 | import javax.servlet.http.HttpServletRequest;
15 |
16 | /**
17 | * 感知client type并与vo绑定
18 | *
19 | * @author stone
20 | * @usage
21 | * @reviewer
22 | * @since 2017年8月17日
23 | */
24 | @Component
25 | public class ClientTypeHandler implements BuildRequestHandler {
26 |
27 | private Logger logger = LoggerFactory.getLogger(getClass());
28 |
29 | @Override
30 | public void handle(HttpServletRequest request, IRequestVo requestVo) throws SystemException {
31 | if (requestVo instanceof ClientTypeAware) {
32 | ClientTypeAware aware = (ClientTypeAware) requestVo;
33 | // 实现了全局参数接口,client type从全局参数中取
34 | GlobalParams gp = requestVo.getGlobalParams();
35 |
36 | }
37 | }
38 |
39 | @Override
40 | public int getOrder() {
41 | return 10005;
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/handler/IpAddressHandler.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.handler;
2 |
3 |
4 | import com.zag.core.exception.SystemException;
5 | import com.zag.core.util.HttpServletHelper;
6 | import com.zag.support.web.BuildRequestHandler;
7 | import com.zag.support.web.assist.IPAddressAware;
8 | import com.zag.support.web.assist.IRequestVo;
9 |
10 | import javax.servlet.http.HttpServletRequest;
11 |
12 | /**
13 | * ip地址处理器,如果请求对象实现了IIPVo接口,将请求者ip写入该对象
14 | *
15 | * @author lei
16 | * @usage
17 | * @reviewer
18 | * @since 2017年8月16日
19 | */
20 | public class IpAddressHandler implements BuildRequestHandler {
21 |
22 | @Override
23 | public void handle(HttpServletRequest request, IRequestVo requestVo) throws SystemException {
24 | if (requestVo instanceof IPAddressAware) {
25 | IPAddressAware ipvo = (IPAddressAware) requestVo;
26 | ipvo.setIp(HttpServletHelper.getClientIP(request));
27 | }
28 | }
29 |
30 | @Override
31 | public int getOrder() {
32 | return 0;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/web-support/src/main/java/com/zag/support/web/handler/PostInitializationHandler.java:
--------------------------------------------------------------------------------
1 | package com.zag.support.web.handler;
2 |
3 | import com.zag.core.exception.SystemException;
4 | import com.zag.support.web.assist.IRequestVo;
5 | import com.zag.support.web.BuildRequestHandler;
6 | import com.zag.support.web.assist.PostInitialization;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 |
10 | /**
11 | * 后置初始化处理器,如果请求对象实现了PostInitialization接口,调用该对象的postInitializing()方法
12 | *
13 | * @author stone
14 | * @usage
15 | * @reviewer
16 | * @since 2017年8月16日
17 | */
18 | public class PostInitializationHandler implements BuildRequestHandler {
19 |
20 | @Override
21 | public void handle(HttpServletRequest request, IRequestVo requestVo) throws SystemException {
22 | if (requestVo instanceof PostInitialization) {
23 | ((PostInitialization) requestVo).postInitializing();
24 | }
25 | }
26 |
27 | @Override
28 | public int getOrder() {
29 | return 0;
30 | }
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------