package io.renren.modules.dataSet.service.impl;

import com.alibaba.fastjson.JSON;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.datasource.annotation.DataSource;
import io.renren.modules.dataSet.DataSetUtils.ToEnglish;
import io.renren.modules.dataSet.entity.Subsystem;
import io.renren.modules.dataSet.mapper.SubsystemMapper;
import io.renren.modules.dataSet.service.SubsystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author allen
 * @since 2021-06-15
 */

@DataSource("bigData")
@Service
public class SubsystemServiceImpl extends ServiceImpl<SubsystemMapper, Subsystem> implements SubsystemService {

    @Autowired
    private  SubsystemMapper subsystemMapper;

    public  String demo(){
        List<Subsystem> demo = subsystemMapper.subsystem();
        String s = JSON.toJSONString(demo);
        return s;
    }

    public String getEquipment(Integer id){
        List<Subsystem> equipment = subsystemMapper.getEquipment(id);
        String s = JSON.toJSONString(equipment);
        return s;
    }

    public String getSubequipment(Integer id){
        List<Subsystem> subequiment = subsystemMapper.getSubequipment(id);
        String s = JSON.toJSONString(subequiment);
        return s;
    }
    public List getcolumns(Integer equpmentId){
        System.out.println("getcolumns");
        List<Map<String,String>> equpmengColumnList = new ArrayList<>();

        List<Subsystem> getEqupmengColumns = subsystemMapper.getcolumns(equpmentId);
        System.out.println(getEqupmengColumns.size());
        for (Subsystem equpmengColumn : getEqupmengColumns) {
            System.out.println(equpmengColumn);
            HashMap<String, String> equpmentMap = new HashMap<>();
            equpmentMap.put("measurepointId",equpmengColumn.getId().toString());
            final String name = equpmengColumn.getName().substring(4);
            equpmentMap.put("name_zh",name);
            final String name_en = ToEnglish.getPinYin(name);
            equpmentMap.put("name_en",name_en+"_after");
            equpmengColumnList.add(equpmentMap);
        }
        return equpmengColumnList;
    }

}
