package cn.com.ctop.crawler.modules.music.service.impl;

import cn.com.ctop.crawler.modules.music.entity.DictMusicType;
import cn.com.ctop.crawler.modules.music.mapper.DictMusicTypeMapper;
import cn.com.ctop.crawler.modules.music.service.IDictMusicTypeService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 抖音音乐类型
 * @author jeecg-boot
 * @date   2020-10-28
 * @version V1.0
 */
@Service
public class DictMusicTypeServiceImpl extends ServiceImpl<DictMusicTypeMapper, DictMusicType> implements IDictMusicTypeService {
    @Autowired
    private DictMusicTypeMapper musicTypeMapper;
    @Override
    public JSONObject listAll() {
        JSONObject data = new JSONObject();
        List<DictMusicType> musicTypeList = musicTypeMapper.getAllExtTypeZh();
        if(null!=musicTypeList&&!musicTypeList.isEmpty()){
            List<DictMusicType> setList = new ArrayList<>();
            for (DictMusicType type:musicTypeList) {
                List<DictMusicType>children = musicTypeMapper.getAllExtInfoByExtTypeZh(type.getExtTypeZh());
                type.setDetail(children);
                setList.add(type);
            }
            data.put("data",setList);
        }
        return data;
    }
}
