|  | @ -1,5 +1,6 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.service.course;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
	
		
			
				|  | @ -8,12 +9,20 @@ import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.course.CourseSalesOrderRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.course.PatientOrderRefundDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.course.RecruitStudentsRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.course.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.order.BusinessOrderDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.dao.BusinessOrderDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.org.dao.BaseOrgDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.ResponseContant;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.base.BaseRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.StringUtil;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
	
		
			
				|  | @ -21,6 +30,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.math.BigDecimal;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.HashMap;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
	
		
			
				|  | @ -55,6 +66,10 @@ public class CourseService {
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientOrderRefundDao patientOrderRefundDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseOrgDao orgDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorHospitalDao doctorHospitalDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ObjectMapper objectMapper;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorHospitalDao baseDoctorHospitalDao;
 | 
	
	
		
			
				|  | @ -121,26 +136,22 @@ public class CourseService {
 | 
	
		
			
				|  |  |         if(flag){
 | 
	
		
			
				|  |  |             //支付信息
 | 
	
		
			
				|  |  |             BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(id);
 | 
	
		
			
				|  |  |             if(businessOrderDO!=null){
 | 
	
		
			
				|  |  |                 JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  |                 json.put("payPrice",businessOrderDO.getPayPrice());
 | 
	
		
			
				|  |  |                 json.put("payTime",DateUtil.dateToStrLong(businessOrderDO.getPayTime()));
 | 
	
		
			
				|  |  |                 json.put("payType",businessOrderDO.getPayType());
 | 
	
		
			
				|  |  |                 resJson.put("businessOrderDO",json);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  |             json.put("payPrice",businessOrderDO.getPayPrice());
 | 
	
		
			
				|  |  |             json.put("payTime",businessOrderDO.getPayTime());
 | 
	
		
			
				|  |  |             json.put("payType",businessOrderDO.getPayType());
 | 
	
		
			
				|  |  |             resJson.put("businessOrderDO",json);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if("5".equals(status)||"6".equals(status)){
 | 
	
		
			
				|  |  |             //退款信息
 | 
	
		
			
				|  |  |             PatientOrderRefundDO refundDO = patientOrderRefundDao.findByTypeAndOrderId(type,id);
 | 
	
		
			
				|  |  |             if(refundDO!=null){
 | 
	
		
			
				|  |  |                 JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  |                 json.put("createTime", DateUtil.dateToStrLong(refundDO.getCreateTime()));
 | 
	
		
			
				|  |  |                 json.put("refundPrice",refundDO.getRefundPrice());
 | 
	
		
			
				|  |  |                 json.put("status",refundDO.getStatus());
 | 
	
		
			
				|  |  |                 json.put("refundDesc",refundDO.getRefundDesc());
 | 
	
		
			
				|  |  |                 json.put("enclosure",refundDO.getEnclosure());
 | 
	
		
			
				|  |  |                 resJson.put("refundDO",json);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  |             json.put("createTime",refundDO.getCreateTime());
 | 
	
		
			
				|  |  |             json.put("refundPrice",refundDO.getRefundPrice());
 | 
	
		
			
				|  |  |             json.put("status",refundDO.getStatus());
 | 
	
		
			
				|  |  |             json.put("refundDesc",refundDO.getRefundDesc());
 | 
	
		
			
				|  |  |             json.put("enclosure",refundDO.getEnclosure());
 | 
	
		
			
				|  |  |             resJson.put("refundDO",json);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return resJson;
 | 
	
	
		
			
				|  | @ -321,14 +332,14 @@ public class CourseService {
 | 
	
		
			
				|  |  |             filter += " and status = "+ status +" ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sqlUnion = " SELECT id,`status`,recruit_name title,pay_type payType,price,1 type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') createTime " +
 | 
	
		
			
				|  |  |         String sqlUnion = " SELECT id,`status`,recruit_name title,pay_type payType,price,1 type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') createTtime " +
 | 
	
		
			
				|  |  |                 " from base_recruit_students_record " + filter+
 | 
	
		
			
				|  |  |                 " UNION ALL " +
 | 
	
		
			
				|  |  |                 " SELECT id,`status`,course_name title,pay_type payType,price,2 type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') createTime  " +
 | 
	
		
			
				|  |  |                 " SELECT id,`status`,course_name title,pay_type payType,price,2 type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') createTtime  " +
 | 
	
		
			
				|  |  |                 " from base_course_sales_order_record " + filter+" ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "SELECT * from ( " + sqlUnion + " ) a " +
 | 
	
		
			
				|  |  |                 " ORDER BY a.createTime desc " +
 | 
	
		
			
				|  |  |                 " ORDER BY a.createTtime desc " +
 | 
	
		
			
				|  |  |                 " LIMIT {start},{end};";
 | 
	
		
			
				|  |  |         String finalSql = sql.replace("{start}", String.valueOf(start))
 | 
	
		
			
				|  |  |                 .replace("{end}", String.valueOf(end));
 | 
	
	
		
			
				|  | @ -361,4 +372,310 @@ public class CourseService {
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //根据机构坐标进行排序
 | 
	
		
			
				|  |  |     public JSONObject getCourseByCourse(String lon2,String lat2, int pageSize,int currentPage){
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = "SELECT id,`name`,longitude,latitude FROM base.base_org where del = 1 and type = 4";
 | 
	
		
			
				|  |  |         List<Map<String , Object>> positionList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<Map<String , Object>> currentPageList = new ArrayList<>();
 | 
	
		
			
				|  |  |         if (positionList.size() > 0){
 | 
	
		
			
				|  |  |             for (int i=0;i<positionList.size();i++){
 | 
	
		
			
				|  |  |                 String sql1 = "SELECT id,code,`name`,longitude,latitude ,funDistance("+positionList.get(i).get("latitude")+","+positionList.get(i).get("longitude")+","+lat2+","+lon2+") funDistance FROM base.base_org where id = '"+positionList.get(i).get("id")+"'";
 | 
	
		
			
				|  |  |                 List<Map<String , Object>> mapList = jdbcTemplate.queryForList(sql1);
 | 
	
		
			
				|  |  |                 JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  |                 obj.put("id",mapList.get(0).get("id"));
 | 
	
		
			
				|  |  |                 obj.put("name",mapList.get(0).get("name"));
 | 
	
		
			
				|  |  |                 obj.put("longitude",mapList.get(0).get("longitude"));
 | 
	
		
			
				|  |  |                 obj.put("latitude",mapList.get(0).get("latitude"));
 | 
	
		
			
				|  |  |                 obj.put("funDistance",mapList.get(0).get("funDistance"));
 | 
	
		
			
				|  |  |                 obj.put("code",mapList.get(0).get("code"));
 | 
	
		
			
				|  |  |                 list.add(obj);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (list.size() > 0){
 | 
	
		
			
				|  |  |                 Collections.sort(list, new Comparator<Map<String, Object>>() {
 | 
	
		
			
				|  |  |                     public int compare(Map<String, Object> o1, Map<String, Object> o2) {
 | 
	
		
			
				|  |  |                         return (Double) o1.get("funDistance") > (Double) o2.get("funDistance") ? 1 : ((Double) o1.get("funDistance") == (Double) o2.get("funDistance") ? 0 : -1);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 });
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             List aList = new ArrayList();
 | 
	
		
			
				|  |  |             if (list.size() > 0){
 | 
	
		
			
				|  |  |                 for (int i =0;i<list.size();i++){
 | 
	
		
			
				|  |  |                     String sql1 = "SELECT * FROM base_course WHERE del = 1 AND org_code = '"+list.get(i).get("code")+"'" ;
 | 
	
		
			
				|  |  |                     List<Map<String , Object >> amapList = jdbcTemplate.queryForList(sql1);
 | 
	
		
			
				|  |  |                     if (amapList.size() > 0){
 | 
	
		
			
				|  |  |                         aList.add(amapList.get(0));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (aList.size() > 0 ){
 | 
	
		
			
				|  |  |                     if (aList != null && aList.size() > 0) {
 | 
	
		
			
				|  |  |                         int currIdx = (currentPage > 1 ? (currentPage - 1) * pageSize : 0);
 | 
	
		
			
				|  |  |                         for (int i = 0; i < pageSize && i < aList.size() - currIdx; i++) {
 | 
	
		
			
				|  |  |                             Map<String, Object> data = (Map<String, Object>) aList.get(currIdx + i);
 | 
	
		
			
				|  |  |                             currentPageList.add(data);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             object.put("object",currentPageList);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getCourseByOrg(String lon2,String lat2){ //, int pageSize,int currentPage
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = "SELECT id,`name`,longitude,latitude FROM base.base_org where del = 1 and type = 4";
 | 
	
		
			
				|  |  |         List<Map<String , Object>> positionList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = new ArrayList<>();
 | 
	
		
			
				|  |  |         if (positionList.size() > 0){
 | 
	
		
			
				|  |  |             for (int i=0;i<positionList.size();i++){
 | 
	
		
			
				|  |  |                 String sql1 = "SELECT id,`name`,photo,address,longitude,latitude ,funDistance("+positionList.get(i).get("latitude")+","+positionList.get(i).get("longitude")+","+lat2+","+lon2+") funDistance FROM base.base_org where id = '"+positionList.get(i).get("id")+"'";
 | 
	
		
			
				|  |  |                 List<Map<String , Object>> mapList = jdbcTemplate.queryForList(sql1);
 | 
	
		
			
				|  |  |                 JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  |                 obj.put("id",mapList.get(0).get("id"));
 | 
	
		
			
				|  |  |                 obj.put("name",mapList.get(0).get("name"));
 | 
	
		
			
				|  |  |                 obj.put("photo",mapList.get(0).get("photo"));
 | 
	
		
			
				|  |  |                 obj.put("address",mapList.get(0).get("address"));
 | 
	
		
			
				|  |  |                 obj.put("longitude",mapList.get(0).get("longitude"));
 | 
	
		
			
				|  |  |                 obj.put("latitude",mapList.get(0).get("latitude"));
 | 
	
		
			
				|  |  |                 obj.put("funDistance",mapList.get(0).get("funDistance"));
 | 
	
		
			
				|  |  |                 list.add(obj);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (list.size() > 0){
 | 
	
		
			
				|  |  |                 Collections.sort(list, new Comparator<Map<String, Object>>() {
 | 
	
		
			
				|  |  |                     public int compare(Map<String, Object> o1, Map<String, Object> o2) {
 | 
	
		
			
				|  |  |                         return (Double) o1.get("funDistance") > (Double) o2.get("funDistance") ? 1 : ((Double) o1.get("funDistance") == (Double) o2.get("funDistance") ? 0 : -1);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 });
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             object.put("object",list);
 | 
	
		
			
				|  |  | //            List<Map<String , Object>> currentPageList = new ArrayList<>();
 | 
	
		
			
				|  |  | //            if (list.size() > 0 ){
 | 
	
		
			
				|  |  | //                if (list != null && list.size() > 0) {
 | 
	
		
			
				|  |  | //                    int currIdx = (currentPage > 1 ? (currentPage - 1) * pageSize : 0);
 | 
	
		
			
				|  |  | //                    for (int i = 0; i < pageSize && i < list.size() - currIdx; i++) {
 | 
	
		
			
				|  |  | //                        Map<String, Object> data = list.get(currIdx + i);
 | 
	
		
			
				|  |  | //                        currentPageList.add(data);
 | 
	
		
			
				|  |  | //                    }
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //            object.put("object",currentPageList);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getCourseByteacher(String lon2,String lat2){ //, int pageSize,int currentPage
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = "SELECT id,`name`,longitude,latitude FROM base.base_org where del = 1 and type = 4";
 | 
	
		
			
				|  |  |         List<Map<String , Object>> positionList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<Map<String , Object>> currentPageList = new ArrayList<>();
 | 
	
		
			
				|  |  |         if (positionList.size() > 0){
 | 
	
		
			
				|  |  |             for (int i=0;i<positionList.size();i++){
 | 
	
		
			
				|  |  |                 String sql1 = "SELECT id,`name`,longitude,latitude ,funDistance("+positionList.get(i).get("latitude")+","+positionList.get(i).get("longitude")+","+lat2+","+lon2+") funDistance FROM base.base_org where id = '"+positionList.get(i).get("id")+"'";
 | 
	
		
			
				|  |  |                 List<Map<String , Object>> mapList = jdbcTemplate.queryForList(sql1);
 | 
	
		
			
				|  |  |                 JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  |                 obj.put("id",mapList.get(0).get("id"));
 | 
	
		
			
				|  |  |                 obj.put("name",mapList.get(0).get("name"));
 | 
	
		
			
				|  |  |                 obj.put("longitude",mapList.get(0).get("longitude"));
 | 
	
		
			
				|  |  |                 obj.put("latitude",mapList.get(0).get("latitude"));
 | 
	
		
			
				|  |  |                 obj.put("funDistance",mapList.get(0).get("funDistance"));
 | 
	
		
			
				|  |  |                 list.add(obj);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (list.size() > 0){
 | 
	
		
			
				|  |  |                 Collections.sort(list, new Comparator<Map<String, Object>>() {
 | 
	
		
			
				|  |  |                     public int compare(Map<String, Object> o1, Map<String, Object> o2) {
 | 
	
		
			
				|  |  |                         return (Double) o1.get("funDistance") > (Double) o2.get("funDistance") ? 1 : ((Double) o1.get("funDistance") == (Double) o2.get("funDistance") ? 0 : -1);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 });
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             List aList = new ArrayList();
 | 
	
		
			
				|  |  |             if (list.size() > 0){
 | 
	
		
			
				|  |  |                 for (int i =0;i<list.size();i++){
 | 
	
		
			
				|  |  |                     String sql1 = "SELECT id,`name`,job_title_code,job_title_name,visit_hospital,visit_hospital_name FROM base_doctor WHERE doctor_level = 3 AND enabled = 1 AND locked = 0 AND del = 1 and  visit_hospital = '"+list.get(i).get("id")+"'" ;
 | 
	
		
			
				|  |  |                     List<Map<String , Object >> amapList = jdbcTemplate.queryForList(sql1);
 | 
	
		
			
				|  |  |                     if (amapList.size() > 0){
 | 
	
		
			
				|  |  |                         aList.add(amapList.get(0));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             object.put("object",aList);
 | 
	
		
			
				|  |  | //                if (list.size() > 0 ){
 | 
	
		
			
				|  |  | //                    if (list != null && list.size() > 0) {
 | 
	
		
			
				|  |  | //                        int currIdx = (currentPage > 1 ? (currentPage - 1) * pageSize : 0);
 | 
	
		
			
				|  |  | //                        for (int i = 0; i < pageSize && i < list.size() - currIdx; i++) {
 | 
	
		
			
				|  |  | //                            Map<String, Object> data = list.get(currIdx + i);
 | 
	
		
			
				|  |  | //                            currentPageList.add(data);
 | 
	
		
			
				|  |  | //                        }
 | 
	
		
			
				|  |  | //                    }
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | //            object.put("object",currentPageList);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getCourseInfo(String id){
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = "SELECT * FROM base_course WHERE id = '"+id+"' AND del = 1 ";
 | 
	
		
			
				|  |  |         List<Map<String , Object>> mapList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         if (mapList.size() > 0){
 | 
	
		
			
				|  |  |             object.put("doctor",mapList.get(0).get("doctor"));
 | 
	
		
			
				|  |  |             object.put("doctorName",mapList.get(0).get("doctor_name"));
 | 
	
		
			
				|  |  |             List<BaseDoctorHospitalDO> baseDoctorHospitalDO = doctorHospitalDao.findByDoctorCode(mapList.get(0).get("doctor").toString());
 | 
	
		
			
				|  |  |             object.put("org",baseDoctorHospitalDO.get(0).getOrgCode());
 | 
	
		
			
				|  |  |             object.put("orgName",baseDoctorHospitalDO.get(0).getOrgName());
 | 
	
		
			
				|  |  |             object.put("jobTitleCode",baseDoctorHospitalDO.get(0).getDoctorDutyCode());
 | 
	
		
			
				|  |  |             object.put("jobTitleName",baseDoctorHospitalDO.get(0).getDoctorDutyName());
 | 
	
		
			
				|  |  |             object.put("introduction",mapList.get(0).get("introduction")); // 课程简介
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getCatalogue(String id,String patient){
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = "SELECT cc.* FROM base_course_catalogue cc,base_course c WHERE cc.course_id = '"+id+"' AND cc.course_id = c.id AND c.del = 1";
 | 
	
		
			
				|  |  |         List<Map<String , Object>> mapList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         JSONArray array = new JSONArray();
 | 
	
		
			
				|  |  |         if (mapList.size() > 0){
 | 
	
		
			
				|  |  |             for (int i = 0; i < mapList.size() ; i++){
 | 
	
		
			
				|  |  |                 //  根据居民code,查询居民是否阅读过本课程
 | 
	
		
			
				|  |  |                 String readSql = "SELECT read_time FROM base_course_catalogue_read_time WHERE course_id = '"+mapList.get(i).get("course_id")+"' AND course_catalogue_id = '"+id+"' AND patient = '"+patient+"'";
 | 
	
		
			
				|  |  |                 List<Map<String , Object>> readMapList = jdbcTemplate.queryForList(readSql);
 | 
	
		
			
				|  |  |                 if (readMapList.size() > 0){
 | 
	
		
			
				|  |  |                     mapList.add(readMapList.get(0));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 array.add(mapList.get(i));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         object.put("object",array);
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getOrgInfoById(String id){
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = "SELECT o.id,o.`code`,o.`name`,o.mobile,o.photo,o.address,o.intro,rs.start_time startTime,rs.end_time endTime,rs.num,rs.fee,rs.id rsId \n" +
 | 
	
		
			
				|  |  |                 "FROM base_org o,base_recruit_students rs\n" +
 | 
	
		
			
				|  |  |                 "WHERE o.id = '"+id+"' AND o.type = 4 AND o.del = 1 AND o.`code` = rs.org_code AND rs.del = 1";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         if (mapList.size() > 0){
 | 
	
		
			
				|  |  |             object.put("id",mapList.get(0).get("id"));//机构id
 | 
	
		
			
				|  |  |             object.put("name",mapList.get(0).get("name"));//机构名称
 | 
	
		
			
				|  |  |             object.put("mobile",mapList.get(0).get("mobile"));//机构联系方式
 | 
	
		
			
				|  |  |             object.put("photo",mapList.get(0).get("photo"));//机构图片
 | 
	
		
			
				|  |  |             object.put("address",mapList.get(0).get("address"));//机构地址
 | 
	
		
			
				|  |  |             object.put("intro",mapList.get(0).get("intro"));//机构简介
 | 
	
		
			
				|  |  |             object.put("startTime",mapList.get(0).get("startTime"));//招生开始时间
 | 
	
		
			
				|  |  |             object.put("endTime",mapList.get(0).get("endTime"));//招生结束时间
 | 
	
		
			
				|  |  |             object.put("num",mapList.get(0).get("num"));//招生名额
 | 
	
		
			
				|  |  |             object.put("fee",mapList.get(0).get("fee"));//报名费用
 | 
	
		
			
				|  |  |             String sql1 = "SELECT COUNT(*) count\n" +
 | 
	
		
			
				|  |  |                     "FROM base_org o,base_recruit_students_record rsr,base_recruit_students rs\n" +
 | 
	
		
			
				|  |  |                     "WHERE o.`code` = rsr.org_code AND rsr.recruit_students_id = '"+mapList.get(0).get("rsId")+"' AND o.`code` = '"+mapList.get(0).get("code")+"' AND (`status` = 3 OR `status` = 6);\n";
 | 
	
		
			
				|  |  |             Integer count = jdbcTemplate.queryForObject(sql1,Integer.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String sql2 = "SELECT * FROM base_course WHERE del = 1 AND org_code = '"+mapList.get(0).get("code")+"'" ;
 | 
	
		
			
				|  |  |             List<Map<String , Object >> amapList = jdbcTemplate.queryForList(sql2);
 | 
	
		
			
				|  |  |             if (amapList.size() > 0){
 | 
	
		
			
				|  |  |                 object.put("allCourse",amapList);//课程
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 object.put("allCourse","");//课程
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String sql3 = "SELECT *  FROM base_doctor d,base_doctor_hospital dh\n" +
 | 
	
		
			
				|  |  |                     "WHERE d.doctor_level = 3 AND d.locked = 0 AND d.enabled = 1 AND d.del = 1 AND d.id = dh.doctor_code AND dh.del = 1 AND dh.org_code = '"+mapList.get(0).get("code")+"'" ;
 | 
	
		
			
				|  |  |             List<Map<String , Object >> bmapList = jdbcTemplate.queryForList(sql3);
 | 
	
		
			
				|  |  |             if (bmapList.size() > 0){
 | 
	
		
			
				|  |  |                 object.put("allDoctor",bmapList);//教师
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 object.put("allDoctor","");//教师
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             object.put("count",count);//已报名人数
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getTecInfoById(String doctor,String orgCode,int page,int size){
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         //老师的基本信息
 | 
	
		
			
				|  |  |         String sql = "SELECT d.id,d.name,d.job_title_code jobTitleCode,d.job_title_name jobTitleName,dh.org_code orgCode,dh.org_name orgName\n" +
 | 
	
		
			
				|  |  |                 "FROM base_doctor d,base_doctor_hospital dh\n" +
 | 
	
		
			
				|  |  |                 "WHERE d.id = '"+doctor+"' AND dh.org_code = '"+orgCode+"' AND d.enabled = 1 AND d.locked = 0 AND d.del = 1 AND dh.del = 1 AND dh.doctor_code = d.id";
 | 
	
		
			
				|  |  |         List<Map<String , Object>> mapList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         object.put("doctorInfo",mapList.get(0));
 | 
	
		
			
				|  |  |         if (mapList.size() > 0){
 | 
	
		
			
				|  |  |             page = page - 1;
 | 
	
		
			
				|  |  |             size = (page+1)*size;
 | 
	
		
			
				|  |  |             String sql1 = "SELECT * FROM base_course WHERE doctor = '"+doctor+"' AND del = 1 limit "+page+","+size+"";
 | 
	
		
			
				|  |  |             List<Map<String , Object>> mapList1 = jdbcTemplate.queryForList(sql1);
 | 
	
		
			
				|  |  |             if (mapList1.size() > 0){
 | 
	
		
			
				|  |  |                 object.put("allCourse",mapList1);
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 object.put("allCourse","");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return  object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getCoursrOrderStatusByPatient(String patient,int status,int page,int size){
 | 
	
		
			
				|  |  |         page = page - 1;
 | 
	
		
			
				|  |  |         size = (page+1)*10;
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = "SELECT id,course_name courseName,buy_time buyTime,pay_type payType,status FROM base_course_sales_order_record WHERE patient = '"+patient+"'";
 | 
	
		
			
				|  |  |         if (status > 0){
 | 
	
		
			
				|  |  |             sql += " and status = "+status+" ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql += " order by create_time desc limit "+page+","+size+" ";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql1 = "SELECT id,org_code orgCode,org_name orgName,pay_type payType,create_time createTime,status FROM base_recruit_students_record WHERE patient = '"+patient+"'";
 | 
	
		
			
				|  |  |         if (status > 0){
 | 
	
		
			
				|  |  |             sql1 += " and status = "+status+" ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql1 += " order by create_time desc limit "+page+","+size+"  ";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> mapList1 = jdbcTemplate.queryForList(sql1);
 | 
	
		
			
				|  |  |         object.put("course",mapList);
 | 
	
		
			
				|  |  |         object.put("org",mapList1);
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getOrderInfo(String orderId){
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = "SELECT id,course_name courseName,order_no orderNo,buy_time buyTime,pay_type payType,status orderStatus FROM base_course_sales_order_record WHERE id = '"+orderId+"'";
 | 
	
		
			
				|  |  |         List<Map<String , Object>> mapList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         if (mapList.size() < 0){
 | 
	
		
			
				|  |  |             sql = "SELECT id,org_code orgCode,org_name orgName,order_no orderNo,pay_type payType,create_time createTime,status FROM base_recruit_students_record WHERE patient = '"+orderId+"'";
 | 
	
		
			
				|  |  |             mapList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (mapList.size() > 0 && mapList.get(0).get("status").equals(6)){
 | 
	
		
			
				|  |  |             String sql1 = "select status,create_time createTime,refund_price refundPrice,refund_desc refundDesc,enclosure from base_patient_order_refund where order_id = '"+mapList.get(0).get("id")+"' " ;
 | 
	
		
			
				|  |  |             List<Map<String , Object>> mapList1 = jdbcTemplate.queryForList(sql1);
 | 
	
		
			
				|  |  |             mapList.get(0).put("refundStatus",mapList1.get(0).get("status"));       //退款状态
 | 
	
		
			
				|  |  |             mapList.get(0).put("createTime",mapList1.get(0).get("createTime"));     //退款申请时间
 | 
	
		
			
				|  |  |             mapList.get(0).put("refundPrice",mapList1.get(0).get("refundPrice"));      //退款金额
 | 
	
		
			
				|  |  |             mapList.get(0).put("refundDesc",mapList1.get(0).get("refundDesc"));     //退款原因
 | 
	
		
			
				|  |  |             mapList.get(0).put("enclosure",mapList1.get(0).get("enclosure"));   //附件
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         object.put("object",mapList);
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public int buyCourseOrder(String patient, String patientName, String courseId, String courseName, String orgCode, String orgName, BigDecimal price,String payType){
 | 
	
		
			
				|  |  |         CourseSalesOrderRecordDO recordDO = new CourseSalesOrderRecordDO();
 | 
	
		
			
				|  |  |         recordDO.setBuyTime(new Date());
 | 
	
		
			
				|  |  |         recordDO.setPatient(patient);
 | 
	
		
			
				|  |  |         recordDO.setPatientName(patientName);
 | 
	
		
			
				|  |  |         recordDO.setCourseId(courseId);
 | 
	
		
			
				|  |  |         recordDO.setCourseName(courseName);
 | 
	
		
			
				|  |  |         recordDO.setOrgCode(orgCode);
 | 
	
		
			
				|  |  |         recordDO.setOrgName(orgName);
 | 
	
		
			
				|  |  |         recordDO.setPrice(price);
 | 
	
		
			
				|  |  |         recordDO.setPayType(payType);
 | 
	
		
			
				|  |  |         long  timeNew =  System.currentTimeMillis(); // 13位数的时间戳
 | 
	
		
			
				|  |  |         recordDO.setOrderNo(timeNew+"");
 | 
	
		
			
				|  |  |         courseSalesOrderRecordDao.save(recordDO);
 | 
	
		
			
				|  |  |         return 1;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |