Commit b99cbb59 authored by wujipeng's avatar wujipeng
Browse files

新增用户逻辑修改-优化

parent 19cbccd6
...@@ -13,7 +13,7 @@ import lombok.Data; ...@@ -13,7 +13,7 @@ import lombok.Data;
public class RelationShipDTO { public class RelationShipDTO {
@ApiModelProperty(value = "id") @ApiModelProperty(value = "id")
private String id; private Integer id;
@ApiModelProperty(value = "用户名") @ApiModelProperty(value = "用户名")
private String userName; private String userName;
......
...@@ -69,34 +69,37 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme ...@@ -69,34 +69,37 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
public Boolean add(UserDTO userDTO) { public Boolean add(UserDTO userDTO) {
//数据转化成json //数据转化成json
List<RelationShipDTO> relationShipList = userDTO.getRelationShipList(); List<RelationShipDTO> relationShipList = userDTO.getRelationShipList();
//解析身份证号
Map<String, String> idCardInfo = IdCardUtils.parseIdCardInfo(userDTO.getIdCard());
if(MapUtil.isNotEmpty(idCardInfo)){
userDTO.setAge(Integer.parseInt(idCardInfo.get("age")));
userDTO.setSex(idCardInfo.get("sex"));
userDTO.setIdType("身份证");
}
if(!relationShipList.isEmpty()){
userDTO.setRelationShip(JSON.toJSONString(relationShipList));
}
save(userDTO);
//更新被选中人的关系
if(!relationShipList.isEmpty()){ if(!relationShipList.isEmpty()){
for (RelationShipDTO relationShipDTO : relationShipList) { for (RelationShipDTO relationShipDTO : relationShipList) {
//查询被选中人信息
UserEntity user = getById(relationShipDTO.getId()); UserEntity user = getById(relationShipDTO.getId());
//更新被选中人的关系
String relationShip = user.getRelationShip(); String relationShip = user.getRelationShip();
//关系反转
relationShipDTO.setId(userDTO.getId());
if(StringUtils.isNotEmpty(relationShip)){ if(StringUtils.isNotEmpty(relationShip)){
String oldRelationShip = user.getRelationShip(); String oldRelationShip = user.getRelationShip();
List<RelationShipDTO> oldRelationShipList = JSON.parseArray(oldRelationShip, RelationShipDTO.class); List<RelationShipDTO> oldRelationShipList = JSON.parseArray(oldRelationShip, RelationShipDTO.class);
oldRelationShipList.add(relationShipDTO); oldRelationShipList.add(relationShipDTO);
user.setRelationShip(JSON.toJSONString(oldRelationShipList)); user.setRelationShip(JSON.toJSONString(oldRelationShipList));
updateById(user);
}else { }else {
List<RelationShipDTO> relationShipList1 = Lists.newArrayList(); List<RelationShipDTO> relationShipList1 = Lists.newArrayList();
relationShipList1.add(relationShipDTO); relationShipList1.add(relationShipDTO);
user.setRelationShip(JSON.toJSONString(relationShipList1)); user.setRelationShip(JSON.toJSONString(relationShipList1));
} }
updateById(user);
} }
String relationShip = JSON.toJSONString(relationShipList);
userDTO.setRelationShip(relationShip);
} }
//解析身份证号 return Boolean.TRUE;
Map<String, String> idCardInfo = IdCardUtils.parseIdCardInfo(userDTO.getIdCard());
if(MapUtil.isNotEmpty(idCardInfo)){
userDTO.setAge(Integer.parseInt(idCardInfo.get("age")));
userDTO.setSex(idCardInfo.get("sex"));
userDTO.setIdType("身份证");
}
return save(userDTO);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment