|
@ -14,10 +14,13 @@ import com.yihu.jw.entity.base.im.ConsultTeamDo;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
|
|
|
import com.yihu.jw.entity.care.doorCoach.*;
|
|
|
import com.yihu.jw.entity.care.lifeCare.LifeCareOrderDO;
|
|
|
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
|
|
|
import com.yihu.jw.entity.order.BusinessOrderDO;
|
|
|
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
|
|
|
import com.yihu.jw.im.dao.ConsultDao;
|
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
|
import com.yihu.jw.order.dao.BusinessOrderDao;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
import com.yihu.jw.util.common.IdCardUtil;
|
|
@ -97,6 +100,8 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
private BaseServiceNewsService serviceNewsService;
|
|
|
@Autowired
|
|
|
private PayService payService;
|
|
|
@Autowired
|
|
|
private BusinessOrderDao businessOrderDao;
|
|
|
|
|
|
/**
|
|
|
* 创建上门辅导服务工单
|
|
@ -137,7 +142,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
orderDO.setCreateUser(orderDO.getProxyPatient());
|
|
|
orderDO.setCreateUserName(orderDO.getProxyPatientName());
|
|
|
orderDO.setOrderInfo("0");
|
|
|
orderDO.setStatus(1);
|
|
|
orderDO.setStatus(0);//待付款
|
|
|
// orderDO.setConclusionStatus(1);
|
|
|
|
|
|
if(StringUtils.isEmpty(orderDO.getPatient())){
|
|
@ -273,7 +278,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
orderDO.setUpdateUser(orderDO.getProxyPatient());
|
|
|
orderDO.setUpdateUserName(orderDO.getProxyPatientName());
|
|
|
}
|
|
|
orderDO.setStatus(2);
|
|
|
orderDO.setStatus(0);//待付款
|
|
|
orderDO.setType(3);
|
|
|
orderDO.setDispatcherResponseTime(new Date());
|
|
|
this.save(orderDO);
|
|
@ -295,11 +300,21 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
//支付完成后开始上门辅导订单
|
|
|
public JSONObject payOrderAfter(String orderId) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(orderId);
|
|
|
if (businessOrderDO==null){
|
|
|
String failMsg = "未查询到该订单";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
BaseDoorCoachOrderDO orderDO= baseDoorCoachOrderDao.findOne(orderId);
|
|
|
if (orderDO!=null){
|
|
|
serviceNewsService.addServiceNews(orderDO.getPatientName(),orderDO.getPatient(),"1",null);
|
|
|
if (orderDO.getPayWay()!=null){
|
|
|
if (orderDO.getType()==3){//医生代预约
|
|
|
if (businessOrderDO.getStatus() == 0){
|
|
|
orderDO.setPayWay(1);
|
|
|
orderDO.setPayTime(new Date());
|
|
|
if (orderDO.getType()== 3){//医生代预约
|
|
|
orderDO.setStatus(2);//待接单
|
|
|
this.save(orderDO);
|
|
|
// 给服务医生发接单消息
|
|
|
this.createMessage("服务工单待接单","707",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(),orderDO.getDoctor(),orderDO.getDoctorName(), null,"您有新的服务工单,请前往处理");
|
|
|
//发送智能助手消息
|
|
@ -335,6 +350,8 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
|
|
|
sendOrderToDoctor(orderDO.getId(),null,"system","系统",transDoctor.getId(),transDoctor.getName(),transDoctor.getJobTitleName());
|
|
|
}else {
|
|
|
orderDO.setStatus(1);//待派单
|
|
|
this.save(orderDO);
|
|
|
JSONObject dispatcherJson = queryDispatcherInfoByPatient(orderDO.getHospital());
|
|
|
if (dispatcherJson.getInteger("resultFlag")==1){
|
|
|
List<Map<String,Object>> dispatcherInfoList = (List<Map<String, Object>>) dispatcherJson.get(ResponseContant.resultMsg);
|
|
@ -354,7 +371,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
}
|
|
|
}else {
|
|
|
String failMsg = "订单未支付";
|
|
|
String failMsg = "订单已支付或已取消";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
}
|
|
@ -367,6 +384,25 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//退款后回调
|
|
|
public JSONObject refundOrderAfter(String orderId) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
BaseDoorCoachOrderDO orderDO= baseDoorCoachOrderDao.findOne(orderId);
|
|
|
if (orderDO == null){
|
|
|
String failMsg = "工单不存在";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
orderDO.setStatus(-1);
|
|
|
orderDO.setPayWay(-1);
|
|
|
this.save(orderDO);
|
|
|
String failMsg = "success";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据接单医生code获取最近一次服务orderId
|
|
|
* @return
|
|
@ -806,57 +842,77 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
if(orderDO.getStatus() > BaseDoorCoachOrderDO.Status.waitForServe.getType()){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "只有医生服务前的工单才可取消:," + orderId;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
//触发退款流程,退款失败时无法取消工单
|
|
|
try {
|
|
|
|
|
|
}catch (Exception e){
|
|
|
String failMsg = "退款失败,无法取消工单:," + orderId;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
orderDO.setCancelType(type);
|
|
|
orderDO.setCancelTime(new Date());
|
|
|
orderDO.setCancelReason(reason);
|
|
|
if(!StringUtils.isEmpty(dispatcher)){
|
|
|
orderDO.setDoctor(dispatcher);
|
|
|
orderDO.setDoctorName(dispatcherName);
|
|
|
orderDO.setDispatcher(dispatcher);
|
|
|
orderDO.setDispatcherName(dispatcherName);
|
|
|
}
|
|
|
//如果是调度员取消,推送IM取消工单json消息,
|
|
|
if (StringUtils.isNotBlank(dispatcher)){
|
|
|
if (!consultTeamService.finishConsult(orderDO.getId(),orderDO.getPatient(),dispatcher,2)){
|
|
|
String failMsg = "咨询结束失败 无法取消工单";
|
|
|
if(type==2){//患者仅未支付的订单能取消
|
|
|
if(orderDO.getStatus() != BaseDoorCoachOrderDO.Status.waitForPay.getType()){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
String failMsg = "无法取消工单,已支付的工单需要到我的订单中进行取消," + orderId;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
if (!consultTeamService.finishConsult(orderDO.getId(),orderDO.getPatient(),orderDO.getPatient(),1)){
|
|
|
String failMsg = "咨询结束失败 无法取消工单";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
}else{//调度员拒单,此时工单已支付抵达调度员
|
|
|
//触发退款流程,退款失败时无法取消工单
|
|
|
try {
|
|
|
if (orderDO.getStatus() > BaseDoorCoachOrderDO.Status.waitForPay.getType()&&1==orderDO.getPayWay()){
|
|
|
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(dispatcher)){
|
|
|
orderDO.setDoctor(dispatcher);
|
|
|
orderDO.setDoctorName(dispatcherName);
|
|
|
orderDO.setDispatcher(dispatcher);
|
|
|
orderDO.setDispatcherName(dispatcherName);
|
|
|
}
|
|
|
//如果是调度员取消,推送IM取消工单json消息,
|
|
|
if (StringUtils.isNotBlank(dispatcher)){
|
|
|
if (!consultTeamService.finishConsult(orderDO.getId(),orderDO.getPatient(),dispatcher,2)){
|
|
|
String failMsg = "咨询结束失败 无法取消工单";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
if (!consultTeamService.finishConsult(orderDO.getId(),orderDO.getPatient(),orderDO.getPatient(),1)){
|
|
|
String failMsg = "咨询结束失败 无法取消工单";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(type == BaseDoorCoachOrderDO.CancelType.dispatcher.getType()){
|
|
|
messageUtil.updateDoorCoachMessage(orderDO,new String[]{"702","703","730"},"732",dispatcher,dispatcher);
|
|
|
}
|
|
|
else if(type == BaseDoorCoachOrderDO.CancelType.patient.getType()){ //居民取消,消息列表也应该不显示
|
|
|
messageUtil.updateDoorCoachMessage(orderDO,new String[]{"702","703","730"},"patientCancel",dispatcher,dispatcher);
|
|
|
}
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
// 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
|
|
|
String first = "key1您好,您的上门预约订单已退回,点击查看原因";
|
|
|
BasePatientDO patient = patientDao.findById(orderDO.getPatient());
|
|
|
first = first.replace("key1", null != patient.getName() ? patient.getName() : "");
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id", orderDO.getId());
|
|
|
List<BasePatientWechatDo> basePatientWechatDos = basePatientWechatDao.findByWechatIdAndPatientId(wxId,patient.getId());
|
|
|
if (basePatientWechatDos.size()>0){
|
|
|
String openId = basePatientWechatDos.get(0).getOpenid();
|
|
|
messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyqx",openId,first,null,null,2,json, DateUtil.dateToChineseDate(new Date()),"上门预约已取消","已取消");
|
|
|
|
|
|
}
|
|
|
|
|
|
}catch (Exception e){
|
|
|
String failMsg = "退款失败,无法取消工单:," + orderId;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
orderDO.setCancelType(type);
|
|
|
orderDO.setCancelTime(new Date());
|
|
|
orderDO.setCancelReason(reason);
|
|
|
|
|
|
|
|
|
orderDO.setStatus(BaseDoorCoachOrderDO.Status.cancel.getType());
|
|
|
this.save(orderDO);
|
|
|
if(type == BaseDoorCoachOrderDO.CancelType.dispatcher.getType()){
|
|
|
messageUtil.updateDoorCoachMessage(orderDO,new String[]{"702","703","730"},"732",dispatcher,dispatcher);
|
|
|
}
|
|
|
else if(type == BaseDoorCoachOrderDO.CancelType.patient.getType()){ //居民取消,消息列表也应该不显示
|
|
|
messageUtil.updateDoorCoachMessage(orderDO,new String[]{"702","703","730"},"patientCancel",dispatcher,dispatcher);
|
|
|
}
|
|
|
|
|
|
//保存取消记录
|
|
|
BaseDoorCoachCancelLogDO cancelLogDO = new BaseDoorCoachCancelLogDO();
|
|
@ -877,19 +933,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
JSONObject confirmInfoJson = new JSONObject();
|
|
|
confirmInfoJson.put("confirmInfo",confirmInfo);
|
|
|
this.orderWithConfirmLogAdd(result,confirmInfo,orderId);
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
// 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
|
|
|
String first = "key1您好,您的上门预约订单已退回,点击查看原因";
|
|
|
BasePatientDO patient = patientDao.findById(orderDO.getPatient());
|
|
|
first = first.replace("key1", null != patient.getName() ? patient.getName() : "");
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id", orderDO.getId());
|
|
|
List<BasePatientWechatDo> basePatientWechatDos = basePatientWechatDao.findByWechatIdAndPatientId(wxId,patient.getId());
|
|
|
if (basePatientWechatDos.size()>0){
|
|
|
String openId = basePatientWechatDos.get(0).getOpenid();
|
|
|
messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyqx",openId,first,null,null,2,json, DateUtil.dateToChineseDate(new Date()),"上门预约已取消","已取消");
|
|
|
|
|
|
}
|
|
|
|
|
|
// 工单状态变更记录
|
|
|
BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
|
|
@ -1131,7 +1175,8 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
order.setTotalFee(totalFee);
|
|
|
this.save(order);
|
|
|
return false;
|
|
|
}
|
|
|
|