|
@@ -4,10 +4,13 @@ import com.zsElectric.boot.business.mapper.FirmAccountLogMapper;
|
|
|
import com.zsElectric.boot.business.model.entity.FirmAccountLog;
|
|
import com.zsElectric.boot.business.model.entity.FirmAccountLog;
|
|
|
import com.zsElectric.boot.business.model.form.FirmBalanceChangeForm;
|
|
import com.zsElectric.boot.business.model.form.FirmBalanceChangeForm;
|
|
|
import com.zsElectric.boot.core.exception.BusinessException;
|
|
import com.zsElectric.boot.core.exception.BusinessException;
|
|
|
|
|
+import com.zsElectric.boot.common.model.Option;
|
|
|
|
|
+import com.zsElectric.boot.system.service.DeptService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -22,12 +25,16 @@ import com.zsElectric.boot.business.converter.FirmInfoConverter;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 企业信息服务实现类
|
|
* 企业信息服务实现类
|
|
@@ -42,6 +49,7 @@ public class FirmInfoServiceImpl extends ServiceImpl<FirmInfoMapper, FirmInfo> i
|
|
|
|
|
|
|
|
private final FirmInfoConverter firmInfoConverter;
|
|
private final FirmInfoConverter firmInfoConverter;
|
|
|
private final FirmAccountLogMapper firmAccountLogMapper;
|
|
private final FirmAccountLogMapper firmAccountLogMapper;
|
|
|
|
|
+ private final DeptService deptService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取企业信息分页列表
|
|
* 获取企业信息分页列表
|
|
@@ -208,4 +216,56 @@ public class FirmInfoServiceImpl extends ServiceImpl<FirmInfoMapper, FirmInfo> i
|
|
|
return "FIRM" + timestamp + uuid;
|
|
return "FIRM" + timestamp + uuid;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取可用的部门选项(排除已被企业/渠道使用的部门)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param excludeId 编辑时排除的企业ID(允许选择自己关联的部门)
|
|
|
|
|
+ * @return 可用部门选项列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<Option<Long>> getAvailableDeptOptions(Long excludeId) {
|
|
|
|
|
+ // 1. 获取所有已被使用的deptId
|
|
|
|
|
+ LambdaQueryWrapper<FirmInfo> queryWrapper = new LambdaQueryWrapper<FirmInfo>()
|
|
|
|
|
+ .select(FirmInfo::getDeptId)
|
|
|
|
|
+ .isNotNull(FirmInfo::getDeptId);
|
|
|
|
|
+ // 如果是编辑模式,排除当前企业自己
|
|
|
|
|
+ if (excludeId != null) {
|
|
|
|
|
+ queryWrapper.ne(FirmInfo::getId, excludeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<FirmInfo> usedFirmList = this.list(queryWrapper);
|
|
|
|
|
+ Set<Long> usedDeptIds = usedFirmList.stream()
|
|
|
|
|
+ .map(FirmInfo::getDeptId)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 获取所有部门选项
|
|
|
|
|
+ List<Option<Long>> allDeptOptions = deptService.listDeptOptions();
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 提取子部门(排除顶级部门parent_id=0)
|
|
|
|
|
+ List<Option<Long>> childDeptOptions = new ArrayList<>();
|
|
|
|
|
+ for (Option<Long> option : allDeptOptions) {
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(option.getChildren())) {
|
|
|
|
|
+ childDeptOptions.addAll(option.getChildren());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 过滤掉已被使用的部门
|
|
|
|
|
+ return filterAvailableOptions(childDeptOptions, usedDeptIds);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 递归过滤可用的部门选项
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<Option<Long>> filterAvailableOptions(List<Option<Long>> options, Set<Long> usedDeptIds) {
|
|
|
|
|
+ if (CollectionUtil.isEmpty(options)) {
|
|
|
|
|
+ return options;
|
|
|
|
|
+ }
|
|
|
|
|
+ return options.stream()
|
|
|
|
|
+ .filter(option -> !usedDeptIds.contains(option.getValue()))
|
|
|
|
|
+ .peek(option -> {
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(option.getChildren())) {
|
|
|
|
|
+ option.setChildren(filterAvailableOptions(option.getChildren(), usedDeptIds));
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|