浏览代码

Merge branch 'dev' of yeshijie/wlyy2.0 into dev

叶仕杰 5 年之前
父节点
当前提交
c9837bc432

+ 19 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/YkyyEntranceService.java

@ -167,6 +167,25 @@ public class YkyyEntranceService {
        return "success";
    }
    /**
     * 查找眼科his 已审核未付款的处方
     * @throws Exception
     */
    public JSONArray getUnsettledPrescription() throws Exception{
        String sql = "SELECT h.BRID,h.CFSB from HLW_CF01 h WHERE h.SPZT = 1 and h.FKZT = 0";
        Map<String,Object> params = new HashedMap();
        params.put("sql",sql);
        HttpResponse response = HttpUtils.doGet(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        Integer status = rs.getInteger("status");
        if(status!=null&&status == 200){
            return rs.getJSONArray("detailModelList");
        }
        return new JSONArray();
    }
    public String updateYkyyDoctor()throws Exception{
        String sql ="select y.code AS \"code\",y.name AS \"name\",y.expertise AS \"expertise\",y.introduce AS \"introduce\",y.mobile AS \"mobile\",y.idCard AS \"idcard\",y.jobtitlecode AS \"jobTitleCode\",y.jobTitleName AS \"jobTitleName\",y.dept AS \"dept\",y.deptName AS \"deptName\" from v_Hlw_Ysxx y where y.idcard is not null";
        Map<String,Object> params = new HashedMap();

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

@ -0,0 +1,11 @@
package com.yihu.jw.wechat.dao;
import com.yihu.jw.entity.base.wx.WxPushLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by yeshijie on 2020/4/27.
 */
public interface WxPushLogDao extends PagingAndSortingRepository<WxPushLogDO, String>, JpaSpecificationExecutor<WxPushLogDO> {
}

+ 79 - 3
business/base-service/src/main/java/com/yihu/jw/wechat/service/WxTemplateService.java

@ -4,10 +4,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.entity.base.wx.WxTemplateDO;
import com.yihu.jw.entity.base.wx.*;
import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
import com.yihu.jw.oauth.OauthSsoService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.Envelop;
@ -15,7 +14,9 @@ import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import com.yihu.jw.utils.RSAEncrypt;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.jw.wechat.dao.BasePatientWechatDao;
import com.yihu.jw.wechat.dao.WxPushLogDao;
import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
import com.yihu.jw.wechat.dao.WxTemplateDao;
import org.slf4j.Logger;
@ -28,6 +29,7 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by Administrator on 2017/5/19 0019.
@ -62,6 +64,14 @@ public class WxTemplateService {
    
    @Autowired
    private XzzxEntranceService xzzxEntranceService;
    @Autowired
    private YkyyEntranceService ykyyEntranceService;
    @Autowired
    private WxPushLogDao wxPushLogDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    
    
    /**
@ -115,6 +125,72 @@ public class WxTemplateService {
        return "success";
    }
    /**
     * 查询HIS的01表中的审方状态,如果已审方,且未结算,则推送一条模板消息给居民,让居民进行支付结算。
     */
    public void unSettledHISPrescription() throws Exception{
        if("xm_ykyy_wx".equals(wechatId)){
            //获取已审核未结算的处方
            JSONArray array = ykyyEntranceService.getUnsettledPrescription();
//            JSONArray array = new JSONArray();
//            JSONObject tmpjson = new JSONObject();
//            tmpjson.put("BRID","1234");
//            tmpjson.put("CFSB","1159744");
//            array.add(tmpjson);
            //发送模板
            if(array!=null&&array.size()>0) {
                for (int i = 0; i<array.size(); i++){
                    JSONObject json = array.getJSONObject(i);
                    String brid = json.getString("BRID");
                    String cfsb = json.getString("CFSB");
                    //查找居民信息
                    BasePatientDO patientDO = ykyyEntranceService.findPatientByMapingCode(brid);
                    if(patientDO!=null){
                        //查找对应的处方
                        String sql = "SELECT w.OUTPATIENT_ID,w.ID,w.DOCTOR_NAME from WLYY_PRESCRIPTION w WHERE REAL_ORDER = '"+cfsb+"' ORDER BY w.CREATE_TIME desc";
                        List<Map<String, Object>> pre = hibenateUtils.createSQLQuery(sql);
                        if(pre!=null && pre.size()>0){
                            String outpatientId = pre.get(0).get("OUTPATIENT_ID").toString();
                            String prescriptionId = pre.get(0).get("ID").toString();
                            String doctorName = pre.get(0).get("DOCTOR_NAME").toString();
                            //判断是否发送过
                            String countSql = "SELECT id from WX_PUSH_LOG w WHERE w.RECEIVER = '"+patientDO.getId()
                                    +"' and w.OPENID = '"+prescriptionId+"' and w.scene = 'djsxxtz' and w.WECHAT_ID='"+wechatId+"'";
                            List<Map<String, Object>> count = hibenateUtils.createSQLQuery(countSql);
                            if(count==null || count.size() == 0){
                                List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,patientDO.getId());
                                if(ps.isEmpty()){
                                    logger.info("该用户"+patientDO.getName()+"没有openid,无法推送模版消息,用户ID:"+patientDO.getId()+"wechatId:"+wechatId);
                                }else{
                                    ps.stream().forEach(one->{
                                        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_unsettled_notice","djsxxtz",1);
                                        config.setFirst(config.getFirst().replace("key1",patientDO.getName()));
                                        config.setUrl(config.getUrl()+""+outpatientId+"&openid="+one.getOpenid());
                                        config.setKeyword3(doctorName);
                                        WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
                                        weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(),one.getOpenid(),config);
                                    });
                                    //保存发送模板记录,
                                    WxPushLogDO wxPushLogDO = new WxPushLogDO();
                                    wxPushLogDO.setCreateTime(new Date());
                                    wxPushLogDO.setOpenid(prescriptionId);
                                    wxPushLogDO.setReceiver(patientDO.getId());
                                    wxPushLogDO.setWechatId(wechatId);
                                    wxPushLogDO.setReceiverName(patientDO.getName());
                                    wxPushLogDO.setScene("djsxxtz");
                                    wxPushLogDao.save(wxPushLogDO);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    public String sendWeTempMesTest(String wechatId,String openid)throws Exception{
        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_survey","test",1);

+ 5 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxPushLogDO.java

@ -3,12 +3,16 @@ package com.yihu.jw.entity.base.wx;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Trick on 2018/8/21.
 */
public class WxPushLogDO extends UuidIdentityEntity {
@Entity
@Table(name = "wx_push_log")
public class WxPushLogDO extends UuidIdentityEntity implements java.io.Serializable{
    private String wechatId;//推送类型
    private String tempName;//模板名称

+ 1 - 1
common/common-util/src/main/java/com/yihu/jw/util/wechat/WeixinMessagePushUtils.java

@ -169,7 +169,7 @@ public class WeixinMessagePushUtils {
        //设置keyword1
        if(StringUtils.isNotBlank(wxtemp.getKeyword1())){
            WechatTemplateDataDO keyword1 = new WechatTemplateDataDO();
            keyword1.setValue(wxtemp.getRemark());
            keyword1.setValue(wxtemp.getKeyword1());
            keyword1.setColor("#000000");
            data.put("keyword1",keyword1);
        }

+ 42 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/job/ykyy/UnSettledHISPrescriptionJob.java

@ -0,0 +1,42 @@
package com.yihu.jw.job.ykyy;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
import com.yihu.jw.job.DataUploadJob;
import com.yihu.jw.util.wechat.WeiXinMessageUtils;
import com.yihu.jw.wechat.service.WxTemplateService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * 定时查询HIS的01表中的审方状态,如果已审方,且未结算,则推送一条模板消息给居民,让居民进行支付结算。
 * Created by yeshijie on 2020/4/26.
 *
 * @author yeshijie.
 */
public class UnSettledHISPrescriptionJob implements Job{
    private static final Logger logger = LoggerFactory.getLogger(UnSettledHISPrescriptionJob.class);
    @Autowired
    private WxTemplateService wxTemplateService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("START========UnSettledHISPrescriptionJob========");
        try {
            wxTemplateService.unSettledHISPrescription();
            logger.info("END========UnSettledHISPrescriptionJob 执行结束========");
        }catch (Exception e){
            e.printStackTrace();
            logger.error("END===ERROE===UnSettledHISPrescriptionJob,message:"+e.getMessage());
        }
    }
}

+ 30 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/web/quota/JobController.java

@ -7,11 +7,13 @@ import com.yihu.jw.internet.service.InternetCommonService;
import com.yihu.jw.internet.service.InternetService;
import com.yihu.jw.internet.service.ykyy.YkyyInternetService;
import com.yihu.jw.job.*;
import com.yihu.jw.job.ykyy.UnSettledHISPrescriptionJob;
import com.yihu.jw.job.ykyy.YkyyDataUploadJob;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.service.quota.JobService;
import com.yihu.jw.util.SystemConf;
import com.yihu.jw.web.BaseController;
import com.yihu.jw.wechat.service.WxTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.LoggerFactory;
@ -53,6 +55,8 @@ public class JobController extends BaseController {
    @Autowired
    private InternetCommonService internetCommonService;
    @Autowired
    private WxTemplateService wxTemplateService;
    @Autowired
    public JobController(JobService jobService, QuartzHelper quartzHelper) {
@ -60,6 +64,21 @@ public class JobController extends BaseController {
        this.quartzHelper = quartzHelper;
    }
    /**
     * 测试方法
     * @return
     */
    @RequestMapping(value = "unSettledHISPrescription", method = RequestMethod.GET)
    public String unSettledHISPrescription() {
        try {
            wxTemplateService.unSettledHISPrescription();
            return success("成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "失败:" + e.getMessage());
        }
    }
    @RequestMapping(value = "removeJob", method = RequestMethod.GET)
    public String removeJob(String taskId) {
@ -145,6 +164,17 @@ public class JobController extends BaseController {
                        logger.info("data_common_upload_job  job exist");
                    }
                    break;
                case "unsettled_prescription_notice_job" :
                    //互联网医院 待结算消息推送
                    if (!quartzHelper.isExistJob("unsettled_prescription_notice_job")) {
                        String trigger = SystemConf.getInstance().getSystemProperties().getProperty("unsettled_prescription_notice_job");
                        quartzHelper.addJob(UnSettledHISPrescriptionJob.class, trigger, "unsettled_prescription_notice_job", new HashMap<String, Object>());
                        logger.info("unsettled_prescription_notice_job  job success");
                    } else {
                        logger.info("unsettled_prescription_notice_job  job exist");
                    }
                    break;
                default :
            }

+ 2 - 2
svr/svr-internet-hospital-job/src/main/resources/application.yml

@ -155,7 +155,7 @@ fastDFS:
wlyy:
  url: http://www.xmtyw.cn/wlyytest/
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040  # base库中,wx_wechat 的id字段
  id: xm_ykyy_wx  # base库中,wx_wechat 的id字段
---
@ -192,7 +192,7 @@ fastDFS:
wlyy:
  url: http://www.xmtyw.cn/wlyytest/
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040  # base库中,wx_wechat 的id字段
  id: xm_ykyy_wx  # base库中,wx_wechat 的id字段
---

+ 2 - 1
svr/svr-internet-hospital-job/src/main/resources/system.properties

@ -11,7 +11,8 @@ data_upload_job=0 0 2 * * ?
#-------------------------中山医院end-----------------------------#
#-------------------------眼科医院-----------------------------#
data_ykupload_job=0 0 0 * * ?
#每间隔1分钟触发
unsettled_prescription_notice_job=0 */1 * * * ?
#-------------------------眼科医院end-----------------------------#
#-------------------------监管平台通用医院-----------------------------#
data_common_upload_job=0 0 0 * * ?