package com.bofeng.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.bofeng.dao.QzTaskDao;
import com.bofeng.dao.RbMapper;
import com.bofeng.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Service
public class RbService {

    @Autowired
    private RbMapper rbMapper;

    public List<sysUptownUnit> selectAll (Long userId) {
        List<sysUptownUnit> sysUptownUnits = rbMapper.selectDY(userId);
        return sysUptownUnits;
    }

    public List<SysUptownHouse> selectXq (Long str) {
//        userId = 1224706869998772226L;
//        List<SysUptownHouse> sysUptownHouses = rbMapper.selectList(new EntityWrapper<SysUptownHouse>().eq("ridgepole",ridgepole).eq("unit",unit));
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String dateStr = simpleDateFormat.format(date);
        List<SysUptownHouse> sysUptownHousesss = rbMapper.selectMp(str,dateStr);
        return sysUptownHousesss;
    }

    public List<MsSuspected> selectYcXq (Long houseId) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String dateStr = simpleDateFormat.format(date);
        List<MsSuspected> sysUptownHouses = rbMapper.selectYcXq(houseId,dateStr);
        if(sysUptownHouses.size() !=0){
            for (int i = 0; i < sysUptownHouses.size(); i++) {

                Integer cough = sysUptownHouses.get(i).getCough();
                if(cough != null && cough == 0){
                    sysUptownHouses.get(i).setChestStr("无咳嗽");
                }else if(cough != null && cough ==1){
                    sysUptownHouses.get(i).setChestStr("偶尔短暂咳嗽");
                }else if(cough != null && cough ==2){
                    sysUptownHouses.get(i).setChestStr("频繁咳嗽轻重");
                }else if(cough != null && cough ==3){
                    sysUptownHouses.get(i).setChestStr("频繁咳嗽重度");
                }
                Integer muscle = sysUptownHouses.get(i).getMuscle();
                if(muscle != null && muscle==0){
                    sysUptownHouses.get(i).setMuscleStr("无肌肉酸痛");
                }else if(muscle != null && muscle ==1){
                    sysUptownHouses.get(i).setMuscleStr("肌肉酸痛加重");
                }else if(muscle != null && muscle ==2){
                    sysUptownHouses.get(i).setMuscleStr("肌肉酸痛好转");
                }else if(muscle != null && muscle ==3){
                    sysUptownHouses.get(i).setMuscleStr("肌肉酸痛无变化");
                }
                Integer dyspnea = sysUptownHouses.get(i).getDyspnea();
                if(dyspnea != null && dyspnea ==0){
                    sysUptownHouses.get(i).setDyspneaStr("无呼吸困难");
                }else if(dyspnea != null && dyspnea ==1){
                    sysUptownHouses.get(i).setDyspneaStr("呼吸困难加重");
                }else if(dyspnea != null && dyspnea ==2){
                    sysUptownHouses.get(i).setDyspneaStr("呼吸困难好转");
                }else if(dyspnea != null && dyspnea ==3){
                    sysUptownHouses.get(i).setDyspneaStr("呼吸困难无变化");
                }else if(dyspnea != null && dyspnea ==4){
                    sysUptownHouses.get(i).setDyspneaStr("呼吸困难严重");
                }
                Integer chest = sysUptownHouses.get(i).getChest();
                if(chest !=null && chest ==0){
                    sysUptownHouses.get(i).setChestStr("无胸闷");
                }else if(chest !=null && chest ==1){
                    sysUptownHouses.get(i).setChestStr("端坐呼吸");
                }else if(chest !=null && chest ==2){
                    sysUptownHouses.get(i).setChestStr("活动无");
                }else if(chest !=null && chest ==3){
                    sysUptownHouses.get(i).setChestStr("无变化");
                }
                Integer fatigue = sysUptownHouses.get(i).getFatigue();
                if(fatigue !=null && fatigue == 0){
                    sysUptownHouses.get(i).setFatigueStr("无乏力");
                }else if(fatigue !=null && fatigue == 1){
                    sysUptownHouses.get(i).setFatigueStr("乏力加重");
                }else if(fatigue !=null && fatigue == 2){
                    sysUptownHouses.get(i).setFatigueStr("乏力好转");
                }else if(fatigue !=null && fatigue == 3){
                    sysUptownHouses.get(i).setFatigueStr("乏力无变化");
                }
                Integer diarrhea = sysUptownHouses.get(i).getDiarrhea();
                if(diarrhea !=null && diarrhea == 0){
                    sysUptownHouses.get(i).setDiarrheaStr("无腹泻");
                }else if(diarrhea !=null && diarrhea == 1){
                    sysUptownHouses.get(i).setDiarrheaStr("有腹泻");
                }
                sysUptownHouses.get(i).setZhengzhuang(sysUptownHouses.get(i).getChestStr()+","+sysUptownHouses.get(i).getMuscleStr()+","+sysUptownHouses.get(i).getDyspneaStr()
                        +","+sysUptownHouses.get(i).getChestStr()+","+sysUptownHouses.get(i).getFatigueStr()+","+sysUptownHouses.get(i).getDiarrheaStr());
            }
        }

        return sysUptownHouses;
    }
}
