Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 33a7dc33
authored
Oct 08, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into develop
2 parents
dff89591
a30807c5
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
306 additions
and
104 deletions
project-interface/src/main/java/com/dituhui/pea/pojo/UserInfo.java
project-interface/src/main/java/com/dituhui/pea/pojo/UserInfoSearch.java
project-interface/src/main/java/com/dituhui/pea/pojo/user/OrgInfo.java
project-interface/src/main/java/com/dituhui/pea/user/IRole.java
project-interface/src/main/java/com/dituhui/pea/user/IUser.java
project-user/pom.xml
project-user/src/main/java/com/dituhui/pea/user/Application.java
project-user/src/main/java/com/dituhui/pea/user/controller/RoleController.java
project-user/src/main/java/com/dituhui/pea/user/controller/UserController.java
project-user/src/main/java/com/dituhui/pea/user/dao/UserOrgDao.java
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity.java
project-user/src/main/java/com/dituhui/pea/user/entity/UserEntity.java
project-user/src/main/java/com/dituhui/pea/user/service/RoleService.java
project-user/src/main/java/com/dituhui/pea/user/service/UserService.java
project-user/src/main/resources/application.yaml
project-interface/src/main/java/com/dituhui/pea/pojo/UserInfo.java
View file @
33a7dc3
...
...
@@ -78,7 +78,7 @@ public class UserInfo {
/**
* 最后登录时间
*/
//
private Date lastLoginTime;
private
Date
lastLoginTime
;
/**
* 用户自定义条件
*/
...
...
@@ -98,18 +98,43 @@ public class UserInfo {
/**
* 创建人
*/
//
private String createdBy;
private
String
createdBy
;
/**
* 创建时间
*/
//
private Date createdTime;
private
Date
createdTime
;
/**
* 更新人
*/
//
private String updatedBy;
private
String
updatedBy
;
/**
* 更新时间
*/
// private Date updatedTime;
private
Date
updatedTime
;
/**
* 是否禁用 0: 否 1:是 默认0
*/
private
Integer
ban
=
0
;
/**
* 用户来源:0:bean 1:新建
*/
private
Integer
source
;
/**
* 工程师工号
*/
private
String
engineerCode
;
/**
* 备注
*/
private
String
notes
;
/**
* 是否正常 0: 否 1:是 默认1
*/
private
Integer
status
=
1
;
}
project-interface/src/main/java/com/dituhui/pea/pojo/UserInfoSearch.java
View file @
33a7dc3
...
...
@@ -65,7 +65,7 @@ public class UserInfoSearch extends PageRequest implements Serializable {
/**
* 最后登录时间
*/
//private Date
lastLoginTime;
private
String
lastLoginTime
;
/**
* 用户自定义条件
*/
...
...
@@ -104,18 +104,22 @@ public class UserInfoSearch extends PageRequest implements Serializable {
/**
* 创建人
*/
//
private String createdBy;
private
String
createdBy
;
/**
* 创建时间
*/
// private Date
createdTime;
private
String
createdTime
;
/**
* 更新人
*/
//
private String updatedBy;
private
String
updatedBy
;
/**
* 更新时间
*/
// private Date updatedTime;
private
String
updatedTime
;
/**
* 更新时间
*/
private
String
notes
;
}
project-interface/src/main/java/com/dituhui/pea/pojo/user/OrgInfo.java
0 → 100644
View file @
33a7dc3
package
com
.
dituhui
.
pea
.
pojo
.
user
;
import
lombok.Data
;
import
java.io.Serializable
;
@Data
public
class
OrgInfo
implements
Serializable
{
/**
* 机构id
*/
private
Integer
id
;
/**
* 机构名称
*/
private
String
name
;
}
project-interface/src/main/java/com/dituhui/pea/user/IRole.java
View file @
33a7dc3
...
...
@@ -31,6 +31,16 @@ public interface IRole {
/**
* 添加角色
*
* @param roleInfo 角色信息
* @return
*/
@RequestMapping
(
value
=
"/pea-user/role/delete2"
,
method
=
RequestMethod
.
POST
)
Result
<
RoleInfo
>
deleteRole2
(
@RequestBody
RoleInfo
roleInfo
);
/**
* 修改角色
*
* @param roleInfo 角色信息
...
...
project-interface/src/main/java/com/dituhui/pea/user/IUser.java
View file @
33a7dc3
...
...
@@ -2,6 +2,7 @@ package com.dituhui.pea.user;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.pojo.*
;
import
com.dituhui.pea.pojo.user.OrgInfo
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestHeader
;
...
...
@@ -12,39 +13,42 @@ import org.springframework.web.bind.annotation.RequestParam;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.enums.ThirdPartyEnum
;
import
java.util.List
;
/**
* 用户相关接口
*
* @author
*/
@FeignClient
(
value
=
"project-user"
,
contextId
=
"user"
)
public
interface
IUser
{
/**
* 登录接口
*
* @param user
* @return
*/
@RequestMapping
(
value
=
"/pea-user/login"
,
method
=
RequestMethod
.
POST
)
public
Result
<
UserLoginDTO
>
userLogin
(
@RequestBody
UserLoginParam
user
);
/**
* 获取用户信息
*
* @param userId
* @return
*/
@RequestMapping
(
value
=
"/pea-user/userInfo"
,
method
=
RequestMethod
.
GET
)
public
Result
<
UserLoginDTO
>
getUserInfo
(
@RequestHeader
(
name
=
"userId"
,
required
=
true
)
String
userId
);
/**
* 刷新appkey接口<br>
* 初始化系统ak缓存,例如系统上线,新ak入库的时候
*
* @return
*/
@RequestMapping
(
value
=
"/pea-user/refreshAppkey"
,
method
=
RequestMethod
.
POST
)
public
Result
<
Boolean
>
refreshAppkey
();
/**
* 登录接口
*
* @param user
* @return
*/
@RequestMapping
(
value
=
"/pea-user/login"
,
method
=
RequestMethod
.
POST
)
public
Result
<
UserLoginDTO
>
userLogin
(
@RequestBody
UserLoginParam
user
);
/**
* 获取用户信息
*
* @param userId
* @return
*/
@RequestMapping
(
value
=
"/pea-user/userInfo"
,
method
=
RequestMethod
.
GET
)
public
Result
<
UserLoginDTO
>
getUserInfo
(
@RequestHeader
(
name
=
"userId"
,
required
=
true
)
String
userId
);
/**
* 刷新appkey接口<br>
* 初始化系统ak缓存,例如系统上线,新ak入库的时候
*
* @return
*/
@RequestMapping
(
value
=
"/pea-user/refreshAppkey"
,
method
=
RequestMethod
.
POST
)
public
Result
<
Boolean
>
refreshAppkey
();
/**
* 获取当前登陆用户信息
...
...
@@ -59,6 +63,7 @@ public interface IUser {
/**
* 获取用户信息
*
* @param id 用户ID
* @return
*/
...
...
@@ -86,7 +91,7 @@ public interface IUser {
/**
* 获取用户信息
*
* @param id 第三方标志
* @param id
第三方标志
* @param type 第三方类型
* @return
*/
...
...
@@ -96,31 +101,35 @@ public interface IUser {
/**
* 添加用户
*
* @param userInfo 用户信息
* @return
*/
@RequestMapping
(
value
=
"/pea-user/add"
,
method
=
RequestMethod
.
POST
)
Web
Result
<
UserInfo
>
addUser
(
@RequestBody
UserInfo
userInfo
);
Result
<
UserInfo
>
addUser
(
@RequestBody
UserInfo
userInfo
);
/**
* 更新用户
*
* @param userInfo 用户信息
* @return
*/
@RequestMapping
(
value
=
"/pea-user/update"
,
method
=
RequestMethod
.
POST
)
Web
Result
<
UserInfo
>
updateUser
(
@RequestBody
UserInfo
userInfo
);
Result
<
UserInfo
>
updateUser
(
@RequestBody
UserInfo
userInfo
);
/**
* 删除用户
*
* @param userId 用户ID
* @return
*/
@RequestMapping
(
value
=
"/pea-user/delete"
,
method
=
RequestMethod
.
POST
)
WebResult
<
Boolean
>
deleteUser
(
@RequestParam
(
"id"
)
String
userId
);
Result
<
Boolean
>
deleteUser
(
@RequestBody
UserInfoSearch
search
);
/**
* 注册用户
*
* @param userInfo 用户信息
* @return
*/
...
...
@@ -129,6 +138,7 @@ public interface IUser {
/**
* 第三方用户注册
*
* @param thirdUserInfo 第三方用户信息
* @return
*/
...
...
@@ -138,6 +148,7 @@ public interface IUser {
/**
* 用户列表
*
* @param search 查询条件
* @return
*/
...
...
@@ -147,10 +158,21 @@ public interface IUser {
/**
* 禁用用户
*
* @param search 查询条件
* @return
*/
@RequestMapping
(
value
=
"/pea-user/ban"
,
method
=
RequestMethod
.
GET
)
Result
<
Boolean
>
ban
(
UserInfoSearch
search
);
@RequestMapping
(
value
=
"/pea-user/ban"
,
method
=
RequestMethod
.
POST
)
Result
<
Boolean
>
ban
(
@RequestBody
UserInfoSearch
search
);
/**
* 获取用户组织
*
* @param userId 查询条件
* @return
*/
@RequestMapping
(
value
=
"/pea-user/orgs"
,
method
=
RequestMethod
.
GET
)
Result
<
List
<
OrgInfo
>>
orgs
(
String
userId
);
}
project-user/pom.xml
View file @
33a7dc3
...
...
@@ -34,10 +34,10 @@
<version>
${druid.version}
</version>
</dependency>
<dependency
>
<groupId>
com.alibaba.cloud
</groupId
>
<artifactId>
spring-cloud-starter-alibaba-seata
</artifactId
>
</dependency
>
<!-- <dependency>--
>
<!-- <groupId>com.alibaba.cloud</groupId>--
>
<!-- <artifactId>spring-cloud-starter-alibaba-seata</artifactId>--
>
<!-- </dependency>--
>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
...
...
project-user/src/main/java/com/dituhui/pea/user/Application.java
View file @
33a7dc3
...
...
@@ -5,11 +5,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.data.jpa.repository.config.EnableJpaAuditing
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
@SpringBootApplication
@ComponentScan
(
basePackages
=
"com.dituhui.pea"
)
@EnableFeignClients
(
basePackages
=
{
"com.dituhui.pea.order"
})
@EnableJpaAuditing
@EnableTransactionManagement
public
class
Application
{
public
static
void
main
(
String
[]
args
)
{
...
...
project-user/src/main/java/com/dituhui/pea/user/controller/RoleController.java
View file @
33a7dc3
...
...
@@ -40,6 +40,14 @@ public class RoleController implements IRole {
}
@Override
public
Result
<
RoleInfo
>
deleteRole2
(
@Validated
RoleInfo
roleInfo
)
{
roleInfo
=
roleService
.
deleteRole2
(
roleInfo
);
return
Result
.
success
(
roleInfo
);
}
@Override
public
Result
<
RoleInfo
>
updateRole
(
@Validated
RoleInfo
roleInfo
)
{
roleInfo
=
roleService
.
updateRole
(
roleInfo
);
...
...
project-user/src/main/java/com/dituhui/pea/user/controller/UserController.java
View file @
33a7dc3
...
...
@@ -3,6 +3,8 @@ package com.dituhui.pea.user.controller;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.pojo.*
;
import
com.dituhui.pea.pojo.user.OrgInfo
;
import
com.dituhui.pea.user.dao.UserOrgDao
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -16,6 +18,8 @@ import com.dituhui.pea.user.service.UserService;
import
cn.hutool.core.util.ObjectUtil
;
import
java.util.List
;
/**
* 用户控制层
*/
...
...
@@ -84,39 +88,38 @@ public class UserController implements IUser {
}
@Override
public
Web
Result
<
UserInfo
>
addUser
(
UserInfo
userInfo
)
{
public
Result
<
UserInfo
>
addUser
(
UserInfo
userInfo
)
{
if
(
ObjectUtil
.
isNull
(
userInfo
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
return
Result
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
,
null
);
}
if
(
StringUtils
.
isBlank
(
userInfo
.
getAccount
()))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
return
Result
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
,
null
);
}
if
(
StringUtils
.
isBlank
(
userInfo
.
getPassword
()))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
userInfo
=
userService
.
saveUser
(
userInfo
);
return
WebResult
.
ok
(
userInfo
);
// if (StringUtils.isBlank(userInfo.getPassword())) {
// return Result.failed(StatusCodeEnum.COMMON_PARAM_EMPTY, null);
// }
return
userService
.
saveUser
(
userInfo
);
}
@Override
public
Web
Result
<
UserInfo
>
updateUser
(
UserInfo
userInfo
)
{
public
Result
<
UserInfo
>
updateUser
(
UserInfo
userInfo
)
{
if
(
userInfo
==
null
)
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
return
Result
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
,
null
);
}
if
(
StringUtils
.
isBlank
(
userInfo
.
getId
()))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
return
Result
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
,
null
);
}
userInfo
=
userService
.
updateUser
(
userInfo
);
return
WebResult
.
ok
(
userInfo
);
return
userService
.
updateUser
(
userInfo
);
}
@Override
public
WebResult
<
Boolean
>
deleteUser
(
String
userId
)
{
public
Result
<
Boolean
>
deleteUser
(
UserInfoSearch
search
)
{
String
userId
=
search
.
getId
();
if
(
StringUtils
.
isBlank
(
userId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
return
Result
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
,
null
);
}
userService
.
deleteUser
(
userId
);
return
WebResult
.
ok
(
);
return
Result
.
success
(
true
);
}
@Override
...
...
@@ -157,4 +160,10 @@ public class UserController implements IUser {
return
Result
.
success
(
true
);
}
@Override
public
Result
<
List
<
OrgInfo
>>
orgs
(
String
userId
)
{
List
<
OrgInfo
>
orgInfos
=
userService
.
orgs
(
userId
);
return
Result
.
success
(
orgInfos
);
}
}
project-user/src/main/java/com/dituhui/pea/user/dao/UserOrgDao.java
View file @
33a7dc3
...
...
@@ -5,6 +5,8 @@ import org.springframework.data.jpa.repository.JpaRepository;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.repository.CrudRepository
;
import
java.util.List
;
/**
* 用户组织关联表
*/
...
...
@@ -17,7 +19,7 @@ public interface UserOrgDao extends JpaRepository<UserOrgEntity, String>, JpaSpe
* @param id
* @return
*/
UserOrgEntity
findByUserId
(
String
i
d
);
List
<
UserOrgEntity
>
findByUserId
(
String
userI
d
);
void
deleteByUserId
(
String
userId
);
}
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity.java
View file @
33a7dc3
...
...
@@ -9,6 +9,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import
javax.persistence.*
;
import
javax.validation.constraints.NotBlank
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
/**
...
...
@@ -18,7 +19,7 @@ import java.util.Date;
@Data
@Entity
@Table
(
name
=
"sys_role"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
//
@EntityListeners(AuditingEntityListener.class)
public
class
RoleEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
71423293715769828L
;
/**
...
...
@@ -27,7 +28,7 @@ public class RoleEntity implements Serializable {
@Id
@GeneratedValue
(
generator
=
"uuid"
)
@GenericGenerator
(
name
=
"uuid"
,
strategy
=
"uuid"
)
@Column
(
name
=
"ID"
,
unique
=
true
,
nullable
=
false
,
length
=
32
)
@Column
(
name
=
"ID"
,
unique
=
true
,
nullable
=
false
,
length
=
60
)
private
String
id
;
/**
* 名称
...
...
@@ -54,9 +55,9 @@ public class RoleEntity implements Serializable {
/**
* 创建时间
*/
@Column
(
name
=
"CREATED_TIME"
)
@C
reatedDate
private
Dat
e
createdTime
;
//
@Column(name = "CREATED_TIME")
@C
olumn
(
name
=
"CREATED_TIME"
,
nullable
=
false
,
updatable
=
false
,
columnDefinition
=
"timestamp default current_timestamp"
)
private
LocalDateTim
e
createdTime
;
/**
* 更新人
*/
...
...
@@ -65,13 +66,14 @@ public class RoleEntity implements Serializable {
/**
* 更新时间
*/
@Column
(
name
=
"UPDATED_TIME"
)
@
LastModifiedDate
private
Dat
e
updatedTime
;
//
@Column(name = "UPDATED_TIME")
@
Column
(
name
=
"UPDATED_TIME"
,
nullable
=
false
,
columnDefinition
=
"timestamp default current_timestamp on update current_timestamp"
)
private
LocalDateTim
e
updatedTime
;
/**
* 备注
*/
@Column
(
name
=
"notes"
)
private
String
notes
;
}
project-user/src/main/java/com/dituhui/pea/user/entity/UserEntity.java
View file @
33a7dc3
...
...
@@ -120,6 +120,12 @@ public class UserEntity implements Serializable {
private
Integer
ban
=
0
;
/**
* 是否正常 0: 否 1:是 默认1
*/
@Column
(
name
=
"status"
)
private
Integer
status
=
1
;
/**
* 用户来源:0:bean 1:新建
*/
@Column
(
name
=
"source"
)
...
...
@@ -130,4 +136,10 @@ public class UserEntity implements Serializable {
*/
@Column
(
name
=
"engineer_code"
)
private
String
engineerCode
;
/**
* 备注
*/
@Column
(
name
=
"notes"
)
private
String
notes
;
}
project-user/src/main/java/com/dituhui/pea/user/service/RoleService.java
View file @
33a7dc3
...
...
@@ -24,9 +24,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.TransactionDefinition
;
import
org.springframework.transaction.TransactionStatus
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.support.DefaultTransactionDefinition
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Date
;
...
...
@@ -59,7 +64,8 @@ public class RoleService {
@Autowired
RedisService
redisService
;
// @Autowired
// private DataSourceTransactionManager dataSourceTransactionManager;
/**
* 失效时间ms
*/
...
...
@@ -68,19 +74,27 @@ public class RoleService {
@Transactional
public
RoleInfo
addRole
(
RoleInfo
roleInfo
)
{
RoleEntity
roleEntity
=
assembleRole
(
roleInfo
);
String
name
=
roleInfo
.
getName
();
String
createdBy
=
roleInfo
.
getCreatedBy
();
String
notes
=
roleInfo
.
getNotes
();
RoleEntity
roleEntity
=
new
RoleEntity
();
roleEntity
.
setName
(
name
);
roleEntity
.
setCreatedBy
(
createdBy
);
roleEntity
.
setCreatedTime
(
LocalDateTime
.
now
());
roleEntity
.
setNotes
(
notes
);
// RoleEntity roleEntity = assembleRole(roleInfo);
log
.
info
(
"新增角色入参:"
+
JSONObject
.
toJSONString
(
roleEntity
));
roleEntity
=
roleDao
.
save
(
roleEntity
);
// roleInfo = BeanUtil.copyProperties(roleEntity, RoleInfo.class);
roleInfo
.
setId
(
roleEntity
.
getId
());
List
<
RoleResourceInfo
>
resourceInfos
=
roleInfo
.
getResourceInfos
();
if
(
CollectionUtils
.
isNotEmpty
(
resourceInfos
))
{
for
(
RoleResourceInfo
resourceInfo
:
resourceInfos
)
{
RoleResourceEntity
roleResourceEntity
=
assembleRoleResource
(
role
Entity
.
getId
(),
resourceInfo
.
getResourceId
());
RoleResourceEntity
roleResourceEntity
=
assembleRoleResource
(
role
Info
.
getId
(),
resourceInfo
.
getResourceId
());
roleResourceDao
.
save
(
roleResourceEntity
);
}
}
// roleInfo = BeanUtil.copyProperties(roleEntity, RoleInfo.class);
roleInfo
.
setId
(
roleEntity
.
getId
());
log
.
info
(
"新增角色信息:"
+
JSONObject
.
toJSONString
(
roleEntity
));
log
.
info
(
"新增角色信息:"
+
JSONObject
.
toJSONString
(
roleInfo
));
return
roleInfo
;
}
...
...
@@ -117,6 +131,34 @@ public class RoleService {
roleResourceDao
.
deleteByRoleId
(
roleId
);
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
RoleInfo
deleteRole2
(
RoleInfo
roleInfo
)
{
String
name
=
roleInfo
.
getName
();
String
createdBy
=
roleInfo
.
getCreatedBy
();
String
notes
=
roleInfo
.
getNotes
();
RoleEntity
roleEntity
=
new
RoleEntity
();
roleEntity
.
setName
(
name
);
roleEntity
.
setCreatedBy
(
createdBy
);
roleEntity
.
setCreatedTime
(
LocalDateTime
.
now
());
roleEntity
.
setNotes
(
notes
);
// RoleEntity roleEntity = assembleRole(roleInfo);
log
.
info
(
"新增角色入参:"
+
JSONObject
.
toJSONString
(
roleEntity
));
roleEntity
=
roleDao
.
save
(
roleEntity
);
// roleInfo = BeanUtil.copyProperties(roleEntity, RoleInfo.class);
roleInfo
.
setId
(
roleEntity
.
getId
());
List
<
RoleResourceInfo
>
resourceInfos
=
roleInfo
.
getResourceInfos
();
if
(
CollectionUtils
.
isNotEmpty
(
resourceInfos
))
{
for
(
RoleResourceInfo
resourceInfo
:
resourceInfos
)
{
RoleResourceEntity
roleResourceEntity
=
assembleRoleResource
(
roleInfo
.
getId
(),
resourceInfo
.
getResourceId
());
roleResourceDao
.
save
(
roleResourceEntity
);
}
}
log
.
info
(
"新增角色信息:"
+
JSONObject
.
toJSONString
(
roleInfo
));
return
roleInfo
;
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
addUserRole
(
String
roleId
,
String
userId
)
{
// 查询角色是否存在
...
...
@@ -249,7 +291,7 @@ public class RoleService {
RoleEntity
roleEntity
=
new
RoleEntity
();
roleEntity
.
setName
(
roleInfo
.
getName
());
roleEntity
.
setCreatedBy
(
roleInfo
.
getCreatedBy
());
roleEntity
.
setCreatedTime
(
new
Date
());
roleEntity
.
setCreatedTime
(
LocalDateTime
.
now
());
roleEntity
.
setNotes
(
roleInfo
.
getNotes
());
return
roleEntity
;
}
...
...
project-user/src/main/java/com/dituhui/pea/user/service/UserService.java
View file @
33a7dc3
...
...
@@ -13,16 +13,16 @@ import javax.persistence.criteria.Predicate;
import
com.alibaba.fastjson.JSONObject
;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.pojo.*
;
import
com.dituhui.pea.pojo.user.OrgInfo
;
import
com.dituhui.pea.user.dao.*
;
import
com.dituhui.pea.user.entity.*
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.hibernate.query.internal.NativeQueryImpl
;
import
org.hibernate.transform.Transformers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -63,6 +63,8 @@ public class UserService {
*/
private
static
final
int
LIVE_TIME_MILLIS
=
7200000
;
private
static
final
Gson
gson
=
new
Gson
();
private
static
final
java
.
text
.
SimpleDateFormat
formatter
=
new
java
.
text
.
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
;
@Autowired
UserDao
userDao
;
...
...
@@ -285,16 +287,22 @@ public class UserService {
* @return
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
UserInfo
saveUser
(
UserInfo
userInfo
)
{
public
Result
<
UserInfo
>
saveUser
(
UserInfo
userInfo
)
{
// 校验用户信息
checkAccount
(
userInfo
);
Result
<
UserInfo
>
checkAccount
=
checkAccount
(
userInfo
);
if
(
null
!=
checkAccount
)
{
return
checkAccount
;
}
UserEntity
userEntity
=
BeanUtil
.
copyProperties
(
userInfo
,
UserEntity
.
class
);
// 密码MD5加密
userEntity
.
setPassword
(
SecureUtil
.
md5
(
user
Info
.
getPassword
(
)));
userEntity
.
setPassword
(
SecureUtil
.
md5
(
user
Entity
.
getPhone
().
substring
(
userEntity
.
getPhone
().
length
()
-
6
)));
// 保存用户信息
userEntity
=
userDao
.
save
(
userEntity
);
userInfo
.
setId
(
userEntity
.
getId
());
savaUserRoleAndOrgInfo
(
userInfo
);
return
BeanUtil
.
copyProperties
(
userEntity
,
UserInfo
.
class
);
UserInfo
info
=
BeanUtil
.
copyProperties
(
userEntity
,
UserInfo
.
class
);
info
.
setPassword
(
null
);
return
Result
.
success
(
info
);
}
/**
...
...
@@ -424,19 +432,23 @@ public class UserService {
* @return
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
UserInfo
updateUser
(
UserInfo
userInfo
)
{
public
Result
<
UserInfo
>
updateUser
(
UserInfo
userInfo
)
{
// 校验用户信息
checkAccount
(
userInfo
);
Result
<
UserInfo
>
checkAccount
=
checkAccount
(
userInfo
);
if
(
null
!=
checkAccount
)
{
return
checkAccount
;
}
// 查询用户信息是否存在
UserEntity
userEntity
=
userDao
.
findById
(
userInfo
.
getId
()).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
userEntity
))
{
throw
new
BusinessException
(
StatusCodeEnum
.
USER_DOES_NOT_EXIST
);
return
Result
.
failed
(
StatusCodeEnum
.
USER_DOES_NOT_EXIST
,
null
);
}
assembleUpdateUserInfo
(
userInfo
,
userEntity
);
userEntity
=
userDao
.
save
(
userEntity
);
savaUserRoleAndOrgInfo
(
userInfo
);
userInfo
=
BeanUtil
.
copyProperties
(
userEntity
,
UserInfo
.
class
);
return
userInfo
;
userInfo
.
setPassword
(
null
);
return
Result
.
success
(
userInfo
);
}
/**
...
...
@@ -460,11 +472,17 @@ public class UserService {
userRoleDao
.
save
(
userRoleEntity
);
}
}
if
(
MapUtils
.
isNotEmpty
(
userRoleMap
))
{
for
(
String
roleId
:
userRoleMap
.
keySet
())
{
UserRoleEntity
userRoleEntity
=
userRoleMap
.
get
(
roleId
);
userRoleDao
.
deleteById
(
userRoleEntity
.
getId
());
}
}
}
//处理用户机构关联信息
if
(
CollectionUtils
.
isNotEmpty
(
userInfo
.
getOrgIds
())
&&
null
!=
userInfo
.
getOrgIds
())
{
userOrgDao
.
deleteByUserId
(
userInfo
.
getId
());
for
(
Integer
orgId
:
userInfo
.
getOrgIds
())
{
userOrgDao
.
deleteByUserId
(
userInfo
.
getId
());
UserOrgEntity
userOrgEntity
=
new
UserOrgEntity
();
userOrgEntity
.
setUserId
(
userInfo
.
getId
());
userOrgEntity
.
setOrgId
(
orgId
);
...
...
@@ -515,33 +533,39 @@ public class UserService {
*
* @param userInfo 用户信息
*/
private
void
checkAccount
(
UserInfo
userInfo
)
{
private
Result
<
UserInfo
>
checkAccount
(
UserInfo
userInfo
)
{
// 校验账号
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getAccount
()))
{
if
(
checkAccount
(
userInfo
.
getAccount
(),
userInfo
.
getId
()))
{
throw
new
BusinessException
(
StatusCodeEnum
.
ACCOUNT_EXISTS
);
return
Result
.
failed
(
StatusCodeEnum
.
ACCOUNT_EXISTS
,
null
);
// throw new BusinessException(StatusCodeEnum.ACCOUNT_EXISTS);
}
}
// 校验手机号
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getPhone
()))
{
// 校验手机格式是否正确
if
(!
Validator
.
isMobile
(
userInfo
.
getPhone
()))
{
throw
new
BusinessException
(
StatusCodeEnum
.
COMMON_PARAM_ERROR
);
return
Result
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_ERROR
,
null
);
// throw new BusinessException(StatusCodeEnum.COMMON_PARAM_ERROR);
}
if
(
checkPhone
(
userInfo
.
getPhone
(),
userInfo
.
getId
()))
{
throw
new
BusinessException
(
StatusCodeEnum
.
MOBILE_NUMBER_EXISTS
);
return
Result
.
failed
(
StatusCodeEnum
.
MOBILE_NUMBER_EXISTS
,
null
);
// throw new BusinessException(StatusCodeEnum.MOBILE_NUMBER_EXISTS);
}
}
// 校验邮箱
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getEmail
()))
{
// 校验邮箱格式是否正确
if
(!
Validator
.
isEmail
(
userInfo
.
getEmail
()))
{
throw
new
BusinessException
(
StatusCodeEnum
.
COMMON_PARAM_ERROR
);
return
Result
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_ERROR
,
null
);
// throw new BusinessException(StatusCodeEnum.COMMON_PARAM_ERROR);
}
if
(
checkEmail
(
userInfo
.
getEmail
(),
userInfo
.
getId
()))
{
throw
new
BusinessException
(
StatusCodeEnum
.
EMAIL_EXISTS
);
return
Result
.
failed
(
StatusCodeEnum
.
EMAIL_EXISTS
,
null
);
// throw new BusinessException(StatusCodeEnum.EMAIL_EXISTS);
}
}
return
null
;
}
/**
...
...
@@ -680,7 +704,7 @@ public class UserService {
querySql
.
append
(
"and su.source ="
+
search
.
getSource
()
+
" "
);
}
if
(
null
!=
search
.
getOrgId
())
{
querySql
.
append
(
"and suo.org_id =
"
+
search
.
getOrgId
()
+
"
"
);
querySql
.
append
(
"and suo.org_id =
'"
+
search
.
getOrgId
()
+
"'
"
);
}
if
(
null
!=
search
.
getQueryString
())
{
querySql
.
append
(
"and (su.engineer_code LIKE '%"
+
search
.
getQueryString
()
+
"%' or su.nickname like '%"
+
search
.
getQueryString
()
+
"%' or su.phone like '%"
+
search
.
getQueryString
()
+
"%' or su.email like '%"
+
search
.
getQueryString
()
+
"%' )"
);
...
...
@@ -726,6 +750,13 @@ public class UserService {
search
.
setPhone
(
map
.
containsKey
(
"phone"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"phone"
))
?
map
.
get
(
"phone"
).
toString
()
:
null
);
search
.
setEngineerCode
(
map
.
containsKey
(
"engineer_code"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"engineer_code"
))
?
map
.
get
(
"engineer_code"
).
toString
()
:
null
);
search
.
setRoleName
(
map
.
containsKey
(
"roleName"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"roleName"
))
?
map
.
get
(
"roleName"
).
toString
()
:
null
);
search
.
setBan
(
map
.
containsKey
(
"ban"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"ban"
))
?
Integer
.
parseInt
(
map
.
get
(
"ban"
).
toString
())
:
null
);
search
.
setCreatedBy
(
map
.
containsKey
(
"CREATED_BY"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"CREATED_BY"
))
?
map
.
get
(
"CREATED_BY"
).
toString
()
:
null
);
search
.
setUpdatedBy
(
map
.
containsKey
(
"UPDATED_BY"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"UPDATED_BY"
))
?
map
.
get
(
"UPDATED_BY"
).
toString
()
:
null
);
search
.
setNotes
(
map
.
containsKey
(
"notes"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"notes"
))
?
map
.
get
(
"notes"
).
toString
()
:
null
);
search
.
setCreatedTime
(
map
.
containsKey
(
"CREATED_TIME"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"CREATED_TIME"
))
?
formatter
.
format
(
map
.
get
(
"CREATED_TIME"
))
:
null
);
search
.
setUpdatedTime
(
map
.
containsKey
(
"UPDATED_TIME"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"UPDATED_TIME"
))
?
formatter
.
format
(
map
.
get
(
"UPDATED_TIME"
))
:
null
);
search
.
setLastLoginTime
(
map
.
containsKey
(
"LAST_LOGIN_TIME"
)
&&
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"LAST_LOGIN_TIME"
))
?
formatter
.
format
(
map
.
get
(
"LAST_LOGIN_TIME"
))
:
null
);
return
search
;
}
...
...
@@ -742,4 +773,18 @@ public class UserService {
userDao
.
save
(
byId
);
}
}
public
List
<
OrgInfo
>
orgs
(
String
userId
)
{
List
<
OrgInfo
>
orgInfos
=
new
ArrayList
<>();
List
<
UserOrgEntity
>
byUserId
=
userOrgDao
.
findByUserId
(
userId
);
if
(
CollectionUtils
.
isEmpty
(
byUserId
))
{
return
orgInfos
;
}
byUserId
.
forEach
(
e
->
{
OrgInfo
orgInfo
=
new
OrgInfo
();
orgInfo
.
setId
(
e
.
getOrgId
());
orgInfos
.
add
(
orgInfo
);
});
return
orgInfos
;
}
}
project-user/src/main/resources/application.yaml
View file @
33a7dc3
...
...
@@ -42,11 +42,11 @@ spring:
seata
:
application-id
:
${spring.application.name}
tx-service-group
:
${spring.application.name}-group
service
:
vgroup-mapping
:
project-user-group
:
default
grouplist
:
default
:
seata-server:8091
#
seata:
#
application-id: ${spring.application.name}
#
tx-service-group: ${spring.application.name}-group
#
service:
#
vgroup-mapping:
#
project-user-group: default
#
grouplist:
#
default: seata-server:8091
Write
Preview
Markdown
is supported
Attach a file
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 post a comment