├── .gitignore
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── github
│ │ └── oneone1995
│ │ └── mvolunteer
│ │ ├── MVolunteerApplication.java
│ │ ├── config
│ │ ├── aliim
│ │ │ └── IMConstantConfig.java
│ │ ├── async
│ │ │ └── AsyncConfig.java
│ │ ├── easemob
│ │ │ └── EasemobIMProperties.java
│ │ ├── monitor
│ │ │ └── PerformanceMonitor.java
│ │ ├── mvc
│ │ │ └── MvcWebConfig.java
│ │ ├── redis
│ │ │ └── RedisCacheConfig.java
│ │ ├── result
│ │ │ └── ResultStatus.java
│ │ ├── retrofit
│ │ │ └── RetrofitConfig.java
│ │ ├── security
│ │ │ ├── AuthorizationServerConfig.java
│ │ │ ├── ResourceServerConfig.java
│ │ │ └── WebSecurityConfig.java
│ │ └── swagger
│ │ │ └── SwaggerConfig.java
│ │ ├── domain
│ │ ├── Activity.java
│ │ ├── ActivityDetails.java
│ │ ├── ActivityStatus.java
│ │ ├── ActivityUser.java
│ │ ├── Certificate.java
│ │ ├── CustomUserDetails.java
│ │ ├── HomeActivity.java
│ │ ├── OrganizationInfo.java
│ │ ├── Role.java
│ │ ├── User.java
│ │ ├── VolunteerDetails.java
│ │ ├── VolunteerInfo.java
│ │ └── moment
│ │ │ ├── Moment.java
│ │ │ └── MomentComment.java
│ │ ├── mapper
│ │ ├── ActivityMapper.java
│ │ ├── ActivityStatusMapper.java
│ │ ├── ActivityUserMapper.java
│ │ ├── CertificateMapper.java
│ │ ├── MomentCommentMapper.java
│ │ ├── MomentMapper.java
│ │ ├── OrganizationInfoMapper.java
│ │ ├── RoleMapper.java
│ │ ├── UserMapper.java
│ │ └── VolunteerInfoMapper.java
│ │ ├── model
│ │ ├── EasemobIMChatGroupModel.java
│ │ ├── EasemobIMChatMessage.java
│ │ ├── IMTribeModel.java
│ │ └── ResultModel.java
│ │ ├── service
│ │ ├── ActivityService.java
│ │ ├── ActivityStatusService.java
│ │ ├── ActivityUserService.java
│ │ ├── CacheService.java
│ │ ├── CertificateService.java
│ │ ├── EasemobIMService.java
│ │ ├── IMGroupService.java
│ │ ├── ImageService.java
│ │ ├── MomentService.java
│ │ ├── OrganizationService.java
│ │ ├── SearchService.java
│ │ ├── SignInService.java
│ │ ├── UserService.java
│ │ ├── VolunteerService.java
│ │ ├── api
│ │ │ └── EasemobApiService.java
│ │ └── impl
│ │ │ ├── ActivityServiceImpl.java
│ │ │ ├── ActivityStatusServiceImpl.java
│ │ │ ├── ActivityUserServiceImpl.java
│ │ │ ├── CacheServiceImpl.java
│ │ │ ├── CertificateServiceImpl.java
│ │ │ ├── EasemobIMServiceImpl.java
│ │ │ ├── ImageServiceImpl.java
│ │ │ ├── MomentServiceImpl.java
│ │ │ ├── OrganizationServiceImpl.java
│ │ │ ├── SearchServiceImpl.java
│ │ │ ├── SignInServiceImpl.java
│ │ │ ├── UserServiceImpl.java
│ │ │ └── VolunteerServiceImpl.java
│ │ ├── utils
│ │ └── IMUtil.java
│ │ └── web
│ │ ├── ActivityController.java
│ │ ├── ActivityStatusController.java
│ │ ├── ActivityUserController.java
│ │ ├── CertificateController.java
│ │ ├── ImageController.java
│ │ ├── LoginController.java
│ │ ├── MomentController.java
│ │ ├── OrganizationController.java
│ │ ├── SearchController.java
│ │ ├── SignInController.java
│ │ ├── UserController.java
│ │ ├── VolunteerController.java
│ │ └── exception
│ │ ├── EasemobGroupCreateFailException.java
│ │ ├── GenerateEasemobTokenFailException.java
│ │ ├── GlobalExceptionHandler.java
│ │ ├── GroupNotFoundException.java
│ │ ├── MomentCommentCreateFailException.java
│ │ ├── MomentCommentNotFoundException.java
│ │ ├── MomentCreateFailException.java
│ │ ├── MomentNotFoundException.java
│ │ ├── PutUserToEasemobGroupFailException.java
│ │ ├── SendEasemobMessageFailException.java
│ │ ├── ServerInternalErrorException.java
│ │ └── UserNotFoundException.java
└── resources
│ ├── application.yml.backup
│ ├── banner.txt
│ ├── generatorConfig.xml
│ ├── lib
│ └── taobao-sdk-java-auto_1486975747295-20170226.jar
│ ├── m_volunteer.sql
│ └── mapper
│ ├── ActivityMapper.xml
│ ├── ActivityStatusMapper.xml
│ ├── ActivityUserMapper.xml
│ ├── CertificateMapper.xml
│ ├── MomentCommentMapper.xml
│ ├── MomentMapper.xml
│ ├── OrganizationInfoMapper.xml
│ ├── RoleMapper.xml
│ ├── UserMapper.xml
│ └── VolunteerInfoMapper.xml
└── test
└── java
└── com
└── github
└── oneone1995
└── mvolunteer
└── MVolunteerApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
25 | /.mvn/
26 | /mvnw
27 | /mvnw.cmd
28 | /src/main/resources/application.yml
29 | /out/
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # M-Volunteer-SpringBoot
2 | 该项目是**美志愿APP**的服务端源码。美志愿是一个公益平台APP,志愿者可以通过它来寻找感兴趣的志愿活动,交到更多志同道合的朋友。美志愿将传统繁杂的志愿活动做进手机,为传统的发布志愿活动、参与志愿项目、活动签到、工时统计、证书申请等带来便利,一切自动化完成,极大的降低了传统的人工劳动力。并在传统基础上融入社交元素,提供智能建群、圈子分享等新互联网元素。
3 |
4 | ## 启动
5 | > 注意:因为这是我第一次使用spring-boot进行项目开发,当时还没有了解到可以分环境配置不同的yml配置文件,所以在本项目中,我把涉及隐私的yml文件加入了gitignore,并复制了一份相同的 **yml.backup** ,但修改了数据库信息。你可以clone以后自建一个yml,并复制backup中的配置。另外静态资源目录也需要重新配置
6 |
7 | > 项目中新使用了retrofit网络请求框架,但retrofit这个starter的作者未发布到maven中央仓库,因此需要先将这个库install到你本地maven仓库。打开命令行窗口,键入:
8 | ```bash
9 | git clone https://github.com/syhily/spring-boot-retrofit-support
10 | cd spring-boot-retrofit-support
11 | mvn clean install
12 | ```
13 | 如果有错,建议用idea打开这个项目,利用ide将库install到本地maven仓库中。
14 |
15 |
16 | 首先,你应该要将这个代码库克隆到你的磁盘上,并进入此目录。启动命令行窗口,键入:
17 |
18 | ```
19 | git clone https://github.com/oneone1995/M-Volunteer-SpringBoot
20 | cd M-Volunteer-SpringBoot
21 | ```
22 |
23 | 然后,启动应用(初次启动的话,这个过程会需要稍微久一点的时间)。在命令行窗口中键入:
24 |
25 | ```
26 | mvn spring-boot:run
27 | ```
28 | 你也可以使用ide的check out form version control直接clone项目并打开。
29 |
30 | 此时,你可以尝试发出一个 HTTP 请求。例如,利用浏览器向你的 Web 应用发出一个 HTTP GET 请求,在地址栏键入:
31 |
32 | ```http
33 | http://localhost:9090/swagger-ui.html
34 | ```
35 | 你将会看到该项目所有的api接口以及参数,但因为找不到在swagger中配置headers的方法,所以部分需要带上token访问的接口无法直接在swagger中直接测试。
36 |
37 | ## 细节
38 |
39 | ### 项目目录
40 | 项目目录树:
41 | M-Volunteer:.
42 | └─src
43 | ├─main
44 | │ ├─java
45 | │ │ └─com
46 | │ │ └─github
47 | │ │ └─oneone1995
48 | │ │ └─mvolunteer
49 | │ │ ├─config
50 | │ │ │ ├─aliim
51 | │ │ │ ├─mvc
52 | │ │ │ ├─result
53 | │ │ │ ├─security
54 | │ │ │ └─swagger
55 | │ │ ├─domain
56 | │ │ ├─mapper
57 | │ │ ├─model
58 | │ │ ├─service
59 | │ │ │ └─impl
60 | │ │ ├─utils
61 | │ │ └─web
62 | │ └─resources
63 | │ ├─lib
64 | │ ├─mapper
65 | │ └─static
66 | └─test
67 | └─…(& so on)
68 | - ```src/main/java/com/github/oneone1995/mvolunteer/config```: 该目录放置了配置类,包下又根据配置的作用域分为多个文件夹,其子目录aliim放置与阿里云旺sdk相关的配置类,mvc目录下放置springMVC相关配置类,result目录下放置api的返回状态码配置类,security目录下放置spring-security的相关配置类,swagger目录下放置文档生成工具swagger-ui的配置相关配置类
69 | - ```src/main/java/com/github/oneone1995/mvolunteer/domain```: 该目录放置了各种模型类与对应域
70 | - ```src/main/java/com/github/oneone1995/mvolunteer/mapper```: 该目录放置了数据库增删改查的mybatis代理接口
71 | - ```src/main/java/com/github/oneone1995/mvolunteer/service```: 该目录下放置服务(一个服务对应于一些业务逻辑的集合)的接口,其子目录 impl 放置了这些接口的实现类
72 | - ```src/main/java/com/github/oneone1995/mvolunteer/util```: 该目录放置了各种工具类
73 | - ```src/main/java/com/github/oneone1995/mvolunteer/web```: 该目录放置了和网络层相关的一切,包括控制器、过滤器等等
74 | - ```src/main/resources/mapeer```: 该目录放置了 MyBatis 的映射器 XML 文件
75 | - ```src/main/resources/lib```: 该目录放置了maven项目以外的lib库文件
76 |
77 | ### 集成 OAuth 2.0
78 |
79 | 为了使服务器的资源受到保护,也就是只让信任的客户端访问受保护的资源,本项目选择 Spring Security OAuth 来集成 OAuth 2.0 来保护我们服务器的资源。
80 |
81 | 只有了解了 OAuth 2.0 的运行流程,我们才能正确的使用它。所以,首先,我们先来了解一下 OAuth 2.0 的运行流程。它的运行流程见[RFC 6749](http://www.rfcreader.com/#rfc6749)。
82 |
83 |
84 | OAuth 2.0 有4种授权方式,分别是:授权码模式(authorization code),简化模式(implicit),密码模式(resource owner password credentials)和客户端模式(client credentials),本项目只采用密码模式。
85 |
86 | 既然清楚了运行流程,那么接下来要进行的是对 Spring Security OAuth 的配置,涉及到这些的类有:
87 |
88 | - ```com.github.oneone1995.mvolunteer.domain.CustomUserDetails```: 该类是一个模型类,继承自User,包装了角色信息的User扩展类,实现了 ```UserDetails```接口。它主要负责传送用户的认证信息,包括:用户名,密码,该用户所拥有的权限等等。只需要将关联查询查询出用户信息和角色信息结果映射到这个模型类即可。
89 | - ```com.github.oneone1995.mvolunteer.config.security.AuthorizationServerConfig```: 该类是一个配置类,继承了 ```AuthorizationServerConfigurerAdapter```。它主要负责授权服务器的配置,包括:信任的客户端信息的管理、请求令牌的 URL 的配置、 令牌的管理、如何认证用户的配置、对于请求令牌的 URL 的安全约束的配置等等
90 | - ```com.github.oneone1995.mvolunteer.config.security.ResourceServerConfig```: 该类是一个配置类,继承了 ```ResourceServerConfigurerAdapter```。他主要负责资源服务器的配置,包括:对于请求资源的 URL 的安全约束的配置等等
91 | - ```com.github.oneone1995.mvolunteer.config.security.WebSecurityConfig```: 该类是一个配置类,继承了 ```GlobalAuthenticationConfigurerAdapter```。它主要负责有关认证的配置,包括:用户的认证信息的获取等等
92 | - ```com.github.oneone1995.mvolunteer.service.UserService```: 该类是一个服务类的接口,继承了 ```UserDetailsService``` 接口。
93 | - ```com.github.oneone1995.mvolunteer.impl.UserServiceImpl```: 该类是 ```UserService``` 接口的实现类。
94 |
95 | 有了这些配置,我们实现的效果是:
96 |
97 | - app首页的活动列表不需要权限认真即可访问
98 | - 对 活动详情的查看需要认证
99 | - 对 报名活动、取消报名、申请证书、签到 需要志愿者权限
100 | - 对 发布活动、审核面试、审核证书 需要志愿组织权限
101 |
102 | #### 使用途径
103 |
104 | 首先,我们尝试访问不需要认证的资源:
105 |
106 | ```
107 | curl -s "http://localhost:9090/api/activity?page=1&rows=10&coordLong=120&coordLat=30"
108 | ```
109 |
110 | 正如我们所期待的,服务器返回了一个活动列表资源给客户端,如下:
111 |
112 | ```json
113 | ...
114 | {
115 | "id": 9,
116 | "distance": 34,
117 | "district": "上城区",
118 | "recruitedPersonNumber": 0,
119 | "recruitPersonNumber": 30,
120 | "picture": "/public/img/f129776e-1b44-4f67-a526-79796c051a38.jpeg",
121 | "name": "志愿者提供志愿服务,包括活动前期准备"
122 | }
123 | ...
124 | ```
125 |
126 | 接下来,我们尝试不带认证信息的访问需要认证的资源(尝试查看某个活动的活动详情,这个api涉及志愿者报名和志愿组织推荐,因此需要登录以后才可以):
127 |
128 | ```
129 | curl -s "http://localhost:9090/api/activity/1?coordLong=120&coordLat=30"
130 | ```
131 |
132 | 我们收到如下的 JSON 字符串响应,告诉我们需要认证了才能访问这个资源:
133 |
134 | ```json
135 | {
136 | "error": "unauthorized",
137 | "error_description": "Full authentication is required to access this resource"
138 | }
139 | ```
140 |
141 | 为了访问受保护的资源,我们需要先向授权服务器请求访问令牌(access token):
142 |
143 | ```
144 | curl http://localhost:9090/oauth/token -X POST -u client:m_volunteer -d "grant_type=password&username=voltest&password=voltest"
145 | ```
146 |
147 | 授权服务器验证了我们的客户端和用户信息,验证成功后将我们需要的令牌(token)信息作为响应传回:
148 |
149 | ```json
150 | {
151 | "access_token": "363860cb-253e-40e2-a719-7e447f147f97",
152 | "token_type": "bearer",
153 | "refresh_token": "e6cd3e81-6f18-4362-bded-24baa79dbf47",
154 | "expires_in": 2591999,
155 | "scope": "read write"
156 | }
157 | ```
158 |
159 | 接下来,我们可以使用上个请求返回的 ```access_token```,查看受保护的资源,这里查看活动id为1的活动详情:
160 |
161 | ```
162 | curl "http://localhost:9090/api/activity/1?coordLong=120&coordLat=30" -X GET -H "Authorization: Bearer 363860cb-253e-40e2-a719-7e447f147f97"
163 | ```
164 |
165 | 相应成功返回:
166 | ```json
167 | {
168 | "id": 1,
169 | "addressStreet": "紫荆花路",
170 | "address": "西湖区紫荆花路9号紫庭南弄紫金庭园芦荻苑9幢3号商铺",
171 | "serviceType": "敬老助残",
172 | "recruitTime": "3月3号",
173 | "recruitPersonNumber": 20,
174 | "name": "为老人开展志愿服务",
175 | "time": "3月5号",
176 | "principalName": "卜丽萍",
177 | "principalContact": "13805771623",
178 | "workingHours": 8,
179 | "picture": "/public/img/9629ec51-4968-4173-b109-4ac89616350a.jpeg",
180 | "organizationId": 3,
181 | "description": "为老人开展志愿服务,要求会理发,义诊,缝补,磨剪刀,心理咨询,清洗眼镜,量血压",
182 | "organization": "富春街道",
183 | "distance": 32,
184 | "recruitedPersonNumber": 3,
185 | "volunteers": [
186 | {
187 | "id": 1,
188 | "avatar": "/public/img/default_avatar.jpg"
189 | },
190 | {
191 | "id": 2,
192 | "avatar": "/public/img/e3e8f15a-56fd-426f-aaa7-bb9698a6f9c9.jpg"
193 | },
194 | {
195 | "id": 5,
196 | "avatar": "/public/img/default_avatar.jpg"
197 | }
198 | ],
199 | "signUp": true
200 | }
201 | }
202 | ```
203 |
204 |
205 | 最后,随着时间(在本项目中是 2591999 秒)的消逝,```access_token``` 会过期。可以使用曾经请求访问令牌时返回的 ```refresh_token``` 来获取一个新的 ```access_token```:
206 |
207 | ```
208 | curl http://localhost:9090/oauth/token -X POST -u client:m_volunteer -d "grant_type=refresh_token&refresh_token=e6cd3e81-6f18-4362-bded-24baa79dbf47"
209 | ```
210 |
211 | ### 集成spring-security
212 |
213 | 使用基于方法的注解来进行方法的权限控制,加在特定角色才能访问的方法上:
214 | ```java
215 | @PreAuthorize("hasRole('ROLE_VOL')")
216 | ```
217 | ### 静态资源配置
218 |
219 | 项目涉及图片上传,静态资源配置需要重新配置,配置教程可参照博客[springboot静态资源处理](http://blog.csdn.net/catoop/article/details/50501706)。
220 | 本项目中涉及这个的有yml中的
221 | - ```upload.path``` 静态资源所在文件夹
222 | - ```upload.dir``` 除去静态资源根目录的根路径的目录
223 | 本项目中涉及这个的类有
224 | - ```com.github.oneone1995.mvolunteer.config.mvc.MvcWebConfig```
225 |
226 | 可参考这些重新配置
227 |
228 | ### ~~集成阿里云旺IM~~~(改用环信了,文档有空补)
229 | ~~**群组功能** 是美志愿APP最大的亮点。群组功能免去传统志愿活动发起后需要手动建立qq群或者微信群并人工通知参与活动的志愿者。因为志愿者的分布问题而使得通知工作变得异常困难,美志愿APP为此提出**自动建群**的解决方案,只要志愿组织发布活动成功,系统便会自动建立一个群用于公告通知和志愿者间相互交流。活动发起者默认为群主,可以设立管理员,看活动大小决定管理员数量,志愿者报名活动申请通过后,会自动加入群。
230 | 自己实现一个im是很困难的,因此项目采用集成阿里云旺sdk的解决方案,[官方文档](https://baichuan.taobao.com/docs/doc.htm?treeId=41&articleId=102626&docType=1)
231 | 项目中涉及建群、退群的方法都写在了 **util** 包中~~
232 |
233 | ## 总结
234 | 由于是比赛项目,进度十分紧张,最后完成的项目(app效果可以参见客户端的仓库。)和我当初的想法相差甚大:
235 | - 项目初期本想设计良好的restful API,最后写出来的还是不尽人意。在关联查询和多参数的接口设计上陷入了较大的困难。
236 | - 在后期编码中也直接使用了**JDBC**的关联查询而不是 **Mybatis** 自身支持的关联查询语法。(写着写着写忘了,join就撸上了....)
237 | - 搜索活动部分用的较为简单的like模糊搜索,并且没有加入分词
238 |
239 | 引用知乎某个问题下面的回答(具体我忘了),一个有规模的项目是不可能这么简单从数据库里拖数据往客户端或者前端丢个api就完事的,中间充斥着大量的业务逻辑、消息队列、缓存机制,这些名词在我开始面试之前我都没有听说过。虽然如此,但仍然是一个比较完整的app服务端项目,可以作为新入门学习demo,即便它只有简单的CURD,称不上一个有深度的web后端项目。这个项目我也仍然为之自豪,这是我学习路上进步最快的一段时间。最后,如果有时间的话,会将目前存在的缺陷都完善,并新增部分新功能的支持。
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.oneone1995
7 | m_volunteer
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | m_volunteer
12 | M-Volunteer Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.5.1.RELEASE
18 |
19 |
20 |
21 |
22 |
23 | UTF-8
24 | UTF-8
25 | 1.8
26 |
27 |
28 | 1.2.0
29 |
30 |
31 | 1.1.0
32 |
33 |
34 | 2.10.0
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-aop
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-starter-thymeleaf
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-web
51 |
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-starter-test
56 | test
57 |
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-starter-security
62 |
63 |
64 |
65 |
66 |
67 | org.springframework.security.oauth
68 | spring-security-oauth2
69 |
70 |
71 |
72 | org.thymeleaf.extras
73 | thymeleaf-extras-springsecurity4
74 |
75 |
76 |
77 |
78 |
79 |
80 | com.zaxxer
81 | HikariCP
82 |
83 |
84 |
85 | mysql
86 | mysql-connector-java
87 | runtime
88 |
89 |
90 |
91 | org.springframework.boot
92 | spring-boot-starter-jdbc
93 |
94 |
95 |
96 |
97 | org.mybatis.spring.boot
98 | mybatis-spring-boot-starter
99 | ${mybatis-spring-boot-starter.version}
100 |
101 |
102 |
103 |
104 | org.projectlombok
105 | lombok
106 | true
107 |
108 |
109 |
110 |
111 | com.github.pagehelper
112 | pagehelper-spring-boot-starter
113 | ${pagehelper-spring-boot-starter.version}
114 |
115 |
116 |
117 |
118 | io.springfox
119 | springfox-swagger2
120 | ${springfox.version}
121 |
122 |
123 | io.springfox
124 | springfox-swagger-ui
125 | ${springfox.version}
126 |
127 |
128 |
129 |
130 |
131 | com.oneapm.touch.retrofit
132 | retrofit-spring-boot-starter
133 | 1.0.8-SNAPSHOT
134 |
135 |
136 |
137 | com.squareup.okhttp3
138 | logging-interceptor
139 | 3.9.1
140 |
141 |
142 |
143 |
144 | org.springframework.boot
145 | spring-boot-starter-data-redis
146 |
147 |
148 |
149 |
150 | org.springframework.boot
151 | spring-boot-configuration-processor
152 | true
153 |
154 |
155 |
156 |
157 | ch.hsr
158 | geohash
159 | 1.3.0
160 |
161 |
162 |
163 |
164 | com.taobao.api
165 | taobao-sdk
166 | 20170226
167 | system
168 | ${project.basedir}/src/main/resources/lib/taobao-sdk-java-auto_1486975747295-20170226.jar
169 |
170 |
171 |
172 |
173 |
174 |
175 | org.springframework.boot
176 | spring-boot-maven-plugin
177 |
178 |
179 |
180 | maven-compiler-plugin
181 |
182 | 1.8
183 | 1.8
184 | UTF-8
185 |
186 | ${project.basedir}/src/resources/lib
187 |
188 |
189 |
190 |
191 |
192 | org.mybatis.generator
193 | mybatis-generator-maven-plugin
194 | 1.3.5
195 |
196 | true
197 | true
198 |
199 |
200 |
201 | mysql
202 | mysql-connector-java
203 | 8.0.28
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 | ${basedir}/src/main/resources
212 | true
213 |
214 | **/application*.yml
215 | **/application*.properties
216 |
217 |
218 |
219 | ${basedir}/src/main/resources
220 |
221 | **/application*.yml
222 | **/application*.properties
223 |
224 |
225 |
226 | src/main/resources
227 | BOOT-INF/lib/
228 |
229 | **/*.jar
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/MVolunteerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MVolunteerApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(MVolunteerApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/aliim/IMConstantConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.aliim;
2 |
3 | /**
4 | * Created by wangl on 2017/2/26.
5 | * 阿里悟空的常量配置类
6 | * 配置了app_key、app_security和访问的api接口地址
7 | *
8 | * 已经改用环信,不再使用,2017.12.19
9 | */
10 | @Deprecated
11 | public class IMConstantConfig {
12 | public static final String APP_KEY = "23653358";
13 | public static final String APP_SECURITY = "a087591f9fcec915ebbc9dc1fa490c0f";
14 | public static final String API_URL = "http://gw.api.taobao.com/router/rest";
15 |
16 | private IMConstantConfig() {
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/async/AsyncConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.async;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.scheduling.annotation.EnableAsync;
5 |
6 | /**
7 | * 异步任务配置类,暂时没什么配置,只是启用了注解
8 | */
9 | @Configuration
10 | @EnableAsync
11 | public class AsyncConfig {
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/easemob/EasemobIMProperties.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.easemob;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.Data;
5 | import lombok.ToString;
6 | import org.springframework.boot.context.properties.ConfigurationProperties;
7 | import org.springframework.boot.context.properties.NestedConfigurationProperty;
8 | import org.springframework.stereotype.Component;
9 |
10 | /**
11 | * 环信即时通讯云的配置映射,具体值在环信管理后台可以查到,配置在application.yml中
12 | * @see
13 | *
14 | * 环信服务器基本架构[环信开发文档]
15 | */
16 |
17 | @Data
18 | @ToString
19 | @Component
20 | @ConfigurationProperties(prefix = "easemob")
21 | public class EasemobIMProperties {
22 | //环信服务体系中企业ID,环信管理后台可以查到
23 | private String orgName;
24 |
25 | //环信服务体系中的app名字,环信管理后台可以查到
26 | private String appName;
27 |
28 | @NestedConfigurationProperty
29 | private Security security;
30 |
31 | @Data
32 | public static class Security {
33 | //环信生成token的OAuth2授权方式,只在生成token的API中使用
34 | @JsonProperty("grant_type")
35 | private String grantType;
36 |
37 | //环信服务体系中的client_id,只在生成token的API中使用
38 | @JsonProperty("client_id")
39 | private String clientId;
40 |
41 | //环信服务体系中的client_secret,只在生成token的API中使用
42 | @JsonProperty("client_secret")
43 | private String clientSecret;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/monitor/PerformanceMonitor.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.monitor;
2 |
3 | import org.aspectj.lang.ProceedingJoinPoint;
4 | import org.aspectj.lang.Signature;
5 | import org.aspectj.lang.annotation.Around;
6 | import org.aspectj.lang.annotation.Aspect;
7 | import org.aspectj.lang.annotation.Pointcut;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.stereotype.Component;
11 | import org.springframework.util.StopWatch;
12 |
13 | /**
14 | * Created by wangl on 2017/2/27.
15 | */
16 | @Aspect
17 | @Component
18 | public class PerformanceMonitor {
19 | protected Logger log = LoggerFactory.getLogger(PerformanceMonitor.class);
20 | @Pointcut("execution(public * com.github.oneone1995.mvolunteer.web..*(..))")
21 | private void controllerLayer() {
22 | }
23 |
24 | /**
25 | * Monitor the elapsed time of method on controller layer, in
26 | * order to detect performance problems as soon as possible.
27 | * If elapsed time > 1 s, log it as an error. Otherwise, log it
28 | * as an info.
29 | */
30 | @Around("controllerLayer()")
31 | public Object monitorElapsedTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
32 | // Timing the method in controller layer
33 | StopWatch stopWatch = new StopWatch();
34 | stopWatch.start();
35 | Object result = proceedingJoinPoint.proceed();
36 | stopWatch.stop();
37 |
38 | // Log the elapsed time
39 | double elapsedTime = stopWatch.getTotalTimeSeconds();
40 | Signature signature = proceedingJoinPoint.getSignature();
41 | String infoString = "[" + signature.toShortString() + "][Elapsed time: " + elapsedTime + " s]";
42 | if (elapsedTime > 1) {
43 | log.error(infoString + "[Note that it's time consuming!]");
44 | } else {
45 | log.info(infoString);
46 | }
47 |
48 | // Return the result
49 | return result;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/mvc/MvcWebConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.mvc;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
7 |
8 | /**
9 | * Created by wangl on 2017/2/20.
10 | * springMVC相关配置类
11 | */
12 | @Configuration
13 | public class MvcWebConfig extends WebMvcConfigurerAdapter {
14 | //静态资源路径配置
15 | @Value("${upload.path}")
16 | private String path;
17 |
18 | /**
19 | * 静态资源映射配置
20 | * @param registry
21 | */
22 | @Override
23 | public void addResourceHandlers(ResourceHandlerRegistry registry) {
24 | registry.addResourceHandler("/public/img/**").addResourceLocations("file:" + path);
25 | super.addResourceHandlers(registry);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/redis/RedisCacheConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.redis;
2 |
3 | import org.springframework.cache.CacheManager;
4 | import org.springframework.cache.annotation.CachingConfigurerSupport;
5 | import org.springframework.cache.annotation.EnableCaching;
6 | import org.springframework.cache.interceptor.KeyGenerator;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.data.redis.cache.RedisCacheManager;
10 | import org.springframework.data.redis.connection.RedisConnectionFactory;
11 | import org.springframework.data.redis.core.RedisTemplate;
12 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
13 | import org.springframework.data.redis.serializer.RedisSerializer;
14 | import org.springframework.data.redis.serializer.StringRedisSerializer;
15 |
16 |
17 | /**
18 | * redis缓存配置类
19 | * 配置了key和value的序列化方式来防止乱码
20 | * 配置了缓存管理器,设置了默认缓存时间
21 | */
22 | @Configuration
23 | @EnableCaching
24 | public class RedisCacheConfig extends CachingConfigurerSupport {
25 |
26 | @Bean
27 | public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
28 | RedisTemplate template = new RedisTemplate<>();
29 | template.setConnectionFactory(factory);
30 |
31 | //设置key序列化类,防止key前面的乱码
32 | RedisSerializer keySerializer = new StringRedisSerializer();
33 | template.setKeySerializer(keySerializer);
34 | template.setHashKeySerializer(keySerializer);
35 |
36 | //设置value序列化
37 | GenericJackson2JsonRedisSerializer jsonSerializer = new GenericJackson2JsonRedisSerializer();
38 | template.setValueSerializer(jsonSerializer);
39 |
40 | template.afterPropertiesSet();
41 |
42 | return template;
43 | }
44 |
45 | @Bean
46 | public CacheManager cacheManager(RedisTemplate redisTemplate) {
47 | RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
48 | //默认缓存过期时间设为10天
49 | cacheManager.setDefaultExpiration(60 * 60 * 24 * 10);
50 | return cacheManager;
51 | }
52 |
53 | /**
54 | * redis缓存key生成策略,类名+方法名
55 | * @return KeyGenerator
56 | */
57 | @Override
58 | public KeyGenerator keyGenerator() {
59 | return (target, method, params) -> target.getClass().getName() + "#" + method.getName();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/result/ResultStatus.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.result;
2 |
3 | /**
4 | * Created by wangl on 2017/2/7.
5 | * 自定义请求状态码
6 | */
7 | public enum ResultStatus {
8 | SUCCESS(200, "成功"),
9 | USERNAME_OR_PASSWORD_ERROR(-1001, "用户名或密码错误"),
10 | USER_NOT_FOUND(-1002, "用户不存在"),
11 | USER_NOT_LOGIN(-1003, "用户未登录"),
12 | ACTIVITY_NOT_FOUNT(-1004, "活动不存在"),
13 | FILE_IS_EMPTY(-1005, "文件为空"),
14 | FILE_UPLOAD_ERROR(-1006, "文件上传失败"),
15 | SIGN_IN_FAIL(-1007, "签到失败"),
16 | ACTIVITY_CREATE_FAIL(-1008, "创建活动失败"),
17 | ACTIVITY_STATUS_NOT_FOUNT(-1009, "活动状态不存在"),
18 | CERTIFICATE_IS_EXIST(-10010, "证书已经申请过啦"),
19 | WORKING_HOURS_NOT_ENOUGH(-10011, "工时不够"),
20 | SIGN_UP_FAIL(-10012, "报名失败"),
21 | CANCEL_FAIL(-10013, "取消失败"),
22 | ACTIVITY_STATUS_UPDATE_FAIL(-10014,"活动状态更新失败"),
23 | ACTIVITY_STATUS_IMMUTABLE(-10015, "活动状态不可更改"),
24 | ORGANIZATION_HAS_NO_VOLUNTEER(-10016, "组织没有志愿者加入"),
25 | CERTIFICATE_STATUS_UPDATE_FAIL(-10017, "证书状态更新失败"),
26 | INTERVIEW_IS_NULL(-10018, "面试列表为空"),
27 | INTERVIEW_STATUS_UPDATE_FAIL(-10019, "面试状态修改失败"),
28 | MOMENT_NOT_FOUNT(-10020, "动态不存在"),
29 | MOMENT_CREATE_FAIL(-10021, "创建动态失败"),
30 | MOMENT_COMMENT_NOT_FOUNT(-10028, "评论不存在"),
31 | MOMENT_COMMENT_CREATE_FAIL(-10029, "创建动态评论失败"),
32 | EASEMOB_GROUP_CREATE_FAIL(-10022, "环信群组创建失败"),
33 | PUT_USER_TO_EASEMOB_GROUP_FAIL(-10024, "添加用户至环信群组失败"),
34 | GENERATE_EASEMOB_TOKEN_FAIL(-10025, "生成环信token失败"),
35 | GROUP_NOT_FOUND(-10026, "群组未找到"),
36 | SEND_MESSAGE_FAIL(-10027, "发送消息失败"),
37 | INTERNAL_SERVER_ERROR(-10023, "系统内部错误");
38 |
39 | /**
40 | * 返回码
41 | */
42 | private int code;
43 |
44 | /**
45 | * 返回信息描述
46 | */
47 | private String message;
48 |
49 | ResultStatus(int code, String message) {
50 | this.code = code;
51 | this.message = message;
52 | }
53 |
54 | public int getCode() {
55 | return code;
56 | }
57 |
58 | public void setCode(int code) {
59 | this.code = code;
60 | }
61 |
62 | public String getMessage() {
63 | return message;
64 | }
65 |
66 | public void setMessage(String message) {
67 | this.message = message;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/retrofit/RetrofitConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.retrofit;
2 |
3 | import com.oneapm.touch.retrofit.boot.RetrofitServiceScan;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | /**
7 | * retrofit相关配置类,目前配置都写在了application.yml中
8 | * 可以参考
9 | * @see
10 | */
11 | @Configuration
12 | @RetrofitServiceScan("com.github.oneone1995.mvolunteer.service")
13 | public class RetrofitConfig {
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/security/AuthorizationServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.security;
2 |
3 | import com.github.oneone1995.mvolunteer.service.UserService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.context.annotation.Primary;
8 | import org.springframework.security.authentication.AuthenticationManager;
9 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
10 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
11 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
12 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
13 | import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
14 | import org.springframework.security.oauth2.provider.token.TokenStore;
15 | import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
16 |
17 | /**
18 | * Created by wangl on 2017/2/14.
19 | * 授权服务器配置类
20 | * 它主要负责授权服务器的配置
21 | * 包括:信任的客户端信息的管理、请求令牌的 URL 的配置、令牌的管理、如何认证用户的配置、对于请求令牌的 URL 的安全约束的配置
22 | */
23 | @Configuration
24 | @EnableAuthorizationServer
25 | public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
26 | @Autowired
27 | private TokenStore tokenStore;
28 |
29 | @Autowired
30 | private AuthenticationManager authenticationManager;
31 |
32 | @Autowired
33 | private UserService userService;
34 |
35 | @Override
36 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
37 | clients
38 | .inMemory()
39 | .withClient("client")
40 | .authorizedGrantTypes("password", "refresh_token")
41 | .scopes("read", "write")
42 | .secret("m_volunteer")
43 | .accessTokenValiditySeconds(2592000);
44 | }
45 |
46 | @Override
47 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
48 | endpoints
49 | .tokenStore(tokenStore)
50 | .authenticationManager(authenticationManager)
51 | .userDetailsService(userService);
52 | }
53 |
54 | @Bean
55 | public TokenStore tokenStore() {
56 | return new InMemoryTokenStore();
57 | }
58 |
59 | @Bean
60 | @Primary
61 | public DefaultTokenServices tokenServices() {
62 | DefaultTokenServices tokenServices = new DefaultTokenServices();
63 | tokenServices.setSupportRefreshToken(true); // support refresh token
64 | tokenServices.setTokenStore(tokenStore); // use in-memory token store
65 | return tokenServices;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/security/ResourceServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.security;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.http.HttpMethod;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
8 |
9 | /**
10 | * Created by wangl on 2017/2/14.
11 | * 配置类
12 | * 主要负责资源服务器的配置,包括:对于请求资源的 URL 的安全约束的配置等等
13 | */
14 | @Configuration
15 | @EnableResourceServer
16 | public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
17 | @Override
18 | public void configure(HttpSecurity http) throws Exception {
19 | http
20 | .authorizeRequests()
21 | .antMatchers("/api/signin/**").authenticated()
22 | .antMatchers("/api/loginSuccess").authenticated()
23 | .antMatchers("/api/**").permitAll()
24 | .antMatchers("/public/**").permitAll()
25 | .antMatchers("/v2/api-docs", "/configuration/ui",
26 | "/swagger-resources", "/configuration/security",
27 | "/swagger-ui.html", "/webjars/**",
28 | "/swagger-resources/configuration/ui", "/swagger-ui.html").permitAll()
29 | .anyRequest().authenticated();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/security/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.security;
2 |
3 | import com.github.oneone1995.mvolunteer.service.UserService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7 | import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter;
8 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
9 |
10 | /**
11 | * Created by wangl on 2017/2/10.
12 | */
13 | @Configuration
14 | //用于@PreAuthorize的生效,基于方法的权限控制
15 | @EnableGlobalMethodSecurity(prePostEnabled = true)
16 | public class WebSecurityConfig extends GlobalAuthenticationConfigurerAdapter {
17 | private final UserService userService;
18 |
19 | @Autowired
20 | public WebSecurityConfig(UserService userService) {
21 | this.userService = userService;
22 | }
23 |
24 | @Override
25 | public void init(AuthenticationManagerBuilder auth) throws Exception {
26 | auth.userDetailsService(userService);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/config/swagger/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.config.swagger;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import springfox.documentation.builders.ApiInfoBuilder;
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.service.ApiInfo;
9 | import springfox.documentation.spi.DocumentationType;
10 | import springfox.documentation.spring.web.plugins.Docket;
11 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
12 |
13 | /**
14 | * Created by wangl on 2017/2/14.
15 | * swagger配置类
16 | */
17 | @Configuration
18 | @EnableSwagger2
19 | public class SwaggerConfig {
20 | @Bean
21 | public Docket createRestApi() {
22 | return new Docket(DocumentationType.SWAGGER_2)
23 | .apiInfo(apiInfo())
24 | .select()
25 | .apis(RequestHandlerSelectors.basePackage("com.github.oneone1995.mvolunteer.web"))
26 | .paths(PathSelectors.any())
27 | .build();
28 | }
29 | private ApiInfo apiInfo() {
30 | return new ApiInfoBuilder()
31 | .title("swagger2")
32 | .description("Spring Boot中使用Swagger2构建RESTful APIs")
33 | .termsOfServiceUrl("https://www.github.com/oneone1995")
34 | .version("1.0")
35 | .build();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/Activity.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | import com.fasterxml.jackson.annotation.JsonInclude;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 |
7 | import java.sql.Date;
8 |
9 | @JsonInclude(JsonInclude.Include.NON_NULL)
10 | public class Activity {
11 | private Integer id;
12 |
13 | private String addressProvince;
14 |
15 | private String addressCity;
16 |
17 | private String addressDistrict;
18 |
19 | private String addressStreet;
20 |
21 | private String address;
22 |
23 | private Double coordLong;
24 |
25 | private Double coordLat;
26 |
27 | //geohash字段,用于查找附近的活动
28 | @Getter
29 | @Setter
30 | private String geohash;
31 |
32 | private String serviceType;
33 |
34 | private String serviceObject;
35 |
36 | private String recruitTime;
37 |
38 | private Integer recruitPersonNumber;
39 |
40 | private String name;
41 |
42 | private String time;
43 |
44 | private String principalName;
45 |
46 | private String principalContact;
47 |
48 | private Integer activityStatusId;
49 |
50 | private Double workingHours;
51 |
52 | private Date timestamp;
53 |
54 | private String picture;
55 |
56 | @Getter
57 | @Setter
58 | private String code;
59 |
60 | private Integer organizationId;
61 |
62 | private String description;
63 |
64 | public Integer getId() {
65 | return id;
66 | }
67 |
68 | public void setId(Integer id) {
69 | this.id = id;
70 | }
71 |
72 | public String getAddressProvince() {
73 | return addressProvince;
74 | }
75 |
76 | public void setAddressProvince(String addressProvince) {
77 | this.addressProvince = addressProvince;
78 | }
79 |
80 | public String getAddressCity() {
81 | return addressCity;
82 | }
83 |
84 | public void setAddressCity(String addressCity) {
85 | this.addressCity = addressCity;
86 | }
87 |
88 | public String getAddressDistrict() {
89 | return addressDistrict;
90 | }
91 |
92 | public void setAddressDistrict(String addressDistrict) {
93 | this.addressDistrict = addressDistrict;
94 | }
95 |
96 | public String getAddressStreet() {
97 | return addressStreet;
98 | }
99 |
100 | public void setAddressStreet(String addressStreet) {
101 | this.addressStreet = addressStreet;
102 | }
103 |
104 | public String getAddress() {
105 | return address;
106 | }
107 |
108 | public void setAddress(String address) {
109 | this.address = address;
110 | }
111 |
112 | public Double getCoordLong() {
113 | return coordLong;
114 | }
115 |
116 | public void setCoordLong(Double coordLong) {
117 | this.coordLong = coordLong;
118 | }
119 |
120 | public Double getCoordLat() {
121 | return coordLat;
122 | }
123 |
124 | public void setCoordLat(Double coordLat) {
125 | this.coordLat = coordLat;
126 | }
127 |
128 | public String getServiceType() {
129 | return serviceType;
130 | }
131 |
132 | public void setServiceType(String serviceType) {
133 | this.serviceType = serviceType;
134 | }
135 |
136 | public String getServiceObject() {
137 | return serviceObject;
138 | }
139 |
140 | public void setServiceObject(String serviceObject) {
141 | this.serviceObject = serviceObject;
142 | }
143 |
144 | public String getRecruitTime() {
145 | return recruitTime;
146 | }
147 |
148 | public void setRecruitTime(String recruitTime) {
149 | this.recruitTime = recruitTime;
150 | }
151 |
152 | public Integer getRecruitPersonNumber() {
153 | return recruitPersonNumber;
154 | }
155 |
156 | public void setRecruitPersonNumber(Integer recruitPersonNumber) {
157 | this.recruitPersonNumber = recruitPersonNumber;
158 | }
159 |
160 | public String getName() {
161 | return name;
162 | }
163 |
164 | public void setName(String name) {
165 | this.name = name;
166 | }
167 |
168 | public String getTime() {
169 | return time;
170 | }
171 |
172 | public void setTime(String time) {
173 | this.time = time;
174 | }
175 |
176 | public String getPrincipalName() {
177 | return principalName;
178 | }
179 |
180 | public void setPrincipalName(String principalName) {
181 | this.principalName = principalName;
182 | }
183 |
184 | public String getPrincipalContact() {
185 | return principalContact;
186 | }
187 |
188 | public void setPrincipalContact(String principalContact) {
189 | this.principalContact = principalContact;
190 | }
191 |
192 | public Integer getActivityStatusId() {
193 | return activityStatusId;
194 | }
195 |
196 | public void setActivityStatusId(Integer activityStatusId) {
197 | this.activityStatusId = activityStatusId;
198 | }
199 |
200 | public Double getWorkingHours() {
201 | return workingHours;
202 | }
203 |
204 | public void setWorkingHours(Double workingHours) {
205 | this.workingHours = workingHours;
206 | }
207 |
208 | public Date getTimestamp() {
209 | return timestamp;
210 | }
211 |
212 | public void setTimestamp(Date timestamp) {
213 | this.timestamp = timestamp;
214 | }
215 |
216 | public String getPicture() {
217 | return picture;
218 | }
219 |
220 | public void setPicture(String picture) {
221 | this.picture = picture;
222 | }
223 |
224 | public Integer getOrganizationId() {
225 | return organizationId;
226 | }
227 |
228 | public void setOrganizationId(Integer organizationId) {
229 | this.organizationId = organizationId;
230 | }
231 |
232 | public String getDescription() {
233 | return description;
234 | }
235 |
236 | public void setDescription(String description) {
237 | this.description = description;
238 | }
239 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/ActivityDetails.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by wangl on 2017/2/21.
7 | * 继承自Activity
8 | * 用于活动详情的实体
9 | * 包含了该活动的id、发起组织、活动内容描述、招募时间、活动开始时间、活动地点、提供时长、
10 | * 活动联系人、联系人电话、服务类别、活动名字、与当地的距离、已报名的人数、已报名的志愿者
11 | */
12 | public class ActivityDetails extends Activity{
13 |
14 | private String organization;
15 |
16 | //面试状态
17 | private String interviewStatus;
18 |
19 | //活动状态
20 | private String activityStatus;
21 |
22 | //与当地的距离
23 | private double distance;
24 |
25 | //已报名的人数
26 | private Integer recruitedPersonNumber;
27 |
28 | //是否已经报名
29 | private boolean isSignUp;
30 |
31 | private List volunteers;
32 |
33 | public String getOrganization() {
34 | return organization;
35 | }
36 |
37 | public void setOrganization(String organization) {
38 | this.organization = organization;
39 | }
40 |
41 | public String getInterviewStatus() {
42 | return interviewStatus;
43 | }
44 |
45 | public void setInterviewStatus(String interviewStatus) {
46 | this.interviewStatus = interviewStatus;
47 | }
48 |
49 | public String getActivityStatus() {
50 | return activityStatus;
51 | }
52 |
53 | public void setActivityStatus(String activityStatus) {
54 | this.activityStatus = activityStatus;
55 | }
56 |
57 | public double getDistance() {
58 | return distance;
59 | }
60 |
61 | public void setDistance(double distance) {
62 | this.distance = distance;
63 | }
64 |
65 | public Integer getRecruitedPersonNumber() {
66 | return recruitedPersonNumber;
67 | }
68 |
69 | public void setRecruitedPersonNumber(Integer recruitedPersonNumber) {
70 | this.recruitedPersonNumber = recruitedPersonNumber;
71 | }
72 |
73 | public boolean isSignUp() {
74 | return isSignUp;
75 | }
76 |
77 | public void setSignUp(boolean signUp) {
78 | isSignUp = signUp;
79 | }
80 |
81 | public List getVolunteers() {
82 | return volunteers;
83 | }
84 |
85 | public void setVolunteers(List volunteers) {
86 | this.volunteers = volunteers;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/ActivityStatus.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | public class ActivityStatus {
4 | private Integer id;
5 |
6 | private String description;
7 |
8 | public Integer getId() {
9 | return id;
10 | }
11 |
12 | public void setId(Integer id) {
13 | this.id = id;
14 | }
15 |
16 | public String getDescription() {
17 | return description;
18 | }
19 |
20 | public void setDescription(String description) {
21 | this.description = description;
22 | }
23 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/ActivityUser.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | /**
4 | * 活动用户表对应的实体域对象。维护了志愿者报名活动后与对应活动的关系,并包含了报名活动后的面试状态。可以看作是活动报名表
5 | */
6 | public class ActivityUser {
7 | private Integer id;
8 |
9 | //活动id
10 | private Integer activityId;
11 |
12 | //志愿者id
13 | private Integer userId;
14 |
15 | //面试状态id,没有具体的域对象映射,只在数据库中有记录
16 | private Integer activityUserStatusId;
17 |
18 | //评分,暂时未使用
19 | private Double star;
20 |
21 | //签到状态
22 | private Integer signInStatus;
23 |
24 | public Integer getId() {
25 | return id;
26 | }
27 |
28 | public void setId(Integer id) {
29 | this.id = id;
30 | }
31 |
32 | public Integer getActivityId() {
33 | return activityId;
34 | }
35 |
36 | public void setActivityId(Integer activityId) {
37 | this.activityId = activityId;
38 | }
39 |
40 | public Integer getUserId() {
41 | return userId;
42 | }
43 |
44 | public void setUserId(Integer userId) {
45 | this.userId = userId;
46 | }
47 |
48 | public Integer getActivityUserStatusId() {
49 | return activityUserStatusId;
50 | }
51 |
52 | public void setActivityUserStatusId(Integer activityUserStatusId) {
53 | this.activityUserStatusId = activityUserStatusId;
54 | }
55 |
56 | public Double getStar() {
57 | return star;
58 | }
59 |
60 | public void setStar(Double star) {
61 | this.star = star;
62 | }
63 |
64 | public Integer getSignInStatus() {
65 | return signInStatus;
66 | }
67 |
68 | public void setSignInStatus(Integer signInStatus) {
69 | this.signInStatus = signInStatus;
70 | }
71 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/Certificate.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | import java.util.Date;
4 |
5 | public class Certificate {
6 | private Integer id;
7 |
8 | private Integer userId;
9 |
10 | private Integer certificateStatusId;
11 |
12 | private Date timestamp;
13 |
14 | private String address;
15 |
16 | private String receiver;
17 |
18 | private String receiverPhone;
19 |
20 | public Integer getId() {
21 | return id;
22 | }
23 |
24 | public void setId(Integer id) {
25 | this.id = id;
26 | }
27 |
28 | public Integer getUserId() {
29 | return userId;
30 | }
31 |
32 | public void setUserId(Integer userId) {
33 | this.userId = userId;
34 | }
35 |
36 | public Integer getCertificateStatusId() {
37 | return certificateStatusId;
38 | }
39 |
40 | public void setCertificateStatusId(Integer certificateStatusId) {
41 | this.certificateStatusId = certificateStatusId;
42 | }
43 |
44 | public Date getTimestamp() {
45 | return timestamp;
46 | }
47 |
48 | public void setTimestamp(Date timestamp) {
49 | this.timestamp = timestamp;
50 | }
51 |
52 | public String getAddress() {
53 | return address;
54 | }
55 |
56 | public void setAddress(String address) {
57 | this.address = address;
58 | }
59 |
60 | public String getReceiver() {
61 | return receiver;
62 | }
63 |
64 | public void setReceiver(String receiver) {
65 | this.receiver = receiver;
66 | }
67 |
68 | public String getReceiverPhone() {
69 | return receiverPhone;
70 | }
71 |
72 | public void setReceiverPhone(String receiverPhone) {
73 | this.receiverPhone = receiverPhone;
74 | }
75 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/CustomUserDetails.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | import org.springframework.security.core.GrantedAuthority;
4 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
5 | import org.springframework.security.core.userdetails.UserDetails;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Collection;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by wangl on 2017/2/10.
13 | * 继承自User,包装了角色信息的User扩展类
14 | * 实现自spring-security提供的UserDetails,并实现接口
15 | * 用于映射一个用户的多权限查询结果集
16 | */
17 | public class CustomUserDetails extends User implements UserDetails {
18 | private List roles;
19 |
20 | public List getRoles() {
21 | return roles;
22 | }
23 |
24 | public void setRoles(List roles) {
25 | this.roles = roles;
26 | }
27 |
28 | @Override
29 | public Collection extends GrantedAuthority> getAuthorities() {
30 | //定义权限集合
31 | List authorities = new ArrayList<>();
32 | //当前用户的角色信息集合
33 | List roles = this.getRoles();
34 | //添加角色信息到权限集合
35 | for (Role role : roles) {
36 | authorities.add(new SimpleGrantedAuthority(role.getType()));
37 | }
38 | return authorities;
39 | }
40 |
41 | @Override
42 | public boolean isAccountNonExpired() {
43 | return true;
44 | }
45 |
46 | @Override
47 | public boolean isAccountNonLocked() {
48 | return true;
49 | }
50 |
51 | @Override
52 | public boolean isCredentialsNonExpired() {
53 | return true;
54 | }
55 |
56 | @Override
57 | public boolean isEnabled() {
58 | return true;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/HomeActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | /**
4 | * Created by wangl on 2017/2/18.
5 | * 首页展示的活动列表对应的实体类
6 | * 包含了id,距离(km),区,已经招募人数,总人数,图片的地址,活动名字
7 | */
8 | public class HomeActivity {
9 | private Integer id;
10 |
11 | private double distance;
12 |
13 | private String district;
14 |
15 | private Integer recruitedPersonNumber;
16 |
17 | private Integer recruitPersonNumber;
18 |
19 | private String picture;
20 |
21 | private String name;
22 |
23 | public Integer getId() {
24 | return id;
25 | }
26 |
27 | public void setId(Integer id) {
28 | this.id = id;
29 | }
30 |
31 | public double getDistance() {
32 | return distance;
33 | }
34 |
35 | public void setDistance(double distance) {
36 | this.distance = distance;
37 | }
38 |
39 | public String getDistrict() {
40 | return district;
41 | }
42 |
43 | public void setDistrict(String district) {
44 | this.district = district;
45 | }
46 |
47 | public Integer getRecruitedPersonNumber() {
48 | return recruitedPersonNumber;
49 | }
50 |
51 | public void setRecruitedPersonNumber(Integer recruitedPersonNumber) {
52 | this.recruitedPersonNumber = recruitedPersonNumber;
53 | }
54 |
55 | public Integer getRecruitPersonNumber() {
56 | return recruitPersonNumber;
57 | }
58 |
59 | public void setRecruitPersonNumber(Integer recruitPersonNumber) {
60 | this.recruitPersonNumber = recruitPersonNumber;
61 | }
62 |
63 | public String getPicture() {
64 | return picture;
65 | }
66 |
67 | public void setPicture(String picture) {
68 | this.picture = picture;
69 | }
70 |
71 | public String getName() {
72 | return name;
73 | }
74 |
75 | public void setName(String name) {
76 | this.name = name;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/OrganizationInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | import java.util.Date;
4 |
5 | public class OrganizationInfo extends User{
6 | private Integer id;
7 |
8 | private String name;
9 |
10 | private String addressProvince;
11 |
12 | private String addressCity;
13 |
14 | private String addressDistrict;
15 |
16 | private String addressStreet;
17 |
18 | private String address;
19 |
20 | private String zipCode;
21 |
22 | private Date foundingDate;
23 |
24 | private Integer volunteerNumber;
25 |
26 | private String principalName;
27 |
28 | private String principalTelephone;
29 |
30 | private Integer principalTelephonePublic;
31 |
32 | private String avatar;
33 |
34 | public Integer getId() {
35 | return id;
36 | }
37 |
38 | public void setId(Integer id) {
39 | this.id = id;
40 | }
41 |
42 | public String getName() {
43 | return name;
44 | }
45 |
46 | public void setName(String name) {
47 | this.name = name;
48 | }
49 |
50 | public String getAddressProvince() {
51 | return addressProvince;
52 | }
53 |
54 | public void setAddressProvince(String addressProvince) {
55 | this.addressProvince = addressProvince;
56 | }
57 |
58 | public String getAddressCity() {
59 | return addressCity;
60 | }
61 |
62 | public void setAddressCity(String addressCity) {
63 | this.addressCity = addressCity;
64 | }
65 |
66 | public String getAddressDistrict() {
67 | return addressDistrict;
68 | }
69 |
70 | public void setAddressDistrict(String addressDistrict) {
71 | this.addressDistrict = addressDistrict;
72 | }
73 |
74 | public String getAddressStreet() {
75 | return addressStreet;
76 | }
77 |
78 | public void setAddressStreet(String addressStreet) {
79 | this.addressStreet = addressStreet;
80 | }
81 |
82 | public String getAddress() {
83 | return address;
84 | }
85 |
86 | public void setAddress(String address) {
87 | this.address = address;
88 | }
89 |
90 | public String getZipCode() {
91 | return zipCode;
92 | }
93 |
94 | public void setZipCode(String zipCode) {
95 | this.zipCode = zipCode;
96 | }
97 |
98 | public Date getFoundingDate() {
99 | return foundingDate;
100 | }
101 |
102 | public void setFoundingDate(Date foundingDate) {
103 | this.foundingDate = foundingDate;
104 | }
105 |
106 | public Integer getVolunteerNumber() {
107 | return volunteerNumber;
108 | }
109 |
110 | public void setVolunteerNumber(Integer volunteerNumber) {
111 | this.volunteerNumber = volunteerNumber;
112 | }
113 |
114 | public String getPrincipalName() {
115 | return principalName;
116 | }
117 |
118 | public void setPrincipalName(String principalName) {
119 | this.principalName = principalName;
120 | }
121 |
122 | public String getPrincipalTelephone() {
123 | return principalTelephone;
124 | }
125 |
126 | public void setPrincipalTelephone(String principalTelephone) {
127 | this.principalTelephone = principalTelephone;
128 | }
129 |
130 | public Integer getPrincipalTelephonePublic() {
131 | return principalTelephonePublic;
132 | }
133 |
134 | public void setPrincipalTelephonePublic(Integer principalTelephonePublic) {
135 | this.principalTelephonePublic = principalTelephonePublic;
136 | }
137 |
138 | public String getAvatar() {
139 | return avatar;
140 | }
141 |
142 | public void setAvatar(String avatar) {
143 | this.avatar = avatar;
144 | }
145 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/Role.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | public class Role {
4 | private Integer id;
5 |
6 | private String name;
7 |
8 | private String type;
9 |
10 |
11 | public Integer getId() {
12 | return id;
13 | }
14 |
15 | public void setId(Integer id) {
16 | this.id = id;
17 | }
18 |
19 | public String getName() {
20 | return name;
21 | }
22 |
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 |
27 | public String getType() {
28 | return type;
29 | }
30 |
31 | public void setType(String type) {
32 | this.type = type;
33 | }
34 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/User.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | import com.fasterxml.jackson.annotation.JsonInclude;
4 |
5 | @JsonInclude(JsonInclude.Include.NON_NULL)
6 | public class User {
7 | private Integer id;
8 |
9 | private String username;
10 |
11 | private String password;
12 |
13 | private String email;
14 |
15 | //头像
16 | private String avatar;
17 |
18 | //姓名,类似于昵称,但此项目中较为正式
19 | private String name;
20 |
21 | public Integer getId() {
22 | return id;
23 | }
24 |
25 | public void setId(Integer id) {
26 | this.id = id;
27 | }
28 |
29 | public String getUsername() {
30 | return username;
31 | }
32 |
33 | public void setUsername(String username) {
34 | this.username = username;
35 | }
36 |
37 | public String getPassword() {
38 | return password;
39 | }
40 |
41 | public void setPassword(String password) {
42 | this.password = password;
43 | }
44 |
45 | public String getEmail() {
46 | return email;
47 | }
48 |
49 | public void setEmail(String email) {
50 | this.email = email;
51 | }
52 |
53 | public String getAvatar() {
54 | return avatar;
55 | }
56 |
57 | public void setAvatar(String avatar) {
58 | this.avatar = avatar;
59 | }
60 |
61 | public String getName() {
62 | return name;
63 | }
64 |
65 | public void setName(String name) {
66 | this.name = name;
67 | }
68 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/VolunteerDetails.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * Created by wangl on 2017/2/25.
8 | * Volunteer包装类,继承自VolunteerInfo,包装了志愿者的证书状态id
9 | * 用于志愿组织 面试管理 和 证书审核管理 中志愿者列表显示
10 | */
11 | @Getter
12 | @Setter
13 | public class VolunteerDetails extends VolunteerInfo{
14 | //下面的字段用于志愿组织面试管理时使用
15 | //1. 该字段用于志愿组织查询该组织志愿者时显示志愿者的证书状态id
16 | private Integer certificateStatusId;
17 |
18 | //下面的字段用于志愿组织面试管理时使用
19 | //1. 该字段用于志愿组织面试管理时显示志愿者的面试状态id
20 | private Integer interviewStatus;
21 |
22 | //2. 该字段用于志愿组织面试管理时显示志愿者报名的活动名称
23 | private String activityName;
24 |
25 | //3. 志愿者报名活动对应的活动报名表id,用于后续交互修改面试状态
26 | private Integer activityUserId;
27 |
28 | //4. 志愿者报名的活动id,用于后续交互进入活动交流群组
29 | private Integer activityId;
30 |
31 | //5. 志愿者报名的活动群组id,用于后续交互进入活动交流群组
32 | private String groupId;
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/VolunteerInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain;
2 |
3 | import java.util.Date;
4 |
5 | public class VolunteerInfo extends User {
6 | private Integer id;
7 |
8 | private String name;
9 |
10 | private String idCard;
11 |
12 | private Integer sex;
13 |
14 | private Integer age;
15 |
16 | private Date birthday;
17 |
18 | private String politicalStatus;
19 |
20 | private String address;
21 |
22 | private String addressProvince;
23 |
24 | private String addressCity;
25 |
26 | private Double workingHours;
27 |
28 | private String avatar;
29 |
30 | public Integer getId() {
31 | return id;
32 | }
33 |
34 | public void setId(Integer id) {
35 | this.id = id;
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | public void setName(String name) {
43 | this.name = name;
44 | }
45 |
46 | public String getIdCard() {
47 | return idCard;
48 | }
49 |
50 | public void setIdCard(String idCard) {
51 | this.idCard = idCard;
52 | }
53 |
54 | public Integer getSex() {
55 | return sex;
56 | }
57 |
58 | public void setSex(Integer sex) {
59 | this.sex = sex;
60 | }
61 |
62 | public Integer getAge() {
63 | return age;
64 | }
65 |
66 | public void setAge(Integer age) {
67 | this.age = age;
68 | }
69 |
70 | public Date getBirthday() {
71 | return birthday;
72 | }
73 |
74 | public void setBirthday(Date birthday) {
75 | this.birthday = birthday;
76 | }
77 |
78 | public String getPoliticalStatus() {
79 | return politicalStatus;
80 | }
81 |
82 | public void setPoliticalStatus(String politicalStatus) {
83 | this.politicalStatus = politicalStatus;
84 | }
85 |
86 | public String getAddress() {
87 | return address;
88 | }
89 |
90 | public void setAddress(String address) {
91 | this.address = address;
92 | }
93 |
94 | public String getAddressProvince() {
95 | return addressProvince;
96 | }
97 |
98 | public void setAddressProvince(String addressProvince) {
99 | this.addressProvince = addressProvince;
100 | }
101 |
102 | public String getAddressCity() {
103 | return addressCity;
104 | }
105 |
106 | public void setAddressCity(String addressCity) {
107 | this.addressCity = addressCity;
108 | }
109 |
110 | public Double getWorkingHours() {
111 | return workingHours;
112 | }
113 |
114 | public void setWorkingHours(Double workingHours) {
115 | this.workingHours = workingHours;
116 | }
117 |
118 | public String getAvatar() {
119 | return avatar;
120 | }
121 |
122 | public void setAvatar(String avatar) {
123 | this.avatar = avatar;
124 | }
125 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/moment/Moment.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain.moment;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.User;
4 | import lombok.Data;
5 |
6 | import java.util.Date;
7 |
8 | /**
9 | * 圈子动态实体,翻译参考自微信
10 | */
11 | @Data
12 | public class Moment {
13 | private Integer id;
14 |
15 | //动态发布者id
16 | private Integer userId;
17 |
18 | //动态发布者详情,包括发布者姓名、头像
19 | private User author;
20 |
21 | //动态文字内容
22 | private String content;
23 |
24 | //动态图片地址,这里可能是多张图,用英文分号隔开
25 | private String images;
26 |
27 | //动态发布时间
28 | private Date time;
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/domain/moment/MomentComment.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.domain.moment;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.User;
4 | import lombok.Data;
5 | import lombok.ToString;
6 |
7 | import java.util.Date;
8 |
9 | @Data
10 | @ToString
11 | public class MomentComment {
12 | private Integer id;
13 |
14 | //评论的动态id
15 | private Integer momentId;
16 |
17 | //评论发布者id
18 | private Integer userId;
19 |
20 | //评论发布者,包括发布者姓名、头像
21 | private User user;
22 |
23 | //评论内容
24 | private String content;
25 |
26 | //评论时间
27 | private Date time;
28 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/ActivityMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.Activity;
4 | import com.github.oneone1995.mvolunteer.domain.ActivityDetails;
5 | import com.github.oneone1995.mvolunteer.domain.HomeActivity;
6 | import org.apache.ibatis.annotations.Mapper;
7 | import org.apache.ibatis.annotations.Param;
8 |
9 | import java.util.List;
10 | import java.util.Set;
11 |
12 | /**
13 | * Created by wangl on 2017/2/19.
14 | */
15 | @Mapper
16 | public interface ActivityMapper {
17 |
18 | /**
19 | * 根据活动id查出所有活动信息
20 | * @param id 活动id
21 | * @return 对应活动的全部信息
22 | */
23 | Activity selectAllInfoByPrimaryKey(@Param("id") Integer id);
24 |
25 | /**
26 | * 根据活动id更新
27 | * @param record Activity实体
28 | * @return 更新记录
29 | */
30 | int updateByPrimaryKey(Activity record);
31 |
32 | /**
33 | * 根据活动添加时间排序查询活动列表返回
34 | * 并根据参数中的经纬度求出距离并将其包装进HomeActivity中的mapper接口
35 | * @param coordLong 经度
36 | * @param coordLat 维度
37 | * @return 首页展示的活动列表
38 | */
39 | List selectAllOderByTime(
40 | @Param("coordLong") double coordLong, @Param("coordLat") double coordLat);
41 |
42 | List selectByActivityName(
43 | @Param("coordLong") double coordLong, @Param("coordLat") double coordLat,
44 | @Param("activityName") String activityName
45 | );
46 |
47 | List selectByCategory(
48 | @Param("coordLong") double coordLong, @Param("coordLat") double coordLat,
49 | @Param("category") String category, @Param("collation") Integer collation,
50 | @Param("district") String district, @Param("geohash") String geohash);
51 |
52 | /**
53 | * 根据活动id和经纬度返回活动详情的mapper接口
54 | * @param id 活动id
55 | * @param coordLong 经度
56 | * @param coordLat 纬度
57 | * @return 活动详情
58 | */
59 | ActivityDetails selectByPrimaryKey(
60 | @Param("id") Integer id,
61 | @Param("coordLong") double coordLong,
62 | @Param("coordLat") double coordLat);
63 |
64 | /**
65 | *
66 | * @param code 活动代码
67 | * @param id 用户id
68 | * @return 根据活动code和用户id返回该记录在活动用户关系表中的主键id
69 | */
70 | Integer selectByCode(
71 | @Param("code") Integer code, @Param("id") Integer id);
72 |
73 | /**
74 | * 根据活动用户关系表主键更新签到状态
75 | * @param id 用户id
76 | * @return 更新记录
77 | */
78 | Integer updateSignStatusByPrimaryKey(
79 | @Param("id") Integer id
80 | );
81 |
82 | /**
83 | * 根据活动实体插入活动
84 | * @param activity 活动实体
85 | * @return 更新记录数
86 | */
87 | Integer insertActivity(Activity activity);
88 |
89 | /**
90 | * 查询所有活动代码
91 | * @return 所有活动代码的集合
92 | */
93 | Set selectAllCode();
94 |
95 | /**
96 | * 根据志愿者id查询其参加的未结束的活动
97 | * @param id 志愿者id
98 | * @return 当前登录用户其参加的未结束的活动列表
99 | */
100 | List selectByVolunteerId(@Param("id") Integer id);
101 |
102 | /**
103 | * 根据志愿者id查询他的服务历史
104 | * @param id 志愿者id
105 | * @return 当前登录用户的已完成活动,即服务历史
106 | */
107 | List selectHistoryByVolunteerId(@Param("id") Integer id);
108 |
109 | /**
110 | * 根据组织id查询该组织的所有活动
111 | * @param id 组织id
112 | * @return 当前登录的组织账号的活动列表
113 | */
114 | List selectByOrganizationId(@Param("id") Integer id);
115 |
116 | /**
117 | * 根据活动id和群号更新指定活动的群号
118 | * @param tribeId 群号
119 | * @param activityId 活动id
120 | * @return
121 | */
122 | Integer updateActivityTribeId(
123 | @Param("tribeId") String tribeId,
124 | @Param("activityId") Integer activityId);
125 |
126 | /**
127 | * 查询活动的群组群号
128 | * @param activityId 活动id
129 | * @return 群号
130 | */
131 | Integer selectTribeId(
132 | @Param("activityId") Integer activityId);
133 |
134 | /**
135 | * 根据群组id查找活动图片
136 | * @param tribeId 群组id
137 | * @return 活动图片
138 | */
139 | String selectActivityPictureByTribeId(
140 | @Param("tribeId") String tribeId);
141 | }
142 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/ActivityStatusMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.ActivityStatus;
4 | import org.apache.ibatis.annotations.Mapper;
5 |
6 | import java.util.List;
7 |
8 | @Mapper
9 | public interface ActivityStatusMapper {
10 | int deleteByPrimaryKey(Integer id);
11 |
12 | int insert(ActivityStatus record);
13 |
14 | ActivityStatus selectByPrimaryKey(Integer id);
15 |
16 | List selectAll();
17 |
18 | int updateByPrimaryKey(ActivityStatus record);
19 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/ActivityUserMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.ActivityUser;
4 | import com.github.oneone1995.mvolunteer.domain.VolunteerDetails;
5 | import org.apache.ibatis.annotations.Mapper;
6 | import org.apache.ibatis.annotations.Param;
7 |
8 | import java.util.List;
9 |
10 | @Mapper
11 | public interface ActivityUserMapper {
12 | int deleteByPrimaryKey(Integer id);
13 |
14 | int insert(ActivityUser record);
15 |
16 | ActivityUser selectByPrimaryKey(Integer id);
17 |
18 | List selectAll();
19 |
20 | int updateByPrimaryKey(
21 | @Param("activityUserStatusId") Integer activityUserStatusId,
22 | @Param("id") Integer id);
23 |
24 | /**
25 | * 根据用户id和活动id查询出关系表中符合条件的记录的id
26 | * @param activityId 活动id
27 | * @param userId 用户id
28 | * @return 活动用户关系表的主键id
29 | */
30 | Integer selectPrimaryKeyByUserIdAndActivityId(
31 | @Param("activityId") Integer activityId,
32 | @Param("userId") Integer userId
33 | );
34 |
35 | /**
36 | * 根据活动id和报名此次活动的用户的签到状态查询关系表记录
37 | * @param id 活动id
38 | * @return 参加该活动的用户id列表
39 | */
40 | List selectAllByActivityId(
41 | @Param("activityId") Integer id);
42 |
43 | /**
44 | * 查询面试列表
45 | * @param orgId 组织id
46 | * @return 需要面试的志愿者列表
47 | */
48 | List selectInterviewList(
49 | @Param("orgId") Integer orgId);
50 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/CertificateMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.Certificate;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import java.util.List;
8 |
9 | @Mapper
10 | public interface CertificateMapper {
11 | int deleteByPrimaryKey(Integer id);
12 |
13 | int insert(Certificate record);
14 |
15 | Certificate selectByPrimaryKey(Integer id);
16 |
17 | List selectAll();
18 |
19 | int updateByPrimaryKey(Certificate record);
20 |
21 | /**
22 | * 根据志愿者id更新证书状态
23 | * @param volunteerId 志愿者id
24 | * @return 更新记录数
25 | */
26 | Integer updateByVolunteerId(
27 | @Param("volunteerId") Integer volunteerId);
28 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/MomentCommentMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.moment.MomentComment;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import java.util.List;
8 |
9 | @Mapper
10 | public interface MomentCommentMapper {
11 | MomentComment selectByPrimaryKey(Integer id);
12 |
13 | int insert(MomentComment record);
14 |
15 | List selectByMomentId(@Param("momentId") Integer momentId);
16 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/MomentMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.moment.Moment;
4 | import org.apache.ibatis.annotations.Mapper;
5 |
6 | import java.util.List;
7 |
8 | @Mapper
9 | public interface MomentMapper {
10 |
11 | /**
12 | * 根据圈子动态实体插入圈子动态
13 | * @param moment 圈子动态实体
14 | * @return 更新记录数
15 | */
16 | int insert(Moment moment);
17 |
18 | /**
19 | * 查询圈子动态列表,其中关联查询出圈子动态发布者的相关信息
20 | * @return 圈子动态列表
21 | */
22 | List selectAll();
23 |
24 | Moment selectByPrimaryKey(Integer id);
25 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/OrganizationInfoMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.OrganizationInfo;
4 | import org.apache.ibatis.annotations.Mapper;
5 |
6 | import java.util.List;
7 |
8 | @Mapper
9 | public interface OrganizationInfoMapper {
10 | int deleteByPrimaryKey(Integer id);
11 |
12 | int insert(OrganizationInfo record);
13 |
14 | OrganizationInfo selectByPrimaryKey(Integer id);
15 |
16 | List selectAll();
17 |
18 | int updateByPrimaryKey(OrganizationInfo record);
19 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/RoleMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.Role;
4 | import org.apache.ibatis.annotations.Mapper;
5 |
6 | import java.util.List;
7 |
8 | @Mapper
9 | public interface RoleMapper {
10 | int deleteByPrimaryKey(Integer id);
11 |
12 | int insert(Role record);
13 |
14 | Role selectByPrimaryKey(Integer id);
15 |
16 | List selectAll();
17 |
18 | int updateByPrimaryKey(Role record);
19 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.CustomUserDetails;
4 | import com.github.oneone1995.mvolunteer.domain.User;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | import java.util.List;
8 |
9 | @Mapper
10 | public interface UserMapper {
11 | int deleteByPrimaryKey(Integer id);
12 |
13 | int insert(User record);
14 |
15 | User selectByPrimaryKey(Integer id);
16 |
17 | List selectAll();
18 |
19 | int updateByPrimaryKey(User record);
20 |
21 | CustomUserDetails selectCustomUserDetailsByUsername(String username);
22 |
23 | /**
24 | * 根据username查找用户返回
25 | * @param username 查找参数username
26 | * @return 找到的用户
27 | */
28 | User selectByUsername(String username);
29 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/mapper/VolunteerInfoMapper.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.mapper;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.VolunteerDetails;
4 | import com.github.oneone1995.mvolunteer.domain.VolunteerInfo;
5 | import org.apache.ibatis.annotations.Mapper;
6 | import org.apache.ibatis.annotations.Param;
7 |
8 | import java.util.List;
9 |
10 | @Mapper
11 | public interface VolunteerInfoMapper {
12 | int deleteByPrimaryKey(Integer id);
13 |
14 | int insert(VolunteerInfo record);
15 |
16 | VolunteerInfo selectByPrimaryKey(Integer id);
17 |
18 | List selectAll();
19 |
20 | int updateByPrimaryKey(VolunteerInfo record);
21 |
22 |
23 | /**
24 | * 根据用户id数组和活动工时更新用户工时
25 | * @param userIds 用户id
26 | * @param workingHours 工时
27 | * @return 更新记录数
28 | */
29 | int updateWorkingHoursByIdAndWorkingHours(
30 | @Param("userIds") List userIds,
31 | @Param("workingHours") double workingHours);
32 |
33 | /**
34 | * 根据组织id查询该组织的志愿者
35 | * @param organizationId 组织id
36 | * @return 包含了证书状态的志愿者列表
37 | */
38 | List selectByOrganizationId(
39 | @Param("organizationId") Integer organizationId);
40 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/model/EasemobIMChatGroupModel.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.model;
2 |
3 |
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 |
8 | import java.io.Serializable;
9 |
10 | /**
11 | * 环信群组API交互model
12 | * 这里只做用于创建群组时与环信服务交互的model,原因如下:
13 | * 这部分环信文档中创建群组和获取群详情中的字段定义不一致,因此暂时不再花时间研究Jackson序列化时有没有好的办法处理
14 | * 另外文档中创建群组有一个member字段,因为为可选参数且实际业务中在创建群组时也不会用,因此到此处也不再使用。好吧是我太懒了...
15 | *
16 | * @see
17 | *
18 | * 参见群组数据结构[环信开发文档]
19 | */
20 | @Data
21 | @AllArgsConstructor
22 | public class EasemobIMChatGroupModel implements Serializable {
23 | private static final long serialVersionUID = -2029531914696293176L;
24 |
25 | //群组ID
26 | @JsonProperty(value = "groupid")
27 | private String groupId;
28 |
29 | //群组名称,此属性为必须的
30 | @JsonProperty(value = "groupname")
31 | private String groupName;
32 |
33 | //群组描述,此属性为必须的
34 | @JsonProperty(value = "desc")
35 | private String description;
36 |
37 | //群组类型:true:公开群,false:私有群。此属性为必须的
38 | @JsonProperty(value = "public")
39 | private boolean isPublic;
40 |
41 | //加入群组是否需要群主或者群管理员审批。true:是,false:否。默认是false
42 | @JsonProperty(value = "members_only", defaultValue = "false")
43 | private boolean membersOnly;
44 |
45 | //是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主才可以往群里加人。
46 | @JsonProperty(value = "allowinvites")
47 | private boolean allowInvites;
48 |
49 | //群组成员最大数(包括群主),值为数值类型,默认值200,最大值2000,此属性为可选的
50 | @JsonProperty(value = "maxusers", defaultValue = "200")
51 | private Integer maxUsers;
52 |
53 | //群组管理员。环信id,此项目中等同于app原有体系的username
54 | private String owner;
55 |
56 | /*
57 | * 参考环信创建群组的API,构造下面的json测试可以成功序列化
58 | {
59 | "groupname":"为老人开展志愿服务交流群",
60 | "desc":"3月5日,西湖区紫荆花路9号紫庭南弄紫金庭园芦荻苑9幢3号商铺,为老人开展志愿服务",
61 | "public":true,
62 | "maxusers":50,
63 | "members_only":false,
64 | "allowinvites": false,
65 | "owner":"xushaohui"
66 | }
67 | 使用new ObjectMapper().readValue()方法
68 | EasemobIMChatGroupModel(
69 | groupId=null, groupName=为老人开展志愿服务交流群,
70 | description=3月5日,西湖区紫荆花路9号紫庭南弄紫金庭园芦荻苑9幢3号商铺,为老人开展志愿服务,
71 | isPublic=true, membersOnly=false, allowInvites=false, maxUsers=50, owner=xushaohui)
72 | * */
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/model/EasemobIMChatMessage.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.ToString;
7 |
8 | /**
9 | * 环信服务端发送消息的实体
10 | * 通过服务端创建的群组不会出现在APP群组界面,因此需要服务端在创建群组和有人加群之后主动发送一条消息
11 | * @see
12 | * 发送消息[环信开发文档]
13 | * @see com.github.oneone1995.mvolunteer.service.EasemobIMService
14 | */
15 | @Data
16 | @AllArgsConstructor
17 | @ToString
18 | public class EasemobIMChatMessage {
19 |
20 | // users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
21 | @JsonProperty("target_type")
22 | private String targetType;
23 |
24 | // 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,
25 | // 也要用数组 ['u1'],给用户发送时数组元素是用户名,给群组发送时
26 | // 数组元素是groupid
27 | private String[] target;
28 |
29 | @JsonProperty("msg")
30 | private Message message;
31 |
32 | //消息发送者
33 | private String from;
34 |
35 | @Data
36 | @ToString
37 | @AllArgsConstructor
38 | public static class Message {
39 | //消息类型,文本消息为text
40 | private String type;
41 | //消息内容
42 | @JsonProperty("msg")
43 | private String content;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/model/IMTribeModel.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.model;
2 |
3 | /**
4 | * Created by wangl on 2017/2/26.
5 | * 群组创建对应的model
6 | * @deprecated 改用环信即时通讯云
7 | * @see com.github.oneone1995.mvolunteer.model.EasemobIMChatGroupModel
8 | */
9 | @Deprecated
10 | public class IMTribeModel {
11 |
12 | /**
13 | * openim_tribe_create_response : {"tribe_info":{"check_mode":0,"name":"环保助力中国梦","notice":"欢迎加入环保助力中国梦志愿活动","recv_flag":0,"tribe_id":2084012145,"tribe_type":0},"request_id":"10ewv3wiibkwv"}
14 | */
15 |
16 | private OpenimTribeCreateResponseBean openim_tribe_create_response;
17 |
18 | public OpenimTribeCreateResponseBean getOpenim_tribe_create_response() {
19 | return openim_tribe_create_response;
20 | }
21 |
22 | public void setOpenim_tribe_create_response(OpenimTribeCreateResponseBean openim_tribe_create_response) {
23 | this.openim_tribe_create_response = openim_tribe_create_response;
24 | }
25 |
26 | public static class OpenimTribeCreateResponseBean {
27 | /**
28 | * tribe_info : {"check_mode":0,"name":"环保助力中国梦","notice":"欢迎加入环保助力中国梦志愿活动","recv_flag":0,"tribe_id":2084012145,"tribe_type":0}
29 | * request_id : 10ewv3wiibkwv
30 | */
31 |
32 | private TribeInfoBean tribe_info;
33 | private String request_id;
34 |
35 | public TribeInfoBean getTribe_info() {
36 | return tribe_info;
37 | }
38 |
39 | public void setTribe_info(TribeInfoBean tribe_info) {
40 | this.tribe_info = tribe_info;
41 | }
42 |
43 | public String getRequest_id() {
44 | return request_id;
45 | }
46 |
47 | public void setRequest_id(String request_id) {
48 | this.request_id = request_id;
49 | }
50 |
51 | public static class TribeInfoBean {
52 | /**
53 | * check_mode : 0
54 | * name : 环保助力中国梦
55 | * notice : 欢迎加入环保助力中国梦志愿活动
56 | * recv_flag : 0
57 | * tribe_id : 2084012145
58 | * tribe_type : 0
59 | */
60 |
61 | private int check_mode;
62 | private String name;
63 | private String notice;
64 | private int recv_flag;
65 | private int tribe_id;
66 | private int tribe_type;
67 |
68 | public int getCheck_mode() {
69 | return check_mode;
70 | }
71 |
72 | public void setCheck_mode(int check_mode) {
73 | this.check_mode = check_mode;
74 | }
75 |
76 | public String getName() {
77 | return name;
78 | }
79 |
80 | public void setName(String name) {
81 | this.name = name;
82 | }
83 |
84 | public String getNotice() {
85 | return notice;
86 | }
87 |
88 | public void setNotice(String notice) {
89 | this.notice = notice;
90 | }
91 |
92 | public int getRecv_flag() {
93 | return recv_flag;
94 | }
95 |
96 | public void setRecv_flag(int recv_flag) {
97 | this.recv_flag = recv_flag;
98 | }
99 |
100 | public int getTribe_id() {
101 | return tribe_id;
102 | }
103 |
104 | public void setTribe_id(int tribe_id) {
105 | this.tribe_id = tribe_id;
106 | }
107 |
108 | public int getTribe_type() {
109 | return tribe_type;
110 | }
111 |
112 | public void setTribe_type(int tribe_type) {
113 | this.tribe_type = tribe_type;
114 | }
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/model/ResultModel.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.model;
2 |
3 | import com.github.oneone1995.mvolunteer.config.result.ResultStatus;
4 |
5 | /**
6 | * Created by wangl on 2017/2/7.
7 | * 自定义的返回结果实体model
8 | */
9 | public class ResultModel {
10 | /**
11 | * 返回码
12 | */
13 | private int code;
14 |
15 | /**
16 | * 返回信息描述
17 | */
18 | private String message;
19 |
20 | /**
21 | * 返回数据
22 | */
23 | private Object data;
24 |
25 | public int getCode() {
26 | return code;
27 | }
28 |
29 | public void setCode(int code) {
30 | this.code = code;
31 | }
32 |
33 | public String getMessage() {
34 | return message;
35 | }
36 |
37 | public void setMessage(String message) {
38 | this.message = message;
39 | }
40 |
41 | public Object getData() {
42 | return data;
43 | }
44 |
45 | public void setData(Object data) {
46 | this.data = data;
47 | }
48 |
49 | //提供几种构造方法
50 | public ResultModel(int code, String message, Object data) {
51 | this.code = code;
52 | this.message = message;
53 | this.data = data;
54 | }
55 |
56 | public ResultModel(ResultStatus resultStatus) {
57 | this.code = resultStatus.getCode();
58 | this.message = resultStatus.getMessage();
59 | this.data = "";
60 | }
61 |
62 | public ResultModel(ResultStatus resultStatus, Object data) {
63 | this.code = resultStatus.getCode();
64 | this.message = resultStatus.getMessage();
65 | this.data = data;
66 | }
67 |
68 | //请求成功的方法
69 |
70 | /**
71 | * 有数据返回时的请求成功方法
72 | * @param data 请求成功的数据
73 | * @return 自定义的ResultModel
74 | */
75 | public static ResultModel ok(Object data) {
76 | return new ResultModel(ResultStatus.SUCCESS, data);
77 | }
78 |
79 | /**
80 | * 无数据返回时的请求成功方法
81 | * @return 自定义的ResultModel
82 | */
83 | public static ResultModel ok() {
84 | return new ResultModel(ResultStatus.SUCCESS);
85 | }
86 |
87 | //请求失败的方法
88 |
89 | /**
90 | * 请求失败时
91 | * @param error 错误状态
92 | * @return 自定义的ResultModel
93 | */
94 | public static ResultModel error(ResultStatus error) {
95 | return new ResultModel(error);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/ActivityService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.Activity;
4 | import com.github.oneone1995.mvolunteer.domain.ActivityDetails;
5 | import com.github.oneone1995.mvolunteer.domain.HomeActivity;
6 | import com.github.pagehelper.PageInfo;
7 |
8 | /**
9 | * Created by wangl on 2017/2/18.
10 | */
11 | public interface ActivityService {
12 | //分页展示首页的活动列表的接口
13 | PageInfo getHomeActivityPageInfo(
14 | Integer page, Integer rows, double coordLong, double coordLat);
15 |
16 | //搜索活动列表
17 | //分页返回搜索结果
18 | PageInfo getHomeActivityPageInfo(
19 | Integer page, Integer rows, double coordLong, double coordLat,
20 | String activityName);
21 |
22 | //根据活动类别返回对应活动列表
23 | //分页返回结果
24 | PageInfo getHomeActivityPageInfo(
25 | Integer page, Integer rows, double coordLong, double coordLat,
26 | String category, Integer collation, String district);
27 |
28 | //根据活动id和经纬度返回包装有志愿者等信息的活动详情
29 | ActivityDetails getActivityById(
30 | Integer id, double coordLong, double coordLat);
31 |
32 | //创建活动
33 | boolean createActivity(Activity activity);
34 |
35 | //根据志愿者id返回该志愿者参与的活动列表
36 | PageInfo getActivityPageInfoByVolunteerId(
37 | Integer page, Integer rows, Integer id);
38 |
39 | //根据志愿者id返回该志愿者的服务历史
40 | PageInfo getHistoricalActivityPageInfo(
41 | Integer page, Integer rows, Integer id);
42 |
43 | //根据组织id返回该组织的所有活动
44 | PageInfo getActivityPageInfoByOrganizationId(
45 | Integer page, Integer rows, Integer id);
46 |
47 | //根据活动id和状态id更新活动
48 | String updateActivityStatusById(
49 | Integer id, Integer activityStatusId);
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/ActivityStatusService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.ActivityStatus;
4 |
5 | /**
6 | * Created by wangl on 2017/2/22.
7 | */
8 | public interface ActivityStatusService {
9 | ActivityStatus getActivityStatusById(Integer id);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/ActivityUserService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.ActivityUser;
4 | import com.github.oneone1995.mvolunteer.domain.VolunteerDetails;
5 | import com.github.pagehelper.PageInfo;
6 |
7 | /**
8 | * Created by wangl on 2017/2/23.
9 | * 志愿者活动报名、取消报名,志愿组织面试管理相关业务处理接口
10 | */
11 | public interface ActivityUserService {
12 | /**
13 | * 报名活动
14 | * @param activityUser 活动用户表对应的实体{@link com.github.oneone1995.mvolunteer.domain.ActivityUser}
15 | * @return 报名成功与否的标志
16 | */
17 | boolean signUpActivity(ActivityUser activityUser);
18 |
19 | boolean cancelActivityByActivityId(Integer activityId);
20 |
21 | /**
22 | * 分页返回待面试的志愿者列表
23 | * 其中志愿者信息包括了志愿者的面试状态id、活动报名表中的对应的记录id、所报名的活动id、活动名、活动群组id、志愿者姓名、志愿者头像
24 | * @see com.github.oneone1995.mvolunteer.domain.VolunteerDetails
25 | * @param page 页码
26 | * @param rows 每页的数量
27 | * @return 待面试的志愿者列表经PageInfo包装的结果
28 | */
29 | PageInfo getInterviewList(Integer page, Integer rows);
30 |
31 | /**
32 | * 修改面试状态
33 | * @param id 活动报名表id
34 | * @param volunteerName 修改的志愿者username
35 | * @param activityGroupId 活动群组id
36 | * @param activityUserStatusId 需要修改的面试状态
37 | * @return 修改面试状态是否成功的标志
38 | */
39 | boolean modifyInterviewStatus(Integer id, String volunteerName, String activityGroupId, Integer activityUserStatusId);
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/CacheService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | public interface CacheService {
4 | /**
5 | * 因为spring AOP导致类内部调用的问题,同一个类中的缓存方法无法调用,所以单独抽了一层接口,其实实际上还是调用的getEasemobToken()
6 | * 也可以将getEasemobToken()接口从EasemobIMService中去除单独放在一个新的类中,但为了保持功能类似的接口都在一个类中,还是采取了现在的做法
7 | * todo 会产生循环依赖,但单例的bean和属性注入不会抛出异常,网上有说使用@Postconstruct注解手动注入来解决循环依赖避免异常出现,现在还不会,以后可能会改
8 | * 参考: {@link EasemobIMService#getEasemobToken()}
9 | * @see spring缓存 同一个 类中调用 缓存无效
10 | * @see spring循环依赖
11 | * @return 环信token
12 | */
13 | String getEasemobToken();
14 |
15 | /**
16 | * 回收活动code随机码,将code码lpush到redis的list
17 | * @param code 活动结束后待回收的随机码
18 | */
19 | void putRandomActivityCode(String code);
20 |
21 | /**
22 | * 从redis中获取一个随机码,rpop形式
23 | * @return 用于活动随机码的code值
24 | */
25 | String getRandomActivityCode();
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/CertificateService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.Certificate;
4 |
5 | /**
6 | * Created by wangl on 2017/2/23.
7 | * 证书申请的业务接口
8 | */
9 | public interface CertificateService {
10 | //申请证书
11 | String applyForCertificate(Certificate certificate);
12 |
13 | //修改证书状态
14 | boolean modifyCertificateStatusByVolunteerId(Integer volunteerId);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/EasemobIMService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.model.EasemobIMChatGroupModel;
4 | import com.github.oneone1995.mvolunteer.model.EasemobIMChatMessage;
5 | import com.github.oneone1995.mvolunteer.service.api.EasemobApiService;
6 | import com.github.oneone1995.mvolunteer.web.exception.EasemobGroupCreateFailException;
7 | import com.github.oneone1995.mvolunteer.web.exception.PutUserToEasemobGroupFailException;
8 |
9 | import java.util.concurrent.Future;
10 |
11 | /**
12 | * 环信即时通讯交互的服务接口。
13 | * 基于下面两个业务需求,需要APP服务端集成环信群组相关接口来和APP业务绑定
14 | * 1. 志愿组织创建活动之后便创建群组
15 | * 2. 志愿者报名志愿活动并通过面试后加入对应的群组
16 | * @see EasemobIMChatGroupModel 与环信API交互实体
17 | * @see EasemobApiService 环信即时通讯云API交互Service
18 | */
19 | public interface EasemobIMService {
20 |
21 | /**
22 | * 创建群组
23 | * @param chatGroupModel 与环信API交互实体
24 | * @exception EasemobGroupCreateFailException 环信群组创建失败异常
25 | * @return 群组创建成功的群号
26 | */
27 | String createGroup(EasemobIMChatGroupModel chatGroupModel) throws EasemobGroupCreateFailException;
28 |
29 | /**
30 | * 将用户添加至环信群组
31 | * @param groupId 环信IM群组id
32 | * @param username 需要添加的用户username
33 | * @return 添加成功与否的标志
34 | * @throws PutUserToEasemobGroupFailException 添加用户至环信IM聊天群异常
35 | */
36 | boolean putUser2Group(String groupId, String username) throws PutUserToEasemobGroupFailException;
37 |
38 | /**
39 | * 获取环信token
40 | * @see com.github.oneone1995.mvolunteer.config.easemob.EasemobIMProperties
41 | * @return 环信token
42 | */
43 | String getEasemobToken();
44 |
45 | /**
46 | * 异步发送群消息,无返回值
47 | * @param groupMessage 环信群消息实体 {@link com.github.oneone1995.mvolunteer.model.EasemobIMChatMessage}
48 | */
49 | void sendEasemobGroupMessage(EasemobIMChatMessage groupMessage);
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/IMGroupService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | /**
4 | * 即时通讯群组相关业务顶级接口,具体实现取决于你使用的第三方sdk
5 | * todo 本项目暂时没有使用这个接口,以后可能会使用
6 | */
7 | public interface IMGroupService {
8 | /**
9 | * 创建群组
10 | * @param group 群组实体,不同sdk有不同的数据结构
11 | * @param parameter 其它参数,有可能需要,例如之前使用的阿里云旺会有很多参数, 包装成json传入
12 | * @return 创建群组是否成功的标志
13 | */
14 | boolean createGroup(G group, String parameter);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/ImageService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import org.springframework.web.multipart.MultipartFile;
4 |
5 | import java.io.IOException;
6 |
7 | /**
8 | * Created by wangl on 2017/2/20.
9 | * 处理图片及头像的业务代码接口
10 | */
11 | public interface ImageService {
12 | String imageUpload(MultipartFile file) throws IOException;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/MomentService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.moment.Moment;
4 | import com.github.oneone1995.mvolunteer.domain.moment.MomentComment;
5 | import com.github.oneone1995.mvolunteer.web.exception.MomentCommentCreateFailException;
6 | import com.github.oneone1995.mvolunteer.web.exception.MomentCommentNotFoundException;
7 | import com.github.oneone1995.mvolunteer.web.exception.MomentCreateFailException;
8 | import com.github.oneone1995.mvolunteer.web.exception.MomentNotFoundException;
9 | import com.github.pagehelper.PageInfo;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * 圈子动态相关接口
15 | */
16 | public interface MomentService {
17 |
18 | /**
19 | * 发布圈子动态
20 | * @param moment 圈子动态实体
21 | * @return 是否创建成功
22 | */
23 | boolean createMoment(Moment moment) throws MomentCreateFailException;
24 |
25 | /**
26 | * 分页查询圈子动态
27 | * @param page 页码
28 | * @param rows 每页的数量
29 | * @return 圈子动态PageHelper分页对象
30 | * @throws MomentNotFoundException 当前没有动态
31 | */
32 | PageInfo getMoment(Integer page, Integer rows) throws MomentNotFoundException;
33 |
34 | /**
35 | * 根据id查看某条具体的动态
36 | * @param id 动态id
37 | * @return 动态详情
38 | * @throws MomentNotFoundException 动态未找到异常
39 | */
40 | Moment getMomentById(Integer id) throws MomentNotFoundException;
41 |
42 | /**
43 | * 根据id查看某条评论
44 | * @param id 评论id
45 | * @return 评论详情
46 | * @throws MomentCommentNotFoundException 评论未找到异常
47 | */
48 | MomentComment getMomentCommentById(Integer id) throws MomentCommentNotFoundException;
49 |
50 | /**
51 | * 创建动态评论
52 | * @param comment 评论实体
53 | * @param momentId 动态id
54 | * @return 创建评论是否成功的标志
55 | * @throws MomentCommentCreateFailException 评论创建失败的异常
56 | */
57 | boolean createMomentComment(Integer momentId, MomentComment comment) throws MomentCommentCreateFailException;
58 |
59 | /**
60 | * 根据动态id查看这条动态的评论
61 | * @param momentId 动态id
62 | * @return 评论列表
63 | * @throws MomentCommentNotFoundException 评论找不到异常
64 | */
65 | List getMomentCommentsByMomentId(Integer momentId) throws MomentCommentNotFoundException;
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/OrganizationService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.OrganizationInfo;
4 |
5 | /**
6 | * Created by wangl on 2017/2/24.
7 | */
8 | public interface OrganizationService {
9 | OrganizationInfo getOrganizationInfoBy(Integer id);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/SearchService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.HomeActivity;
4 | import com.github.oneone1995.mvolunteer.domain.User;
5 | import com.github.oneone1995.mvolunteer.web.exception.GroupNotFoundException;
6 | import com.github.oneone1995.mvolunteer.web.exception.UserNotFoundException;
7 | import com.github.pagehelper.PageInfo;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by wangl on 2017/2/20.
13 | */
14 | public interface SearchService {
15 | //分页返回搜索结果
16 | PageInfo getHomeActivityPageInfo(
17 | Integer page, Integer rows, double coordLong, double coordLat, String activityName);
18 |
19 | //根据username搜索用户
20 | User getUserByUsername(String username) throws UserNotFoundException;
21 |
22 | //根据群id返回群头像
23 | String getGroupAvatar(String groupId) throws GroupNotFoundException;
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/SignInService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | /**
4 | * Created by wangl on 2017/2/21.
5 | *签到的业务代码接口
6 | */
7 | public interface SignInService {
8 | //根据活动签到码进行签到
9 | String signIn(Integer code);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 |
4 | import com.github.oneone1995.mvolunteer.domain.User;
5 | import org.springframework.security.core.userdetails.UserDetailsService;
6 |
7 | /**
8 | * Created by wangl on 2017/2/5.
9 | */
10 |
11 | public interface UserService extends UserDetailsService{
12 | User getUserById(int id);
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/VolunteerService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.VolunteerDetails;
4 | import com.github.oneone1995.mvolunteer.domain.VolunteerInfo;
5 | import com.github.pagehelper.PageInfo;
6 |
7 | /**
8 | * Created by wangl on 2017/2/22.
9 | */
10 | public interface VolunteerService {
11 | VolunteerInfo getVolunteerById(Integer id);
12 |
13 | PageInfo getVolunteerListPageInfoByOrganizationId(
14 | Integer page, Integer rows, Integer id);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/api/EasemobApiService.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.api;
2 |
3 | import com.github.oneone1995.mvolunteer.config.easemob.EasemobIMProperties;
4 | import com.github.oneone1995.mvolunteer.model.EasemobIMChatGroupModel;
5 | import com.github.oneone1995.mvolunteer.model.EasemobIMChatMessage;
6 | import com.oneapm.touch.retrofit.boot.annotation.RetrofitService;
7 | import okhttp3.ResponseBody;
8 | import retrofit2.Call;
9 | import retrofit2.http.*;
10 |
11 | /**
12 | * 环信即时通讯云API交互Service
13 | *
14 | * 注意:我用ResponseBody去接收,也可以建一个与响应结果对应的实体直接映射处理,但是响应失败和成功的返回不一样,需要特殊处理
15 | * 我是第一次使用retrofit,暂时不知道有什么办法来处理,也许可以通过拦截器来做。因此都统一用ResponseBody来接收响应,然后自己用Jackson来解析想要的结果
16 | * 参考starter文档和GitHub上的一个项目
17 | * @see
18 | * @see
19 | */
20 | @RetrofitService("easemob")
21 | public interface EasemobApiService {
22 |
23 | /**
24 | * 通过retrofit请求环信即时通讯云创建群组API
25 | * @param token 环信token
26 | * @param orgName 环信企业ID
27 | * @param appName 环信APP名称
28 | * @param chatGroupModel 环信群组API交互model
29 | * @return retrofit包装的请求响应结果
30 | */
31 | @POST("{org_name}/{app_name}/chatgroups")
32 | Call createChatGroups(
33 | @Header("Authorization") String token,
34 | @Path("org_name") String orgName,
35 | @Path("app_name") String appName,
36 | @Body EasemobIMChatGroupModel chatGroupModel);
37 |
38 | /**
39 | * 通过retrofit请求环信即时通讯云创建群组API
40 | * @param token 环信token
41 | * @param orgName 环信企业ID
42 | * @param appName 环信APP名称
43 | * @param groupId 环信群组Id
44 | * @param username 需要加入群组的用户
45 | * @return retrofit包装的请求响应结果
46 | */
47 | @POST("{org_name}/{app_name}/chatgroups/{group_id}/users/{username}")
48 | Call putUser2ChatGroup(
49 | @Header("Authorization") String token,
50 | @Path("org_name") String orgName,
51 | @Path("app_name") String appName,
52 | @Path("group_id") String groupId,
53 | @Path("username") String username);
54 |
55 | /**
56 | * 通过retrofit请求环信即时通讯云生成环信token
57 | * @param orgName 环信企业ID
58 | * @param appName 环信APP名称
59 | * @param easemobSecurity 环信OAuth2授权配置,包含grantType、client_key、client_secret
60 | * @return retrofit包装的请求响应结果
61 | */
62 | @Headers({"Content-Type: application/json"})
63 | @POST("{org_name}/{app_name}/token")
64 | Call generateToken(
65 | @Path("org_name") String orgName,
66 | @Path("app_name") String appName,
67 | @Body EasemobIMProperties.Security easemobSecurity);
68 |
69 | /**
70 | * 发送消息
71 | * @param token 环信token
72 | * @param orgName 环信企业ID
73 | * @param appName 环信APP名称
74 | * @param message 与环信交互发消息实体
75 | * @return retrofit包装的请求响应结果
76 | */
77 | @Headers({"Content-Type: application/json"})
78 | @POST("{org_name}/{app_name}/messages")
79 | Call sendMessage(
80 | @Header("Authorization") String token,
81 | @Path("org_name") String orgName,
82 | @Path("app_name") String appName,
83 | @Body EasemobIMChatMessage message);
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/ActivityStatusServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.ActivityStatus;
4 | import com.github.oneone1995.mvolunteer.mapper.ActivityStatusMapper;
5 | import com.github.oneone1995.mvolunteer.service.ActivityStatusService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | * Created by wangl on 2017/2/22.
11 | */
12 | @Service
13 | public class ActivityStatusServiceImpl implements ActivityStatusService {
14 | @Autowired
15 | private ActivityStatusMapper activityStatusMapper;
16 |
17 | @Override
18 | public ActivityStatus getActivityStatusById(Integer id) {
19 | ActivityStatus activityStatus = activityStatusMapper.selectByPrimaryKey(id);
20 |
21 | if (activityStatus == null) {
22 | return null;
23 | }
24 | return activityStatus;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/ActivityUserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.ActivityUser;
4 | import com.github.oneone1995.mvolunteer.domain.CustomUserDetails;
5 | import com.github.oneone1995.mvolunteer.domain.VolunteerDetails;
6 | import com.github.oneone1995.mvolunteer.mapper.ActivityMapper;
7 | import com.github.oneone1995.mvolunteer.mapper.ActivityUserMapper;
8 | import com.github.oneone1995.mvolunteer.model.EasemobIMChatMessage;
9 | import com.github.oneone1995.mvolunteer.service.ActivityUserService;
10 | import com.github.oneone1995.mvolunteer.service.EasemobIMService;
11 | import com.github.oneone1995.mvolunteer.web.exception.PutUserToEasemobGroupFailException;
12 | import com.github.pagehelper.PageHelper;
13 | import com.github.pagehelper.PageInfo;
14 | import lombok.extern.slf4j.Slf4j;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.security.core.context.SecurityContextHolder;
17 | import org.springframework.stereotype.Service;
18 | import org.springframework.transaction.annotation.Transactional;
19 |
20 | import javax.annotation.Resource;
21 | import java.util.List;
22 |
23 | /**
24 | * Created by wangl on 2017/2/23.
25 | */
26 | @Service
27 | @Slf4j
28 | public class ActivityUserServiceImpl implements ActivityUserService {
29 | //面试通过
30 | private static final Integer INTERVIEW_PASSED = 2;
31 |
32 | //环信消息目标类型
33 | private static final String EASEMOB_MESSAGE_TARGET_TYPE = "chatgroups";
34 |
35 | //环信文本消息类型
36 | private static final String EASEMOB_TEXT_TYPE_MESSAGE = "txt";
37 |
38 | //环信有人加入群组的系统消息
39 | private static final String EASEMOB_GREET_MESSAGE = "欢迎";
40 |
41 | @Resource
42 | private ActivityUserMapper activityUserMapper;
43 |
44 | @Autowired
45 | private EasemobIMService easemobIMService;
46 |
47 | @Override
48 | @Transactional
49 | public boolean signUpActivity(ActivityUser activityUser) {
50 | //获取当前用户
51 | CustomUserDetails currentUser = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
52 | //获取当前用户的id
53 | activityUser.setUserId(currentUser.getId());
54 |
55 | //这里因为接口传入没有activityUserId,因此我们无法知道用户是否已经报名,所以都先去查一次。
56 | //todo 应该在数据库中这里将user_id和activity_id设为唯一索引来约束。便不需要先查一次
57 | //获取当前用户id和活动id在关系表中的记录id
58 | Integer activityUserId = activityUserMapper.selectPrimaryKeyByUserIdAndActivityId(
59 | activityUser.getActivityId(), activityUser.getUserId());
60 | ////若已经报名,则不能再次报名,返回报名失败
61 | if (activityUserId != null) {
62 | log.error("current user has already sign up activity, username: {}, activityId: {}", currentUser.getUsername(), activityUser.getActivityId());
63 | return false;
64 | } else {
65 | //没有报名则
66 | //设置面试状态为待面试
67 | activityUser.setActivityUserStatusId(1);
68 | //设置评分为0
69 | activityUser.setStar(0.0);
70 | //设置签到状态为未签到
71 | activityUser.setSignInStatus(0);
72 |
73 | log.info("sign up activity, activityUser: {}", activityUser);
74 | //加入群组逻辑改到面试通过后才加群
75 | return activityUserMapper.insert(activityUser) > 0;
76 | }
77 | }
78 |
79 | @Override
80 | @Transactional
81 | public boolean cancelActivityByActivityId(Integer activityId) {
82 | //获取当前用户
83 | CustomUserDetails currentUser = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
84 |
85 | //获取当前用户的id
86 | Integer userId = currentUser.getId();
87 |
88 | //获取当前用户id和活动id在关系表中的记录id
89 | Integer id = activityUserMapper.selectPrimaryKeyByUserIdAndActivityId(
90 | activityId, userId
91 | );
92 |
93 | ////根据记录id删除活动
94 | return activityUserMapper.deleteByPrimaryKey(id) > 0;
95 |
96 | }
97 |
98 | @Override
99 | public PageInfo getInterviewList(Integer page, Integer rows) {
100 | //获取当前用户
101 | CustomUserDetails currentUser = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
102 |
103 | //获取当前用户的id
104 | Integer orgId = currentUser.getId();
105 |
106 | PageHelper.startPage(page, rows);
107 | List interviewList = activityUserMapper.selectInterviewList(orgId);
108 |
109 | if (interviewList == null || interviewList.isEmpty()) {
110 | return null;
111 | }
112 | return new PageInfo<>(interviewList);
113 | }
114 |
115 | @Override
116 | @Transactional
117 | public boolean modifyInterviewStatus(Integer id, String volunteerName, String activityGroupId, Integer activityUserStatusId) {
118 | //这里是考虑到第三方SDK加群成功但是修改面试状态失败,用户也会加群。
119 | //但是如果先修改再建调用api加群,不会有这个问题,api调用失败则可以事务回滚。同样的策略在创建活动时建群也能发现。
120 | //如果数据库操作成功且是将面试状态修改为面试通过,则调用api将用户加入IM群
121 | if (activityUserMapper.updateByPrimaryKey(activityUserStatusId, id) > 0 && activityUserStatusId.equals(INTERVIEW_PASSED)) {
122 | //调用环信api进入活动对应的群组
123 | try {
124 | boolean putUser2GroupResult = easemobIMService.putUser2Group(activityGroupId, volunteerName);
125 | //异步调用
126 | easemobIMService.sendEasemobGroupMessage(
127 | new EasemobIMChatMessage(
128 | EASEMOB_MESSAGE_TARGET_TYPE,
129 | new String[]{activityGroupId},
130 | new EasemobIMChatMessage.Message(EASEMOB_TEXT_TYPE_MESSAGE, EASEMOB_GREET_MESSAGE + volunteerName),
131 | "admin"));
132 | //异步调用结束
133 | return putUser2GroupResult;
134 | } catch (PutUserToEasemobGroupFailException e) {
135 | throw new RuntimeException(e);
136 | }
137 | }
138 | return false;
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/CacheServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.service.CacheService;
4 | import com.github.oneone1995.mvolunteer.service.EasemobIMService;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.data.redis.core.StringRedisTemplate;
8 | import org.springframework.stereotype.Service;
9 |
10 | import java.util.*;
11 |
12 | @Service
13 | @Slf4j
14 | public class CacheServiceImpl implements CacheService {
15 | //活动码在redis中的键名
16 | private static final String ACTIVITY_CODE_REDIS_KEY = "activity-code";
17 |
18 | @Autowired
19 | private EasemobIMService easemobIMService;
20 |
21 | @Autowired
22 | private StringRedisTemplate redisTemplate;
23 |
24 | @Override
25 | public String getEasemobToken() {
26 | return easemobIMService.getEasemobToken();
27 | }
28 |
29 | @Override
30 | public void putRandomActivityCode(String code) {
31 | log.info("put code {} into redis", code);
32 |
33 | redisTemplate
34 | .opsForList()
35 | .leftPush(ACTIVITY_CODE_REDIS_KEY, code);
36 | }
37 |
38 | @Override
39 | public String getRandomActivityCode() {
40 | String code = redisTemplate
41 | .opsForList()
42 | .rightPop(ACTIVITY_CODE_REDIS_KEY);
43 |
44 | log.info("get code {} from redis", code);
45 | return code;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/CertificateServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.Certificate;
4 | import com.github.oneone1995.mvolunteer.domain.CustomUserDetails;
5 | import com.github.oneone1995.mvolunteer.mapper.CertificateMapper;
6 | import com.github.oneone1995.mvolunteer.mapper.VolunteerInfoMapper;
7 | import com.github.oneone1995.mvolunteer.service.CertificateService;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.security.core.context.SecurityContextHolder;
10 | import org.springframework.stereotype.Service;
11 | import org.springframework.transaction.annotation.Transactional;
12 |
13 | /**
14 | * Created by wangl on 2017/2/23.
15 | */
16 |
17 | @Service
18 | public class CertificateServiceImpl implements CertificateService {
19 | @Autowired
20 | private CertificateMapper certificateMapper;
21 |
22 | @Autowired
23 | private VolunteerInfoMapper volunteerInfoMapper;
24 |
25 | @Override
26 | @Transactional
27 | public String applyForCertificate(Certificate certificate) {
28 | //获取当前用户
29 | CustomUserDetails currentUser = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
30 | //查询当前用户的工时
31 | if (volunteerInfoMapper.selectByPrimaryKey(currentUser.getId()).getWorkingHours() >= 60) {
32 | certificate.setUserId(currentUser.getId());
33 | certificate.setCertificateStatusId(1);
34 | return certificateMapper.insert(certificate) > 0 ? "SUCCESS": "ALREADY_ERROR";
35 | }
36 | return "INSUFFICIENT_ERROR";
37 | }
38 |
39 | @Override
40 | @Transactional
41 | public boolean modifyCertificateStatusByVolunteerId(Integer volunteerId) {
42 | //更新证书状态
43 | return certificateMapper.updateByVolunteerId(volunteerId) > 0;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/ImageServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.service.ImageService;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.stereotype.Service;
6 | import org.springframework.web.multipart.MultipartFile;
7 | import java.io.File;
8 | import java.io.IOException;
9 | import java.util.UUID;
10 |
11 | /**
12 | * Created by wangl on 2017/2/20.
13 | */
14 | @Service
15 | public class ImageServiceImpl implements ImageService {
16 | //文件上传完整目录
17 | @Value("${upload.path}")
18 | private String path;
19 |
20 | //文件上传目录,不包括根目录
21 | @Value("${upload.dir}")
22 | private String dir;
23 |
24 | /**
25 | * 将上传的图片保存到服务器指定目录
26 | * @param file 客户端传输的文件
27 | * @return 保存目录和文件名共同组成的字符串
28 | */
29 | @Override
30 | public String imageUpload(MultipartFile file) {
31 | // 获取文件名
32 | String filename = file.getOriginalFilename();
33 | // 获取文件的后缀名
34 | String suffixName = filename.substring(filename.lastIndexOf("."));
35 |
36 | // 解决中文问题,linux下中文路径,图片显示问题
37 | filename = UUID.randomUUID() + suffixName;
38 | File dest = new File(path + filename);
39 | try {
40 | file.transferTo(dest);
41 | //上传成功则返回服务器地址和文件名共同组成的字符串
42 | return dir + filename;
43 | } catch (IOException e) {
44 | return null;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/MomentServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.config.result.ResultStatus;
4 | import com.github.oneone1995.mvolunteer.domain.CustomUserDetails;
5 | import com.github.oneone1995.mvolunteer.domain.User;
6 | import com.github.oneone1995.mvolunteer.domain.moment.Moment;
7 | import com.github.oneone1995.mvolunteer.domain.moment.MomentComment;
8 | import com.github.oneone1995.mvolunteer.mapper.MomentCommentMapper;
9 | import com.github.oneone1995.mvolunteer.mapper.MomentMapper;
10 | import com.github.oneone1995.mvolunteer.service.MomentService;
11 | import com.github.oneone1995.mvolunteer.web.exception.MomentCommentCreateFailException;
12 | import com.github.oneone1995.mvolunteer.web.exception.MomentCommentNotFoundException;
13 | import com.github.oneone1995.mvolunteer.web.exception.MomentCreateFailException;
14 | import com.github.oneone1995.mvolunteer.web.exception.MomentNotFoundException;
15 | import com.github.pagehelper.PageHelper;
16 | import com.github.pagehelper.PageInfo;
17 | import lombok.extern.slf4j.Slf4j;
18 | import org.springframework.beans.factory.annotation.Autowired;
19 | import org.springframework.security.core.context.SecurityContextHolder;
20 | import org.springframework.stereotype.Service;
21 | import org.springframework.transaction.annotation.Propagation;
22 | import org.springframework.transaction.annotation.Transactional;
23 |
24 | import javax.annotation.Resource;
25 | import java.util.List;
26 |
27 | @Service
28 | @Slf4j
29 | public class MomentServiceImpl implements MomentService {
30 |
31 | @Resource
32 | private MomentMapper momentMapper;
33 |
34 | @Resource
35 | private MomentCommentMapper momentCommentMapper;
36 |
37 | @Override
38 | @Transactional(propagation = Propagation.REQUIRED)
39 | public boolean createMoment(Moment moment) throws MomentCreateFailException {
40 | //获取当前用户
41 | CustomUserDetails currentUser = (CustomUserDetails) SecurityContextHolder.
42 | getContext().getAuthentication().getPrincipal();
43 |
44 | //这里只需要存发布动态作者的userID即可,因为圈子动态中的用户信息是由数据库通过user_id关联user表维护的
45 | moment.setUserId(currentUser.getId());
46 | log.info("create moment service, moment: {}", moment);
47 |
48 | //插入圈子动态记录失败
49 | if (momentMapper.insert(moment) <= 0) {
50 | throw new MomentCreateFailException(ResultStatus.MOMENT_CREATE_FAIL.getMessage());
51 | }
52 |
53 | return true;
54 | }
55 |
56 | @Override
57 | @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
58 | public PageInfo getMoment(Integer page, Integer rows) throws MomentNotFoundException {
59 |
60 | //在mapper查询语句前使用下面这句代码可以有分页效果
61 | PageHelper.startPage(page, rows);
62 | List momentList = momentMapper.selectAll();
63 |
64 | if (momentList == null || momentList.isEmpty()) {
65 | throw new MomentNotFoundException(ResultStatus.MOMENT_NOT_FOUNT.getMessage());
66 | }
67 |
68 | return new PageInfo<>(momentList);
69 | }
70 |
71 | @Override
72 | public Moment getMomentById(Integer id) throws MomentNotFoundException {
73 | Moment moment = momentMapper.selectByPrimaryKey(id);
74 | if (moment == null) {
75 | throw new MomentNotFoundException(ResultStatus.MOMENT_NOT_FOUNT.getMessage());
76 | }
77 | log.info("get moment by id, return : {}", moment);
78 | return moment;
79 | }
80 |
81 | @Override
82 | @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
83 | public MomentComment getMomentCommentById(Integer id) throws MomentCommentNotFoundException {
84 | MomentComment momentComment = momentCommentMapper.selectByPrimaryKey(id);
85 | if (momentComment == null) {
86 | throw new MomentCommentNotFoundException(ResultStatus.MOMENT_COMMENT_NOT_FOUNT.getMessage());
87 | }
88 | log.info("get moment comment by id, return : {}", momentComment);
89 | return momentComment;
90 | }
91 |
92 | @Override
93 | @Transactional(propagation = Propagation.REQUIRED)
94 | public boolean createMomentComment(Integer momentId, MomentComment comment) throws MomentCommentCreateFailException {
95 | //获取当前用户
96 | CustomUserDetails currentUser = (CustomUserDetails) SecurityContextHolder.
97 | getContext().getAuthentication().getPrincipal();
98 |
99 | comment.setMomentId(momentId);
100 |
101 | comment.setUserId(currentUser.getId());
102 |
103 | log.info("create moment comment, comment :{}", comment);
104 |
105 | if (momentCommentMapper.insert(comment) < 1) {
106 | log.error("create moment comment fail by comment : {}", comment);
107 | throw new MomentCommentCreateFailException(ResultStatus.MOMENT_COMMENT_CREATE_FAIL.getMessage());
108 | }
109 | return true;
110 | }
111 |
112 | @Override
113 | @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
114 | public List getMomentCommentsByMomentId(Integer momentId) throws MomentCommentNotFoundException {
115 | List momentComments = momentCommentMapper.selectByMomentId(momentId);
116 |
117 | if (momentComments == null || momentComments.isEmpty()) {
118 | log.error("get moment comments by moment id {} fail", momentId);
119 | throw new MomentCommentNotFoundException(ResultStatus.MOMENT_COMMENT_NOT_FOUNT.getMessage());
120 | }
121 | log.info("get moment comments success, return : {}", momentComments);
122 | return momentComments;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/OrganizationServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.OrganizationInfo;
4 | import com.github.oneone1995.mvolunteer.mapper.OrganizationInfoMapper;
5 | import com.github.oneone1995.mvolunteer.service.OrganizationService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | * Created by wangl on 2017/2/24.
11 | */
12 | @Service
13 | public class OrganizationServiceImpl implements OrganizationService {
14 | @Autowired
15 | private OrganizationInfoMapper organizationInfoMapper;
16 |
17 | @Override
18 | public OrganizationInfo getOrganizationInfoBy(Integer id) {
19 | OrganizationInfo organizationInfo = organizationInfoMapper.selectByPrimaryKey(id);
20 |
21 | if (organizationInfo == null) {
22 | return null;
23 | }
24 | return organizationInfo;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/SearchServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.config.result.ResultStatus;
4 | import com.github.oneone1995.mvolunteer.domain.HomeActivity;
5 | import com.github.oneone1995.mvolunteer.domain.User;
6 | import com.github.oneone1995.mvolunteer.mapper.ActivityMapper;
7 | import com.github.oneone1995.mvolunteer.mapper.UserMapper;
8 | import com.github.oneone1995.mvolunteer.service.ActivityService;
9 | import com.github.oneone1995.mvolunteer.service.SearchService;
10 | import com.github.oneone1995.mvolunteer.web.exception.GroupNotFoundException;
11 | import com.github.oneone1995.mvolunteer.web.exception.UserNotFoundException;
12 | import com.github.pagehelper.PageInfo;
13 | import lombok.extern.slf4j.Slf4j;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.stereotype.Service;
16 |
17 | import javax.annotation.Resource;
18 | import java.util.List;
19 |
20 | /**
21 | * Created by wangl on 2017/2/20.
22 | */
23 | @Service
24 | @Slf4j
25 | public class SearchServiceImpl implements SearchService {
26 | @Autowired
27 | private ActivityService activityService;
28 |
29 | @Resource
30 | private UserMapper userMapper;
31 |
32 | @Resource
33 | private ActivityMapper activityMapper;
34 |
35 | @Override
36 | public PageInfo getHomeActivityPageInfo(Integer page, Integer rows, double coordLong, double coordLat, String activityName) {
37 | return activityService.getHomeActivityPageInfo(page, rows, coordLong, coordLat, activityName);
38 | }
39 |
40 | @Override
41 | public User getUserByUsername(String username) throws UserNotFoundException {
42 | log.info("search user info by username: {}", username);
43 |
44 | User user = userMapper.selectByUsername(username);
45 | if (user == null) {
46 | log.error("user not found by username :{}", username);
47 | throw new UserNotFoundException(ResultStatus.USER_NOT_FOUND.getMessage());
48 | }
49 | log.info("search user : {} success", user);
50 | return user;
51 | }
52 |
53 | @Override
54 | public String getGroupAvatar(String groupId) throws GroupNotFoundException {
55 | log.info("search activity picture use for group avatar by group id:{}", groupId);
56 |
57 | String groupAvatar = activityMapper.selectActivityPictureByTribeId(groupId);
58 |
59 | if (groupAvatar == null || groupAvatar.length() == 0) {
60 | log.error("group not found by group id:{}", groupId);
61 | throw new GroupNotFoundException(ResultStatus.GROUP_NOT_FOUND.getMessage());
62 | }
63 | log.info("get group avatar success by activity picture:{}", groupAvatar);
64 | return groupAvatar;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/SignInServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.CustomUserDetails;
4 | import com.github.oneone1995.mvolunteer.mapper.ActivityMapper;
5 | import com.github.oneone1995.mvolunteer.service.SignInService;
6 | import org.springframework.security.core.context.SecurityContextHolder;
7 | import org.springframework.stereotype.Service;
8 |
9 | import javax.annotation.Resource;
10 |
11 | /**
12 | * Created by wangl on 2017/2/21.
13 | */
14 | @Service
15 | public class SignInServiceImpl implements SignInService {
16 | @Resource
17 | private ActivityMapper activityMapper;
18 |
19 | @Override
20 | public String signIn(Integer code) {
21 | //得到当前登录的用户
22 | CustomUserDetails currentUser = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
23 | //得到当前用户的id
24 | Integer id = currentUser.getId();
25 |
26 | //根据活动code和用户id返回该记录在活动用户关系表中的主键id
27 | Integer activityUserId = activityMapper.selectByCode(code, id);
28 |
29 | if (activityUserId == null) {
30 | return "fail";
31 | }
32 | Integer record = activityMapper.updateSignStatusByPrimaryKey(activityUserId);
33 | if (record == 1) {
34 | return "success";
35 | }
36 | return "fail";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.CustomUserDetails;
4 | import com.github.oneone1995.mvolunteer.domain.User;
5 | import com.github.oneone1995.mvolunteer.mapper.RoleMapper;
6 | import com.github.oneone1995.mvolunteer.mapper.UserMapper;
7 | import com.github.oneone1995.mvolunteer.service.UserService;
8 | import org.springframework.security.core.userdetails.UserDetails;
9 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
10 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11 | import org.springframework.stereotype.Service;
12 |
13 | import javax.annotation.Resource;
14 |
15 | /**
16 | * Created by wangl on 2017/2/10.
17 | */
18 | @Service
19 | public class UserServiceImpl implements UserService {
20 | @Resource
21 | private UserMapper userMapper;
22 |
23 | @Override
24 | public User getUserById(int id) {
25 | return userMapper.selectByPrimaryKey(id);
26 | }
27 |
28 | @Override
29 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
30 | CustomUserDetails user = userMapper.selectCustomUserDetailsByUsername(username);
31 | if (user == null) {
32 | throw new UsernameNotFoundException("Could not find the user '" + username + "'");
33 | }
34 |
35 | return user;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/service/impl/VolunteerServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.service.impl;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.VolunteerDetails;
4 | import com.github.oneone1995.mvolunteer.domain.VolunteerInfo;
5 | import com.github.oneone1995.mvolunteer.mapper.VolunteerInfoMapper;
6 | import com.github.oneone1995.mvolunteer.service.VolunteerService;
7 | import com.github.pagehelper.PageHelper;
8 | import com.github.pagehelper.PageInfo;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Service;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by wangl on 2017/2/22.
16 | */
17 | @Service
18 | public class VolunteerServiceImpl implements VolunteerService {
19 | @Autowired
20 | private VolunteerInfoMapper volunteerInfoMapper;
21 |
22 | @Override
23 | public VolunteerInfo getVolunteerById(Integer id) {
24 | VolunteerInfo volunteerInfo = volunteerInfoMapper.selectByPrimaryKey(id);
25 |
26 | if (volunteerInfo == null) {
27 | return null;
28 | }
29 | return volunteerInfo;
30 | }
31 |
32 | @Override
33 | public PageInfo getVolunteerListPageInfoByOrganizationId(
34 | Integer page, Integer rows, Integer id) {
35 |
36 | PageHelper.startPage(page, rows);
37 | List volunteerDetailsList = volunteerInfoMapper.selectByOrganizationId(id);
38 |
39 | if (volunteerDetailsList == null || volunteerDetailsList.isEmpty()) {
40 | return null;
41 | }
42 | return new PageInfo<>(volunteerDetailsList);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/utils/IMUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.utils;
2 |
3 | import com.github.oneone1995.mvolunteer.domain.CustomUserDetails;
4 | import com.taobao.api.ApiException;
5 | import com.taobao.api.DefaultTaobaoClient;
6 | import com.taobao.api.TaobaoClient;
7 | import com.taobao.api.domain.OpenImUser;
8 | import com.taobao.api.request.OpenimTribeCreateRequest;
9 | import com.taobao.api.request.OpenimTribeJoinRequest;
10 | import com.taobao.api.request.OpenimTribeQuitRequest;
11 | import com.taobao.api.response.OpenimTribeCreateResponse;
12 | import com.taobao.api.response.OpenimTribeJoinResponse;
13 | import com.taobao.api.response.OpenimTribeQuitResponse;
14 | import org.slf4j.Logger;
15 | import org.slf4j.LoggerFactory;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | import static com.github.oneone1995.mvolunteer.config.aliim.IMConstantConfig.*;
21 |
22 | /**
23 | * Created by wangl on 2017/2/26.
24 | * IM相关的一些工具类
25 | * @deprecated 改用环信即时通讯云
26 | * @see com.github.oneone1995.mvolunteer.service.EasemobIMService
27 | */
28 | @Deprecated
29 | public class IMUtil {
30 |
31 | protected static Logger logger = LoggerFactory.getLogger(IMUtil.class);
32 |
33 | /**
34 | * 创建普通群组
35 | * @param currentUser 当前用户,默认为群的管理员
36 | * @param tribeName 群名
37 | * @param notice 群公告
38 | * @return 访问阿里服务器接口的Response
39 | */
40 | public static OpenimTribeCreateResponse creteTribe(
41 | CustomUserDetails currentUser,
42 | String tribeName,
43 | String notice
44 | ) {
45 | TaobaoClient client = new DefaultTaobaoClient(API_URL, APP_KEY, APP_SECURITY);
46 | OpenimTribeCreateRequest tribeCreateRequest = new OpenimTribeCreateRequest();
47 | //=======必要的参数=======//
48 | //用户信息
49 | OpenImUser openImUser = new OpenImUser();
50 | openImUser.setUid(currentUser.getUsername());
51 | openImUser.setAppKey(APP_KEY);
52 | openImUser.setTaobaoAccount(false);
53 | tribeCreateRequest.setUser(openImUser);
54 | //群名称
55 | tribeCreateRequest.setTribeName(tribeName);
56 | //群公告
57 | tribeCreateRequest.setNotice(notice);
58 | //群类型
59 | tribeCreateRequest.setTribeType(0L);
60 | //添加当前用户为群成员
61 | List openImUserList = new ArrayList<>();
62 | OpenImUser openImCurrentUser = new OpenImUser();
63 | openImCurrentUser.setUid(currentUser.getUsername());
64 | openImCurrentUser.setAppKey(APP_KEY);
65 | openImCurrentUser.setTaobaoAccount(false);
66 | openImUserList.add(openImCurrentUser);
67 |
68 | tribeCreateRequest.setMembers(openImUserList);
69 |
70 | OpenimTribeCreateResponse tribeCreateResponse = null;
71 | try {
72 | tribeCreateResponse = client.execute(tribeCreateRequest);
73 | } catch (ApiException e) {
74 | logger.error(e.getErrMsg());
75 | }
76 | return tribeCreateResponse;
77 | }
78 |
79 | public static OpenimTribeJoinResponse joinTribe(
80 | CustomUserDetails currentUser,
81 | Integer tribeId
82 | ) {
83 | TaobaoClient client = new DefaultTaobaoClient(API_URL, APP_KEY, APP_SECURITY);
84 | OpenimTribeJoinRequest tribeJoinRequest = new OpenimTribeJoinRequest();
85 | //=======必要的参数=======//
86 | //用户信息
87 | OpenImUser openImUser = new OpenImUser();
88 | openImUser.setUid(currentUser.getUsername());
89 | openImUser.setAppKey(APP_KEY);
90 | openImUser.setTaobaoAccount(false);
91 | tribeJoinRequest.setUser(openImUser);
92 | //群号
93 | tribeJoinRequest.setTribeId(Long.valueOf(tribeId));
94 |
95 | //发送
96 | OpenimTribeJoinResponse tribeJoinResponse = null;
97 | try {
98 | tribeJoinResponse = client.execute(tribeJoinRequest);
99 | } catch (ApiException e) {
100 | logger.error(e.getErrMsg());
101 | }
102 | return tribeJoinResponse;
103 | }
104 |
105 |
106 | /**
107 | * 退出群
108 | * @param currentUser 当前用户
109 | * @param tribeId 要退出的群的群号
110 | * @return 访问阿里API接口的Response
111 | */
112 | public static OpenimTribeQuitResponse quitTribe(
113 | CustomUserDetails currentUser,
114 | Integer tribeId
115 | ) {
116 | TaobaoClient client = new DefaultTaobaoClient(API_URL, APP_KEY, APP_SECURITY);
117 | OpenimTribeQuitRequest tribeQuitRequest = new OpenimTribeQuitRequest();
118 | //=======必要的参数=======//
119 | //用户信息
120 | OpenImUser openImUser = new OpenImUser();
121 | openImUser.setUid(currentUser.getUsername());
122 | openImUser.setAppKey(APP_KEY);
123 | openImUser.setTaobaoAccount(false);
124 | tribeQuitRequest.setUser(openImUser);
125 | //群号
126 | tribeQuitRequest.setTribeId(Long.valueOf(tribeId));
127 |
128 | //发送
129 | OpenimTribeQuitResponse tribeQuitResponse = null;
130 | try {
131 | tribeQuitResponse = client.execute(tribeQuitRequest);
132 | } catch (ApiException e) {
133 | logger.error(e.getErrMsg());
134 | }
135 | return tribeQuitResponse;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/com/github/oneone1995/mvolunteer/web/ActivityController.java:
--------------------------------------------------------------------------------
1 | package com.github.oneone1995.mvolunteer.web;
2 |
3 | import com.github.oneone1995.mvolunteer.config.result.ResultStatus;
4 | import com.github.oneone1995.mvolunteer.domain.Activity;
5 | import com.github.oneone1995.mvolunteer.domain.ActivityDetails;
6 | import com.github.oneone1995.mvolunteer.domain.HomeActivity;
7 | import com.github.oneone1995.mvolunteer.model.ResultModel;
8 | import com.github.oneone1995.mvolunteer.service.ActivityService;
9 | import com.github.pagehelper.PageInfo;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.security.access.prepost.PreAuthorize;
14 | import org.springframework.web.bind.annotation.*;
15 |
16 | /**
17 | * Created by wangl on 2017/2/18.
18 | * 活动相关API接口
19 | */
20 | @RestController
21 | @RequestMapping("/api/activity")
22 | public class ActivityController {
23 |
24 | @Autowired
25 | private ActivityService activityService;
26 |
27 | /**
28 | * APP首页的活动列表分页获取接口
29 | * @param page 页码
30 | * @param rows 单页数量
31 | * @param coordLong 经度
32 | * @param coordLat 维度
33 | */
34 | @GetMapping
35 | public ResponseEntity> getActivities(
36 | @RequestParam(value = "page") Integer page,
37 | @RequestParam(value = "rows", defaultValue = "10") Integer rows,
38 | @RequestParam(value = "coordLong") double coordLong,
39 | @RequestParam(value = "coordLat") double coordLat) {
40 |
41 | PageInfo homeActivityPageInfo = activityService.getHomeActivityPageInfo(
42 | page, rows, coordLong, coordLat);
43 |
44 | if (homeActivityPageInfo == null) {
45 | return new ResponseEntity<>(ResultModel.error(ResultStatus.ACTIVITY_NOT_FOUNT), HttpStatus.NO_CONTENT);
46 | }
47 |
48 | return new ResponseEntity<>(ResultModel.ok(homeActivityPageInfo), HttpStatus.OK);
49 | }
50 |
51 |
52 | /**
53 | * 根据活动所属类别分页获取符合规则的活动列表API接口
54 | * @param page 页码
55 | * @param rows 但也数量
56 | * @param coordLong 当前经度
57 | * @param coordLat 当前维度
58 | * @param category 活动类别
59 | * @param collation 排序规则 0为按时间排序、1为按距离排序
60 | * @param district 按地区筛选
61 | */
62 | @GetMapping("/category")
63 | public ResponseEntity> getActivitiesByCategory(
64 | @RequestParam(value = "page") Integer page,
65 | @RequestParam(value = "rows", defaultValue = "10") Integer rows,
66 | @RequestParam(value = "coordLong") double coordLong,
67 | @RequestParam(value = "coordLat") double coordLat,
68 | @RequestParam(value = "category", required = false) String category,
69 | @RequestParam(value = "collation", defaultValue = "0") Integer collation,
70 | @RequestParam(value = "district", required = false) String district
71 | ) {
72 | PageInfo categoryActivityPageInfo = activityService.getHomeActivityPageInfo(
73 | page, rows, coordLong, coordLat, category, collation, district);
74 |
75 | if (categoryActivityPageInfo == null) {
76 | return new ResponseEntity<>(ResultModel.error(ResultStatus.ACTIVITY_NOT_FOUNT), HttpStatus.NO_CONTENT);
77 | }
78 | return new ResponseEntity<>(ResultModel.ok(categoryActivityPageInfo), HttpStatus.OK);
79 | }
80 |
81 | /**
82 | * 查看某个具体活动详情的api接口,需要鉴权才能访问,但不区分角色
83 | * @param id 活动id
84 | * @param coordLong 移动设备经度
85 | * @param coordLat 移动设备维度
86 | */
87 | @GetMapping("/{id}")
88 | @PreAuthorize("hasRole('ROLE_VOL') or hasRole('ROLE_ORG')")
89 | public ResponseEntity> getActivityById(
90 | @PathVariable Integer id,
91 | @RequestParam(value = "coordLong") double coordLong,
92 | @RequestParam(value = "coordLat") double coordLat
93 | ) {
94 | ActivityDetails activityDetails = activityService.getActivityById(
95 | id, coordLong, coordLat);
96 |
97 | if (activityDetails == null) {
98 | return new ResponseEntity<>(ResultModel.error(ResultStatus.ACTIVITY_NOT_FOUNT), HttpStatus.NO_CONTENT);
99 | }
100 | return new ResponseEntity<>(ResultModel.ok(activityDetails), HttpStatus.OK);
101 | }
102 |
103 | /**
104 | * 发布活动的api接口,只有拥有志愿组织权限(ROLE_ORG)才能使用
105 | * @param activity 活动实体 {@link com.github.oneone1995.mvolunteer.domain.Activity}
106 | */
107 | @PostMapping
108 | @PreAuthorize("hasRole('ROLE_ORG')")
109 | public ResponseEntity> postActivity(@RequestBody Activity activity) {
110 | boolean result = activityService.createActivity(activity);
111 |
112 | if (!result) {
113 | return new ResponseEntity<>(ResultModel.error(ResultStatus.ACTIVITY_CREATE_FAIL), HttpStatus.INTERNAL_SERVER_ERROR);
114 | }
115 | return new ResponseEntity<>(ResultModel.ok("创建活动成功"), HttpStatus.OK);
116 | }
117 |
118 | /**
119 | * 修改活动状态API接口,只有拥有志愿组织权限(ROLE_ORG)才能使用
120 | * @param id 需要修改状态的活动id
121 | * @param activityStatusId 修改为什么状态 1为正在招募,2为活动进行,3为活动结束
122 | * @return
123 | */
124 | @PutMapping("/{id}")
125 | @PreAuthorize("hasRole('ROLE_ORG')")
126 | public ResponseEntity> putActivity(
127 | @PathVariable Integer id,
128 | @RequestParam(value = "activityStatusId") Integer activityStatusId
129 | ) {
130 | String result = activityService.updateActivityStatusById(id, activityStatusId);
131 |
132 | if (result.equals("ACTIVITY_NOT_FOUNT")) {
133 | return new ResponseEntity