package org.example.service;

import org.example.entity.HospitalOverview;
import org.example.mapper.HospitalOverviewMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HospitalOverviewService {
    
    @Autowired
    private HospitalOverviewMapper hospitalOverviewMapper;
    
    /**
     * 获取医院概况信息
     * @return 医院概况对象
     */
    public HospitalOverview getHospitalOverview() {
        return hospitalOverviewMapper.getHospitalOverview();
    }
    
    /**
     * 保存医院概况信息
     * @param hospitalOverview 医院概况对象
     * @return 是否保存成功
     */
    public boolean saveHospitalOverview(HospitalOverview hospitalOverview) {
        try {
            // 先尝试获取现有记录
            HospitalOverview existing = hospitalOverviewMapper.getHospitalOverview();
            
            int result;
            if (existing != null) {
                // 如果存在记录，则更新
                hospitalOverview.setId(existing.getId());
                result = hospitalOverviewMapper.updateHospitalOverview(hospitalOverview);
            } else {
                // 如果不存在记录，则插入新记录
                result = hospitalOverviewMapper.insertHospitalOverview(hospitalOverview);
            }
            
            return result > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}