|
@ -0,0 +1,2912 @@
|
|
|
package com.yihu.jw.door.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.yihu.fastdfs.FastDFSUtil;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
|
|
|
import com.yihu.jw.door.dao.*;
|
|
|
import com.yihu.jw.door.service.consult.ConsultTeamService;
|
|
|
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.door.*;
|
|
|
import com.yihu.jw.im.dao.ConsultDao;
|
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
|
import com.yihu.jw.message.dao.MessageDao;
|
|
|
import com.yihu.jw.org.dao.BaseOrgDao;
|
|
|
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.common.QrcodeUtil;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.util.entity.EntityUtils;
|
|
|
import com.yihu.jw.util.http.HttpClientUtil;
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
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.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 上门服务工单服务service--居民端
|
|
|
*
|
|
|
* @version <pre>
|
|
|
* Author Version Date Changes
|
|
|
* Administrator 1.0 2019年03月20日 Created
|
|
|
*
|
|
|
* </pre>
|
|
|
* @since 1
|
|
|
*/
|
|
|
@Service
|
|
|
public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceOrderDO, WlyyDoorServiceOrderDao> {
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(WlyyDoorServiceOrderService.class);
|
|
|
|
|
|
/* @Value("${server.server_url}")
|
|
|
private String wxServerUrl;
|
|
|
@Value("${doctorAssistant.api}")
|
|
|
private String doctorAssistant;
|
|
|
@Value("${doctorAssistant.target_url}")
|
|
|
private String targetUrl;
|
|
|
@Autowired
|
|
|
private HttpClientUtil httpClientUtil;*/
|
|
|
@Autowired
|
|
|
private WlyyDoorServiceOrderDao wlyyDoorServiceOrderDao;
|
|
|
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorFeeDetailService wlyyDoorFeeDetailService;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorFeeDetailDao wlyyDoorFeeDetailDao;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorDoctorDao wlyyDoorDoctorDao;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorDoctorService wlyyDoorDoctorService;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorConclusionDao wlyyDoorConclusionDao;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorPatientConfirmLogDao wlyyDoorPatientConfirmLogDao;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorDoctorStatusDao wlyyDoorDoctorStatusDao;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorCancelLogDao wlyyDoorCancelLogDao;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorTransRecordDao wlyyDoorTransRecordDao;
|
|
|
|
|
|
@Autowired
|
|
|
private MessageDao messageDao;
|
|
|
|
|
|
@Autowired
|
|
|
private ImUtil imUtill;
|
|
|
|
|
|
@Autowired
|
|
|
private ConsultDao consultDao;
|
|
|
|
|
|
@Autowired
|
|
|
private BasePatientDao patientDao;
|
|
|
|
|
|
@Autowired
|
|
|
private ConsultTeamService consultTeamService;
|
|
|
|
|
|
/* @Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
|
|
|
@Autowired
|
|
|
WeiXinAccessTokenUtils tokenUtils;
|
|
|
|
|
|
@Autowired
|
|
|
private DmJobService dmJobService;*/
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyDoorProcessLogDao wlyyDoorProcessLogDao;
|
|
|
|
|
|
/* @Autowired
|
|
|
private WechatTemplateConfigDao templateConfigDao;
|
|
|
@Autowired
|
|
|
private SignFamilyDao signFamilyDao;*/
|
|
|
|
|
|
@Autowired
|
|
|
private DoorOrderService doorOrderService;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private DoorServiceVoucherDao doorServiceVoucherDao;
|
|
|
|
|
|
@Autowired
|
|
|
private BaseDoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private BaseDoctorHospitalDao baseDoctorHospitalDao;
|
|
|
@Autowired
|
|
|
private BaseOrgDao hospitalDao;
|
|
|
@Autowired
|
|
|
private FastDFSUtil fastDFSUtil;
|
|
|
@Autowired
|
|
|
private WlyyDoorPrescriptionDao doorPrescriptionDao;
|
|
|
|
|
|
@Value("${neiwang.enable}")
|
|
|
private Boolean isneiwang; //如果不是内网项目要转到到内网wlyy在上传
|
|
|
@Value("${fastDFS.fastdfs_file_url}")
|
|
|
private String fastdfs_file_url;
|
|
|
@Value("${neiwang.wlyy}")
|
|
|
private String neiwangWlyy; //内网的项目地址
|
|
|
@Autowired
|
|
|
private WlyyDoorOrderItemDao doorOrderItemDao;
|
|
|
@Autowired
|
|
|
private DoorServiceApplicationService doorServiceApplicationService;
|
|
|
|
|
|
/**
|
|
|
* 上门服务工单服务基本信息
|
|
|
*
|
|
|
* @param result
|
|
|
* @param jsonObjectParam
|
|
|
* @param jsonData
|
|
|
* @return
|
|
|
*/
|
|
|
public WlyyDoorServiceOrderDO jsonToWlyyDoorServiceOrder(JSONObject result, JSONObject jsonObjectParam, String jsonData) {
|
|
|
WlyyDoorServiceOrderDO wlyyDoorServiceOrder;
|
|
|
try {
|
|
|
wlyyDoorServiceOrder = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "上门服务工单服务基本信息:" + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return new WlyyDoorServiceOrderDO();
|
|
|
}
|
|
|
wlyyDoorServiceOrder.setNumber(getRandomIntStr());
|
|
|
return wlyyDoorServiceOrder;
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 工单与服务项费用关联关系(新增)
|
|
|
*
|
|
|
* @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, WlyyDoorServiceOrderDO order ) {
|
|
|
List<WlyyDoorFeeDetailDO> feeDetailDOList = new ArrayList<>();
|
|
|
List<WlyyDoorOrderItemDO> orderItemDOList = new ArrayList<>();
|
|
|
BigDecimal totalFee = order.getTotalFee();
|
|
|
if(null == totalFee){
|
|
|
totalFee = new BigDecimal(0);
|
|
|
}
|
|
|
//服务项费用
|
|
|
JSONArray packageItemArray = jsonObjectParam.getJSONArray("packageItemArr");
|
|
|
if (!CollectionUtils.isEmpty(packageItemArray)) {
|
|
|
for (Object one : packageItemArray) {
|
|
|
WlyyDoorFeeDetailDO feeDetailDO = null;
|
|
|
JSONObject oneJson = (JSONObject)one;
|
|
|
try {
|
|
|
feeDetailDO = EntityUtils.jsonToEntity(one.toString(), WlyyDoorFeeDetailDO.class);
|
|
|
WlyyDoorOrderItemDO orderItemDO = new WlyyDoorOrderItemDO();
|
|
|
orderItemDO.setDoctor(order.getDoctor());
|
|
|
orderItemDO.setCode(feeDetailDO.getCode());
|
|
|
orderItemDO.setCreateTime(new Date());
|
|
|
orderItemDO.setPatient(orderItemDO.getPatient());
|
|
|
orderItemDOList.add(orderItemDO);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "工单与服务费用关联关系时," + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return true;
|
|
|
}
|
|
|
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(WlyyDoorFeeDetailDO.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());
|
|
|
}
|
|
|
feeDetailDOList.add(feeDetailDO);
|
|
|
}
|
|
|
// order.setTotalFee(totalFee);
|
|
|
// this.save(order);
|
|
|
try {
|
|
|
wlyyDoorFeeDetailDao.save(feeDetailDOList);
|
|
|
doorOrderItemDao.save(orderItemDOList);
|
|
|
// wlyyDoorFeeDetailService.batchInsert(feeDetailDOList);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "保存服务费用到数据库异常:," + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return true;
|
|
|
}
|
|
|
}/*else{
|
|
|
// 未添加服务项时,费用默认为0
|
|
|
order.setTotalFee(new BigDecimal(0));
|
|
|
this.save(order);
|
|
|
}*/
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 删除出诊医生或服务项
|
|
|
* @param jsonObjectParam
|
|
|
* {
|
|
|
* "deleteItemArr":[
|
|
|
* {
|
|
|
* "id":""
|
|
|
* },
|
|
|
* {
|
|
|
* "id":""
|
|
|
* }
|
|
|
* ],
|
|
|
* "deleteDoctorArr":[
|
|
|
* {
|
|
|
* "id":""
|
|
|
* },
|
|
|
* {
|
|
|
* "id":""
|
|
|
* }
|
|
|
* ]
|
|
|
* }
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean orderWithFeeDelete(JSONObject jsonObjectParam,WlyyDoorServiceOrderDO orderDO) {
|
|
|
BigDecimal totalFee = orderDO.getTotalFee();
|
|
|
//删除的服务项
|
|
|
JSONArray itemArray = jsonObjectParam.getJSONArray("deleteItemArr");
|
|
|
if (!CollectionUtils.isEmpty(itemArray)) {
|
|
|
List<WlyyDoorFeeDetailDO> list = new ArrayList<>();
|
|
|
//删除的服务项要减去服务项费用
|
|
|
BigDecimal itemFee = new BigDecimal(0);
|
|
|
for(Object oneId : itemArray) {
|
|
|
JSONObject oneIdJson = (JSONObject) oneId;
|
|
|
WlyyDoorFeeDetailDO doorFeeDetail = wlyyDoorFeeDetailDao.findOne(String.valueOf(oneIdJson.get("id")));
|
|
|
doorFeeDetail.setStatus(3);
|
|
|
doorFeeDetail.setUpdateTime(new Date());
|
|
|
list.add(doorFeeDetail);
|
|
|
itemFee = itemFee.add(doorFeeDetail.getFee().multiply(BigDecimal.valueOf(doorFeeDetail.getNumber())));
|
|
|
|
|
|
}
|
|
|
wlyyDoorFeeDetailDao.save(list);
|
|
|
// orderDO.setTotalFee(totalFee.subtract(itemFee));
|
|
|
}
|
|
|
//出诊的医生
|
|
|
JSONArray doctorArray = jsonObjectParam.getJSONArray("deleteDoctorArr");
|
|
|
if (!CollectionUtils.isEmpty(doctorArray)) {
|
|
|
Set idStrSet = new HashSet();
|
|
|
StringBuffer idStrBuffer = new StringBuffer();
|
|
|
doctorArray.forEach(
|
|
|
oneId -> {
|
|
|
JSONObject idJson = (JSONObject)oneId;
|
|
|
idStrSet.add(idJson.getString("id"));
|
|
|
idStrBuffer.append(idJson.getString("id")).append(" ");
|
|
|
});
|
|
|
// 根据id查询医生code集合
|
|
|
List<String> doctors = wlyyDoorDoctorDao.findDoctorByIds(idStrSet);
|
|
|
if(org.springframework.util.CollectionUtils.isEmpty(doctors)){
|
|
|
logger.error("修改医生时,根据工单医生表id获取医生列表为空! id: " + idStrBuffer.toString() );
|
|
|
}else{
|
|
|
// 费用表里也有医生出诊费用,需要一起删除,获取工单服务项id(type=2 医生出诊费用)
|
|
|
List<Map<String,Object>> doctorFees = wlyyDoorFeeDetailDao.findIdByCodeAndType(doctors, 2);
|
|
|
if(!CollectionUtils.isEmpty(doctorFees)){
|
|
|
//删除的医生要减去出诊费用
|
|
|
BigDecimal totalSubFee = new BigDecimal(0);
|
|
|
for(Map<String,Object> rowMap : doctorFees){
|
|
|
String id = rowMap.get("id").toString();
|
|
|
idStrSet.add(id);
|
|
|
BigDecimal fee = BigDecimal.valueOf(Double.parseDouble(rowMap.get("fee").toString()));
|
|
|
totalSubFee = totalSubFee.add(fee);
|
|
|
}
|
|
|
wlyyDoorFeeDetailService.delete(idStrSet.toArray());
|
|
|
totalFee = orderDO.getTotalFee().subtract(totalSubFee);
|
|
|
// orderDO.setTotalFee(totalFee);
|
|
|
}
|
|
|
}
|
|
|
wlyyDoorDoctorService.delete(idStrSet.toArray());
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 统计居民已经服务的次数
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public Integer countPatientDoorTimes(String patient){
|
|
|
Integer count = 0;
|
|
|
String sql = "SELECT count(d.id) as count FROM wlyy_door_service_order o, wlyy_door_doctor d where o.id = d.order_id and o.patient = '" + patient + "'";
|
|
|
count = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 工单关联的出诊医生人员
|
|
|
*
|
|
|
* @param result
|
|
|
* @param jsonObjectParam
|
|
|
* @param orderDO
|
|
|
* {
|
|
|
* "doctorArr":[
|
|
|
* {
|
|
|
* "doctor":"",
|
|
|
* "doctorName":"",
|
|
|
* "doctorLevel":"",
|
|
|
* "doctorJobCode":"",
|
|
|
* "doctorJobName":"",
|
|
|
* }
|
|
|
* ]
|
|
|
* }
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean orderWithDoctorAdd(JSONObject result, JSONObject jsonObjectParam, WlyyDoorServiceOrderDO orderDO) {
|
|
|
List<WlyyDoorDoctorDO> doorDoctorDOList = new ArrayList<>();
|
|
|
List<WlyyDoorFeeDetailDO> feeDetailDOList = new ArrayList<>();
|
|
|
BigDecimal totalFee = orderDO.getTotalFee();
|
|
|
if(null == totalFee){
|
|
|
totalFee = new BigDecimal(0);
|
|
|
}
|
|
|
//出诊人员
|
|
|
JSONArray doctorArray = jsonObjectParam.getJSONArray("doctorArr");
|
|
|
if (!CollectionUtils.isEmpty(doctorArray)) {
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderDO.getId());
|
|
|
String sessionId = null;
|
|
|
if(consult!=null){
|
|
|
sessionId = orderDO.getPatient() + "_" + consult.getId() + "_" + orderDO.getNumber() + "_" + consult.getType();
|
|
|
}
|
|
|
for (Object one : doctorArray) {
|
|
|
WlyyDoorDoctorDO doorDoctorDO = null;
|
|
|
try {
|
|
|
doorDoctorDO = EntityUtils.jsonToEntity(one.toString(), WlyyDoorDoctorDO.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "工单关联出诊医生人员时," + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return true;
|
|
|
}
|
|
|
// 医生不可重复添加
|
|
|
if(wlyyDoorDoctorDao.existsByOrderIdAndDoctor(orderDO.getId(),doorDoctorDO.getDoctor())){
|
|
|
continue;
|
|
|
}
|
|
|
doorDoctorDO.setOrderId(orderDO.getId());
|
|
|
doorDoctorDOList.add(doorDoctorDO);
|
|
|
|
|
|
//出诊人员费用
|
|
|
WlyyDoorFeeDetailDO feeDetailDO = new WlyyDoorFeeDetailDO();
|
|
|
feeDetailDO.setOrderId(orderDO.getId());
|
|
|
feeDetailDO.setCode(doorDoctorDO.getDoctor());
|
|
|
feeDetailDO.setName(doorDoctorDO.getDoctorName());
|
|
|
feeDetailDO.setNumber(1);
|
|
|
feeDetailDO.setStatus(2);
|
|
|
feeDetailDO.setType(2);
|
|
|
feeDetailDO.setCreateTime(new Date());
|
|
|
// 被服务的居民的次数(非代理居民)
|
|
|
Integer tiems = countPatientDoorTimes(orderDO.getPatient());
|
|
|
// BigDecimal fee = BigDecimal.valueOf(dmJobService.getJobFee(doorDoctorDO.getDoctorJobCode(),doorDoctorDO.getHospitalLevel(),tiems));
|
|
|
BigDecimal fee = BigDecimal.valueOf(120);
|
|
|
feeDetailDO.setFee(fee);
|
|
|
totalFee = totalFee.add(fee);
|
|
|
feeDetailDOList.add(feeDetailDO);
|
|
|
|
|
|
// 把医生拉入会话,作为其中一个成员
|
|
|
if(StringUtils.isNoneBlank(sessionId)){
|
|
|
imUtill.updateParticipant(sessionId,doorDoctorDO.getDoctor(),null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
wlyyDoorDoctorDao.save(doorDoctorDOList);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "保存工单关联的出诊医生人员时:," + e.getMessage();
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return true;
|
|
|
}
|
|
|
try {
|
|
|
wlyyDoorFeeDetailDao.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;
|
|
|
}
|
|
|
// orderDO.setTotalFee(totalFee);
|
|
|
this.save(orderDO);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取居民所签约的机构的调度员(一个机构可以有多个调度员)
|
|
|
* wlyy_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 List<Map<String,Object>> queryDispatcherInfoByHospital(String hospital){
|
|
|
String sql ="SELECT " +
|
|
|
" d.`code`, " +
|
|
|
" d.`name`, " +
|
|
|
" d.`hospital_name` as hospitalName " +
|
|
|
" FROM " +
|
|
|
" manage_role_user m " +
|
|
|
" JOIN manage_roles r ON m.role_id = r.id " +
|
|
|
" JOIN (select code,name,hospital_name from wlyy_doctor where hospital = '"+ hospital +"') as d ON m.user_code = d.code" +
|
|
|
" WHERE " +
|
|
|
" r.code = 'dispatcher'";
|
|
|
return jdbcTemplate.queryForList(sql);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建上门服务工单
|
|
|
*
|
|
|
* @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;
|
|
|
}
|
|
|
WlyyDoorServiceOrderDO orderDO = null;
|
|
|
try {
|
|
|
orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.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;
|
|
|
}
|
|
|
|
|
|
/* SignFamily signFamily = signFamilyDao.findSignFamilyByPatient(orderDO.getPatient());
|
|
|
if (signFamily == null) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前服务对象未完成家庭医生签约,请完成签约后再预约上门服务!";
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}*/
|
|
|
|
|
|
//已取消的订单也可以申请
|
|
|
boolean bool = wlyyDoorServiceOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
|
|
|
new Integer[]{WlyyDoorServiceOrderDO.Status.waitForSend.getType(),
|
|
|
WlyyDoorServiceOrderDO.Status.waitForAccept.getType(),
|
|
|
WlyyDoorServiceOrderDO.Status.waitForServe.getType(),
|
|
|
WlyyDoorServiceOrderDO.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);
|
|
|
|
|
|
//创建咨询
|
|
|
JSONObject successOrNot = null;
|
|
|
try {
|
|
|
successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
|
|
|
} catch (Exception e) {
|
|
|
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)) {return result;}
|
|
|
|
|
|
JSONObject dispatcherJson = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
|
|
|
if (dispatcherJson.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
|
|
|
return dispatcherJson;
|
|
|
}
|
|
|
List<Map<String,Object>> dispatcherInfoList = (List)dispatcherJson.get(ResponseContant.resultMsg);
|
|
|
for(Map<String,Object> map: dispatcherInfoList){
|
|
|
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()+"申请");
|
|
|
}
|
|
|
//给机构调度员发送医生助手消息
|
|
|
String dispatcherSql = "SELECT u.user_code FROM `manage_role_user` u ,wlyy_doctor d where u.role_id = 22 and u.user_code = d.`code` and d.hospital = '" +orderDO.getHospital() + "'";
|
|
|
List<Map<String, Object>> dispatcherList = jdbcTemplate.queryForList(dispatcherSql);
|
|
|
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);
|
|
|
|
|
|
//发送 预约卡片信息(2101类型)
|
|
|
JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
|
|
|
orderInfoContent.put("re_msg_type",0);//居民预约
|
|
|
this.qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", 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;
|
|
|
}
|
|
|
|
|
|
|
|
|
public void sendWeixinMessage(Integer type,String doctorCode,String patient){
|
|
|
//提交资质审核
|
|
|
if (type==1){
|
|
|
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);
|
|
|
String doctorName = doctor.getName();
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patient);
|
|
|
String first =doctorName+"医生,您好!"+patient1.getName()+"提交了资质申请,请及时登录PC或APP处理";
|
|
|
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==2){
|
|
|
//调度员转交给家庭医生
|
|
|
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或APP处理";
|
|
|
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==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 dispatcher
|
|
|
* @param orderId
|
|
|
*/
|
|
|
public JSONObject dispatcherIntoTopic(String orderId, String hospitalName, String dispatcher, String dispatcherName) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(orderId);
|
|
|
if (null == orderDO) {
|
|
|
String failMsg = "调度员进入聊天室时,找不到对应工单,工单id=" + orderId;
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
String sessionId = orderDO.getPatient() + "_" + consult.getId() + "_" + orderDO.getNumber() + "_" + consult.getType();
|
|
|
// 把调度员拉入会话,作为其中一个成员,第一个进入会话的调度员,系统发送欢迎语和居民的预约卡片信息
|
|
|
if (StringUtils.isEmpty(orderDO.getDispatcher())) {
|
|
|
orderDO.setDispatcher(dispatcher);
|
|
|
orderDO.setDispatcherName(dispatcherName);
|
|
|
this.save(orderDO);
|
|
|
// 先进入会话,再聊天
|
|
|
imUtill.updateParticipant(sessionId,dispatcher,null);
|
|
|
String noticeContent = hospitalName + dispatcherName + "为您服务";
|
|
|
this.qucikSendIM(orderId, dispatcher, "智能助手", "1", noticeContent);
|
|
|
}
|
|
|
// 把调度员拉入会话,作为其中一个成员
|
|
|
imUtill.updateParticipant(sessionId,dispatcher,null);
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, "调度员["+dispatcherName+"]进入会话成功");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 回写最后一个回复内容的调度员到工单表
|
|
|
* @param dispatcher
|
|
|
* @param orderId
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject saveLastDispatcher(String orderId, String dispatcher, String dispatcherName) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(orderId);
|
|
|
if (null == orderDO) {
|
|
|
String failMsg = "回写最后一个回复内容的调度员到工单表时,找不到对应工单,工单id=" + orderId;
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
orderDO.setDispatcher(dispatcher);
|
|
|
orderDO.setDispatcherName(dispatcherName);
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, dispatcherName);
|
|
|
this.save(orderDO);
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
WlyyDoorServiceOrderDO wlyyDoorServiceOrder = new WlyyDoorServiceOrderDO();
|
|
|
wlyyDoorServiceOrder = jsonToWlyyDoorServiceOrder(result, jsonObjectParam, jsonData);
|
|
|
this.save(wlyyDoorServiceOrder);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, wlyyDoorServiceOrder);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询单个工单预约详情
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryOneDetail(String id) {
|
|
|
JSONObject orderJson = new JSONObject();
|
|
|
List<WlyyDoorServiceOrderDO> orderList = this.findByField("id", id);
|
|
|
if (CollectionUtils.isEmpty(orderList)) {
|
|
|
orderJson.put(ResponseContant.resultMsg, orderList);
|
|
|
return orderJson;
|
|
|
}
|
|
|
|
|
|
JSONObject orderBriefInfo = new JSONObject();
|
|
|
WlyyDoorServiceOrderDO orderDO = orderList.get(0);
|
|
|
|
|
|
// 工单预约简要主体信息
|
|
|
orderBriefInfo = (JSONObject) JSONObject.toJSON(orderDO);
|
|
|
|
|
|
// 服务对象名称,
|
|
|
String serverName = "";
|
|
|
|
|
|
//获取居民性别跟年龄
|
|
|
BasePatientDO patient = patientDao.findById(orderDO.getPatient());
|
|
|
String sexName = IdCardUtil.getSexNameForIdcard_new(patient.getIdcard());
|
|
|
int age = IdCardUtil.getAgeByIdcardOrBirthday(patient.getIdcard(),patient.getBirthday());
|
|
|
serverName = orderDO.getPatientName() + "(" + sexName + " " + age + "岁)";
|
|
|
|
|
|
orderBriefInfo.put("patientName", orderDO.getPatientName());
|
|
|
orderBriefInfo.put("serverName", serverName);
|
|
|
orderBriefInfo.put("phone", orderDO.getPatientPhone());
|
|
|
//处理详情时间节点格式
|
|
|
orderBriefInfo.put("createTime", DateUtil.dateToStr(orderDO.getCreateTime(), "MM-dd HH:mm"));
|
|
|
orderBriefInfo.put("updateTime", DateUtil.dateToStr(orderDO.getUpdateTime(), "MM-dd HH:mm"));
|
|
|
if(orderDO.getDispatcherResponseTime() != null) {
|
|
|
orderBriefInfo.put("dispatcherResponseTime", DateUtil.dateToStr(orderDO.getDispatcherResponseTime(), "MM-dd HH:mm"));
|
|
|
}
|
|
|
orderBriefInfo.put("serviceResponseTime", DateUtil.dateToStr(orderDO.getServiceResponseTime(), "MM-dd HH:mm"));
|
|
|
orderBriefInfo.put("patientConfirmTime", DateUtil.dateToStr(orderDO.getPatientConfirmTime(), "MM-dd HH:mm"));
|
|
|
orderBriefInfo.put("payTime", DateUtil.dateToStr(orderDO.getPayTime(), "MM-dd HH:mm"));
|
|
|
orderBriefInfo.put("doctorSignTime", DateUtil.dateToStr(orderDO.getDoctorSignTime(), "MM-dd HH:mm"));
|
|
|
orderBriefInfo.put("completeTime", DateUtil.dateToStr(orderDO.getCompleteTime(), "MM-dd HH:mm"));
|
|
|
orderBriefInfo.put("prescriptionTime", DateUtil.dateToStr(orderDO.getPrescriptionTime(), "MM-dd HH:mm"));
|
|
|
|
|
|
// 计算服务包支付多少钱
|
|
|
List<Map<String, Object>> feeDetailDOS = doorOrderService.getDoorFeeDetailGroupByStatus(id);
|
|
|
String jsonData = null;
|
|
|
try {
|
|
|
jsonData = doorOrderService.serverPackagePriceByOrderId(id);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(feeDetailDOS)) {
|
|
|
Map<String, Object> map = doorOrderService.countServerPackagePrice(jsonData, orderDO.getPatient());
|
|
|
orderBriefInfo.put("packageFee", map.get("serverPackagePrice"));
|
|
|
}
|
|
|
orderJson.put("order", orderBriefInfo);
|
|
|
|
|
|
//关联服务项
|
|
|
String sql = "SELECT " +
|
|
|
" fd.`code`, " +
|
|
|
" fd.`name`, " +
|
|
|
" fd.fee, " +
|
|
|
" fd.type, " +
|
|
|
" fd.`number`, " +
|
|
|
" fd.`status`, " +
|
|
|
" dd.doctor_job_name doctorJobName " +
|
|
|
" FROM " +
|
|
|
" wlyy_door_fee_detail fd " +
|
|
|
" LEFT JOIN wlyy_door_doctor dd ON fd.order_id = dd.order_id " +
|
|
|
" WHERE " +
|
|
|
" fd.order_id = '" + id + "'" +
|
|
|
" GROUP BY fd.id";
|
|
|
List<Map<String,Object>> feeDetailList = new ArrayList<>();
|
|
|
try {
|
|
|
feeDetailList = jdbcTemplate.queryForList(sql);
|
|
|
}catch (Exception e){
|
|
|
logger.error("居民工单详情-查询关联服务项费用异常:" + e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
return orderJson;
|
|
|
}
|
|
|
JSONArray itemArray = new JSONArray();
|
|
|
if (!CollectionUtils.isEmpty(feeDetailList)) {
|
|
|
for (Map<String,Object> feeDetailMap : feeDetailList) {
|
|
|
JSONObject itemJson = new JSONObject();
|
|
|
itemJson.put("code",feeDetailMap.get("code"));
|
|
|
itemJson.put("name",feeDetailMap.get("name"));
|
|
|
itemJson.put("fee",feeDetailMap.get("fee"));
|
|
|
itemJson.put("number",feeDetailMap.get("number"));
|
|
|
itemJson.put("status",feeDetailMap.get("status"));
|
|
|
itemJson.put("type",feeDetailMap.get("type"));
|
|
|
itemJson.put("doctorJobName",feeDetailMap.get("doctorJobName"));
|
|
|
itemArray.add(itemJson);
|
|
|
}
|
|
|
}
|
|
|
orderJson.put("itemArray", itemArray);
|
|
|
|
|
|
//关联的医生
|
|
|
List<WlyyDoorDoctorDO> doctorDOList = wlyyDoorDoctorDao.findByOrderId(id);
|
|
|
JSONArray doctoryArray = new JSONArray();
|
|
|
if (!CollectionUtils.isEmpty(doctorDOList)) {
|
|
|
for (WlyyDoorDoctorDO doctorDO : doctorDOList) {
|
|
|
JSONObject doctorJson = new JSONObject();
|
|
|
doctorJson.put("doctor",doctorDO.getDoctor());
|
|
|
doctorJson.put("doctorName",doctorDO.getDoctorName());
|
|
|
doctorJson.put("doctorJobName",doctorDO.getDoctorJobName());
|
|
|
doctoryArray.add(doctorJson);
|
|
|
}
|
|
|
}
|
|
|
orderJson.put("doctoryArray", doctoryArray);
|
|
|
|
|
|
//服务小结登记情况
|
|
|
JSONObject conclusionJson = new JSONObject();
|
|
|
WlyyDoorConclusionDO conclusionDO = wlyyDoorConclusionDao.findByOrderId(orderDO.getId());
|
|
|
if(null != conclusionDO){
|
|
|
conclusionJson.put("time",conclusionDO.getCreateTime());
|
|
|
conclusionJson.put("id",conclusionDO.getId());
|
|
|
}
|
|
|
orderJson.put("conclusion",conclusionJson);
|
|
|
|
|
|
//获取上门前后开方详情
|
|
|
List<WlyyDoorPrescriptionDO> doorBeforePrescriptionDOList = doorPrescriptionDao.findByOrderIdAndIsAfterDoor(id, 1);
|
|
|
List<WlyyDoorPrescriptionDO> doorAfterPrescriptionDOList = doorPrescriptionDao.findByOrderIdAndIsAfterDoor(id, 2);
|
|
|
|
|
|
orderJson.put("doorBeforePrescription",doorBeforePrescriptionDOList);
|
|
|
orderJson.put("doorAfterPrescription", doorAfterPrescriptionDOList);
|
|
|
return orderJson;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成二維碼
|
|
|
* @param id
|
|
|
* @param token
|
|
|
* @return
|
|
|
*/
|
|
|
public String twoDimensionalCode(String id , String token) {
|
|
|
JSONObject orderJson = new JSONObject();
|
|
|
List<WlyyDoorServiceOrderDO> orderList = this.findByField("id", id);
|
|
|
if (orderList.size()>0){
|
|
|
WlyyDoorServiceOrderDO orderDO = orderList.get(0);
|
|
|
Map<String, Object> param = new HashedMap();
|
|
|
String fileUrl = "";
|
|
|
//生成二维码图片
|
|
|
String contentJsonStr=orderDO.getNumber();
|
|
|
InputStream ipt = QrcodeUtil.createQrcode(contentJsonStr, 300, "png");
|
|
|
if (isneiwang) {
|
|
|
// 圖片列表
|
|
|
List<String> tempPaths = new ArrayList<String>();
|
|
|
try {
|
|
|
ObjectNode imgNode = fastDFSUtil.upload(ipt, "png", "plan_service_qrcode" + System.currentTimeMillis());
|
|
|
JSONObject json = JSONObject.parseObject(imgNode.toString());
|
|
|
tempPaths.add(json.getString("fid"));
|
|
|
String urls = "";
|
|
|
for (String image : tempPaths) {
|
|
|
if (urls.length() == 0) {
|
|
|
urls = image;
|
|
|
} else {
|
|
|
urls += "," + image;
|
|
|
}
|
|
|
}
|
|
|
fileUrl = fastdfs_file_url + urls;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
} else {
|
|
|
try {
|
|
|
fileUrl = fastdfs_file_url + PrescriptionQRCodetoNeiWang(ipt);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
System.out.println("服务码-----------1"+fileUrl);
|
|
|
param.put("number", orderDO.getNumber());
|
|
|
param.put("imageUrl",fileUrl);
|
|
|
return fileUrl;
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 长处方生成取药码,生成取药二维码
|
|
|
* 如果是外网那是发送到内网的服务器
|
|
|
* @param ipt
|
|
|
* @return
|
|
|
*/
|
|
|
public String PrescriptionQRCodetoNeiWang(InputStream ipt) throws FileNotFoundException {
|
|
|
String filename = "QRCode_"+System.currentTimeMillis();
|
|
|
String fileUrls = "";
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
String returnStr = request(request, ipt,filename );
|
|
|
logger.info("returnStr :" + returnStr);
|
|
|
logger.info("fileName :" + filename);
|
|
|
logger.info("result :" + returnStr.toString());
|
|
|
if (returnStr != null) {
|
|
|
//1.3.7去掉前缀
|
|
|
fileUrls += returnStr+",";
|
|
|
}
|
|
|
|
|
|
return fileUrls.substring(0,fileUrls.length()-1);
|
|
|
}
|
|
|
|
|
|
public String request(HttpServletRequest request, InputStream in, String fileName) {
|
|
|
String url = neiwangWlyy + "/wlyy/upload/commonUpload";//uri请求路径 http://172.19.103.88/wlyy/upload/chat
|
|
|
|
|
|
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
String result = "";
|
|
|
try {
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
builder.addBinaryBody("file", in, ContentType.MULTIPART_FORM_DATA, fileName);// 文件流
|
|
|
builder.addTextBody("filename", fileName);// 类似浏览器表单提交,对应input的name和value
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(request.getParameter("type")) ||
|
|
|
!org.springframework.util.StringUtils.isEmpty(request.getAttribute("type"))) {
|
|
|
builder.addTextBody("type", null != request.getParameter("type") ? request.getParameter("type") : String.valueOf(request.getAttribute("type"))); //发送类型
|
|
|
}
|
|
|
HttpEntity entity = builder.build();
|
|
|
httpPost.setEntity(entity);
|
|
|
HttpResponse response = httpClient.execute(httpPost);// 执行提交
|
|
|
HttpEntity responseEntity = response.getEntity();
|
|
|
if (responseEntity != null) {
|
|
|
// 将响应内容转换为字符串
|
|
|
result = org.apache.http.util.EntityUtils.toString(responseEntity, Charset.forName("UTF-8"));
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
try {
|
|
|
httpClient.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
try {
|
|
|
in.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 居民端-查询上门服务工单列表(预约咨询记录)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryInfoList(String patient,Integer status, int page, int size) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
status = null == status ? -100 : status;
|
|
|
int start = 0 == page ? page++ : (page - 1) * size;
|
|
|
int end = 0 == size ? 15 : size;
|
|
|
|
|
|
String sql = "SELECT " +
|
|
|
" d.photo AS doctorPhoto, " +
|
|
|
" d.`name` AS doctorName, " +
|
|
|
" d.`job_name` AS doctorJobName, " +
|
|
|
" d.hospital_name AS hospitalName, " +
|
|
|
" d.mobile AS doctorPhone, " +
|
|
|
" o.id, " +
|
|
|
" o.number, " +
|
|
|
" o.total_fee as totalFee, " +
|
|
|
" o.patient_expected_serve_time AS serveTime, " +
|
|
|
" o.serve_desc AS description, " +
|
|
|
" o.`status` AS status, " +
|
|
|
" o.`pay_way` AS payWay, o.type," +
|
|
|
" ifnull(de.order_id,concat(rand(),'_notExist')) AS feeOrderId, " +
|
|
|
" dm.phone AS hospitalPhone, " +
|
|
|
" count(de.number) as itemCount " +
|
|
|
" FROM " +
|
|
|
" ( wlyy_door_service_order o " +
|
|
|
" LEFT JOIN wlyy_doctor d ON o.doctor = d.`code`) " +
|
|
|
" LEFT JOIN wlyy_door_fee_detail de on o.id = de.order_id " +
|
|
|
" LEFT JOIN dm_hospital dm on o.hospital = dm.code " +
|
|
|
" WHERE " +
|
|
|
" (o.patient = '{patient}' " +
|
|
|
// "or o.proxy_patient = '{patient}'" +
|
|
|
") " +
|
|
|
" AND (o.`status` = {status} or -100 = {status})" +
|
|
|
" group by o.id " +
|
|
|
" ORDER BY o.create_time desc" +
|
|
|
" LIMIT {start},{end};";
|
|
|
|
|
|
String finalSql = sql.replace("{patient}", patient)
|
|
|
.replace("{status}", String.valueOf(status))
|
|
|
.replace("{start}", String.valueOf(start))
|
|
|
.replace("{end}", String.valueOf(end));
|
|
|
|
|
|
String countSql = "SELECT " +
|
|
|
" count(DISTINCT o.id) " +
|
|
|
" FROM " +
|
|
|
" ( wlyy_door_service_order o " +
|
|
|
" LEFT JOIN wlyy_doctor d ON o.doctor = d.`code`) " +
|
|
|
" LEFT JOIN wlyy_door_fee_detail de on o.id = de.order_id " +
|
|
|
" LEFT JOIN dm_hospital dm on o.hospital = dm.code " +
|
|
|
" WHERE " +
|
|
|
" (o.patient = '{patient}' or o.proxy_patient = '{patient}') " +
|
|
|
" AND (o.`status` = {status} or -100 = {status})";
|
|
|
|
|
|
String finqlCountSql = countSql.replace("{patient}", patient)
|
|
|
.replace("{status}", String.valueOf(status));
|
|
|
|
|
|
List sqlResultlist = new ArrayList<>();
|
|
|
logger.info("infoList-info: "+finalSql);
|
|
|
logger.info("infoList-count: "+finqlCountSql);
|
|
|
try {
|
|
|
sqlResultlist = jdbcTemplate.queryForList(finalSql);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "从数据库上门服务工单列表信息失败:" + e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Integer count = 0;
|
|
|
try {
|
|
|
count = jdbcTemplate.queryForObject(finqlCountSql, Integer.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "从数据库统计上门服务工单数量失败:" + e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, sqlResultlist);
|
|
|
JSONObject countItem = new JSONObject();
|
|
|
countItem.put("count", count);
|
|
|
result.putAll(countItem);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 居民端-统计上门服务工单各状态下的数量列表(预约咨询记录)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryInfoStatusCountList(String patient) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
String countSql = "SELECT " +
|
|
|
" count(o.id) as count, " +
|
|
|
" o.status as status " +
|
|
|
" FROM " +
|
|
|
" wlyy_door_service_order o " +
|
|
|
" WHERE " +
|
|
|
" o.patient = '"+ patient + "' " +
|
|
|
// "or o.proxy_patient = '"+ patient + "'" +
|
|
|
" GROUP BY o.`status`";
|
|
|
|
|
|
List<Map<String,Object>> countMapList = new ArrayList();
|
|
|
try {
|
|
|
countMapList = jdbcTemplate.queryForList(countSql);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "统计上门服务工单各状态下的数量列表失败:" + e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, countMapList);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 居民端-居民付款
|
|
|
* @param orderId
|
|
|
* @param payWay
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean payOrder(String orderId,int payWay) {
|
|
|
WlyyDoorServiceOrderDO doorServiceOrderDO = wlyyDoorServiceOrderDao.findOne(orderId);
|
|
|
if(null == doorServiceOrderDO){
|
|
|
return false;
|
|
|
}
|
|
|
doorServiceOrderDO.setPayWay(payWay);
|
|
|
doorServiceOrderDO.setPayTime(new Date());
|
|
|
wlyyDoorServiceOrderDao.save(doorServiceOrderDO);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int updateOrderInfo(String orderId) {
|
|
|
String sql = "UPDATE `wlyy_door_service_order` SET order_info =2 WHERE id = ?";
|
|
|
Object [] params = new Object[]{orderId};
|
|
|
int a = jdbcTemplate.update(sql , params);
|
|
|
return a;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 服务工单居民确认操作日志记录
|
|
|
*
|
|
|
* {
|
|
|
* "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) {
|
|
|
WlyyDoorPatientConfirmLogDO confirmLogDO = null;
|
|
|
try {
|
|
|
confirmLogDO = EntityUtils.jsonToEntity(confirmInfo.toString(), WlyyDoorPatientConfirmLogDO.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 {
|
|
|
wlyyDoorPatientConfirmLogDao.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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消工单
|
|
|
* @param orderId
|
|
|
* @param type 取消类型
|
|
|
* @param reason 取消理由
|
|
|
*/
|
|
|
public JSONObject cancelOrder(String orderId,int type,String reason,String dispatcher,String dispatcherName){
|
|
|
JSONObject result = new JSONObject();
|
|
|
WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.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() > WlyyDoorServiceOrderDO.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);
|
|
|
}
|
|
|
orderDO.setStatus(WlyyDoorServiceOrderDO.Status.cancel.getType());
|
|
|
this.save(orderDO);
|
|
|
|
|
|
//如果是调度员取消,推送IM取消工单json消息,
|
|
|
/* if(type == WlyyDoorServiceOrderDO.CancelType.dispatcher.getType()){
|
|
|
JSONObject content = this.queryOrderCardInfo(orderDO);
|
|
|
content.put("title","工单已取消");
|
|
|
// this.qucikSendIM(orderId,dispatcher,dispatcherName,"2101",content.toJSONString());
|
|
|
|
|
|
List<BaseMessageDO> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{402,403,430});
|
|
|
if(CollectionUtils.isEmpty(messages)){
|
|
|
logger.error("当前工单没有系统消息!!orderId:" + orderId);
|
|
|
} else {
|
|
|
// 432 调度员拒单即取消工单-- 李四拒绝了张三的服务工单12345678
|
|
|
messages.forEach(
|
|
|
message -> {
|
|
|
if (message.getType() == 430) {
|
|
|
message.setTitle("调度员拒单");
|
|
|
message.setContent(orderDO.getDispatcherName() + "拒绝了"+ orderDO.getPatientName() +"的服务工单" + orderDO.getNumber());
|
|
|
message.setType(432);
|
|
|
message.setReceiver(dispatcher);
|
|
|
message.setSender(dispatcher);
|
|
|
message.setCreateTime(new Date());
|
|
|
}else{
|
|
|
message.setOver("0");
|
|
|
}
|
|
|
messageDao.save(message);
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
else if(type == WlyyDoorServiceOrderDO.CancelType.patient.getType()){ //居民取消,消息列表也应该不显示
|
|
|
|
|
|
List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{402,403});
|
|
|
if(CollectionUtils.isEmpty(messages)){
|
|
|
logger.error("当前工单没有系统消息!!orderId:" + orderId);
|
|
|
} else {
|
|
|
messages.forEach(
|
|
|
message -> {
|
|
|
message.setOver("0");
|
|
|
messageDao.save(message);
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
//保存取消记录
|
|
|
WlyyDoorCancelLogDO cancelLogDO = new WlyyDoorCancelLogDO();
|
|
|
cancelLogDO.setOrderId(orderId);
|
|
|
cancelLogDO.setPatient(orderDO.getProxyPatient());
|
|
|
cancelLogDO.setCancelType(type);
|
|
|
cancelLogDO.setCancelReason(reason);
|
|
|
cancelLogDO.setTime(orderDO.getCancelTime());
|
|
|
wlyyDoorCancelLogDao.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);
|
|
|
|
|
|
/* Consult consult = consultDao.queryByRelationCode(orderId);
|
|
|
// 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
|
|
|
Patient patient = patientInfoService.findByCode(orderDO.getPatient());
|
|
|
WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","smyyyqx");
|
|
|
String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
|
|
|
org.json.JSONObject json = new org.json.JSONObject();
|
|
|
json.put("first", first);
|
|
|
json.put("keyword1", DateUtil.dateToStrShort(new Date()));
|
|
|
json.put("keyword2", "上门预约已取消");
|
|
|
json.put("url", templateConfig.getUrl());
|
|
|
json.put("remark", templateConfig.getRemark());
|
|
|
if(consult != null) {
|
|
|
json.put("consult", consult.getCode());
|
|
|
}else {
|
|
|
json.put("id", orderDO.getId());
|
|
|
}
|
|
|
pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json);*/
|
|
|
|
|
|
// 工单状态变更记录
|
|
|
WlyyDoorProcessLogDO processLogDO = new WlyyDoorProcessLogDO();
|
|
|
processLogDO.setOrderId(orderId);
|
|
|
processLogDO.setStatus(WlyyDoorServiceOrderDO.Status.cancel.getType());
|
|
|
processLogDO.setDispatcher(dispatcher);
|
|
|
processLogDO.setDispatcherName(dispatcherName);
|
|
|
wlyyDoorProcessLogDao.save(processLogDO);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, "工单服务已取消!");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public JSONObject orderMsgTask(String orderId){
|
|
|
JSONObject result = new JSONObject();
|
|
|
WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(orderId);
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
// 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
|
|
|
/* BasePatientDO patient = patientDao.findById(orderDO.getPatient());
|
|
|
WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","smyyyqx");
|
|
|
String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
|
|
|
org.json.JSONObject json = new org.json.JSONObject();
|
|
|
json.put("first", orderDO.getPatientName()+",您好!您的上门服务知情同意书已送达");
|
|
|
json.put("keyword1", DateUtil.dateToStrShort(new Date()));
|
|
|
json.put("keyword2", "知情同意书已推送");
|
|
|
// json.put("url", templateConfig.getUrl());
|
|
|
json.put("url", "appoint_service/html/appoint-serviceDetail.html?id="+orderId);
|
|
|
// appoint_service/html/appoint-serviceDetail.html?openid=ojsU-1XJVftkfdbP1F5bi8JVPtOo&consult=e0d17c67ab07477f8e96534bc610e51b
|
|
|
json.put("remark", templateConfig.getRemark());
|
|
|
if(consult != null) {
|
|
|
json.put("consult", consult.getCode());
|
|
|
}else {
|
|
|
json.put("id", orderDO.getId());
|
|
|
}
|
|
|
pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json);*/
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 统计居民一个月内工单取消次数
|
|
|
* @param patient
|
|
|
*/
|
|
|
public int countPtientCancelTimesOneMonth(String patient){
|
|
|
if(StringUtils.isEmpty(patient)){
|
|
|
return 100;
|
|
|
}
|
|
|
Integer count = wlyyDoorCancelLogDao.countCancelTimes(patient);
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询预约简要卡片信息
|
|
|
*
|
|
|
* 服务时间:2019-01-01 12:30
|
|
|
* 服务对象:张三
|
|
|
* 联系电话:13125256565(儿子)
|
|
|
* 上门地址:福建省厦门市思明区望海路55号
|
|
|
*
|
|
|
* @param orderDO
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryOrderCardInfo(WlyyDoorServiceOrderDO 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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改预约简要卡片信息
|
|
|
*
|
|
|
* 服务时间:2019-01-01 12:30
|
|
|
* 服务对象:张三
|
|
|
* 联系电话:13125256565(儿子)
|
|
|
* 上门地址:福建省厦门市思明区望海路55号
|
|
|
*
|
|
|
* {
|
|
|
* "orderId":"",
|
|
|
* "doctorArrivingTime":"",
|
|
|
* "patientName":"",
|
|
|
* "phone:"",
|
|
|
* "serveAddress:"",
|
|
|
* "serveLat:"",
|
|
|
* "serveLon:"",
|
|
|
* "serveTown:"",
|
|
|
* "serveAddress:"",
|
|
|
* }
|
|
|
*
|
|
|
* @param jsonData
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject updateOrderCardInfo(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;
|
|
|
}
|
|
|
WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findOne(jsonObjectParam.getString("orderId"));
|
|
|
|
|
|
wlyyDoorServiceOrder.setPatientName(jsonObjectParam.getString("patientName"));
|
|
|
|
|
|
// wlyyDoorServiceOrder.setProxyPatientPhone(jsonObjectParam.getString("phone"));
|
|
|
// 居民电话
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("phone"))){
|
|
|
wlyyDoorServiceOrder.setPatientPhone(jsonObjectParam.getString("phone"));
|
|
|
}
|
|
|
// 医生预计达到时间
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("doctorArrivingTime"))){
|
|
|
wlyyDoorServiceOrder.setDoctorArrivingTime(jsonObjectParam.get("doctorArrivingTime").toString());
|
|
|
}
|
|
|
// 居民期望服务时间
|
|
|
// if(!StringUtils.isEmpty(jsonObjectParam.getString("patientExpectedServeTime"))){
|
|
|
wlyyDoorServiceOrder.setPatientExpectedServeTime(jsonObjectParam.get("patientExpectedServeTime").toString());
|
|
|
// }
|
|
|
// 服务区
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("serveTown"))){
|
|
|
wlyyDoorServiceOrder.setServeTown(jsonObjectParam.getString("serveTown"));
|
|
|
}
|
|
|
// 服务地址
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("serveAddress"))){
|
|
|
wlyyDoorServiceOrder.setServeAddress(jsonObjectParam.getString("serveAddress"));
|
|
|
}
|
|
|
wlyyDoorServiceOrder.setServeAddress(jsonObjectParam.getString("serveAddress"));
|
|
|
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("serveLat"))){
|
|
|
wlyyDoorServiceOrder.setServeLat(jsonObjectParam.getString("serveLat"));
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("serveLon"))){
|
|
|
wlyyDoorServiceOrder.setServeLon(jsonObjectParam.getString("serveLon"));
|
|
|
}
|
|
|
// 服务描述
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("serveDesc"))){
|
|
|
wlyyDoorServiceOrder.setServeDesc(jsonObjectParam.getString("serveDesc"));
|
|
|
}
|
|
|
//服务类型 医生端和居民端公用接口
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("serviceStatus"))){
|
|
|
wlyyDoorServiceOrder.setServiceStatus(jsonObjectParam.getString("serviceStatus"));
|
|
|
}else {
|
|
|
wlyyDoorServiceOrder.setServiceStatus("1");//默认为1 预约项目
|
|
|
}
|
|
|
// wlyyDoorServiceOrder.setIsPatientConfirm(WlyyDoorServiceOrderDO.IsPatientConfirm.yes.getType());
|
|
|
// wlyyDoorServiceOrder.setPatientConfirmTime(new Date());
|
|
|
this.save(wlyyDoorServiceOrder);
|
|
|
|
|
|
//新增工单居民确认操作日志记录
|
|
|
if (orderWithConfirmLogAdd(result, jsonObjectParam, wlyyDoorServiceOrder.getId())) {return result;}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, wlyyDoorServiceOrder);
|
|
|
|
|
|
|
|
|
//发送 预约卡片信息(2101类型)
|
|
|
JSONObject orderInfoContent = this.queryOrderCardInfo(wlyyDoorServiceOrder);
|
|
|
orderInfoContent.put("re_msg_type",1);//医生修改待确认
|
|
|
this.qucikSendIM(wlyyDoorServiceOrder.getId(), wlyyDoorServiceOrder.getDispatcher(), "智能助手", "2101", orderInfoContent.toJSONString());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 医生更新上门信息
|
|
|
*
|
|
|
* 预计到达:2019-01-01 09:00
|
|
|
* 服务医生:张三(全科医生)、王五(健管师)
|
|
|
*
|
|
|
* {
|
|
|
* "orderId":"",
|
|
|
* "doctorArrivingTime":"",
|
|
|
* "doctorArr":[
|
|
|
* {
|
|
|
* "doctor":"",
|
|
|
* "doctorName":"",
|
|
|
* "doctorLevel":3,
|
|
|
* "doctorJobCode":"",
|
|
|
* "doctorJobName":"",
|
|
|
* }
|
|
|
* ],
|
|
|
* "deleteDoctorArr":[
|
|
|
* {
|
|
|
* "id":""
|
|
|
* },
|
|
|
* {
|
|
|
* "id":""
|
|
|
* }
|
|
|
* ]
|
|
|
* }
|
|
|
* @param jsonData
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject updateDoctorInfo(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;
|
|
|
}
|
|
|
|
|
|
WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findOne(jsonObjectParam.getString("orderId"));
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("doctorArrivingTime"))) {
|
|
|
wlyyDoorServiceOrder.setDoctorArrivingTime(jsonObjectParam.getString("doctorArrivingTime"));
|
|
|
}
|
|
|
//添加居民同意状态
|
|
|
wlyyDoorServiceOrder.setIsPatientConfirm(1);
|
|
|
wlyyDoorServiceOrder.setPatientConfirmTime(new Date());
|
|
|
wlyyDoorServiceOrder.setUpdateTime(new Date());
|
|
|
this.save(wlyyDoorServiceOrder);
|
|
|
|
|
|
//修改时有更改到关联关系,则先删除原有关联关系,再新增关联关系
|
|
|
//删除工单原来医生的关联关系
|
|
|
// 删除出诊医生或服务项
|
|
|
this.orderWithFeeDelete(jsonObjectParam,wlyyDoorServiceOrder);
|
|
|
|
|
|
//新增工单医生关联关系
|
|
|
if (orderWithDoctorAdd(result, jsonObjectParam, wlyyDoorServiceOrder)) {return result;}
|
|
|
|
|
|
//新增工单居民确认操作日志记录
|
|
|
if (orderWithConfirmLogAdd(result, jsonObjectParam, wlyyDoorServiceOrder.getId())) {return result;}
|
|
|
|
|
|
//微信模板消息-反馈处理通知
|
|
|
// pushMsgTask.putWxMsg(tokenUtils.getAccessToken(),30,);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, wlyyDoorServiceOrder);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public List filterPatientType(List data,String type){
|
|
|
String[] types = type.split(",");
|
|
|
Set<String> patientSet = doorServiceVoucherDao.queryByTypeIn(types);
|
|
|
if(CollectionUtils.isEmpty(patientSet)){
|
|
|
return data;
|
|
|
}
|
|
|
// data.forEach();
|
|
|
return data;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 调度员-查询-工单列表
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryBriefList(String dispatcher,String hospital,String orderNumber,String patientName,String phone,Integer status, String patientType,int page, int size) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
orderNumber = null == orderNumber ? "" : orderNumber;
|
|
|
patientName = null == patientName ? "" : patientName;
|
|
|
phone = null == phone ? "" : phone;
|
|
|
status = null == status ? -100 : status;
|
|
|
int start = 0 == page ? page++ : (page - 1) * size;
|
|
|
int end = 0 == size ? 15 : page * size;
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
if (StringUtils.isNoneBlank(orderNumber)){
|
|
|
buffer.append(" AND ( o.`number` like '%"+orderNumber+"%' ) ");
|
|
|
}else if (StringUtils.isNoneBlank(patientName)){
|
|
|
buffer.append(" AND o.`patient_name` like '%"+patientName+"%' ");
|
|
|
}else if (StringUtils.isNoneBlank(phone)){
|
|
|
buffer.append(" AND o.`proxy_patient_phone` like '%"+phone+"%'");
|
|
|
}
|
|
|
String sql = "SELECT " +
|
|
|
" p.name AS patientName, " +
|
|
|
" p.photo AS photo, " +
|
|
|
" case p.sex " +
|
|
|
" when 1 then '男' " +
|
|
|
" when 2 then '女' " +
|
|
|
" end AS sex, " +
|
|
|
" TIMESTAMPDIFF(year,p.birthday,NOW()) AS age," +
|
|
|
" o.id as orderId, " +
|
|
|
" o.patient_phone as phone, " +
|
|
|
" o.proxy_patient as proxyPatient, " +
|
|
|
" o.patient as patient, " +
|
|
|
" o.number as number, " +
|
|
|
" o.patient_expected_serve_time as serveTime, o.doctor, o.doctor_name as doctorName, " +
|
|
|
" o.serve_address as address, " +
|
|
|
" o.serve_lon as lon, " +
|
|
|
" o.serve_lat as lat, " +
|
|
|
" o.`status` as status, " +
|
|
|
" o.`dispatcher_name` as dispatcherName, " +
|
|
|
" concat( o.patient,'_' ,c.`code`, '_',o.`number`,'_11' ) as sessionId, " +
|
|
|
" t1.`type` as patientType " +
|
|
|
" FROM " +
|
|
|
" ( wlyy_door_service_order o " +
|
|
|
"LEFT JOIN wlyy_patient p ON o.patient = p.`code` ) LEFT JOIN wlyy_consult c on o.id = c.relation_code" +
|
|
|
" JOIN ( " +
|
|
|
" select a.patient, group_concat(v.type) as type " +
|
|
|
" from wlyy_door_service_voucher v " +
|
|
|
" JOIN (select t.id, t.patient, max(t.create_time) " +
|
|
|
" from wlyy_door_service_application t " +
|
|
|
" where t.status in (2, 3) " +
|
|
|
" group by t.patient) as a " +
|
|
|
" on a.id = v.service_id " +
|
|
|
" where v.status = 1 " +
|
|
|
" group by a.patient " +
|
|
|
" ) as t1 on o.patient = t1.patient" +
|
|
|
" WHERE " +
|
|
|
" o.hospital = '{hospital}' and o.type != 3 " +buffer+
|
|
|
" AND ( o.`status` = {status} OR -100 = {status} ) " +
|
|
|
" ORDER BY o.create_time desc " +
|
|
|
" LIMIT {start},{end};";
|
|
|
|
|
|
|
|
|
String finalSql = sql.replace("{hospital}", hospital)
|
|
|
.replace("{status}", String.valueOf(status))
|
|
|
.replace("{start}", String.valueOf(start))
|
|
|
.replace("{end}", String.valueOf(end));
|
|
|
|
|
|
String countSql = "SELECT " +
|
|
|
" count(o.id) " +
|
|
|
" FROM " +
|
|
|
" wlyy_door_service_order o " +
|
|
|
" LEFT JOIN wlyy_patient p ON o.patient = p.`code` " +
|
|
|
" JOIN ( " +
|
|
|
" select a.patient, group_concat(v.type) as type " +
|
|
|
" from wlyy_door_service_voucher v " +
|
|
|
" JOIN (select t.id, t.patient, max(t.create_time) " +
|
|
|
" from wlyy_door_service_application t " +
|
|
|
" where t.status in (2, 3) " +
|
|
|
" group by t.patient) as a " +
|
|
|
" on a.id = v.service_id " +
|
|
|
" where v.status = 1 " +
|
|
|
" group by a.patient " +
|
|
|
" ) as t1 on o.patient = t1.patient" +
|
|
|
" WHERE " +
|
|
|
" o.hospital = '{hospital}' " +buffer+
|
|
|
" AND (o.`status` = {status} or -100 = {status})";
|
|
|
|
|
|
String finqlCountSql = countSql.replace("{hospital}", hospital)
|
|
|
.replace("{status}", String.valueOf(status));
|
|
|
|
|
|
List<Map<String,Object>> sqlResultlist = new ArrayList<>();
|
|
|
try {
|
|
|
sqlResultlist = jdbcTemplate.queryForList(finalSql);
|
|
|
logger.info(finalSql);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "从数据库查询【调度员】上门服务工单列表信息失败:" + e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Integer count = 0;
|
|
|
try {
|
|
|
count = jdbcTemplate.queryForObject(finqlCountSql, Integer.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "从数据库统计【调度员】上门服务工单数量失败:" + e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
List filteredResult = new ArrayList();
|
|
|
String[] types = null;
|
|
|
if(!StringUtils.isEmpty(patientType)){
|
|
|
types = patientType.split(",");
|
|
|
}else{
|
|
|
types = new String[]{"1","2","3","4","5","6"};
|
|
|
}
|
|
|
String serviceSql = "SELECT count(d.id) times FROM wlyy_door_doctor d where d.order_id in(SELECT id from wlyy_door_service_order WHERE DATE_FORMAT(doctor_sign_time, '%Y') = DATE_FORMAT(NOW(), '%Y') AND patient=?)";
|
|
|
sqlResultlist.forEach(
|
|
|
oneMap -> {
|
|
|
// 获取服务次数
|
|
|
Integer serviceCount = jdbcTemplate.queryForObject(serviceSql, Integer.class, oneMap.get("patient")+"");
|
|
|
oneMap.put("serviceCount", serviceCount);
|
|
|
oneMap.put("isInSession",false);
|
|
|
String sessionId = String.valueOf(oneMap.get("sessionId"));
|
|
|
JSONArray parArray = imUtill.getParticipants(sessionId);
|
|
|
parArray.forEach(
|
|
|
oneParObj -> {
|
|
|
org.json.JSONObject oneParJson = (org.json.JSONObject)oneParObj;
|
|
|
if(StringUtils.equalsIgnoreCase(oneParJson.getString("id"),dispatcher)){
|
|
|
oneMap.put("isInSession",true);
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
});
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, sqlResultlist);
|
|
|
JSONObject countItem = new JSONObject();
|
|
|
countItem.put("count", count);
|
|
|
result.putAll(countItem);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 调度员-查询-服务人员列表(医生)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryDoctorList(String patient,String hospital,String doctorName,String status, int page, int size) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
doctorName = null == doctorName ? "" : doctorName;
|
|
|
if(StringUtils.isBlank(status)) {
|
|
|
status = "-100";
|
|
|
}
|
|
|
int start = 0 == page ? page++ : (page - 1) * size;
|
|
|
int end = 0 == size ? 15 : size;
|
|
|
|
|
|
//
|
|
|
String sql = "SELECT " +
|
|
|
" d.code as doctor, " +
|
|
|
" d.photo as photo, " +
|
|
|
" d.name as name," +
|
|
|
" case d.sex " +
|
|
|
" when 0 then '无' " +
|
|
|
" when 1 then '男' " +
|
|
|
" when 2 then '女' " +
|
|
|
" end as sex, " +
|
|
|
" d.`job_name` AS jobName, " +
|
|
|
" d.mobile as phone, " +
|
|
|
" IFNULL(ds.`status`,5) as status," +
|
|
|
" 1 as sortFlag ,count(o.id) as count" +
|
|
|
" FROM " +
|
|
|
" wlyy_doctor d " +
|
|
|
" LEFT JOIN wlyy_door_doctor_status ds ON d.`code` = ds.doctor LEFT JOIN wlyy_door_service_order o on o.doctor = d.code and o.`status` in (2,3,4) " +
|
|
|
" WHERE d.status = 1" +
|
|
|
" AND d.level <> 11" +
|
|
|
" AND d.hospital = '{hospital}' " +
|
|
|
" AND d.`name` like '%{doctorName}%' " +
|
|
|
" AND (ds.`status` in ({status}) or '-100' = '{status}')" +
|
|
|
" AND d.del=1 " +
|
|
|
" GROUP BY d.`code` ORDER BY ds.create_time DESC " +
|
|
|
" LIMIT {start},{end}";
|
|
|
|
|
|
String finalSql = sql.replace("{hospital}", hospital)
|
|
|
.replace("{doctorName}", doctorName)
|
|
|
.replace("{status}", String.valueOf(status))
|
|
|
.replace("{start}", String.valueOf(start))
|
|
|
.replace("{end}", String.valueOf(end));
|
|
|
|
|
|
String countSql = "SELECT " +
|
|
|
" count(d.id) " +
|
|
|
" FROM " +
|
|
|
" wlyy_doctor d " +
|
|
|
" LEFT JOIN wlyy_door_doctor_status ds ON d.`code` = ds.doctor " +
|
|
|
" WHERE d.status = 1" +
|
|
|
" AND d.level <> 4" +
|
|
|
" AND d.hospital = '{hospital}' "+
|
|
|
" AND d.`name` like '%{doctorName}%' " +
|
|
|
" AND d.del=1 and d.status=1 " +
|
|
|
" AND (ds.`status` in ({status}) or '-100' = '{status}')";
|
|
|
|
|
|
String finalCountSql = countSql.replace("{hospital}", hospital)
|
|
|
.replace("{doctorName}", doctorName)
|
|
|
.replace("{status}", String.valueOf(status));
|
|
|
|
|
|
List<Map<String,Object>> sqlResultlist = new ArrayList<>();
|
|
|
try {
|
|
|
sqlResultlist = jdbcTemplate.queryForList(finalSql);
|
|
|
if (sqlResultlist!=null&&sqlResultlist.size()!=0){
|
|
|
for (Map<String,Object> map:sqlResultlist){
|
|
|
/* BaseDoctorDO doctor = doctorDao.findById(map.get("doctor").toString());
|
|
|
BaseOrgDO hospital1 = hospitalDao.findByCode(doctor.getHospital());
|
|
|
if (doctor.getPosition()==null||doctor.getPosition()==""){
|
|
|
map.put("position",hospital1.getPosition());
|
|
|
}else {
|
|
|
map.put("position",doctor.getPosition());
|
|
|
}*/
|
|
|
map.put("position","117.13,36.18");
|
|
|
}
|
|
|
}
|
|
|
logger.info("服务医生人员sql:"+finalSql);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "从数据库查询 服务医生人员 列表信息失败:" + e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Integer count = 0;
|
|
|
try {
|
|
|
count = jdbcTemplate.queryForObject(finalCountSql, Integer.class);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "从数据库统计 服务医生人员 数量失败:" + e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
//添加未完成服务工单列表
|
|
|
for(Map<String,Object> map : sqlResultlist){
|
|
|
String doctor = map.get("doctor") + "";
|
|
|
Long notFinish = (Long) map.get("count");
|
|
|
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 " +
|
|
|
"where o.doctor ='"+doctor + "' and o.status in (2,3,4)";
|
|
|
List<Map<String, Object>> notFinishList = jdbcTemplate.queryForList(notFinishSql);
|
|
|
map.put("notFinishList", notFinishList);
|
|
|
}
|
|
|
}
|
|
|
// 居民端第一页置顶家庭医生
|
|
|
/* if(!StringUtils.isEmpty(patient) && page == 1){
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patient);
|
|
|
if(null != signFamily){
|
|
|
String signDoctor = signFamily.getDoctor();
|
|
|
String signDoctorName = signFamily.getDoctorName();
|
|
|
//判断当前居民是否有家庭医生
|
|
|
boolean doctorExist = wlyyDoorDoctorStatusDao.existsByDoctorAndStatusIn(signDoctor,new Integer[]{1,2,3,4});
|
|
|
if(doctorExist){
|
|
|
boolean bool = false;
|
|
|
Map<String,Object> signDoctorMap = new HashMap<>();
|
|
|
for(Map<String,Object> oneDoctorMap : sqlResultlist){
|
|
|
bool = oneDoctorMap.containsValue(signDoctor);
|
|
|
if(bool){
|
|
|
oneDoctorMap.put("sortFlag",0L);
|
|
|
oneDoctorMap.put("isSignDoctor",true);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(!bool){
|
|
|
//查出家签医生置顶
|
|
|
String signDocSql="SELECT " +
|
|
|
" d. CODE AS doctor, " +
|
|
|
" d.photo AS photo, " +
|
|
|
" d. NAME AS name, " +
|
|
|
" CASE d.sex " +
|
|
|
"WHEN 0 THEN " +
|
|
|
" '无' " +
|
|
|
"WHEN 1 THEN " +
|
|
|
" '男' " +
|
|
|
"WHEN 2 THEN " +
|
|
|
" '女' " +
|
|
|
"END AS sex, " +
|
|
|
" d.`job_name` AS jobName, " +
|
|
|
" d.mobile AS phone, " +
|
|
|
" IFNULL(ds.`status`, 5) AS STATUS, " +
|
|
|
" 0 AS sortFlag, " +
|
|
|
" count(o.id) AS count " +
|
|
|
"FROM " +
|
|
|
" wlyy_doctor d " +
|
|
|
"LEFT JOIN wlyy_door_doctor_status ds ON d.`code` = ds.doctor " +
|
|
|
"LEFT JOIN wlyy_door_service_order o ON o.doctor = d. CODE " +
|
|
|
"AND o.`status` IN (2, 3, 4) " +
|
|
|
"WHERE " +
|
|
|
" d. STATUS = 1 AND d.hospital = '" + hospital + "'" +
|
|
|
" and d.name like '%"+doctorName+"%'" +
|
|
|
"AND d.`code` = '" + signDoctor + "'";
|
|
|
sqlResultlist.addAll(jdbcTemplate.queryForList(signDocSql));
|
|
|
// count += 1;
|
|
|
}
|
|
|
sqlResultlist.sort(comparing((doctor) -> Integer.parseInt(doctor.get("sortFlag").toString())));
|
|
|
}
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, sqlResultlist);
|
|
|
JSONObject countItem = new JSONObject();
|
|
|
countItem.put("count", count);
|
|
|
result.putAll(countItem);
|
|
|
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 ds.doctor,d.name, d.job_name as jobName, 1 as sortFlag " +
|
|
|
" from wlyy_door_doctor_status ds " +
|
|
|
" JOIN (select * from wlyy_doctor where hospital = '" + hospital + "') d on ds.doctor = d.code " +
|
|
|
" where ds.status in (1,2,3,4)" +
|
|
|
" limit " + start + "," + end ;
|
|
|
|
|
|
String countSql = "select count(ds.id) " +
|
|
|
"from wlyy_door_doctor_status ds " +
|
|
|
" JOIN (select * from wlyy_doctor where hospital = '" + hospital + "') d on ds.doctor = d.code " +
|
|
|
"where ds.status in (1,2,3,4)";
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/* SignFamily signFamily = signFamilyDao.findByPatient(patient);
|
|
|
if(null != signFamily){
|
|
|
String signDoctor = signFamily.getDoctor();
|
|
|
String signDoctorName = signFamily.getDoctorName();
|
|
|
//判断当前居民是否有家庭医生
|
|
|
boolean doctorExist = wlyyDoorDoctorStatusDao.existsByDoctorAndStatusIn(signDoctor,new Integer[]{1,2,3,4});
|
|
|
if(doctorExist){
|
|
|
// 获取签约医生职称
|
|
|
String querySignJobSql = "select ifnull(job_name,'no_job') from wlyy_doctor where code = '"+ signDoctor + "'";
|
|
|
String signDoctorJobName = jdbcTemplate.queryForObject(querySignJobSql,String.class);
|
|
|
if(StringUtils.equalsIgnoreCase("no_job",signDoctorJobName)){
|
|
|
String failMsg = "当前居民的签约医生没有职称,signDoctor = " + signDoctor;
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
Map<String,Object> signDoctorMap = new HashMap<>();
|
|
|
signDoctorMap.put("doctor",signDoctor);
|
|
|
signDoctorMap.put("jobName",signDoctorJobName);
|
|
|
signDoctorMap.put("name",signFamily.getDoctorName());
|
|
|
signDoctorMap.put("sortFlag",1L);
|
|
|
int signDoctorIndex = doctorList.indexOf(signDoctorMap);
|
|
|
if(signDoctorIndex != -1){
|
|
|
Map<String,Object> originalSignDoctorMap = doctorList.get(signDoctorIndex);
|
|
|
originalSignDoctorMap.put("isSignDoctor",true);
|
|
|
originalSignDoctorMap.put("sortFlag",0L);
|
|
|
|
|
|
}else{
|
|
|
// 表示新增了一个
|
|
|
signDoctorMap.put("name",signDoctorName);
|
|
|
signDoctorMap.put("isSignDoctor",true);
|
|
|
signDoctorMap.put("sortFlag",0L);
|
|
|
doctorList.add(signDoctorMap);
|
|
|
count += 1;
|
|
|
}
|
|
|
doctorList.sort(comparing((doctor) -> Integer.parseInt(doctor.get("sortFlag").toString())));
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
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 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();
|
|
|
|
|
|
WlyyDoorServiceOrderDO doorServiceOrderDO = wlyyDoorServiceOrderDao.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;
|
|
|
}
|
|
|
|
|
|
WlyyDoorDoctorStatusDO doorDoctorStatusDO = wlyyDoorDoctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{WlyyDoorDoctorStatusDO.Status.waitForSend.getType(),
|
|
|
WlyyDoorDoctorStatusDO.Status.waitForAccept.getType(),
|
|
|
WlyyDoorDoctorStatusDO.Status.waitForServe.getType(),
|
|
|
WlyyDoorDoctorStatusDO.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(WlyyDoorDoctorStatusDO.Status.waitForAccept.getType());
|
|
|
doorServiceOrderDO.setUpdateUser(dispatcher);
|
|
|
doorServiceOrderDO.setUpdateUserName(dispathcherName);
|
|
|
doorServiceOrderDO.setDispatcherResponseTime(new Date());
|
|
|
this.save(doorServiceOrderDO);
|
|
|
|
|
|
// 给医生发派单消息
|
|
|
if(WlyyDoorServiceOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
|
|
|
this.createMessage(orderId,doorServiceOrderDO.getTransedDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
|
|
|
}else{
|
|
|
this.createMessage(orderId,doorServiceOrderDO.getDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
|
|
|
}
|
|
|
//发送智能助手消息
|
|
|
sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
|
|
|
|
|
|
// 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
|
|
|
imUtill.updateParticipant(sessionId,doctor,null);
|
|
|
|
|
|
// 调度员处理完该单(新增预约的,或者是拒单重新派单的)
|
|
|
/* List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{402,404,430,435});
|
|
|
if(CollectionUtils.isEmpty(messages)){
|
|
|
logger.error("当前工单没有 居民新增预约 消息!!orderId:" + orderId);
|
|
|
}else{
|
|
|
// 设置消息处理完毕
|
|
|
messages.forEach(
|
|
|
message -> {
|
|
|
String title = "调度员派单(派给本社区医生)";
|
|
|
if("system".equals(dispatcher)){
|
|
|
title = "系统派单(派给服务医生)";
|
|
|
}
|
|
|
if (message.getType() == 430) {
|
|
|
message.setTitle(title);
|
|
|
message.setContent(doorServiceOrderDO.getDispatcherName() + "已将服务工单" + doorServiceOrderDO.getNumber() + "指派给" + doctorName + "医生");
|
|
|
message.setType(431);
|
|
|
message.setReceiver(dispatcher);
|
|
|
message.setSender(dispatcher);
|
|
|
message.setCreateTime(new Date());
|
|
|
}else{
|
|
|
message.setOver("0");
|
|
|
}
|
|
|
messageDao.save(message);
|
|
|
}
|
|
|
);
|
|
|
}*/
|
|
|
|
|
|
// 工单状态变更记录
|
|
|
WlyyDoorProcessLogDO processLogDO = new WlyyDoorProcessLogDO();
|
|
|
processLogDO.setOrderId(orderId);
|
|
|
processLogDO.setStatus(WlyyDoorServiceOrderDO.Status.waitForAccept.getType());
|
|
|
processLogDO.setDispatcher(dispatcher);
|
|
|
processLogDO.setDispatcherName(dispathcherName);
|
|
|
processLogDO.setCreateTime(new Date());
|
|
|
wlyyDoorProcessLogDao.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();
|
|
|
WlyyDoorServiceOrderDO doorServiceOrderDO = wlyyDoorServiceOrderDao.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;
|
|
|
}
|
|
|
|
|
|
WlyyDoorDoctorStatusDO doorDoctorStatusDO = wlyyDoorDoctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{WlyyDoorDoctorStatusDO.Status.waitForSend.getType(),
|
|
|
WlyyDoorDoctorStatusDO.Status.waitForAccept.getType(),
|
|
|
WlyyDoorDoctorStatusDO.Status.waitForServe.getType(),
|
|
|
WlyyDoorDoctorStatusDO.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(WlyyDoorDoctorStatusDO.Status.waitForAccept.getType());
|
|
|
doorServiceOrderDO.setUpdateUser(dispatcher);
|
|
|
doorServiceOrderDO.setUpdateUserName(dispathcherName);
|
|
|
doorServiceOrderDO.setDispatcherResponseTime(new Date());
|
|
|
this.save(doorServiceOrderDO);
|
|
|
|
|
|
// 给医生发派单消息
|
|
|
if(doorServiceOrderDO.getIsTransOtherOrg().equals(WlyyDoorServiceOrderDO.IsTransOtherOrg.yes.getType())){
|
|
|
this.createMessage(orderId,doorServiceOrderDO.getTransedDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
|
|
|
}else{
|
|
|
this.createMessage(orderId,doorServiceOrderDO.getDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
|
|
|
}
|
|
|
//发送智能助手消息
|
|
|
sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
|
|
|
|
|
|
// 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
|
|
|
ConsultDo consult = consultDao.queryByRelationCode(orderId);
|
|
|
String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
|
|
|
imUtill.updateParticipant(sessionId,doctor,null);
|
|
|
|
|
|
// 调度员处理完该单(新增预约的,或者是拒单重新派单的)
|
|
|
/* List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{402,404,430,435});
|
|
|
if(CollectionUtils.isEmpty(messages)){
|
|
|
logger.error("当前工单没有 居民新增预约 消息!!orderId:" + orderId);
|
|
|
}else{
|
|
|
// 设置消息处理完毕
|
|
|
messages.forEach(
|
|
|
message -> {
|
|
|
if (message.getType() == 430) {
|
|
|
message.setTitle("医生转派单(派给本社区医生)");
|
|
|
message.setContent(doorServiceOrderDO.getDispatcherName() + "已将服务工单" + doorServiceOrderDO.getNumber() + "转派给" + doctorName + "医生");
|
|
|
message.setType(431);
|
|
|
message.setReceiver(dispatcher);
|
|
|
message.setSender(dispatcher);
|
|
|
message.setCreateTime(new Date());
|
|
|
}else{
|
|
|
message.setOver("0");
|
|
|
}
|
|
|
messageDao.save(message);
|
|
|
}
|
|
|
);
|
|
|
}*/
|
|
|
|
|
|
// 工单状态变更记录
|
|
|
WlyyDoorProcessLogDO processLogDO = new WlyyDoorProcessLogDO();
|
|
|
processLogDO.setOrderId(orderId);
|
|
|
processLogDO.setStatus(WlyyDoorServiceOrderDO.Status.waitForAccept.getType());
|
|
|
processLogDO.setDispatcher(dispatcher);
|
|
|
processLogDO.setDispatcherName(dispathcherName);
|
|
|
processLogDO.setCreateTime(new Date());
|
|
|
wlyyDoorProcessLogDao.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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 调度员将工单转给其他机构
|
|
|
* 1、工单记录转接机构
|
|
|
* 2、工单转接日志
|
|
|
*
|
|
|
* @param orderId
|
|
|
* @param hospital
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject transOrderToOtherOrg(String orderId,String hospital){
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
WlyyDoorServiceOrderDO doorServiceOrderDO = wlyyDoorServiceOrderDao.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;
|
|
|
}
|
|
|
|
|
|
String transDispatcherInfoSql = "select code,name,hospital_name from wlyy_doctor where hospital = '" + hospital + "' and `level` = 11";
|
|
|
List<Map<String,Object>> transDispatcherInfoList = jdbcTemplate.queryForList(transDispatcherInfoSql);
|
|
|
if(CollectionUtils.isEmpty(transDispatcherInfoList)){
|
|
|
String failMsg = "当前转接机构[" + hospital + "]暂无调度员,转接失败!";
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// 工单转接
|
|
|
Map<String,Object> infoMap = transDispatcherInfoList.get(0);
|
|
|
String transDispatcher = String.valueOf(infoMap.get("code"));
|
|
|
String transDispatcherName = String.valueOf(infoMap.get("name"));
|
|
|
doorServiceOrderDO.setIsTransOtherOrg(WlyyDoorServiceOrderDO.IsTransOtherOrg.yes.getType());
|
|
|
doorServiceOrderDO.setTransedOrgCode(hospital);
|
|
|
doorServiceOrderDO.setTransedDispatcher(transDispatcher);
|
|
|
doorServiceOrderDO.setTransedDispatcherName(transDispatcherName);
|
|
|
this.save(doorServiceOrderDO);
|
|
|
|
|
|
// 转接日志
|
|
|
WlyyDoorTransRecordDO transRecordDO = new WlyyDoorTransRecordDO();
|
|
|
transRecordDO.setDispatcher(doorServiceOrderDO.getDispatcher());
|
|
|
transRecordDO.setDispatcherName(doorServiceOrderDO.getDispatcherName());
|
|
|
transRecordDO.setOrderId(orderId);
|
|
|
transRecordDO.setTransedOrgCode(hospital);
|
|
|
transRecordDO.setTransedDispatcher(transDispatcher);
|
|
|
transRecordDO.setTransedDispatcherName(transDispatcherName);
|
|
|
wlyyDoorTransRecordDao.save(transRecordDO);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, doorServiceOrderDO);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 添加【工单派单,转单】等系统消息
|
|
|
* @param orderId
|
|
|
* @param sender
|
|
|
* @param receiver
|
|
|
* @param Content
|
|
|
*/
|
|
|
public void createMessage(String orderId,String sender,String receiver,int type,String title,String Content){
|
|
|
/* Message message=new Message();
|
|
|
message.setCzrq(new Date());
|
|
|
message.setCreateTime(new Date());
|
|
|
message.setRead(1);
|
|
|
message.setState(1);
|
|
|
message.setRelationCode(orderId);
|
|
|
message.setOver("1");
|
|
|
message.setReceiver(receiver);
|
|
|
message.setSender(sender);
|
|
|
message.setCode(getCode());
|
|
|
message.setTitle(title);
|
|
|
message.setContent(Content);
|
|
|
//消息类型:401为资质申请审核
|
|
|
message.setType(type);
|
|
|
message.setDel("1");
|
|
|
messageDao.save(message);*/
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 【调度员,医生】快速发送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;
|
|
|
}
|
|
|
|
|
|
WlyyDoorServiceOrderDO wlyyDoorServiceOrder = null;
|
|
|
String response = null;
|
|
|
|
|
|
if(StringUtils.isBlank(sendId)){
|
|
|
wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findOne(orderId);
|
|
|
String sender = "system";
|
|
|
if(StringUtils.isNoneBlank(wlyyDoorServiceOrder.getDispatcher())){
|
|
|
sender = wlyyDoorServiceOrder.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 messageId
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject orderIsCancel(String messageId) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
String sql = "SELECT m.* FROM `wlyy_message` m LEFT JOIN wlyy_door_service_order o on m.relation_code=o.id " +
|
|
|
"where o.status = -1 and m.id='" + messageId + "'";
|
|
|
List<Map<String, Object>> messageList = jdbcTemplate.queryForList(sql);
|
|
|
if(messageList.size() == 0){
|
|
|
//订单没有被取消
|
|
|
result.put(ResponseContant.resultMsg, true);
|
|
|
}else {
|
|
|
//订单已经被取消
|
|
|
result.put(ResponseContant.resultMsg, false);
|
|
|
}
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断是否跳过登记服务小结
|
|
|
* @param orderId
|
|
|
*/
|
|
|
public void cancelConclusion(String orderId) {
|
|
|
wlyyDoorServiceOrderDao.updateConclusionStatus(orderId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新订单居民确认状态
|
|
|
* @param orderId
|
|
|
* @param isPatientConfirm
|
|
|
*/
|
|
|
public void updateIsPatientConfirm(String orderId, Integer isPatientConfirm) {
|
|
|
WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findOne(orderId);
|
|
|
wlyyDoorServiceOrder.setIsPatientConfirm(isPatientConfirm);
|
|
|
wlyyDoorServiceOrder.setPatientConfirmTime(new Date());
|
|
|
this.save(wlyyDoorServiceOrder);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新处方状态跟记录
|
|
|
* @param orderId
|
|
|
* @param prescriptionCode 手动输入处方code,多个用逗号隔开
|
|
|
* @param commitPrescriptionCode
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject createPrescription(String orderId, String prescriptionCode, String commitPrescriptionCode) {
|
|
|
JSONObject res = new JSONObject();
|
|
|
//上门后在线开方,手动关联处方号的话更新处方单号跟状态
|
|
|
if(StringUtils.isNotBlank(commitPrescriptionCode)){
|
|
|
WlyyDoorPrescriptionDO prescription = doorPrescriptionDao.findByCode(commitPrescriptionCode);
|
|
|
prescription.setStatus(1);
|
|
|
prescription.setRecipeNo(prescriptionCode);
|
|
|
prescription.setUpdateTime(new Date());
|
|
|
doorPrescriptionDao.save(prescription);
|
|
|
}else {
|
|
|
//判断手动输入的处方号是否被关联过
|
|
|
String[] recipeNoString = prescriptionCode.split(",");
|
|
|
for (int i = 0; i < recipeNoString.length; i++) {
|
|
|
//判断是否被工单手工关联过
|
|
|
List<WlyyDoorServiceOrderDO> orderDOList = wlyyDoorServiceOrderDao.findByPrescriptionCode("%" + recipeNoString[i] + "%");
|
|
|
WlyyDoorPrescriptionDO prescriptionDO = doorPrescriptionDao.findByRecipeNo(recipeNoString[i]);
|
|
|
if(orderDOList.size() > 0 || prescriptionDO != null){
|
|
|
res.put("status", -1);
|
|
|
res.put("msg", "处方号:" + recipeNoString[i] + "已被关联过,请重新输入");
|
|
|
return res;
|
|
|
}
|
|
|
}
|
|
|
//上门前手动开方即更新工单的处方号
|
|
|
wlyyDoorServiceOrderDao.updatePrescriptionById(orderId, prescriptionCode, new Date());
|
|
|
WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(orderId);
|
|
|
//非代预约才发送im消息
|
|
|
if(orderDO.getType() != null && orderDO.getType() != 3) {
|
|
|
//发送 预约卡片信息(2101类型)
|
|
|
JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
|
|
|
orderInfoContent.put("re_msg_type", 2);//开方完成消息
|
|
|
this.qucikSendIM(orderDO.getId(), orderDO.getDispatcher(), "智能助手", "2101", orderInfoContent.toJSONString());
|
|
|
}
|
|
|
}
|
|
|
res.put("status", 200);
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 更新医生地理位置状态
|
|
|
*
|
|
|
* @param doctor
|
|
|
* @param positionStatus
|
|
|
* @param position
|
|
|
*/
|
|
|
public void updateDoctorStatus(String doctor,Integer positionStatus,String position){
|
|
|
/* Doctor doctor1 = doctorDao.findByCode(doctor);
|
|
|
Hospital hospital = hospitalDao.findByCode(doctor1.getHospital());
|
|
|
if (positionStatus == 0){
|
|
|
doctor1.setPosition(hospital.getPosition());
|
|
|
}else {
|
|
|
doctor1.setPosition(position);
|
|
|
}
|
|
|
doctorDao.save(doctor1);*/
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取上门服务代预约对象列表
|
|
|
* @param teamCode
|
|
|
* @param doctor
|
|
|
* @param patientName
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String, Object>> getDoorPatientList(String teamCode, String doctor, String patientName, Integer page, Integer pageSize) {
|
|
|
int start = 0 == page ? page++ : (page - 1) * pageSize;
|
|
|
int end = 0 == pageSize ? 10 : pageSize;
|
|
|
String sql = "select DISTINCT patient,name,openid,idcard,mobile,town,townName,address from (SELECT s.patient,s.`name`,s.openid,s.idcard, s.mobile,h.town,h.town_name townName, p.address,a.create_time createTime from wlyy_sign_family s, wlyy_door_service_application a ,dm_hospital h,wlyy_patient p " +
|
|
|
"WHERE s.admin_team_code = " + teamCode + " AND ( s.doctor = '" + doctor + "' OR s.doctor_health = '" + doctor + "') and s.`status`= 1 and s.expenses_status=1 and a.`status` =2 " +
|
|
|
"and s.patient = a.patient and s.hospital = h.code and s.patient = p.code and p.status = 1 and (p.archive_status is null or p.archive_status != 2) ";
|
|
|
if(StringUtils.isNotBlank(patientName)){
|
|
|
sql += "and s.`name` LIKE '%" + patientName + "%' ";
|
|
|
}
|
|
|
|
|
|
sql += " union SELECT s.patient,s.`name`,s.openid,s.idcard, s.mobile,h.town,h.town_name townName, p.address,r.create_time createTime from wlyy_sign_family s, wlyy_door_service_order r ,dm_hospital h,wlyy_patient p " +
|
|
|
"WHERE s.admin_team_code = " + teamCode + " AND ( s.doctor = '" + doctor + "' OR s.doctor_health = '" + doctor + "') and s.`status`= 1 and s.expenses_status=1 and s.doctor = '" + doctor + "' " +
|
|
|
"and r.patient = s.patient and s.hospital = h.code and s.patient = p.code and p.status = 1 and (p.archive_status is null or p.archive_status != 2) ";
|
|
|
if(StringUtils.isNotBlank(patientName)){
|
|
|
sql += "and s.`name` LIKE '%" + patientName + "%' ";
|
|
|
}
|
|
|
sql += " ) tmp ";
|
|
|
sql += "ORDER BY createTime desc limit " + start + ", " + end;
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
for(Map<String, Object> map : list){
|
|
|
//获取年龄跟性别
|
|
|
String idcard = map.get("idcard") + "";
|
|
|
|
|
|
|
|
|
//上门服务待预约对象。如果有已完成的服务工单,n那么就取上一次的服务签到地址
|
|
|
String sql1 = "SELECT * FROM wlyy_door_service_order WHERE patient = '"+map.get("patient")+"' AND status = 6 ORDER BY doctor_sign_time DESC LIMIT 1";
|
|
|
List<WlyyDoorServiceOrderDO> orderDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper<>(WlyyDoorServiceOrderDO.class));
|
|
|
if (orderDOList.size()>0){
|
|
|
map.put("address",orderDOList.get(0).getServeAddress());
|
|
|
}
|
|
|
|
|
|
|
|
|
map.put("age", IdCardUtil.getAgeForIdcard(idcard));
|
|
|
map.put("sex", IdCardUtil.getSexForIdcard_new(idcard));
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
@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;
|
|
|
}
|
|
|
|
|
|
//资质处理 .医生填写资质信息后,生成一个已通过审核的资质
|
|
|
try{
|
|
|
if(jsonObjectParam.get("doorServiceApplication")!=null){
|
|
|
doorServiceApplicationService.create("2",jsonObjectParam.get("doorServiceApplication").toString(),doctorCode);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
|
|
|
WlyyDoorServiceOrderDO orderDO = null;
|
|
|
try {
|
|
|
orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.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())) {
|
|
|
/* SignFamily signFamily = signFamilyDao.findSignFamilyByPatient(orderDO.getPatient());
|
|
|
if (signFamily == null) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前服务对象未完成家庭医生签约,请完成签约后再预约上门服务!";
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
logger.error(failMsg);
|
|
|
return result;
|
|
|
}*/
|
|
|
|
|
|
//已取消的订单也可以申请
|
|
|
boolean bool = wlyyDoorServiceOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
|
|
|
new Integer[]{WlyyDoorServiceOrderDO.Status.waitForAccept.getType(),
|
|
|
WlyyDoorServiceOrderDO.Status.waitForServe.getType(),
|
|
|
WlyyDoorServiceOrderDO.Status.accept.getType(),
|
|
|
WlyyDoorServiceOrderDO.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 {
|
|
|
WlyyDoorServiceOrderDO serviceOrderDO = wlyyDoorServiceOrderDao.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;
|
|
|
}
|
|
|
//更新重新派单操作状态
|
|
|
// messageDao.updateByReceiverAndRelationCode(serviceOrderDO.getProxyPatient(), orderDO.getId(), 403);
|
|
|
|
|
|
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)) {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);
|
|
|
|
|
|
/* BaseDoctorDO doctor = doctorDao.findById(orderDO.getDoctor());
|
|
|
Hospital hospital = hospitalDao.findByCode(doctor.getHospital());
|
|
|
doorOrderService.acceptOrder1(orderDO.getId(), doctor.getJob(), doctor.getJobName(), hospital.getLevel());*/
|
|
|
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(orderDO.getId(),orderDO.getProxyPatient(),orderDO.getDoctor(),407,"服务工单待接单","您有新的服务工单,请前往处理");
|
|
|
//发送智能助手消息
|
|
|
sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
public JSONObject proxyUpdate(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;
|
|
|
}
|
|
|
|
|
|
WlyyDoorServiceOrderDO orderDO = null;
|
|
|
try {
|
|
|
orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.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.getId())){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前服务对象id为空,请联系管理员检查参数!id = " + orderDO.getId();
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
WlyyDoorServiceOrderDO serviceOrderDO = wlyyDoorServiceOrderDao.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;
|
|
|
}
|
|
|
//更新重新派单操作状态
|
|
|
// messageDao.updateByReceiverAndRelationCode(serviceOrderDO.getProxyPatient(), orderDO.getId(), 403);
|
|
|
|
|
|
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(serviceOrderDO.getType());
|
|
|
orderDO.setDispatcherResponseTime(new Date());
|
|
|
this.save(orderDO);
|
|
|
result.put("orderId",orderDO.getId());
|
|
|
//新增工单与服务项费用关联关系
|
|
|
if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO)){
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if(!orderDO.getDoctor().equals(serviceOrderDO.getDoctor())){
|
|
|
//服务医生修改,直接转派
|
|
|
BaseDoctorDO doctor = doctorDao.findById(doctorCode);
|
|
|
BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
|
|
|
transferOrder(orderDO.getId(),null,doctor.getId(),doctor.getName(),transDoctor.getId(),transDoctor.getName(),transDoctor.getJobTitleName());
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public List<Map<String,Object>> getProxyPatientList(String patient) {
|
|
|
//根据代理人code查代理预约对象
|
|
|
String sql = "SELECT o.patient,o.patient_name,o.patient_relation,p.photo, IFNULL(m.family_relation, -1) family_relation FROM `wlyy_door_service_order` o LEFT JOIN wlyy_patient_family_member m " +
|
|
|
"on o.proxy_patient = m.patient and o.patient = m.family_member JOIN wlyy_patient p on p.`code` = o.patient and p.`status` = 1 " +
|
|
|
"where o.proxy_patient = '" + patient + "' and o.type != 3 " +
|
|
|
" GROUP BY o.patient ORDER BY family_relation ";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<WlyyDoorServiceOrderDO> selectRelationCode(String relationCode){
|
|
|
return wlyyDoorServiceOrderDao.findByRelationCode(relationCode);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 医生更新上门信息
|
|
|
*
|
|
|
* 预计到达:2019-01-01 09:00
|
|
|
* 服务医生:张三(全科医生)、王五(健管师)
|
|
|
*
|
|
|
* {
|
|
|
* "orderId":"",
|
|
|
* "doctorArrivingTime":"",
|
|
|
* "doctorArr":[
|
|
|
* {
|
|
|
* "doctor":"",
|
|
|
* "doctorName":"",
|
|
|
* "doctorLevel":3,
|
|
|
* "doctorJobCode":"",
|
|
|
* "doctorJobName":"",
|
|
|
* }
|
|
|
* ],
|
|
|
* "deleteDoctorArr":[
|
|
|
* {
|
|
|
* "id":""
|
|
|
* },
|
|
|
* {
|
|
|
* "id":""
|
|
|
* }
|
|
|
* ]
|
|
|
* }
|
|
|
* @param jsonData
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject updateDoctorInfoNoPatient(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;
|
|
|
}
|
|
|
|
|
|
WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findOne(jsonObjectParam.getString("orderId"));
|
|
|
if(!StringUtils.isEmpty(jsonObjectParam.getString("doctorArrivingTime"))) {
|
|
|
wlyyDoorServiceOrder.setDoctorArrivingTime(jsonObjectParam.getString("doctorArrivingTime"));
|
|
|
}
|
|
|
|
|
|
// //添加居民同意状态
|
|
|
// wlyyDoorServiceOrder.setIsPatientConfirm(1);
|
|
|
// wlyyDoorServiceOrder.setPatientConfirmTime(new Date());
|
|
|
// wlyyDoorServiceOrder.setUpdateTime(new Date());
|
|
|
// this.save(wlyyDoorServiceOrder);
|
|
|
//
|
|
|
// //修改时有更改到关联关系,则先删除原有关联关系,再新增关联关系
|
|
|
// //删除工单原来医生的关联关系
|
|
|
// // 删除出诊医生或服务项
|
|
|
// this.orderWithFeeDelete(jsonObjectParam,wlyyDoorServiceOrder);
|
|
|
|
|
|
//新增工单医生关联关系
|
|
|
if (orderWithDoctorAdd(result, jsonObjectParam, wlyyDoorServiceOrder)) {return result;}
|
|
|
|
|
|
// //新增工单居民确认操作日志记录
|
|
|
// if (orderWithConfirmLogAdd(result, jsonObjectParam, wlyyDoorServiceOrder.getId())) {return result;}
|
|
|
|
|
|
//微信模板消息-反馈处理通知
|
|
|
// pushMsgTask.putWxMsg(tokenUtils.getAccessToken(),30,);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, wlyyDoorServiceOrder);
|
|
|
return result;
|
|
|
}
|
|
|
}
|