Blame view

ServiceFileTreeServiceImpl.java 4.95 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.exception.HttpException;
import com.subsidy.model.ServiceFileTreeDO;
import com.subsidy.mapper.ServiceFileTreeMapper;
import com.subsidy.service.ServiceFileTreeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.tree.TreesVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 文件目录树 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2024-04-08
 */
@Service
public class ServiceFileTreeServiceImpl extends ServiceImpl<ServiceFileTreeMapper, ServiceFileTreeDO> implements ServiceFileTreeService {


    public List<TreesVO> trees(ServiceFileTreeDO serviceFileTreeDO) {

        List<TreesVO> result = new ArrayList<>();

        List<ServiceFileTreeDO> serviceFileTreeDOS = this.baseMapper.selectList(new QueryWrapper<ServiceFileTreeDO>()
                .lambda()
                .eq(ServiceFileTreeDO::getCompanyId, serviceFileTreeDO.getCompanyId())
                .eq(ServiceFileTreeDO::getServiceId, serviceFileTreeDO.getServiceId())
                .isNull(ServiceFileTreeDO::getParentId));

        for (ServiceFileTreeDO sftd : serviceFileTreeDOS) {
            TreesVO treesVO = new TreesVO();
            treesVO.setId(sftd.getId());
            treesVO.setTreeName(sftd.getTreeName());
            List<ServiceFileTreeDO> serviceFileTreeDOList = this.baseMapper.selectList(new QueryWrapper<ServiceFileTreeDO>()
                    .lambda()
                    .eq(ServiceFileTreeDO::getParentId, sftd.getId()));

            List<TreesVO> resultTmp = new ArrayList<>();
            for (ServiceFileTreeDO sftd2 : serviceFileTreeDOList) {
                TreesVO treesVO1 = new TreesVO();
                treesVO1.setId(sftd2.getId());
                treesVO1.setTreeName(sftd2.getTreeName());
                treesVO1.setParentId(sftd.getId());
                resultTmp.add(treesVO1);
            }
            treesVO.setTreesVOS(resultTmp);
            result.add(treesVO);
        }
        return result;
    }

    public String addTree(ServiceFileTreeDO serviceFileTreeDO) {

        //查看当前节点下有没有重名的
        int count = this.baseMapper.selectCount(new QueryWrapper<ServiceFileTreeDO>()
                .lambda()
                .eq(ServiceFileTreeDO::getCompanyId, serviceFileTreeDO.getCompanyId())
                .eq(ServiceFileTreeDO::getParentId, serviceFileTreeDO.getParentId())
                .eq(ServiceFileTreeDO::getTreeName, serviceFileTreeDO.getTreeName())
                .eq(ServiceFileTreeDO::getServiceId, serviceFileTreeDO.getServiceId()));

        if (count > 0) {
            throw new HttpException(40001);
        }

        this.baseMapper.insert(serviceFileTreeDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    public String updateTree(ServiceFileTreeDO serviceFileTreeDO) {

        ServiceFileTreeDO serviceFileTreeDO1 = this.baseMapper.selectById(serviceFileTreeDO.getId());
        //查看当前节点下有没有重名的
        int count = this.baseMapper.selectCount(new QueryWrapper<ServiceFileTreeDO>()
                .lambda()
                .eq(ServiceFileTreeDO::getCompanyId, serviceFileTreeDO1.getCompanyId())
                .eq(ServiceFileTreeDO::getParentId, serviceFileTreeDO1.getParentId())
                .eq(ServiceFileTreeDO::getTreeName, serviceFileTreeDO.getTreeName())
                .eq(ServiceFileTreeDO::getServiceId, serviceFileTreeDO1.getServiceId())
                .ne(ServiceFileTreeDO::getId, serviceFileTreeDO.getId()));

        if (count > 0) {
            throw new HttpException(40001);
        }

        this.baseMapper.updateById(serviceFileTreeDO);
        return ConstantUtils.SUCCESS_UPDATE;
    }

    public String deleteTree(ServiceFileTreeDO serviceFileTreeDO) {

        ServiceFileTreeDO serviceFileTreeDO1 = this.baseMapper.selectById(serviceFileTreeDO.getId());
        this.baseMapper.deleteById(serviceFileTreeDO.getId());

        List<Long> deleteIds = new ArrayList<>();
        deleteIds.add(serviceFileTreeDO.getId());

        //如果是一级目录的话,要删除对应的二级目录
        if (null == serviceFileTreeDO1.getParentId()) {

            //找出二级节点
            List<ServiceFileTreeDO> serviceFileTreeDOS = this.baseMapper.selectList(new QueryWrapper<ServiceFileTreeDO>()
                    .lambda()
                    .eq(ServiceFileTreeDO::getParentId, serviceFileTreeDO.getId()));
            for (ServiceFileTreeDO sftd : serviceFileTreeDOS) {
                deleteIds.add(sftd.getId());
            }

            // 删除该目录下及子目录下的文件
            this.baseMapper.delete(new QueryWrapper<ServiceFileTreeDO>()
                    .lambda()
                    .in(ServiceFileTreeDO::getId, deleteIds));
        }
        return ConstantUtils.DELETE_SUCCESS;
    }


}