|  | @ -6,16 +6,22 @@ import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.http.HttpClientUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.hibernate.HibenateUtils;
 | 
	
		
			
				|  |  | import jxl.WorkbookSettings;
 | 
	
		
			
				|  |  | import jxl.write.*;
 | 
	
		
			
				|  |  | import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | import org.apache.poi.hssf.usermodel.*;
 | 
	
		
			
				|  |  | import org.apache.poi.xssf.usermodel.XSSFCell;
 | 
	
		
			
				|  |  | import org.apache.poi.xssf.usermodel.XSSFRow;
 | 
	
		
			
				|  |  | import org.apache.poi.xssf.usermodel.XSSFSheet;
 | 
	
		
			
				|  |  | import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.io.OutputStream;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class PayInfoNoticeService {
 | 
	
	
		
			
				|  | @ -25,8 +31,16 @@ public class PayInfoNoticeService {
 | 
	
		
			
				|  |  |     private HttpClientUtil httpClientUtil;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao patientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HibenateUtils hibenateUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${wechat.id}")
 | 
	
		
			
				|  |  |     private String wxId;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${wechat.flag}")
 | 
	
		
			
				|  |  |     private boolean flag;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String pushPrescriptionPay(String patient,String doctorName,String orderNo,String outpatientId,String prescriptionId,String total,String title,String url){
 | 
	
		
			
				|  |  |         BasePatientDO patientDO = patientDao.findById(patient);
 | 
	
		
			
				|  |  |         if (patientDO!=null){
 | 
	
	
		
			
				|  | @ -85,14 +99,47 @@ public class PayInfoNoticeService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //导出es查询数据
 | 
	
		
			
				|  |  |     public void exportEsPrescription(OutputStream os, com.alibaba.fastjson.JSONObject jsonObject) throws Exception{
 | 
	
		
			
				|  |  |         WritableWorkbook wwb = jxl.Workbook.createWorkbook(os);
 | 
	
		
			
				|  |  |     public void exportEsPrescription(OutputStream os, List<Map<String,Object>> list) throws Exception{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         WorkbookSettings settings = new WorkbookSettings();
 | 
	
		
			
				|  |  |         settings.setWriteAccess(null);
 | 
	
		
			
				|  |  |         settings.setEncoding("UTF-8");
 | 
	
		
			
				|  |  |         WritableWorkbook wwb = jxl.Workbook.createWorkbook(os,settings);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> totallist = new ArrayList<>();
 | 
	
		
			
				|  |  |         if (null!=list&&list.size()>0){
 | 
	
		
			
				|  |  |             totallist =list;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |        /* HSSFWorkbook workbook = new HSSFWorkbook();
 | 
	
		
			
				|  |  |         HSSFSheet sheet = workbook.createSheet("shee1");
 | 
	
		
			
				|  |  |         //headers表示excel表中第一行的表头
 | 
	
		
			
				|  |  |         HSSFRow row = sheet.createRow(0);
 | 
	
		
			
				|  |  |         //在excel表中添加表头
 | 
	
		
			
				|  |  |         String[] header = {"医生姓名", "出诊科室", "接诊数量", "开方数量", "物流数量"};
 | 
	
		
			
				|  |  |         for(int i=0;i<header.length;i++){
 | 
	
		
			
				|  |  |             HSSFCell cell = row.createCell(i);
 | 
	
		
			
				|  |  |             HSSFRichTextString text = new HSSFRichTextString(header[i]);
 | 
	
		
			
				|  |  |             cell.setCellValue(text);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         workbook.write(os);
 | 
	
		
			
				|  |  |         //接诊 +开方+物流
 | 
	
		
			
				|  |  |         com.alibaba.fastjson.JSONArray totallist = new JSONArray();
 | 
	
		
			
				|  |  |         if (null!=jsonObject){
 | 
	
		
			
				|  |  |             totallist = jsonObject.getJSONArray("outpatient");
 | 
	
		
			
				|  |  |         List<Map<String,Object>> totallist = new ArrayList<>();
 | 
	
		
			
				|  |  |         if (null!=list&&list.size()>0){
 | 
	
		
			
				|  |  |             totallist =list;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         int rowNum = 1;
 | 
	
		
			
				|  |  |         if (null!=totallist&&totallist.size()>0){
 | 
	
		
			
				|  |  |             for (int n=0;n<totallist.size();n++) {
 | 
	
		
			
				|  |  |                 Map<String,Object> object = totallist.get(n);
 | 
	
		
			
				|  |  |                 HSSFRow row1 = sheet.createRow(rowNum);
 | 
	
		
			
				|  |  |                 row1.createCell(0).setCellValue(object.get("doctorName").toString());
 | 
	
		
			
				|  |  |                 row1.createCell(1).setCellValue(null==object.get("deptName")?"":object.get("deptName").toString());
 | 
	
		
			
				|  |  |                 row1.createCell(2).setCellValue(null==object.get("pickNum")?"":object.get("pickNum").toString());
 | 
	
		
			
				|  |  |                 row1.createCell(3).setCellValue(null==object.get("preNum")?"":object.get("preNum").toString());
 | 
	
		
			
				|  |  |                 row1.createCell(4).setCellValue(null==object.get("wlNum")?"":object.get("wlNum").toString());
 | 
	
		
			
				|  |  |                 rowNum++;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         workbook.write(os);*/
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             WritableSheet ws;
 | 
	
		
			
				|  |  |             ws = wwb.createSheet("sheet", 1);
 | 
	
	
		
			
				|  | @ -106,16 +153,15 @@ public class PayInfoNoticeService {
 | 
	
		
			
				|  |  |             int i = 1;
 | 
	
		
			
				|  |  |             if (null!=totallist&&totallist.size()>0){
 | 
	
		
			
				|  |  |                 for (int n=0;n<totallist.size();n++) {
 | 
	
		
			
				|  |  |                     JSONObject object = totallist.getJSONObject(i);
 | 
	
		
			
				|  |  |                     Map<String,Object> object = totallist.get(n);
 | 
	
		
			
				|  |  |                     addCell(ws, i, 0, object.get("doctorName").toString(), "");
 | 
	
		
			
				|  |  |                     addCell(ws, i, 1, null==object.get("dept")?"":object.get("dept").toString(),"");
 | 
	
		
			
				|  |  |                     addCell(ws, i, 1, null==object.get("out")?"":object.get("out").toString(),"");
 | 
	
		
			
				|  |  |                     addCell(ws, i, 1, null==object.get("pre")?"":object.get("pre").toString(),"");
 | 
	
		
			
				|  |  |                     addCell(ws, i, 1, null==object.get("sf")?"":object.get("sf").toString(),"");
 | 
	
		
			
				|  |  |                     addCell(ws, i, 1, null==object.get("deptName")?"":object.get("deptName").toString(),"");
 | 
	
		
			
				|  |  |                     addCell(ws, i, 2, null==object.get("pickNum")?"":object.get("pickNum").toString(),"");
 | 
	
		
			
				|  |  |                     addCell(ws, i, 3, null==object.get("preNum")?"":object.get("preNum").toString(),"");
 | 
	
		
			
				|  |  |                     addCell(ws, i, 4, null==object.get("wlNum")?"":object.get("wlNum").toString(),"");
 | 
	
		
			
				|  |  |                     i++;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             wwb.write();
 | 
	
		
			
				|  |  |             wwb.close();
 | 
	
		
			
				|  |  |         } catch (IOException e) {
 | 
	
	
		
			
				|  | @ -140,5 +186,149 @@ public class PayInfoNoticeService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         ws.addCell(label);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> dealSqlQuery(String beginTime,String endTime){
 | 
	
		
			
				|  |  |         //发起问诊量
 | 
	
		
			
				|  |  |         String sqlOutPatient="SELECT\n" +
 | 
	
		
			
				|  |  |                 "\tt.doctor as \"doctor\",\n" +
 | 
	
		
			
				|  |  |                 "\tt.doctor_name as \"doctorName\",\n" +
 | 
	
		
			
				|  |  |                 "\tt.dept_name as \"deptName\",\n" +
 | 
	
		
			
				|  |  |                 "\tcount(*) as \"total\" \n" +
 | 
	
		
			
				|  |  |                 "FROM\n" +
 | 
	
		
			
				|  |  |                 "\t wlyy_outpatient t \n" +
 | 
	
		
			
				|  |  |                 "WHERE 1=1 and t.doctor is not null\n" ;
 | 
	
		
			
				|  |  |         //接诊量
 | 
	
		
			
				|  |  |         String sqlDoctorOut = "SELECT\n" +
 | 
	
		
			
				|  |  |                 "\tt.doctor as \"doctor\",\n" +
 | 
	
		
			
				|  |  |                 "\tt.doctor_name as \"doctorName\",\n" +
 | 
	
		
			
				|  |  |                 "\tt.dept_name as \"deptName\",\n" +
 | 
	
		
			
				|  |  |                 "\tcount(*) as \"total\" \n" +
 | 
	
		
			
				|  |  |                 "FROM\n" +
 | 
	
		
			
				|  |  |                 "\t wlyy_outpatient t \n" +
 | 
	
		
			
				|  |  |                 "WHERE 1=1 and t.doctor is not null\n";
 | 
	
		
			
				|  |  |         //开具处方量
 | 
	
		
			
				|  |  |         String sqlPrescription = "SELECT\n" +
 | 
	
		
			
				|  |  |                 "\tt.doctor as \"doctor\",\n" +
 | 
	
		
			
				|  |  |                 "\tt.doctor_name as \"doctorName\",\n" +
 | 
	
		
			
				|  |  |                 "\tt.dept_name as \"deptName\",\n" +
 | 
	
		
			
				|  |  |                 "\tcount(*) as \"total\" \n" +
 | 
	
		
			
				|  |  |                 "FROM\n" +
 | 
	
		
			
				|  |  |                 "\t wlyy_prescription t \n" +
 | 
	
		
			
				|  |  |                 "WHERE 1=1 and t.doctor is not null\n" ;
 | 
	
		
			
				|  |  |         //物流量
 | 
	
		
			
				|  |  |         String sqlWL = "SELECT\n" +
 | 
	
		
			
				|  |  |                 "\to.doctor as \"doctor\",\n" +
 | 
	
		
			
				|  |  |                 " o.doctor_name as \"doctorName\",\n" +
 | 
	
		
			
				|  |  |                 " o.dept_name as \"deptName\",\n" +
 | 
	
		
			
				|  |  |                 " count(*) as \"total\"" +
 | 
	
		
			
				|  |  |                 "FROM\n" +
 | 
	
		
			
				|  |  |                 " base.wlyy_prescription_expressage t\n" +
 | 
	
		
			
				|  |  |                 "LEFT JOIN base.wlyy_prescription b ON b.outpatient_id = t.outpatient_id\n" +
 | 
	
		
			
				|  |  |                 "LEFT JOIN base.wlyy_outpatient o ON o.id= b.outpatient_id\n" +
 | 
	
		
			
				|  |  |                 "WHERE 1=1 and o.doctor is not null\n" ;
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(beginTime)){
 | 
	
		
			
				|  |  |             wxId="xx";
 | 
	
		
			
				|  |  |             if("xm_ykyy_wx".equals(wxId)){
 | 
	
		
			
				|  |  |                 if (flag){
 | 
	
		
			
				|  |  |                     sqlOutPatient+=" and t.create_time > '" + beginTime + " 00:00:00' ";
 | 
	
		
			
				|  |  |                     sqlDoctorOut+=" and t.create_time > '" + beginTime + " 00:00:00' ";
 | 
	
		
			
				|  |  |                     sqlPrescription+=" and t.create_time > '" + beginTime + " 00:00:00' ";
 | 
	
		
			
				|  |  |                     sqlWL+=" and t.create_time > '" + beginTime + " 00:00:00' ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     sqlOutPatient+=" and t.create_time > to_date('" + beginTime + " 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
 | 
	
		
			
				|  |  |                     sqlDoctorOut+=" and t.create_time > to_date('" + beginTime + " 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
 | 
	
		
			
				|  |  |                     sqlPrescription+=" and t.create_time > to_date('" + beginTime + " 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
 | 
	
		
			
				|  |  |                     sqlWL+=" and t.create_time > to_date('" + beginTime + " 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 sqlOutPatient+=" and t.create_time > '" + beginTime + " 00:00:00'";
 | 
	
		
			
				|  |  |                 sqlDoctorOut+=" and t.create_time > '" + beginTime + " 00:00:00'";
 | 
	
		
			
				|  |  |                 sqlPrescription+=" and t.create_time > '" + beginTime + " 00:00:00'";
 | 
	
		
			
				|  |  |                 sqlWL+=" and t.create_time > '" + beginTime + " 00:00:00'";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(endTime)){
 | 
	
		
			
				|  |  |             if("xm_ykyy_wx".equals(wxId)){
 | 
	
		
			
				|  |  |                 if (flag){
 | 
	
		
			
				|  |  |                     sqlOutPatient+="  and t.create_time<'" + endTime + " 23:59:59'";
 | 
	
		
			
				|  |  |                     sqlDoctorOut+="  and t.create_time<'" + endTime + " 23:59:59'";
 | 
	
		
			
				|  |  |                     sqlPrescription+="  and t.create_time<'" + endTime + " 23:59:59'";
 | 
	
		
			
				|  |  |                     sqlWL+="  and t.create_time<'" + endTime + " 23:59:59'";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     sqlOutPatient+="  and t.create_time< to_date('" + endTime + " 23:59:59','yyyy-mm-dd hh24:mi:ss')";
 | 
	
		
			
				|  |  |                     sqlDoctorOut+="  and t.create_time< to_date('" + endTime + " 23:59:59','yyyy-mm-dd hh24:mi:ss')";
 | 
	
		
			
				|  |  |                     sqlPrescription+="  and t.create_time< to_date('" + endTime + " 23:59:59','yyyy-mm-dd hh24:mi:ss')";
 | 
	
		
			
				|  |  |                     sqlWL+="  and t.create_time< to_date('" + endTime + " 23:59:59','yyyy-mm-dd hh24:mi:ss')";
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 sqlOutPatient+="  and t.create_time<'" + endTime + " 23:59:59'";
 | 
	
		
			
				|  |  |                 sqlDoctorOut+="  and t.create_time<'" + endTime + " 23:59:59'";
 | 
	
		
			
				|  |  |                 sqlPrescription+="  and t.create_time<'" + endTime + " 23:59:59'";
 | 
	
		
			
				|  |  |                 sqlWL+="  and t.create_time<'" + endTime + " 23:59:59'";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sqlOutPatient+="\tAND t.patient_name NOT IN ( '王志南', '游水连', '林志芳', '郑绩', '陈晓亮', '王培坤' ) \n" +
 | 
	
		
			
				|  |  |                 "\tAND t.STATUS IN ( 0,1,2,3 )\n" +
 | 
	
		
			
				|  |  |                 "\tGROUP BY t.doctor_name,\n" +
 | 
	
		
			
				|  |  |                 "\tt.dept_name,t.doctor";
 | 
	
		
			
				|  |  |         sqlDoctorOut+= "\tAND t.patient_name NOT IN ( '王志南', '游水连', '林志芳', '郑绩', '陈晓亮', '王培坤' ) \n" +
 | 
	
		
			
				|  |  |                 "\tAND t.STATUS IN ( 1, 2, 3 )\n" +
 | 
	
		
			
				|  |  |                 " and t.pay_status =1 "+
 | 
	
		
			
				|  |  |                 "\tGROUP BY t.doctor_name,\n" +
 | 
	
		
			
				|  |  |                 "\tt.dept_name ,t.doctor";
 | 
	
		
			
				|  |  |         sqlPrescription+="\tAND t.patient_name NOT IN ( '王志南', '游水连', '林志芳', '郑绩', '陈晓亮', '王培坤' ) \n" +
 | 
	
		
			
				|  |  |                 "\tGROUP BY t.doctor_name,\n" +
 | 
	
		
			
				|  |  |                 "\tt.dept_name,t.doctor";
 | 
	
		
			
				|  |  |         sqlWL+= "AND t. NAME NOT IN (\n" +
 | 
	
		
			
				|  |  |                 " '王志南',\n" +
 | 
	
		
			
				|  |  |                 " '游水连',\n" +
 | 
	
		
			
				|  |  |                 " '林志芳',\n" +
 | 
	
		
			
				|  |  |                 " '郑绩',\n" +
 | 
	
		
			
				|  |  |                 " '陈晓亮',\n" +
 | 
	
		
			
				|  |  |                 " '王培坤',\n" +
 | 
	
		
			
				|  |  |                 " '林'\n" +
 | 
	
		
			
				|  |  |                 ")\n" +
 | 
	
		
			
				|  |  |                 "AND t.oneself_pickup_flg = 0\n" +
 | 
	
		
			
				|  |  |                 "\n" +
 | 
	
		
			
				|  |  |                 "AND b.`status`IN(20,32,100)\n" +
 | 
	
		
			
				|  |  |                 "AND b.drug_fee !=0\n" +
 | 
	
		
			
				|  |  |                 "AND b.real_order IS not NULL"+
 | 
	
		
			
				|  |  |                 "\tGROUP BY o.doctor_name,\n" +
 | 
	
		
			
				|  |  |                 "\to.dept_name,o.doctor";;
 | 
	
		
			
				|  |  |         List<Map<String,Object>> result = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<Map<String,Object>> outPatient=hibenateUtils.createSQLQuery(sqlOutPatient);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> docPickup=hibenateUtils.createSQLQuery(sqlDoctorOut);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> prescription=hibenateUtils.createSQLQuery(sqlPrescription);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> wl=hibenateUtils.createSQLQuery(sqlWL);
 | 
	
		
			
				|  |  |         if(null!=outPatient&&outPatient.size()>0){
 | 
	
		
			
				|  |  |             for (Map<String,Object> map:outPatient){
 | 
	
		
			
				|  |  |                 if (docPickup!=null&&docPickup.size()>0){
 | 
	
		
			
				|  |  |                     for (Map<String,Object> pickMap:docPickup){
 | 
	
		
			
				|  |  |                         if (pickMap.get("doctor").toString().equalsIgnoreCase(map.get("doctor").toString())){
 | 
	
		
			
				|  |  |                             map.put("pickNum",null==pickMap.get("total")?"":pickMap.get("total").toString());
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (prescription!=null&&prescription.size()>0){
 | 
	
		
			
				|  |  |                     for (Map<String,Object> pre:prescription){
 | 
	
		
			
				|  |  |                         if (pre.get("doctor").toString().equalsIgnoreCase(map.get("doctor").toString())){
 | 
	
		
			
				|  |  |                             map.put("preNum",null==pre.get("total")?"":pre.get("total").toString());
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (wl!=null&&wl.size()>0){
 | 
	
		
			
				|  |  |                     for (Map<String,Object> wMap:wl){
 | 
	
		
			
				|  |  |                         if (wMap.get("doctor").toString().equalsIgnoreCase(map.get("doctor").toString())){
 | 
	
		
			
				|  |  |                             map.put("wlNum",null==wMap.get("total")?"":wMap.get("total").toString());
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 result.add(map);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |      return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 | 
	
		
			
				|  |  | 
 |