| 
					
				 | 
			
			
				@ -0,0 +1,189 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.service.course; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.course.RecruitStudentsDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.course.RecruitStudentsRecordDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.course.RecruitStudentsDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.course.RecruitStudentsRecordDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.ResponseContant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.collections.map.HashedMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.BeanPropertyRowMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created with IntelliJ IDEA. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Author: yeshijie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Date: 2021/6/8 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Description: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class RecruitStudentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientDao patientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoctorDao doctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private RecruitStudentsRecordDao recruitStudentsRecordDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private RecruitStudentsDao recruitStudentsDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoctorHospitalDao baseDoctorHospitalDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 在线报名-已报名数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctorId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Integer onlineRegisterCount(String doctorId){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<RecruitStudentsRecordDO> list = recruitStudentsRecordDao.findByOrgCodeAndStatus(baseDoctorHospitalDO.get(0).getOrgCode(),"1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list.size(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 统计在线报名各状态下的数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject onlineRegisterStatusCount(String doctorId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int total = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> res = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //状态 已报名1  已录取2 未录取4 已退学8 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        res.put("1",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        res.put("2",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        res.put("4",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        res.put("8",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String countSql = "SELECT " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  count(o.id) as count, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  o.status as status " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_recruit_students_record o " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  o.org_code = '"+ baseDoctorHospitalDO.get(0).getOrgCode() + "' and o.del = 1 "+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " GROUP BY o.`status`"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> countMapList = jdbcTemplate.queryForList(countSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for(Map<String,Object> map:countMapList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            int c = Integer.valueOf(map.get("count").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            total +=c; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            res.put(String.valueOf(map.get("status")),c); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        res.put("total",total); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultFlag, ResponseContant.success); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultMsg, res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 在线报名列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject queryInfoList(String doctorId,Integer status, int page, int size) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String orgCode = baseDoctorHospitalDO.get(0).getOrgCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        status = null == status ? -100 : status; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int start = 0 == page ? page++ : (page - 1) * size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int end = 0 == size ? 15 : size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT o.id,o.patient,o.patient_name patientName,o.status,o.create_time createTime,p.photo  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " FROM  base_recruit_students_record o" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " left join base_patient p on o.patient = p.id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE o.org_code = '{org_code}' and o.del =1 "+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " AND (o.`status` = {status} or -100 = {status})" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " ORDER BY o.create_time desc" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " LIMIT {start},{end} "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String finalSql = sql.replace("{org_code}", orgCode) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{status}", String.valueOf(status)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{start}", String.valueOf(start)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{end}", String.valueOf(end)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String countSql = "SELECT count(DISTINCT o.id) FROM base_recruit_students_record o " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE o.org_code = '{org_code}' and o.del =1 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " AND (o.`status` = {status} or -100 = {status})"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String finqlCountSql = countSql.replace("{org_code}", orgCode) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{status}", String.valueOf(status)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> sqlResultlist= jdbcTemplate.queryForList(finalSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer count = jdbcTemplate.queryForObject(finqlCountSql, Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultFlag, ResponseContant.success); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultMsg, sqlResultlist); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject countItem = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        countItem.put("count", count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.putAll(countItem); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 录取单个 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public synchronized String admission(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        RecruitStudentsRecordDO recruitStudentsRecordDO = recruitStudentsRecordDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(!"1".equals(recruitStudentsRecordDO.getStatus())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "只有已报名状态的人员才能录取"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(isAdmissionFull(recruitStudentsRecordDO.getRecruitStudentsId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "超过录取名额,无法录取"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recruitStudentsRecordDO.setStatus("2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recruitStudentsRecordDao.save(recruitStudentsRecordDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 是否录取满 true录取满了 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public synchronized boolean isAdmissionFull(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<RecruitStudentsRecordDO> list = findListById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        RecruitStudentsDO recruitStudentsDO = recruitStudentsDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(recruitStudentsDO.getNum()<=list.size()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<RecruitStudentsRecordDO> findListById(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select * from base_recruit_students_record where recruit_students_id = '"+id+"' and status in ('2','3','6') and del =1 "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<RecruitStudentsRecordDO> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(RecruitStudentsRecordDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 拒绝单个 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public synchronized String refuse(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        RecruitStudentsRecordDO recruitStudentsRecordDO = recruitStudentsRecordDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(!"1".equals(recruitStudentsRecordDO.getStatus())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "只有已报名状态的人员才能拒绝"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recruitStudentsRecordDO.setStatus("4"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recruitStudentsRecordDao.save(recruitStudentsRecordDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |