package com.lantone.qc.dbanaly.lt.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lantone.qc.dbanaly.lt.entity.ModelHospital;
import com.lantone.qc.dbanaly.lt.service.impl.ModelHospitalServiceImpl;
import com.lantone.qc.dbanaly.util.SpecialStorageUtil;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * @Description:
 * @author: rengb
 * @time: 2020/6/4 17:13
 */
@Component
public class ModelHospitalFacade extends ModelHospitalServiceImpl {

    @Autowired
    private SpecialStorageUtil specialStorageUtil;

    public List<String> getRecTitles(long hospitalId, long modelId) {
        List<String> recTitles = specialStorageUtil.getJsonStringValue("recTitles");
        if (ListUtil.isEmpty(recTitles)) {
            QueryWrapper<ModelHospital> qcModelHospitalQe = new QueryWrapper<>();
            qcModelHospitalQe.eq("hospital_id", hospitalId);
            qcModelHospitalQe.eq("stand_model_id", modelId);
            qcModelHospitalQe.select("hospital_model_name");
            recTitles = list(qcModelHospitalQe)
                    .stream()
                    .map(i -> i.getHospitalModelName())
                    .filter(i -> StringUtil.isNotBlank(i))
                    .distinct()
                    .collect(Collectors.toList());
            specialStorageUtil.setJsonStringValue("recTitles", recTitles);
        }
        return recTitles;
    }

}