|  | @ -0,0 +1,157 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.service.course;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.course.CourseCatalogueDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.course.CourseDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.course.CourseSalesOrderRecordDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.ResponseContant;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.HashMap;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import static com.yihu.jw.rm.iot.IotRequestMapping.Common.hospital;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created with IntelliJ IDEA.
 | 
	
		
			
				|  |  |  *
 | 
	
		
			
				|  |  |  * @Author: yeshijie
 | 
	
		
			
				|  |  |  * @Date: 2021/5/18
 | 
	
		
			
				|  |  |  * @Description:
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class CourseService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private CourseDao courseDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private CourseCatalogueDao courseCatalogueDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private CourseSalesOrderRecordDao courseSalesOrderRecordDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao patientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorDao doctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 顶部状态栏订单各分类总条数
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Map<String, Integer> topStatusBarNum(String patient) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "SELECT a.`status`,COUNT(*) num from ( " +
 | 
	
		
			
				|  |  |                 "SELECT `status` from base_recruit_students_record  where patient = '"+patient+"' " +
 | 
	
		
			
				|  |  |                 "UNION ALL " +
 | 
	
		
			
				|  |  |                 "SELECT `status` from base_course_sales_order_record where patient = '"+patient+"' ) a " +
 | 
	
		
			
				|  |  |                 "GROUP BY a.`status` " ;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         Map<String, Integer> map = new HashMap<>();
 | 
	
		
			
				|  |  |         //状态 待服务 1、已完成 2 、已取消 -1
 | 
	
		
			
				|  |  |         map.put("1",0);
 | 
	
		
			
				|  |  |         map.put("2",0);
 | 
	
		
			
				|  |  |         map.put("3",0);
 | 
	
		
			
				|  |  |         map.put("4",0);
 | 
	
		
			
				|  |  |         map.put("5",0);
 | 
	
		
			
				|  |  |         int total = 0;
 | 
	
		
			
				|  |  |         if(list.size()>0){
 | 
	
		
			
				|  |  |             for (Map<String, Object> one:list){
 | 
	
		
			
				|  |  |                 map.put(String.valueOf(one.get("status")), Integer.valueOf(String.valueOf(one.get("num"))));
 | 
	
		
			
				|  |  |                 total+=Integer.valueOf(String.valueOf(one.get("num")));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         map.put("total", total);
 | 
	
		
			
				|  |  |         return map;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject patientOrderList(String patient, Integer status, int page, int size) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         int start = 0 == page ? page++ : (page - 1) * size;
 | 
	
		
			
				|  |  |         int end = 0 == size ? 15 : size;
 | 
	
		
			
				|  |  |         StringBuffer buffer = new StringBuffer();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "SELECT " +
 | 
	
		
			
				|  |  |                 "  p.name AS patientName, " +
 | 
	
		
			
				|  |  |                 "  p.photo AS photo, " +
 | 
	
		
			
				|  |  |                 "  p.idcard," +
 | 
	
		
			
				|  |  |                 "  case p.sex  " +
 | 
	
		
			
				|  |  |                 "  when 1 then '男'  " +
 | 
	
		
			
				|  |  |                 "  when 2 then '女' " +
 | 
	
		
			
				|  |  |                 "  end AS sex, " +
 | 
	
		
			
				|  |  |                 "  TIMESTAMPDIFF(year,p.birthday,NOW()) AS age," +
 | 
	
		
			
				|  |  |                 "  o.id as orderId, " +
 | 
	
		
			
				|  |  |                 "  o.patient_phone as phone, " +
 | 
	
		
			
				|  |  |                 "  o.proxy_patient as proxyPatient, " +
 | 
	
		
			
				|  |  |                 "  o.patient as patient, " +
 | 
	
		
			
				|  |  |                 "  o.number as number, " +
 | 
	
		
			
				|  |  |                 "  o.patient_expected_serve_time as serveTime, o.doctor, o.doctor_name as doctorName, " +
 | 
	
		
			
				|  |  |                 "  o.serve_address as address, " +
 | 
	
		
			
				|  |  |                 "  o.type as type, " +
 | 
	
		
			
				|  |  |                 "  o.serve_lon as lon, " +
 | 
	
		
			
				|  |  |                 "  o.serve_lat as lat, " +
 | 
	
		
			
				|  |  |                 "  o.`status` as status " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " ( base_life_care_order o " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN base_patient p ON o.patient = p.id ) "+
 | 
	
		
			
				|  |  |                 " WHERE " +
 | 
	
		
			
				|  |  |                 "  o.hospital = '{hospital}' and o.type != 3 " +buffer+
 | 
	
		
			
				|  |  |                 " AND ( o.`status` = {status} OR -100 = {status} ) " +
 | 
	
		
			
				|  |  |                 " ORDER BY o.create_time desc " +
 | 
	
		
			
				|  |  |                 " LIMIT {start},{end};";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String finalSql = sql.replace("{status}", String.valueOf(status))
 | 
	
		
			
				|  |  |                 .replace("{start}", String.valueOf(start))
 | 
	
		
			
				|  |  |                 .replace("{end}", String.valueOf(end));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String countSql = "SELECT  " +
 | 
	
		
			
				|  |  |                 "   count(o.id)  " +
 | 
	
		
			
				|  |  |                 " FROM  " +
 | 
	
		
			
				|  |  |                 "   base_life_care_order o  " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN base_patient p ON o.patient = p.id " +
 | 
	
		
			
				|  |  |                 " WHERE  " +
 | 
	
		
			
				|  |  |                 "  o.hospital = '{hospital}' " +buffer+
 | 
	
		
			
				|  |  |                 " AND (o.`status` = {status} or -100 = {status})";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String finqlCountSql = countSql.replace("{hospital}", hospital)
 | 
	
		
			
				|  |  |                 .replace("{status}", String.valueOf(status));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<Map<String,Object>> sqlResultlist;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             sqlResultlist = jdbcTemplate.queryForList(finalSql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, "从数据库查询生活照料工单列表信息失败");
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Long count;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             count = jdbcTemplate.queryForObject(finqlCountSql, Long.class);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, "从数据库统计生活照料工单数量失败" );
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, sqlResultlist);
 | 
	
		
			
				|  |  |         JSONObject countItem = new JSONObject();
 | 
	
		
			
				|  |  |         countItem.put("count", count);
 | 
	
		
			
				|  |  |         result.putAll(countItem);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |