Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

Conflicts:
	common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticleES.java
liuwenbin 7 years ago
parent
commit
bcf37fe3d4

+ 1 - 1
common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticleES.java

@ -16,7 +16,7 @@ import java.util.List;
public class HealthEduArticleES {
    @JestId
    private String id;
    //说明:如医生推送文章给5个居民,则保存5条userType=1的记录和1条userType=2的记录(共6条)batchNo批次号一样
    //说明:如医生推送文章给5个居民,则保存5条userType=1的记录和1条userType=2的记录(共6条)batchNo批次号一样。
    private String batchNo;//批次号记录发送所属批次(ES:必填)
    private String patientCode; // 患者标识(ES)(根据userType的值,userType=1,必填;userType=2,为空)
    private String patientName; // 患者名称(ES)(根据userType的值,userType=1,必填;userType=2,为空)

+ 1 - 1
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/main.jsp

@ -138,7 +138,7 @@
							<sec:authorize url="/admin/static/pay/initial">
								<li><a href="javascript:locationMenu('staticPay');">支付统计报表</a></li>
							</sec:authorize>
							<sec:authorize url="/admin/static/static/center">
							<sec:authorize url="/admin/static/center">
						</ul>
					</div>
				</div>

File diff suppressed because it is too large
+ 1 - 1
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/PrescriptionController.java


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

@ -105,7 +105,7 @@ activemq:
  password: admin
  url: tcp://172.19.103.87:61616
  queue:
    healtHarticleQueue: healthArticleChannel_test
    healtHarticleQueue: healthArticleChannel_devtest
  consumers:
    count: 10 #消费者集群数

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

@ -110,7 +110,7 @@ activemq:
  password: admin
  url: tcp://172.19.103.87:61616
  queue:
    healtHarticleQueue: healthArticleChannel_test  #健康文章推送
    healtHarticleQueue: healthArticleChannel_dev  #健康文章推送
  consumers:
    count: 10 #消费者集群数

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/SwaggerConfig.java

@ -175,6 +175,7 @@ public class SwaggerConfig {
                        regex("/wechat/.*"),
                        regex("/nofilter/.*"),
                        regex("/idc10/.*"),
                        regex("/iot/.*"),
                        regex("/im_new/.*"),
                        regex("/dataHandling/.*"),
                        regex("/version/.*"),

+ 82 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java

@ -0,0 +1,82 @@
package com.yihu.wlyy.service.third.iot;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.util.HttpClientUtil;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
 * 物联网设备对接
 * @author yeshijie on 2018/1/3.
 */
@Service
public class IotDeviceService {
//    @Value("${}")
    private String baseUrl = "https://iot.xmtyw.cn/";
    private String grantType = "client_credentials&";
    private String clientId = "Va5yQRHlA4Fq4eR3LT0vuXV4&";
    private String clientSecret = "0rDSjzQ20XUj5itV7WRtznPQSzr5pVw2";
    @Autowired
    private HttpClientUtil httpClientUtil;
    private String accessToken = "";
    public String getAccessToken(){
        String url = baseUrl+"/oauth/2.0/token";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("grant_type",grantType));
        params.add(new BasicNameValuePair("client_id",clientId));
        params.add(new BasicNameValuePair("client_secret",clientSecret));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
    }
    /**
     * 设备注册及绑定
     * @return
     */
    public String registedevice(JSONObject json){
        json.put("access_token",accessToken);
        String url = baseUrl+"/registedevice";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("json",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
    }
    /**
     * 数据上传
     * @param json
     * @return
     */
    public String upload(JSONObject json){
        json.put("access_token",accessToken);
        String url = baseUrl+"/upload";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("json",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
    }
    /**
     * 查询
     * @param json
     * @return
     */
    public String search(JSONObject json){
        json.put("access_token",accessToken);
        String url = baseUrl+"/upload";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("json",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
    }
}

+ 61 - 36
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java

@ -8,8 +8,8 @@ import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.third.jkedu.service.EduArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONArray;
import org.json.JSONObject;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
/**
 * Created by Administrator on 2016.10.08.
 * 修改历史数据处理控制器
@ -39,10 +41,11 @@ public class DataHandlingController extends BaseController {
    private com.yihu.wlyy.util.HttpUtil HttpUtil;
    @Autowired
    private EduArticleService eduArticleService;
    /**
     * 生成签约表中的行政团队的code
     */
    @RequestMapping(value = "produceSignAdminTeamCode",method =RequestMethod.GET)
    @RequestMapping(value = "produceSignAdminTeamCode", method = RequestMethod.GET)
    @ResponseBody
    public String produceSignAdminTeamCode() {
        try {
@ -55,9 +58,10 @@ public class DataHandlingController extends BaseController {
    /**
     * 生成咨询表中中的行政团队的code
     *
     * @return
     */
    @RequestMapping(value = "produceConsultAdminTeamCode",method =RequestMethod.GET)
    @RequestMapping(value = "produceConsultAdminTeamCode", method = RequestMethod.GET)
    @ResponseBody
    public String produceConsultAdminTeamCode() {
        try {
@ -70,10 +74,11 @@ public class DataHandlingController extends BaseController {
    /**
     * 生成医生和患者表中有身份的用户的密码
     *
     * @return
     */
    @ApiOperation("生成医生和患者表中有身份的用户的密码")
    @RequestMapping(value = "producePatientAndDoctorPassword",method =RequestMethod.GET)
    @RequestMapping(value = "producePatientAndDoctorPassword", method = RequestMethod.GET)
    @ResponseBody
    public String producePatientAndDoctorPasswor() {
        try {
@ -83,12 +88,14 @@ public class DataHandlingController extends BaseController {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 初始化wlyy_doctor的数据到wlyy_user
     *
     * @return
     */
    @ApiOperation("初始化wlyy_doctor的数据到wlyy_user")
    @RequestMapping(value = "initWLyyDoctorTable2WLyyUserTable",method = RequestMethod.GET)
    @RequestMapping(value = "initWLyyDoctorTable2WLyyUserTable", method = RequestMethod.GET)
    @ResponseBody
    public String initWLyyDoctorTable2WLyyUserTable() {
        try {
@ -99,63 +106,81 @@ public class DataHandlingController extends BaseController {
        }
    }
    @RequestMapping(value = "/getArticleListToNewDataBase",method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleListToNewDataBase", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("文章列表转移")
    public String getArticleListToNewDataBase(){
    public String getArticleListToNewDataBase() {
        boolean flag = eduArticleService.getArticleListToNewDataBase();
        if (flag){
            return write(200,"数据转移成功!");
        }else{
            return write(0,"数据转移失败!");
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
        }
    }
    @RequestMapping(value = "/getArticleCollectToNewDataBase",method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleCollectToNewDataBase", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("文章收藏转移")
    public String getArticleCollectToNewDataBase(){
    public String getArticleCollectToNewDataBase() {
        boolean flag = eduArticleService.getArticleCollectToNewDataBase();
        if (flag){
            return write(200,"数据转移成功!");
        }else{
            return write(0,"数据转移失败!");
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
        }
    }
    @RequestMapping(value = "/getArticleBehaviorToNewDataBase",method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleBehaviorToNewDataBase", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("文章行为转移")
    public String getArticleBehaviorToNewDataBase(){
    public String getArticleBehaviorToNewDataBase() {
        boolean flag = eduArticleService.getArticleBehaviorToNewDataBase();
        if (flag){
            return write(200,"数据转移成功!");
        }else{
            return write(0,"数据转移失败!");
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
        }
    }
    @RequestMapping(value = "/getArticleSendToEs",method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleSendToEs", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("已发送文章列表转移Es")
    public String getArticleSendToEs(){
    public String getArticleSendToEs() {
        boolean flag = eduArticleService.getArticleSendedListToEs();
        if (flag){
            return write(200,"数据转移成功!");
        }else{
            return write(0,"数据转移失败!");
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
        }
    }
    @RequestMapping(value = "/updateEsArticlePatent",method = RequestMethod.GET)
    @RequestMapping(value = "/updateEsArticlePatent", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("更新es里的数据没有userType")
    public String updateEsArticlePatent(){
    public String updateEsArticlePatent() {
        boolean flag = eduArticleService.updateData();
        if (flag){
            return write(200,"数据更新成功!");
        }else{
            return write(0,"数据更新失败!");
        if (flag) {
            return write(200, "数据更新成功!");
        } else {
            return write(0, "数据更新失败!");
        }
    }
    @RequestMapping(value = "/getArticleSendToEsByDoctor", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("根据医生去把Mysql数据抽到区ES数据")
    public String getArticleSendToEsByDoctor(
            @ApiParam(name = "doctorCodes", value = "医生code,多个逗号分割", required = true) @RequestParam(value = "doctorCodes", required = true) String doctorCodes
    ) {
        Map<String, JSONObject> flag = null;
        try {
            flag = eduArticleService.getArticleSendToEsByDoctor(doctorCodes);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return write(200, "数据更新成功!","data",flag);
    }
}

+ 9 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/jimeiJkEduPC/DoctorJMJkEduArticlePCController.java

@ -3,6 +3,7 @@ package com.yihu.wlyy.web.doctor.jimeiJkEduPC;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.es.entity.HealthEduArticleES;
import com.yihu.wlyy.service.app.health.HealthEduArticleLabelService;
import com.yihu.wlyy.service.jimeiJkEdu.JMJkEduArticleService;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.web.BaseController;
@ -39,6 +40,8 @@ public class DoctorJMJkEduArticlePCController extends BaseController {
    private String esIndex;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Autowired
    private HealthEduArticleLabelService healthEduArticleLabelService;
    @RequestMapping(value = "saveArticle", method = RequestMethod.POST)
    @ApiOperation("添加、编辑文章")
@ -137,8 +140,12 @@ public class DoctorJMJkEduArticlePCController extends BaseController {
            JSONObject response = jmJkEduArticleService.queryArticlePcList(firstLevelCategoryId,secondLevelCategoryId,insertTimeStart,insertTimeEnd,articlelevel,articleTitle,
                    getUID(),currentUserRole,currentUserRoleLevel,isAuthentication,isMyArticle,page,pageSize,sEcho,roleType);
            
            
            if(StringUtils.isNotBlank(articleTitle)){
                //记录搜索记录
                healthEduArticleLabelService.saveOrUpdateLabel(articleTitle,getUID());
            }
            //判断文章列表是否有推送过该居民
            if(StringUtils.isNotBlank(patient)){
                com.alibaba.fastjson.JSONArray pushresponse = jmJkEduArticleService.pushArticleLogs(0,0,patient,"");

+ 112 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java

@ -0,0 +1,112 @@
package com.yihu.wlyy.web.third.iot;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.third.iot.IotDeviceService;
import com.yihu.wlyy.web.BaseController;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author yeshijie on 2018/1/3.
 */
@RestController
@RequestMapping(value = "/iot",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "物联网测试类")
public class IotDeviceController extends BaseController{
    @Autowired
    private IotDeviceService iotDeviceService;
    @RequestMapping(value = "/registedevice",method = RequestMethod.POST)
    @ApiOperation("注册设备")
    public String registedevice(){
        try {
            JSONObject json = new JSONObject();
            JSONObject js = new JSONObject();
            js.put("sn","2638234828");
            js.put("ext_code","1");
            js.put("device_name","血压计-康为A206G");
            js.put("device_model","血压计-康为A206G");
            js.put("idcard","350429198905194016");
            js.put("username","邹林");
            js.put("manufacture_code","");
            js.put("manufacture_name","");
            js.put("owner_org_code","");
            js.put("owner_org_name","");
            js.put("sale_org_code","");
            js.put("sale_org_name","");
            js.put("manufacture_tel","");
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(js);
            json.put("data",jsonArray);
            String re = iotDeviceService.registedevice(json);
            return write(200, "注册设备成功!", "data", re);
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "/upload1",method = RequestMethod.POST)
    @ApiOperation("不含居民身份的数据上传协议")
    public String upload1(){
        try {
            JSONObject json = new JSONObject();
            JSONObject js = new JSONObject();
            js.put("measure_time","2018-01-01 01:01:01");
            js.put("systolic","111");
            js.put("diastolic","60");
            js.put("pulse","66");
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(js);
            json.put("data",jsonArray);
            json.put("sn","2638234828");
            json.put("ext_code","1");
            json.put("device_name","血压计-康为A206G");
            json.put("device_model","血压计-康为A206G");
            String re = iotDeviceService.upload(json);
            return write(200, "注册设备成功!", "data", re);
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "/upload2",method = RequestMethod.POST)
    @ApiOperation("不含居民身份的数据上传协议")
    public String upload2(){
        try {
            JSONObject json = new JSONObject();
            JSONObject js = new JSONObject();
            js.put("measure_time","2018-01-01 11:01:01");
            js.put("blood_sugar","6.7");
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(js);
            json.put("data",jsonArray);
            json.put("data",jsonArray);
            json.put("sn","2638234828");
            json.put("ext_code","1");
            json.put("device_name","血压计-康为A206G");
            json.put("device_model","血压计-康为A206G");
            json.put("idcard","350429198905194016");
            json.put("username","邹林");
            String re = iotDeviceService.upload(json);
            return write(200, "注册设备成功!", "data", re);
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
}

+ 323 - 123
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/service/EduArticleService.java

@ -10,6 +10,8 @@ import com.yihu.wlyy.config.es.ElastricSearchSave;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.education.HealthEduArticle;
import com.yihu.wlyy.entity.education.HealthEduArticleDoctor;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.jkedu.repository.JkeduArticleDao;
import com.yihu.wlyy.jkedu.repository.JkeduBehaviorArticleDao;
@ -22,10 +24,12 @@ import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.util.MapListUtils;
import com.yihu.wlyy.util.SpringUtil;
import com.yihu.wlyy.web.third.gateway.service.GcLabelService;
import com.yihu.wlyy.web.third.jkedu.vo.save.SaveEduArticleHelper;
import io.searchbox.client.JestClient;
import io.searchbox.core.*;
import org.apache.axis.utils.Admin;
import org.apache.commons.collections.list.AbstractLinkedList;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.update.UpdateRequest;
@ -38,6 +42,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.hateoas.alps.Doc;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -73,6 +78,9 @@ public class EduArticleService {
    private ElasticsearchUtil elasticsearchUtil;
    @Autowired
    private ElasticFactory elasticFactory;
    @Autowired
    private GcLabelService gcLabelService;
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
@ -83,9 +91,10 @@ public class EduArticleService {
    /**
     * 健康教育文章列表转移
     *
     * @return
     */
    public boolean getArticleListToNewDataBase(){
    public boolean getArticleListToNewDataBase() {
        boolean flag = true;
        //获取卫计委code
        String wjwSql = "select code AS wjwCode from wlyy_role WHERE  name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
@ -93,31 +102,31 @@ public class EduArticleService {
        String wjwCode = result.get("wjwCode") + "";
        //先将原来数据库的数据删除
        List<NewArticleModel> delOldList = jkeduArticleDao.findOldArticle();
        if (delOldList!=null && delOldList.size()>0){
        if (delOldList != null && delOldList.size() > 0) {
            jkeduArticleDao.delete(delOldList);
        }
        //分页查询,执行插入
        String countSql = "select COUNT(1) AS num from wlyy_health_edu_article";
        Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
        if (countMap!=null){
        Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
        if (countMap != null) {
            int count = Integer.valueOf(String.valueOf(countMap.get("num")));
            double pageCount = Math.ceil(Double.valueOf(count)/Double.valueOf(pageSize));
            if (pageCount>0){
                String  sql ="SELECT code AS ArticleId,title AS ArticleTitle,summary AS Summary,content AS ArticleContent, " +
            double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize));
            if (pageCount > 0) {
                String sql = "SELECT code AS ArticleId,title AS ArticleTitle,summary AS Summary,content AS ArticleContent, " +
                        "url AS URL, czrq AS InsertTime, czrq AS UpdateTime,whea_type AS FirstLevelCategoryId," +
                        " keyword AS KeyWord FROM wlyy_health_edu_article limit ?,?";
                for (int i = 1;i<=pageCount;i++){
                    int start = (i-1)*pageSize;
                for (int i = 1; i <= pageCount; i++) {
                    int start = (i - 1) * pageSize;
                    //分页查询数据
                    List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
                    List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new Object[]{start, pageSize});
                    List<NewArticleModel> newList = new ArrayList<>();
                    try {
                        for (Map<String, Object> map : list) {
                            OldArticleModel oldArticleModel = new OldArticleModel();
                            NewArticleModel newArticleModel = new NewArticleModel();
                            //转换数据
                            oldArticleModel = MapListUtils.convertMap2Bean(map,OldArticleModel.class);
                            BeanUtils.copyProperties(oldArticleModel,newArticleModel);
                            oldArticleModel = MapListUtils.convertMap2Bean(map, OldArticleModel.class);
                            BeanUtils.copyProperties(oldArticleModel, newArticleModel);
                            newArticleModel.setArticleOrder(99);
                            newArticleModel.setArticleState(1);
                            newArticleModel.setOrgName("厦门市卫生与计划生育委员会");
@ -139,7 +148,7 @@ public class EduArticleService {
                        }
                        //执行插入新数据库
                        jkeduArticleDao.save(newList);
                    }catch (Exception e){
                    } catch (Exception e) {
                        e.printStackTrace();
                        flag = false;
                    }
@ -153,9 +162,10 @@ public class EduArticleService {
    /**
     * 健康教育收藏列表转移
     *
     * @return
     */
    public boolean getArticleCollectToNewDataBase(){
    public boolean getArticleCollectToNewDataBase() {
        boolean flag = true;
        try {
            //获取卫计委code
@ -164,14 +174,14 @@ public class EduArticleService {
            String wjwCode = result.get("wjwCode") + "";
            //先将原来数据库的数据删除
            List<Integer> delOldList = jkeduCollectionArticleDao.findOldArticleCollection();
            if (delOldList!=null && delOldList.size()>0){
            if (delOldList != null && delOldList.size() > 0) {
                int count = 1;
                double num = Math.ceil(Double.valueOf(delOldList.size())/1000.0);
                for (int i=0;i<num;i++){
                double num = Math.ceil(Double.valueOf(delOldList.size()) / 1000.0);
                for (int i = 0; i < num; i++) {
                    List idsList = new ArrayList<>();
                    for (int j =0;j<1000;j++){
                        if (count<=delOldList.size()){
                            idsList.add(delOldList.get(j+i*1000));
                    for (int j = 0; j < 1000; j++) {
                        if (count <= delOldList.size()) {
                            idsList.add(delOldList.get(j + i * 1000));
                        }
                        count++;
                    }
@ -179,13 +189,13 @@ public class EduArticleService {
                }
            }
            //先分页查询
            String countSql ="select COUNT(1) AS num from wlyy_health_edu_article_doctor";
            Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
            if (countMap!=null){
            String countSql = "select COUNT(1) AS num from wlyy_health_edu_article_doctor";
            Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
            if (countMap != null) {
                int count = Integer.valueOf(String.valueOf(countMap.get("num")));
                double pageCount = Math.ceil(Double.valueOf(count)/Double.valueOf(pageSize));
                if (pageCount>0) {
                    String  sql ="SELECT" +
                double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize));
                if (pageCount > 0) {
                    String sql = "SELECT" +
                            " ad.doctor AS UserId," +
                            " ad.article AS ArticleId, " +
                            " ad.url, " +
@ -200,13 +210,13 @@ public class EduArticleService {
                    for (int i = 1; i <= pageCount; i++) {
                        int start = (i - 1) * pageSize;
                        //分页查询数据
                        List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
                        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new Object[]{start, pageSize});
                        for (Map<String, Object> map : list) {
                            OldArticleCollectModel oldArticleCollectModel = new OldArticleCollectModel();
                            NewArticleCollectModel newArticleCollectModel = new NewArticleCollectModel();
                            oldArticleCollectModel = MapListUtils.convertMap2Bean(map,OldArticleCollectModel.class);
                            oldArticleCollectModel = MapListUtils.convertMap2Bean(map, OldArticleCollectModel.class);
                            //@// TODO: 2017/12/25 完善数据
                            BeanUtils.copyProperties(oldArticleCollectModel,newArticleCollectModel);
                            BeanUtils.copyProperties(oldArticleCollectModel, newArticleCollectModel);
                            newArticleCollectModel.setUserType(1);
                            newArticleCollectModel.setOrgName("厦门市卫生与计划生育委员会");
                            newArticleCollectModel.setOrgId(wjwCode);
@ -218,7 +228,7 @@ public class EduArticleService {
                    }
                }
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }
@ -227,22 +237,23 @@ public class EduArticleService {
    /**
     * 转移健康教育行为
     *
     * @return
     */
    public boolean getArticleBehaviorToNewDataBase(){
    public boolean getArticleBehaviorToNewDataBase() {
        boolean flag = true;
        try {
            //数量也许过大,分批次删除
            //先将原来数据库的数据删除
            List<NewArticleBehaviorModel> delOldList = jkeduBehaviorArticleDao.findOldArticleBehavior();
            if (delOldList!=null && delOldList.size()>0){
            if (delOldList != null && delOldList.size() > 0) {
                int count = 1;
                double num = Math.ceil(Double.valueOf(delOldList.size())/1000.0);
                for (int i=0;i<num;i++){
                double num = Math.ceil(Double.valueOf(delOldList.size()) / 1000.0);
                for (int i = 0; i < num; i++) {
                    List idsList = new ArrayList<>();
                    for (int j =0;j<1000;j++){
                        if (count<=delOldList.size()){
                            idsList.add(delOldList.get(j+i*1000).getID());
                    for (int j = 0; j < 1000; j++) {
                        if (count <= delOldList.size()) {
                            idsList.add(delOldList.get(j + i * 1000).getID());
                        }
                        count++;
                    }
@ -251,25 +262,25 @@ public class EduArticleService {
            }
            //分批次查询
            String countSql = "select COUNT(1) AS num from wlyy_health_edu_article_op_history";
            Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
            if (countMap!=null) {
            Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
            if (countMap != null) {
                int count = Integer.valueOf(String.valueOf(countMap.get("num")));
                double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize));
                if (pageCount > 0) {
                    String  sql ="SELECT code AS ArticleId, status AS BehaviorAction,creater AS UserId," +
                    String sql = "SELECT code AS ArticleId, status AS BehaviorAction,creater AS UserId," +
                            " created_time AS InsertTime FROM wlyy_health_edu_article_op_history limit ?,?";
                    List<NewArticleBehaviorModel> newList = new ArrayList<>();
                    //分页查询
                    for (int i = 1; i <= pageCount; i++) {
                        int start = (i - 1) * pageSize;
                        List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
                        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new Object[]{start, pageSize});
                        for (Map<String, Object> map : list) {
                            OldArticleBehaviorModel oldArticleBehaviorModel = new OldArticleBehaviorModel();
                            NewArticleBehaviorModel newArticleBehaviorModel = new NewArticleBehaviorModel();
                            oldArticleBehaviorModel = MapListUtils.convertMap2Bean(map,OldArticleBehaviorModel.class);
                            oldArticleBehaviorModel = MapListUtils.convertMap2Bean(map, OldArticleBehaviorModel.class);
                            //@// TODO: 2017/12/25 完善数据
                            BeanUtils.copyProperties(oldArticleBehaviorModel,newArticleBehaviorModel);
                            if (newArticleBehaviorModel.getBehaviorAction()==1){
                            BeanUtils.copyProperties(oldArticleBehaviorModel, newArticleBehaviorModel);
                            if (newArticleBehaviorModel.getBehaviorAction() == 1) {
                                newArticleBehaviorModel.setBehaviorAction(5);
                            }
                            newArticleBehaviorModel.setIsOld(1);
@ -280,7 +291,7 @@ public class EduArticleService {
                    }
                }
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }
@ -289,44 +300,45 @@ public class EduArticleService {
    /**
     * 数据转移至Es.
     *
     * @return
     */
    public boolean getArticleSendedListToEs(){
    public boolean getArticleSendedListToEs() {
        boolean flag = true;
        try{
        try {
            //获取卫计委code
            String sql = "select code AS wjwCode from wlyy_role WHERE  name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
            Map<String, Object> result = jdbcTemplate.queryForMap(sql);
            String wjwCode = result.get("wjwCode") + "";
            //查询es最大的时间记录
            String timeSql ="select createTime from "+esType+" order by createTime desc limit 0,1";
            HealthEduArticleESResult healthEduArticleESResult = (HealthEduArticleESResult)elasticsearchUtil.excuteOneObject(timeSql,HealthEduArticleESResult.class,esType,esIndex);
            String startTimeForSql = DateUtil.dateToStr(healthEduArticleESResult.getCreateTime(),"yyyy-MM-dd HH:mm:ss");
            String timeSql = "select createTime from " + esType + " order by createTime desc limit 0,1";
            HealthEduArticleESResult healthEduArticleESResult = (HealthEduArticleESResult) elasticsearchUtil.excuteOneObject(timeSql, HealthEduArticleESResult.class, esType, esIndex);
            String startTimeForSql = DateUtil.dateToStr(healthEduArticleESResult.getCreateTime(), "yyyy-MM-dd HH:mm:ss");
            //查询出所有的医生
            List<Doctor> doctorList = doctorDao.findAllCertifiedDoctors();
            Map<String,Doctor> doctorMap = new HashedMap();
            if (doctorList!=null && doctorList.size()>0){
                for (Doctor doctor: doctorList){
                    doctorMap.put(doctor.getCode(),doctor);
            Map<String, Doctor> doctorMap = new HashedMap();
            if (doctorList != null && doctorList.size() > 0) {
                for (Doctor doctor : doctorList) {
                    doctorMap.put(doctor.getCode(), doctor);
                }
            }
            //查询出所有的文章列表
            List<HealthEduArticle> healthEduArticleList = healthEduArticleDao.findAllArticle();
            Map<String,HealthEduArticle> articleMap = new HashedMap();
            if (healthEduArticleList!=null && healthEduArticleList.size()>0){
                for (HealthEduArticle healthEduArticle: healthEduArticleList){
                    articleMap.put(healthEduArticle.getCode(),healthEduArticle);
            Map<String, HealthEduArticle> articleMap = new HashedMap();
            if (healthEduArticleList != null && healthEduArticleList.size() > 0) {
                for (HealthEduArticle healthEduArticle : healthEduArticleList) {
                    articleMap.put(healthEduArticle.getCode(), healthEduArticle);
                }
            }
            //获取所有的健康教育发送记录数量,分页,userType=1
            String countSql = "SELECT COUNT(id) AS num from wlyy_health_edu_article_patient WHERE admin_team_code IS NOT NULL";
            if (StringUtils.isNotBlank(startTimeForSql)){
                countSql += " AND czrq > '"+startTimeForSql+"'";
            if (StringUtils.isNotBlank(startTimeForSql)) {
                countSql += " AND czrq > '" + startTimeForSql + "'";
            }
            Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
            if (countMap!=null) {
            if (countMap != null) {
                int count = Integer.valueOf(String.valueOf(countMap.get("num")));
                double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize*20));
                double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize * 20));
                if (pageCount > 0) {
                    String resultSql = "SELECT " +
                            " ap.patient AS patientCode, " +
@ -336,25 +348,25 @@ public class EduArticleService {
                            " ap.czrq AS createTime, " +
                            " ap.admin_team_code AS adminTeamCode, " +
                            " ap.batch_no AS batchNo, " +
                            " ap.send_type AS sendSource,"+
                            " p.name AS patientName,"+
                            " t.name AS adminTeamName"+
                            " ap.send_type AS sendSource," +
                            " p.name AS patientName," +
                            " t.name AS adminTeamName" +
                            " FROM " +
                            " wlyy_health_edu_article_patient ap " +
                            " LEFT JOIN wlyy_patient p ON ap.patient = p.code " +
                            " LEFT JOIN wlyy_admin_team t ON ap.admin_team_code = t.id " +
                            " WHERE " +
                            " ap.admin_team_code IS NOT NULL ";
                    if (StringUtils.isNotBlank(startTimeForSql)){
                        resultSql += " AND ap.czrq > '"+startTimeForSql+"' ORDER BY ap.czrq ASC limit ?,? ";
                    }else {
                    if (StringUtils.isNotBlank(startTimeForSql)) {
                        resultSql += " AND ap.czrq > '" + startTimeForSql + "' ORDER BY ap.czrq ASC limit ?,? ";
                    } else {
                        resultSql += "  ORDER BY ap.czrq ASC limit ?,? ";
                    }
                    for (int i = 1; i <= pageCount; i++) {
                        int start = (i - 1) * (pageSize*20);
                        List<Map<String,Object>> resultList = jdbcTemplate.queryForList(resultSql,new Object[]{start,pageSize*20});
                        if (CollectionUtils.isEmpty(resultList)){
                        int start = (i - 1) * (pageSize * 20);
                        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(resultSql, new Object[]{start, pageSize * 20});
                        if (CollectionUtils.isEmpty(resultList)) {
                            flag = false;
                            return flag;
                        }
@ -362,9 +374,9 @@ public class EduArticleService {
                        for (Map<String, Object> map : resultList) {
                            HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
                            //Map转对象
                            healthEduArticleES = MapListUtils.convertMap2Bean(map,HealthEduArticleES.class);
                            healthEduArticleES = setDateToObj(healthEduArticleES,doctorMap,articleMap,wjwCode,1);
                            if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
                            healthEduArticleES = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
                            healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 1);
                            if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
                                healthEduArticleES.setDoctorCode(wjwCode);
                                //卫计委发送
                                healthEduArticleES.setSendType(2);
@ -380,10 +392,10 @@ public class EduArticleService {
            }
            //按批次查询文章信息。userType=2
            //要先删除原来的数据。
            String batSql ="SELECT batch_no from wlyy_health_edu_article_patient WHERE admin_team_code IS NOT NULL GROUP BY batch_no ";
            List<Map<String,Object>> batchNoMap = jdbcTemplate.queryForList(batSql);
            if (batchNoMap!=null && batchNoMap.size()>0){
                deleteData(2,batchNoMap);
            String batSql = "SELECT batch_no from wlyy_health_edu_article_patient WHERE admin_team_code IS NOT NULL GROUP BY batch_no ";
            List<Map<String, Object>> batchNoMap = jdbcTemplate.queryForList(batSql);
            if (batchNoMap != null && batchNoMap.size() > 0) {
                deleteData(2, batchNoMap);
            }
            String BartchNoSql = "SELECT " +
@ -394,26 +406,26 @@ public class EduArticleService {
                    " ap.czrq AS createTime, " +
                    " ap.admin_team_code AS adminTeamCode, " +
                    " ap.batch_no AS batchNo, " +
                    " ap.send_type AS sendSource,"+
                    " p.name AS patientName,"+
                    " t.name AS adminTeamName"+
                    " ap.send_type AS sendSource," +
                    " p.name AS patientName," +
                    " t.name AS adminTeamName" +
                    " FROM " +
                    " wlyy_health_edu_article_patient ap " +
                    " LEFT JOIN wlyy_patient p ON ap.patient = p.code " +
                    " LEFT JOIN wlyy_admin_team t ON ap.admin_team_code = t.id" +
                    " WHERE " +
                    " ap.admin_team_code IS NOT NULL GROUP BY ap.batch_no ORDER BY createTime ASC ";
            System.out.println("userType2========="+BartchNoSql);
            List<Map<String,Object>> batchList = jdbcTemplate.queryForList(BartchNoSql);
            System.out.println("userType2=========" + BartchNoSql);
            List<Map<String, Object>> batchList = jdbcTemplate.queryForList(BartchNoSql);
            List<HealthEduArticleES> batchEsList = new ArrayList<>();
            if (batchList!=null && batchList.size()>0){
            if (batchList != null && batchList.size() > 0) {
                for (Map<String, Object> map : batchList) {
                    HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
                    healthEduArticleES.setNewArricleFlag(false);
                    //Map转对象
                    healthEduArticleES = MapListUtils.convertMap2Bean(map,HealthEduArticleES.class);
                    healthEduArticleES = setDateToObj(healthEduArticleES,doctorMap,articleMap,wjwCode,2);
                    if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
                    healthEduArticleES = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
                    healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 2);
                    if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
                        healthEduArticleES.setDoctorCode(wjwCode);
                        //卫计委发送
                        healthEduArticleES.setSendType(2);
@ -425,18 +437,18 @@ public class EduArticleService {
                //保存到Es中
                saveDate(batchEsList);
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag= false;
            flag = false;
        }
        return flag;
    }
    public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES,Map<String,Doctor> doctorMap,Map<String,HealthEduArticle> articleMap,String wjwCode,Integer userType)throws Exception{
    public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES, Map<String, Doctor> doctorMap, Map<String, HealthEduArticle> articleMap, String wjwCode, Integer userType) throws Exception {
        //遍历医生
        Set<Map.Entry<String,Doctor>> doctorSet=doctorMap.entrySet();
        for(Map.Entry<String, Doctor> doctorEntry:doctorSet){
            if (doctorEntry.getKey().equals(healthEduArticleES.getDoctorCode())){
        Set<Map.Entry<String, Doctor>> doctorSet = doctorMap.entrySet();
        for (Map.Entry<String, Doctor> doctorEntry : doctorSet) {
            if (doctorEntry.getKey().equals(healthEduArticleES.getDoctorCode())) {
                Doctor doctor = doctorEntry.getValue();
                healthEduArticleES.setDoctorCode(doctor.getCode());
                healthEduArticleES.setDoctorName(doctor.getName());
@ -454,8 +466,8 @@ public class EduArticleService {
            }
        }
        //遍历文章
        Set<Map.Entry<String,HealthEduArticle>> articleSet=articleMap.entrySet();
        for(Map.Entry<String, HealthEduArticle> articleEntry:articleSet){
        Set<Map.Entry<String, HealthEduArticle>> articleSet = articleMap.entrySet();
        for (Map.Entry<String, HealthEduArticle> articleEntry : articleSet) {
            if (articleEntry.getKey().equals(healthEduArticleES.getArticleId())) {
                HealthEduArticle healthEduArticle = articleEntry.getValue();
                healthEduArticleES.setArticleId(healthEduArticle.getCode());
@ -469,7 +481,7 @@ public class EduArticleService {
        healthEduArticleES.setUserType(userType);
        healthEduArticleES.setOperatorId(wjwCode);
        healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");
        return  healthEduArticleES;
        return healthEduArticleES;
    }
@ -478,39 +490,39 @@ public class EduArticleService {
     *
     * @param
     */
    private Boolean saveDate(List<HealthEduArticleES> sms)throws Exception {
    private Boolean saveDate(List<HealthEduArticleES> sms) throws Exception {
        return SpringUtil.getBean(SaveEduArticleHelper.class).save(sms);
    }
    /**
     * 删除数据
     */
    private void deleteData(int userType,List<Map<String,Object>> batchNoMap) {
    private void deleteData(int userType, List<Map<String, Object>> batchNoMap) {
        JestClient jestClient = null;
        List<HealthEduArticleES> saveModels = new ArrayList<>();
        try {
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
           for (Map<String,Object> map: batchNoMap){
               SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
               BoolQueryBuilder boolQueryBuilder =  new BoolQueryBuilder();
               boolQueryBuilder.must(QueryBuilders.matchQuery("userType",userType));
               boolQueryBuilder.must(QueryBuilders.matchQuery("batchNo",map.get("batch_no")+""));
               searchSourceBuilder.query(boolQueryBuilder).size(100);//一次取10000条
               Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                       .build();
               SearchResult result = jestClient.execute(search);
               List<HealthEduArticleES> healthEduArticleESList =  result.getSourceAsObjectList(HealthEduArticleES.class);
               if (healthEduArticleESList!=null && healthEduArticleESList.size()>0){
                   for (HealthEduArticleES healthEduArticleES : healthEduArticleESList){
                       saveModels.add(healthEduArticleES);
                   }
               }
           }
            for (Map<String, Object> map : batchNoMap) {
                SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
                BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
                boolQueryBuilder.must(QueryBuilders.matchQuery("userType", userType));
                boolQueryBuilder.must(QueryBuilders.matchQuery("batchNo", map.get("batch_no") + ""));
                searchSourceBuilder.query(boolQueryBuilder).size(100);//一次取10000条
                Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                        .build();
                SearchResult result = jestClient.execute(search);
                List<HealthEduArticleES> healthEduArticleESList = result.getSourceAsObjectList(HealthEduArticleES.class);
                if (healthEduArticleESList != null && healthEduArticleESList.size() > 0) {
                    for (HealthEduArticleES healthEduArticleES : healthEduArticleESList) {
                        saveModels.add(healthEduArticleES);
                    }
                }
            }
            //根据id批量删除
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (HealthEduArticleES obj : saveModels) {
                if (obj!=null){
                if (obj != null) {
                    Delete index = new Delete.Builder(obj.getId()).build();
                    bulk.addAction(index);
                }
@ -520,7 +532,7 @@ public class EduArticleService {
            logger.info("delete data count:" + saveModels.size());
            logger.info("delete flag:" + br.isSucceeded());
        } catch (Exception e) {
            System.out.println("======error:"+e.getMessage());
            System.out.println("======error:" + e.getMessage());
            e.printStackTrace();
        } finally {
            if (jestClient != null) {
@ -532,19 +544,19 @@ public class EduArticleService {
    /**
     * 更新es数据库数据
     */
    public boolean updateData(){
    public boolean updateData() {
        boolean flag = true;
        JestClient jestClient = null;
        try{
        try {
            jestClient = elasticFactory.getJestClient();
            //先查询出相关数据
            /*String timeSql ="select * from "+esType+" where userType<>1 and userType<>2 ";
            List<HealthEduArticleES> saveModels = elasticsearchUtil.excute(timeSql,HealthEduArticleES.class,esType,esIndex);*/
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolQueryBuilder =  new BoolQueryBuilder();
            boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType",1));
            boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType",2));
            BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
            boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType", 1));
            boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType", 2));
            searchSourceBuilder.query(boolQueryBuilder).size(100000);//一次取100000条
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
@ -563,14 +575,202 @@ public class EduArticleService {
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("update data count:" + saveModels.size());
            logger.info("update flag:" + br.isSucceeded());
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }finally {
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return flag;
    }
    public Map<String, net.sf.json.JSONObject> getArticleSendToEsByDoctor(String doctorCodes) throws Exception {
        Map<String, net.sf.json.JSONObject> returnMap = new HashedMap();
        String[] doctorCodeArr = doctorCodes.split(",");
        //初始化文章
        for (String doctorCode : doctorCodeArr) {
            net.sf.json.JSONObject o = new net.sf.json.JSONObject();
            //删除医生的推送记录
            deleteEsDataByDoctor(doctorCode);
            //新增医生的推送记录
            Integer size = saveByDoctor(doctorCode);
            o.put("saveEsSize", size);
            returnMap.put(doctorCode, o);
        }
        return returnMap;
    }
    /**
     * 根据code删除ES中的推送表的记录
     *
     * @param doctorCode
     */
    private void deleteEsDataByDoctor(String doctorCode) {
        JestClient jestClient = null;
        try {
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(
                    new BoolQueryBuilder()
                            .must(QueryBuilders.matchQuery("quotaCode", doctorCode))
            ).size(500000);//一次取10000条
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                    .build();
            SearchResult result = jestClient.execute(search);
            List<HealthEduArticleES> healthEduArticleESs = result.getSourceAsObjectList(HealthEduArticleES.class);
            //根据id批量删除
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (HealthEduArticleES obj : healthEduArticleESs) {
                Delete index = new Delete.Builder(obj.getId()).build();
                bulk.addAction(index);
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("delete data count:" + healthEduArticleESs.size());
            logger.info("delete flag:" + br.isSucceeded());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
    }
    /**
     * 保存推送记录到ES中
     *
     * @param doctorCode
     */
    private Integer saveByDoctor(String doctorCode) throws Exception {
        Doctor doctor = doctorDao.findByCode(doctorCode);
        //1.查询出所有的文章列表
        List<HealthEduArticle> healthEduArticleList = healthEduArticleDao.findAllArticle();
        Map<String, HealthEduArticle> articleMap = new HashedMap();//key是文章code
        if (healthEduArticleList != null && healthEduArticleList.size() > 0) {
            for (HealthEduArticle healthEduArticle : healthEduArticleList) {
                articleMap.put(healthEduArticle.getCode(), healthEduArticle);
            }
        }
        //2.获取医生的推送记录
        String sql = "select * from wlyy_health_edu_article_patient where doctor='" + doctorCode + "'";
        List<HealthEduArticlePatient> healthEduArticlePatients = jdbcTemplate.query(sql, new BeanPropertyRowMapper(HealthEduArticlePatient.class));
        //推送记录按照批次号分组
        Map<String, List<HealthEduArticlePatient>> healthEduArticlePatientMap = new HashMap<>();
        healthEduArticlePatients.stream().forEach(one -> {
            List<HealthEduArticlePatient> healthEduArticlePatientTemp = healthEduArticlePatientMap.get(one.getBatchNo());
            if (healthEduArticlePatientTemp == null) {
                healthEduArticlePatientTemp = new ArrayList<HealthEduArticlePatient>();
            }
            healthEduArticlePatientTemp.add(one);
            healthEduArticlePatientMap.put(one.getBatchNo(), healthEduArticlePatientTemp);
        });
        //3.转换成新的健康教育需要的数据
        List<HealthEduArticleES> healthEduArticleESSaveList = new ArrayList<>();
        //获取医生的角色
        Map<String,Object> roleMaps=  gcLabelService.fetchUserHighestAuthority(doctorCode);
        healthEduArticlePatientMap.keySet().stream().forEach(one -> {
            //获取患者数据
            List<HealthEduArticlePatient> healthEduArticlePatientTemps = healthEduArticlePatientMap.get(one);
            AdminTeam adminTeam = doctorAdminTeamDao.findOne(healthEduArticlePatientTemps.get(0).getId());
            //遍历数据
            healthEduArticlePatientTemps.stream().forEach(healthEduArticlePatient -> {
                //3,1 保存userType=1的
                HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
                healthEduArticleES.setDoctorCode(doctorCode);
                healthEduArticleES.setDoctorName(doctor.getName());
                healthEduArticleES.setSendName(doctor.getName());
                healthEduArticleES.setSendSex(doctor.getSex().toString());
                healthEduArticleES.setSendPic(doctor.getPhoto());
                healthEduArticleES.setSendLevel(doctor.getLevel().toString());
                healthEduArticleES.setSendSource(1);//旧数据都是1 i健康发送
                healthEduArticleES.setSendType(1);//默认是医生发送
                if(roleMaps!=null){
                   // healthEduArticleES.setCurrentUserRoleLevel("2");
                   // healthEduArticleES.setCurrentUserRoleCode();
                }else{
                }
                healthEduArticleES.setBatchNo(healthEduArticlePatient.getBatchNo());
                healthEduArticleES.setPatientCode(healthEduArticlePatient.getPatient());
                healthEduArticleES.setPatientName(patientDao.findByCode(healthEduArticlePatient.getPatient()).getName());
                HealthEduArticle healthEduArticle = articleMap.get(healthEduArticlePatient.getArticle());
                healthEduArticleES.setArticleId(healthEduArticle.getCode());
                healthEduArticleES.setArticleContent(healthEduArticle.getContent());
                healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
                healthEduArticleES.setIsRead(healthEduArticlePatient.getRead());
                healthEduArticleES.setOperatorId(doctorCode); //之前旧数据没有文章作者 默认是发送人
                healthEduArticleES.setArticleCover(healthEduArticle.getUrl());
                healthEduArticleES.setArticleSource(adminTeam.getOrgName());//文章来源 旧数据默认是医生的所在团队的所属机构
                healthEduArticleES.setAdminTeamCode(adminTeam.getId());
                healthEduArticleES.setAdminTeamName(adminTeam.getName());
                healthEduArticleES.setHospital(adminTeam.getOrgCode());
                healthEduArticleES.setHospitalName(adminTeam.getOrgName());
                healthEduArticleES.setTown(adminTeam.getTownCode());
                healthEduArticleES.setTownName(adminTeam.getTownName());
                healthEduArticleES.setCreateTime(new Date());
                healthEduArticleES.setUserType(1);//患者
                healthEduArticleESSaveList.add(healthEduArticleES);
            });
            //3,2 保存userType=2的
            HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
            healthEduArticleES.setDoctorCode(doctorCode);
            healthEduArticleES.setDoctorName(doctor.getName());
            healthEduArticleES.setSendName(doctor.getName());
            healthEduArticleES.setSendSex(doctor.getSex().toString());
            healthEduArticleES.setSendPic(doctor.getPhoto());
            healthEduArticleES.setSendLevel(doctor.getLevel().toString());
            healthEduArticleES.setSendSource(1);//旧数据都是1 i健康发送
            healthEduArticleES.setSendType(1);//默认是医生发送
            healthEduArticleES.setBatchNo(healthEduArticlePatientTemps.get(0).getBatchNo());
            HealthEduArticle healthEduArticle = articleMap.get(healthEduArticlePatientTemps.get(0).getArticle());
            healthEduArticleES.setArticleId(healthEduArticle.getCode());
            healthEduArticleES.setArticleContent(healthEduArticle.getContent());
            healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
            healthEduArticleES.setOperatorId(doctorCode); //之前旧数据没有文章作者 默认是发送人
            healthEduArticleES.setArticleCover(healthEduArticle.getUrl());
            healthEduArticleES.setArticleSource(adminTeam.getOrgName());//文章来源 旧数据默认是医生的所在团队的所属机构
            healthEduArticleES.setAdminTeamCode(adminTeam.getId());
            healthEduArticleES.setAdminTeamName(adminTeam.getName());
            healthEduArticleES.setHospital(adminTeam.getOrgCode());
            healthEduArticleES.setHospitalName(adminTeam.getOrgName());
            healthEduArticleES.setTown(adminTeam.getTownCode());
            healthEduArticleES.setTownName(adminTeam.getTownName());
            healthEduArticleES.setUserType(2); //医生
            healthEduArticleES.setAllCount(healthEduArticlePatientTemps.size());
            healthEduArticleES.setCreateTime(new Date());
            healthEduArticleESSaveList.add(healthEduArticleES);
        });
        //数据存到ES
        saveDate(healthEduArticleESSaveList);
        return healthEduArticleESSaveList.size();
    }
}

+ 3 - 3
patient-co/patient-co-wlyy/src/main/resources/application-devtest.yml

@ -105,11 +105,11 @@ pushMes:
  redis_prescription_title: redisMessage
es:
  index:
    HealthEduArticlePatient: health_edu_article_patient_test3
    HealthEduArticlePatient: health_edu_article_patient_test6
    FollowUp: wlyy_followup
    Statistics: wlyy_quota_test
  type:
    HealthEduArticlePatient: health_edu_article_patient_test3
    HealthEduArticlePatient: health_edu_article_patient_test6
    FollowUpContent: wlyy_followup_content
    Statistics: wlyy_quota_test
  host:  http://172.19.103.68:9200
@ -129,7 +129,7 @@ activemq:
  password: admin
  url: tcp://172.19.103.87:61616
  queue:
    healtHarticleQueue: healthArticleChannel_test  #健康文章推送
    healtHarticleQueue: healthArticleChannel_devtest  #健康文章推送
##如果是外网项目就是flase 内网是true
neiwang: