├── .idea ├── compiler.xml ├── encodings.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── vcs.xml └── workspace.xml ├── README.md ├── core ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── zag │ └── core │ ├── ali │ └── oss │ │ ├── config │ │ └── OssConfig.java │ │ └── util │ │ └── OssUtil.java │ ├── annotation │ ├── ExcelColumn.java │ ├── ExcelFileName.java │ ├── ExcelSheetName.java │ └── ProjectOnly.java │ ├── asserts │ ├── BusinessAsserts.java │ └── SystemAsserts.java │ ├── baidu │ └── map │ │ ├── BaiduMapConfig.java │ │ └── BaiduMapUtil.java │ ├── codec │ ├── AesCryptographer.java │ ├── AesDecryptException.java │ ├── AesEncryptException.java │ ├── MD5Util.java │ └── PasswordUtil.java │ ├── enums │ ├── EnumerableNameAndValue.java │ ├── EnumerableNameAndValueAndDescription.java │ ├── EnumerableValue.java │ ├── Weeks.java │ └── converter │ │ ├── BaseEnumNameAndValueAndDescriptionConverter.java │ │ ├── BaseEnumValueConverter.java │ │ ├── BaseListEnumConverter.java │ │ └── EnumConverter.java │ ├── exception │ ├── BusinessException.java │ ├── ExceptionType.java │ ├── FunctionExceptions.java │ ├── RrbSystemException.java │ ├── SerializationException.java │ └── SystemException.java │ ├── logging │ ├── Loggers.java │ └── LogstashLog.java │ ├── model │ ├── Identifiable.java │ ├── String2LongTransformationFunction.java │ └── TransformationFunction.java │ ├── notification │ ├── AppType.java │ ├── NoticePlatform.java │ ├── Notification.java │ ├── NotificationPlatform.java │ ├── NotificationSendType.java │ ├── NotifyType.java │ ├── PushMessage.java │ └── TransmissionType.java │ ├── page │ ├── PageResult.java │ └── PageableRequest.java │ ├── property │ └── PropertyDescriptorExtends.java │ ├── register │ ├── MailUtil.java │ └── SMSUtil.java │ ├── spring │ ├── event │ │ ├── AbstractEventListener.java │ │ ├── AbstractMultipleEventListener.java │ │ ├── AsyncBaseEventWrapper.java │ │ ├── BaseEvent.java │ │ ├── BaseEventWrapper.java │ │ ├── EventMulticaster.java │ │ ├── EventPublisher.java │ │ └── SyncBaseEventWrapper.java │ ├── properties │ │ └── PropertiesResource.java │ └── transaction │ │ ├── SimpleJpaTransactionManager.java │ │ └── SimpleTransactionManager.java │ ├── util │ ├── CharUtil.java │ ├── DateUtil.java │ ├── DebugUtil.java │ ├── DistanceCalc.java │ ├── ExcelUtil.java │ ├── ExecutionUnit.java │ ├── FileUtil.java │ ├── GZIPRequestInterceptor.java │ ├── GZIPResponseInterceptor.java │ ├── HttpClientUtil.java │ ├── HttpServletHelper.java │ ├── HttpUtil.java │ ├── ImageUtils.java │ ├── JsonUtil.java │ ├── ListSortUtil.java │ ├── MapUtil.java │ ├── NumberUtil.java │ ├── ParamValidUtil.java │ ├── PingYinUtil.java │ ├── PinyinUtil.java │ ├── PriceUtil.java │ ├── ReflectionUtil.java │ ├── StringTool.java │ ├── StringUtil.java │ ├── SyncExecutionUnit.java │ ├── SyncUtil.java │ ├── Timers.java │ └── WebUtil.java │ └── web3_eth │ ├── CreatEthAccount.java │ ├── DecryptWallet.java │ ├── Erc20TokenClient.java │ ├── Erc20Withdraw.java │ ├── EthWithdraw.java │ └── Web3Config.java ├── dao ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── zag │ │ │ ├── bean │ │ │ └── PageControl.java │ │ │ ├── constant │ │ │ └── Constant.java │ │ │ ├── db │ │ │ ├── mysql │ │ │ │ ├── po │ │ │ │ │ └── web3 │ │ │ │ │ │ ├── ArticlePo.java │ │ │ │ │ │ ├── CurrencyAllPo.java │ │ │ │ │ │ ├── CurrencyPo.java │ │ │ │ │ │ ├── CurrencyUserPo.java │ │ │ │ │ │ ├── TransactionPo.java │ │ │ │ │ │ ├── UserAccountPo.java │ │ │ │ │ │ └── UserPo.java │ │ │ │ └── repository │ │ │ │ │ ├── ex │ │ │ │ │ ├── CurrencyAllDao.java │ │ │ │ │ ├── CurrencyAllRepository.java │ │ │ │ │ ├── CurrencyAllRepositoryImpl.java │ │ │ │ │ ├── CurrencyDao.java │ │ │ │ │ ├── CurrencyRepository.java │ │ │ │ │ ├── CurrencyRepositoryImpl.java │ │ │ │ │ ├── CurrencyUserDao.java │ │ │ │ │ ├── CurrencyUserRepository.java │ │ │ │ │ ├── CurrencyUserRepositoryImpl.java │ │ │ │ │ ├── TransactionDao.java │ │ │ │ │ ├── TransactionRepository.java │ │ │ │ │ ├── TransactionRepositoryImpl.java │ │ │ │ │ ├── UserAccountDao.java │ │ │ │ │ ├── UserAccountRepository.java │ │ │ │ │ ├── UserAccountRepositoryImpl.java │ │ │ │ │ ├── UserDao.java │ │ │ │ │ ├── UserRepository.java │ │ │ │ │ └── UserRepositoryImpl.java │ │ │ │ │ └── web3 │ │ │ │ │ ├── ArticleDao.java │ │ │ │ │ ├── ArticleRepository.java │ │ │ │ │ └── ArticleRepositoryImpl.java │ │ │ └── redis │ │ │ │ └── repository │ │ │ │ ├── CrudRedisDao.java │ │ │ │ └── SimpleDataRedisDao.java │ │ │ ├── enums │ │ │ ├── TransactionTypeEnums.java │ │ │ ├── UserExamineEnums.java │ │ │ └── UserTypeEnums.java │ │ │ ├── exception │ │ │ ├── Exceptions.java │ │ │ └── IllegalParameterException.java │ │ │ ├── transfrom │ │ │ ├── ex │ │ │ │ └── UserPoToFindRespVo.java │ │ │ └── web3 │ │ │ │ └── ArticlePoToSearchRespVo.java │ │ │ └── vo │ │ │ ├── BaseRequestVo.java │ │ │ ├── IdRequestVo.java │ │ │ ├── ex │ │ │ ├── account │ │ │ │ ├── Erc20WithdrawReqVo.java │ │ │ │ └── EthWithdrawReqVo.java │ │ │ └── user │ │ │ │ ├── req │ │ │ │ ├── UserAddMailReqVo.java │ │ │ │ ├── UserAddPhoneOrMailReqVo.java │ │ │ │ ├── UserAddPhoneReqVo.java │ │ │ │ ├── UserFindReqVo.java │ │ │ │ └── UserSend.java │ │ │ │ └── resp │ │ │ │ ├── JwtUser.java │ │ │ │ └── UserRespVo.java │ │ │ └── web3 │ │ │ ├── req │ │ │ ├── ArticleAddReqVo.java │ │ │ └── ArticleReqVo.java │ │ │ └── resp │ │ │ └── ArticleRespVo.java │ └── resources │ │ ├── META-INF │ │ └── persistence.xml │ │ ├── application-dao.xml │ │ ├── jpa-datasource.xml │ │ ├── mybatis-configuration.xml │ │ └── mybatis-datasource.xml │ └── test │ └── resources │ └── META-INF │ └── persistence.xml ├── jpa-support ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── zag │ └── support │ └── jpa │ ├── converter │ ├── AbstractListStringConverter.java │ ├── AbstractSetStringConverter.java │ ├── ListIntegerConverter.java │ ├── ListLongConverter.java │ ├── ListStringConverter.java │ ├── SetIntegerConverter.java │ ├── SetLongConverter.java │ └── SetStringConverter.java │ ├── po │ ├── BaseEntity.java │ ├── BaseEntityPKIncrement.java │ └── BasePo.java │ ├── repository │ ├── CommonJpaRepository.java │ ├── CommonJpaRepositoryBean.java │ ├── CommonRepositoryFactory.java │ └── CommonRepositoryFactoryBean.java │ └── util │ ├── CustomMysqlDialect.java │ └── UnderscoreNameCustomizer.java ├── pom.xml ├── redis-support ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── zag │ │ │ └── redis │ │ │ ├── JedisCurdCommonRedisDao.java │ │ │ ├── ShardedJedisCurdCommonRedisDao.java │ │ │ ├── annotation │ │ │ ├── FieldMapping.java │ │ │ ├── FieldSortedSet.java │ │ │ ├── MethodSortedSet.java │ │ │ ├── NotOverride.java │ │ │ ├── RedisWriteIgnore.java │ │ │ ├── Ro.java │ │ │ ├── RoLock.java │ │ │ └── RoSortedSet.java │ │ │ ├── api │ │ │ └── ComJedisRedis.java │ │ │ ├── bean │ │ │ ├── BaseRedisObject.java │ │ │ ├── BaseRo.java │ │ │ └── RedisObjMap.java │ │ │ ├── cluster │ │ │ └── JedisClusterPipeline.java │ │ │ ├── spi │ │ │ ├── JedisRedis.java │ │ │ └── ShardedJedisRedis.java │ │ │ ├── trans │ │ │ ├── BeanRegistry.java │ │ │ ├── ConvertorMatcher.java │ │ │ ├── ConvertorRegistry.java │ │ │ ├── DataItem.java │ │ │ ├── DataTransformer.java │ │ │ ├── RedisObject.java │ │ │ ├── Translator.java │ │ │ ├── ValueConvertor.java │ │ │ └── impl │ │ │ │ ├── DefaultBeanRegistry.java │ │ │ │ ├── DefaultConvertorRegistry.java │ │ │ │ ├── DefaultDataTransformer.java │ │ │ │ ├── DefaultTranslator.java │ │ │ │ ├── StringMap.java │ │ │ │ ├── TranslatorBuilder.java │ │ │ │ └── convertor │ │ │ │ ├── AbstractMultiValueConvertor.java │ │ │ │ ├── AbstractNumberConvertor.java │ │ │ │ ├── AbstractSimpleValueConvertor.java │ │ │ │ ├── BasicConvertor.java │ │ │ │ ├── BeanConvertor.java │ │ │ │ ├── EnumConvertor.java │ │ │ │ └── StringMapComvertor.java │ │ │ └── util │ │ │ ├── ExpressionUtil.java │ │ │ ├── FieldMappingAssist.java │ │ │ ├── JedisPoolLoad.java │ │ │ ├── RedisUtil.java │ │ │ ├── ShardedJedisPoolLoad.java │ │ │ └── SortedSetAssist.java │ └── resources │ │ ├── META-INF │ │ └── jedis.xml │ │ └── redis.xml │ └── test │ ├── java │ └── com │ │ └── rrb │ │ └── redis │ │ └── test │ │ ├── Item.java │ │ ├── TestItem.java │ │ ├── TestRedisDao.java │ │ └── TestRo.java │ └── resources │ ├── application-test-redis.xml │ ├── redis.properties │ └── redis.xml ├── rest ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── zag │ │ └── rest │ │ ├── base │ │ ├── Constants.java │ │ └── handler │ │ │ └── GlobalParamsHandler.java │ │ ├── controller │ │ ├── BaseController.java │ │ ├── ex │ │ │ ├── AccountController.java │ │ │ └── UserController.java │ │ └── web3j │ │ │ └── Web3jController.java │ │ ├── interceptor │ │ ├── AuthInterceptor.java │ │ ├── SignInterceptor.java │ │ └── TokenInterceptor.java │ │ └── util │ │ ├── JwtToken.java │ │ ├── JwtUnsign.java │ │ ├── NetUtils.java │ │ └── SignUtil.java │ ├── resources │ ├── logback.xml │ ├── properties │ │ ├── datasource.properties │ │ ├── oss_config.properties │ │ └── redis.properties │ └── spring │ │ ├── application-mvc.xml │ │ └── application-rest.xml │ └── webapp │ ├── WEB-INF │ ├── views │ │ └── index.jsp │ └── web.xml │ ├── error.jsp │ ├── favicon.ico │ └── index.jsp ├── service ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── zag │ │ │ ├── filter │ │ │ └── EncodingConvertFilter.java │ │ │ ├── service │ │ │ ├── AbstractBaseService.java │ │ │ ├── IdService.java │ │ │ ├── JwtSign.java │ │ │ ├── SpringContextService.java │ │ │ ├── SystemConfig.java │ │ │ ├── ex │ │ │ │ ├── account │ │ │ │ │ ├── AccountService.java │ │ │ │ │ ├── AccountServiceImpl.java │ │ │ │ │ ├── AccountTxlistService.java │ │ │ │ │ └── AccountTxlistServiceImpl.java │ │ │ │ └── user │ │ │ │ │ ├── UserService.java │ │ │ │ │ └── UserServiceImpl.java │ │ │ └── web3 │ │ │ │ ├── ArticleService.java │ │ │ │ └── ArticleServiceImpl.java │ │ │ ├── validation │ │ │ ├── CollectionSizeValidator.java │ │ │ ├── IdCardValidator.java │ │ │ ├── MobileValidator.java │ │ │ ├── NotBlankValidator.java │ │ │ ├── NotEmptyValidator.java │ │ │ ├── NotNullValidator.java │ │ │ ├── StringLengthValidator.java │ │ │ └── constraints │ │ │ │ ├── CollectionSizeCheck.java │ │ │ │ ├── IdCard.java │ │ │ │ ├── IsMobile.java │ │ │ │ ├── IsNotBlank.java │ │ │ │ ├── IsNotEmpty.java │ │ │ │ ├── IsNotNull.java │ │ │ │ └── StringLength.java │ │ │ └── view │ │ │ └── ExcelView.java │ └── resources │ │ ├── application-service.xml │ │ └── lib │ │ └── taobao-sdk-java-auto_1455552377940-20160607.jar │ └── test │ └── resources │ ├── application-service-test.xml │ ├── datasource.properties │ └── logback.xml └── web-support ├── .gitignore ├── pom.xml └── src └── main └── java └── com └── zag └── support └── web ├── BuildRequestHandler.java ├── LogFilter.java ├── assist ├── ClientType.java ├── ClientTypeAware.java ├── GlobalParams.java ├── GlobalParamsAware.java ├── IPAddressAware.java ├── IRequestVo.java └── PostInitialization.java ├── filter └── AccessControlFilter.java └── handler ├── ClientTypeHandler.java ├── IpAddressHandler.java ├── JSONResult.java └── PostInitializationHandler.java /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # exchange 2 | 钱包系统,中心钱包 可冷热钱包配合使用。 主钱包,为用户分配钱包等.... 3 | -------------------------------------------------------------------------------- /core/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/ali/oss/config/OssConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.zag.core.ali.oss.config; 5 | 6 | import java.util.ResourceBundle; 7 | 8 | /** 9 | * oss 属性配置类 10 | * @author stone 11 | * @date 2017年8月16日 12 | * @reviewer 13 | */ 14 | public interface OssConfig { 15 | 16 | ResourceBundle rb = ResourceBundle.getBundle("oss_config"); 17 | 18 | String endpoint = rb.getString("endpoint"); 19 | 20 | String accessKeyId = rb.getString("accessKeyId"); 21 | 22 | String accessKeySecret = rb.getString("accessKeySecret"); 23 | 24 | String defaultBucketName = rb.getString("bucketName"); 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/annotation/ExcelColumn.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 属性注解,标注excel导出字段 12 | * @author stone 13 | * @date 2017年11月15日 14 | */ 15 | @Target(ElementType.FIELD) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Inherited 18 | @Documented 19 | public @interface ExcelColumn { 20 | String name(); 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/annotation/ExcelFileName.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 属性注解,标注excel导出文件名前缀 12 | * @author stone 13 | * @date 2017年11月15日 14 | */ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Inherited 18 | @Documented 19 | public @interface ExcelFileName { 20 | String name(); 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/annotation/ExcelSheetName.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 属性注解,标注excel sheet名 12 | * @author stone 13 | * @date 2017年11月15日 14 | */ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Inherited 18 | @Documented 19 | public @interface ExcelSheetName { 20 | String name(); 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/annotation/ProjectOnly.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * 子工程自行扫描的组件 7 | * @author stone 8 | * @since 2017年10月20日 9 | * @usage 10 | * @reviewer 11 | */ 12 | @Component 13 | public @interface ProjectOnly { 14 | 15 | String value() default ""; 16 | } 17 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/baidu/map/BaiduMapConfig.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.baidu.map; 2 | 3 | /** 4 | * 百度地图配置 5 | * 6 | * @author stone 7 | * @date 2017年09月12日 8 | * @reviewer 9 | * @see 10 | */ 11 | public class BaiduMapConfig { 12 | 13 | public static String LOCATION_DECODE_URL = "http://api.map.baidu.com/geocoder/v2/?ak=%s&location=%s&output=json"; 14 | 15 | public static String BAIDU_MAP_AK = ""; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/baidu/map/BaiduMapUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.baidu.map; 2 | 3 | 4 | import com.zag.core.util.HttpClientUtil; 5 | 6 | /** 7 | * @author stone 8 | * @date 2017年09月12日 9 | * @reviewer 10 | * @see 11 | */ 12 | public class BaiduMapUtil { 13 | 14 | public static String getLocationDecode(Double latitude, Double longitude) { 15 | String requestUrl = String.format(BaiduMapConfig.LOCATION_DECODE_URL, BaiduMapConfig.BAIDU_MAP_AK, latitude + "," + longitude); 16 | return HttpClientUtil.doGet(requestUrl); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/codec/AesDecryptException.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.codec; 2 | 3 | /** 4 | * Created by stone on 11/16/15. 5 | */ 6 | public class AesDecryptException extends RuntimeException { 7 | 8 | private static final long serialVersionUID = -5917283691756557660L; 9 | 10 | public AesDecryptException() { 11 | } 12 | 13 | public AesDecryptException(String message) { 14 | super(message); 15 | } 16 | 17 | public AesDecryptException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public AesDecryptException(Throwable cause) { 22 | super(cause); 23 | } 24 | 25 | public AesDecryptException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 26 | super(message, cause, enableSuppression, writableStackTrace); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/codec/AesEncryptException.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.codec; 2 | 3 | /** 4 | * Created by stone on 11/16/15. 5 | */ 6 | public class AesEncryptException extends RuntimeException { 7 | 8 | private static final long serialVersionUID = -8831358639761706899L; 9 | 10 | public AesEncryptException() { 11 | } 12 | 13 | public AesEncryptException(String message) { 14 | super(message); 15 | } 16 | 17 | public AesEncryptException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public AesEncryptException(Throwable cause) { 22 | super(cause); 23 | } 24 | 25 | public AesEncryptException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 26 | super(message, cause, enableSuppression, writableStackTrace); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/codec/MD5Util.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.codec; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.security.MessageDigest; 5 | 6 | /** 7 | * MD5 8 | * Created @ClassName: MD5Util By @author stone 9 | * @date 2017年5月31日 上午11:46:56 10 | */ 11 | public class MD5Util 12 | { 13 | private static String ENCODING = "UTF-8"; 14 | 15 | /*** 16 | * MD5加码 生成32位大写md5码 17 | */ 18 | public static String string2MD5HexUpper(String inStr) 19 | { 20 | return string2MD5HexLower(inStr).toUpperCase(); 21 | } 22 | 23 | /*** 24 | * MD5加码 生成32位小写md5码 25 | */ 26 | public static String string2MD5HexLower(String inStr) 27 | { 28 | if(null == inStr || inStr.length() == 0) return ""; 29 | byte[] byteArray; 30 | try 31 | { 32 | byteArray = inStr.getBytes(ENCODING); 33 | } 34 | catch (UnsupportedEncodingException e) 35 | { 36 | return ""; 37 | } 38 | return byte2MD5HexLower(byteArray); 39 | } 40 | 41 | public static String byte2MD5HexUpper(byte[] byteArray) 42 | { 43 | return byte2MD5HexLower(byteArray).toUpperCase(); 44 | } 45 | 46 | public static String byte2MD5HexLower(byte[] byteArray) 47 | { 48 | MessageDigest md5 = null; 49 | try 50 | { 51 | md5 = MessageDigest.getInstance("MD5"); 52 | } 53 | catch (Exception e) 54 | { 55 | return ""; 56 | } 57 | 58 | byte[] md5Bytes = md5.digest(byteArray); 59 | StringBuffer hexValue = new StringBuffer(); 60 | for (int i = 0; i < md5Bytes.length; i++) 61 | { 62 | int val = ((int) md5Bytes[i]) & 0xff; 63 | if (val < 16) hexValue.append("0"); 64 | hexValue.append(Integer.toHexString(val)); 65 | } 66 | return hexValue.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/enums/EnumerableNameAndValue.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.enums; 2 | 3 | /** 4 | * 枚举上层接口扩展(描述信息) 只有枚举才应该继承本接口 5 | * 配合BaseEnumNameAndValueAndDescriptionConverter使用 6 | */ 7 | public interface EnumerableNameAndValue { 8 | 9 | String getName(); 10 | 11 | int getValue(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/enums/EnumerableNameAndValueAndDescription.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.enums; 2 | 3 | /** 4 | * 枚举上层接口扩展(描述信息) 只有枚举才应该继承本接口 5 | * 配合BaseEnumNameAndValueAndDescriptionConverter使用 6 | */ 7 | public interface EnumerableNameAndValueAndDescription { 8 | 9 | String getName(); 10 | 11 | int getValue(); 12 | 13 | String getDescription(); 14 | } 15 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/enums/EnumerableValue.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.enums; 2 | 3 | /** 4 | * 枚举int的上层接口,只有枚举才应该继承本接口 5 | * 配合BaseEnumValueConverter使用 6 | * 7 | * @author stone 2017年5月5日 8 | */ 9 | public interface EnumerableValue{ 10 | 11 | int getValue(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/enums/Weeks.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.enums; 2 | 3 | import java.util.Calendar; 4 | 5 | import com.zag.core.enums.converter.BaseListEnumConverter; 6 | import com.zag.core.enums.converter.BaseEnumValueConverter; 7 | 8 | /** 9 | * 星期枚举 10 | * @author stone 11 | * @since 2017年12月15日 12 | * @usage 13 | * @reviewer 14 | */ 15 | public enum Weeks implements EnumerableValue { 16 | 17 | MONDAY(Calendar.MONDAY,"星期一"), 18 | 19 | TUESDAY(Calendar.TUESDAY,"星期二"), 20 | 21 | WEDNESDAY(Calendar.WEDNESDAY,"星期三"), 22 | 23 | THURSDAY(Calendar.THURSDAY,"星期四"), 24 | 25 | FRIDAY(Calendar.FRIDAY,"星期五"), 26 | 27 | SATURDAY(Calendar.SATURDAY,"星期六"), 28 | 29 | SUNDAY(Calendar.SUNDAY, "星期日"); 30 | 31 | private int value; 32 | 33 | private String desc; 34 | 35 | @Override 36 | public int getValue() { 37 | return value; 38 | } 39 | 40 | public String getDesc() { 41 | return desc; 42 | } 43 | 44 | private Weeks(int value, String desc) { 45 | this.value = value; 46 | this.desc = desc; 47 | } 48 | 49 | public static Weeks getWeekByCalendarWeekInt(int week){ 50 | switch(week){ 51 | case Calendar.MONDAY: 52 | return Weeks.MONDAY; 53 | case Calendar.TUESDAY: 54 | return Weeks.TUESDAY; 55 | case Calendar.WEDNESDAY: 56 | return Weeks.WEDNESDAY; 57 | case Calendar.THURSDAY: 58 | return Weeks.THURSDAY; 59 | case Calendar.FRIDAY: 60 | return Weeks.FRIDAY; 61 | case Calendar.SATURDAY: 62 | return Weeks.SATURDAY; 63 | case Calendar.SUNDAY: 64 | return Weeks.SUNDAY; 65 | default: return null; 66 | } 67 | } 68 | 69 | public static class Converter extends BaseEnumValueConverter{} 70 | 71 | public static class ListConverter extends BaseListEnumConverter {} 72 | } 73 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/enums/converter/BaseEnumValueConverter.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.enums.converter; 2 | 3 | import java.lang.reflect.Method; 4 | import java.lang.reflect.ParameterizedType; 5 | 6 | import javax.persistence.AttributeConverter; 7 | 8 | import com.zag.core.exception.SystemException; 9 | import com.zag.core.enums.EnumerableValue; 10 | 11 | /** 12 | * 枚举属性转换器基类,将枚举的value转换为数据库的int值,使用方式见: 13 | * 14 | * @see com.rrb.core.common.model.user.SommelierStatus 15 | * 16 | * @param 17 | * 枚举类 18 | * @author stone 2017年5月6日 19 | */ 20 | public abstract class BaseEnumValueConverter implements AttributeConverter { 21 | 22 | private Class clz; 23 | private Method method; 24 | 25 | @Override 26 | public Integer convertToDatabaseColumn(EnumerableValue attribute) { 27 | return attribute == null ? null : attribute.getValue(); 28 | } 29 | 30 | @Override 31 | public E convertToEntityAttribute(Integer dbData) { 32 | return valueOf(dbData); 33 | } 34 | 35 | @SuppressWarnings("unchecked") 36 | public BaseEnumValueConverter() { 37 | try { 38 | clz = (Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]; 39 | method = clz.getMethod("values"); 40 | } catch (Exception e) { 41 | throw new SystemException("反射失败", e); 42 | } 43 | } 44 | 45 | /** 46 | * 根据value获取对应枚举 47 | * 48 | * @param value 49 | * @return 50 | */ 51 | @SuppressWarnings("unchecked") 52 | public E valueOf(Integer value) { 53 | if (value == null) return null; 54 | try { 55 | method = clz.getMethod("values"); 56 | for (E e : (E[]) method.invoke(null)) 57 | if (e.getValue() == value) 58 | return e; 59 | return null; 60 | } catch (Exception e) { 61 | throw new SystemException("反射失败", e); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/enums/converter/EnumConverter.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.enums.converter; 2 | 3 | import org.apache.commons.beanutils.converters.AbstractConverter; 4 | 5 | /** 6 | * 枚举类型转换 7 | * 8 | */ 9 | public class EnumConverter extends AbstractConverter { 10 | 11 | /** 枚举类型 */ 12 | private final Class enumClass; 13 | 14 | /** 15 | * @param enumClass 16 | * 枚举类型 17 | */ 18 | public EnumConverter(Class enumClass) { 19 | this(enumClass, null); 20 | } 21 | 22 | /** 23 | * @param enumClass 24 | * 枚举类型 25 | * @param defaultValue 26 | * 默认值 27 | */ 28 | public EnumConverter(Class enumClass, Object defaultValue) { 29 | super(defaultValue); 30 | this.enumClass = enumClass; 31 | } 32 | 33 | /** 34 | * 获取默认类型 35 | * 36 | * @return 默认类型 37 | */ 38 | @Override 39 | protected Class getDefaultType() { 40 | return this.enumClass; 41 | } 42 | 43 | /** 44 | * 转换为枚举对象 45 | * 46 | * @param type 47 | * 类型 48 | * @param value 49 | * 值 50 | * @return 枚举对象 51 | */ 52 | @SuppressWarnings({ "unchecked", "rawtypes" }) 53 | protected Object convertToType(Class type, Object value) { 54 | String stringValue = value.toString().trim(); 55 | return Enum.valueOf(type, stringValue); 56 | } 57 | 58 | /** 59 | * 转换为字符串 60 | * 61 | * @param value 62 | * 值 63 | * @return 字符串 64 | */ 65 | protected String convertToString(Object value) { 66 | return value.toString(); 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/exception/ExceptionType.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.exception; 2 | 3 | /** 4 | * 业务异常类型顶层接口,推荐使用枚举来进行实现 5 | * 6 | * @author stone 7 | * @date 2017年7月24日 8 | * @reviewer 9 | */ 10 | public interface ExceptionType { 11 | /** 12 | * 异常代码,为方便前端捕捉,推荐分段处理 13 | * @author stone 14 | * @date 2017年7月24日 15 | * @return 16 | */ 17 | int getCode(); 18 | 19 | /** 20 | * 异常描述信息 21 | * @author stone 22 | * @date 2017年7月24日 23 | * @return 24 | */ 25 | String getDescription(); 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/exception/FunctionExceptions.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.exception; 2 | 3 | /** 4 | * 枚举异常常量 5 | * @author stone 6 | * @date 2017年8月30日 7 | * @reviewer 8 | */ 9 | public interface FunctionExceptions { 10 | 11 | int SERVERERR = 600; 12 | 13 | enum System implements ExceptionType { 14 | OBJ_ISNULL (SERVERERR + 1, "对象不能为NULL"), 15 | ID_NOT_EXIST (SERVERERR + 2, "id不存在"), 16 | PARAMETER_ERROR (SERVERERR + 3, "参数异常"), 17 | MISSING_REQUIRED_PARAMS (SERVERERR + 4, "缺少必要参数"), 18 | TYPE_ISERR (SERVERERR + 5, "类型匹配错误"), 19 | ILLEGAL_OPERATION (SERVERERR + 6, "非法操作"), 20 | SYS_EXCEPTION (SERVERERR + 304, "")//直接提示给客户端的文字 21 | 22 | ; 23 | 24 | private int code; 25 | private String description; 26 | 27 | System(int code, String description) { 28 | this.code = code; 29 | this.description = description; 30 | } 31 | 32 | public int getCode() { 33 | return code; 34 | } 35 | 36 | public String getDescription() { 37 | return description; 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/exception/RrbSystemException.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.exception; 2 | 3 | /** 4 | * 所有需要捕获的异常的父类 5 | * 6 | * @author lei 7 | * @date 2017年10月31日 8 | * @reviewer 9 | * @see 10 | */ 11 | /** 12 | * 13 | * @author stone 14 | * @date 2017年7月28日 15 | * @reviewer 16 | */ 17 | public class RrbSystemException extends Exception{ 18 | 19 | private static final long serialVersionUID = 6994564415657921473L; 20 | 21 | public RrbSystemException() { 22 | super(); 23 | } 24 | 25 | public RrbSystemException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 26 | super(message, cause, enableSuppression, writableStackTrace); 27 | } 28 | 29 | public RrbSystemException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | public RrbSystemException(String message) { 34 | super(message); 35 | } 36 | 37 | public RrbSystemException(Throwable cause) { 38 | super(cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/exception/SerializationException.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.exception; 2 | 3 | public class SerializationException extends SystemException{ 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -6285871793188767403L; 9 | 10 | public SerializationException(String s) { 11 | super(s); 12 | } 13 | 14 | public SerializationException(String s, Throwable e) { 15 | super(s, e); 16 | } 17 | 18 | public SerializationException(Throwable e) { 19 | super(e); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/exception/SystemException.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.exception; 2 | 3 | import com.zag.core.asserts.SystemAsserts; 4 | 5 | /** 6 | * 所有与程序编码有关的异常统一抛出本类及其子类, 使用系统断言{@link SystemAsserts}来进行快速检查 7 | * 8 | * @author stone 9 | * @date 2017年7月24日 10 | * @see SystemAsserts 11 | * @reviewer 12 | */ 13 | public class SystemException extends RuntimeException { 14 | 15 | private static final long serialVersionUID = -6415147203498700978L; 16 | 17 | public SystemException() { 18 | super(); 19 | } 20 | 21 | public SystemException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 22 | super(message, cause, enableSuppression, writableStackTrace); 23 | } 24 | 25 | public SystemException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | 29 | public SystemException(String message) { 30 | super(message); 31 | } 32 | 33 | public SystemException(Throwable cause) { 34 | super(cause); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/model/Identifiable.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.model; 2 | 3 | public interface Identifiable { 4 | ID getId(); 5 | void setId(ID id); 6 | } 7 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/model/String2LongTransformationFunction.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.model; 2 | 3 | import com.google.common.base.Function; 4 | 5 | /** 6 | * 字符串->long值转换器,字符串必须为一个合法整形 7 | * @author stone 8 | * @since 2017年9月8日 9 | * @usage 10 | * @reviewer 11 | */ 12 | public class String2LongTransformationFunction implements Function{ 13 | 14 | @Override 15 | public Long apply(String input) { 16 | return Long.valueOf(input); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/model/TransformationFunction.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.model; 2 | 3 | import com.google.common.base.Function; 4 | 5 | public class TransformationFunction implements Function,Long>{ 6 | @Override 7 | public Long apply(Identifiable input) { 8 | return input.getId(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/notification/AppType.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.notification; 2 | 3 | /** 4 | * app类型 5 | * @author stone 6 | * @date 2017年08月08日 7 | * @reviewer 8 | * @see 9 | */ 10 | public enum AppType { 11 | RRB_C, //人人帮用户端App 12 | RRB_SHIP, //人人帮配送App 13 | RRB_B //人人帮商户端App 14 | } 15 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/notification/NoticePlatform.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.notification; 2 | 3 | /** 4 | * 推送平台描述 5 | * 6 | * @author stone 7 | * @date 2017年08月13日 8 | * @reviewer 9 | * @see 10 | */ 11 | public class NoticePlatform { 12 | 13 | public static final String MI = "mi"; 14 | 15 | public static final String IOS = "ios"; 16 | 17 | public static final String ANDROID = "android"; 18 | 19 | public static final String ANDROID_IOS = "android_ios"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/notification/NotificationPlatform.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.notification; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | 5 | /** 6 | * Created by stone on 6/8/17. 7 | */ 8 | public class NotificationPlatform { 9 | 10 | public static final String MI = "mi"; 11 | 12 | public static final String IOS = "ios"; 13 | 14 | public static final String ANDROID = "android"; 15 | 16 | public static final String ANDROID_IOS = "android_ios"; 17 | 18 | /** 19 | * 是否Android平台 20 | * @param plaftorm 21 | * @return 22 | */ 23 | public static Boolean isPlatformAndroid(String plaftorm) { 24 | plaftorm = StringUtils.trim(plaftorm); 25 | return StringUtils.equalsIgnoreCase(plaftorm, ANDROID) || StringUtils.equalsIgnoreCase(plaftorm, ANDROID_IOS); 26 | } 27 | 28 | /** 29 | * 是否Ios平台 30 | * @param plaftorm 31 | * @return 32 | */ 33 | public static Boolean isPlatformIos(String plaftorm) { 34 | plaftorm = StringUtils.trim(plaftorm); 35 | return StringUtils.equalsIgnoreCase(plaftorm, IOS) || StringUtils.equalsIgnoreCase(plaftorm, ANDROID_IOS); 36 | } 37 | 38 | public static void main(String[] args) { 39 | System.out.println(isPlatformAndroid("android")); 40 | System.out.println(isPlatformIos("ios")); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/notification/NotificationSendType.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.notification; 2 | 3 | /** 4 | * @author stone 5 | * @date 2017年08月13日 6 | * @reviewer 7 | * @see 8 | */ 9 | public enum NotificationSendType { 10 | INAPP, ALERT 11 | } 12 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/notification/NotifyType.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.notification; 2 | 3 | /** 4 | * @author stone 5 | * @date 2017年08月08日 6 | * @reviewer 7 | * @see 8 | */ 9 | public enum NotifyType { 10 | BROADCAST, //广播发送模式:对所有用户发送, 11 | GROUP, //对指定组发送 12 | P2P //对单个用户发送 13 | } 14 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/notification/TransmissionType.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.notification; 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 | * @date 2017年10月08日 12 | * @reviewer 13 | * @see 14 | */ 15 | public enum TransmissionType implements EnumerableValue { 16 | 17 | REDIRECT_URL(1), REDIRECT_APP_VIEW(2); 18 | 19 | private int value; 20 | 21 | TransmissionType(int value) { 22 | this.value = value; 23 | } 24 | 25 | @Override 26 | public int getValue() { 27 | return value; 28 | } 29 | 30 | public static class Converter extends BaseEnumValueConverter { 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/page/PageResult.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.page; 2 | 3 | import com.google.common.base.Preconditions; 4 | import java.io.Serializable; 5 | import java.util.List; 6 | 7 | /** 8 | * @author stone 9 | * @date 2016/12/22 10 | */ 11 | public class PageResult implements Serializable { 12 | 13 | private static final long serialVersionUID = 1048029186252168978L; 14 | 15 | private int currentPage = 0; 16 | 17 | private int size = 10; 18 | 19 | private List result; 20 | 21 | private int total; 22 | 23 | private boolean hasNext; 24 | 25 | public PageResult(int currentPage, int size, long total, List result) { 26 | Preconditions.checkArgument(result != null); 27 | this.currentPage = currentPage; 28 | this.size = size; 29 | this.result = result; 30 | this.total = (int) total; 31 | } 32 | 33 | //用于 dubbo 序列化,平时不要使用 34 | public PageResult() { 35 | } 36 | 37 | public List getResult() { 38 | return result; 39 | } 40 | 41 | public void setResult(List result) { 42 | this.result = result; 43 | } 44 | 45 | public int getCurrentPage() { 46 | return currentPage; 47 | } 48 | 49 | public void setCurrentPage(int currentPage) { 50 | this.currentPage = currentPage; 51 | } 52 | 53 | public int getSize() { 54 | return size; 55 | } 56 | 57 | public void setSize(int size) { 58 | this.size = size; 59 | } 60 | 61 | public int getTotal() { 62 | return total; 63 | } 64 | 65 | public void setTotal(int total) { 66 | this.total = total; 67 | } 68 | 69 | public boolean isHasNext() { 70 | return hasNext; 71 | } 72 | 73 | public void setHasNext(boolean hasNext) { 74 | this.hasNext = hasNext; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/page/PageableRequest.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.page; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author stone 7 | * @date 2016/12/19 8 | */ 9 | public class PageableRequest implements Serializable { 10 | 11 | private static final long serialVersionUID = 9084950607751477752L; 12 | 13 | private int page = 0; 14 | 15 | private int size = 10; 16 | 17 | public PageableRequest(int page, int size) { 18 | this.page = page; 19 | this.size = size; 20 | } 21 | 22 | public PageableRequest() { 23 | } 24 | 25 | public int getPage() { 26 | return page; 27 | } 28 | 29 | public void setPage(int page) { 30 | this.page = page; 31 | } 32 | 33 | public int getSize() { 34 | return size; 35 | } 36 | 37 | public void setSize(int size) { 38 | this.size = size; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/spring/event/AbstractEventListener.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.spring.event; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.ApplicationListener; 6 | 7 | import javax.annotation.PostConstruct; 8 | 9 | /** 10 | * 预先抽象的事件监听器基类 11 | * 12 | * @author stone 13 | * @date 2017年7月24日 14 | * @reviewer 15 | * @param 监听的事件类型 16 | */ 17 | public abstract class AbstractEventListener implements ApplicationListener { 18 | 19 | protected Logger logger = LoggerFactory.getLogger(getClass()); 20 | 21 | @Override 22 | // @Transactional 23 | public void onApplicationEvent(E event) { 24 | handleEvent(event); 25 | } 26 | 27 | @PostConstruct 28 | void init() { 29 | logger.debug("初始化事件监听器:{}", this.getClass().getName()); 30 | } 31 | 32 | protected abstract void handleEvent(E event); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/spring/event/AsyncBaseEventWrapper.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.spring.event; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | /** 6 | * 异步事件包装,配合{@link EventMulticaster}使用 7 | * @author stone 8 | * @since 2017年7月24日 9 | * @reviewer 10 | */ 11 | final class AsyncBaseEventWrapper extends ApplicationEvent implements BaseEventWrapper { 12 | 13 | private static final long serialVersionUID = -7071108383289433708L; 14 | 15 | private final BaseEvent event; 16 | 17 | /** 18 | * 19 | * @author stone 20 | * @date 2017年7月24日 21 | * @param event 22 | */ 23 | public AsyncBaseEventWrapper(BaseEvent event) { 24 | super(event.getSource()); 25 | this.event = event; 26 | } 27 | 28 | public BaseEvent getEvent() { 29 | return event; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/spring/event/BaseEvent.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.spring.event; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | public class BaseEvent extends ApplicationEvent{ 6 | 7 | private static final long serialVersionUID = 8809937598352484211L; 8 | 9 | public BaseEvent(Object source) { 10 | super(source); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/spring/event/BaseEventWrapper.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.spring.event; 2 | 3 | public interface BaseEventWrapper { 4 | BaseEvent getEvent(); 5 | } 6 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/spring/event/SyncBaseEventWrapper.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.spring.event; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | final class SyncBaseEventWrapper extends ApplicationEvent implements BaseEventWrapper { 6 | private static final long serialVersionUID = -5170108322289431707L; 7 | 8 | private final BaseEvent event; 9 | 10 | /** 11 | * 12 | * @author stone 13 | * @date 2017年7月24日 14 | * @param event 15 | */ 16 | public SyncBaseEventWrapper(BaseEvent event) { 17 | super(event.getSource()); 18 | this.event = event; 19 | } 20 | 21 | @Override 22 | public BaseEvent getEvent() { 23 | return event; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/spring/properties/PropertiesResource.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.spring.properties; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.util.Properties; 6 | 7 | import org.springframework.core.io.ByteArrayResource; 8 | 9 | import com.zag.core.exception.SystemException; 10 | 11 | public class PropertiesResource extends ByteArrayResource { 12 | 13 | public PropertiesResource(Properties properties) { 14 | super(prop2bytes(properties)); 15 | } 16 | 17 | private static byte[] prop2bytes(Properties properties) { 18 | ByteArrayOutputStream os = new ByteArrayOutputStream(); 19 | try { 20 | properties.store(os, null); 21 | } catch (IOException e) { 22 | throw new SystemException("properties convert to bytes failed.", e); 23 | } 24 | return os.toByteArray(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/DistanceCalc.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | /* 4 | * 计算距离 5 | */ 6 | @SuppressWarnings("unused") 7 | public class DistanceCalc { 8 | private static double PI = Math.PI; 9 | private static double TWOPI = Math.PI * 2; 10 | private static double DE2RA = 0.01745329252; 11 | private static double RA2DE = 57.2957795129; 12 | private static double ERAD = 6378.135; 13 | private static double ERADM = 6378135.0; 14 | private static double AVG_ERAD = 6371.0; 15 | private static double FLATTENING = 1.0 / 298.257223563; 16 | 17 | private static double EPS = 0.000000000005; 18 | private static double KM2MI = 0.621371; 19 | private static double GEOSTATIONARY_ALT = 35786.0; // km 20 | 21 | public static double distance(double lat1, double lon1, double lat2, double lon2) { 22 | lat1 = DE2RA * lat1; 23 | lon1 = -DE2RA * lon1; 24 | lat2 = DE2RA * lat2; 25 | lon2 = -DE2RA * lon2; 26 | 27 | double F = (lat1 + lat2) / 2.0; 28 | double G = (lat1 - lat2) / 2.0; 29 | double L = (lon1 - lon2) / 2.0; 30 | 31 | double sing = Math.sin(G); 32 | double cosl = Math.cos(L); 33 | double cosf = Math.cos(F); 34 | double sinl = Math.sin(L); 35 | double sinf = Math.sin(F); 36 | double cosg = Math.cos(G); 37 | 38 | double S = sing * sing * cosl * cosl + cosf * cosf * sinl * sinl; 39 | double C = cosg * cosg * cosl * cosl + sinf * sinf * sinl * sinl; 40 | double W = Math.atan2(Math.sqrt(S), Math.sqrt(C)); 41 | double R = Math.sqrt((S * C)) / W; 42 | double H1 = (3 * R - 1.0) / (2.0 * C); 43 | double H2 = (3 * R + 1.0) / (2.0 * S); 44 | double D = 2 * W * ERAD; 45 | return (D * (1 + FLATTENING * H1 * sinf * sinf * cosg * cosg - FLATTENING * H2 * cosf * cosf * sing * sing)) * 1000; 46 | } 47 | 48 | public static void main(String[] args) { 49 | System.out.println(distance(30.56903946, 104.06201405, 32.234233, 23.23123)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/ExcelUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import java.net.URLEncoder; 7 | 8 | public class ExcelUtil { 9 | public static String encodeFilename(String filename, HttpServletRequest request) { 10 | /** 11 | * 获取客户端浏览器和操作系统信息 12 | * 在IE浏览器中得到的是:User-Agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; Alexa Toolbar) 13 | * 在Firefox中得到的是:User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.7.10) Gecko/20050717 Firefox/1.0.6 14 | */ 15 | String agent = request.getHeader("USER-AGENT"); 16 | try { 17 | if ((agent != null) && (-1 != agent.indexOf("MSIE"))) { 18 | String newFileName = URLEncoder.encode(filename, "UTF-8"); 19 | newFileName = StringUtils.replace(newFileName, "+", "%20"); 20 | if (newFileName.length() > 150) { 21 | newFileName = new String(filename.getBytes("GB2312"), "ISO8859-1"); 22 | newFileName = StringUtils.replace(newFileName, " ", "%20"); 23 | } 24 | return newFileName; 25 | } 26 | return filename; 27 | } catch (Exception ex) { 28 | return filename; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/ExecutionUnit.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | /** 4 | * redis操作函数封装类 5 | * @author stone 6 | * @since 2017年8月8日 7 | * @usage 8 | * @reviewer 9 | */ 10 | public interface ExecutionUnit { 11 | void execute(); 12 | } 13 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/GZIPRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import org.apache.http.HttpException; 4 | import org.apache.http.HttpRequest; 5 | import org.apache.http.HttpRequestInterceptor; 6 | import org.apache.http.protocol.HttpContext; 7 | 8 | import java.io.IOException; 9 | 10 | public class GZIPRequestInterceptor implements HttpRequestInterceptor { 11 | 12 | @Override 13 | public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { 14 | if (!request.containsHeader("Accept-Encoding")) { 15 | request.addHeader("Accept-Encoding", "gzip"); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/GZIPResponseInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import org.apache.http.*; 4 | import org.apache.http.client.entity.GzipDecompressingEntity; 5 | import org.apache.http.protocol.HttpContext; 6 | 7 | import java.io.IOException; 8 | 9 | public class GZIPResponseInterceptor implements HttpResponseInterceptor { 10 | 11 | public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { 12 | 13 | HttpEntity entity = response.getEntity(); 14 | if (entity != null) { 15 | Header ceheader = entity.getContentEncoding(); 16 | if (ceheader != null) { 17 | HeaderElement[] codecs = ceheader.getElements(); 18 | for (int i = 0; i < codecs.length; i++) { 19 | if (codecs[i].getName().equalsIgnoreCase("gzip")) { 20 | response.setEntity(new GzipDecompressingEntity(response.getEntity())); 21 | return; 22 | } 23 | } 24 | } 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/HttpUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.net.HttpURLConnection; 7 | import java.net.URL; 8 | 9 | /** 10 | * @ProjectName: web3j-zag 11 | * @Package: com.zag.core.util 12 | * @ClassName: ${HttpUtil} 13 | * @Description: 程序中访问http数据接口 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/27 14:27 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/27 14:27 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | public class HttpUtil { 22 | /** 23 | * 程序中访问http数据接口 24 | */ 25 | public static String getURLContent(String urlStr) { 26 | /** 网络的url地址 */ 27 | URL url = null; 28 | /** http连接 */ 29 | HttpURLConnection httpConn = null; 30 | /**//** 输入流 */ 31 | BufferedReader in = null; 32 | StringBuffer sb = new StringBuffer(); 33 | try { 34 | url = new URL(urlStr); 35 | in = new BufferedReader(new InputStreamReader(url.openStream(), "GBK")); 36 | String str = null; 37 | while ((str = in.readLine()) != null) { 38 | sb.append(str); 39 | } 40 | } catch (Exception ex) { 41 | 42 | } finally { 43 | try { 44 | if (in != null) { 45 | in.close(); 46 | } 47 | } catch (IOException ex) { 48 | } 49 | } 50 | String result = sb.toString(); 51 | return result; 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/ListSortUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.List; 7 | 8 | public class ListSortUtil { 9 | /** 10 | * @author stone 11 | * @param targetList 目标排序List 12 | * @param sortField 排序字段(实体类属性名) String 13 | * @param sortMode 排序方式(asc or desc) 14 | */ 15 | @SuppressWarnings({ "unchecked", "rawtypes" }) 16 | public void sort(List targetList, final String sortField, final String sortMode) { 17 | 18 | Collections.sort(targetList, new Comparator() { 19 | @Override 20 | public int compare(Object obj1, Object obj2) { 21 | int retVal = 0; 22 | try { 23 | //首字母转大写 24 | String newStr=sortField.substring(0, 1).toUpperCase()+sortField.replaceFirst("\\w",""); 25 | String methodStr="get"+newStr; 26 | 27 | Method method1 = ((T)obj1).getClass().getMethod(methodStr, null); 28 | Method method2 = ((T)obj2).getClass().getMethod(methodStr, null); 29 | if (sortMode != null && "desc".equals(sortMode)) { 30 | retVal = method2.invoke(((T) obj2), null).toString().compareTo(method1.invoke(((T) obj1), null).toString()); // 倒序 31 | } else { 32 | retVal = method1.invoke(((T) obj1), null).toString().compareTo(method2.invoke(((T) obj2), null).toString()); // 正序 33 | } 34 | } catch (Exception e) { 35 | throw new RuntimeException(); 36 | } 37 | return retVal; 38 | } 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/MapUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public class MapUtil { 8 | 9 | /** 10 | * 将Oject对象转换成Map 11 | * @param obj 12 | * @return 13 | * @throws Exception 14 | */ 15 | public static Map objectToMap(Object obj) { 16 | try { 17 | if (obj == null) { 18 | return null; 19 | } 20 | Map map = new HashMap(); 21 | Field[] declaredFields = obj.getClass().getDeclaredFields(); 22 | for (Field field : declaredFields) { 23 | field.setAccessible(true); 24 | map.put(field.getName(), field.get(obj).toString()); 25 | } 26 | return map; 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | return null; 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/ParamValidUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import java.util.Set; 4 | 5 | import javax.validation.ConstraintViolation; 6 | import javax.validation.Validation; 7 | import javax.validation.Validator; 8 | 9 | import com.fasterxml.jackson.databind.DeserializationFeature; 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | /** 13 | * Rest接口工具 14 | * 15 | * @author lei 16 | * @date 2017年9月5日 17 | */ 18 | public class ParamValidUtil { 19 | 20 | private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper(); 21 | 22 | static { 23 | OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 24 | } 25 | 26 | private final static Validator VALIDATOR = 27 | Validation.buildDefaultValidatorFactory().getValidator(); 28 | 29 | /** 30 | * 校验参数 31 | * 32 | * @param obj 33 | * @param groups 34 | */ 35 | public static void validate(Object obj, Class... groups) throws RuntimeException { 36 | Set> constraintViolations = null; 37 | if (groups == null || groups.length == 0) { 38 | constraintViolations = VALIDATOR.validate(obj); 39 | } else { 40 | constraintViolations = VALIDATOR.validate(obj, groups); 41 | } 42 | 43 | if (constraintViolations != null && !constraintViolations.isEmpty()) { 44 | StringBuilder errorInfo = new StringBuilder(); 45 | for (ConstraintViolation cv : constraintViolations) { 46 | errorInfo.append(cv.getPropertyPath()).append(", ").append(cv.getMessage()) 47 | .append("; "); 48 | } 49 | throw new RuntimeException("业务参数约束出错:" + errorInfo); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/ReflectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | 6 | public class ReflectionUtil { 7 | 8 | @SuppressWarnings("unchecked") 9 | public static Class findGenericParameter(Class rawClz,int argIndex){ 10 | Type[] clz = null; 11 | Type superType = rawClz.getGenericSuperclass(); 12 | if(superType instanceof ParameterizedType){ 13 | ParameterizedType pt = (ParameterizedType)superType; 14 | clz = pt.getActualTypeArguments(); 15 | if(clz.length-1 > argIndex){ 16 | return (Class)clz[argIndex]; 17 | } 18 | } 19 | return null; 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/SyncExecutionUnit.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | /** 4 | * 同步操作执行单元,配合同步工具使用{@link SyncUtil} 5 | * @author stone 6 | * @date 2017年7月24日 7 | * @reviewer 8 | * @see com.SyncUtil.base.core.util.SyncUtils 9 | */ 10 | public interface SyncExecutionUnit { 11 | /** 12 | * 操作是否可执行,在进入同步体前判断一次,进入后判断一次 13 | * @author stone 14 | * @date 2017年7月24日 15 | * @return 16 | */ 17 | boolean isExecutable(); 18 | 19 | /** 20 | * 获取同步锁数据源,一般是id,数据源经过hash处理和取模运算后,拿到同步锁池中的锁,来进行同步操作 21 | * 根据锁池的大小,降低碰撞概率 22 | * @author stone 23 | * @date 2017年7月24日 24 | * @return 同步锁数据源,不能为null 25 | */ 26 | Object getSyncLockSource(); 27 | 28 | /** 29 | * 同步方法体,放置需要进行同步操作的逻辑 30 | * @author stone 31 | * @date 2017年7月24日 32 | * @return 33 | */ 34 | 35 | R execute(); 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/SyncUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | public class SyncUtil { 4 | private final int lockStoreSize; 5 | private final Object[] lockStore; 6 | 7 | /** 8 | * 创建指定大小的同步锁仓库 9 | * @author stone 10 | * @date 2017年7月24日 11 | * @param lockStoreSize 12 | */ 13 | public SyncUtil(int lockStoreSize){ 14 | this.lockStoreSize = lockStoreSize; 15 | lockStore = new Object[lockStoreSize]; 16 | for (int i = 0; i < lockStore.length; i++) { 17 | lockStore[i] = new Object(); 18 | } 19 | } 20 | /** 21 | * 默认构造器, 同步锁仓库大小为64 22 | * @author stone 23 | * @date 2017年7月24日 24 | */ 25 | public SyncUtil(){ 26 | this(64); 27 | } 28 | /** 29 | * 根据同步锁数据源,进行哈希和取模之后从仓库中获取对应的锁 30 | * @author stone 31 | * @date 2017年7月24日 32 | * @param source 33 | * @return 34 | */ 35 | private Object getSyncLock(Object source){ 36 | if(source==null) throw new RuntimeException("source 不能为null"); 37 | return lockStore[Math.abs(source.hashCode() % lockStoreSize)]; 38 | } 39 | 40 | /** 41 | * 执行方法体 42 | * @author stone 43 | * @date 2017年7月24日 44 | * @param unit 执行单元 45 | * @return 执行单元的execute方法返回的对象, 如果没有执行,返回null 46 | */ 47 | public T syncExecute(SyncExecutionUnit unit){ 48 | Object lock = getSyncLock(unit.getSyncLockSource()); 49 | if(unit.isExecutable()){ 50 | synchronized (lock) { 51 | if(unit.isExecutable()){ 52 | return unit.execute(); 53 | } 54 | } 55 | } 56 | return null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/util/Timers.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.util; 2 | 3 | import com.google.common.collect.Maps; 4 | import org.apache.commons.lang3.time.StopWatch; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * 性能计时器 12 | * @author stone 13 | * @since 2017年10月13日 14 | * @usage 15 | * @reviewer 16 | */ 17 | public class Timers{ 18 | private StopWatch sw = new StopWatch(); 19 | // private List time = Lists.newArrayList(); 20 | private Map map = Maps.newLinkedHashMap(); 21 | private long preTime = 0; 22 | private boolean enabled = true; 23 | private static final Logger logger = LoggerFactory.getLogger(Timers.class); 24 | private Timers(){ 25 | } 26 | 27 | public static Timers createAndBegin(boolean enabled){ 28 | Timers timers = new Timers(); 29 | timers.enabled = enabled; 30 | if(!enabled)return timers; 31 | timers.sw.start(); 32 | return timers; 33 | } 34 | public void record(String tag){ 35 | if(!enabled)return; 36 | sw.split(); 37 | long splitTime = sw.getSplitTime(); 38 | long sub = splitTime - preTime; 39 | // time.add(sub); 40 | map.put(tag, sub); 41 | preTime=splitTime; 42 | } 43 | private Map out(){ 44 | if(!enabled)return map; 45 | if (!sw.isStopped()) { 46 | sw.stop(); 47 | } 48 | long all = sw.getTime(); 49 | map.put("总计用时", all); 50 | return map; 51 | } 52 | public void print(String tag){ 53 | if(!enabled)return; 54 | logger.debug(tag +" {}", this.out()); 55 | } 56 | } -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/web3_eth/CreatEthAccount.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.web3_eth; 2 | 3 | import org.web3j.crypto.WalletUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | /** 9 | * @ProjectName: web3j-zag 10 | * @Package: com.zag.core.web3_eth 11 | * @ClassName: ${创建eth账号} 12 | * @Description: java类作用描述 13 | * @Author: 作者姓名 14 | * @CreateDate: 2018/8/23 10:51 15 | * @UpdateUser: Neil.Zhou 16 | * @UpdateDate: 2018/8/23 10:51 17 | * @UpdateRemark: The modified content 18 | * @Version: 1.0 19 | */ 20 | public class CreatEthAccount { 21 | 22 | /** 23 | * 创建钱包 24 | * @param path //保存路径 25 | * @param password //密码 26 | * */ 27 | public static String saveEthAccount(String path, String password) { 28 | String wallet_file=""; 29 | try { 30 | File tempFile = new File(path); 31 | if (!tempFile.exists()) { 32 | tempFile.mkdirs(); 33 | } 34 | wallet_file = WalletUtils.generateLightNewWalletFile(password, tempFile); 35 | System.out.println("钱包输出:"+wallet_file); 36 | 37 | } catch (IOException e) { 38 | e.printStackTrace(); 39 | } catch (Exception e) { 40 | e.printStackTrace(); 41 | } finally { 42 | // 完毕,关闭所有链接 43 | } 44 | return wallet_file; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core/src/main/java/com/zag/core/web3_eth/Web3Config.java: -------------------------------------------------------------------------------- 1 | package com.zag.core.web3_eth; 2 | 3 | import org.web3j.protocol.Web3j; 4 | import org.web3j.protocol.http.HttpService; 5 | 6 | /** 7 | * @ProjectName: web3j-zag 8 | * @Package: com.zag.core.web3_eth 9 | * @ClassName: ${web3Config} 10 | * @Description: infura 配置 无账号自己申请 11 | * @Author: skyhuihui 12 | * @CreateDate: 2018/8/23 17:04 13 | * @UpdateUser: Neil.Zhou 14 | * @UpdateDate: 2018/8/23 17:04 15 | * @UpdateRemark: The modified content 16 | * @Version: 1.0 17 | */ 18 | public class Web3Config { 19 | //infura环境 你自己的infura 20 | public static String web3j = ; 21 | //热钱包本地地址(提币)(收款) 22 | public static String hotWallet = "E:\\Wallet\\0\\eth\\eth.json"; 23 | // 冷钱包账户地址 (收款) 24 | public static String coldWallet = ""; 25 | } 26 | -------------------------------------------------------------------------------- /dao/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/constant/Constant.java: -------------------------------------------------------------------------------- 1 | package com.zag.constant; 2 | 3 | /** 4 | * Constant 5 | * 6 | * @author lei 7 | * @date 2017年11月30日 8 | * @reviewer 9 | * @see 10 | */ 11 | public class Constant { 12 | 13 | public static final int DEFAULT_PAGE = 0; 14 | 15 | public static final int DEFAULT_PAGE_SIZE = 10; 16 | 17 | /** 18 | * 平台统一配送费用key 19 | */ 20 | public static final String PLATFORM_FREIGHT_KEY = "global:freight"; 21 | 22 | /** 23 | * 默认平台统一配送费 24 | */ 25 | public static final int DEFAULT_PLATFORM_FREIGHT = 3; 26 | } 27 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/po/web3/ArticlePo.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.po.web3; 2 | 3 | import com.zag.support.jpa.po.BaseEntity; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Table; 8 | 9 | /** 10 | * @ProjectName: web3-zag 11 | * @Package: com.zag.db.mysql.po 12 | * @ClassName: ArticlePo 13 | * @Description: Article表 字段:id,用户地址,数据,时间 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/2 16:17 16 | * @UpdateUser: skyhuihui 17 | * @UpdateDate: 2018/8/2 16:17 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | @Entity 22 | @Table(name = "web3_article") 23 | public class ArticlePo extends BaseEntity { 24 | 25 | @Column(columnDefinition = "varchar(50) COMMENT '账户'") 26 | private String account; 27 | 28 | @Column(columnDefinition = "varchar(1000) COMMENT '信息'") 29 | private String content; 30 | 31 | @Column(columnDefinition = "varchar(20) COMMENT '时间戳'") 32 | private String time; 33 | 34 | public String getAccount() { 35 | return account; 36 | } 37 | 38 | public void setAccount(String account) { 39 | this.account = account; 40 | } 41 | 42 | public String getContent() { 43 | return content; 44 | } 45 | 46 | public void setContent(String content) { 47 | this.content = content; 48 | } 49 | 50 | public String getTime() { 51 | return time; 52 | } 53 | 54 | public void setTime(String time) { 55 | this.time = time; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/po/web3/CurrencyPo.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.po.web3; 2 | 3 | import com.zag.support.jpa.po.BaseEntity; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Table; 8 | 9 | /** 10 | * @ProjectName: web3j-zag 11 | * @Package: com.zag.db.mysql.po.web3 12 | * @ClassName: ${currency} 13 | * @Description: 交易所支持的 核心钱包 (eth,btc , usdt ,eos......) 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/27 18:03 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/27 18:03 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | @Entity 22 | @Table(name = "ex_currency") 23 | public class CurrencyPo extends BaseEntity { 24 | 25 | @Column(columnDefinition = "varchar(20) COMMENT '币种名称'") 26 | private String name; 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/po/web3/CurrencyUserPo.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.po.web3; 2 | 3 | import com.zag.support.jpa.po.BaseEntity; 4 | 5 | import javax.persistence.*; 6 | 7 | /** 8 | * @ProjectName: web3j-zag 9 | * @Package: com.zag.db.mysql.po.web3 10 | * @ClassName: ${CurrencyUserPo} 11 | * @Description: 用户对应的币 所拥有数量 12 | * @Author: skyhuihui 13 | * @CreateDate: 2018/8/27 18:17 14 | * @UpdateUser: Neil.Zhou 15 | * @UpdateDate: 2018/8/27 18:17 16 | * @UpdateRemark: The modified content 17 | * @Version: 1.0 18 | */ 19 | @Entity 20 | @Table(name = "ex_currency_user") 21 | public class CurrencyUserPo extends BaseEntity { 22 | 23 | /** 币种 */ 24 | @ManyToOne 25 | @JoinColumn(name = "currencyall_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) 26 | private CurrencyAllPo currencyAllPo; 27 | 28 | /** 所属用户 */ 29 | @ManyToOne 30 | @JoinColumn(name = "user_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) 31 | private UserPo userPo; 32 | 33 | private Double amont; 34 | 35 | public CurrencyAllPo getCurrencyAllPo() { 36 | return currencyAllPo; 37 | } 38 | 39 | public void setCurrencyAllPo(CurrencyAllPo currencyAllPo) { 40 | this.currencyAllPo = currencyAllPo; 41 | } 42 | 43 | public UserPo getUserPo() { 44 | return userPo; 45 | } 46 | 47 | public void setUserPo(UserPo userPo) { 48 | this.userPo = userPo; 49 | } 50 | 51 | public Double getAmont() { 52 | return amont; 53 | } 54 | 55 | public void setAmont(Double amont) { 56 | this.amont = amont; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/po/web3/UserAccountPo.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.po.web3; 2 | 3 | import com.zag.support.jpa.po.BaseEntity; 4 | 5 | import javax.persistence.*; 6 | 7 | /** 8 | * @ProjectName: web3j-zag 9 | * @Package: com.zag.db.mysql.po.web3 10 | * @ClassName: ${UserAccountPo} 11 | * @Description: 用户区块链账户表 12 | * @Author: skyhuihui 13 | * @CreateDate: 2018/8/23 11:04 14 | * @UpdateUser: Neil.Zhou 15 | * @UpdateDate: 2018/8/23 11:04 16 | * @UpdateRemark: The modified content 17 | * @Version: 1.0 18 | */ 19 | @Entity 20 | @Table(name = "ex_user_account") 21 | public class UserAccountPo extends BaseEntity { 22 | 23 | /** 用户 */ 24 | @OneToOne 25 | @JoinColumn(name = "user_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) 26 | private UserPo userPo; 27 | 28 | @Column(columnDefinition = "varchar(500) COMMENT '以太坊本地账户地址'") 29 | private String ethAccount; 30 | 31 | @Column(columnDefinition = "varchar(500) COMMENT '以太坊地址'") 32 | private String address; 33 | 34 | public UserPo getUserPo() { 35 | return userPo; 36 | } 37 | 38 | public void setUserPo(UserPo userPo) { 39 | this.userPo = userPo; 40 | } 41 | 42 | public String getEthAccount() { 43 | return ethAccount; 44 | } 45 | 46 | public void setEthAccount(String ethAccount) { 47 | this.ethAccount = ethAccount; 48 | } 49 | 50 | public String getAddress() { 51 | return address; 52 | } 53 | 54 | public void setAddress(String address) { 55 | this.address = address; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyAllDao.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.db.mysql.repository.ex 8 | * @ClassName: ${TYPE_NAME} 9 | * @Description: java类作用描述 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/28 10:16 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/28 10:16 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | @NoRepositoryBean 18 | public interface CurrencyAllDao { 19 | } 20 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyAllRepository.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.CurrencyAllPo; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @ProjectName: web3j-zag 9 | * @Package: com.zag.db.mysql.repository.ex 10 | * @ClassName: ${TYPE_NAME} 11 | * @Description: java类作用描述 12 | * @Author: skyhuihui 13 | * @CreateDate: 2018/8/28 10:17 14 | * @UpdateUser: Neil.Zhou 15 | * @UpdateDate: 2018/8/28 10:17 16 | * @UpdateRemark: The modified content 17 | * @Version: 1.0 18 | */ 19 | @Repository 20 | public interface CurrencyAllRepository extends JpaRepository, CurrencyAllDao{ 21 | 22 | CurrencyAllPo findByaddress(String address); 23 | } 24 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyAllRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.CurrencyAllPo; 4 | import com.zag.support.jpa.repository.CommonJpaRepositoryBean; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import javax.persistence.EntityManager; 8 | 9 | /** 10 | * @ProjectName: web3j-zag 11 | * @Package: com.zag.db.mysql.repository.ex 12 | * @ClassName: ${TYPE_NAME} 13 | * @Description: java类作用描述 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/28 10:17 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/28 10:17 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | public class CurrencyAllRepositoryImpl extends CommonJpaRepositoryBean implements CurrencyAllDao{ 22 | @Autowired 23 | public CurrencyAllRepositoryImpl(EntityManager em) { 24 | super(CurrencyAllPo.class, em); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyDao.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.db.mysql.repository.ex 8 | * @ClassName: ${TYPE_NAME} 9 | * @Description: java类作用描述 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/28 10:10 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/28 10:10 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | @NoRepositoryBean 18 | public interface CurrencyDao { 19 | } 20 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyRepository.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.CurrencyPo; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @ProjectName: web3j-zag 9 | * @Package: com.zag.db.mysql.repository.ex 10 | * @ClassName: ${TYPE_NAME} 11 | * @Description: 核心钱包(币种) repository 12 | * @Author: skyhuihui 13 | * @CreateDate: 2018/8/28 10:11 14 | * @UpdateUser: Neil.Zhou 15 | * @UpdateDate: 2018/8/28 10:11 16 | * @UpdateRemark: The modified content 17 | * @Version: 1.0 18 | */ 19 | @Repository 20 | public interface CurrencyRepository extends JpaRepository, CurrencyDao{ 21 | } 22 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.CurrencyPo; 4 | import com.zag.db.mysql.po.web3.UserAccountPo; 5 | import com.zag.support.jpa.repository.CommonJpaRepositoryBean; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import javax.persistence.EntityManager; 9 | 10 | /** 11 | * @ProjectName: web3j-zag 12 | * @Package: com.zag.db.mysql.repository.ex 13 | * @ClassName: ${TYPE_NAME} 14 | * @Description: java类作用描述 15 | * @Author: skyhuihui 16 | * @CreateDate: 2018/8/28 10:11 17 | * @UpdateUser: Neil.Zhou 18 | * @UpdateDate: 2018/8/28 10:11 19 | * @UpdateRemark: The modified content 20 | * @Version: 1.0 21 | */ 22 | public class CurrencyRepositoryImpl extends CommonJpaRepositoryBean implements CurrencyDao{ 23 | @Autowired 24 | public CurrencyRepositoryImpl(EntityManager em) { 25 | super(CurrencyPo.class, em); 26 | } 27 | } -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyUserDao.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.db.mysql.repository.ex 8 | * @ClassName: ${TYPE_NAME} 9 | * @Description: java类作用描述 10 | * @Author: 作者姓名 11 | * @CreateDate: 2018/8/28 10:19 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/28 10:19 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | @NoRepositoryBean 18 | public interface CurrencyUserDao { 19 | } 20 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyUserRepository.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.CurrencyAllPo; 4 | import com.zag.db.mysql.po.web3.CurrencyUserPo; 5 | import com.zag.db.mysql.po.web3.UserPo; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.stereotype.Repository; 8 | 9 | 10 | /** 11 | * @ProjectName: web3j-zag 12 | * @Package: com.zag.db.mysql.repository.ex 13 | * @ClassName: ${TYPE_NAME} 14 | * @Description: java类作用描述 15 | * @Author: 作者姓名 16 | * @CreateDate: 2018/8/28 10:20 17 | * @UpdateUser: Neil.Zhou 18 | * @UpdateDate: 2018/8/28 10:20 19 | * @UpdateRemark: The modified content 20 | * @Version: 1.0 21 | */ 22 | @Repository 23 | public interface CurrencyUserRepository extends JpaRepository, CurrencyUserDao{ 24 | 25 | CurrencyUserPo findByUserPoAndCurrencyAllPo(UserPo userPo, CurrencyAllPo currencyAllPo); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/CurrencyUserRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.CurrencyUserPo; 4 | import com.zag.db.mysql.po.web3.UserAccountPo; 5 | import com.zag.support.jpa.repository.CommonJpaRepositoryBean; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import javax.persistence.EntityManager; 9 | 10 | /** 11 | * @ProjectName: web3j-zag 12 | * @Package: com.zag.db.mysql.repository.ex 13 | * @ClassName: ${TYPE_NAME} 14 | * @Description: java类作用描述 15 | * @Author: 作者姓名 16 | * @CreateDate: 2018/8/28 10:20 17 | * @UpdateUser: Neil.Zhou 18 | * @UpdateDate: 2018/8/28 10:20 19 | * @UpdateRemark: The modified content 20 | * @Version: 1.0 21 | */ 22 | public class CurrencyUserRepositoryImpl extends CommonJpaRepositoryBean implements CurrencyUserDao{ 23 | @Autowired 24 | public CurrencyUserRepositoryImpl(EntityManager em) { 25 | super(CurrencyUserPo.class, em); 26 | } 27 | } -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/TransactionDao.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.db.mysql.repository.ex 8 | * @ClassName: ${TYPE_NAME} 9 | * @Description: java类作用描述 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/28 10:39 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/28 10:39 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | @NoRepositoryBean 18 | public interface TransactionDao { 19 | } 20 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/TransactionRepository.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.TransactionPo; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @ProjectName: web3j-zag 9 | * @Package: com.zag.db.mysql.repository.ex 10 | * @ClassName: ${TYPE_NAME} 11 | * @Description: 交易记录 12 | * @Author: skyhuihui 13 | * @CreateDate: 2018/8/28 10:39 14 | * @UpdateUser: Neil.Zhou 15 | * @UpdateDate: 2018/8/28 10:39 16 | * @UpdateRemark: The modified content 17 | * @Version: 1.0 18 | */ 19 | @Repository 20 | public interface TransactionRepository extends JpaRepository, TransactionDao{ 21 | } 22 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/TransactionRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.TransactionPo; 4 | import com.zag.support.jpa.repository.CommonJpaRepositoryBean; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import javax.persistence.EntityManager; 8 | 9 | /** 10 | * @ProjectName: web3j-zag 11 | * @Package: com.zag.db.mysql.repository.ex 12 | * @ClassName: ${TYPE_NAME} 13 | * @Description: java类作用描述 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/28 10:39 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/28 10:39 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | public class TransactionRepositoryImpl extends CommonJpaRepositoryBean implements TransactionDao{ 22 | @Autowired 23 | public TransactionRepositoryImpl(EntityManager em) { 24 | super(TransactionPo.class, em); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/UserAccountDao.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.db.mysql.repository.ex 8 | * @ClassName: ${UserAccountDao} 9 | * @Description: dao 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/23 11:38 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/23 11:38 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | @NoRepositoryBean 18 | public interface UserAccountDao { 19 | } 20 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/UserAccountRepository.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.UserAccountPo; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.query.Param; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * @ProjectName: web3j-zag 11 | * @Package: com.zag.db.mysql.repository.ex 12 | * @ClassName: ${TYPE_NAME} 13 | * @Description: repository 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/23 11:38 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/23 11:38 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | @Repository 22 | public interface UserAccountRepository extends JpaRepository, UserAccountDao{ 23 | 24 | @Query(value = "SELECT accountPo FROM UserAccountPo accountPo WHERE accountPo.userPo.id = :userId") 25 | UserAccountPo findByUserPo(@Param("userId") Long userId); 26 | 27 | UserAccountPo findByAddress(String address); 28 | } 29 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/UserAccountRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.UserAccountPo; 4 | import com.zag.support.jpa.repository.CommonJpaRepositoryBean; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import javax.persistence.EntityManager; 8 | 9 | /** 10 | * @ProjectName: web3j-zag 11 | * @Package: com.zag.db.mysql.repository.ex 12 | * @ClassName: ${TYPE_NAME} 13 | * @Description: java类作用描述 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/23 11:39 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/23 11:39 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | public class UserAccountRepositoryImpl extends CommonJpaRepositoryBean implements UserAccountDao{ 22 | @Autowired 23 | public UserAccountRepositoryImpl(EntityManager em) { 24 | super(UserAccountPo.class, em); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.db.mysql.repository.ex 8 | * @ClassName: UserDao 9 | * @Description: java类作用描述 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/8 10:31 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/8 10:31 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | @NoRepositoryBean 18 | public interface UserDao { 19 | } 20 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/ex/UserRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.ex; 2 | 3 | import com.zag.db.mysql.po.web3.UserPo; 4 | import com.zag.support.jpa.repository.CommonJpaRepositoryBean; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import javax.persistence.EntityManager; 8 | 9 | /** 10 | * @ProjectName: web3j-zag 11 | * @Package: com.zag.db.mysql.repository.ex 12 | * @ClassName: UserRepositoryImpl 13 | * @Description: UserRepositoryImpl 实体 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/8 10:32 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/8 10:32 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | public class UserRepositoryImpl extends CommonJpaRepositoryBean implements UserDao { 22 | @Autowired 23 | public UserRepositoryImpl(EntityManager em) { 24 | super(UserPo.class, em); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/web3/ArticleDao.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.web3; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | 5 | /** 6 | * @ProjectName: web3-zag 7 | * @Package: com.zag.db.mysql.repository.web3 8 | * @ClassName: ArticleDao 9 | * @Description: java类作用描述 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/2 16:34 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/2 16:34 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | @NoRepositoryBean 18 | public interface ArticleDao { 19 | } 20 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/web3/ArticleRepository.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.web3; 2 | 3 | import com.zag.db.mysql.po.web3.ArticlePo; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @ProjectName: web3-zag 12 | * @Package: com.zag.db.mysql.repository.web3 13 | * @ClassName: ArticleRepository 14 | * @Description: java类作用描述 15 | * @Author: skyhuihui 16 | * @CreateDate: 2018/8/2 16:34 17 | * @UpdateUser: skyhuihui 18 | * @UpdateDate: 2018/8/2 16:34 19 | * @UpdateRemark: The modified content 20 | * @Version: 1.0 21 | */ 22 | @Repository 23 | public interface ArticleRepository extends JpaRepository, ArticleDao { 24 | 25 | List findAllByAccount(String account, Pageable pageable); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/mysql/repository/web3/ArticleRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.mysql.repository.web3; 2 | 3 | import com.zag.db.mysql.po.web3.ArticlePo; 4 | import com.zag.support.jpa.repository.CommonJpaRepositoryBean; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import javax.persistence.EntityManager; 8 | 9 | /** 10 | * @ProjectName: web3-zag 11 | * @Package: com.zag.db.mysql.repository.web3 12 | * @ClassName: ArticleRepositoryImpl 13 | * @Description: java类作用描述 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/2 16:35 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/2 16:35 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | public class ArticleRepositoryImpl extends CommonJpaRepositoryBean implements ArticleDao { 22 | 23 | @Autowired 24 | public ArticleRepositoryImpl(EntityManager em) { 25 | super(ArticlePo.class, em); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/db/redis/repository/SimpleDataRedisDao.java: -------------------------------------------------------------------------------- 1 | package com.zag.db.redis.repository; 2 | 3 | import com.zag.redis.spi.ShardedJedisRedis; 4 | import com.zag.redis.util.RedisUtil; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.stereotype.Repository; 8 | import redis.clients.jedis.ShardedJedis; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Collection; 12 | import java.util.Collections; 13 | import java.util.List; 14 | 15 | 16 | /** 17 | * 用于操作简单数据的redis-dao,例如序列号池,token等 18 | * @author stone 19 | * @since 2017年8月20日 20 | * @usage 21 | * @reviewer 22 | */ 23 | @Repository 24 | public class SimpleDataRedisDao extends ShardedJedisRedis { 25 | protected Logger logger = LoggerFactory.getLogger(this.getClass()); 26 | protected String getset(String key, String newVal) { 27 | try (ShardedJedis jedis = shardedJedisPool.getResource()) { 28 | return jedis.getSet(key, newVal); 29 | } 30 | } 31 | protected List bytesSet2LongList(Collection set){ 32 | if(set == null)return Collections.emptyList(); 33 | List result = new ArrayList<>(set.size()); 34 | for (byte[] bs : set) { 35 | result.add(RedisUtil.byteArrayToLong(bs)); 36 | } 37 | return result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/enums/TransactionTypeEnums.java: -------------------------------------------------------------------------------- 1 | package com.zag.enums; 2 | 3 | import com.zag.core.enums.EnumerableValue; 4 | import com.zag.core.enums.converter.BaseEnumValueConverter; 5 | 6 | /** 7 | * @ProjectName: web3j-zag 8 | * @Package: com.zag.enums 9 | * @ClassName: ${TYPE_NAME} 10 | * @Description: 余额变化类型(交易类型) 11 | * @Author: skyhuihui 12 | * @CreateDate: 2018/8/28 10:31 13 | * @UpdateUser: Neil.Zhou 14 | * @UpdateDate: 2018/8/28 10:31 15 | * @UpdateRemark: The modified content 16 | * @Version: 1.0 17 | */ 18 | public enum TransactionTypeEnums implements EnumerableValue { 19 | /** 20 | * 提现 21 | */ 22 | Withdraw(0), 23 | 24 | /** 25 | * 充值 26 | */ 27 | Recharge(1), 28 | 29 | /** 30 | * 转账 31 | */ 32 | Transfer(2); 33 | 34 | private int value; 35 | 36 | 37 | TransactionTypeEnums(int value) { 38 | this.value = value; 39 | } 40 | 41 | @Override 42 | public int getValue() { 43 | return value; 44 | } 45 | 46 | public static class Converter extends BaseEnumValueConverter { 47 | } 48 | } -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/enums/UserExamineEnums.java: -------------------------------------------------------------------------------- 1 | package com.zag.enums; 2 | 3 | import com.zag.core.enums.EnumerableValue; 4 | import com.zag.core.enums.converter.BaseEnumValueConverter; 5 | 6 | /** 7 | * @ProjectName: web3j-zag 8 | * @Package: com.zag.enums 9 | * @ClassName: ${UserExamineEnums} 10 | * @Description: 用户审核 11 | * @Author: skyhuihui 12 | * @CreateDate: 2018/8/8 11:20 13 | * @UpdateUser: Neil.Zhou 14 | * @UpdateDate: 2018/8/8 11:20 15 | * @UpdateRemark: The modified content 16 | * @Version: 1.0 17 | */ 18 | public enum UserExamineEnums implements EnumerableValue { 19 | /** 20 | * 未审核 21 | */ 22 | Unaudited(0), 23 | /** 24 | * 审核中 25 | */ 26 | Audit(1), 27 | /** 28 | * 审核成功 29 | */ 30 | AuditSuccess(2), 31 | /** 32 | * 审核失败 33 | */ 34 | AuditFailure(3); 35 | 36 | private int value; 37 | 38 | 39 | UserExamineEnums(int value) { 40 | this.value = value; 41 | } 42 | 43 | @Override 44 | public int getValue() { 45 | return value; 46 | } 47 | 48 | public static class Converter extends BaseEnumValueConverter { 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/enums/UserTypeEnums.java: -------------------------------------------------------------------------------- 1 | package com.zag.enums; 2 | 3 | import com.zag.core.enums.EnumerableValue; 4 | import com.zag.core.enums.converter.BaseEnumValueConverter; 5 | 6 | /** 7 | * @ProjectName: web3j-zag 8 | * @Package: com.zag.enums 9 | * @ClassName: ${TYPE_NAME} 10 | * @Description: java类作用描述 11 | * @Author: 作者姓名 12 | * @CreateDate: 2018/8/8 10:09 13 | * @UpdateUser: Neil.Zhou 14 | * @UpdateDate: 2018/8/8 10:09 15 | * @UpdateRemark: The modified content 16 | * @Version: 1.0 17 | */ 18 | public enum UserTypeEnums implements EnumerableValue { 19 | 20 | /** 21 | * 禁用 22 | */ 23 | DISABLE(0), 24 | /** 25 | * 启用 26 | */ 27 | ENABLE(1); 28 | 29 | private int value; 30 | 31 | 32 | UserTypeEnums(int value) { 33 | this.value = value; 34 | } 35 | 36 | @Override 37 | public int getValue() { 38 | return value; 39 | } 40 | 41 | public boolean isEnable() { 42 | return this.value == ENABLE.getValue(); 43 | } 44 | 45 | public static class Converter extends BaseEnumValueConverter { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/exception/IllegalParameterException.java: -------------------------------------------------------------------------------- 1 | package com.zag.exception; 2 | 3 | import com.zag.core.exception.BusinessException; 4 | import com.zag.core.exception.ExceptionType; 5 | 6 | /** 7 | * 参数不合法 8 | * 9 | * @author lei 10 | * @date 2017年05月02日 11 | * @reviewer 12 | * @see 13 | */ 14 | public class IllegalParameterException extends BusinessException { 15 | private static final long serialVersionUID = 6191216245233367781L; 16 | 17 | private static final ExceptionType exceptionType = Exceptions.Global.ILLEGAL_PARAMETER_ERROR; 18 | 19 | public IllegalParameterException(String message) { 20 | super(exceptionType, message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/transfrom/ex/UserPoToFindRespVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.transfrom.ex; 2 | 3 | import com.google.common.base.Function; 4 | import com.zag.db.mysql.po.web3.UserPo; 5 | import com.zag.vo.ex.user.resp.UserRespVo; 6 | 7 | /** 8 | * @ProjectName: web3j-zag 9 | * @Package: com.zag.transfrom.ex 10 | * @ClassName: ${UserPoToFindRespVo} 11 | * @Description: PoTo 12 | * @Author: skyhuihui 13 | * @CreateDate: 2018/8/8 11:37 14 | * @UpdateUser: Neil.Zhou 15 | * @UpdateDate: 2018/8/8 11:37 16 | * @UpdateRemark: The modified content 17 | * @Version: 1.0 18 | */ 19 | public class UserPoToFindRespVo implements Function { 20 | 21 | @Override 22 | public UserRespVo apply(UserPo userPo) { 23 | UserRespVo userRespVo = new UserRespVo(); 24 | userRespVo.setId(userPo.getId()); 25 | userRespVo.setArea(userPo.getArea()); 26 | userRespVo.setHandIdCard(userPo.getHandIdCard()); 27 | userRespVo.setIdCardBack(userPo.getIdCardBack()); 28 | userRespVo.setIdCardFront(userPo.getIdCardFront()); 29 | userRespVo.setMailbox(userPo.getMailbox()); 30 | userRespVo.setName(userPo.getName()); 31 | userRespVo.setPhone(userPo.getPhone()); 32 | userRespVo.setType(userPo.getType()); 33 | userRespVo.setUserExamineEnums(userPo.getUserExamineEnums()); 34 | return userRespVo; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/transfrom/web3/ArticlePoToSearchRespVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.transfrom.web3; 2 | 3 | import com.google.common.base.Function; 4 | import com.zag.db.mysql.po.web3.ArticlePo; 5 | import com.zag.vo.web3.resp.ArticleRespVo; 6 | 7 | import javax.annotation.Nullable; 8 | 9 | /** 10 | * @ProjectName: web3-zag 11 | * @Package: com.zag.transfrom.web3 12 | * @ClassName: ${TYPE_NAME} 13 | * @Description: java类作用描述 14 | * @Author: 作者姓名 15 | * @CreateDate: 2018/8/2 17:04 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/2 17:04 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | public class ArticlePoToSearchRespVo implements Function { 22 | 23 | @Override 24 | public ArticleRespVo apply(ArticlePo article) { 25 | ArticleRespVo articleRespVo = new ArticleRespVo(); 26 | articleRespVo.setId(article.getId()); 27 | articleRespVo.setAccount(article.getAccount()); 28 | articleRespVo.setContent(article.getContent()); 29 | articleRespVo.setTime(article.getTime()); 30 | return articleRespVo; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/IdRequestVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | /** 6 | * @author stone 7 | * @usage 8 | * @reviewer 9 | * @since 2017年8月6日 10 | */ 11 | public class IdRequestVo extends BaseRequestVo { 12 | private static final long serialVersionUID = 8145491923251311486L; 13 | 14 | @NotNull(message = "id不能为null") 15 | private Long id; 16 | 17 | public IdRequestVo() { 18 | } 19 | 20 | public IdRequestVo(Long id) { 21 | this(); 22 | this.id = id; 23 | } 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/ex/account/Erc20WithdrawReqVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.ex.account; 2 | 3 | import com.zag.vo.BaseRequestVo; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.vo.ex.account 8 | * @ClassName: ${TYPE_NAME} 9 | * @Description: java类作用描述 10 | * @Author: 作者姓名 11 | * @CreateDate: 2018/8/24 15:52 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/24 15:52 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | public class Erc20WithdrawReqVo extends BaseRequestVo { 18 | 19 | public String account; 20 | 21 | public Double amount; 22 | 23 | public String contractAddress; 24 | 25 | public String getContractAddress() { 26 | return contractAddress; 27 | } 28 | 29 | public void setContractAddress(String contractAddress) { 30 | this.contractAddress = contractAddress; 31 | } 32 | 33 | public Double getAmount() { 34 | return amount; 35 | } 36 | 37 | public void setAmount(Double amount) { 38 | this.amount = amount; 39 | } 40 | 41 | public String getAccount() { 42 | return account; 43 | } 44 | 45 | public void setAccount(String account) { 46 | this.account = account; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/ex/account/EthWithdrawReqVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.ex.account; 2 | 3 | import com.zag.vo.BaseRequestVo; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.vo.ex.account 8 | * @ClassName: ${WithdrawReqVo} 9 | * @Description: 用户提币请求数据 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/24 15:37 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/24 15:37 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | public class EthWithdrawReqVo extends BaseRequestVo { 18 | 19 | public String account; 20 | 21 | public Double amount; 22 | 23 | public Double getAmount() { 24 | return amount; 25 | } 26 | 27 | public void setAmount(Double amount) { 28 | this.amount = amount; 29 | } 30 | 31 | public String getAccount() { 32 | return account; 33 | } 34 | 35 | public void setAccount(String account) { 36 | this.account = account; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/ex/user/req/UserAddMailReqVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.ex.user.req; 2 | 3 | import com.zag.enums.UserTypeEnums; 4 | import com.zag.vo.BaseRequestVo; 5 | 6 | import javax.persistence.Column; 7 | 8 | /** 9 | * @ProjectName: web3j-zag 10 | * @Package: com.zag.vo.ex.user.req 11 | * @ClassName: ${UserAddReqVo} 12 | * @Description: 添加新用户(用户注册 邮箱) 13 | * @Author: skyhuihui 14 | * @CreateDate: 2018/8/8 10:43 15 | * @UpdateUser: Neil.Zhou 16 | * @UpdateDate: 2018/8/8 10:43 17 | * @UpdateRemark: The modified content 18 | * @Version: 1.0 19 | */ 20 | public class UserAddMailReqVo extends BaseRequestVo { 21 | 22 | //邮箱号 23 | private String mailbox; 24 | 25 | //姓名 26 | private String name; 27 | 28 | //密码 29 | private String password; 30 | 31 | //验证码 32 | private String code; 33 | 34 | public String getCode() { 35 | return code; 36 | } 37 | 38 | public void setCode(String code) { 39 | this.code = code; 40 | } 41 | 42 | public String getMailbox() { 43 | return mailbox; 44 | } 45 | 46 | public void setMailbox(String mailbox) { 47 | this.mailbox = mailbox; 48 | } 49 | 50 | @Override 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | @Override 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | public String getPassword() { 61 | return password; 62 | } 63 | 64 | public void setPassword(String password) { 65 | this.password = password; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/ex/user/req/UserAddPhoneOrMailReqVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.ex.user.req; 2 | 3 | import com.zag.vo.BaseRequestVo; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.vo.ex.user.req 8 | * @ClassName: ${TYPE_NAME} 9 | * @Description: java类作用描述 10 | * @Author: 作者姓名 11 | * @CreateDate: 2018/8/9 15:50 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/9 15:50 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | public class UserAddPhoneOrMailReqVo extends BaseRequestVo { 18 | 19 | private String phone; 20 | 21 | private String mail; 22 | 23 | private String code; 24 | 25 | public String getCode() { 26 | return code; 27 | } 28 | 29 | public void setCode(String code) { 30 | this.code = code; 31 | } 32 | 33 | public String getPhone() { 34 | return phone; 35 | } 36 | 37 | public void setPhone(String phone) { 38 | this.phone = phone; 39 | } 40 | 41 | public String getMail() { 42 | return mail; 43 | } 44 | 45 | public void setMail(String mail) { 46 | this.mail = mail; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/ex/user/req/UserAddPhoneReqVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.ex.user.req; 2 | 3 | import com.zag.vo.BaseRequestVo; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.vo.ex.user.req 8 | * @ClassName: ${UserAddPhoneReqVo} 9 | * @Description: 手机号注册 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/8 10:49 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/8 10:49 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | public class UserAddPhoneReqVo extends BaseRequestVo { 18 | 19 | //手机号 20 | private String phone; 21 | 22 | //姓名 23 | private String name; 24 | 25 | //密码 26 | private String password; 27 | 28 | //地区 (+86) 29 | private Integer area; 30 | 31 | //验证码 32 | private String code; 33 | 34 | public String getCode() { 35 | return code; 36 | } 37 | 38 | public void setCode(String code) { 39 | this.code = code; 40 | } 41 | 42 | public String getPhone() { 43 | return phone; 44 | } 45 | 46 | public void setPhone(String phone) { 47 | this.phone = phone; 48 | } 49 | 50 | @Override 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | @Override 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | public String getPassword() { 61 | return password; 62 | } 63 | 64 | public void setPassword(String password) { 65 | this.password = password; 66 | } 67 | 68 | public Integer getArea() { 69 | return area; 70 | } 71 | 72 | public void setArea(Integer area) { 73 | this.area = area; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/ex/user/req/UserFindReqVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.ex.user.req; 2 | 3 | import com.zag.vo.BaseRequestVo; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.vo.ex.user.req 8 | * @ClassName: ${UserFindReqVo} 9 | * @Description: 手机号/邮箱登录 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/8 11:12 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/8 11:12 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | public class UserFindReqVo extends BaseRequestVo { 18 | 19 | //邮箱号 20 | private String mailbox; 21 | 22 | //手机号 23 | private String phone; 24 | 25 | //密码 26 | private String password; 27 | 28 | public String getMailbox() { 29 | return mailbox; 30 | } 31 | 32 | public void setMailbox(String mailbox) { 33 | this.mailbox = mailbox; 34 | } 35 | 36 | public String getPhone() { 37 | return phone; 38 | } 39 | 40 | public void setPhone(String phone) { 41 | this.phone = phone; 42 | } 43 | 44 | public String getPassword() { 45 | return password; 46 | } 47 | 48 | public void setPassword(String password) { 49 | this.password = password; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/ex/user/req/UserSend.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.ex.user.req; 2 | 3 | import com.zag.vo.BaseRequestVo; 4 | 5 | /** 6 | * @ProjectName: web3j-zag 7 | * @Package: com.zag.vo.ex.user.req 8 | * @ClassName: ${UserSend} 9 | * @Description: 用户填写手机号/邮箱 获的验证码 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/8 17:14 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/8 17:14 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | public class UserSend extends BaseRequestVo { 18 | 19 | private String phone; 20 | 21 | private String mail; 22 | 23 | public String getPhone() { 24 | return phone; 25 | } 26 | 27 | public void setPhone(String phone) { 28 | this.phone = phone; 29 | } 30 | 31 | public String getMail() { 32 | return mail; 33 | } 34 | 35 | public void setMail(String mail) { 36 | this.mail = mail; 37 | } 38 | } -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/ex/user/resp/JwtUser.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.ex.user.resp; 2 | 3 | import com.zag.enums.UserExamineEnums; 4 | import com.zag.enums.UserTypeEnums; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @ProjectName: web3j-zag 10 | * @Package: com.zag.vo.ex.user.resp 11 | * @ClassName: ${JwtUser} 12 | * @Description: jwt参数 13 | * @Author: skyhuihui 14 | * @CreateDate: 2018/8/9 11:26 15 | * @UpdateUser: Neil.Zhou 16 | * @UpdateDate: 2018/8/9 11:26 17 | * @UpdateRemark: The modified content 18 | * @Version: 1.0 19 | */ 20 | public class JwtUser implements Serializable { 21 | 22 | public JwtUser() { 23 | } 24 | 25 | public JwtUser(Long id, String name, UserTypeEnums type, UserExamineEnums userExamineEnums) { 26 | this.id = id; 27 | this.name = name; 28 | this.type = type; 29 | this.userExamineEnums = userExamineEnums; 30 | } 31 | 32 | private Long id; 33 | 34 | private String name; 35 | 36 | private UserTypeEnums type; 37 | 38 | private UserExamineEnums userExamineEnums; 39 | 40 | public Long getId() { 41 | return id; 42 | } 43 | 44 | public void setId(Long id) { 45 | this.id = id; 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public void setName(String name) { 53 | this.name = name; 54 | } 55 | 56 | public UserTypeEnums getType() { 57 | return type; 58 | } 59 | 60 | public void setType(UserTypeEnums type) { 61 | this.type = type; 62 | } 63 | 64 | public UserExamineEnums getUserExamineEnums() { 65 | return userExamineEnums; 66 | } 67 | 68 | public void setUserExamineEnums(UserExamineEnums userExamineEnums) { 69 | this.userExamineEnums = userExamineEnums; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/web3/req/ArticleAddReqVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.web3.req; 2 | 3 | import com.zag.constant.Constant; 4 | import com.zag.vo.BaseRequestVo; 5 | 6 | /** 7 | * @ProjectName: web3-zag 8 | * @Package: com.zag.vo.web3.req 9 | * @ClassName: ${TYPE_NAME} 10 | * @Description: java类作用描述 11 | * @Author: 作者姓名 12 | * @CreateDate: 2018/8/3 15:27 13 | * @UpdateUser: Neil.Zhou 14 | * @UpdateDate: 2018/8/3 15:27 15 | * @UpdateRemark: The modified content 16 | * @Version: 1.0 17 | */ 18 | public class ArticleAddReqVo extends BaseRequestVo { 19 | //账户 20 | private String account; 21 | 22 | //信息 23 | private String content; 24 | 25 | //time 26 | private String time; 27 | 28 | //页码 29 | private Integer page= Constant.DEFAULT_PAGE; 30 | 31 | //数位 32 | private Integer size = Constant.DEFAULT_PAGE_SIZE; 33 | 34 | public String getAccount() { 35 | return account; 36 | } 37 | 38 | public void setAccount(String account) { 39 | this.account = account; 40 | } 41 | 42 | public String getContent() { 43 | return content; 44 | } 45 | 46 | public void setContent(String content) { 47 | this.content = content; 48 | } 49 | 50 | public String getTime() { 51 | return time; 52 | } 53 | 54 | public void setTime(String time) { 55 | this.time = time; 56 | } 57 | 58 | public Integer getPage() { 59 | return page; 60 | } 61 | 62 | public void setPage(Integer page) { 63 | this.page = page; 64 | } 65 | 66 | public Integer getSize() { 67 | return size; 68 | } 69 | 70 | public void setSize(Integer size) { 71 | this.size = size; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/web3/req/ArticleReqVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.web3.req; 2 | 3 | import com.zag.constant.Constant; 4 | import com.zag.vo.BaseRequestVo; 5 | 6 | /** 7 | * @ProjectName: web3-zag 8 | * @Package: com.zag.vo.web3.req 9 | * @ClassName: ${TYPE_NAME} 10 | * @Description: java类作用描述 11 | * @Author: skyhuihui 12 | * @CreateDate: 2018/8/2 16:53 13 | * @UpdateUser: Neil.Zhou 14 | * @UpdateDate: 2018/8/2 16:53 15 | * @UpdateRemark: The modified content 16 | * @Version: 1.0 17 | */ 18 | public class ArticleReqVo extends BaseRequestVo { 19 | 20 | //账户 21 | private String account = "0x00"; 22 | 23 | //页码 24 | private Integer page= Constant.DEFAULT_PAGE; 25 | 26 | //数位 27 | private Integer size = Constant.DEFAULT_PAGE_SIZE; 28 | 29 | public String getAccount() { 30 | return account; 31 | } 32 | 33 | public void setAccount(String account) { 34 | this.account = account; 35 | } 36 | 37 | public Integer getPage() { 38 | return page; 39 | } 40 | 41 | public void setPage(Integer page) { 42 | this.page = page; 43 | } 44 | 45 | public Integer getSize() { 46 | return size; 47 | } 48 | 49 | public void setSize(Integer size) { 50 | this.size = size; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /dao/src/main/java/com/zag/vo/web3/resp/ArticleRespVo.java: -------------------------------------------------------------------------------- 1 | package com.zag.vo.web3.resp; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @ProjectName: web3-zag 7 | * @Package: com.zag.vo.web3.resp 8 | * @ClassName: ArticleRespVo 9 | * @Description: java类作用描述 10 | * @Author: skyhuihui 11 | * @CreateDate: 2018/8/2 16:58 12 | * @UpdateUser: Neil.Zhou 13 | * @UpdateDate: 2018/8/2 16:58 14 | * @UpdateRemark: The modified content 15 | * @Version: 1.0 16 | */ 17 | public class ArticleRespVo implements Serializable { 18 | 19 | private Long id; 20 | 21 | private String account; 22 | 23 | private String content; 24 | 25 | private String time; 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getAccount() { 36 | return account; 37 | } 38 | 39 | public void setAccount(String account) { 40 | this.account = account; 41 | } 42 | 43 | public String getContent() { 44 | return content; 45 | } 46 | 47 | public void setContent(String content) { 48 | this.content = content; 49 | } 50 | 51 | public String getTime() { 52 | return time; 53 | } 54 | 55 | public void setTime(String time) { 56 | this.time = time; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /dao/src/main/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.hibernate.ejb.HibernatePersistence 5 | 6 | -------------------------------------------------------------------------------- /dao/src/main/resources/application-dao.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /dao/src/main/resources/mybatis-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /dao/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.hibernate.ejb.HibernatePersistence 5 | 6 | -------------------------------------------------------------------------------- /jpa-support/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /jpa-support/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.zag 9 | zag 10 | 1.0.0 11 | 12 | 13 | jpa-support 14 | jar 15 | 16 | 17 | 18 | com.zag 19 | core 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.data 29 | spring-data-jpa 30 | 31 | 32 | org.hibernate 33 | hibernate-entitymanager 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/converter/ListIntegerConverter.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.converter; 2 | 3 | /* 4 | * List -> "1,2,3,4" 5 | * String(e.g. "1,2,3,4" ) -> List 6 | * 7 | */ 8 | public class ListIntegerConverter extends AbstractListStringConverter { 9 | 10 | @Override 11 | protected Integer string2Element(String data) { 12 | return Integer.valueOf(data); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/converter/ListLongConverter.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.converter; 2 | 3 | /* 4 | * List -> "1,2,3,4" 5 | * String(e.g. "1,2,3,4" ) -> List 6 | * 7 | */ 8 | public class ListLongConverter extends AbstractListStringConverter { 9 | public static final ListLongConverter INSTANCE = new ListLongConverter(); 10 | private static final long serialVersionUID = -858560178317910071L; 11 | 12 | @Override 13 | protected Long string2Element(String data) { 14 | return Long.valueOf(data); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/converter/ListStringConverter.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.converter; 2 | 3 | /** 4 | * 将实体中的List和数据库中的text相互转换 <----最初的作用
5 | * 按照固定的规则(逗号分隔值)将list和string做相互转化 <----现在的作用
6 | * 弊端: 7 | * 在实体中写List,并使用本转换器转换的属性,无法用@Modifying和@Query单独写jpql更新,只能查出原有对象再更新 8 | * 9 | * @author lei 2017年5月5日 10 | */ 11 | public class ListStringConverter extends AbstractListStringConverter { 12 | public static final ListStringConverter INSTANCE = new ListStringConverter(); 13 | private static final long serialVersionUID = -3786469606707789991L; 14 | 15 | public ListStringConverter() { 16 | } 17 | 18 | @Override 19 | protected String string2Element(String data) { 20 | return data; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/converter/SetIntegerConverter.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.converter; 2 | 3 | /* 4 | * Set -> "1,2,3,4" 5 | * String(e.g. "1,2,3,4" ) -> Set 6 | * 7 | */ 8 | public class SetIntegerConverter extends AbstractSetStringConverter { 9 | 10 | @Override 11 | protected Integer string2Element(String data) { 12 | return Integer.valueOf(data); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/converter/SetLongConverter.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.converter; 2 | 3 | /** 4 | * @author lei 5 | * @date 2016/12/23 6 | */ 7 | public class SetLongConverter extends AbstractSetStringConverter { 8 | @Override 9 | protected Long string2Element(String data) { 10 | return Long.valueOf(data); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/converter/SetStringConverter.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.converter; 2 | 3 | /** 4 | * 将set或string按照固定规则相互转换 5 | * 6 | * @author yikun.mao 7 | * @usage 8 | * @reviewer 9 | * @since 2017年8月23日 10 | */ 11 | public class SetStringConverter extends AbstractSetStringConverter { 12 | public static final SetStringConverter INSTANCE = new SetStringConverter(); 13 | 14 | public SetStringConverter() { 15 | } 16 | 17 | @Override 18 | protected String string2Element(String data) { 19 | return data; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/po/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.po; 2 | 3 | import org.hibernate.annotations.UpdateTimestamp; 4 | 5 | import javax.persistence.Id; 6 | import javax.persistence.MappedSuperclass; 7 | import java.io.Serializable; 8 | import java.sql.Timestamp; 9 | 10 | /** 11 | * po基类,id不会自动生成 12 | * 13 | * @author lei 14 | * @usage 15 | * @reviewer 16 | * @since 2017年8月2日 17 | */ 18 | @SuppressWarnings("serial") 19 | @MappedSuperclass 20 | public class BaseEntity extends BasePo implements Serializable { 21 | 22 | @Id 23 | private Long id; 24 | 25 | private Timestamp createTimestamp = new Timestamp(System.currentTimeMillis()); 26 | 27 | @UpdateTimestamp 28 | private Timestamp updateTimestamp; 29 | 30 | @Override 31 | public Long getId() { 32 | return id; 33 | } 34 | 35 | @Override 36 | public void setId(Long id) { 37 | this.id = id; 38 | } 39 | 40 | public Timestamp getCreateTimestamp() { 41 | return createTimestamp; 42 | } 43 | 44 | public void setCreateTimestamp(Timestamp createTime) { 45 | this.createTimestamp = createTime; 46 | } 47 | 48 | public Timestamp getUpdateTimestamp() { 49 | return updateTimestamp; 50 | } 51 | 52 | public void setUpdateTimestamp(Timestamp updateTime) { 53 | this.updateTimestamp = updateTime; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return this.getClass().getName() + "#" + this.getId(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/po/BaseEntityPKIncrement.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.po; 2 | 3 | import org.hibernate.annotations.UpdateTimestamp; 4 | 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import javax.persistence.MappedSuperclass; 8 | import java.sql.Timestamp; 9 | 10 | /** 11 | * @author lei 12 | */ 13 | @SuppressWarnings("serial") 14 | @MappedSuperclass 15 | public class BaseEntityPKIncrement extends BasePo { 16 | 17 | @Id 18 | @GeneratedValue 19 | private Long id; 20 | 21 | private Timestamp createTimestamp = new Timestamp(System.currentTimeMillis()); 22 | 23 | @UpdateTimestamp 24 | private Timestamp updateTimestamp; 25 | 26 | @Override 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | @Override 32 | public void setId(Long id) { 33 | this.id = id; 34 | } 35 | 36 | public Timestamp getCreateTimestamp() { 37 | return createTimestamp; 38 | } 39 | 40 | public void setCreateTimestamp(Timestamp createTimestamp) { 41 | this.createTimestamp = createTimestamp; 42 | } 43 | 44 | public Timestamp getUpdateTimestamp() { 45 | return updateTimestamp; 46 | } 47 | 48 | public void setUpdateTimestamp(Timestamp updateTimestamp) { 49 | this.updateTimestamp = updateTimestamp; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return super.toString(); 55 | // return DebugUtil.toString(this); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/po/BasePo.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.po; 2 | 3 | import com.zag.core.model.Identifiable; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * 基础Po 9 | * 10 | * @author stone 11 | * @date 2017年04月12日 12 | */ 13 | public abstract class BasePo implements Identifiable { 14 | 15 | private static final long serialVersionUID = 4920583045812713490L; 16 | 17 | @Override 18 | public boolean equals(Object o) { 19 | 20 | if (this == o) { 21 | return true; 22 | } 23 | if (!(o instanceof BasePo)) { 24 | return false; 25 | } 26 | 27 | BasePo po = (BasePo) o; 28 | return getId() != null && po.getId() != null && Objects.equals(po.getId(), this.getId()); 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | 34 | return getId() != null ? getId().hashCode() : 0; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return this.getClass().getName() + "#" + this.getId(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/repository/CommonJpaRepository.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.repository.NoRepositoryBean; 5 | 6 | import java.io.Serializable; 7 | 8 | @NoRepositoryBean 9 | public interface CommonJpaRepository extends JpaRepository { 10 | 11 | 12 | void persist(T entity); 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/repository/CommonJpaRepositoryBean.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.repository; 2 | 3 | import org.springframework.data.jpa.repository.support.JpaEntityInformation; 4 | import org.springframework.data.jpa.repository.support.SimpleJpaRepository; 5 | import org.springframework.data.repository.NoRepositoryBean; 6 | 7 | import javax.persistence.EntityManager; 8 | 9 | @NoRepositoryBean 10 | public class CommonJpaRepositoryBean extends SimpleJpaRepository implements CommonJpaRepository { 11 | 12 | private EntityManager entityManager; 13 | 14 | public CommonJpaRepositoryBean(Class domainClass, EntityManager em) { 15 | super(domainClass, em); 16 | this.entityManager = em; 17 | } 18 | 19 | public CommonJpaRepositoryBean(final JpaEntityInformation entityInformation, final EntityManager entityManager) { 20 | super(entityInformation, entityManager); 21 | this.entityManager = entityManager; 22 | } 23 | 24 | protected EntityManager getEntityManager() { 25 | return entityManager; 26 | } 27 | 28 | @Override 29 | public void persist(T entity) { 30 | getEntityManager().persist(entity); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/repository/CommonRepositoryFactory.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.repository; 2 | 3 | import org.springframework.data.jpa.repository.support.JpaRepositoryFactory; 4 | import org.springframework.data.repository.core.RepositoryMetadata; 5 | 6 | import javax.persistence.EntityManager; 7 | 8 | public class CommonRepositoryFactory extends JpaRepositoryFactory { 9 | 10 | public CommonRepositoryFactory(EntityManager entityManager) { 11 | super(entityManager); 12 | } 13 | 14 | /* 15 | * (non-Javadoc) 16 | * 17 | * @see 18 | * org.springframework.data.repository.support.RepositoryFactorySupport# 19 | * getRepositoryBaseClass() 20 | */ 21 | @Override 22 | protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { 23 | return CommonJpaRepositoryBean.class; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/repository/CommonRepositoryFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean; 5 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 6 | 7 | import javax.persistence.EntityManager; 8 | import java.io.Serializable; 9 | 10 | /** 11 | * @author stone 12 | */ 13 | public class CommonRepositoryFactoryBean> extends JpaRepositoryFactoryBean { 14 | 15 | 16 | @Override 17 | protected RepositoryFactorySupport createRepositoryFactory(EntityManager em) { 18 | return new CommonRepositoryFactory(em); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/util/CustomMysqlDialect.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.util; 2 | 3 | import org.hibernate.dialect.MySQL5InnoDBDialect; 4 | 5 | /** 6 | * 修正自动建表使用latin1作为字符集的错误 7 | */ 8 | public class CustomMysqlDialect extends MySQL5InnoDBDialect{ 9 | 10 | @Override 11 | public String getTableTypeString() { 12 | return " ENGINE=InnoDB DEFAULT CHARSET=utf8"; 13 | } 14 | } -------------------------------------------------------------------------------- /jpa-support/src/main/java/com/zag/support/jpa/util/UnderscoreNameCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.zag.support.jpa.util; 2 | 3 | 4 | import com.zag.core.util.StringUtil; 5 | import org.hibernate.boot.model.naming.Identifier; 6 | import org.hibernate.boot.model.naming.PhysicalNamingStrategy; 7 | import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; 8 | 9 | public class UnderscoreNameCustomizer implements PhysicalNamingStrategy { 10 | @Override 11 | public Identifier toPhysicalCatalogName(Identifier identifier, JdbcEnvironment jdbcEnv) { 12 | return convert(identifier); 13 | } 14 | 15 | @Override 16 | public Identifier toPhysicalColumnName(Identifier identifier, JdbcEnvironment jdbcEnv) { 17 | return convert(identifier); 18 | } 19 | 20 | @Override 21 | public Identifier toPhysicalSchemaName(Identifier identifier, JdbcEnvironment jdbcEnv) { 22 | return convert(identifier); 23 | } 24 | 25 | @Override 26 | public Identifier toPhysicalSequenceName(Identifier identifier, JdbcEnvironment jdbcEnv) { 27 | return convert(identifier); 28 | } 29 | 30 | @Override 31 | public Identifier toPhysicalTableName(Identifier identifier, JdbcEnvironment jdbcEnv) { 32 | return convert(identifier); 33 | } 34 | 35 | private Identifier convert(Identifier identifier) { 36 | if (identifier == null || StringUtil.isNullOrEmpty(identifier.getText())) { 37 | return identifier; 38 | } 39 | 40 | String regex = "([a-z])([A-Z])"; 41 | String replacement = "$1_$2"; 42 | String newName = identifier.getText().replaceAll(regex, replacement).toLowerCase(); 43 | return Identifier.toIdentifier(newName); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /redis-support/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /redis-support/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.zag 9 | zag 10 | 1.0.0 11 | 12 | 13 | redis-support 14 | jar 15 | 16 | 17 | 18 | redis.clients 19 | jedis 20 | 21 | 22 | 23 | com.zag 24 | core 25 | 26 | 27 | 28 | org.springframework 29 | spring-expression 30 | 31 | 32 | 33 | org.apache.commons 34 | commons-pool2 35 | 36 | 37 | 38 | org.springframework 39 | spring-beans 40 | 41 | 42 | 43 | org.springframework 44 | spring-context 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/annotation/FieldMapping.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 属性注解 获取属性存取的key 7 | * 如果有此注解 则当前进行更新保存的对象,需增加到当前当前key的value对象到id的映射 8 | * @author stone(by lei) 9 | * @date 2017年8月11日 10 | * @reviewer 11 | */ 12 | @Target(ElementType.FIELD) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Inherited 15 | @Documented 16 | public @interface FieldMapping { 17 | 18 | String prefix() default ""; 19 | 20 | String key(); 21 | } -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/annotation/FieldSortedSet.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 属性注解 获取属性存取的key 12 | * 如果有此注解 则当前进行更新保存的对象,需增加当前对象id到当前key的value 13 | * @author stone(by lei) 14 | * @date 2017年8月11日 15 | * @reviewer 16 | */ 17 | @Target(ElementType.FIELD) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Inherited 20 | @Documented 21 | public @interface FieldSortedSet { 22 | 23 | String prefix() default ""; 24 | 25 | String key(); 26 | 27 | String score() default ""; 28 | } -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/annotation/MethodSortedSet.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 属性注解 获取属性存取的key 12 | * 如果有此注解 则当前进行更新保存的对象,需增加当前对象id到当前key的value 13 | * @author stone(by lei) 14 | * @date 2017年8月11日 15 | * @reviewer 16 | */ 17 | @Target(ElementType.METHOD) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Inherited 20 | @Documented 21 | public @interface MethodSortedSet { 22 | 23 | String prefix() default ""; 24 | 25 | String key(); 26 | 27 | String score() default ""; 28 | } -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/annotation/NotOverride.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.annotation; 2 | 3 | public @interface NotOverride { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/annotation/RedisWriteIgnore.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author lei 10 | * @date 2017/2/27 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.FIELD) 14 | public @interface RedisWriteIgnore { 15 | 16 | enum IgnoreType{ 17 | /** 18 | * 忽略该字段,不会写入redis 19 | */ 20 | ALL, 21 | /** 22 | * 当该字段为 null 值时,不写入 redis(不覆盖 hash) 23 | */ 24 | NULL, 25 | /** 26 | * 当该字段为 null 或空字符串时,不写入 redis(不覆盖 hash) 27 | */ 28 | NULL_OR_EMPTY_STRING 29 | } 30 | 31 | IgnoreType type() default IgnoreType.ALL; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/annotation/Ro.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 12 | * 类注解 获取类存取的key 13 | * 如果有此注解 则当前进行更新保存的对象,需序列当前对象到当前key的value 14 | * @author stone(by lei) 15 | * @date 2017年8月11日 16 | * @reviewer 17 | */ 18 | @Target(ElementType.TYPE) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Inherited 21 | @Documented 22 | public @interface Ro { 23 | 24 | String key(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/annotation/RoLock.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * @reviewer 12 | */ 13 | @Target(ElementType.TYPE) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Inherited 16 | @Documented 17 | public @interface RoLock { 18 | 19 | String key(); 20 | } 21 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/annotation/RoSortedSet.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 12 | * 类注解 获取类存取的key 13 | * 如果有此注解 则当前进行更新保存的对象,需序列当前对象id到当前key的value 14 | * @author stone(by lei) 15 | * @date 2017年8月11日 16 | * @reviewer 17 | */ 18 | @Target(ElementType.TYPE) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Inherited 21 | @Documented 22 | public @interface RoSortedSet { 23 | 24 | String key(); 25 | 26 | String score() default ""; 27 | } 28 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/bean/BaseRo.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | public class BaseRo implements Serializable { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/BeanRegistry.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans; 2 | 3 | import com.zag.core.property.PropertyDescriptorExtends; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author lei 9 | * @date 2016/12/22 10 | */ 11 | public interface BeanRegistry { 12 | 13 | /** 14 | * 根据ro对象获取其属性描述符扩展,首先从缓存中查找,如果没有找到,则注册一次并缓存,然后获取 15 | * @param beanClazz 16 | * @return 17 | */ 18 | List findProperties(Class beanClazz); 19 | 20 | /** 21 | * 创建一个 ro 新对象 22 | * @param beanClazz 23 | * @param 24 | * @return 25 | */ 26 | RO newBeanInstance(Class beanClazz); 27 | 28 | /** 29 | * 注册 ro 类,使其属性描述符得到缓存 30 | * @param beanClazz 31 | */ 32 | void registerObject(Class beanClazz); 33 | 34 | 35 | ConvertorRegistry getConvertorRegistry(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/ConvertorMatcher.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans; 2 | 3 | /** 4 | * 5 | * @author lei 6 | * @date 2016/12/21 7 | */ 8 | public interface ConvertorMatcher { 9 | 10 | boolean isMatch(Class clazz); 11 | } 12 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/ConvertorRegistry.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans; 2 | 3 | /** 4 | * @author lei 5 | * @date 2016/12/21 6 | */ 7 | public interface ConvertorRegistry { 8 | 9 | 10 | /** 11 | * 注册一个类型的值转换器,并同时注册一个转换器匹配策略 12 | * @param convertor 13 | * @param 14 | */ 15 | void registerConvertor(ConvertorMatcher matcher, ValueConvertor convertor); 16 | 17 | /** 18 | * 注册一个类型的值转换器,使用默认的转换器匹配策略(类型直接匹配),重复注册同一个 class,后一个注册的会覆盖前一个 19 | * @param clazz 20 | * @param convertor 21 | * @param 22 | */ 23 | void registerConvertor(Class clazz, ValueConvertor convertor); 24 | 25 | /** 26 | * 根据类型寻找对应的 convertor,先找默认匹配策略,再找自定义匹配策略 27 | * @param clazz 28 | * @return 29 | */ 30 | ValueConvertor findConvertor(Class clazz); 31 | 32 | /** 33 | * 判断当前类型的属性是否受到转换器支持 34 | * @param clazz 属性类型 35 | * @return 36 | */ 37 | boolean isSupportedPropertyType(Class clazz); 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/DataItem.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans; 2 | 3 | import org.apache.commons.lang3.builder.ToStringBuilder; 4 | 5 | import java.util.Map.Entry; 6 | 7 | /** 8 | * @author lei 9 | * @date 2016/12/21 10 | */ 11 | public class DataItem { 12 | 13 | private final String key; 14 | 15 | private final byte[] data; 16 | 17 | public DataItem(String key, byte[] data) { 18 | this.key = key; 19 | this.data = data; 20 | } 21 | 22 | public DataItem(Entry entry){ 23 | this.key = new String(entry.getKey()); 24 | this.data = entry.getValue(); 25 | } 26 | 27 | public String getKey() { 28 | return key; 29 | } 30 | 31 | public byte[] getData() { 32 | return data; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return new ToStringBuilder(this) 38 | .append("key", key) 39 | .append("data", new String(data)) 40 | .toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/DataTransformer.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * @author lei 7 | * @date 2016/12/22 8 | */ 9 | public interface DataTransformer { 10 | 11 | /** 12 | * 将一个 redis 数据结构转换为 DataItem 的数组 13 | * @param redisData 14 | * @return 15 | */ 16 | DataItem[] redisData2Items(Map redisData); 17 | 18 | Map redisData2ItemsMap(Map redisData); 19 | 20 | Map items2RedisData(DataItem[] items); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/RedisObject.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans; 2 | 3 | /** 4 | * @author lei 5 | * @date 2016/12/22 6 | */ 7 | public interface RedisObject { 8 | } 9 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/Translator.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans; 2 | 3 | import com.zag.redis.bean.BaseRedisObject; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * @author lei 9 | * @date 2016/12/21 10 | */ 11 | public interface Translator { 12 | 13 | String SEPERATOR = "."; 14 | 15 | /** 16 | * 将一个 redis hash 数据转换为一个 ro 对象 17 | * @param redisData 18 | * @return 19 | */ 20 | RO toObject(Class clazz, Map redisData); 21 | 22 | 23 | /** 24 | * 将一个 redis hash 数据向对象中填充 25 | * @param ro 被填充数据的对象 26 | * @param redisData 27 | * @return 28 | */ 29 | void fillObject(Object ro, Map redisData); 30 | 31 | 32 | 33 | /** 34 | * 将一个 ro 对象转换为 redis hash 数据 35 | * @param object 36 | * @return 37 | */ 38 | Map toRedisData(BaseRedisObject object); 39 | 40 | 41 | DataTransformer getDataTransformer(); 42 | 43 | ConvertorRegistry getConvertorRegistry(); 44 | 45 | BeanRegistry getBeanRegistry(); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/ValueConvertor.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans; 2 | 3 | /** 4 | * @author lei 5 | * @date 2016/12/21 6 | */ 7 | public interface ValueConvertor { 8 | 9 | /** 10 | * 将值转换为数据项,key 为属性名 11 | * 例如,对象结构为: 12 | * 13 | * { 14 | * "name":"zhangsan", 15 | * "role":{ 16 | * "text":"admin", 17 | * "id":1 18 | * } 19 | * } 20 | * 对应传入本方法的参数为:(两个不同的 Convertor 实现) 21 | * "name","zhangsan" => {["name"="zhangsan"]} 22 | * "role",{ 23 | * "text":"admin", 24 | * "id":1 25 | * } => {["role.id"=1,"role.text"="admin"]} 26 | * 27 | * 28 | * @param key 29 | * @param val 30 | * @return 31 | */ 32 | DataItem[] toRedisData(String key, V val); 33 | 34 | 35 | /** 36 | * 将数据项转换为对应类型的值 37 | * 例如,有如下数据项: 38 | * 39 | * "name","zhangsan" 40 | * "role.text","admin" 41 | * "role.id",1 42 | * 它应该分为两次调用本方法, 43 | * 一次传递参数:"",{["name"="zhangsan"]} => "zhangsan" 44 | * 一次传递参数:"role",{["role.id"=1,"role.text"="admin"]} => { 45 | * "id":1 46 | * "text":"admin" 47 | * } 48 | * 49 | * @param clazz 50 | * @param prefix 51 | * @param redisData 52 | * @return 53 | */ 54 | V toValue(Class clazz, String prefix, DataItem[] redisData); 55 | // 56 | // /** 57 | // * 返回当前转换器和属性类型之间的匹配策略,如果返回 null,则使用简单匹配策略 58 | // * @return 59 | // */ 60 | // ConvertorMatcher getMatcher(); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/impl/DefaultConvertorRegistry.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans.impl; 2 | 3 | import com.google.common.collect.Lists; 4 | import com.google.common.collect.Maps; 5 | import com.zag.redis.trans.ConvertorRegistry; 6 | import com.zag.redis.trans.ConvertorMatcher; 7 | import com.zag.redis.trans.ValueConvertor; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author lei 14 | * @date 2016/12/22 15 | */ 16 | public class DefaultConvertorRegistry implements ConvertorRegistry { 17 | 18 | private Map level1Container = Maps.newHashMap(); 19 | private List level2Container = Lists.newArrayList(); 20 | 21 | 22 | @Override 23 | public void registerConvertor(ConvertorMatcher matcher, ValueConvertor convertor) { 24 | level2Container.add(new Bucket(matcher, convertor)); 25 | } 26 | 27 | @Override 28 | public void registerConvertor(Class clazz, ValueConvertor convertor) { 29 | level1Container.put(clazz,convertor); 30 | } 31 | 32 | @Override 33 | public ValueConvertor findConvertor(Class clazz) { 34 | ValueConvertor vc = level1Container.get(clazz); 35 | if(vc==null){ 36 | for (Bucket b : level2Container) { 37 | if(b.convertorMatcher.isMatch(clazz)){ 38 | vc = b.valueConvertor; 39 | break; 40 | } 41 | } 42 | } 43 | return vc; 44 | } 45 | 46 | @Override 47 | public boolean isSupportedPropertyType(Class clazz) { 48 | return findConvertor(clazz)!=null; 49 | } 50 | 51 | private static class Bucket{ 52 | ValueConvertor valueConvertor; 53 | ConvertorMatcher convertorMatcher; 54 | 55 | public Bucket(ConvertorMatcher convertorMatcher, ValueConvertor valueConvertor) { 56 | this.valueConvertor = valueConvertor; 57 | this.convertorMatcher = convertorMatcher; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/impl/StringMap.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans.impl; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * @author lei 7 | * @date 2016/12/22 8 | */ 9 | public class StringMap extends HashMap { 10 | } 11 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/impl/convertor/AbstractMultiValueConvertor.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans.impl.convertor; 2 | 3 | import com.zag.redis.trans.ConvertorRegistry; 4 | import com.zag.redis.trans.DataItem; 5 | import com.zag.redis.trans.Translator; 6 | import com.zag.redis.trans.ValueConvertor; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | /** 12 | * @author lei 13 | * @date 2016/12/22 14 | */ 15 | public abstract class AbstractMultiValueConvertor implements ValueConvertor { 16 | private ConvertorRegistry convertorRegistry; 17 | protected Logger logger = LoggerFactory.getLogger(this.getClass()); 18 | 19 | protected ConvertorRegistry getConvertorRegistry() { 20 | return convertorRegistry; 21 | } 22 | public AbstractMultiValueConvertor(ConvertorRegistry convertorRegistry) { 23 | this.convertorRegistry = convertorRegistry; 24 | } 25 | 26 | protected DataItem[] resolveItems(String key, Object value){ 27 | return this.resolveItems(null, key, value); 28 | } 29 | 30 | protected DataItem[] resolveItems(String prefix, String propKey, Object value) { 31 | if(StringUtils.isNotBlank(prefix)){ 32 | propKey = prefix + Translator.SEPERATOR + propKey; 33 | } 34 | ValueConvertor convertor = getConvertorRegistry().findConvertor(value.getClass()); 35 | if(convertor==null){ 36 | logger.warn("prop[name={},type={}] convertor not found",propKey,value.getClass().getSimpleName()); 37 | } 38 | return convertor.toRedisData(propKey, value); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/impl/convertor/AbstractNumberConvertor.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans.impl.convertor; 2 | 3 | /** 4 | * @author lei 5 | * @date 2016/12/22 6 | */ 7 | public abstract class AbstractNumberConvertor extends AbstractSimpleValueConvertor { 8 | 9 | @Override 10 | protected String val2String(N val) { 11 | return val.toString(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/impl/convertor/AbstractSimpleValueConvertor.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans.impl.convertor; 2 | 3 | import com.zag.redis.trans.DataItem; 4 | import com.zag.redis.trans.ValueConvertor; 5 | 6 | import java.util.Objects; 7 | 8 | /** 9 | * @author lei 10 | * @date 2016/12/21 11 | */ 12 | public abstract class AbstractSimpleValueConvertor implements ValueConvertor { 13 | 14 | 15 | @Override 16 | public DataItem[] toRedisData(String key, V val) { 17 | /** 18 | * null 值将写入为空字符串 19 | */ 20 | if(val == null) return new DataItem[]{new DataItem(key,"".getBytes())}; 21 | return new DataItem[]{new DataItem(key,val2String(val).getBytes())}; 22 | } 23 | 24 | @Override 25 | public V toValue(Class clazz, String key, DataItem[] items) { 26 | if(items==null||items.length==0)return null; 27 | if(items.length>1){ 28 | throw new IllegalArgumentException("简单值数据项数组长度只能为1"); 29 | } 30 | /** 31 | * 空字符串将转换为 null 32 | */ 33 | String data = new String(items[0].getData()); 34 | if(Objects.equals(data,"")) return null; 35 | return parseValue(data); 36 | } 37 | 38 | protected abstract V parseValue(String data); 39 | protected abstract String val2String(V val); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/trans/impl/convertor/EnumConvertor.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.trans.impl.convertor; 2 | 3 | import com.zag.redis.trans.ConvertorMatcher; 4 | import com.zag.redis.trans.DataItem; 5 | import com.zag.redis.trans.ValueConvertor; 6 | import org.apache.commons.lang3.EnumUtils; 7 | 8 | /** 9 | * @author lei 10 | * @date 2016/12/25 11 | */ 12 | public class EnumConvertor> implements ValueConvertor { 13 | 14 | public static final ConvertorMatcher MARCHER = new ConvertorMatcher(){ 15 | @Override 16 | public boolean isMatch(Class clazz) { 17 | return Enum.class.isAssignableFrom(clazz); 18 | } 19 | }; 20 | 21 | @Override 22 | public DataItem[] toRedisData(String key, Enum val) { 23 | if(val==null) 24 | return new DataItem[0]; 25 | return new DataItem[]{new DataItem(key,val.name().getBytes())}; 26 | } 27 | 28 | @Override 29 | public E toValue(Class clazz, String prefix, DataItem[] redisData) { 30 | if(redisData==null || redisData.length==0){ 31 | return null; 32 | } 33 | String enumName = new String(redisData[0].getData()); 34 | return EnumUtils.getEnum(clazz,enumName); 35 | } 36 | // enum TEST{ 37 | // A, 38 | // B 39 | // } 40 | // public static void main(String[] args) { 41 | // EnumConvertor ec = new EnumConvertor(); 42 | // DataItem[] items = ec.toRedisData("abc", TEST.A); 43 | // System.out.println(Arrays.toString(items)); 44 | // Enum anEnum = ec.toValue(TEST.class, "", items); 45 | // System.out.println(anEnum); 46 | // } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/util/ExpressionUtil.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.util; 2 | 3 | import org.springframework.expression.Expression; 4 | import org.springframework.expression.spel.support.StandardEvaluationContext; 5 | 6 | /** 7 | * 表达式工具辅助类 8 | * @author stone(by lei) 9 | * @date 2017年8月12日 10 | * @reviewer 11 | */ 12 | public class ExpressionUtil { 13 | 14 | /** 15 | * 传递的是id或者时间 16 | * @author stone(by lei) 17 | * @date 2017年8月12日 18 | * @param idOrDate 19 | * @param expression 20 | * @return 21 | */ 22 | public static long getScore(StandardEvaluationContext itemContext, Expression expression) { 23 | if (expression == null) { 24 | return System.currentTimeMillis(); 25 | } else { 26 | Object obj = expression.getValue(itemContext); 27 | // System.out.println(obj.getClass().getName()); 28 | // System.out.println(obj); 29 | if (obj instanceof java.util.Date) { 30 | return ((java.util.Date) obj).getTime(); 31 | } if (obj instanceof java.sql.Date) { 32 | return ((java.sql.Date) obj).getTime(); 33 | } if (obj instanceof java.sql.Timestamp) { 34 | return ((java.sql.Timestamp) obj).getTime(); 35 | } else if (obj instanceof Number) { 36 | return ((Number) obj).longValue(); 37 | } else { 38 | throw new IllegalArgumentException(); 39 | } 40 | } 41 | } 42 | 43 | 44 | public static String getKey(Object ro, Expression expression) { 45 | return expression.getValue(ro).toString(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /redis-support/src/main/java/com/zag/redis/util/FieldMappingAssist.java: -------------------------------------------------------------------------------- 1 | package com.zag.redis.util; 2 | 3 | import com.zag.redis.bean.BaseRedisObject; 4 | import org.springframework.expression.Expression; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * 属性注解 属性注解辅助类 10 | * 11 | * @author stone(by lei) 12 | * @date 2017年8月12日 13 | * @reviewer 14 | * @param 15 | */ 16 | public class FieldMappingAssist, ID extends Serializable> { 17 | 18 | private String fieldName; 19 | private String prefix; 20 | private Expression keyExpression; 21 | 22 | public FieldMappingAssist() { 23 | super(); 24 | } 25 | 26 | public FieldMappingAssist(String fieldName, String prefix, Expression keyExpression) { 27 | super(); 28 | this.fieldName = fieldName; 29 | this.prefix = prefix; 30 | this.keyExpression = keyExpression; 31 | } 32 | 33 | public String getFieldName() { 34 | return fieldName; 35 | } 36 | 37 | public void setFieldName(String fieldName) { 38 | this.fieldName = fieldName; 39 | } 40 | 41 | public String getPrefix() { 42 | return prefix; 43 | } 44 | 45 | public void setPrefix(String prefix) { 46 | this.prefix = prefix; 47 | } 48 | 49 | public Expression getKeyExpression() { 50 | return keyExpression; 51 | } 52 | 53 | public void setKeyExpression(Expression keyExpression) { 54 | this.keyExpression = keyExpression; 55 | } 56 | 57 | /** 58 | * 属性名称加上表达式值KEY 59 | * @author stone(by lei) 60 | * @date 2017年8月12日 61 | * @return 62 | */ 63 | public String getKey(T ro) { 64 | return this.prefix + ":" + ExpressionUtil.getKey(ro, keyExpression); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /redis-support/src/main/resources/META-INF/jedis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /redis-support/src/main/resources/redis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /redis-support/src/test/java/com/rrb/redis/test/Item.java: -------------------------------------------------------------------------------- 1 | package com.rrb.redis.test; 2 | 3 | import java.util.Date; 4 | 5 | public class Item { 6 | private String name; 7 | 8 | private int qty; 9 | 10 | private Long ts; 11 | 12 | private Date date; 13 | 14 | public Item(String name, int qty) { 15 | super(); 16 | this.name = name; 17 | this.qty = qty; 18 | this.ts = System.currentTimeMillis(); 19 | date = new java.sql.Timestamp(System.currentTimeMillis()); 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public int getQty() { 31 | return qty; 32 | } 33 | 34 | public void setQty(int qty) { 35 | this.qty = qty; 36 | } 37 | 38 | public Long getTs() { 39 | return ts; 40 | } 41 | 42 | public void setTs(Long ts) { 43 | this.ts = ts; 44 | } 45 | 46 | public Date getDate() { 47 | return date; 48 | } 49 | 50 | public void setDate(Date date) { 51 | this.date = date; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /redis-support/src/test/java/com/rrb/redis/test/TestRedisDao.java: -------------------------------------------------------------------------------- 1 | package com.rrb.redis.test; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.zag.redis.ShardedJedisCurdCommonRedisDao; 6 | 7 | @Component 8 | public class TestRedisDao extends ShardedJedisCurdCommonRedisDao { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /redis-support/src/test/java/com/rrb/redis/test/TestRo.java: -------------------------------------------------------------------------------- 1 | package com.rrb.redis.test; 2 | 3 | import com.zag.redis.annotation.FieldSortedSet; 4 | import com.zag.redis.annotation.Ro; 5 | import com.zag.redis.annotation.RoSortedSet; 6 | import com.zag.redis.bean.BaseRedisObject; 7 | 8 | @Ro(key = "test:test") 9 | @RoSortedSet(key = "all", score = "ts") 10 | public class TestRo extends BaseRedisObject { 11 | 12 | private String id; 13 | private String name; 14 | 15 | @FieldSortedSet(key = "categoryId", score = "createTime") 16 | private Long categoryId; 17 | 18 | @FieldSortedSet(key = "categoryId", score = "createTime") 19 | private java.sql.Timestamp createTime; 20 | 21 | private Long ts = 123456L; 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public Long getCategoryId() { 32 | return categoryId; 33 | } 34 | 35 | public void setCategoryId(Long categoryId) { 36 | this.categoryId = categoryId; 37 | } 38 | 39 | public java.sql.Timestamp getCreateTime() { 40 | return createTime; 41 | } 42 | 43 | public void setCreateTime(java.sql.Timestamp createTime) { 44 | this.createTime = createTime; 45 | } 46 | 47 | public void setId(String id) { 48 | this.id = id; 49 | } 50 | 51 | public String getId() { 52 | return id; 53 | } 54 | 55 | public Long getTs() { 56 | return ts; 57 | } 58 | 59 | public void setTs(Long ts) { 60 | this.ts = ts; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /redis-support/src/test/resources/application-test-redis.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | classpath:redis.properties 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /redis-support/src/test/resources/redis.properties: -------------------------------------------------------------------------------- 1 | #\u6700\u5927\u5206\u914d\u7684\u5bf9\u8c61\u6570 2 | redis.maxTotal=${redis.maxTotal} 3 | #\u6700\u5927\u80fd\u591f\u4fdd\u6301idel\u72b6\u6001\u7684\u5bf9\u8c61\u6570 4 | redis.maxIdle=${redis.maxIdle} 5 | redis.minIdle=${redis.minIdle} 6 | #\u5f53\u8c03\u7528borrow Object\u65b9\u6cd5\u65f6\uff0c\u662f\u5426\u8fdb\u884c\u6709\u6548\u6027\u68c0\u67e5 7 | redis.testOnBorrow=${redis.testOnBorrow} 8 | # 9 | redis.maxWaitMillis=${redis.maxWaitMillis} 10 | # 11 | redis.testOnReturn=${redis.testOnReturn} 12 | # 13 | redis.testWhileIdle=${redis.testWhileIdle} 14 | #\u591a\u957f\u65f6\u95f4\u68c0\u67e5\u4e00\u6b21\u8fde\u63a5\u6c60\u4e2d\u7a7a\u95f2\u7684\u8fde\u63a5 15 | redis.timeBetweenEvictionRunsMillis=${redis.timeBetweenEvictionRunsMillis} 16 | #\u7a7a\u95f2\u8fde\u63a5\u591a\u957f\u65f6\u95f4\u540e\u4f1a\u88ab\u6536\u56de 17 | redis.minEvictableIdleTimeMillis=${redis.minEvictableIdleTimeMillis} 18 | redis.socketTimeout=${redis.socketTimeout} 19 | 20 | # Global Settings. 21 | 22 | #\u591a\u4e2a\u4e4b\u95f4\u4f7f\u7528@\u9017\u53f7\u9694\u5f00 \u5982 127.0.0.1@128.0.0.1@ 23 | redis.host=${redis.host} 24 | redis.port=${redis.port} 25 | redis.name=${redis.name} 26 | redis.password=${redis.password} 27 | -------------------------------------------------------------------------------- /redis-support/src/test/resources/redis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /rest/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /rest/src/main/java/com/zag/rest/base/Constants.java: -------------------------------------------------------------------------------- 1 | package com.zag.rest.base; 2 | 3 | public interface Constants { 4 | 5 | String DATA = "data_map"; 6 | 7 | String DATA_STR = "data_str"; 8 | 9 | String SCENE_PROD = "production"; 10 | 11 | //图片验证码hash,key开头标记 12 | String IMAGE_CODE = "global:imageVerifyCode:"; 13 | 14 | //短信验证码hash,key开头标记 15 | String SMS_CODE = "global:sms:"; 16 | 17 | //网络环境常量 18 | String APN_WIFI = "wifi"; 19 | String APN_WAN = "wan"; 20 | 21 | 22 | //使用场景定义 23 | String SCENE_DEV = "dev"; 24 | String SCENE_TEST = "test"; 25 | /** 26 | * Rest接口md5数据 在httprequest attribute中的存放key值 27 | */ 28 | String MD5_HTTP_ATTR_NAME = "com.gridy.rest.md5"; 29 | 30 | /** 31 | * Rest接口post数据参数名 32 | */ 33 | String POST_DATA_PARAM_NAME = "data"; 34 | 35 | /** 36 | * 从httpReqest中指定签名开关, 优先级高于配置, 目录 combineApi接口使用, 37 | * 如果未指定该字段, 从配置读取 38 | */ 39 | String SIGN_FLAG_REQ_ATTR = "com.gridy.rest.signFlag"; 40 | 41 | String DEFAULT_TOKEN = "20161919"; 42 | 43 | /** 44 | * 当前页码 的参数名 45 | */ 46 | String CUR_PAGE = "curPage"; 47 | 48 | } -------------------------------------------------------------------------------- /rest/src/main/java/com/zag/rest/base/handler/GlobalParamsHandler.java: -------------------------------------------------------------------------------- 1 | package com.zag.rest.base.handler; 2 | 3 | import com.zag.core.exception.SystemException; 4 | import com.zag.support.web.BuildRequestHandler; 5 | import com.zag.support.web.assist.GlobalParams; 6 | import com.zag.support.web.assist.IRequestVo; 7 | import com.zag.vo.BaseRequestVo; 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.core.Ordered; 12 | import org.springframework.stereotype.Component; 13 | 14 | import javax.servlet.http.HttpServletRequest; 15 | import java.math.BigDecimal; 16 | 17 | import static com.zag.core.util.WebUtil.writeEscapedXml; 18 | 19 | /** 20 | * 全局参数初始化处理器 21 | * @author stone 22 | * @since 2017年8月16日 23 | * @usage 24 | * @reviewer 25 | */ 26 | @Component 27 | public class GlobalParamsHandler implements BuildRequestHandler { 28 | 29 | private Logger logger = LoggerFactory.getLogger(getClass()); 30 | 31 | @Override 32 | public void handle(HttpServletRequest request, IRequestVo requestVo) throws SystemException { 33 | if (requestVo != null) { 34 | // 初始化全局参数 35 | GlobalParams globalParams = parseGlobalParams(request); 36 | requestVo.setGlobalParams(globalParams); 37 | if (requestVo instanceof BaseRequestVo) { 38 | 39 | } 40 | } 41 | } 42 | 43 | private GlobalParams parseGlobalParams(HttpServletRequest httpRequest) { 44 | GlobalParams params = null; 45 | try { 46 | GlobalParams p = new GlobalParams(); 47 | 48 | params = p; 49 | } catch (Exception e) { 50 | logger.error("解析全局参数出错", e); 51 | } 52 | return params; 53 | } 54 | 55 | @Override 56 | public int getOrder() { 57 | return Ordered.HIGHEST_PRECEDENCE; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /rest/src/main/java/com/zag/rest/interceptor/AuthInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.zag.rest.interceptor; 2 | 3 | import com.google.common.base.Objects; 4 | import com.zag.core.asserts.BusinessAsserts; 5 | import com.zag.core.util.DebugUtil; 6 | import com.zag.exception.Exceptions; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | 15 | /** 16 | * 校验拦截器 17 | */ 18 | public class AuthInterceptor extends HandlerInterceptorAdapter { 19 | 20 | private Logger logger = LoggerFactory.getLogger(getClass()); 21 | 22 | private boolean enabled = false; 23 | 24 | @Override 25 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 26 | if(!isEnabled()){ 27 | return true; 28 | } 29 | if(DebugUtil.isDebugEnabled() && Objects.equal("true", request.getParameter("debug"))){ 30 | logger.debug("debug mode enabled, and parameter [debug] is 'true', pass"); 31 | return true; 32 | } 33 | 34 | String token = request.getParameter("authToken"); 35 | 36 | return true; 37 | } 38 | 39 | public boolean isEnabled() { 40 | return enabled; 41 | } 42 | 43 | public void setEnabled(boolean enabled) { 44 | this.enabled = enabled; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rest/src/main/java/com/zag/rest/util/JwtToken.java: -------------------------------------------------------------------------------- 1 | package com.zag.rest.util; 2 | 3 | import com.zag.enums.UserExamineEnums; 4 | import com.zag.enums.UserTypeEnums; 5 | import com.zag.service.ex.user.UserService; 6 | import com.zag.vo.ex.user.resp.JwtUser; 7 | import com.zag.vo.ex.user.resp.UserRespVo; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | 10 | import java.util.Objects; 11 | 12 | /** 13 | * @ProjectName: web3j-zag 14 | * @Package: com.zag.rest.util 15 | * @ClassName: ${JwtToken} 16 | * @Description: Jwt验证 17 | * @Author: skyhuihui 18 | * @CreateDate: 2018/8/8 15:21 19 | * @UpdateUser: Neil.Zhou 20 | * @UpdateDate: 2018/8/8 15:21 21 | * @UpdateRemark: The modified content 22 | * @Version: 1.0 23 | */ 24 | public class JwtToken { 25 | 26 | /** 27 | * jwt验证过期时间 28 | * @author skyhuihui 29 | * @version V1.0 30 | * @return boolean 31 | */ 32 | public Boolean jwtToken(String token){ 33 | JwtUser jwtUser = JwtUnsign.unsign(token, JwtUser.class); 34 | if(Objects.nonNull(jwtUser)){ 35 | //表示token合法 36 | return true; 37 | }else{ 38 | //token不合法或者过期 39 | return false; 40 | } 41 | } 42 | 43 | /** 44 | * jwt验证权限 是否实名认证 45 | * @author skyhuihui 46 | * @version V1.0 47 | * @return boolean 48 | */ 49 | public Boolean jwtUserType(String token){ 50 | JwtUser jwtUser = JwtUnsign.unsign(token, JwtUser.class); 51 | if(Objects.nonNull(jwtUser)){ 52 | System.out.println(jwtUser.getUserExamineEnums() +" 是否经过审核"+ UserExamineEnums.AuditSuccess ); 53 | if(jwtUser.getUserExamineEnums().equals(UserExamineEnums.AuditSuccess)){ 54 | return true; 55 | } 56 | return false; 57 | }else{ 58 | //token不合法或者过期 59 | return false; 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /rest/src/main/java/com/zag/rest/util/JwtUnsign.java: -------------------------------------------------------------------------------- 1 | package com.zag.rest.util; 2 | 3 | import com.auth0.jwt.JWTSigner; 4 | import com.auth0.jwt.JWTVerifier; 5 | import com.auth0.jwt.internal.com.fasterxml.jackson.databind.ObjectMapper; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * @ProjectName: web3j-zag 11 | * @Package: com.zag.rest.util 12 | * @ClassName: JWT 13 | * @Description: JWT验证 14 | * @Author: skyhuihui 15 | * @CreateDate: 2018/8/6 17:29 16 | * @UpdateUser: Neil.Zhou 17 | * @UpdateDate: 2018/8/6 17:29 18 | * @UpdateRemark: The modified content 19 | * @Version: 1.0 20 | */ 21 | public class JwtUnsign { 22 | 23 | private static final String SECRET = "XX#$%()(#*!()!KL<>?N<:{LWPW"; 24 | private static final String EXP = "exp"; 25 | private static final String PAYLOAD = "payload"; 26 | 27 | //解密,传入一个加密后的token字符串和解密后的类型 28 | public static T unsign(String jwt, Class classT) { 29 | final JWTVerifier verifier = new JWTVerifier(SECRET); 30 | try { 31 | final Map claims= verifier.verify(jwt); 32 | if (claims.containsKey(EXP) && claims.containsKey(PAYLOAD)) { 33 | long exp = (Long)claims.get(EXP); 34 | long currentTimeMillis = System.currentTimeMillis(); 35 | if (exp > currentTimeMillis) { 36 | String json = (String)claims.get(PAYLOAD); 37 | ObjectMapper objectMapper = new ObjectMapper(); 38 | return objectMapper.readValue(json, classT); 39 | } 40 | } 41 | return null; 42 | } catch (Exception e) { 43 | return null; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /rest/src/main/java/com/zag/rest/util/NetUtils.java: -------------------------------------------------------------------------------- 1 | package com.zag.rest.util; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import java.io.InputStream; 7 | 8 | 9 | public class NetUtils { 10 | private static Logger logger = Logger.getLogger(NetUtils.class); 11 | 12 | public static String getHttpRequestBody(HttpServletRequest request){ 13 | 14 | Object requestContext = request.getAttribute("requestContext"); 15 | if(requestContext != null){ 16 | return requestContext.toString(); 17 | } 18 | String result = null; 19 | try { 20 | request.setCharacterEncoding("UTF-8"); 21 | 22 | int contentLen = request.getContentLength(); 23 | if(contentLen > 0){ 24 | InputStream is = request.getInputStream(); 25 | byte[] message = new byte[contentLen]; 26 | int readLen = 0; 27 | int readLengthThisTime = 0; 28 | while (readLen != contentLen) { 29 | readLengthThisTime = is.read(message, readLen, contentLen - readLen); 30 | if (readLengthThisTime == -1){ 31 | break; 32 | } 33 | readLen += readLengthThisTime; 34 | } 35 | if(readLen >= contentLen){ 36 | result = new String(message, "UTF-8"); 37 | } 38 | } 39 | } catch (Exception e) { 40 | logger.error(e.getMessage()); 41 | return null; 42 | } 43 | logger.info("request 信息:" + result); 44 | request.setAttribute("requestContext", result); 45 | return result; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /rest/src/main/resources/properties/datasource.properties: -------------------------------------------------------------------------------- 1 | # 数据库相关 2 | jdbc.driver = com.mysql.jdbc.Driver 3 | jdbc.url = jdbc:mysql://127.0.0.1:3306/web3j-zag?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false 4 | jdbc.username = root 5 | jdbc.password = root 6 | 7 | # 池初始化大小 8 | jdbc.initialSize= 2 9 | 10 | # 池最小连接数 11 | jdbc.minIdle= 2 12 | 13 | # 池最大连接数 14 | jdbc.maxIdle= 100 15 | 16 | # 池最大连接数 17 | jdbc.maxActive= 10 18 | 19 | # 获取连接等待超时的时间 20 | jdbc.maxWait= 1000 21 | 22 | # 对于建立时间超过removeAbandonedTimeout的连接强制关闭 23 | jdbc.removeAbandoned = true 24 | 25 | # 指定连接建立多长时间就需要被强制关闭 26 | jdbc.removeAbandonedTimeout= 1800 27 | 28 | # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 29 | jdbc.timeBetweenEvictionRunsMillis= 60000 30 | 31 | # 一个连接在池中最小生存的时间,单位是毫秒 32 | jdbc.minEvictableIdleTimeMillis= 300000 33 | 34 | # 是否打开PSCache 35 | jdbc.poolPreparedStatements= true 36 | 37 | # 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100 38 | jdbc.maxOpenPreparedStatements = 100 39 | 40 | # 指定每个连接上PSCache的大小 41 | jdbc.maxPoolPreparedStatementPerConnectionSize= 30 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= true -------------------------------------------------------------------------------- /rest/src/main/resources/properties/oss_config.properties: -------------------------------------------------------------------------------- 1 | oss_config.endpoint=http://oss-cn-beijing.aliyuncs.com 2 | oss_config.accessKeyId=LTAI9MJQBUbs9lpi 3 | oss_config.accessKeySecret=f65a6asliXyxsdwDOCvOK5dXMRa9j3 4 | oss_config.bucketName=zagshuwu 5 | -------------------------------------------------------------------------------- /rest/src/main/resources/properties/redis.properties: -------------------------------------------------------------------------------- 1 | #最大分配的对象数 2 | redis.maxTotal= 1000 3 | #最大能够保持idel状态的对象数 4 | redis.maxIdle= 200 5 | redis.minIdle= 10 6 | #当调用borrow Object方法时,是否进行有效性检查 7 | redis.testOnBorrow=true 8 | # 9 | redis.maxWaitMillis= 1000 10 | # 11 | redis.testOnReturn=true 12 | # 13 | redis.testWhileIdle=true 14 | #多长时间检查一次连接池中空闲的连接 15 | redis.timeBetweenEvictionRunsMillis=30000 16 | #空闲连接多长时间后会被收回 17 | redis.minEvictableIdleTimeMillis=30000 18 | redis.socketTimeout=2000 19 | 20 | # Global Settings. 21 | 22 | #多个之间使用英文逗号隔开 如 127.0.0.1,128.0.0.1, 23 | redis.host=127.0.0.1@ 24 | redis.port=6379@ 25 | redis.name= 26 | redis.password= 27 | 28 | #判断参数 29 | redis.config.localpath=properties/redis.properties -------------------------------------------------------------------------------- /rest/src/main/resources/spring/application-rest.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | classpath:properties/datasource.properties 17 | classpath:properties/oss_config.properties 18 | classpath:properties/redis.properties 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /rest/src/main/webapp/WEB-INF/views/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: skyhuihui 4 | Date: 2018/1/27 5 | Time: 20:09 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 欢迎来到skyhuihui的项目 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /rest/src/main/webapp/error.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

这是个错误页面哦,亲

4 | 5 | 6 | -------------------------------------------------------------------------------- /rest/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skyhuihui/exchange/7785866ae7a7e21daee9629a793bd9a33ff6f43c/rest/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /rest/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /service/src/main/java/com/zag/service/JwtSign.java: -------------------------------------------------------------------------------- 1 | package com.zag.service; 2 | 3 | import com.auth0.jwt.JWTSigner; 4 | import com.auth0.jwt.JWTVerifier; 5 | import com.auth0.jwt.internal.com.fasterxml.jackson.databind.ObjectMapper; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * @ProjectName: web3j-zag 12 | * @Package: com.zag.rest.util 13 | * @ClassName: JWT 14 | * @Description: JWT验证 15 | * @Author: skyhuihui 16 | * @CreateDate: 2018/8/6 17:29 17 | * @UpdateUser: Neil.Zhou 18 | * @UpdateDate: 2018/8/6 17:29 19 | * @UpdateRemark: The modified content 20 | * @Version: 1.0 21 | */ 22 | public class JwtSign { 23 | 24 | private static final String SECRET = "XX#$%()(#*!()!KL<>?N<:{LWPW"; 25 | private static final String EXP = "exp"; 26 | private static final String PAYLOAD = "payload"; 27 | 28 | //加密,传入一个对象和有效期 29 | public static String sign(T object, long maxAge) { 30 | try { 31 | final JWTSigner signer = new JWTSigner(SECRET); 32 | final Map claims = new HashMap(); 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[] 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[] 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[] 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[] 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[] 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[] 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[] 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 | --------------------------------------------------------------------------------