|
@ -0,0 +1,1085 @@
|
|
|
package com.yihu.jw.care.service.doorCoach;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.care.dao.doorCoach.*;
|
|
|
import com.yihu.jw.care.service.consult.ConsultTeamService;
|
|
|
import com.yihu.jw.care.util.MessageUtil;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.im.ConsultDo;
|
|
|
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.hospital.message.SystemMessageDO;
|
|
|
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.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
import com.yihu.jw.util.common.IdCardUtil;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.util.entity.EntityUtils;
|
|
|
import com.yihu.jw.wechat.dao.BasePatientWechatDao;
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 上门辅导服务工单服务service--居民端
|
|
|
**/
|
|
|
|
|
|
@Service
|
|
|
public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOrderDO, BaseDoorCoachOrderDao> {
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(PatientDoorCoachOrderService.class);
|
|
|
@Value("${wechat.id}")
|
|
|
private String wxId;
|
|
|
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private BaseDoorCoachOrderDao baseDoorCoachOrderDao;
|
|
|
@Autowired
|
|
|
private BaseDoorCoachFeeDetailDao baseDoorCoachFeeDetailDao;
|
|
|
@Autowired
|
|
|
private BaseDoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private BaseDoorCoachDoctorStatusDao baseDoorCoachDoctorStatusDao;
|
|
|
@Autowired
|
|
|
private BaseDoorCoachProcessLogDao baseDoorCoachProcessLogDao;
|
|
|
@Autowired
|
|
|
private DoctorDoorCoachOrderService doorOrderService;
|
|
|
@Autowired
|
|
|
private BaseDoorCoachCancelLogDao baseDoorCoachCancelLogDao;
|
|
|
@Autowired
|
|
|
private BasePatientWechatDao basePatientWechatDao;
|
|
|
@Autowired
|
|
|
private BaseDoorCoachPatientConfirmLogDao patientConfirmLogDao;
|
|
|
|
|
|
@Autowired
|
|
|
private MessageUtil messageUtil;
|
|
|
|
|
|
@Autowired
|
|
|
private ImUtil imUtill;
|
|
|
|
|
|
@Autowired
|
|
|
private ConsultDao consultDao;
|
|
|
|
|
|
@Autowired
|
|
|
private BasePatientDao patientDao;
|
|
|
|
|
|
@Autowired
|
|
|
private ConsultTeamService consultTeamService;
|
|
|
@Autowired
|
|
|
private SystemMessageDao systemMessageDao;
|
|
|
|
|
|
/**
|
|
|
* 创建上门辅导服务工单
|
|
|
*
|
|
|
* @param jsonData
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject create(String jsonData) {
|
|
|
|
|
|
logger.info("创建上门服务jsonData参数:" + jsonData);
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
JSONObject jsonObjectParam;
|
|
|
try {
|
|
|
jsonObjectParam = JSONObject.parseObject(jsonData);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
BaseDoorCoachOrderDO orderDO = null;
|
|
|
try {
|
|
|
orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), BaseDoorCoachOrderDO.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "上门服务工单服务基本信息:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
orderDO.setNumber(getRandomIntStr());
|
|
|
orderDO.setCreateTime(new Date());
|
|
|
orderDO.setCreateUser(orderDO.getProxyPatient());
|
|
|
orderDO.setCreateUserName(orderDO.getProxyPatientName());
|
|
|
orderDO.setOrderInfo("0");
|
|
|
// orderDO.setConclusionStatus(1);
|
|
|
|
|
|
if(StringUtils.isEmpty(orderDO.getPatient())){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isEmpty(orderDO.getProxyPatient())){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前代理对象code为空,请联系管理员检查参数!proxyPatient = " + orderDO.getProxyPatient();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//已取消的订单也可以申请
|
|
|
boolean bool = baseDoorCoachOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
|
|
|
new Integer[]{BaseDoorCoachOrderDO.Status.waitForSend.getType(),
|
|
|
BaseDoorCoachOrderDO.Status.waitForAccept.getType(),
|
|
|
BaseDoorCoachOrderDO.Status.waitForServe.getType(),
|
|
|
BaseDoorCoachOrderDO.Status.accept.getType(),
|
|
|
});
|
|
|
|
|
|
if(bool){
|
|
|
String failMsg = "当前服务对象存在未完成的上门服务,请先完成该服务!";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
|
|
|
orderDO.setCreateTime(new Date());
|
|
|
//判断创建上门服务类型,发起类型(1本人发起 2家人待预约 3医生代预约)
|
|
|
if(orderDO.getProxyPatient().equals(orderDO.getPatient())){
|
|
|
orderDO.setType(1);
|
|
|
}else if(!orderDO.getProxyPatient().equals(orderDO.getPatient())){
|
|
|
orderDO.setType(2);
|
|
|
}
|
|
|
orderDO.setServiceStatus("1");
|
|
|
this.save(orderDO);
|
|
|
result.put("orderId",orderDO.getId());
|
|
|
//创建咨询
|
|
|
JSONObject successOrNot = null;
|
|
|
try {
|
|
|
successOrNot = consultTeamService.addDoorCoachServiceConsult(orderDO.getId());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
String failMsg = "创建咨询时异常: " + e.getMessage();
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
if (Integer.parseInt(successOrNot.get(ResponseContant.resultFlag).toString()) == ResponseContant.fail) {
|
|
|
return JSONObject.parseObject(successOrNot.toString());
|
|
|
}
|
|
|
ConsultTeamDo consultTeam = (ConsultTeamDo)successOrNot.get(ResponseContant.resultMsg);
|
|
|
|
|
|
//新增工单与服务项费用关联关系
|
|
|
if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO,null)) {return result;}
|
|
|
|
|
|
JSONObject dispatcherJson = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
|
|
|
|
|
|
List<Map<String,Object>> dispatcherInfoList = (List)dispatcherJson.get(ResponseContant.resultMsg);
|
|
|
for(Map<String,Object> map: dispatcherInfoList){
|
|
|
String dispatcher = map.get("code").toString();
|
|
|
BaseDoctorDO doctorVO = doctorDao.findById(dispatcher);
|
|
|
// 派单消息-首页
|
|
|
this.createMessage("新增居民预约服务申请","702","system","system", orderDO.getId(), dispatcher,doctorVO.getName() ,doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
|
|
|
// 派单-实时工单消息 430 居民提交工单申请-- 张三提交了服务工单12345678申请
|
|
|
this.createMessage("居民提交工单申请","730","system","system", orderDO.getId(), dispatcher,doctorVO.getName() ,doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务工单"+orderDO.getNumber()+"申请");
|
|
|
}
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, consultTeam);
|
|
|
//发送智能助手消息
|
|
|
sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
|
|
|
|
|
|
//发送 预约卡片信息(2201类型)
|
|
|
JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
|
|
|
orderInfoContent.put("re_msg_type",0);//居民预约
|
|
|
this.qucikSendIM(orderDO.getId(), "system", "智能助手", "2201", orderInfoContent.toJSONString());
|
|
|
|
|
|
if(StringUtils.isNoneBlank(orderDO.getDoctor())){
|
|
|
//服务医生修改,直接转派
|
|
|
BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
|
|
|
sendOrderToDoctor(orderDO.getId(),null,"system","系统",transDoctor.getId(),transDoctor.getName(),transDoctor.getJobTitleName());
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
public JSONObject proxyCreate(String jsonData,String doctorCode) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
JSONObject jsonObjectParam;
|
|
|
try {
|
|
|
jsonObjectParam = JSONObject.parseObject(jsonData);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BaseDoorCoachOrderDO orderDO = null;
|
|
|
try {
|
|
|
orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), BaseDoorCoachOrderDO.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "上门服务工单服务基本信息:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isEmpty(orderDO.getPatient())){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isEmpty(orderDO.getProxyPatient())){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前代理对象code为空,请联系管理员检查参数!proxyPatient = " + orderDO.getProxyPatient();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
//判断工单是否已存在,新建或者编辑
|
|
|
if(StringUtils.isBlank(orderDO.getId())) {
|
|
|
//已取消的订单也可以申请
|
|
|
boolean bool = baseDoorCoachOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
|
|
|
new Integer[]{BaseDoorCoachOrderDO.Status.waitForAccept.getType(),
|
|
|
BaseDoorCoachOrderDO.Status.waitForServe.getType(),
|
|
|
BaseDoorCoachOrderDO.Status.accept.getType(),
|
|
|
BaseDoorCoachOrderDO.Status.waitForSend.getType()
|
|
|
});
|
|
|
|
|
|
if(bool){
|
|
|
String failMsg = "当前服务对象存在未完成的上门服务,请先完成该服务!";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
orderDO.setNumber(getRandomIntStr());
|
|
|
orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
|
|
|
orderDO.setCreateTime(new Date());
|
|
|
orderDO.setCreateUser(orderDO.getProxyPatient());
|
|
|
orderDO.setCreateUserName(orderDO.getProxyPatientName());
|
|
|
}else {
|
|
|
BaseDoorCoachOrderDO serviceOrderDO = baseDoorCoachOrderDao.findOne(orderDO.getId());
|
|
|
// 删除出诊医生或服务项
|
|
|
Boolean b = this.orderWithFeeDelete(jsonObjectParam, serviceOrderDO);
|
|
|
if(b){
|
|
|
String failMsg = "删除服务项失败!";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
orderDO.setNumber(serviceOrderDO.getNumber());
|
|
|
orderDO.setHospital(serviceOrderDO.getHospital());
|
|
|
orderDO.setUpdateTime(new Date());
|
|
|
orderDO.setUpdateUser(orderDO.getProxyPatient());
|
|
|
orderDO.setUpdateUserName(orderDO.getProxyPatientName());
|
|
|
}
|
|
|
orderDO.setStatus(2);
|
|
|
orderDO.setType(3);
|
|
|
orderDO.setDispatcherResponseTime(new Date());
|
|
|
this.save(orderDO);
|
|
|
result.put("orderId",orderDO.getId());
|
|
|
//新增工单与服务项费用关联关系
|
|
|
if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO,doctorCode)) {return result;}
|
|
|
|
|
|
if("1".equals(orderDO.getShortcutType())){
|
|
|
//快捷的当前医生直接接单
|
|
|
try{
|
|
|
String sql = "SELECT d.job_title_code,d.job_title_name,o.org_level from base_doctor d,base_doctor_hospital h,base_org o " +
|
|
|
"WHERE d.id = h.doctor_code and h.org_code = o.id";
|
|
|
sql += " and d.id = '"+orderDO.getDoctor()+"'";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
doorOrderService.acceptOrder1(orderDO.getId(), list.get(0).get("job_title_code").toString(),
|
|
|
list.get(0).get("job_title_name").toString(), Integer.valueOf(list.get(0).get("org_level").toString()));
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
// 给服务医生发接单消息
|
|
|
this.createMessage("服务工单待接单","707",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(),orderDO.getDoctor(),orderDO.getDoctorName(), null,"您有新的服务工单,请前往处理");
|
|
|
//发送智能助手消息
|
|
|
sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 调度员-查询-服务人员列表(医生-可接单状态的)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryDoctorListWithNotStopped(String patient,String hospital,int page, int size) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
int start = 0 == page ? page++ : (page - 1) * size;
|
|
|
int end = 0 == size ? 15 : page * size;
|
|
|
|
|
|
String sql = "select DISTINCT ds.doctor,d.name, d.job_title_name as jobName, 1 as sortFlag " +
|
|
|
" from base_door_coach_doctor_status ds " +
|
|
|
" JOIN (select b.* from base_doctor b,base_doctor_hospital dh where b.id=dh.doctor_code and dh.del = 1 and dh.org_code='" + hospital + "') d on ds.doctor = d.id " +
|
|
|
" LEFT JOIN base_doctor_role dr ON dr.doctor_code = d.id where ds.status in (1,2,3,4) AND dr.role_code != 'nurse' " +
|
|
|
" limit " + start + "," + end ;
|
|
|
|
|
|
String countSql = "select DISTINCT count(ds.id) " +
|
|
|
"from wlyy_door_doctor_status ds " +
|
|
|
" JOIN (select b.* from base_doctor b,base_door_coach_doctor_status dh where b.id=dh.doctor_code and dh.del = 1 and dh.org_code= '" + hospital + "') d on ds.doctor = d.id " +
|
|
|
" LEFT JOIN base_doctor_role dr ON dr.doctor_code = d.id where ds.status in (1,2,3,4) AND dr.role_code != 'nurse' ";
|
|
|
List<Map<String,Object>> doctorList = new ArrayList<>();
|
|
|
try {
|
|
|
doctorList = jdbcTemplate.queryForList(sql);
|
|
|
} catch (Exception e) {
|
|
|
String failMsg = "从数据库查询 可接单状态的服务医生人员 列表信息失败:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg,failMsg );
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Integer count = 0;
|
|
|
try {
|
|
|
count = jdbcTemplate.queryForObject(countSql,Integer.class);
|
|
|
} catch (Exception e) {
|
|
|
String failMsg = "从数据库统计 可接单状态的服务医生人员 数量失败:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, doctorList);
|
|
|
JSONObject countItem = new JSONObject();
|
|
|
countItem.put("count", count);
|
|
|
result.putAll(countItem);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改上门服务工单(包括医生,费用,居民确认信息等)
|
|
|
*
|
|
|
* @param jsonData
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject update(String jsonData) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
JSONObject jsonObjectParam;
|
|
|
|
|
|
try {
|
|
|
jsonObjectParam = JSONObject.parseObject(jsonData);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
BaseDoorCoachOrderDO wlyyDoorServiceOrder = new BaseDoorCoachOrderDO();
|
|
|
wlyyDoorServiceOrder = jsonToWlyyDoorServiceOrder(result, jsonObjectParam, jsonData);
|
|
|
this.save(wlyyDoorServiceOrder);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, wlyyDoorServiceOrder);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除出诊医生或服务项
|
|
|
* @param jsonObjectParam
|
|
|
* {
|
|
|
* "deleteItemArr":[
|
|
|
* {
|
|
|
* "id":""
|
|
|
* },
|
|
|
* {
|
|
|
* "id":""
|
|
|
* }
|
|
|
* ],
|
|
|
* "deleteDoctorArr":[
|
|
|
* {
|
|
|
* "id":""
|
|
|
* },
|
|
|
* {
|
|
|
* "id":""
|
|
|
* }
|
|
|
* ]
|
|
|
* }
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean orderWithFeeDelete(JSONObject jsonObjectParam, BaseDoorCoachOrderDO orderDO) {
|
|
|
BigDecimal totalFee = orderDO.getTotalFee();
|
|
|
//删除的服务项
|
|
|
JSONArray itemArray = jsonObjectParam.getJSONArray("deleteItemArr");
|
|
|
if (!CollectionUtils.isEmpty(itemArray)) {
|
|
|
List<BaseDoorCoachFeeDetailDO> list = new ArrayList<>();
|
|
|
//删除的服务项要减去服务项费用
|
|
|
BigDecimal itemFee = new BigDecimal(0);
|
|
|
for(Object oneId : itemArray) {
|
|
|
JSONObject oneIdJson = (JSONObject) oneId;
|
|
|
BaseDoorCoachFeeDetailDO doorFeeDetail = baseDoorCoachFeeDetailDao.findOne(String.valueOf(oneIdJson.get("id")));
|
|
|
if(doorFeeDetail.getPayStatus()==0){
|
|
|
doorFeeDetail.setStatus(3);
|
|
|
doorFeeDetail.setUpdateTime(new Date());
|
|
|
list.add(doorFeeDetail);
|
|
|
itemFee = itemFee.add(doorFeeDetail.getFee().multiply(BigDecimal.valueOf(doorFeeDetail.getNumber())));
|
|
|
}
|
|
|
}
|
|
|
baseDoorCoachFeeDetailDao.save(list);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 上门服务工单服务基本信息
|
|
|
*
|
|
|
* @param result
|
|
|
* @param jsonObjectParam
|
|
|
* @param jsonData
|
|
|
* @return
|
|
|
*/
|
|
|
public BaseDoorCoachOrderDO jsonToWlyyDoorServiceOrder(JSONObject result, JSONObject jsonObjectParam, String jsonData) {
|
|
|
BaseDoorCoachOrderDO wlyyDoorServiceOrder;
|
|
|
try {
|
|
|
wlyyDoorServiceOrder = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), BaseDoorCoachOrderDO.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "上门服务工单服务基本信息:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return new BaseDoorCoachOrderDO();
|
|
|
}
|
|
|
wlyyDoorServiceOrder.setNumber(getRandomIntStr());
|
|
|
return wlyyDoorServiceOrder;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询预约简要卡片信息
|
|
|
*
|
|
|
* 服务时间:2019-01-01 12:30
|
|
|
* 服务对象:张三
|
|
|
* 联系电话:13125256565(儿子)
|
|
|
* 上门地址:福建省厦门市思明区望海路55号
|
|
|
*
|
|
|
* @param orderDO
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryOrderCardInfo(BaseDoorCoachOrderDO orderDO){
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("patientCode", orderDO.getPatient());
|
|
|
BasePatientDO patientDO = patientDao.findById(orderDO.getPatient());
|
|
|
result.put("title","预约服务信息如下:");
|
|
|
result.put("orderId",orderDO.getId());
|
|
|
result.put("status",orderDO.getStatus());
|
|
|
result.put("number",orderDO.getNumber());
|
|
|
result.put("serveDesc",orderDO.getServeDesc());
|
|
|
result.put("expectedDoctor",orderDO.getExpectedDoctorName());
|
|
|
result.put("serviceStatus",orderDO.getServiceStatus());
|
|
|
if(orderDO.getStatus() < 4){
|
|
|
if(StringUtils.isBlank(orderDO.getPatientExpectedServeTime())){
|
|
|
result.put("time","工作时间");
|
|
|
}else {
|
|
|
result.put("time", orderDO.getPatientExpectedServeTime());
|
|
|
}
|
|
|
}else {
|
|
|
if(StringUtils.isBlank(orderDO.getDoctorArrivingTime())){
|
|
|
result.put("time","工作时间");
|
|
|
}else{
|
|
|
result.put("time", orderDO.getDoctorArrivingTime());
|
|
|
}
|
|
|
}
|
|
|
result.put("patientName",patientDO.getName());
|
|
|
result.put("patientSex", IdCardUtil.getSexNameForIdcard_new(patientDO.getIdcard()));
|
|
|
result.put("patientAge", IdCardUtil.getAgeByIdcardOrBirthday(patientDO.getIdcard(),patientDO.getBirthday()));
|
|
|
result.put("phone",orderDO.getPatientPhone());
|
|
|
result.put("serveDesc",orderDO.getServeDesc());
|
|
|
if(StringUtils.equalsIgnoreCase(orderDO.getPatient(),orderDO.getProxyPatient())){
|
|
|
result.put("relation","");
|
|
|
}else{
|
|
|
result.put("relation",orderDO.getPatientRelation());
|
|
|
}
|
|
|
result.put("serveTown",orderDO.getServeTown());
|
|
|
result.put("serveAddress",orderDO.getServeAddress());
|
|
|
result.put("type",11);
|
|
|
return result;
|
|
|
}
|
|
|
/**
|
|
|
* 【调度员,医生】快速发送IM消息
|
|
|
* @param orderId
|
|
|
* @param sendId
|
|
|
* @param sendName
|
|
|
* @param content
|
|
|
* @return
|
|
|
*/
|
|
|
public int qucikSendIM(String orderId,String sendId,String sendName,String contentType,String content) {
|
|
|
int result = -1;
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
if (null == consult) {
|
|
|
logger.error("当前工单未关联咨询,工单id:" + orderId);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
BaseDoorCoachOrderDO baseDoorCoachOrderDO = null;
|
|
|
String response = null;
|
|
|
|
|
|
if(StringUtils.isBlank(sendId)){
|
|
|
baseDoorCoachOrderDO = baseDoorCoachOrderDao.findOne(orderId);
|
|
|
String sender = "system";
|
|
|
if(StringUtils.isNoneBlank(baseDoorCoachOrderDO.getDispatcher())){
|
|
|
sender = baseDoorCoachOrderDO.getDispatcher();
|
|
|
}
|
|
|
response = imUtill.sendTopicIM(sender, "智能助手", consult.getId(), contentType, content, null);
|
|
|
}else{
|
|
|
response = imUtill.sendTopicIM(sendId, sendName, consult.getId(), contentType, content, null);
|
|
|
}
|
|
|
JSONObject resObj = JSONObject.parseObject(response);
|
|
|
if (resObj.getIntValue("status") == -1) {
|
|
|
logger.error("上门服务工单消息发送失败:" + resObj.getString("message"));
|
|
|
return result;
|
|
|
}
|
|
|
result = 1;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 调度员(系统)给医生派单
|
|
|
*
|
|
|
* @param orderId
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject sendOrderToDoctor(String orderId,String remark,String dispatcher,String dispathcherName,String doctor,String doctorName,String doctorJobName){
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
BaseDoorCoachOrderDO doorServiceOrderDO = baseDoorCoachOrderDao.findOne(orderId);
|
|
|
if(null == doorServiceOrderDO){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前工单不存在,id:" + orderId;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
BaseDoorCoachDoctorStatusDO doorDoctorStatusDO = baseDoorCoachDoctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{BaseDoorCoachOrderDO.Status.waitForSend.getType(),
|
|
|
BaseDoorCoachDoctorStatusDO.Status.waitForAccept.getType(),
|
|
|
BaseDoorCoachDoctorStatusDO.Status.waitForServe.getType(),
|
|
|
BaseDoorCoachDoctorStatusDO.Status.serving.getType(),
|
|
|
});
|
|
|
if(null == doorDoctorStatusDO){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前派单的医生不存在或禁止接单,doctor:" + doctor;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
doorServiceOrderDO.setRemark(remark);
|
|
|
doorServiceOrderDO.setDoctor(doctor);
|
|
|
doorServiceOrderDO.setDoctorName(doctorName);
|
|
|
doorServiceOrderDO.setDoctorType(doctorJobName);
|
|
|
doorServiceOrderDO.setStatus(BaseDoorCoachOrderDO.Status.waitForAccept.getType());
|
|
|
doorServiceOrderDO.setUpdateUser(dispatcher);
|
|
|
doorServiceOrderDO.setUpdateUserName(dispathcherName);
|
|
|
doorServiceOrderDO.setDispatcherResponseTime(new Date());
|
|
|
|
|
|
|
|
|
this.save(doorServiceOrderDO);
|
|
|
|
|
|
// 给医生发派单消息
|
|
|
if(BaseDoorCoachOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
|
|
|
this.createMessage("服务工单待接单","707",doorServiceOrderDO.getTransedDispatcher(),doorServiceOrderDO.getTransedDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
|
|
|
}else{
|
|
|
this.createMessage("服务工单待接单","707",doorServiceOrderDO.getDispatcher(),doorServiceOrderDO.getDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
|
|
|
}
|
|
|
//发送智能助手消息//·
|
|
|
sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
|
|
|
|
|
|
// 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
|
|
|
imUtill.updateParticipantNew(sessionId,doctor,null);
|
|
|
messageUtil.updateDoorCoachMessage(doorServiceOrderDO,new String[]{"702","703","730","735"},"731",dispatcher,dispatcher);
|
|
|
|
|
|
// 工单状态变更记录
|
|
|
BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
|
|
|
processLogDO.setOrderId(orderId);
|
|
|
processLogDO.setStatus(BaseDoorCoachOrderDO.Status.waitForAccept.getType());
|
|
|
processLogDO.setDispatcher(dispatcher);
|
|
|
processLogDO.setDispatcherName(dispathcherName);
|
|
|
processLogDO.setCreateTime(new Date());
|
|
|
baseDoorCoachProcessLogDao.save(processLogDO);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, doorServiceOrderDO);
|
|
|
|
|
|
// 发送IM消息通知患者医生已派单
|
|
|
String noticeContent = "已分派"+doorServiceOrderDO.getDoctorName()+"医生为您服务,请耐心等待医生接单";
|
|
|
this.qucikSendIM(doorServiceOrderDO.getId(), doorServiceOrderDO.getDispatcher(), "智能助手","1", noticeContent);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 医生给医生派单
|
|
|
*
|
|
|
* @param orderId
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject transferOrder(String orderId,String remark,String dispatcher,String dispathcherName,String doctor,String doctorName,String doctorJobName){
|
|
|
JSONObject result = new JSONObject();
|
|
|
BaseDoorCoachOrderDO doorServiceOrderDO = baseDoorCoachOrderDao.findOne(orderId);
|
|
|
if(null == doorServiceOrderDO){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前工单不存在,id:" + orderId;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
BaseDoorCoachDoctorStatusDO doorDoctorStatusDO = baseDoorCoachDoctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{BaseDoorCoachDoctorStatusDO.Status.waitForSend.getType(),
|
|
|
BaseDoorCoachDoctorStatusDO.Status.waitForAccept.getType(),
|
|
|
BaseDoorCoachDoctorStatusDO.Status.waitForServe.getType(),
|
|
|
BaseDoorCoachDoctorStatusDO.Status.serving.getType(),
|
|
|
});
|
|
|
if(null == doorDoctorStatusDO){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前转派单的医生不存在或禁止接单,doctor:" + doctor;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
doorServiceOrderDO.setRemark(remark);
|
|
|
doorServiceOrderDO.setDoctor(doctor);
|
|
|
doorServiceOrderDO.setDoctorName(doctorName);
|
|
|
doorServiceOrderDO.setDoctorType(doctorJobName);
|
|
|
doorServiceOrderDO.setStatus(BaseDoorCoachOrderDO.Status.waitForAccept.getType());
|
|
|
doorServiceOrderDO.setUpdateUser(dispatcher);
|
|
|
doorServiceOrderDO.setUpdateUserName(dispathcherName);
|
|
|
doorServiceOrderDO.setDispatcherResponseTime(new Date());
|
|
|
|
|
|
System.out.println(dispathcherName+"医生派单给"+doctorName+"医生");
|
|
|
String sql = "DELETE FROM wlyy_door_doctor WHERE order_id ='"+orderId+"' AND doctor = '"+dispatcher+"'";
|
|
|
jdbcTemplate.execute(sql);
|
|
|
this.save(doorServiceOrderDO);
|
|
|
|
|
|
// 给医生发派单消息
|
|
|
if(BaseDoorCoachOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
|
|
|
this.createMessage("服务工单待接单","707",doorServiceOrderDO.getTransedDispatcher(),doorServiceOrderDO.getTransedDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
|
|
|
}else{
|
|
|
this.createMessage("服务工单待接单","707",doorServiceOrderDO.getDispatcher(),doorServiceOrderDO.getDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
|
|
|
}
|
|
|
//发送智能助手消息
|
|
|
sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
|
|
|
|
|
|
// 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
|
|
|
imUtill.updateParticipantNew(sessionId,doctor,null);
|
|
|
|
|
|
messageUtil.updateDoorCoachMessage(doorServiceOrderDO,new String[]{"702","703","730","735"},"731",dispatcher,dispatcher);
|
|
|
|
|
|
// 工单状态变更记录
|
|
|
BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
|
|
|
processLogDO.setOrderId(orderId);
|
|
|
processLogDO.setStatus(BaseDoorCoachOrderDO.Status.waitForAccept.getType());
|
|
|
processLogDO.setDispatcher(dispatcher);
|
|
|
processLogDO.setDispatcherName(dispathcherName);
|
|
|
processLogDO.setCreateTime(new Date());
|
|
|
baseDoorCoachProcessLogDao.save(processLogDO);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, doorServiceOrderDO);
|
|
|
|
|
|
// 发送IM消息通知患者医生已派单
|
|
|
String noticeContent = "已转派"+doorServiceOrderDO.getDoctorName()+"医生为您服务,请耐心等待医生接单";
|
|
|
this.qucikSendIM(doorServiceOrderDO.getId(), dispatcher, "智能助手","1", noticeContent);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消工单
|
|
|
* @param orderId
|
|
|
* @param type 取消类型
|
|
|
* @param reason 取消理由
|
|
|
*/
|
|
|
public JSONObject cancelOrder(String orderId,int type,String reason,String dispatcher,String dispatcherName){
|
|
|
JSONObject result = new JSONObject();
|
|
|
BaseDoorCoachOrderDO orderDO = baseDoorCoachOrderDao.findOne(orderId);
|
|
|
if(null == orderDO){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "【取消工单】该工单不存在:," + orderId;
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
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;
|
|
|
}
|
|
|
orderDO.setCancelType(type);
|
|
|
orderDO.setCancelTime(new Date());
|
|
|
orderDO.setCancelReason(reason);
|
|
|
if(!StringUtils.isEmpty(dispatcher)){
|
|
|
orderDO.setDispatcher(dispatcher);
|
|
|
orderDO.setDispatcherName(dispatcherName);
|
|
|
}
|
|
|
//如果是调度员取消,推送IM取消工单json消息,
|
|
|
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();
|
|
|
cancelLogDO.setOrderId(orderId);
|
|
|
cancelLogDO.setPatient(orderDO.getProxyPatient());
|
|
|
cancelLogDO.setCancelType(type);
|
|
|
cancelLogDO.setCancelReason(reason);
|
|
|
cancelLogDO.setTime(orderDO.getCancelTime());
|
|
|
baseDoorCoachCancelLogDao.save(cancelLogDO);
|
|
|
|
|
|
//保存居民确认取消记录
|
|
|
JSONObject confirmInfo = new JSONObject();
|
|
|
confirmInfo.put("orderId",orderId);
|
|
|
confirmInfo.put("patient",orderDO.getProxyPatient());
|
|
|
confirmInfo.put("patientName",orderDO.getProxyPatientName());
|
|
|
confirmInfo.put("type",4);
|
|
|
confirmInfo.put("description",reason);
|
|
|
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();
|
|
|
if(consult != null) {
|
|
|
json.put("consult", consult.getId());
|
|
|
}else {
|
|
|
json.put("id", orderDO.getId());
|
|
|
}
|
|
|
List<BasePatientWechatDo> basePatientWechatDos = basePatientWechatDao.findByWechatIdAndPatientId(wxId,patient.getId());
|
|
|
String openId = basePatientWechatDos.get(0).getOpenid();
|
|
|
messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyqx",openId,first,null,null,30,json, DateUtil.dateToChineseDate(new Date()),"上门预约已取消");
|
|
|
|
|
|
|
|
|
// 工单状态变更记录
|
|
|
BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
|
|
|
processLogDO.setOrderId(orderId);
|
|
|
processLogDO.setStatus(BaseDoorCoachOrderDO.Status.cancel.getType());
|
|
|
processLogDO.setDispatcher(dispatcher);
|
|
|
processLogDO.setDispatcherName(dispatcherName);
|
|
|
baseDoorCoachProcessLogDao.save(processLogDO);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, "工单服务已取消!");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 服务工单居民确认操作日志记录
|
|
|
*
|
|
|
* {
|
|
|
* "confirmInfo":{
|
|
|
* "patient":"",
|
|
|
* "patientName":"",
|
|
|
* "type":"",
|
|
|
* "description":""
|
|
|
* }
|
|
|
* }
|
|
|
*
|
|
|
* @param result
|
|
|
* @param jsonObjectParam
|
|
|
* @param orderId
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean orderWithConfirmLogAdd(JSONObject result, JSONObject jsonObjectParam, String orderId) {
|
|
|
// 确认信息
|
|
|
JSONObject confirmInfo = jsonObjectParam.getJSONObject("confirmInfo");
|
|
|
if (null != confirmInfo) {
|
|
|
BaseDoorCoachPatientConfirmLogDO confirmLogDO = null;
|
|
|
try {
|
|
|
confirmLogDO = EntityUtils.jsonToEntity(confirmInfo.toString(), BaseDoorCoachPatientConfirmLogDO.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "工单关联【居民确认操作日志记录】时," + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return true;
|
|
|
}
|
|
|
confirmLogDO.setOrderId(orderId);
|
|
|
confirmLogDO.setCreateTime(new Date());
|
|
|
try {
|
|
|
patientConfirmLogDao.save(confirmLogDO);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "保存工单关联的【居民确认操作日志记录】时:," + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public void sendWeixinMessage(Integer type,String doctorCode,String patient){
|
|
|
if (type==3){
|
|
|
//上门预约申请
|
|
|
try {
|
|
|
/* WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","zztj");
|
|
|
org.json.JSONObject sendJson = new org.json.JSONObject();
|
|
|
Patient patient1 =patientDao.findByCode(patient);
|
|
|
Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patient);
|
|
|
String doctorName = doctor.getName();
|
|
|
String first =doctorName+"医生,您好!"+patient1.getName()+"提交了上门出诊服务预约,请及时登录PC处理";
|
|
|
String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
params.add(new BasicNameValuePair("type", "15"));
|
|
|
params.add(new BasicNameValuePair("url", targetUrl));
|
|
|
params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
|
|
|
params.add(new BasicNameValuePair("first", first));
|
|
|
params.add(new BasicNameValuePair("remark", templateConfig.getRemark()));
|
|
|
params.add(new BasicNameValuePair("keywords", "上门服务预约待派单"));
|
|
|
params.add(new BasicNameValuePair("keywords", signFamily.getHospitalName()));
|
|
|
params.add(new BasicNameValuePair("keywords", doctorName));
|
|
|
httpClientUtil.post(url, params, "UTF-8");
|
|
|
logger.info("sendJson: " + params);*/
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}else if (type==4){
|
|
|
try {
|
|
|
//社区调度员指派服务工单给家签医生
|
|
|
/* WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","zztj");
|
|
|
org.json.JSONObject sendJson = new org.json.JSONObject();
|
|
|
Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patient);
|
|
|
String doctorName = doctor.getName();
|
|
|
String first =doctorName+"医生,您好!您有新的服务工单,请及时登录APP或PC处理";
|
|
|
String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
params.add(new BasicNameValuePair("type", "15"));
|
|
|
params.add(new BasicNameValuePair("url", targetUrl));
|
|
|
params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
|
|
|
params.add(new BasicNameValuePair("first", first));
|
|
|
params.add(new BasicNameValuePair("remark", templateConfig.getRemark()));
|
|
|
params.add(new BasicNameValuePair("keywords", "上门服务预约待接单"));
|
|
|
params.add(new BasicNameValuePair("keywords", signFamily.getHospitalName()));
|
|
|
params.add(new BasicNameValuePair("keywords", doctorName));
|
|
|
httpClientUtil.post(url, params, "UTF-8");
|
|
|
logger.info("sendJson: " + params);*/
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 工单与服务项费用关联关系
|
|
|
*
|
|
|
* @param result
|
|
|
* @param jsonObjectParam
|
|
|
* @param order
|
|
|
* {
|
|
|
* "packageItemArr":[
|
|
|
* {
|
|
|
* "type": null,
|
|
|
* "code": null,
|
|
|
* "name": null,
|
|
|
* "fee": null,
|
|
|
* "feeDiscount": null,
|
|
|
* "number": null,
|
|
|
* "status": null
|
|
|
* },
|
|
|
* ],
|
|
|
* "orderId": null,
|
|
|
* "status":""
|
|
|
* }
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean orderWithPackageItemFeeAdd(JSONObject result, JSONObject jsonObjectParam, BaseDoorCoachOrderDO order, String doctorId) {
|
|
|
List<BaseDoorCoachFeeDetailDO> feeDetailDOList = new ArrayList<>();
|
|
|
BigDecimal totalFee = order.getTotalFee();
|
|
|
if(null == totalFee){
|
|
|
totalFee = new BigDecimal(0);
|
|
|
}
|
|
|
//新增服务项
|
|
|
int addNum = 0;
|
|
|
//服务项费用
|
|
|
JSONArray packageItemArray = jsonObjectParam.getJSONArray("packageItemArr");
|
|
|
if (!CollectionUtils.isEmpty(packageItemArray)) {
|
|
|
for (Object one : packageItemArray) {
|
|
|
BaseDoorCoachFeeDetailDO feeDetailDO = null;
|
|
|
JSONObject oneJson = (JSONObject)one;
|
|
|
try {
|
|
|
//工单主表中记录总费用
|
|
|
totalFee = totalFee.add(feeDetailDO.getFee().multiply(BigDecimal.valueOf(feeDetailDO.getNumber())));
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "工单主表中记录总费用时," + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
// 服务项可能一开始由居民预约,后期由医生新增或医生删除
|
|
|
Integer status = jsonObjectParam.getInteger("status");
|
|
|
if(null == status || status == 1){
|
|
|
feeDetailDO.setStatus(BaseDoorCoachFeeDetailDO.Status.patient.getType());
|
|
|
}else{
|
|
|
feeDetailDO.setStatus(status);
|
|
|
}
|
|
|
|
|
|
// feeDetailDO.setNumber(1);
|
|
|
feeDetailDO.setOrderId(order.getId());
|
|
|
if(StringUtils.isBlank(feeDetailDO.getId())) {
|
|
|
feeDetailDO.setCreateTime(new Date());
|
|
|
}else {
|
|
|
feeDetailDO.setUpdateTime(new Date());
|
|
|
}
|
|
|
if(StringUtils.isBlank(feeDetailDO.getId())){
|
|
|
feeDetailDO.setPayStatus(0);
|
|
|
addNum++;
|
|
|
feeDetailDOList.add(feeDetailDO);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
try {
|
|
|
baseDoorCoachFeeDetailDao.save(feeDetailDOList);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "保存服务费用到数据库异常:," + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public List<Map<String,Object>> queryDispatcherInfoByHospital(String hospital){
|
|
|
String sql =" SELECT" +
|
|
|
" d.`code`, " +
|
|
|
" d.`name`, " +
|
|
|
" d.`hospital_name` as hospitalName " +
|
|
|
" FROM " +
|
|
|
" base_doctor_role m " +
|
|
|
" JOIN base_doctor_role_dict r ON m.role_code = r.code " +
|
|
|
" JOIN (select a.id code,a.name,o.org_name hospital_name from base_doctor_hospital o,base_doctor a " +
|
|
|
" where a.id = o.doctor_code and o.del=1 and o.org_code = '"+hospital+"') as d ON m.doctor_code = d.code" +
|
|
|
" WHERE " +
|
|
|
" r.code = 'dispatcher'";
|
|
|
return jdbcTemplate.queryForList(sql);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取居民所签约的机构的调度员(一个机构可以有多个调度员)
|
|
|
* doctor中,level -- 11-- 调度员
|
|
|
* @param hospitalCode
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject queryDispatcherInfoByPatient(String hospitalCode) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
List dispatcherInfoList = queryDispatcherInfoByHospital(hospitalCode);
|
|
|
if(CollectionUtils.isEmpty(dispatcherInfoList)){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前居民所签约机构【" + hospitalCode + "】没有调度员,请联系管理员分配!";
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, dispatcherInfoList);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加【工单派单,转单】等系统消息
|
|
|
|
|
|
*/
|
|
|
public void createMessage(String title,String type,String sender,String senderName,String relationCode,String Receiver,String ReceiverName,String idCard,String msg){
|
|
|
SystemMessageDO messageDO = new SystemMessageDO();
|
|
|
messageDO.setTitle(title);
|
|
|
messageDO.setType(type);//401为资质申请审核
|
|
|
messageDO.setSender(sender);
|
|
|
messageDO.setSenderName(senderName);
|
|
|
messageDO.setRelationCode(relationCode);
|
|
|
messageDO.setReceiver(Receiver);
|
|
|
messageDO.setReceiverName(ReceiverName);
|
|
|
messageDO.setOver("1");
|
|
|
messageDO.setData(msg);
|
|
|
messageDO.setDel("1");
|
|
|
messageDO.setCreateTime(new Date());
|
|
|
systemMessageDao.save(messageDO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 统计居民已经服务的次数
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public Integer countPatientDoorTimes(String patient){
|
|
|
Integer count = 0;
|
|
|
String sql = "SELECT count(o.id) as count FROM base_door_coach_order o where o.patient = '" + patient + "' and status>="+BaseDoorCoachOrderDO.Status.waitForCommnet.getType();
|
|
|
count = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
|
|
|
private String getRandomIntStr(){
|
|
|
Random rand = new Random();
|
|
|
int i = rand.nextInt(); //int范围类的随机数
|
|
|
i = rand.nextInt(100); //生成0-100以内的随机数
|
|
|
i = (int)(Math.random() * 100000000); //0-100以内的随机数,用Matn.random()方式
|
|
|
return String.valueOf(i);
|
|
|
}
|
|
|
}
|