|
|
@@ -1,11 +1,14 @@
|
|
|
package com.izouma.wenlvju.web;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.izouma.wenlvju.domain.Organization;
|
|
|
import com.izouma.wenlvju.domain.Setting;
|
|
|
-import com.izouma.wenlvju.service.SettingService;
|
|
|
import com.izouma.wenlvju.dto.PageQuery;
|
|
|
import com.izouma.wenlvju.exception.BusinessException;
|
|
|
+import com.izouma.wenlvju.repo.OrganizationRepo;
|
|
|
import com.izouma.wenlvju.repo.SettingRepo;
|
|
|
+import com.izouma.wenlvju.service.SettingService;
|
|
|
import com.izouma.wenlvju.utils.ObjUtils;
|
|
|
import com.izouma.wenlvju.utils.excel.ExcelUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -21,21 +24,58 @@ import java.util.List;
|
|
|
@RequestMapping("/setting")
|
|
|
@AllArgsConstructor
|
|
|
public class SettingController extends BaseController {
|
|
|
- private SettingService settingService;
|
|
|
- private SettingRepo settingRepo;
|
|
|
+ private SettingService settingService;
|
|
|
+ private SettingRepo settingRepo;
|
|
|
+ private OrganizationRepo organizationRepo;
|
|
|
|
|
|
- //@PreAuthorize("hasRole('ADMIN')")
|
|
|
+ @PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
|
public Setting save(@RequestBody Setting record) {
|
|
|
if (record.getId() != null) {
|
|
|
Setting orig = settingRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
ObjUtils.merge(orig, record);
|
|
|
- return settingRepo.save(orig);
|
|
|
+ Setting save = settingRepo.save(orig);
|
|
|
+
|
|
|
+ //艺考联盟
|
|
|
+ if (orig.getFlag() == 5) {
|
|
|
+ Organization organization = organizationRepo.findByAllianceId(record.getId()).orElse(null);
|
|
|
+ if (ObjectUtil.isNotNull(organization)) {
|
|
|
+ if (!organization.getName().equals(save.getName())) {
|
|
|
+ organization.setAllianceId(null);
|
|
|
+ organizationRepo.save(organization);
|
|
|
+ List<Organization> organizations = organizationRepo.findAllByNameEquals(record.getName());
|
|
|
+ if (CollUtil.isNotEmpty(organizations)) {
|
|
|
+ organization = organizations.get(0);
|
|
|
+ organization.setAllianceId(record.getId());
|
|
|
+ organizationRepo.save(organization);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<Organization> organizations = organizationRepo.findAllByNameEquals(record.getName());
|
|
|
+ if (CollUtil.isNotEmpty(organizations)) {
|
|
|
+ organization = organizations.get(0);
|
|
|
+ organization.setAllianceId(record.getId());
|
|
|
+ organizationRepo.save(organization);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return save;
|
|
|
}
|
|
|
if (record.getParent() == null) {
|
|
|
record.setFlag(settingRepo.nextSort());
|
|
|
}
|
|
|
- return settingRepo.save(record);
|
|
|
+ record = settingRepo.save(record);
|
|
|
+
|
|
|
+ if (record.getFlag() == 5) {
|
|
|
+ List<Organization> organizations = organizationRepo.findAllByNameEquals(record.getName());
|
|
|
+ if (organizations.size() > 0) {
|
|
|
+ Organization organization = organizations.get(0);
|
|
|
+ organization.setAllianceId(record.getId());
|
|
|
+ organizationRepo.save(organization);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return record;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -70,7 +110,7 @@ public class SettingController extends BaseController {
|
|
|
@PostMapping("/byFlag")
|
|
|
public List<Setting> byFlag(int flag) {
|
|
|
List<Setting> tree = settingService.getTree(settingRepo.findAllByFlag(flag));
|
|
|
- if (CollUtil.isEmpty(tree)){
|
|
|
+ if (CollUtil.isEmpty(tree)) {
|
|
|
return null;
|
|
|
}
|
|
|
return tree.get(0).getChildren();
|