This commit is contained in:
oneao committed 2025-12-19 17:31:43 +08:00
1 parent 1fea531918
commit 898d209594
11 files changed
+295 -78

No files matched your search

@@ -5,13 +5,14 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DeleteCompanyUserDTO {
@NotNull(message = "公司成员不能为空")
private Long id;
private List<Long> ids;
@NotNull(message = "公司不能为空")
private Long companyId;
@@ -18,7 +18,6 @@ public class UpdateCompanyUserDTO {
@NotBlank(message = "邮箱不能为空")
private String email;
@NotBlank(message = "密码不能为空")
private String password;
private String position;
@@ -12,6 +12,7 @@ import cn.link56.company.model.dto.UpdateCompanyUserDTO;
import cn.link56.company.model.po.CompanyUserPO;
import cn.link56.company.model.vo.QueryCompanyUserVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
@@ -205,46 +206,69 @@ public class CompanyUserService extends ServiceImpl<CompanyUserMapper, CompanyUs
public void updateCompanyUser(UpdateCompanyUserDTO companyUserDTO) {
Long id = companyUserDTO.getId();
Long companyId = companyUserDTO.getCompanyId();
String email = companyUserDTO.getEmail();
String phone = companyUserDTO.getPhone();
String password = companyUserDTO.getPassword();
boolean hasPermission = hasPermission(companyId, UserContext.getUserId());
if (!hasPermission){
if (!hasPermission) {
throw new BusinessException("您没有权限访问该公司的信息,操作被拒绝");
}
CompanyUserPO companyUserPO = companyUserMapper.selectById(id);
if (ObjectUtils.isEmpty(companyUserPO)){
String oldPassword = companyUserPO.getPassword();
if (ObjectUtils.isEmpty(companyUserPO)) {
throw new BusinessException("更新失败,该用户不存在");
}
// 检查邮箱
if (!StringUtils.equals(email, companyUserPO.getEmail())
&& isEmailExists(email)) {
// 检查邮箱是否发生变化
boolean isEmailChanged = !StringUtils.equals(email, companyUserPO.getEmail());
if (isEmailChanged && isEmailExists(email)) {
throw new BusinessException("邮箱已被注册");
}
// 检查手机号
if (!StringUtils.equals(phone, companyUserPO.getPhone())
&& isPhoneExists(phone)) {
// 检查手机号是否发生变化
if (!StringUtils.equals(phone, companyUserPO.getPhone()) && isPhoneExists(phone)) {
throw new BusinessException("手机号已被注册");
}
BeanUtils.copyProperties(companyUserDTO,companyUserPO);
if (StringUtils.isNotBlank(password)) {
companyUserPO.setPassword(password);
}
BeanUtils.copyProperties(companyUserDTO, companyUserPO);
if(StringUtils.isNotBlank(password)){
companyUserPO.setPassword(password);
}else{
companyUserPO.setPassword(oldPassword);
}
// 更新用户信息
companyUserMapper.updateById(companyUserPO);
}
public void deleteCompanyUser(DeleteCompanyUserDTO deleteCompanyUserDTO) {
Long id = deleteCompanyUserDTO.getId();
List<Long> ids = deleteCompanyUserDTO.getIds();
Long companyId = deleteCompanyUserDTO.getCompanyId();
// 检查用户是否有权限删除该公司用户
boolean hasPermission = hasPermission(companyId, UserContext.getUserId());
if (!hasPermission){
if (!hasPermission) {
throw new BusinessException("您没有权限访问该公司的信息,操作被拒绝");
}
companyUserMapper.deleteById(id);
LambdaUpdateWrapper<CompanyUserPO> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.in(CompanyUserPO::getId, ids)
.eq(CompanyUserPO::getCompanyId, companyId)
.ne(CompanyUserPO::getRole, 0);
// 执行删除操作
companyUserMapper.delete(updateWrapper);
}
}