This commit is contained in:
oneao committed 2025-12-18 17:28:06 +08:00
1 parent 1217f7df5f
commit 6e59e8be45
42 files changed
+1256 -430

No files matched your search

@@ -6,6 +6,8 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Data
@AllArgsConstructor
@@ -20,10 +22,10 @@ public class AuthRegisterDTO {
public static class Company {
@NotBlank(message = "公司名称不能为空")
private String name;
@NotBlank(message = "所属行业不能为空")
private String industry;
@NotBlank(message = "公司地址不能为空")
private String area;
@NotEmpty(message = "所属行业不能为空")
private List<String> industries;
@NotEmpty(message = "公司地址不能为空")
private List<String> areas;
private String phone;
private String email;
private String profile;
@@ -43,6 +43,10 @@ public class AuthIdentityService {
}
if(StringUtils.isNotBlank(company.getPhone()) && companyService.isPhoneExists(company.getPhone())){
throw new BusinessException("公司联系方式已被注册");
}
if(StringUtils.isNotBlank(company.getEmail()) && companyService.isEmailExists(company.getEmail())){
throw new BusinessException("公司邮箱已被注册");
}
@@ -60,8 +64,8 @@ public class AuthIdentityService {
new CompanyPO()
.setId(companyId)
.setName(company.getName())
.setIndustry(company.getIndustry())
.setArea(company.getArea())
.setIndustry(StringUtils.join(company.getIndustries(),","))
.setArea(StringUtils.join(company.getAreas(),","))
.setPhone(company.getPhone())
.setEmail(company.getEmail())
.setProfile(company.getProfile())
@@ -116,7 +120,12 @@ public class AuthIdentityService {
*/
private AuthLoginVO buildLoginVO(CompanyUserPO user) {
CompanyPO company = companyService.getById(user.getCompanyId());
AuthToken authToken = tokenService.generateToken(new TokenPayload(user.getCompanyId(), user.getId()));
TokenPayload tokenPayload = new TokenPayload();
tokenPayload.setCompanyId(user.getCompanyId());
tokenPayload.setUserId(user.getId());
AuthToken authToken = tokenService.generateToken(tokenPayload);
return new AuthLoginVO(
company.getId(),
@@ -7,10 +7,7 @@ import cn.link56.common.Result;
import cn.link56.common.utils.HttpUtils;
import cn.link56.common.utils.JsonUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -20,7 +17,7 @@ public class FileController {
@Resource
private FileService fileService;
@PostMapping("/getAliyunKey")
@GetMapping("/getAliyunKey")
public Result<AliyunKeyVO> getAliyunKey() {
String requestUrl = "http://g3oss.g3soft.cn:8082/upload?orgid=link56&bucket=g3hdzjsj";
String s = HttpUtils.sendGet(requestUrl);
@@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
@Accessors(chain = true)
public class FilePO {
@TableId(value = "b_id")
private String id;
private Long id;
@TableField("mx_filename")
private String name;
@@ -3,6 +3,7 @@ package cn.link56.base.service;
import cn.link56.base.mapper.FileMapper;
import cn.link56.base.model.dto.AddFileDTO;
import cn.link56.base.model.po.FilePO;
import cn.link56.common.utils.snowflake.idgen.IdGenerator;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@@ -30,7 +31,11 @@ public class FileService extends ServiceImpl<FileMapper, FilePO> {
}
FilePO filePO = new FilePO();
filePO.setExt(suffix).setName(fileName).setMapName(fileMapName).setSize(fileSize);
filePO.setId(IdGenerator.nextId())
.setExt(suffix)
.setName(fileName)
.setMapName(fileMapName)
.setSize(fileSize);
fileMapper.insert(filePO);
}
@@ -30,8 +30,6 @@ public class AuthInterceptor implements HandlerInterceptor {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
return true;
}
System.out.println(request.getRequestURI());
System.out.println(request.getRequestURL());
try {
String token = request.getHeader("Authorization");
@@ -39,6 +37,12 @@ public class AuthInterceptor implements HandlerInterceptor {
return writeUnauthorized(response);
}
if (token.startsWith("Bearer ")) {
token = token.substring(7);
}else{
return writeUnauthorized(response);
}
boolean flag = authTokenService.validateToken(token);
if (!flag){
@@ -2,17 +2,19 @@ package cn.link56.company.controller;
import cn.link56.common.BasePageVO;
import cn.link56.common.Result;
import cn.link56.company.model.dto.PageCompanyDTO;
import cn.link56.company.model.dto.QueryCompanyDTO;
import cn.link56.company.model.dto.UpdateCompanyDTO;
import cn.link56.company.model.vo.CompanyDetailVO;
import cn.link56.company.model.vo.PageCompanyVO;
import cn.link56.company.model.vo.QueryCompanyVO;
import cn.link56.company.model.vo.RecommendCompanyVO;
import cn.link56.company.model.vo.RecommendHotCompanyVO;
import cn.link56.company.service.CompanyService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.util.List;
@RestController
@@ -23,8 +25,8 @@ public class CompanyController {
// 公司分页
@PostMapping("/query")
public Result<BasePageVO<PageCompanyVO>> query(@RequestBody PageCompanyDTO pageCompanyDTO){
BasePageVO<PageCompanyVO> data = companyService.queryCompany(pageCompanyDTO);
public Result<BasePageVO<QueryCompanyVO>> query(@RequestBody QueryCompanyDTO queryCompanyDTO){
BasePageVO<QueryCompanyVO> data = companyService.queryCompany(queryCompanyDTO);
return Result.success(data);
}
@@ -44,9 +46,19 @@ public class CompanyController {
// 公司详细
@GetMapping("/detail/{id}")
public Result<CompanyDetailVO> getCompanyDetail(@PathVariable Long id){
public Result<CompanyDetailVO> getCompanyDetail(@PathVariable
@NotNull(message = "公司ID不能为空")
@Positive(message = "公司ID不能为空")
Long id){
CompanyDetailVO companyDetailVO = companyService.getCompanyDetail(id);
return Result.success(companyDetailVO);
}
// 更新
@PostMapping("/update")
public Result<Void> updateDetail(@RequestBody @Validated UpdateCompanyDTO updateCompanyDTO){
companyService.updateDetail(updateCompanyDTO);
return Result.success();
}
}
@@ -0,0 +1,39 @@
package cn.link56.company.controller;
import cn.link56.common.BasePageVO;
import cn.link56.common.Result;
import cn.link56.company.model.dto.AddCompanyUserDTO;
import cn.link56.company.model.dto.QueryCompanyUserDTO;
import cn.link56.company.model.dto.UpdateCompanyUserDTO;
import cn.link56.company.model.vo.QueryCompanyUserVO;
import cn.link56.company.service.CompanyUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/company/user")
public class CompanyUserController {
@Resource
private CompanyUserService companyUserService;
@PostMapping("/query")
public Result<BasePageVO<QueryCompanyUserVO>> getUsersByCompanyId(@RequestBody QueryCompanyUserDTO queryCompanyUserDTO) {
BasePageVO<QueryCompanyUserVO> result = companyUserService.getUsersByCompanyId(queryCompanyUserDTO);
return Result.success(result);
}
@PostMapping("/add")
public Result<Void> addCompanyUser(@RequestBody @Validated AddCompanyUserDTO companyUserDTO){
companyUserService.addCompanyUser(companyUserDTO);
return Result.success();
}
@PostMapping("/update")
public Result<Void> updateCompanyUser(@RequestBody @Validated UpdateCompanyUserDTO companyUserDTO){
companyUserService.updateCompanyUser(companyUserDTO);
return Result.success();
}
}
@@ -0,0 +1,26 @@
package cn.link56.company.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AddCompanyUserDTO {
@NotNull(message = "公司不能为空")
private Long companyId;
@NotBlank(message = "邮箱不能为空")
private String email;
@NotBlank(message = "密码不能为空")
private String password;
private String position;
private String name;
private String phone;
private String canuse;
}
@@ -9,7 +9,7 @@ import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageCompanyDTO {
public class QueryCompanyDTO {
private Integer currentPage;
private Integer pageSize;
@@ -0,0 +1,23 @@
package cn.link56.company.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class QueryCompanyUserDTO {
private Integer currentPage;
private Integer pageSize;
@NotNull(message = "公司ID不能为空")
private Long companyId;
private String name;
private String position;
private String email;
private String phone;
private String canuse;
}
@@ -0,0 +1,34 @@
package cn.link56.company.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateCompanyDTO {
@NotNull(message = "公司ID不能为空")
private Long id;
@NotBlank(message = "公司名称不能为空")
private String name;
@NotEmpty(message = "所属行业不能为空")
private List<String> industries;
@NotEmpty(message = "公司地址不能为空")
private List<String> areas;
private Date establishmentDate;
private String logo;
private String phone;
private String email;
private String profile;
private String description;
}
@@ -0,0 +1,28 @@
package cn.link56.company.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateCompanyUserDTO {
@NotNull(message = "用户不能为空")
private Long id;
@NotNull(message = "公司不能为空")
private Long companyId;
@NotBlank(message = "邮箱不能为空")
private String email;
@NotBlank(message = "密码不能为空")
private String password;
private String position;
private String name;
private String phone;
private String canuse;
}
@@ -64,4 +64,8 @@ public class CompanyPO {
@TableField("b_hot_recommend")
private String hotRecommend;
@TableField("b_establishment_date")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date establishmentDate;
}
@@ -42,6 +42,9 @@ public class CompanyUserPO {
@TableField("b_position")
private String position;
@TableField("b_canuse")
private String canuse;
@TableField(value = "b_create_time",fill = FieldFill.INSERT)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
@Data
@@ -19,6 +20,7 @@ public class CompanyDetailVO {
private String email;
private String phone;
private String description;
private Date establishmentDate;
private List<User> users;
@Data
@@ -0,0 +1,21 @@
package cn.link56.company.model.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class QueryCompanyUserVO {
private Long id;
private String name;
private Integer role;
private String position;
private String email;
private String phone;
private String canuse;
}
@@ -11,7 +11,7 @@ import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class PageCompanyVO {
public class QueryCompanyVO {
private Long id;
private String name;
private List<String> areas;
@@ -1,26 +1,30 @@
package cn.link56.company.service;
import cn.link56.common.BasePageVO;
import cn.link56.common.context.UserContext;
import cn.link56.common.exception.BusinessException;
import cn.link56.company.mapper.CompanyMapper;
import cn.link56.company.mapper.CompanyUserMapper;
import cn.link56.company.model.dto.PageCompanyDTO;
import cn.link56.company.model.dto.QueryCompanyDTO;
import cn.link56.company.model.dto.UpdateCompanyDTO;
import cn.link56.company.model.middle.RecommendCompanyRow;
import cn.link56.company.model.po.CompanyPO;
import cn.link56.company.model.po.CompanyUserPO;
import cn.link56.company.model.vo.CompanyDetailVO;
import cn.link56.company.model.vo.PageCompanyVO;
import cn.link56.company.model.vo.QueryCompanyVO;
import cn.link56.company.model.vo.RecommendCompanyVO;
import cn.link56.company.model.vo.RecommendHotCompanyVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@@ -99,13 +103,24 @@ public class CompanyService extends ServiceImpl<CompanyMapper,CompanyPO> {
return count > 0;
}
public BasePageVO<PageCompanyVO> queryCompany(PageCompanyDTO pageCompanyDTO) {
Integer currentPage = pageCompanyDTO.getCurrentPage();
Integer pageSize = pageCompanyDTO.getPageSize();
/**
* 检查公司邮箱是否重复
*/
public boolean isEmailExists(String email) {
Long count = companyMapper.selectCount(
new LambdaQueryWrapper<CompanyPO>()
.eq(CompanyPO::getEmail, email)
);
return count > 0;
}
String name = pageCompanyDTO.getName();
List<String> areas = pageCompanyDTO.getAreas();
List<String> industries = pageCompanyDTO.getIndustries();
public BasePageVO<QueryCompanyVO> queryCompany(QueryCompanyDTO queryCompanyDTO) {
Integer currentPage = queryCompanyDTO.getCurrentPage();
Integer pageSize = queryCompanyDTO.getPageSize();
String name = queryCompanyDTO.getName();
List<String> areas = queryCompanyDTO.getAreas();
List<String> industries = queryCompanyDTO.getIndustries();
// 分页
Page<CompanyPO> companyPage = new Page<>(currentPage,pageSize);
@@ -136,23 +151,23 @@ public class CompanyService extends ServiceImpl<CompanyMapper,CompanyPO> {
queryWrapper.eq(CompanyPO::getCanuse,"1");
List<PageCompanyVO> result = companyMapper.selectList(companyPage, queryWrapper).stream().map(item -> {
PageCompanyVO pageCompanyVO = new PageCompanyVO();
List<QueryCompanyVO> result = companyMapper.selectList(companyPage, queryWrapper).stream().map(item -> {
QueryCompanyVO queryCompanyVO = new QueryCompanyVO();
pageCompanyVO.setId(item.getId());
pageCompanyVO.setName(item.getName());
pageCompanyVO.setProfile(item.getProfile());
pageCompanyVO.setLogo(item.getLogo());
pageCompanyVO.setAreas(Arrays.stream(item.getArea().split(","))
queryCompanyVO.setId(item.getId());
queryCompanyVO.setName(item.getName());
queryCompanyVO.setProfile(item.getProfile());
queryCompanyVO.setLogo(item.getLogo());
queryCompanyVO.setAreas(Arrays.stream(item.getArea().split(","))
.collect(Collectors.toList()));
pageCompanyVO.setIndustries(Arrays.stream(item.getIndustry().split(","))
queryCompanyVO.setIndustries(Arrays.stream(item.getIndustry().split(","))
.collect(Collectors.toList()));
return pageCompanyVO;
return queryCompanyVO;
}).collect(Collectors.toList());
return new BasePageVO<PageCompanyVO>()
return new BasePageVO<QueryCompanyVO>()
.setRecords(result)
.setTotal(companyPage.getTotal());
}
@@ -172,11 +187,62 @@ public class CompanyService extends ServiceImpl<CompanyMapper,CompanyPO> {
companyDetailVO.setUsers(companyUserPOS.stream()
.map(item -> {
CompanyDetailVO.User user = new CompanyDetailVO.User();
BeanUtils.copyProperties(item, user); // 复制属性
BeanUtils.copyProperties(item, user);
return user;
})
.collect(Collectors.toList()));
return companyDetailVO;
}
@Transactional
public void updateDetail(UpdateCompanyDTO updateCompanyDTO) {
Long id = updateCompanyDTO.getId();
if (!companyUserService.hasPermission(id,UserContext.getUserId())){
throw new BusinessException("您没有权限访问该公司的信息,操作被拒绝");
}
String name = updateCompanyDTO.getName();
String phone = updateCompanyDTO.getPhone();
String email = updateCompanyDTO.getEmail();
Date establishmentDate = updateCompanyDTO.getEstablishmentDate();
String profile = updateCompanyDTO.getProfile();
String description = updateCompanyDTO.getDescription();
String logo = updateCompanyDTO.getLogo();
String area = StringUtils.join(updateCompanyDTO.getAreas(), ",");
String industry = StringUtils.join(updateCompanyDTO.getIndustries(), ",");
// 检查
CompanyPO companyPO = companyMapper.selectById(id);
if (ObjectUtils.isEmpty(companyPO)){
throw new BusinessException("更新失败,该公司不存在");
}
// 检查名称
if (!companyPO.getName().equals(name) && isNameExists(name)){
throw new BusinessException("公司名称已存在");
}
// 检查联系电话
if (!StringUtils.equals(phone, companyPO.getPhone())
&& isPhoneExists(phone)) {
throw new BusinessException("公司联系电话已存在");
}
// 检查邮箱
if (!StringUtils.equals(email, companyPO.getEmail())
&& isEmailExists(email)) {
throw new BusinessException("公司联系邮箱已存在");
}
// 更新
BeanUtils.copyProperties(updateCompanyDTO,companyPO);
companyPO.setArea(area);
companyPO.setIndustry(industry);
// 保存更新后的公司信息
companyMapper.updateById(companyPO);
}
}
@@ -1,13 +1,27 @@
package cn.link56.company.service;
import cn.link56.common.BasePageVO;
import cn.link56.common.context.UserContext;
import cn.link56.common.exception.BusinessException;
import cn.link56.common.utils.snowflake.idgen.IdGenerator;
import cn.link56.company.mapper.CompanyUserMapper;
import cn.link56.company.model.dto.AddCompanyUserDTO;
import cn.link56.company.model.dto.QueryCompanyUserDTO;
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.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class CompanyUserService extends ServiceImpl<CompanyUserMapper, CompanyUserPO> {
@@ -21,6 +35,9 @@ public class CompanyUserService extends ServiceImpl<CompanyUserMapper, CompanyUs
* @return true 表示邮箱已存在,false 表示可用
*/
public boolean isEmailExists(String email) {
if(StringUtils.isBlank(email)){
return false;
}
long count = companyUserMapper.selectCount(
new LambdaQueryWrapper<CompanyUserPO>()
.eq(CompanyUserPO::getEmail, email)
@@ -42,6 +59,38 @@ public class CompanyUserService extends ServiceImpl<CompanyUserMapper, CompanyUs
}
/**
* 校验当前用户是否有权限操作指定的公司
* @param companyId 当前公司ID
* @param userId 当前用户ID
* @return 是否有权限
*/
public boolean hasPermission(Long companyId, Long userId) {
// 根据 userId 查询公司用户信息
CompanyUserPO companyUserPO = companyUserMapper.selectById(userId);
// 如果 companyUserPO 为空,表示该用户不存在,直接返回无权限
if (ObjectUtils.isEmpty(companyUserPO)) {
return false;
}
// 判断用户公司是否属于该公司
if(!UserContext.getCompanyId().equals(companyId)){
return false;
}
// 判断用户是否属于该公司
if (!companyUserPO.getCompanyId().equals(companyId)) {
return false;
}
// 检查用户角色是否为 0,只有角色为 0 才有权限
return companyUserPO.getRole() == 0;
// 如果角色不是 0,表示没有权限
}
public CompanyUserPO loginByEmailAndPassword(String email, String password){
LambdaQueryWrapper<CompanyUserPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CompanyUserPO::getEmail,email)
@@ -63,4 +112,125 @@ public class CompanyUserService extends ServiceImpl<CompanyUserMapper, CompanyUs
return companyUserMapper.selectList(queryWrapper);
}
public BasePageVO<QueryCompanyUserVO> getUsersByCompanyId(QueryCompanyUserDTO queryCompanyUserDTO) {
boolean hasPermission = hasPermission(queryCompanyUserDTO.getCompanyId(), UserContext.getUserId());
if (!hasPermission){
throw new BusinessException("您没有权限访问该公司的信息,操作被拒绝");
}
Integer currentPage = queryCompanyUserDTO.getCurrentPage();
Integer pageSize = queryCompanyUserDTO.getPageSize();
Long companyId = queryCompanyUserDTO.getCompanyId();
String name = queryCompanyUserDTO.getName();
String email = queryCompanyUserDTO.getEmail();
String phone = queryCompanyUserDTO.getPhone();
String position = queryCompanyUserDTO.getPosition();
String canuse = queryCompanyUserDTO.getCanuse();
Page<CompanyUserPO> queryPage = new Page<>(currentPage,pageSize);
LambdaQueryWrapper<CompanyUserPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CompanyUserPO::getCompanyId,companyId);
if (StringUtils.isNotBlank(name)){
queryWrapper.like(CompanyUserPO::getName,name);
}
if (StringUtils.isNotBlank(email)){
queryWrapper.like(CompanyUserPO::getEmail,email);
}
if (StringUtils.isNotBlank(phone)){
queryWrapper.like(CompanyUserPO::getPhone,phone);
}
if (StringUtils.isNotBlank(position)){
queryWrapper.like(CompanyUserPO::getPosition,position);
}
if (StringUtils.isNotBlank(canuse)){
queryWrapper.eq(CompanyUserPO::getCanuse,canuse);
}
List<CompanyUserPO> companyUserPOS = companyUserMapper.selectList(queryPage, queryWrapper);
List<QueryCompanyUserVO> result = companyUserPOS.stream().map(item -> {
QueryCompanyUserVO queryCompanyUserVO = new QueryCompanyUserVO();
BeanUtils.copyProperties(item, queryCompanyUserVO);
return queryCompanyUserVO;
}).collect(Collectors.toList());
return new BasePageVO<>(queryPage.getTotal(),result);
}
@Transactional
public void addCompanyUser(AddCompanyUserDTO companyUserDTO) {
boolean hasPermission = hasPermission(companyUserDTO.getCompanyId(), UserContext.getUserId());
if (!hasPermission){
throw new BusinessException("您没有权限访问该公司的信息,操作被拒绝");
}
String email = companyUserDTO.getEmail();
String phone = companyUserDTO.getPhone();
if(isEmailExists(email)){
throw new BusinessException("邮箱已被注册");
}
if(StringUtils.isNotBlank(phone) && !isPhoneExists(phone)){
throw new BusinessException("手机号已被注册");
}
String canuse = companyUserDTO.getCanuse();
if (StringUtils.isBlank(canuse) || (!"1".equals(canuse) && !"0".equals(canuse))) {
canuse = "1";
}
CompanyUserPO companyUserPO = new CompanyUserPO();
BeanUtils.copyProperties(companyUserDTO,companyUserPO);
companyUserPO.setId(IdGenerator.nextId());
companyUserPO.setRole(1);
companyUserPO.setCanuse(canuse);
companyUserMapper.insert(companyUserPO);
}
@Transactional
public void updateCompanyUser(UpdateCompanyUserDTO companyUserDTO) {
Long id = companyUserDTO.getId();
Long companyId = companyUserDTO.getCompanyId();
String email = companyUserDTO.getEmail();
String phone = companyUserDTO.getPhone();
boolean hasPermission = hasPermission(companyId, UserContext.getUserId());
if (!hasPermission){
throw new BusinessException("您没有权限访问该公司的信息,操作被拒绝");
}
CompanyUserPO companyUserPO = companyUserMapper.selectById(id);
if (ObjectUtils.isEmpty(companyUserPO)){
throw new BusinessException("更新失败,该用户不存在");
}
// 检查邮箱
if (!StringUtils.equals(email, companyUserPO.getEmail())
&& isEmailExists(email)) {
throw new BusinessException("邮箱已被注册");
}
// 检查手机号
if (!StringUtils.equals(phone, companyUserPO.getPhone())
&& isPhoneExists(phone)) {
throw new BusinessException("手机号已被注册");
}
BeanUtils.copyProperties(companyUserDTO,companyUserPO);
companyUserMapper.updateById(companyUserPO);
}
}