|  | @ -4,11 +4,19 @@ import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.prescription.Prescription;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.prescription.PrescriptionReviewed;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.message.MessageDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.prescription.PrescriptionDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.prescription.PrescriptionReviewedDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.ImUtill;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * 线下调整处方
 | 
	
	
		
			
				|  | @ -23,16 +31,28 @@ public class PrescriptionAdjustService extends BaseService {
 | 
	
		
			
				|  |  |     private PrescriptionDao prescriptionDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionLogService prescriptionLogService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionService prescriptionService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private MessageDao messageDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionReviewedDao prescriptionReviewedDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionInfoService prescriptionInfoService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ImUtill imUtill;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 线下调整处方
 | 
	
		
			
				|  |  |      * @param code
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void adjustPrescription(String code){
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public JSONObject adjustPrescription(String code){
 | 
	
		
			
				|  |  |         JSONObject re = new JSONObject();
 | 
	
		
			
				|  |  |         Prescription prescription = prescriptionDao.findByCode(code);
 | 
	
		
			
				|  |  |         if(prescription.getStatus()== PrescriptionLog.PrescriptionLogStatus.revieweding.getValue()){
 | 
	
		
			
				|  |  |         if(prescription.getStatus()== PrescriptionLog.PrescriptionLogStatus.revieweding.getValue()||
 | 
	
		
			
				|  |  |                 prescription.getStatus()== PrescriptionLog.PrescriptionLogStatus.change_error.getValue()){
 | 
	
		
			
				|  |  |             //待审核状态才可以线下调整处方
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String response = jwPrescriptionService.saveRecipe(code,prescription.getJwGisterTypeCode(),prescription.getJwDeptCode());
 | 
	
		
			
				|  |  |             JSONObject json = JSONObject.parseObject(response);
 | 
	
		
			
				|  |  |             if(json.getInteger("status")==200){
 | 
	
	
		
			
				|  | @ -49,27 +69,107 @@ public class PrescriptionAdjustService extends BaseService {
 | 
	
		
			
				|  |  |                         prescription.setRecipeNo(recipeNo);
 | 
	
		
			
				|  |  |                         prescriptionDao.save(prescription);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         //发送Im消息
 | 
	
		
			
				|  |  |                         JSONObject content = new JSONObject();
 | 
	
		
			
				|  |  |                         content.put("title", "我已经审核您" + DateUtil.dateToStr(prescription.getCreateTime(), "yyyy-MM-dd") + "发起的续方申请");
 | 
	
		
			
				|  |  |                         content.put("result", "审核通过");
 | 
	
		
			
				|  |  |                         content.put("reason", "");
 | 
	
		
			
				|  |  |                         content.put("url", "");
 | 
	
		
			
				|  |  |                         imUtill.sendTopicIM(prescription.getDoctor(), prescription.getDoctorName(), prescription.getConsult(), "15", content.toString(), null);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         //添加日志
 | 
	
		
			
				|  |  |                         prescriptionLogService.addLog(prescription,PrescriptionLog.PrescriptionLogType.zy.getValue(),1,2);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         re.put("status",200);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         //请求失败
 | 
	
		
			
				|  |  |                         prescriptionLogService.addLog(prescription,PrescriptionLog.PrescriptionLogType.zy.getValue(),0,2);
 | 
	
		
			
				|  |  |                         JSONArray byRefParaData = data.getJSONArray("byRefParaData");
 | 
	
		
			
				|  |  |                         re.put("status",-1);
 | 
	
		
			
				|  |  |                         re.put("msg",byRefParaData.getJSONObject(0).getString("errorMsg"));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     //调整请求失败
 | 
	
		
			
				|  |  |                     prescriptionLogService.addLog(prescription,PrescriptionLog.PrescriptionLogType.zy.getValue(),0,2);
 | 
	
		
			
				|  |  |                     re.put("status",-1);
 | 
	
		
			
				|  |  |                     re.put("msg",data.getString("MESSAGE"));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 //请求报错
 | 
	
		
			
				|  |  |                 prescriptionLogService.addLog(prescription,PrescriptionLog.PrescriptionLogType.zy.getValue(),0,2);
 | 
	
		
			
				|  |  |                 re.put("status",-1);
 | 
	
		
			
				|  |  |                 re.put("msg","请求调整失败");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             re.put("status",-1);
 | 
	
		
			
				|  |  |             re.put("msg","只有待审核和调整失败的续方可以转线下调整");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return  re;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 上传ca认证信息
 | 
	
		
			
				|  |  |      * @param code
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject uploadCaDigital(String code){
 | 
	
		
			
				|  |  |         JSONObject re = new JSONObject();
 | 
	
		
			
				|  |  |         Prescription prescription = prescriptionDao.findByCode(code);
 | 
	
		
			
				|  |  |         if(prescription.getStatus()==PrescriptionLog.PrescriptionLogStatus.change_success.getValue()){
 | 
	
		
			
				|  |  |             String response = jwPrescriptionService.affirmCARecipe(code);
 | 
	
		
			
				|  |  |             JSONObject json = JSONObject.parseObject(response);
 | 
	
		
			
				|  |  |             if(json.getInteger("status")==200){
 | 
	
		
			
				|  |  |                 JSONObject data = json.getJSONObject("data");
 | 
	
		
			
				|  |  |                 String zyCode = data.getString("CODE");
 | 
	
		
			
				|  |  |                 if("1".equals(zyCode)){
 | 
	
		
			
				|  |  |                     JSONArray returnData = data.getJSONArray("returnData");
 | 
	
		
			
				|  |  |                     if(returnData.size()>0){
 | 
	
		
			
				|  |  |                         JSONObject pre = returnData.getJSONArray(0).getJSONObject(0);
 | 
	
		
			
				|  |  |                         //认证成功-审核完成
 | 
	
		
			
				|  |  |                         prescription.setStatus(PrescriptionLog.PrescriptionLogStatus.wait_pay.getValue());
 | 
	
		
			
				|  |  |                         //设置审核通过
 | 
	
		
			
				|  |  |                         PrescriptionReviewed reviewed = prescriptionReviewedDao.findByPrescriptionCode(code);
 | 
	
		
			
				|  |  |                         reviewed.setStatus(1);
 | 
	
		
			
				|  |  |                         reviewed.setReviewedTime(new Date());
 | 
	
		
			
				|  |  |                         prescriptionDao.save(prescription);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         //审核通过模板消息
 | 
	
		
			
				|  |  |                         prescriptionInfoService.sendRMess(prescription.getCode(), 1);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |                         //修改系统的续方消息的审核状态
 | 
	
		
			
				|  |  |                         messageDao.updatePreScriptionMessage(prescription.getConsult(), "1", 6);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         //获取智业待结算接口,更新药品金额
 | 
	
		
			
				|  |  |                         prescriptionService.getPerscriptionInfoCostFromPayInfo(prescription.getCode());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         //添加日志
 | 
	
		
			
				|  |  |                         prescriptionLogService.addLog(prescription,PrescriptionLog.PrescriptionLogType.zy.getValue(),1,2);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         re.put("status",200);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         //请求失败
 | 
	
		
			
				|  |  |                         prescriptionLogService.addLog(prescription,PrescriptionLog.PrescriptionLogType.zy.getValue(),0,2);
 | 
	
		
			
				|  |  |                         JSONArray byRefParaData = data.getJSONArray("byRefParaData");
 | 
	
		
			
				|  |  |                         re.put("status",-1);
 | 
	
		
			
				|  |  |                         re.put("msg",byRefParaData.getJSONObject(0).getString("errorMsg"));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     //调整请求失败
 | 
	
		
			
				|  |  |                     prescriptionLogService.addLog(prescription,PrescriptionLog.PrescriptionLogType.zy.getValue(),0,2);
 | 
	
		
			
				|  |  |                     re.put("status",-1);
 | 
	
		
			
				|  |  |                     re.put("msg",data.getString("MESSAGE"));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 //请求报错
 | 
	
		
			
				|  |  |                 prescriptionLogService.addLog(prescription,PrescriptionLog.PrescriptionLogType.zy.getValue(),0,2);
 | 
	
		
			
				|  |  |                 re.put("status",-1);
 | 
	
		
			
				|  |  |                 re.put("msg","请求调整失败");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             re.put("status",-1);
 | 
	
		
			
				|  |  |             re.put("msg","只有调整成功的续方才可上传ca认证信息");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return  re;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |