package com.org.web.data.service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.org.web.data.domain.DataStatistics;
import com.org.web.data.domain.DataStatisticsItem;
import com.org.web.data.mapper.DataMapper;
import com.org.web.person.domain.BcPersonSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Service
@Slf4j
public class DataService extends ServiceImpl<DataMapper, BcPersonSupport> {

    /**
     * 列表
     */
    public DataStatistics queryDataStatistics() {

        List<DataStatisticsItem> sexList = baseMapper.listSex();
        List<DataStatisticsItem> ageList = baseMapper.listAgeCount();
        List<DataStatisticsItem> nursingLevelList = baseMapper.listNursingLevel();
        List<DataStatisticsItem> ifHelpPoorList = baseMapper.listIfHelpPoor();

        int ljrzCount = baseMapper.getLjrzCount();
        int jnrzCount = baseMapper.getJnrzCount();
        int byxzCount = baseMapper.getByxzCount();
        int mqzyCount = baseMapper.getMqzyCount();
        int wcjyCount = baseMapper.getWcjyCount();
        int jnjyCount = baseMapper.getJnjyCount();

        BigDecimal jzgyl = baseMapper.getJzgyl();
        BigDecimal fsgyl = baseMapper.getFsgyl();

        List<DataStatisticsItem> villageRankList = baseMapper.listVillageRank();

        // 修改value总数->剩余数
        List<DataStatisticsItem> roomCountList = baseMapper.listRoomCount();

        // 供养床位
        DataStatisticsItem gycw = new DataStatisticsItem();
        if (roomCountList != null && !roomCountList.isEmpty()) {
            gycw.setName("供养床位");
            gycw.setId(1);
            gycw.setValue(roomCountList.get(0).getValue()); // 床位总数
        }

        for (DataStatisticsItem item : roomCountList) {
            item.setValue(item.getValue() - item.getValue2());
        }

        List<DataStatisticsItem> roomTypeList = baseMapper.listRoomType();

        List<DataStatisticsItem> villageCountList = baseMapper.listVillageCount();

        DataStatistics dataStatistics = new DataStatistics();
        dataStatistics.setSexList(sexList);
        dataStatistics.setAgeList(ageList);
        dataStatistics.setNursingLevelList(nursingLevelList);
        dataStatistics.setIfHelpPoorList(ifHelpPoorList);

        dataStatistics.setVillageRankList(villageRankList);
        dataStatistics.setLjrzCount(ljrzCount);
        dataStatistics.setJnrzCount(jnrzCount);
        dataStatistics.setByxzCount(byxzCount);
        dataStatistics.setMqzyCount(mqzyCount);
        dataStatistics.setWcjyCount(wcjyCount);
        dataStatistics.setJnjyCount(jnjyCount);
        dataStatistics.setJzgyRate(jzgyl);
        dataStatistics.setFsgyRate(fsgyl);


        dataStatistics.setRoomCountList(roomCountList);

        roomTypeList.add(gycw);
        dataStatistics.setRoomTypeList(roomTypeList);

        dataStatistics.setVillageCountList(villageCountList);

        return dataStatistics;
    }

}
