|
@@ -3,6 +3,7 @@ package com.izouma.jiashanxia.service;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.jiashanxia.domain.Company;
|
|
import com.izouma.jiashanxia.domain.Company;
|
|
|
import com.izouma.jiashanxia.domain.User;
|
|
import com.izouma.jiashanxia.domain.User;
|
|
|
|
|
+import com.izouma.jiashanxia.dto.CompanyDTO;
|
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
|
import com.izouma.jiashanxia.enums.AuthorityName;
|
|
import com.izouma.jiashanxia.enums.AuthorityName;
|
|
|
import com.izouma.jiashanxia.exception.BusinessException;
|
|
import com.izouma.jiashanxia.exception.BusinessException;
|
|
@@ -16,6 +17,7 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -30,14 +32,31 @@ public class CompanyService {
|
|
|
private UserRepo userRepo;
|
|
private UserRepo userRepo;
|
|
|
private UserPackageRepo userPackageRepo;
|
|
private UserPackageRepo userPackageRepo;
|
|
|
|
|
|
|
|
- public Page<Company> all(PageQuery pageQuery, User user) {
|
|
|
|
|
|
|
+ public Page<CompanyDTO> all(PageQuery pageQuery, User user) {
|
|
|
pageQuery.setSort("createdAt,desc");
|
|
pageQuery.setSort("createdAt,desc");
|
|
|
Set<Authority> authorities = user.getAuthorities();
|
|
Set<Authority> authorities = user.getAuthorities();
|
|
|
if (!authorities.contains(Authority.get(AuthorityName.ROLE_ADMIN)) && authorities.contains(Authority.get(AuthorityName.ROLE_CREATOR))) {
|
|
if (!authorities.contains(Authority.get(AuthorityName.ROLE_ADMIN)) && authorities.contains(Authority.get(AuthorityName.ROLE_CREATOR))) {
|
|
|
Map<String, Object> query = pageQuery.getQuery();
|
|
Map<String, Object> query = pageQuery.getQuery();
|
|
|
query.put("userId", user.getId());
|
|
query.put("userId", user.getId());
|
|
|
|
|
+ return companyRepo.findAll(JpaUtils.toSpecification(pageQuery, Company.class), JpaUtils.toPageRequest(pageQuery))
|
|
|
|
|
+ .map(company -> {
|
|
|
|
|
+ CompanyDTO dto = new CompanyDTO(company);
|
|
|
|
|
+ dto.setNickname(user.getNickname());
|
|
|
|
|
+ return dto;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
- return companyRepo.findAll(JpaUtils.toSpecification(pageQuery, Company.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
|
|
|
|
+ Map<Long, User> userMap = userRepo.findAllByTeamFounderTrueAndDelFalse()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .collect(Collectors.toMap(User::getId, user1 -> user1));
|
|
|
|
|
+ return companyRepo.findAll(JpaUtils.toSpecification(pageQuery, Company.class), JpaUtils.toPageRequest(pageQuery))
|
|
|
|
|
+ .map(company -> {
|
|
|
|
|
+ User user1 = userMap.get(company.getUserId());
|
|
|
|
|
+ CompanyDTO dto = new CompanyDTO(company);
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(user1)) {
|
|
|
|
|
+ dto.setNickname(user1.getNickname());
|
|
|
|
|
+ }
|
|
|
|
|
+ return dto;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -71,19 +90,6 @@ public class CompanyService {
|
|
|
return userRepo.findAllByCompanyIdAndDelFalse(company.getId());
|
|
return userRepo.findAllByCompanyIdAndDelFalse(company.getId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- 批量增加员工
|
|
|
|
|
- */
|
|
|
|
|
- public void batchEmployee(List<Long> employee, Long companyId) {
|
|
|
|
|
- List<User> employees = userRepo.findAllById(employee);
|
|
|
|
|
- employees.forEach(yee -> {
|
|
|
|
|
- if (yee.getCompanyId() == null || !yee.getCompanyId().equals(companyId)) {
|
|
|
|
|
- yee.setCompanyId(companyId);
|
|
|
|
|
- userRepo.save(yee);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/*
|
|
/*
|
|
|
新建企业
|
|
新建企业
|
|
|
*/
|
|
*/
|
|
@@ -111,7 +117,7 @@ public class CompanyService {
|
|
|
// 新员工加入团队
|
|
// 新员工加入团队
|
|
|
employee.removeAll(userMap.keySet());
|
|
employee.removeAll(userMap.keySet());
|
|
|
if (ObjectUtil.isNotEmpty(employee)) {
|
|
if (ObjectUtil.isNotEmpty(employee)) {
|
|
|
- this.batchEmployee(employee, record.getId());
|
|
|
|
|
|
|
+ userRepo.updateCompanyId(record.getId(), employee);
|
|
|
}
|
|
}
|
|
|
// 更换团队管理人
|
|
// 更换团队管理人
|
|
|
if (!record.getUserId().equals(orig.getUserId())) {
|
|
if (!record.getUserId().equals(orig.getUserId())) {
|
|
@@ -131,8 +137,12 @@ public class CompanyService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 增加
|
|
// 增加
|
|
|
|
|
+ record.setAmount(BigDecimal.ZERO);
|
|
|
Company save = companyRepo.save(record);
|
|
Company save = companyRepo.save(record);
|
|
|
|
|
+ // 管理员加权限
|
|
|
this.teamFounder(save.getUserId(), creator, save.getId());
|
|
this.teamFounder(save.getUserId(), creator, save.getId());
|
|
|
|
|
+ // 员工加入企业
|
|
|
|
|
+ userRepo.updateCompanyId(save.getId(), record.getEmployee());
|
|
|
return save;
|
|
return save;
|
|
|
}
|
|
}
|
|
|
|
|
|