package com.yihu.figure.service;

import com.yihu.figure.dao.SuggestDao;
import com.yihu.figure.dao.patient.portrait.UserPortraitDao;
import com.yihu.figure.model.patient.portrait.UserPortrait;
import com.yihu.figure.model.suggest.Suggest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chenweida on 2017/3/7.
 */
@Service
public class SuggestService {

    @Autowired
    private UserPortraitDao userPortraitDao;
    @Autowired
    private SuggestDao suggesdao;

    public Map<String, List<Suggest>> getPatientSuggest(String patientCode) {
        //得到用户标签
        List<UserPortrait> userPortraits = userPortraitDao.findByPatientCode(patientCode);
        //根据用户的标签得到建议
        Map<String, List<Suggest>> map = new HashMap<>();
        userPortraits.stream().forEach(u -> {
            List<Suggest> ss = suggesdao.findByKeyword("%" + u.getValue() + "%");
            ss.stream().forEach(s -> {
                if (map.containsKey(s.getTypeName())) {
                    map.get(s.getTypeName()).add(s);
                } else {
                    List<Suggest> suggests = new ArrayList<Suggest>();
                    suggests.add(s);
                    map.put(s.getTypeName(), suggests);
                }
            });
        });
        return map;
    }
}
