package com.lantone.facade.cdss;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.util.BeanUtil;
import com.diagbot.util.EntityUtil;
import com.diagbot.util.ListUtil;
import com.lantone.dto.cdss.DictionaryInfoDTO;
import com.lantone.entity.cdss.DictionaryInfo;
import com.lantone.service.cdss.impl.DictionaryInfoServiceImpl;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author:zhoutg
 * @time: 2018/11/23 11:37
 */
@Component
public class DictionaryFacade extends DictionaryInfoServiceImpl {

    /**
     * 返回字典信息
     *
     * @return
     */
    public Map<Long, List<DictionaryInfoDTO>> getList() {
        List<DictionaryInfo> list = this.list(new QueryWrapper<DictionaryInfo>()
                .in("return_type", ListUtil.arrayToList(new Long[] { 0L, 2L }))
                .eq("is_deleted", IsDeleteEnum.N.getKey())
                .orderByAsc("group_type", "order_no"));
        List<DictionaryInfoDTO> listRes = BeanUtil.listCopyTo(list, DictionaryInfoDTO.class);
        return EntityUtil.makeEntityListMap(listRes, "groupType");
    }

    /**
     * 返回字典信息
     *
     * @return
     */
    public Map<Long, List<DictionaryInfoDTO>> getListBack() {
        List<DictionaryInfo> list = this.list(new QueryWrapper<DictionaryInfo>()
                .in("return_type", ListUtil.arrayToList(new Long[] { 0L, 1L }))
                .eq("is_deleted", IsDeleteEnum.N.getKey())
                .orderByAsc("group_type", "order_no"));
        List<DictionaryInfoDTO> listRes = BeanUtil.listCopyTo(list, DictionaryInfoDTO.class);
        return EntityUtil.makeEntityListMap(listRes, "groupType");
    }


    /**
     * 返回指定字典信息
     *
     * @param groupType
     * @return
     */
    public List<DictionaryInfoDTO> getListByGroupType(Integer groupType) {
        List<DictionaryInfo> list = this.list(new QueryWrapper<DictionaryInfo>()
                .eq("group_type", groupType)
                .eq("is_deleted", IsDeleteEnum.N.getKey())
                .orderByAsc("order_no"));
        List<DictionaryInfoDTO> listRes = BeanUtil.listCopyTo(list, DictionaryInfoDTO.class);
        return listRes;
    }
    
}