package com.bootdo.data.service.impl;

import com.bootdo.common.service.DictService;
import com.bootdo.common.utils.StringUtils;
import com.bootdo.data.domain.DataPartDO;
import com.bootdo.data.service.DataPartService;
import com.bootdo.oa.domain.NotifyDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.bootdo.data.dao.DataInfoDao;
import com.bootdo.data.domain.DataInfoDO;
import com.bootdo.data.service.DataInfoService;

@Service
public class DataInfoServiceImpl implements DataInfoService {
    @Autowired
    private DataInfoDao dataInfoDao;

    @Autowired
    private DictService dictService;

    @Autowired
    private DataPartService dataPartService;

    @Override
    public DataInfoDO get(Long id) {
        DataInfoDO dataInfoDO = dataInfoDao.get(id);
        //dataInfoDO.setDataType(dictService.getName("data_type", dataInfoDO.getDataType()));
        return dataInfoDO;
    }

    @Override
    public List<DataInfoDO> list(Map<String, Object> map) {
        List<DataInfoDO> lsit = dataInfoDao.list(map);
        // 遍历词典
        for (DataInfoDO dataInfoDO : lsit) {
            //数据类型
            if(StringUtils.isNotBlank(dataInfoDO.getDataType()) && !dataInfoDO.getDataType().equals("other")){
                DataPartDO dataPartDO = dataPartService.get(Long.valueOf(dataInfoDO.getDataType()));
                dataInfoDO.setDataType(dataPartDO.getPartName());
            }else{
                dataInfoDO.setDataType("其它");
            }
            //数据类型子类
            if(StringUtils.isNotBlank(dataInfoDO.getDataSub())){
                DataPartDO dataPartDOs = dataPartService.get(Long.valueOf(dataInfoDO.getDataSub()));
                dataInfoDO.setDataSub(dataPartDOs.getPartName());
            }else{
                dataInfoDO.setDataSub("");
            }

        }
        return lsit;
    }

    @Override
    public int count(Map<String, Object> map) {
        return dataInfoDao.count(map);
    }

    @Override
    public int save(DataInfoDO dataInfo) {
        return dataInfoDao.save(dataInfo);
    }

    @Override
    public int update(DataInfoDO dataInfo) {
        return dataInfoDao.update(dataInfo);
    }

    @Override
    public int remove(Long id) {
        return dataInfoDao.remove(id);
    }

    @Override
    public int batchRemove(Long[] ids) {
        return dataInfoDao.batchRemove(ids);
    }

    /**
     * @Description:重要数据和核心数据目录备案清单 初始化
     * @Author: wangp
     * @Date: 2022/3/1 19:05
     * @param params
     * @Return: List<DataInfoDO>
     */
    @Override
    public List<DataInfoDO> querylistInfo(Map<String, Object> params) {
        return dataInfoDao.querylistInfo(params);
    }

}
