浏览代码

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

Progr1mmer 6 年之前
父节点
当前提交
abd7356b07
共有 25 个文件被更改,包括 1197 次插入139 次删除
  1. 1 1
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WechatTemplateDO.java
  2. 113 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxPushLogDO.java
  3. 188 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxTemplateConfigDO.java
  4. 10 0
      common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/PatientRehabilitationPlanDO.java
  5. 11 11
      common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationDetailDO.java
  6. 5 6
      common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationTemplateDetailDO.java
  7. 1 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/WechatRequestMapping.java
  8. 7 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/specialist/SpecialistMapping.java
  9. 12 0
      common/common-util/pom.xml
  10. 0 23
      common/common-util/src/main/java/com/yihu/jw/util/wechat/PushMsgTask.java
  11. 223 0
      common/common-util/src/main/java/com/yihu/jw/util/wechat/WeixinMessagePushUtils.java
  12. 171 0
      common/common-util/src/main/java/com/yihu/jw/util/wechat/wxhttp/HttpUtil.java
  13. 5 5
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/controller/WechatCoreController.java
  14. 32 42
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/controller/WxTemplateController.java
  15. 15 0
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxTemplateConfigDao.java
  16. 47 6
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WechatCoreService.java
  17. 2 2
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WxAccessTokenService.java
  18. 37 38
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WxTemplateService.java
  19. 1 1
      svr/svr-base/src/main/resources/bootstrap.yml
  20. 4 2
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/SpecialistController.java
  21. 159 0
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/rehabilitation/RehabilitationPlanController.java
  22. 14 0
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/rehabilitation/RehabilitationPlanTemplateDao.java
  23. 14 0
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/rehabilitation/RehabilitationTemplateDetailDao.java
  24. 27 2
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/SpecialistService.java
  25. 98 0
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/rehabilitation/RehabilitationPlanService.java

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

@ -17,7 +17,7 @@ public class WechatTemplateDO implements Serializable {
    private String url;//URL置空,则在发送后,点击模板消息会进入一个空白页面(ios),或无法点击(android)
    private String url;//URL置空,则在发送后,点击模板消息会进入一个空白页面(ios),或无法点击(android)
    private Miniprogram miniprogram;
    private Miniprogram miniprogram; //小程序跳转
    private Map<String,WechatTemplateDataDO> data;//详细内容
    private Map<String,WechatTemplateDataDO> data;//详细内容

+ 113 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxPushLogDO.java

@ -0,0 +1,113 @@
package com.yihu.jw.entity.base.wx;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Column;
import java.util.Date;
/**
 * Created by Trick on 2018/8/21.
 */
public class WxPushLogDO extends UuidIdentityEntity {
    private String wechatId;//推送类型
    private String tempName;//模板名称
    private String scene;//场景值
    private String openid;//接收者openid
    private String receiver;//接收者code
    private String receiverName;//接收者姓名
    private String request;//请求入参
    private String response;//返回值
    private String status;//状态(0失败,1成功)
    private Date createTime;//创建时间
    @Column(name = "wechat_id")
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    @Column(name = "temp_name")
    public String getTempName() {
        return tempName;
    }
    public void setTempName(String tempName) {
        this.tempName = tempName;
    }
    @Column(name = "scene")
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
    @Column(name = "openid")
    public String getOpenid() {
        return openid;
    }
    public void setOpenid(String openid) {
        this.openid = openid;
    }
    @Column(name = "receiver")
    public String getReceiver() {
        return receiver;
    }
    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }
    @Column(name = "receiver_name")
    public String getReceiverName() {
        return receiverName;
    }
    public void setReceiverName(String receiverName) {
        this.receiverName = receiverName;
    }
    @Column(name = "request")
    public String getRequest() {
        return request;
    }
    public void setRequest(String request) {
        this.request = request;
    }
    @Column(name = "response")
    public String getResponse() {
        return response;
    }
    public void setResponse(String response) {
        this.response = response;
    }
    @Column(name = "status")
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    @Column(name = "create_time")
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

+ 188 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxTemplateConfigDO.java

@ -0,0 +1,188 @@
package com.yihu.jw.entity.base.wx;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Trick on 2018/8/21.
 */
@Entity
@Table(name = "wx_template_config")
public class WxTemplateConfigDO extends UuidIdentityEntityWithOperator implements java.io.Serializable{
    private String wechatId;//微信id
    private String templateId;//微信模板id
    private String templateName;//自定义模板名称
    private String scene;//使用场景值
    private String sceneDescription;//使用场景描述
    private String first;//头部,
    private String url;//跳转链接
    private String remark;//备注
    private String keyword1;//项目
    private String keyword2;//项目
    private String keyword3;//项目
    private String keyword4;//项目
    private String keyword5;//项目
    private String keyword6;//项目
    private String keyword7;//项目
    private String appid;//跳转小程序的appid
    private String pagepath;//跳转小程序路径
    @Column(name = "wechat_id")
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    @Column(name = "template_id")
    public String getTemplateId() {
        return templateId;
    }
    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }
    @Column(name = "template_name")
    public String getTemplateName() {
        return templateName;
    }
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
    @Column(name = "scene")
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
    @Column(name = "scene_description")
    public String getSceneDescription() {
        return sceneDescription;
    }
    public void setSceneDescription(String sceneDescription) {
        this.sceneDescription = sceneDescription;
    }
    @Column(name = "first")
    public String getFirst() {
        return first;
    }
    public void setFirst(String first) {
        this.first = first;
    }
    @Column(name = "url")
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    @Column(name = "remark")
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    @Column(name = "keyword1")
    public String getKeyword1() {
        return keyword1;
    }
    public void setKeyword1(String keyword1) {
        this.keyword1 = keyword1;
    }
    @Column(name = "keyword2")
    public String getKeyword2() {
        return keyword2;
    }
    public void setKeyword2(String keyword2) {
        this.keyword2 = keyword2;
    }
    @Column(name = "keyword3")
    public String getKeyword3() {
        return keyword3;
    }
    public void setKeyword3(String keyword3) {
        this.keyword3 = keyword3;
    }
    @Column(name = "keyword4")
    public String getKeyword4() {
        return keyword4;
    }
    public void setKeyword4(String keyword4) {
        this.keyword4 = keyword4;
    }
    @Column(name = "keyword5")
    public String getKeyword5() {
        return keyword5;
    }
    public void setKeyword5(String keyword5) {
        this.keyword5 = keyword5;
    }
    @Column(name = "keyword6")
    public String getKeyword6() {
        return keyword6;
    }
    public void setKeyword6(String keyword6) {
        this.keyword6 = keyword6;
    }
    @Column(name = "keyword7")
    public String getKeyword7() {
        return keyword7;
    }
    public void setKeyword7(String keyword7) {
        this.keyword7 = keyword7;
    }
    @Column(name = "appid")
    public String getAppid() {
        return appid;
    }
    public void setAppid(String appid) {
        this.appid = appid;
    }
    @Column(name = "pagepath")
    public String getPagepath() {
        return pagepath;
    }
    public void setPagepath(String pagepath) {
        this.pagepath = pagepath;
    }
}

+ 10 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/PatientRehabilitationPlanDO.java

@ -30,6 +30,8 @@ public class PatientRehabilitationPlanDO extends UuidIdentityEntityWithOperator
    private Integer planType;//安排类型(1康复计划,2转社区医院,3转家庭病床)
    private Integer planType;//安排类型(1康复计划,2转社区医院,3转家庭病床)
    @Column(name = "service_package_id")
    @Column(name = "service_package_id")
    private String servicePackageId;//服务包id
    private String servicePackageId;//服务包id
    @Column(name = "status")
    private Integer status;//状态(0已中止,1进行中,2已完成)
    public String getSaasId() {
    public String getSaasId() {
        return saasId;
        return saasId;
@ -94,4 +96,12 @@ public class PatientRehabilitationPlanDO extends UuidIdentityEntityWithOperator
    public void setServicePackageId(String servicePackageId) {
    public void setServicePackageId(String servicePackageId) {
        this.servicePackageId = servicePackageId;
        this.servicePackageId = servicePackageId;
    }
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}
}

+ 11 - 11
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationDetailDO.java

@ -13,13 +13,13 @@ import java.util.Date;
 * Created by humingfen on 2018/8/15.
 * Created by humingfen on 2018/8/15.
 */
 */
@Entity
@Entity
@Table(name = "wlyy_rehabilitation_detail")
@Table(name = "wlyy_rehabilitation_plan_detail")
public class RehabilitationDetailDO extends UuidIdentityEntityWithOperator implements Serializable {
public class RehabilitationDetailDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    @Column(name = "saas_id")
    private String saasId;
    private String saasId;
    @Column(name = "program_id")
    private String programId;//居民康复套餐code
    @Column(name = "plan_id")
    private String planId;//居民康复套餐code
    @Column(name = "service_item_id")
    @Column(name = "service_item_id")
    private String serviceItemId;//服务项目id
    private String serviceItemId;//服务项目id
    @Column(name = "hospital")
    @Column(name = "hospital")
@ -33,9 +33,9 @@ public class RehabilitationDetailDO extends UuidIdentityEntityWithOperator imple
    @Column(name = "doctor_name")
    @Column(name = "doctor_name")
    private String doctorName;//计划完成者标识
    private String doctorName;//计划完成者标识
    @Column(name = "execute_time")
    @Column(name = "execute_time")
    private String executeTime;//服务项目执行时间
    private Date executeTime;//服务项目执行时间
    @Column(name = "status")
    @Column(name = "status")
    private Integer status;//状态(0未开始,1进行中,2已完成)
    private Integer status;//状态(0已中止,1进行中,2已完成)
    public String getSaasId() {
    public String getSaasId() {
        return saasId;
        return saasId;
@ -45,12 +45,12 @@ public class RehabilitationDetailDO extends UuidIdentityEntityWithOperator imple
        this.saasId = saasId;
        this.saasId = saasId;
    }
    }
    public String getProgramId() {
        return programId;
    public String getPlanId() {
        return planId;
    }
    }
    public void setProgramId(String programId) {
        this.programId = programId;
    public void setPlanId(String planId) {
        this.planId = planId;
    }
    }
    public String getServiceItemId() {
    public String getServiceItemId() {
@ -69,11 +69,11 @@ public class RehabilitationDetailDO extends UuidIdentityEntityWithOperator imple
        this.hospital = hospital;
        this.hospital = hospital;
    }
    }
    public String getExecuteTime() {
    public Date getExecuteTime() {
        return executeTime;
        return executeTime;
    }
    }
    public void setExecuteTime(String executeTime) {
    public void setExecuteTime(Date executeTime) {
        this.executeTime = executeTime;
        this.executeTime = executeTime;
    }
    }

+ 5 - 6
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationTemplateDetailDO.java

@ -19,7 +19,7 @@ public class RehabilitationTemplateDetailDO extends UuidIdentityEntityWithOperat
    @Column(name = "template_id")
    @Column(name = "template_id")
    private String templateId;//康复套餐模板id
    private String templateId;//康复套餐模板id
    @Column(name = "service_item_id")
    @Column(name = "service_item_id")
    private String serviceId;//服务项目id
    private String serviceItemId;//服务项目id
    public String getSaasId() {
    public String getSaasId() {
        return saasId;
        return saasId;
@ -37,12 +37,11 @@ public class RehabilitationTemplateDetailDO extends UuidIdentityEntityWithOperat
        this.templateId = templateId;
        this.templateId = templateId;
    }
    }
    public String getServiceId() {
        return serviceId;
    public String getServiceItemId() {
        return serviceItemId;
    }
    }
    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    public void setServiceItemId(String serviceItemId) {
        this.serviceItemId = serviceItemId;
    }
    }
}
}

+ 1 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/WechatRequestMapping.java

@ -66,6 +66,7 @@ public class WechatRequestMapping {
        public static final String api_getWxTemplates="/template/list";
        public static final String api_getWxTemplates="/template/list";
        public static final String api_getById="/template/{id}";
        public static final String api_getById="/template/{id}";
        public static final String api_sendTemplateMessage="/sendTemplateMessage";
        public static final String api_sendTemplateMessage="/sendTemplateMessage";
        public static final String api_test_template="/test_template";
        public static final String message_success_create="wxTemplate create success";
        public static final String message_success_create="wxTemplate create success";
        public static final String message_success_update="wxTemplate update success";
        public static final String message_success_update="wxTemplate update success";

+ 7 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/specialist/SpecialistMapping.java

@ -51,5 +51,12 @@ public class SpecialistMapping {
    public static class rehabilitation{
    public static class rehabilitation{
        public static final String findRehabilitationPlan = "/findRehabilitationPlan";
        public static final String findRehabilitationPlan = "/findRehabilitationPlan";
        public static final String createRehabilitationPlanTemplate = "/createRehabilitationPlanTemplate";
        public static final String createRehabilitationTemplateDetail = "/createRehabilitationTemplateDetail";
        public static final String findRehabilitationPlanTemplate = "/findRehabilitationPlanTemplate";
        public static final String findTemplateDetailByTemplateId = "/findTemplateDetailByTemplateId";
        public static final String updateRehabilitationTemplateDetail = "/updateRehabilitationTemplateDetail";
        public static final String createPatientRehabilitationPlan = "/createPatientRehabilitationPlan";
    }
    }
}
}

+ 12 - 0
common/common-util/pom.xml

@ -37,5 +37,17 @@
            <groupId>org.slf4j</groupId>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        </dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-util</artifactId>
        </dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-entity</artifactId>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>utils</artifactId> <!-- 此依赖包含大部分常用工具类 -->
        </dependency>
    </dependencies>
    </dependencies>
</project>
</project>

+ 0 - 23
common/common-util/src/main/java/com/yihu/jw/util/wechat/PushMsgTask.java

@ -1,23 +0,0 @@
package com.yihu.jw.util.wechat;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.concurrent.LinkedBlockingQueue;
/**
 * Created by Trick on 2018/8/20.
 */
@Component
public class PushMsgTask {
    private static Logger logger = LoggerFactory.getLogger(PushMsgTask.class);
    private static LinkedBlockingQueue<JSONObject> queue = new LinkedBlockingQueue<JSONObject>();
}

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

@ -0,0 +1,223 @@
package com.yihu.jw.util.wechat;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.entity.base.wx.*;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import com.yihu.utils.network.HttpUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
/**
 * 微信模板消息工具类
 * 调用putWxMsg 发送模板消息
 * 微信文档地址
 * https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1445241432
 * Created by Trick on 2018/8/21.
 */
@Component
public class WeixinMessagePushUtils {
    private static Logger logger = LoggerFactory.getLogger(WeixinMessagePushUtils.class);
    private static LinkedBlockingQueue<Map<String,Object>> queue = new LinkedBlockingQueue<Map<String,Object>>();
    public void putWxMsg(String accessToken,String opennid,WxTemplateConfigDO wxTemplateConfigDO){
        try {
            Map<String,Object> mes = new HashMap();
            if(StringUtils.isBlank(opennid)){
                logger.info("wechat queue put opennid is null ");
                return;
            }
            if(StringUtils.isBlank(accessToken)){
                logger.info("wechat queue put accessToken is null ");
                return;
            }
            mes.put("accessToken",accessToken);
            mes.put("openid",opennid);
            mes.put("wxTemplateConfig",wxTemplateConfigDO);
            queue.put(mes);
        }catch (Exception e){
            logger.info("wechat queue put error :",e);
        }
    }
    @PostConstruct
    private void run() {
        new Thread(new ConsumerTask()).start();
    }
    // 消费者
    class ConsumerTask implements Runnable {
        @Override
        public void run() {
            while (true) {
                try {
                    // 如果queue为空,则当前线程会堵塞,直到有新数据加入
                    Map<String,Object> mes = queue.take();
                    //发送微信模板消息
                    sendWeixinMessage(mes);
                }catch (Exception e){
                    logger.info("wechat ConsumerTask run:",e);
                }
            }
        }
    }
    /**
     * 发送微信模板消息
     * @param mes
     * @return
     */
    public boolean sendWeixinMessage(Map<String,Object> mes){
        WxTemplateConfigDO wxtemp = (WxTemplateConfigDO)mes.get("wxTemplateConfig");
        String token = (String)mes.get("accessToken");
        //发送微信模板地址
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
        //微信消息参数
        String params = getWxParam(mes);
        if(StringUtils.isBlank(params)){
            logger.info("wechat params is null");
            return false;
        }
        //发送微信模板消息
        String result = HttpUtil.sendPost(url, params);
        JSONObject jsonResult = new JSONObject(result);
        if (Integer.parseInt(jsonResult.get("errcode").toString()) == 0) {
            logger.info("wechat temp send success");
            return true;
        } else {
            logger.error("wechat temp send fail:"+result);
            return false;
        }
    }
    /**
     * 构造微信模板参数
     *
     * @param mes
     * @return
     */
    public String getWxParam(Map<String,Object> mes){
        try{
            String toUser = (String)mes.get("openid");
            //微信模板消息实体
            WxTemplateConfigDO wxtemp = (WxTemplateConfigDO)mes.get("wxTemplateConfig");
            //创建微信模板实体,设置参数及内容
            WechatTemplateDO wechatTemp = new WechatTemplateDO();
            //接收者的openid
            wechatTemp.setTouser(toUser);
            //设置模板ID
            wechatTemp.setTemplate_id(wxtemp.getTemplateId());
            //设置跳转路径
            if(StringUtils.isNotBlank(wxtemp.getUrl())){
                wechatTemp.setUrl(wxtemp.getUrl());
            }
            //设置小程序跳转
            if(StringUtils.isNotBlank(wxtemp.getAppid())){
                Miniprogram miniprogram = new Miniprogram();
                miniprogram.setAppid(wxtemp.getAppid());
                miniprogram.setPagepath(wxtemp.getPagepath());
                wechatTemp.setMiniprogram(miniprogram);
            }
            //配置微信模板内容
            setWechatTemplateData(wechatTemp,wxtemp);
            ObjectMapper mapper = new ObjectMapper();
            String strJson = mapper.writeValueAsString(wechatTemp);
            logger.info("--------wechat param json message --------:" + strJson);
            return strJson;
        }catch (Exception e){
            logger.info("--------wechat param json message --------:" + e);
        }
        return "";
    }
    /**
     * 设置微信模板内容
     * @param wechatTemp 微信待发送模板
     * @param wxtemp 读取数据配置
     */
    public void setWechatTemplateData(WechatTemplateDO wechatTemp,WxTemplateConfigDO wxtemp){
        //设置模板内容
        Map<String,WechatTemplateDataDO> data = new HashedMap();
        //设置头部
        WechatTemplateDataDO first = new WechatTemplateDataDO();
        first.setValue(wxtemp.getFirst());
        first.setColor("#000000");
        data.put("first",first);
        //设置备注
        WechatTemplateDataDO remark = new WechatTemplateDataDO();
        remark.setValue(wxtemp.getRemark());
        remark.setColor("#000000");
        data.put("remark",remark);
        //配置keyword,微信最多可配置7个项目
        //设置keyword1
        if(StringUtils.isNotBlank(wxtemp.getKeyword1())){
            WechatTemplateDataDO keyword1 = new WechatTemplateDataDO();
            keyword1.setValue(wxtemp.getRemark());
            keyword1.setColor("#000000");
            data.put("keyword1",keyword1);
        }
        //设置keyword2
        if(StringUtils.isNotBlank(wxtemp.getKeyword2())){
            WechatTemplateDataDO keyword2 = new WechatTemplateDataDO();
            keyword2.setValue(wxtemp.getKeyword2());
            keyword2.setColor("#000000");
            data.put("keyword2",keyword2);
        }
        //设置keyword3
        if(StringUtils.isNotBlank(wxtemp.getKeyword3())){
            WechatTemplateDataDO keyword3 = new WechatTemplateDataDO();
            keyword3.setValue(wxtemp.getKeyword3());
            keyword3.setColor("#000000");
            data.put("keyword3",keyword3);
        }
        //设置keyword4
        if(StringUtils.isNotBlank(wxtemp.getKeyword4())){
            WechatTemplateDataDO keyword4 = new WechatTemplateDataDO();
            keyword4.setValue(wxtemp.getKeyword4());
            keyword4.setColor("#000000");
            data.put("keyword4",keyword4);
        }
        //设置keyword5
        if(StringUtils.isNotBlank(wxtemp.getKeyword5())){
            WechatTemplateDataDO keyword5 = new WechatTemplateDataDO();
            keyword5.setValue(wxtemp.getKeyword5());
            keyword5.setColor("#000000");
            data.put("keyword5",keyword5);
        }
        //设置keyword6
        if(StringUtils.isNotBlank(wxtemp.getKeyword6())){
            WechatTemplateDataDO keyword6 = new WechatTemplateDataDO();
            keyword6.setValue(wxtemp.getKeyword6());
            keyword6.setColor("#000000");
            data.put("keyword1",keyword6);
        }
        //设置keyword7
        if(StringUtils.isNotBlank(wxtemp.getKeyword7())){
            WechatTemplateDataDO keyword7 = new WechatTemplateDataDO();
            keyword7.setValue(wxtemp.getKeyword7());
            keyword7.setColor("#000000");
            data.put("keyword7",keyword7);
        }
        //设置微信内容,头部,备注,项目参数
        wechatTemp.setData(data);
    }
}

+ 171 - 0
common/common-util/src/main/java/com/yihu/jw/util/wechat/wxhttp/HttpUtil.java

@ -0,0 +1,171 @@
package com.yihu.jw.util.wechat.wxhttp;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
/**
 * Created by Trick on 2018/8/21.
 */
public class HttpUtil {
    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
    /**
     * 向指定URL发送GET方法的请求
     *
     * @param url
     *            发送请求的URL
     * @param param
     *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
     * @return URL 所代表远程资源的响应结果
     */
    public static String sendGet(String url, String param) {
        String result = "";
        BufferedReader in = null;
        try {
            String urlNameString = url + "?" + param;
            URL realUrl = new URL(urlNameString);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            // 设置通用的请求属性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 建立实际的连接
            connection.connect();
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }
    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url
     *            发送请求的 URL带上参数
     * @param param
     *            POST参数。
     * @return 所代表远程资源的响应结果
     */
    public static String sendPost(String url, String param) {
        StringBuffer buffer = new StringBuffer();
        PrintWriter out = null;
        BufferedReader in = null;
        HttpURLConnection conn = null;
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            conn = (HttpURLConnection) realUrl.openConnection();
            conn.setRequestMethod("POST");
            conn.setConnectTimeout(5000);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestProperty("Content-Type", "application/text");
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            osw.write(param.toString());
            osw.flush();
            // 读取返回内容
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String temp;
            while ((temp = br.readLine()) != null) {
                buffer.append(temp);
                buffer.append("\n");
            }
        } catch (Exception e) {
            logger.error("push message error:", e);
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return buffer.toString();
    }
    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url 发送请求的 URL带上参数
     * @param param POST参数。
     * @param charset 编码格式
     * @return 所代表远程资源的响应结果
     */
    public static String sendPost(String url, String param, String charset) {
        StringBuffer buffer = new StringBuffer();
        PrintWriter out = null;
        BufferedReader in = null;
        HttpURLConnection conn = null;
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            conn = (HttpURLConnection) realUrl.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestProperty("Content-Type", "application/text");
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream(), charset);
            osw.write(param.toString());
            osw.flush();
            // 读取返回内容
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));
            String temp;
            while ((temp = br.readLine()) != null) {
                buffer.append(temp);
                buffer.append("\n");
            }
        } catch (Exception e) {
            logger.error("push message error:", e);
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return buffer.toString();
    }
}

+ 5 - 5
svr/svr-base/src/main/java/com/yihu/jw/business/wx/controller/WechatCoreController.java

@ -174,9 +174,9 @@ public class WechatCoreController extends EnvelopRestEndpoint {
        return strDigest;
        return strDigest;
    }
    }
//    @RequestMapping(value ="test", method = RequestMethod.POST)
//    @ResponseBody
//    public String  testProcess() throws Exception{
//        return wechatCoreService.testProcess();
//    }
    @RequestMapping(value ="test", method = RequestMethod.POST)
    @ResponseBody
    public String  testProcess() throws Exception{
        return wechatCoreService.testProcess();
    }
}
}

+ 32 - 42
svr/svr-base/src/main/java/com/yihu/jw/business/wx/controller/WxTemplateController.java

@ -1,44 +1,34 @@
//package com.yihu.jw.business.wx.controller;
//
//import com.yihu.jw.business.wx.WechatResponse;
//import com.yihu.jw.base.wx.Miniprogram;
//import com.yihu.jw.base.wx.WxTemplateDO;
//import com.yihu.jw.base.wx.WxWechatDO;
//import com.yihu.jw.business.wx.service.WechatService;
//import com.yihu.jw.business.wx.service.WxTemplateService;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.restmodel.common.Envelop;
//import com.yihu.jw.restmodel.common.EnvelopRestController;
//import com.yihu.jw.restmodel.base.wx.WxTemplateVO;
//import com.yihu.jw.restmodel.base.wx.WxWechatVO;
//import com.yihu.jw.rm.base.WechatRequestMapping;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import org.apache.commons.lang.StringUtils;
//import org.json.JSONObject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by Administrator on 2017/5/19 0019.
// */
//@RestController
//@RequestMapping(WechatRequestMapping.api_common)
//@Api(value = "微信模版相关操作", description = "微信模版相关操作")
//public class WxTemplateController extends EnvelopRestController {
//    @Autowired
//    private WxTemplateService wxTemplateService;
//
//    @Autowired
//    private WechatService wechatService;
//
package com.yihu.jw.business.wx.controller;
import com.yihu.jw.business.wx.service.WxTemplateService;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.WechatRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by Administrator on 2017/5/19 0019.
 */
@RestController
@RequestMapping(WechatRequestMapping.api_common)
@Api(value = "微信模版相关操作", description = "微信模版相关操作")
public class WxTemplateController extends EnvelopRestEndpoint {
    @Autowired
    private WxTemplateService wxTemplateService;
    @PostMapping(value = WechatRequestMapping.WxTemplate.api_test_template, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "测试发送微信模板", notes = "测试发送微信模板")
    public String sendWeTempMesTest(String wechatId,String openid)throws Exception{
        return wxTemplateService.sendWeTempMesTest(wechatId,openid);
    }
//    @PostMapping(value = WechatRequestMapping.WxTemplate.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @PostMapping(value = WechatRequestMapping.WxTemplate.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ApiOperation(value = "创建微信模版", notes = "创建微信模版")
//    @ApiOperation(value = "创建微信模版", notes = "创建微信模版")
//    public Envelop createWxTemplate(
//    public Envelop createWxTemplate(
@ -185,4 +175,4 @@
//            return Envelop.getSuccess("error", exception);
//            return Envelop.getSuccess("error", exception);
//        }
//        }
//    }
//    }
//}
}

+ 15 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxTemplateConfigDao.java

@ -0,0 +1,15 @@
package com.yihu.jw.business.wx.dao;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2018/8/21.
 */
public interface WxTemplateConfigDao extends PagingAndSortingRepository<WxTemplateConfigDO, String>, JpaSpecificationExecutor<WxTemplateConfigDO> {
    WxTemplateConfigDO findByWechatIdAndTemplateNameAndScene(String wechatId,String templateName,String scene);
}

+ 47 - 6
svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WechatCoreService.java

@ -88,12 +88,11 @@ public class WechatCoreService {
        String returnStr = "";
        String returnStr = "";
        Map<String, String> message = new HashMap();
        Map<String, String> message = new HashMap();
        message.put("Content","1");
        message.put("CreateTime","1534486843");
        message.put("Event","subscribe");
        message.put("CreateTime","1534495338");
        message.put("ToUserName","gh_73959f6e996b");
        message.put("ToUserName","gh_73959f6e996b");
        message.put("FromUserName","oVH-2uJdhNrcAMt0Jhp3PMarDdaM");
        message.put("FromUserName","oVH-2uJdhNrcAMt0Jhp3PMarDdaM");
        message.put("MsgType","text");
        message.put("MsgId","6590570807493983575");
        message.put("MsgType","event");
        returnStr = messageProcess(message);
        returnStr = messageProcess(message);
@ -165,7 +164,30 @@ public class WechatCoreService {
        return result;
        return result;
    }
    }
    public String scanEventProcess(Map<String, String> message){
    /**
     * 扫描二维码事件
     * 1. 用户未关注时,进行关注后的事件推送
     * <xml><ToUserName>< ![CDATA[toUser] ]></ToUserName><FromUserName>< ![CDATA[FromUser] ]></FromUserName><CreateTime>123456789</CreateTime><MsgType>< ![CDATA[event] ]></MsgType><Event>< ![CDATA[subscribe] ]></Event><EventKey>< ![CDATA[qrscene_123123] ]></EventKey><Ticket>< ![CDATA[TICKET] ]></Ticket></xml>
     * 2. 用户已关注时的事件推送
     * <xml> <ToUserName>< ![CDATA[toUser] ]></ToUserName> <FromUserName>< ![CDATA[FromUser] ]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType>< ![CDATA[event] ]></MsgType> <Event>< ![CDATA[SCAN] ]></Event> <EventKey>< ![CDATA[SCENE_VALUE] ]></EventKey> <Ticket>< ![CDATA[TICKET] ]></Ticket> </xml>
     * @param message
     * @return
     */
    public String scanEventProcess(Map<String, String> message) throws Exception{
        //获取原始id
        String toUserName = message.get("ToUserName");
        //如果为已经关注,EventKey值为带参二维码值,如果是未关注 qrscene_为前缀,后面为二维码的参数值
        String eventKey = message.get("EventKey");
        //查询需要对应匹配的带参二维码事件值
        List<WxReplySceneDO> scenes = wxReplySceneDao.findByAppOriginIdAndMsgTypeAndEventAndStatus(toUserName,WeiXinMessageUtils.REQ_MESSAGE_TYPE_EVENT,WeiXinMessageUtils.EVENT_TYPE_SCAN,1);
        if(scenes!=null&&scenes.size()>0){
            for(WxReplySceneDO scene:scenes){
                //判断带参二维码中前缀是否包该场景值
                if(StringUtils.isNotBlank(scene.getScene())&&eventKey.indexOf(scene.getScene())!=-1){
                    return getGraphicXMl(scene.getScene(),scene.getWechatId(),message);
                }
            }
        }
        return "";
        return "";
    }
    }
@ -176,8 +198,9 @@ public class WechatCoreService {
     * @return
     * @return
     */
     */
    public String subscribeEventProcess(Map<String, String> message) throws Exception{
    public String subscribeEventProcess(Map<String, String> message) throws Exception{
        //获取原始id
        String toUserName = message.get("ToUserName");
        String toUserName = message.get("ToUserName");
        List<WxReplySceneDO> scenes = wxReplySceneDao.findByAppOriginIdAndMsgTypeAndEventAndStatus(toUserName,WeiXinMessageUtils.RESP_MESSAGE_TYPE_TEXT,WeiXinMessageUtils.EVENT_TYPE_SUBSCRIBE,1);
        List<WxReplySceneDO> scenes = wxReplySceneDao.findByAppOriginIdAndMsgTypeAndEventAndStatus(toUserName,WeiXinMessageUtils.REQ_MESSAGE_TYPE_EVENT,WeiXinMessageUtils.EVENT_TYPE_SUBSCRIBE,1);
        if(scenes!=null&&scenes.size()>0){
        if(scenes!=null&&scenes.size()>0){
            WxReplySceneDO scene = scenes.get(0);
            WxReplySceneDO scene = scenes.get(0);
            if(StringUtils.isNotBlank(scene.getScene())){
            if(StringUtils.isNotBlank(scene.getScene())){
@ -187,10 +210,20 @@ public class WechatCoreService {
        return "";
        return "";
    }
    }
    /**
     * 取消关注事件,根据需求开发
     * @param message
     * @return
     */
    public String unsubscribeEventProcess(Map<String, String> message){
    public String unsubscribeEventProcess(Map<String, String> message){
        return "";
        return "";
    }
    }
    /**
     * 点击事件,根据需求开发
     * @param message
     * @return
     */
    public String clickProcess(Map<String, String> message){
    public String clickProcess(Map<String, String> message){
        return "";
        return "";
    }
    }
@ -232,6 +265,7 @@ public class WechatCoreService {
    public String getGraphicXMl(String secene,String wxId,Map<String, String> message)throws Exception{
    public String getGraphicXMl(String secene,String wxId,Map<String, String> message)throws Exception{
        List<Map<String,Object>> group = getGraphicGroupByScene(secene,wxId);
        List<Map<String,Object>> group = getGraphicGroupByScene(secene,wxId);
        String result = "";
        String result = "";
        String eventKey = message.get("EventKey");
        if(group!=null&&group.size()>0){
        if(group!=null&&group.size()>0){
            List<Map<String, String>> articles = new ArrayList<>();
            List<Map<String, String>> articles = new ArrayList<>();
@ -251,6 +285,13 @@ public class WechatCoreService {
                if(url.indexOf("{appId}")!=-1){
                if(url.indexOf("{appId}")!=-1){
                    url = url.replace("{appId}",appId);
                    url = url.replace("{appId}",appId);
                }
                }
                //传递带参二维码给前端页面
                if(url.indexOf("{EventKey}")!=-1){
                    if(eventKey.indexOf("qrscene_")!=-1){
                        eventKey = eventKey.replace("qrscene_","");
                    }
                    url = url.replace("{EventKey}",eventKey);
                }
                article.put("Url", url);
                article.put("Url", url);
                article.put("Title", title);
                article.put("Title", title);

+ 2 - 2
svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WxAccessTokenService.java

@ -74,7 +74,7 @@ public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAcce
            params.put("appid", appId);
            params.put("appid", appId);
            params.put("secret", appSecret);
            params.put("secret", appSecret);
            String result = HttpUtils.doGet(token_url, params).getContent();
            String result = HttpUtils.doGet(token_url, params).getContent();
            logger.info("--------------微信返回结果:"+result+"---------------");
            logger.info("--------------wechat token return :"+result+"---------------");
            JSONObject json = new JSONObject(result);
            JSONObject json = new JSONObject(result);
            if (json.has("access_token")) {
            if (json.has("access_token")) {
                String token = json.get("access_token").toString();
                String token = json.get("access_token").toString();
@ -132,7 +132,7 @@ public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAcce
            params.put("appid", appId);
            params.put("appid", appId);
            params.put("secret", appSecret);
            params.put("secret", appSecret);
            String result = HttpUtils.doGet(token_url, params).getContent();
            String result = HttpUtils.doGet(token_url, params).getContent();
            logger.info("--------------微信返回结果:"+result+"---------------");
            logger.info("--------------wechat token return:"+result+"---------------");
            JSONObject json = new JSONObject(result);
            JSONObject json = new JSONObject(result);
            if (json.has("access_token")) {
            if (json.has("access_token")) {
                String token = json.get("access_token").toString();
                String token = json.get("access_token").toString();

+ 37 - 38
svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WxTemplateService.java

@ -1,40 +1,39 @@
//package com.yihu.jw.business.wx.service;
//
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.yihu.jw.base.wx.*;
//import com.yihu.jw.business.wx.dao.WxTemplateDao;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.base.mysql.query.BaseJpaService;
//import com.yihu.jw.rm.base.WechatRequestMapping;
//import com.yihu.jw.util.HttpUtil;
//import org.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.util.StringUtils;
//
//import java.util.*;
//
///**
// * Created by Administrator on 2017/5/19 0019.
// */
//@Service
//public class WxTemplateService extends BaseJpaService<WxTemplateDO, WxTemplateDao> {
//
//    private Logger logger= LoggerFactory.getLogger(WxTemplateService.class);
//
//    @Autowired
//    private WxTemplateDao wxTemplateDao;
//
//    @Autowired
//    private WxAccessTokenService wxAccessTokenService;
//
//    @Autowired
//    private WechatService wechatService;
//
package com.yihu.jw.business.wx.service;
import com.yihu.jw.business.wx.dao.WxTemplateConfigDao;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created by Administrator on 2017/5/19 0019.
 */
@Service
public class WxTemplateService {
    private Logger logger= LoggerFactory.getLogger(WxTemplateService.class);
    @Autowired
    private WxTemplateConfigDao wxTemplateConfigDao;
    @Autowired
    private WxAccessTokenService wxAccessTokenService;
    @Autowired
    private WeixinMessagePushUtils weixinMessagePushUtils;
    public String sendWeTempMesTest(String wechatId,String openid)throws Exception{
        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndScene(wechatId,"template_survey","test");
        config.setFirst(config.getFirst().replace("key1","小明"));
        config.setKeyword2("2018-08-21");
        weixinMessagePushUtils.putWxMsg(wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken(),openid,config);
        return "success";
    }
//    public WxTemplateDO createWxTemplate(WxTemplateDO wxTemplate) {
//    public WxTemplateDO createWxTemplate(WxTemplateDO wxTemplate) {
//        if (StringUtils.isEmpty(wxTemplate.getTemplateId())) {
//        if (StringUtils.isEmpty(wxTemplate.getTemplateId())) {
//            throw new ApiException(WechatRequestMapping.WxTemplate.message_fail_templateid_is_null, ExceptionCode.common_error_params_code);
//            throw new ApiException(WechatRequestMapping.WxTemplate.message_fail_templateid_is_null, ExceptionCode.common_error_params_code);
@ -154,4 +153,4 @@
//    public List<WxTemplateDO> findByWxId(String code) {
//    public List<WxTemplateDO> findByWxId(String code) {
//        return wxTemplateDao.findByWxId(code);
//        return wxTemplateDao.findByWxId(code);
//    }
//    }
//}
}

+ 1 - 1
svr/svr-base/src/main/resources/bootstrap.yml

@ -29,4 +29,4 @@ spring:
  cloud:
  cloud:
    config:
    config:
      uri: ${wlyy.pring.config.uri:http://172.17.110.212:1221}
      uri: ${wlyy.pring.config.uri:http://172.17.110.212:1221}
      label: ${wlyy.spring.config.label:jwprod}
      label: ${wlyy.spring.config.label:jwprod}

+ 4 - 2
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/SpecialistController.java

@ -205,9 +205,11 @@ public class SpecialistController extends EnvelopRestEndpoint {
    @ApiOperation(value = "专科医生审核")
    @ApiOperation(value = "专科医生审核")
    public MixEnvelop<Boolean, Boolean> agreeSpecialistTeam(@ApiParam(name = "state", value = "状态0为拒绝,1为同意") @RequestParam(required = true)String state,
    public MixEnvelop<Boolean, Boolean> agreeSpecialistTeam(@ApiParam(name = "state", value = "状态0为拒绝,1为同意") @RequestParam(required = true)String state,
                                                   @ApiParam(name = "relationCode", value = "关联code") @RequestParam(required = true)String relationCode,
                                                   @ApiParam(name = "relationCode", value = "关联code") @RequestParam(required = true)String relationCode,
                                                   @ApiParam(name = "remark", value = "审核失败原因") @RequestParam(required = false)String remark) {
                                                   @ApiParam(name = "remark", value = "审核失败原因") @RequestParam(required = false)String remark,
                                                   @ApiParam(name = "health_assistant", value = "计管医生CODE") @RequestParam(required = false)String health_assistant,
                                                   @ApiParam(name = "health_assistant_name", value = "计管医生名称") @RequestParam(required = false)String health_assistant_name) {
        try {
        try {
            return specialistService.agreeSpecialistTeam(state,relationCode,remark);
            return specialistService.agreeSpecialistTeam(state,relationCode,remark,health_assistant,health_assistant_name);
        }catch (Exception e){
        }catch (Exception e){
            e.printStackTrace();
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            tracer.getCurrentSpan().logEvent(e.getMessage());

+ 159 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/rehabilitation/RehabilitationPlanController.java

@ -0,0 +1,159 @@
package com.yihu.jw.controller.rehabilitation;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationPlanTemplateDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationTemplateDetailDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.service.rehabilitation.RehabilitationPlanService;
import com.yihu.jw.util.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by humingfen on 2018/8/17.
 */
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "康复服务套餐管理相关操作", description = "康复服务套餐管理相关操作")
public class RehabilitationPlanController extends EnvelopRestEndpoint {
    @Autowired
    private RehabilitationPlanService rehabilitationPlanService;
    @Autowired
    private Tracer tracer;
    /******************************** 康复服务套餐模板 ****************************************/
    @PostMapping(value = SpecialistMapping.rehabilitation.createRehabilitationPlanTemplate)
    @ApiOperation(value = "康复服务套餐模板创建")
    public MixEnvelop<String, String> createRehabilitationPlanTemplate(@ApiParam(name = "rehabilitationTemplate", value = "实体JSON")
                                                             @RequestParam(value = "rehabilitationTemplate", required = true)String rehabilitationTemplate){
        try {
            RehabilitationPlanTemplateDO templateDO = toEntity(rehabilitationTemplate, RehabilitationPlanTemplateDO.class);
            return rehabilitationPlanService.createRehabilitationTemplate(templateDO);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.rehabilitation.createRehabilitationTemplateDetail)
    @ApiOperation(value = "康复服务套餐模板明细创建")
    public MixEnvelop<Boolean, Boolean> createRehabilitationTemplateDetail(@ApiParam(name = "rehabilitationTemplateDetail", value = "实体JSON")
                                                             @RequestParam(value = "rehabilitationTemplateDetail", required = true)String rehabilitationTemplateDetail){
        try {
            List<RehabilitationTemplateDetailDO> details = new ObjectMapper().readValue(rehabilitationTemplateDetail, new TypeReference<List<RehabilitationTemplateDetailDO>>(){});
            return rehabilitationPlanService.createRehabilitationTemplateDetail(details);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.findRehabilitationPlanTemplate)
    @ApiOperation(value = "获取康复服务套餐模板列表")
    public MixEnvelop<RehabilitationPlanTemplateDO, RehabilitationPlanTemplateDO> findRehabilitationPlanTemplate(@ApiParam(name = "adminTeamCode", value = "行政团队id")
                                                                                   @RequestParam(value = "adminTeamCode", required = true)Integer adminTeamCode,
                                                                               @ApiParam(name = "page", value = "第几页,从1开始")
                                                                              @RequestParam(value = "page", required = false)Integer page,
                                                                              @ApiParam(name = "size", value = ",每页分页大小")
                                                                              @RequestParam(value = "size", required = false)Integer size){
        try {
            return rehabilitationPlanService.findRehabilitationPlanTemplate(adminTeamCode, page, size);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.findTemplateDetailByTemplateId)
    @ApiOperation(value = "获取康复服务套餐模板明细")
    public MixEnvelop<RehabilitationTemplateDetailDO, RehabilitationTemplateDetailDO> findTemplateDetailByTemplateId(@ApiParam(name = "templateId", value = "模板id")
                                                                                      @RequestParam(value = "templateId", required = true)String templateId){
        try {
            return rehabilitationPlanService.findTemplateDetailByTemplateId(templateId);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.rehabilitation.updateRehabilitationTemplateDetail)
    @ApiOperation(value = "编辑康复服务套餐模板明细")
    public MixEnvelop<Boolean, Boolean> updateRehabilitationTemplateDetail(@ApiParam(name = "rehabilitationTemplateDetail", value = "实体JSON")
                                                                           @RequestParam(value = "rehabilitationTemplateDetail", required = true)String rehabilitationTemplateDetail){
        try {
            List<RehabilitationTemplateDetailDO> details = new ObjectMapper().readValue(rehabilitationTemplateDetail, new TypeReference<List<RehabilitationTemplateDetailDO>>(){});
            return rehabilitationPlanService.updateRehabilitationTemplateDetail(details);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /******************************** 居民康复计划 ***************************************/
    @PostMapping(value = SpecialistMapping.rehabilitation.createPatientRehabilitationPlan)
    @ApiOperation(value = "居民康复服务套餐创建")
    public MixEnvelop<String, String> createPatientRehabilitationPlan(@ApiParam(name = "rehabilitationPlan", value = "实体JSON")
                                                                       @RequestParam(value = "rehabilitationPlan", required = true)String rehabilitationPlan){
        try {
            JSONObject json = new JSONObject(rehabilitationPlan);
            JSONArray array = new JSONArray();
            for(Object planDetail : json.getJSONArray("detail")) {
                JSONObject j = (JSONObject)planDetail;
                String executeTime = j.get("executeTime").toString();
                String[] result = null;
                if(executeTime.contains(",")){
                    result = executeTime.split(",");
                }else {
                    result = new String[1];
                    result[0] = executeTime;
                }
                int len =  result.length;
                while(len > 0){
                    len --;
                    JSONObject temp = new JSONObject(j.toString());
                    temp.put("executeTime", result[len]);
                    temp.put("createUser", json.get("createUser"));
                    temp.put("createUserName", json.get("createUserName"));
                    array.put(temp);
                }
            }
            String planDetails = array.toString();
            ObjectMapper object = new ObjectMapper();
            object.setDateFormat(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"));
            List<RehabilitationDetailDO> details = object.readValue(planDetails, new TypeReference<List<RehabilitationDetailDO>>(){});
            PatientRehabilitationPlanDO planDO = toEntity(rehabilitationPlan, PatientRehabilitationPlanDO.class);
            planDO = rehabilitationPlanService.createPatientRehabilitationPlan(planDO);
            details = rehabilitationPlanService.createRehabilitationDetail(details, planDO.getId());
            return MixEnvelop.getSuccess(SpecialistMapping.api_success);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 14 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/rehabilitation/RehabilitationPlanTemplateDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.dao.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationPlanTemplateDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface RehabilitationPlanTemplateDao extends PagingAndSortingRepository<RehabilitationPlanTemplateDO, Long>,JpaSpecificationExecutor<RehabilitationPlanTemplateDO> {
    @Query("select t from RehabilitationPlanTemplateDO t where t.adminTeamCode = ?1 ORDER BY t.createTime DESC ")
    List<RehabilitationPlanTemplateDO> findByAdminTeamCode(Integer adminTeamCode);
}

+ 14 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/rehabilitation/RehabilitationTemplateDetailDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.dao.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationTemplateDetailDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface RehabilitationTemplateDetailDao extends PagingAndSortingRepository<RehabilitationTemplateDetailDO, Long>,JpaSpecificationExecutor<RehabilitationTemplateDetailDO> {
    List<RehabilitationTemplateDetailDO> findTemplateDetailByTemplateId(String templateId);
    void deleteByTemplateId(String templateId);
}

+ 27 - 2
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/SpecialistService.java

@ -180,6 +180,8 @@ public class SpecialistService{
    public MixEnvelop<PatientLabelVO, PatientLabelVO> getPatientByLabel(String doctor, String labelType, String labelCode, Integer page, Integer size){
    public MixEnvelop<PatientLabelVO, PatientLabelVO> getPatientByLabel(String doctor, String labelType, String labelCode, Integer page, Integer size){
    
    
        String sql="SELECT " +
        String sql="SELECT " +
                " p. NAME, " +
                " p. NAME, " +
                " p. CODE, " +
                " p. CODE, " +
@ -227,6 +229,27 @@ public class SpecialistService{
                " ) h ON h.patient = lb.patient " +
                " ) h ON h.patient = lb.patient " +
                " WHERE s.doctor ='"+doctor+"' AND s.status >=0  AND s.sign_status >0"+
                " WHERE s.doctor ='"+doctor+"' AND s.status >=0  AND s.sign_status >0"+
                " LIMIT "+(page-1)*size+","+size;
                " LIMIT "+(page-1)*size+","+size;
        
        if("7".equals(labelType)){
            sql = "SELECT " +
                    "c.CODE," +
                    "c.NAME," +
                    "c.sex," +
                    "IFNULL(YEAR (from_days(datediff(now(),c.birthday))),'未知') age," +
                    "c.photo,b.disease AS label," +
                    "b.disease_name AS labelName," +
                    "d.label_name AS health," +
                    "d.label AS healthcode," +
                    "a.health_assistant AS healthAssistant," +
                    "a.health_assistant_name AS healthAssistantName " +
                    "FROM wlyy_specialist.wlyy_specialist_patient_relation a " +
                    "JOIN "+basedb+".wlyy_patient_disease_server b ON a.patient=b.patient AND b.disease=4 " +
                    "JOIN "+basedb+".wlyy_patient c ON a.patient=c.CODE " +
                    "LEFT JOIN "+basedb+".wlyy_sign_patient_label_info d ON a.patient=d.patient AND d.label_type=8 AND d.`status`=1" +
                    " WHERE a.sign_status> 0 AND a.`status`>=0 AND a.doctor='"+doctor+"'"+
                    " LIMIT "+(page-1)*size+","+size;
        }
        List<PatientLabelVO> PatientLabelVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientLabelVO.class));
        List<PatientLabelVO> PatientLabelVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientLabelVO.class));
@ -462,7 +485,7 @@ public class SpecialistService{
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,relationDO.getId());
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,relationDO.getId());
    }
    }
    public MixEnvelop<Boolean, Boolean> agreeSpecialistTeam(String state, String relationCode, String remark){
    public MixEnvelop<Boolean, Boolean> agreeSpecialistTeam(String state, String relationCode, String remark,String health_assistant,String health_assistant_name){
        SpecialistPatientRelationDO relation = specialistPatientRelationDao.findOne(relationCode);
        SpecialistPatientRelationDO relation = specialistPatientRelationDao.findOne(relationCode);
@ -473,6 +496,8 @@ public class SpecialistService{
            specialistPatientRelationDao.save(relation);
            specialistPatientRelationDao.save(relation);
        }else{
        }else{
            relation.setSignStatus("1");
            relation.setSignStatus("1");
            relation.setHealthAssistant(health_assistant);
            relation.setHealthAssistant(health_assistant_name);
            specialistPatientRelationDao.save(relation);
            specialistPatientRelationDao.save(relation);
        }
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,relation);
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,relation);
@ -493,7 +518,7 @@ public class SpecialistService{
                " t.id As teamCode, " +
                " t.id As teamCode, " +
                " r.create_time AS createTime," +
                " r.create_time AS createTime," +
                " r.status," +
                " r.status," +
                " r.sign_status AS signStatus  " +
                " r.sign_status AS signStatus,  " +
                " r.team_code AS teamCode  " +
                " r.team_code AS teamCode  " +
                " FROM " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " wlyy_specialist_patient_relation r " +

+ 98 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/rehabilitation/RehabilitationPlanService.java

@ -0,0 +1,98 @@
package com.yihu.jw.service.rehabilitation;
import com.yihu.jw.dao.rehabilitation.PatientRehabilitationPlanDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationDetailDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationPlanTemplateDao;
import com.yihu.jw.dao.rehabilitation.RehabilitationTemplateDetailDao;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationPlanTemplateDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationTemplateDetailDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
 * Created by humingfen on 2018/8/17.
 */
@Service
@Transactional
public class RehabilitationPlanService {
    @Autowired
    private RehabilitationPlanTemplateDao templateDao;
    @Autowired
    private RehabilitationTemplateDetailDao templateDetailDao;
    @Autowired
    private PatientRehabilitationPlanDao patientRehabilitationPlanDao;
    @Autowired
    private RehabilitationDetailDao rehabilitationDetailDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    public MixEnvelop<String, String> createRehabilitationTemplate(RehabilitationPlanTemplateDO templateDO) {
        templateDO.setCreateTime(new Date());
        templateDO = templateDao.save(templateDO);
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,templateDO.getId());
    }
    public MixEnvelop<Boolean, Boolean> createRehabilitationTemplateDetail(List<RehabilitationTemplateDetailDO> details) {
        for(RehabilitationTemplateDetailDO detail : details){
            detail.setCreateTime(new Date());
            templateDetailDao.save(detail);
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,true);
    }
    public MixEnvelop<Boolean,Boolean> updateRehabilitationTemplateDetail(List<RehabilitationTemplateDetailDO> details) {
        String templateId = details.get(0).getTemplateId();
        if(templateId != null && templateId.length() > 0){
            templateDetailDao.deleteByTemplateId(templateId);
        }
        for(RehabilitationTemplateDetailDO detail : details){
            detail.setCreateTime(new Date());
            templateDetailDao.save(detail);
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,true);
    }
    public MixEnvelop<RehabilitationPlanTemplateDO, RehabilitationPlanTemplateDO> findRehabilitationPlanTemplate(Integer adminTeamCode, Integer page, Integer size) {
        if(page != null && size != null){
            String sql = "select * from wlyy_rehabilitation_plan_template t where t.admin_team_code = '" + adminTeamCode + "' ORDER BY t.create_time DESC LIMIT "+(page-1)*size+","+size;
            List<RehabilitationPlanTemplateDO> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper(RehabilitationPlanTemplateDO.class));
            String countSql = "select count(1) from wlyy_rehabilitation_plan_template t where t.admin_team_code = '" + adminTeamCode + "'";
            Long count = jdbcTemplate.queryForObject(countSql, Long.class);
            return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,list,page,size,count);
        }else {
            List<RehabilitationPlanTemplateDO> list = templateDao.findByAdminTeamCode(adminTeamCode);
            return MixEnvelop.getSuccess(SpecialistMapping.api_success,list, list.size());
        }
    }
    public MixEnvelop<RehabilitationTemplateDetailDO, RehabilitationTemplateDetailDO> findTemplateDetailByTemplateId(String templateId) {
        List<RehabilitationTemplateDetailDO> list = templateDetailDao.findTemplateDetailByTemplateId(templateId);
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,list, list.size());
    }
    public PatientRehabilitationPlanDO createPatientRehabilitationPlan(PatientRehabilitationPlanDO planDO) {
        planDO.setCreateTime(new Date());
        planDO.setStatus(1);
        return patientRehabilitationPlanDao.save(planDO);
    }
    public List<RehabilitationDetailDO> createRehabilitationDetail(List<RehabilitationDetailDO> details, String planId) {
        for(RehabilitationDetailDO detail : details) {
            detail.setPlanId(planId);
            detail.setStatus(1);
        }
        return (List<RehabilitationDetailDO>)rehabilitationDetailDao.save(details);
    }
}