package com.ruoyi.tc.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.tc.entity.*;
import com.ruoyi.tc.entity.request.Acomma;
import com.ruoyi.tc.entity.request.AssetCurrentPageRequest;
import com.ruoyi.tc.mapper.AssetCurrentMapper;
import com.ruoyi.tc.service.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 现有资产表(AssetCurrent)表服务实现类
 *
 * @author makejava
 * @since 2024-11-15 10:04:03
 */
@Service("assetCurrentService")
public class AssetCurrentServiceImpl extends ServiceImpl<AssetCurrentMapper, AssetCurrent> implements AssetCurrentService {

    @Resource
    private AssetSupplyChainService assetSupplyChainService;

    @Resource
    private AssetBasicNetworkService assetBasicNetworkService;

    @Resource
    private AssetBusinessFormService assetBusinessFormService;

    @Resource
    private UnitOtherConcatService unitOtherConcatService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param as   查询实体
     * @return 所有数据
     */
    @Override
    public Page<AssetCurrent> page(Page<AssetCurrent> page, AssetCurrentPageRequest as) {
        return baseMapper.page(page, as);
    }

    /**
     * 导出查询所有数据
     *
     * @param as 查询实体
     * @return 所有数据
     */
    @Override
    public List<AssetExport> page1(AssetCurrentPageRequest as) {
        return baseMapper.page1(as);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Override
    public AssetCurrent selectOne(Serializable id) {
        AssetCurrent byId = getById(id);
        byId.setGylxxList(assetSupplyChainService.lambdaQuery().eq(AssetSupplyChain::getAssetId, id).eq(AssetSupplyChain::getDelFlag, "0").list());
        byId.setJcwlList(assetBasicNetworkService.lambdaQuery().eq(AssetBasicNetwork::getAssetId, id).eq(AssetBasicNetwork::getDelFlag, "0").list());
        byId.setXjgywxt(assetBusinessFormService.lambdaQuery().eq(AssetBusinessForm::getAssetId, id).eq(AssetBusinessForm::getDelFlag, "0").one());
        byId.setOtherConcat(unitOtherConcatService.lambdaQuery().eq(UnitOtherConcat::getAssetId, id).eq(UnitOtherConcat::getDelFlag, "0").list());
        List<Acomma> a1 = new ArrayList<>();
        if(byId.getGlym()!=null){
            Arrays.asList(byId.getGlym().split(",")).forEach(x -> {
                Acomma acomma = new Acomma();
                acomma.setKey(x);
                a1.add(acomma);
            });
            byId.setGlymList(a1);
        }
        List<Acomma> a2 = new ArrayList<>();
        if(byId.getGlIp()!=null){
            Arrays.asList(byId.getGlIp().split(",")).forEach(x -> {
                Acomma acomma = new Acomma();
                acomma.setKey(x);
                a2.add(acomma);
            });
            byId.setGlIpList(a2);
        }
        return byId;
    }

    /**
     * 逻辑删除
     */
    @Override
    public void deleteByUnitIds(Long id) {
        baseMapper.deleteByUnitIds(id);
    }

    @Override
    public void deleteIdList(List<Long> idList) {
        baseMapper.deleteIdList(idList);
    }

    /**
     * 查询所有数据(带子表)
     */
    @Override
    public List<AssetExport> selectAllAsset(AssetCurrentPageRequest as) {
        return baseMapper.selectAllAsset(as);
    }

    @Override
    public Integer findBydwmc(String part) {
        return baseMapper.findBydwmc(part);
    }
}

