├── codegen ├── build.bat ├── wCodeGen-all-1.0.jar ├── run.bat ├── bootrun.bat ├── codegen.bat ├── DAFramework │ ├── service-center.yml │ ├── service-center-test.yml │ ├── security.yml │ ├── security-test.yml │ ├── api-gateway.yml │ ├── api-gateway-test.yml │ ├── account.yml │ └── account-test.yml ├── docker-compose.yml ├── docker-compose.base.yml ├── sql │ └── create.sql ├── projects.pro.yml ├── projects.yml ├── gradle.yml └── components.yml ├── settings.gradle ├── service-center ├── src │ ├── test │ │ └── resources │ │ │ └── bootstrap.yml │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── dataagg │ │ └── EurekaServerApplication.java └── build.gradle ├── commons ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── dataagg │ │ │ └── util │ │ │ ├── TextUtilTest.java │ │ │ ├── OAuth2RestHelperTest.java │ │ │ ├── lang │ │ │ ├── MoneyUtilTest.java │ │ │ └── ArithUtilsTest.java │ │ │ └── CryptoUtilTest.java │ └── main │ │ └── java │ │ └── com │ │ └── dataagg │ │ ├── util │ │ ├── WJsonExclued.java │ │ ├── IdGen.java │ │ ├── collection │ │ │ ├── ListTraverser.java │ │ │ ├── MapTraverser.java │ │ │ ├── StrMap.java │ │ │ └── MapUtil.java │ │ ├── WPage.java │ │ ├── oauth │ │ │ ├── WXAuthorizationCodeAccessTokenProvider.java │ │ │ └── OAuth2ClientResources.java │ │ ├── Constans.java │ │ ├── WPageIterator.java │ │ ├── SearchQueryJS.java │ │ ├── FindFileUtil.java │ │ ├── lang │ │ │ ├── ArgCheck.java │ │ │ ├── ValuePlus.java │ │ │ ├── ArithUtils.java │ │ │ └── MoneyUtil.java │ │ ├── FileUtil.java │ │ ├── JsonObjGetter.java │ │ ├── text │ │ │ ├── VcfBean.java │ │ │ └── VCard.java │ │ ├── ITreeNode.java │ │ ├── SecurityHelper.java │ │ ├── xml │ │ │ ├── XmlCoder.java │ │ │ ├── XPathEvaluator.java │ │ │ └── XmlUtil.java │ │ ├── TreeNode.java │ │ ├── WMap.java │ │ ├── WJsonUtils.java │ │ ├── SysToolkit.java │ │ └── CryptoUtil.java │ │ └── commons │ │ ├── dao │ │ ├── OrgDao.java │ │ ├── FileDao.java │ │ ├── AccessTokenDao.java │ │ ├── UserDao.java │ │ ├── OpenUserDao.java │ │ ├── DictDao.java │ │ ├── AccountDao.java │ │ ├── AuthorityDao.java │ │ ├── MenuDao.java │ │ ├── AreaDao.java │ │ └── RoleDao.java │ │ ├── vo │ │ ├── ActionResult.java │ │ ├── ActionResultList.java │ │ ├── ActionResultObj.java │ │ └── IActionResult.java │ │ ├── service │ │ ├── DictService.java │ │ ├── FileService.java │ │ ├── OrgService.java │ │ ├── MenuService.java │ │ └── AreaService.java │ │ └── domain │ │ ├── EOpenUser.java │ │ ├── EAuthority.java │ │ ├── ERole.java │ │ ├── EAuthorization.java │ │ ├── EFile.java │ │ ├── EDict.java │ │ ├── EAccessToken.java │ │ ├── EUser.java │ │ └── EAccount.java ├── build.gradle └── sqls │ └── oauth.sql ├── .gitignore ├── api-gateway ├── src │ ├── test │ │ ├── resources │ │ │ └── bootstrap.yml │ │ └── java │ │ │ └── com │ │ │ └── dataagg │ │ │ └── security │ │ │ ├── UserPrincipal.java │ │ │ └── service │ │ │ └── SysUserDetailsServiceTest.java │ └── main │ │ ├── java │ │ └── com │ │ │ └── dataagg │ │ │ ├── APIGatewayApplication.java │ │ │ └── security │ │ │ └── config │ │ │ └── MethodSecurityConfig.java │ │ └── resources │ │ └── application.yml └── build.gradle ├── core-service ├── src │ ├── test │ │ ├── resources │ │ │ └── bootstrap.yml │ │ └── java │ │ │ └── com │ │ │ └── dataagg │ │ │ ├── commons │ │ │ ├── service │ │ │ │ └── DictServiceTest.java │ │ │ ├── dao │ │ │ │ ├── RoleDaoTest.java │ │ │ │ └── MenuDaoTest.java │ │ │ └── controller │ │ │ │ ├── DictControllerTest.java │ │ │ │ ├── AreaControllerTest.java │ │ │ │ └── OrgControllerTest.java │ │ │ ├── CoreServiceApplicationTests.java │ │ │ └── account │ │ │ └── controller │ │ │ └── AccountControllerTest.java │ └── main │ │ ├── java │ │ └── com │ │ │ └── dataagg │ │ │ ├── commons │ │ │ ├── vo │ │ │ │ └── VLogin.java │ │ │ └── controller │ │ │ │ ├── DictController.java │ │ │ │ └── MenuController.java │ │ │ ├── account │ │ │ ├── client │ │ │ │ └── SecurityServiceClient.java │ │ │ ├── dao │ │ │ │ └── AuthorizationDao.java │ │ │ ├── service │ │ │ │ ├── AccountService.java │ │ │ │ └── AccountServiceImpl.java │ │ │ └── controller │ │ │ │ ├── ErrorHandler.java │ │ │ │ └── AccountController.java │ │ │ └── CoreServiceApplication.java │ │ └── resources │ │ └── application.yml └── build.gradle ├── LICENSE ├── .vscode └── settings.json ├── project.md ├── README.md └── README_zh.md /codegen/build.bat: -------------------------------------------------------------------------------- 1 | @call jset.bat 2 | gradle idea bootrepackage -p .. -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':commons' 2 | include ':api-gateway' 3 | include ':core-service' 4 | -------------------------------------------------------------------------------- /codegen/wCodeGen-all-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataAgg/DAFramework/HEAD/codegen/wCodeGen-all-1.0.jar -------------------------------------------------------------------------------- /codegen/run.bat: -------------------------------------------------------------------------------- 1 | ::docker-compose -f docker-compose.base.yml up -d 2 | ::docker-compose up 3 | gradle bootRun -p .. 4 | :: gradle bootDebug -p .. -------------------------------------------------------------------------------- /service-center/src/test/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: service-center 4 | server: 5 | port: 8761 6 | logging: 7 | level: 8 | root: WARN 9 | -------------------------------------------------------------------------------- /codegen/bootrun.bat: -------------------------------------------------------------------------------- 1 | call jset.bat 2 | ::start gradle bootrun -p ../service-center 3 | ::sleep 15 4 | start gradle bootrun -p ../api-gateway 5 | start gradle bootrun -p ../core-service 6 | -------------------------------------------------------------------------------- /codegen/codegen.bat: -------------------------------------------------------------------------------- 1 | @java -cp wCodeGen-all-1.0.jar io.github.datasays.codeGen2.ProjectGen projects.yml 2 | @java -cp wCodeGen-all-1.0.jar io.github.datasays.codeGen2.GradleGen gradle.yml 3 | gradle idea eclipse classes -p .. -------------------------------------------------------------------------------- /commons/src/test/java/com/dataagg/util/TextUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import org.junit.Before; 4 | 5 | public class TextUtilTest { 6 | 7 | @Before 8 | public void setUp() throws Exception { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /codegen/DAFramework/service-center.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: service-center 4 | server: 5 | context-path: /service-center 6 | port: 8761 7 | logging: 8 | level: 9 | root: WARN 10 | eureka: 11 | instance: 12 | prefer-ip-address: true 13 | client: 14 | registerWithEureka: false 15 | fetchRegistry: false 16 | server: 17 | waitTimeInMsWhenSyncEmpty: 0 18 | -------------------------------------------------------------------------------- /service-center/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: service-center 4 | server: 5 | port: 8761 6 | logging: 7 | level: 8 | root: WARN 9 | eureka: 10 | instance: 11 | prefer-ip-address: true 12 | client: 13 | registerWithEureka: false 14 | fetchRegistry: false 15 | serviceUrl: 16 | defaultZone: http://service-center:8761/eureka/ 17 | -------------------------------------------------------------------------------- /codegen/DAFramework/service-center-test.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: service-center 4 | server: 5 | context-path: /service-center 6 | port: 8761 7 | logging: 8 | level: 9 | root: WARN 10 | eureka: 11 | instance: 12 | prefer-ip-address: true 13 | client: 14 | registerWithEureka: false 15 | fetchRegistry: false 16 | server: 17 | waitTimeInMsWhenSyncEmpty: 0 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.ipr 3 | *.iws 4 | *.jar 5 | .checkstyle 6 | .class 7 | .classpath 8 | .idea 9 | .mymetadata 10 | .project 11 | .rar 12 | .war 13 | .zip 14 | **/.gradle/ 15 | **/.idea/ 16 | **/.settings/ 17 | **/.svn/ 18 | **/bin/ 19 | **/build/ 20 | **/node_modules/ 21 | **/target/ 22 | **/xtend-gen/ 23 | **/out/ 24 | **/npm-debug.log 25 | **/yarn.lock 26 | /gateway/src/main/resources/public 27 | /core-service/src/main/resources/public 28 | -------------------------------------------------------------------------------- /api-gateway/src/test/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: api-gateway 4 | datasource: 5 | driver-class-name: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull 7 | username: dataagg 8 | password: 3yXcH7AIK7Wrs1sQeGJe 9 | server: 10 | port: 80 11 | logging: 12 | level: 13 | root: WARN 14 | -------------------------------------------------------------------------------- /core-service/src/test/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: core-service 4 | datasource: 5 | driver-class-name: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull 7 | username: dataagg 8 | password: 3yXcH7AIK7Wrs1sQeGJe 9 | server: 10 | port: 6000 11 | logging: 12 | level: 13 | root: WARN 14 | -------------------------------------------------------------------------------- /api-gateway/src/test/java/com/dataagg/security/UserPrincipal.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.security; 2 | 3 | import java.security.Principal; 4 | 5 | public class UserPrincipal implements Principal { 6 | private String name; 7 | 8 | public UserPrincipal(String name) { 9 | this.name = name; 10 | } 11 | 12 | @Override 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/WJsonExclued.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.FIELD; 7 | import static java.lang.annotation.ElementType.TYPE_USE; 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | @Retention(RUNTIME) 11 | @Target({FIELD, TYPE_USE}) 12 | public @interface WJsonExclued { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/dataagg/APIGatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.dataagg; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 6 | 7 | @SpringBootApplication 8 | @EnableZuulProxy 9 | public class APIGatewayApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(APIGatewayApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /commons/src/test/java/com/dataagg/util/OAuth2RestHelperTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | public class OAuth2RestHelperTest { 10 | 11 | @Before 12 | public void setUp() throws Exception {} 13 | 14 | @After 15 | public void tearDown() throws Exception {} 16 | 17 | @Test 18 | public void testGetAccessToken() { 19 | fail("Not yet implemented"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /service-center/src/main/java/com/dataagg/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.dataagg; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class EurekaServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(EurekaServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /commons/src/test/java/com/dataagg/util/lang/MoneyUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.lang; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class MoneyUtilTest { 8 | @Test() 9 | public void testGetWeightedAverage1() { 10 | Double d1 = 150d; 11 | Double d2 = 149d; 12 | Long q1 = 0L; 13 | Long q2 = 1L; 14 | Double result = MoneyUtil.getWeightedAverage(d1, q1, d2, q2); 15 | assertEquals(149d, result.doubleValue(), 2); 16 | } 17 | 18 | @Test() 19 | public void testGetWeightedAverage2() { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /codegen/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | api-gateway: 4 | image: java:8-jre 5 | volumes: ['../api-gateway/build/libs/:/app/'] 6 | ports: ['80:80'] 7 | expose: [80] 8 | command: [java, '-Djava.security.egd=file:/dev/./urandom', -Xmx200m, -jar, /app/app.jar] 9 | core-service: 10 | image: java:8-jre 11 | volumes: ['../core-service/build/libs/:/app/'] 12 | ports: ['6000:6000'] 13 | expose: [6000] 14 | command: [java, '-Djava.security.egd=file:/dev/./urandom', -Xmx200m, -jar, /app/app.jar] 15 | depends_on: [api-gateway] 16 | -------------------------------------------------------------------------------- /codegen/DAFramework/security.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: security 4 | datasource: 5 | driver-class-name: com.mysql.jdbc.Driver 6 | url: jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 7 | username: dataagg 8 | password: EdIyNje2GsRyzPDXQfp1 9 | server: 10 | context-path: /security 11 | port: 5000 12 | logging: 13 | level: 14 | root: WARN 15 | eureka: 16 | instance: 17 | prefer-ip-address: true 18 | client: 19 | serviceUrl: 20 | defaultZone: http://service-center:8761/eureka/ 21 | -------------------------------------------------------------------------------- /codegen/docker-compose.base.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | rabbitmq: 4 | image: rabbitmq:3-management 5 | restart: always 6 | ports: 7 | - 15672:15672 8 | logging: 9 | options: 10 | max-size: "10m" 11 | max-file: "10" 12 | 13 | # mongodb: 14 | # environment: 15 | # INIT_DUMP: account-dump.js 16 | # MONGODB_PASSWORD: YFzCAfocMInyJ5YaO805 17 | # build: 18 | # context: ./mongodb 19 | # dockerfile: Dockerfile 20 | # restart: always 21 | # logging: 22 | # options: 23 | # max-size: "10m" 24 | # max-file: "10" 25 | 26 | -------------------------------------------------------------------------------- /codegen/DAFramework/security-test.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: security 4 | datasource: 5 | driver-class-name: com.mysql.jdbc.Driver 6 | url: jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 7 | username: dataagg 8 | password: EdIyNje2GsRyzPDXQfp1 9 | server: 10 | context-path: /security 11 | port: 5000 12 | logging: 13 | level: 14 | root: WARN 15 | eureka: 16 | instance: 17 | prefer-ip-address: true 18 | client: 19 | serviceUrl: 20 | defaultZone: http://service-center:8761/eureka/ 21 | enabled: false 22 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/commons/vo/VLogin.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | public class VLogin implements Serializable { 6 | private static final long serialVersionUID = 5916516763070125465L; 7 | private String username; 8 | private String password; 9 | 10 | public String getUsername() { 11 | return username; 12 | } 13 | 14 | public void setUsername(String username) { 15 | this.username = username; 16 | } 17 | 18 | public String getPassword() { 19 | return password; 20 | } 21 | 22 | public void setPassword(String password) { 23 | this.password = password; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/OrgDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import com.dataagg.commons.domain.EOrg; 4 | 5 | import javax.sql.DataSource; 6 | 7 | import org.nutz.dao.impl.NutDao; 8 | import org.nutz.service.IdEntityService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * 机构管理DAO 14 | * Created by carlos on 2017/3/29. 15 | */ 16 | @Component 17 | public class OrgDao extends IdEntityService { 18 | 19 | @Autowired 20 | public OrgDao(@Autowired DataSource dataSource) { 21 | super(new NutDao(dataSource)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/account/client/SecurityServiceClient.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.account.client; 2 | 3 | import com.dataagg.commons.domain.EUser; 4 | import org.springframework.cloud.netflix.feign.FeignClient; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | 9 | @FeignClient(name = "security", url = "/security") 10 | public interface SecurityServiceClient { 11 | @RequestMapping(method = RequestMethod.POST, value = "/users", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) 12 | void createUser(EUser user); 13 | } 14 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/FileDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import com.dataagg.commons.domain.EFile; 4 | 5 | import javax.sql.DataSource; 6 | 7 | import org.nutz.dao.impl.NutDao; 8 | import org.nutz.service.IdEntityService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * 附件管理DAO 14 | * Created by carlos on 2017/3/29. 15 | */ 16 | @Component 17 | public class FileDao extends IdEntityService { 18 | 19 | @Autowired 20 | public FileDao(@Autowired DataSource dataSource) { 21 | super(new NutDao(dataSource)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/account/dao/AuthorizationDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.account.dao; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.nutz.dao.impl.NutDao; 6 | import org.nutz.service.IdEntityService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Component; 9 | 10 | import com.dataagg.commons.domain.EAuthorization; 11 | 12 | /** 13 | * Created by watano on 2017/3/1. 14 | */ 15 | @Component 16 | public class AuthorizationDao extends IdEntityService { 17 | @Autowired 18 | public AuthorizationDao(@Autowired DataSource dataSource) { 19 | super(new NutDao(dataSource)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/IdGen.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.util.UUID; 4 | 5 | import org.springframework.context.annotation.Lazy; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * 封装各种生成唯一性ID算法的工具类. 10 | * @author carlos 2017年3月31日 16:37:51 11 | */ 12 | @Service 13 | @Lazy(false) 14 | public class IdGen { 15 | 16 | /** 17 | * 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割. 18 | */ 19 | public static String uuid() { 20 | return UUID.randomUUID().toString().replaceAll("-", ""); 21 | } 22 | 23 | public static void main(String[] args) { 24 | System.out.println(IdGen.uuid()); 25 | System.out.println(IdGen.uuid().length()); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/collection/ListTraverser.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.collection; 2 | 3 | import java.util.List; 4 | 5 | public class ListTraverser { 6 | private List list = null; 7 | public Object input = null; 8 | 9 | public ListTraverser(List l) { 10 | list = l; 11 | input = null; 12 | } 13 | 14 | public ListTraverser(List l, Object obj) { 15 | list = l; 16 | input = obj; 17 | } 18 | 19 | public List getList() { 20 | return list; 21 | } 22 | 23 | public Object getInput() { 24 | return input; 25 | } 26 | 27 | public void doAction(Object key) { 28 | System.err.println(key); 29 | } 30 | 31 | public Object getResult() { 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/vo/ActionResult.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.vo; 2 | 3 | /** 4 | * Created by watano on 2016/12/22. 5 | */ 6 | public class ActionResult implements IActionResult{ 7 | private int code; 8 | private String message; 9 | private T data; 10 | 11 | public int getCode() { 12 | return code; 13 | } 14 | 15 | public void setCode(int code) { 16 | this.code = code; 17 | } 18 | 19 | public String getMessage() { 20 | return message; 21 | } 22 | 23 | public void setMessage(String message) { 24 | this.message = message; 25 | } 26 | 27 | public T getData() { 28 | return data; 29 | } 30 | 31 | public void setData(T data) { 32 | this.data = data; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/WPage.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | public class WPage { 4 | private int from = 0; //开始索引 5 | private int size = 20; //每页数量 6 | private Integer total = 0; //总数 7 | 8 | public int getFrom() { 9 | return from; 10 | } 11 | 12 | public void setFrom(int from) { 13 | this.from = from; 14 | } 15 | 16 | public int getSize() { 17 | return size; 18 | } 19 | 20 | public void setSize(int size) { 21 | this.size = size; 22 | } 23 | 24 | public Integer getTotal() { 25 | return total; 26 | } 27 | 28 | public void setTotal(Integer total) { 29 | this.total = total; 30 | } 31 | 32 | public void nextItem() { 33 | from++; 34 | } 35 | 36 | public void preItem() { 37 | from--; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /commons/src/test/java/com/dataagg/util/CryptoUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import org.junit.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import static org.junit.Assert.assertNotNull; 8 | 9 | public class CryptoUtilTest { 10 | private static final Logger LOG = LoggerFactory.getLogger(CryptoUtilTest.class); 11 | 12 | @Test 13 | public void testAll() { 14 | long starttime = System.currentTimeMillis(); 15 | try { 16 | for (int i = 0; i < 10000; i++) { 17 | assertNotNull(CryptoUtil.encrypt(System.currentTimeMillis() + "4--]tFyI;hU!'ct^+c}swatano")); 18 | } 19 | } catch (Exception e) { 20 | assertNotNull(e); 21 | } 22 | LOG.debug("total time:" + (System.currentTimeMillis() - starttime) + "ms"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/vo/ActionResultList.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.vo; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by watano on 2016/12/22. 7 | */ 8 | public class ActionResultList implements IActionResult> { 9 | private int code; 10 | private String message; 11 | private List data; 12 | 13 | public int getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(int code) { 18 | this.code = code; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | 25 | public void setMessage(String message) { 26 | this.message = message; 27 | } 28 | 29 | public List getData() { 30 | return data; 31 | } 32 | 33 | public void setData(List data) { 34 | this.data = data; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /api-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: api-gateway 4 | datasource: 5 | driver-class-name: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull 7 | username: dataagg 8 | password: 3yXcH7AIK7Wrs1sQeGJe 9 | server: 10 | port: 80 11 | logging: 12 | level: 13 | root: WARN 14 | com.dataagg: info 15 | ribbon: 16 | ReadTimeout: 20000 17 | ConnectTimeout: 20000 18 | eureka: 19 | enabled: false 20 | zuul: 21 | host: 22 | connect-timeout-millis: 20000 23 | socket-timeout-millis: 20000 24 | routes: 25 | core: 26 | path: /** 27 | url: http://127.0.0.1:6000/ 28 | stripPrefix: false 29 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/oauth/WXAuthorizationCodeAccessTokenProvider.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.oauth; 2 | 3 | import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider; 4 | 5 | /** 6 | * Created by watano on 2017/3/20. 7 | */ 8 | public class WXAuthorizationCodeAccessTokenProvider extends AuthorizationCodeAccessTokenProvider { 9 | public WXAuthorizationCodeAccessTokenProvider(){ 10 | super(); 11 | setAuthorizationRequestEnhancer((request, resource, form, headers) -> { 12 | form.set("appid", resource.getClientId()); 13 | form.set("secret", resource.getClientSecret()); 14 | form.set("scope", "snsapi_userinfo"); 15 | form.set("response_type", "code"); 16 | form.set("#wechat_redirect", ""); 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/vo/ActionResultObj.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.vo; 2 | 3 | /** 4 | * Created by watano on 2016/12/22. 5 | */ 6 | public class ActionResultObj implements IActionResult { 7 | private int code; 8 | private String message; 9 | private Object data; 10 | 11 | @Override 12 | public int getCode() { 13 | return code; 14 | } 15 | 16 | @Override 17 | public void setCode(int code) { 18 | this.code = code; 19 | } 20 | 21 | @Override 22 | public String getMessage() { 23 | return message; 24 | } 25 | 26 | @Override 27 | public void setMessage(String message) { 28 | this.message = message; 29 | } 30 | 31 | @Override 32 | public Object getData() { 33 | return data; 34 | } 35 | 36 | @Override 37 | public void setData(Object data) { 38 | this.data = data; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /codegen/DAFramework/api-gateway.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: api-gateway 4 | server: 5 | context-path: /api-gateway 6 | port: 80 7 | logging: 8 | level: 9 | root: WARN 10 | eureka: 11 | instance: 12 | prefer-ip-address: true 13 | client: 14 | serviceUrl: 15 | defaultZone: http://service-center:8761/eureka/ 16 | ribbon: 17 | ReadTimeout: 20000 18 | ConnectTimeout: 20000 19 | zuul: 20 | ignoredServices: '*' 21 | host: 22 | connect-timeout-millis: 20000 23 | socket-timeout-millis: 20000 24 | routes: 25 | security: 26 | path: /security/** 27 | url: http://security:5000 28 | stripPrefix: false 29 | sensitiveHeaders: '' 30 | account: 31 | path: /account/** 32 | serviceId: http://account:6000 33 | stripPrefix: false 34 | sensitiveHeaders: '' 35 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/collection/MapTraverser.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.collection; 2 | 3 | import java.util.Map; 4 | 5 | public class MapTraverser { 6 | private Map map = null; 7 | protected Object input = null; 8 | 9 | public MapTraverser(Map m) { 10 | map = m; 11 | } 12 | 13 | public MapTraverser(Map m, Object obj) { 14 | map = m; 15 | input = obj; 16 | } 17 | 18 | public Map getMap() { 19 | return map; 20 | } 21 | 22 | public Object getInput() { 23 | return input; 24 | } 25 | 26 | public void doAction(Object key, Object value) { 27 | System.err.println(key + "--" + value); 28 | } 29 | 30 | public Object getResult() { 31 | return input; 32 | } 33 | // public MapTraverser setInput(Object input) { 34 | // this.input = input; 35 | // return this; 36 | // } 37 | } 38 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/account/service/AccountService.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.account.service; 2 | 3 | import com.dataagg.commons.domain.EAccount; 4 | import com.dataagg.commons.domain.EUser; 5 | 6 | public interface AccountService { 7 | 8 | /** 9 | * Finds account by given name 10 | * 11 | * @param accountName 12 | * @return found account 13 | */ 14 | EAccount findByName(String accountName); 15 | 16 | /** 17 | * Checks if account with the same name already exists 18 | * Invokes Auth Service user creation 19 | * Creates new account with default parameters 20 | * 21 | * @param user 22 | * @return created account 23 | */ 24 | EAccount create(EUser user); 25 | 26 | /** 27 | * save EAccount info 28 | * @param name 29 | * @param account 30 | */ 31 | void saveAccount(String name, EAccount account); 32 | } 33 | -------------------------------------------------------------------------------- /codegen/DAFramework/api-gateway-test.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: api-gateway 4 | server: 5 | context-path: /api-gateway 6 | port: 80 7 | logging: 8 | level: 9 | root: WARN 10 | eureka: 11 | instance: 12 | prefer-ip-address: true 13 | client: 14 | serviceUrl: 15 | defaultZone: http://service-center:8761/eureka/ 16 | enabled: false 17 | ribbon: 18 | ReadTimeout: 20000 19 | ConnectTimeout: 20000 20 | zuul: 21 | ignoredServices: '*' 22 | host: 23 | connect-timeout-millis: 20000 24 | socket-timeout-millis: 20000 25 | routes: 26 | security: 27 | path: /security/** 28 | url: http://security:5000 29 | stripPrefix: false 30 | sensitiveHeaders: '' 31 | account: 32 | path: /account/** 33 | serviceId: http://account:6000 34 | stripPrefix: false 35 | sensitiveHeaders: '' 36 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/account/controller/ErrorHandler.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.account.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.web.bind.annotation.ControllerAdvice; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.bind.annotation.ResponseStatus; 9 | 10 | @ControllerAdvice 11 | public class ErrorHandler { 12 | private final Logger log = LoggerFactory.getLogger(getClass()); 13 | 14 | // TODO add MethodArgumentNotValidException handler 15 | // TODO remove such general handler 16 | @ExceptionHandler(IllegalArgumentException.class) 17 | @ResponseStatus(HttpStatus.BAD_REQUEST) 18 | public void processValidationError(IllegalArgumentException e) { 19 | log.info("Returning HTTP 400 Bad Request", e); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/vo/IActionResult.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.vo; 2 | 3 | /** 4 | * Created by watano on 2016/12/22. 5 | */ 6 | public interface IActionResult { 7 | public int getCode(); 8 | 9 | public String getMessage(); 10 | 11 | public void setCode(int code); 12 | 13 | public void setMessage(String msg); 14 | 15 | public void setData(T data); 16 | 17 | public T getData(); 18 | 19 | public default void msg(int code, String msg) { 20 | this.setCode(code); 21 | this.setMessage(msg); 22 | } 23 | 24 | public default void errorMsg(String msg) { 25 | this.msg(-1, msg); 26 | } 27 | 28 | public default void okMsg(String msg) { 29 | this.msg(1, msg); 30 | } 31 | 32 | public default void ok(T data){ 33 | this.setData(data); 34 | okMsg(""); 35 | } 36 | 37 | public default void error(Throwable t) { 38 | this.msg(-100, t.getMessage()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /service-center/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'eclipse' 4 | id 'idea' 5 | id 'org.springframework.boot' version '1.5.3.RELEASE' 6 | } 7 | 8 | group = 'com.dataagg' 9 | version = '0.1' 10 | description = """eurekaServer(服务注册及发现)""" 11 | 12 | dependencies { 13 | testCompile 'org.springframework.boot:spring-boot-starter-test' 14 | compile 'org.springframework.cloud:spring-cloud-starter-eureka-server' 15 | } 16 | 17 | dependencyManagement { 18 | imports { mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE' } 19 | } 20 | 21 | jar { 22 | baseName = 'service-center' 23 | version = '0.1' 24 | archiveName = 'app.jar' 25 | } 26 | 27 | sourceCompatibility = 1.8 28 | targetCompatibility = 1.8 29 | 30 | tasks.withType(JavaCompile) { 31 | sourceCompatibility = 1.8 32 | targetCompatibility = 1.8 33 | options.encoding = "UTF-8" 34 | } 35 | configurations { 36 | published 37 | } 38 | 39 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/oauth/OAuth2ClientResources.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.oauth; 2 | 3 | import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; 4 | import org.springframework.boot.context.properties.NestedConfigurationProperty; 5 | import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails; 6 | 7 | /** 8 | * Created by watano on 2017/3/19. 9 | */ 10 | public class OAuth2ClientResources { 11 | @NestedConfigurationProperty 12 | private AuthorizationCodeResourceDetails client = new AuthorizationCodeResourceDetails(); 13 | 14 | @NestedConfigurationProperty 15 | private ResourceServerProperties resource = new ResourceServerProperties(); 16 | 17 | public AuthorizationCodeResourceDetails getClient() { 18 | return client; 19 | } 20 | 21 | public ResourceServerProperties getResource() { 22 | return resource; 23 | } 24 | } -------------------------------------------------------------------------------- /core-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: core-service 4 | datasource: 5 | driver-class-name: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull 7 | username: dataagg 8 | password: 3yXcH7AIK7Wrs1sQeGJe 9 | server: 10 | port: 6000 11 | logging: 12 | level: 13 | root: WARN 14 | com.dataagg: info 15 | security: 16 | oauth2: 17 | resource: 18 | user-info-uri: http://api-gateway:5000/security/users/current 19 | client: 20 | clientId: core-service 21 | clientSecret: YFzCAfocMInyJ5YaO805 22 | accessTokenUri: http://api-gateway:5000/security/oauth/token 23 | grant-type: client_credentials 24 | scope: server 25 | file: 26 | rootPath: e:\\wdtc\\html 27 | filePath: /files 28 | sms: 29 | canSend: false 30 | -------------------------------------------------------------------------------- /codegen/DAFramework/account.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: account 4 | datasource: 5 | driver-class-name: com.mysql.jdbc.Driver 6 | url: jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 7 | username: dataagg 8 | password: EdIyNje2GsRyzPDXQfp1 9 | server: 10 | context-path: /account 11 | port: 6000 12 | logging: 13 | level: 14 | root: WARN 15 | eureka: 16 | instance: 17 | prefer-ip-address: true 18 | client: 19 | serviceUrl: 20 | defaultZone: http://service-center:8761/eureka/ 21 | security: 22 | oauth2: 23 | resource: 24 | user-info-uri: http://security:5000/security/users/current 25 | client: 26 | clientId: account 27 | clientSecret: YFzCAfocMInyJ5YaO805 28 | accessTokenUri: http://security:5000/security/oauth/token 29 | grant-type: client_credentials 30 | scope: server 31 | -------------------------------------------------------------------------------- /codegen/DAFramework/account-test.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: account 4 | datasource: 5 | driver-class-name: com.mysql.jdbc.Driver 6 | url: jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 7 | username: dataagg 8 | password: EdIyNje2GsRyzPDXQfp1 9 | server: 10 | context-path: /account 11 | port: 6000 12 | logging: 13 | level: 14 | root: WARN 15 | eureka: 16 | instance: 17 | prefer-ip-address: true 18 | client: 19 | serviceUrl: 20 | defaultZone: http://service-center:8761/eureka/ 21 | enabled: false 22 | security: 23 | oauth2: 24 | resource: 25 | user-info-uri: http://security:5000/security/users/current 26 | client: 27 | clientId: account 28 | clientSecret: YFzCAfocMInyJ5YaO805 29 | accessTokenUri: http://security:5000/security/oauth/token 30 | grant-type: client_credentials 31 | scope: server 32 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/AccessTokenDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.nutz.dao.Cnd; 6 | import org.nutz.dao.impl.NutDao; 7 | import org.nutz.service.IdEntityService; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | import com.dataagg.commons.domain.EAccessToken; 14 | 15 | /** 16 | * Created by watano on 2017/3/20. 17 | */ 18 | @Component 19 | public class AccessTokenDao extends IdEntityService { 20 | private final Logger log = LoggerFactory.getLogger(AccessTokenDao.class); 21 | 22 | @Autowired 23 | public AccessTokenDao(@Autowired DataSource dataSource) { 24 | super(new NutDao(dataSource)); 25 | } 26 | 27 | public EAccessToken findByName(String name) { 28 | log.debug("findByName"); 29 | return fetch(Cnd.where("userName", "=", name)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.nutz.dao.Cnd; 6 | import org.nutz.dao.Sqls; 7 | import org.nutz.dao.impl.NutDao; 8 | import org.nutz.service.IdEntityService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | 12 | import com.dataagg.commons.domain.EUser; 13 | 14 | /** 15 | * Created by watano on 2017/2/26. 16 | */ 17 | @Component 18 | public class UserDao extends IdEntityService { 19 | @Autowired 20 | public UserDao(@Autowired DataSource dataSource) { 21 | super(new NutDao(dataSource)); 22 | } 23 | 24 | public EUser fetchByName(String name) { 25 | return fetch(Cnd.where("username", "=", name)); 26 | } 27 | 28 | //FIXME pls polish this codes 29 | public EUser updateRoles(EUser vo) { 30 | dao().execute(Sqls.create("delete from sys_user_role where userid=" + vo.getId())); 31 | return _insertRelation(vo, "roles"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core-service/src/test/java/com/dataagg/commons/service/DictServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.service; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | import com.dataagg.CoreServiceApplication; 10 | import com.dataagg.commons.dao.DictDao; 11 | import com.dataagg.commons.domain.EDict; 12 | 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @SpringBootTest(classes = CoreServiceApplication.class) 15 | public class DictServiceTest { 16 | @Autowired 17 | private DictDao dictDao; 18 | 19 | @Test 20 | public void test() {} 21 | 22 | public void add(String[][] dictList) { 23 | EDict d = null; 24 | int i = 1; 25 | for (String[] dict : dictList) { 26 | d = new EDict(); 27 | d.setType(dict[0]); 28 | d.setValue(dict[1]); 29 | d.setLabel(dict[2]); 30 | d.setDescription(dict[3]); 31 | d.setSort(i); 32 | i++; 33 | dictDao._insert(d); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 云南数聚社 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/Constans.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import jodd.util.StringUtil; 4 | 5 | public class Constans { 6 | /** 7 | * 分页索引 8 | * */ 9 | public static final int Page_No = 1; 10 | /** 11 | * 分页-每页数目 12 | * */ 13 | public static final int Page_Size = 20; 14 | 15 | /** 16 | * 正反 17 | * 正 1 反 0 18 | * 像删除标记,都可以使用 19 | */ 20 | public static class POS_NEG{ 21 | 22 | /** 23 | * 1 正 是 24 | */ 25 | public static final String POS = "1"; 26 | 27 | /** 28 | * 0 反 否 29 | */ 30 | public static final String NEG = "0"; 31 | } 32 | 33 | /** 34 | * 性别 35 | */ 36 | public static class Sex { 37 | /** 38 | * 1 男 39 | */ 40 | public static final String Man = "1"; 41 | /** 42 | * 2 女 43 | */ 44 | public static final String Woman = "2"; 45 | 46 | public static String getLable(String type) { 47 | if(StringUtil.isBlank(type)){ 48 | return ""; 49 | } 50 | switch (type) { 51 | case Man: 52 | return "男"; 53 | case Woman: 54 | return "女"; 55 | default: 56 | return ""; 57 | } 58 | } 59 | } 60 | 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /api-gateway/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'eclipse' 4 | id 'idea' 5 | id 'org.springframework.boot' version '1.5.3.RELEASE' 6 | } 7 | 8 | group = 'com.dataagg' 9 | version = '0.1' 10 | description = """api-gateway(API网关)+security(权限检查服务)""" 11 | 12 | dependencies { 13 | testCompile 'org.springframework.boot:spring-boot-starter-test' 14 | compile 'org.springframework.boot:spring-boot-starter-web' 15 | compile 'org.springframework.cloud:spring-cloud-starter-zuul' 16 | compile 'org.springframework.cloud:spring-cloud-starter-feign' 17 | compile project(':commons') 18 | compile 'mysql:mysql-connector-java:6.0.6' 19 | compile 'org.springframework.boot:spring-boot-starter-jdbc' 20 | } 21 | 22 | dependencyManagement { 23 | imports { mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE' } 24 | } 25 | 26 | jar { 27 | baseName = 'api-gateway' 28 | version = '0.1' 29 | archiveName = 'commons.jar' 30 | } 31 | 32 | sourceCompatibility = 1.8 33 | targetCompatibility = 1.8 34 | 35 | tasks.withType(JavaCompile) { 36 | sourceCompatibility = 1.8 37 | targetCompatibility = 1.8 38 | options.encoding = "UTF-8" 39 | } 40 | configurations { 41 | published 42 | } 43 | 44 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/WPageIterator.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.util.Iterator; 4 | import java.util.List; 5 | 6 | public abstract class WPageIterator implements Iterator { 7 | private WPage page; 8 | private List data = null; 9 | private int dataIndex = 0; 10 | 11 | public WPageIterator() { 12 | super(); 13 | } 14 | 15 | public WPageIterator(WPage page) { 16 | super(); 17 | reset(page); 18 | } 19 | 20 | public WPage getPage() { 21 | return page; 22 | } 23 | 24 | public void reset(WPage page) { 25 | this.page = page; 26 | _search(); 27 | } 28 | 29 | @Override 30 | public boolean hasNext() { 31 | return page != null && page.getTotal() != null && page.getTotal() > 0 && page.getFrom() + 1 <= page.getTotal(); 32 | } 33 | 34 | @Override 35 | public T next() { 36 | if (dataIndex + 1 > data.size()) { 37 | _search(); 38 | } 39 | T d = data.get(dataIndex++); 40 | page.nextItem(); 41 | return d; 42 | } 43 | 44 | public void update(List data, int total) { 45 | this.data = data; 46 | this.page.setTotal(total); 47 | } 48 | 49 | private void _search() { 50 | doSearch(); 51 | dataIndex = 0; 52 | } 53 | 54 | public abstract void doSearch(); 55 | } 56 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/collection/StrMap.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.collection; 2 | 3 | import jodd.util.StringUtil; 4 | 5 | import java.util.LinkedHashMap; 6 | 7 | public class StrMap extends LinkedHashMap { 8 | private static final long serialVersionUID = -2822103329782602109L; 9 | 10 | public StrMap() { 11 | super(); 12 | } 13 | 14 | public StrMap(String... allkv) { 15 | super(); 16 | this.addAll(allkv); 17 | } 18 | 19 | public void addAll(String... allkv) { 20 | if (allkv != null && allkv.length % 2 == 0) { 21 | for (int i = 0; i + 1 < allkv.length; i += 2) { 22 | put(allkv[i], allkv[i + 1]); 23 | } 24 | } 25 | } 26 | 27 | public void putWithoutNull(String key, String value) { 28 | if (value != null) { 29 | put(key, value); 30 | } 31 | } 32 | 33 | public void put(String key, String value, String defaultValue) { 34 | if (value == null && defaultValue != null) { 35 | put(key, defaultValue); 36 | return; 37 | } 38 | put(key, value); 39 | } 40 | 41 | public String eval(String text) { 42 | String out = text; 43 | for (String key : keySet()) { 44 | out = StringUtil.replace(out, "${" + key + "}", get(key)); 45 | } 46 | return out; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /commons/src/test/java/com/dataagg/util/lang/ArithUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.lang; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class ArithUtilsTest { 7 | 8 | @Test 9 | public void testAdd() { 10 | Assert.assertEquals(ArithUtils.add(0d, 0d), 0.0, 10); 11 | Assert.assertEquals(ArithUtils.add(1.00001, 1.0001), 2.00011, 10); 12 | } 13 | 14 | @Test 15 | public void testSub() { 16 | } 17 | 18 | @Test 19 | public void testMul() { 20 | } 21 | 22 | @Test 23 | public void testDivDoubleDouble() { 24 | } 25 | 26 | @Test 27 | public void testDivDoubleDoubleInt() { 28 | } 29 | 30 | @Test 31 | public void testRound() { 32 | Assert.assertEquals(ArithUtils.round(0.1234, 2), 0.12, 10); 33 | Assert.assertEquals(ArithUtils.round(0.0049, 2), 0.00, 10); 34 | Assert.assertEquals(ArithUtils.round(0.0050, 2), 0.01, 10); 35 | Assert.assertEquals(ArithUtils.round(0.0099, 2), 0.01, 10); 36 | Assert.assertEquals(ArithUtils.round(0.0000, 2), 0.00, 10); 37 | Assert.assertEquals(ArithUtils.round(-0.1234, 2), -0.12, 10); 38 | Assert.assertEquals(ArithUtils.round(1234567890.1234, 2), 1234567890.12, 10); 39 | Assert.assertEquals(ArithUtils.round(-1234567890.1234, 2), -1234567890.12, 10); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "*.iml": "explorerExcludedFiles", 4 | "*.ipr": "explorerExcludedFiles", 5 | "*.iws": "explorerExcludedFiles", 6 | "*.jar": "explorerExcludedFiles", 7 | ".checkstyle": "explorerExcludedFiles", 8 | ".class": "explorerExcludedFiles", 9 | ".classpath": "explorerExcludedFiles", 10 | ".idea": "explorerExcludedFiles", 11 | ".mymetadata": "explorerExcludedFiles", 12 | ".project": "explorerExcludedFiles", 13 | ".rar": "explorerExcludedFiles", 14 | ".war": "explorerExcludedFiles", 15 | ".zip": "explorerExcludedFiles", 16 | "**/.gradle/": "explorerExcludedFiles", 17 | "**/.idea/": "explorerExcludedFiles", 18 | "**/.settings/": "explorerExcludedFiles", 19 | "**/.svn/": "explorerExcludedFiles", 20 | "**/bin/": "explorerExcludedFiles", 21 | "**/build/": "explorerExcludedFiles", 22 | "**/node_modules/": "explorerExcludedFiles", 23 | "**/target/": "explorerExcludedFiles", 24 | "**/xtend-gen/": "explorerExcludedFiles", 25 | "**/out/": "explorerExcludedFiles", 26 | "**/npm-debug.log": "explorerExcludedFiles", 27 | "**/yarn.lock": "explorerExcludedFiles", 28 | "gateway/src/main/resources/public": "explorerExcludedFiles" 29 | } 30 | } -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/SearchQueryJS.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.nutz.dao.pager.Pager; 6 | 7 | public class SearchQueryJS implements Serializable{ 8 | private static final long serialVersionUID = -559520775581829448L; 9 | private WPage page;//分页信息 10 | private WMap query;//查询条件 11 | 12 | public WPage getPage() { 13 | return page; 14 | } 15 | 16 | public void setPage(WPage page) { 17 | this.page = page; 18 | } 19 | 20 | public WMap getQuery() { 21 | return query; 22 | } 23 | 24 | public void setQuery(WMap query) { 25 | this.query = query; 26 | } 27 | 28 | public Pager toPager(){ 29 | if(page != null){ 30 | return new Pager(page.getFrom(), page.getSize()); 31 | } 32 | return new Pager(Constans.Page_No, Constans.Page_Size); 33 | } 34 | public Pager toPager(int pageSize){ 35 | if(page != null){ 36 | return new Pager(page.getFrom(), pageSize); 37 | } 38 | return new Pager(Constans.Page_No, pageSize); 39 | } 40 | public WPage toWPage(Pager pager){ 41 | WPage page = new WPage(); 42 | if(pager != null){ 43 | page.setFrom(pager.getPageNumber()); 44 | page.setSize(pager.getPageSize()); 45 | page.setTotal(pager.getRecordCount()); 46 | } 47 | return page; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /commons/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'eclipse' 4 | id 'idea' 5 | } 6 | 7 | group = 'com.dataagg' 8 | version = '0.1' 9 | description = """公用实体类,VO及常用工具类""" 10 | 11 | dependencies { 12 | compile 'org.jodd:jodd-core:3.8.5' 13 | compile 'org.jodd:jodd-bean:3.8.5' 14 | compile 'org.jodd:jodd-props:3.8.5' 15 | compile 'com.google.code.gson:gson:2.8.0' 16 | compile 'org.nutz:nutz:1.r.61' 17 | compile 'mysql:mysql-connector-java:6.0.6' 18 | compile 'org.springframework.boot:spring-boot-starter-jdbc:1.5.3.RELEASE' 19 | compile 'org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE' 20 | compile 'org.springframework.boot:spring-boot-starter-security:1.5.3.RELEASE' 21 | compile 'org.springframework.security:spring-security-core:4.2.2.RELEASE' 22 | compile 'org.springframework.security.oauth:spring-security-oauth2:2.0.13.RELEASE' 23 | testCompile 'junit:junit:4.12' 24 | testCompile 'org.springframework.boot:spring-boot-starter-test:1.5.3.RELEASE' 25 | } 26 | 27 | jar { 28 | baseName = 'commons' 29 | version = '0.1' 30 | archiveName = 'commons.jar' 31 | } 32 | 33 | sourceCompatibility = 1.8 34 | targetCompatibility = 1.8 35 | 36 | tasks.withType(JavaCompile) { 37 | sourceCompatibility = 1.8 38 | targetCompatibility = 1.8 39 | options.encoding = "UTF-8" 40 | } 41 | configurations { 42 | published 43 | } 44 | 45 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/OpenUserDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import java.util.List; 4 | 5 | import javax.sql.DataSource; 6 | 7 | import org.nutz.dao.Cnd; 8 | import org.nutz.dao.impl.NutDao; 9 | import org.nutz.service.IdEntityService; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Component; 14 | 15 | import com.dataagg.commons.domain.EOpenUser; 16 | 17 | /** 18 | * Created by watano on 2017/3/21. 19 | */ 20 | @Component 21 | public class OpenUserDao extends IdEntityService { 22 | private final Logger log = LoggerFactory.getLogger(OpenUserDao.class); 23 | 24 | @Autowired 25 | public OpenUserDao(@Autowired DataSource dataSource) { 26 | super(new NutDao(dataSource)); 27 | } 28 | 29 | public EOpenUser createOrFind(EOpenUser openUser) { 30 | EOpenUser newEOpenUser = fetch(Cnd.where("clientId", "=", openUser.getClientId()).and("openId", "=", openUser.getOpenId())); 31 | if (newEOpenUser == null) { 32 | newEOpenUser = _insert(openUser); 33 | } 34 | log.debug("createOrFind"); 35 | return newEOpenUser; 36 | } 37 | 38 | public List findByName(String userName) { 39 | return query(Cnd.where("clientName", "=", userName)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core-service/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'eclipse' 4 | id 'idea' 5 | id 'org.springframework.boot' version '1.5.3.RELEASE' 6 | } 7 | 8 | group = 'com.dataagg' 9 | version = '0.1' 10 | description = """核心服务 用户,组织,角色,菜单,字典,区域,附件等基础服务""" 11 | 12 | dependencies { 13 | testCompile 'org.springframework.boot:spring-boot-starter-test' 14 | compile 'org.springframework.cloud:spring-cloud-starter-feign' 15 | compile project(':commons') 16 | compile 'org.springframework.boot:spring-boot-starter-web' 17 | compile 'mysql:mysql-connector-java:6.0.6' 18 | compile 'org.springframework.boot:spring-boot-starter-jdbc' 19 | compile 'org.springframework.boot:spring-boot-starter-security' 20 | compile 'org.springframework.security.oauth:spring-security-oauth2' 21 | compile 'org.springframework.cloud:spring-cloud-security:1.1.3.RELEASE' 22 | } 23 | 24 | dependencyManagement { 25 | imports { mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE' } 26 | } 27 | 28 | jar { 29 | baseName = 'core-service' 30 | version = '0.1' 31 | archiveName = 'app.jar' 32 | } 33 | 34 | sourceCompatibility = 1.8 35 | targetCompatibility = 1.8 36 | 37 | tasks.withType(JavaCompile) { 38 | sourceCompatibility = 1.8 39 | targetCompatibility = 1.8 40 | options.encoding = "UTF-8" 41 | } 42 | configurations { 43 | published 44 | } 45 | 46 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/service/DictService.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | 6 | import com.dataagg.commons.domain.EDict; 7 | import com.dataagg.util.Constans; 8 | import com.dataagg.commons.dao.DictDao; 9 | import com.dataagg.commons.service.DictService; 10 | 11 | /** 12 | * 数据字典管理service实现类 13 | * Created by carlos on 2017/3/29. 14 | */ 15 | @Service 16 | public class DictService{ 17 | @Autowired 18 | private DictDao dictDao; 19 | 20 | public EDict insert(EDict dict){ 21 | dict.setDelFlag(Constans.POS_NEG.NEG); 22 | return dictDao._insert(dict); 23 | } 24 | public EDict update(EDict dict){ 25 | dict.setDelFlag(Constans.POS_NEG.NEG); 26 | return dictDao._update(dict) > 0 ? dict : null; 27 | } 28 | public boolean delete(long id) { 29 | EDict dict = dictDao.fetch(id); 30 | if(dict ==null){ 31 | return false; 32 | } 33 | dict.setDelFlag(Constans.POS_NEG.POS); 34 | return dictDao._update(dict)>0 ? true : false; 35 | } 36 | 37 | /** 38 | * 通用的新增和修改方法 39 | * @param dict 40 | * @return 41 | */ 42 | public EDict save(EDict dict){ 43 | if (dict.getId() != null && dict.getId()>0) { 44 | return update(dict); 45 | }else{ 46 | return insert(dict); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/service/FileService.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | 6 | import com.dataagg.commons.domain.EFile; 7 | import com.dataagg.util.Constans; 8 | import com.dataagg.commons.dao.FileDao; 9 | import com.dataagg.commons.service.FileService; 10 | 11 | /** 12 | * 附件管理service实现类 13 | * Created by carlos on 2017/3/29. 14 | */ 15 | @Service 16 | public class FileService{ 17 | @Autowired 18 | private FileDao fileDao; 19 | 20 | public EFile insert(EFile file){ 21 | file.setDelFlag(Constans.POS_NEG.NEG); 22 | return fileDao._insert(file); 23 | } 24 | public EFile update(EFile file){ 25 | file.setDelFlag(Constans.POS_NEG.NEG); 26 | return fileDao._update(file) > 0 ? file : null; 27 | } 28 | public boolean delete(long id) { 29 | EFile file = fileDao.fetch(id); 30 | if(file ==null){ 31 | return false; 32 | } 33 | // file.setDelFlag(Constans.POS_NEG.POS); 34 | return fileDao.delete(file.getId())>0 ? true : false; 35 | } 36 | 37 | /** 38 | * 通用的新增和修改方法 39 | * @param file 40 | * @return 41 | */ 42 | public EFile save(EFile file){ 43 | if (file.getId() != null && file.getId()>0) { 44 | return update(file); 45 | }else{ 46 | return insert(file); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/FindFileUtil.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.io.File; 4 | import java.util.Iterator; 5 | 6 | import jodd.io.findfile.FindFile; 7 | import jodd.io.findfile.WildcardFindFile; 8 | 9 | public class FindFileUtil { 10 | public static Iterator search(boolean recursive, boolean includeDirs, String dir) { 11 | FindFile ff = create(recursive, includeDirs).searchPath(dir); 12 | Iterator iterator = ff.iterator(); 13 | return iterator; 14 | } 15 | 16 | public static Iterator search(boolean recursive, boolean includeDirs, String dir, String fileName) { 17 | FindFile ff = create(recursive, includeDirs).include(fileName).searchPath(dir); 18 | return ff.iterator(); 19 | } 20 | 21 | public static Iterator search(boolean recursive, boolean includeDirs, File dir) { 22 | FindFile ff = create(recursive, includeDirs).searchPath(dir); 23 | Iterator iterator = ff.iterator(); 24 | return iterator; 25 | } 26 | 27 | public static Iterator search(boolean recursive, boolean includeDirs, File dir, String fileName) { 28 | FindFile ff = create(recursive, includeDirs).include(fileName).searchPath(dir); 29 | return ff.iterator(); 30 | } 31 | 32 | public static FindFile create(boolean recursive, boolean includeDirs) { 33 | return new WildcardFindFile().recursive(recursive).includeDirs(includeDirs).includeFiles(true); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/EOpenUser.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.domain; 2 | 3 | import org.nutz.dao.entity.annotation.Column; 4 | import org.nutz.dao.entity.annotation.Comment; 5 | import org.nutz.dao.entity.annotation.Id; 6 | import org.nutz.dao.entity.annotation.Table; 7 | 8 | /** 9 | * Created by watano on 2017/3/21. 10 | */ 11 | @Table("sys_open_user") 12 | @Comment("Open User") 13 | public class EOpenUser { 14 | @Id 15 | private Long id; 16 | @Column 17 | private String clientId; 18 | @Column 19 | private Long userId; 20 | @Column 21 | private String openId; 22 | @Column 23 | private String clientName; 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getClientId() { 34 | return clientId; 35 | } 36 | 37 | public void setClientId(String clientId) { 38 | this.clientId = clientId; 39 | } 40 | 41 | public Long getUserId() { 42 | return userId; 43 | } 44 | 45 | public void setUserId(Long userId) { 46 | this.userId = userId; 47 | } 48 | 49 | public String getOpenId() { 50 | return openId; 51 | } 52 | 53 | public void setOpenId(String openId) { 54 | this.openId = openId; 55 | } 56 | 57 | public String getClientName() { 58 | return clientName; 59 | } 60 | 61 | public void setClientName(String clientName) { 62 | this.clientName = clientName; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/DictDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import java.util.List; 4 | 5 | import javax.sql.DataSource; 6 | 7 | import org.nutz.dao.Cnd; 8 | import org.nutz.dao.impl.NutDao; 9 | import org.nutz.dao.util.cri.SimpleCriteria; 10 | import org.nutz.service.IdEntityService; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | 14 | import com.dataagg.commons.domain.EDict; 15 | 16 | /** 17 | * 数据字典管理DAO Created by carlos on 2017/3/29. 18 | */ 19 | @Component 20 | public class DictDao extends IdEntityService { 21 | 22 | @Autowired 23 | public DictDao(@Autowired DataSource dataSource) { 24 | super(new NutDao(dataSource)); 25 | } 26 | public EDict fecthByTypeAndValue(String type, String value) { 27 | return dao().fetch(EDict.class, Cnd.where("type", "=", type).and("value","=",value)); 28 | } 29 | public String fecthLableByTypeAndValue(String type, String value) { 30 | EDict dict = this.fecthByTypeAndValue(type, value); 31 | if(dict != null){ 32 | return dict.getLabel(); 33 | } 34 | return ""; 35 | } 36 | /** 37 | * 获取具体类型数据字典列表 38 | * @param type 39 | * @return 40 | */ 41 | public List getDictListByType(String type){ 42 | SimpleCriteria simpleCr=Cnd.cri(); 43 | simpleCr.where().and("type", "=", type); 44 | simpleCr.asc("sort"); 45 | return query(simpleCr); 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/AccountDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.nutz.dao.Cnd; 6 | import org.nutz.dao.impl.NutDao; 7 | import org.nutz.service.IdEntityService; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.util.Assert; 13 | 14 | import com.dataagg.commons.domain.EAccount; 15 | import com.dataagg.commons.domain.EUser; 16 | 17 | /** 18 | * Created by watano on 2017/3/21. 19 | */ 20 | @Component 21 | public class AccountDao extends IdEntityService { 22 | private final Logger log = LoggerFactory.getLogger(AccountDao.class); 23 | 24 | @Autowired 25 | public AccountDao(@Autowired DataSource dataSource) { 26 | super(new NutDao(dataSource)); 27 | } 28 | 29 | public EAccount fetch(EUser user) { 30 | if (user == null || user.getId() == null) { return null; } 31 | return fetch(Cnd.where("userId", "=", user.getId())); 32 | } 33 | 34 | public EAccount create(EAccount account) { 35 | Assert.notNull(account, "account不能为null"); 36 | Assert.notNull(account.getUser(), "account中的user不能为null"); 37 | Assert.notNull(account.getUser().getId(), "account中的user.id不能为null"); 38 | account.setUserId(account.getUser().getId()); 39 | log.debug("create account"); 40 | return _insert(account); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/AuthorityDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import javax.sql.DataSource; 8 | 9 | import org.nutz.dao.Cnd; 10 | import org.nutz.dao.impl.NutDao; 11 | import org.nutz.service.IdEntityService; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Component; 14 | 15 | import com.dataagg.commons.domain.EAuthority; 16 | 17 | @Component 18 | public class AuthorityDao extends IdEntityService { 19 | 20 | @Autowired 21 | public AuthorityDao(@Autowired DataSource dataSource) { 22 | super(new NutDao(dataSource)); 23 | } 24 | 25 | public List getDefaultAuthorities() { 26 | return Arrays.asList(fetch(1)); 27 | } 28 | 29 | public EAuthority fetchByName(String name) { 30 | return fetch(Cnd.where("name", "=", name)); 31 | } 32 | 33 | public void insertAll(Map allAuthorities) { 34 | if (allAuthorities != null) { 35 | for (String name : allAuthorities.keySet()) { 36 | EAuthority a = fetchByName(name); 37 | if (a == null) { 38 | a = new EAuthority(); 39 | a.setName(name); 40 | a.setDescription(allAuthorities.get(name)); 41 | _insert(a); 42 | } else { 43 | a.setName(name); 44 | a.setDescription(allAuthorities.get(name)); 45 | _update(a); 46 | } 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /commons/sqls/oauth.sql: -------------------------------------------------------------------------------- 1 | create table oauth_client_details ( 2 | client_id VARCHAR(255) PRIMARY KEY, 3 | resource_ids VARCHAR(255), 4 | client_secret VARCHAR(255), 5 | scope VARCHAR(255), 6 | authorized_grant_types VARCHAR(255), 7 | web_server_redirect_uri VARCHAR(255), 8 | authorities VARCHAR(255), 9 | access_token_validity INTEGER, 10 | refresh_token_validity INTEGER, 11 | additional_information VARCHAR(4096), 12 | autoapprove varchar(255) 13 | ); 14 | 15 | create table oauth_client_token ( 16 | token_id VARCHAR(255), 17 | token BLOB, 18 | authentication_id VARCHAR(255), 19 | user_name VARCHAR(255), 20 | client_id VARCHAR(255) 21 | ); 22 | 23 | create table oauth_access_token ( 24 | token_id VARCHAR(255), 25 | token BLOB, 26 | authentication_id VARCHAR(255), 27 | user_name VARCHAR(255), 28 | client_id VARCHAR(255), 29 | authentication BLOB, 30 | refresh_token VARCHAR(255) 31 | ); 32 | 33 | create table oauth_refresh_token ( 34 | token_id VARCHAR(255), 35 | token BLOB, 36 | authentication BLOB 37 | 38 | ); 39 | 40 | create table oauth_code ( 41 | code VARCHAR(255), authentication BLOB 42 | ); 43 | 44 | create table oauth_approvals ( 45 | userId VARCHAR(256), 46 | clientId VARCHAR(256), 47 | scope VARCHAR(256), 48 | status VARCHAR(10), 49 | expiresAt TIMESTAMP, 50 | lastModifiedAt TIMESTAMP 51 | ); 52 | 53 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/lang/ArgCheck.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.lang; 2 | 3 | import jodd.util.ArraysUtil; 4 | import jodd.util.StringUtil; 5 | 6 | public class ArgCheck { 7 | public static void checkState(boolean b, String msg) { 8 | if (!b) { 9 | throw new IllegalArgumentException(msg); 10 | } 11 | } 12 | 13 | public static void checkState(boolean b) { 14 | if (!b) { 15 | throw new IllegalArgumentException(); 16 | } 17 | } 18 | 19 | public static void checkNotNull(Object object) { 20 | if (object == null) { 21 | throw new IllegalArgumentException(); 22 | } 23 | } 24 | 25 | public static void checkNotNull(Object object, String msg) { 26 | if (object == null) { 27 | throw new IllegalArgumentException(msg); 28 | } 29 | } 30 | 31 | public static void checkNotContains(String possibleValues, String value) { 32 | checkNotContains(StringUtil.split(possibleValues, ","), value); 33 | } 34 | 35 | public static void checkNotContains(String possibleValues, String value, String msg) { 36 | checkNotContains(StringUtil.split(possibleValues, ","), value, msg); 37 | } 38 | 39 | public static void checkNotContains(String[] possibleValues, String value, String msg) { 40 | if (!ArraysUtil.contains(possibleValues, value)) { 41 | throw new IllegalArgumentException(msg); 42 | } 43 | } 44 | 45 | public static void checkNotContains(String[] possibleValues, String value) { 46 | checkNotContains(possibleValues, value, "possible values are [" + possibleValues + "], but value=" + value); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/service/OrgService.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.service; 2 | 3 | import com.dataagg.commons.dao.OrgDao; 4 | import com.dataagg.commons.domain.EOrg; 5 | import com.dataagg.util.Constans; 6 | 7 | import org.nutz.dao.Chain; 8 | import org.nutz.dao.Cnd; 9 | import org.nutz.dao.sql.Criteria; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | /** 14 | * 机构管理service实现类 15 | * Created by carlos on 2017/3/29. 16 | */ 17 | @Service 18 | public class OrgService{ 19 | @Autowired 20 | private OrgDao orgDao; 21 | 22 | public EOrg insert(EOrg org){ 23 | org.setDelFlag(Constans.POS_NEG.NEG); 24 | return orgDao._insert(org); 25 | } 26 | public EOrg update(EOrg org){ 27 | org.setDelFlag(Constans.POS_NEG.NEG); 28 | return orgDao._update(org) > 0 ? org : null; 29 | } 30 | public boolean delete(long id) { 31 | EOrg org = orgDao.fetch(id); 32 | if(org ==null){ 33 | return false; 34 | } 35 | Criteria cnd = Cnd.cri(); 36 | cnd.where().andEquals("id", org.getId()); 37 | cnd.where().orLike("parent_ids", "%,"+org.getId()+",%"); 38 | 39 | Chain chain = Chain.make("del_flag", Constans.POS_NEG.POS); 40 | 41 | return orgDao.update(chain, cnd)>0 ? true : false; 42 | } 43 | 44 | /** 45 | * 通用的新增和修改方法 46 | * @param org 47 | * @return 48 | */ 49 | public EOrg save(EOrg org){ 50 | if (org.getId() != null && org.getId()>0) { 51 | return update(org); 52 | }else{ 53 | return insert(org); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/account/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.account.controller; 2 | 3 | import com.dataagg.commons.domain.EAccount; 4 | import com.dataagg.commons.domain.EUser; 5 | import com.dataagg.account.service.AccountService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.access.prepost.PreAuthorize; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import javax.validation.Valid; 11 | import java.security.Principal; 12 | 13 | @RestController 14 | public class AccountController { 15 | 16 | @Autowired 17 | private AccountService accountService; 18 | 19 | @PreAuthorize("#oauth2.hasScope('server') or #name.equals('demo')") 20 | @RequestMapping(path = "/{name}", method = RequestMethod.GET) 21 | public EAccount getAccountByName(@PathVariable String name) { 22 | return accountService.findByName(name); 23 | } 24 | 25 | @RequestMapping(path = "/current", method = RequestMethod.GET) 26 | public EAccount getCurrentAccount(Principal principal) { 27 | return accountService.findByName(principal.getName()); 28 | } 29 | 30 | @RequestMapping(path = "/current", method = RequestMethod.PUT) 31 | public void saveCurrentAccount(Principal principal, @Valid @RequestBody EAccount account) { 32 | accountService.saveAccount(principal.getName(), account); 33 | } 34 | 35 | @RequestMapping(path = "/", method = RequestMethod.POST) 36 | public EAccount createNewAccount(@Valid @RequestBody EUser user) { 37 | return accountService.create(user); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * author: loserStar 3 | * date: 2017年5月5日下午5:19:25 4 | * email:362527240@qq.com 5 | * github:https://github.com/xinxin321198 6 | * remarks: 7 | */ 8 | package com.dataagg.util; 9 | 10 | /** 11 | * author: loserStar 12 | * date: 2017年5月5日下午5:19:25 13 | * remarks:本系统的文件生成辅助类 14 | */ 15 | public class FileUtil { 16 | /** 17 | * 生成一个以uuid命名的新文件名,保留原后缀 18 | * test.doc -> uuid.doc 19 | * test -> uud 20 | * @param sourceFilename 21 | * @return 22 | */ 23 | public static String generateFileName(String sourceFileName){ 24 | // long time = System.currentTimeMillis(); 25 | String newFileName = IdGen.uuid() + getFileNameSuffix(sourceFileName);// 构成新文件名。 26 | return newFileName; 27 | } 28 | 29 | /** 30 | * 提取文件的文件名,不要后缀 31 | * test.doc -> test 32 | * test -> test 33 | * @param sourceFileName 34 | * @return 35 | */ 36 | public static String getFileNameNotSuffix(String sourceFileName){ 37 | String oldFileName = sourceFileName.indexOf(".") != -1 ? sourceFileName.substring(0, sourceFileName.lastIndexOf(".")) : sourceFileName; 38 | return oldFileName; 39 | } 40 | 41 | /** 42 | * 提取文件的后缀,如果没有后缀返回空字符穿 43 | * test.doc -> .doc 44 | * test -> 45 | * @param sourceFileName 46 | * @return 47 | */ 48 | public static String getFileNameSuffix(String sourceFileName){ 49 | String suffix = sourceFileName.indexOf(".") != -1 ? sourceFileName.substring(sourceFileName.lastIndexOf("."), sourceFileName.length()) : ""; 50 | return suffix; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/EAuthority.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.domain; 2 | 3 | import org.nutz.dao.entity.annotation.ColDefine; 4 | import org.nutz.dao.entity.annotation.ColType; 5 | import org.nutz.dao.entity.annotation.Column; 6 | import org.nutz.dao.entity.annotation.Comment; 7 | import org.nutz.dao.entity.annotation.Id; 8 | import org.nutz.dao.entity.annotation.Table; 9 | import org.springframework.security.core.GrantedAuthority; 10 | 11 | /** 12 | * Created by watano on 2017/3/13. 13 | */ 14 | @Table("sys_authority") 15 | @Comment("权限标识") 16 | public class EAuthority implements GrantedAuthority { 17 | private static final long serialVersionUID = 7423414401567180611L; 18 | @Id 19 | private Long id; 20 | 21 | @Column(hump = true) 22 | @ColDefine(type = ColType.VARCHAR, width = 64, notNull = true) 23 | @Comment("权限标识") 24 | private String name; 25 | 26 | @Column(hump = true) 27 | @ColDefine(type = ColType.VARCHAR, width = 200, notNull = true) 28 | @Comment("描述") 29 | private String description; 30 | 31 | public Long getId() { 32 | return id; 33 | } 34 | 35 | public void setId(Long id) { 36 | this.id = id; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | @Override 48 | public String getAuthority() { 49 | return name; 50 | } 51 | 52 | public String getDescription() { 53 | return description; 54 | } 55 | 56 | public void setDescription(String description) { 57 | this.description = description; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/JsonObjGetter.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class JsonObjGetter { 7 | private Object obj; 8 | 9 | public JsonObjGetter(Object obj) { 10 | super(); 11 | if (obj != null) { 12 | this.obj = obj; 13 | } 14 | } 15 | 16 | public Map map() { 17 | if (obj instanceof Map) { 18 | return (Map) obj; 19 | } 20 | return null; 21 | } 22 | 23 | public List list() { 24 | if (obj instanceof List) { 25 | return (List) obj; 26 | } 27 | return null; 28 | } 29 | 30 | public JsonObjGetter obj(Object key) { 31 | try { 32 | return new JsonObjGetter(map().get(key)); 33 | } catch (Exception e) { 34 | return null; 35 | } 36 | } 37 | 38 | public String str(Object key) { 39 | try { 40 | return (map().get(key)).toString(); 41 | } catch (Exception e) { 42 | return null; 43 | } 44 | } 45 | 46 | public Number num(Object key) { 47 | try { 48 | return (Number) (map().get(key)); 49 | } catch (Exception e) { 50 | return null; 51 | } 52 | } 53 | 54 | public Boolean bool(Object key) { 55 | try { 56 | return (Boolean) (map().get(key)); 57 | } catch (Exception e) { 58 | return null; 59 | } 60 | } 61 | 62 | public Map map(Object key) { 63 | try { 64 | return (Map) (map().get(key)); 65 | } catch (Exception e) { 66 | return null; 67 | } 68 | } 69 | 70 | public List list(Object key) { 71 | try { 72 | return (List) (map().get(key)); 73 | } catch (Exception e) { 74 | return null; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /codegen/sql/create.sql: -------------------------------------------------------------------------------- 1 | SET FOREIGN_KEY_CHECKS=0; 2 | drop table if exists oauth_client_details; 3 | drop table if exists oauth_access_token; 4 | drop table if exists oauth_refresh_token; 5 | drop table if exists oauth_code; 6 | 7 | create table oauth_client_details ( 8 | client_id VARCHAR(50) PRIMARY KEY, 9 | resource_ids VARCHAR(256), 10 | client_secret VARCHAR(256), 11 | scope VARCHAR(256), 12 | `access_token_validity` int(11) DEFAULT NULL, 13 | `refresh_token_validity` int(11) DEFAULT NULL, 14 | `additional_information` varchar(4096) DEFAULT NULL, 15 | `autoapprove` varchar(255) DEFAULT NULL, 16 | authorized_grant_types VARCHAR(256), 17 | web_server_redirect_uri VARCHAR(256), 18 | authorities VARCHAR(256) 19 | ); 20 | 21 | create table oauth_access_token ( 22 | token_id VARCHAR(256), 23 | token blob, 24 | authentication_id VARCHAR(256), 25 | authentication blob, 26 | refresh_token VARCHAR(256) 27 | ); 28 | 29 | create table oauth_refresh_token ( 30 | token_id VARCHAR(256), 31 | token blob, 32 | authentication blob 33 | ); 34 | 35 | create table oauth_code ( 36 | code VARCHAR(256), 37 | authentication blob 38 | ); 39 | 40 | INSERT INTO `oauth_client_details` (`client_id`, `resource_ids`, `client_secret`, `scope`, `access_token_validity`, `refresh_token_validity`, `additional_information`, `autoapprove`, `authorized_grant_types`, `web_server_redirect_uri`, `authorities`) VALUES 41 | ('dataagg', 'security', 'secret', 'account_role', 3600, 3600, '{"scopRangeBy":"role"}', NULL, 'password', NULL, 'ROLE_CLIENT'); 42 | 43 | -------------------------------------------------------------------------------- /core-service/src/test/java/com/dataagg/commons/dao/RoleDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import com.dataagg.CoreServiceApplication; 15 | import com.dataagg.commons.domain.ERole; 16 | 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @SpringBootTest(classes = CoreServiceApplication.class) 19 | public class RoleDaoTest { 20 | @Autowired 21 | private RoleDao roleDao; 22 | 23 | @Before 24 | public void setUp() throws Exception {} 25 | 26 | @After 27 | public void tearDown() throws Exception {} 28 | 29 | @Test 30 | public void testGetDefaultRoles() {} 31 | 32 | @Test 33 | public void testFetchByName() {} 34 | 35 | @Test 36 | public void testFetchFullByName() {} 37 | 38 | @Test 39 | public void testSave() { 40 | ERole adminRole = new ERole(); 41 | adminRole.setId(1L); 42 | adminRole.setName("Admin"); 43 | adminRole.setDescription("系统管理员"); 44 | adminRole = roleDao.save(adminRole); 45 | assertEquals(new Long(1L), adminRole.getId()); 46 | adminRole = roleDao.fetch(1L); 47 | assertNotNull(adminRole); 48 | assertEquals(new Long(1L), adminRole.getId()); 49 | } 50 | 51 | @Test 52 | public void testInsertAll() {} 53 | 54 | @Test 55 | public void testUpdateAuthorities() {} 56 | 57 | } 58 | -------------------------------------------------------------------------------- /api-gateway/src/main/java/com/dataagg/security/config/MethodSecurityConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.dataagg.security.config; 17 | 18 | import org.springframework.context.annotation.Configuration; 19 | import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; 20 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 21 | import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; 22 | import org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler; 23 | 24 | /** 25 | * @author Rob Winch 26 | * @author Dave Syer 27 | * 28 | */ 29 | @Configuration 30 | @EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true) 31 | public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration { 32 | @Override 33 | protected MethodSecurityExpressionHandler createExpressionHandler() { 34 | return new OAuth2MethodSecurityExpressionHandler(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/service/MenuService.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.service; 2 | 3 | import org.nutz.dao.Chain; 4 | import org.nutz.dao.Cnd; 5 | import org.nutz.dao.sql.Criteria; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.dataagg.commons.dao.MenuDao; 10 | import com.dataagg.commons.domain.EMenu; 11 | import com.dataagg.util.Constans; 12 | 13 | /** 14 | * 区域管理service实现类 15 | * Created by carlos on 2017/3/29. 16 | */ 17 | @Service 18 | public class MenuService { 19 | @Autowired 20 | private MenuDao menuDao; 21 | 22 | public EMenu insert(EMenu menu) { 23 | menu.setDelFlag(Constans.POS_NEG.NEG); 24 | return menuDao._insert(menu); 25 | } 26 | 27 | public EMenu update(EMenu menu) { 28 | menu.setDelFlag(Constans.POS_NEG.NEG); 29 | return menuDao._update(menu) > 0 ? menu : null; 30 | } 31 | 32 | public boolean delete(long id) { 33 | EMenu menu = menuDao.fetch(id); 34 | if (menu == null) { return false; } 35 | Criteria cnd = Cnd.cri(); 36 | cnd.where().andEquals("id", menu.getId()); 37 | cnd.where().orLike("parent_ids", "%," + menu.getId() + ",%"); 38 | 39 | Chain chain = Chain.make("del_flag", Constans.POS_NEG.POS); 40 | 41 | return menuDao.update(chain, cnd) > 0 ? true : false; 42 | } 43 | 44 | /** 45 | * 通用的新增和修改方法 46 | * @param menu 47 | * @return 48 | */ 49 | public EMenu save(EMenu menu) { 50 | if (menu.getParentId() != null && menu.getParentId() != 0) { 51 | EMenu parent = menuDao.fetch(menu.getParentId()); 52 | menu.setParentIds(parent.getParentIds() + parent.getId() + ","); 53 | } 54 | if (menu.getId() != null && menu.getId() > 0) { 55 | return update(menu); 56 | } else { 57 | return insert(menu); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/ERole.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.domain; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.nutz.dao.entity.annotation.ColDefine; 7 | import org.nutz.dao.entity.annotation.ColType; 8 | import org.nutz.dao.entity.annotation.Column; 9 | import org.nutz.dao.entity.annotation.Comment; 10 | import org.nutz.dao.entity.annotation.Id; 11 | import org.nutz.dao.entity.annotation.ManyMany; 12 | import org.nutz.dao.entity.annotation.Table; 13 | 14 | /** 15 | * Created by watano on 2017/3/13. 16 | */ 17 | @Table("sys_role") 18 | @Comment("角色信息") 19 | public class ERole { 20 | @Id 21 | @Comment("主键") 22 | private Long id; 23 | 24 | @Column(hump = true) 25 | @ColDefine(type = ColType.VARCHAR, width = 64, notNull = true) 26 | @Comment("角色名") 27 | private String name; 28 | 29 | @Column(hump = true) 30 | @ColDefine(type = ColType.VARCHAR, width = 200, notNull = false) 31 | @Comment("描述") 32 | private String description; 33 | 34 | @ManyMany(relation = "sys_role_authority", from = "role_id", to = "authority_id") 35 | private List authorities = new ArrayList<>(); 36 | 37 | public Long getId() { 38 | return id; 39 | } 40 | 41 | public void setId(Long id) { 42 | this.id = id; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | public List getAuthorities() { 54 | return authorities; 55 | } 56 | 57 | public void setAuthorities(List authorities) { 58 | this.authorities = authorities; 59 | } 60 | 61 | public String getDescription() { 62 | return description; 63 | } 64 | 65 | public void setDescription(String description) { 66 | this.description = description; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/text/VcfBean.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.text; 2 | 3 | public class VcfBean { 4 | private String fullName; //全名 5 | private String mobile; //手机号 6 | private String workMobile; //工作手机号 7 | private String telePhone; //电话 8 | private String email; //邮箱 9 | private String org; //公司 10 | private String title; //职务 11 | private String address; //地址 12 | private String note; //备注 13 | 14 | public String getFullName() { 15 | return fullName; 16 | } 17 | 18 | public void setFullName(String fullName) { 19 | this.fullName = fullName; 20 | } 21 | 22 | public String getMobile() { 23 | return mobile; 24 | } 25 | 26 | public void setMobile(String mobile) { 27 | this.mobile = mobile; 28 | } 29 | 30 | public String getWorkMobile() { 31 | return workMobile; 32 | } 33 | 34 | public void setWorkMobile(String workMobile) { 35 | this.workMobile = workMobile; 36 | } 37 | 38 | public String getTelePhone() { 39 | return telePhone; 40 | } 41 | 42 | public void setTelePhone(String telePhone) { 43 | this.telePhone = telePhone; 44 | } 45 | 46 | public String getEmail() { 47 | return email; 48 | } 49 | 50 | public void setEmail(String email) { 51 | this.email = email; 52 | } 53 | 54 | public String getOrg() { 55 | return org; 56 | } 57 | 58 | public void setOrg(String org) { 59 | this.org = org; 60 | } 61 | 62 | public String getTitle() { 63 | return title; 64 | } 65 | 66 | public void setTitle(String title) { 67 | this.title = title; 68 | } 69 | 70 | public String getNote() { 71 | return note; 72 | } 73 | 74 | public void setNote(String note) { 75 | this.note = note; 76 | } 77 | 78 | public String getAddress() { 79 | return address; 80 | } 81 | 82 | public void setAddress(String address) { 83 | this.address = address; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/service/AreaService.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.service; 2 | 3 | import org.nutz.dao.Chain; 4 | import org.nutz.dao.Cnd; 5 | import org.nutz.dao.sql.Criteria; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.dataagg.commons.domain.EArea; 10 | import com.dataagg.util.Constans; 11 | import com.dataagg.commons.dao.AreaDao; 12 | import com.dataagg.commons.service.AreaService; 13 | 14 | /** 15 | * 区域管理service实现类 16 | * Created by carlos on 2017/3/29. 17 | */ 18 | @Service 19 | public class AreaService{ 20 | @Autowired 21 | private AreaDao areaDao; 22 | 23 | public EArea insert(EArea area){ 24 | area.setDelFlag(Constans.POS_NEG.NEG); 25 | return areaDao._insert(area); 26 | } 27 | public EArea update(EArea area){ 28 | area.setDelFlag(Constans.POS_NEG.NEG); 29 | return areaDao._update(area) > 0 ? area : null; 30 | } 31 | public boolean delete(long id) { 32 | EArea area = areaDao.fetch(id); 33 | if(area ==null){ 34 | return false; 35 | } 36 | Criteria cnd = Cnd.cri(); 37 | cnd.where().andEquals("id", area.getId()); 38 | cnd.where().orLike("parent_ids", "%,"+area.getId()+",%"); 39 | 40 | Chain chain = Chain.make("del_flag", Constans.POS_NEG.POS); 41 | 42 | return areaDao.update(chain, cnd)>0 ? true : false; 43 | } 44 | 45 | /** 46 | * 通用的新增和修改方法 47 | * @param area 48 | * @return 49 | */ 50 | public EArea save(EArea area){ 51 | if(area.getParentId() != null && area.getParentId() != 0){ 52 | EArea parent = areaDao.fetch(area.getParentId()); 53 | area.setParentIds(parent.getParentIds()+parent.getId()+","); 54 | area.setFullName(parent.getFullName()+"-"+area.getName()); 55 | } 56 | if (area.getId() != null && area.getId()>0) { 57 | return update(area); 58 | }else{ 59 | return insert(area); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/MenuDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | 7 | import javax.sql.DataSource; 8 | 9 | import org.nutz.dao.Cnd; 10 | import org.nutz.dao.impl.NutDao; 11 | import org.nutz.service.IdNameEntityService; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Component; 14 | 15 | import com.dataagg.commons.domain.EMenu; 16 | import com.dataagg.util.ITreeNode; 17 | import com.dataagg.util.SecurityHelper; 18 | 19 | /** 20 | * Created by watano on 2017/2/26. 21 | */ 22 | @Component 23 | public class MenuDao extends IdNameEntityService { 24 | @Autowired 25 | public MenuDao(@Autowired DataSource dataSource) { 26 | super(new NutDao(dataSource)); 27 | } 28 | 29 | public EMenu allMenus(Set authorities) { 30 | List> allNodes = getAllMenus(authorities); 31 | EMenu root = (EMenu) allNodes.get(0); 32 | return (EMenu) root.buildTree(allNodes); 33 | } 34 | 35 | public List> getAllMenus(Set authorities) { 36 | List allMenus = query(Cnd.where("flag", "=", "1").and("del_flag", "=", "0").orderBy("sort", "asc")); 37 | List> allNodes = new ArrayList<>(); 38 | EMenu root = new EMenu(); 39 | root.setId(0L); 40 | allNodes.add(root); 41 | if (allMenus != null) { 42 | for (EMenu m : allMenus) { 43 | if (SecurityHelper.hasAuthority(authorities, m.getAuauthorities())) { 44 | allNodes.add(m); 45 | } 46 | } 47 | } 48 | return allNodes; 49 | } 50 | 51 | public EMenu buildMenuTree(List allMenus) { 52 | List> allNodes = new ArrayList<>(); 53 | EMenu root = new EMenu(); 54 | root.setId(0L); 55 | allNodes.add(root); 56 | if (allMenus != null && !allMenus.isEmpty()) { 57 | allNodes.addAll(allMenus); 58 | } 59 | return (EMenu) root.buildTree(allNodes); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/account/service/AccountServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.account.service; 2 | 3 | import org.nutz.dao.Cnd; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.util.Assert; 9 | 10 | import com.dataagg.account.client.SecurityServiceClient; 11 | import com.dataagg.commons.dao.AccountDao; 12 | import com.dataagg.commons.domain.EAccount; 13 | import com.dataagg.commons.domain.EUser; 14 | 15 | @Service 16 | public class AccountServiceImpl implements AccountService { 17 | 18 | private final Logger log = LoggerFactory.getLogger(getClass()); 19 | 20 | @Autowired 21 | private SecurityServiceClient authClient; 22 | 23 | @Autowired 24 | private AccountDao accountDao; 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | @Override 30 | public EAccount findByName(String accountName) { 31 | Assert.hasLength(accountName, ""); 32 | return accountDao.fetch(Cnd.where("full_name", "=", accountName)); 33 | } 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public EAccount create(EUser user) { 40 | 41 | EAccount existing = findByName(user.getUsername()); 42 | Assert.isNull(existing, "account already exists: " + user.getUsername()); 43 | 44 | authClient.createUser(user); 45 | EAccount account = new EAccount(); 46 | account.setFullName(user.getUsername()); 47 | 48 | //accountMapper.insert(account); 49 | log.info("new account has been created: " + account.getFullName()); 50 | 51 | return account; 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | @Override 58 | public void saveAccount(String name, EAccount account) { 59 | EAccount account1 = findByName(name); 60 | Assert.notNull(account1, "can't find account1 with name " + name); 61 | 62 | accountDao._update(account1); 63 | 64 | log.debug("payment {} changes has been saved", name); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/ITreeNode.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.Hashtable; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | public interface ITreeNode> extends Serializable { 13 | public static final Logger LOG = LoggerFactory.getLogger(ITreeNode.class); 14 | 15 | public Long getId(); 16 | 17 | public void setId(Long id); 18 | 19 | public Long getParentId(); 20 | 21 | public void setParentId(Long parentId); 22 | 23 | public String getParentIds(); 24 | 25 | public void setParentIds(String parentIds); 26 | 27 | public String getName(); 28 | 29 | public void setName(String name); 30 | 31 | public String getCode(); 32 | 33 | public void setCode(String code); 34 | 35 | public List getItems(); 36 | 37 | public void setItems(List items); 38 | 39 | public default void addChild(C node) { 40 | List items = getItems(); 41 | if (items == null) { 42 | items = new ArrayList<>(); 43 | } 44 | node.setParentId(getId()); 45 | items.add(node); 46 | setItems(items); 47 | } 48 | 49 | @SuppressWarnings("unchecked") 50 | public default ITreeNode buildTree(List> nodes) { 51 | Map> allNodes = new Hashtable<>(); 52 | for (ITreeNode node : nodes) { 53 | allNodes.put(node.getId(), node); 54 | } 55 | 56 | ITreeNode root = null; 57 | for (ITreeNode node : nodes) { 58 | ITreeNode parent = null; 59 | if (node.getParentId() != null) { 60 | parent = allNodes.get(node.getParentId()); 61 | if (parent != null) { 62 | parent.addChild((C) node); 63 | } else { 64 | LOG.debug("不能找到根节点" + node.getId() + "--" + node.getParentId()); 65 | } 66 | } else { 67 | if (root != null) { 68 | LOG.debug("重复的根节点" + root.getId() + "--" + node.getParentId()); 69 | } 70 | root = node; 71 | } 72 | } 73 | return root; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/SecurityHelper.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 9 | import org.springframework.security.core.Authentication; 10 | import org.springframework.security.core.context.SecurityContext; 11 | import org.springframework.security.core.context.SecurityContextHolder; 12 | 13 | import com.dataagg.commons.domain.EAuthority; 14 | 15 | public class SecurityHelper { 16 | public static Authentication getAuthentication() { 17 | SecurityContext sc = SecurityContextHolder.getContext(); 18 | return sc.getAuthentication(); 19 | } 20 | 21 | public static Authentication auth(AuthenticationManager authenticationManager, String userName, String password) { 22 | SecurityContext sc = SecurityContextHolder.getContext(); 23 | UsernamePasswordAuthenticationToken upToken = new UsernamePasswordAuthenticationToken(userName, password); 24 | Authentication authentication = authenticationManager.authenticate(upToken); 25 | sc.setAuthentication(authentication); 26 | return sc.getAuthentication(); 27 | } 28 | 29 | public static boolean hasAuthority(Set authorities, String authority) { 30 | if (authorities != null) { 31 | String authorityText = "," + authority + ","; 32 | for (String a : authorities) { 33 | if (authorityText.contains("," + a + ",")) { return true; } 34 | } 35 | } 36 | return false; 37 | } 38 | 39 | public static List buildAuthority(String... allAuthorities) { 40 | List all = new ArrayList<>(); 41 | if (allAuthorities != null) { 42 | for (String authority : allAuthorities) { 43 | EAuthority a = new EAuthority(); 44 | a.setName(authority); 45 | all.add(a); 46 | } 47 | } 48 | return all; 49 | } 50 | 51 | // public static SecurityExpressionOperations get() { 52 | // return new MethodSecurityExpressionRoot(getAuthentication()); 53 | // } 54 | } 55 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/EAuthorization.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.domain; 2 | 3 | import org.nutz.dao.entity.annotation.Column; 4 | import org.nutz.dao.entity.annotation.Comment; 5 | import org.nutz.dao.entity.annotation.Id; 6 | import org.nutz.dao.entity.annotation.One; 7 | import org.nutz.dao.entity.annotation.Table; 8 | 9 | /** 10 | * Created by watano on 2017/3/1. 11 | */ 12 | @Table("sys_authorization") 13 | @Comment("OAuth2认证信息") 14 | public class EAuthorization { 15 | @Id 16 | private Long id; 17 | @Column 18 | private Long userId; 19 | @One(field = "userId") 20 | private EUser user; 21 | @Column 22 | private String accessToken; 23 | @Column 24 | private Long expiresIn = 3600L; 25 | @Column 26 | private String tokenType; 27 | @Column 28 | private String scope; 29 | @Column 30 | private String refreshToken; 31 | 32 | public Long getId() { 33 | return id; 34 | } 35 | 36 | public void setId(Long id) { 37 | this.id = id; 38 | } 39 | 40 | public Long getUserId() { 41 | return userId; 42 | } 43 | 44 | public void setUserId(Long userId) { 45 | this.userId = userId; 46 | } 47 | 48 | public EUser getUser() { 49 | return user; 50 | } 51 | 52 | public void setUser(EUser user) { 53 | this.user = user; 54 | } 55 | 56 | public String getAccessToken() { 57 | return accessToken; 58 | } 59 | 60 | public void setAccessToken(String accessToken) { 61 | this.accessToken = accessToken; 62 | } 63 | 64 | public Long getExpiresIn() { 65 | return expiresIn; 66 | } 67 | 68 | public void setExpiresIn(Long expiresIn) { 69 | this.expiresIn = expiresIn; 70 | } 71 | 72 | public String getTokenType() { 73 | return tokenType; 74 | } 75 | 76 | public void setTokenType(String tokenType) { 77 | this.tokenType = tokenType; 78 | } 79 | 80 | public String getScope() { 81 | return scope; 82 | } 83 | 84 | public void setScope(String scope) { 85 | this.scope = scope; 86 | } 87 | 88 | public String getRefreshToken() { 89 | return refreshToken; 90 | } 91 | 92 | public void setRefreshToken(String refreshToken) { 93 | this.refreshToken = refreshToken; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/AreaDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.sql.DataSource; 7 | 8 | import org.nutz.dao.Cnd; 9 | import org.nutz.dao.impl.NutDao; 10 | import org.nutz.dao.sql.Criteria; 11 | import org.nutz.service.IdEntityService; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Component; 14 | 15 | import com.dataagg.commons.domain.EArea; 16 | import com.dataagg.util.Constans; 17 | import com.dataagg.util.ITreeNode; 18 | import com.dataagg.util.WMap; 19 | 20 | import jodd.util.StringUtil; 21 | 22 | /** 23 | * 区域管理DAO 24 | * Created by carlos on 2017/3/29. 25 | */ 26 | @Component 27 | public class AreaDao extends IdEntityService { 28 | 29 | @Autowired 30 | public AreaDao(@Autowired DataSource dataSource) { 31 | super(new NutDao(dataSource)); 32 | } 33 | 34 | public EArea allArea(WMap query) { 35 | //处理查询条件 36 | Criteria cnd = Cnd.cri(); 37 | cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG); 38 | if (query.get("extId") != null && StringUtil.isNotBlank(query.get("extId").toString())) { 39 | cnd.where().andNotIn("id", query.get("extId").toString()); 40 | cnd.where().andNotLike("parent_ids", "%," + query.get("extId").toString() + ",%"); 41 | } 42 | cnd.getOrderBy().asc("sort"); 43 | List allAreas = query(cnd); 44 | List> allNodes = new ArrayList<>(); 45 | EArea root = new EArea(); 46 | root.setId(0L); 47 | allNodes.add(root); 48 | if (allAreas != null && !allAreas.isEmpty()) { 49 | allNodes.addAll(allAreas); 50 | } 51 | return (EArea) root.buildTree(allNodes); 52 | } 53 | 54 | /** 55 | * 根据一个parentId,得到其下级的地区 56 | * @param parentId 57 | * @return 58 | */ 59 | public List getAreaByParentId(Long parentId){ 60 | //处理查询条件 61 | Criteria cnd = Cnd.cri(); 62 | cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG); 63 | cnd.where().andEquals("parent_id", parentId); 64 | cnd.getOrderBy().asc("sort"); 65 | List areas = query(cnd); 66 | return areas; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/xml/XmlCoder.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.xml; 2 | 3 | import jodd.util.ClassLoaderUtil; 4 | import com.dataagg.util.collection.StrMap; 5 | import com.dataagg.util.lang.ValuePlus; 6 | import com.dataagg.util.lang.TextUtils; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.w3c.dom.Element; 10 | import org.w3c.dom.Node; 11 | import org.w3c.dom.NodeList; 12 | 13 | public class XmlCoder { 14 | private static final Logger LOG = LoggerFactory.getLogger(XmlCoder.class); 15 | protected Element root; 16 | protected StrMap ns; 17 | public XPathEvaluator evaluator; 18 | 19 | private void init() { 20 | evaluator = new XPathEvaluator(); 21 | evaluator.init(); 22 | } 23 | 24 | public String getNodeText(String exp) { 25 | return evaluator.getNodeText(root, exp); 26 | } 27 | 28 | public String getNodeAttr(String exp, String attrName) { 29 | return evaluator.getNodeAttr(root, exp, attrName); 30 | } 31 | 32 | public String[] getNodesAttr(String exp, String attrName) { 33 | return evaluator.getNodesAttr(root, exp, attrName); 34 | } 35 | 36 | public Node findOneNode(Node node, String exp) { 37 | NodeList nodes = evaluator.findNodes(node, exp); 38 | if (nodes != null && nodes.getLength() > 0) { 39 | return nodes.item(0); 40 | } 41 | return null; 42 | } 43 | 44 | public NodeList findNodes(String exp) { 45 | return evaluator.findNodes(root, exp); 46 | } 47 | 48 | public Node findOneNode(String exp) { 49 | return findOneNode(root, exp); 50 | } 51 | 52 | public void parse(String filePath) { 53 | try { 54 | init(); 55 | root = XmlUtil.parseRootElement(ClassLoaderUtil.getResourceAsStream(filePath)); 56 | ns = XmlUtil.parseNameSpaces(root); 57 | } catch (Exception e) { 58 | LOG.error(e.getMessage(), e); 59 | } 60 | } 61 | 62 | public String getNsPrefix(String node, String url) { 63 | for (String nskey : ns.keySet()) { 64 | String nsurl = ValuePlus.strValue(ns.get(nskey), null); 65 | node = TextUtils.prefix(node); 66 | if (nsurl != null && nsurl.equals(url) && nskey.startsWith(node)) { 67 | return nskey.substring(node.length()); 68 | } 69 | } 70 | return ""; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /project.md: -------------------------------------------------------------------------------- 1 | # com.dataagg:DAFramework:0.1 2 | DAFramework 3 | 4 | ## com.dataagg:commons:0.1 5 | 公用实体类,VO及常用工具类 6 | 7 | + compile 'org.jodd:jodd-core:3.8.5' 8 | + compile 'org.jodd:jodd-bean:3.8.5' 9 | + compile 'org.jodd:jodd-props:3.8.5' 10 | + compile 'com.google.code.gson:gson:2.8.0' 11 | + compile 'org.nutz:nutz:1.r.61' 12 | + compile 'mysql:mysql-connector-java:6.0.6' 13 | + compile 'org.springframework.boot:spring-boot-starter-jdbc:1.5.3.RELEASE' 14 | + compile 'org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE' 15 | + compile 'org.springframework.boot:spring-boot-starter-security:1.5.3.RELEASE' 16 | + compile 'org.springframework.security:spring-security-core:4.2.2.RELEASE' 17 | + compile 'org.springframework.security.oauth:spring-security-oauth2:2.0.13.RELEASE' 18 | + testCompile 'junit:junit:4.12' 19 | + testCompile 'org.springframework.boot:spring-boot-starter-test:1.5.3.RELEASE' 20 | 21 | ## com.dataagg:api-gateway:0.1 22 | api-gateway(API网关)+security(权限检查服务) 23 | 24 | + testCompile 'org.springframework.boot:spring-boot-starter-test' 25 | + compile 'org.springframework.boot:spring-boot-starter-web' 26 | + compile 'org.springframework.cloud:spring-cloud-starter-zuul' 27 | + compile 'org.springframework.cloud:spring-cloud-starter-feign' 28 | + commons 29 | + compile 'mysql:mysql-connector-java:6.0.6' 30 | + compile 'org.springframework.boot:spring-boot-starter-jdbc' 31 | 32 | ## com.dataagg:core-service:0.1 33 | 核心服务 用户,组织,角色,菜单,字典,区域,附件等基础服务 34 | 35 | + testCompile 'org.springframework.boot:spring-boot-starter-test' 36 | + compile 'org.springframework.cloud:spring-cloud-starter-feign' 37 | + commons 38 | + compile 'org.springframework.boot:spring-boot-starter-web' 39 | + compile 'mysql:mysql-connector-java:6.0.6' 40 | + compile 'org.springframework.boot:spring-boot-starter-jdbc' 41 | + compile 'org.springframework.boot:spring-boot-starter-security' 42 | + compile 'org.springframework.security.oauth:spring-security-oauth2' 43 | + compile 'org.springframework.cloud:spring-cloud-security:1.1.3.RELEASE' 44 | 45 | # 项目依赖 46 | ```graphLR 47 | commons[commons] 48 | api-gateway[api-gateway] 49 | api-gateway-->commons[commons] 50 | core-service[core-service] 51 | core-service-->commons[commons] 52 | ``` 53 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/dao/RoleDao.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import javax.sql.DataSource; 8 | 9 | import org.nutz.dao.Chain; 10 | import org.nutz.dao.Cnd; 11 | import org.nutz.dao.Sqls; 12 | import org.nutz.dao.impl.NutDao; 13 | import org.nutz.service.IdEntityService; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Component; 16 | 17 | import com.dataagg.commons.domain.ERole; 18 | 19 | /** 20 | * Created by watano on 2017/3/13. 21 | */ 22 | @Component 23 | public class RoleDao extends IdEntityService { 24 | @Autowired 25 | public RoleDao(@Autowired DataSource dataSource) { 26 | super(new NutDao(dataSource)); 27 | } 28 | 29 | public List getDefaultRoles() { 30 | return Arrays.asList(fetch(1)); 31 | } 32 | 33 | public ERole fetchByName(String name) { 34 | return fetch(Cnd.where("name", "=", name)); 35 | } 36 | 37 | public ERole fetchFullByName(String name) { 38 | ERole role = fetchByName(name); 39 | return _fetchLinks(role, "authorities"); 40 | } 41 | 42 | public ERole save(ERole role) { 43 | Long newId = role.getId(); 44 | if (newId != null) { 45 | ERole tmp = fetch(newId); 46 | if (tmp != null) { 47 | _update(role); 48 | return role; 49 | } 50 | //FIXME 插入是不会使用设置过的id,始终自动生成:( 51 | role = _insert(role); 52 | update(Chain.make("id", newId), Cnd.where("id", "=", role.getId())); 53 | role.setId(newId); 54 | return role; 55 | } 56 | return _insert(role); 57 | } 58 | 59 | public void insertAll(Map allAoles) { 60 | if (allAoles != null) { 61 | for (String name : allAoles.keySet()) { 62 | ERole a = fetchByName(name); 63 | if (a == null) { 64 | a = new ERole(); 65 | a.setName(name); 66 | a.setDescription(allAoles.get(name)); 67 | _insert(a); 68 | } else { 69 | a.setName(name); 70 | a.setDescription(allAoles.get(name)); 71 | _update(a); 72 | } 73 | } 74 | } 75 | } 76 | 77 | //FIXME pls polish this codes 78 | public ERole updateAuthorities(ERole vo) { 79 | dao().execute(Sqls.create("delete from sys_role_authority where role_id=" + vo.getId())); 80 | return _insertRelation(vo, "authorities"); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /core-service/src/test/java/com/dataagg/commons/controller/DictControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.controller; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | import org.springframework.test.web.servlet.MockMvc; 12 | import org.springframework.test.web.servlet.MvcResult; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | import org.springframework.web.context.WebApplicationContext; 16 | 17 | import com.dataagg.CoreServiceApplication; 18 | import com.dataagg.util.SearchQueryJS; 19 | import com.dataagg.util.WMap; 20 | import com.fasterxml.jackson.databind.ObjectMapper; 21 | 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | @SpringBootTest(classes = CoreServiceApplication.class) 24 | @WebAppConfiguration 25 | public class DictControllerTest { 26 | 27 | private static final ObjectMapper mapper = new ObjectMapper(); 28 | 29 | @Autowired 30 | private WebApplicationContext webApplicationConnect; 31 | 32 | private MockMvc mockMvc; 33 | 34 | @Before 35 | public void setup() { 36 | mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationConnect).build(); 37 | } 38 | 39 | @Test 40 | public void get() throws Exception { 41 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/dict/3").accept(MediaType.APPLICATION_JSON)).andReturn(); 42 | int status = mvcResult.getResponse().getStatus(); 43 | String content = mvcResult.getResponse().getContentAsString(); 44 | System.out.println(status + "--" + content); 45 | } 46 | 47 | @Test 48 | public void list() throws Exception { 49 | SearchQueryJS queryJs = new SearchQueryJS(); 50 | WMap query = new WMap(); 51 | queryJs.setQuery(query); 52 | String json = mapper.writeValueAsString(queryJs); 53 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/dict/type/unit").contentType(MediaType.APPLICATION_JSON).content(json)).andReturn(); 54 | int status = mvcResult.getResponse().getStatus(); 55 | String content = mvcResult.getResponse().getContentAsString(); 56 | System.out.println(status + "--" + content); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core-service/src/test/java/com/dataagg/commons/controller/AreaControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.controller; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | import org.springframework.test.web.servlet.MockMvc; 12 | import org.springframework.test.web.servlet.MvcResult; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | import org.springframework.web.context.WebApplicationContext; 16 | 17 | import com.dataagg.CoreServiceApplication; 18 | import com.dataagg.util.SearchQueryJS; 19 | import com.dataagg.util.WMap; 20 | import com.fasterxml.jackson.databind.ObjectMapper; 21 | 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | @SpringBootTest(classes = CoreServiceApplication.class) 24 | @WebAppConfiguration 25 | public class AreaControllerTest { 26 | 27 | private static final ObjectMapper mapper = new ObjectMapper(); 28 | 29 | @Autowired 30 | private WebApplicationContext webApplicationConnect; 31 | 32 | private MockMvc mockMvc; 33 | 34 | @Before 35 | public void setup() { 36 | mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationConnect).build(); 37 | } 38 | 39 | @Test 40 | public void get() throws Exception { 41 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/area/delete/2").accept(MediaType.APPLICATION_JSON)).andReturn(); 42 | int status = mvcResult.getResponse().getStatus(); 43 | String content = mvcResult.getResponse().getContentAsString(); 44 | System.out.println(status + "--" + content); 45 | } 46 | 47 | // @Test 48 | public void page() throws Exception { 49 | SearchQueryJS queryJs = new SearchQueryJS(); 50 | WMap map = new WMap(); 51 | map.put("parentId", "10"); 52 | queryJs.setQuery(map); 53 | 54 | String json = mapper.writeValueAsString(queryJs); 55 | 56 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/area/list").contentType(MediaType.APPLICATION_JSON).content(json)).andReturn(); 57 | int status = mvcResult.getResponse().getStatus(); 58 | String content = mvcResult.getResponse().getContentAsString(); 59 | System.out.println(status + "--" + content); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /core-service/src/test/java/com/dataagg/CoreServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dataagg; 2 | 3 | import static org.springframework.util.Assert.isNull; 4 | import static org.springframework.util.Assert.isTrue; 5 | import static org.springframework.util.Assert.notNull; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.security.authentication.AuthenticationManager; 12 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 13 | import org.springframework.security.core.Authentication; 14 | import org.springframework.security.core.context.SecurityContext; 15 | import org.springframework.security.core.context.SecurityContextHolder; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | import com.dataagg.CoreServiceApplication; 19 | import com.dataagg.account.service.AccountService; 20 | import com.dataagg.commons.domain.EUser; 21 | 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | @SpringBootTest(classes = CoreServiceApplication.class) 24 | public class CoreServiceApplicationTests { 25 | 26 | @Autowired 27 | private AccountService accountService; 28 | @Autowired 29 | private AuthenticationManager authenticationManager; 30 | // 31 | // @Autowired 32 | // private WeChatServiceClient weChatServiceClient; 33 | 34 | @Test 35 | public void testCreateAccount() { 36 | EUser user = new EUser(); 37 | user.setUsername("name" + System.currentTimeMillis()); 38 | user.setPassword("password"); 39 | accountService.create(user); 40 | 41 | notNull(user, ""); 42 | notNull(user.getUsername(), ""); 43 | } 44 | 45 | @Test 46 | public void testWeChatService() { 47 | // String redirect_uri = ""; 48 | } 49 | 50 | @Test 51 | public void testSecurity() { 52 | SecurityContext sc = SecurityContextHolder.getContext(); 53 | Authentication authentication = sc.getAuthentication(); 54 | 55 | isNull(authentication, "未认证"); 56 | 57 | UsernamePasswordAuthenticationToken upToken = new UsernamePasswordAuthenticationToken("watano", "123456"); 58 | // Perform the security 59 | authentication = authenticationManager.authenticate(upToken); 60 | sc.setAuthentication(authentication); 61 | 62 | authentication = sc.getAuthentication(); 63 | 64 | notNull(authentication, "已认证"); 65 | isTrue(authentication.isAuthenticated(), "未认证"); 66 | 67 | //1.访问/user页面, 失败返回失败,提示登录 68 | 69 | //2.使用username和password提交到/login, 返回登录成功 70 | 71 | //3.附带token信息,再次访问/user页面, 成功返回 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/lang/ValuePlus.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.lang; 2 | 3 | import jodd.typeconverter.Convert; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class ValuePlus { 9 | public static int intValue(Object value, int defaultValue) { 10 | if (value != null) { 11 | return Convert.toIntValue(value); 12 | } 13 | return defaultValue; 14 | } 15 | 16 | public static long longValue(Object value, long defaultValue) { 17 | if (value != null) { 18 | return Convert.toLongValue(value); 19 | } 20 | return defaultValue; 21 | } 22 | 23 | public static short shortValue(Object value, short defaultValue) { 24 | if (value != null) { 25 | return Convert.toShortValue(value); 26 | } 27 | return defaultValue; 28 | } 29 | 30 | public static float floatValue(Object value, float defaultValue) { 31 | if (value != null) { 32 | return Convert.toFloatValue(value); 33 | } 34 | return defaultValue; 35 | } 36 | 37 | public static double doubleValue(Object value, double defaultValue) { 38 | if (value != null) { 39 | return Convert.toDoubleValue(value); 40 | } 41 | return defaultValue; 42 | } 43 | 44 | public static byte byteValue(Object value, byte defaultValue) { 45 | if (value != null) { 46 | return Convert.toByteValue(value); 47 | } 48 | return defaultValue; 49 | } 50 | 51 | public static char charValue(Object value, char defaultValue) { 52 | if (value != null) { 53 | return Convert.toCharValue(value); 54 | } 55 | return defaultValue; 56 | } 57 | 58 | public static String strValue(Object value, String defaultValue) { 59 | if (value != null) { 60 | return Convert.toString(value); 61 | } 62 | return defaultValue; 63 | } 64 | 65 | public static String[] strValues(Object value, String[] defaultValue) { 66 | if (value != null) { 67 | return Convert.toStringArray(value); 68 | } 69 | return defaultValue; 70 | } 71 | 72 | public static boolean booleanValue(Object value, boolean defaultValue) { 73 | if (value != null && value instanceof String && ((String) value).trim().length() > 0) { 74 | String v = ((String) value).trim(); 75 | if ("1".equals(v) || "true".equalsIgnoreCase(v) || "yes".equalsIgnoreCase(v) || "on".equalsIgnoreCase(v)) { 76 | return true; 77 | } 78 | if ("0".equals(v) || "false".equalsIgnoreCase(v) || "no".equalsIgnoreCase(v) || "off".equalsIgnoreCase(v)) { 79 | return false; 80 | } 81 | return Convert.toBooleanValue(value); 82 | } 83 | return defaultValue; 84 | } 85 | 86 | @SuppressWarnings("unchecked") 87 | public static List lst(T... all) { 88 | List lst = new ArrayList<>(); 89 | for (T t : all) { 90 | lst.add(t); 91 | } 92 | return lst; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import jodd.util.StringUtil; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Hashtable; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class TreeNode { 11 | public long id; 12 | public String name; 13 | public int type = 1; 14 | public Object obj; 15 | public String code; 16 | public long parentId; 17 | public List Children; 18 | 19 | // public TreeNode(long id, String name, int type, Message obj) { 20 | // super(); 21 | // this.id = id; 22 | // this.name = name; 23 | // this.type = type; 24 | // this.obj = obj; 25 | // } 26 | 27 | public TreeNode(long parentId, long id, String name, int type, Object obj) { 28 | super(); 29 | this.id = id; 30 | this.parentId = parentId; 31 | this.name = name; 32 | this.type = type; 33 | this.obj = obj; 34 | } 35 | 36 | public void addChild(TreeNode node) { 37 | if (Children == null) { 38 | Children = new ArrayList(); 39 | } 40 | node.parentId = id; 41 | Children.add(node); 42 | } 43 | 44 | public static TreeNode buildTree(List nodes) { 45 | Map allNodes = new Hashtable(); 46 | for (TreeNode node : nodes) { 47 | allNodes.put(node.id, node); 48 | } 49 | 50 | TreeNode root = null; 51 | for (TreeNode node : nodes) { 52 | TreeNode parent = allNodes.get(node.parentId); 53 | if (parent != null) { 54 | parent.addChild(node); 55 | } else { 56 | if (root != null) { 57 | System.out.println("重复的根节点" + root.id + "--" + node.parentId); 58 | } 59 | root = node; 60 | } 61 | } 62 | return root; 63 | } 64 | 65 | // public static WORKFLOW_TREENODE.Builder convert(TreeNode node) { 66 | // WORKFLOW_TREENODE.Builder tree = WORKFLOW_TREENODE.newBuilder(); 67 | // if (node != null) { 68 | // tree.setID(node.id); 69 | // tree.setTYPE(node.type); 70 | // tree.setNAME(node.name); 71 | // tree.setPARENTID(node.parentId); 72 | // if (node.obj != null) { 73 | // tree.setCODE(MessageUtil.conver2String(node.obj)); 74 | // } else if (node.code != null) { 75 | // tree.setCODE(node.code); 76 | // } 77 | // if (node.Children != null) { 78 | // for (int i = 0; i < node.Children.size(); i++) { 79 | // WORKFLOW_TREENODE.Builder child = convert(node.Children.get(i)); 80 | // tree.addChildren(child); 81 | // } 82 | // } 83 | // } 84 | // return tree; 85 | // } 86 | 87 | public static void main(String[] args) { 88 | try { 89 | String text = "功能界面设计"; 90 | 91 | System.out.println(StringUtil.escapeJava(text)); 92 | } catch (Exception e) { 93 | e.printStackTrace(); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/EFile.java: -------------------------------------------------------------------------------- 1 | /** 2 | * author: loserStar 3 | * date: 2017年3月30日上午10:06:24 4 | * email:362527240@qq.com 5 | * github:https://github.com/xinxin321198 6 | * remarks: 7 | */ 8 | package com.dataagg.commons.domain; 9 | 10 | import org.nutz.dao.entity.annotation.ColDefine; 11 | import org.nutz.dao.entity.annotation.ColType; 12 | import org.nutz.dao.entity.annotation.Column; 13 | import org.nutz.dao.entity.annotation.Comment; 14 | import org.nutz.dao.entity.annotation.Default; 15 | import org.nutz.dao.entity.annotation.Id; 16 | import org.nutz.dao.entity.annotation.Table; 17 | 18 | /** 19 | * author: carlos 2017年3月31日 11:28:25 remarks: 附件实体类 20 | */ 21 | @Table("sys_file") 22 | public class EFile { 23 | @Id 24 | @Comment("主键") 25 | private Long id; 26 | 27 | @Column("name") 28 | @Comment("名称") 29 | @ColDefine(type = ColType.VARCHAR, width = 100, notNull = true) 30 | private String name; 31 | 32 | @Column("path") 33 | @Comment("路径") 34 | @ColDefine(type = ColType.VARCHAR, width = 200, notNull = true) 35 | private String path; 36 | 37 | @Column("del_flag") 38 | @Comment("删除标记(0:正常,1:删除)") 39 | @ColDefine(type = ColType.CHAR, width = 1, notNull = true) 40 | @Default("0") 41 | private String delFlag; 42 | 43 | @Column("grouping") 44 | @Comment("分组") 45 | @ColDefine(type = ColType.VARCHAR, width = 64, notNull = true) 46 | private String grouping; 47 | 48 | @Column(hump=true) 49 | @Comment("文件来源类型") 50 | @ColDefine(type = ColType.CHAR, width = 1, notNull = false) 51 | private String sourceType; 52 | 53 | @Column(hump=true) 54 | @Comment("文件来源ID") 55 | @ColDefine(type = ColType.VARCHAR, width = 64, notNull = false) 56 | private String sourceId; 57 | 58 | public Long getId() { 59 | return id; 60 | } 61 | 62 | public void setId(Long id) { 63 | this.id = id; 64 | } 65 | 66 | public String getGrouping() { 67 | return grouping; 68 | } 69 | 70 | public void setGrouping(String grouping) { 71 | this.grouping = grouping; 72 | } 73 | 74 | public String getName() { 75 | return name; 76 | } 77 | 78 | public void setName(String name) { 79 | this.name = name; 80 | } 81 | 82 | public String getPath() { 83 | return path; 84 | } 85 | 86 | public void setPath(String path) { 87 | this.path = path; 88 | } 89 | 90 | public String getDelFlag() { 91 | return delFlag; 92 | } 93 | 94 | public void setDelFlag(String delFlag) { 95 | this.delFlag = delFlag; 96 | } 97 | 98 | public String getSourceType() { 99 | return sourceType; 100 | } 101 | 102 | public void setSourceType(String sourceType) { 103 | this.sourceType = sourceType; 104 | } 105 | 106 | public String getSourceId() { 107 | return sourceId; 108 | } 109 | 110 | public void setSourceId(String sourceId) { 111 | this.sourceId = sourceId; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DAFramework -- 云南数聚基础框架 2 | DAFramework是云南数聚科技开源的微服务基础框架, 基于Spring-boot, Spring-security, Spring-cloud, Spring-data和Docker构建. 这是一个Spring-cloud的脚手架项目, 提供一些基础服务, 帮助更多的开发人员更快速地构建他们的项目. DAFramework源于[PiggyMetrics](https://github.com/sqshq/PiggyMetrics)项目. 3 | 4 | ![基础组件](https://watano.gitbooks.io/daframework/content/images/componets.png "基础组件") 5 | 6 | ## 为何选择DAFramework 7 | --- 8 | + 基于Spring-boot, Spring-MVC, Spring-security和Spring-cloud构建, 减少用户的学习成本; 9 | + 基于Docker构建, 帮助开发人员快速实施DevOps; 10 | + 完整的 [微服务体系结构模式(Microservice Architecture Pattern)](http://martinfowler.com/microservices/)实现, 更先进的架构设计; 11 | + 模块化设计,层次结构清晰, 封装重用业务组件, 减少二次开发; 包含服务注册发现、配置中心、智能路由、负载均衡、性能监控、缓存、用户角色权限控制等; 12 | + 完整的代码生成工具,帮助快速开发新功能,减少重复coding工作; 13 | + 后端输出纯JSON(可配置为其他格式:XML,protobuf等),方便前后端分离; 14 | 15 | ## 基础组件 16 | --- 17 | + 配置中心: Spring-cloud config server和client 18 | + 服务注册发现: Spring-cloud NetFlix Eureka 19 | + 熔断器: Spring-cloud NetFlix Hystrix客户端和Hystrix Dashboard 20 | + 客户端负载均衡:Spring-cloud NetFlix Ribbon 21 | + 智能路由: Spring-cloud NetFlix Zuul 22 | + REST client: Spring-cloud NetFlix Feign 23 | + 监控系统: Spring-cloud NetFlix Turbine 24 | + 权限检查: Spring-cloud Security 25 | + 消息队列代理: Spring-cloud Bus 26 | + 数据持久化访问: Spring-Data和[NutDao](https://nutzam.com/core/dao/basic_operations.html) 27 | + 前端技术: ES2015/TypeScript、LESS、VueJs、Vue-router、[vux](https://github.com/airyland/vux)、echarts、axios和EsLint 28 | + 前端组件:[Element](https://element.eleme.io)、[Mint-UI](https://github.com/ElemeFE/mint-ui)和Bootstrap4 grid.css 29 | + 构建工具: [Gradle](https://gradle.org/)和[Cooking](http://cookingjs.github.io/) 30 | + 容器技术: [Docker](http://docker.com/) 31 | 32 | ## 环境搭建 33 | --- 34 | ### 后端部分 35 | 1. 安装gradle, 去[官网](https://gradle.org/gradle-download/)下载v3.x版本,并安装; 36 | 2. 在命令行中进入DAFramework目录, 执行以下命令编译打包: 37 | ```shell 38 | cd DAFramework 39 | gradle bootrepackage 40 | ``` 41 | 3. 进入codegen目录, 执行以下命令启动Docker容器: 42 | ```shell 43 | cd codegen 44 | docker-compose up 45 | ``` 46 | 4. 在浏览器中访问系统: 47 | - http://DOCKER-HOST:80 - 通过API Gateway访问系统功能 48 | - http://DOCKER-HOST:8761 - 访问Eureka Dashboard 49 | - http://DOCKER-HOST:9000/hystrix - 访问Hystrix Dashboard 50 | - http://DOCKER-HOST:8989 - 访问监控系统Turbine 51 | - http://DOCKER-HOST:15672 - RabbitMq management (默认登陆名/密码: guest/guest) 52 | 53 | ### 前端部分 54 | 1. 安装nodejs, 去[官网](https://nodejs.org)下载v7.x版本NodeJs,并安装; 55 | 1. 在命令行下安装cnpm: 56 | ```shell 57 | npm install -g cnpm --registry=https://registry.npm.taobao.org 58 | ``` 59 | 1. 进入web目录,安装相关全局工具和相关依赖: 60 | ```shell 61 | cd web 62 | cnpm install -g vue-cli webpack eslint gulp cooking-cli 63 | cnpm install 64 | ``` 65 | 1. 运行dev开发模式 66 | ```shell 67 | npm run dev 68 | ``` 69 | 1. 运行lint检查代码文件(注:dev模式自动检查,build是也检查,lint一般只是快速检查时使用) 70 | ```shell 71 | npm run lint 72 | ``` 73 | 1. 运行build工具编译生成静态文件(发布时使用) 74 | ```shell 75 | npm run build 76 | ``` 77 | 78 | ## 关于我们 79 | + [官网](https://dataagg.github.io/) 80 | + [团队博客](https://dataagg.github.io/) 81 | + [文档](https://watano.gitbooks.io/daframework/content/) 82 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 | # DAFramework -- 云南数聚基础框架 2 | DAFramework是云南数聚科技开源的微服务基础框架, 基于Spring-boot, Spring-security, Spring-cloud, Spring-data和Docker构建. 这是一个Spring-cloud的脚手架项目, 提供一些基础服务, 帮助更多的开发人员更快速地构建他们的项目. DAFramework源于[PiggyMetrics](https://github.com/sqshq/PiggyMetrics)项目. 3 | 4 | ![基础组件](https://watano.gitbooks.io/daframework/content/images/componets.png "基础组件") 5 | 6 | ## 为何选择DAFramework 7 | --- 8 | + 基于Spring-boot, Spring-MVC, Spring-security和Spring-cloud构建, 减少用户的学习成本; 9 | + 基于Docker构建, 帮助开发人员快速实施DevOps; 10 | + 完整的 [微服务体系结构模式(Microservice Architecture Pattern)](http://martinfowler.com/microservices/)实现, 更先进的架构设计; 11 | + 模块化设计,层次结构清晰, 封装重用业务组件, 减少二次开发; 包含服务注册发现、配置中心、智能路由、负载均衡、性能监控、缓存、用户角色权限控制等; 12 | + 完整的代码生成工具,帮助快速开发新功能,减少重复coding工作; 13 | + 后端输出纯JSON(可配置为其他格式:XML,protobuf等),方便前后端分离; 14 | 15 | ## 基础组件 16 | --- 17 | + 配置中心: Spring-cloud config server和client 18 | + 服务注册发现: Spring-cloud NetFlix Eureka 19 | + 熔断器: Spring-cloud NetFlix Hystrix客户端和Hystrix Dashboard 20 | + 客户端负载均衡:Spring-cloud NetFlix Ribbon 21 | + 智能路由: Spring-cloud NetFlix Zuul 22 | + REST client: Spring-cloud NetFlix Feign 23 | + 监控系统: Spring-cloud NetFlix Turbine 24 | + 权限检查: Spring-cloud Security 25 | + 消息队列代理: Spring-cloud Bus 26 | + 数据持久化访问: Spring-Data和[NutDao](https://nutzam.com/core/dao/basic_operations.html) 27 | + 前端技术: ES2015/TypeScript、LESS、VueJs、Vue-router、[vux](https://github.com/airyland/vux)、echarts、axios和EsLint 28 | + 前端组件:[Element](https://element.eleme.io)、[Mint-UI](https://github.com/ElemeFE/mint-ui)和Bootstrap4 grid.css 29 | + 构建工具: [Gradle](https://gradle.org/)和[Cooking](http://cookingjs.github.io/) 30 | + 容器技术: [Docker](http://docker.com/) 31 | 32 | ## 环境搭建 33 | --- 34 | ### 后端部分 35 | 1. 安装gradle, 去[官网](https://gradle.org/gradle-download/)下载v3.x版本,并安装; 36 | 2. 在命令行中进入DAFramework目录, 执行以下命令编译打包: 37 | ```shell 38 | cd DAFramework 39 | gradle bootrepackage 40 | ``` 41 | 3. 进入codegen目录, 执行以下命令启动Docker容器: 42 | ```shell 43 | cd codegen 44 | docker-compose up 45 | ``` 46 | 4. 在浏览器中访问系统: 47 | - http://DOCKER-HOST:80 - 通过API Gateway访问系统功能 48 | - http://DOCKER-HOST:8761 - 访问Eureka Dashboard 49 | - http://DOCKER-HOST:9000/hystrix - 访问Hystrix Dashboard 50 | - http://DOCKER-HOST:8989 - 访问监控系统Turbine 51 | - http://DOCKER-HOST:15672 - RabbitMq management (默认登陆名/密码: guest/guest) 52 | 53 | ### 前端部分 54 | 1. 安装nodejs, 去[官网](https://nodejs.org)下载v7.x版本NodeJs,并安装; 55 | 1. 在命令行下安装cnpm: 56 | ```shell 57 | npm install -g cnpm --registry=https://registry.npm.taobao.org 58 | ``` 59 | 1. 进入web目录,安装相关全局工具和相关依赖: 60 | ```shell 61 | cd web 62 | cnpm install -g vue-cli webpack eslint gulp cooking-cli 63 | cnpm install 64 | ``` 65 | 1. 运行dev开发模式 66 | ```shell 67 | npm run dev 68 | ``` 69 | 1. 运行lint检查代码文件(注:dev模式自动检查,build是也检查,lint一般只是快速检查时使用) 70 | ```shell 71 | npm run lint 72 | ``` 73 | 1. 运行build工具编译生成静态文件(发布时使用) 74 | ```shell 75 | npm run build 76 | ``` 77 | 78 | ## 关于我们 79 | + [官网](https://dataagg.github.io/) 80 | + [团队博客](https://dataagg.github.io/) 81 | + [文档](https://watano.gitbooks.io/daframework/content/) 82 | -------------------------------------------------------------------------------- /codegen/projects.pro.yml: -------------------------------------------------------------------------------- 1 | WorkDir: .. 2 | props: 3 | slf4jVersion: "1.7.25" 4 | joddVersion: "3.8.5" 5 | bootVersion: "1.5.3.RELEASE" 6 | cloudVersion: Dalston.RELEASE 7 | mysqlVersion: "6.0.6" 8 | nutzVersion: "1.r.61" 9 | springSecurityVersion: "4.2.2.RELEASE" 10 | cloudSecurityVersion: "1.1.3.RELEASE" 11 | clientSecret: YFzCAfocMInyJ5YaO805 12 | jdbcUrl: "jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull" 13 | jdbcUser: "dataagg" 14 | jdbcPswd: "3yXcH7AIK7Wrs1sQeGJe" 15 | group: com.dataagg 16 | project: DAFramework 17 | version: 0.1 18 | plugins: [eclipse, idea, "'com.github.ben-manes.versions:0.14.0'"] 19 | description: DAFramework 20 | 21 | subProjects: 22 | commons: 23 | type: jar 24 | description: '公用实体类,VO及常用工具类' 25 | plugins: [java, eclipse, idea] 26 | archiveName: commons.jar 27 | deps: 28 | - compile 'org.jodd:jodd-core:${joddVersion}' 29 | - compile 'org.jodd:jodd-bean:${joddVersion}' 30 | - compile 'org.jodd:jodd-props:${joddVersion}' 31 | - compile 'com.google.code.gson:gson:2.8.0' 32 | - compile 'org.nutz:nutz:${nutzVersion}' 33 | - compile 'mysql:mysql-connector-java:${mysqlVersion}' 34 | - compile 'org.springframework.boot:spring-boot-starter-jdbc:${bootVersion}' 35 | - compile 'org.springframework.boot:spring-boot-starter-web:${bootVersion}' 36 | - compile 'org.springframework.boot:spring-boot-starter-security:${bootVersion}' 37 | - compile 'org.springframework.security:spring-security-core:${springSecurityVersion}' 38 | - compile 'org.springframework.security.oauth:spring-security-oauth2:2.0.13.RELEASE' 39 | - testCompile 'junit:junit:4.12' 40 | - testCompile 'org.springframework.boot:spring-boot-starter-test:${bootVersion}' 41 | config: 42 | logging: 43 | level: 44 | root: WARN 45 | com.dataagg: info 46 | service-center: 47 | description: eurekaServer(服务注册及发现) 48 | ports: 8761 49 | components: [springBoot, eurekaServer] 50 | config: 51 | api-gateway: 52 | description: api-gateway(API网关)+security(权限检查服务) 53 | ports: 80 54 | components: [springBoot, eurekaClient, starterWeb, zuul, feign, ':commons', starterJdbc] 55 | config: 56 | zuul: 57 | routes: 58 | core: 59 | path: /core/** 60 | serviceId: core-service 61 | core-service: 62 | description: "核心服务 用户,组织,角色,菜单,字典,区域,附件等基础服务" 63 | ports: 6000 64 | components: [springBoot, eurekaClient, feign, ':commons', starterWeb, starterJdbc, securityClient] 65 | docker: 66 | depends_on: [api-gateway] 67 | config: 68 | logging: 69 | level: 70 | root: WARN 71 | com.dataagg: info 72 | file: 73 | rootPath: e:\\wdtc\\html 74 | filePath: /files 75 | sms: 76 | #短信接口是否允许发送的标识,true允许,false不允许 77 | canSend: false 78 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/EDict.java: -------------------------------------------------------------------------------- 1 | /** 2 | * author: loserStar 3 | * date: 2017年3月30日上午10:06:24 4 | * email:362527240@qq.com 5 | * github:https://github.com/xinxin321198 6 | * remarks: 7 | */ 8 | package com.dataagg.commons.domain; 9 | 10 | import org.nutz.dao.entity.annotation.ColDefine; 11 | import org.nutz.dao.entity.annotation.ColType; 12 | import org.nutz.dao.entity.annotation.Column; 13 | import org.nutz.dao.entity.annotation.Comment; 14 | import org.nutz.dao.entity.annotation.Default; 15 | import org.nutz.dao.entity.annotation.Id; 16 | import org.nutz.dao.entity.annotation.Table; 17 | 18 | /** 19 | * author: loserStar 20 | * date: 2017年3月30日上午10:06:24 21 | * email:362527240@qq.com 22 | * github:https://github.com/xinxin321198 23 | * remarks: 数据字典实体类 24 | */ 25 | @Table("sys_dict") 26 | public class EDict { 27 | @Id 28 | @Comment("主键") 29 | private Long id; 30 | 31 | @Column("type") 32 | @Comment("类型") 33 | @ColDefine(type=ColType.VARCHAR, width=100, notNull=true) 34 | private String type; 35 | 36 | @Column("value") 37 | @Comment("数据值") 38 | @ColDefine(type=ColType.VARCHAR, width=100, notNull=true) 39 | private String value; 40 | 41 | @Column("label") 42 | @Comment("标签名") 43 | @ColDefine(type=ColType.VARCHAR, width=100, notNull=true) 44 | private String label; 45 | 46 | @Column("description") 47 | @Comment("描述") 48 | @ColDefine(type=ColType.VARCHAR, width=100) 49 | private String description; 50 | 51 | @Column("sort") 52 | @Comment("排序(升序)") 53 | @ColDefine(type=ColType.INT, width=10, notNull=true) 54 | @Default("0") 55 | private int sort; 56 | 57 | @Comment("删除标记(0:正常,1:删除)") 58 | @ColDefine(type = ColType.CHAR, width = 1, notNull = true) 59 | @Column("del_flag") 60 | @Default("0") 61 | private String delFlag; 62 | 63 | public Long getId() { 64 | return id; 65 | } 66 | 67 | public void setId(Long id) { 68 | this.id = id; 69 | } 70 | 71 | public String getType() { 72 | return type; 73 | } 74 | 75 | public void setType(String type) { 76 | this.type = type; 77 | } 78 | 79 | public String getValue() { 80 | return value; 81 | } 82 | 83 | public void setValue(String value) { 84 | this.value = value; 85 | } 86 | 87 | public String getLabel() { 88 | return label; 89 | } 90 | 91 | public void setLabel(String label) { 92 | this.label = label; 93 | } 94 | 95 | public String getDescription() { 96 | return description; 97 | } 98 | 99 | public void setDescription(String description) { 100 | this.description = description; 101 | } 102 | 103 | public int getSort() { 104 | return sort; 105 | } 106 | 107 | public void setSort(int sort) { 108 | this.sort = sort; 109 | } 110 | 111 | public String getDelFlag() { 112 | return delFlag; 113 | } 114 | 115 | public void setDelFlag(String delFlag) { 116 | this.delFlag = delFlag; 117 | } 118 | 119 | 120 | 121 | } 122 | -------------------------------------------------------------------------------- /codegen/projects.yml: -------------------------------------------------------------------------------- 1 | WorkDir: .. 2 | props: 3 | slf4jVersion: "1.7.25" 4 | joddVersion: "3.8.5" 5 | bootVersion: "1.5.3.RELEASE" 6 | cloudVersion: Dalston.RELEASE 7 | mysqlVersion: "6.0.6" 8 | nutzVersion: "1.r.61" 9 | springSecurityVersion: "4.2.2.RELEASE" 10 | cloudSecurityVersion: "1.1.3.RELEASE" 11 | clientSecret: YFzCAfocMInyJ5YaO805 12 | jdbcUrl: "jdbc:mysql://127.0.0.1:3306/dataagg?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull" 13 | jdbcUser: "dataagg" 14 | jdbcPswd: "3yXcH7AIK7Wrs1sQeGJe" 15 | group: com.dataagg 16 | project: DAFramework 17 | version: 0.1 18 | plugins: [eclipse, idea, "'com.github.ben-manes.versions:0.14.0'"] 19 | description: DAFramework 20 | 21 | subProjects: 22 | commons: 23 | type: jar 24 | description: '公用实体类,VO及常用工具类' 25 | plugins: [java, eclipse, idea] 26 | archiveName: commons.jar 27 | deps: 28 | - compile 'org.jodd:jodd-core:${joddVersion}' 29 | - compile 'org.jodd:jodd-bean:${joddVersion}' 30 | - compile 'org.jodd:jodd-props:${joddVersion}' 31 | - compile 'com.google.code.gson:gson:2.8.0' 32 | - compile 'org.nutz:nutz:${nutzVersion}' 33 | - compile 'mysql:mysql-connector-java:${mysqlVersion}' 34 | - compile 'org.springframework.boot:spring-boot-starter-jdbc:${bootVersion}' 35 | - compile 'org.springframework.boot:spring-boot-starter-web:${bootVersion}' 36 | - compile 'org.springframework.boot:spring-boot-starter-security:${bootVersion}' 37 | - compile 'org.springframework.security:spring-security-core:${springSecurityVersion}' 38 | - compile 'org.springframework.security.oauth:spring-security-oauth2:2.0.13.RELEASE' 39 | - testCompile 'junit:junit:4.12' 40 | - testCompile 'org.springframework.boot:spring-boot-starter-test:${bootVersion}' 41 | config: 42 | logging: 43 | level: 44 | root: WARN 45 | com.dataagg: info 46 | # service-center: 47 | # description: eurekaServer(服务注册及发现) 48 | # ports: 8761 49 | # components: [springBoot, eurekaServer] 50 | # config: 51 | api-gateway: 52 | description: api-gateway(API网关)+security(权限检查服务) 53 | ports: 80 54 | components: [springBoot, starterWeb, zuul, feign, ':commons', starterJdbc] 55 | config: 56 | zuul: 57 | routes: 58 | core: 59 | path: /** 60 | url: http://127.0.0.1:6000/ 61 | stripPrefix: false 62 | # serviceId: core-service 63 | core-service: 64 | description: "核心服务 用户,组织,角色,菜单,字典,区域,附件等基础服务" 65 | ports: 6000 66 | components: [springBoot, feign, ':commons', starterWeb, starterJdbc, securityClient] 67 | docker: 68 | depends_on: [api-gateway] 69 | config: 70 | logging: 71 | level: 72 | root: WARN 73 | com.dataagg: info 74 | file: 75 | rootPath: e:\\wdtc\\html 76 | filePath: /files 77 | sms: 78 | #短信接口是否允许发送的标识,true允许,false不允许 79 | canSend: false 80 | -------------------------------------------------------------------------------- /codegen/gradle.yml: -------------------------------------------------------------------------------- 1 | WorkDir: .. 2 | GenType: gradle 3 | props: {} 4 | 5 | group: com.dataagg 6 | project: DAFramework 7 | version: 0.1 8 | description: DAFramework 9 | plugins: [eclipse, idea, 'com.github.ben-manes.versions:0.14.0'] 10 | subProjects: 11 | commons: 12 | version: 0.1 13 | description: 公用实体类,VO及常用工具类 14 | archiveName: commons.jar 15 | plugins: [java, eclipse, idea] 16 | deps: 17 | - compile 'org.jodd:jodd-core:3.8.5' 18 | - compile 'org.jodd:jodd-bean:3.8.5' 19 | - compile 'org.jodd:jodd-props:3.8.5' 20 | - compile 'com.google.code.gson:gson:2.8.0' 21 | - compile 'org.nutz:nutz:1.r.61' 22 | - compile 'mysql:mysql-connector-java:6.0.6' 23 | - compile 'org.springframework.boot:spring-boot-starter-jdbc:1.5.3.RELEASE' 24 | - compile 'org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE' 25 | - compile 'org.springframework.boot:spring-boot-starter-security:1.5.3.RELEASE' 26 | - compile 'org.springframework.security:spring-security-core:4.2.2.RELEASE' 27 | - compile 'org.springframework.security.oauth:spring-security-oauth2:2.0.13.RELEASE' 28 | - testCompile 'junit:junit:4.12' 29 | - testCompile 'org.springframework.boot:spring-boot-starter-test:1.5.3.RELEASE' 30 | api-gateway: 31 | version: 0.1 32 | description: api-gateway(API网关)+security(权限检查服务) 33 | archiveName: commons.jar 34 | plugins: [java, eclipse, idea, 'org.springframework.boot:1.5.3.RELEASE'] 35 | deps: 36 | - testCompile 'org.springframework.boot:spring-boot-starter-test' 37 | - compile 'org.springframework.boot:spring-boot-starter-web' 38 | - compile 'org.springframework.cloud:spring-cloud-starter-zuul' 39 | - compile 'org.springframework.cloud:spring-cloud-starter-feign' 40 | - compile project(':commons') 41 | - compile 'mysql:mysql-connector-java:6.0.6' 42 | - compile 'org.springframework.boot:spring-boot-starter-jdbc' 43 | dependencyManagement: 44 | - imports { mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE' } 45 | core-service: 46 | version: 0.1 47 | description: 核心服务 用户,组织,角色,菜单,字典,区域,附件等基础服务 48 | archiveName: app.jar 49 | plugins: [java, eclipse, idea, 'org.springframework.boot:1.5.3.RELEASE'] 50 | deps: 51 | - testCompile 'org.springframework.boot:spring-boot-starter-test' 52 | - compile 'org.springframework.cloud:spring-cloud-starter-feign' 53 | - compile project(':commons') 54 | - compile 'org.springframework.boot:spring-boot-starter-web' 55 | - compile 'mysql:mysql-connector-java:6.0.6' 56 | - compile 'org.springframework.boot:spring-boot-starter-jdbc' 57 | - compile 'org.springframework.boot:spring-boot-starter-security' 58 | - compile 'org.springframework.security.oauth:spring-security-oauth2' 59 | - compile 'org.springframework.cloud:spring-cloud-security:1.1.3.RELEASE' 60 | dependencyManagement: 61 | - imports { mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE' } 62 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/EAccessToken.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.domain; 2 | 3 | import org.nutz.dao.entity.annotation.Column; 4 | import org.nutz.dao.entity.annotation.Comment; 5 | import org.nutz.dao.entity.annotation.Id; 6 | import org.nutz.dao.entity.annotation.One; 7 | import org.nutz.dao.entity.annotation.Table; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * Created by watano on 2017/3/20. 13 | */ 14 | @Table("sys_access_token") 15 | @Comment("OAuth2 Access Token") 16 | public class EAccessToken { 17 | 18 | @Id 19 | private Long id; 20 | @Column 21 | private Long openUserId; 22 | @One(field = "openUserId") 23 | private EOpenUser openUser; 24 | @Column 25 | private String remoteAddress; 26 | @Column 27 | private String sessionId; 28 | @Column 29 | private String tokenValue; 30 | @Column 31 | private String tokenType; 32 | @Column 33 | private String refreshToken; 34 | @Column 35 | private Integer expiresIn; 36 | @Column 37 | private String scopes; 38 | 39 | private Map details; 40 | 41 | public Long getId() { 42 | return id; 43 | } 44 | 45 | public void setId(Long id) { 46 | this.id = id; 47 | } 48 | 49 | public Long getOpenUserId() { 50 | return openUserId; 51 | } 52 | 53 | public void setOpenUserId(Long openUserId) { 54 | this.openUserId = openUserId; 55 | } 56 | 57 | public EOpenUser getOpenUser() { 58 | return openUser; 59 | } 60 | 61 | public void setOpenUser(EOpenUser openUser) { 62 | this.openUser = openUser; 63 | } 64 | 65 | public Map getDetails() { 66 | return details; 67 | } 68 | 69 | public void setDetails(Map details) { 70 | this.details = details; 71 | } 72 | 73 | public String getRemoteAddress() { 74 | return remoteAddress; 75 | } 76 | 77 | public void setRemoteAddress(String remoteAddress) { 78 | this.remoteAddress = remoteAddress; 79 | } 80 | 81 | public String getSessionId() { 82 | return sessionId; 83 | } 84 | 85 | public void setSessionId(String sessionId) { 86 | this.sessionId = sessionId; 87 | } 88 | 89 | public String getTokenValue() { 90 | return tokenValue; 91 | } 92 | 93 | public void setTokenValue(String tokenValue) { 94 | this.tokenValue = tokenValue; 95 | } 96 | 97 | public String getTokenType() { 98 | return tokenType; 99 | } 100 | 101 | public void setTokenType(String tokenType) { 102 | this.tokenType = tokenType; 103 | } 104 | 105 | public String getRefreshToken() { 106 | return refreshToken; 107 | } 108 | 109 | public void setRefreshToken(String refreshToken) { 110 | this.refreshToken = refreshToken; 111 | } 112 | 113 | public Integer getExpiresIn() { 114 | return expiresIn; 115 | } 116 | 117 | public void setExpiresIn(Integer expiresIn) { 118 | this.expiresIn = expiresIn; 119 | } 120 | 121 | public String getScopes() { 122 | return scopes; 123 | } 124 | 125 | public void setScopes(String scopes) { 126 | this.scopes = scopes; 127 | } 128 | 129 | 130 | } 131 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/lang/ArithUtils.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.lang; 2 | 3 | import java.math.BigDecimal; 4 | 5 | /** 6 | * 由于Java的简单类型不能够精确的对浮点数进行运算, 这个工具类提供精确的浮点数运算,包括加减乘除和四舍五入。 7 | */ 8 | public final class ArithUtils { 9 | // 默认除法运算精度 10 | private static final int DEFAULT_DIV_SCALE = 10; 11 | 12 | // 这个类不能实例化 13 | private ArithUtils() { 14 | } 15 | 16 | /** 17 | * 提供精确的加法运算。 18 | * 19 | * @param v1 被加数 20 | * @param v2 加数 21 | * @return 两个参数的和 22 | */ 23 | public static Double add(Double v1, Double v2) { 24 | checkArguments(v1, v2); 25 | BigDecimal b1 = new BigDecimal(Double.toString(v1)); 26 | BigDecimal b2 = new BigDecimal(Double.toString(v2)); 27 | return b1.add(b2).doubleValue(); 28 | } 29 | 30 | /** 31 | * 提供精确的减法运算。 32 | * 33 | * @param v1 被减数 34 | * @param v2 减数 35 | * @return 两个参数的差 36 | */ 37 | public static Double sub(Double v1, Double v2) { 38 | checkArguments(v1, v2); 39 | BigDecimal b1 = new BigDecimal(Double.toString(v1)); 40 | BigDecimal b2 = new BigDecimal(Double.toString(v2)); 41 | return b1.subtract(b2).doubleValue(); 42 | } 43 | 44 | /** 45 | * 提供精确的乘法运算。 46 | * 47 | * @param v1 被乘数 48 | * @param v2 乘数 49 | * @return 两个参数的积 50 | */ 51 | public static Double mul(Double v1, Double v2) { 52 | checkArguments(v1, v2); 53 | BigDecimal b1 = new BigDecimal(Double.toString(v1)); 54 | BigDecimal b2 = new BigDecimal(Double.toString(v2)); 55 | return b1.multiply(b2).doubleValue(); 56 | } 57 | 58 | /** 59 | * 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到小数点以后10位,以后的数字四舍五入。 60 | * 61 | * @param v1 被除数 62 | * @param v2 除数 63 | * @return 两个参数的商 64 | */ 65 | public static Double div(Double v1, Double v2) { 66 | return div(v1, v2, DEFAULT_DIV_SCALE); 67 | } 68 | 69 | /** 70 | * 提供(相对)精确的除法运算。 当发生除不尽的情况时,由scale参数指定精度,以后的数字四舍五入。 71 | * 72 | * @param v1 被除数 73 | * @param v2 除数 74 | * @param scale 表示表示需要精确到小数点以后几位。 75 | * @return 两个参数的商 76 | */ 77 | public static Double div(Double v1, Double v2, int scale) { 78 | checkArguments(v1, v2); 79 | if (scale < 0) { 80 | throw new IllegalArgumentException("The scale must be a positive integer or zero"); 81 | } 82 | BigDecimal b1 = new BigDecimal(Double.toString(v1)); 83 | BigDecimal b2 = new BigDecimal(Double.toString(v2)); 84 | return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); 85 | } 86 | 87 | private static void checkArguments(Double v1, Double v2) { 88 | if (v1 == null || v2 == null) { 89 | throw new IllegalArgumentException("caculate error: argument v1 or v2 can not be null"); 90 | } 91 | } 92 | 93 | /** 94 | * 提供精确的小数位四舍五入处理。 95 | * 96 | * @param v 需要四舍五入的数字 97 | * @param scale 小数点后保留几位 98 | * @return 四舍五入后的结果 99 | */ 100 | public static Double round(Double v, int scale) { 101 | if (v == null) { 102 | return null; 103 | } 104 | if (scale < 0) { 105 | throw new IllegalArgumentException("The scale must be a positive integer or zero"); 106 | } 107 | BigDecimal b = new BigDecimal(Double.toString(v)); 108 | BigDecimal one = new BigDecimal("1"); 109 | return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/CoreServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dataagg; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 9 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 10 | import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 14 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 15 | import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; 16 | import org.springframework.security.oauth2.client.OAuth2RestTemplate; 17 | import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; 18 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; 19 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 20 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 21 | import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; 22 | 23 | import com.dataagg.account.service.security.CustomUserInfoTokenServices; 24 | 25 | import feign.RequestInterceptor; 26 | 27 | @SpringBootApplication 28 | @EnableResourceServer 29 | //@EnableDiscoveryClient 30 | @EnableOAuth2Client 31 | @EnableFeignClients 32 | @EnableGlobalMethodSecurity(prePostEnabled = true) 33 | @EnableConfigurationProperties 34 | @Configuration 35 | public class CoreServiceApplication extends ResourceServerConfigurerAdapter { 36 | 37 | @Autowired 38 | private ResourceServerProperties sso; 39 | 40 | public static void main(String[] args) { 41 | SpringApplication.run(CoreServiceApplication.class, args); 42 | } 43 | 44 | @Bean 45 | @ConfigurationProperties(prefix = "security.oauth2.client") 46 | public ClientCredentialsResourceDetails clientCredentialsResourceDetails() { 47 | return new ClientCredentialsResourceDetails(); 48 | } 49 | 50 | @Bean 51 | public RequestInterceptor oauth2FeignRequestInterceptor() { 52 | return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails()); 53 | } 54 | 55 | @Bean 56 | public OAuth2RestTemplate clientCredentialsRestTemplate() { 57 | return new OAuth2RestTemplate(clientCredentialsResourceDetails()); 58 | } 59 | 60 | @Bean 61 | public ResourceServerTokenServices tokenServices() { 62 | return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); 63 | } 64 | 65 | @Override 66 | public void configure(HttpSecurity http) throws Exception { 67 | http.authorizeRequests().antMatchers("/", "/demo").permitAll().anyRequest().authenticated(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/WMap.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import org.nutz.lang.util.NutMap; 4 | 5 | import java.util.ArrayList; 6 | import java.util.LinkedHashSet; 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.Set; 10 | 11 | /** 12 | * Created by watano on 2017/3/4. 13 | */ 14 | public class WMap extends NutMap { 15 | private static final long serialVersionUID = -852470603991540244L; 16 | 17 | public WMap() { 18 | super(); 19 | } 20 | 21 | public WMap(Map data) { 22 | super(data); 23 | } 24 | 25 | public String string(String key) { 26 | return this.getAs(key, String.class); 27 | } 28 | 29 | public String[] strings(String key) { 30 | List strings = new ArrayList<>(); 31 | for (Object v : this.getArray(key, Object.class)) { 32 | strings.add(v.toString()); 33 | } 34 | return strings.toArray(new String[]{}); 35 | } 36 | 37 | public String[] stringsNoDuplicate(String key) { 38 | Set strings = new LinkedHashSet<>(); 39 | for (Object v : this.getArray(key, Object.class)) { 40 | strings.add(v.toString()); 41 | } 42 | return strings.toArray(new String[]{}); 43 | } 44 | 45 | public WMap map(String key) { 46 | return this.getAs(key, WMap.class); 47 | } 48 | 49 | public List list(String key) { 50 | return this.getAs(key, List.class); 51 | } 52 | 53 | public void addAll(WMap data2) { 54 | for (String key : data2.keySet()) { 55 | addX(key, data2.get(key)); 56 | } 57 | } 58 | 59 | @SuppressWarnings({ "unchecked", "rawtypes" }) 60 | public void addX(String key, Object value) { 61 | if (value == null) { 62 | return; 63 | } 64 | Object currValue = get(key); 65 | if (currValue == null) { 66 | put(key, value); 67 | } else if (currValue instanceof Map && value instanceof Map) { 68 | WMap obj = map(key); 69 | Map vObj = (Map) value; 70 | for (Object k : vObj.keySet()) { 71 | obj.addX(k.toString(), vObj.get(k)); 72 | } 73 | put(key, obj); 74 | } else if (currValue instanceof List) { 75 | List lst = getList(key, Object.class); 76 | if (value instanceof List) { 77 | lst.addAll((List) value); 78 | } else if (value instanceof Object[]) { 79 | for(Object o:(Object[])value){ 80 | lst.add(o); 81 | } 82 | } else { 83 | lst.add(value); 84 | } 85 | put(key, lst); 86 | } else if (value instanceof List) { 87 | ((List) value).add(currValue); 88 | put(key, value); 89 | } else if (value instanceof Object[]) { 90 | List all = new ArrayList<>(); 91 | all.add(currValue); 92 | for(Object o:(Object[])value){ 93 | all.add(o); 94 | } 95 | put(key, all); 96 | } else { 97 | put(key, value); 98 | } 99 | } 100 | 101 | public static Set convert(List lst) { 102 | Set set = new LinkedHashSet<>(); 103 | if (lst != null) { 104 | for (T o : lst) { 105 | if (!set.contains(o)) { 106 | set.add(o); 107 | } 108 | } 109 | } 110 | return set; 111 | } 112 | 113 | @SafeVarargs 114 | public static Set convert(T... lst) { 115 | Set set = new LinkedHashSet<>(); 116 | if (lst != null) { 117 | for (T o : lst) { 118 | if (!set.contains(o)) { 119 | set.add(o); 120 | } 121 | } 122 | } 123 | return set; 124 | } 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /core-service/src/test/java/com/dataagg/account/controller/AccountControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.account.controller; 2 | 3 | import java.util.Date; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | import org.springframework.test.context.web.WebAppConfiguration; 13 | import org.springframework.test.web.servlet.MockMvc; 14 | import org.springframework.test.web.servlet.MvcResult; 15 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 16 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 17 | import org.springframework.web.context.WebApplicationContext; 18 | 19 | import com.dataagg.CoreServiceApplication; 20 | import com.dataagg.commons.domain.EAccount; 21 | import com.dataagg.util.SearchQueryJS; 22 | import com.dataagg.util.WMap; 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @SpringBootTest(classes = CoreServiceApplication.class) 27 | @WebAppConfiguration 28 | public class AccountControllerTest { 29 | 30 | private static final ObjectMapper mapper = new ObjectMapper(); 31 | 32 | @Autowired 33 | private WebApplicationContext webApplicationConnect; 34 | 35 | private MockMvc mockMvc; 36 | 37 | @Before 38 | public void setup() { 39 | mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationConnect).build(); 40 | } 41 | 42 | @Test 43 | public void get() throws Exception { 44 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/account/get/1").accept(MediaType.APPLICATION_JSON)).andReturn(); 45 | int status = mvcResult.getResponse().getStatus(); 46 | String content = mvcResult.getResponse().getContentAsString(); 47 | System.out.println(status + "--" + content); 48 | } 49 | 50 | @Test 51 | public void page() throws Exception { 52 | SearchQueryJS queryJs = new SearchQueryJS(); 53 | WMap map = new WMap(); 54 | map.put("full_name", "名"); 55 | queryJs.setQuery(map); 56 | 57 | String json = mapper.writeValueAsString(queryJs); 58 | 59 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/account/list").contentType(MediaType.APPLICATION_JSON).content(json)).andReturn(); 60 | int status = mvcResult.getResponse().getStatus(); 61 | String content = mvcResult.getResponse().getContentAsString(); 62 | System.out.println(status + "--" + content); 63 | } 64 | 65 | // @Test 66 | public void save() throws Exception { 67 | EAccount account = new EAccount(); 68 | account.setFullName("用户全名"); 69 | account.setMobile("13987725457"); 70 | account.setEmail("362527240@qq.com"); 71 | account.setAddress("大帝国"); 72 | account.setComment("这是备注" + new Date()); 73 | account.setUserId(1L); 74 | account.setOrgId(1L); 75 | account.setNumber("530404199007777777"); 76 | 77 | String json = mapper.writeValueAsString(account); 78 | 79 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/account/save").contentType(MediaType.APPLICATION_JSON).content(json)).andReturn(); 80 | int status = mvcResult.getResponse().getStatus(); 81 | String content = mvcResult.getResponse().getContentAsString(); 82 | System.out.println(status + "--" + content); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /core-service/src/test/java/com/dataagg/commons/controller/OrgControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.controller; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.mockito.InjectMocks; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.MvcResult; 14 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 15 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 16 | import org.springframework.web.context.WebApplicationContext; 17 | 18 | import com.dataagg.CoreServiceApplication; 19 | import com.dataagg.commons.domain.EOrg; 20 | import com.dataagg.commons.service.OrgService; 21 | import com.dataagg.util.SearchQueryJS; 22 | import com.dataagg.util.WMap; 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @SpringBootTest(classes = CoreServiceApplication.class) 27 | @WebAppConfiguration 28 | public class OrgControllerTest { 29 | 30 | private static final ObjectMapper mapper = new ObjectMapper(); 31 | 32 | @InjectMocks 33 | private OrgController orgController; 34 | 35 | @Autowired 36 | private WebApplicationContext webApplicationConnect; 37 | @Autowired 38 | private OrgService orgService; 39 | 40 | private MockMvc mockMvc; 41 | 42 | @Before 43 | public void setup() { 44 | mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationConnect).build(); 45 | } 46 | 47 | // @Test 48 | public void save() throws Exception { 49 | final EOrg org = new EOrg(); 50 | org.setName("测试项目" + System.currentTimeMillis()); 51 | org.setCode("001"); 52 | org.setCode("10000"); 53 | orgService.save(org); 54 | 55 | String json = mapper.writeValueAsString(org); 56 | 57 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/org/save").contentType(MediaType.APPLICATION_JSON).content(json)).andReturn(); 58 | int status = mvcResult.getResponse().getStatus(); 59 | String content = mvcResult.getResponse().getContentAsString(); 60 | System.out.println(status + "--" + content); 61 | } 62 | 63 | @Test 64 | public void get() throws Exception { 65 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/org/3").accept(MediaType.APPLICATION_JSON)).andReturn(); 66 | int status = mvcResult.getResponse().getStatus(); 67 | String content = mvcResult.getResponse().getContentAsString(); 68 | System.out.println(status + "--" + content); 69 | } 70 | 71 | @Test 72 | public void page() throws Exception { 73 | SearchQueryJS queryJs = new SearchQueryJS(); 74 | WMap query = new WMap(); 75 | query.put("name", "83945332"); 76 | query.put("code", "002"); 77 | queryJs.setQuery(query); 78 | String json = mapper.writeValueAsString(queryJs); 79 | MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/org/list").contentType(MediaType.APPLICATION_JSON).content(json)).andReturn(); 80 | int status = mvcResult.getResponse().getStatus(); 81 | String content = mvcResult.getResponse().getContentAsString(); 82 | System.out.println(status + "--" + content); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/xml/XPathEvaluator.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.xml; 2 | 3 | import com.dataagg.util.lang.ArgCheck; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.w3c.dom.Node; 7 | import org.w3c.dom.NodeList; 8 | 9 | import javax.xml.namespace.QName; 10 | import javax.xml.xpath.XPath; 11 | import javax.xml.xpath.XPathConstants; 12 | import javax.xml.xpath.XPathExpression; 13 | import javax.xml.xpath.XPathExpressionException; 14 | import javax.xml.xpath.XPathFactory; 15 | import java.util.ArrayList; 16 | import java.util.Hashtable; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | public class XPathEvaluator { 21 | private static final Logger LOG = LoggerFactory.getLogger(XPathEvaluator.class); 22 | private XPathFactory factory = null; 23 | private XPath xpath = null; 24 | private Map expCache; 25 | 26 | public XPathEvaluator() { 27 | init(); 28 | } 29 | 30 | public void init() { 31 | factory = XPathFactory.newInstance(); 32 | xpath = factory.newXPath(); 33 | expCache = new Hashtable(); 34 | } 35 | 36 | /** 37 | * @param node 38 | * @param exp 39 | * @param returnType XPathConstants.NODESET 40 | * @return 41 | */ 42 | public Object evaluate(Node node, String exp, QName returnType) { 43 | try { 44 | XPathExpression expr = getExpr(exp); 45 | if (expr != null) { 46 | return expr.evaluate(node, returnType); 47 | } 48 | } catch (Exception e) { 49 | LOG.error(e.getMessage(), e); 50 | } 51 | return null; 52 | } 53 | 54 | public Object evaluate(Node node, String exp) { 55 | try { 56 | XPathExpression expr = getExpr(exp); 57 | if (expr != null) { 58 | return expr.evaluate(node); 59 | } 60 | } catch (Exception e) { 61 | LOG.error(e.getMessage(), e); 62 | } 63 | return null; 64 | } 65 | 66 | public NodeList findNodes(Node node, String exp) { 67 | return (NodeList) evaluate(node, exp, XPathConstants.NODESET); 68 | } 69 | 70 | public Node findOneNode(Node node, String exp) { 71 | NodeList nodes = findNodes(node, exp); 72 | if (nodes != null && nodes.getLength() > 0) { 73 | return nodes.item(0); 74 | } 75 | return null; 76 | } 77 | 78 | public XPathExpression getExpr(String exp) { 79 | XPathExpression expr = expCache.get(exp); 80 | if (expr == null) { 81 | try { 82 | expr = xpath.compile(exp); 83 | if (expr != null) { 84 | expCache.put(exp, expr); 85 | } 86 | return expr; 87 | } catch (XPathExpressionException e) { 88 | LOG.error(e.getMessage(), e); 89 | return null; 90 | } 91 | } 92 | return expr; 93 | } 94 | 95 | public String[] getNodesAttr(Node node, String exp, String attrName) { 96 | List qs = new ArrayList(); 97 | try { 98 | NodeList nodes = findNodes(node, exp); 99 | if (nodes != null && nodes.getLength() > 0) { 100 | for (int i = 0; i < nodes.getLength(); i++) { 101 | qs.add(XmlUtil.getAttribute(nodes.item(i), attrName)); 102 | } 103 | } 104 | } catch (Exception e) { 105 | } 106 | return qs.toArray(new String[]{}); 107 | } 108 | 109 | public String getNodeAttr(Node node, String exp, String attrName) { 110 | Node n = findOneNode(node, exp); 111 | ArgCheck.checkNotNull(n); 112 | return XmlUtil.getAttribute(n, attrName); 113 | } 114 | 115 | public String getNodeText(Node node, String exp) { 116 | Node n = findOneNode(node, exp); 117 | ArgCheck.checkNotNull(n); 118 | return n.getTextContent(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/WJsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import com.google.gson.ExclusionStrategy; 4 | import com.google.gson.FieldAttributes; 5 | import com.google.gson.GsonBuilder; 6 | import jodd.io.FileUtil; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.lang.reflect.ParameterizedType; 13 | import java.lang.reflect.Type; 14 | 15 | public class WJsonUtils { 16 | private static final Logger LOG = LoggerFactory.getLogger(WJsonUtils.class); 17 | 18 | /** 19 | * 根据cls和泛型类型反序列化json字符串 20 | * 21 | * @param json 22 | * @param cls 23 | * @param genericCls 24 | * @return 25 | */ 26 | public static T toObject(String json, Class cls, Type... genericCls) { 27 | ParameterizedType pt = new ParameterizedType() { 28 | @Override 29 | public Type[] getActualTypeArguments() { 30 | return genericCls; 31 | } 32 | 33 | @Override 34 | public Type getRawType() { 35 | return cls; 36 | } 37 | 38 | @Override 39 | public Type getOwnerType() { 40 | return null; 41 | } 42 | }; 43 | return getGsonBuilder().create().fromJson(json, pt); 44 | } 45 | 46 | /** 47 | * 根据cls反序列化json字符串 48 | * 49 | * @param json 50 | * @param cls 51 | * @return 52 | */ 53 | public static T fromJson(String json, Class cls) { 54 | return (T) getGsonBuilder().create().fromJson(json, cls); 55 | } 56 | 57 | public static T fromJson(File f, Class cls) { 58 | try { 59 | return fromJson(FileUtil.readString(f, "utf-8"), cls); 60 | } catch (Exception e) { 61 | LOG.error(e.getMessage(), e); 62 | return null; 63 | } 64 | } 65 | 66 | public static JsonObjGetter fromJson(File f) { 67 | try { 68 | return fromJson(FileUtil.readString(f, "utf-8")); 69 | } catch (Exception e) { 70 | LOG.error(e.getMessage(), e); 71 | return null; 72 | } 73 | } 74 | 75 | public static JsonObjGetter fromJson(String json) { 76 | try { 77 | return new JsonObjGetter(getGsonBuilder().create().fromJson(json, Object.class)); 78 | } catch (Exception e) { 79 | LOG.error(e.getMessage(), e); 80 | return null; 81 | } 82 | } 83 | 84 | public static String toJson(Object obj) { 85 | return getGsonBuilder().create().toJson(obj); 86 | } 87 | 88 | public static String toJson(Object obj, boolean prettyPrinting) { 89 | return getGsonBuilder(prettyPrinting).create().toJson(obj); 90 | } 91 | 92 | public static void writeJson(String file, Object obj) { 93 | try { 94 | FileUtil.writeString(file, getGsonBuilder().create().toJson(obj), "utf-8"); 95 | } catch (IOException e) { 96 | LOG.error(e.getMessage(), e); 97 | } 98 | } 99 | 100 | /** 101 | * 构建通用GsonBuilder, 封装初始化工作 102 | * 103 | * @return 104 | */ 105 | public static GsonBuilder getGsonBuilder() { 106 | return getGsonBuilder(LOG.isDebugEnabled()); 107 | } 108 | 109 | /** 110 | * 构建通用GsonBuilder, 封装初始化工作 111 | * 112 | * @return 113 | */ 114 | public static GsonBuilder getGsonBuilder(boolean prettyPrinting) { 115 | GsonBuilder gb = new GsonBuilder(); 116 | gb.setDateFormat("yyyy-MM-dd HH:mm:ss:mss"); 117 | gb.setExclusionStrategies(new ExclusionStrategy() { 118 | @Override 119 | public boolean shouldSkipField(FieldAttributes f) { 120 | return f.getAnnotation(WJsonExclued.class) != null; 121 | } 122 | 123 | @Override 124 | public boolean shouldSkipClass(Class clazz) { 125 | return clazz.getAnnotation(WJsonExclued.class) != null; 126 | } 127 | }); 128 | if (prettyPrinting) 129 | gb.setPrettyPrinting(); 130 | return gb; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/EUser.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.domain; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.nutz.dao.entity.annotation.ColDefine; 7 | import org.nutz.dao.entity.annotation.ColType; 8 | import org.nutz.dao.entity.annotation.Column; 9 | import org.nutz.dao.entity.annotation.Comment; 10 | import org.nutz.dao.entity.annotation.Default; 11 | import org.nutz.dao.entity.annotation.Id; 12 | import org.nutz.dao.entity.annotation.ManyMany; 13 | import org.nutz.dao.entity.annotation.One; 14 | import org.nutz.dao.entity.annotation.Table; 15 | import org.springframework.security.core.userdetails.UserDetails; 16 | 17 | @Table("sys_user") 18 | @Comment("用户信息") 19 | public class EUser implements UserDetails { 20 | private static final long serialVersionUID = 1485837934469013198L; 21 | 22 | @Id 23 | private Long id; 24 | 25 | @Column(hump = true, value = "username") 26 | @ColDefine(type = ColType.VARCHAR, width = 64, notNull = true) 27 | private String username; 28 | 29 | @Column 30 | private String password; 31 | 32 | private String oldPassword; 33 | 34 | @Column("org_id") 35 | @Comment("所属机构Id") 36 | @ColDefine(type = ColType.INT, width = 20, notNull = true) 37 | private Long orgId; 38 | 39 | @Comment("所属机构类型") 40 | private String orgType; 41 | 42 | @Comment("删除标记(0:正常,1:删除)") 43 | @Column("del_flag") 44 | @ColDefine(type = ColType.CHAR, width = 1, notNull = true) 45 | @Default("0") 46 | private String delFlag; 47 | 48 | private List grantedAuthorities = new ArrayList<>(); 49 | 50 | @ManyMany(relation = "sys_user_role", from = "userid", to = "roleid") 51 | private List roles = new ArrayList<>(); 52 | 53 | @One(field = "id", key = "userId") 54 | private EAccount account; 55 | 56 | @Override 57 | public String getPassword() { 58 | return password; 59 | } 60 | 61 | @Override 62 | public String getUsername() { 63 | return username; 64 | } 65 | 66 | public void setGrantedAuthorities(List grantedAuthorities) { 67 | this.grantedAuthorities = grantedAuthorities; 68 | } 69 | 70 | @Override 71 | public List getAuthorities() { 72 | return grantedAuthorities; 73 | } 74 | 75 | public Long getId() { 76 | return id; 77 | } 78 | 79 | public void setId(Long id) { 80 | this.id = id; 81 | } 82 | 83 | public Long getOrgId() { 84 | return orgId; 85 | } 86 | 87 | public void setOrgId(Long orgId) { 88 | this.orgId = orgId; 89 | } 90 | 91 | public void setUsername(String username) { 92 | this.username = username; 93 | } 94 | 95 | public void setPassword(String password) { 96 | this.password = password; 97 | } 98 | 99 | public List getRoles() { 100 | return roles; 101 | } 102 | 103 | public void setRoles(List roles) { 104 | this.roles = roles; 105 | } 106 | 107 | public EAccount getAccount() { 108 | return account; 109 | } 110 | 111 | public void setAccount(EAccount account) { 112 | this.account = account; 113 | } 114 | 115 | @Override 116 | public boolean isAccountNonExpired() { 117 | return true; 118 | } 119 | 120 | @Override 121 | public boolean isAccountNonLocked() { 122 | return true; 123 | } 124 | 125 | @Override 126 | public boolean isCredentialsNonExpired() { 127 | return true; 128 | } 129 | 130 | @Override 131 | public boolean isEnabled() { 132 | return true; 133 | } 134 | 135 | public String getDelFlag() { 136 | return delFlag; 137 | } 138 | 139 | public void setDelFlag(String delFlag) { 140 | this.delFlag = delFlag; 141 | } 142 | 143 | public String getOldPassword() { 144 | return oldPassword; 145 | } 146 | 147 | public void setOldPassword(String oldPassword) { 148 | this.oldPassword = oldPassword; 149 | } 150 | 151 | 152 | 153 | @Override 154 | public String toString() { 155 | return "EUser{" + "id=" + id + ", username='" + username + "\'}"; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/SysToolkit.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.StringWriter; 7 | import java.nio.file.FileSystems; 8 | import java.nio.file.Files; 9 | import java.nio.file.LinkOption; 10 | import java.nio.file.attribute.BasicFileAttributes; 11 | 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import jodd.io.FileUtil; 16 | import jodd.io.FileUtilParams; 17 | import jodd.io.StreamUtil; 18 | import jodd.util.StringUtil; 19 | 20 | public class SysToolkit { 21 | private static final Logger LOG = LoggerFactory.getLogger(SysToolkit.class); 22 | 23 | public static void exec(String cmd, String cwd, boolean showError, boolean showOut) throws Exception { 24 | Process p = Runtime.getRuntime().exec("cmd /c " + cmd, null, new File(cwd)); 25 | if (showOut) { 26 | StringWriter sw = new StringWriter(); 27 | StreamUtil.copy(p.getInputStream(), sw, "gbk"); 28 | String out = sw.toString().trim(); 29 | if (out.length() > 0) { 30 | LOG.info(out); 31 | } 32 | } 33 | if (showError) { 34 | StringWriter sw = new StringWriter(); 35 | StreamUtil.copy(p.getErrorStream(), sw, "gbk"); 36 | String error = sw.toString().trim(); 37 | if (error.length() > 0) { 38 | LOG.error(cmd + "\n" + error); 39 | throw new Exception(error); 40 | } 41 | } 42 | } 43 | 44 | public static boolean isSymbolicLink(String path) throws Exception { 45 | BasicFileAttributes attrs = Files.readAttributes(FileSystems.getDefault().getPath(polishFilePath(path)), BasicFileAttributes. 46 | 47 | class, LinkOption.NOFOLLOW_LINKS); 48 | return attrs.isSymbolicLink(); 49 | } 50 | 51 | public static void mklink(String target, String source) throws Exception { 52 | File fTarget = new File(polishFilePath(target)); 53 | if (fTarget.exists() && fTarget.isDirectory()) { 54 | if (isSymbolicLink(target)) { 55 | exec("rd /q " + fTarget.getAbsolutePath(), ".", true, true); 56 | } else { 57 | FileUtil.deleteDir(fTarget); 58 | } 59 | } 60 | if (!fTarget.getParentFile().exists()) { 61 | FileUtil.mkdirs(fTarget.getParentFile()); 62 | } 63 | File fSource = new File(polishFilePath(source)); 64 | if (fSource.isDirectory()) { 65 | exec("mklink /d " + target + " " + source, ".", true, true); 66 | } else { 67 | exec("mklink /h " + target + " " + source, ".", true, true); 68 | } 69 | } 70 | 71 | public 72 | 73 | static void copyDir(String srcDir, String destDir) throws Exception { 74 | FileUtil.copyDir(polishFilePath(srcDir), polishFilePath(destDir)); 75 | } 76 | 77 | public 78 | 79 | static void copyFile(String srcDir, String destDir) throws Exception { 80 | FileUtil.copyFile(polishFilePath(srcDir), polishFilePath(destDir)); 81 | } 82 | 83 | public 84 | 85 | static String polishFilePath(String path) { 86 | String path2 = StringUtil.replace(path, "\\", File.separator); 87 | path2 = StringUtil.replace(path2, "/", File.separator); 88 | return path2; 89 | } 90 | 91 | public static void delFiles(String file) throws Exception { 92 | File f = new File(polishFilePath(file)); 93 | if (f.exists()) { 94 | LOG.info("删除" + file); 95 | if (f.isDirectory()) { 96 | if (isSymbolicLink(file)) { 97 | exec("rd /q " + f.getAbsolutePath() + "", ".", true, true); 98 | } else { 99 | FileUtil.deleteDir(f.getAbsolutePath(), new FileUtilParams().setRecursive(true).setContinueOnError(false)); 100 | } 101 | } else { 102 | FileUtil.delete(f.getAbsolutePath(), new FileUtilParams().setContinueOnError(false)); 103 | } 104 | } 105 | } 106 | 107 | public static String readFromClassPath(Object classLoader, String path) throws IOException { 108 | InputStream inputStream = classLoader.getClass().getClassLoader().getResourceAsStream(path); 109 | return new String(StreamUtil.readBytes(inputStream), "utf8"); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/lang/MoneyUtil.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.lang; 2 | 3 | import java.math.BigDecimal; 4 | import java.text.DecimalFormat; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import jodd.util.StringUtil; 9 | 10 | public class MoneyUtil { 11 | /** 12 | * 判断2个金额是否相等。因为存储精度的问题,当2个金额差额小于0.001时,就认为这2个金额相等 13 | * 14 | * @param money1 15 | * @param money2 16 | * @return 17 | */ 18 | public static boolean equals(Double money1, Double money2) { 19 | return (money1 == null && money2 == null) 20 | || (money1 != null && money2 != null && Math.abs(money1 - money2) < 0.001); 21 | } 22 | 23 | /** 24 | * 修正金额,精确到2位小数 25 | * 26 | * @param price 27 | * @return 28 | */ 29 | public static Double fixPrice(Double price) { 30 | return ArithUtils.round(price, 2); 31 | } 32 | 33 | /** 34 | * 修正折扣(以10为单位),精确到1位小数 35 | * 36 | * @param discount 37 | * @return 38 | */ 39 | public static Double fixDiscount(Double discount) { 40 | return ArithUtils.round(discount, 1); 41 | } 42 | 43 | /** 44 | * 获取一组金额(单价*数量)加权平均的结果 45 | * 46 | * @param amounts 47 | * @return 48 | */ 49 | public static Double getWeightedAverage(Map amounts) { 50 | Double totalAmount = 0d; 51 | Long quantity = 0L; 52 | if (amounts != null && amounts.size() > 0) { 53 | for (Double money : amounts.keySet()) { 54 | Double amount = ArithUtils.mul(money, amounts.get(money).doubleValue()); 55 | totalAmount = ArithUtils.add(totalAmount, amount); 56 | quantity += amounts.get(money); 57 | } 58 | } 59 | return ArithUtils.div(totalAmount, quantity.doubleValue()); 60 | } 61 | 62 | /** 63 | * 获取2个金额(单价*数量)加权平均的结果 64 | * 65 | * @param money1 66 | * @param quantity1 67 | * @param money2 68 | * @param quantity2 69 | * @return 70 | */ 71 | public static Double getWeightedAverage(Double money1, Long quantity1, Double money2, Long quantity2) { 72 | if (equals(money1, money2)) { 73 | return money1; 74 | } 75 | Map amounts = new HashMap(); 76 | amounts.put(money1, quantity1); 77 | amounts.put(money2, quantity2); 78 | return MoneyUtil.getWeightedAverage(amounts); 79 | } 80 | 81 | /** 82 | * 金额格式化 逗号拼接 83 | * 84 | * @return 85 | */ 86 | public static String formatMoney(Object money, int bit) { 87 | try { 88 | if (money == null || money.toString() == "") { 89 | money = 0.0; 90 | } 91 | StringBuffer formatStr = new StringBuffer("#,###,##0"); 92 | if (bit < 0) { 93 | bit = 0; 94 | } 95 | if (bit > 0) { 96 | formatStr.append("."); 97 | } 98 | for (int i = 0; i < bit; i++) { 99 | formatStr.append("#"); 100 | } 101 | if (parseDouble(money).compareTo(0.0) > 0) { 102 | return numberFormat(parseDouble(money), formatStr.toString()); 103 | } else { 104 | return ""; 105 | } 106 | } catch (Exception e) { 107 | } 108 | return ""; 109 | } 110 | 111 | public static Long parseLong(Object number) { 112 | if (number != null && number instanceof Number) { 113 | return ((Number) number).longValue(); 114 | } else if (number != null && number instanceof BigDecimal) { 115 | return ((Number) number).longValue(); 116 | } else if (number != null && StringUtil.isNotBlank(number.toString())) { 117 | return Long.parseLong(number.toString().trim()); 118 | } 119 | return null; 120 | } 121 | 122 | public static Double parseDouble(Object number) { 123 | if (number != null && number instanceof Number) { 124 | return ((Number) number).doubleValue(); 125 | } else if (number != null && number instanceof BigDecimal) { 126 | return ((Number) number).doubleValue(); 127 | } else if (number != null && StringUtil.isNotBlank(number.toString())) { 128 | return Double.parseDouble(number.toString().trim()); 129 | } 130 | return null; 131 | } 132 | 133 | public static String numberFormat(Object object, String format) { 134 | DecimalFormat myformat = new DecimalFormat(); 135 | myformat.applyPattern(format); 136 | return myformat.format(object); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/text/VCard.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.text; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | 5 | public class VCard { 6 | public String name; 7 | public String telephone; 8 | public String address; 9 | 10 | public VCard() { 11 | } 12 | 13 | public VCard(String name, String telephone) { 14 | super(); 15 | this.name = name; 16 | this.telephone = telephone; 17 | } 18 | 19 | public String toText() throws Exception { 20 | StringBuffer sb = new StringBuffer(); 21 | sb.append("BEGIN:VCARD\n"); 22 | sb.append("VERSION:3.0\n"); 23 | if (name != null && name.trim().length() > 0) { 24 | sb.append("FN:" + name + "\n"); 25 | sb.append("N:" + name + ";;;\n"); 26 | } 27 | if (telephone != null && telephone.trim().length() > 0) { 28 | sb.append("TEL;TYPE=CELL:" + telephone + "\n"); 29 | } 30 | if (address != null && address.trim().length() > 0) { 31 | sb.append("ADR;TYPE=HOME:;;" + address + ";;;;\n"); 32 | } 33 | sb.append("END:VCARD\n"); 34 | return sb.toString(); 35 | } 36 | 37 | /** 38 | * 编码 UTF8 quoted-printable 39 | * 40 | * @param str 需要编码的字符串 41 | * @return 编码后的字符串 42 | * @throws Exception 43 | */ 44 | public static String qpEncodeingUTF8(String str) throws Exception { 45 | if (str != null) { 46 | char[] encode = str.toCharArray(); 47 | StringBuffer sb = new StringBuffer(); 48 | for (int i = 0; i < encode.length; i++) { 49 | if ((encode[i] >= '!') && (encode[i] <= '~') 50 | && (encode[i] != '=') && (encode[i] != '\n')) { 51 | sb.append(encode[i]); 52 | } else if (encode[i] == '=') { 53 | sb.append("=3D"); 54 | } else if (encode[i] == '\n') { 55 | sb.append("\n"); 56 | } else { 57 | StringBuffer sbother = new StringBuffer(); 58 | sbother.append(encode[i]); 59 | String ss = sbother.toString(); 60 | byte[] buf = null; 61 | buf = ss.getBytes("utf-8"); 62 | // UTF-8: buf.length == 3 63 | // GBK: buf.length == 2 64 | if (buf.length == 3) { 65 | for (int j = 0; j < buf.length; j++) { 66 | String s16 = String.valueOf(Integer.toHexString(buf[j])); 67 | char c16_6; 68 | char c16_7; 69 | if (s16.charAt(6) >= 97 && s16.charAt(6) <= 122) { 70 | c16_6 = (char) (s16.charAt(6) - 32); 71 | } else { 72 | c16_6 = s16.charAt(6); 73 | } 74 | if (s16.charAt(7) >= 97 && s16.charAt(7) <= 122) { 75 | c16_7 = (char) (s16.charAt(7) - 32); 76 | } else { 77 | c16_7 = s16.charAt(7); 78 | } 79 | sb.append("=" + c16_6 + c16_7); 80 | } 81 | } 82 | } 83 | } 84 | str = sb.toString(); 85 | } 86 | return str; 87 | } 88 | 89 | /** 90 | * 解码 UTF8 quoted-printable 91 | * 92 | * @param str 需要解码的字符串 93 | * @return 解码后的字符串 94 | * @throws Exception 95 | */ 96 | public static String qpDecodingUTF8(String str) throws Exception { 97 | if (str != null) { 98 | StringBuffer sb = new StringBuffer(str); 99 | for (int i = 0; i < sb.length(); i++) { 100 | if (sb.charAt(i) == '\n' && sb.charAt(i - 1) == '=') { 101 | sb.deleteCharAt(i - 1); 102 | } 103 | } 104 | str = sb.toString(); 105 | byte[] bytes = str.getBytes("US-ASCII"); 106 | for (int i = 0; i < bytes.length; i++) { 107 | byte b = bytes[i]; 108 | if (b != 95) { 109 | bytes[i] = b; 110 | } else { 111 | bytes[i] = 32; 112 | } 113 | } 114 | if (bytes != null) { 115 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 116 | for (int i = 0; i < bytes.length; i++) { 117 | int b = bytes[i]; 118 | if (b == '=') { 119 | try { 120 | int u = Character.digit((char) bytes[++i], 16); 121 | int l = Character.digit((char) bytes[++i], 16); 122 | if (u == -1 || l == -1) { 123 | continue; 124 | } 125 | buffer.write((char) ((u << 4) + l)); 126 | } catch (ArrayIndexOutOfBoundsException e) { 127 | e.printStackTrace(); 128 | } 129 | } else { 130 | buffer.write(b); 131 | } 132 | } 133 | str = new String(buffer.toByteArray(), "UTF-8"); 134 | } 135 | } 136 | return str; 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/collection/MapUtil.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.collection; 2 | 3 | import java.util.Iterator; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | @SuppressWarnings("unchecked") 8 | public class MapUtil { 9 | public static Object traverse(MapTraverser action) { 10 | Iterator keys = action.getMap().keySet().iterator(); 11 | while (keys.hasNext()) { 12 | Object key = keys.next(); 13 | action.doAction(key, action.getMap().get(key)); 14 | } 15 | return action.getResult(); 16 | } 17 | 18 | public static Object traverse(ListTraverser action) { 19 | Iterator keys = action.getList().iterator(); 20 | while (keys.hasNext()) { 21 | Object key = keys.next(); 22 | action.doAction(key); 23 | } 24 | return action.getResult(); 25 | } 26 | 27 | public static String toString(Map map) { 28 | return (String) MapUtil.traverse(new MapTraverser(map) { 29 | private StringBuffer sb = new StringBuffer(); 30 | 31 | @Override 32 | public void doAction(Object key, Object value) { 33 | sb.append("\t[").append(/*value.getClass().getName()+"@"+value.hashCode()+"@"+*/key).append("="); 34 | if (value instanceof Map) { 35 | sb.append(MapUtil.toString((Map) value)); 36 | } else if (value instanceof List) { 37 | sb.append(MapUtil.toString((List) value)); 38 | } else { 39 | sb.append(value); 40 | } 41 | sb.append("],\n"); 42 | } 43 | 44 | @Override 45 | public Object getResult() { 46 | return /*super.getMap().getClass().getName()+"@"+super.getMap().hashCode()+*/"{\n" + sb.toString() + "}"; 47 | } 48 | }); 49 | } 50 | 51 | public static String toString(List list) { 52 | return (String) MapUtil.traverse(new ListTraverser(list) { 53 | private StringBuffer sb = new StringBuffer(); 54 | 55 | @Override 56 | public void doAction(Object key) { 57 | if (key instanceof Map) { 58 | sb.append(MapUtil.toString((Map) key)); 59 | } else if (key instanceof List) { 60 | sb.append(MapUtil.toString((List) key)); 61 | } else { 62 | sb.append(key); 63 | } 64 | sb.append(","); 65 | } 66 | 67 | @Override 68 | public Object getResult() { 69 | return /*super.getList().getClass().getName()+"@"+super.getList().hashCode()+*/"{" + sb.toString() + "}"; 70 | } 71 | }); 72 | } 73 | 74 | public static boolean compare(Map map1, Map map2) { 75 | boolean result = true; 76 | if (map1 == map2) { 77 | return true; 78 | } 79 | if (map1.equals(map2)) { 80 | return true; 81 | } 82 | if (map1.size() != map2.size()) { 83 | return false; 84 | } 85 | //TODO compare(Map map1, Map map2) 86 | result = false; 87 | return result; 88 | } 89 | 90 | public static String muilString(String str, int i) { 91 | String tmp = ""; 92 | int j = i; 93 | while (j-- > 0) { 94 | tmp += str; 95 | } 96 | return tmp; 97 | } 98 | 99 | public static void append(Map map1, Map map2) { 100 | MapUtil.traverse(new MapTraverser(map2, map1) { 101 | @Override 102 | public void doAction(Object key, Object value) { 103 | Map target = (Map) input; 104 | target.put(key, value); 105 | } 106 | }); 107 | } 108 | 109 | public static Object getValue(Map map, Object key, Object defaultValue) { 110 | Object value = null; 111 | if (map != null) { 112 | value = map.get(key); 113 | if (value == null) { 114 | value = defaultValue; 115 | } 116 | } 117 | return value; 118 | } 119 | 120 | /** 121 | * note: 122 | * this method invoked Object.equals(),so need insure that 123 | * otherExclusion implement equals() method according to your want 124 | * 125 | * @param map 126 | * @param key 127 | * @param defaultValue 128 | * @param otherExclusion 129 | * @return 130 | */ 131 | public static Object getValue(Map map, Object key, Object defaultValue, Object otherExclusion) { 132 | Object value = null; 133 | if (map != null) { 134 | value = map.get(key); 135 | if (value == null || value.equals(otherExclusion)) { 136 | value = defaultValue; 137 | } 138 | } 139 | return value; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/xml/XmlUtil.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util.xml; 2 | 3 | import jodd.typeconverter.Convert; 4 | import jodd.util.StringUtil; 5 | import com.dataagg.util.collection.StrMap; 6 | import com.dataagg.util.lang.ArgCheck; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.w3c.dom.Document; 10 | import org.w3c.dom.Element; 11 | import org.w3c.dom.NamedNodeMap; 12 | import org.w3c.dom.Node; 13 | import org.w3c.dom.NodeList; 14 | 15 | import javax.xml.parsers.DocumentBuilder; 16 | import javax.xml.parsers.DocumentBuilderFactory; 17 | import java.io.InputStream; 18 | 19 | import static com.dataagg.util.lang.TextUtils.prefix; 20 | 21 | public class XmlUtil { 22 | private static final Logger LOG = LoggerFactory.getLogger(XmlUtil.class); 23 | public static final String NamespacePrefix = "xmlns:"; 24 | 25 | public static boolean isBlank(Node node) { 26 | return node != null && ((node.getNodeType() == Node.TEXT_NODE && StringUtil.isBlank(node.getNodeValue())) || (node.getNodeType() == Node.COMMENT_NODE)); 27 | } 28 | 29 | public static boolean hasChildren(Node node) { 30 | return node != null && node.getChildNodes() != null && node.getChildNodes().getLength() > 0; 31 | } 32 | 33 | public static String getAttribute(Node node, String attrName) { 34 | try { 35 | if (node != null && node.getAttributes() != null && node.getAttributes().getNamedItem(attrName) != null) { 36 | return node.getAttributes().getNamedItem(attrName).getNodeValue(); 37 | } 38 | } catch (Throwable e) { 39 | } 40 | return null; 41 | } 42 | 43 | public static Node getNotBlankChildNode(Node node, int index) { 44 | if (node != null) { 45 | NodeList nodes = node.getChildNodes(); 46 | int nindex = 0; 47 | for (int i = 0; i < nodes.getLength(); i++) { 48 | Node n = nodes.item(i); 49 | if (!XmlUtil.isBlank(n)) { 50 | if (nindex == index) { 51 | return n; 52 | } 53 | nindex++; 54 | } 55 | } 56 | } 57 | return null; 58 | } 59 | 60 | public static int getNotBlankChildNodeSize(Node node) { 61 | if (node != null) { 62 | NodeList nodes = node.getChildNodes(); 63 | int nindex = 0; 64 | for (int i = 0; i < nodes.getLength(); i++) { 65 | Node n = nodes.item(i); 66 | if (!XmlUtil.isBlank(n)) { 67 | nindex++; 68 | } 69 | } 70 | return nindex; 71 | } 72 | return 0; 73 | } 74 | 75 | public static StrMap getAttributes(Node node) { 76 | StrMap attrs = new StrMap(); 77 | ArgCheck.checkNotNull(node); 78 | NamedNodeMap attrNodeMap = node.getAttributes(); 79 | if (attrNodeMap != null) { 80 | for (int i = 0; i < attrNodeMap.getLength(); i++) { 81 | Node attNode = attrNodeMap.item(i); 82 | if (attNode.getNodeType() == Node.ATTRIBUTE_NODE) { 83 | attrs.put(attNode.getNodeName(), attNode.getNodeValue()); 84 | } else { 85 | LOG.warn("error node type:" + attNode.getNodeType()); 86 | } 87 | } 88 | } 89 | return attrs; 90 | } 91 | 92 | private static Document parseDocument(InputStream is) { 93 | try { 94 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 95 | factory.setValidating(false); 96 | DocumentBuilder builder = factory.newDocumentBuilder(); 97 | return builder.parse(is); 98 | } catch (Throwable e) { 99 | LOG.error(e.getMessage(), e); 100 | } 101 | return null; 102 | } 103 | 104 | public static Element parseRootElement(InputStream is) { 105 | try { 106 | Document doc = parseDocument(is); 107 | return doc.getDocumentElement(); 108 | } catch (Throwable e) { 109 | LOG.error(e.getMessage(), e); 110 | } 111 | return null; 112 | } 113 | 114 | public static StrMap parseNameSpaces(Node doc) { 115 | StrMap ns = new StrMap(); 116 | String rootNodeName = doc.getNodeName(); 117 | //parse namespaces 118 | StrMap attrs = XmlUtil.getAttributes(doc); 119 | for (String attrName : attrs.keySet()) { 120 | if (attrName.trim().startsWith(NamespacePrefix)) { 121 | String value = Convert.toString(attrs.get(attrName)); 122 | String name = attrName.substring(NamespacePrefix.length()); 123 | ns.put(prefix(rootNodeName) + name, value); 124 | } 125 | } 126 | return ns; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/commons/domain/EAccount.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.domain; 2 | 3 | import java.util.List; 4 | 5 | import org.nutz.dao.entity.annotation.ColDefine; 6 | import org.nutz.dao.entity.annotation.ColType; 7 | import org.nutz.dao.entity.annotation.Column; 8 | import org.nutz.dao.entity.annotation.Comment; 9 | import org.nutz.dao.entity.annotation.Default; 10 | import org.nutz.dao.entity.annotation.Id; 11 | import org.nutz.dao.entity.annotation.One; 12 | import org.nutz.dao.entity.annotation.Table; 13 | 14 | @Table("da_account") 15 | @Comment("账户信息") 16 | public class EAccount { 17 | @Id 18 | @Comment("主键") 19 | private Long id; 20 | 21 | @Comment("删除标记(0:正常,1:删除)") 22 | @Column("del_flag") 23 | @ColDefine(type = ColType.CHAR, width = 1, notNull = true) 24 | @Default("0") 25 | private String delFlag; 26 | 27 | 28 | @Column("org_id") 29 | @Comment("所属机构Id") 30 | @ColDefine(type = ColType.INT,width=20,notNull=true) 31 | private Long orgId; 32 | 33 | @Comment("所属机构的名称") 34 | private String orgName; 35 | 36 | @Column("user_id") 37 | @ColDefine(notNull=true) 38 | @Comment("关联用户") 39 | private Long userId; 40 | 41 | @One(field="userId") 42 | private EUser user; 43 | 44 | @Column(hump=true) 45 | @ColDefine(type = ColType.VARCHAR,width=128) 46 | @Comment("用户全名") 47 | private String fullName; 48 | 49 | @Column(hump=true) 50 | @ColDefine(type = ColType.VARCHAR,width=128) 51 | @Comment("手机") 52 | private String mobile; 53 | 54 | @Column(hump=true) 55 | @ColDefine(type = ColType.VARCHAR,width=128) 56 | @Comment("email") 57 | private String email; 58 | 59 | @Column(hump=true) 60 | @ColDefine(type = ColType.VARCHAR,width=128) 61 | @Comment("地址") 62 | private String address; 63 | 64 | @Column(hump=true) 65 | @ColDefine(type = ColType.VARCHAR,width=128) 66 | @Comment("身份证号") 67 | private String number; 68 | 69 | @Column(hump=true) 70 | @ColDefine(type = ColType.VARCHAR,width=512) 71 | @Comment("备注") 72 | private String comment; 73 | 74 | //角色列表 75 | private List roleList; 76 | 77 | public Long getId() { 78 | return id; 79 | } 80 | 81 | public void setId(Long id) { 82 | this.id = id; 83 | } 84 | 85 | public Long getUserId() { 86 | return userId; 87 | } 88 | 89 | public void setUserId(Long userId) { 90 | this.userId = userId; 91 | } 92 | 93 | public EUser getUser() { 94 | return user; 95 | } 96 | 97 | public void setUser(EUser user) { 98 | this.user = user; 99 | } 100 | 101 | public String getFullName() { 102 | return fullName; 103 | } 104 | 105 | public void setFullName(String fullName) { 106 | this.fullName = fullName; 107 | } 108 | 109 | public String getNumber() { 110 | return number; 111 | } 112 | 113 | public void setNumber(String number) { 114 | this.number = number; 115 | } 116 | 117 | public String getMobile() { 118 | return mobile; 119 | } 120 | 121 | public void setMobile(String mobile) { 122 | this.mobile = mobile; 123 | } 124 | 125 | public String getEmail() { 126 | return email; 127 | } 128 | 129 | public void setEmail(String email) { 130 | this.email = email; 131 | } 132 | 133 | public String getAddress() { 134 | return address; 135 | } 136 | 137 | public void setAddress(String address) { 138 | this.address = address; 139 | } 140 | 141 | public String getComment() { 142 | return comment; 143 | } 144 | 145 | public void setComment(String comment) { 146 | this.comment = comment; 147 | } 148 | 149 | public Long getOrgId() { 150 | return orgId; 151 | } 152 | 153 | public void setOrgId(Long orgId) { 154 | this.orgId = orgId; 155 | } 156 | 157 | public String getDelFlag() { 158 | return delFlag; 159 | } 160 | 161 | public void setDelFlag(String delFlag) { 162 | this.delFlag = delFlag; 163 | } 164 | 165 | public List getRoleList() { 166 | return roleList; 167 | } 168 | 169 | public void setRoleList(List roleList) { 170 | this.roleList = roleList; 171 | } 172 | 173 | /** 174 | * @return the orgName 175 | */ 176 | public String getOrgName() { 177 | return orgName; 178 | } 179 | 180 | /** 181 | * @param orgName the orgName to set 182 | */ 183 | public void setOrgName(String orgName) { 184 | this.orgName = orgName; 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /codegen/components.yml: -------------------------------------------------------------------------------- 1 | springBoot: 2 | plugins: [java, eclipse, idea, "'org.springframework.boot:${bootVersion}'"] 3 | archiveName: app.jar 4 | deps: 5 | - testCompile 'org.springframework.boot:spring-boot-starter-test' 6 | dependencyManagement: 7 | - "imports { mavenBom 'org.springframework.cloud:spring-cloud-dependencies:${cloudVersion}' }" 8 | config: 9 | spring: 10 | application: 11 | name: ${_SubProject_} 12 | server: 13 | # context-path: /${_SubProject_} 14 | port: ${_SubProjectPort_} 15 | logging: 16 | level: 17 | root: WARN 18 | testConfig: 19 | spring: 20 | application: 21 | name: ${_SubProject_} 22 | server: 23 | # context-path: /${_SubProject_} 24 | port: ${_SubProjectPort_} 25 | logging: 26 | level: 27 | root: WARN 28 | docker: 29 | image: java:8-jre 30 | volumes: 31 | - "../${_SubProject_}/build/libs/:/app/" 32 | ports: ['${_SubProjectPort_}:${_SubProjectPort_}'] 33 | expose: [${_SubProjectPort_}] 34 | command: ['java', '-Djava.security.egd=file:/dev/./urandom', '-Xmx200m', '-jar', '/app/app.jar'] 35 | starterWeb: 36 | plugins: [java, eclipse, idea, "'org.springframework.boot:${bootVersion}'"] 37 | archiveName: app.jar 38 | deps: 39 | - compile 'org.springframework.boot:spring-boot-starter-web' 40 | starterJdbc: 41 | deps: 42 | - compile 'mysql:mysql-connector-java:${mysqlVersion}' 43 | # - compile 'com.alibaba:druid:1.0.26' 44 | - compile 'org.springframework.boot:spring-boot-starter-jdbc' 45 | config: 46 | spring: 47 | datasource: 48 | driver-class-name: com.mysql.cj.jdbc.Driver 49 | url: ${jdbcUrl} 50 | username: ${jdbcUser} 51 | password: ${jdbcPswd} 52 | testConfig: 53 | spring: 54 | datasource: 55 | driver-class-name: com.mysql.cj.jdbc.Driver 56 | url: ${jdbcUrl} 57 | username: ${jdbcUser} 58 | password: ${jdbcPswd} 59 | eurekaServer: 60 | deps: 61 | - compile 'org.springframework.cloud:spring-cloud-starter-eureka-server' 62 | dependencyManagement: 63 | - imports { mavenBom 'org.springframework.cloud:spring-cloud-dependencies:${cloudVersion}' } 64 | config: 65 | eureka: 66 | instance: 67 | prefer-ip-address: true 68 | client: 69 | registerWithEureka: false 70 | fetchRegistry: false 71 | serviceUrl: 72 | defaultZone: http://service-center:8761/eureka/ 73 | eurekaClient: 74 | deps: 75 | - compile 'org.springframework.cloud:spring-cloud-starter-eureka' 76 | config: 77 | eureka: 78 | client: 79 | serviceUrl: 80 | defaultZone: http://service-center:8761/eureka/ 81 | testConfig: 82 | eureka: 83 | client: 84 | enabled: false 85 | zuul: 86 | deps: 87 | - compile 'org.springframework.cloud:spring-cloud-starter-zuul' 88 | config: 89 | ribbon: 90 | ReadTimeout: 20000 91 | ConnectTimeout: 20000 92 | eureka: 93 | enabled: false 94 | zuul: 95 | # ignoredServices: '*' 96 | host: 97 | connect-timeout-millis: 20000 98 | socket-timeout-millis: 20000 99 | securityServer: 100 | deps: 101 | - compile 'org.springframework.boot:spring-boot-starter-security' 102 | - compile 'org.springframework.security.oauth:spring-security-oauth2' 103 | securityClient: 104 | deps: 105 | - compile 'org.springframework.boot:spring-boot-starter-security' 106 | - compile 'org.springframework.security.oauth:spring-security-oauth2' 107 | - compile 'org.springframework.cloud:spring-cloud-security:${cloudSecurityVersion}' 108 | config: 109 | security: 110 | oauth2: 111 | resource: 112 | user-info-uri: http://api-gateway:5000/security/users/current 113 | client: 114 | clientId: ${_SubProject_} 115 | clientSecret: ${clientSecret} 116 | accessTokenUri: http://api-gateway:5000/security/oauth/token 117 | grant-type: client_credentials 118 | scope: server 119 | feign: 120 | deps: 121 | - compile 'org.springframework.cloud:spring-cloud-starter-feign' 122 | ribbon: 123 | deps: 124 | - compile 'org.springframework.cloud:spring-cloud-starter-ribbon' 125 | hystrix: 126 | deps: 127 | - compile 'org.springframework.cloud:spring-cloud-starter-hystrix' 128 | - compile 'org.springframework.boot:spring-boot-starter-actuator' 129 | - compile 'org.springframework.cloud:spring-cloud-starter-hystrix-dashboard' 130 | -------------------------------------------------------------------------------- /api-gateway/src/test/java/com/dataagg/security/service/SysUserDetailsServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.security.service; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.fail; 5 | 6 | import java.util.List; 7 | import java.util.Set; 8 | 9 | import org.junit.After; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.test.context.SpringBootTest; 15 | import org.springframework.security.core.userdetails.UserDetails; 16 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 17 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 18 | import org.springframework.util.Assert; 19 | 20 | import com.dataagg.APIGatewayApplication; 21 | import com.dataagg.commons.dao.AuthorityDao; 22 | import com.dataagg.commons.dao.UserDao; 23 | import com.dataagg.commons.domain.EAccount; 24 | import com.dataagg.commons.domain.EAuthority; 25 | import com.dataagg.commons.domain.EUser; 26 | import com.dataagg.commons.service.SysUserDetailsService; 27 | import com.dataagg.security.UserPrincipal; 28 | 29 | import static org.springframework.util.Assert.isNull; 30 | import static org.springframework.util.Assert.isTrue; 31 | import static org.springframework.util.Assert.notNull; 32 | 33 | import jodd.util.StringUtil; 34 | 35 | @RunWith(SpringJUnit4ClassRunner.class) 36 | @SpringBootTest(classes = APIGatewayApplication.class) 37 | public class SysUserDetailsServiceTest { 38 | @Autowired 39 | private UserDao userDao; 40 | @Autowired 41 | private AuthorityDao authorityDao; 42 | @Autowired 43 | private SysUserDetailsService userDetailsService; 44 | 45 | @Before 46 | public void setUp() throws Exception {} 47 | 48 | @After 49 | public void tearDown() throws Exception {} 50 | 51 | @Test 52 | public void shouldCreateUser() { 53 | Assert.isTrue(userDao.exists(1L), ""); 54 | EUser user = new EUser(); 55 | user.setUsername("name" + System.currentTimeMillis()); 56 | user.setPassword("password"); 57 | user.setOrgId(1L); 58 | EAccount account = new EAccount(); 59 | account.setFullName("test"); 60 | account.setOrgId(1L); 61 | user.setAccount(account); 62 | userDetailsService.create(user); 63 | Assert.notNull(user, ""); 64 | Assert.notNull(user.getId(), ""); 65 | 66 | String username = user.getUsername(); 67 | 68 | user = userDao.fetch(user.getId()); 69 | Assert.notNull(user, ""); 70 | Assert.notNull(user.getId(), ""); 71 | Assert.isTrue(username.equals(user.getUsername()), ""); 72 | } 73 | 74 | @Test 75 | public void testLoadUserByUsername() { 76 | //test found user 77 | String username = "watano"; 78 | UserDetails ud = userDetailsService.loadUserByUsername(username); 79 | notNull(ud, "UserDetails is not null"); 80 | notNull(ud.getUsername(), "Username is not null"); 81 | isTrue(username.equals(ud.getUsername()), "Username is not " + username); 82 | notNull(ud.getPassword(), "Password is not null"); 83 | 84 | //UsernameNotFoundException 85 | try { 86 | username = "watano1"; 87 | ud = userDetailsService.loadUserByUsername(username); 88 | fail("UserDetails is not null"); 89 | } catch (UsernameNotFoundException e) {} 90 | } 91 | 92 | @Test 93 | public void testFetchByName() { 94 | String username = "watano"; 95 | EUser ud = userDetailsService.fetchByName(username); 96 | notNull(ud, "UserDetails is not null"); 97 | notNull(ud.getUsername(), "Username is not null"); 98 | isTrue(username.equals(ud.getUsername()), "Username is not " + username); 99 | notNull(ud.getPassword(), "Password is not null"); 100 | username = "watano1"; 101 | ud = userDetailsService.fetchByName(username); 102 | isNull(ud, "UserDetails is null"); 103 | } 104 | 105 | @Test 106 | public void testUpdateAuthorities() {} 107 | 108 | @Test 109 | public void testFetchFullByName() {} 110 | 111 | @Test 112 | public void testFetchUserAuthoritiesPrincipal() { 113 | //principal==null时获取到guest权限信息 114 | Set authorities = userDetailsService.principalAuthorities(null); 115 | notNull(authorities, ""); 116 | isTrue(authorities.size() == 1, ""); 117 | isTrue("guest".equals(StringUtil.join(authorities, ",")), ""); 118 | //admin user时获取全部权限 119 | UserPrincipal up = new UserPrincipal("watano"); 120 | authorities = userDetailsService.principalAuthorities(up); 121 | notNull(authorities, ""); 122 | isTrue(authorities.size() > 0, ""); 123 | isTrue(authorities.contains("pro_list"), ""); 124 | List allAuthorities = authorityDao.query(); 125 | assertEquals(authorities.size(), allAuthorities.size()); 126 | } 127 | 128 | @Test 129 | public void testFetchUserAuthoritiesString() {} 130 | 131 | } 132 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/commons/controller/DictController.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.nutz.dao.Cnd; 6 | import org.nutz.dao.pager.Pager; 7 | import org.nutz.dao.sql.Criteria; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestBody; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import com.dataagg.commons.domain.EDict; 17 | import com.dataagg.commons.vo.ActionResultObj; 18 | import com.dataagg.util.Constans; 19 | import com.dataagg.util.SearchQueryJS; 20 | import com.dataagg.util.WMap; 21 | import com.dataagg.commons.dao.DictDao; 22 | import com.dataagg.commons.service.DictService; 23 | 24 | import jodd.util.StringUtil; 25 | 26 | 27 | /** 28 | * Created by carlos on 2017/3/29. 29 | * 数据字典管理 controller 30 | */ 31 | @RestController 32 | @RequestMapping("/dict") 33 | public class DictController { 34 | private Logger LOG = LoggerFactory.getLogger(DictController.class); 35 | @Autowired 36 | public DictService dictService; 37 | @Autowired 38 | public DictDao dictDao; 39 | 40 | @RequestMapping(value="list") 41 | public ActionResultObj list(@RequestBody SearchQueryJS queryJs){ 42 | ActionResultObj result = new ActionResultObj(); 43 | try{ 44 | Pager pager = queryJs.toPager(); 45 | WMap query = queryJs.getQuery(); 46 | 47 | //处理查询条件 48 | Criteria cnd = Cnd.cri(); 49 | if(query.get("type") != null && StringUtil.isNotBlank(query.get("type").toString())){ 50 | cnd.where().andEquals("type", query.get("type").toString()); 51 | } 52 | cnd.getGroupBy().groupBy("type"); 53 | cnd.getOrderBy().desc("sort"); 54 | //分页查询 55 | List projectList = dictDao.query(cnd, pager); 56 | 57 | //处理返回值 58 | WMap map = new WMap(); 59 | if(queryJs.getQuery() != null){ 60 | map.putAll(queryJs.getQuery()); 61 | } 62 | map.put("data", projectList); 63 | map.put("page", queryJs.toWPage(pager)); 64 | result.ok(map); 65 | result.okMsg("查询成功!"); 66 | }catch(Exception e){ 67 | e.printStackTrace(); 68 | LOG.error("查询失败,原因:"+e.getMessage()); 69 | result.error(e); 70 | } 71 | return result; 72 | } 73 | @RequestMapping(value="type/{type}") 74 | public ActionResultObj findByType(@PathVariable String type){ 75 | ActionResultObj result = new ActionResultObj(); 76 | try{ 77 | if(StringUtil.isNotBlank(type)){ 78 | List dictList = dictDao.query(Cnd.where("type", "=", type).and("del_flag", "=", Constans.POS_NEG.NEG).orderBy("sort", "asc")); 79 | //处理返回值 80 | WMap map = new WMap(); 81 | map.put("type", type); 82 | map.put("data", dictList); 83 | result.ok(map); 84 | result.okMsg("查询成功!"); 85 | }else{ 86 | result.errorMsg("查询失败,字典类型不存在!"); 87 | } 88 | }catch(Exception e){ 89 | e.printStackTrace(); 90 | LOG.error("查询失败,原因:"+e.getMessage()); 91 | result.error(e); 92 | } 93 | return result; 94 | } 95 | @RequestMapping(value="/{id}") 96 | public ActionResultObj get(@PathVariable Long id){ 97 | ActionResultObj result = new ActionResultObj(); 98 | try{ 99 | if(id != 0){ 100 | EDict dict = dictDao.fetch(id); 101 | if(dict != null){ 102 | result.ok(dict); 103 | result.okMsg("查询成功!"); 104 | }else{ 105 | result.errorMsg("查询失败!"); 106 | } 107 | }else{ 108 | result.errorMsg("查询失败,链接不存在!"); 109 | } 110 | }catch(Exception e){ 111 | LOG.error("查询失败,原因:"+e.getMessage()); 112 | result.error(e); 113 | } 114 | return result; 115 | } 116 | @RequestMapping(value="save") 117 | public ActionResultObj save(@RequestBody EDict dict){ 118 | ActionResultObj result = new ActionResultObj(); 119 | try{ 120 | if(dictService.save(dict) != null){ 121 | result.okMsg("保存成功!"); 122 | }else{ 123 | result.errorMsg("保存失败!"); 124 | } 125 | }catch(Exception e){ 126 | LOG.error("保存失败,原因:"+e.getMessage()); 127 | result.error(e); 128 | } 129 | return result; 130 | } 131 | 132 | @RequestMapping(value="delete") 133 | public ActionResultObj delete(@RequestBody Long id){ 134 | ActionResultObj result = new ActionResultObj(); 135 | try{ 136 | if(id != 0){ 137 | if(dictService.delete(id)){ 138 | result.okMsg("删除成功!"); 139 | }else{ 140 | result.errorMsg("删除失败!"); 141 | } 142 | }else{ 143 | result.errorMsg("删除失败,链接不存在!"); 144 | } 145 | }catch(Exception e){ 146 | LOG.error("删除失败,原因:"+e.getMessage()); 147 | result.error(e); 148 | } 149 | return result; 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /core-service/src/test/java/com/dataagg/commons/dao/MenuDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.dao; 2 | 3 | import java.io.IOException; 4 | import java.util.List; 5 | 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.boot.test.context.SpringBootTest; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | import org.springframework.util.Assert; 15 | 16 | import com.dataagg.CoreServiceApplication; 17 | import com.dataagg.commons.domain.EMenu; 18 | import com.dataagg.commons.vo.ActionResultList; 19 | import com.dataagg.util.ITreeNode; 20 | import com.dataagg.util.WJsonUtils; 21 | 22 | import jodd.io.FileUtil; 23 | 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | @SpringBootTest(classes = CoreServiceApplication.class) 26 | public class MenuDaoTest { 27 | private static final Logger LOG = LoggerFactory.getLogger(MenuDaoTest.class); 28 | 29 | // @Autowired 30 | // private MenuDao menuDao; 31 | // @Autowired 32 | // private SysUserDetailsService userDetailsService; 33 | 34 | @Before 35 | public void setUp() throws Exception {} 36 | 37 | @After 38 | public void tearDown() throws Exception {} 39 | 40 | private void printMenuInsertSql(String id, String parentId, String name, String code, int menuType, String icon) { 41 | //System.out.println("#" + id + "--" + parentId + "--" + name + "--" + code + "--" + menuType + "--" + icon); 42 | System.out.println((code != null ? code : "") + name + "', '" + (code != null ? code : "") + "', " + menuType + ", '" + icon + "');"); 43 | } 44 | 45 | // @Test 46 | // public void testAll() { 47 | // // EMenu root = menuDao.allMenus(new HashSet()); 48 | // // assertNotNull(root); 49 | // // assertNotNull(root.getItems()); 50 | // // for (EMenu menu1 : root.getItems()) { 51 | // // System.out.println(menu1); 52 | // // if (menu1.getItems() != null) { 53 | // // for (EMenu menu2 : menu1.getItems()) { 54 | // // System.out.println(menu2); 55 | // // if (menu2.getItems() != null) { 56 | // // for (EMenu menu3 : menu2.getItems()) { 57 | // // System.out.println(menu3); 58 | // // } 59 | // // } 60 | // // } 61 | // // } 62 | // // } 63 | // //check menus 64 | // UserPrincipal up = new UserPrincipal("watano"); 65 | // Set authorities = userDetailsService.principalAuthorities(up); 66 | // List> allNodes = menuDao.getAllMenus(authorities); 67 | // assertEquals(32, allNodes.size()); 68 | // assertTrue(assertMenu(allNodes, 7010L)); 69 | // 70 | // up = new UserPrincipal("shilin001"); 71 | // authorities = userDetailsService.principalAuthorities(up); 72 | // allNodes = menuDao.getAllMenus(authorities); 73 | // assertEquals(7, allNodes.size()); 74 | // assertTrue(assertMenu(allNodes, 70L)); 75 | // assertTrue(assertMenu(allNodes, 7020L)); 76 | // assertFalse(assertMenu(allNodes, 7030L)); 77 | // 78 | // } 79 | 80 | public boolean assertMenu(List> allNodes, long menuId) { 81 | for (ITreeNode node : allNodes) { 82 | if (node.getId().longValue() == menuId) { return true; } 83 | } 84 | return false; 85 | } 86 | 87 | @Test 88 | public void insertAll() { 89 | try { 90 | String json = FileUtil.readString("../../WdtcWeb/static/data/allMenus.json", "utf-8"); 91 | ActionResultList allMenus = WJsonUtils.toObject(json, ActionResultList.class, EMenu.class); 92 | Assert.notNull(allMenus, ""); 93 | Assert.notNull(allMenus.getData(), ""); 94 | int index = 10; 95 | for (EMenu menu : allMenus.getData()) { 96 | if (menu.getItems() != null && menu.getItems().size() > 0) { 97 | printMenuInsertSql(index + "", "0", menu.getName(), menu.getCode(), 10, "message"); 98 | int subIndex1 = 10; 99 | for (EMenu subMenu1 : menu.getItems()) { 100 | if (subMenu1.getItems() != null && subMenu1.getItems().size() > 0) { 101 | printMenuInsertSql(index + "" + subIndex1, index + "", subMenu1.getName(), subMenu1.getCode(), 20, "message"); 102 | int subIndex2 = 10; 103 | for (EMenu subMenu2 : subMenu1.getItems()) { 104 | printMenuInsertSql(index + "" + subIndex1 + "" + subIndex2, index + "" + subIndex1, subMenu2.getName(), subMenu2.getCode(), 1, "message"); 105 | subIndex2 += 10; 106 | } 107 | } else { 108 | printMenuInsertSql(index + "" + subIndex1, index + "", subMenu1.getName(), subMenu1.getCode(), 20, "message"); 109 | } 110 | subIndex1 += 10; 111 | } 112 | } else { 113 | printMenuInsertSql(index + "", "0", menu.getName(), menu.getCode(), 1, "message"); 114 | } 115 | index += 10; 116 | } 117 | } catch (IOException e) { 118 | LOG.error(e.getMessage(), e); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /core-service/src/main/java/com/dataagg/commons/controller/MenuController.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.commons.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.nutz.dao.Cnd; 6 | import org.nutz.dao.sql.Criteria; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import com.dataagg.commons.dao.MenuDao; 17 | import com.dataagg.commons.domain.EMenu; 18 | import com.dataagg.commons.service.MenuService; 19 | import com.dataagg.commons.vo.ActionResultObj; 20 | import com.dataagg.util.Constans; 21 | import com.dataagg.util.SearchQueryJS; 22 | import com.dataagg.util.WMap; 23 | 24 | import jodd.util.StringUtil; 25 | 26 | /** 27 | * Created by carlos on 2017/3/29. 28 | * 区域管理 controller 29 | */ 30 | @RestController 31 | @RequestMapping("/menu") 32 | public class MenuController { 33 | private Logger LOG = LoggerFactory.getLogger(MenuController.class); 34 | @Autowired 35 | public MenuService menuService; 36 | @Autowired 37 | public MenuDao menuDao; 38 | 39 | @RequestMapping(value = "/list") 40 | public ActionResultObj list(@RequestBody SearchQueryJS queryJs) { 41 | ActionResultObj result = new ActionResultObj(); 42 | try { 43 | 44 | //处理查询条件 45 | Criteria cnd = Cnd.cri(); 46 | cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG); 47 | cnd.getOrderBy().asc("sort"); 48 | 49 | List allMenus = menuDao.query(cnd); 50 | EMenu menu = menuDao.buildMenuTree(allMenus); 51 | 52 | //处理返回值 53 | WMap map = new WMap(); 54 | map.put("data", menu.getItems()); 55 | result.ok(map); 56 | result.okMsg("查询成功!"); 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | LOG.error("查询失败,原因:" + e.getMessage()); 60 | result.error(e); 61 | } 62 | return result; 63 | } 64 | 65 | @RequestMapping(value = "/allMenu", method = RequestMethod.POST) 66 | public ActionResultObj findAllmenu(@RequestBody SearchQueryJS queryJs) { 67 | ActionResultObj result = new ActionResultObj(); 68 | try { 69 | WMap query = queryJs.getQuery(); 70 | //处理查询条件 71 | Criteria cnd = Cnd.cri(); 72 | cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG); 73 | if (query.get("extId") != null && StringUtil.isNotBlank(query.get("extId").toString())) { 74 | cnd.where().andNotIn("id", query.get("extId").toString()); 75 | cnd.where().andNotLike("parent_ids", "%," + query.get("extId").toString() + ",%"); 76 | } 77 | cnd.getOrderBy().asc("sort"); 78 | List allMenus = menuDao.query(cnd); 79 | EMenu menu = menuDao.buildMenuTree(allMenus); 80 | WMap map = new WMap(); 81 | map.put("data", menu.getItems()); 82 | result.setData(map); 83 | result.okMsg("查询成功!"); 84 | } catch (Exception e) { 85 | e.printStackTrace(); 86 | LOG.error("查询失败,原因:" + e.getMessage()); 87 | result.error(e); 88 | } 89 | return result; 90 | } 91 | 92 | @RequestMapping(value = "/save") 93 | public ActionResultObj save(@RequestBody EMenu menu) { 94 | ActionResultObj result = new ActionResultObj(); 95 | try { 96 | if (menuService.save(menu) != null) { 97 | result.okMsg("保存成功!"); 98 | } else { 99 | result.errorMsg("保存失败!"); 100 | } 101 | } catch (Exception e) { 102 | LOG.error("保存失败,原因:" + e.getMessage()); 103 | result.error(e); 104 | } 105 | return result; 106 | } 107 | 108 | @RequestMapping(value = "/get/{id}") 109 | public ActionResultObj get(@PathVariable Long id) { 110 | ActionResultObj result = new ActionResultObj(); 111 | try { 112 | if (id > 0) { 113 | EMenu menu = menuDao.fetch(id); 114 | if (menu != null) { 115 | WMap map = new WMap(); 116 | map.put("data", menu); 117 | result.ok(map); 118 | result.okMsg("查询成功!"); 119 | } else { 120 | result.errorMsg("查询失败!"); 121 | } 122 | } else { 123 | result.errorMsg("查询失败,链接不存在!"); 124 | } 125 | } catch (Exception e) { 126 | LOG.error("查询失败,原因:" + e.getMessage()); 127 | result.error(e); 128 | } 129 | return result; 130 | } 131 | 132 | @RequestMapping(value = "/delete/{id}") 133 | public ActionResultObj delete(@PathVariable Long id) { 134 | ActionResultObj result = new ActionResultObj(); 135 | try { 136 | if (id != 0) { 137 | if (menuService.delete(id)) { 138 | result.okMsg("删除成功!"); 139 | } else { 140 | result.errorMsg("删除失败!"); 141 | } 142 | } else { 143 | result.errorMsg("删除失败,链接不存在!"); 144 | } 145 | } catch (Exception e) { 146 | LOG.error("删除失败,原因:" + e.getMessage()); 147 | result.error(e); 148 | } 149 | return result; 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /commons/src/main/java/com/dataagg/util/CryptoUtil.java: -------------------------------------------------------------------------------- 1 | package com.dataagg.util; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import javax.crypto.Cipher; 7 | import javax.crypto.SecretKey; 8 | import javax.crypto.spec.SecretKeySpec; 9 | import java.security.MessageDigest; 10 | import java.security.NoSuchAlgorithmException; 11 | 12 | public class CryptoUtil { 13 | private static final String Algorithm = "DESede";// DES,DESede,Blowfish 14 | private static final String Algorithm2 = "SHA1";// SHA1,SHA-256,MD5 15 | private static final Logger LOG = LoggerFactory.getLogger(CryptoUtil.class); 16 | 17 | static { 18 | //Security.addProvider(new SunJCE()); 19 | } 20 | 21 | private static byte[] getKey() throws Exception { 22 | // KeyGenerator keygen = KeyGenerator.getInstance(Algorithm); 23 | // SecretKey deskey = keygen.generateKey(); 24 | // deskey.getEncoded(); 25 | byte[] key = hex2byte("4F9D3497E379AE6E54E004DF15A8DFC27CCD97AE756B9B9D"); 26 | LOG.debug("generate Key:" + byte2hex(key)); 27 | return key; 28 | } 29 | 30 | public static String encode(String input) { 31 | try { 32 | LOG.debug("intput string:" + input); 33 | SecretKey deskey = new SecretKeySpec(getKey(), Algorithm); 34 | Cipher c1 = Cipher.getInstance(Algorithm); 35 | c1.init(Cipher.ENCRYPT_MODE, deskey); 36 | byte[] cipherByte = c1.doFinal(input.getBytes("utf-8")); 37 | LOG.debug("ouput string:" + byte2hex(cipherByte)); 38 | return byte2hex(cipherByte); 39 | } catch (Exception e) { 40 | LOG.error("CryptoUtil.encode error!", e); 41 | return null; 42 | } 43 | } 44 | 45 | public static String decode(String input) { 46 | try { 47 | LOG.debug("intput string:" + input); 48 | SecretKey deskey; 49 | deskey = new SecretKeySpec(getKey(), Algorithm); 50 | Cipher c1 = Cipher.getInstance(Algorithm); 51 | c1.init(Cipher.DECRYPT_MODE, deskey); 52 | byte[] clearByte = c1.doFinal(input.getBytes("utf-8")); 53 | LOG.debug("ouput string:" + byte2hex(clearByte)); 54 | return byte2hex(clearByte); 55 | } catch (Exception e) { 56 | LOG.error("CryptoUtil.decode error!", e); 57 | return null; 58 | } 59 | } 60 | 61 | public static String encrypt(String strSrc) { 62 | MessageDigest md = null; 63 | String strDes = null; 64 | 65 | byte[] bt = strSrc.getBytes(); 66 | try { 67 | md = MessageDigest.getInstance(Algorithm2); 68 | md.update(bt); 69 | strDes = byte2hex(md.digest()); // to HexString 70 | } catch (NoSuchAlgorithmException e) { 71 | LOG.error("Invalid algorithm.", e); 72 | return null; 73 | } 74 | return strDes; 75 | } 76 | 77 | private static String byte2hex(byte bytes[]) { 78 | StringBuffer retString = new StringBuffer(); 79 | for (int i = 0; i < bytes.length; ++i) { 80 | retString.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1).toUpperCase()); 81 | } 82 | return retString.toString(); 83 | } 84 | 85 | private static byte[] hex2byte(String hex) { 86 | byte[] bts = new byte[hex.length() / 2]; 87 | for (int i = 0; i < bts.length; i++) { 88 | bts[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16); 89 | } 90 | return bts; 91 | } 92 | 93 | /** 94 | * 将一个数字转换成0-9a-zA-z的62进制 95 | */ 96 | public static String encodeLongToString(long i) { 97 | if (i == 0) { 98 | return "0"; 99 | } else if (i < 0) { 100 | throw new IllegalArgumentException(); 101 | } 102 | StringBuffer buffer = new StringBuffer(); 103 | while (i > 0) { 104 | buffer.insert(0, encodeIntToChar((int) (i % 62))); 105 | i /= 62; 106 | } 107 | return buffer.toString(); 108 | } 109 | 110 | /** 111 | * 将0-9a-zA-z的62进制转换成一个数字 112 | */ 113 | public static long decodeStringToLong(String s) { 114 | long i = 0; 115 | for (int index = 0; index < s.length(); index++) { 116 | if (index > 0) { 117 | i *= 62; 118 | } 119 | i += decodeCharToInt(s.charAt(index)); 120 | } 121 | return i; 122 | } 123 | 124 | /** 125 | * 将数字作为顺序转换成单位的0-9a-zA-z
126 | * 0 -> '0'
127 | * 9 -> '9'
128 | * 10 -> 'a'
129 | * 35 -> 'z'
130 | * 36 -> 'A'
131 | * 61 -> 'Z' 132 | */ 133 | private static char encodeIntToChar(int i) { 134 | if (i >= 0 && i <= 9) { 135 | return (char) (i + 48); 136 | } else if (i >= 10 && i <= 35) { 137 | return (char) (i + 87); 138 | } else if (i >= 36 && i <= 61) { 139 | return (char) (i + 29); 140 | } else { 141 | throw new IllegalArgumentException(); 142 | } 143 | } 144 | 145 | /** 146 | * 将单位的0-9a-zA-z按顺序转换成数字
147 | * '0' -> 0
148 | * '9' -> 9
149 | * 'a' -> 10
150 | * 'z' -> 35
151 | * 'A' -> 36
152 | * 'Z' -> 61 153 | */ 154 | private static int decodeCharToInt(char c) { 155 | if (c >= '0' && c <= '9') { 156 | return c - 48; 157 | } else if (c >= 'a' && c <= 'z') { 158 | return c - 87; 159 | } else if (c >= 'A' && c <= 'Z') { 160 | return c - 29; 161 | } else { 162 | throw new IllegalArgumentException(); 163 | } 164 | } 165 | } 166 | --------------------------------------------------------------------------------