package com.yihu.jw.base.service.course;

import com.yihu.jw.base.dao.course.CourseDao;
import com.yihu.jw.entity.care.course.CourseDO;
import com.yihu.jw.utils.StringUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/5/12
 * @Description:
 */
@Service
public class CourseService extends BaseJpaService<CourseDO, CourseDao> {

    @Autowired
    private CourseDao courseDao;

    /**
     * 伪删除
     * @param ids
     */
    public void deletes(String ids){
        List<CourseDO> courseDOList = new ArrayList<>();
        for(String id:ids.split(",")){
            CourseDO courseDO = courseDao.findOne(id);
            courseDO.setDel(0);
            courseDOList.add(courseDO);
        }
        courseDao.save(courseDOList);
    }

    /**
     * 查找机构的老师
     * @param orgCode
     * @return
     */
    public List<Map<String,Object>> findDoctorByOrg(String orgCode){
        String sql ="SELECT d.id,d.name from base_doctor_hospital h,base_doctor d " +
                "WHERE h.doctor_code = d.id and h.del = '1' and d.del = '1' ";
        if(!StringUtil.isBlank(orgCode)){
            sql += " and h.org_code = '"+orgCode+"' ";
        }
        return jdbcTemplate.queryForList(sql);
    }
}
