Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
JuniorSpringMVCTemplate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HireTest
JuniorSpringMVCTemplate
Commits
e384f16e
Commit
e384f16e
authored
Jul 30, 2018
by
邢足健
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coding
parent
f6ba40f4
Changes
39
Hide whitespace changes
Inline
Side-by-side
Showing
39 changed files
with
0 additions
and
10874 deletions
+0
-10874
AuthTokenService.java
...dio/JuniorSpringMVCTemplate/service/AuthTokenService.java
+0
-141
CcLoggingService.java
...dio/JuniorSpringMVCTemplate/service/CcLoggingService.java
+0
-141
CcNotificationSettingService.java
...ringMVCTemplate/service/CcNotificationSettingService.java
+0
-141
DepartmentService.java
...io/JuniorSpringMVCTemplate/service/DepartmentService.java
+0
-141
FunctionAuthorityService.java
...orSpringMVCTemplate/service/FunctionAuthorityService.java
+0
-141
HmLogService.java
...ostudio/JuniorSpringMVCTemplate/service/HmLogService.java
+0
-141
HmUserService.java
...studio/JuniorSpringMVCTemplate/service/HmUserService.java
+0
-141
MenuService.java
...mostudio/JuniorSpringMVCTemplate/service/MenuService.java
+0
-141
OrganizationService.java
.../JuniorSpringMVCTemplate/service/OrganizationService.java
+0
-141
RoleFunctionService.java
.../JuniorSpringMVCTemplate/service/RoleFunctionService.java
+0
-141
RoleMenuService.java
...udio/JuniorSpringMVCTemplate/service/RoleMenuService.java
+0
-141
RoleService.java
...mostudio/JuniorSpringMVCTemplate/service/RoleService.java
+0
-141
ViewHmUserDepartmentRoleService.java
...gMVCTemplate/service/ViewHmUserDepartmentRoleService.java
+0
-141
AuthTokenServiceImpl.java
...rSpringMVCTemplate/service/impl/AuthTokenServiceImpl.java
+0
-264
CcLoggingServiceImpl.java
...rSpringMVCTemplate/service/impl/CcLoggingServiceImpl.java
+0
-264
CcNotificationSettingServiceImpl.java
...mplate/service/impl/CcNotificationSettingServiceImpl.java
+0
-264
DepartmentServiceImpl.java
...SpringMVCTemplate/service/impl/DepartmentServiceImpl.java
+0
-264
FunctionAuthorityServiceImpl.java
...VCTemplate/service/impl/FunctionAuthorityServiceImpl.java
+0
-264
HmLogServiceImpl.java
...uniorSpringMVCTemplate/service/impl/HmLogServiceImpl.java
+0
-264
HmUserServiceImpl.java
...niorSpringMVCTemplate/service/impl/HmUserServiceImpl.java
+0
-264
MenuServiceImpl.java
...JuniorSpringMVCTemplate/service/impl/MenuServiceImpl.java
+0
-264
OrganizationServiceImpl.java
...ringMVCTemplate/service/impl/OrganizationServiceImpl.java
+0
-264
RoleFunctionServiceImpl.java
...ringMVCTemplate/service/impl/RoleFunctionServiceImpl.java
+0
-264
RoleMenuServiceImpl.java
...orSpringMVCTemplate/service/impl/RoleMenuServiceImpl.java
+0
-264
RoleServiceImpl.java
...JuniorSpringMVCTemplate/service/impl/RoleServiceImpl.java
+0
-264
ViewHmUserDepartmentRoleServiceImpl.java
...ate/service/impl/ViewHmUserDepartmentRoleServiceImpl.java
+0
-264
AuthTokenController.java
...niorSpringMVCTemplate/controller/AuthTokenController.java
+0
-333
CcLoggingController.java
...niorSpringMVCTemplate/controller/CcLoggingController.java
+0
-443
CcNotificationSettingController.java
...CTemplate/controller/CcNotificationSettingController.java
+0
-393
DepartmentController.java
...iorSpringMVCTemplate/controller/DepartmentController.java
+0
-458
FunctionAuthorityController.java
...ngMVCTemplate/controller/FunctionAuthorityController.java
+0
-338
HmLogController.java
...o/JuniorSpringMVCTemplate/controller/HmLogController.java
+0
-368
HmUserController.java
.../JuniorSpringMVCTemplate/controller/HmUserController.java
+0
-578
MenuController.java
...io/JuniorSpringMVCTemplate/controller/MenuController.java
+0
-393
OrganizationController.java
...rSpringMVCTemplate/controller/OrganizationController.java
+0
-383
RoleController.java
...io/JuniorSpringMVCTemplate/controller/RoleController.java
+0
-368
RoleFunctionController.java
...rSpringMVCTemplate/controller/RoleFunctionController.java
+0
-323
RoleMenuController.java
...uniorSpringMVCTemplate/controller/RoleMenuController.java
+0
-323
ViewHmUserDepartmentRoleController.java
...mplate/controller/ViewHmUserDepartmentRoleController.java
+0
-908
No files found.
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/AuthTokenService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.AuthToken
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
AuthTokenService
{
int
create
(
AuthToken
item
);
int
delete
(
String
id
);
int
update
(
AuthToken
item
);
AuthToken
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
AuthToken
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/CcLoggingService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.CcLogging
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
CcLoggingService
{
int
create
(
CcLogging
item
);
int
delete
(
String
id
);
int
update
(
CcLogging
item
);
CcLogging
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
CcLogging
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/CcNotificationSettingService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.CcNotificationSetting
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
CcNotificationSettingService
{
int
create
(
CcNotificationSetting
item
);
int
delete
(
String
id
);
int
update
(
CcNotificationSetting
item
);
CcNotificationSetting
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
CcNotificationSetting
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/DepartmentService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.Department
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
DepartmentService
{
int
create
(
Department
item
);
int
delete
(
String
id
);
int
update
(
Department
item
);
Department
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
Department
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/FunctionAuthorityService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.FunctionAuthority
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
FunctionAuthorityService
{
int
create
(
FunctionAuthority
item
);
int
delete
(
String
id
);
int
update
(
FunctionAuthority
item
);
FunctionAuthority
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
FunctionAuthority
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/HmLogService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.HmLog
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
HmLogService
{
int
create
(
HmLog
item
);
int
delete
(
String
id
);
int
update
(
HmLog
item
);
HmLog
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
HmLog
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/HmUserService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.HmUser
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
HmUserService
{
int
create
(
HmUser
item
);
int
delete
(
String
id
);
int
update
(
HmUser
item
);
HmUser
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
HmUser
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/MenuService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.Menu
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
MenuService
{
int
create
(
Menu
item
);
int
delete
(
String
id
);
int
update
(
Menu
item
);
Menu
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
Menu
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/OrganizationService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.Organization
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
OrganizationService
{
int
create
(
Organization
item
);
int
delete
(
String
id
);
int
update
(
Organization
item
);
Organization
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
Organization
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/RoleFunctionService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.RoleFunction
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
RoleFunctionService
{
int
create
(
RoleFunction
item
);
int
delete
(
String
id
);
int
update
(
RoleFunction
item
);
RoleFunction
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
RoleFunction
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/RoleMenuService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.RoleMenu
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
RoleMenuService
{
int
create
(
RoleMenu
item
);
int
delete
(
String
id
);
int
update
(
RoleMenu
item
);
RoleMenu
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
RoleMenu
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/RoleService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.Role
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
RoleService
{
int
create
(
Role
item
);
int
delete
(
String
id
);
int
update
(
Role
item
);
Role
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
Role
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/ViewHmUserDepartmentRoleService.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.ViewHmUserDepartmentRole
;
import
java.util.List
;
/**
* Created by hxgqh on 2016/1/7.
*/
public
interface
ViewHmUserDepartmentRoleService
{
int
create
(
ViewHmUserDepartmentRole
item
);
int
delete
(
String
id
);
int
update
(
ViewHmUserDepartmentRole
item
);
ViewHmUserDepartmentRole
get
(
String
id
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串,格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表
*/
List
<
ViewHmUserDepartmentRole
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
);
/**
* 获取列表
* @param pageNo 整数,如1
* @param pageSize 整数,如10
* @param sortItem 格式为"id, name"
* @param sortOrder 格式为"asc, desc"
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @param includes JSON字符串, 用来将本表的外链字段(table_id类似的字段)指向的外链表的完整行数据返回, 格式为
* {
* 'include_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'include_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param refers JSON字符串, 用来将其他表的外链字段为本表的表数据返回, 格式为
* {
* 'refer_table1': {
* includes: ['include_table11', 'include_table12']
* },
* 'refer_table2': {
* includes: ['include_table21', 'include_table22']
* }
* }
* @param relates JSON字符串, 用来将其他有间接关系的表(所谓间接关系, 一定是跟本表的某个字段名一致, 且指向同一张表)
* {
* 'relate_table1': ['column1', 'column2'],
* 'relate_table1': ['column3', 'column4']
* }
* @return 列表
*/
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
);
/**
* 获取列表数量
* @param filters JSON字符串, 用来过滤列表的数据, 格式为
* {
* table:
* {
* column1: {
* like: '%abc%',
* notLike: ''
* between: [1, 10],
* notBetween: [1, 10]
* isNull: true, // 只能为true
* isNotNull: true, // 只能为true
* equalTo: "abc",
* notEqualTo: "abc",
* greaterThan: 10,
* greaterThanOrEqualTo: 10,
* lessThan: 10,
* lessThanOrEqualTo: 10,
* in: [],
* notIn: []
* }
* }
* }
* @return 列表计数
*/
Long
countListWithPagingAndFilter
(
String
filters
);
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/AuthTokenServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"authTokenService"
)
public
class
AuthTokenServiceImpl
implements
AuthTokenService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AuthTokenServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
AuthToken
item
)
{
return
authTokenMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
authTokenMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
AuthToken
item
)
{
return
authTokenMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
AuthToken
get
(
String
id
)
{
return
authTokenMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
AuthTokenVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
AuthTokenVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
AuthTokenExample
tableExampleObj
=
new
AuthTokenExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
AuthToken
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
AuthTokenExample
exampleObj
=
new
AuthTokenExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"AuthToken"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
authTokenMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
AuthTokenExample
exampleObj
=
new
AuthTokenExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"AuthToken"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
AuthToken
>
modelList
=
authTokenMapper
.
selectByExample
(
exampleObj
);
List
<
AuthTokenVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
AuthTokenVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
AuthTokenExample
exampleObj
=
new
AuthTokenExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"AuthToken"
,
filters
);
return
authTokenMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
AuthTokenVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
AuthTokenVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/CcLoggingServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"ccLoggingService"
)
public
class
CcLoggingServiceImpl
implements
CcLoggingService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
CcLoggingServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
CcLogging
item
)
{
return
ccLoggingMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
ccLoggingMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
CcLogging
item
)
{
return
ccLoggingMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
CcLogging
get
(
String
id
)
{
return
ccLoggingMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
CcLoggingVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
CcLoggingVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
CcLoggingExample
tableExampleObj
=
new
CcLoggingExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
CcLogging
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
CcLoggingExample
exampleObj
=
new
CcLoggingExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"CcLogging"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
ccLoggingMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
CcLoggingExample
exampleObj
=
new
CcLoggingExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"CcLogging"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
CcLogging
>
modelList
=
ccLoggingMapper
.
selectByExample
(
exampleObj
);
List
<
CcLoggingVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
CcLoggingVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
CcLoggingExample
exampleObj
=
new
CcLoggingExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"CcLogging"
,
filters
);
return
ccLoggingMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
CcLoggingVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
CcLoggingVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/CcNotificationSettingServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"ccNotificationSettingService"
)
public
class
CcNotificationSettingServiceImpl
implements
CcNotificationSettingService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
CcNotificationSettingServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
CcNotificationSetting
item
)
{
return
ccNotificationSettingMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
ccNotificationSettingMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
CcNotificationSetting
item
)
{
return
ccNotificationSettingMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
CcNotificationSetting
get
(
String
id
)
{
return
ccNotificationSettingMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
CcNotificationSettingVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
CcNotificationSettingVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
CcNotificationSettingExample
tableExampleObj
=
new
CcNotificationSettingExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
CcNotificationSetting
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
CcNotificationSettingExample
exampleObj
=
new
CcNotificationSettingExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"CcNotificationSetting"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
ccNotificationSettingMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
CcNotificationSettingExample
exampleObj
=
new
CcNotificationSettingExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"CcNotificationSetting"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
CcNotificationSetting
>
modelList
=
ccNotificationSettingMapper
.
selectByExample
(
exampleObj
);
List
<
CcNotificationSettingVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
CcNotificationSettingVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
CcNotificationSettingExample
exampleObj
=
new
CcNotificationSettingExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"CcNotificationSetting"
,
filters
);
return
ccNotificationSettingMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
CcNotificationSettingVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
CcNotificationSettingVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/DepartmentServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"departmentService"
)
public
class
DepartmentServiceImpl
implements
DepartmentService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
DepartmentServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
Department
item
)
{
return
departmentMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
departmentMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
Department
item
)
{
return
departmentMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
Department
get
(
String
id
)
{
return
departmentMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
DepartmentVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
DepartmentVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
DepartmentExample
tableExampleObj
=
new
DepartmentExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
Department
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
DepartmentExample
exampleObj
=
new
DepartmentExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Department"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
departmentMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
DepartmentExample
exampleObj
=
new
DepartmentExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Department"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
Department
>
modelList
=
departmentMapper
.
selectByExample
(
exampleObj
);
List
<
DepartmentVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
DepartmentVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
DepartmentExample
exampleObj
=
new
DepartmentExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Department"
,
filters
);
return
departmentMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
DepartmentVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
DepartmentVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/FunctionAuthorityServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"functionAuthorityService"
)
public
class
FunctionAuthorityServiceImpl
implements
FunctionAuthorityService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
FunctionAuthorityServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
FunctionAuthority
item
)
{
return
functionAuthorityMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
functionAuthorityMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
FunctionAuthority
item
)
{
return
functionAuthorityMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
FunctionAuthority
get
(
String
id
)
{
return
functionAuthorityMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
FunctionAuthorityVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
FunctionAuthorityVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
FunctionAuthorityExample
tableExampleObj
=
new
FunctionAuthorityExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
FunctionAuthority
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
FunctionAuthorityExample
exampleObj
=
new
FunctionAuthorityExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"FunctionAuthority"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
functionAuthorityMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
FunctionAuthorityExample
exampleObj
=
new
FunctionAuthorityExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"FunctionAuthority"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
FunctionAuthority
>
modelList
=
functionAuthorityMapper
.
selectByExample
(
exampleObj
);
List
<
FunctionAuthorityVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
FunctionAuthorityVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
FunctionAuthorityExample
exampleObj
=
new
FunctionAuthorityExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"FunctionAuthority"
,
filters
);
return
functionAuthorityMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
FunctionAuthorityVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
FunctionAuthorityVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/HmLogServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"hmLogService"
)
public
class
HmLogServiceImpl
implements
HmLogService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
HmLogServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
HmLog
item
)
{
return
hmLogMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
hmLogMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
HmLog
item
)
{
return
hmLogMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
HmLog
get
(
String
id
)
{
return
hmLogMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
HmLogVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
HmLogVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
HmLogExample
tableExampleObj
=
new
HmLogExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
HmLog
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
HmLogExample
exampleObj
=
new
HmLogExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"HmLog"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
hmLogMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
HmLogExample
exampleObj
=
new
HmLogExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"HmLog"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
HmLog
>
modelList
=
hmLogMapper
.
selectByExample
(
exampleObj
);
List
<
HmLogVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
HmLogVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
HmLogExample
exampleObj
=
new
HmLogExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"HmLog"
,
filters
);
return
hmLogMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
HmLogVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
HmLogVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/HmUserServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"hmUserService"
)
public
class
HmUserServiceImpl
implements
HmUserService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
HmUserServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
HmUser
item
)
{
return
hmUserMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
hmUserMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
HmUser
item
)
{
return
hmUserMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
HmUser
get
(
String
id
)
{
return
hmUserMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
HmUserVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
HmUserVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
HmUserExample
tableExampleObj
=
new
HmUserExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
HmUser
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
HmUserExample
exampleObj
=
new
HmUserExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"HmUser"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
hmUserMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
HmUserExample
exampleObj
=
new
HmUserExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"HmUser"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
HmUser
>
modelList
=
hmUserMapper
.
selectByExample
(
exampleObj
);
List
<
HmUserVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
HmUserVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
HmUserExample
exampleObj
=
new
HmUserExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"HmUser"
,
filters
);
return
hmUserMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
HmUserVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
HmUserVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/MenuServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"menuService"
)
public
class
MenuServiceImpl
implements
MenuService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MenuServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
Menu
item
)
{
return
menuMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
menuMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
Menu
item
)
{
return
menuMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
Menu
get
(
String
id
)
{
return
menuMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
MenuVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
MenuVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
MenuExample
tableExampleObj
=
new
MenuExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
Menu
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
MenuExample
exampleObj
=
new
MenuExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Menu"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
menuMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
MenuExample
exampleObj
=
new
MenuExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Menu"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
Menu
>
modelList
=
menuMapper
.
selectByExample
(
exampleObj
);
List
<
MenuVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
MenuVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
MenuExample
exampleObj
=
new
MenuExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Menu"
,
filters
);
return
menuMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
MenuVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
MenuVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/OrganizationServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"organizationService"
)
public
class
OrganizationServiceImpl
implements
OrganizationService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
OrganizationServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
Organization
item
)
{
return
organizationMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
organizationMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
Organization
item
)
{
return
organizationMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
Organization
get
(
String
id
)
{
return
organizationMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
OrganizationVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
OrganizationVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
OrganizationExample
tableExampleObj
=
new
OrganizationExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
Organization
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
OrganizationExample
exampleObj
=
new
OrganizationExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Organization"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
organizationMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
OrganizationExample
exampleObj
=
new
OrganizationExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Organization"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
Organization
>
modelList
=
organizationMapper
.
selectByExample
(
exampleObj
);
List
<
OrganizationVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
OrganizationVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
OrganizationExample
exampleObj
=
new
OrganizationExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Organization"
,
filters
);
return
organizationMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
OrganizationVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
OrganizationVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/RoleFunctionServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"roleFunctionService"
)
public
class
RoleFunctionServiceImpl
implements
RoleFunctionService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RoleFunctionServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
RoleFunction
item
)
{
return
roleFunctionMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
roleFunctionMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
RoleFunction
item
)
{
return
roleFunctionMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
RoleFunction
get
(
String
id
)
{
return
roleFunctionMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
RoleFunctionVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
RoleFunctionVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
RoleFunctionExample
tableExampleObj
=
new
RoleFunctionExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
RoleFunction
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
RoleFunctionExample
exampleObj
=
new
RoleFunctionExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"RoleFunction"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
roleFunctionMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
RoleFunctionExample
exampleObj
=
new
RoleFunctionExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"RoleFunction"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
RoleFunction
>
modelList
=
roleFunctionMapper
.
selectByExample
(
exampleObj
);
List
<
RoleFunctionVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
RoleFunctionVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
RoleFunctionExample
exampleObj
=
new
RoleFunctionExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"RoleFunction"
,
filters
);
return
roleFunctionMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
RoleFunctionVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
RoleFunctionVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/RoleMenuServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"roleMenuService"
)
public
class
RoleMenuServiceImpl
implements
RoleMenuService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RoleMenuServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
RoleMenu
item
)
{
return
roleMenuMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
roleMenuMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
RoleMenu
item
)
{
return
roleMenuMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
RoleMenu
get
(
String
id
)
{
return
roleMenuMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
RoleMenuVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
RoleMenuVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
RoleMenuExample
tableExampleObj
=
new
RoleMenuExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
RoleMenu
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
RoleMenuExample
exampleObj
=
new
RoleMenuExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"RoleMenu"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
roleMenuMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
RoleMenuExample
exampleObj
=
new
RoleMenuExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"RoleMenu"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
RoleMenu
>
modelList
=
roleMenuMapper
.
selectByExample
(
exampleObj
);
List
<
RoleMenuVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
RoleMenuVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
RoleMenuExample
exampleObj
=
new
RoleMenuExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"RoleMenu"
,
filters
);
return
roleMenuMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
RoleMenuVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
RoleMenuVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/RoleServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"roleService"
)
public
class
RoleServiceImpl
implements
RoleService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RoleServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
Role
item
)
{
return
roleMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
roleMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
Role
item
)
{
return
roleMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
Role
get
(
String
id
)
{
return
roleMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
RoleVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
RoleVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
RoleExample
tableExampleObj
=
new
RoleExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
Role
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
RoleExample
exampleObj
=
new
RoleExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Role"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
roleMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
RoleExample
exampleObj
=
new
RoleExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Role"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
Role
>
modelList
=
roleMapper
.
selectByExample
(
exampleObj
);
List
<
RoleVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
RoleVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
RoleExample
exampleObj
=
new
RoleExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"Role"
,
filters
);
return
roleMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
RoleVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
RoleVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
service/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/service/impl/ViewHmUserDepartmentRoleServiceImpl.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.JuniorSpringMVCTemplate.dao.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.vo.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.*
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.MybatisExampleHelper
;
import
org.apache.ibatis.binding.MapperProxy
;
import
org.apache.ibatis.session.RowBounds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.haomo.plugin.Page
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Proxy
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* Created by hxgqh on 2016/1/7.
*/
@Service
(
"viewHmUserDepartmentRoleService"
)
public
class
ViewHmUserDepartmentRoleServiceImpl
implements
ViewHmUserDepartmentRoleService
{
protected
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ViewHmUserDepartmentRoleServiceImpl
.
class
);
// 将所有的modelMapper注入
@Autowired
OrganizationMapper
organizationMapper
;
@Autowired
DepartmentMapper
departmentMapper
;
@Autowired
HmUserMapper
hmUserMapper
;
@Autowired
AuthTokenMapper
authTokenMapper
;
@Autowired
RoleMapper
roleMapper
;
@Autowired
RoleMenuMapper
roleMenuMapper
;
@Autowired
MenuMapper
menuMapper
;
@Autowired
FunctionAuthorityMapper
functionAuthorityMapper
;
@Autowired
RoleFunctionMapper
roleFunctionMapper
;
@Autowired
CcNotificationSettingMapper
ccNotificationSettingMapper
;
@Autowired
ViewHmUserDepartmentRoleMapper
viewHmUserDepartmentRoleMapper
;
@Autowired
HmLogMapper
hmLogMapper
;
@Autowired
CcLoggingMapper
ccLoggingMapper
;
@Override
public
int
create
(
ViewHmUserDepartmentRole
item
)
{
return
viewHmUserDepartmentRoleMapper
.
insertSelective
(
item
);
}
@Override
public
int
delete
(
String
id
)
{
return
viewHmUserDepartmentRoleMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
int
update
(
ViewHmUserDepartmentRole
item
)
{
return
viewHmUserDepartmentRoleMapper
.
updateByPrimaryKeySelective
(
item
);
}
@Override
public
ViewHmUserDepartmentRole
get
(
String
id
)
{
return
viewHmUserDepartmentRoleMapper
.
selectByPrimaryKey
(
id
);
}
private
void
assignRelates
(
String
relates
,
List
<
ViewHmUserDepartmentRoleVO
>
modelVOList
){
JSONObject
relatesObj
=
JSON
.
parseObject
(
relates
);
for
(
String
table:
relatesObj
.
keySet
())
{
for
(
ViewHmUserDepartmentRoleVO
modelVO:
modelVOList
){
List
<
String
>
joinCols
=
(
List
<
String
>)
relatesObj
.
get
(
table
);
ViewHmUserDepartmentRoleExample
tableExampleObj
=
new
ViewHmUserDepartmentRoleExample
();
Map
<
String
,
Map
<
String
,
Map
<
String
,
Object
>>>
tableFilters
=
new
HashMap
<>();
for
(
String
joinCol:
joinCols
){
Map
<
String
,
Map
<
String
,
Object
>>
column
=
new
HashMap
<>();
Method
m
=
MybatisExampleHelper
.
getMethod
(
modelVO
.
getSuperior
(),
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
joinCol
));
Map
<
String
,
Object
>
condition
=
new
HashMap
();
try
{
if
(
m
.
invoke
(
modelVO
.
getSuperior
())==
null
){
return
;
}
condition
.
put
(
"equalTo"
,
(
String
)
JSON
.
parse
(
JSON
.
toJSONString
(
m
.
invoke
(
modelVO
.
getSuperior
()))));
column
.
put
(
joinCol
,
condition
);
tableFilters
.
put
(
table
,
column
);
}
catch
(
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
toString
());
}
catch
(
IllegalAccessException
e
){
LOG
.
error
(
e
.
toString
());
}
}
MybatisExampleHelper
.
assignWhereClause
(
tableExampleObj
,
tableExampleObj
.
or
(),
table
,
JSON
.
toJSONString
(
tableFilters
));
tableExampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
"id"
,
"asc"
));
// 获取到关联表的列表
try
{
Field
mapperFieldDef
=
this
.
getClass
()
.
getDeclaredField
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Mapper"
);
mapperFieldDef
.
setAccessible
(
true
);
Object
fieldValue
=
mapperFieldDef
.
get
(
this
);
MapperProxy
proxy
=
(
MapperProxy
)
Proxy
.
getInvocationHandler
(
fieldValue
);
Method
sbewr
=
MybatisExampleHelper
.
getMethod
(
fieldValue
,
"selectByExample"
);
Page
page
=
new
Page
(
0
,
1000
);
tableExampleObj
.
setPage
(
page
);
Object
[]
args
=
new
Object
[]{
tableExampleObj
};
modelVO
.
getRelates
().
put
(
table
,
(
List
<
Object
>)(
proxy
.
invoke
(
proxy
,
sbewr
,
args
)));
}
catch
(
Throwable
e
){
LOG
.
error
(
e
.
toString
());
}
}
}
}
@Override
public
List
<
ViewHmUserDepartmentRole
>
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
){
ViewHmUserDepartmentRoleExample
exampleObj
=
new
ViewHmUserDepartmentRoleExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"ViewHmUserDepartmentRole"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
return
viewHmUserDepartmentRoleMapper
.
selectByExample
(
exampleObj
);
}
@Override
public
Object
getListWithPagingAndFilter
(
Integer
pageNo
,
Integer
pageSize
,
String
sortItem
,
String
sortOrder
,
String
filters
,
String
includes
,
String
refers
,
String
relates
){
ViewHmUserDepartmentRoleExample
exampleObj
=
new
ViewHmUserDepartmentRoleExample
();
Page
page
=
new
Page
((
pageNo
-
1
)
*
pageSize
,
pageSize
);
exampleObj
.
setPage
(
page
);
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"ViewHmUserDepartmentRole"
,
filters
);
exampleObj
.
setOrderByClause
(
MybatisExampleHelper
.
createOrderClause
(
sortItem
,
sortOrder
));
List
<
ViewHmUserDepartmentRole
>
modelList
=
viewHmUserDepartmentRoleMapper
.
selectByExample
(
exampleObj
);
List
<
ViewHmUserDepartmentRoleVO
>
modelVOList
=
modelList
.
stream
().
map
(
model
->
new
ViewHmUserDepartmentRoleVO
(
model
)).
collect
(
Collectors
.
toList
());
// 处理includes的外链字段 处理refers的关联表
if
((
includes
!=
null
||
refers
!=
null
)&&
modelList
.
size
()
>
0
){
//对Vo层数据循环处理外链表数据
modelVOList
.
stream
().
forEach
(
status
->{
if
(
includes
!=
null
){
this
.
assignIncludes
(
includes
,
status
);
}
if
(
refers
!=
null
){
this
.
assignRefers
(
refers
,
status
);
}
});
}
// 处理join的关联表
if
(
relates
!=
null
&&
modelList
.
size
()
>
0
){
this
.
assignRelates
(
relates
,
modelVOList
);
}
if
(
includes
==
null
&&
refers
==
null
&&
relates
==
null
){
return
modelList
;
}
else
{
return
modelVOList
;
}
}
@Override
public
Long
countListWithPagingAndFilter
(
String
filters
){
ViewHmUserDepartmentRoleExample
exampleObj
=
new
ViewHmUserDepartmentRoleExample
();
MybatisExampleHelper
.
assignWhereClause
(
exampleObj
,
exampleObj
.
or
(),
"ViewHmUserDepartmentRole"
,
filters
);
return
viewHmUserDepartmentRoleMapper
.
countByExample
(
exampleObj
);
}
private
void
assignIncludes
(
String
includes
,
ViewHmUserDepartmentRoleVO
status
){
JSONObject
includesObj
=
JSON
.
parseObject
(
includes
);
//定义容器存储所有外链表数据
Map
<
String
,
Object
>
map
=
new
HashMap
();
// 循环解析每一个键值对
if
(
includesObj
!=
null
&&
includesObj
.
keySet
().
size
()
>
0
){
includesObj
.
keySet
().
stream
().
forEach
(
table
->{
//每一个key都是一个po实体类名
Object
className
=
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
);
JSONObject
jsonObject
=
includesObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
//反射机制将要执行的方法名
String
ffName
=
"get"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
obj
.
toString
());
//获取Method的对象
Method
m
=
MybatisExampleHelper
.
getMethod
(
status
.
getSuperior
(),
ffName
);
MybatisExampleHelper
.
dealSearchIncludes
(
m
,
status
.
getSuperior
(),
className
,
map
,
table
,
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setIncludes
(
map
);
}
private
void
assignRefers
(
String
refers
,
ViewHmUserDepartmentRoleVO
status
){
//解析includes字符串为JSONObject
JSONObject
refersObj
=
JSON
.
parseObject
(
refers
);
//定义容器存储所有外链表数据
Map
<
String
,
List
<
Object
>>
map
=
new
HashMap
();
if
(
refersObj
!=
null
&&
refersObj
.
keySet
().
size
()
>
0
){
// 循环解析每一个键值对
refersObj
.
keySet
().
stream
().
forEach
(
table
->
{
//每一个key都是一个po实体类名
JSONObject
jsonObject
=
refersObj
.
getJSONObject
(
CaseFormat
.
UPPER_CAMEL
.
to
(
CaseFormat
.
LOWER_UNDERSCORE
,
table
));
//对内层的includes数据进行解析
JSONArray
columnCondition
=
jsonObject
.
getJSONArray
(
"includes"
);
if
(
columnCondition
!=
null
&&
columnCondition
.
toArray
().
length
>
0
){
//循环数组
Arrays
.
stream
(
columnCondition
.
toArray
()).
forEach
(
obj
->
{
MybatisExampleHelper
.
dealSearchRefers
(
status
.
getSuperior
().
getId
(),
table
,
map
,
obj
,
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
table
),
this
.
getClass
().
getPackage
().
getName
());
});
}
});
}
status
.
setRefers
(
map
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/AuthTokenController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.AuthToken
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.AuthTokenService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"身份令牌"
)
@Controller
public
class
AuthTokenController
{
@Autowired
AuthTokenService
authTokenService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'身份令牌'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/auth_tokens/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createAuthToken
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"userId"
,
required
=
false
)
String
userId
,
@RequestParam
(
value
=
"token"
,
required
=
false
)
String
tokens
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"validTime"
,
required
=
false
)
String
validTime
)
{
AuthToken
item
=
new
AuthToken
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
userId
!=
null
){
item
.
setUserId
(
userId
);
}
if
(
tokens
!=
null
){
item
.
setToken
(
token
);
}
item
.
setCreateTime
(
new
Date
());
if
(
validTime
!=
null
){
item
.
setValidTime
(
Tools
.
convertStringToDate
(
validTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
authTokenService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
authTokenService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'身份令牌'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/auth_tokens/{auth_token_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteAuthToken
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"auth_token_id"
)
String
id
)
{
AuthToken
item
=
authTokenService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
authTokenService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'身份令牌'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/auth_tokens/{auth_token_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editAuthToken
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"auth_token_id"
)
String
id
,
@RequestParam
(
value
=
"userId"
,
required
=
false
)
String
userId
,
@RequestParam
(
value
=
"token"
,
required
=
false
)
String
tokens
,
@RequestParam
(
value
=
"validTime"
,
required
=
false
)
String
validTime
)
{
AuthToken
item
=
authTokenService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
userId
!=
null
){
item
.
setUserId
(
userId
);
}
if
(
tokens
!=
null
){
item
.
setToken
(
token
);
}
if
(
validTime
!=
null
){
item
.
setValidTime
(
Tools
.
convertStringToDate
(
validTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
authTokenService
.
update
(
item
);
return
authTokenService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'身份令牌'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/auth_tokens/{auth_token_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getAuthToken
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"auth_token_id"
)
String
id
,
@RequestParam
(
value
=
"userId"
,
required
=
false
)
String
userId
,
@RequestParam
(
value
=
"token"
,
required
=
false
)
String
tokens
,
@RequestParam
(
value
=
"validTime"
,
required
=
false
)
String
validTime
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
AuthToken
item
=
authTokenService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
AuthToken
item
=
authTokenService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
userId
!=
null
){
item
.
setUserId
(
userId
);
}
if
(
tokens
!=
null
){
item
.
setToken
(
token
);
}
if
(
validTime
!=
null
){
item
.
setValidTime
(
Tools
.
convertStringToDate
(
validTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
authTokenService
.
update
(
item
);
return
authTokenService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
AuthToken
item
=
authTokenService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
authTokenService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'身份令牌'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/auth_tokens"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getAuthTokens
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
authTokenService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
authTokenService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/auth_tokens/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getAuthTokensId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
AuthToken
>
list
=
authTokenService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
AuthToken
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'身份令牌'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/auth_tokens/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsAuthTokens
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
AuthToken
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
AuthToken
item
=
new
AuthToken
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"userId"
)
){
item
.
setUserId
(
jsonObject
.
get
(
"userId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"token"
)
){
item
.
setToken
(
jsonObject
.
get
(
"token"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"validTime"
)
){
item
.
setValidTime
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"validTime"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
authTokenService
.
create
(
item
);
lists
.
add
(
authTokenService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'身份令牌'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/auth_tokens/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesAuthToken
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
AuthToken
item
=
authTokenService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
authTokenService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/CcLoggingController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.CcLogging
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.CcLoggingService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"日志记录"
)
@Controller
public
class
CcLoggingController
{
@Autowired
CcLoggingService
ccLoggingService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'日志记录'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/cc_loggings/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createCcLogging
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"operator"
,
required
=
false
)
String
operator
,
@RequestParam
(
value
=
"loginTimePeriod"
,
required
=
false
)
String
loginTimePeriod
,
@RequestParam
(
value
=
"operatingTimePeriod"
,
required
=
false
)
String
operatingTimePeriod
,
@RequestParam
(
value
=
"loginType"
,
required
=
false
)
String
loginType
,
@RequestParam
(
value
=
"typeOperation"
,
required
=
false
)
String
typeOperation
,
@RequestParam
(
value
=
"operatingModule"
,
required
=
false
)
String
operatingModule
,
@RequestParam
(
value
=
"affiliation"
,
required
=
false
)
String
affiliation
,
@RequestParam
(
value
=
"theirDepartment"
,
required
=
false
)
String
theirDepartment
,
@RequestParam
(
value
=
"logContent"
,
required
=
false
)
String
logContent
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
,
@RequestParam
(
value
=
"operatorId"
,
required
=
false
)
String
operatorId
)
{
CcLogging
item
=
new
CcLogging
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
operator
!=
null
){
item
.
setOperator
(
operator
);
}
if
(
loginTimePeriod
!=
null
){
item
.
setLoginTimePeriod
(
Tools
.
convertStringToDate
(
loginTimePeriod
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
operatingTimePeriod
!=
null
){
item
.
setOperatingTimePeriod
(
Tools
.
convertStringToDate
(
operatingTimePeriod
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
loginType
!=
null
){
item
.
setLoginType
(
loginType
);
}
if
(
typeOperation
!=
null
){
item
.
setTypeOperation
(
typeOperation
);
}
if
(
operatingModule
!=
null
){
item
.
setOperatingModule
(
operatingModule
);
}
if
(
affiliation
!=
null
){
item
.
setAffiliation
(
affiliation
);
}
if
(
theirDepartment
!=
null
){
item
.
setTheirDepartment
(
theirDepartment
);
}
if
(
logContent
!=
null
){
item
.
setLogContent
(
logContent
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
operatorId
!=
null
){
item
.
setOperatorId
(
operatorId
);
}
ccLoggingService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
ccLoggingService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'日志记录'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/cc_loggings/{cc_logging_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteCcLogging
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"cc_logging_id"
)
String
id
)
{
CcLogging
item
=
ccLoggingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
ccLoggingService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'日志记录'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/cc_loggings/{cc_logging_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editCcLogging
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"cc_logging_id"
)
String
id
,
@RequestParam
(
value
=
"operator"
,
required
=
false
)
String
operator
,
@RequestParam
(
value
=
"loginTimePeriod"
,
required
=
false
)
String
loginTimePeriod
,
@RequestParam
(
value
=
"operatingTimePeriod"
,
required
=
false
)
String
operatingTimePeriod
,
@RequestParam
(
value
=
"loginType"
,
required
=
false
)
String
loginType
,
@RequestParam
(
value
=
"typeOperation"
,
required
=
false
)
String
typeOperation
,
@RequestParam
(
value
=
"operatingModule"
,
required
=
false
)
String
operatingModule
,
@RequestParam
(
value
=
"affiliation"
,
required
=
false
)
String
affiliation
,
@RequestParam
(
value
=
"theirDepartment"
,
required
=
false
)
String
theirDepartment
,
@RequestParam
(
value
=
"logContent"
,
required
=
false
)
String
logContent
,
@RequestParam
(
value
=
"operatorId"
,
required
=
false
)
String
operatorId
)
{
CcLogging
item
=
ccLoggingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
operator
!=
null
){
item
.
setOperator
(
operator
);
}
if
(
loginTimePeriod
!=
null
){
item
.
setLoginTimePeriod
(
Tools
.
convertStringToDate
(
loginTimePeriod
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
operatingTimePeriod
!=
null
){
item
.
setOperatingTimePeriod
(
Tools
.
convertStringToDate
(
operatingTimePeriod
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
loginType
!=
null
){
item
.
setLoginType
(
loginType
);
}
if
(
typeOperation
!=
null
){
item
.
setTypeOperation
(
typeOperation
);
}
if
(
operatingModule
!=
null
){
item
.
setOperatingModule
(
operatingModule
);
}
if
(
affiliation
!=
null
){
item
.
setAffiliation
(
affiliation
);
}
if
(
theirDepartment
!=
null
){
item
.
setTheirDepartment
(
theirDepartment
);
}
if
(
logContent
!=
null
){
item
.
setLogContent
(
logContent
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
operatorId
!=
null
){
item
.
setOperatorId
(
operatorId
);
}
ccLoggingService
.
update
(
item
);
return
ccLoggingService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'日志记录'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/cc_loggings/{cc_logging_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getCcLogging
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"cc_logging_id"
)
String
id
,
@RequestParam
(
value
=
"operator"
,
required
=
false
)
String
operator
,
@RequestParam
(
value
=
"loginTimePeriod"
,
required
=
false
)
String
loginTimePeriod
,
@RequestParam
(
value
=
"operatingTimePeriod"
,
required
=
false
)
String
operatingTimePeriod
,
@RequestParam
(
value
=
"loginType"
,
required
=
false
)
String
loginType
,
@RequestParam
(
value
=
"typeOperation"
,
required
=
false
)
String
typeOperation
,
@RequestParam
(
value
=
"operatingModule"
,
required
=
false
)
String
operatingModule
,
@RequestParam
(
value
=
"affiliation"
,
required
=
false
)
String
affiliation
,
@RequestParam
(
value
=
"theirDepartment"
,
required
=
false
)
String
theirDepartment
,
@RequestParam
(
value
=
"logContent"
,
required
=
false
)
String
logContent
,
@RequestParam
(
value
=
"operatorId"
,
required
=
false
)
String
operatorId
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
CcLogging
item
=
ccLoggingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
CcLogging
item
=
ccLoggingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
operator
!=
null
){
item
.
setOperator
(
operator
);
}
if
(
loginTimePeriod
!=
null
){
item
.
setLoginTimePeriod
(
Tools
.
convertStringToDate
(
loginTimePeriod
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
operatingTimePeriod
!=
null
){
item
.
setOperatingTimePeriod
(
Tools
.
convertStringToDate
(
operatingTimePeriod
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
loginType
!=
null
){
item
.
setLoginType
(
loginType
);
}
if
(
typeOperation
!=
null
){
item
.
setTypeOperation
(
typeOperation
);
}
if
(
operatingModule
!=
null
){
item
.
setOperatingModule
(
operatingModule
);
}
if
(
affiliation
!=
null
){
item
.
setAffiliation
(
affiliation
);
}
if
(
theirDepartment
!=
null
){
item
.
setTheirDepartment
(
theirDepartment
);
}
if
(
logContent
!=
null
){
item
.
setLogContent
(
logContent
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
operatorId
!=
null
){
item
.
setOperatorId
(
operatorId
);
}
ccLoggingService
.
update
(
item
);
return
ccLoggingService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
CcLogging
item
=
ccLoggingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
ccLoggingService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'日志记录'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/cc_loggings"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getCcLoggings
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
ccLoggingService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
ccLoggingService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/cc_loggings/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getCcLoggingsId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
CcLogging
>
list
=
ccLoggingService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
CcLogging
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'日志记录'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/cc_loggings/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsCcLoggings
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
CcLogging
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
CcLogging
item
=
new
CcLogging
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"operator"
)
){
item
.
setOperator
(
jsonObject
.
get
(
"operator"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"loginTimePeriod"
)
){
item
.
setLoginTimePeriod
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"loginTimePeriod"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"operatingTimePeriod"
)
){
item
.
setOperatingTimePeriod
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"operatingTimePeriod"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"loginType"
)
){
item
.
setLoginType
(
jsonObject
.
get
(
"loginType"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"typeOperation"
)
){
item
.
setTypeOperation
(
jsonObject
.
get
(
"typeOperation"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"operatingModule"
)
){
item
.
setOperatingModule
(
jsonObject
.
get
(
"operatingModule"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"affiliation"
)
){
item
.
setAffiliation
(
jsonObject
.
get
(
"affiliation"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"theirDepartment"
)
){
item
.
setTheirDepartment
(
jsonObject
.
get
(
"theirDepartment"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"logContent"
)
){
item
.
setLogContent
(
jsonObject
.
get
(
"logContent"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"operatorId"
)
){
item
.
setOperatorId
(
jsonObject
.
get
(
"operatorId"
).
toString
());
}
ccLoggingService
.
create
(
item
);
lists
.
add
(
ccLoggingService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'日志记录'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/cc_loggings/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesCcLogging
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
CcLogging
item
=
ccLoggingService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
ccLoggingService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/CcNotificationSettingController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.CcNotificationSetting
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.CcNotificationSettingService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"通知设置"
)
@Controller
public
class
CcNotificationSettingController
{
@Autowired
CcNotificationSettingService
ccNotificationSettingService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'通知设置'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/cc_notification_settings/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createCcNotificationSetting
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"remindingTime"
,
required
=
false
)
Integer
remindingTime
,
@RequestParam
(
value
=
"type"
,
required
=
false
)
String
type
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"whetherReminding"
,
required
=
false
)
String
whetherReminding
,
@RequestParam
(
value
=
"reminderModule"
,
required
=
false
)
String
reminderModule
,
@RequestParam
(
value
=
"people"
,
required
=
false
)
String
people
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
CcNotificationSetting
item
=
new
CcNotificationSetting
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
remindingTime
!=
null
){
item
.
setRemindingTime
(
remindingTime
);
}
if
(
type
!=
null
){
item
.
setType
(
type
);
}
item
.
setCreateTime
(
new
Date
());
if
(
whetherReminding
!=
null
){
item
.
setWhetherReminding
(
whetherReminding
);
}
if
(
reminderModule
!=
null
){
item
.
setReminderModule
(
reminderModule
);
}
if
(
people
!=
null
){
item
.
setPeople
(
people
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
ccNotificationSettingService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
ccNotificationSettingService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'通知设置'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/cc_notification_settings/{cc_notification_setting_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteCcNotificationSetting
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"cc_notification_setting_id"
)
String
id
)
{
CcNotificationSetting
item
=
ccNotificationSettingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
ccNotificationSettingService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'通知设置'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/cc_notification_settings/{cc_notification_setting_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editCcNotificationSetting
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"cc_notification_setting_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"remindingTime"
,
required
=
false
)
Integer
remindingTime
,
@RequestParam
(
value
=
"type"
,
required
=
false
)
String
type
,
@RequestParam
(
value
=
"whetherReminding"
,
required
=
false
)
String
whetherReminding
,
@RequestParam
(
value
=
"reminderModule"
,
required
=
false
)
String
reminderModule
,
@RequestParam
(
value
=
"people"
,
required
=
false
)
String
people
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
CcNotificationSetting
item
=
ccNotificationSettingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
remindingTime
!=
null
){
item
.
setRemindingTime
(
remindingTime
);
}
if
(
type
!=
null
){
item
.
setType
(
type
);
}
if
(
whetherReminding
!=
null
){
item
.
setWhetherReminding
(
whetherReminding
);
}
if
(
reminderModule
!=
null
){
item
.
setReminderModule
(
reminderModule
);
}
if
(
people
!=
null
){
item
.
setPeople
(
people
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
ccNotificationSettingService
.
update
(
item
);
return
ccNotificationSettingService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'通知设置'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/cc_notification_settings/{cc_notification_setting_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getCcNotificationSetting
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"cc_notification_setting_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"remindingTime"
,
required
=
false
)
Integer
remindingTime
,
@RequestParam
(
value
=
"type"
,
required
=
false
)
String
type
,
@RequestParam
(
value
=
"whetherReminding"
,
required
=
false
)
String
whetherReminding
,
@RequestParam
(
value
=
"reminderModule"
,
required
=
false
)
String
reminderModule
,
@RequestParam
(
value
=
"people"
,
required
=
false
)
String
people
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
CcNotificationSetting
item
=
ccNotificationSettingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
CcNotificationSetting
item
=
ccNotificationSettingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
remindingTime
!=
null
){
item
.
setRemindingTime
(
remindingTime
);
}
if
(
type
!=
null
){
item
.
setType
(
type
);
}
if
(
whetherReminding
!=
null
){
item
.
setWhetherReminding
(
whetherReminding
);
}
if
(
reminderModule
!=
null
){
item
.
setReminderModule
(
reminderModule
);
}
if
(
people
!=
null
){
item
.
setPeople
(
people
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
ccNotificationSettingService
.
update
(
item
);
return
ccNotificationSettingService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
CcNotificationSetting
item
=
ccNotificationSettingService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
ccNotificationSettingService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'通知设置'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/cc_notification_settings"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getCcNotificationSettings
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
ccNotificationSettingService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
ccNotificationSettingService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/cc_notification_settings/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getCcNotificationSettingsId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
CcNotificationSetting
>
list
=
ccNotificationSettingService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
CcNotificationSetting
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'通知设置'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/cc_notification_settings/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsCcNotificationSettings
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
CcNotificationSetting
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
CcNotificationSetting
item
=
new
CcNotificationSetting
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"name"
)
){
item
.
setName
(
jsonObject
.
get
(
"name"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"remindingTime"
)
){
item
.
setRemindingTime
(
new
Integer
(
jsonObject
.
get
(
"remindingTime"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"type"
)
){
item
.
setType
(
jsonObject
.
get
(
"type"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"whetherReminding"
)
){
item
.
setWhetherReminding
(
jsonObject
.
get
(
"whetherReminding"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"reminderModule"
)
){
item
.
setReminderModule
(
jsonObject
.
get
(
"reminderModule"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"people"
)
){
item
.
setPeople
(
jsonObject
.
get
(
"people"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rank"
)
){
item
.
setRank
(
new
Integer
(
jsonObject
.
get
(
"rank"
).
toString
()));
}
ccNotificationSettingService
.
create
(
item
);
lists
.
add
(
ccNotificationSettingService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'通知设置'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/cc_notification_settings/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesCcNotificationSetting
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
CcNotificationSetting
item
=
ccNotificationSettingService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
ccNotificationSettingService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/DepartmentController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.Department
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.DepartmentService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"部门"
)
@Controller
public
class
DepartmentController
{
@Autowired
DepartmentService
departmentService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'部门'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/departments/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createDepartment
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"parentDepartmentCode"
,
required
=
false
)
String
parentDepartmentCode
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"description"
,
required
=
false
)
String
description
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
,
@RequestParam
(
value
=
"simpleName"
,
required
=
false
)
String
simpleName
,
@RequestParam
(
value
=
"organizationName"
,
required
=
false
)
String
organizationName
,
@RequestParam
(
value
=
"personLiable"
,
required
=
false
)
String
personLiable
,
@RequestParam
(
value
=
"organizationId"
,
required
=
false
)
String
organizationId
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"numberReading"
,
required
=
false
)
Integer
numberReading
,
@RequestParam
(
value
=
"personLiableName"
,
required
=
false
)
String
personLiableName
)
{
Department
item
=
new
Department
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
parentDepartmentCode
!=
null
){
item
.
setParentDepartmentCode
(
parentDepartmentCode
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
description
!=
null
){
item
.
setDescription
(
description
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
simpleName
!=
null
){
item
.
setSimpleName
(
simpleName
);
}
if
(
organizationName
!=
null
){
item
.
setOrganizationName
(
organizationName
);
}
if
(
personLiable
!=
null
){
item
.
setPersonLiable
(
personLiable
);
}
if
(
organizationId
!=
null
){
item
.
setOrganizationId
(
organizationId
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
numberReading
!=
null
){
item
.
setNumberReading
(
numberReading
);
}
if
(
personLiableName
!=
null
){
item
.
setPersonLiableName
(
personLiableName
);
}
departmentService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
departmentService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'部门'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/departments/{department_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteDepartment
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"department_id"
)
String
id
)
{
Department
item
=
departmentService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
departmentService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'部门'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/departments/{department_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editDepartment
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"department_id"
)
String
id
,
@RequestParam
(
value
=
"parentDepartmentCode"
,
required
=
false
)
String
parentDepartmentCode
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"description"
,
required
=
false
)
String
description
,
@RequestParam
(
value
=
"simpleName"
,
required
=
false
)
String
simpleName
,
@RequestParam
(
value
=
"organizationName"
,
required
=
false
)
String
organizationName
,
@RequestParam
(
value
=
"personLiable"
,
required
=
false
)
String
personLiable
,
@RequestParam
(
value
=
"organizationId"
,
required
=
false
)
String
organizationId
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"numberReading"
,
required
=
false
)
Integer
numberReading
,
@RequestParam
(
value
=
"personLiableName"
,
required
=
false
)
String
personLiableName
)
{
Department
item
=
departmentService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
parentDepartmentCode
!=
null
){
item
.
setParentDepartmentCode
(
parentDepartmentCode
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
description
!=
null
){
item
.
setDescription
(
description
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
simpleName
!=
null
){
item
.
setSimpleName
(
simpleName
);
}
if
(
organizationName
!=
null
){
item
.
setOrganizationName
(
organizationName
);
}
if
(
personLiable
!=
null
){
item
.
setPersonLiable
(
personLiable
);
}
if
(
organizationId
!=
null
){
item
.
setOrganizationId
(
organizationId
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
numberReading
!=
null
){
item
.
setNumberReading
(
numberReading
);
}
if
(
personLiableName
!=
null
){
item
.
setPersonLiableName
(
personLiableName
);
}
departmentService
.
update
(
item
);
return
departmentService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'部门'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/departments/{department_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getDepartment
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"department_id"
)
String
id
,
@RequestParam
(
value
=
"parentDepartmentCode"
,
required
=
false
)
String
parentDepartmentCode
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"description"
,
required
=
false
)
String
description
,
@RequestParam
(
value
=
"simpleName"
,
required
=
false
)
String
simpleName
,
@RequestParam
(
value
=
"organizationName"
,
required
=
false
)
String
organizationName
,
@RequestParam
(
value
=
"personLiable"
,
required
=
false
)
String
personLiable
,
@RequestParam
(
value
=
"organizationId"
,
required
=
false
)
String
organizationId
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"numberReading"
,
required
=
false
)
Integer
numberReading
,
@RequestParam
(
value
=
"personLiableName"
,
required
=
false
)
String
personLiableName
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
Department
item
=
departmentService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
Department
item
=
departmentService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
parentDepartmentCode
!=
null
){
item
.
setParentDepartmentCode
(
parentDepartmentCode
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
description
!=
null
){
item
.
setDescription
(
description
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
simpleName
!=
null
){
item
.
setSimpleName
(
simpleName
);
}
if
(
organizationName
!=
null
){
item
.
setOrganizationName
(
organizationName
);
}
if
(
personLiable
!=
null
){
item
.
setPersonLiable
(
personLiable
);
}
if
(
organizationId
!=
null
){
item
.
setOrganizationId
(
organizationId
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
numberReading
!=
null
){
item
.
setNumberReading
(
numberReading
);
}
if
(
personLiableName
!=
null
){
item
.
setPersonLiableName
(
personLiableName
);
}
departmentService
.
update
(
item
);
return
departmentService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
Department
item
=
departmentService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
departmentService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'部门'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/departments"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getDepartments
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
departmentService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
departmentService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/departments/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getDepartmentsId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
Department
>
list
=
departmentService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
Department
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'部门'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/departments/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsDepartments
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
Department
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
Department
item
=
new
Department
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"parentDepartmentCode"
)
){
item
.
setParentDepartmentCode
(
jsonObject
.
get
(
"parentDepartmentCode"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"code"
)
){
item
.
setCode
(
jsonObject
.
get
(
"code"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"name"
)
){
item
.
setName
(
jsonObject
.
get
(
"name"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"description"
)
){
item
.
setDescription
(
jsonObject
.
get
(
"description"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"simpleName"
)
){
item
.
setSimpleName
(
jsonObject
.
get
(
"simpleName"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"organizationName"
)
){
item
.
setOrganizationName
(
jsonObject
.
get
(
"organizationName"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"personLiable"
)
){
item
.
setPersonLiable
(
jsonObject
.
get
(
"personLiable"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"organizationId"
)
){
item
.
setOrganizationId
(
jsonObject
.
get
(
"organizationId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rank"
)
){
item
.
setRank
(
new
Integer
(
jsonObject
.
get
(
"rank"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"numberReading"
)
){
item
.
setNumberReading
(
new
Integer
(
jsonObject
.
get
(
"numberReading"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"personLiableName"
)
){
item
.
setPersonLiableName
(
jsonObject
.
get
(
"personLiableName"
).
toString
());
}
departmentService
.
create
(
item
);
lists
.
add
(
departmentService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'部门'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/departments/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesDepartment
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
Department
item
=
departmentService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
departmentService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/FunctionAuthorityController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.FunctionAuthority
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.FunctionAuthorityService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"功能权限"
)
@Controller
public
class
FunctionAuthorityController
{
@Autowired
FunctionAuthorityService
functionAuthorityService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'功能权限'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/function_authorities/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createFunctionAuthority
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"menuCode"
,
required
=
false
)
String
menuCode
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
,
@RequestParam
(
value
=
"createPeple"
,
required
=
false
)
String
createPeple
)
{
FunctionAuthority
item
=
new
FunctionAuthority
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
menuCode
!=
null
){
item
.
setMenuCode
(
menuCode
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
createPeple
!=
null
){
item
.
setCreatePeple
(
createPeple
);
}
functionAuthorityService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
functionAuthorityService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'功能权限'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/function_authorities/{function_authority_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteFunctionAuthority
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"function_authority_id"
)
String
id
)
{
FunctionAuthority
item
=
functionAuthorityService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
functionAuthorityService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'功能权限'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/function_authorities/{function_authority_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editFunctionAuthority
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"function_authority_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"menuCode"
,
required
=
false
)
String
menuCode
,
@RequestParam
(
value
=
"createPeple"
,
required
=
false
)
String
createPeple
)
{
FunctionAuthority
item
=
functionAuthorityService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
menuCode
!=
null
){
item
.
setMenuCode
(
menuCode
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
createPeple
!=
null
){
item
.
setCreatePeple
(
createPeple
);
}
functionAuthorityService
.
update
(
item
);
return
functionAuthorityService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'功能权限'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/function_authorities/{function_authority_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getFunctionAuthority
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"function_authority_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"menuCode"
,
required
=
false
)
String
menuCode
,
@RequestParam
(
value
=
"createPeple"
,
required
=
false
)
String
createPeple
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
FunctionAuthority
item
=
functionAuthorityService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
FunctionAuthority
item
=
functionAuthorityService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
menuCode
!=
null
){
item
.
setMenuCode
(
menuCode
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
createPeple
!=
null
){
item
.
setCreatePeple
(
createPeple
);
}
functionAuthorityService
.
update
(
item
);
return
functionAuthorityService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
FunctionAuthority
item
=
functionAuthorityService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
functionAuthorityService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'功能权限'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/function_authorities"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getFunctionAuthorities
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
functionAuthorityService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
functionAuthorityService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/function_authorities/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getFunctionAuthoritiesId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
FunctionAuthority
>
list
=
functionAuthorityService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
FunctionAuthority
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'功能权限'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/function_authorities/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsFunctionAuthorities
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
FunctionAuthority
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
FunctionAuthority
item
=
new
FunctionAuthority
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"name"
)
){
item
.
setName
(
jsonObject
.
get
(
"name"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"menuCode"
)
){
item
.
setMenuCode
(
jsonObject
.
get
(
"menuCode"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"createPeple"
)
){
item
.
setCreatePeple
(
jsonObject
.
get
(
"createPeple"
).
toString
());
}
functionAuthorityService
.
create
(
item
);
lists
.
add
(
functionAuthorityService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'功能权限'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/function_authorities/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesFunctionAuthority
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
FunctionAuthority
item
=
functionAuthorityService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
functionAuthorityService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/HmLogController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.HmLog
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmLogService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"用户日志"
)
@Controller
public
class
HmLogController
{
@Autowired
HmLogService
hmLogService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'用户日志'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/hm_logs/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createHmLog
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"userId"
,
required
=
false
)
String
userId
,
@RequestParam
(
value
=
"content"
,
required
=
false
)
String
content
,
@RequestParam
(
value
=
"operatingTime"
,
required
=
false
)
String
operatingTime
,
@RequestParam
(
value
=
"auxiliaryInspection"
,
required
=
false
)
String
auxiliaryInspection
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
,
@RequestParam
(
value
=
"updateUserId"
,
required
=
false
)
String
updateUserId
)
{
HmLog
item
=
new
HmLog
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
userId
!=
null
){
item
.
setUserId
(
userId
);
}
if
(
content
!=
null
){
item
.
setContent
(
content
);
}
if
(
operatingTime
!=
null
){
item
.
setOperatingTime
(
Tools
.
convertStringToDate
(
operatingTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
auxiliaryInspection
!=
null
){
item
.
setAuxiliaryInspection
(
auxiliaryInspection
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
updateUserId
!=
null
){
item
.
setUpdateUserId
(
updateUserId
);
}
hmLogService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
hmLogService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'用户日志'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/hm_logs/{hm_log_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteHmLog
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"hm_log_id"
)
String
id
)
{
HmLog
item
=
hmLogService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
hmLogService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'用户日志'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/hm_logs/{hm_log_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editHmLog
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"hm_log_id"
)
String
id
,
@RequestParam
(
value
=
"userId"
,
required
=
false
)
String
userId
,
@RequestParam
(
value
=
"content"
,
required
=
false
)
String
content
,
@RequestParam
(
value
=
"operatingTime"
,
required
=
false
)
String
operatingTime
,
@RequestParam
(
value
=
"auxiliaryInspection"
,
required
=
false
)
String
auxiliaryInspection
,
@RequestParam
(
value
=
"updateUserId"
,
required
=
false
)
String
updateUserId
)
{
HmLog
item
=
hmLogService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
userId
!=
null
){
item
.
setUserId
(
userId
);
}
if
(
content
!=
null
){
item
.
setContent
(
content
);
}
if
(
operatingTime
!=
null
){
item
.
setOperatingTime
(
Tools
.
convertStringToDate
(
operatingTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
auxiliaryInspection
!=
null
){
item
.
setAuxiliaryInspection
(
auxiliaryInspection
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
updateUserId
!=
null
){
item
.
setUpdateUserId
(
updateUserId
);
}
hmLogService
.
update
(
item
);
return
hmLogService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'用户日志'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/hm_logs/{hm_log_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getHmLog
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"hm_log_id"
)
String
id
,
@RequestParam
(
value
=
"userId"
,
required
=
false
)
String
userId
,
@RequestParam
(
value
=
"content"
,
required
=
false
)
String
content
,
@RequestParam
(
value
=
"operatingTime"
,
required
=
false
)
String
operatingTime
,
@RequestParam
(
value
=
"auxiliaryInspection"
,
required
=
false
)
String
auxiliaryInspection
,
@RequestParam
(
value
=
"updateUserId"
,
required
=
false
)
String
updateUserId
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
HmLog
item
=
hmLogService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
HmLog
item
=
hmLogService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
userId
!=
null
){
item
.
setUserId
(
userId
);
}
if
(
content
!=
null
){
item
.
setContent
(
content
);
}
if
(
operatingTime
!=
null
){
item
.
setOperatingTime
(
Tools
.
convertStringToDate
(
operatingTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
auxiliaryInspection
!=
null
){
item
.
setAuxiliaryInspection
(
auxiliaryInspection
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
updateUserId
!=
null
){
item
.
setUpdateUserId
(
updateUserId
);
}
hmLogService
.
update
(
item
);
return
hmLogService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
HmLog
item
=
hmLogService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
hmLogService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'用户日志'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/hm_logs"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getHmLogs
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
hmLogService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
hmLogService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/hm_logs/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getHmLogsId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
HmLog
>
list
=
hmLogService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
HmLog
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'用户日志'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/hm_logs/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsHmLogs
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
HmLog
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
HmLog
item
=
new
HmLog
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"userId"
)
){
item
.
setUserId
(
jsonObject
.
get
(
"userId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"content"
)
){
item
.
setContent
(
jsonObject
.
get
(
"content"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"operatingTime"
)
){
item
.
setOperatingTime
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"operatingTime"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"auxiliaryInspection"
)
){
item
.
setAuxiliaryInspection
(
jsonObject
.
get
(
"auxiliaryInspection"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"updateUserId"
)
){
item
.
setUpdateUserId
(
jsonObject
.
get
(
"updateUserId"
).
toString
());
}
hmLogService
.
create
(
item
);
lists
.
add
(
hmLogService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'用户日志'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/hm_logs/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesHmLog
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
HmLog
item
=
hmLogService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
hmLogService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/HmUserController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.HmUser
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUserService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"用户表"
)
@Controller
public
class
HmUserController
{
@Autowired
HmUserService
hmUserService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'用户表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/hm_users/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createHmUser
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"username"
,
required
=
false
)
String
username
,
@RequestParam
(
value
=
"loginid"
,
required
=
false
)
String
loginid
,
@RequestParam
(
value
=
"password"
,
required
=
false
)
String
password
,
@RequestParam
(
value
=
"mobile"
,
required
=
false
)
String
mobile
,
@RequestParam
(
value
=
"email"
,
required
=
false
)
String
email
,
@RequestParam
(
value
=
"avatar"
,
required
=
false
)
String
avatar
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
,
@RequestParam
(
value
=
"lastLoginTime"
,
required
=
false
)
String
lastLoginTime
,
@RequestParam
(
value
=
"departmentCode"
,
required
=
false
)
String
departmentCode
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"meetingRemindingTime"
,
required
=
false
)
Integer
meetingRemindingTime
,
@RequestParam
(
value
=
"jobTitle"
,
required
=
false
)
String
jobTitle
,
@RequestParam
(
value
=
"phoneNumber"
,
required
=
false
)
String
phoneNumber
,
@RequestParam
(
value
=
"phoneNumberSpare"
,
required
=
false
)
String
phoneNumberSpare
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"community"
,
required
=
false
)
String
community
,
@RequestParam
(
value
=
"enable"
,
required
=
false
)
String
enable
,
@RequestParam
(
value
=
"hide"
,
required
=
false
)
String
hide
,
@RequestParam
(
value
=
"departmentId"
,
required
=
false
)
String
departmentId
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
)
{
HmUser
item
=
new
HmUser
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
username
!=
null
){
item
.
setUsername
(
username
);
}
if
(
loginid
!=
null
){
item
.
setLoginid
(
loginid
);
}
if
(
password
!=
null
){
item
.
setPassword
(
password
);
}
if
(
mobile
!=
null
){
item
.
setMobile
(
mobile
);
}
if
(
email
!=
null
){
item
.
setEmail
(
email
);
}
if
(
avatar
!=
null
){
item
.
setAvatar
(
avatar
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
lastLoginTime
!=
null
){
item
.
setLastLoginTime
(
Tools
.
convertStringToDate
(
lastLoginTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
departmentCode
!=
null
){
item
.
setDepartmentCode
(
departmentCode
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
meetingRemindingTime
!=
null
){
item
.
setMeetingRemindingTime
(
meetingRemindingTime
);
}
if
(
jobTitle
!=
null
){
item
.
setJobTitle
(
jobTitle
);
}
if
(
phoneNumber
!=
null
){
item
.
setPhoneNumber
(
phoneNumber
);
}
if
(
phoneNumberSpare
!=
null
){
item
.
setPhoneNumberSpare
(
phoneNumberSpare
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
community
!=
null
){
item
.
setCommunity
(
community
);
}
if
(
enable
!=
null
){
item
.
setEnable
(
enable
);
}
if
(
hide
!=
null
){
item
.
setHide
(
hide
);
}
if
(
departmentId
!=
null
){
item
.
setDepartmentId
(
departmentId
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
hmUserService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
hmUserService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'用户表'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/hm_users/{hm_user_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteHmUser
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"hm_user_id"
)
String
id
)
{
HmUser
item
=
hmUserService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
hmUserService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'用户表'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/hm_users/{hm_user_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editHmUser
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"hm_user_id"
)
String
id
,
@RequestParam
(
value
=
"username"
,
required
=
false
)
String
username
,
@RequestParam
(
value
=
"loginid"
,
required
=
false
)
String
loginid
,
@RequestParam
(
value
=
"password"
,
required
=
false
)
String
password
,
@RequestParam
(
value
=
"mobile"
,
required
=
false
)
String
mobile
,
@RequestParam
(
value
=
"email"
,
required
=
false
)
String
email
,
@RequestParam
(
value
=
"avatar"
,
required
=
false
)
String
avatar
,
@RequestParam
(
value
=
"lastLoginTime"
,
required
=
false
)
String
lastLoginTime
,
@RequestParam
(
value
=
"departmentCode"
,
required
=
false
)
String
departmentCode
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"meetingRemindingTime"
,
required
=
false
)
Integer
meetingRemindingTime
,
@RequestParam
(
value
=
"jobTitle"
,
required
=
false
)
String
jobTitle
,
@RequestParam
(
value
=
"phoneNumber"
,
required
=
false
)
String
phoneNumber
,
@RequestParam
(
value
=
"phoneNumberSpare"
,
required
=
false
)
String
phoneNumberSpare
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"community"
,
required
=
false
)
String
community
,
@RequestParam
(
value
=
"enable"
,
required
=
false
)
String
enable
,
@RequestParam
(
value
=
"hide"
,
required
=
false
)
String
hide
,
@RequestParam
(
value
=
"departmentId"
,
required
=
false
)
String
departmentId
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
)
{
HmUser
item
=
hmUserService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
username
!=
null
){
item
.
setUsername
(
username
);
}
if
(
loginid
!=
null
){
item
.
setLoginid
(
loginid
);
}
if
(
password
!=
null
){
item
.
setPassword
(
password
);
}
if
(
mobile
!=
null
){
item
.
setMobile
(
mobile
);
}
if
(
email
!=
null
){
item
.
setEmail
(
email
);
}
if
(
avatar
!=
null
){
item
.
setAvatar
(
avatar
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
lastLoginTime
!=
null
){
item
.
setLastLoginTime
(
Tools
.
convertStringToDate
(
lastLoginTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
departmentCode
!=
null
){
item
.
setDepartmentCode
(
departmentCode
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
meetingRemindingTime
!=
null
){
item
.
setMeetingRemindingTime
(
meetingRemindingTime
);
}
if
(
jobTitle
!=
null
){
item
.
setJobTitle
(
jobTitle
);
}
if
(
phoneNumber
!=
null
){
item
.
setPhoneNumber
(
phoneNumber
);
}
if
(
phoneNumberSpare
!=
null
){
item
.
setPhoneNumberSpare
(
phoneNumberSpare
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
community
!=
null
){
item
.
setCommunity
(
community
);
}
if
(
enable
!=
null
){
item
.
setEnable
(
enable
);
}
if
(
hide
!=
null
){
item
.
setHide
(
hide
);
}
if
(
departmentId
!=
null
){
item
.
setDepartmentId
(
departmentId
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
hmUserService
.
update
(
item
);
return
hmUserService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'用户表'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/hm_users/{hm_user_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getHmUser
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"hm_user_id"
)
String
id
,
@RequestParam
(
value
=
"username"
,
required
=
false
)
String
username
,
@RequestParam
(
value
=
"loginid"
,
required
=
false
)
String
loginid
,
@RequestParam
(
value
=
"password"
,
required
=
false
)
String
password
,
@RequestParam
(
value
=
"mobile"
,
required
=
false
)
String
mobile
,
@RequestParam
(
value
=
"email"
,
required
=
false
)
String
email
,
@RequestParam
(
value
=
"avatar"
,
required
=
false
)
String
avatar
,
@RequestParam
(
value
=
"lastLoginTime"
,
required
=
false
)
String
lastLoginTime
,
@RequestParam
(
value
=
"departmentCode"
,
required
=
false
)
String
departmentCode
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"meetingRemindingTime"
,
required
=
false
)
Integer
meetingRemindingTime
,
@RequestParam
(
value
=
"jobTitle"
,
required
=
false
)
String
jobTitle
,
@RequestParam
(
value
=
"phoneNumber"
,
required
=
false
)
String
phoneNumber
,
@RequestParam
(
value
=
"phoneNumberSpare"
,
required
=
false
)
String
phoneNumberSpare
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"community"
,
required
=
false
)
String
community
,
@RequestParam
(
value
=
"enable"
,
required
=
false
)
String
enable
,
@RequestParam
(
value
=
"hide"
,
required
=
false
)
String
hide
,
@RequestParam
(
value
=
"departmentId"
,
required
=
false
)
String
departmentId
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
HmUser
item
=
hmUserService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
HmUser
item
=
hmUserService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
username
!=
null
){
item
.
setUsername
(
username
);
}
if
(
loginid
!=
null
){
item
.
setLoginid
(
loginid
);
}
if
(
password
!=
null
){
item
.
setPassword
(
password
);
}
if
(
mobile
!=
null
){
item
.
setMobile
(
mobile
);
}
if
(
email
!=
null
){
item
.
setEmail
(
email
);
}
if
(
avatar
!=
null
){
item
.
setAvatar
(
avatar
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
lastLoginTime
!=
null
){
item
.
setLastLoginTime
(
Tools
.
convertStringToDate
(
lastLoginTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
departmentCode
!=
null
){
item
.
setDepartmentCode
(
departmentCode
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
meetingRemindingTime
!=
null
){
item
.
setMeetingRemindingTime
(
meetingRemindingTime
);
}
if
(
jobTitle
!=
null
){
item
.
setJobTitle
(
jobTitle
);
}
if
(
phoneNumber
!=
null
){
item
.
setPhoneNumber
(
phoneNumber
);
}
if
(
phoneNumberSpare
!=
null
){
item
.
setPhoneNumberSpare
(
phoneNumberSpare
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
community
!=
null
){
item
.
setCommunity
(
community
);
}
if
(
enable
!=
null
){
item
.
setEnable
(
enable
);
}
if
(
hide
!=
null
){
item
.
setHide
(
hide
);
}
if
(
departmentId
!=
null
){
item
.
setDepartmentId
(
departmentId
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
hmUserService
.
update
(
item
);
return
hmUserService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
HmUser
item
=
hmUserService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
hmUserService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'用户表'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/hm_users"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getHmUsers
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
hmUserService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
hmUserService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/hm_users/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getHmUsersId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
HmUser
>
list
=
hmUserService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
HmUser
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'用户表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/hm_users/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsHmUsers
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
HmUser
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
HmUser
item
=
new
HmUser
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"username"
)
){
item
.
setUsername
(
jsonObject
.
get
(
"username"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"loginid"
)
){
item
.
setLoginid
(
jsonObject
.
get
(
"loginid"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"password"
)
){
item
.
setPassword
(
jsonObject
.
get
(
"password"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"mobile"
)
){
item
.
setMobile
(
jsonObject
.
get
(
"mobile"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"email"
)
){
item
.
setEmail
(
jsonObject
.
get
(
"email"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"avatar"
)
){
item
.
setAvatar
(
jsonObject
.
get
(
"avatar"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"lastLoginTime"
)
){
item
.
setLastLoginTime
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"lastLoginTime"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"departmentCode"
)
){
item
.
setDepartmentCode
(
jsonObject
.
get
(
"departmentCode"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"roleId"
)
){
item
.
setRoleId
(
jsonObject
.
get
(
"roleId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"meetingRemindingTime"
)
){
item
.
setMeetingRemindingTime
(
new
Integer
(
jsonObject
.
get
(
"meetingRemindingTime"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"jobTitle"
)
){
item
.
setJobTitle
(
jsonObject
.
get
(
"jobTitle"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"phoneNumber"
)
){
item
.
setPhoneNumber
(
jsonObject
.
get
(
"phoneNumber"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"phoneNumberSpare"
)
){
item
.
setPhoneNumberSpare
(
jsonObject
.
get
(
"phoneNumberSpare"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rank"
)
){
item
.
setRank
(
new
Integer
(
jsonObject
.
get
(
"rank"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"community"
)
){
item
.
setCommunity
(
jsonObject
.
get
(
"community"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"enable"
)
){
item
.
setEnable
(
jsonObject
.
get
(
"enable"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"hide"
)
){
item
.
setHide
(
jsonObject
.
get
(
"hide"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"departmentId"
)
){
item
.
setDepartmentId
(
jsonObject
.
get
(
"departmentId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"code"
)
){
item
.
setCode
(
jsonObject
.
get
(
"code"
).
toString
());
}
hmUserService
.
create
(
item
);
lists
.
add
(
hmUserService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'用户表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/hm_users/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesHmUser
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
HmUser
item
=
hmUserService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
hmUserService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/MenuController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.Menu
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.MenuService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"菜单"
)
@Controller
public
class
MenuController
{
@Autowired
MenuService
menuService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'菜单'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/menus/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createMenu
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"menuLogo"
,
required
=
false
)
String
menuLogo
,
@RequestParam
(
value
=
"superiorMenuId"
,
required
=
false
)
String
superiorMenuId
,
@RequestParam
(
value
=
"grade"
,
required
=
false
)
Integer
grade
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"link"
,
required
=
false
)
String
link
,
@RequestParam
(
value
=
"type"
,
required
=
false
)
String
type
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
Menu
item
=
new
Menu
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
menuLogo
!=
null
){
item
.
setMenuLogo
(
menuLogo
);
}
if
(
superiorMenuId
!=
null
){
item
.
setSuperiorMenuId
(
superiorMenuId
);
}
if
(
grade
!=
null
){
item
.
setGrade
(
grade
);
}
item
.
setCreateTime
(
new
Date
());
if
(
link
!=
null
){
item
.
setLink
(
link
);
}
if
(
type
!=
null
){
item
.
setType
(
type
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
menuService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
menuService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'菜单'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/menus/{menu_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteMenu
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"menu_id"
)
String
id
)
{
Menu
item
=
menuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
menuService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'菜单'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/menus/{menu_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editMenu
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"menu_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"menuLogo"
,
required
=
false
)
String
menuLogo
,
@RequestParam
(
value
=
"superiorMenuId"
,
required
=
false
)
String
superiorMenuId
,
@RequestParam
(
value
=
"grade"
,
required
=
false
)
Integer
grade
,
@RequestParam
(
value
=
"link"
,
required
=
false
)
String
link
,
@RequestParam
(
value
=
"type"
,
required
=
false
)
String
type
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
Menu
item
=
menuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
menuLogo
!=
null
){
item
.
setMenuLogo
(
menuLogo
);
}
if
(
superiorMenuId
!=
null
){
item
.
setSuperiorMenuId
(
superiorMenuId
);
}
if
(
grade
!=
null
){
item
.
setGrade
(
grade
);
}
if
(
link
!=
null
){
item
.
setLink
(
link
);
}
if
(
type
!=
null
){
item
.
setType
(
type
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
menuService
.
update
(
item
);
return
menuService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'菜单'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/menus/{menu_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getMenu
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"menu_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"menuLogo"
,
required
=
false
)
String
menuLogo
,
@RequestParam
(
value
=
"superiorMenuId"
,
required
=
false
)
String
superiorMenuId
,
@RequestParam
(
value
=
"grade"
,
required
=
false
)
Integer
grade
,
@RequestParam
(
value
=
"link"
,
required
=
false
)
String
link
,
@RequestParam
(
value
=
"type"
,
required
=
false
)
String
type
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
Menu
item
=
menuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
Menu
item
=
menuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
menuLogo
!=
null
){
item
.
setMenuLogo
(
menuLogo
);
}
if
(
superiorMenuId
!=
null
){
item
.
setSuperiorMenuId
(
superiorMenuId
);
}
if
(
grade
!=
null
){
item
.
setGrade
(
grade
);
}
if
(
link
!=
null
){
item
.
setLink
(
link
);
}
if
(
type
!=
null
){
item
.
setType
(
type
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
menuService
.
update
(
item
);
return
menuService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
Menu
item
=
menuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
menuService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'菜单'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/menus"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getMenus
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
menuService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
menuService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/menus/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getMenusId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
Menu
>
list
=
menuService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
Menu
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'菜单'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/menus/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsMenus
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
Menu
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
Menu
item
=
new
Menu
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"name"
)
){
item
.
setName
(
jsonObject
.
get
(
"name"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"menuLogo"
)
){
item
.
setMenuLogo
(
jsonObject
.
get
(
"menuLogo"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"superiorMenuId"
)
){
item
.
setSuperiorMenuId
(
jsonObject
.
get
(
"superiorMenuId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"grade"
)
){
item
.
setGrade
(
new
Integer
(
jsonObject
.
get
(
"grade"
).
toString
()));
}
item
.
setCreateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"link"
)
){
item
.
setLink
(
jsonObject
.
get
(
"link"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"type"
)
){
item
.
setType
(
jsonObject
.
get
(
"type"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rank"
)
){
item
.
setRank
(
new
Integer
(
jsonObject
.
get
(
"rank"
).
toString
()));
}
menuService
.
create
(
item
);
lists
.
add
(
menuService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'菜单'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/menus/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesMenu
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
Menu
item
=
menuService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
menuService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/OrganizationController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.Organization
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.OrganizationService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"组织社区"
)
@Controller
public
class
OrganizationController
{
@Autowired
OrganizationService
organizationService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'组织社区'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/organizations/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createOrganization
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"createPeple"
,
required
=
false
)
String
createPeple
,
@RequestParam
(
value
=
"linkToken"
,
required
=
false
)
String
linkToken
,
@RequestParam
(
value
=
"whetherInside"
,
required
=
false
)
String
whetherInside
,
@RequestParam
(
value
=
"communityId"
,
required
=
false
)
String
communityId
)
{
Organization
item
=
new
Organization
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
name
!=
null
){
item
.
setName
(
name
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
createPeple
!=
null
){
item
.
setCreatePeple
(
createPeple
);
}
if
(
linkToken
!=
null
){
item
.
setLinkToken
(
linkToken
);
}
if
(
whetherInside
!=
null
){
item
.
setWhetherInside
(
whetherInside
);
}
if
(
communityId
!=
null
){
item
.
setCommunityId
(
communityId
);
}
organizationService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
organizationService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'组织社区'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/organizations/{organization_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteOrganization
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"organization_id"
)
String
id
)
{
Organization
item
=
organizationService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
organizationService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'组织社区'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/organizations/{organization_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editOrganization
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"organization_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"createPeple"
,
required
=
false
)
String
createPeple
,
@RequestParam
(
value
=
"linkToken"
,
required
=
false
)
String
linkToken
,
@RequestParam
(
value
=
"whetherInside"
,
required
=
false
)
String
whetherInside
,
@RequestParam
(
value
=
"communityId"
,
required
=
false
)
String
communityId
)
{
Organization
item
=
organizationService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
createPeple
!=
null
){
item
.
setCreatePeple
(
createPeple
);
}
if
(
linkToken
!=
null
){
item
.
setLinkToken
(
linkToken
);
}
if
(
whetherInside
!=
null
){
item
.
setWhetherInside
(
whetherInside
);
}
if
(
communityId
!=
null
){
item
.
setCommunityId
(
communityId
);
}
organizationService
.
update
(
item
);
return
organizationService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'组织社区'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/organizations/{organization_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getOrganization
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"organization_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"createPeple"
,
required
=
false
)
String
createPeple
,
@RequestParam
(
value
=
"linkToken"
,
required
=
false
)
String
linkToken
,
@RequestParam
(
value
=
"whetherInside"
,
required
=
false
)
String
whetherInside
,
@RequestParam
(
value
=
"communityId"
,
required
=
false
)
String
communityId
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
Organization
item
=
organizationService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
Organization
item
=
organizationService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
createPeple
!=
null
){
item
.
setCreatePeple
(
createPeple
);
}
if
(
linkToken
!=
null
){
item
.
setLinkToken
(
linkToken
);
}
if
(
whetherInside
!=
null
){
item
.
setWhetherInside
(
whetherInside
);
}
if
(
communityId
!=
null
){
item
.
setCommunityId
(
communityId
);
}
organizationService
.
update
(
item
);
return
organizationService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
Organization
item
=
organizationService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
organizationService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'组织社区'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/organizations"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getOrganizations
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
organizationService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
organizationService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/organizations/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getOrganizationsId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
Organization
>
list
=
organizationService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
Organization
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'组织社区'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/organizations/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsOrganizations
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
Organization
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
Organization
item
=
new
Organization
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"name"
)
){
item
.
setName
(
jsonObject
.
get
(
"name"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"rank"
)
){
item
.
setRank
(
new
Integer
(
jsonObject
.
get
(
"rank"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"createPeple"
)
){
item
.
setCreatePeple
(
jsonObject
.
get
(
"createPeple"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"linkToken"
)
){
item
.
setLinkToken
(
jsonObject
.
get
(
"linkToken"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"whetherInside"
)
){
item
.
setWhetherInside
(
jsonObject
.
get
(
"whetherInside"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"communityId"
)
){
item
.
setCommunityId
(
jsonObject
.
get
(
"communityId"
).
toString
());
}
organizationService
.
create
(
item
);
lists
.
add
(
organizationService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'组织社区'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/organizations/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesOrganization
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
Organization
item
=
organizationService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
organizationService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/RoleController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.Role
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.RoleService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"角色"
)
@Controller
public
class
RoleController
{
@Autowired
RoleService
roleService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'角色'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/roles/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createRole
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"description"
,
required
=
false
)
String
description
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"grade"
,
required
=
false
)
Integer
grade
,
@RequestParam
(
value
=
"abbreviation"
,
required
=
false
)
String
abbreviation
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
Role
item
=
new
Role
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
description
!=
null
){
item
.
setDescription
(
description
);
}
item
.
setCreateTime
(
new
Date
());
if
(
grade
!=
null
){
item
.
setGrade
(
grade
);
}
if
(
abbreviation
!=
null
){
item
.
setAbbreviation
(
abbreviation
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
roleService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
roleService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'角色'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/roles/{role_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteRole
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_id"
)
String
id
)
{
Role
item
=
roleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
roleService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'角色'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/roles/{role_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editRole
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"description"
,
required
=
false
)
String
description
,
@RequestParam
(
value
=
"grade"
,
required
=
false
)
Integer
grade
,
@RequestParam
(
value
=
"abbreviation"
,
required
=
false
)
String
abbreviation
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
Role
item
=
roleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
description
!=
null
){
item
.
setDescription
(
description
);
}
if
(
grade
!=
null
){
item
.
setGrade
(
grade
);
}
if
(
abbreviation
!=
null
){
item
.
setAbbreviation
(
abbreviation
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
roleService
.
update
(
item
);
return
roleService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'角色'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/roles/{role_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRole
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_id"
)
String
id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
value
=
"description"
,
required
=
false
)
String
description
,
@RequestParam
(
value
=
"grade"
,
required
=
false
)
Integer
grade
,
@RequestParam
(
value
=
"abbreviation"
,
required
=
false
)
String
abbreviation
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
Role
item
=
roleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
Role
item
=
roleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
name
!=
null
){
item
.
setName
(
name
);
}
if
(
description
!=
null
){
item
.
setDescription
(
description
);
}
if
(
grade
!=
null
){
item
.
setGrade
(
grade
);
}
if
(
abbreviation
!=
null
){
item
.
setAbbreviation
(
abbreviation
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
roleService
.
update
(
item
);
return
roleService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
Role
item
=
roleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
roleService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'角色'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/roles"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRoles
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
roleService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
roleService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/roles/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRolesId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
Role
>
list
=
roleService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
Role
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'角色'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/roles/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsRoles
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
Role
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
Role
item
=
new
Role
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"name"
)
){
item
.
setName
(
jsonObject
.
get
(
"name"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"description"
)
){
item
.
setDescription
(
jsonObject
.
get
(
"description"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"grade"
)
){
item
.
setGrade
(
new
Integer
(
jsonObject
.
get
(
"grade"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"abbreviation"
)
){
item
.
setAbbreviation
(
jsonObject
.
get
(
"abbreviation"
).
toString
());
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"rank"
)
){
item
.
setRank
(
new
Integer
(
jsonObject
.
get
(
"rank"
).
toString
()));
}
roleService
.
create
(
item
);
lists
.
add
(
roleService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'角色'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/roles/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesRole
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
Role
item
=
roleService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
roleService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/RoleFunctionController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.RoleFunction
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.RoleFunctionService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"角色功能关系表"
)
@Controller
public
class
RoleFunctionController
{
@Autowired
RoleFunctionService
roleFunctionService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'角色功能关系表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/role_functions/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createRoleFunction
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"functionId"
,
required
=
false
)
String
functionId
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
)
{
RoleFunction
item
=
new
RoleFunction
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
functionId
!=
null
){
item
.
setFunctionId
(
functionId
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
roleFunctionService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
roleFunctionService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'角色功能关系表'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/role_functions/{role_function_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteRoleFunction
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_function_id"
)
String
id
)
{
RoleFunction
item
=
roleFunctionService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
roleFunctionService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'角色功能关系表'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/role_functions/{role_function_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editRoleFunction
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_function_id"
)
String
id
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"functionId"
,
required
=
false
)
String
functionId
)
{
RoleFunction
item
=
roleFunctionService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
functionId
!=
null
){
item
.
setFunctionId
(
functionId
);
}
item
.
setLastUpdateTime
(
new
Date
());
roleFunctionService
.
update
(
item
);
return
roleFunctionService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'角色功能关系表'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/role_functions/{role_function_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRoleFunction
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_function_id"
)
String
id
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"functionId"
,
required
=
false
)
String
functionId
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
RoleFunction
item
=
roleFunctionService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
RoleFunction
item
=
roleFunctionService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
functionId
!=
null
){
item
.
setFunctionId
(
functionId
);
}
item
.
setLastUpdateTime
(
new
Date
());
roleFunctionService
.
update
(
item
);
return
roleFunctionService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
RoleFunction
item
=
roleFunctionService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
roleFunctionService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'角色功能关系表'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/role_functions"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRoleFunctions
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
roleFunctionService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
roleFunctionService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/role_functions/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRoleFunctionsId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
RoleFunction
>
list
=
roleFunctionService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
RoleFunction
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'角色功能关系表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/role_functions/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsRoleFunctions
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
RoleFunction
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
RoleFunction
item
=
new
RoleFunction
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"roleId"
)
){
item
.
setRoleId
(
jsonObject
.
get
(
"roleId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"functionId"
)
){
item
.
setFunctionId
(
jsonObject
.
get
(
"functionId"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
roleFunctionService
.
create
(
item
);
lists
.
add
(
roleFunctionService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'角色功能关系表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/role_functions/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesRoleFunction
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
RoleFunction
item
=
roleFunctionService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
roleFunctionService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/RoleMenuController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.RoleMenu
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.RoleMenuService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"角色菜单关系表"
)
@Controller
public
class
RoleMenuController
{
@Autowired
RoleMenuService
roleMenuService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'角色菜单关系表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/role_menus/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createRoleMenu
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"menuId"
,
required
=
false
)
String
menuId
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
)
{
RoleMenu
item
=
new
RoleMenu
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
menuId
!=
null
){
item
.
setMenuId
(
menuId
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
roleMenuService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
roleMenuService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'角色菜单关系表'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/role_menus/{role_menu_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteRoleMenu
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_menu_id"
)
String
id
)
{
RoleMenu
item
=
roleMenuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
roleMenuService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'角色菜单关系表'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/role_menus/{role_menu_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editRoleMenu
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_menu_id"
)
String
id
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"menuId"
,
required
=
false
)
String
menuId
)
{
RoleMenu
item
=
roleMenuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
menuId
!=
null
){
item
.
setMenuId
(
menuId
);
}
item
.
setLastUpdateTime
(
new
Date
());
roleMenuService
.
update
(
item
);
return
roleMenuService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'角色菜单关系表'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/role_menus/{role_menu_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRoleMenu
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"role_menu_id"
)
String
id
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"menuId"
,
required
=
false
)
String
menuId
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
RoleMenu
item
=
roleMenuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
RoleMenu
item
=
roleMenuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
menuId
!=
null
){
item
.
setMenuId
(
menuId
);
}
item
.
setLastUpdateTime
(
new
Date
());
roleMenuService
.
update
(
item
);
return
roleMenuService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
RoleMenu
item
=
roleMenuService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
roleMenuService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'角色菜单关系表'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/role_menus"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRoleMenus
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
roleMenuService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
roleMenuService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/role_menus/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getRoleMenusId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
RoleMenu
>
list
=
roleMenuService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
RoleMenu
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'角色菜单关系表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/role_menus/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsRoleMenus
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
RoleMenu
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
RoleMenu
item
=
new
RoleMenu
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"roleId"
)
){
item
.
setRoleId
(
jsonObject
.
get
(
"roleId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"menuId"
)
){
item
.
setMenuId
(
jsonObject
.
get
(
"menuId"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
roleMenuService
.
create
(
item
);
lists
.
add
(
roleMenuService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'角色菜单关系表'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/role_menus/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesRoleMenu
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
RoleMenu
item
=
roleMenuService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
roleMenuService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
web/src/main/java/com/haomostudio/JuniorSpringMVCTemplate/controller/ViewHmUserDepartmentRoleController.java
deleted
100644 → 0
View file @
f6ba40f4
package
com
.
haomostudio
.
JuniorSpringMVCTemplate
.
controller
;
import
com.haomostudio.JuniorSpringMVCTemplate.common.Resp
;
import
com.haomostudio.JuniorSpringMVCTemplate.po.ViewHmUserDepartmentRole
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.ViewHmUserDepartmentRoleService
;
import
com.haomostudio.JuniorSpringMVCTemplate.service.HmUtils.Tools
;
import
com.alibaba.fastjson.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.InvocationTargetException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* Created by hxg on 2016/10/06.
*/
@Api
(
description
=
"用户部门角色视图"
)
@Controller
public
class
ViewHmUserDepartmentRoleController
{
@Autowired
ViewHmUserDepartmentRoleService
viewHmUserDepartmentRoleService
;
@Autowired
HttpServletResponse
response
;
@ApiOperation
(
value
=
"创建'用户部门角色视图'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/view_hm_user_department_roles/new"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createViewHmUserDepartmentRole
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@RequestParam
(
value
=
"username"
,
required
=
false
)
String
username
,
@RequestParam
(
value
=
"loginid"
,
required
=
false
)
String
loginid
,
@RequestParam
(
value
=
"password"
,
required
=
false
)
String
password
,
@RequestParam
(
value
=
"mobile"
,
required
=
false
)
String
mobile
,
@RequestParam
(
value
=
"email"
,
required
=
false
)
String
email
,
@RequestParam
(
value
=
"avatar"
,
required
=
false
)
String
avatar
,
@RequestParam
(
value
=
"createTime"
,
required
=
false
)
String
createTime
,
@RequestParam
(
value
=
"lastUpdateTime"
,
required
=
false
)
String
lastUpdateTime
,
@RequestParam
(
value
=
"lastLoginTime"
,
required
=
false
)
String
lastLoginTime
,
@RequestParam
(
value
=
"departmentCode"
,
required
=
false
)
String
departmentCode
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"meetingRemindingTime"
,
required
=
false
)
Integer
meetingRemindingTime
,
@RequestParam
(
value
=
"jobTitle"
,
required
=
false
)
String
jobTitle
,
@RequestParam
(
value
=
"phoneNumber"
,
required
=
false
)
String
phoneNumber
,
@RequestParam
(
value
=
"phoneNumberSpare"
,
required
=
false
)
String
phoneNumberSpare
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"community"
,
required
=
false
)
String
community
,
@RequestParam
(
value
=
"enable"
,
required
=
false
)
String
enable
,
@RequestParam
(
value
=
"hide"
,
required
=
false
)
String
hide
,
@RequestParam
(
value
=
"departmentId"
,
required
=
false
)
String
departmentId
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"depId"
,
required
=
false
)
String
depId
,
@RequestParam
(
value
=
"depParentDepartmentCode"
,
required
=
false
)
String
depParentDepartmentCode
,
@RequestParam
(
value
=
"depCode"
,
required
=
false
)
String
depCode
,
@RequestParam
(
value
=
"depName"
,
required
=
false
)
String
depName
,
@RequestParam
(
value
=
"depDescription"
,
required
=
false
)
String
depDescription
,
@RequestParam
(
value
=
"depCreateTime"
,
required
=
false
)
String
depCreateTime
,
@RequestParam
(
value
=
"depLastUpdateTime"
,
required
=
false
)
String
depLastUpdateTime
,
@RequestParam
(
value
=
"depSimpleName"
,
required
=
false
)
String
depSimpleName
,
@RequestParam
(
value
=
"depOrganizationName"
,
required
=
false
)
String
depOrganizationName
,
@RequestParam
(
value
=
"depPersonLiable"
,
required
=
false
)
String
depPersonLiable
,
@RequestParam
(
value
=
"depOrganizationId"
,
required
=
false
)
String
depOrganizationId
,
@RequestParam
(
value
=
"depRank"
,
required
=
false
)
Integer
depRank
,
@RequestParam
(
value
=
"depNumberReading"
,
required
=
false
)
Integer
depNumberReading
,
@RequestParam
(
value
=
"depPersonLiableName"
,
required
=
false
)
String
depPersonLiableName
,
@RequestParam
(
value
=
"rolId"
,
required
=
false
)
String
rolId
,
@RequestParam
(
value
=
"rolName"
,
required
=
false
)
String
rolName
,
@RequestParam
(
value
=
"rolDescription"
,
required
=
false
)
String
rolDescription
,
@RequestParam
(
value
=
"rolCreateTime"
,
required
=
false
)
String
rolCreateTime
,
@RequestParam
(
value
=
"rolGrade"
,
required
=
false
)
Integer
rolGrade
,
@RequestParam
(
value
=
"rolAbbreviation"
,
required
=
false
)
String
rolAbbreviation
,
@RequestParam
(
value
=
"rolLastUpdateTime"
,
required
=
false
)
String
rolLastUpdateTime
,
@RequestParam
(
value
=
"rolRank"
,
required
=
false
)
Integer
rolRank
)
{
ViewHmUserDepartmentRole
item
=
new
ViewHmUserDepartmentRole
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
username
!=
null
){
item
.
setUsername
(
username
);
}
if
(
loginid
!=
null
){
item
.
setLoginid
(
loginid
);
}
if
(
password
!=
null
){
item
.
setPassword
(
password
);
}
if
(
mobile
!=
null
){
item
.
setMobile
(
mobile
);
}
if
(
email
!=
null
){
item
.
setEmail
(
email
);
}
if
(
avatar
!=
null
){
item
.
setAvatar
(
avatar
);
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
lastLoginTime
!=
null
){
item
.
setLastLoginTime
(
Tools
.
convertStringToDate
(
lastLoginTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
departmentCode
!=
null
){
item
.
setDepartmentCode
(
departmentCode
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
meetingRemindingTime
!=
null
){
item
.
setMeetingRemindingTime
(
meetingRemindingTime
);
}
if
(
jobTitle
!=
null
){
item
.
setJobTitle
(
jobTitle
);
}
if
(
phoneNumber
!=
null
){
item
.
setPhoneNumber
(
phoneNumber
);
}
if
(
phoneNumberSpare
!=
null
){
item
.
setPhoneNumberSpare
(
phoneNumberSpare
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
community
!=
null
){
item
.
setCommunity
(
community
);
}
if
(
enable
!=
null
){
item
.
setEnable
(
enable
);
}
if
(
hide
!=
null
){
item
.
setHide
(
hide
);
}
if
(
departmentId
!=
null
){
item
.
setDepartmentId
(
departmentId
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
if
(
depId
!=
null
){
item
.
setDepId
(
depId
);
}
if
(
depParentDepartmentCode
!=
null
){
item
.
setDepParentDepartmentCode
(
depParentDepartmentCode
);
}
if
(
depCode
!=
null
){
item
.
setDepCode
(
depCode
);
}
if
(
depName
!=
null
){
item
.
setDepName
(
depName
);
}
if
(
depDescription
!=
null
){
item
.
setDepDescription
(
depDescription
);
}
if
(
depCreateTime
!=
null
){
item
.
setDepCreateTime
(
Tools
.
convertStringToDate
(
depCreateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
depLastUpdateTime
!=
null
){
item
.
setDepLastUpdateTime
(
Tools
.
convertStringToDate
(
depLastUpdateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
depSimpleName
!=
null
){
item
.
setDepSimpleName
(
depSimpleName
);
}
if
(
depOrganizationName
!=
null
){
item
.
setDepOrganizationName
(
depOrganizationName
);
}
if
(
depPersonLiable
!=
null
){
item
.
setDepPersonLiable
(
depPersonLiable
);
}
if
(
depOrganizationId
!=
null
){
item
.
setDepOrganizationId
(
depOrganizationId
);
}
if
(
depRank
!=
null
){
item
.
setDepRank
(
depRank
);
}
if
(
depNumberReading
!=
null
){
item
.
setDepNumberReading
(
depNumberReading
);
}
if
(
depPersonLiableName
!=
null
){
item
.
setDepPersonLiableName
(
depPersonLiableName
);
}
if
(
rolId
!=
null
){
item
.
setRolId
(
rolId
);
}
if
(
rolName
!=
null
){
item
.
setRolName
(
rolName
);
}
if
(
rolDescription
!=
null
){
item
.
setRolDescription
(
rolDescription
);
}
if
(
rolCreateTime
!=
null
){
item
.
setRolCreateTime
(
Tools
.
convertStringToDate
(
rolCreateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
rolGrade
!=
null
){
item
.
setRolGrade
(
rolGrade
);
}
if
(
rolAbbreviation
!=
null
){
item
.
setRolAbbreviation
(
rolAbbreviation
);
}
if
(
rolLastUpdateTime
!=
null
){
item
.
setRolLastUpdateTime
(
Tools
.
convertStringToDate
(
rolLastUpdateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
rolRank
!=
null
){
item
.
setRolRank
(
rolRank
);
}
viewHmUserDepartmentRoleService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
return
viewHmUserDepartmentRoleService
.
get
(
id
);
//return item;
}
@ApiOperation
(
value
=
"删除'用户部门角色视图'表中的某条记录"
,
notes
=
"根据url传入的数据id,删除整条记录。"
)
@RequestMapping
(
value
=
"/view_hm_user_department_roles/{view_hm_user_department_role_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteViewHmUserDepartmentRole
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"view_hm_user_department_role_id"
)
String
id
)
{
ViewHmUserDepartmentRole
item
=
viewHmUserDepartmentRoleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
viewHmUserDepartmentRoleService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@ApiOperation
(
value
=
"修改'用户部门角色视图'表中的某条记录"
,
notes
=
"根据url传入的数据id,确定修改表中的某条记录,传入表中字段要修改的信息,不传代表不修改。并返回给View层"
)
@RequestMapping
(
value
=
"/view_hm_user_department_roles/{view_hm_user_department_role_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editViewHmUserDepartmentRole
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"view_hm_user_department_role_id"
)
String
id
,
@RequestParam
(
value
=
"username"
,
required
=
false
)
String
username
,
@RequestParam
(
value
=
"loginid"
,
required
=
false
)
String
loginid
,
@RequestParam
(
value
=
"password"
,
required
=
false
)
String
password
,
@RequestParam
(
value
=
"mobile"
,
required
=
false
)
String
mobile
,
@RequestParam
(
value
=
"email"
,
required
=
false
)
String
email
,
@RequestParam
(
value
=
"avatar"
,
required
=
false
)
String
avatar
,
@RequestParam
(
value
=
"lastLoginTime"
,
required
=
false
)
String
lastLoginTime
,
@RequestParam
(
value
=
"departmentCode"
,
required
=
false
)
String
departmentCode
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"meetingRemindingTime"
,
required
=
false
)
Integer
meetingRemindingTime
,
@RequestParam
(
value
=
"jobTitle"
,
required
=
false
)
String
jobTitle
,
@RequestParam
(
value
=
"phoneNumber"
,
required
=
false
)
String
phoneNumber
,
@RequestParam
(
value
=
"phoneNumberSpare"
,
required
=
false
)
String
phoneNumberSpare
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"community"
,
required
=
false
)
String
community
,
@RequestParam
(
value
=
"enable"
,
required
=
false
)
String
enable
,
@RequestParam
(
value
=
"hide"
,
required
=
false
)
String
hide
,
@RequestParam
(
value
=
"departmentId"
,
required
=
false
)
String
departmentId
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"depId"
,
required
=
false
)
String
depId
,
@RequestParam
(
value
=
"depParentDepartmentCode"
,
required
=
false
)
String
depParentDepartmentCode
,
@RequestParam
(
value
=
"depCode"
,
required
=
false
)
String
depCode
,
@RequestParam
(
value
=
"depName"
,
required
=
false
)
String
depName
,
@RequestParam
(
value
=
"depDescription"
,
required
=
false
)
String
depDescription
,
@RequestParam
(
value
=
"depCreateTime"
,
required
=
false
)
String
depCreateTime
,
@RequestParam
(
value
=
"depLastUpdateTime"
,
required
=
false
)
String
depLastUpdateTime
,
@RequestParam
(
value
=
"depSimpleName"
,
required
=
false
)
String
depSimpleName
,
@RequestParam
(
value
=
"depOrganizationName"
,
required
=
false
)
String
depOrganizationName
,
@RequestParam
(
value
=
"depPersonLiable"
,
required
=
false
)
String
depPersonLiable
,
@RequestParam
(
value
=
"depOrganizationId"
,
required
=
false
)
String
depOrganizationId
,
@RequestParam
(
value
=
"depRank"
,
required
=
false
)
Integer
depRank
,
@RequestParam
(
value
=
"depNumberReading"
,
required
=
false
)
Integer
depNumberReading
,
@RequestParam
(
value
=
"depPersonLiableName"
,
required
=
false
)
String
depPersonLiableName
,
@RequestParam
(
value
=
"rolId"
,
required
=
false
)
String
rolId
,
@RequestParam
(
value
=
"rolName"
,
required
=
false
)
String
rolName
,
@RequestParam
(
value
=
"rolDescription"
,
required
=
false
)
String
rolDescription
,
@RequestParam
(
value
=
"rolCreateTime"
,
required
=
false
)
String
rolCreateTime
,
@RequestParam
(
value
=
"rolGrade"
,
required
=
false
)
Integer
rolGrade
,
@RequestParam
(
value
=
"rolAbbreviation"
,
required
=
false
)
String
rolAbbreviation
,
@RequestParam
(
value
=
"rolLastUpdateTime"
,
required
=
false
)
String
rolLastUpdateTime
,
@RequestParam
(
value
=
"rolRank"
,
required
=
false
)
Integer
rolRank
)
{
ViewHmUserDepartmentRole
item
=
viewHmUserDepartmentRoleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
username
!=
null
){
item
.
setUsername
(
username
);
}
if
(
loginid
!=
null
){
item
.
setLoginid
(
loginid
);
}
if
(
password
!=
null
){
item
.
setPassword
(
password
);
}
if
(
mobile
!=
null
){
item
.
setMobile
(
mobile
);
}
if
(
email
!=
null
){
item
.
setEmail
(
email
);
}
if
(
avatar
!=
null
){
item
.
setAvatar
(
avatar
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
lastLoginTime
!=
null
){
item
.
setLastLoginTime
(
Tools
.
convertStringToDate
(
lastLoginTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
departmentCode
!=
null
){
item
.
setDepartmentCode
(
departmentCode
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
meetingRemindingTime
!=
null
){
item
.
setMeetingRemindingTime
(
meetingRemindingTime
);
}
if
(
jobTitle
!=
null
){
item
.
setJobTitle
(
jobTitle
);
}
if
(
phoneNumber
!=
null
){
item
.
setPhoneNumber
(
phoneNumber
);
}
if
(
phoneNumberSpare
!=
null
){
item
.
setPhoneNumberSpare
(
phoneNumberSpare
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
community
!=
null
){
item
.
setCommunity
(
community
);
}
if
(
enable
!=
null
){
item
.
setEnable
(
enable
);
}
if
(
hide
!=
null
){
item
.
setHide
(
hide
);
}
if
(
departmentId
!=
null
){
item
.
setDepartmentId
(
departmentId
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
if
(
depId
!=
null
){
item
.
setDepId
(
depId
);
}
if
(
depParentDepartmentCode
!=
null
){
item
.
setDepParentDepartmentCode
(
depParentDepartmentCode
);
}
if
(
depCode
!=
null
){
item
.
setDepCode
(
depCode
);
}
if
(
depName
!=
null
){
item
.
setDepName
(
depName
);
}
if
(
depDescription
!=
null
){
item
.
setDepDescription
(
depDescription
);
}
if
(
depCreateTime
!=
null
){
item
.
setDepCreateTime
(
Tools
.
convertStringToDate
(
depCreateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
depLastUpdateTime
!=
null
){
item
.
setDepLastUpdateTime
(
Tools
.
convertStringToDate
(
depLastUpdateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
depSimpleName
!=
null
){
item
.
setDepSimpleName
(
depSimpleName
);
}
if
(
depOrganizationName
!=
null
){
item
.
setDepOrganizationName
(
depOrganizationName
);
}
if
(
depPersonLiable
!=
null
){
item
.
setDepPersonLiable
(
depPersonLiable
);
}
if
(
depOrganizationId
!=
null
){
item
.
setDepOrganizationId
(
depOrganizationId
);
}
if
(
depRank
!=
null
){
item
.
setDepRank
(
depRank
);
}
if
(
depNumberReading
!=
null
){
item
.
setDepNumberReading
(
depNumberReading
);
}
if
(
depPersonLiableName
!=
null
){
item
.
setDepPersonLiableName
(
depPersonLiableName
);
}
if
(
rolId
!=
null
){
item
.
setRolId
(
rolId
);
}
if
(
rolName
!=
null
){
item
.
setRolName
(
rolName
);
}
if
(
rolDescription
!=
null
){
item
.
setRolDescription
(
rolDescription
);
}
if
(
rolCreateTime
!=
null
){
item
.
setRolCreateTime
(
Tools
.
convertStringToDate
(
rolCreateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
rolGrade
!=
null
){
item
.
setRolGrade
(
rolGrade
);
}
if
(
rolAbbreviation
!=
null
){
item
.
setRolAbbreviation
(
rolAbbreviation
);
}
if
(
rolLastUpdateTime
!=
null
){
item
.
setRolLastUpdateTime
(
Tools
.
convertStringToDate
(
rolLastUpdateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
rolRank
!=
null
){
item
.
setRolRank
(
rolRank
);
}
viewHmUserDepartmentRoleService
.
update
(
item
);
return
viewHmUserDepartmentRoleService
.
get
(
id
);
}
@ApiOperation
(
value
=
"查询'用户部门角色视图'表中的某条记录"
,
notes
=
"根据url传入的数据id,查询对应的一条数据。"
)
@RequestMapping
(
value
=
"/view_hm_user_department_roles/{view_hm_user_department_role_id}"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
PUT
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getViewHmUserDepartmentRole
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"view_hm_user_department_role_id"
)
String
id
,
@RequestParam
(
value
=
"username"
,
required
=
false
)
String
username
,
@RequestParam
(
value
=
"loginid"
,
required
=
false
)
String
loginid
,
@RequestParam
(
value
=
"password"
,
required
=
false
)
String
password
,
@RequestParam
(
value
=
"mobile"
,
required
=
false
)
String
mobile
,
@RequestParam
(
value
=
"email"
,
required
=
false
)
String
email
,
@RequestParam
(
value
=
"avatar"
,
required
=
false
)
String
avatar
,
@RequestParam
(
value
=
"lastLoginTime"
,
required
=
false
)
String
lastLoginTime
,
@RequestParam
(
value
=
"departmentCode"
,
required
=
false
)
String
departmentCode
,
@RequestParam
(
value
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
value
=
"meetingRemindingTime"
,
required
=
false
)
Integer
meetingRemindingTime
,
@RequestParam
(
value
=
"jobTitle"
,
required
=
false
)
String
jobTitle
,
@RequestParam
(
value
=
"phoneNumber"
,
required
=
false
)
String
phoneNumber
,
@RequestParam
(
value
=
"phoneNumberSpare"
,
required
=
false
)
String
phoneNumberSpare
,
@RequestParam
(
value
=
"rank"
,
required
=
false
)
Integer
rank
,
@RequestParam
(
value
=
"community"
,
required
=
false
)
String
community
,
@RequestParam
(
value
=
"enable"
,
required
=
false
)
String
enable
,
@RequestParam
(
value
=
"hide"
,
required
=
false
)
String
hide
,
@RequestParam
(
value
=
"departmentId"
,
required
=
false
)
String
departmentId
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"depId"
,
required
=
false
)
String
depId
,
@RequestParam
(
value
=
"depParentDepartmentCode"
,
required
=
false
)
String
depParentDepartmentCode
,
@RequestParam
(
value
=
"depCode"
,
required
=
false
)
String
depCode
,
@RequestParam
(
value
=
"depName"
,
required
=
false
)
String
depName
,
@RequestParam
(
value
=
"depDescription"
,
required
=
false
)
String
depDescription
,
@RequestParam
(
value
=
"depCreateTime"
,
required
=
false
)
String
depCreateTime
,
@RequestParam
(
value
=
"depLastUpdateTime"
,
required
=
false
)
String
depLastUpdateTime
,
@RequestParam
(
value
=
"depSimpleName"
,
required
=
false
)
String
depSimpleName
,
@RequestParam
(
value
=
"depOrganizationName"
,
required
=
false
)
String
depOrganizationName
,
@RequestParam
(
value
=
"depPersonLiable"
,
required
=
false
)
String
depPersonLiable
,
@RequestParam
(
value
=
"depOrganizationId"
,
required
=
false
)
String
depOrganizationId
,
@RequestParam
(
value
=
"depRank"
,
required
=
false
)
Integer
depRank
,
@RequestParam
(
value
=
"depNumberReading"
,
required
=
false
)
Integer
depNumberReading
,
@RequestParam
(
value
=
"depPersonLiableName"
,
required
=
false
)
String
depPersonLiableName
,
@RequestParam
(
value
=
"rolId"
,
required
=
false
)
String
rolId
,
@RequestParam
(
value
=
"rolName"
,
required
=
false
)
String
rolName
,
@RequestParam
(
value
=
"rolDescription"
,
required
=
false
)
String
rolDescription
,
@RequestParam
(
value
=
"rolCreateTime"
,
required
=
false
)
String
rolCreateTime
,
@RequestParam
(
value
=
"rolGrade"
,
required
=
false
)
Integer
rolGrade
,
@RequestParam
(
value
=
"rolAbbreviation"
,
required
=
false
)
String
rolAbbreviation
,
@RequestParam
(
value
=
"rolLastUpdateTime"
,
required
=
false
)
String
rolLastUpdateTime
,
@RequestParam
(
value
=
"rolRank"
,
required
=
false
)
Integer
rolRank
)
{
if
(
request
.
getMethod
().
equals
(
"GET"
)){
ViewHmUserDepartmentRole
item
=
viewHmUserDepartmentRoleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
else
if
(
request
.
getMethod
().
equals
(
"PUT"
)){
ViewHmUserDepartmentRole
item
=
viewHmUserDepartmentRoleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
if
(
username
!=
null
){
item
.
setUsername
(
username
);
}
if
(
loginid
!=
null
){
item
.
setLoginid
(
loginid
);
}
if
(
password
!=
null
){
item
.
setPassword
(
password
);
}
if
(
mobile
!=
null
){
item
.
setMobile
(
mobile
);
}
if
(
email
!=
null
){
item
.
setEmail
(
email
);
}
if
(
avatar
!=
null
){
item
.
setAvatar
(
avatar
);
}
item
.
setLastUpdateTime
(
new
Date
());
if
(
lastLoginTime
!=
null
){
item
.
setLastLoginTime
(
Tools
.
convertStringToDate
(
lastLoginTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
departmentCode
!=
null
){
item
.
setDepartmentCode
(
departmentCode
);
}
if
(
roleId
!=
null
){
item
.
setRoleId
(
roleId
);
}
if
(
meetingRemindingTime
!=
null
){
item
.
setMeetingRemindingTime
(
meetingRemindingTime
);
}
if
(
jobTitle
!=
null
){
item
.
setJobTitle
(
jobTitle
);
}
if
(
phoneNumber
!=
null
){
item
.
setPhoneNumber
(
phoneNumber
);
}
if
(
phoneNumberSpare
!=
null
){
item
.
setPhoneNumberSpare
(
phoneNumberSpare
);
}
if
(
rank
!=
null
){
item
.
setRank
(
rank
);
}
if
(
community
!=
null
){
item
.
setCommunity
(
community
);
}
if
(
enable
!=
null
){
item
.
setEnable
(
enable
);
}
if
(
hide
!=
null
){
item
.
setHide
(
hide
);
}
if
(
departmentId
!=
null
){
item
.
setDepartmentId
(
departmentId
);
}
if
(
code
!=
null
){
item
.
setCode
(
code
);
}
if
(
depId
!=
null
){
item
.
setDepId
(
depId
);
}
if
(
depParentDepartmentCode
!=
null
){
item
.
setDepParentDepartmentCode
(
depParentDepartmentCode
);
}
if
(
depCode
!=
null
){
item
.
setDepCode
(
depCode
);
}
if
(
depName
!=
null
){
item
.
setDepName
(
depName
);
}
if
(
depDescription
!=
null
){
item
.
setDepDescription
(
depDescription
);
}
if
(
depCreateTime
!=
null
){
item
.
setDepCreateTime
(
Tools
.
convertStringToDate
(
depCreateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
depLastUpdateTime
!=
null
){
item
.
setDepLastUpdateTime
(
Tools
.
convertStringToDate
(
depLastUpdateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
depSimpleName
!=
null
){
item
.
setDepSimpleName
(
depSimpleName
);
}
if
(
depOrganizationName
!=
null
){
item
.
setDepOrganizationName
(
depOrganizationName
);
}
if
(
depPersonLiable
!=
null
){
item
.
setDepPersonLiable
(
depPersonLiable
);
}
if
(
depOrganizationId
!=
null
){
item
.
setDepOrganizationId
(
depOrganizationId
);
}
if
(
depRank
!=
null
){
item
.
setDepRank
(
depRank
);
}
if
(
depNumberReading
!=
null
){
item
.
setDepNumberReading
(
depNumberReading
);
}
if
(
depPersonLiableName
!=
null
){
item
.
setDepPersonLiableName
(
depPersonLiableName
);
}
if
(
rolId
!=
null
){
item
.
setRolId
(
rolId
);
}
if
(
rolName
!=
null
){
item
.
setRolName
(
rolName
);
}
if
(
rolDescription
!=
null
){
item
.
setRolDescription
(
rolDescription
);
}
if
(
rolCreateTime
!=
null
){
item
.
setRolCreateTime
(
Tools
.
convertStringToDate
(
rolCreateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
rolGrade
!=
null
){
item
.
setRolGrade
(
rolGrade
);
}
if
(
rolAbbreviation
!=
null
){
item
.
setRolAbbreviation
(
rolAbbreviation
);
}
if
(
rolLastUpdateTime
!=
null
){
item
.
setRolLastUpdateTime
(
Tools
.
convertStringToDate
(
rolLastUpdateTime
,
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
rolRank
!=
null
){
item
.
setRolRank
(
rolRank
);
}
viewHmUserDepartmentRoleService
.
update
(
item
);
return
viewHmUserDepartmentRoleService
.
get
(
id
);
}
else
if
(
request
.
getMethod
().
equals
(
"DELETE"
)){
ViewHmUserDepartmentRole
item
=
viewHmUserDepartmentRoleService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
viewHmUserDepartmentRoleService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
return
Resp
.
fail
(
"Unknown http method"
);
}
@ApiOperation
(
value
=
"查询'用户部门角色视图'表中的多条记录或者新增某条记录"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。数据数量取决于pageNo和pageSize;数据的先后顺序取决于sortItem,sortOrder; post请求:新增某条记录,传入表字段对应的值"
)
@RequestMapping
(
value
=
"/view_hm_user_department_roles"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getViewHmUserDepartmentRoles
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"filters"
,
required
=
false
)
String
filters
,
@RequestParam
(
value
=
"includes"
,
required
=
false
)
String
includes
,
@RequestParam
(
value
=
"refers"
,
required
=
false
)
String
refers
,
@RequestParam
(
value
=
"relates"
,
required
=
false
)
String
relates
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
filters
==
null
){
filters
=
"{}"
;
}
Long
total
=
viewHmUserDepartmentRoleService
.
countListWithPagingAndFilter
(
filters
);
response
.
addHeader
(
"total"
,
String
.
valueOf
(
total
));
return
viewHmUserDepartmentRoleService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
,
includes
,
refers
,
relates
);
}
@ApiOperation
(
value
=
"出入字段数组返回对应字段数据"
,
notes
=
"get传参:根据url传入的filters(过滤条件),查询对应的多条数据。只返回你传进来的字段对应的数据"
)
@RequestMapping
(
value
=
"/view_hm_user_department_roles/columns"
,
method
=
{
RequestMethod
.
GET
},
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getViewHmUserDepartmentRolesId
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"filters"
,
required
=
true
)
String
filters
,
@RequestParam
(
value
=
"columns"
,
required
=
true
)
String
columns
,
@RequestParam
(
value
=
"sortOrder"
,
required
=
false
)
String
sortOrder
,
@RequestParam
(
value
=
"sortItem"
,
required
=
false
)
String
sortItem
,
@RequestParam
(
value
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
required
=
false
)
Integer
pageSize
)
{
if
(
pageNo
==
null
){
pageNo
=
1
;
}
if
(
pageSize
==
null
){
pageSize
=
10
;
}
if
(
sortOrder
==
null
){
sortOrder
=
"asc"
;
}
if
(
sortItem
==
null
){
sortItem
=
"id"
;
}
JSONArray
jsonArray
=
JSON
.
parseArray
(
columns
);
List
<
Map
<
String
,
Object
>>
lists
=
new
ArrayList
<>();
List
<
ViewHmUserDepartmentRole
>
list
=
viewHmUserDepartmentRoleService
.
getListWithPagingAndFilter
(
pageNo
,
pageSize
,
sortItem
,
sortOrder
,
filters
);
//反射调取get方法
Class
clz
=
ViewHmUserDepartmentRole
.
class
;
list
.
stream
().
forEach
(
lot
->{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
Object
j
:
jsonArray
){
String
s
=
(
String
)
j
;
s
=
s
.
replaceFirst
(
s
.
substring
(
0
,
1
),
s
.
substring
(
0
,
1
).
toUpperCase
());
try
{
if
(
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
)
!=
null
){
map
.
put
((
String
)
j
,
clz
.
getMethod
(
"get"
+
s
).
invoke
(
lot
));
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
lists
.
add
(
map
);
});
return
lists
;
}
@ApiOperation
(
value
=
"批量创建'用户部门角色视图'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/view_hm_user_department_roles/create//batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
createsViewHmUserDepartmentRoles
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"params"
,
required
=
false
)
String
params
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
params
);
List
<
ViewHmUserDepartmentRole
>
lists
=
new
ArrayList
<>();
jsonArray
.
stream
().
forEach
((
Object
object
)
->
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
object
.
toString
());
ViewHmUserDepartmentRole
item
=
new
ViewHmUserDepartmentRole
();
String
id
=
Tools
.
getUUID
();
item
.
setId
(
id
);
if
(
jsonObject
.
containsKey
(
"username"
)
){
item
.
setUsername
(
jsonObject
.
get
(
"username"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"loginid"
)
){
item
.
setLoginid
(
jsonObject
.
get
(
"loginid"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"password"
)
){
item
.
setPassword
(
jsonObject
.
get
(
"password"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"mobile"
)
){
item
.
setMobile
(
jsonObject
.
get
(
"mobile"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"email"
)
){
item
.
setEmail
(
jsonObject
.
get
(
"email"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"avatar"
)
){
item
.
setAvatar
(
jsonObject
.
get
(
"avatar"
).
toString
());
}
item
.
setCreateTime
(
new
Date
());
item
.
setLastUpdateTime
(
new
Date
());
if
(
jsonObject
.
containsKey
(
"lastLoginTime"
)
){
item
.
setLastLoginTime
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"lastLoginTime"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"departmentCode"
)
){
item
.
setDepartmentCode
(
jsonObject
.
get
(
"departmentCode"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"roleId"
)
){
item
.
setRoleId
(
jsonObject
.
get
(
"roleId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"meetingRemindingTime"
)
){
item
.
setMeetingRemindingTime
(
new
Integer
(
jsonObject
.
get
(
"meetingRemindingTime"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"jobTitle"
)
){
item
.
setJobTitle
(
jsonObject
.
get
(
"jobTitle"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"phoneNumber"
)
){
item
.
setPhoneNumber
(
jsonObject
.
get
(
"phoneNumber"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"phoneNumberSpare"
)
){
item
.
setPhoneNumberSpare
(
jsonObject
.
get
(
"phoneNumberSpare"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rank"
)
){
item
.
setRank
(
new
Integer
(
jsonObject
.
get
(
"rank"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"community"
)
){
item
.
setCommunity
(
jsonObject
.
get
(
"community"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"enable"
)
){
item
.
setEnable
(
jsonObject
.
get
(
"enable"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"hide"
)
){
item
.
setHide
(
jsonObject
.
get
(
"hide"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"departmentId"
)
){
item
.
setDepartmentId
(
jsonObject
.
get
(
"departmentId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"code"
)
){
item
.
setCode
(
jsonObject
.
get
(
"code"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depId"
)
){
item
.
setDepId
(
jsonObject
.
get
(
"depId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depParentDepartmentCode"
)
){
item
.
setDepParentDepartmentCode
(
jsonObject
.
get
(
"depParentDepartmentCode"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depCode"
)
){
item
.
setDepCode
(
jsonObject
.
get
(
"depCode"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depName"
)
){
item
.
setDepName
(
jsonObject
.
get
(
"depName"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depDescription"
)
){
item
.
setDepDescription
(
jsonObject
.
get
(
"depDescription"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depCreateTime"
)
){
item
.
setDepCreateTime
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"depCreateTime"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"depLastUpdateTime"
)
){
item
.
setDepLastUpdateTime
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"depLastUpdateTime"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"depSimpleName"
)
){
item
.
setDepSimpleName
(
jsonObject
.
get
(
"depSimpleName"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depOrganizationName"
)
){
item
.
setDepOrganizationName
(
jsonObject
.
get
(
"depOrganizationName"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depPersonLiable"
)
){
item
.
setDepPersonLiable
(
jsonObject
.
get
(
"depPersonLiable"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depOrganizationId"
)
){
item
.
setDepOrganizationId
(
jsonObject
.
get
(
"depOrganizationId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"depRank"
)
){
item
.
setDepRank
(
new
Integer
(
jsonObject
.
get
(
"depRank"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"depNumberReading"
)
){
item
.
setDepNumberReading
(
new
Integer
(
jsonObject
.
get
(
"depNumberReading"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"depPersonLiableName"
)
){
item
.
setDepPersonLiableName
(
jsonObject
.
get
(
"depPersonLiableName"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rolId"
)
){
item
.
setRolId
(
jsonObject
.
get
(
"rolId"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rolName"
)
){
item
.
setRolName
(
jsonObject
.
get
(
"rolName"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rolDescription"
)
){
item
.
setRolDescription
(
jsonObject
.
get
(
"rolDescription"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rolCreateTime"
)
){
item
.
setRolCreateTime
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"rolCreateTime"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"rolGrade"
)
){
item
.
setRolGrade
(
new
Integer
(
jsonObject
.
get
(
"rolGrade"
).
toString
()));
}
if
(
jsonObject
.
containsKey
(
"rolAbbreviation"
)
){
item
.
setRolAbbreviation
(
jsonObject
.
get
(
"rolAbbreviation"
).
toString
());
}
if
(
jsonObject
.
containsKey
(
"rolLastUpdateTime"
)
){
item
.
setRolLastUpdateTime
(
Tools
.
convertStringToDate
(
jsonObject
.
get
(
"rolLastUpdateTime"
).
toString
(),
"yyyy-MM-dd HH:mm:ss"
));
}
if
(
jsonObject
.
containsKey
(
"rolRank"
)
){
item
.
setRolRank
(
new
Integer
(
jsonObject
.
get
(
"rolRank"
).
toString
()));
}
viewHmUserDepartmentRoleService
.
create
(
item
);
lists
.
add
(
viewHmUserDepartmentRoleService
.
get
(
id
));
});
return
lists
;
}
@ApiOperation
(
value
=
"批量删除'用户部门角色视图'表中一条信息"
,
notes
=
"通过post方法请求,传入表中字段的对应信息,创建一条数据。并返回给View层"
)
@RequestMapping
(
value
=
"/view_hm_user_department_roles/delete/batch"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deletesViewHmUserDepartmentRole
(
HttpServletRequest
request
,
@RequestHeader
(
value
=
"X-Auth-Token"
,
required
=
false
)
String
token
,
@RequestParam
(
value
=
"ids"
,
required
=
true
)
String
ids
)
{
JSONArray
jsonArray
=
JSON
.
parseArray
(
ids
);
jsonArray
.
stream
().
forEach
(
id
->{
ViewHmUserDepartmentRole
item
=
viewHmUserDepartmentRoleService
.
get
(
id
.
toString
());
if
(
null
!=
item
)
{
viewHmUserDepartmentRoleService
.
delete
(
id
.
toString
());
}
});
return
Resp
.
succ
(
"delete success"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment