|
|
@@ -0,0 +1,204 @@
|
|
|
+/*
|
|
|
+ * Copyright [2022] [https://www.xiaonuo.vip]
|
|
|
+ *
|
|
|
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
|
|
+ *
|
|
|
+ * 1.请不要删除和修改根目录下的LICENSE文件。
|
|
|
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
|
|
|
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
|
|
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
|
|
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
|
|
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
|
|
+ */
|
|
|
+package vip.xiaonuo.disk.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollStreamUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.lang.tree.Tree;
|
|
|
+import cn.hutool.core.lang.tree.TreeNode;
|
|
|
+import cn.hutool.core.lang.tree.TreeUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import vip.xiaonuo.common.enums.CommonSortOrderEnum;
|
|
|
+import vip.xiaonuo.common.exception.CommonException;
|
|
|
+import vip.xiaonuo.common.page.CommonPageRequest;
|
|
|
+import vip.xiaonuo.disk.domain.ResourceType;
|
|
|
+import vip.xiaonuo.disk.mapper.ResourceTypeMapper;
|
|
|
+import vip.xiaonuo.disk.param.ResourceTypeAddParam;
|
|
|
+import vip.xiaonuo.disk.param.ResourceTypeEditParam;
|
|
|
+import vip.xiaonuo.disk.param.ResourceTypeIdParam;
|
|
|
+import vip.xiaonuo.disk.param.ResourceTypePageParam;
|
|
|
+import vip.xiaonuo.disk.service.ResourceTypeService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * resource_typeService接口实现类
|
|
|
+ *
|
|
|
+ * @author pans
|
|
|
+ * @date 2025/07/04 14:39
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, ResourceType> implements ResourceTypeService {
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ResourceType> page(ResourceTypePageParam resourceTypePageParam) {
|
|
|
+ QueryWrapper<ResourceType> queryWrapper = new QueryWrapper<>();
|
|
|
+ // 查询部分字段
|
|
|
+ queryWrapper.lambda().select(ResourceType::getId, ResourceType::getParentId, ResourceType::getName,
|
|
|
+ ResourceType::getCategory, ResourceType::getSortCode, ResourceType::getIsResourceaccount);
|
|
|
+ if(ObjectUtil.isNotEmpty(resourceTypePageParam.getParentId())) {
|
|
|
+ queryWrapper.lambda().eq(ResourceType::getParentId, resourceTypePageParam.getParentId());
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(resourceTypePageParam.getSearchKey())) {
|
|
|
+ queryWrapper.lambda().like(ResourceType::getName, resourceTypePageParam.getSearchKey());
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isAllNotEmpty(resourceTypePageParam.getSortField(), resourceTypePageParam.getSortOrder())) {
|
|
|
+ CommonSortOrderEnum.validate(resourceTypePageParam.getSortOrder());
|
|
|
+ queryWrapper.orderBy(true, resourceTypePageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
|
|
|
+ StrUtil.toUnderlineCase(resourceTypePageParam.getSortField()));
|
|
|
+ } else {
|
|
|
+ queryWrapper.lambda().orderByAsc(ResourceType::getSortCode);
|
|
|
+ }
|
|
|
+ return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Tree<String>> tree() {
|
|
|
+ List<ResourceType> collegeList = this.getAllOrgList();
|
|
|
+ List<TreeNode<String>> treeNodeList = collegeList.stream().map(college ->
|
|
|
+ new TreeNode<>(college.getId(), college.getParentId(),
|
|
|
+ college.getName(), college.getSortCode()).setExtra(JSONUtil.parseObj(college)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return TreeUtil.build(treeNodeList, "0");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void add(ResourceTypeAddParam resourceTypeAddParam) {
|
|
|
+
|
|
|
+ ResourceType resourceType = BeanUtil.toBean(resourceTypeAddParam, ResourceType.class);
|
|
|
+ // 重复名称
|
|
|
+ boolean repeatName = this.count(new LambdaQueryWrapper<ResourceType>().eq(ResourceType::getParentId, resourceType.getParentId())
|
|
|
+ .eq(ResourceType::getName, resourceType.getName())) > 0;
|
|
|
+ if(repeatName) {
|
|
|
+ throw new CommonException("存在重复的同级组织,名称为:{}", resourceType.getName());
|
|
|
+ }
|
|
|
+ resourceType.setCode(RandomUtil.randomString(10));
|
|
|
+ this.save(resourceType);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void edit(ResourceTypeEditParam resourceTypeEditParam) {
|
|
|
+ ResourceType resourceType = this.queryEntity(resourceTypeEditParam.getId());
|
|
|
+ BeanUtil.copyProperties(resourceTypeEditParam, resourceType);
|
|
|
+ boolean repeatName = this.count(new LambdaQueryWrapper<ResourceType>().eq(ResourceType::getParentId, resourceType.getParentId())
|
|
|
+ .eq(ResourceType::getName, resourceType.getName()).ne(ResourceType::getId, resourceType.getId())) > 0;
|
|
|
+ if(repeatName) {
|
|
|
+ throw new CommonException("存在重复的同级组织,名称为:{}", resourceType.getName());
|
|
|
+ }
|
|
|
+ List<ResourceType> originDataList = this.getAllOrgList();
|
|
|
+ boolean errorLevel = this.getChildListById(originDataList, resourceType.getId(), true).stream()
|
|
|
+ .map(ResourceType::getId).collect(Collectors.toList()).contains(resourceType.getParentId());
|
|
|
+ if(errorLevel) {
|
|
|
+ throw new CommonException("不可选择上级组织:{}", this.getById(originDataList, resourceType.getParentId()).getName());
|
|
|
+ }
|
|
|
+ this.updateById(resourceType);
|
|
|
+
|
|
|
+ // 发布更新事件
|
|
|
+ // CommonDataChangeEventCenter.doUpdateWithData(SysDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(resourceType));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResourceType getById(List<ResourceType> originDataList, String id) {
|
|
|
+ int index = CollStreamUtil.toList(originDataList, ResourceType::getId).indexOf(id);
|
|
|
+ return index == -1?null:originDataList.get(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ResourceType> getAllOrgList() {
|
|
|
+ return this.list(new LambdaQueryWrapper<ResourceType>().orderByAsc(ResourceType::getSortCode));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ResourceType> getChildListById(List<ResourceType> originDataList, String id, boolean includeSelf) {
|
|
|
+ List<ResourceType> resultList = CollectionUtil.newArrayList();
|
|
|
+ execRecursionFindChild(originDataList, id, resultList);
|
|
|
+ if(includeSelf) {
|
|
|
+ ResourceType self = this.getById(originDataList, id);
|
|
|
+ if(ObjectUtil.isNotEmpty(self)) {
|
|
|
+ resultList.add(self);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void execRecursionFindChild(List<ResourceType> originDataList, String id, List<ResourceType> resultList) {
|
|
|
+ originDataList.forEach(item -> {
|
|
|
+ if(item.getParentId().equals(id)) {
|
|
|
+ resultList.add(item);
|
|
|
+ execRecursionFindChild(originDataList, item.getId(), resultList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(List<ResourceTypeIdParam> resourceTypeIdParamList) {
|
|
|
+ List<String> orgIdList = CollStreamUtil.toList(resourceTypeIdParamList, ResourceTypeIdParam::getId);
|
|
|
+ if(ObjectUtil.isNotEmpty(orgIdList)) {
|
|
|
+ List<ResourceType> allOrgList = this.getAllOrgList();
|
|
|
+ // 获取所有子组织
|
|
|
+ List<String> toDeleteOrgIdList = CollectionUtil.newArrayList();
|
|
|
+ orgIdList.forEach(orgId -> toDeleteOrgIdList.addAll(this.getChildListById(allOrgList, orgId, true).stream()
|
|
|
+ .map(ResourceType::getId).collect(Collectors.toList())));
|
|
|
+
|
|
|
+ // 执行删除
|
|
|
+ this.removeByIds(toDeleteOrgIdList);
|
|
|
+
|
|
|
+ // 发布删除事件
|
|
|
+ //CommonDataChangeEventCenter.doDeleteWithDataId(SysDataTypeEnum.ORG.getValue(), toDeleteOrgIdList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResourceType detail(ResourceTypeIdParam resourceTypeIdParam) {
|
|
|
+ return this.queryEntity(resourceTypeIdParam.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResourceType queryEntity(String id) {
|
|
|
+ ResourceType resourceType = this.getById(id);
|
|
|
+ if(ObjectUtil.isEmpty(resourceType)) {
|
|
|
+ throw new CommonException("resource_type不存在,id值为:{}", id);
|
|
|
+ }
|
|
|
+ return resourceType;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Tree<String>> orgTreeSelector() {
|
|
|
+ List<ResourceType> collegeList = this.getAllOrgList();
|
|
|
+ List<TreeNode<String>> treeNodeList = collegeList.stream().map(college ->
|
|
|
+ new TreeNode<>(college.getId(), college.getParentId(), college.getName(), college.getSortCode()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return TreeUtil.build(treeNodeList, "0");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|