| 
					
				 | 
			
			
				@ -7,7 +7,9 @@ import com.yihu.wlyy.entity.patient.prescription.PrescriptionInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.PrescriptionDispensaryCodeDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.PrescriptionInfoDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.BaseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.QrcodeService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.HttpUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.QrcodeUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.SystemConf; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.fastdfs.FastDFSUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -22,8 +24,7 @@ import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.UnsupportedEncodingException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.HttpURLConnection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.MalformedURLException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.URL; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -66,8 +67,9 @@ public class PrescriptionDispensaryCodeService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                case 4:timeLimit = 7*24*60*60*31*12;break;//近一年 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Object> params = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String precriptionSql = "select p2.*,p1.diagnosis as diagnosis ,p3.address as address from wlyy_prescription_dispensary_code p2 left join  wlyy_prescription p1 on p2.prescription_code=p1.code LEFT JOIN wlyy_prescription_expressage p3 on p1.code=p3.prescription_code where p1.patient=? and p2.type=?  and p2.is_Use=0 "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Object> params = new ArrayList<>();//p2.*,p1.diagnosis as diagnosis ,p3.address as address 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String precriptionSql = "select p1.status , p1.diagnosis ,p3.address as address,p2.prescription_code as prescriptionCode,p2.code as dispensaryCode,p2.type  from wlyy_prescription_dispensary_code p2 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " left join  wlyy_prescription p1 on p2.prescription_code=p1.code LEFT JOIN wlyy_prescription_expressage p3 on p1.code=p3.prescription_code where p1.patient=? and p2.type=?  and p2.is_Use=0 "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        params.add(patientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        params.add(type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(status!=null){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -84,8 +86,8 @@ public class PrescriptionDispensaryCodeService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> result = jdbcTemplate.queryForList(precriptionSql,params.toArray()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> result2 = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Map<String, Object> m:result) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<PrescriptionInfo> list = prescriptionInfoDao.findByPrescriptionCode(m.get("prescription_code").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            m.put("data",list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<PrescriptionInfo> list = prescriptionInfoDao.findByPrescriptionCode(m.get("prescriptionCode").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            m.put("prescriptionInfo",list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result2.add(m); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray array = new JSONArray(result2); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -110,7 +112,7 @@ public class PrescriptionDispensaryCodeService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //生成居民端取药码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public PrescriptionDispensaryCode savePatientQRCode(String token,String prescriptionCode){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public PrescriptionDispensaryCode savePatientQRCode(String token,String prescriptionCode) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //获取年月日8位数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Calendar cal  = Calendar.getInstance(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String year = String.valueOf(cal.get(Calendar.YEAR)); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -129,8 +131,9 @@ public class PrescriptionDispensaryCodeService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 生成二维码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ObjectNode imgNode = makeQrcodeFromWeiXin(token,code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //Prescription类  取药类型:1 自取 2快递配送 3健管师配送 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        InputStream ipt = QrcodeUtil.createQrcode(code,300,"png"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ObjectNode imgNode = FastDFSUtil.upload(ipt,"png","QRCode_"+System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        Prescription类  取药类型:1 自取 2快递配送 3健管师配送 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String fileUrl = fastdfs_file_url + imgNode.get("groupName").toString().replaceAll("\"","") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"",""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -142,12 +145,11 @@ public class PrescriptionDispensaryCodeService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDispensaryCode.setPrescriptionCode(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDispensaryCode.setType(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return prescriptionDispensaryCodeDao.save(prescriptionDispensaryCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //生成配送员(健管师)取药码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //生成配送员(健管师)(2、取药码  2、配送码) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public PrescriptionDispensaryCode saveDoctorQRCode(String code,String token,String prescriptionCode){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public PrescriptionDispensaryCode saveQRCode(String code,String token,String prescriptionCode,Integer type) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String jgsCode= ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        synchronized (obj2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            boolean bl = true; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -159,49 +161,23 @@ public class PrescriptionDispensaryCodeService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //String jgsID= "";//配送员用户ID后4位 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        String jgsCode = code+"1234";//code+jgsID.substring(jgsID.length()-4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ObjectNode imgNode2 = makeQrcodeFromWeiXin(token,jgsCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String fileUrl = fastdfs_file_url + imgNode2.get("groupName").toString().replaceAll("\"","") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                + "/" + imgNode2.get("remoteFileName").toString().replaceAll("\"",""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 生成二维码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        InputStream ipt = QrcodeUtil.createQrcode(code,300,"png"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ObjectNode imgNode = FastDFSUtil.upload(ipt,"png","QRCode_"+System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        Prescription类  取药类型:1 自取 2快递配送 3健管师配送 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String fileUrl = fastdfs_file_url + imgNode.get("groupName").toString().replaceAll("\"","") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"",""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //新增配送员处方取码记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PrescriptionDispensaryCode prescriptionDispensaryCode = new PrescriptionDispensaryCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDispensaryCode.setCode(jgsCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDispensaryCode.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDispensaryCode.setImgUrl(fileUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDispensaryCode.setPrescriptionCode(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDispensaryCode.setType(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDispensaryCode.setType(type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return prescriptionDispensaryCodeDao.save(prescriptionDispensaryCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //在微信端生成二维码,并上传FastFDS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjectNode makeQrcodeFromWeiXin(String token,String content){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String token_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + token; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String params = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"" + content + "\"}}}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String result = httpUtil.sendPost(token_url, params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!StringUtils.isEmpty(result)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject json = new JSONObject(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 下载二维码图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            URL urlGet = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                urlGet = new URL("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        + URLEncoder.encode(json.get("ticket").toString(), "UTF-8")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                HttpURLConnection connection = (HttpURLConnection) urlGet.openConnection(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                connection.connect(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ObjectNode imgNode = FastDFSUtil.upload(connection.getInputStream(),"png","QRCode_"+System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return imgNode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (MalformedURLException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (UnsupportedEncodingException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //随机生成匹配数字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public  String randomString(String base, int length) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -213,4 +189,13 @@ public class PrescriptionDispensaryCodeService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return sb.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String, Object> getQrcode(String dispensaryCode ,String patientCode ,Integer type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select p2.code as dispensaryCode,p2.img_url,p3.hospital_name as hospitalName  from wlyy_prescription_dispensary_code p2 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " left join  wlyy_prescription p1 on p2.prescription_code=p1.code LEFT JOIN wlyy_prescription_expressage p3 on p1.code=p3.prescription_code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where p2.prescription_code=? and p1.patient=? and p2.type=?  and p2.is_Use=0 "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, Object> result = jdbcTemplate.queryForMap(sql,dispensaryCode,patientCode,type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |