Bladeren bron

代码修改

chenweida 7 jaren geleden
bovenliggende
commit
93f026d636
20 gewijzigde bestanden met toevoegingen van 701 en 132 verwijderingen
  1. 9 0
      common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticlePatient.java
  2. 79 0
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/HttpController.java
  3. 170 0
      patient-co/patient-co-statistics-es/doc/es/QuartzJobConfig.java
  4. 127 0
      patient-co/patient-co-statistics-es/doc/es/QuartzJobConfig1.java
  5. 1 1
      patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/dao/ConsultTeamDao.java
  6. 5 5
      patient-co/patient-co-statistics/pom.xml
  7. 40 40
      patient-co/patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/config/WebSecurityConfig.java
  8. 8 0
      patient-co/patient-co-wlyy-job/pom.xml
  9. 35 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/config/RedisConfig.java
  10. 105 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/redis/HealthAricleListener.java
  11. 10 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/redis/RedisQueueListener.java
  12. 4 0
      patient-co/patient-co-wlyy/doc/技术文档/es/统计新增索引.txt
  13. 9 0
      patient-co/patient-co-wlyy/pom.xml
  14. 31 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/ActiveMQProduceConfig.java
  15. 9 5
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/GateWayAOP.java
  16. 30 65
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcEduArticleController.java
  17. 0 8
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/listener/HealthAricleListener.java
  18. 5 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/service/GcEduArticleService.java
  19. 12 1
      patient-co/patient-co-wlyy/src/main/resources/application.yml
  20. 12 3
      pom.xml

+ 9 - 0
common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticlePatient.java

@ -43,6 +43,7 @@ public class HealthEduArticlePatient {
    private String level2Type;//2级类别
    private String level;//等级
    private Integer allCount;//所有的推送数目
    private String type;//推送类型 1:文章 2:健康课程
    public String getId() {
        return id;
@ -259,4 +260,12 @@ public class HealthEduArticlePatient {
    public void setSendLevel(String sendLevel) {
        this.sendLevel = sendLevel;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}

+ 79 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/HttpController.java

@ -0,0 +1,79 @@
package com.yihu.wlyy.service.controller;
import com.yihu.wlyy.service.common.http.HttpHelper;
import com.yihu.wlyy.service.common.http.HttpResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
 * Created by chenweida on 2017/9/9.
 */
@Controller
@RequestMapping(value = "/http")
@Api(description = "http请求接口")
public class HttpController {
    @Autowired
    private HttpHelper httpHelper;
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("统一get接口")
    public String get(
            @ApiParam(name = "url", value = "请求的url 例 http://127.0.0.1:8761:xzx/xxx", required = false) @RequestParam(value = "url", required = false) String url,
            @ApiParam(name = "params", value = "请求的参数(json格式)", required = false) @RequestParam(value = "params", required = false) String params
    ) {
        try {
            JSONObject jsonObject = JSONObject.fromObject(params);
            Map<String, Object> mapParams = new HashMap<>();
            Iterator it = jsonObject.keys();
            // 遍历jsonObject数据,添加到Map对象
            while (it.hasNext()) {
                String key = String.valueOf(it.next());
                String value = (String) jsonObject.get(key);
                mapParams.put(key, value);
            }
            HttpResponse h = httpHelper.get(url, mapParams);
            return h.getBody();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "执行失败";
    }
    @RequestMapping(value = "/post", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("统一post接口")
    public String post(
            @ApiParam(name = "url", value = "请求的url", required = false) @RequestParam(value = "url", required = false) String url,
            @ApiParam(name = "params", value = "请求的参数", required = false) @RequestParam(value = "params", required = false) String params) {
        try {
            JSONObject jsonObject = JSONObject.fromObject(params);
            Map<String, Object> mapParams = new HashMap<>();
            Iterator it = jsonObject.keys();
            // 遍历jsonObject数据,添加到Map对象
            while (it.hasNext()) {
                String key = String.valueOf(it.next());
                String value = (String) jsonObject.get(key);
                mapParams.put(key, value);
            }
            HttpResponse h = httpHelper.post(url, mapParams);
            return h.getBody();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "执行失败";
    }
}

+ 170 - 0
patient-co/patient-co-statistics-es/doc/es/QuartzJobConfig.java

@ -0,0 +1,170 @@
package com.yihu.wlyy.entity.job;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
/**
 * 计划任务
 */
@Entity
@Table(name = "wlyy_job_config")
public class QuartzJobConfig implements java.io.Serializable {
	private String id;
	private String quotaId;//指标id
	private String jobName;//任务名称
	private String jobInfo;//任务描述
	private String jobType;//任务类型(0--单次执行  1--周期执行 2--监听任务)
	private String jobClass;//任务执行的class
	private String quartzCron;//quartz表达式
	private String status;//1 启动 0停止
	private String del;//是否删除 1正常 0删除
	private String sql;
	private String sqlCount;
	private String sqlDay;
	private String sqlYear;
	private String cacheKey;//缓存的key
	/** minimal constructor */
	public QuartzJobConfig() {
	}
	/** full constructor */
	public QuartzJobConfig(String jobName, String jobInfo, String jobType,
                           String jobClass, String quartzCron, String status) {
		this.jobName = jobName;
		this.jobInfo = jobInfo;
		this.jobType = jobType;
		this.jobClass = jobClass;
		this.quartzCron = quartzCron;
		this.status = status;
	}
	// Property accessors
	@GenericGenerator(name = "generator", strategy = "uuid")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false, length = 50)
	public String getId() {
		return this.id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@Column(name = "job_name", length = 50)
	public String getJobName() {
		return this.jobName;
	}
	public void setJobName(String jobName) {
		this.jobName = jobName;
	}
	@Column(name = "job_info", length = 200)
	public String getJobInfo() {
		return this.jobInfo;
	}
	public void setJobInfo(String jobInfo) {
		this.jobInfo = jobInfo;
	}
	@Column(name = "job_type", length = 10)
	public String getJobType() {
		return this.jobType;
	}
	public void setJobType(String jobType) {
		this.jobType = jobType;
	}
	@Column(name = "job_class", length = 200)
	public String getJobClass() {
		return jobClass;
	}
	public void setJobClass(String jobClass) {
		this.jobClass = jobClass;
	}
	@Column(name = "quartz_cron", length = 200)
	public String getQuartzCron() {
		return this.quartzCron;
	}
	public void setQuartzCron(String quartzCron) {
		this.quartzCron = quartzCron;
	}
	@Column(name = "status", length = 1)
	public String getStatus() {
		return this.status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	@Column(name = "quota_id", length = 50)
	public String getQuotaId() {
		return quotaId;
	}
	public void setQuotaId(String quotaId) {
		this.quotaId = quotaId;
	}
	@Column(name = "del", length = 1)
	public String getDel() {
		return del;
	}
	public void setDel(String del) {
		this.del = del;
	}
	public String getSql() {
		return sql;
	}
	public void setSql(String sql) {
		this.sql = sql;
	}
	public String getSqlCount() {
		return sqlCount;
	}
	public void setSqlCount(String sqlCount) {
		this.sqlCount = sqlCount;
	}
	public String getSqlDay() {
		return sqlDay;
	}
	public void setSqlDay(String sqlDay) {
		this.sqlDay = sqlDay;
	}
	public String getSqlYear() {
		return sqlYear;
	}
	public void setSqlYear(String sqlYear) {
		this.sqlYear = sqlYear;
	}
	public String getCacheKey() {
		return cacheKey;
	}
	public void setCacheKey(String cacheKey) {
		this.cacheKey = cacheKey;
	}
}

+ 127 - 0
patient-co/patient-co-statistics-es/doc/es/QuartzJobConfig1.java

@ -0,0 +1,127 @@
//package com.yihu.wlyy.entity.job;
//
//import javax.persistence.Column;
//import javax.persistence.Entity;
//import javax.persistence.GeneratedValue;
//import javax.persistence.Id;
//import javax.persistence.Table;
//import org.hibernate.annotations.GenericGenerator;
//
///**
// * 计划任务
// */
//@Entity
//@Table(name = "wlyy_job_config")
//public class QuartzJobConfig implements java.io.Serializable {
//
//	private String id;
//	private String quotaId;//指标id
//	private String jobName;//任务名称
//	private String jobInfo;//任务描述
//	private String jobType;//任务类型(0--单次执行  1--周期执行 2--监听任务)
//	private String jobClass;//任务执行的class
//	private String quartzCron;//quartz表达式
//	private String status;//1 启动 0停止
//	private String del;//是否删除 1正常 0删除
//
//	/** minimal constructor */
//	public QuartzJobConfig() {
//
//	}
//
//	/** full constructor */
//	public QuartzJobConfig(String jobName, String jobInfo, String jobType,
//                           String jobClass, String quartzCron, String status) {
//		this.jobName = jobName;
//		this.jobInfo = jobInfo;
//		this.jobType = jobType;
//		this.jobClass = jobClass;
//		this.quartzCron = quartzCron;
//		this.status = status;
//	}
//
//	// Property accessors
//	@GenericGenerator(name = "generator", strategy = "uuid")
//	@Id
//	@GeneratedValue(generator = "generator")
//	@Column(name = "id", unique = true, nullable = false, length = 50)
//	public String getId() {
//		return this.id;
//	}
//
//	public void setId(String id) {
//		this.id = id;
//	}
//
//	@Column(name = "job_name", length = 50)
//	public String getJobName() {
//		return this.jobName;
//	}
//
//	public void setJobName(String jobName) {
//		this.jobName = jobName;
//	}
//
//	@Column(name = "job_info", length = 200)
//	public String getJobInfo() {
//		return this.jobInfo;
//	}
//
//	public void setJobInfo(String jobInfo) {
//		this.jobInfo = jobInfo;
//	}
//
//	@Column(name = "job_type", length = 10)
//	public String getJobType() {
//		return this.jobType;
//	}
//
//	public void setJobType(String jobType) {
//		this.jobType = jobType;
//	}
//
//	@Column(name = "job_class", length = 200)
//	public String getJobClass() {
//		return jobClass;
//	}
//
//	public void setJobClass(String jobClass) {
//		this.jobClass = jobClass;
//	}
//
//	@Column(name = "quartz_cron", length = 200)
//	public String getQuartzCron() {
//		return this.quartzCron;
//	}
//
//	public void setQuartzCron(String quartzCron) {
//		this.quartzCron = quartzCron;
//	}
//
//	@Column(name = "status", length = 1)
//	public String getStatus() {
//		return this.status;
//	}
//
//	public void setStatus(String status) {
//		this.status = status;
//	}
//
//	@Column(name = "quota_id", length = 50)
//	public String getQuotaId() {
//		return quotaId;
//	}
//
//	public void setQuotaId(String quotaId) {
//		this.quotaId = quotaId;
//	}
//
//	@Column(name = "del", length = 1)
//	public String getDel() {
//		return del;
//	}
//
//	public void setDel(String del) {
//		this.del = del;
//	}
//}

+ 1 - 1
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/dao/ConsultTeamDao.java

@ -114,6 +114,6 @@ public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam,
    @Query("FROM ConsultTeam a where TIMESTAMPDIFF(SECOND, a.czrq, CURRENT_TIME) < 86400 and a.status = 0 order by a.czrq desc")
    Page<ConsultTeam> getUnresponsedConsultIn24Hours(Pageable pageable);
	@Query("FROM ConsultTeam a where a.type=?1 and a.adminTeamCode is null")
	@Query("FROM ConsultTeam a where a.type=?1 and a.adminTeamId is null")
	List<ConsultTeam> findByTypeAndAdminTeamIdIsNull(Integer s);
}

+ 5 - 5
patient-co/patient-co-statistics/pom.xml

@ -351,11 +351,11 @@
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <version>${version.spring-boot}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>${version.spring-boot}</version>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-starter-security</artifactId>-->
            <!--<version>${version.spring-boot}</version>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>

+ 40 - 40
patient-co/patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/config/WebSecurityConfig.java

@ -1,40 +1,40 @@
package com.yihu.wlyy.statistics.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
 * Created by Administrator on 2016.10.17.
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Value("${security.basic.username}")
    String username;
    @Value("${security.basic.password}")
    String password;
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .formLogin().defaultSuccessUrl("/swagger-ui.html").failureUrl("/login") //登录成功之后的跳转
                .permitAll()
                .and()
                .logout().logoutSuccessUrl("/login")
                .permitAll();
    }
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
            auth.inMemoryAuthentication()
                .withUser(username).password(password).roles("USER");
    }
}
//package com.yihu.wlyy.statistics.config;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//
///**
// * Created by Administrator on 2016.10.17.
// */
//@Configuration
//@EnableWebSecurity
//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//
//    @Value("${security.basic.username}")
//    String username;
//    @Value("${security.basic.password}")
//    String password;
//
//    protected void configure(HttpSecurity http) throws Exception {
//        http.csrf().disable().authorizeRequests()
//                .anyRequest().authenticated()
//                .and()
//                .formLogin().defaultSuccessUrl("/swagger-ui.html").failureUrl("/login") //登录成功之后的跳转
//                .permitAll()
//                .and()
//                .logout().logoutSuccessUrl("/login")
//                .permitAll();
//    }
//
//    @Autowired
//    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
//            auth.inMemoryAuthentication()
//                .withUser(username).password(password).roles("USER");
//    }
//
//}

+ 8 - 0
patient-co/patient-co-wlyy-job/pom.xml

@ -125,6 +125,14 @@
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-keyvalue</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-all</artifactId>
        </dependency>
        <!-- spring end -->
        <!--Swagger start -->

+ 35 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/config/RedisConfig.java

@ -0,0 +1,35 @@
package com.yihu.wlyy.config;
import com.yihu.wlyy.redis.RedisQueueListener;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;
/**
 * Created by chenweida on 2017/9/8.
 */
@Component
public class RedisConfig {
    private String channelName = "healthArticleChannel";
    @Bean
    RedisMessageListenerContainer containerHealthArticleChannel(RedisConnectionFactory connectionFactory,
                                                                MessageListenerAdapter listenerAdapter) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(listenerAdapter, new PatternTopic(channelName));//注册监听器
        return container;
    }
    //添加消息监听
    @Bean(name = "listenerAdapterHealthArticleChannel")
    MessageListenerAdapter listenerAdapterHealthArticleChannel(RedisQueueListener receiver) {
        return new MessageListenerAdapter(receiver, "onMessage");
    }
}

+ 105 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/redis/HealthAricleListener.java

@ -0,0 +1,105 @@
package com.yihu.wlyy.redis;
import com.yihu.es.entity.HealthEduArticlePatient;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ImUtill;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
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 java.util.List;
/**
 * Created by chenweida on 2017/9/8.
 * 监听消费
 */
@Component
public class HealthAricleListener implements RedisQueueListener<String> {
    private Logger logger = LoggerFactory.getLogger(HealthAricleListener.class);
    @Autowired
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private PatientService patientService;
    @Autowired
    private ConsultService consultService;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Override
    public void onMessage(String message) {
        HealthEduArticlePatient healthEduArticlePatient = (HealthEduArticlePatient) net.sf.json.JSONObject.toBean(net.sf.json.JSONObject.fromObject(message), HealthEduArticlePatient.class);
        //保存到ES中
        //发送IM消息
    }
    //发送到IM和
    private void sendWxTemplateAndIM(List<HealthEduArticlePatient> healthEduArticlePatients, Integer sendType) {
        String endMsg = "";//"为了您的健康," + doctor.getName() + "医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
        healthEduArticlePatients.stream().forEach(one -> {
            Patient patient = patientService.findByCode(one.getPatient());
            try {
                //卫纪委发送不推IM
                if (1 == sendType) {
                    consultService.sendMucMessageBySingnType(one.getSendCode(), one.getSendName(), patient.getCode(), "{\"title\":\"" + one.getAttachedTitle() + "\",\"type\":0,\"id\":\"" + one.getId() + "\",\"img\":\"" + one.getAttachedPic() + "\",\"content\":\"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通\"}", "4", patient.getName());
                    if (StringUtils.isNotBlank(one.getAttachedMessage())) {
                        //发送备注
                        consultService.sendMucMessageBySingnType(one.getSendCode(), one.getSendName(), patient.getCode(), one.getAttachedMessage(), ImUtill.CONTENT_TYPE_TEXT, patient.getName());
                    }
                }
                // 推送消息给微信端
                JSONObject json = new JSONObject();
                json.put("first", patient.getName() + ",您好! " + one.getSendName() + "医生给您发来了一篇患教文章");
                json.put("toUser", patient.getCode());
                json.put("article", one.getId() + "");
                json.put("title", one.getAttachedTitle());
                json.put("doctorName", one.getSendName());
                json.put("represented", patient.getCode());//被代理人
                json.put("date", DateUtil.dateToStrLong(DateUtil.getNowDate()));
                json.put("remark", org.springframework.util.StringUtils.isEmpty(one.getAttachedMessage()) ? "  " : one.getAttachedMessage());
                if (StringUtils.isNotBlank(patient.getOpenid())) {
                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 9,
                            patient.getOpenid(),
                            patient.getName(),
                            json);
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        json.remove("toUser");
                        json.put("toUser", member.getCode());
                        json.remove("first");
                        try {
                            json.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (StringUtils.isNotBlank(member.getOpenid())) {
                            pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 9, member.getOpenid(), patient.getName(), json);
                        }
                    }
                }
            } catch (Exception e) {
                logger.error("patient:" + patient.getCode() + "," + e.getMessage());
            }
        });
    }
}

+ 10 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/redis/RedisQueueListener.java

@ -0,0 +1,10 @@
package com.yihu.wlyy.redis;
/**
 * Created by chenweida on 2017/9/8.
 * redis 队列监听
 */
public interface RedisQueueListener<T> {
    void onMessage(T value);
}

+ 4 - 0
patient-co/patient-co-wlyy/doc/技术文档/es/统计新增索引.txt

@ -99,6 +99,10 @@ POST http://172.19.103.68:9200/health_edu_article_patient_test/health_edu_articl
                    "type": "string",
                    "index": "not_analyzed"
                },
                "type": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "createTime": {
                    "type": "date",
                    "index": "not_analyzed"

+ 9 - 0
patient-co/patient-co-wlyy/pom.xml

@ -100,6 +100,7 @@
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <!-- end -->
        <dependency>
@ -125,6 +126,14 @@
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-keyvalue</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-all</artifactId>
        </dependency>
        <!-- spring end -->
        <!--Swagger start -->

+ 31 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/ActiveMQProduceConfig.java

@ -0,0 +1,31 @@
package com.yihu.wlyy.config;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
/**
 * Created by chenweida on 2017/9/9.
 * 生产者配置
 */
@EnableJms
@Configuration
public class ActiveMQProduceConfig {
    @Value("${activemq.username}")
    private String username;
    @Value("${activemq.password}")
    private String password;
    @Value("${activemq.url}")
    private String url;
    @Bean
    public ActiveMQConnectionFactory activeMQConnectionFactory() {
        ActiveMQConnectionFactory activeMQConnectionFactory =
                new ActiveMQConnectionFactory(username, password, url);
//                        "tcp://192.168.0.100:61616");
        return activeMQConnectionFactory;
    }
}

+ 9 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/GateWayAOP.java

@ -6,6 +6,8 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
@ -21,7 +23,7 @@ import java.io.PrintWriter;
@Aspect
@Component
public class GateWayAOP {
    private ThreadLocal entityThreadLocal = new ThreadLocal();
    private Logger logger = LoggerFactory.getLogger(GateWayAOP.class);
    //Controller层切点路径
    @Pointcut("execution(* com.yihu.wlyy.web..*.*(..))")
@ -37,14 +39,16 @@ public class GateWayAOP {
    @Around("controllerAspect()")
    public Object checkToken(ProceedingJoinPoint point) throws Throwable {
        Object obj = null;
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpServletRequest request = null;
        try {
            request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            obj = point.proceed();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        if (request != null) {
            request.setAttribute("returnObj", obj);
        }
        request.setAttribute("returnObj", obj);
        return obj;
    }
}

+ 30 - 65
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcEduArticleController.java

@ -1,21 +1,16 @@
package com.yihu.wlyy.web.third.gateway.controller.doctor;
import com.yihu.wlyy.config.es.ElastricSearchSave;
import com.yihu.es.entity.HealthEduArticlePatient;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.util.ImUtill;
import com.yihu.wlyy.web.WeixinBaseController;
import com.yihu.wlyy.web.third.gateway.service.GcEduArticleService;
import com.yihu.wlyy.web.third.gateway.vo.HealthEduArticlePatientModel;
import com.yihu.wlyy.web.third.gateway.vo.base.BaseResultModel;
import com.yihu.wlyy.web.third.gateway.vo.base.ResultBatchModel;
import com.yihu.wlyy.web.third.gateway.vo.base.ResultPageListModel;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import io.swagger.annotations.Api;
@ -24,10 +19,11 @@ import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -44,6 +40,7 @@ import java.util.*;
@ResponseBody
@Api(description = "医生文章相关服务")
public class GcEduArticleController extends WeixinBaseController {
    private Logger logger = LoggerFactory.getLogger(GcEduArticleController.class);
    @Autowired
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
@ -55,6 +52,11 @@ public class GcEduArticleController extends WeixinBaseController {
    private ConsultService consultService;
    @Autowired
    private GcEduArticleService gcEduArticleService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    private String channelName = "healthArticleChannel";
    /**
     * @param doctorCode
@ -64,13 +66,13 @@ public class GcEduArticleController extends WeixinBaseController {
     */
    @RequestMapping(value = "logs", method = RequestMethod.GET)
    @ApiOperation("查询医生给患者推送记录 ")
    @ResponseBody
    public ResultPageListModel<HealthEduArticlePatientModel> getPatientHealthLogs(
            @ApiParam(name = "articleType", value = "文章类别", required = false) @RequestParam(value = "articleType", required = false) String articleType,
            @ApiParam(name = "level1Type", value = "一级分类", required = false) @RequestParam(value = "level1Type", required = false) String level1Type,
            @ApiParam(name = "level2Type", value = "二级分类", required = false) @RequestParam(value = "level2Type", required = false) String level2Type,
            @ApiParam(name = "level", value = "等级", required = false) @RequestParam(value = "level", required = false) String level,
            @ApiParam(name = "doctorCode", value = "医生code,为空从useragent取", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode,
            @ApiParam(name = "patientCode", value = "接收人code", required = false) @RequestParam(value = "patientCode", required = false) String patientCode,
            @ApiParam(name = "articleTitle", value = "文章标题", required = false) @RequestParam(value = "articleTitle", required = false) String articleTitle,
            @ApiParam(name = "startTime", value = "开始时间yyyy-Mm-dd", required = false) @RequestParam(value = "startTime", required = false) String startTime,
            @ApiParam(name = "endTime", value = "结束时间yyyy-Mm-dd", required = false) @RequestParam(value = "endTime", required = false) String endTime,
@ -80,7 +82,11 @@ public class GcEduArticleController extends WeixinBaseController {
            if (org.springframework.util.StringUtils.isEmpty(doctorCode)) {
                doctorCode = getUID();
            }
            List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.getPatientHealthLogs(getUID(), articleType, level1Type, level2Type, level, articleTitle, startTime, endTime, page, pagesize);
            //最大1000
            if (pagesize > 1000) {
                pagesize = 1000;
            }
            List<HealthEduArticlePatientModel> eduArticlePatients = gcEduArticleService.getPatientHealthLogs(doctorCode, articleType, level1Type, level2Type, level, articleTitle, startTime, endTime, page, pagesize);
            Long count = gcEduArticleService.getPatientHealthLogsCount(getUID(), articleType, level1Type, level2Type, level, articleTitle, startTime, endTime);
            return new ResultPageListModel(
                    page,
@ -126,70 +132,29 @@ public class GcEduArticleController extends WeixinBaseController {
            //得到需要发送的患者
            gcEduArticleService.initPatient(patientSet, patients, unPatients, labelType, labelCode, teamId);
            //保存发送记录
            List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.saveArticle(patientSet, sendCode, sendName, sendType, sendMessage, teamId, articleId, articlePic, articleTitle, articleContent, articleType, level1Type, level2Type, level);
            //获取保存发送记录
            List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.getSaveArticle(patientSet, sendCode, sendName, sendType, sendMessage, teamId, articleId, articlePic, articleTitle, articleContent, articleType, level1Type, level2Type, level);
            //推送微信模板消息和发送im消息
            sendWxTemplateAndIM(healthEduArticlePatients, sendType);
            new Thread(() -> {
                //发送任务到redis
                sender(healthEduArticlePatients);
            }).start();
            System.out.println("结束");
            return new BaseResultModel();
        } catch (Exception e) {
            return new BaseResultModel(BaseResultModel.statusEm.opera_error.getCode(), BaseResultModel.statusEm.opera_error.getMessage() + ":" + e.getMessage());
        }
    }
    @Async
    private void sendWxTemplateAndIM(List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients, Integer sendType) throws Exception {
        String endMsg = "";//"为了您的健康," + doctor.getName() + "医生给您发送了一篇患教文章,请仔细查阅,如有问题,可随时咨询医生。";
    /**
     * 发送到redis
     *
     * @param healthEduArticlePatients
     */
    public void sender(List<HealthEduArticlePatient> healthEduArticlePatients) {
        healthEduArticlePatients.stream().forEach(one -> {
            Patient patient = patientService.findByCode(one.getPatient());
            //卫纪委发送不推IM
            if (1 == sendType) {
                consultService.sendMucMessageBySingnType(one.getSendCode(), one.getSendName(), patient.getCode(), "{\"title\":\"" + one.getAttachedTitle() + "\",\"type\":0,\"id\":\"" + one.getId() + "\",\"img\":\"" + one.getAttachedPic() + "\",\"content\":\"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通\"}", "4", patient.getName());
                if (StringUtils.isNotBlank(one.getAttachedMessage())) {
                    //发送备注
                    consultService.sendMucMessageBySingnType(one.getSendCode(), one.getSendName(), patient.getCode(), one.getAttachedMessage(), ImUtill.CONTENT_TYPE_TEXT, patient.getName());
                }
            }
            // 推送消息给微信端
            JSONObject json = new JSONObject();
            json.put("first", patient.getName() + ",您好! " + one.getSendName() + "医生给您发来了一篇患教文章");
            json.put("toUser", patient.getCode());
            json.put("article", one.getId() + "");
            json.put("title", one.getAttachedTitle());
            json.put("doctorName", one.getSendName());
            json.put("represented", patient.getCode());//被代理人
            json.put("date", DateUtil.dateToStrLong(DateUtil.getNowDate()));
            json.put("remark", org.springframework.util.StringUtils.isEmpty(one.getAttachedMessage()) ? "  " : one.getAttachedMessage());
            if (StringUtils.isNotBlank(patient.getOpenid())) {
                pushMsgTask.putWxMsg(getAccessToken(), 9,
                        patient.getOpenid(),
                        patient.getName(),
                        json);
            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    json.remove("toUser");
                    json.put("toUser", member.getCode());
                    json.remove("first");
                    try {
                        json.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        pushMsgTask.putWxMsg(getAccessToken(), 9, member.getOpenid(), patient.getName(), json);
                    }
                }
            }
            redisTemplate.convertAndSend(channelName, net.sf.json.JSONObject.fromObject(one).toString());
        });
    }
}

+ 0 - 8
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/listener/HealthAricleListener.java

@ -1,8 +0,0 @@
package com.yihu.wlyy.web.third.gateway.listener;
/**
 * Created by chenweida on 2017/9/8.
 * 监听消费
 */
public class HealthAricleListener{
}

+ 5 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/service/GcEduArticleService.java

@ -125,7 +125,7 @@ public class GcEduArticleService {
     * @param articleTitle 文章主题
     */
    @Transactional
    public List<com.yihu.es.entity.HealthEduArticlePatient> saveArticle(Set<String> patientSet,
    public List<com.yihu.es.entity.HealthEduArticlePatient> getSaveArticle(Set<String> patientSet,
                                                                        String sendCode,
                                                                        String sendName,
                                                                        Integer sendType,
@ -164,9 +164,9 @@ public class GcEduArticleService {
            }
            healthEduArticlePatient.setBatchNo(batchNo);
            healthEduArticlePatient.setCreateTime(createTime);
            healthEduArticlePatient.setSendLevel(doctor.getLevel() + "");
            healthEduArticlePatient.setSendLevel(doctor.getLevel()!=null?String.valueOf(doctor.getLevel()):"");
            healthEduArticlePatient.setSendPic(doctor.getPhoto());
            healthEduArticlePatient.setSendSex(doctor.getSex() + "");
            healthEduArticlePatient.setSendSex(doctor.getSex()!=null?String.valueOf(doctor.getSex()):"");
            healthEduArticlePatient.setArticleId(articleId);
            healthEduArticlePatient.setAttachedTitle(articleTitle);
@ -177,12 +177,13 @@ public class GcEduArticleService {
            healthEduArticlePatient.setLevel(level);
            healthEduArticlePatient.setLevel1Type(level1Type);
            healthEduArticlePatient.setLevel2Type(level2Type);
            healthEduArticlePatient.setType("1");//文章
            healthEduArticlePatients.add(healthEduArticlePatient);
        }
        //保存到ES中
        elastricSearchSave.save(healthEduArticlePatients, esIndex, esType);
        //elastricSearchSave.save(healthEduArticlePatients, esIndex, esType);
        return healthEduArticlePatients;
    }

+ 12 - 1
patient-co/patient-co-wlyy/src/main/resources/application.yml

@ -92,6 +92,10 @@ interceptor:
    status: 1 ###  1开启 0 关闭
    time: 2 ##对外接的accesstoken生命周期 2小时
---
##测试的配置
spring:
@ -509,4 +513,11 @@ es:
  host: 172.19.103.68
  port: 9200
  tPort: 9300
  clusterName: jkzl
  clusterName: jkzl
activemq:
  username:
  password:
  url:

+ 12 - 3
pom.xml

@ -63,9 +63,7 @@
        <selenium.version>2.42.2</selenium.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.mysql>5.1.38</version.mysql>
        <version.activemq>5.15.0</version.activemq>
        <version.common>1.0.0</version.common>
    </properties>
@ -178,6 +176,7 @@
                <artifactId>spring-core</artifactId>
                <version>${version.spring}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-commons</artifactId>
@ -188,6 +187,16 @@
                <artifactId>spring-data-keyvalue</artifactId>
                <version>${version.spring-data-keyvalue}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jms</artifactId>
                <version>${version.spring}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.activemq</groupId>
                <artifactId>activemq-all</artifactId>
                <version>${version.activemq}</version>
            </dependency>
            <!-- spring end -->
            <!--Swagger start -->