|
|
@@ -1,7 +1,10 @@
|
|
|
package com.izouma.jiashanxia.web;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.izouma.jiashanxia.domain.Company;
|
|
|
import com.izouma.jiashanxia.domain.User;
|
|
|
+import com.izouma.jiashanxia.dto.CompanyDTO;
|
|
|
+import com.izouma.jiashanxia.repo.UserRepo;
|
|
|
import com.izouma.jiashanxia.service.CompanyService;
|
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
|
import com.izouma.jiashanxia.exception.BusinessException;
|
|
|
@@ -17,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
|
|
|
@RestController
|
|
|
@@ -25,16 +29,41 @@ import java.util.List;
|
|
|
public class CompanyController extends BaseController {
|
|
|
private CompanyService companyService;
|
|
|
private CompanyRepo companyRepo;
|
|
|
+ private UserRepo userRepo;
|
|
|
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
|
- public Company save(@RequestBody Company record) {
|
|
|
+ public Company save(@RequestBody CompanyDTO record) {
|
|
|
if (record.getId() != null) {
|
|
|
Company orig = companyRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
ObjUtils.merge(orig, record);
|
|
|
+ List<Long> employee = record.getEmployee();
|
|
|
+ if (CollUtil.isNotEmpty(employee)) {
|
|
|
+ List<User> employees = userRepo.findAllById(employee);
|
|
|
+ employees.forEach(yee -> {
|
|
|
+ if (yee.getCompanyId() == null || !yee.getCompanyId().equals(record.getId())) {
|
|
|
+ yee.setCompanyId(record.getId());
|
|
|
+ userRepo.save(yee);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
return companyRepo.save(orig);
|
|
|
}
|
|
|
- return companyRepo.save(record);
|
|
|
+ Company save = companyRepo.save(Company.builder()
|
|
|
+ .amount(BigDecimal.ZERO)
|
|
|
+ .name(record.getName())
|
|
|
+ .userId(record.getUserId())
|
|
|
+ .build());
|
|
|
+ if (CollUtil.isNotEmpty(record.getEmployee())) {
|
|
|
+ List<User> employees = userRepo.findAllById(record.getEmployee());
|
|
|
+ employees.forEach(yee -> {
|
|
|
+ if (yee.getCompanyId() == null || !yee.getCompanyId().equals(record.getId())) {
|
|
|
+ yee.setCompanyId(record.getId());
|
|
|
+ userRepo.save(yee);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return save;
|
|
|
}
|
|
|
|
|
|
@PreAuthorize("hasAnyRole('ADMIN','CREATOR')")
|