ServiceCompanyFilesServiceImpl.java 2.41 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.dto.company.CompanyFilesDTO;
import com.subsidy.mapper.ServiceFileTreeMapper;
import com.subsidy.model.ServiceCompanyFilesDO;
import com.subsidy.mapper.ServiceCompanyFilesMapper;
import com.subsidy.model.ServiceFileTreeDO;
import com.subsidy.service.ServiceCompanyFilesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 协议管理材料表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2024-01-11
 */
@Service
public class ServiceCompanyFilesServiceImpl extends ServiceImpl<ServiceCompanyFilesMapper, ServiceCompanyFilesDO> implements ServiceCompanyFilesService {

    @Autowired
    private ServiceFileTreeMapper serviceFileTreeMapper;

    public IPage<ServiceCompanyFilesDO> companyFiles(CompanyFilesDTO companyFilesDTO) {
        Page pager = new Page(companyFilesDTO.getPageNum(), companyFilesDTO.getPageSize());

        List<Long> treeIds = new ArrayList<>();
        treeIds.add(companyFilesDTO.getTreeId());

        ServiceFileTreeDO serviceFileTreeDO = serviceFileTreeMapper.selectById(companyFilesDTO.getTreeId());

        if (null == serviceFileTreeDO.getParentId()){
            //找出二级节点
            List<ServiceFileTreeDO> serviceFileTreeDOS = serviceFileTreeMapper.selectList(new QueryWrapper<ServiceFileTreeDO>()
            .lambda()
            .eq(ServiceFileTreeDO::getParentId,serviceFileTreeDO.getId()));
            for (ServiceFileTreeDO serviceFileTreeDO1 : serviceFileTreeDOS){
                treeIds.add(serviceFileTreeDO1.getId());
            }
        }
        return this.baseMapper.companyFiles(pager,treeIds, companyFilesDTO.getFileName());
    }

    public String deleteFile(ServiceCompanyFilesDO serviceCompanyFilesDO) {
        this.baseMapper.deleteById(serviceCompanyFilesDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

    public String uploadFile(ServiceCompanyFilesDO serviceCompanyFilesDO) {
        this.baseMapper.insert(serviceCompanyFilesDO);
        return ConstantUtils.ADD_SUCCESS;
    }

}