Browse Source

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

wangzhinan 4 years ago
parent
commit
ed79a0f5e3

+ 8 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/SystemMessageDao.java

@ -21,5 +21,13 @@ public interface SystemMessageDao extends PagingAndSortingRepository<SystemMessa
    @Query("from SystemMessageDO p where p.id = ?1")
    SystemMessageDO queryById(String id);
    @Modifying
    @Query("delete from SystemMessageDO a   where a.receiver = ?1 and a.relationCode = ?2 and a.type ='407'")
    int orderMessageDel(String doctor, String orderId);
    List<SystemMessageDO> queryByRelationCodeAndTypeIn(String relationCode,String[] type);
    //获取资质申请审核有效的未结束已发送的消息
    @Query("select a from SystemMessageDO a where a.type in ('401','408') and a.del='1' and a.over='1' and relationCode = ?1  ")
    List<SystemMessageDO> findMessageByRelationCode(String relationCode);
}

+ 9 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/hospital/message/SystemMessageDO.java

@ -57,6 +57,7 @@ public class SystemMessageDO extends UuidIdentityEntity {
     *是否删除
     */
    private String del;
    private String over;//是否操作结束 是否操作结束 1否,0是
    /**
     *已读时间
     */
@ -164,4 +165,12 @@ public class SystemMessageDO extends UuidIdentityEntity {
        this.createTime = createTime;
    }
    @Column(name = "over")
    public String getOver() {
        return over;
    }
    public void setOver(String over) {
        this.over = over;
    }
}

+ 64 - 4
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/controller/doctor/DoctorController.java

@ -1,21 +1,27 @@
package com.yihu.jw.door.controller.doctor;
import com.alibaba.fastjson.JSON;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.door.controller.BaseController;
import com.yihu.jw.door.service.common.WlyyMessageService;
import com.yihu.jw.door.service.common.PatientService;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.org.dao.BaseOrgDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by yeshijie on 2020/12/30.
@ -33,6 +39,48 @@ public class DoctorController extends BaseController {
    private BasePatientDao patientDao;
    @Autowired
    private PatientService patientService;
    @Autowired
    private BaseOrgDao orgDao;
    @Autowired
    private WlyyMessageService messageService;
    @RequestMapping(value = "message/getWaitingMessages",method = RequestMethod.GET)
    @ApiOperation("获取服务工单待接单列表")
    public String getWaitingMessages(
            @ApiParam(name = "message",value = "消息对象")
            @RequestParam(value = "message")String message,
            @ApiParam(name="types",value="消息类型")
            @RequestParam(value="types",required = true) String types,
            @ApiParam(name="page",value="第几页",defaultValue = "1")
            @RequestParam(value="page",required = true) String page,
            @ApiParam(name="pageSize",value="",defaultValue = "10")
            @RequestParam(value="pageSize",required = true) String pageSize){
        if (StringUtils.isBlank(pageSize)) {
            pageSize = "10";
        }
        if (page.equals("0")) {
            page = "1";
        }
        String[] split = StringUtils.split(types, ",");
        List<Integer> typeList = new ArrayList<>();
        for (String s : split) {
            typeList.add(Integer.valueOf(s));
        }
        SystemMessageDO message1 = new SystemMessageDO();
        com.alibaba.fastjson.JSONObject object = JSON.parseObject(message);
        message1.setOver(object.getString("over"));
        message1.setIsRead(object.get("read")+"");
        message1.setReceiver(getUID());
        try {
            JSONObject waitingMessages = messageService.getWaitingMessages(message1, types, Integer.valueOf(page), Integer.valueOf(pageSize));
            return write(200, "查询成功","data",waitingMessages);
        }catch (Exception e){
            error(e);
            return error( -1, "查询失败!");
        }
    }
    /**
     * 查询居民信息
@ -55,6 +103,18 @@ public class DoctorController extends BaseController {
        }
    }
    @GetMapping(value = "getHospitalInfoByCode")
    @ApiOperation("根据机构code获取机构信息")
    public String getHospitalInfoByCode(String code) {
        try {
            BaseOrgDO baseOrgDO = orgDao.findByCode(code);
            return write(200, "查询成功", "data", baseOrgDO);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
    /**
     * 医生基本信息查询接口
     *

+ 11 - 0
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/controller/doctor/DoctorDoorServiceAuditController.java

@ -167,4 +167,15 @@ public class DoctorDoorServiceAuditController extends BaseController {
            return error(-1, "获取失败!"+e.getMessage());
        }
    }
    @RequestMapping(value = "myMyTest",method = RequestMethod.POST)
    @ApiOperation("测试")
    public String myMyTest(){
        try {
            return write(200,"请求成功","data",doorServiceApplicationService.myMyTest());
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"请求失败"+e.getMessage());
        }
    }
}

+ 14 - 1
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/controller/doctor/DoorOrderController.java

@ -243,7 +243,7 @@ public class DoorOrderController extends BaseController {
            @ApiParam(value = "二维码内容", name = "twoDimensionalCode")
            @RequestParam(value = "twoDimensionalCode", required = false) String twoDimensionalCode) {
        try {
            WlyyDoorServiceOrderDO wlyyDoorServiceOrderDO = doorOrderService.signIn(orderId, signTime, signWay, signLocation, signImg,twoDimensionalCode);
            WlyyDoorServiceOrderDO wlyyDoorServiceOrderDO = doorOrderService.signIn(orderId, signTime, signWay, signLocation, signImg,twoDimensionalCode,getUID());
            if (wlyyDoorServiceOrderDO != null){
                return write(200, "操作成功", "data", wlyyDoorServiceOrderDO);
            }else {
@ -935,6 +935,19 @@ public class DoorOrderController extends BaseController {
        }
    }
    @PostMapping(value = "savePrescription")
    @ApiOperation("上门服务前手工开方接口")
    public String savePrescription(@ApiParam(name = "orderId", value = "工单id", required = true) @RequestParam String orderId,
                                     @ApiParam(name = "prescriptionCode", value = "处方单号,多个用逗号隔开", required = true) @RequestParam String prescriptionCode) {
        try {
            wlyyDoorServiceOrderService.savePrescription(orderId, prescriptionCode);
            return write(200, "操作成功");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败");
        }
    }
    @PostMapping(value = "createPrescription")
    @ResponseBody
    @ApiOperation("上门服务前手工开方接口")

+ 3 - 0
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/dao/WlyyDoorCommentDao.java

@ -2,6 +2,7 @@ package com.yihu.jw.door.dao;
import com.yihu.jw.entity.door.WlyyDoorCommentDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
@ -17,4 +18,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 * @since 1.
 */
public interface WlyyDoorCommentDao extends PagingAndSortingRepository<WlyyDoorCommentDO, Integer>, JpaSpecificationExecutor<WlyyDoorCommentDO>  {
    @Query("select t from WlyyDoorCommentDO t where t.patient = ?1 and t.orderId = ?2 ")
    WlyyDoorCommentDO selectCommentDoctor(String patient, String orderId);
}

+ 167 - 91
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/service/DoorOrderService.java

@ -5,11 +5,14 @@ import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.door.dao.*;
import com.yihu.jw.door.util.MessageUtil;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.door.*;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.dao.ConsultTeamDao;
import com.yihu.jw.im.util.ImUtil;
@ -17,8 +20,10 @@ import com.yihu.jw.message.dao.MessageDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import jxl.Workbook;
import jxl.write.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.jsoup.Jsoup;
@ -97,6 +102,8 @@ public class DoorOrderService {
    @Autowired
    private ImUtil imUtill;
    @Autowired
    private MessageUtil messageUtil;
    @Autowired
    private ConsultDao consultDao;
    @Autowired
    private ConsultTeamDao consultTeamDao;
@ -109,7 +116,18 @@ public class DoorOrderService {
    private WlyyDoorServiceOrderDao wlyyDoorServiceOrderDao;
    @Autowired
    private WlyyDoorFeeDetailDao wlyyDoorFeeDetailDao;
    @Value("${base.hospitalUrl}")
    private String hospitalUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private WlyyDoorCommentDao doorCommentDao;
    @Autowired
    private SystemMessageDao systemMessageDao;
    /**
     * 顶部状态栏订单各分类总条数
     * @param doctor
@ -151,9 +169,15 @@ public class DoorOrderService {
        if (!map.containsKey("completed")) {
            map.put("completed", "0");
        }
        if(!map.containsKey("exampaperstatus")){
        //待补录
        String sqlCount = "SELECT COUNT(DISTINCT o.id) FROM wlyy_door_service_order o LEFT JOIN wlyy_door_doctor d ON d.order_id = o.id " +
                "WHERE o.conclusion_status = 1 and (d.doctor='"+doctor+"' or o.doctor='"+doctor+"')";
        Integer count = jdbcTemplate.queryForObject(sqlCount,Integer.class);
        map.put("exampaperstatus", String.valueOf(count));
/*        if(!map.containsKey("exampaperstatus")){
            map.put("exampaperstatus", "0");
        }
        }*/
        return map;
    }
@ -355,14 +379,15 @@ public class DoorOrderService {
     * @param signImg
     * @return
     */
    public WlyyDoorServiceOrderDO signIn(String orderId, String signTime, Integer signWay, String signLocation, String signImg, String twoDimensionalCode) throws Exception {
    public WlyyDoorServiceOrderDO signIn(String orderId, String signTime, Integer signWay, String signLocation,
                                         String signImg, String twoDimensionalCode,String doctorId) throws Exception {
        WlyyDoorServiceOrderDO doorServiceOrder = this.doorServiceOrderDao.findOne(orderId);
        doorServiceOrder.setDoctorSignTime(DateUtil.strToDate(signTime));
        doorServiceOrder.setDoctorSignWay(signWay);
        // 签到方式-2扫码时,需要去解析地址
        doorServiceOrder.setDoctorSignLocation(signLocation);
        doorServiceOrder.setDoctorSignImg(StringUtils.isEmpty(signImg) ? null : signImg);
        doorServiceOrder.setStatus(4);
        if(signWay == 4 ){//扫码签到
            if (twoDimensionalCode.equals(doorServiceOrder.getNumber())){
@ -370,6 +395,7 @@ public class DoorOrderService {
                doorServiceOrder = doorServiceOrderDao.save(doorServiceOrder);
                // 修改医生上门服务工单状态 4服务中
                this.updateDispatchStatusBySystem(doorServiceOrder.getDoctor(), 4);
                appointmentRevisitOnDoor(doorServiceOrder,doctorId);
                return doorServiceOrder;
            }else {
                logger.info("扫码签到失败");
@ -380,10 +406,33 @@ public class DoorOrderService {
            doorServiceOrder = doorServiceOrderDao.save(doorServiceOrder);
            // 修改医生上门服务工单状态 4服务中
            this.updateDispatchStatusBySystem(doorServiceOrder.getDoctor(), 4);
            appointmentRevisitOnDoor(doorServiceOrder,doctorId);
            return doorServiceOrder;
        }
    }
    /**
     * 挂号
     * @param orderDO
     * @param doctorId
     */
    public void appointmentRevisitOnDoor(WlyyDoorServiceOrderDO orderDO,String doctorId){
        BaseDoctorDO doctorDO = doctorDao.findById(doctorId);
        JSONObject outpatientJson = new JSONObject();
        outpatientJson.put("hospital",orderDO.getHospital());
        outpatientJson.put("patient",orderDO.getPatient());
        outpatientJson.put("patientName",orderDO.getPatientName());
        outpatientJson.put("mobile",orderDO.getPatientPhone());
        outpatientJson.put("doctor",doctorId);
        outpatientJson.put("doctorName",doctorDO.getName());
        String url = hospitalUrl + "/open/noLogin/appointmentRevisitOnDoor";
        JSONObject json = new JSONObject();
        json.put("outpatientJson", outpatientJson);
        String res = httpClientUtil.postBody(url,json);
        System.out.println("appointmentRevisitOnDoor res:"+res);
    }
    /**
     * 编辑保存服务工单小结
     * @param model
@ -440,7 +489,7 @@ public class DoorOrderService {
        doorServiceOrderDao.save(doorServiceOrder);
//        this.messageDao.orderMessageDel(doorServiceOrder.getDoctor(),orderId);
        systemMessageDao.orderMessageDel(doorServiceOrder.getDoctor(),orderId);
        if(doorServiceOrder.getType() == null|| doorServiceOrder.getType() != 3) {
            //获取咨询
@ -476,52 +525,44 @@ public class DoorOrderService {
        }
        // 发送微信模板消息通知患者医生已接单
        BasePatientDO patient = patientInfoService.findById(doorServiceOrder.getPatient());
        BasePatientDO patient = patientInfoService.findById(doorServiceOrder.getPatient());//·
        // 获取微信模板
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        try{
/*            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","smyyyjjd");
            String first = templateConfig.getFirst();
            first = first.replace("key1",(patient.getName()==null?"":patient.getName()));
            first = first.replace("key2", null != doorServiceOrder.getDoctorName() ? doorServiceOrder.getDoctorName() : "");
            String keyword1 = templateConfig.getKeyword1();
            org.json.JSONObject json = new org.json.JSONObject();
            json.put("first", first);
            json.put("keyword1", DateUtil.dateToStrShort(new Date()));
            json.put("keyword2", "上门服务已接单");
            json.put("url", templateConfig.getUrl());
            json.put("remark", templateConfig.getRemark());
        try {
            String patientName=patient.getName()==null?"":patient.getName();
            String doctorName=doorServiceOrder.getDoctorName()!=null? doorServiceOrder.getDoctorName() : "";
            if(consult != null) {
                json.put("consult", consult.getCode());
                String consultStr =  consult.getId();
            }
            String first = patientName+",您好!您的上门预约服务已由【"+doctorName+"】医生接单了";
            logger.info("上门服务已接单推送前");
            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json);
            logger.info("上门服务已接单推送后");*/
        }catch (Exception e) {
            //url + json.getString("url") + "?openid=" + openid + "&consult=" + json.getString("consult")
            messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyjjd",patient.getOpenid(),first,null,null,DateUtil.dateToStrShort(new Date()),"上门服务已接单");
            logger.info("上门服务已接单推送前");
        }catch (Exception e){
            logger.error(e.getMessage());
        }
        //  待接单消息设为已操作, 434 医生接单-- 王五接受了服务工单12345678
/*        List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{403,407});
        if(CollectionUtils.isEmpty(messages)){
        List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,new String[]{"403","407"});
        if (CollectionUtils.isEmpty(messages)){
            logger.error("当前工单没有医生待接单消息!orderId:" + orderId);
        } else {
            messages.forEach(
                    message -> {
                        if (message.getType() == 403) {
                            message.setTitle("医生接单");
                            message.setContent(doorServiceOrder.getDispatcherName() + "接受了服务工单"+ doorServiceOrder.getNumber());
                            message.setType(434);
                            message.setReceiver(doorServiceOrder.getDispatcher());
                            message.setSender(doorServiceOrder.getDoctor());
                            message.setCreateTime(new Date());
                        }else{
                            message.setOver("0");
                        }
                        messageDao.save(message);
                    }
            );
        }*/
        }else {
            messages.forEach(message->{
                systemMessageDao.orderMessageDel(message.getReceiver(),message.getRelationCode());
                if (message.getType().equals("403") ) {
                    BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doorServiceOrder.getDispatcher());//·
                    String msg=doorServiceOrder.getDispatcherName() + "接受了服务工单"+ doorServiceOrder.getNumber();
                    messageUtil.saveSystemMessage(message.getId(),message.getRelationCode(),"医生接单","434",doorServiceOrder.getDoctor(),doorServiceOrder.getDoctorName(),
                            doorServiceOrder.getDispatcher(),doorServiceOrder.getDispatcherName(),null,msg,message.getOver());
                }
                else{
                    message.setOver("0");
                    systemMessageDao.save(message);
                }
            });
        }
    }
    /**
@ -537,28 +578,24 @@ public class DoorOrderService {
        }
        //给代预约医生发消息
        if (doorServiceOrder.getType() != null && doorServiceOrder.getType() == 3) {
            this.createMessage(doorServiceOrder.getId(), "system", doorServiceOrder.getProxyPatient(), 403, "代预约服务工单重新派单", doorServiceOrder.getPatientName() + "的代预约服务工单需重新派单,请您前往处理");
            BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doorServiceOrder.getProxyPatient());//·
            this.createMessage("代预约服务工单重新派单","403","system","system", doorServiceOrder.getId(), doorServiceOrder.getProxyPatient(),baseDoctorDO.getName() ,null, doorServiceOrder.getPatientName() + "的代预约服务工单需重新派单,请您前往处理");
        } else {
/*            this.messageDao.orderMessageDel(doorServiceOrder.getDoctor(),orderId);
            systemMessageDao.orderMessageDel(doorServiceOrder.getDoctor(),orderId);
            if(StringUtils.isNotBlank(doorServiceOrder.getDispatcher())){
                // 派单消息
                this.createMessage(doorServiceOrder.getId(), "system", doorServiceOrder.getDispatcher(), 404, "服务工单拒单待重新派单", doorServiceOrder.getDoctorName() + "拒绝了" + doorServiceOrder.getProxyPatientName() + "的服务预约申请,请重新派单");
                BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doorServiceOrder.getDispatcher());//·
                this.createMessage("服务工单拒单待重新派单","404","system","system", doorServiceOrder.getId(), doorServiceOrder.getDispatcher(),baseDoctorDO.getName() , null,doorServiceOrder.getDoctorName() + "拒绝了" + doorServiceOrder.getProxyPatientName() + "的服务预约申请,请重新派单");
                //  调度员-派单-实时工单消息:435 医生拒单-- 王五拒绝了服务工单12345678
                List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId, new Integer[]{431, 433});
                List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,new String[]{"431","433"});
                if (CollectionUtils.isEmpty(messages)) {
                    logger.error("当前工单没有医生待接单消息!orderId:" + orderId);
                } else {
                    Message message = messages.get(0);
                    message.setTitle("医生拒单");
                    message.setContent(doorServiceOrder.getDoctorName() + "拒绝了服务工单" + doorServiceOrder.getNumber() + ", 请重新派单");
                    message.setType(435);
                    message.setReceiver(doorServiceOrder.getDispatcher());
                    message.setSender(doorServiceOrder.getDoctor());
                    message.setCreateTime(new Date());
                    messageDao.save(message);
                    SystemMessageDO message = messages.get(0);
                    String msg=doorServiceOrder.getDoctorName() + "拒绝了服务工单" + doorServiceOrder.getNumber() + ", 请重新派单";
                    messageUtil.saveSystemMessage(message.getId(),message.getRelationCode(),"医生拒单","435",doorServiceOrder.getDoctor(),doorServiceOrder.getDoctorName(),
                            doorServiceOrder.getDispatcher(),doorServiceOrder.getDispatcherName(),null,msg,message.getOver());
                }
            }*/
            }
        }
        doorServiceOrder.setDoctor(null);
        doorServiceOrder.setDoctorName(null);
@ -571,28 +608,29 @@ public class DoorOrderService {
    /**
     * 添加【工单派单,转单】等系统消息
     * @param orderId
     * @param sender
     * @param receiver
     * @param Content
     */
    public void createMessage(String orderId,String sender,String receiver,int type,String title,String Content){
/*        Message message= new Message();
        message.setCzrq(new Date());
        message.setCreateTime(new Date());
        message.setRead(1);
        message.setState(1);
        message.setRelationCode(orderId);
        message.setOver("1");
        message.setReceiver(receiver);
        message.setSender(sender);
        message.setCode(getCode());
        message.setTitle(title);
        message.setContent(Content);
        //消息类型:401为资质申请审核
        message.setType(type);
        message.setDel("1");
        messageDao.save(message);*/
    public void createMessage(String title,String type,String sender,String senderName,String relationCode,String Receiver,String ReceiverName,String idCard,String msg){
        SystemMessageDO messageDO = new SystemMessageDO();
        messageDO.setTitle(title);
        messageDO.setType(type);//401为资质申请审核
        messageDO.setSender(sender);
        messageDO.setSenderName(senderName);
        messageDO.setRelationCode(relationCode);
        messageDO.setReceiver(Receiver);
        messageDO.setReceiverName(ReceiverName);
        net.sf.json.JSONObject data = new net.sf.json.JSONObject();
        data.put("name", ReceiverName);
        data.put("age", IdCardUtil.getAgeForIdcard(idCard));
        try {
            data.put("gender", IdCardUtil.getSexForIdcard(idCard));
        } catch (Exception e) {
            e.printStackTrace();
        }
        data.put("msg", msg);
        messageDO.setData(msg);
        messageDO.setDel("1");
        messageDO.setCreateTime(new Date());
        systemMessageDao.save(messageDO);
    }
    /**
@ -616,7 +654,7 @@ public class DoorOrderService {
                " o.patient_phone,o.remark,o.serve_desc,o.create_time,o.patient as patientCode ,o.exam_paper_status as examPaperStatus,o.number as serverCode,o.total_fee,h.org_level as hosLevel, " +
                "o.doctor, o.doctor_name as doctorName, o.doctor_type as doctorType "
                ;
        String sqlCount = " select count(*) as total ";
        String sqlCount = " select count(DISTINCT o.id) as total ";
        String sql = " from wlyy_door_service_order o " +
                " LEFT JOIN wlyy_sign_family f ON f.patient = o.patient AND f. STATUS = 1 AND f.expenses_status = 1 " +
                " LEFT JOIN base_org h on h.code=o.hospital and h.del=1 "
@ -730,8 +768,7 @@ public class DoorOrderService {
            // 获取或者基本信息
            BasePatientDO patient = patientInfoService.findById(String.valueOf(one.get("patientCode")));
            if (patient != null) {
                String sex = IdCardUtil.getSexForIdcard(patient.getIdcard());
                object.put("sex", "1".equals(sex) ? "男" : "2".equals(sex) ? "女" : "未知");
                object.put("sex", IdCardUtil.getSexForIdcard(patient.getIdcard()));
                object.put("age", IdCardUtil.getAgeByIdcardOrBirthday(patient.getIdcard(),patient.getBirthday()));
                object.put("photo", patient.getPhoto());
@ -967,7 +1004,21 @@ public class DoorOrderService {
        BasePatientDO patient = patientInfoService.findById(one.getPatient());
        // 获取微信模板 smfwdwk-上门服务待付款
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        try {
        try {//·
            String first = "key1预约上门服务医生已完成服务。为提高服务质量,诚邀您对本次服务医生进行评分";
            first = first.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
            first = first .replace("key2", null != one.getDoctorName() ? one.getDoctorName() : "");
            WlyyDoorCommentDO wlyyDoorCommentDO = doorCommentDao.selectCommentDoctor(patient.getId(),orderId);
            String finish="";
            if(wlyyDoorCommentDO!=null){
                finish = "0";
            }else {
                finish = "1";
            }
            //url:url + json.getString("url")+"?openid=" + openid + "&id=" + json.getString("id")+ "&finish=" + finish)
            messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","fwyspf",patient.getOpenid(),first,null,null,DateUtil.dateToStrShort(new Date()),"服务医生评分");
/*            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","fwyspf");
            String first = templateConfig.getFirst();
            first = first.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
@ -1031,13 +1082,31 @@ public class DoorOrderService {
        doorServiceOrderDao.save(one);
        // 更新居民签约服务包服务项次数
        this.reduceServiceItemTimes(serverPackagePriceByOrderId(orderId), one.getPatient());
        // 发送微信消息通知--用户评价
/*        BasePatientDO patient = patientInfoService.findById(one.getPatient());
        // 发送微信消息通知--用户评价//·
        BasePatientDO patient = patientInfoService.findById(one.getPatient());
        // 获取微信模板  fwyspf-服务医生评分
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        try {
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","fwyspf");
            String first = "key1预约上门服务医生已完成服务。为提高服务质量,诚邀您对本次服务医生进行评分";
            first = first.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
            first = first .replace("key2", null != one.getDoctorName() ? one.getDoctorName() : "");
            WlyyDoorCommentDO wlyyDoorCommentDO = doorCommentDao.selectCommentDoctor(patient.getId(),orderId);
            String finish="";
            if(wlyyDoorCommentDO!=null){
                finish = "0";
            }else {
                finish = "1";
            }
            //url:url + json.getString("url")+"?openid=" + openid + "&id=" + json.getString("id")+ "&finish=" + finish)
            messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","fwyspf",patient.getOpenid(),first,null,null,DateUtil.dateToStrShort(new Date()),"服务医生评分");
        }catch (Exception e){
            logger.error(e.getMessage());
        }
/*        try {
         WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","fwyspf");
            String first = templateConfig.getFirst();
            first = first.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
            first = first .replace("key2", null != one.getDoctorName() ? one.getDoctorName() : "");
@ -1377,12 +1446,18 @@ public class DoorOrderService {
        wlyyDoorServiceOrderService.orderWithPackageItemFeeAdd(new JSONObject(), jsonObjectParam, order);
        // 发送微信模板消息,通知居民服务项目已经变更(smyyyjjd-服务项目变更通知)
/*        BasePatientDO patient = patientInfoService.findById(order.getProxyPatient());
       BasePatientDO patient = patientInfoService.findById(order.getProxyPatient());//·
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        Integer status = 0;
        try{
            String first = "您的预约服务的服务项目已变更,请及时确认";
            first = first.replace("key1",(patient.getName()==null?"":patient.getName()));
            first = first .replace("key2", null != order.getDoctorName() ? order.getDoctorName() : "");
            String consultStr = consult.getId();
//            url1 + json.getString("url")+"?openid=" + openid + "&consult=" + json.getString("consult") + "&status=" + json.getInt("status")
//            messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","fwyspf",patient.getOpenid(),first,null,null,DateUtil.dateToStrShort(new Date()),"服务项目变更确认");
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","fwxmbgtz");
            /* WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","fwxmbgtz");
            String first = templateConfig.getFirst();
            first = first.replace("key1",(patient.getName()==null?"":patient.getName()));
            first = first .replace("key2", null != order.getDoctorName() ? order.getDoctorName() : "");
@ -1395,10 +1470,11 @@ public class DoorOrderService {
            json.put("remark", templateConfig.getRemark());
            json.put("consult",consult.getCode());
            json.put("status",status);
//            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 32, patient.getOpenid(), patient.getName(), json);
//            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 32, patient.getOpenid(), patient.getName(), json);*/
        }catch (Exception e) {
            logger.error(e.getMessage());
        }*/
        }
    }

+ 60 - 3
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/service/DoorServiceApplicationService.java

@ -4,20 +4,25 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.door.dao.DoorServiceApplicationDao;
import com.yihu.jw.door.dao.DoorServiceVoucherDao;
import com.yihu.jw.door.util.MessageUtil;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.door.WlyyDoorServiceApplicationDo;
import com.yihu.jw.entity.door.WlyyDoorServiceVoucherDo;
import com.yihu.jw.entity.hospital.family.WlyyPatientFamilyMemberDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.family.dao.WlyyPatientFamilyMemberDao;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.message.dao.MessageDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -60,6 +65,16 @@ public class DoorServiceApplicationService {
    private WechatTemplateConfigDao templateConfigDao;*/
    @Autowired
    private WlyyDoorServiceOrderService doorServiceOrderService;
    @Autowired
    private WxTemplateConfigDao wxTemplateConfigDao;
    @Autowired
    private BasePatientDao patientInfoService;
    @Autowired
    private MessageUtil messageUtil;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private SystemMessageDao systemMessageDao;
    @PostConstruct
    public void init() {
@ -259,7 +274,7 @@ public class DoorServiceApplicationService {
        }
        WlyyDoorServiceApplicationDo wlyyDoorServiceApplicationDo1 = doorServiceApplicationDao.save(wlyyDoorServiceApplicationDo);
        if(!"2".equals(doctorFlag)){
            //居民申请给调度员发系统消息
            //居民申请给调度员发系统消息//··
/*            List<Map<String, Object>> mapList = findDispatcherByPatient(patient);
            Message message=null;
            for(Map<String,Object> map:mapList){
@ -491,11 +506,16 @@ public class DoorServiceApplicationService {
            wlyyDoorServiceApplicationDo.setUpdateUser(doctor.getId());
            wlyyDoorServiceApplicationDo.setUpdateUserName(doctor.getName());
            //将所有调度员的消息处理为结束
            List<SystemMessageDO> messages = systemMessageDao.findMessageByRelationCode(String.valueOf(id));
            messages.forEach(item->{
                item.setOver("0");
                systemMessageDao.save(item);
            });
/*            List<Message> messages=messageDao.findMessageByRelationCode(String.valueOf(id));
            messages.forEach(item->{
                item.setOver("0");
            });
            messageDao.save(messages);
            messageDao.save(messages);//··
            //在转给家医的时候需要给家医发消息
            List<SignFamily> signFamilies= signFamilyDao.getSignFamilyByPatient(wlyyDoorServiceApplicationDo.getPatient());
            if(null!=signFamilies&&signFamilies.size()>0){
@ -524,6 +544,11 @@ public class DoorServiceApplicationService {
        }else {
            //处理消息
            List<SystemMessageDO> messages = systemMessageDao.findMessageByRelationCode(String.valueOf(id));
            messages.forEach(item->{
                item.setOver("0");
                systemMessageDao.save(item);
            });
/*            List<Message> messages=messageDao.findMessageByRelationCode(String.valueOf(id));
            messages.forEach(item->{
                item.setOver("0");
@ -557,7 +582,21 @@ public class DoorServiceApplicationService {
        }
        WlyyDoorServiceApplicationDo wlyyDoorServiceApplicationDo1=doorServiceApplicationDao.save(wlyyDoorServiceApplicationDo);
        if(null!=wlyyDoorServiceApplicationDo1){
            //给代理申请资质的居民发送微信模板消息-审核结果
            //给代理申请资质的居民发送微信模板消息-审核结果//·
            BasePatientDO patient = patientInfoService.findById(wlyyDoorServiceApplicationDo1.getProxyPatient());
            String first ="key1您好,key2的资格审核医生已处理。";
            first = first.replace("key1",(patient.getName()==null?"":patient.getName()));
            first = first.replace("key2", (wlyyDoorServiceApplicationDo1.getPatientName() == null ? "" : wlyyDoorServiceApplicationDo1.getPatientName()));
            wlyyDoorServiceApplicationDo1.getAuditorName();
//            String urlStr= json.getString("url");
//            boolean status = urlStr.contains("openid=");
//            if(!status){
//                urlStr=json.getString("url")+"?openid=" + openid;
//            }
//            temp.setUrl(url + urlStr )
            messageUtil.putTemplateWxMessage(wxId,"template_doctor_audit",scene,patient.getOpenid(),first,null,null,null,wlyyDoorServiceApplicationDo1.getAuditorName());
/*            Patient patient = patientDao.findByCode(wlyyDoorServiceApplicationDo1.getProxyPatient());
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_audit",scene);
            if(null==templateConfig){
@ -635,5 +674,23 @@ public class DoorServiceApplicationService {
        return jsonObject;
    }
    public String myMyTest(){
//        String sql="select w.* from base.wx_template_config w where w.wechat_id='xm_ykyy_wx' and w.template_name='template_evaluate_notice' and w.scene='fwqjtx' and w.status=1";
//        List<WxTemplateConfigDO> config =  jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxTemplateConfigDO.class));
//        System.out.println("!");
//        //消息推送测试
//        String first = "王俊,您好!您的上门预约服务已由医生接单了";
//        String contentMsg = "";
//        String remark = "您可点击消息查看详情。";
//        String url ="https://www.baidu.com/s?ie=UTF-8&wd=%E7%99%BE%E5%BA%A6";
//
//        //模板消息
////        messageUtil.putTemplateWxMessage("97ed8a0a-4f07-4b85-ab02-b716c611a464","eee","zxxq","oULM4xCMTL9tuX_DjwEDdi6iaY0c",first,remark,url,"1231312312",DateUtil.getStringDate());
//
//        messageUtil.sendWXMes("xm_ykyy_wx","808080eb73e02e8f0173ebe51e1b007d","210503199507250313",first,contentMsg,remark,url);
        BasePatientDO temp = patientDao.findById("0000000067bab53a0167badd74f00004");
        BasePatientDO patient = patientInfoService.findById("0000000067bab53a0167badd74f00004");
        return "ss";
    }
}

+ 16 - 1
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/service/WlyyDoorPrescriptionService.java

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.discovery.converters.Auto;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.door.dao.DoorServiceOrderDao;
import com.yihu.jw.door.dao.WlyyDoorPrescriptionDao;
@ -11,12 +12,14 @@ import com.yihu.jw.door.dao.WlyyDoorPrescriptionDetailDao;
import com.yihu.jw.door.dao.WlyyDoorPrescriptionDrugDao;
import com.yihu.jw.door.service.prescription.JwDoorPrescriptionService;
import com.yihu.jw.door.service.prescription.PresModeAdapter;
import com.yihu.jw.door.util.MessageUtil;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.door.WlyyDoorPrescriptionDO;
import com.yihu.jw.entity.door.WlyyDoorPrescriptionDrugDO;
import com.yihu.jw.entity.door.WlyyDoorServiceOrderDO;
import com.yihu.jw.entity.patient.Patient;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.util.ImUtil;
@ -85,9 +88,13 @@ public class WlyyDoorPrescriptionService  extends BaseJpaService<WlyyDoorPrescri
    private ZyIvDeptDictDao zyIvDeptDictDao;*/
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private MessageUtil messageUtil;
    @Value("${server.server_url}")
    private String server_url;
    @Value("${wechat.id}")
    private String wxId;
    /**
     * 造长处方开方数据
@ -257,7 +264,15 @@ public class WlyyDoorPrescriptionService  extends BaseJpaService<WlyyDoorPrescri
//        orderDO.setAuthorizeImage(authorizeImage);
        orderDO.setAuthorizeImage(server_url+"/images/healthCardQRcode.png");
        doorServiceOrderDao.save(orderDO);
/*        Patient patient = patientDao.findByCode(orderDO.getPatient());
        BasePatientDO patient = patientDao.findById(orderDO.getPatient());
        String first = "key1,您好!请授权电子健康卡";//·
        first = first.replace("key1", orderDO.getPatientName());
//        json.put("orderId", orderDO.getId());
//        json.put("openId", patient.getOpenid()());
//        json.put("authorizeImage", orderDO.getAuthorizeImage());
        messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","authorize",patient.getOpenid(),first,null,DateUtil.dateToStrShort(new Date()));
/*        Patient patient = patientDao.findByCode(orderDO.getPatient());//·
        //发送微信模板消息
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback", "authorize");
        String first = templateConfig.getFirst();

+ 180 - 80
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/service/WlyyDoorServiceOrderService.java

@ -8,12 +8,15 @@ import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.door.dao.*;
import com.yihu.jw.door.service.consult.ConsultTeamService;
import com.yihu.jw.door.util.MessageUtil;
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.org.BaseOrgDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.door.*;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.org.dao.BaseOrgDao;
@ -160,6 +163,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    private WlyyDoorOrderItemDao doorOrderItemDao;
    @Autowired
    private DoorServiceApplicationService doorServiceApplicationService;
    @Autowired
    private MessageUtil messageUtil;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private SystemMessageDao systemMessageDao;
    /**
     * 上门服务工单服务基本信息
@ -639,7 +648,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            //新增工单医生关联关系
            if (orderWithDoctorAdd(result, jsonObjectParam, wlyyDoorServiceOrder)) {return result;}
            // 给服务医生发接单消息
            this.createMessage(orderDO.getId(),orderDO.getProxyPatient(),orderDO.getDoctor(),407,"服务工单待接单","您有新的服务工单,请前往处理");
            this.createMessage("服务工单待接单","407",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(), orderDO.getDoctor(),orderDO.getDoctorName() ,null, "您有新的服务工单,请前往处理");
            //发送智能助手消息
//            sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
@ -658,10 +667,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        List<Map<String,Object>> dispatcherInfoList = (List)dispatcherJson.get(ResponseContant.resultMsg);
        for(Map<String,Object> map: dispatcherInfoList){
            String dispatcher = map.get("code").toString();
            BaseDoctorDO doctorVO = doctorDao.findById(dispatcher);
            // 派单消息-首页
            this.createMessage(orderDO.getId(),"system",dispatcher,402,"新增居民预约服务申请",orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
            this.createMessage("新增居民预约服务申请","402","system","system", orderDO.getId(), dispatcher,doctorVO.getName() ,doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
            // 派单-实时工单消息  430 居民提交工单申请-- 张三提交了服务工单12345678申请
            this.createMessage(orderDO.getId(),"system",dispatcher,430,"居民提交工单申请",orderDO.getPatientName() + "提交了服务工单"+orderDO.getNumber()+"申请");
            this.createMessage("居民提交工单申请","430","system","system", orderDO.getId(), dispatcher,doctorVO.getName() ,doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务工单"+orderDO.getNumber()+"申请");
        }
        //给机构调度员发送医生助手消息
/*        String  dispatcherSql = "SELECT m.doctor_code FROM base_doctor_role m " +
@ -1354,9 +1364,57 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            orderDO.setDispatcher(dispatcher);
            orderDO.setDispatcherName(dispatcherName);
        }
        //如果是调度员取消,推送IM取消工单json消息,
        orderDO.setStatus(WlyyDoorServiceOrderDO.Status.cancel.getType());
        this.save(orderDO);
        if(type == WlyyDoorServiceOrderDO.CancelType.dispatcher.getType()){
            List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,new String[]{"402","403","430"});
            if(CollectionUtils.isEmpty(messages)){
                logger.error("当前工单没有系统消息!!orderId:" + orderId);
            } else {
                // 432 调度员拒单即取消工单-- 李四拒绝了张三的服务工单12345678
                messages.forEach(
                        message -> {
                            if (message.getType() .equals("430")) {
                                String msg=orderDO.getDispatcherName() + "拒绝了"+ orderDO.getPatientName() +"的服务工单" + orderDO.getNumber();
                                messageUtil.saveSystemMessage(message.getId(),message.getRelationCode(),"调度员拒单","432",dispatcher,dispatcherName,
                                        dispatcher,dispatcherName,null,msg,message.getOver());
                            }else{
                                message.setOver("0");
                                systemMessageDao.save(message);
                            }
                        }
                );
            }
        }
        else if(type == WlyyDoorServiceOrderDO.CancelType.patient.getType()){                   //居民取消,消息列表也应该不显示
            List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,new String[]{"402","403"});
            if(CollectionUtils.isEmpty(messages)){
                logger.error("当前工单没有系统消息!!orderId:" + orderId);
            } else {
                messages.forEach(
                        message -> {
                            message.setOver("0");
                            systemMessageDao.save(message);
                        }
                );
            }
        }
//        else if(type == WlyyDoorServiceOrderDO.CancelType.patient.getType()){                   //居民取消,消息列表也应该不显示
//
//            List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{402,403});
//            if(CollectionUtils.isEmpty(messages)){
//                logger.error("当前工单没有系统消息!!orderId:" + orderId);
//            } else {
//                messages.forEach(
//                        message -> {
//                            message.setOver("0");
//                            messageDao.save(message);
//                        }
//                );
//            }
//        }
        //如果是调度员取消,推送IM取消工单json消息,
/*        if(type == WlyyDoorServiceOrderDO.CancelType.dispatcher.getType()){
            JSONObject content = this.queryOrderCardInfo(orderDO);
@ -1419,6 +1477,27 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        JSONObject confirmInfoJson = new JSONObject();
        confirmInfoJson.put("confirmInfo",confirmInfo);
        this.orderWithConfirmLogAdd(result,confirmInfo,orderId);
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
        String first = "key1,您好,您的上门预约服务已退回,点击查看原因";
        BasePatientDO patient = patientDao.findById(orderDO.getPatient());
        first  = first.replace("key1", null != patient.getName() ? patient.getName() : "");
//        if(consult != null) {
//            json.put("consult", consult.getCode());
//        }else {
//            json.put("id", orderDO.getId());
//        }
//        if(json.has("consult")) {
//            temp.setUrl(url + json.getString("url") + "?openid=" + openid + "&consult=" + json.getString("consult"));
//        }else if (json.has("id")){
//            temp.setUrl(url + json.getString("url") + "?openid=" + openid + "&id=" + json.getString("id"));
//        }else if(json.has("relationCode")){
//            temp.setUrl(url + json.getString("url") + "?openid=" + openid );
//        }else if(json.has("resultCode")){
//            temp.setUrl(url + json.getString("url") + "?resultCode=" + json.getString("resultCode"));
//        }
        messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyqx",patient.getOpenid(),first,null,null,DateUtil.dateToStrShort(new Date()),"上门预约已取消");
/*        Consult consult = consultDao.queryByRelationCode(orderId);
        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
@ -1456,6 +1535,18 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(orderId);
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
        BasePatientDO patient = patientDao.findById(orderDO.getPatient());
        String first="key1,您好,您的上门预约服务已退回,点击查看原因";
        first = first.replace("key1", null != patient.getName() ? patient.getName() : "");
//        json.put("url", "appoint_service/html/appoint-serviceDetail.html?id="+orderId);
//        json.put("remark", templateConfig.getRemark());
//        if(consult != null) {
//            json.put("consult", consult.getCode());
//        }else {
//            json.put("id", orderDO.getId());
//        }
        messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyqx",patient.getOpenid(),first,null,null,DateUtil.dateToStrShort(new Date()),"知情同意书已推送");
/*        BasePatientDO patient = patientDao.findById(orderDO.getPatient());
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","smyyyqx");
        String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
@ -1745,6 +1836,24 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        }else if (StringUtils.isNoneBlank(phone)){
            buffer.append(" AND o.`proxy_patient_phone` like '%"+phone+"%'");
        }
        String applicationSql = "";
        String patientTypeTemp = "";
        if("1".equals(isApplication)){
            applicationSql +=                 " JOIN ( " +
                    "         select a.patient, group_concat(v.type) as type " +
                    "         from wlyy_door_service_voucher v " +
                    "                  JOIN (select t.id, t.patient, max(t.create_time) " +
                    "                        from wlyy_door_service_application t " +
                    "                        where t.status in (2, 3) " +
                    "                        group by t.patient) as a " +
                    "                       on a.id = v.service_id " +
                    "         where v.status = 1 " +
                    "         group by a.patient " +
                    "        ) as t1 on o.patient = t1.patient" ;
            patientTypeTemp = " ,t1.`type` as patientType ";
        }
        String sql = "SELECT " +
                "  p.name AS patientName, " +
                "  p.photo AS photo, " +
@ -1764,23 +1873,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "  o.serve_lat as lat, " +
                "  o.`status` as status, " +
                "  o.`dispatcher_name` as dispatcherName, " +
                "  concat( o.patient,'_' ,c.id, '_',o.`number`,'_11' ) as sessionId, " +
                "   t1.`type` as patientType " +
                "  concat( o.patient,'_' ,c.id, '_',o.`number`,'_11' ) as sessionId " +
                patientTypeTemp +
                " FROM " +
                " ( wlyy_door_service_order o " +
                " LEFT JOIN base_patient p ON o.patient = p.id ) LEFT JOIN wlyy_consult c on o.id = c.relation_code" +
                " JOIN ( " +
                "         select a.patient, group_concat(v.type) as type " +
                "         from wlyy_door_service_voucher v " +
                "                  JOIN (select t.id, t.patient, max(t.create_time) " +
                "                        from wlyy_door_service_application t " +
                "                        where t.status in (2, 3) " +
                "                        group by t.patient) as a " +
                "                       on a.id = v.service_id " +
                "         where v.status = 1 " +
                "         group by a.patient " +
                "        ) as t1 on o.patient = t1.patient" +
                " WHERE " +
                " LEFT JOIN base_patient p ON o.patient = p.id ) LEFT JOIN wlyy_consult c on o.id = c.relation_code"+
                applicationSql+" WHERE " +
                "  o.hospital = '{hospital}' and o.type != 3 " +buffer+
                " AND ( o.`status` = {status} OR -100 = {status} ) " +
                " ORDER BY o.create_time desc " +
@ -1797,17 +1895,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                " FROM  " +
                "   wlyy_door_service_order o  " +
                " LEFT JOIN base_patient p ON o.patient = p.id " +
                " JOIN  ( " +
                "         select a.patient, group_concat(v.type) as type " +
                "         from wlyy_door_service_voucher v " +
                "                  JOIN (select t.id, t.patient, max(t.create_time) " +
                "                        from wlyy_door_service_application t " +
                "                        where t.status in (2, 3) " +
                "                        group by t.patient) as a " +
                "                       on a.id = v.service_id " +
                "         where v.status = 1 " +
                "         group by a.patient " +
                "        ) as t1 on o.patient = t1.patient" +
                applicationSql +
                " WHERE  " +
                "  o.hospital = '{hospital}' " +buffer+
                " AND (o.`status` = {status} or -100 = {status})";
@ -1852,7 +1940,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                    JSONArray parArray = imUtill.getParticipants(sessionId);
                    parArray.forEach(
                            oneParObj -> {
                                org.json.JSONObject oneParJson = (org.json.JSONObject)oneParObj;
                                JSONObject oneParJson = (com.alibaba.fastjson.JSONObject)oneParObj;
                                if(StringUtils.equalsIgnoreCase(oneParJson.getString("id"),dispatcher)){
                                    oneMap.put("isInSession",true);
                                }
@ -2046,7 +2134,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        int start = 0 == page ? page++ : (page - 1) * size;
        int end = 0 == size ? 15 : page * size;
        String sql = "select ds.doctor,d.name, d.job_name as jobName, 1 as sortFlag " +
        String sql = "select ds.doctor,d.name, d.job_title_name as jobName, 1 as sortFlag " +
                " from wlyy_door_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)" +
@ -2054,7 +2142,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        String countSql = "select count(ds.id) " +
                "from wlyy_door_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.code " +
                "         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)";
        List<Map<String,Object>> doctorList = new ArrayList<>();
        try {
@ -2172,11 +2260,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        // 给医生发派单消息
        if(WlyyDoorServiceOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
            this.createMessage(orderId,doorServiceOrderDO.getTransedDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
            this.createMessage("服务工单待接单","407",doorServiceOrderDO.getTransedDispatcher(),doorServiceOrderDO.getTransedDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
        }else{
            this.createMessage(orderId,doorServiceOrderDO.getDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
            this.createMessage("服务工单待接单","407",doorServiceOrderDO.getDispatcher(),doorServiceOrderDO.getDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
        }
        //发送智能助手消息
        //发送智能助手消息//·
        sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
        // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
@ -2185,7 +2273,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        imUtill.updateParticipant(sessionId,doctor,null);
        // 调度员处理完该单(新增预约的,或者是拒单重新派单的)
/*        List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{402,404,430,435});
        List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,new String[]{"402","404","430","435"});
        if(CollectionUtils.isEmpty(messages)){
            logger.error("当前工单没有 居民新增预约 消息!!orderId:" + orderId);
        }else{
@ -2196,20 +2284,19 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                        if("system".equals(dispatcher)){
                            title = "系统派单(派给服务医生)";
                        }
                        if (message.getType() == 430) {
                        if (message.getType() .equals("430")) {
                            message.setTitle(title);
                            message.setContent(doorServiceOrderDO.getDispatcherName() + "已将服务工单" + doorServiceOrderDO.getNumber() + "指派给" + doctorName + "医生");
                            message.setType(431);
                            message.setReceiver(dispatcher);
                            message.setSender(dispatcher);
                            message.setCreateTime(new Date());
                            String msg = doorServiceOrderDO.getDispatcherName() + "已将服务工单" + doorServiceOrderDO.getNumber() + "指派给" + doctorName + "医生";
                            messageUtil.saveSystemMessage(message.getId(),message.getRelationCode(),title,"431",dispatcher,dispathcherName,
                                    dispatcher,dispathcherName,null,msg,message.getOver());
                        }else{
                            message.setOver("0");
                            systemMessageDao.save(message);
                        }
                        messageDao.save(message);
                    }
            );
        }*/
        }
        // 工单状态变更记录
        WlyyDoorProcessLogDO processLogDO = new WlyyDoorProcessLogDO();
@ -2273,9 +2360,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        // 给医生发派单消息
        if(WlyyDoorServiceOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
            this.createMessage(orderId,doorServiceOrderDO.getTransedDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
            this.createMessage("服务工单待接单","407",doorServiceOrderDO.getTransedDispatcher(),doorServiceOrderDO.getTransedDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
        }else{
            this.createMessage(orderId,doorServiceOrderDO.getDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
            this.createMessage("服务工单待接单","407",doorServiceOrderDO.getDispatcher(),doorServiceOrderDO.getDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
        }
        //发送智能助手消息
        sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
@ -2386,28 +2473,33 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    /**
     * 添加【工单派单,转单】等系统消息
     * @param orderId
     * @param sender
     * @param receiver
     * @param Content
     */
    public void createMessage(String orderId,String sender,String receiver,int type,String title,String Content){
/*        Message message=new Message();
        message.setCzrq(new Date());
        message.setCreateTime(new Date());
        message.setRead(1);
        message.setState(1);
        message.setRelationCode(orderId);
        message.setOver("1");
        message.setReceiver(receiver);
        message.setSender(sender);
        message.setCode(getCode());
        message.setTitle(title);
        message.setContent(Content);
        //消息类型:401为资质申请审核
        message.setType(type);
        message.setDel("1");
        messageDao.save(message);*/
    public void createMessage(String title,String type,String sender,String senderName,String relationCode,String Receiver,String ReceiverName,String idCard,String msg){
        SystemMessageDO messageDO = new SystemMessageDO();
        messageDO.setTitle(title);
        messageDO.setType(type);//401为资质申请审核
        messageDO.setSender(sender);
        messageDO.setSenderName(senderName);
        messageDO.setRelationCode(relationCode);
        messageDO.setReceiver(Receiver);
        messageDO.setReceiverName(ReceiverName);
        messageDO.setOver("1");
        net.sf.json.JSONObject data = new net.sf.json.JSONObject();
        data.put("name", ReceiverName);
        try {
            if(StringUtils.isNoneBlank(idCard)){
                data.put("age", IdCardUtil.getAgeForIdcard(idCard));
                data.put("gender", IdCardUtil.getSexForIdcard(idCard));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        data.put("msg", msg);
        messageDO.setData(msg);
        messageDO.setDel("1");
        messageDO.setCreateTime(new Date());
        systemMessageDao.save(messageDO);
    }
    /**
@ -2533,6 +2625,26 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        return res;
    }
    /**
     * 互联网医院开方后 关联上门工单
     * @param orderId
     * @param prescriptionCode
     */
    public void savePrescription(String orderId,String prescriptionCode){
        WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(orderId);
        orderDO.setPrescriptionCode(prescriptionCode);
        orderDO.setPrescriptionTime(new Date());
        orderDO.setPrescriptionStatus(1);
        wlyyDoorServiceOrderDao.save(orderDO);
        //非代预约才发送im消息
        if(orderDO.getType() != null && orderDO.getType() != 3) {
            //发送 预约卡片信息(2101类型)
            JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
            orderInfoContent.put("re_msg_type", 2);//开方完成消息
            this.qucikSendIM(orderDO.getId(), orderDO.getDispatcher(), "智能助手", "2101", orderInfoContent.toJSONString());
        }
    }
    /**
     *  更新医生地理位置状态
@ -2657,15 +2769,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        }
        //判断工单是否已存在,新建或者编辑
        if(StringUtils.isBlank(orderDO.getId())) {
/*            SignFamily signFamily = signFamilyDao.findSignFamilyByPatient(orderDO.getPatient());
            if (signFamily == null) {
                result.put(ResponseContant.resultFlag, ResponseContant.fail);
                String failMsg = "当前服务对象未完成家庭医生签约,请完成签约后再预约上门服务!";
                result.put(ResponseContant.resultMsg, failMsg);
                logger.error(failMsg);
                return result;
            }*/
            //已取消的订单也可以申请
            boolean bool = wlyyDoorServiceOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
                    new Integer[]{WlyyDoorServiceOrderDO.Status.waitForAccept.getType(),
@ -2721,9 +2824,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                sql += " and d.id = '"+orderDO.getDoctor()+"'";
                List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
/*                BaseDoctorDO doctor = doctorDao.findById(orderDO.getDoctor());
                Hospital hospital = hospitalDao.findByCode(doctor.getHospital());
                doorOrderService.acceptOrder1(orderDO.getId(), doctor.getJob(), doctor.getJobName(), hospital.getLevel());*/
                doorOrderService.acceptOrder1(orderDO.getId(), list.get(0).get("job_title_code").toString(),
                        list.get(0).get("job_title_name").toString(), Integer.valueOf(list.get(0).get("org_level").toString()));
            }catch (Exception e){
@ -2732,7 +2832,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        }else{
            // 给服务医生发接单消息
            this.createMessage(orderDO.getId(),orderDO.getProxyPatient(),orderDO.getDoctor(),407,"服务工单待接单","您有新的服务工单,请前往处理");
            this.createMessage("服务工单待接单","407",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(),orderDO.getDoctor(),orderDO.getDoctorName(), null,"您有新的服务工单,请前往处理");
            //发送智能助手消息
            sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
        }

+ 10 - 2
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/service/common/PatientService.java

@ -2,8 +2,10 @@ package com.yihu.jw.door.service.common;
import com.yihu.jw.door.dao.common.SignFamilyDao;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
import com.yihu.jw.entity.door.SignFamily;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang3.StringUtils;
@ -22,6 +24,8 @@ public class PatientService {
    private BasePatientDao patientDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private BasePatientMedicareCardDao patientMedicareCardDao;
    /**
     * 查询单个居民信息
@ -34,10 +38,12 @@ public class PatientService {
        JSONObject json = new JSONObject();
        BasePatientDO p = patientDao.findById(patient);
        PatientMedicareCardDO medicareCardDO = patientMedicareCardDao.findByTypeAndPatientCodeAndDel("A_01",patient,"1");
        if (p == null) {
            throw new Exception("patient info can not find");
        }
        // 设置患者标识
        json.put("code", p.getId());
        // 设置患者姓名
@ -66,8 +72,10 @@ public class PatientService {
        json.put("streetName", p.getStreetName());
        // 设置患者地址
        json.put("address", p.getAddress());
        // 社保号
//        json.put("ssc", p.getSsc());
        // 社保号/医保卡
        if(medicareCardDO!=null){
            json.put("ssc", medicareCardDO.getCode());
        }
        //病情类型:0健康,1高血压,2糖尿病,(1,2)高血压+糖尿病
/*        json.put("disease",p.getDisease());

+ 79 - 0
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/service/common/WlyyMessageService.java

@ -0,0 +1,79 @@
package com.yihu.jw.door.service.common;
import com.alibaba.fastjson.JSONArray;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by yeshijie on 2021/1/4.
 */
@Service
public class WlyyMessageService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 获取待接单的接口
     *
     * @param message {"read":1,"over":0}
     * @param page 页码
     * @param size 分页大小
     * @return
     * @throws Exception
     */
    public JSONObject getWaitingMessages(SystemMessageDO message, String types, Integer page, Integer size) throws Exception{
        String sqlList = " SELECT a.*, b.`status` AS appliStatus ";
        String sqlCount = " select count(*) as total ";
        String sql =  " FROM base_system_message a " +
                " LEFT JOIN wlyy_door_service_application b ON a.relation_code = b.id ";
        sql+= " where a.del='1' AND a.over = 1  ";
        if(!StringUtils.isEmpty(message.getReceiver())){
            sql+=" AND a.receiver = '"+message.getReceiver()+"'";
        }
        if(!StringUtils.isEmpty(types)){
            sql+=" AND a.type IN ('"+types.replaceAll(",","','")+"')";
        }
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount+sql);
        sql+=" ORDER BY a.create_time DESC LIMIT "+(page-1)*size+","+size;
        List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sqlList+sql);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        JSONArray jsonArray = new JSONArray();
        for(Map<String,Object> one:mapList){
            JSONObject object = new JSONObject();
            object.put("over",one.get("over"));
            object.put("receiver",one.get("receiver"));
            object.put("del",one.get("del"));
            object.put("title",one.get("title"));
            object.put("type",one.get("type"));
            object.put("content",one.get("content"));
            object.put("sender",one.get("sender"));
            object.put("id",one.get("id"));
            object.put("relation_code",one.get("relation_code"));
            object.put("has_read",one.get("is_read"));
            object.put("appliStatus",one.get("appliStatus"));
            Date date = (Date)one.get("create_time");
            object.put("create_time", DateUtil.dateToStr(date,"yyyy-MM-dd HH:mm:ss"));
            Date date1 = (Date)one.get("czrq");
            object.put("czrq", DateUtil.dateToStr(date1,"yyyy-MM-dd HH:mm:ss"));
            jsonArray.add(object);
        }
        JSONObject object = new JSONObject();
        object.put("total",count);
        object.put("waitingMessages",jsonArray);
        object.put("currPage",page);
        object.put("pageSize",size);
        return object;
    }
}

+ 304 - 0
svr/svr-door-serivce/src/main/java/com/yihu/jw/door/util/MessageUtil.java

@ -0,0 +1,304 @@
package com.yihu.jw.door.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
import com.yihu.jw.entity.base.wx.WxAccessTokenDO;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.rm.base.WechatRequestMapping;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import com.yihu.jw.wechat.dao.WxAccessTokenDao;
import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
import com.yihu.jw.wechat.service.WxAccessTokenService;
import com.yihu.utils.network.HttpUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * Created by liub on 2020/12/28.
 */
@Component
public class MessageUtil {
    private static Logger logger = LoggerFactory.getLogger(MessageUtil.class);
    @Autowired
    private WxAccessTokenService wxAccessTokenService;
    @Value("${hospital.url}")
    private String serverUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private WeixinMessagePushUtils weixinMessagePushUtils;
    @Autowired
    private WxTemplateConfigDao wxTemplateConfigDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SystemMessageDao systemMessageDao;
    @Autowired
    private WxAccessTokenDao wxAccessTokenDao;
    //发送微信模板消息
    public static String sendMessageUrl ="http://172.16.100.37:8090/hospitalPortal-sms/sms/sendMessage";
    /**
     *
     * @param wxId
     * @param patient 患者id
     * @param cardNo
     * @param first
     * @param noticeContent
     * @param remark
     * @param redirectUrl
     * @return
     */
    public String sendWXMes(String wxId,String patient,String cardNo,String first,String noticeContent,String remark,String redirectUrl){
        String msg="first:"+first+"contentMsg:"+noticeContent+"remark:"+remark;
        logger.info("发送的信息="+msg);
        JSONObject params = new JSONObject();
        params.put("transType","sms.hospital.notice");
        params.put("merchId","3501000014");
        JSONObject p = new JSONObject();
        String openId = "";
        if(StringUtils.isNotBlank(patient)){
            String sql = "select * from base.base_patient_wechat where wechat_id='"+wxId+"'and patient_id='"+patient+"' ";
            List<BasePatientWechatDo> paientWechatDos = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BasePatientWechatDo.class));
            if(paientWechatDos!=null&&paientWechatDos.size()>0){
                openId = paientWechatDos.get(0).getOpenid();
                p.put("openId",openId);
            }
        }else {
            p.put("cardNo",cardNo);
        }
        p.put("first",first);
        p.put("noticeTime", DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss"));
        p.put("noticeContent",noticeContent);
        if(StringUtils.isNotBlank(redirectUrl)){
            p.put("redirectUrl",redirectUrl);
        }
        p.put("remark",remark);
        params.put("param",p);
        logger.info("params :"+params.toString());
        if(StringUtils.isNotBlank(openId)||StringUtils.isNotBlank(cardNo)){
            String rs = HttpUtil.sendPost(sendMessageUrl,params.toJSONString());
            JSONObject rsJson = JSON.parseObject(rs);
            String resCode = rsJson.getString("respCode");
            if("000000".equals(resCode)){
                return "1";
            }
            return "0";
        }else {
            return "-1";
        }
    }
    public String ehospitalNotice(String userName, String idCard, String phone, String title, String content, String contentString,String url) {
        String msg="first:"+title+"contentMsg:"+content+"remark:"+contentString;
        logger.info("发送的信息="+msg);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userName", userName);
        jsonObject.put("idCard", idCard);
        jsonObject.put("phone", phone);
        jsonObject.put("title", title);
        jsonObject.put("url", url);
        jsonObject.put("content", content);
        jsonObject.put("contentString", contentString);
        System.out.println(serverUrl);
        String responseMsg = httpClientUtil.sendPost(serverUrl + "/interface/ehospitalNoticePush.htm", jsonObject.toString());
        logger.info("ehospitalNoticePushResult:" + responseMsg);
        return responseMsg;
    }
    public void putTemplateWxMessage(String wechatId,String templateName,String scene,String openId,String first,String remark,String url,String ...keywords){
        try {
            WxAccessTokenDO wxAccessTokenDO = getWxAccessTokenById(wechatId);
            if (wxAccessTokenDO==null){
                logger.info("wx_access_token表获取为空,wechatId"+wechatId);
                return;
            }
            WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
            String sql="select w.* from base.wx_template_config w where w.wechat_id='"+wechatId+"' and w.template_name='"+templateName+"' and w.scene='"+scene+"' and w.status=1";
            List<WxTemplateConfigDO> configList =  jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxTemplateConfigDO.class));
            WxTemplateConfigDO config =null;
            if (configList.size()>0){
                config = configList.get(0);
            }else {
                logger.info("微信模板不存在!请确认wechatId:"+wechatId+",templateName:"+templateName+",scene:"+scene);
                return;
            }
            BeanUtils.copyProperties(config, newConfig);
            if (StringUtils.isNoneBlank(url)){
                newConfig.setUrl(url);
            }
            if (StringUtils.isNoneBlank(remark)){
                newConfig.setRemark(remark);
            }
            newConfig.setFirst(first);
            int keyLength = keywords.length;
            if (keyLength>=1){
                newConfig.setKeyword1(keywords[0]);
            }
            if (keyLength>=2){
                newConfig.setKeyword1(keywords[1]);
            }
            if (keyLength>=3){
                newConfig.setKeyword1(keywords[2]);
            }
            if (keyLength>=4){
                newConfig.setKeyword1(keywords[3]);
            }
            if (keyLength>=5){
                newConfig.setKeyword1(keywords[4]);
            }
            if (keyLength>=6){
                newConfig.setKeyword1(keywords[5]);
            }
            if (keyLength>=7){
                newConfig.setKeyword1(keywords[6]);
            }
            //发起微信消息模板推送
            weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(), openId, newConfig);
        }catch (Exception e){
            logger.info("微信模板推送异常");
            e.printStackTrace();
        }
    }
    public WxAccessTokenDO getWxAccessTokenById(String wechatId) {
        try {
            //根据wechatCode查找出appid和appSecret
            String sql ="select * from base.wx_wechat w where w.id = '"+wechatId+"' and w.status!=-1";
            List<WxWechatDO> wxWechatList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxWechatDO.class));
            WxWechatDO wxWechat=null;
            if (wxWechatList.size()>0){
                wxWechat = wxWechatList.get(0);
            }
            sql="select * from base.wx_access_token w where w.wechat_id ='"+wechatId+"' order by w.add_timestamp desc ";
            List<WxAccessTokenDO> wxAccessTokens =  jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxAccessTokenDO.class));
            if(wxWechat==null){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code);
            }
            if(wxAccessTokens!=null&&wxAccessTokens.size()>0){
                for (WxAccessTokenDO accessToken : wxAccessTokens) {
                    if ((System.currentTimeMillis() - accessToken.getAddTimestamp()) < (accessToken.getExpiresIn() * 500)) {
                        return accessToken;
                    } else {
                        sql="DELETE  from  base.wx_access_token where wechat_id='"+accessToken.getWechatId()+"' and access_token='"+accessToken.getAccessToken()+"'";
                        jdbcTemplate.execute(sql);
                        break;
                    }
                }
            }
            String token_url = "https://api.weixin.qq.com/cgi-bin/token";
            String appId="";
            String appSecret="";
            appId = wxWechat.getAppId();
            appSecret = wxWechat.getAppSecret();
            if (org.springframework.util.StringUtils.isEmpty(appId)){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_is_null, ExceptionCode.common_error_params_code);
            }
            if (org.springframework.util.StringUtils.isEmpty(appSecret)){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appSecret_is_null, ExceptionCode.common_error_params_code);
            }
            Map<String, Object> params = new HashMap<>();
            params.put("grant_type", "client_credential");
            params.put("appid", appId);
            params.put("secret", appSecret);
            String result = HttpUtils.doGet(token_url, params).getContent();
            logger.info("--------------wechat token return:"+result+"---------------");
            org.json.JSONObject json = new org.json.JSONObject(result);
            if (json.has("access_token")) {
                String token = json.get("access_token").toString();
                String expires_in = json.get("expires_in").toString();
                WxAccessTokenDO newaccessToken = new WxAccessTokenDO();
                newaccessToken.setAccessToken(token);
                newaccessToken.setExpiresIn(Long.parseLong(expires_in));
                newaccessToken.setAddTimestamp(System.currentTimeMillis());
                newaccessToken.setCzrq(new Date());
                newaccessToken.setCode(UUID.randomUUID().toString().replace("-",""));
                newaccessToken.setWechatId(wechatId);
                wxAccessTokenDao.save(newaccessToken);
                return newaccessToken;
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     *
     */
    public SystemMessageDO saveSystemMessage(String messageId,String relationCode,String title,String type,String sender,String senderName,String receiver,String receiverName,String idCard,String msg,String over) {
        SystemMessageDO messageDO = new SystemMessageDO();
        if (StringUtils.isBlank(messageId)){
            messageDO.setId(UUID.randomUUID().toString().replace("-",""));
        }
        messageDO.setTitle(title);
        messageDO.setType(type);
        messageDO.setSender(sender);
        messageDO.setSenderName(senderName);
        messageDO.setRelationCode(relationCode);
        messageDO.setReceiver(receiver);
        messageDO.setReceiverName(receiverName);
        net.sf.json.JSONObject data = new net.sf.json.JSONObject();
        data.put("name", receiverName);
        try {
            if(StringUtils.isNoneBlank(idCard)){
                data.put("age", IdCardUtil.getAgeForIdcard(idCard));
                data.put("gender", IdCardUtil.getSexForIdcard(idCard));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        data.put("msg", msg);
        messageDO.setData(data.toString());
        messageDO.setOver(over);
        messageDO.setDel("1");
        messageDO.setCreateTime(new Date());
        systemMessageDao.save(messageDO);
        return messageDO;
    }
    public  void test(){
        String sql="select w.* from base.wx_template_config w where w.wechat_id='xm_ykyy_wx' and w.template_name='template_evaluate_notice' and w.scene='fwqjtx' and w.status=1";
        List<Map<String,Object>> config =  jdbcTemplate.queryForList(sql);
//        wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus("xm_ykyy_wx", "template_pay_notice_jz", "mzxxtx", 1)
        System.out.println("!");
    }
    public static void main(String[] args){
        try {
            for (int i=0;i<10;i++){
                System.out.println(UUID.randomUUID().toString().replace("-",""));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("1");
    }
}

+ 82 - 1
svr/svr-door-serivce/src/main/resources/application.yml

@ -94,7 +94,7 @@ neiwang:
base:
  url: http://172.17.110.212:10020/
  hospitalUrl: http://172.26.0.107:10022/
wechat:
  appId: wxd03f859efdf0873d
  appSecret: 2935b54b53a957d9516c920a544f2537
@ -173,6 +173,7 @@ neiwang:
base:
  url: http://172.17.110.212:10020/
  hospitalUrl: http://172.26.0.107:10022/
wechat:
  appId: wx1f129f7b51701428
@ -251,6 +252,7 @@ server:
base:
  url: http://192.168.120.96:10020/svr-base/
  hospitalUrl: http://172.26.0.107:10022/
wechat:
  appId: wxad04e9c4c5255acf
@ -299,5 +301,84 @@ FileTempPath:
  voice_path : /var/local/upload/voice
  chat_file_path : /var/local/upload/chat
# 系统配置
systemSetting:
  isApplication: 0 # 是否需要资质申请 1需要 0 不需要
---
spring:
  profiles: tnJwprod
  datasource:
    url: jdbc:mysql://10.9.1.247:3306/base?useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true
    username: wlyy
    password: qY#j2n5O
  redis:
    host: 10.9.1.247 # Redis server host.
    port: 6380 # Redis server port.
    password: Kb6wKDQP1W4
fastDFS:
  fastdfs_file_url: https://hlwyy.xmzsh.com/fastdfs/
fast-dfs:
  tracker-server: 10.9.1.247:22122
  public-server: https://hlwyy.xmzsh.com/fastdfs/
neiwang:
  enable: true
  wlyy: http://59.61.92.90:9099/iot/
server:
  server_url: http://ehr.yihu.com/wlyy/
base:
  url: http://192.168.120.96:10020/svr-base/
  hospitalUrl: http://172.26.0.107:10022/
wechat:
  appId: wxad04e9c4c5255acf
  appSecret: ae77c48ccf1af5d07069f5153d1ac8d3
  wechat_token: 27eb3bb24f149a7760cf1bb154b08040
  wechat_base_url: http%3a%2f%2fwww.xmtyw.cn%2fwlyy
  accId: gh_ffd64560fb21
  id: sd_tnzyy_wx  # base库中,wx_wechat 的id字段
  flag: true #演示环境  true走Mysql数据库  false走Oracle
im:
  im_list_get: http://10.9.1.247:3000/
  data_base_name: im
es:
  pwflag: 1 # 1需要密码,2不需要密码
  index:
    Statistics: hlw_quota_prod
  type:
    Statistics: hlw_quota_prod
  host:  http://10.9.1.247:9200
  tHost: 10.9.1.247:9300
  clusterName: jkzl
  securityUser: lion:jkzlehr
  user: lion
  password: jkzlehr
wlyy:
  url: http://ehr.yihu.com/wlyy/
hospital:
  url: https://wx.xmzsh.com
  mqUser: JKZL
  mqPwd: 123456
  SourceSysCode: S60
  TargetSysCode: S01
demo:
  flag: false
express:
  sf_url: https://mrds-admin.sf-express.com:443
  sf_code: WH000101
  sf_check_word: EDSAFWFAQWyjt8099
pay:
  flag: true
# 上传文件临时路径配置
FileTempPath:
  upload_temp_path : /var/local/temp
  image_path : /var/local/upload/images
  voice_path : /var/local/upload/voice
  chat_file_path : /var/local/upload/chat
# 系统配置
systemSetting:
  isApplication: 0 # 是否需要资质申请 1需要 0 不需要