package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.entity.BasHospitalInfo;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.impl.BasHospitalInfoServiceImpl;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description:
 * @author: gaodm
 * @time: 2024/4/12 11:39
 */
@Component
public class BasHospitalInfoFacade  extends BasHospitalInfoServiceImpl {

    private static Map<Long, String> hospitalMap = null;

    /**
     * 初始化医院信息
     */
    public void init() {
        if (hospitalMap == null) {
            List<BasHospitalInfo> basHospitalInfoList = this.list(new QueryWrapper<BasHospitalInfo>()
                    .eq("is_deleted", IsDeleteEnum.N.getKey())
            );
            hospitalMap = basHospitalInfoList.stream().collect(Collectors.toMap(r -> r.getId(), r -> r.getCode()));
        }
    }


    /**
     * 获取医院编码
     *
     * @param hospitalId
     * @return
     */
    public String getHosCode(Long hospitalId) {
        init();
        return hospitalMap.get(hospitalId);
    }

}
