package com.qunzhixinxi.hnqz.admin.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qunzhixinxi.hnqz.admin.entity.WmDeptTaskTypeTemplate;
import com.qunzhixinxi.hnqz.admin.mapper.WmDeptTaskTypeTemplateMapper;
import com.qunzhixinxi.hnqz.admin.service.WmDeptTaskTypeTemplateService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * @author lixuesong
 * @date 2022年01月18日 11:57
 */
@Service
@AllArgsConstructor
public class WmDeptTaskTypeTemplateServiceImpl extends ServiceImpl<WmDeptTaskTypeTemplateMapper, WmDeptTaskTypeTemplate> implements WmDeptTaskTypeTemplateService {

	/**
	 * 查询企业是否配置了医院拜访的任务类型模板
	 *
	 * @param deptId
	 * @param taskTypeId
	 * @return
	 */
	@Override
	public boolean checkDeptIdHospitalTemplate(Integer deptId, String taskTypeId) {
		int count = this.count(Wrappers.<WmDeptTaskTypeTemplate>lambdaQuery()
				.eq(WmDeptTaskTypeTemplate::getDeptId, deptId)
				.eq(WmDeptTaskTypeTemplate::getTaskTypeId, taskTypeId));
		return count > 0;
	}

	/**
	 * 根据deptId查询列表
	 *
	 * @param deptId
	 * @return
	 */
	@Override
	public List<String> listTaskTypeByDeptId(Integer deptId) {
		List<WmDeptTaskTypeTemplate> list = this.list(Wrappers.<WmDeptTaskTypeTemplate>lambdaQuery()
				.eq(WmDeptTaskTypeTemplate::getDeptId, deptId));
		if (CollUtil.isNotEmpty(list)) {
			return list.stream()
					.map(WmDeptTaskTypeTemplate::getTaskTypeId).collect(Collectors.toList());
		}
		return new ArrayList<>();
	}
}
