|  | @ -1,12 +1,48 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.service.admin;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.doorCoach.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.lifeCare.BaseAdminServiceDynamicDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.consult.ConsultTeamService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.doorCoach.DoctorDoorCoachOrderService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.doorCoach.PatientDoorCoachOrderService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.message.BaseServiceNewsService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.pay.PayService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.util.MessageUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.im.ConsultDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.im.ConsultTeamDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.doorCoach.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.door.BaseAdminServiceDynamic;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.message.SystemMessageDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.order.BusinessOrderDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.dao.SystemMessageDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.dao.ConsultDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.util.ImUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.dao.BusinessOrderDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.ResponseContant;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.entity.EntityUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.BasePatientWechatDao;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.math.BigDecimal;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /***
 | 
	
		
			
				|  |  |  * @ClassName: AdminDoorCoachOrderService
 | 
	
	
		
			
				|  | @ -15,12 +51,63 @@ import java.util.Map;
 | 
	
		
			
				|  |  |  * @Date: 2021/8/31 16:40
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class AdminDoorCoachOrderService {
 | 
	
		
			
				|  |  | public class AdminDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOrderDO, BaseDoorCoachOrderDao> {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private Logger logger = LoggerFactory.getLogger(AdminDoorCoachOrderService.class);
 | 
	
		
			
				|  |  |     @Value("${wechat.id}")
 | 
	
		
			
				|  |  |     private String wxId;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseAdminServiceDynamicDao baseAdminServiceDynamicDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoorCoachOrderDao baseDoorCoachOrderDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoorCoachFeeDetailDao baseDoorCoachFeeDetailDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorDao doctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoorCoachFeeDetailDao doorFeeDetailDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoorCoachDoctorStatusDao baseDoorCoachDoctorStatusDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoorCoachProcessLogDao baseDoorCoachProcessLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DoctorDoorCoachOrderService doorOrderService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoorCoachCancelLogDao baseDoorCoachCancelLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientWechatDao basePatientWechatDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoorCoachPatientConfirmLogDao patientConfirmLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DoctorDoorCoachOrderService doctorDoorCoachOrderService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao patientInfoService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private MessageUtil messageUtil;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ImUtil imUtill;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ConsultDao consultDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao patientDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ConsultTeamService consultTeamService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SystemMessageDao systemMessageDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseServiceNewsService serviceNewsService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PayService payService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BusinessOrderDao businessOrderDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseAdminServiceDynamicDao baseAdminServiceDynamicDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String , Object>> getServiceDynamic(Integer page,Integer size){
 | 
	
		
			
				|  |  |         page = (page-1)*size;
 | 
	
	
		
			
				|  | @ -29,4 +116,1490 @@ public class AdminDoorCoachOrderService {
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 创建上门辅导服务工单
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param jsonData
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject create(String jsonData) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         logger.info("创建上门预约jsonData参数:" + jsonData);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         JSONObject jsonObjectParam;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             jsonObjectParam = JSONObject.parseObject(jsonData);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO orderDO = null;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), BaseDoorCoachOrderDO.class);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "上门预约工单服务基本信息:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         JSONObject dispatcherJson = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
 | 
	
		
			
				|  |  |         String hospital = jsonObjectParam.getJSONObject("hospital").get("code").toString();
 | 
	
		
			
				|  |  |         orderDO.setHospital(hospital);
 | 
	
		
			
				|  |  |         orderDO.setNumber(getRandomIntStr());
 | 
	
		
			
				|  |  |         orderDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         orderDO.setCreateUser(orderDO.getProxyPatient());
 | 
	
		
			
				|  |  |         orderDO.setCreateUserName(orderDO.getProxyPatientName());
 | 
	
		
			
				|  |  |         orderDO.setOrderInfo("0");
 | 
	
		
			
				|  |  |         orderDO.setStatus(0);//待付款
 | 
	
		
			
				|  |  |         orderDO.setPayStatus(0);//待付款
 | 
	
		
			
				|  |  | //        orderDO.setConclusionStatus(1);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(StringUtils.isEmpty(orderDO.getPatient())){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(StringUtils.isEmpty(orderDO.getProxyPatient())){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前代理对象code为空,请联系管理员检查参数!proxyPatient = " + orderDO.getProxyPatient();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //已取消的订单也可以申请
 | 
	
		
			
				|  |  |         boolean bool = baseDoorCoachOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
 | 
	
		
			
				|  |  |                 new Integer[]{
 | 
	
		
			
				|  |  |                         BaseDoorCoachOrderDO.Status.waitForPay.getType(),
 | 
	
		
			
				|  |  |                         BaseDoorCoachOrderDO.Status.waitForSend.getType(),
 | 
	
		
			
				|  |  |                         BaseDoorCoachOrderDO.Status.waitForAccept.getType(),
 | 
	
		
			
				|  |  |                         BaseDoorCoachOrderDO.Status.waitForServe.getType(),
 | 
	
		
			
				|  |  |                         BaseDoorCoachOrderDO.Status.accept.getType(),
 | 
	
		
			
				|  |  |                 });
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(bool){
 | 
	
		
			
				|  |  |             String failMsg = "当前服务对象存在未支付或未完成的上门预约,无法再次申请!";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
 | 
	
		
			
				|  |  |         orderDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         //判断创建上门预约类型,发起类型(1本人发起 2家人待预约 3医生代预约)
 | 
	
		
			
				|  |  |         if(orderDO.getProxyPatient().equals(orderDO.getPatient())){
 | 
	
		
			
				|  |  |             orderDO.setType(1);
 | 
	
		
			
				|  |  |         }else if(!orderDO.getProxyPatient().equals(orderDO.getPatient())){
 | 
	
		
			
				|  |  |             orderDO.setType(2);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         orderDO.setServiceStatus("1");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             BaseAdminServiceDynamic baseAdminServiceDynamic = new BaseAdminServiceDynamic();
 | 
	
		
			
				|  |  |             baseAdminServiceDynamic.setDoctorName(orderDO.getDoctorName());
 | 
	
		
			
				|  |  |             baseAdminServiceDynamic.setDoctor(orderDO.getDoctor());
 | 
	
		
			
				|  |  |             baseAdminServiceDynamic.setName(orderDO.getPatientName());
 | 
	
		
			
				|  |  |             baseAdminServiceDynamic.setPatient(orderDO.getPatient());
 | 
	
		
			
				|  |  |             baseAdminServiceDynamic.setType(1);
 | 
	
		
			
				|  |  |             baseAdminServiceDynamic.setValue("创建了上门辅导申请");
 | 
	
		
			
				|  |  |             baseAdminServiceDynamic.setCreateTime(DateUtil.getTime());
 | 
	
		
			
				|  |  |             baseAdminServiceDynamic.setName(orderDO.getNumber());
 | 
	
		
			
				|  |  |             baseAdminServiceDynamicDao.save(baseAdminServiceDynamic);
 | 
	
		
			
				|  |  |         }catch (Exception e) {
 | 
	
		
			
				|  |  |             logger.info(e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         this.save(orderDO);
 | 
	
		
			
				|  |  |         result.put("orderId",orderDO.getId());
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, orderDO);
 | 
	
		
			
				|  |  |         orderDO.setTotalFee(new BigDecimal(0));
 | 
	
		
			
				|  |  |         //新增工单与服务项费用关联关系
 | 
	
		
			
				|  |  |         if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO,null)) {return result;}
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //发起支付订单
 | 
	
		
			
				|  |  |         payService.submitOrder(orderDO.getPatient(),"3",orderDO.getId(),orderDO.getTotalFee().doubleValue());
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public JSONObject proxyCreate(String jsonData,String doctorCode) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         //医养暂无该功能--屏蔽
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, "暂无该功能");
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |         /*
 | 
	
		
			
				|  |  |         JSONObject jsonObjectParam;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             jsonObjectParam = JSONObject.parseObject(jsonData);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO orderDO = null;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), BaseDoorCoachOrderDO.class);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "上门预约工单服务基本信息:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(StringUtils.isEmpty(orderDO.getPatient())){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(StringUtils.isEmpty(orderDO.getProxyPatient())){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前代理对象code为空,请联系管理员检查参数!proxyPatient = " + orderDO.getProxyPatient();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //判断工单是否已存在,新建或者编辑
 | 
	
		
			
				|  |  |         if(StringUtils.isBlank(orderDO.getId())) {
 | 
	
		
			
				|  |  |             //已取消的订单也可以申请
 | 
	
		
			
				|  |  |             boolean bool = baseDoorCoachOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
 | 
	
		
			
				|  |  |                     new Integer[]{BaseDoorCoachOrderDO.Status.waitForPay.getType(),
 | 
	
		
			
				|  |  |                             BaseDoorCoachOrderDO.Status.waitForAccept.getType(),
 | 
	
		
			
				|  |  |                             BaseDoorCoachOrderDO.Status.waitForServe.getType(),
 | 
	
		
			
				|  |  |                             BaseDoorCoachOrderDO.Status.accept.getType(),
 | 
	
		
			
				|  |  |                             BaseDoorCoachOrderDO.Status.waitForSend.getType()
 | 
	
		
			
				|  |  |                     });
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if(bool){
 | 
	
		
			
				|  |  |                 String failMsg = "当前服务对象存在未完成的上门预约,请先完成该服务!";
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 logger.error(failMsg);
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             orderDO.setNumber(getRandomIntStr());
 | 
	
		
			
				|  |  |             orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
 | 
	
		
			
				|  |  |             orderDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             orderDO.setCreateUser(orderDO.getProxyPatient());
 | 
	
		
			
				|  |  |             orderDO.setCreateUserName(orderDO.getProxyPatientName());
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             BaseDoorCoachOrderDO serviceOrderDO = baseDoorCoachOrderDao.findOne(orderDO.getId());
 | 
	
		
			
				|  |  |             // 删除出诊医生或服务项
 | 
	
		
			
				|  |  |             Boolean b = this.orderWithFeeDelete(jsonObjectParam, serviceOrderDO);
 | 
	
		
			
				|  |  |             if(b){
 | 
	
		
			
				|  |  |                 String failMsg = "删除服务项失败!";
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             orderDO.setNumber(serviceOrderDO.getNumber());
 | 
	
		
			
				|  |  |             orderDO.setHospital(serviceOrderDO.getHospital());
 | 
	
		
			
				|  |  |             orderDO.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |             orderDO.setUpdateUser(orderDO.getProxyPatient());
 | 
	
		
			
				|  |  |             orderDO.setUpdateUserName(orderDO.getProxyPatientName());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         orderDO.setStatus(0);//待付款
 | 
	
		
			
				|  |  |         orderDO.setPayStatus(0);//待付款
 | 
	
		
			
				|  |  |         orderDO.setType(3);
 | 
	
		
			
				|  |  |         orderDO.setDispatcherResponseTime(new Date());
 | 
	
		
			
				|  |  |         this.save(orderDO);
 | 
	
		
			
				|  |  |         result.put("orderId",orderDO.getId());
 | 
	
		
			
				|  |  |         orderDO.setTotalFee(new BigDecimal(0));
 | 
	
		
			
				|  |  |         //新增工单与服务项费用关联关系
 | 
	
		
			
				|  |  |         if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO,doctorCode)) {return result;}
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 给服务医生发接单消息
 | 
	
		
			
				|  |  |         this.createMessage("服务工单待接单","707",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(),orderDO.getDoctor(),orderDO.getDoctorName(), null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         //发送智能助手消息
 | 
	
		
			
				|  |  |         sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //发起支付订单
 | 
	
		
			
				|  |  |         BusinessOrderDO businessOrderDO =  payService.submitOrder(orderDO.getPatient(),"3",orderDO.getId(),orderDO.getTotalFee().doubleValue());
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |         */
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //支付完成后开始上门辅导订单
 | 
	
		
			
				|  |  |     public JSONObject payOrderAfter(String orderId) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(orderId);
 | 
	
		
			
				|  |  |             if (businessOrderDO==null){
 | 
	
		
			
				|  |  |                 String failMsg = "未查询到该订单";
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             BaseDoorCoachOrderDO orderDO= baseDoorCoachOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |             if (orderDO!=null){
 | 
	
		
			
				|  |  |                 orderDO.setPayStatus(1);
 | 
	
		
			
				|  |  |                 orderDO.setPayWay(1);
 | 
	
		
			
				|  |  |                 orderDO.setPayTime(new Date());
 | 
	
		
			
				|  |  |                 if (orderDO.getType()== 3){//医生代预约
 | 
	
		
			
				|  |  |                     orderDO.setStatus(2);//待接单
 | 
	
		
			
				|  |  |                     this.save(orderDO);
 | 
	
		
			
				|  |  |                     // 给服务医生发接单消息
 | 
	
		
			
				|  |  |                     this.createMessage("服务工单待接单","707",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(),orderDO.getDoctor(),orderDO.getDoctorName(), null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |                     //发送智能助手消息
 | 
	
		
			
				|  |  |                     sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     //创建咨询
 | 
	
		
			
				|  |  |                     JSONObject successOrNot = null;
 | 
	
		
			
				|  |  |                     try {
 | 
	
		
			
				|  |  |                         successOrNot = consultTeamService.addDoorCoachServiceConsult(orderDO.getId());
 | 
	
		
			
				|  |  |                     } catch (Exception e) {
 | 
	
		
			
				|  |  |                         e.printStackTrace();
 | 
	
		
			
				|  |  |                         String failMsg = "创建咨询时异常: " + e.getMessage();
 | 
	
		
			
				|  |  |                         result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                         result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                         logger.error(failMsg);
 | 
	
		
			
				|  |  |                         return result;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (Integer.parseInt(successOrNot.get(ResponseContant.resultFlag).toString()) == ResponseContant.fail) {
 | 
	
		
			
				|  |  |                         return JSONObject.parseObject(successOrNot.toString());
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     ConsultTeamDo consultTeam = (ConsultTeamDo)successOrNot.get(ResponseContant.resultMsg);
 | 
	
		
			
				|  |  |                     //发送智能助手消息
 | 
	
		
			
				|  |  |                     sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //发送 预约卡片信息(2201类型)
 | 
	
		
			
				|  |  |                     JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
 | 
	
		
			
				|  |  |                     orderInfoContent.put("re_msg_type",0);//居民预约
 | 
	
		
			
				|  |  |                     this.qucikSendIM(orderDO.getId(), "system", "智能助手", "2201", orderInfoContent.toJSONString());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if(StringUtils.isNoneBlank(orderDO.getDoctor())){
 | 
	
		
			
				|  |  |                         //期望服务医生存在,直接转派
 | 
	
		
			
				|  |  |                         BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
 | 
	
		
			
				|  |  |                         sendOrderToDoctor(orderDO.getId(),null,"system","系统",transDoctor.getId(),transDoctor.getName(),transDoctor.getJobTitleName());
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         orderDO.setStatus(1);//待派单
 | 
	
		
			
				|  |  |                         this.save(orderDO);
 | 
	
		
			
				|  |  |                         JSONObject dispatcherJson = queryDispatcherInfoByPatient(orderDO.getHospital());
 | 
	
		
			
				|  |  |                         if (dispatcherJson.getInteger("resultFlag")==1){
 | 
	
		
			
				|  |  |                             List<Map<String,Object>> dispatcherInfoList = (List<Map<String, Object>>) dispatcherJson.get(ResponseContant.resultMsg);
 | 
	
		
			
				|  |  |                             for(Map<String,Object> map: dispatcherInfoList){
 | 
	
		
			
				|  |  |                                 String dispatcher = map.get("code").toString();
 | 
	
		
			
				|  |  |                                 BaseDoctorDO doctorVO = doctorDao.findById(dispatcher);
 | 
	
		
			
				|  |  |                                 // 派单消息-首页
 | 
	
		
			
				|  |  |                                 this.createMessage("新增居民预约服务申请","702","system","system", orderDO.getId(), dispatcher,doctorVO.getName() ,doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
 | 
	
		
			
				|  |  |                                 // 派单-实时工单消息  430 居民提交工单申请-- 张三提交了服务工单12345678申请
 | 
	
		
			
				|  |  |                                 this.createMessage("居民提交工单申请","730","system","system", orderDO.getId(), dispatcher,doctorVO.getName() ,doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务工单"+orderDO.getNumber()+"申请");
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     serviceNewsService.addServiceNews(orderDO.getPatientName(),orderDO.getPatient(),"1",null);
 | 
	
		
			
				|  |  |                     String failMsg = "success";
 | 
	
		
			
				|  |  |                     result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |                     result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else {
 | 
	
		
			
				|  |  |                 String failMsg = "工单不存在";
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //退款后回调
 | 
	
		
			
				|  |  |     public JSONObject refundOrderAfter(String orderId) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             BaseDoorCoachOrderDO orderDO= baseDoorCoachOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |             if (orderDO == null){
 | 
	
		
			
				|  |  |                 String failMsg = "工单不存在";
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             orderDO.setPayStatus(2);
 | 
	
		
			
				|  |  |             this.save(orderDO);
 | 
	
		
			
				|  |  |             String failMsg = "success";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据接单医生code获取最近一次服务orderId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getOrderIdByPatient(String patient) {
 | 
	
		
			
				|  |  |         String sql = "SELECT id as orderId from base_door_coach_order where patient=? and status in(1,2,3,4,5,6) ORDER BY patient_expected_serve_time desc,update_time desc,create_time desc, status ASC limit 1";
 | 
	
		
			
				|  |  |         List<String> orderId = jdbcTemplate.queryForList(sql, String.class, new Object[]{patient});
 | 
	
		
			
				|  |  |         if (orderId.size()>0){
 | 
	
		
			
				|  |  |             return orderId.get(0);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> selectItemsByHospital(String hospital,String serverItemName){
 | 
	
		
			
				|  |  |         String sql ="select org_code,dict_code code,dict_value name,ext1 fee from base_business_sys_dict where dict_name='DOOR_APPLY_ITEM' ";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(hospital)){
 | 
	
		
			
				|  |  |             sql +=" and org_code='"+hospital+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(serverItemName)){
 | 
	
		
			
				|  |  |             sql += " and dict_value like '%"+serverItemName+"%' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 调度员-查询-服务人员列表(医生-可接单状态的)
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject queryDoctorListWithNotStopped(String hospital,int page, int size) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         int start = 0 == page ? page++ : (page - 1) * size;
 | 
	
		
			
				|  |  |         int end = 0 == size ? 15 : page * size;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "select DISTINCT ds.doctor,d.name, d.job_title_name as jobName, 1 as sortFlag " +
 | 
	
		
			
				|  |  |                 " from base_door_coach_doctor_status ds " +
 | 
	
		
			
				|  |  |                 "        JOIN (select b.* from base_doctor b,base_doctor_hospital dh where b.id=dh.doctor_code and dh.del = 1 and dh.org_code='" + hospital + "')  d on ds.doctor = d.id " +
 | 
	
		
			
				|  |  |                 "  where ds.status in (1,2,3,4)  " +
 | 
	
		
			
				|  |  |                 " limit " + start + "," + end ;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String countSql = "select DISTINCT count(ds.id) " +
 | 
	
		
			
				|  |  |                 "from base_door_coach_doctor_status ds " +
 | 
	
		
			
				|  |  |                 "         JOIN (select b.* from base_doctor b,base_doctor_hospital dh where b.id=dh.doctor_code and dh.del = 1 and dh.org_code= '" + hospital + "') d on ds.doctor = d.id " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN base_doctor_role dr ON dr.doctor_code = d.id where ds.status in (1,2,3,4)  ";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> doctorList = new ArrayList<>();
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             doctorList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             String failMsg = "从数据库查询 可接单状态的服务医生人员 列表信息失败:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg );
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Integer count = 0;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             count = jdbcTemplate.queryForObject(countSql,Integer.class);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             String failMsg = "从数据库统计  可接单状态的服务医生人员 数量失败:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, doctorList);
 | 
	
		
			
				|  |  |         JSONObject countItem = new JSONObject();
 | 
	
		
			
				|  |  |         countItem.put("count", count);
 | 
	
		
			
				|  |  |         result.putAll(countItem);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 修改上门预约工单(包括医生,费用,居民确认信息等)
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param jsonData
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public JSONObject update(String jsonData) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         JSONObject jsonObjectParam;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             jsonObjectParam = JSONObject.parseObject(jsonData);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO wlyyDoorServiceOrder = new BaseDoorCoachOrderDO();
 | 
	
		
			
				|  |  |         wlyyDoorServiceOrder = jsonToWlyyDoorServiceOrder(result, jsonObjectParam, jsonData);
 | 
	
		
			
				|  |  |         this.save(wlyyDoorServiceOrder);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, wlyyDoorServiceOrder);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 删除出诊医生或服务项
 | 
	
		
			
				|  |  |      * @param jsonObjectParam
 | 
	
		
			
				|  |  |      * {
 | 
	
		
			
				|  |  |      *     "deleteItemArr":[
 | 
	
		
			
				|  |  |      *        {
 | 
	
		
			
				|  |  |      *           "id":""
 | 
	
		
			
				|  |  |      *       },
 | 
	
		
			
				|  |  |      *        {
 | 
	
		
			
				|  |  |      *           "id":""
 | 
	
		
			
				|  |  |      *      }
 | 
	
		
			
				|  |  |      *     ],
 | 
	
		
			
				|  |  |      *     "deleteDoctorArr":[
 | 
	
		
			
				|  |  |      *     {
 | 
	
		
			
				|  |  |      *         "id":""
 | 
	
		
			
				|  |  |      *     },
 | 
	
		
			
				|  |  |      *      {
 | 
	
		
			
				|  |  |      *         "id":""
 | 
	
		
			
				|  |  |      *     }
 | 
	
		
			
				|  |  |      *     ]
 | 
	
		
			
				|  |  |      * }
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public boolean orderWithFeeDelete(JSONObject jsonObjectParam, BaseDoorCoachOrderDO orderDO) {
 | 
	
		
			
				|  |  |         BigDecimal totalFee = orderDO.getTotalFee();
 | 
	
		
			
				|  |  |         //删除的服务项
 | 
	
		
			
				|  |  |         JSONArray itemArray = jsonObjectParam.getJSONArray("deleteItemArr");
 | 
	
		
			
				|  |  |         if (!CollectionUtils.isEmpty(itemArray)) {
 | 
	
		
			
				|  |  |             List<BaseDoorCoachFeeDetailDO> list = new ArrayList<>();
 | 
	
		
			
				|  |  |             //删除的服务项要减去服务项费用
 | 
	
		
			
				|  |  |             BigDecimal itemFee = new BigDecimal(0);
 | 
	
		
			
				|  |  |             for(Object oneId : itemArray) {
 | 
	
		
			
				|  |  |                 JSONObject oneIdJson = (JSONObject) oneId;
 | 
	
		
			
				|  |  |                 BaseDoorCoachFeeDetailDO doorFeeDetail = baseDoorCoachFeeDetailDao.findOne(String.valueOf(oneIdJson.get("id")));
 | 
	
		
			
				|  |  |                 if(doorFeeDetail.getPayStatus()==0){
 | 
	
		
			
				|  |  |                     doorFeeDetail.setStatus(3);
 | 
	
		
			
				|  |  |                     doorFeeDetail.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |                     list.add(doorFeeDetail);
 | 
	
		
			
				|  |  |                     itemFee = itemFee.add(doorFeeDetail.getFee().multiply(BigDecimal.valueOf(doorFeeDetail.getNumber())));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             baseDoorCoachFeeDetailDao.save(list);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return false;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 上门预约工单服务基本信息
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param result
 | 
	
		
			
				|  |  |      * @param jsonObjectParam
 | 
	
		
			
				|  |  |      * @param jsonData
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public BaseDoorCoachOrderDO jsonToWlyyDoorServiceOrder(JSONObject result, JSONObject jsonObjectParam, String jsonData) {
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO wlyyDoorServiceOrder;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             wlyyDoorServiceOrder = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), BaseDoorCoachOrderDO.class);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "上门预约工单服务基本信息:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return new BaseDoorCoachOrderDO();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         wlyyDoorServiceOrder.setNumber(getRandomIntStr());
 | 
	
		
			
				|  |  |         return wlyyDoorServiceOrder;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查询预约简要卡片信息
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * 服务时间:2019-01-01   12:30
 | 
	
		
			
				|  |  |      * 服务对象:张三
 | 
	
		
			
				|  |  |      * 联系电话:13125256565(儿子)
 | 
	
		
			
				|  |  |      * 上门地址:福建省厦门市思明区望海路55号
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param orderDO
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject queryOrderCardInfo(BaseDoorCoachOrderDO orderDO){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         result.put("patientCode", orderDO.getPatient());
 | 
	
		
			
				|  |  |         BasePatientDO patientDO = patientDao.findById(orderDO.getPatient());
 | 
	
		
			
				|  |  |         result.put("title","预约服务信息如下:");
 | 
	
		
			
				|  |  |         result.put("orderId",orderDO.getId());
 | 
	
		
			
				|  |  |         result.put("status",orderDO.getStatus());
 | 
	
		
			
				|  |  |         result.put("number",orderDO.getNumber());
 | 
	
		
			
				|  |  |         result.put("serveDesc",orderDO.getServeDesc());
 | 
	
		
			
				|  |  |         result.put("expectedDoctor",orderDO.getExpectedDoctorName());
 | 
	
		
			
				|  |  |         result.put("serviceStatus",orderDO.getServiceStatus());
 | 
	
		
			
				|  |  |         if(orderDO.getStatus() < 4){
 | 
	
		
			
				|  |  |             if(StringUtils.isBlank(orderDO.getPatientExpectedServeTime())){
 | 
	
		
			
				|  |  |                 result.put("time","工作时间");
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 result.put("time", orderDO.getPatientExpectedServeTime());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             if(StringUtils.isBlank(orderDO.getDoctorArrivingTime())){
 | 
	
		
			
				|  |  |                 result.put("time","工作时间");
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 result.put("time", orderDO.getDoctorArrivingTime());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         result.put("patientName",patientDO.getName());
 | 
	
		
			
				|  |  |         result.put("patientSex", IdCardUtil.getSexNameForIdcard_new(patientDO.getIdcard()));
 | 
	
		
			
				|  |  |         result.put("patientAge", IdCardUtil.getAgeByIdcardOrBirthday(patientDO.getIdcard(),patientDO.getBirthday()));
 | 
	
		
			
				|  |  |         result.put("phone",orderDO.getPatientPhone());
 | 
	
		
			
				|  |  |         result.put("serveDesc",orderDO.getServeDesc());
 | 
	
		
			
				|  |  |         if(StringUtils.equalsIgnoreCase(orderDO.getPatient(),orderDO.getProxyPatient())){
 | 
	
		
			
				|  |  |             result.put("relation","");
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             result.put("relation",orderDO.getPatientRelation());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         result.put("serveTown",orderDO.getServeTown());
 | 
	
		
			
				|  |  |         result.put("serveAddress",orderDO.getServeAddress());
 | 
	
		
			
				|  |  |         result.put("type",21);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 【调度员,医生】快速发送IM消息
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param sendId
 | 
	
		
			
				|  |  |      * @param sendName
 | 
	
		
			
				|  |  |      * @param content
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public int qucikSendIM(String orderId,String sendId,String sendName,String contentType,String content) {
 | 
	
		
			
				|  |  |         int result = -1;
 | 
	
		
			
				|  |  |         ConsultDo consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  |         if (null == consult) {
 | 
	
		
			
				|  |  |             logger.error("当前工单未关联咨询,工单id:" + orderId);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO baseDoorCoachOrderDO = null;
 | 
	
		
			
				|  |  |         String response = null;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(StringUtils.isBlank(sendId)){
 | 
	
		
			
				|  |  |             baseDoorCoachOrderDO = baseDoorCoachOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |             String sender = "system";
 | 
	
		
			
				|  |  |             if(StringUtils.isNoneBlank(baseDoorCoachOrderDO.getDispatcher())){
 | 
	
		
			
				|  |  |                 sender = baseDoorCoachOrderDO.getDispatcher();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             response = imUtill.sendTopicIM(sender, "智能助手", consult.getId(), contentType, content, null);
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             response = imUtill.sendTopicIM(sendId, sendName, consult.getId(), contentType, content, null);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         JSONObject resObj = JSONObject.parseObject(response);
 | 
	
		
			
				|  |  |         if (resObj.getIntValue("status") == -1) {
 | 
	
		
			
				|  |  |             logger.error("上门预约工单消息发送失败:" + resObj.getString("message"));
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         result = 1;
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 调度员(系统)给医生派单
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param doctor
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public JSONObject sendOrderToDoctor(String orderId,String remark,String dispatcher,String dispathcherName,String doctor,String doctorName,String doctorJobName){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO doorServiceOrderDO = baseDoorCoachOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         if(null == doorServiceOrderDO){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前工单不存在,id:" + orderId;
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BaseDoorCoachDoctorStatusDO doorDoctorStatusDO = baseDoorCoachDoctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{BaseDoorCoachOrderDO.Status.waitForSend.getType(),
 | 
	
		
			
				|  |  |                 BaseDoorCoachDoctorStatusDO.Status.waitForAccept.getType(),
 | 
	
		
			
				|  |  |                 BaseDoorCoachDoctorStatusDO.Status.waitForServe.getType(),
 | 
	
		
			
				|  |  |                 BaseDoorCoachDoctorStatusDO.Status.serving.getType(),
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         if(null == doorDoctorStatusDO){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前派单的医生不存在或禁止接单,doctor:" + doctor;
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(remark)&&!"null".equals(remark)){
 | 
	
		
			
				|  |  |             doorServiceOrderDO.setRemark(remark);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctor(doctor);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctorName(doctorName);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctorType(doctorJobName);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setStatus(BaseDoorCoachOrderDO.Status.waitForAccept.getType());
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setUpdateUser(dispatcher);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setUpdateUserName(dispathcherName);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDispatcherResponseTime(new Date());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         this.save(doorServiceOrderDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 给医生发派单消息
 | 
	
		
			
				|  |  |         if(BaseDoorCoachOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","707",doorServiceOrderDO.getTransedDispatcher(),doorServiceOrderDO.getTransedDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","707",doorServiceOrderDO.getDispatcher(),doorServiceOrderDO.getDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //发送智能助手消息//·
 | 
	
		
			
				|  |  |         sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
 | 
	
		
			
				|  |  |         ConsultDo consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  |         String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
 | 
	
		
			
				|  |  |         imUtill.updateParticipantNew(sessionId,doctor,null);
 | 
	
		
			
				|  |  |         if (!dispatcher.equals("System")){
 | 
	
		
			
				|  |  |             messageUtil.updateDoorCoachMessage(doorServiceOrderDO,new String[]{"702","703","730","735"},"731",dispatcher,dispatcher);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 工单状态变更记录
 | 
	
		
			
				|  |  |         BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
 | 
	
		
			
				|  |  |         processLogDO.setOrderId(orderId);
 | 
	
		
			
				|  |  |         processLogDO.setStatus(BaseDoorCoachOrderDO.Status.waitForAccept.getType());
 | 
	
		
			
				|  |  |         processLogDO.setDispatcher(dispatcher);
 | 
	
		
			
				|  |  |         processLogDO.setDispatcherName(dispathcherName);
 | 
	
		
			
				|  |  |         processLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         baseDoorCoachProcessLogDao.save(processLogDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, doorServiceOrderDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 发送IM消息通知患者医生已派单
 | 
	
		
			
				|  |  |         String noticeContent = "已分派"+doorServiceOrderDO.getDoctorName()+"医生为您服务,请耐心等待医生接单";
 | 
	
		
			
				|  |  |         if (!doorServiceOrderDO.getDispatcher().equals("System")) {
 | 
	
		
			
				|  |  |             this.qucikSendIM(doorServiceOrderDO.getId(), doorServiceOrderDO.getDispatcher(), "智能助手","1", noticeContent);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 医生给医生派单
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param doctor
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public JSONObject transferOrder(String orderId,String remark,String dispatcher,String dispathcherName,String doctor,String doctorName,String doctorJobName){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO doorServiceOrderDO = baseDoorCoachOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         if(null == doorServiceOrderDO){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前工单不存在,id:" + orderId;
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BaseDoorCoachDoctorStatusDO doorDoctorStatusDO = baseDoorCoachDoctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{BaseDoorCoachDoctorStatusDO.Status.waitForSend.getType(),
 | 
	
		
			
				|  |  |                 BaseDoorCoachDoctorStatusDO.Status.waitForAccept.getType(),
 | 
	
		
			
				|  |  |                 BaseDoorCoachDoctorStatusDO.Status.waitForServe.getType(),
 | 
	
		
			
				|  |  |                 BaseDoorCoachDoctorStatusDO.Status.serving.getType(),
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         if(null == doorDoctorStatusDO){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前转派单的医生不存在或禁止接单,doctor:" + doctor;
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setRemark(remark);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctor(doctor);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctorName(doctorName);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctorType(doctorJobName);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setStatus(BaseDoorCoachOrderDO.Status.waitForAccept.getType());
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setUpdateUser(dispatcher);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setUpdateUserName(dispathcherName);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDispatcherResponseTime(new Date());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         System.out.println(dispathcherName+"医生派单给"+doctorName+"医生");
 | 
	
		
			
				|  |  | //        String sql = "DELETE FROM wlyy_door_doctor WHERE order_id ='"+orderId+"' AND doctor = '"+dispatcher+"'";
 | 
	
		
			
				|  |  | //        jdbcTemplate.execute(sql);
 | 
	
		
			
				|  |  |         this.save(doorServiceOrderDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 给医生发派单消息
 | 
	
		
			
				|  |  |         if(BaseDoorCoachOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","707",doorServiceOrderDO.getTransedDispatcher(),doorServiceOrderDO.getTransedDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","707",doorServiceOrderDO.getDispatcher(),doorServiceOrderDO.getDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //发送智能助手消息
 | 
	
		
			
				|  |  |         sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
 | 
	
		
			
				|  |  |         ConsultDo consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  |         String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
 | 
	
		
			
				|  |  |         imUtill.updateParticipantNew(sessionId,doctor,null);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         messageUtil.updateDoorCoachMessage(doorServiceOrderDO,new String[]{"702","703","730","735"},"731",dispatcher,dispatcher);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 工单状态变更记录
 | 
	
		
			
				|  |  |         BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
 | 
	
		
			
				|  |  |         processLogDO.setOrderId(orderId);
 | 
	
		
			
				|  |  |         processLogDO.setStatus(BaseDoorCoachOrderDO.Status.waitForAccept.getType());
 | 
	
		
			
				|  |  |         processLogDO.setDispatcher(dispatcher);
 | 
	
		
			
				|  |  |         processLogDO.setDispatcherName(dispathcherName);
 | 
	
		
			
				|  |  |         processLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         baseDoorCoachProcessLogDao.save(processLogDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, doorServiceOrderDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 发送IM消息通知患者医生已派单
 | 
	
		
			
				|  |  |         String noticeContent = "已转派"+doorServiceOrderDO.getDoctorName()+"医生为您服务,请耐心等待医生接单";
 | 
	
		
			
				|  |  |         this.qucikSendIM(doorServiceOrderDO.getId(), dispatcher, "智能助手","1", noticeContent);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 取消工单
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param type 取消类型
 | 
	
		
			
				|  |  |      * @param reason 取消理由
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject cancelOrder(String orderId,int type,String reason,String dispatcher,String dispatcherName){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO orderDO = baseDoorCoachOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         if(null == orderDO){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "【取消工单】该工单不存在:," + orderId;
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(type==2){//v0.5.1 患者仅未支付的订单能取消此时未正式开始工单,未创建咨询
 | 
	
		
			
				|  |  |             if(orderDO.getStatus() != BaseDoorCoachOrderDO.Status.waitForPay.getType()){
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 String failMsg = "无法取消工单,已支付的工单需要到我的订单中进行申请退款," + orderId;
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 logger.error(failMsg);
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(orderDO.getId());
 | 
	
		
			
				|  |  |             businessOrderDO.setStatus(2);
 | 
	
		
			
				|  |  |             businessOrderDao.save(businessOrderDO);
 | 
	
		
			
				|  |  |         }else{//调度员拒单,此时工单已支付抵达调度员
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 if (orderDO.getStatus() > BaseDoorCoachOrderDO.Status.waitForPay.getType()&&1==orderDO.getPayWay()){
 | 
	
		
			
				|  |  |                     BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(orderDO.getId());
 | 
	
		
			
				|  |  |                     if (businessOrderDO!=null){
 | 
	
		
			
				|  |  |                         if (1 == businessOrderDO.getStatus()){
 | 
	
		
			
				|  |  |                             //退款流程
 | 
	
		
			
				|  |  |                             try {
 | 
	
		
			
				|  |  |                                 payService.dispatcherOrderRefund(businessOrderDO.getOrderNo(),"调度员拒单退款");
 | 
	
		
			
				|  |  |                                 orderDO.setPayStatus(2);
 | 
	
		
			
				|  |  |                             }catch (Exception e){
 | 
	
		
			
				|  |  |                                 e.printStackTrace();
 | 
	
		
			
				|  |  |                                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                                 result.put(ResponseContant.resultMsg,"退款失败,无法拒绝工单!");
 | 
	
		
			
				|  |  |                                 return result;
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //如果是调度员取消,推送IM取消工单json消息,
 | 
	
		
			
				|  |  | //                if (StringUtils.isNotBlank(dispatcher)){
 | 
	
		
			
				|  |  | //                    if (!consultTeamService.finishConsult(orderDO.getId(),orderDO.getPatient(),dispatcher,2)){
 | 
	
		
			
				|  |  | //                        String failMsg = "咨询结束失败 无法取消工单";
 | 
	
		
			
				|  |  | //                        result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  | //                        result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  | //                        return result;
 | 
	
		
			
				|  |  | //                    }
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  |                 if(!StringUtils.isEmpty(dispatcher)){
 | 
	
		
			
				|  |  |                     orderDO.setDoctor(dispatcher);
 | 
	
		
			
				|  |  |                     orderDO.setDoctorName(dispatcherName);
 | 
	
		
			
				|  |  |                     orderDO.setDispatcher(dispatcher);
 | 
	
		
			
				|  |  |                     orderDO.setDispatcherName(dispatcherName);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if(type == BaseDoorCoachOrderDO.CancelType.dispatcher.getType()){
 | 
	
		
			
				|  |  |                     messageUtil.updateDoorCoachMessage(orderDO,new String[]{"702","703","730"},"732",dispatcher,dispatcher);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 else if(type == BaseDoorCoachOrderDO.CancelType.patient.getType()){                   //居民取消,消息列表也应该不显示
 | 
	
		
			
				|  |  |                     messageUtil.updateDoorCoachMessage(orderDO,new String[]{"702","703","730"},"patientCancel",dispatcher,dispatcher);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 ConsultDo consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  |                 // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
 | 
	
		
			
				|  |  |                 String first = "key1您好,您的上门预约订单已退回,点击查看原因";
 | 
	
		
			
				|  |  |                 BasePatientDO patient = patientDao.findById(orderDO.getPatient());
 | 
	
		
			
				|  |  |                 first  = first.replace("key1", null != patient.getName() ? patient.getName() : "");
 | 
	
		
			
				|  |  |                 JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  |                 json.put("id", orderDO.getId());
 | 
	
		
			
				|  |  |                 List<BasePatientWechatDo> basePatientWechatDos = basePatientWechatDao.findByWechatIdAndPatientId(wxId,patient.getId());
 | 
	
		
			
				|  |  |                 if (basePatientWechatDos.size()>0){
 | 
	
		
			
				|  |  |                     String openId = basePatientWechatDos.get(0).getOpenid();
 | 
	
		
			
				|  |  |                     messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyqx",openId,first,null,null,2,json, DateUtil.dateToChineseDate(new Date()),"上门预约已取消","已取消");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |                 String failMsg = "退款失败,无法取消工单:," + orderId;
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         orderDO.setCancelType(type);
 | 
	
		
			
				|  |  |         orderDO.setCancelTime(new Date());
 | 
	
		
			
				|  |  |         orderDO.setCancelReason(reason);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         orderDO.setStatus(BaseDoorCoachOrderDO.Status.cancel.getType());
 | 
	
		
			
				|  |  |         this.save(orderDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //保存取消记录
 | 
	
		
			
				|  |  |         BaseDoorCoachCancelLogDO cancelLogDO = new BaseDoorCoachCancelLogDO();
 | 
	
		
			
				|  |  |         cancelLogDO.setOrderId(orderId);
 | 
	
		
			
				|  |  |         cancelLogDO.setPatient(orderDO.getProxyPatient());
 | 
	
		
			
				|  |  |         cancelLogDO.setCancelType(type);
 | 
	
		
			
				|  |  |         cancelLogDO.setCancelReason(reason);
 | 
	
		
			
				|  |  |         cancelLogDO.setTime(orderDO.getCancelTime());
 | 
	
		
			
				|  |  |         baseDoorCoachCancelLogDao.save(cancelLogDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //保存居民确认取消记录
 | 
	
		
			
				|  |  |         JSONObject confirmInfo = new JSONObject();
 | 
	
		
			
				|  |  |         confirmInfo.put("orderId",orderId);
 | 
	
		
			
				|  |  |         confirmInfo.put("patient",orderDO.getProxyPatient());
 | 
	
		
			
				|  |  |         confirmInfo.put("patientName",orderDO.getProxyPatientName());
 | 
	
		
			
				|  |  |         confirmInfo.put("type",4);
 | 
	
		
			
				|  |  |         confirmInfo.put("description",reason);
 | 
	
		
			
				|  |  |         JSONObject confirmInfoJson = new JSONObject();
 | 
	
		
			
				|  |  |         confirmInfoJson.put("confirmInfo",confirmInfo);
 | 
	
		
			
				|  |  |         this.orderWithConfirmLogAdd(result,confirmInfo,orderId);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 工单状态变更记录
 | 
	
		
			
				|  |  |         BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
 | 
	
		
			
				|  |  |         processLogDO.setOrderId(orderId);
 | 
	
		
			
				|  |  |         processLogDO.setStatus(BaseDoorCoachOrderDO.Status.cancel.getType());
 | 
	
		
			
				|  |  |         processLogDO.setDispatcher(dispatcher);
 | 
	
		
			
				|  |  |         processLogDO.setDispatcherName(dispatcherName);
 | 
	
		
			
				|  |  |         baseDoorCoachProcessLogDao.save(processLogDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, "工单服务已取消!");
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 服务工单居民确认操作日志记录
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * {
 | 
	
		
			
				|  |  |      *     "confirmInfo":{
 | 
	
		
			
				|  |  |      *         "patient":"",
 | 
	
		
			
				|  |  |      *         "patientName":"",
 | 
	
		
			
				|  |  |      *         "type":"",
 | 
	
		
			
				|  |  |      *         "description":""
 | 
	
		
			
				|  |  |      *     }
 | 
	
		
			
				|  |  |      * }
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param result
 | 
	
		
			
				|  |  |      * @param jsonObjectParam
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public boolean orderWithConfirmLogAdd(JSONObject result, JSONObject jsonObjectParam, String orderId) {
 | 
	
		
			
				|  |  |         // 确认信息
 | 
	
		
			
				|  |  |         JSONObject confirmInfo = jsonObjectParam.getJSONObject("confirmInfo");
 | 
	
		
			
				|  |  |         if (null != confirmInfo) {
 | 
	
		
			
				|  |  |             BaseDoorCoachPatientConfirmLogDO confirmLogDO = null;
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 confirmLogDO = EntityUtils.jsonToEntity(confirmInfo.toString(), BaseDoorCoachPatientConfirmLogDO.class);
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 String failMsg = "工单关联【居民确认操作日志记录】时," + e.getMessage();
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 logger.error(failMsg);
 | 
	
		
			
				|  |  |                 return true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             confirmLogDO.setOrderId(orderId);
 | 
	
		
			
				|  |  |             confirmLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 patientConfirmLogDao.save(confirmLogDO);
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 String failMsg = "保存工单关联的【居民确认操作日志记录】时:," + e.getMessage();
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 logger.error(failMsg);
 | 
	
		
			
				|  |  |                 return true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return false;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void sendWeixinMessage(Integer type,String doctorCode,String patient){
 | 
	
		
			
				|  |  |         if (type==3){
 | 
	
		
			
				|  |  |             //上门预约申请
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  | /*                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","zztj");
 | 
	
		
			
				|  |  |                 org.json.JSONObject sendJson = new org.json.JSONObject();
 | 
	
		
			
				|  |  |                 Patient patient1 =patientDao.findByCode(patient);
 | 
	
		
			
				|  |  |                 Doctor doctor = doctorDao.findByCode(doctorCode);
 | 
	
		
			
				|  |  |                 SignFamily signFamily = signFamilyDao.findByPatient(patient);
 | 
	
		
			
				|  |  |                 String doctorName = doctor.getName();
 | 
	
		
			
				|  |  |                 String first =doctorName+"医生,您好!"+patient1.getName()+"提交了上门出诊服务预约,请及时登录PC处理";
 | 
	
		
			
				|  |  |                 String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
 | 
	
		
			
				|  |  |                 List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("type", "15"));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("url", targetUrl));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("first", first));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("remark", templateConfig.getRemark()));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("keywords", "上门预约待派单"));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("keywords", signFamily.getHospitalName()));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("keywords", doctorName));
 | 
	
		
			
				|  |  |                 httpClientUtil.post(url, params, "UTF-8");
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + params);*/
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else if (type==4){
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 //社区调度员指派服务工单给家签医生
 | 
	
		
			
				|  |  | /*                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","zztj");
 | 
	
		
			
				|  |  |                 org.json.JSONObject sendJson = new org.json.JSONObject();
 | 
	
		
			
				|  |  |                 Doctor doctor = doctorDao.findByCode(doctorCode);
 | 
	
		
			
				|  |  |                 SignFamily signFamily = signFamilyDao.findByPatient(patient);
 | 
	
		
			
				|  |  |                 String doctorName = doctor.getName();
 | 
	
		
			
				|  |  |                 String first =doctorName+"医生,您好!您有新的服务工单,请及时登录APP或PC处理";
 | 
	
		
			
				|  |  |                 String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
 | 
	
		
			
				|  |  |                 List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("type", "15"));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("url", targetUrl));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("first", first));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("remark", templateConfig.getRemark()));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("keywords", "上门预约待接单"));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("keywords", signFamily.getHospitalName()));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("keywords", doctorName));
 | 
	
		
			
				|  |  |                 httpClientUtil.post(url, params, "UTF-8");
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + params);*/
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 调度员进入聊天室
 | 
	
		
			
				|  |  |      * @param dispatcher
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject dispatcherIntoTopic(String orderId, String hospitalName, String dispatcher, String dispatcherName) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO orderDO = baseDoorCoachOrderDao.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 (org.apache.commons.lang3.StringUtils.isEmpty(orderDO.getDispatcher())) {
 | 
	
		
			
				|  |  |             orderDO.setDispatcher(dispatcher);
 | 
	
		
			
				|  |  |             orderDO.setDispatcherName(dispatcherName);
 | 
	
		
			
				|  |  |             this.save(orderDO);
 | 
	
		
			
				|  |  |             // 先进入会话,再聊天
 | 
	
		
			
				|  |  |             imUtill.updateParticipantNew(sessionId,dispatcher,null);
 | 
	
		
			
				|  |  |             String noticeContent = hospitalName + dispatcherName + "为您服务";
 | 
	
		
			
				|  |  |             this.qucikSendIM(orderId, dispatcher, "智能助手", "1", noticeContent);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 把调度员拉入会话,作为其中一个成员
 | 
	
		
			
				|  |  |         imUtill.updateParticipantNew(sessionId,dispatcher,null);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, "调度员["+dispatcherName+"]进入会话成功");
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 工单与服务项费用关联关系
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param result
 | 
	
		
			
				|  |  |      * @param jsonObjectParam
 | 
	
		
			
				|  |  |      * @param order
 | 
	
		
			
				|  |  |      * {
 | 
	
		
			
				|  |  |      *     "packageItemArr":[
 | 
	
		
			
				|  |  |      *     {
 | 
	
		
			
				|  |  |      *    "type": null,
 | 
	
		
			
				|  |  |      *    "code": null,
 | 
	
		
			
				|  |  |      *    "name": null,
 | 
	
		
			
				|  |  |      *    "fee": null,
 | 
	
		
			
				|  |  |      *    "feeDiscount": null,
 | 
	
		
			
				|  |  |      *    "number": null,
 | 
	
		
			
				|  |  |      *    "status": null
 | 
	
		
			
				|  |  |      *  },
 | 
	
		
			
				|  |  |      *     ],
 | 
	
		
			
				|  |  |      *     "orderId": null,
 | 
	
		
			
				|  |  |      *     "status":""
 | 
	
		
			
				|  |  |      * }
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public boolean orderWithPackageItemFeeAdd(JSONObject result, JSONObject jsonObjectParam, BaseDoorCoachOrderDO order, String doctorId) {
 | 
	
		
			
				|  |  |         List<BaseDoorCoachFeeDetailDO> feeDetailDOList = new ArrayList<>();
 | 
	
		
			
				|  |  |         BigDecimal totalFee = order.getTotalFee();
 | 
	
		
			
				|  |  |         if(null == totalFee){
 | 
	
		
			
				|  |  |             totalFee = new BigDecimal(0);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //新增服务项
 | 
	
		
			
				|  |  |         int addNum = 0;
 | 
	
		
			
				|  |  |         //服务项费用
 | 
	
		
			
				|  |  |         JSONArray packageItemArray = jsonObjectParam.getJSONArray("packageItemArr");
 | 
	
		
			
				|  |  |         if (!CollectionUtils.isEmpty(packageItemArray)) {
 | 
	
		
			
				|  |  |             for (Object one : packageItemArray) {
 | 
	
		
			
				|  |  |                 BaseDoorCoachFeeDetailDO feeDetailDO = null;
 | 
	
		
			
				|  |  |                 JSONObject oneJson = (JSONObject)one;
 | 
	
		
			
				|  |  |                 try {
 | 
	
		
			
				|  |  |                     feeDetailDO = EntityUtils.jsonToEntity(one.toString(), BaseDoorCoachFeeDetailDO.class);
 | 
	
		
			
				|  |  |                 } 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(BaseDoorCoachFeeDetailDO.Status.patient.getType());
 | 
	
		
			
				|  |  |                 }else{
 | 
	
		
			
				|  |  |                     feeDetailDO.setStatus(status);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //                feeDetailDO.setNumber(1);
 | 
	
		
			
				|  |  |                 feeDetailDO.setOrderId(order.getId());
 | 
	
		
			
				|  |  |                 if(StringUtils.isBlank(feeDetailDO.getId())) {
 | 
	
		
			
				|  |  |                     feeDetailDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     feeDetailDO.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if(StringUtils.isBlank(feeDetailDO.getId())){
 | 
	
		
			
				|  |  |                     feeDetailDO.setPayStatus(0);
 | 
	
		
			
				|  |  |                     addNum++;
 | 
	
		
			
				|  |  |                     feeDetailDOList.add(feeDetailDO);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 baseDoorCoachFeeDetailDao.save(feeDetailDOList);
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 String failMsg = "保存服务费用到数据库异常:," + e.getMessage();
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 logger.error(failMsg);
 | 
	
		
			
				|  |  |                 return true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         order.setTotalFee(totalFee);
 | 
	
		
			
				|  |  |         this.save(order);
 | 
	
		
			
				|  |  |         return false;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> queryDispatcherInfoByHospital(String hospital){
 | 
	
		
			
				|  |  |         String sql ="    SELECT" +
 | 
	
		
			
				|  |  |                 "                 d.`code`, " +
 | 
	
		
			
				|  |  |                 "                 d.`name`, " +
 | 
	
		
			
				|  |  |                 "                 d.`hospital_name` as hospitalName " +
 | 
	
		
			
				|  |  |                 "                 FROM " +
 | 
	
		
			
				|  |  |                 "                 base_doctor_role m " +
 | 
	
		
			
				|  |  |                 "                 JOIN base_doctor_role_dict r ON m.role_code = r.code " +
 | 
	
		
			
				|  |  |                 "                 JOIN (select a.id code,a.name,o.org_name hospital_name from base_doctor_hospital o,base_doctor a " +
 | 
	
		
			
				|  |  |                 " where a.id = o.doctor_code and o.del=1 and o.org_code = '"+hospital+"') as d ON m.doctor_code = d.code" +
 | 
	
		
			
				|  |  |                 "                 WHERE " +
 | 
	
		
			
				|  |  |                 "                 r.code = 'dispatcher'";
 | 
	
		
			
				|  |  |         return jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取居民所签约的机构的调度员(一个机构可以有多个调度员)
 | 
	
		
			
				|  |  |      * doctor中,level -- 11-- 调度员
 | 
	
		
			
				|  |  |      * @param hospitalCode
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public JSONObject queryDispatcherInfoByPatient(String hospitalCode) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<Map<String,Object>> 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;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 顶部状态栏订单各分类总条数
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Map<String, Integer> getNumGroupByStatus(String patient) throws Exception {
 | 
	
		
			
				|  |  |         String sql = "SELECT a.status, COUNT(DISTINCT a.id) as num FROM base_door_coach_order a  where a.patient = '"+patient+"' group BY a.status " ;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         Map<String, Integer> map = new HashMap<>();
 | 
	
		
			
				|  |  |         Integer all = 0;
 | 
	
		
			
				|  |  |         Integer waitForPay = 0;//待付款
 | 
	
		
			
				|  |  |         Integer waitForAccept = 0;//待接单
 | 
	
		
			
				|  |  |         Integer waitForServe = 0;//待服务
 | 
	
		
			
				|  |  |         Integer served = 0;//已完成
 | 
	
		
			
				|  |  |         Integer cancel = 0;//已取消
 | 
	
		
			
				|  |  |         // -1已取消 [1,4]待服务 [5,6]已服务
 | 
	
		
			
				|  |  |         for (Map<String, Object> tmp:list){
 | 
	
		
			
				|  |  |             switch (String.valueOf(tmp.get("status"))){
 | 
	
		
			
				|  |  |                 case "-1":
 | 
	
		
			
				|  |  |                     cancel += Integer.valueOf(tmp.get("num").toString()) ;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "0":
 | 
	
		
			
				|  |  |                     waitForPay += Integer.valueOf(tmp.get("num").toString()) ;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "1":
 | 
	
		
			
				|  |  |                     waitForAccept += Integer.valueOf(tmp.get("num").toString()) ;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "2":
 | 
	
		
			
				|  |  |                     waitForAccept += Integer.valueOf(tmp.get("num").toString()) ;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "3":
 | 
	
		
			
				|  |  |                     waitForServe += Integer.valueOf(tmp.get("num").toString()) ;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "4":
 | 
	
		
			
				|  |  |                     waitForServe += Integer.valueOf(tmp.get("num").toString()) ;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "5":
 | 
	
		
			
				|  |  |                     waitForServe += Integer.valueOf(tmp.get("num").toString()) ;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "6":
 | 
	
		
			
				|  |  |                     served += Integer.valueOf(tmp.get("num").toString()) ;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 default: {
 | 
	
		
			
				|  |  |                     throw new Exception("类型错误!"+String.valueOf(tmp.get("status")));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         all = waitForPay+waitForAccept+waitForServe+served+cancel;
 | 
	
		
			
				|  |  |         map.put("all",all);
 | 
	
		
			
				|  |  |         map.put("waitForPay",waitForPay);
 | 
	
		
			
				|  |  |         map.put("waitForAccept",waitForAccept);
 | 
	
		
			
				|  |  |         map.put("waitForServe",waitForServe);
 | 
	
		
			
				|  |  |         map.put("served",served);
 | 
	
		
			
				|  |  |         map.put("cancel",cancel);
 | 
	
		
			
				|  |  |         return map;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param patientName
 | 
	
		
			
				|  |  |      * @param patientPhone
 | 
	
		
			
				|  |  |      * @param hospitalCode
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      * @param createTimeStart
 | 
	
		
			
				|  |  |      * @param createTimeEnd
 | 
	
		
			
				|  |  |      * @param serverDoctorName
 | 
	
		
			
				|  |  |      * @param patientId
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param pageSize
 | 
	
		
			
				|  |  |      * @param type
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject getDoorOrderList(String orderId, String patientName, String patientPhone, String hospitalCode,
 | 
	
		
			
				|  |  |                                        StringBuffer status, String createTimeStart, String createTimeEnd, String serverDoctorName,
 | 
	
		
			
				|  |  |                                        String patientId, Integer page, Integer pageSize, Integer type)throws Exception{
 | 
	
		
			
				|  |  |         String sqlList = "select DISTINCT o.id as orderId,o.status,h.code orgCode,h.name as orgName,o.is_trans_other_org," +
 | 
	
		
			
				|  |  |                 "o.transed_org_code, o.patient_name, o.patient_phone,o.remark,o.serve_desc,o.create_time,o.patient as patientCode," +
 | 
	
		
			
				|  |  |                 "o.exam_paper_status as examPaperStatus,o.number as serverCode,o.total_fee,h.org_level as hosLevel, o.doctor," +
 | 
	
		
			
				|  |  |                 "o.doctor_name as doctorName, o.doctor_type as doctorType"
 | 
	
		
			
				|  |  |                 ;
 | 
	
		
			
				|  |  |         String sqlCount = " select count(DISTINCT o.id) as total ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = " from base_door_coach_order o LEFT JOIN base_org h on h.code=o.hospital and h.del=1 where 1=1";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(!org.apache.commons.lang.StringUtils.isEmpty(orderId)){
 | 
	
		
			
				|  |  |             sql+=" and o.number = '"+orderId+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(!org.apache.commons.lang.StringUtils.isEmpty(patientName)){
 | 
	
		
			
				|  |  |             sql+=" and o.patient_name like '%"+patientName+"%'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(!org.apache.commons.lang.StringUtils.isEmpty(patientPhone)){
 | 
	
		
			
				|  |  |             sql+=" and o.patient_phone ='"+patientPhone+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(!org.apache.commons.lang.StringUtils.isEmpty(hospitalCode)&&!"350200%".equals(hospitalCode)){
 | 
	
		
			
				|  |  |             sql+=" and (o.hospital like '"+hospitalCode+"' or o.transed_org_code like '"+hospitalCode+"') ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(status!=null){
 | 
	
		
			
				|  |  |             sql+=" and o.status in ("+status+")";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(!org.apache.commons.lang.StringUtils.isEmpty(createTimeStart)){
 | 
	
		
			
				|  |  |             sql+=" and o.create_time >='"+createTimeStart+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(!org.apache.commons.lang.StringUtils.isEmpty(createTimeEnd)){
 | 
	
		
			
				|  |  |             sql+=" and o.create_time <='"+createTimeEnd+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(!org.apache.commons.lang.StringUtils.isEmpty(serverDoctorName)){
 | 
	
		
			
				|  |  |             sql+=" and o.doctor_name like '%"+serverDoctorName+"%'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //获取医生代预约记录
 | 
	
		
			
				|  |  |         if (type!=null){
 | 
	
		
			
				|  |  |             sql += " and o.type = " + type +" ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(org.apache.commons.lang.StringUtils.isNotBlank(patientId)){
 | 
	
		
			
				|  |  |             sql += " and o.patient= '"+patientId+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount+sql);
 | 
	
		
			
				|  |  |         sql+=" order by o.create_time desc LIMIT "+(page-1)*pageSize+","+pageSize;
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sqlList+sql);
 | 
	
		
			
				|  |  |         Long count = 0L;
 | 
	
		
			
				|  |  |         if(rstotal!=null&&rstotal.size()>0){
 | 
	
		
			
				|  |  |             count = (Long) rstotal.get(0).get("total");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         JSONArray jsonArray = new JSONArray();
 | 
	
		
			
				|  |  |         for(Map<String,Object> one:list){
 | 
	
		
			
				|  |  |             JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |             object.put("id",one.get("orderId"));
 | 
	
		
			
				|  |  |             object.put("serverCode",one.get("serverCode"));
 | 
	
		
			
				|  |  |             Integer statustemp = Integer.valueOf(one.get("status")+"");
 | 
	
		
			
				|  |  |             String statusName = "";
 | 
	
		
			
				|  |  |             switch (statustemp){
 | 
	
		
			
				|  |  |                 case -1:statusName="已取消";break;
 | 
	
		
			
				|  |  |                 case 0:statusName="待付款";break;
 | 
	
		
			
				|  |  |                 case 1:statusName="待接单";break;
 | 
	
		
			
				|  |  |                 case 2:statusName="待接单";break;
 | 
	
		
			
				|  |  |                 case 3:statusName="待服务";break;
 | 
	
		
			
				|  |  |                 case 4:statusName="待服务";break;
 | 
	
		
			
				|  |  |                 case 5:statusName="待服务";break;
 | 
	
		
			
				|  |  |                 case 6:statusName="已完成";break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             object.put("status",statustemp);
 | 
	
		
			
				|  |  |             object.put("statusName",statusName);
 | 
	
		
			
				|  |  |             //工单是否转给其他机构,0-不转,1-已转
 | 
	
		
			
				|  |  |             String transOtherOrg = one.get("is_trans_other_org")+"";
 | 
	
		
			
				|  |  |             Object hospitalName = null;
 | 
	
		
			
				|  |  |             Object hospital = null;
 | 
	
		
			
				|  |  |             hospital = one.get("orgCode");
 | 
	
		
			
				|  |  |             hospitalName = one.get("orgName");//签约表中的机构
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             object.put("hospital",hospital);
 | 
	
		
			
				|  |  |             object.put("hospitalName",hospitalName);
 | 
	
		
			
				|  |  |             object.put("patient",one.get("patientCode"));
 | 
	
		
			
				|  |  |             object.put("patientName",one.get("patient_name"));
 | 
	
		
			
				|  |  |             object.put("patientPhone",one.get("patient_phone"));
 | 
	
		
			
				|  |  |             object.put("remark",one.get("remark"));
 | 
	
		
			
				|  |  |             object.put("serveDesc",one.get("serve_desc"));
 | 
	
		
			
				|  |  |             object.put("hosLevel",one.get("hosLevel"));
 | 
	
		
			
				|  |  |             Date date = (Date)one.get("create_time");
 | 
	
		
			
				|  |  |             object.put("createTime",DateUtil.dateToStrLong(date));
 | 
	
		
			
				|  |  |             object.put("examPaperStatus",one.get("examPaperStatus"));
 | 
	
		
			
				|  |  |             object.put("totalFee",one.get("total_fee"));
 | 
	
		
			
				|  |  |             List<BaseDoorCoachFeeDetailDO> feeDetailDOs = doorFeeDetailDao.findByOrderIdAndType(one.get("orderId")+"", 1);
 | 
	
		
			
				|  |  |             List<Map<String,Object>> feeDetailResultList = new ArrayList();
 | 
	
		
			
				|  |  |             for(BaseDoorCoachFeeDetailDO d:feeDetailDOs){
 | 
	
		
			
				|  |  |                 Map<String,Object> map = new HashMap<>();
 | 
	
		
			
				|  |  |                 map.put("code",d.getCode());
 | 
	
		
			
				|  |  |                 map.put("name",d.getName());
 | 
	
		
			
				|  |  |                 map.put("fee",d.getFee());
 | 
	
		
			
				|  |  |                 map.put("number",d.getNumber());
 | 
	
		
			
				|  |  |                 feeDetailResultList.add(map);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             object.put("feeDetailResultList",feeDetailResultList);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             // 获取或者基本信息
 | 
	
		
			
				|  |  |             BasePatientDO patient = patientInfoService.findById(String.valueOf(one.get("patientCode")));
 | 
	
		
			
				|  |  |             if (patient != null) {
 | 
	
		
			
				|  |  |                 object.put("sex", IdCardUtil.getSexForIdcard(patient.getIdcard()));
 | 
	
		
			
				|  |  |                 object.put("age", IdCardUtil.getAgeByIdcardOrBirthday(patient.getIdcard(),patient.getBirthday()));
 | 
	
		
			
				|  |  |                 object.put("photo", patient.getPhoto());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //                object.put("typeValue", "儿童");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             String id = one.get("orderId").toString();
 | 
	
		
			
				|  |  |             BaseDoorCoachOrderDO doorServiceOrder = this.baseDoorCoachOrderDao.findOne(id);
 | 
	
		
			
				|  |  |             //获取咨询
 | 
	
		
			
				|  |  |             ConsultDo consult = consultDao.queryByRelationCode(id);
 | 
	
		
			
				|  |  |             if (null != consult) {
 | 
	
		
			
				|  |  |                 doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getId() + "_"  + doorServiceOrder.getNumber() +  "_" +  consult.getType());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             object.put("sessionId",doorServiceOrder.getSessionId());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             // 获取服务次数
 | 
	
		
			
				|  |  |             Integer serviceCount = doctorDoorCoachOrderService.serviceCount(doorServiceOrder.getPatient());
 | 
	
		
			
				|  |  |             object.put("serviceCount", serviceCount);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //添加服务医生
 | 
	
		
			
				|  |  |             object.put("doctorName", doorServiceOrder.getDoctorName());
 | 
	
		
			
				|  |  |             object.put("doctorType", doorServiceOrder.getDoctorType());
 | 
	
		
			
				|  |  |             object.put("type", doorServiceOrder.getType());
 | 
	
		
			
				|  |  |             jsonArray.add(object);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject object = new JSONObject();
 | 
	
		
			
				|  |  |         object.put("total",count);
 | 
	
		
			
				|  |  |         object.put("detailModelList",jsonArray);
 | 
	
		
			
				|  |  |         object.put("currPage",page);
 | 
	
		
			
				|  |  |         object.put("pageSize",pageSize);
 | 
	
		
			
				|  |  |         return object;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @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;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         BaseDoorCoachOrderDO wlyyDoorServiceOrder = baseDoorCoachOrderDao.findOne(jsonObjectParam.getString("orderId"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         wlyyDoorServiceOrder.setPatientName(jsonObjectParam.getString("patientName"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 居民电话
 | 
	
		
			
				|  |  |         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(), "智能助手", "2201", orderInfoContent.toJSONString());
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 添加【工单派单,转单】等系统消息
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void createMessage(String title,String type,String sender,String senderName,String relationCode,String Receiver,String ReceiverName,String idCard,String msg){
 | 
	
		
			
				|  |  |         SystemMessageDO messageDO = new SystemMessageDO();
 | 
	
		
			
				|  |  |         messageDO.setTitle(title);
 | 
	
		
			
				|  |  |         messageDO.setType(type);//401为资质申请审核
 | 
	
		
			
				|  |  |         messageDO.setSender(sender);
 | 
	
		
			
				|  |  |         messageDO.setSenderName(senderName);
 | 
	
		
			
				|  |  |         messageDO.setRelationCode(relationCode);
 | 
	
		
			
				|  |  |         messageDO.setReceiver(Receiver);
 | 
	
		
			
				|  |  |         messageDO.setReceiverName(ReceiverName);
 | 
	
		
			
				|  |  |         messageDO.setOver("1");
 | 
	
		
			
				|  |  |         messageDO.setData(msg);
 | 
	
		
			
				|  |  |         messageDO.setDel("1");
 | 
	
		
			
				|  |  |         messageDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         systemMessageDao.save(messageDO);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 统计居民已经服务的次数
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Integer countPatientDoorTimes(String patient){
 | 
	
		
			
				|  |  |         Integer count = 0;
 | 
	
		
			
				|  |  |         String sql = "SELECT count(o.id) as count FROM base_door_coach_order o where  o.patient = '" + patient + "' and status>="+BaseDoorCoachOrderDO.Status.waitForCommnet.getType();
 | 
	
		
			
				|  |  |         count = jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |         return count;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private String getRandomIntStr(){
 | 
	
		
			
				|  |  |         Random rand = new Random();
 | 
	
		
			
				|  |  |         int i = rand.nextInt(); //int范围类的随机数
 | 
	
		
			
				|  |  |         i = rand.nextInt(100); //生成0-100以内的随机数
 | 
	
		
			
				|  |  |         i = (int)(Math.random() * 100000000); //0-100以内的随机数,用Matn.random()方式
 | 
	
		
			
				|  |  |         return String.valueOf(i);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |