package com.lightinit.hsdatashow.impl.admin;

import com.lightinit.hsdatashow.dictionary.DicSpreadType;
import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.mapper.ComprehensiveMapper;
import com.lightinit.hsdatashow.mapper.PublicSentimentMapper;
import com.lightinit.hsdatashow.model.admin.CulturalFalitiesListModel;
import com.lightinit.hsdatashow.model.admin.EducationalPortraitListModel;
import com.lightinit.hsdatashow.model.admin.EducationalPortraitNameModel;
import com.lightinit.hsdatashow.model.admin.SpreadListModel;
import com.lightinit.hsdatashow.service.admin.IPublicService;
import com.lightinit.hsdatashow.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service
public class PublicSerciveImpl implements IPublicService {
    @Autowired
    private ComprehensiveMapper comprehensiveMapper;
    @Autowired
    private PublicSentimentMapper publicSentimentMapper;
    @Override
    public SpreadListModel getComprehensive() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        SpreadListModel<BigDecimal> model = new SpreadListModel<>();
        ComprehensiveExample example = new ComprehensiveExample();
        List<Comprehensive> list = comprehensiveMapper.selectByExample(example);
        List<String> name = new ArrayList<>();
        List<String> name1 = new ArrayList<>();
        List<BigDecimal> siG = new ArrayList<>();
        List<BigDecimal> television = new ArrayList<>();
        List<BigDecimal> wifi = new ArrayList<>();
        List<BigDecimal> reads = new ArrayList<>();
        List<BigDecimal> value = new ArrayList<>();
        List<BigDecimal> value1 = new ArrayList<>();
        List<BigDecimal> value2 = new ArrayList<>();
        List<BigDecimal> value3= new ArrayList<>();
        for (Comprehensive comprehensive : list) {
            if(comprehensive.getNameType().equals("执政能力")){

                name1.add(comprehensive.getName());
                value.add(comprehensive.getCommonly());
                value1.add(comprehensive.getDissatisfied());
                value2.add(comprehensive.getSatisfied());
                value3.add(comprehensive.getVerySatisfied());
            }else if(comprehensive.getNameType().equals("生活条件")){
                name.add(comprehensive.getName());
                wifi.add(comprehensive.getCommonly());
                siG.add(comprehensive.getDissatisfied());
                television.add(comprehensive.getSatisfied());
                reads.add(comprehensive.getVerySatisfied());
            }
        }

        model.setName(name);
        model.setReads(reads);
        model.setSiG(siG);
        model.setWifi(wifi);
        model.setTelevision(television);
        model.setName1(name1);
        model.setValue(value);
        model.setValue1(value1);
        model.setValue2(value2);
        model.setValue3(value3);
        return model;
    }

    @Override
    public CulturalFalitiesListModel getPublicSentiment() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        CulturalFalitiesListModel model = new CulturalFalitiesListModel();
        PublicSentimentExample example = new PublicSentimentExample();
       List<PublicSentiment> list = publicSentimentMapper.selectByExample(example);
        List<EducationalPortraitNameModel> ListNmae = new ArrayList<>();
        List<EducationalPortraitNameModel> ListNmae1 = new ArrayList<>();
        for (PublicSentiment publicSentiment:list
             ) {
            EducationalPortraitNameModel name= new EducationalPortraitNameModel();
            EducationalPortraitNameModel name1= new EducationalPortraitNameModel();
            if(publicSentiment.getPublicOpinionType().equals("积极舆情")){

                name.setName(publicSentiment.getName());
                name.setValue(publicSentiment.getValue());
                ListNmae.add(name);
            }
        }
        model.setValue(ListNmae);
        model.setValue1(ListNmae1);
        return model;
    }
    @Override
    public CulturalFalitiesListModel getPublicSentiment1() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        CulturalFalitiesListModel model = new CulturalFalitiesListModel();
        PublicSentimentExample example = new PublicSentimentExample();
        List<PublicSentiment> list = publicSentimentMapper.selectByExample(example);
        List<EducationalPortraitNameModel> ListNmae = new ArrayList<>();
        List<EducationalPortraitNameModel> ListNmae1 = new ArrayList<>();
        for (PublicSentiment publicSentiment:list
                ) {
            EducationalPortraitNameModel name= new EducationalPortraitNameModel();
            EducationalPortraitNameModel name1= new EducationalPortraitNameModel();
            if(publicSentiment.getPublicOpinionType().equals("消极舆情")){

                name.setName(publicSentiment.getName());
                name.setValue(publicSentiment.getValue());
                ListNmae.add(name);
            }
        }
        model.setValue(ListNmae);
        model.setValue1(ListNmae1);
        return model;
    }
}
