Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeoFlyApi
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GeoFly
GeoFlyApi
Commits
7cdc2a09
Commit
7cdc2a09
authored
Apr 22, 2025
by
gdj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户增加增删改接口。
parent
cc0735f5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
0 deletions
+129
-0
sample/src/main/java/com/dji/sample/manage/controller/UserController.java
+40
-0
sample/src/main/java/com/dji/sample/manage/service/IUserService.java
+14
-0
sample/src/main/java/com/dji/sample/manage/service/impl/UserServiceImpl.java
+75
-0
No files found.
sample/src/main/java/com/dji/sample/manage/controller/UserController.java
View file @
7cdc2a09
...
...
@@ -2,6 +2,7 @@ package com.dji.sample.manage.controller;
import
com.dji.sample.common.model.CustomClaim
;
import
com.dji.sample.manage.model.dto.UserListDTO
;
import
com.dji.sample.manage.model.entity.UserEntity
;
import
com.dji.sample.manage.service.IUserService
;
import
com.dji.sdk.common.HttpResultResponse
;
import
com.dji.sdk.common.PaginationData
;
...
...
@@ -61,4 +62,43 @@ public class UserController {
userService
.
updateUser
(
workspaceId
,
userId
,
user
);
return
HttpResultResponse
.
success
();
}
/**
* delete user
* @param workspaceId
* @param userId
* @return
*/
@DeleteMapping
(
"/{workspace_id}/delUser/{user_id}"
)
public
HttpResultResponse
delUser
(
@PathVariable
(
"workspace_id"
)
String
workspaceId
,
@PathVariable
(
"user_id"
)
String
userId
)
{
userService
.
deleteUser
(
workspaceId
,
userId
);
return
HttpResultResponse
.
success
();
}
/**
* delete user
* @param workspaceId
* @return
*/
@PostMapping
(
"/{workspace_id}/addUser"
)
public
HttpResultResponse
addUser
(
@RequestBody
UserEntity
user
,
@PathVariable
(
"workspace_id"
)
String
workspaceId
)
{
userService
.
addUser
(
workspaceId
,
user
);
return
HttpResultResponse
.
success
();
}
/**
* Query the information of the userId user.
* @param workspaceId
* @param userId
* @return
*/
@GetMapping
(
"/{workspace_id}/userInfo/{user_id}"
)
public
HttpResultResponse
getOneUserInfo
(
@PathVariable
(
"workspace_id"
)
String
workspaceId
,
@PathVariable
(
"user_id"
)
String
userId
)
{
return
userService
.
getUserByUserId
(
userId
,
workspaceId
);
}
}
sample/src/main/java/com/dji/sample/manage/service/IUserService.java
View file @
7cdc2a09
...
...
@@ -2,6 +2,7 @@ package com.dji.sample.manage.service;
import
com.dji.sample.manage.model.dto.UserDTO
;
import
com.dji.sample.manage.model.dto.UserListDTO
;
import
com.dji.sample.manage.model.entity.UserEntity
;
import
com.dji.sdk.common.HttpResultResponse
;
import
com.dji.sdk.common.PaginationData
;
...
...
@@ -41,4 +42,17 @@ public interface IUserService {
PaginationData
<
UserListDTO
>
getUsersByWorkspaceId
(
long
page
,
long
pageSize
,
String
workspaceId
);
Boolean
updateUser
(
String
workspaceId
,
String
userId
,
UserListDTO
user
);
Boolean
deleteUser
(
String
workspaceId
,
String
userId
);
Boolean
addUser
(
String
workspaceId
,
UserEntity
user
);
/**
* Query user's details based on userId
* @param username
* @param workspaceId
* @return
*/
HttpResultResponse
getUserByUserId
(
String
username
,
String
workspaceId
);
}
sample/src/main/java/com/dji/sample/manage/service/impl/UserServiceImpl.java
View file @
7cdc2a09
...
...
@@ -35,6 +35,7 @@ import java.time.ZoneId;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
@Service
...
...
@@ -165,6 +166,48 @@ public class UserServiceImpl implements IUserService {
return
id
>
0
;
}
@Override
public
Boolean
deleteUser
(
String
workspaceId
,
String
userId
)
{
LambdaQueryWrapper
<
UserEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
eq
(
UserEntity:
:
getWorkspaceId
,
workspaceId
);
queryWrapper
.
eq
(
UserEntity:
:
getUserId
,
userId
);
// 需要先查询
UserEntity
userEntity
=
this
.
mapper
.
selectOne
(
queryWrapper
);
// 管理员
if
(
userEntity
.
getUserType
()
==
UserTypeEnum
.
WEB
.
getVal
())
{
throw
new
RuntimeException
(
"Failed to delete admin"
);
}
int
delete
=
mapper
.
delete
(
queryWrapper
);
return
delete
>
0
;
}
@Override
public
Boolean
addUser
(
String
workspaceId
,
UserEntity
user
)
{
// 用户名不能重复
String
username
=
user
.
getUsername
();
LambdaQueryWrapper
<
UserEntity
>
userQueryWrapper
=
new
LambdaQueryWrapper
<>();
userQueryWrapper
.
eq
(
UserEntity:
:
getUsername
,
username
);
List
<
UserEntity
>
nameUserList
=
this
.
mapper
.
selectList
(
userQueryWrapper
);
if
(!
CollectionUtils
.
isEmpty
(
nameUserList
))
{
throw
new
RuntimeException
(
"the username is already existed"
);
}
UserEntity
userEntity
=
new
UserEntity
();
userEntity
.
setUserType
(
user
.
getUserType
()
!=
null
?
user
.
getUserType
()
:
UserTypeEnum
.
PILOT
.
getVal
());
userEntity
.
setUserId
(
UUID
.
randomUUID
().
toString
());
userEntity
.
setPassword
(
SecurityUtils
.
encryptPassword
(
user
.
getPassword
()));
userEntity
.
setUsername
(
user
.
getUsername
());
userEntity
.
setWorkspaceId
(
workspaceId
);
int
insert
=
this
.
mapper
.
insert
(
userEntity
);
return
insert
>
0
;
}
/**
* Convert database entity objects into user data transfer object.
* @param entity
...
...
@@ -198,6 +241,16 @@ public class UserServiceImpl implements IUserService {
}
/**
* Query a user by username.
* @param userId
* @return
*/
private
UserEntity
getUserByUserId
(
String
userId
)
{
return
mapper
.
selectOne
(
new
QueryWrapper
<
UserEntity
>()
.
eq
(
"user_id"
,
userId
));
}
/**
* Convert database entity objects into user data transfer object.
* @param entity
* @return
...
...
@@ -215,4 +268,26 @@ public class UserServiceImpl implements IUserService {
.
mqttAddr
(
MqttPropertyConfiguration
.
getBasicMqttAddress
())
.
build
();
}
/**
* Query user's details based on userId
* @param userId
* @param workspaceId
* @return
*/
@Override
public
HttpResultResponse
getUserByUserId
(
String
userId
,
String
workspaceId
)
{
UserEntity
userEntity
=
this
.
getUserByUserId
(
userId
);
if
(
userEntity
==
null
)
{
return
new
HttpResultResponse
()
.
setCode
(
HttpStatus
.
UNAUTHORIZED
.
value
())
.
setMessage
(
"invalid userId"
);
}
UserDTO
user
=
this
.
entityConvertToDTO
(
userEntity
);
user
.
setWorkspaceId
(
workspaceId
);
return
HttpResultResponse
.
success
(
user
);
}
}
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