Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
relation
Commits
90a15a1e
Commit
90a15a1e
authored
Aug 01, 2025
by
wujipeng
Browse files
用户关系表
parent
8b58ecae
Changes
6
Show whitespace changes
Inline
Side-by-side
src/main/java/com/platform/mapper/UserRelationMapper.java
0 → 100644
View file @
90a15a1e
package
com.platform.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.platform.model.entity.UserRelationEntity
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* @author : wujipeng
* @date : 2025/8/1 14:28
* @Version: 1.0
* @Desc : 描述信息
*/
@Mapper
public
interface
UserRelationMapper
extends
BaseMapper
<
UserRelationEntity
>
{
}
src/main/java/com/platform/model/entity/UserEntity.java
View file @
90a15a1e
...
...
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.IdType;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.platform.model.dto.RelationShipDTO
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
...
...
@@ -39,11 +38,7 @@ public class UserEntity {
private
String
basicInfo
;
@ApiModelProperty
(
"关系"
)
@TableField
(
"relation_ship"
)
private
String
relationShip
;
@ApiModelProperty
(
"关系,方便解析和会回显"
)
@TableField
(
exist
=
false
)
private
List
<
Relation
ShipDTO
>
relationShipList
;
private
List
<
User
Relation
Entity
>
relationShipList
;
}
src/main/java/com/platform/model/
dto/
Relation
ShipDTO
.java
→
src/main/java/com/platform/model/
entity/User
Relation
Entity
.java
View file @
90a15a1e
package
com.platform.model.
dto
;
package
com.platform.model.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @author : wujipeng
* @date : 2025/8/1 1
1
:26
* @date : 2025/8/1 1
4
:26
* @Version: 1.0
* @Desc : 描述信息
*/
@TableName
(
"user_relation"
)
@Data
public
class
Relation
ShipDTO
{
public
class
User
Relation
Entity
{
@
ApiModelProperty
(
value
=
"id"
)
@
TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"用户id"
)
@TableField
(
"user_id"
)
private
Integer
userId
;
@ApiModelProperty
(
value
=
"对方id"
)
@TableField
(
"other_id"
)
private
Integer
otherId
;
@ApiModelProperty
(
value
=
"用户名"
)
@TableField
(
"user_name"
)
private
String
userName
;
@ApiModelProperty
(
value
=
"关系"
)
@TableField
(
"relation_ship"
)
private
String
relationShip
;
@ApiModelProperty
(
value
=
"备注"
)
...
...
src/main/java/com/platform/service/UserRelationService.java
0 → 100644
View file @
90a15a1e
package
com.platform.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.model.entity.UserRelationEntity
;
/**
* @author : wujipeng
* @date : 2025/8/1 14:28
* @Version: 1.0
* @Desc : 描述信息
*/
public
interface
UserRelationService
extends
IService
<
UserRelationEntity
>
{
}
src/main/java/com/platform/service/impl/UserRelationServiceImpl.java
0 → 100644
View file @
90a15a1e
package
com.platform.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.mapper.UserRelationMapper
;
import
com.platform.model.entity.UserRelationEntity
;
import
com.platform.service.UserRelationService
;
import
org.springframework.stereotype.Service
;
/**
* @author : wujipeng
* @date : 2025/8/1 14:28
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public
class
UserRelationServiceImpl
extends
ServiceImpl
<
UserRelationMapper
,
UserRelationEntity
>
implements
UserRelationService
{
}
src/main/java/com/platform/service/impl/UserServiceImpl.java
View file @
90a15a1e
package
com.platform.service.impl
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.ListUtil
;
import
cn.hutool.core.map.MapUtil
;
import
com.alibaba.fastjson2.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.platform.mapper.UserMapper
;
import
com.platform.model.dto.RelationShipDTO
;
import
com.platform.model.dto.UserDTO
;
import
com.platform.model.entity.UserAccountEntity
;
import
com.platform.model.entity.UserEntity
;
import
com.platform.model.entity.UserRelationEntity
;
import
com.platform.model.vo.UserVO
;
import
com.platform.service.UserAccountService
;
import
com.platform.service.UserRelationService
;
import
com.platform.service.UserService
;
import
com.platform.utils.DozerUtils
;
import
com.platform.utils.IdCardUtils
;
import
com.platform.utils.StringUtils
;
import
org.checkerframework.checker.nullness.qual.Nullable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ObjectUtils
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -32,6 +28,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
@Resource
private
UserAccountService
userAccountService
;
@Resource
private
UserRelationService
userRelationService
;
@Override
public
UserVO
getDetail
(
String
userName
)
{
...
...
@@ -43,21 +41,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
List
<
UserAccountEntity
>
userAccountEntityList
=
userAccountService
.
queryListByUserName
(
userName
);
userVO
.
setUserAccountList
(
userAccountEntityList
);
}
String
relationShip
=
userEntity
.
getRelationShip
();
if
(
StringUtils
.
isNotEmpty
(
relationShip
)){
List
<
RelationShipDTO
>
relationShipDTOS
=
JSON
.
parseArray
(
relationShip
,
RelationShipDTO
.
class
);
if
(!
relationShipDTOS
.
isEmpty
()){
userVO
.
setRelationShipList
(
relationShipDTOS
);
}
List
<
UserRelationEntity
>
relationShipList
=
userRelationService
.
list
(
new
LambdaQueryWrapper
<
UserRelationEntity
>().
eq
(
UserRelationEntity:
:
getUserId
,
userEntity
.
getId
()));
if
(!
ObjectUtils
.
isEmpty
(
relationShipList
)){
userVO
.
setRelationShipList
(
relationShipList
);
}
return
userVO
;
}
@Override
public
boolean
updateUser
(
UserDTO
userDTO
)
{
List
<
Relation
ShipDTO
>
relationShipList
=
userDTO
.
getRelationShipList
();
List
<
User
Relation
Entity
>
relationShipList
=
userDTO
.
getRelationShipList
();
if
(!
ObjectUtils
.
isEmpty
(
relationShipList
)){
user
DTO
.
set
RelationS
hip
(
JSON
.
toJSONString
(
relationShipList
)
)
;
userRelationS
ervice
.
saveOrUpdateBatch
(
relationShipList
);
}
updateById
(
userDTO
);
//先删除账户信息
...
...
@@ -72,9 +67,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
}
@Override
@Transactional
public
Boolean
add
(
UserDTO
userDTO
)
{
//数据转化成json
List
<
RelationShipDTO
>
relationShipList
=
userDTO
.
getRelationShipList
();
//解析身份证号
Map
<
String
,
String
>
idCardInfo
=
IdCardUtils
.
parseIdCardInfo
(
userDTO
.
getIdCard
());
if
(
MapUtil
.
isNotEmpty
(
idCardInfo
)){
...
...
@@ -82,30 +76,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
userDTO
.
setSex
(
idCardInfo
.
get
(
"sex"
));
userDTO
.
setIdType
(
"身份证"
);
}
if
(!
relationShipList
.
isEmpty
()){
userDTO
.
setRelationShip
(
JSON
.
toJSONString
(
relationShipList
));
}
save
(
userDTO
);
//更新被选中人的关系
if
(!
relationShipList
.
isEmpty
()){
for
(
RelationShipDTO
relationShipDTO
:
relationShipList
)
{
UserEntity
user
=
getById
(
relationShipDTO
.
getId
());
String
relationShip
=
user
.
getRelationShip
();
//关系反转
relationShipDTO
.
setId
(
userDTO
.
getId
());
if
(
StringUtils
.
isNotEmpty
(
relationShip
)){
String
oldRelationShip
=
user
.
getRelationShip
();
List
<
RelationShipDTO
>
oldRelationShipList
=
JSON
.
parseArray
(
oldRelationShip
,
RelationShipDTO
.
class
);
oldRelationShipList
.
add
(
relationShipDTO
);
user
.
setRelationShip
(
JSON
.
toJSONString
(
oldRelationShipList
));
}
else
{
List
<
RelationShipDTO
>
relationShipList1
=
Lists
.
newArrayList
();
relationShipList1
.
add
(
relationShipDTO
);
user
.
setRelationShip
(
JSON
.
toJSONString
(
relationShipList1
));
}
updateById
(
user
);
List
<
UserRelationEntity
>
relationShipList
=
userDTO
.
getRelationShipList
();
for
(
UserRelationEntity
userRelationEntity
:
relationShipList
)
{
userRelationEntity
.
setOtherId
(
userDTO
.
getId
());
}
userRelationService
.
saveBatch
(
relationShipList
);
for
(
UserRelationEntity
userRelationEntity
:
relationShipList
)
{
userRelationEntity
.
setOtherId
(
userRelationEntity
.
getUserId
());
userRelationEntity
.
setUserId
(
userDTO
.
getId
());
userRelationEntity
.
setId
(
null
);
}
userRelationService
.
saveBatch
(
relationShipList
);
return
Boolean
.
TRUE
;
}
}
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