Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

LAPTOP-KB9HII50\70708 1 năm trước cách đây
mục cha
commit
9aec85695d

+ 44 - 7
business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java

@ -678,16 +678,16 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        logger.info("map:"+map.toString());
        Map<String, Object> pay = unifiedorder(map, wxWechatDO.getAppKey());
        String returnCode = pay.get("return_code").toString();
        String resultCode = pay.get("result_code").toString();
        System.out.println("-----返回结果:"+resultCode);
        System.out.println("-----return_code:"+returnCode);
        if (returnCode.equalsIgnoreCase("SUCCESS")){
            String appid = pay.get("appid").toString();
            String mchId = pay.get("mch_id").toString();
            String nonceStr = pay.get("nonce_str").toString();
            String prepayId = pay.get("prepay_id").toString();
            String trade = "";
            String resultCode = pay.get("result_code").toString();
            System.out.println("-----返回结果:"+resultCode);
            if ("SUCCESS".equalsIgnoreCase(resultCode)){
                String appid = pay.get("appid").toString();
                String mchId = pay.get("mch_id").toString();
                String nonceStr = pay.get("nonce_str").toString();
                String prepayId = pay.get("prepay_id").toString();
                String trade = "";
                trade = pay.get("trade_type").toString();
                if (trade.equalsIgnoreCase("Native")){
                    Map<String,String> param = new HashedMap();
@ -744,6 +744,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
    }
    /**
     * 微信退款
     * @param wechatId
@ -1132,6 +1133,42 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        return rs;
    }
    public Map<String,String> getWxPayResultCloudNotify(String result) {
        Map<String,String> rs = new HashedMap();
        Map<String,Object> wxrs =  XMLUtil.xmltoMap(result);
        logger.info("回调参数"+wxrs+"==============="+result);
        if("SUCCESS".equals(wxrs.get("return_code").toString())){
            // 我方 订单号+时间差
            String seqNo = wxrs.get("out_trade_no")+"";
            String totalFee=wxrs.get("total_fee")+"";
            // 微信充值流水号
            String wxSeqNo = wxrs.get("transaction_id")+"";
            // 微信分配的终端设备号
            String wxDeviceInfo = wxrs.get("device_info")+"";
            String timeEnd= wxrs.get("time_end")+"";
            //更改业务状态,做日志保存等操作
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(seqNo);
            businessOrderDO.setPayTime(DateUtil.strToDate(timeEnd,DateUtil.YYYY_MM_DD_HH_MM_SS));
            businessOrderDO.setStatus(1);
            businessOrderDO.setUpdateTime(new Date());
            businessOrderDao.save(businessOrderDO);
            //操作微信日志表记录
            List<WxPayLogDO> wxPayLogDOs = wxPayLogDao.findBySeqNo(seqNo);
            WxPayLogDO wxPayLogDO = wxPayLogDOs.get(0);
            wxPayLogDO.setPayResponse(result);
            wxPayLogDO.setPayStatus(1);
            wxPayLogDO.setPayTime(new Date());
            wxPayLogDO.setPayStatus(1);
            wxPayLogDao.save(wxPayLogDO);
            rs.put("return_code","SUCCESS");
            rs.put("return_msg","OK");
        }else{
            rs.put("return_code","FAIL");
            rs.put("return_msg","OK");
        }
        return rs;
    }
    public String sendDataToYkt(String orderNo){

+ 6 - 0
business/base-service/src/main/java/com/yihu/jw/wechat/dao/WxTemplateConfigDao.java

@ -2,7 +2,9 @@ package com.yihu.jw.wechat.dao;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.entity.wechat.WechatTemplateConfig;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
@ -16,4 +18,8 @@ public interface WxTemplateConfigDao extends PagingAndSortingRepository<WxTempla
    WxTemplateConfigDO findByWechatIdAndTemplateNameAndScene(String wechatId, String templateName, String scene);
    List<WxTemplateConfigDO> findByWechatIdAndScene(String wechatId, String scene);
    //根据自定义模板名称、场景值查询有效模板内容
    @Query("select t  from WxTemplateConfigDO t where t.templateName=?1 and t.scene=?2 and t.status = 1 ")
    WxTemplateConfigDO findByScene(String template_process_feedback, String smyyyqx);
}

+ 25 - 11
business/im-service/src/main/java/com/yihu/jw/im/util/ImUtil.java

@ -458,13 +458,15 @@ public class ImUtil {
     */
    public String updateParticipant(String sessionId, String user, String oldUserId) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participant/update";
        System.out.println("更新会话成员-地址:" + imAddr);
        JSONObject params = new JSONObject();
        params.put("session_id", sessionId);
        params.put("user_id", user);
        if (!StringUtils.isEmpty(oldUserId)) {
            params.put("old_user_id", oldUserId);
        }
        return HttpClientUtil.postBody(imAddr, params);
        String res = HttpClientUtil.postBody(imAddr, params);
        return res;
    }
    /**
@ -475,14 +477,23 @@ public class ImUtil {
     * @param oldUserId 删除的成员id
     */
    public String updateParticipantNew(String sessionId, String user, String oldUserId) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participant/updateNew";
        JSONObject params = new JSONObject();
        params.put("session_id", sessionId);
        params.put("user_id", user);
        if (!StringUtils.isEmpty(oldUserId)) {
            params.put("old_user_id", oldUserId);
        try {
            String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participant/updateNew";
            System.out.println("更新会话成员-地址:" + imAddr);
            JSONObject params = new JSONObject();
            params.put("session_id", sessionId);
            params.put("user_id", user);
            if (!StringUtils.isEmpty(oldUserId)) {
                params.put("old_user_id", oldUserId);
            }
            System.out.println("参数:" + JSON.toJSONString(params));
            String res = HttpClientUtil.postBody(imAddr, params);
            System.out.println("响应结果:" + res);
            return res;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return HttpClientUtil.postBody(imAddr, params);
        return null;
    }
    /**
@ -560,10 +571,13 @@ public class ImUtil {
            params.put("messages", messages.toString());
            params.put("session_id", sessionId);
            params.put("session_type", sessionType);
            String ret = HttpClientUtil.postBody(imAddr, params);
            obj = JSON.parseObject(ret);
            System.out.println("创建议题==>" + "\n地址:" + imAddr + "\n参数:" + JSON.toJSONString(params));
            String res = HttpClientUtil.postBody(imAddr, params);
            System.out.println("结果:" + res);
            obj = JSON.parseObject(res);
        } catch (Exception e) {
			System.out.println("创建议题失败:topicId=>" + topicId);
            e.printStackTrace();
            System.out.println("创建议题失败:topicId=>" + topicId);
            return null;
        }
        return obj;

+ 47 - 3
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PayEndpoint.java

@ -8,11 +8,15 @@ import com.yihu.jw.care.service.doorCoach.PatientDoorCoachOrderService;
import com.yihu.jw.care.service.pay.PayService;
import com.yihu.jw.care.util.WxpayUtil;
import com.yihu.jw.care.util.XMLUtil;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
import com.yihu.jw.order.dao.BusinessOrderDao;
import com.yihu.jw.order.dao.BusinessOrderRefundDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
@ -21,6 +25,7 @@ import com.yihu.jw.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -28,7 +33,10 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -175,7 +183,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = "cloudWxPay")
    @ApiOperation(value = "云照护支付")
    @ObserverRequired
    public ObjEnvelop wxWapPay(
    public ObjEnvelop cloudWxPay(
            @ApiParam(name = "relationCode", value = "关联表id")
            @RequestParam(value = "relationCode", required = false) String relationCode,
            @ApiParam(name = "relationName", value = "关联表名称")
@ -188,17 +196,31 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            @RequestParam(value = "doctor", required = false) String doctor,
            @ApiParam(name = "fee", value = "费用金额")
            @RequestParam(value = "fee", required = false) String fee,
            @ApiParam(name = "depositType", value = "支付类型")
            @ApiParam(name = "depositType", value = "支付类型 NATIVE pc二维码,JSAPI 公众号支付,APPLETS 小程序支付")
            @RequestParam(value = "depositType", required = false) String depositType,
            @ApiParam(name = "appletCode", value = "费用金额")
            @RequestParam(value = "appletCode", required = false) String appletCode) {
        try{
            return ObjEnvelop.getSuccess("请求成功",payService.cloudWxPay(relationCode,relationName,orderType,patient,doctor,fee,depositType, appletCode));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "selectOrderByRelationCode")
    @ApiOperation(value = "云照护支付查询记录")
    @ObserverRequired
    public ObjEnvelop selectOrderByRelationCode(
            @ApiParam(name = "relationCode", value = "关联表id")
            @RequestParam(value = "relationCode", required = true) String relationCode) {
        try{
            return ObjEnvelop.getSuccess("请求成功",payService.selectOrderByRelationCode(relationCode));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping(value = "cloudWxRefund")
    @ApiOperation(value = "云照护支付退款")
@ -219,6 +241,29 @@ public class PayEndpoint extends EnvelopRestEndpoint {
        }
    }
    /**
     * 微信支付回调
     *
     * @param request
     * @return java.lang.String
     */
    @PostMapping("open/cloudPayNotify")
    @ResponseBody
    @ApiOperation("云照护微信支付回调")
    public String cloudPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String result = "";
        String inputLine;
        while ((inputLine = request.getReader().readLine()) != null) {
            result += inputLine;
        }
        request.getReader().close();
        //im处方发消息
        Map<String,Object> wxrs =  com.yihu.jw.util.common.XMLUtil.xmltoMap(result);
        Map<String, String> map = new HashedMap();
        map= payService.getWxPayResultCloudNotify(result);
        return com.yihu.jw.util.common.XMLUtil.map2xml(map);
    }
    @PostMapping(value = "applyRefund")
    @ApiOperation(value = "申请退款")
    @ObserverRequired
@ -315,7 +360,6 @@ public class PayEndpoint extends EnvelopRestEndpoint {
        }
    }
    /**
     * 微信支付退款回调
     *

+ 343 - 319
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/doorCoach/PatientDoorCoachOrderService.java

@ -129,6 +129,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        }
        BaseDoorCoachOrderDO orderDO = null;
        try {
            System.out.println(jsonObjectParam.get("order").toString());
            orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), BaseDoorCoachOrderDO.class);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
@ -149,7 +150,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        orderDO.setPayStatus(0);//待付款
//        orderDO.setConclusionStatus(1);
        if(StringUtils.isEmpty(orderDO.getPatient())){
        if (StringUtils.isEmpty(orderDO.getPatient())) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient();
            result.put(ResponseContant.resultMsg, failMsg);
@ -157,7 +158,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            return result;
        }
        if(StringUtils.isEmpty(orderDO.getProxyPatient())){
        if (StringUtils.isEmpty(orderDO.getProxyPatient())) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前代理对象code为空,请联系管理员检查参数!proxyPatient = " + orderDO.getProxyPatient();
            result.put(ResponseContant.resultMsg, failMsg);
@ -175,7 +176,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
                        BaseDoorCoachOrderDO.Status.accept.getType(),
                });
        if(bool){
        if (bool) {
            String failMsg = "当前服务对象存在未支付或未完成的上门预约,无法再次申请!";
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, failMsg);
@ -186,9 +187,9 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
        orderDO.setCreateTime(new Date());
        //判断创建上门预约类型,发起类型(1本人发起 2家人待预约 3医生代预约)
        if(orderDO.getProxyPatient().equals(orderDO.getPatient())){
        if (orderDO.getProxyPatient().equals(orderDO.getPatient())) {
            orderDO.setType(1);
        }else if(!orderDO.getProxyPatient().equals(orderDO.getPatient())){
        } else if (!orderDO.getProxyPatient().equals(orderDO.getPatient())) {
            orderDO.setType(2);
        }
        orderDO.setServiceStatus("1");
@ -208,25 +209,27 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
                baseAdminServiceDynamic.setPhoto(patientDO.getPhoto());
            }
            baseAdminServiceDynamicDao.save(baseAdminServiceDynamic);
        }catch (Exception e) {
        } catch (Exception e) {
            logger.info(e.getMessage());
        }
        this.save(orderDO);
        result.put("orderId",orderDO.getId());
        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;}
        if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO, null)) {
            return result;
        }
        //发起支付订单
        payService.submitOrder(orderDO.getPatient(),"3",orderDO.getId(),orderDO.getTotalFee().doubleValue());
        payService.submitOrder(orderDO.getPatient(), "3", orderDO.getId(), orderDO.getTotalFee().doubleValue());
        return result;
    }
    @Transactional
    public JSONObject proxyCreate(String jsonData,String doctorCode) {
    public JSONObject proxyCreate(String jsonData, String doctorCode) {
        JSONObject result = new JSONObject();
        //医养暂无该功能--屏蔽
        result.put(ResponseContant.resultFlag, ResponseContant.fail);
@ -337,25 +340,25 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        JSONObject result = new JSONObject();
        try {
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(orderId);
            if (businessOrderDO==null){
            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){
            BaseDoorCoachOrderDO orderDO = baseDoorCoachOrderDao.findOne(orderId);
            if (orderDO != null) {
                orderDO.setPayStatus(1);
                orderDO.setPayWay(1);
                orderDO.setPayTime(new Date());
                if (orderDO.getType()== 3){//医生代预约
                if (orderDO.getType() == 3) {//医生代预约
                    orderDO.setStatus(2);//待接单
                    this.save(orderDO);
                    // 给服务医生发接单消息
                    this.createMessage("服务工单待接单","707",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(),orderDO.getDoctor(),orderDO.getDoctorName(), null,"您有新的服务工单,请前往处理");
                    this.createMessage("服务工单待接单", "707", orderDO.getProxyPatient(), orderDO.getProxyPatientName(), orderDO.getId(), orderDO.getDoctor(), orderDO.getDoctorName(), null, "您有新的服务工单,请前往处理");
                    //发送智能助手消息
                    sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
                }else {
                    sendWeixinMessage(4, orderDO.getDoctor(), orderDO.getPatient());
                } else {
                    //创建咨询
                    JSONObject successOrNot = null;
                    try {
@ -372,47 +375,46 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
                        return JSONObject.parseObject(successOrNot.toString());
                    }
                    ConsultTeamDo consultTeam = (ConsultTeamDo)successOrNot.get(ResponseContant.resultMsg);
                    ConsultTeamDo consultTeam = (ConsultTeamDo) successOrNot.get(ResponseContant.resultMsg);
                    //发送智能助手消息
                    sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
                    sendWeixinMessage(4, orderDO.getDoctor(), orderDO.getPatient());
                    //发送 预约卡片信息(2201类型)
                    JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
                    orderInfoContent.put("re_msg_type",0);//居民预约
                    orderInfoContent.put("re_msg_type", 0);//居民预约
                    this.qucikSendIM(orderDO.getId(), "system", "智能助手", "2201", orderInfoContent.toJSONString());
                    if(StringUtils.isNoneBlank(orderDO.getDoctor())){
                    if (StringUtils.isNoneBlank(orderDO.getDoctor())) {
                        //期望服务医生存在,直接转派
                        BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
                        sendOrderToDoctor(orderDO.getId(),null,"system","系统",transDoctor.getId(),transDoctor.getName(),transDoctor.getJobTitleName());
                    }else {
                        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){
                        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() + "提交了服务预约申请,请您前往处理");
                                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()+"申请");
                                this.createMessage("居民提交工单申请", "730", "system", "system", orderDO.getId(), dispatcher, doctorVO.getName(), doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务工单" + orderDO.getNumber() + "申请");
                            }
                        }
                    }
                    serviceNewsService.addServiceNews(orderDO.getPatientName(),orderDO.getPatient(),"1",null,orderId,1);
                    serviceNewsService.addServiceNews(orderDO.getPatientName(), orderDO.getPatient(), "1", null, orderId, 1);
                    String failMsg = "success";
                    result.put(ResponseContant.resultFlag, ResponseContant.success);
                    result.put(ResponseContant.resultMsg, failMsg);
                }
            }
            else {
            } else {
                String failMsg = "工单不存在";
                result.put(ResponseContant.resultFlag, ResponseContant.fail);
                result.put(ResponseContant.resultMsg, failMsg);
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
@ -422,8 +424,8 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    public JSONObject refundOrderAfter(String orderId) {
        JSONObject result = new JSONObject();
        try {
            BaseDoorCoachOrderDO orderDO= baseDoorCoachOrderDao.findOne(orderId);
            if (orderDO == null){
            BaseDoorCoachOrderDO orderDO = baseDoorCoachOrderDao.findOne(orderId);
            if (orderDO == null) {
                String failMsg = "工单不存在";
                result.put(ResponseContant.resultFlag, ResponseContant.fail);
                result.put(ResponseContant.resultMsg, failMsg);
@ -434,7 +436,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            String failMsg = "success";
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, failMsg);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
@ -442,26 +444,27 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    /**
     * 根据接单医生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){
        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+"' ";
    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+"%' ";
        if (StringUtils.isNotBlank(serverItemName)) {
            sql += " and dict_value like '%" + serverItemName + "%' ";
        }
        List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
        return result;
    }
@ -471,7 +474,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
     *
     * @return
     */
    public JSONObject queryDoctorListWithNotStopped(String hospital,int page, int size) {
    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;
@ -480,26 +483,26 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
                " 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 ;
                " 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<>();
        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 );
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
        }
        Integer count = 0;
        try {
            count = jdbcTemplate.queryForObject(countSql,Integer.class);
            count = jdbcTemplate.queryForObject(countSql, Integer.class);
        } catch (Exception e) {
            String failMsg = "从数据库统计  可接单状态的服务医生人员 数量失败:" + e.getMessage();
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
@ -548,25 +551,25 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    /**
     * 删除出诊医生或服务项
     * @param jsonObjectParam
     * {
     *     "deleteItemArr":[
     *        {
     *           "id":""
     *       },
     *        {
     *           "id":""
     *      }
     *     ],
     *     "deleteDoctorArr":[
     *     {
     *         "id":""
     *     },
     *      {
     *         "id":""
     *     }
     *     ]
     * }
     *
     * @param jsonObjectParam {
     *                        "deleteItemArr":[
     *                        {
     *                        "id":""
     *                        },
     *                        {
     *                        "id":""
     *                        }
     *                        ],
     *                        "deleteDoctorArr":[
     *                        {
     *                        "id":""
     *                        },
     *                        {
     *                        "id":""
     *                        }
     *                        ]
     *                        }
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
@ -578,10 +581,10 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            List<BaseDoorCoachFeeDetailDO> list = new ArrayList<>();
            //删除的服务项要减去服务项费用
            BigDecimal itemFee = new BigDecimal(0);
            for(Object oneId : itemArray) {
            for (Object oneId : itemArray) {
                JSONObject oneIdJson = (JSONObject) oneId;
                BaseDoorCoachFeeDetailDO doorFeeDetail = baseDoorCoachFeeDetailDao.findOne(String.valueOf(oneIdJson.get("id")));
                if(doorFeeDetail.getPayStatus()==0){
                if (doorFeeDetail.getPayStatus() == 0) {
                    doorFeeDetail.setStatus(3);
                    doorFeeDetail.setUpdateTime(new Date());
                    list.add(doorFeeDetail);
@ -618,7 +621,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    /**
     * 查询预约简要卡片信息
     *
     * <p>
     * 服务时间:2019-01-01   12:30
     * 服务对象:张三
     * 联系电话:13125256565(儿子)
@ -627,54 +630,56 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
     * @param orderDO
     * @return
     */
    public JSONObject queryOrderCardInfo(BaseDoorCoachOrderDO orderDO){
    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("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{
        } else {
            if (StringUtils.isBlank(orderDO.getDoctorArrivingTime())) {
                result.put("time", "工作时间");
            } else {
                result.put("time", orderDO.getDoctorArrivingTime());
            }
        }
        result.put("patientName",patientDO.getName());
        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);
        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) {
    public int qucikSendIM(String orderId, String sendId, String sendName, String contentType, String content) {
        int result = -1;
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        if (null == consult) {
@ -685,14 +690,14 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        BaseDoorCoachOrderDO baseDoorCoachOrderDO = null;
        String response = null;
        if(StringUtils.isBlank(sendId)){
        if (StringUtils.isBlank(sendId)) {
            baseDoorCoachOrderDO = baseDoorCoachOrderDao.findOne(orderId);
            String sender = "system";
            if(StringUtils.isNoneBlank(baseDoorCoachOrderDO.getDispatcher())){
            if (StringUtils.isNoneBlank(baseDoorCoachOrderDO.getDispatcher())) {
                sender = baseDoorCoachOrderDO.getDispatcher();
            }
            response = imUtill.sendTopicIM(sender, "智能助手", consult.getId(), contentType, content, null);
        }else{
        } else {
            response = imUtill.sendTopicIM(sendId, sendName, consult.getId(), contentType, content, null);
        }
        JSONObject resObj = JSONObject.parseObject(response);
@ -712,11 +717,11 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public JSONObject sendOrderToDoctor(String orderId,String remark,String dispatcher,String dispathcherName,String doctor,String doctorName,String doctorJobName){
    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){
        if (null == doorServiceOrderDO) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前工单不存在,id:" + orderId;
            result.put(ResponseContant.resultMsg, failMsg);
@ -724,19 +729,19 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            return result;
        }
        BaseDoorCoachDoctorStatusDO doorDoctorStatusDO = baseDoorCoachDoctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{BaseDoorCoachOrderDO.Status.waitForSend.getType(),
        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){
        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)){
        if (StringUtils.isNotBlank(remark) && !"null".equals(remark)) {
            doorServiceOrderDO.setRemark(remark);
        }
        doorServiceOrderDO.setDoctor(doctor);
@ -751,19 +756,19 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        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,"您有新的服务工单,请前往处理");
        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());
        sendWeixinMessage(4, doctor, doorServiceOrderDO.getPatient());
        // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getType();
        imUtill.updateParticipantNew(sessionId,doctor,null);
        messageUtil.updateDoorCoachMessage(doorServiceOrderDO,new String[]{"702","703","730","735"},"731",dispatcher,dispatcher);
        imUtill.updateParticipantNew(sessionId, doctor, null);
        messageUtil.updateDoorCoachMessage(doorServiceOrderDO, new String[]{"702", "703", "730", "735"}, "731", dispatcher, dispatcher);
        // 工单状态变更记录
        BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
@ -778,8 +783,8 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        result.put(ResponseContant.resultMsg, doorServiceOrderDO);
        // 发送IM消息通知患者医生已派单
        String noticeContent = "已分派"+doorServiceOrderDO.getDoctorName()+"医生为您服务,请耐心等待医生接单";
        this.qucikSendIM(doorServiceOrderDO.getId(), doorServiceOrderDO.getDispatcher(), "智能助手","1", noticeContent);
        String noticeContent = "已分派" + doorServiceOrderDO.getDoctorName() + "医生为您服务,请耐心等待医生接单";
        this.qucikSendIM(doorServiceOrderDO.getId(), doorServiceOrderDO.getDispatcher(), "智能助手", "1", noticeContent);
        return result;
    }
@ -791,10 +796,10 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public JSONObject transferOrder(String orderId,String remark,String dispatcher,String dispathcherName,String doctor,String doctorName,String doctorJobName){
    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){
        if (null == doorServiceOrderDO) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前工单不存在,id:" + orderId;
            result.put(ResponseContant.resultMsg, failMsg);
@ -802,12 +807,12 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            return result;
        }
        BaseDoorCoachDoctorStatusDO doorDoctorStatusDO = baseDoorCoachDoctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{BaseDoorCoachDoctorStatusDO.Status.waitForSend.getType(),
        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){
        if (null == doorDoctorStatusDO) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前转派单的医生不存在或禁止接单,doctor:" + doctor;
            result.put(ResponseContant.resultMsg, failMsg);
@ -824,26 +829,26 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        doorServiceOrderDO.setUpdateUserName(dispathcherName);
        doorServiceOrderDO.setDispatcherResponseTime(new Date());
        System.out.println(dispathcherName+"医生派单给"+doctorName+"医生");
        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,"您有新的服务工单,请前往处理");
        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());
        sendWeixinMessage(4, doctor, doorServiceOrderDO.getPatient());
        // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getType();
        imUtill.updateParticipantNew(sessionId,doctor,null);
        imUtill.updateParticipantNew(sessionId, doctor, null);
        messageUtil.updateDoorCoachMessage(doorServiceOrderDO,new String[]{"702","703","730","735"},"731",dispatcher,dispatcher);
        messageUtil.updateDoorCoachMessage(doorServiceOrderDO, new String[]{"702", "703", "730", "735"}, "731", dispatcher, dispatcher);
        // 工单状态变更记录
        BaseDoorCoachProcessLogDO processLogDO = new BaseDoorCoachProcessLogDO();
@ -858,29 +863,30 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        result.put(ResponseContant.resultMsg, doorServiceOrderDO);
        // 发送IM消息通知患者医生已派单
        String noticeContent = "已转派"+doorServiceOrderDO.getDoctorName()+"医生为您服务,请耐心等待医生接单";
        this.qucikSendIM(doorServiceOrderDO.getId(), dispatcher, "智能助手","1", noticeContent);
        String noticeContent = "已转派" + doorServiceOrderDO.getDoctorName() + "医生为您服务,请耐心等待医生接单";
        this.qucikSendIM(doorServiceOrderDO.getId(), dispatcher, "智能助手", "1", noticeContent);
        return result;
    }
    /**
     * 取消工单
     *
     * @param orderId
     * @param type 取消类型
     * @param reason 取消理由
     * @param type    取消类型
     * @param reason  取消理由
     */
    public JSONObject cancelOrder(String orderId,int type,String reason,String dispatcher,String dispatcherName){
    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){
        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()){
        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);
@ -890,60 +896,59 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(orderDO.getId());
            businessOrderDO.setStatus(2);
            businessOrderDao.save(businessOrderDO);
        }else{//调度员拒单,此时工单已支付抵达调度员
        } else {//调度员拒单,此时工单已支付抵达调度员
            try {
                if (orderDO.getStatus() > BaseDoorCoachOrderDO.Status.waitForPay.getType()&&1==orderDO.getPayWay()){
                if (orderDO.getStatus() > BaseDoorCoachOrderDO.Status.waitForPay.getType() && 1 == orderDO.getPayWay()) {
                    BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(orderDO.getId());
                    if (businessOrderDO!=null){
                    if (businessOrderDO != null) {
                        //1.4.2 上门辅导费用0时 无需走退款流程
                        if (1 == businessOrderDO.getStatus()&&businessOrderDO.getPayPrice()>0.0){
                        if (1 == businessOrderDO.getStatus() && businessOrderDO.getPayPrice() > 0.0) {
                            //退款流程
                            try {
                                payService.dispatcherOrderRefund(businessOrderDO.getOrderNo(),"调度员拒单退款");
                                payService.dispatcherOrderRefund(businessOrderDO.getOrderNo(), "调度员拒单退款");
                                orderDO.setPayStatus(2);
                            }catch (Exception e){
                            } catch (Exception e) {
                                e.printStackTrace();
                                result.put(ResponseContant.resultFlag, ResponseContant.fail);
                                result.put(ResponseContant.resultMsg,"退款失败,无法拒绝工单!");
                                result.put(ResponseContant.resultMsg, "退款失败,无法拒绝工单!");
                                return result;
                            }
                        }
                    }
                }
                //如果是调度员取消,推送IM取消工单json消息,
                if (StringUtils.isNotBlank(dispatcher)){
                    if (!consultTeamService.finishConsult(orderDO.getId(),orderDO.getPatient(),dispatcher,2)){
                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);
                        result.put(ResponseContant.resultMsg, failMsg);
                        return result;
                    }
                }
                if(!StringUtils.isEmpty(dispatcher)){
                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);
                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() : "");
                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){
                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()),"上门预约已取消","已取消");
                    messageUtil.putTemplateWxMessage(wxId, "template_process_feedback", "smyyyqx", openId, first, null, null, 2, json, DateUtil.dateToChineseDate(new Date()), "上门预约已取消", "已取消");
                }
            }catch (Exception e){
            } catch (Exception e) {
                e.printStackTrace();
                String failMsg = "退款失败,无法取消工单:," + orderId;
                result.put(ResponseContant.resultMsg, failMsg);
@ -969,14 +974,14 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        //保存居民确认取消记录
        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);
        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);
        confirmInfoJson.put("confirmInfo", confirmInfo);
        this.orderWithConfirmLogAdd(result, confirmInfo, orderId);
        // 工单状态变更记录
@ -994,14 +999,14 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    /**
     * 服务工单居民确认操作日志记录
     *
     * <p>
     * {
     *     "confirmInfo":{
     *         "patient":"",
     *         "patientName":"",
     *         "type":"",
     *         "description":""
     *     }
     * "confirmInfo":{
     * "patient":"",
     * "patientName":"",
     * "type":"",
     * "description":""
     * }
     * }
     *
     * @param result
@ -1039,8 +1044,8 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        return false;
    }
    public void sendWeixinMessage(Integer type,String doctorCode,String patient){
        if (type==3){
    public void sendWeixinMessage(Integer type, String doctorCode, String patient) {
        if (type == 3) {
            //上门预约申请
            try {
/*                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","zztj");
@ -1065,7 +1070,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else if (type==4){
        } else if (type == 4) {
            try {
                //社区调度员指派服务工单给家签医生
/*                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","zztj");
@ -1096,6 +1101,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    /**
     * 调度员进入聊天室
     *
     * @param dispatcher
     * @param orderId
     */
@ -1110,21 +1116,23 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            return result;
        }
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        String sessionId = orderDO.getPatient() + "_" +  consult.getType();
        String sessionId = orderDO.getPatient() + "_" + 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 imMsg = imUtill.updateParticipantNew(sessionId, dispatcher, null);
            System.out.println("先进入会话,再聊天==>" + imMsg);
            String noticeContent = hospitalName + dispatcherName + "为您服务";
            this.qucikSendIM(orderId, dispatcher, "智能助手", "1", noticeContent);
        }
        // 把调度员拉入会话,作为其中一个成员
        imUtill.updateParticipantNew(sessionId,dispatcher,null);
        String imMsg = imUtill.updateParticipantNew(sessionId, dispatcher, null);
        System.out.println("把调度员拉入会话,作为其中一个成员:" + imMsg);
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, "调度员["+dispatcherName+"]进入会话成功");
        result.put(ResponseContant.resultMsg, "调度员[" + dispatcherName + "]进入会话成功");
        return result;
    }
@ -1133,30 +1141,28 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
     *
     * @param result
     * @param jsonObjectParam
     * @param order
     * {
     *     "packageItemArr":[
     *     {
     *    "type": null,
     *    "code": null,
     *    "name": null,
     *    "fee": null,
     *    "feeDiscount": null,
     *    "number": null,
     *    "status": null
     *  },
     *     ],
     *     "orderId": null,
     *     "status":""
     * }
     *
     * @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){
        if (null == totalFee) {
            totalFee = new BigDecimal(0);
        }
@ -1167,7 +1173,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        if (!CollectionUtils.isEmpty(packageItemArray)) {
            for (Object one : packageItemArray) {
                BaseDoorCoachFeeDetailDO feeDetailDO = null;
                JSONObject oneJson = (JSONObject)one;
                JSONObject oneJson = (JSONObject) one;
                try {
                    feeDetailDO = EntityUtils.jsonToEntity(one.toString(), BaseDoorCoachFeeDetailDO.class);
                } catch (Exception e) {
@ -1190,20 +1196,20 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
                // 服务项可能一开始由居民预约,后期由医生新增或医生删除
                Integer status = jsonObjectParam.getInteger("status");
                if(null == status || status == 1){
                if (null == status || status == 1) {
                    feeDetailDO.setStatus(BaseDoorCoachFeeDetailDO.Status.patient.getType());
                }else{
                } else {
                    feeDetailDO.setStatus(status);
                }
//                feeDetailDO.setNumber(1);
                feeDetailDO.setOrderId(order.getId());
                if(StringUtils.isBlank(feeDetailDO.getId())) {
                if (StringUtils.isBlank(feeDetailDO.getId())) {
                    feeDetailDO.setCreateTime(new Date());
                }else {
                } else {
                    feeDetailDO.setUpdateTime(new Date());
                }
                if(StringUtils.isBlank(feeDetailDO.getId())){
                if (StringUtils.isBlank(feeDetailDO.getId())) {
                    feeDetailDO.setPayStatus(0);
                    addNum++;
                    feeDetailDOList.add(feeDetailDO);
@ -1225,8 +1231,8 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        return false;
    }
    public List<Map<String,Object>> queryDispatcherInfoByHospital(String hospital){
        String sql ="    SELECT" +
    public List<Map<String, Object>> queryDispatcherInfoByHospital(String hospital) {
        String sql = "    SELECT" +
                "                 d.`code`, " +
                "                 d.`name`, " +
                "                 d.`hospital_name` as hospitalName " +
@ -1234,7 +1240,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
                "                 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 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);
@ -1243,6 +1249,7 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    /**
     * 获取居民所签约的机构的调度员(一个机构可以有多个调度员)
     * doctor中,level -- 11-- 调度员
     *
     * @param hospitalCode
     * @return
     */
@ -1250,8 +1257,8 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    public JSONObject queryDispatcherInfoByPatient(String hospitalCode) {
        JSONObject result = new JSONObject();
        List<Map<String,Object>> dispatcherInfoList = queryDispatcherInfoByHospital(hospitalCode);
        if(CollectionUtils.isEmpty(dispatcherInfoList)){
        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);
@ -1267,11 +1274,12 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    /**
     * 顶部状态栏订单各分类总条数
     *
     * @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 " ;
        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<>();
@ -1282,49 +1290,48 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        Integer served = 0;//已完成
        Integer cancel = 0;//已取消
        // -1已取消 [1,4]待服务 [5,6]已服务
        for (Map<String, Object> tmp:list){
            switch (String.valueOf(tmp.get("status"))){
        for (Map<String, Object> tmp : list) {
            switch (String.valueOf(tmp.get("status"))) {
                case "-1":
                    cancel += Integer.valueOf(tmp.get("num").toString()) ;
                    cancel += Integer.valueOf(tmp.get("num").toString());
                    break;
                case "0":
                    waitForPay += Integer.valueOf(tmp.get("num").toString()) ;
                    waitForPay += Integer.valueOf(tmp.get("num").toString());
                    break;
                case "1":
                    waitForAccept += Integer.valueOf(tmp.get("num").toString()) ;
                    waitForAccept += Integer.valueOf(tmp.get("num").toString());
                    break;
                case "2":
                    waitForAccept += Integer.valueOf(tmp.get("num").toString()) ;
                    waitForAccept += Integer.valueOf(tmp.get("num").toString());
                    break;
                case "3":
                    waitForServe += Integer.valueOf(tmp.get("num").toString()) ;
                    waitForServe += Integer.valueOf(tmp.get("num").toString());
                    break;
                case "4":
                    waitForServe += Integer.valueOf(tmp.get("num").toString()) ;
                    waitForServe += Integer.valueOf(tmp.get("num").toString());
                    break;
                case "5":
                    waitForServe += Integer.valueOf(tmp.get("num").toString()) ;
                    waitForServe += Integer.valueOf(tmp.get("num").toString());
                    break;
                case "6":
                    served += Integer.valueOf(tmp.get("num").toString()) ;
                    served += Integer.valueOf(tmp.get("num").toString());
                    break;
                default: {
                    throw new Exception("类型错误!"+String.valueOf(tmp.get("status")));
                    throw new Exception("类型错误!" + String.valueOf(tmp.get("status")));
                }
            }
        }
        all = 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);
        all = 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
@ -1342,111 +1349,126 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
     */
    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 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"
                ;
                "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(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(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(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 (!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 (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(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(createTimeEnd)) {
            sql += " and o.create_time <='" + createTimeEnd + "'";
        }
        if(!org.apache.commons.lang.StringUtils.isEmpty(serverDoctorName)){
            sql+=" and o.doctor_name like '%"+serverDoctorName+"%'";
        if (!org.apache.commons.lang.StringUtils.isEmpty(serverDoctorName)) {
            sql += " and o.doctor_name like '%" + serverDoctorName + "%'";
        }
        //获取医生代预约记录
        if (type!=null){
            sql += " and o.type = " + type +" ";
        if (type != null) {
            sql += " and o.type = " + type + " ";
        }
        if(org.apache.commons.lang.StringUtils.isNotBlank(patientId)){
            sql += " and o.patient= '"+patientId+"' ";
        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);
        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){
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
        }
        JSONArray jsonArray = new JSONArray();
        for(Map<String,Object> one:list){
        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")+"");
            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;
            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);
            object.put("status", statustemp);
            object.put("statusName", statusName);
            //工单是否转给其他机构,0-不转,1-已转
            String transOtherOrg = one.get("is_trans_other_org")+"";
            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());
            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);
            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("age", IdCardUtil.getAgeByIdcardOrBirthday(patient.getIdcard(), patient.getBirthday()));
                object.put("photo", patient.getPhoto());
//                object.put("typeValue", "儿童");
@ -1456,9 +1478,9 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
            //获取咨询
            ConsultDo consult = consultDao.queryByRelationCode(id);
            if (null != consult) {
                doorServiceOrder.setSessionId(doorServiceOrder.getPatient() +  "_" +  consult.getType());
                doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getType());
            }
            object.put("sessionId",doorServiceOrder.getSessionId());
            object.put("sessionId", doorServiceOrder.getSessionId());
            // 获取服务次数
            Integer serviceCount = doctorDoorCoachOrderService.serviceCount(doorServiceOrder.getPatient());
@ -1472,15 +1494,15 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        }
        JSONObject object = new JSONObject();
        object.put("total",count);
        object.put("detailModelList",jsonArray);
        object.put("currPage",page);
        object.put("pageSize",pageSize);
        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){
    public JSONObject updateOrderCardInfo(String jsonData) {
        JSONObject result = new JSONObject();
        JSONObject jsonObjectParam;
@ -1498,41 +1520,41 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        wlyyDoorServiceOrder.setPatientName(jsonObjectParam.getString("patientName"));
        // 居民电话
        if(!StringUtils.isEmpty(jsonObjectParam.getString("phone"))){
        if (!StringUtils.isEmpty(jsonObjectParam.getString("phone"))) {
            wlyyDoorServiceOrder.setPatientPhone(jsonObjectParam.getString("phone"));
        }
        // 医生预计达到时间
        if(!StringUtils.isEmpty(jsonObjectParam.getString("doctorArrivingTime"))){
        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("patientExpectedServeTime"))) {
            wlyyDoorServiceOrder.setPatientExpectedServeTime(jsonObjectParam.get("patientExpectedServeTime").toString());
        }
        // 服务区
        if(!StringUtils.isEmpty(jsonObjectParam.getString("serveTown"))){
        if (!StringUtils.isEmpty(jsonObjectParam.getString("serveTown"))) {
            wlyyDoorServiceOrder.setServeTown(jsonObjectParam.getString("serveTown"));
        }
        // 服务地址
        if(!StringUtils.isEmpty(jsonObjectParam.getString("serveAddress"))){
        if (!StringUtils.isEmpty(jsonObjectParam.getString("serveAddress"))) {
            wlyyDoorServiceOrder.setServeAddress(jsonObjectParam.getString("serveAddress"));
        }
        wlyyDoorServiceOrder.setServeAddress(jsonObjectParam.getString("serveAddress"));
        if(!StringUtils.isEmpty(jsonObjectParam.getString("serveLat"))){
        if (!StringUtils.isEmpty(jsonObjectParam.getString("serveLat"))) {
            wlyyDoorServiceOrder.setServeLat(jsonObjectParam.getString("serveLat"));
        }
        if(!StringUtils.isEmpty(jsonObjectParam.getString("serveLon"))){
        if (!StringUtils.isEmpty(jsonObjectParam.getString("serveLon"))) {
            wlyyDoorServiceOrder.setServeLon(jsonObjectParam.getString("serveLon"));
        }
        // 服务描述
        if(!StringUtils.isEmpty(jsonObjectParam.getString("serveDesc"))){
        if (!StringUtils.isEmpty(jsonObjectParam.getString("serveDesc"))) {
            wlyyDoorServiceOrder.setServeDesc(jsonObjectParam.getString("serveDesc"));
        }
        //服务类型    医生端和居民端公用接口
        if(!StringUtils.isEmpty(jsonObjectParam.getString("serviceStatus"))){
        if (!StringUtils.isEmpty(jsonObjectParam.getString("serviceStatus"))) {
            wlyyDoorServiceOrder.setServiceStatus(jsonObjectParam.getString("serviceStatus"));
        }else {
        } else {
            wlyyDoorServiceOrder.setServiceStatus("1");//默认为1  预约项目
        }
//        wlyyDoorServiceOrder.setIsPatientConfirm(WlyyDoorServiceOrderDO.IsPatientConfirm.yes.getType());
@ -1540,7 +1562,9 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        this.save(wlyyDoorServiceOrder);
        //新增工单居民确认操作日志记录
        if (orderWithConfirmLogAdd(result, jsonObjectParam, wlyyDoorServiceOrder.getId())) {return result;}
        if (orderWithConfirmLogAdd(result, jsonObjectParam, wlyyDoorServiceOrder.getId())) {
            return result;
        }
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, wlyyDoorServiceOrder);
@ -1548,16 +1572,15 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
        //发送 预约卡片信息(2101类型)
        JSONObject orderInfoContent = this.queryOrderCardInfo(wlyyDoorServiceOrder);
        orderInfoContent.put("re_msg_type",1);//医生修改待确认
        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){
    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为资质申请审核
@ -1575,22 +1598,23 @@ public class PatientDoorCoachOrderService extends BaseJpaService<BaseDoorCoachOr
    /**
     * 统计居民已经服务的次数
     *
     * @param patient
     * @return
     */
    public Integer countPatientDoorTimes(String patient){
    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);
        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(){
    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()方式
        i = (int) (Math.random() * 100000000); //0-100以内的随机数,用Matn.random()方式
        return String.valueOf(i);
    }
}

+ 22 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/pay/PayService.java

@ -813,7 +813,7 @@ public class PayService {
     * @param relationCode
     * @param relationName
     * @param orderType
     * @param depositType
     * @param depositType NATIVE pc二维码,JSAPI 公众号支付,APPLETS 小程序支付
     * @return
     * @throws Exception
     */
@ -885,8 +885,7 @@ public class PayService {
                }
                businessOrderDO.setOrderNo(getOrderNo());
                businessOrderDO= businessOrderDao.save(businessOrderDO);
                String url = wxWechatDO.getBaseUrl();
                String notifyUrl =url;
                String notifyUrl ="https://zhyzh.gongshu.gov.cn/cloudCare/pay/open/cloudPayNotify";
                String totalFee =businessOrderDO.getPayPrice().intValue()+"";
                map = businessOrderService.unifiedorder(wechatId,businessOrderDO.getDescription(),totalFee, depositType,openId,businessOrderDO.getOrderNo(),notifyUrl,businessOrderDO.getPatient());
            }
@ -898,9 +897,17 @@ public class PayService {
    }
    /**
     * 查询订单是否支付
     * @param relationCode
     * @return
     */
    public BusinessOrderDO selectOrderByRelationCode(String relationCode){
        return businessOrderDao.selectByRelationCode(relationCode);
    }
    /**
     * 云照护支付退款
     * @param wechatId
     * @param patient
     * @param orderNo
     * @param refundPrice
@ -948,6 +955,7 @@ public class PayService {
                orderRefundDO.setRefundTime(new Date());
                orderRefundDO.setRefundDesc(map.get("err_code_des").toString());
                orderRefundDao.save(orderRefundDO);
            }else {
                orderRefundDO.setStatus(2);
                orderRefundDO.setRefundTime(new Date());
@ -962,6 +970,16 @@ public class PayService {
        return map;
    }
    /**
     * 云照护支付回调
     * @param result
     * @return
     */
    public Map<String,String> getWxPayResultCloudNotify(String result) {
        return businessOrderService.getWxPayResultCloudNotify(result);
    }
    public String getOrderNo(){
        return ""+System.currentTimeMillis()+(int)(Math.random()*900)+100;
    }

+ 186 - 40
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/controller/ConsultController.java

@ -9,17 +9,21 @@ import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.im.ConsultTeamLogDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.message.MessageNoticeSetting;
import com.yihu.jw.entity.util.SystemConfEntity;
import com.yihu.jw.hospital.module.consult.service.ConsultTeamService;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.CommonUtil;
import com.yihu.jw.hospital.utils.HttpUtil;
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.dao.ConsultTeamDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.im.util.ImageCompress;
import com.yihu.jw.message.service.MessageService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.hospital.utils.CommonUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -38,9 +42,14 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
/**
 * 患者端:三师咨询控制类
@ -52,12 +61,13 @@ import java.util.Map;
@Api(description = "患者端-患者咨询")
public class ConsultController extends EnvelopRestEndpoint {
    @Autowired
    protected HttpServletRequest request;
    @Autowired
    private ConsultTeamService consultTeamService;
    //    @Autowired
//    private DoctorCommentService doctorCommentService;
//    @Autowired
//    private DoctorStatisticsService doctorStatisticsService;
    @Autowired
    private BaseDoctorInfoService doctorService;
@ -69,29 +79,35 @@ public class ConsultController extends EnvelopRestEndpoint {
    @Autowired
    private CommonUtil CommonUtil;
    @Autowired
    private ImUtil imUtill;
    @Autowired
    private HttpUtil httpUtil;
    private ConsultTeamDao consultTeamDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    private HttpClientUtil httpClientUtil;
    @Autowired
    private ConsultTeamDao consultTeamDao;
    private MessageService messageService;
    @Autowired
    private PrescriptionDao prescriptionDao;
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private ConsultDao consultDao;
    @Autowired
    WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Value("${doctorAssistant.api}")
    private String doctorAssistant;
    @Value("${doctorAssistant.target_url}")
    private String targetUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private MessageService messageService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Value("${im.data_base_name}")
    private String im;
@ -100,8 +116,16 @@ public class ConsultController extends EnvelopRestEndpoint {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private HttpUtil httpUtil;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private PrescriptionDao prescriptionDao;
//    @Autowired
//    private DoctorCommentService doctorCommentService;
//    @Autowired
//    private DoctorStatisticsService doctorStatisticsService;
//    @Autowired
//    private DoctorWorkTimeService doctorWorkTimeService;
//    @Autowired
@ -113,6 +137,7 @@ public class ConsultController extends EnvelopRestEndpoint {
//    @Autowired
//    private WlyyDynamicMessagesDao dynamicMessagesDao;
//    @ApiOperation("testRedis")
//    @RequestMapping(value = "testRedis",method = RequestMethod.POST)
//    public String testRedis(){
@ -1176,27 +1201,23 @@ public class ConsultController extends EnvelopRestEndpoint {
     * @param pagesize 每页显示数,默认为10
     * @return
     */
//    @RequestMapping(value = "loglist")
//    @ApiOperation("网络咨询咨询日志查询")
//    public String loglist(@RequestParam String consult, @RequestParam int page, @RequestParam int pagesize) {
//        try {
//            ConsultTeamDo consultModel = consultTeamService.findByCode(consult);
//            if (consultModel == null) {
//                return error(-1, "咨询记录不存在!");
//            }
//            JSONObject messageObj = imUtill.getTopicMessage(consultModel.getConsult(), consultModel.getStartMsgId(), consultModel.getEndMsgId(), page, pagesize, getRepUID());
//
//            //过滤续签
    @RequestMapping(value = "loglist")
    @ApiOperation("网络咨询咨询日志查询")
    public String loglist(@RequestParam String consult, @RequestParam int page, @RequestParam int pagesize) {
        try {
            ConsultTeamDo consultModel = consultTeamService.findById(consult);
            if (consultModel == null) {
                return error(-1, "咨询记录不存在!");
            }
            com.alibaba.fastjson.JSONObject messageObj = imUtill.getTopicMessage(consultModel.getConsult(), consultModel.getStartMsgId(), consultModel.getEndMsgId(), page, pagesize, getRepUID());
            //过滤续签
//            consultTeamService.removeRenewPerson(messageObj, getRepUID());
//
//            return write(200, "查询成功", "list", messageObj);
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            error(e);
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
            return write(200, "查询成功", "list", messageObj);
        } catch (Exception e) {
            error(e);
            return "查询失败!";
        }
    }
    /**
     * 网络咨询咨询日志查询
@ -1853,4 +1874,129 @@ public class ConsultController extends EnvelopRestEndpoint {
        }
    }
    /**
     * 获取微信服务器图片
     *
     * @return
     */
    public String fetchWxImages() {
        String photos = "";
        try {
            String images = request.getParameter("mediaIds");
            if (StringUtils.isEmpty(images)) {
                return photos;
            }
            String[] mediaIds = images.split(",");
            for (String mediaId : mediaIds) {
                if (StringUtils.isEmpty(mediaId)) {
                    continue;
                }
                String temp = saveImageToDisk(mediaId);
                if (StringUtils.isNotEmpty(temp)) {
                    if (photos.length() == 0) {
                        photos = temp;
                    } else {
                        photos += "," + temp;
                    }
                }
            }
        } catch (Exception e) {
            error(e);
        }
        return photos;
    }
    /**
     * 获取下载图片信息(jpg)
     *
     * @param mediaId 文件的id
     * @throws Exception
     */
    public String saveImageToDisk(String mediaId) throws Exception {
        // 文件保存的临时路径
        String tempPath = SystemConfEntity.getInstance().getTempPath() + File.separator;
        // 拼接年月日路径
        String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
        // 重命名文件
        String newFileName = DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000) + ".png";
        // 保存路径
        File uploadFile = new File(tempPath + datePath + newFileName);
        InputStream inputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            if (!uploadFile.getParentFile().exists()) {
                uploadFile.getParentFile().mkdirs();
            }
            inputStream = getInputStream(mediaId);
            byte[] data = new byte[1024];
            int len = 0;
            fileOutputStream = new FileOutputStream(uploadFile);
            while ((len = inputStream.read(data)) != -1) {
                fileOutputStream.write(data, 0, len);
            }
            // 生成缩略图
            ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
            // 返回保存路径
            return datePath + newFileName;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    /**
     * 下载多媒体文件(请注意,视频文件不支持下载,调用该接口需http协议)
     *
     * @return
     */
    public InputStream getInputStream(String mediaId) {
        String accessToken = getAccessToken();
        InputStream is = null;
        String url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=" + accessToken + "&media_id=" + mediaId;
        try {
            URL urlGet = new URL(url);
            HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
            http.setRequestMethod("GET"); // 必须是get方式请求
            http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            http.setDoOutput(true);
            http.setDoInput(true);
            System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
            System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
            http.connect();
            // 获取文件转化为byte流
            is = http.getInputStream();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return is;
    }
    /**
     * 获取微信的access_token
     *
     * @return
     */
    public String getAccessToken() {
        return weiXinAccessTokenUtils.getAccessToken();
    }
}

+ 19 - 9
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/service/ConsultTeamService.java

@ -219,8 +219,13 @@ public class ConsultTeamService extends ConsultService {
        consult.setRelationCode(doorServiceOrderDO.getId());//关联业务code
        consultTeam.setConsult(consult.getCode()); // 设置咨询标识
        //(im创建咨询) 上门服务咨询的sessionid为居民code+咨询code+工单编号+咨询类型
        String sessionId = patient + "_" + consult.getCode() + "_" + doorServiceOrderDO.getNumber() + "_" + consultTeam.getType();
        /**
         * 原本:(im创建咨询) 上门服务咨询的sessionid为居民code+咨询code+工单编号+咨询类型
         * 现在:居民+咨询id+订单号
         * */
        String sessionId = patient + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consultTeam.getType();
//        String sessionId = patient + "_" + consult.getId();
        //4、 上门服务咨询-参与者
        JSONObject participants = new JSONObject();
@ -228,14 +233,17 @@ public class ConsultTeamService extends ConsultService {
//        String content = signFamily.getHospitalName() + "为您服务";
        String content = doorServiceOrderDO.getDoctorName() + "为您服务";
        //封装JSONObject的messages
        JSONObject messages = imUtill.getCreateTopicMessage(patient, patientDO.getName(), consult.getTitle(), content, consult.getImages(), "");
        //这边应该是要抛出异常比较合适
        /**
         * 创建议题
         */
        JSONObject imResponseJson = imUtill.createTopics(sessionId, consult.getCode(), content, participants, messages, ImUtil.SESSION_TYPE_ONDOOR_NURSING);
//        if (imResponseJson == null || imResponseJson.getString("status").equals("-1")) {
//            String failMsg = "发起服务咨询时:IM" + imResponseJson.getString("message");
//            throw new Exception(failMsg);
//        }
        if (imResponseJson == null || imResponseJson.getString("status").equals("-1")) {
            String failMsg = "发起服务咨询时:IM" + imResponseJson.getString("message");
            throw new Exception(failMsg);
        }
        if (imResponseJson != null && imResponseJson.get("start_msg_id") != null) {
            consultTeam.setStartMsgId(imResponseJson.get("start_msg_id").toString());
        }
@ -2176,6 +2184,10 @@ public class ConsultTeamService extends ConsultService {
        return consultTeamDao.findByConsult(code);
    }
    public ConsultTeamDo findById(String id) {
        return consultTeamDao.findOne(id);
    }
    /**
     * 三师咨询转接医生
     *
@ -3356,7 +3368,6 @@ public class ConsultTeamService extends ConsultService {
//        result.putIfAbsent("data", consult);
//        return result;
//    }
    public org.json.JSONObject updateIMMsg(String sessionId, String sessionType, String msgId, String content) {
        org.json.JSONObject result = new org.json.JSONObject();
        if (StringUtils.isEmpty(sessionId) || StringUtils.isEmpty(sessionType) || StringUtils.isEmpty(msgId) || StringUtils.isEmpty(content)) {
@ -3480,5 +3491,4 @@ public class ConsultTeamService extends ConsultService {
//    }
}

+ 24 - 3
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/controller/WlyyDoorServiceOrderController.java

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.hospital.module.door.service.DoorOrderService;
import com.yihu.jw.hospital.module.door.service.WlyyDoorPrescriptionService;
import com.yihu.jw.hospital.module.door.service.WlyyDoorServiceOrderService;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
@ -31,7 +32,8 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
    @Autowired
    private WlyyDoorServiceOrderService wlyyDoorServiceOrderService;
    @Autowired
    private ImUtil imUtil;
    @Autowired
    private DoorOrderService doorOrderService;
@ -49,6 +51,24 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
//    private String accId;
    @PostMapping(value = "testIm")
    @ApiOperation(value = "测试im")
    public Envelop testIm(
            @ApiParam(name = "jsonData", value = "Json数据", required = true) @RequestParam String jsonData
    ) {
        JSONObject participants = new JSONObject();
        participants.put("111", 0);
        String sessionId = "";
        String topicId = "";//consult.getId()
        String content = "";
        String messages = "";
//        JSONObject imResponseJson = imUtil.createTopics(sessionId,topicId, content, participants, messages, ImUtil.SESSION_TYPE_DOOR_COACH);
        return null;
    }
    /**
     * 居民创建上门服务
     * 参数:
@ -76,6 +96,7 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
    public Envelop queryInfoStatusCountList(
            @ApiParam(name = "patient", value = "居民code") @RequestParam(value = "patient", required = false) String patient
    ) {
        System.out.println("统计上门服务工单各状态下的数量列表--参数" + patient);
        JSONObject result = wlyyDoorServiceOrderService.queryInfoStatusCountList(patient);
        if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
            return failed(result.getString(ResponseContant.resultMsg));
@ -262,6 +283,7 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
            @ApiParam(name = "reason", value = "取消理由") @RequestParam(value = "reason", required = true) String reason) {
        JSONObject result = new JSONObject();
        try {
            System.out.println("取消工单--参数orderId:" + orderId);
            result = wlyyDoorServiceOrderService.cancelOrder(orderId, 2, reason, null, null);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return failed(result.getString(ResponseContant.resultMsg));
@ -272,10 +294,9 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
        }
        return success(result.get(ResponseContant.resultMsg));
    }
    @GetMapping(value = "queryDoctorList")
    @ApiOperation(value = "服务人员列表(医生列表)")
    public PageEnvelop queryDoctorList(

+ 25 - 12
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/WlyyDoorServiceOrderService.java

@ -9,14 +9,13 @@ 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.WxTemplateConfigDO;
import com.yihu.jw.entity.door.*;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.wechat.WechatTemplateConfig;
import com.yihu.jw.hospital.HospitalDao;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.hospital.module.consult.service.ConsultTeamService;
import com.yihu.jw.hospital.module.door.dao.*;
import com.yihu.jw.hospital.module.wx.dao.WechatTemplateConfigDao;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.im.dao.ConsultDao;
@ -30,6 +29,7 @@ import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.EntityUtils;
import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
@ -172,8 +172,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    @Autowired
    private WeiXinAccessTokenUtils tokenUtils;
//    @Autowired
//    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    private WxTemplateConfigDao wxTemplateConfigDao;
//    @Autowired
//    private DmJobService dmJobService;
@ -888,14 +891,17 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            return result;
        }
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        String sessionId = orderDO.getPatient() + "_" + consult.getCode() + "_" + orderDO.getNumber() + "_" + consult.getType();
        String sessionId = orderDO.getPatient() + "_" + consult.getId() + "_" + orderDO.getNumber() + "_" + consult.getType();
//        String sessionId = orderDO.getPatient() + "_" + consult.getId() + "_" + orderDO.getNumber();
        // 把调度员拉入会话,作为其中一个成员,第一个进入会话的调度员,系统发送欢迎语和居民的预约卡片信息
        if (StringUtils.isEmpty(orderDO.getDispatcher())) {
            orderDO.setDispatcher(dispatcher);
            orderDO.setDispatcherName(dispatcherName);
            this.save(orderDO);
            // 先进入会话,再聊天
            imUtill.updateParticipant(sessionId, dispatcher, null);
//            String msg = imUtill.updateParticipant(sessionId, dispatcher, null);
            String msg = imUtill.updateParticipantNew(sessionId, dispatcher, null);
            System.out.println("进入会话,再聊天==>" + msg);
            String noticeContent = hospitalName + dispatcherName + "为您服务";
            this.qucikSendIM(orderId, dispatcher, "智能助手", "1", noticeContent);
//            imUtill.sendIntoTopicIM(dispatcher, sessionId, consult.getCode(), noticeContent, orderDO.getProxyPatient(), orderDO.getProxyPatientName());
@ -904,7 +910,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        }
        // 把调度员拉入会话,作为其中一个成员
        imUtill.updateParticipant(sessionId, dispatcher, null);
//        String msg = imUtill.updateParticipant(sessionId, dispatcher, null);
        String msg = imUtill.updateParticipantNew(sessionId, dispatcher, null);
        System.out.println("把调度员拉入会话,作为其中一个成员==>" + msg);
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, "调度员[" + dispatcherName + "]进入会话成功");
        return result;
@ -1044,9 +1052,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            e.printStackTrace();
        }
        if (!CollectionUtils.isEmpty(feeDetailDOS)) {
            //2023-10-11 先注释 计算服务费用
            Map<String, Object> map = doorOrderService.countServerPackagePrice(jsonData, orderDO.getPatient());
            orderBriefInfo.put("packageFee", map.get("serverPackagePrice"));
            /**
             *  2023-10-11 先注释 计算服务费用
             *  这边需要改写用表base_service_package_record
             */
//            Map<String, Object> map = doorOrderService.countServerPackagePrice(jsonData, orderDO.getPatient());
//            orderBriefInfo.put("packageFee", map.get("serverPackagePrice"));
        }
        orderJson.put("order", orderBriefInfo);
@ -1538,7 +1549,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
        BasePatientDO patient = patientService.findPatientById(orderDO.getPatient());
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback", "smyyyqx");
        WxTemplateConfigDO templateConfig = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndScene("xm_test_ihealth_wx", "template_process_feedback", "smyyyqx");
        String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
        org.json.JSONObject json = new org.json.JSONObject();
        json.put("first", first);
@ -1572,7 +1583,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
        BasePatientDO patient = patientService.findPatientById(orderDO.getPatient());
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback", "smyyyqx");
        WxTemplateConfigDO templateConfig = wxTemplateConfigDao.findByScene("template_process_feedback", "smyyyqx");
        String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
        org.json.JSONObject json = new org.json.JSONObject();
        json.put("first", orderDO.getPatientName() + ",您好!您的上门服务知情同意书已送达");
@ -1969,6 +1980,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        }
        String serviceSql = "SELECT count(d.id) times FROM wlyy_door_doctor d where d.order_id in(SELECT id from wlyy_door_service_order WHERE DATE_FORMAT(doctor_sign_time, '%Y') = DATE_FORMAT(NOW(), '%Y') AND patient=?)";
//        final Set<String>  patientSet = doorServiceVoucherDao.queryByTypeIn(types);
        sqlResultlist.forEach(
                oneMap -> {
                    // 获取服务次数
@ -1985,7 +1998,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                    if (parArray != null) {
                        parArray.forEach(
                                oneParObj -> {
                                    org.json.JSONObject oneParJson = (org.json.JSONObject) oneParObj;
                                    com.alibaba.fastjson.JSONObject oneParJson = (com.alibaba.fastjson.JSONObject) oneParObj;
                                    if (StringUtils.equalsIgnoreCase(oneParJson.getString("id"), dispatcher)) {
                                        oneMap.put("isInSession", true);
                                    }

+ 1 - 1
svr/svr-visit-behind/src/main/resources/bootstrap.yml

@ -1,6 +1,6 @@
spring:
  application:
    name:  svr-visit-behind
    name:  svr-visit-behind --
  cloud:
    config:
      failFast: true