|
@ -12,6 +12,7 @@ import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
|
|
|
import com.yihu.jw.entity.door.*;
|
|
|
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
|
|
|
import com.yihu.jw.entity.order.BusinessOrderDO;
|
|
|
import com.yihu.jw.hospital.HospitalDao;
|
|
|
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
|
|
|
import com.yihu.jw.hospital.module.consult.service.ConsultTeamService;
|
|
@ -20,6 +21,8 @@ import com.yihu.jw.hospital.task.PushMsgTask;
|
|
|
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
|
|
|
import com.yihu.jw.im.dao.ConsultDao;
|
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
|
import com.yihu.jw.order.BusinessOrderService;
|
|
|
import com.yihu.jw.order.dao.BusinessOrderDao;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.patient.service.BasePatientService;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
@ -79,6 +82,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
|
|
|
@Autowired
|
|
|
private HttpClientUtil httpClientUtil;
|
|
|
|
|
|
@Autowired
|
|
|
private BusinessOrderDao businessOrderDao;
|
|
|
@Autowired
|
|
|
private BusinessOrderService businessOrderService;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorServiceOrderDao wlyyDoorServiceOrderDao;
|
|
|
|
|
@ -405,10 +413,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
|
|
|
wlyyDoorFeeDetailDao.save(feeDetailDOList);
|
|
|
doorOrderItemDao.save(orderItemDOList);
|
|
|
|
|
|
// //更新总费用-这边没用到
|
|
|
// order.setTotalFee(totalFee);
|
|
|
// wlyyDoorServiceOrderDao.save(order);
|
|
|
|
|
|
//更新总费用
|
|
|
order.setTotalFee(totalFee);
|
|
|
wlyyDoorServiceOrderDao.save(order);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@ -659,11 +666,26 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
|
|
|
WlyyDoorServiceOrderDO orderDO = EntityUtils.jsonToEntity(
|
|
|
jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.class);
|
|
|
|
|
|
|
|
|
orderDO.setNumber(getRandomIntStr());
|
|
|
orderDO.setCreateTime(new Date());
|
|
|
orderDO.setCreateUser(orderDO.getProxyPatient());
|
|
|
orderDO.setCreateUserName(orderDO.getProxyPatientName());
|
|
|
orderDO.setOrderInfo("0");
|
|
|
orderDO.setOrderInfo("0");//工单详情 0-未推送 1-未确认 2-已确认
|
|
|
|
|
|
//服务后收费标识(1是0否)
|
|
|
if ("1".equals(orderDO.getFeeAfter())) {
|
|
|
//工单状态:-1-已取消,1-待(调度员)派单,2-待(医生)接单,3-待服务,4-待付款,5-待评价,6-已完成
|
|
|
if (StringUtils.isNotBlank(orderDO.getDoctor())) {
|
|
|
//有医生
|
|
|
orderDO.setStatus(2);//待接单(医生)
|
|
|
} else {
|
|
|
orderDO.setStatus(1);//待派单(调度员)
|
|
|
}
|
|
|
} else {
|
|
|
orderDO.setStatus(4);//待付款
|
|
|
}
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(orderDO.getPatient())) {
|
|
|
throw new Exception("当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient());
|
|
@ -683,10 +705,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
|
|
|
});
|
|
|
|
|
|
if (bool) {
|
|
|
String failMsg = "当前服务对象存在未完成的上门服务,请先完成该服务!";
|
|
|
String failMsg = "当前服务对象存在未完成或未付款的上门服务,请先完成该服务!";
|
|
|
throw new Exception(failMsg);
|
|
|
}
|
|
|
|
|
|
|
|
|
orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
|
|
|
orderDO.setCreateTime(new Date());
|
|
|
//判断创建上门服务类型,发起类型(1本人发起 2家人待预约 3医生代预约)
|
|
@ -695,78 +718,163 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
|
|
|
} else if (!orderDO.getProxyPatient().equals(orderDO.getPatient())) {
|
|
|
orderDO.setType(2);
|
|
|
}
|
|
|
orderDO.setServiceStatus("1");
|
|
|
orderDO.setServiceStatus("1");//服务类型 1-预约项目 2-即时项目
|
|
|
//保存服务订单
|
|
|
wlyyDoorServiceOrderDao.save(orderDO);
|
|
|
|
|
|
//创建咨询
|
|
|
JSONObject successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
|
|
|
ConsultTeamDo consultTeam = (ConsultTeamDo) successOrNot.get(ResponseContant.resultMsg);
|
|
|
|
|
|
//新增工单与服务项费用关联关系
|
|
|
if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO)) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//判断其是否有分配执行人。如果有不用走调度平台
|
|
|
if (StringUtils.isNotBlank(orderDO.getDoctor())) {
|
|
|
orderDO.setStatus(2);
|
|
|
//应该是康复模板的康复下转,才有签约--先注释
|
|
|
orderDO.setDoctor(orderDO.getDoctor());
|
|
|
orderDO.setDoctorName(orderDO.getDoctorName());
|
|
|
this.save(orderDO);
|
|
|
//新增工单医生关联关系
|
|
|
if (orderWithDoctorAdd(result, jsonObjectParam, orderDO)) {
|
|
|
return result;
|
|
|
}
|
|
|
// 给服务医生发接单消息--先注释
|
|
|
this.createMessage(orderDO.getId(), orderDO.getProxyPatient(), orderDO.getDoctor(), 407, "服务工单待接单", "您有新的服务工单,请前往处理");
|
|
|
//发送智能助手消息-微信消息先注释
|
|
|
sendWeixinMessage(4, orderDO.getDoctor(), orderDO.getPatient());
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, consultTeam);
|
|
|
return result;
|
|
|
}
|
|
|
//发起支付订单
|
|
|
result = submitDoorOrderAndSendMsg(orderDO, "5", jsonObjectParam);
|
|
|
|
|
|
//获取机构的调度员
|
|
|
List<Map<String, Object>> dispatcherList = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 5表示上门服务
|
|
|
* 情况
|
|
|
* 1.直接付款走流程
|
|
|
* 2.创建订单没付完款-待付款
|
|
|
* 3.还要超时订单
|
|
|
*/
|
|
|
private JSONObject submitDoorOrderAndSendMsg(WlyyDoorServiceOrderDO orderDO, String type, JSONObject jsonObjectParam) throws Exception {
|
|
|
boolean flag = true;
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
//有调度员
|
|
|
if (!dispatcherList.isEmpty()) {
|
|
|
for (Map<String, Object> map : dispatcherList) {
|
|
|
String dispatcher = map.get("code").toString();
|
|
|
// 派单消息-首页
|
|
|
this.createMessage(orderDO.getId(), "system", dispatcher, 402, "新增居民预约服务申请", orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
|
|
|
// 派单-实时工单消息 430 居民提交工单申请-- 张三提交了服务工单12345678申请
|
|
|
this.createMessage(orderDO.getId(), "system", dispatcher, 430, "居民提交工单申请", orderDO.getPatientName() + "提交了服务工单" + orderDO.getNumber() + "申请");
|
|
|
//创建订单信息
|
|
|
BasePatientDO pateint = patientDao.findById(orderDO.getPatient());
|
|
|
//查询是否存在订单信息
|
|
|
BusinessOrderDO businessOrderDO = businessOrderDao.findByOrderId(orderDO.getId());
|
|
|
if (businessOrderDO == null) {
|
|
|
businessOrderDO = new BusinessOrderDO();
|
|
|
businessOrderDO.setPatient(pateint.getId());
|
|
|
//支付账号
|
|
|
businessOrderDO.setYkOrderId(pateint.getMobile());
|
|
|
businessOrderDO.setPatientName(pateint.getName());
|
|
|
businessOrderDO.setOrderType(1);
|
|
|
businessOrderDO.setOrderCategory(type);
|
|
|
Date date = new Date();
|
|
|
Long lastPayTime = date.getTime() + 1000 * 60 * 30;//订单截至支付日期
|
|
|
businessOrderDO.setDescription("上门服务");
|
|
|
businessOrderDO.setRelationCode(orderDO.getId());//订单id
|
|
|
businessOrderDO.setRelationName("上门服务");
|
|
|
businessOrderDO.setCreateTime(date);
|
|
|
businessOrderDO.setUpdateTime(date);
|
|
|
businessOrderDO.setStatus(0);
|
|
|
businessOrderDO.setOrderNo(orderDO.getNumber());
|
|
|
businessOrderDO.setUploadStatus(0);
|
|
|
businessOrderDO.setPayType(1);
|
|
|
businessOrderDO.setPayPrice(Double.valueOf(orderDO.getTotalFee().doubleValue()));
|
|
|
businessOrderDO.setLastPayTime(lastPayTime);
|
|
|
} else {
|
|
|
/**
|
|
|
* 是否付款完成
|
|
|
* 判断付款时间是否超过时长了--还需要定时任务监听订单修改状态,把未付款改成已取消
|
|
|
*/
|
|
|
if (businessOrderDO.getStatus() != 1) {
|
|
|
long nowTime = System.currentTimeMillis();
|
|
|
Long lastPayTime = businessOrderDO.getLastPayTime();
|
|
|
if (lastPayTime > nowTime) {
|
|
|
//超时了 修改工单状态成已取消
|
|
|
orderDO.setStatus(-1);//-已取消
|
|
|
wlyyDoorServiceOrderDao.save(orderDO);//更新上门工单
|
|
|
businessOrderDO.setStatus(2);//已取消
|
|
|
businessOrderDao.save(businessOrderDO);//更新业务表
|
|
|
flag = false;//不用创建咨询内容
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//给机构调度员发送医生助手消息
|
|
|
for (Map<String, Object> map : dispatcherList) {
|
|
|
//这边还没有微信消息的功能呢。
|
|
|
sendWeixinMessage(3, map.get("user_code") + "", orderDO.getPatient());
|
|
|
}
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, consultTeam);
|
|
|
//费用0时无需支付
|
|
|
if ("4".equals(type) && 0.0 == orderDO.getTotalFee().doubleValue()) {
|
|
|
businessOrderDO.setStatus(1);//1已支付
|
|
|
businessOrderDao.save(businessOrderDO);
|
|
|
} else {
|
|
|
/**
|
|
|
* 保存订单信息-这边要判断付款回调修改状态值-付款失败取消订单
|
|
|
* businessOrderService
|
|
|
*/
|
|
|
businessOrderDO.setStatus(0);//0待支付
|
|
|
businessOrderDao.save(businessOrderDO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* todo 调用微信支付
|
|
|
* 再来更新flag标识
|
|
|
*/
|
|
|
|
|
|
|
|
|
//给出标识是否成功,往下面创建咨询信息发送内容
|
|
|
if (flag) {
|
|
|
//支付成功或者不用支付
|
|
|
//创建咨询
|
|
|
JSONObject successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
|
|
|
ConsultTeamDo consultTeam = (ConsultTeamDo) successOrNot.get(ResponseContant.resultMsg);
|
|
|
//判断其是否有分配执行人。如果有不用走调度平台
|
|
|
if (StringUtils.isNotBlank(orderDO.getDoctor())) {
|
|
|
orderDO.setStatus(2);//待接单
|
|
|
orderDO.setDoctor(orderDO.getDoctor());
|
|
|
orderDO.setDoctorName(orderDO.getDoctorName());
|
|
|
this.save(orderDO);
|
|
|
//新增工单医生关联关系
|
|
|
if (orderWithDoctorAdd(result, jsonObjectParam, orderDO)) {
|
|
|
return result;
|
|
|
}
|
|
|
// 给服务医生发接单消息
|
|
|
this.createMessage(orderDO.getId(), orderDO.getProxyPatient(), orderDO.getDoctor(), 407, "服务工单待接单", "您有新的服务工单,请前往处理");
|
|
|
//发送智能助手消息-微信消息先注释
|
|
|
sendWeixinMessage(4, orderDO.getDoctor(), orderDO.getPatient());
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, consultTeam);
|
|
|
return result;
|
|
|
}
|
|
|
//获取机构的调度员
|
|
|
List<Map<String, Object>> dispatcherList = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
|
|
|
|
|
|
//有调度员
|
|
|
if (!dispatcherList.isEmpty()) {
|
|
|
for (Map<String, Object> map : dispatcherList) {
|
|
|
String dispatcher = map.get("code").toString();
|
|
|
// 派单消息-首页
|
|
|
this.createMessage(orderDO.getId(), "system", dispatcher, 402, "新增居民预约服务申请", orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
|
|
|
// 派单-实时工单消息 430 居民提交工单申请-- 张三提交了服务工单12345678申请
|
|
|
this.createMessage(orderDO.getId(), "system", dispatcher, 430, "居民提交工单申请", orderDO.getPatientName() + "提交了服务工单" + orderDO.getNumber() + "申请");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//发送 预约卡片信息(2101类型)
|
|
|
JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
|
|
|
orderInfoContent.put("re_msg_type", 0);//居民预约
|
|
|
//发送消息
|
|
|
int i = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
|
|
|
// if (i != 1) {
|
|
|
// throw new Exception("上门服务工单消息发送失败");
|
|
|
// }
|
|
|
//给机构调度员发送医生助手消息
|
|
|
for (Map<String, Object> map : dispatcherList) {
|
|
|
//这边还没有微信消息的功能呢
|
|
|
sendWeixinMessage(3, map.get("code") + "", orderDO.getPatient());
|
|
|
}
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, consultTeam);
|
|
|
|
|
|
//发送 预约卡片信息(2101类型)
|
|
|
JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
|
|
|
orderInfoContent.put("re_msg_type", 0);//居民预约
|
|
|
//发送消息
|
|
|
int i = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
|
|
|
if (i != 1) {
|
|
|
throw new Exception("上门服务工单消息发送失败");
|
|
|
}
|
|
|
|
|
|
//后面这个要修改下,加个字段判断下是否转派
|
|
|
if (StringUtils.isNoneBlank(orderDO.getDoctor())) {
|
|
|
//服务医生修改,直接转派
|
|
|
BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
|
|
|
sendOrderToDoctor(orderDO.getId(), null, "system", "系统", transDoctor.getId(), transDoctor.getName(), transDoctor.getJobTitleName());
|
|
|
//后面这个要修改下,加个字段判断下是否转派
|
|
|
if (StringUtils.isNoneBlank(orderDO.getDoctor())) {
|
|
|
//服务医生修改,直接转派
|
|
|
BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
|
|
|
sendOrderToDoctor(orderDO.getId(), null, "system", "系统", transDoctor.getId(), transDoctor.getName(), transDoctor.getJobTitleName());
|
|
|
}
|
|
|
} else {
|
|
|
//取消订单
|
|
|
orderDO.setStatus(-1);//-已取消
|
|
|
wlyyDoorServiceOrderDao.save(orderDO);//更新上门工单
|
|
|
}
|
|
|
//result赋值返回
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@ -2104,7 +2212,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
|
|
|
if (notFinish > 0 && StringUtils.isNotBlank(doctor)) {
|
|
|
String notFinishSql = "select o.id,o.number,o.patient,o.patient_name,o.patient_phone,o.patient_expected_serve_time,o.`status`, CASE p.sex when 1 then '男' when 2 THEN '女' END as sex,p.idcard, " +
|
|
|
"year(now()) - ((CASE LENGTH(p.idcard) WHEN 18 THEN substring(p.idcard, 7, 4) WHEN 15 THEN CONCAT('19',substring(p.idcard, 7, 2)) END )) as age , p.photo,o.serve_lat AS lat,o.serve_lon AS lon,o.id AS orderId " +
|
|
|
"from wlyy_door_service_order o LEFT JOIN wlyy_patient p on o.patient = p.`code` and p.`status`=1 " +
|
|
|
"from wlyy_door_service_order o LEFT JOIN base_patient p on o.patient = p.`id` and p.`del`=1 " +
|
|
|
"where o.doctor ='" + doctor + "' and o.status in (2,3,4)";
|
|
|
List<Map<String, Object>> notFinishList = jdbcTemplate.queryForList(notFinishSql);
|
|
|
map.put("notFinishList", notFinishList);
|