package com.xinelu.familydoctor.service.impl;

import com.xinelu.familydoctor.entity.*;
import com.xinelu.familydoctor.mapper.*;
import com.xinelu.familydoctor.service.PhysicalSignService;
import com.xinelu.familydoctor.vo.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author gaoyu
 * @description 体征检测业务实现类
 * @date 2023-10-8 15:59
 */
@Service
public class PhysicalSignServiceImpl implements PhysicalSignService {
    @Resource
    private DeviceBfRecordMapper deviceBfRecordMapper;
    @Resource
    private DeviceBgRecordMapper deviceBgRecordMapper;
    @Resource
    private DeviceBmiRecordMapper deviceBmiRecordMapper;
    @Resource
    private DeviceBoRecordMapper deviceBoRecordMapper;
    @Resource
    private DeviceBpRecordMapper deviceBpRecordMapper;
    @Resource
    private DeviceHrRecordMapper deviceHrRecordMapper;
    @Resource
    private DeviceTempRecordMapper deviceTempRecordMapper;

    @Override
    public void saveBg(DeviceBgRecord record) {
        deviceBgRecordMapper.insert(record);
    }

    @Override
    public void saveBp(DeviceBpRecord record) {
        deviceBpRecordMapper.insert(record);
    }

    @Override
    public void saveBf(DeviceBfRecord record) {
        deviceBfRecordMapper.insert(record);
    }

    @Override
    public void saveBmi(DeviceBmiRecord record) {
        deviceBmiRecordMapper.insert(record);
    }

    @Override
    public void saveBo(DeviceBoRecord record) {
        deviceBoRecordMapper.insert(record);
    }

    @Override
    public void saveHr(DeviceHrRecord record) {
        deviceHrRecordMapper.insert(record);
    }

    @Override
    public void saveTemp(DeviceTempRecord record) {
        deviceTempRecordMapper.insert(record);
    }

    @Override
    public Map<String, Object> record(String identity, String type, String label) {
        Map<String, Object> map = new HashMap<>();
        switch (label) {
            case "1":
                map = bgRecord(identity, type);
                break;
            case "2":
                map = bpRecord(identity, type);
                break;
            case "3":
                map = bfRecord(identity, type);
                break;
            case "4":
                map = bmiRecord(identity, type);
                break;
            case "5":
                map = boRecord(identity, type);
                break;
            case "6":
                map = hrRecord(identity, type);
                break;
            case "7":
                map = tempRecord(identity, type);
                break;
            default:
                break;
        }
        return map;
    }

    @Override
    public List<PhysicalLastRecordVO> getLastRecord(String identity) {
        return deviceBgRecordMapper.getLastRecord(identity);
    }

    private Map<String, Object> bgRecord(String identity, String type) {
        Map<String, Object> map = new HashMap<>();
        List<DeviceBgRecord> list = deviceBgRecordMapper.getBgRecord(identity, type);
        BgCalcVO calc = deviceBgRecordMapper.getBgCalc(identity, type);
        map.put("list", list);
        map.put("calc", calc);
        return map;
    }

    private Map<String, Object> bpRecord(String identity, String type) {
        Map<String, Object> map = new HashMap<>();
        List<DeviceBpRecord> list = deviceBpRecordMapper.getBpRecord(identity, type);
        BpCalcVO calc = deviceBpRecordMapper.getBpCalc(identity, type);
        map.put("list", list);
        map.put("calc", calc);
        return map;
    }

    private Map<String, Object> bfRecord(String identity, String type) {
        Map<String, Object> map = new HashMap<>();
        List<DeviceBfRecord> list = deviceBfRecordMapper.getBfRecord(identity, type);
//        BfCalcVO calc = deviceBfRecordMapper.getBfCalc(identity, type);
        map.put("list", list);
//        map.put("calc", calc);
        return map;
    }

    private Map<String, Object> bmiRecord(String identity, String type) {
        Map<String, Object> map = new HashMap<>();
        List<DeviceBmiRecord> list = deviceBmiRecordMapper.getBmiRecord(identity, type);
        BmiCalcVO calc = deviceBmiRecordMapper.getBmiCalc(identity, type);
        map.put("list", list);
        map.put("calc", calc);
        return map;
    }

    private Map<String, Object> boRecord(String identity, String type) {
        Map<String, Object> map = new HashMap<>();
        List<DeviceBoRecord> list = deviceBoRecordMapper.getBoRecord(identity, type);
        BoCalcVO calc = deviceBoRecordMapper.getBoCalc(identity, type);
        map.put("list", list);
        map.put("calc", calc);
        return map;
    }

    private Map<String, Object> hrRecord(String identity, String type) {
        Map<String, Object> map = new HashMap<>();
        List<DeviceHrRecord> list = deviceHrRecordMapper.getHrRecord(identity, type);
        HrCalcVO calc = deviceHrRecordMapper.getHrCalc(identity, type);
        map.put("list", list);
        map.put("calc", calc);
        return map;
    }

    private Map<String, Object> tempRecord(String identity, String type) {
        Map<String, Object> map = new HashMap<>();
        List<DeviceTempRecord> list = deviceTempRecordMapper.getTempRecord(identity, type);
        TempCalcVO calc = deviceTempRecordMapper.getTempCalc(identity, type);
        map.put("list", list);
        map.put("calc", calc);
        return map;
    }
}
