绑定父子关系
This commit is contained in:
@@ -75,4 +75,22 @@ public class LbDepartmentUserController {
|
||||
}
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
|
||||
@PostMapping("/bindParentUser")
|
||||
@Operation(summary = "绑定父子用户关系")
|
||||
public ResponseEntity<Map<String, Object>> bindParentUser(
|
||||
@RequestParam String parentUserId,
|
||||
@RequestParam(required = false) String parentUserName,
|
||||
@RequestParam String childUserId,
|
||||
@RequestParam(required = false) String childUserName,
|
||||
@RequestParam String tenantId) {
|
||||
Map<String, Object> result = lbDepartmentUserService.bindParentUser(
|
||||
parentUserId, parentUserName, childUserId, childUserName, tenantId
|
||||
);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,10 @@ public interface ILbDepartmentUserService extends IService<LbDepartmentUser> {
|
||||
String name,
|
||||
String phone,
|
||||
String industry);
|
||||
|
||||
Map<String, Object> bindParentUser(String parentUserId,
|
||||
String parentUserName,
|
||||
String childUserId,
|
||||
String childUserName,
|
||||
String tenantId);
|
||||
}
|
||||
|
||||
@@ -152,4 +152,72 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> bindParentUser(String parentUserId,
|
||||
String parentUserName,
|
||||
String childUserId,
|
||||
String childUserName,
|
||||
String tenantId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (parentUserId == null || parentUserId.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "父用户id不能为空");
|
||||
return result;
|
||||
}
|
||||
if (childUserId == null || childUserId.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "子用户id不能为空");
|
||||
return result;
|
||||
}
|
||||
if (tenantId == null || tenantId.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "租户id不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
String parentUserIdTrim = parentUserId.trim();
|
||||
String childUserIdTrim = childUserId.trim();
|
||||
String tenantIdTrim = tenantId.trim();
|
||||
|
||||
// 第1步:根据子用户id查询目标记录
|
||||
LambdaQueryWrapper<LbDepartmentUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(LbDepartmentUser::getTenantId, tenantIdTrim)
|
||||
.eq(LbDepartmentUser::getUserId, childUserIdTrim);
|
||||
if (childUserName != null && !childUserName.trim().isEmpty()) {
|
||||
queryWrapper.eq(LbDepartmentUser::getName, childUserName.trim());
|
||||
}
|
||||
LbDepartmentUser childUser = this.getOne(queryWrapper, false);
|
||||
if (childUser == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "未查询到对应子用户");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 第2步:设置父用户id
|
||||
childUser.setParentId(parentUserIdTrim);
|
||||
childUser.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 第3步:更新数据库表
|
||||
boolean ok = this.updateById(childUser);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "绑定父用户成功" : "绑定父用户失败");
|
||||
if (ok) {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("parentUserId", parentUserIdTrim);
|
||||
data.put("parentUserName", parentUserName);
|
||||
data.put("childUserId", childUserIdTrim);
|
||||
data.put("childUserName", childUser.getName());
|
||||
data.put("tenantId", tenantIdTrim);
|
||||
data.put("record", this.getById(childUser.getId()));
|
||||
result.put("data", data);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "绑定父子用户异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user