| 
					
				 | 
			
			
				@ -2,20 +2,46 @@ package com.yihu.wlyy.service.app.prescription; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.message.Message; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.Patient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.Prescription; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.message.MessageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.patient.PatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.PrescriptionDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.PrescriptionExpressageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.BaseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.task.PushMsgTask; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.MessageType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by chenweida on 2017/7/27. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class PrescriptionService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static Logger logger = LoggerFactory.getLogger(PrescriptionService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionDao prescriptionDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private MessageDao messageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PushMsgTask pushMsgTask; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionExpressageDao prescriptionExpressageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionNoticesService prescriptionNoticesService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientDao patientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     *  获取处方信息 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -31,11 +57,45 @@ public class PrescriptionService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void dispensingComplete(String code){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info("配药完成,提示居民或健管师取药:"+code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Prescription prescription = prescriptionDao.findByCode(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(prescription.getStatus().equals(PrescriptionLog.PrescriptionLogStatus.wait_expressage.getValue())){//等待领药 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(prescription.getDispensaryType()==1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //自取 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Patient patient = patientDao.findByCode(prescription.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionNoticesService.sendMessages(patient.getCode(), patient.getName(), null, null, 2, 0, ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logger.info("微信模板发送失败,续方code"+code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else if(prescription.getDispensaryType()==3){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //健管师配送 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                PrescriptionExpressage expressage = prescriptionExpressageDao.findByPrescriptionCode(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(StringUtils.isEmpty(expressage.getExpressageCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String content = "您有一条新的续方订单待取药!"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Message message = new Message(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setRead(1);//设置未读 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setOver("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setReceiver(expressage.getExpressageCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setSender("system"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setCode(getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setSenderName("系统"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setTitle("居民"+prescription.getPatientName()+"的续方订单待取药"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setContent("您有一条新的续方订单待取药!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setType(7);//续方订单待取药 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setReadonly(1);//是否只读消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setRelationCode(prescription.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    message.setPrescriptionStatus("0");//待取药 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    messageDao.save(message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    pushMsgTask.put(expressage.getExpressageCode(), MessageType.MESSAGE_TYPE_PRESCRIPTION_WAIT_TAKE_DRUG.D_P_WRD.name(), MessageType.MESSAGE_TYPE_PRESCRIPTION_WAIT_TAKE_DRUG.续方消息.name(), content, prescription.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info("配药完成,提示居民或健管师取药:"+code+",status="+prescription.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 |