Просмотр исходного кода

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

liuwenbin 7 лет назад
Родитель
Сommit
f2c857801b
14 измененных файлов с 589 добавлено и 79 удалено
  1. 1 1
      common/common-entity/src/main/java/com/yihu/edu/entity/dataClean/NewArticleBehaviorModel.java
  2. 1 1
      common/common-entity/src/main/java/com/yihu/edu/entity/dataClean/NewArticleCollectModel.java
  3. 1 1
      common/common-entity/src/main/java/com/yihu/edu/entity/dataClean/NewArticleModel.java
  4. 75 0
      common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticleESResult.java
  5. 4 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/DoctorAdminTeamDao.java
  6. 5 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/education/HealthEduArticleDao.java
  7. 26 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/ServiceStatisticsService.java
  8. 143 7
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java
  9. 2 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/jimeiJkEdu/JMJkEduArticleService.java
  10. 3 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/HealthEduArticleController.java
  11. 2 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java
  12. 186 61
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/service/EduArticleService.java
  13. 112 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/vo/save/ElastricSearchSaveEduArticle.java
  14. 28 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/vo/save/SaveEduArticleHelper.java

+ 1 - 1
common/common-entity/src/main/java/com/yihu/edu/entity/dataClean/NewArticleBehaviorModel.java

@ -7,7 +7,7 @@ import java.util.Date;
 * Created by Administrator on 2017/12/25.
 */
@Entity
@Table(name = "user_behavior_copy")
@Table(name = "user_behavior")
public class NewArticleBehaviorModel {
    private int ID;

+ 1 - 1
common/common-entity/src/main/java/com/yihu/edu/entity/dataClean/NewArticleCollectModel.java

@ -12,7 +12,7 @@ import java.util.Date;
 * Created by Administrator on 2017/9/29.
 */
@Entity
@Table(name = "user_articlecollection_copy")
@Table(name = "user_articlecollection")
public class NewArticleCollectModel {
    private  int ID;

+ 1 - 1
common/common-entity/src/main/java/com/yihu/edu/entity/dataClean/NewArticleModel.java

@ -13,7 +13,7 @@ import java.util.Date;
 * Created by zhangdan on 2017/9/29.
 */
@Entity
@Table(name = "org_article_copy")
@Table(name = "org_article")
public class NewArticleModel {
    //文章ID
    private String articleId;

+ 75 - 0
common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticleESResult.java

@ -0,0 +1,75 @@
package com.yihu.es.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.searchbox.annotations.JestId;
import org.springframework.data.annotation.CreatedDate;
import java.util.Date;
import java.util.List;
/**
 * 推送记录表
 * Created by chenweida on 2017/9/7.
 */
public class HealthEduArticleESResult {
    private Double batchCount;
    private Double articleCount;
    private Double addBatchno;
    private Double addCount;
    private String doctorCode;
    private Date createTime;
    public Double getBatchCount() {
        return batchCount;
    }
    public void setBatchCount(Double batchCount) {
        this.batchCount = batchCount;
    }
    public Double getArticleCount() {
        return articleCount;
    }
    public void setArticleCount(Double articleCount) {
        this.articleCount = articleCount;
    }
    public Double getAddBatchno() {
        return addBatchno;
    }
    public void setAddBatchno(Double addBatchno) {
        this.addBatchno = addBatchno;
    }
    public Double getAddCount() {
        return addCount;
    }
    public void setAddCount(Double addCount) {
        this.addCount = addCount;
    }
    public String getDoctorCode() {
        return doctorCode;
    }
    public void setDoctorCode(String doctorCode) {
        this.doctorCode = doctorCode;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

+ 4 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/DoctorAdminTeamDao.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.patient.Patient;
import org.apache.axis.utils.Admin;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@ -96,4 +97,7 @@ public interface DoctorAdminTeamDao extends
    //  查询当前医生是否为团队长
    @Query("SELECT t.id from AdminTeam t WHERE t.available = true  AND t.leaderCode = ?1 ")
    Integer findLeader(String leaderCode);
    @Query("select t from AdminTeam t where t.available = true")
    List<AdminTeam> findAllAvailableAdminTeam();
}

+ 5 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/education/HealthEduArticleDao.java

@ -8,6 +8,8 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import com.yihu.wlyy.entity.education.HealthEduArticle;
import java.util.List;
public interface HealthEduArticleDao extends PagingAndSortingRepository<HealthEduArticle, Long>, JpaSpecificationExecutor<HealthEduArticle> {
@ -16,4 +18,7 @@ public interface HealthEduArticleDao extends PagingAndSortingRepository<HealthEd
	@Query("SELECT a FROM HealthEduArticle a WHERE (a.title like ?1 or a.keyword like ?2) ORDER BY a.czrq DESC")
	Page<HealthEduArticle> list(String title, String keyword, Pageable pageRequest);
	@Query("select a from HealthEduArticle a")
	List<HealthEduArticle> findAllArticle();
}

+ 26 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/ServiceStatisticsService.java

@ -6,9 +6,11 @@ import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ElasticsearchUtil;
import io.swagger.annotations.ApiParam;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -32,6 +34,14 @@ public class ServiceStatisticsService extends BaseService {
    @Autowired
    AdminTeamService teamService;
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
    @Value("${es.index.HealthEduArticlePatient}")
    private String esIndex;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    public JSONObject getServiceStatistics(String patient, long teamCode, String doctor) throws Exception {
        JSONObject result = new JSONObject();
        AdminTeam team = teamService.getTeam(teamCode);
@ -142,11 +152,11 @@ public class ServiceStatisticsService extends BaseService {
     * @return
     */
    public JSONObject getArticleStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
        JSONObject result = new JSONObject();
               JSONObject result = new JSONObject();
        result.put("history", 0);
        result.put("year", 0);
        result.put("month", 0);
        String sqlHistory = "select count(1) h from wlyy_health_edu_article_patient where patient = ? and admin_team_code = ?";
       /* String sqlHistory = "select count(1) h from wlyy_health_edu_article_patient where patient = ? and admin_team_code = ?";
        String sqlYear = "select count(1) y from wlyy_health_edu_article_patient where patient = ? and admin_team_code = ? and czrq >= ? and czrq <= ?";
        String sqlMonth = "select count(1) m from wlyy_health_edu_article_patient where patient = ? and admin_team_code = ? and czrq >= ?";
        String sql = "select * from " +
@ -162,11 +172,24 @@ public class ServiceStatisticsService extends BaseService {
            result.put("history", counts.get(0).get("h").toString());
            result.put("year", counts.get(0).get("y").toString());
            result.put("month", counts.get(0).get("m").toString());
        }
        }*/
        //数据转移至Es
        String sqlHistory="select count(*) AS h from " + esType + " where patients.code='" + patient + "' and adminTeamCode = '"+teamCode+"'";
        String sqlYear = "select count(*) AS y from "+esType+" where patients.code='" + patient + "' and adminTeamCode = '"+teamCode+"' and czrq >= "+changeDate(yearBegin)+" and czrq <= "+changeDate(yearEnd);
        String sqlMonth = "select count(*) AS m from "+esType+" where patients.code='" + patient + "' and adminTeamCode = '"+teamCode+"' and czrq >= "+changeDate(monthBegin);
        result.put("history", elasticsearchUtil.excuteForLong(sqlHistory,esType,esIndex));
        result.put("year", elasticsearchUtil.excuteForLong(sqlYear,esType,esIndex));
        result.put("month", elasticsearchUtil.excuteForLong(sqlMonth,esType,esIndex));
        return result;
    }
    private String changeDate(String quotaDate) {
        return quotaDate + "T00:00:00+0800";
    }
    /**
     * 健康指导统计

+ 143 - 7
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -1,5 +1,7 @@
package com.yihu.wlyy.service.app.statistics;
import com.yihu.es.entity.HealthEduArticleES;
import com.yihu.es.entity.HealthEduArticleESResult;
import com.yihu.wlyy.entity.address.Town;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
@ -15,10 +17,7 @@ import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.statistics.PopulationBaseDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.util.Constant;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.MapListUtils;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.util.*;
import io.swagger.models.auth.In;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.time.DateUtils;
@ -67,9 +66,15 @@ public class StatisticsService extends BaseService {
    private StringRedisTemplate redisTemplate;
    @Autowired
    private StatisticsAllService statisticsAllService;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Value("${im.data_base_name}")
    private String im_dataBase_name;
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
    @Value("${es.index.HealthEduArticlePatient}")
    private String esIndex;
    /**
     * 获取上次统计时间
@ -3987,7 +3992,7 @@ public class StatisticsService extends BaseService {
    public JSONArray getTeamEduList(String teamCode, String startDate, String endDate, String sort, String sortType) {
        startDate = DateUtil.getNextDay(startDate,-1)+" 17:00:00";
        endDate = endDate + " 17:00:00";
        endDate = endDate+" 17:00:00";
        String totalSql = "SELECT " +
                " IFNULL(c.articleCount,0) AS articleCount, " +
@ -4020,13 +4025,13 @@ public class StatisticsService extends BaseService {
                totalSql = totalSql + " ORDER BY articleCount DESC";
            } else if ("2".equals(sortType)) {
                //总批次
                totalSql = totalSql + " ORDER BY batchno DESC";
                totalSql = totalSql + " ORDER BY batchCount DESC";
            }
        } else {
            if ("0".equals(sortType)) {
                totalSql = totalSql + " ORDER BY articleCount ASC";
            } else if ("2".equals(sortType)) {
                totalSql = totalSql + " ORDER BY batchno ASC";
                totalSql = totalSql + " ORDER BY batchCount ASC";
            }
        }
        String addSql = "SELECT " +
@ -4123,6 +4128,132 @@ public class StatisticsService extends BaseService {
        }
    }
    public JSONArray getTeamEduListFromEs(String teamCode, String startDate, String endDate, String sort, String sortType) {
        startDate = changeDate(DateUtil.getNextDay(startDate,-1));
        endDate = changeDate(endDate);
        String totalSql =
                "SELECT count(DISTINCT batchNo) AS batchCount, count(*) AS articleCount,doctorCode" +
                        " FROM " +esType+
                        " where adminTeamCode = "+teamCode+" and " +
                        " createTime <= '"+endDate+"' group by doctorCode";
        if ("0".equals(sort)) {
            //降序
            if ("0".equals(sortType)) {
                //总人次
                totalSql = totalSql + " ORDER BY articleCount DESC";
            } else if ("2".equals(sortType)) {
                //总批次
                totalSql = totalSql + " ORDER BY batchCount DESC";
            }
        } else {
            if ("0".equals(sortType)) {
                totalSql = totalSql + " ORDER BY articleCount ASC";
            } else if ("2".equals(sortType)) {
                totalSql = totalSql + " ORDER BY batchCount ASC";
            }
        }
        String addSql=
                "SELECT count(DISTINCT batchNo) AS addBatchno, count(*) AS addCount,doctorCode" +
                        " FROM " +esType+
                        " where adminTeamCode = "+teamCode+" and " +
                        "createTime >= '"+startDate+"' and createTime <= '"+endDate+"' group by doctorCode";
        if ("0".equals(sort)) {
            if ("1".equals(sortType)) {
                addSql = addSql + " ORDER BY addCount DESC";
            } else if ("3".equals(sortType)) {
                addSql = addSql + " ORDER BY addBatchno DESC";
            }
        } else {
            if ("1".equals(sortType)) {
                addSql = addSql + " ORDER BY addCount ASC";
            } else if ("3".equals(sortType)) {
                addSql = addSql + " ORDER BY addBatchno ASC";
            }
        }
        //查询出所有这个团队code的医生
        String doctorSql ="SELECT d.name,d.code AS doctorCode FROM  wlyy_doctor d " +
                "LEFT JOIN wlyy_admin_team_member m ON d.code = m.doctor_code " +
                "WHERE m.available=1 AND m.team_id="+teamCode;
        List<Map<String, Object>> doctorList = jdbcTemplate.queryForList(doctorSql);
        List<HealthEduArticleESResult> totalList = elasticsearchUtil.excute(totalSql,HealthEduArticleESResult.class,esType,esIndex);
        List<HealthEduArticleESResult> addList = elasticsearchUtil.excute(addSql,HealthEduArticleESResult.class,esType,esIndex);
        if (doctorList!=null && doctorList.size()>0){
            for (Map<String,Object> doctorMap : doctorList){
                doctorMap.put("batchno","0");
                doctorMap.put("articleCount","0");
                doctorMap.put("addBatchno","0");
                doctorMap.put("addCount","0");
                //循环总数
                if (totalList!=null && totalList.size()>0){
                    for (HealthEduArticleESResult healthEduArticleESResultTotal :totalList){
                        if (String.valueOf(doctorMap.get("doctorCode")).equals(healthEduArticleESResultTotal.getDoctorCode())){
                            doctorMap.put("batchno",healthEduArticleESResultTotal.getBatchCount());
                            doctorMap.put("articleCount",healthEduArticleESResultTotal.getArticleCount());
                        }
                    }
                }
                //循环新增
                if (addList!=null && addList.size()>0){
                    for (HealthEduArticleESResult healthEduArticleESResultAdd :addList){
                        if (String.valueOf(doctorMap.get("doctorCode")).equals(healthEduArticleESResultAdd.getDoctorCode())){
                            doctorMap.put("addBatchno",healthEduArticleESResultAdd.getAddBatchno());
                            doctorMap.put("addCount",healthEduArticleESResultAdd.getAddCount());
                        }
                    }
                }
            }
        }
        return  new JSONArray(doctorList);
    }
    public JSONObject getTeamDoctorEduTitleFromEs(String teamCode, String startDate, String endDate, String doctor) {
        startDate = changeDate(DateUtil.getNextDay(startDate,-1));
        endDate = changeDate(endDate);
        String totalSql = "select count(*) AS articleCount,count(DISTINCT batchNo) AS batchCount " +
                " from " +esType+
                " where adminTeamCode="+teamCode+" and doctorCode='"+doctor+"' and createTime <='"+endDate+"'";
        String addSql = "SELECT " +
                " COUNT(*) AS addCount, " +
                " COUNT(DISTINCT batchNo) addBatchno " +
                " FROM " + esType +
                " WHERE " +
                " adminTeamCode =" + teamCode +
                " AND doctorCode ='" + doctor + "'" +
                " AND createTime <= '" + endDate + "' " +
                " AND createTime >= '" + startDate + "'";
        List<HealthEduArticleESResult> totalList = elasticsearchUtil.excute(totalSql,HealthEduArticleESResult.class,esType,esIndex);
        List<HealthEduArticleESResult> addList = elasticsearchUtil.excute(addSql,HealthEduArticleESResult.class,esType,esIndex);
        JSONObject rs = new JSONObject();
        //转换到map
        List<Map<String,Object>> totalMapList = new ArrayList<>();
        Map<String,Object> totalMap = new HashedMap();
        totalMap.put("batchno","0");
        totalMap.put("articleCount","0");
        if (totalList!=null && totalList.size()>0){
            totalMap.put("batchno",totalList.get(0).getBatchCount());
            totalMap.put("articleCount",totalList.get(0).getArticleCount());
        }
        totalMapList.add(totalMap);
        //转换到map
        List<Map<String,Object>> addMapList = new ArrayList<>();
        Map<String,Object> addMap = new HashedMap();
        addMap.put("addCount","0");
        addMap.put("addBatchno","0");
        if (addList!=null && addList.size()>0){
            totalMap.put("addCount",addList.get(0).getAddCount());
            totalMap.put("addBatchno",addList.get(0).getAddBatchno());
        }
        addMapList.add(addMap);
        rs.put("totalList", totalMapList);
        rs.put("addList", addMapList);
        return rs;
    }
    public JSONObject getTeamDoctorEduTitle(String teamCode, String startDate, String endDate, String doctor) {
        startDate = DateUtil.getNextDay(startDate,-1)+" 17:00:00";
        endDate = endDate + " 17:00:00";
@ -6946,5 +7077,10 @@ public class StatisticsService extends BaseService {
        }
        return resultList;
    }
    private String changeDate(String quotaDate) {
        return quotaDate + "T17:00:00+0800";
    }
}

+ 2 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/jimeiJkEdu/JMJkEduArticleService.java

@ -1070,7 +1070,7 @@ public class JMJkEduArticleService extends BaseService {
     * 一键修改居民推送文章的文章为已读
     * @param patient
     */
    public void readAllArticleNew(String patient){
    public void readAllArticleNew(String patient,String firstLevelCategoryId){
        JestClient jestClient = null;
    
        try {
@ -1079,6 +1079,7 @@ public class JMJkEduArticleService extends BaseService {
            searchSourceBuilder.query(
                    new BoolQueryBuilder()
                            .must(QueryBuilders.matchQuery("patientCode", patient))
                            .must(QueryBuilders.matchQuery("firstLevelCategoryId", firstLevelCategoryId))
            );
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType).build();
            SearchResult result = jestClient.execute(search);

+ 3 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/HealthEduArticleController.java

@ -207,12 +207,13 @@ public class HealthEduArticleController extends BaseController {
    @RequestMapping(value = "/readAllArticle", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("对当前用户的所有未读文章设置为已读")
    public String readAllArticle() {
    public String readAllArticle(@ApiParam(name = "firstLevelCategoryId", value = "一级分类ID")
                                     @RequestParam(value = "firstLevelCategoryId", required = true) String firstLevelCategoryId) {
        try {
//            String patient = getUID();
            String patient = getRepUID();
//            healthEduArticleService.readAllArticle(patient);
            jmJkEduArticleService.readAllArticleNew(patient);
            jmJkEduArticleService.readAllArticleNew(patient,firstLevelCategoryId);
            return write(200, "更改状态成功!");
        } catch (Exception e) {
            error(e);

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java

@ -1416,7 +1416,7 @@ public class EsStatisticsController extends BaseController {
                                 @RequestParam(required = true) String sort,
                                 @RequestParam(required = true) String sortType) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamEduList(teamCode, startDate, endDate, sort, sortType));
            return write(200, "查询成功", "data", statisticsService.getTeamEduListFromEs(teamCode, startDate, endDate, sort, sortType));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1430,7 +1430,7 @@ public class EsStatisticsController extends BaseController {
                                        @RequestParam(required = true) String endDate,
                                        @RequestParam(required = true) String doctor) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorEduTitle(teamCode, startDate, endDate, doctor));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorEduTitleFromEs(teamCode, startDate, endDate, doctor));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");

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

@ -2,21 +2,32 @@ package com.yihu.wlyy.web.third.jkedu.service;
import com.yihu.edu.entity.dataClean.*;
import com.yihu.es.entity.HealthEduArticlePatient;
import com.yihu.es.entity.HealthEduArticleES;
import com.yihu.es.entity.HealthEduArticleESResult;
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.patient.Patient;
import com.yihu.wlyy.jkedu.repository.JkeduArticleDao;
import com.yihu.wlyy.jkedu.repository.JkeduBehaviorArticleDao;
import com.yihu.wlyy.jkedu.repository.JkeduCollectionArticleDao;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.education.HealthEduArticleDao;
import com.yihu.wlyy.repository.patient.PatientDao;
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.jkedu.vo.save.SaveEduArticleHelper;
import org.apache.axis.utils.Admin;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
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.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -35,7 +46,9 @@ public class EduArticleService {
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private ElastricSearchSave elastricSearchSave;
    private PatientDao patientDao;
    @Autowired
    private DoctorAdminTeamDao doctorAdminTeamDao;
    @Autowired
    private HealthEduArticleDao healthEduArticleDao;
    @Autowired
@ -44,6 +57,8 @@ public class EduArticleService {
    private JkeduCollectionArticleDao jkeduCollectionArticleDao;
    @Autowired
    private JkeduBehaviorArticleDao jkeduBehaviorArticleDao;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
@ -270,27 +285,84 @@ public class EduArticleService {
            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") + "";
            //转移到数据库的时候按照批次来聚合
            sql = "SELECT batch_no ,article,doctor,doctor_name,admin_team_code,czrq " +
                    " FROM wlyy_health_edu_article_patient " +
                    " WHERE  batch_no IS NOT NULL GROUP BY batch_no";
            List<Map<String,Object>> resultList = jdbcTemplate.queryForList(sql);
            if (CollectionUtils.isEmpty(resultList)){
                return flag;
            //查询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");
            //查询出所有的医生
            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);
                }
            }
            //查询出所有的文章列表
            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);
                }
            }
            //获取所有的健康教育发送记录数量,分页
            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+"'";
            }
            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*20));
                if (pageCount > 0) {
                    String resultSql = "SELECT " +
                            " ap.patient AS patientCode, " +
                            " ap.article AS articleId, " +
                            " ap.doctor AS doctorCode, " +
                            " ap.is_read AS isRead, " +
                            " ap.czrq AS createTime, " +
                            " ap.admin_team_code AS adminTeamCode, " +
                            " ap.batch_no AS batchNo, " +
                            " 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 {
                        resultSql += " ORDER BY ap.czrq ASC limit ?,?";
                    }
            for (Map<String, Object> map: resultList){
                List<Map<String,Object>> articleList = null;
                String batchNo = map.get("batch_no")+"";
                String article = map.get("article")+"";
                String doctorCode = map.get("doctor")+"";
                String adminTeamId = map.get("admin_team_code")+"";
                String  czrq =  map.get("czrq")+"";
                //同一个批次号只会有一篇文章
                String batchSql = "select * from wlyy_health_edu_article_patient where batch_no = '"+batchNo+"'";
                HealthEduArticlePatient healthEduArticlePatient = setDateToObj(batchSql,doctorCode,adminTeamId,wjwCode,batchNo,article,czrq);
                //保存到Es中
                elastricSearchSave.save(healthEduArticlePatient, esIndex, esType);
                    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)){
                            flag = false;
                            return flag;
                        }
                        List<HealthEduArticleES> esList = new ArrayList<>();
                        for (Map<String, Object> map : resultList) {
                            HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
                            //Map转对象
                            healthEduArticleES = MapListUtils.convertMap2Bean(map,HealthEduArticleES.class);
                            healthEduArticleES = setDateToObj(healthEduArticleES,doctorMap,articleMap,wjwCode);
                            if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
                                healthEduArticleES.setDoctorCode(wjwCode);
                                healthEduArticleES.setSendCode(wjwCode);
                                healthEduArticleES.setSendName("厦门市卫生与计划生育委员会");
                                healthEduArticleES.setDoctorName("厦门市卫生与计划生育委员会");
                            }
                            esList.add(healthEduArticleES);
                        }
                        //保存到Es中
                        saveDate(esList);
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
@ -299,56 +371,109 @@ public class EduArticleService {
        return flag;
    }
    public HealthEduArticlePatient setDateToObj(String batchSql,String doctorCode,String adminTeamId,String wjwCode,String batchNo,String article,String czrq)throws Exception{
        HealthEduArticlePatient healthEduArticlePatient = new HealthEduArticlePatient();
        //创建对象
        List<Map<String,Object>> articleList= jdbcTemplate.queryForList(batchSql);
        //放置患者集合
        if (!CollectionUtils.isEmpty(articleList)){
            List<Patient> patientList = new ArrayList<>();
            for (Map<String,Object> sendMap: articleList){
                patientList.add(new Patient(sendMap.get("patient")+""));
    public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES,Map<String,Doctor> doctorMap,Map<String,HealthEduArticle> articleMap,String wjwCode)throws Exception{
        //遍历医生
        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());
                healthEduArticleES.setSendCode(doctor.getCode());
                healthEduArticleES.setSendName(doctor.getCode());
                healthEduArticleES.setSendPic(doctor.getPhoto());
                healthEduArticleES.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
                healthEduArticleES.setHospital(doctor.getHospital());
                healthEduArticleES.setHospitalName(doctor.getHospitalName());
                healthEduArticleES.setTown(doctor.getTown());
                healthEduArticleES.setTownName(doctor.getTownName());
                healthEduArticleES.setSendType(1);
                healthEduArticleES.setSendLevel(doctor.getLevel() != null ? String.valueOf(doctor.getLevel()) : "");
            }
        }
        //遍历文章
        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());
                healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
                healthEduArticleES.setArticleContent(healthEduArticle.getSummary());
            }
            healthEduArticlePatient.setPatients(patientList);
        }
        healthEduArticleES.setSendType(2);
        healthEduArticleES.setOperatorId(wjwCode);
        healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");
        return  healthEduArticleES;
    }
    public HealthEduArticleES setDateToObj1(Map<String,Object> map, String wjwCode)throws Exception{
        HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
        String article = map.get("article")+"";
        String doctorCode = map.get("doctor")+"";
        String adminTeamId = map.get("admin_team_code")+"";
        String  czrq =  map.get("czrq")+"";
        String patient = map.get("patient")+"";
        //数据放入对象中
        if (map.get("batch_no")!=null){
            healthEduArticleES.setBatchNo(map.get("batch_no")+"");
        }
        healthEduArticleES.setPatientCode(patient);
        Patient patientObj = patientDao.findByCode(patient);
        if (patientObj!=null){
            healthEduArticleES.setPatientName(patientObj.getName());
        }
        Doctor doctor = doctorDao.findByCode(doctorCode);
        healthEduArticlePatient.setAdminTeamCode(Long.valueOf(adminTeamId));
        if (doctor!=null){
            healthEduArticlePatient.setDoctorCode(doctor.getCode());
            healthEduArticlePatient.setSendName(doctor.getCode());
            healthEduArticlePatient.setDoctorName(doctor.getName());
            healthEduArticlePatient.setSendType(1);
            healthEduArticlePatient.setHospital(doctor.getHospital());
            healthEduArticlePatient.setHospitalName(doctor.getHospitalName());
            healthEduArticlePatient.setTown(doctor.getTown());
            healthEduArticlePatient.setTownName(doctor.getTownName());
            healthEduArticlePatient.setSendLevel(doctor.getLevel() != null ? String.valueOf(doctor.getLevel()) : "");
            healthEduArticlePatient.setSendPic(doctor.getPhoto());
            healthEduArticlePatient.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
            healthEduArticleES.setDoctorCode(doctor.getCode());
            healthEduArticleES.setDoctorName(doctor.getName());
            healthEduArticleES.setSendCode(doctor.getCode());
            healthEduArticleES.setSendName(doctor.getCode());
            healthEduArticleES.setSendPic(doctor.getPhoto());
            healthEduArticleES.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
            healthEduArticleES.setHospital(doctor.getHospital());
            healthEduArticleES.setHospitalName(doctor.getHospitalName());
            healthEduArticleES.setTown(doctor.getTown());
            healthEduArticleES.setTownName(doctor.getTownName());
            healthEduArticleES.setSendType(1);
            healthEduArticleES.setSendLevel(doctor.getLevel() != null ? String.valueOf(doctor.getLevel()) : "");
        }else{
            healthEduArticlePatient.setDoctorCode(wjwCode);
            healthEduArticlePatient.setSendName("厦门市卫生与计划生育委员会");
            healthEduArticlePatient.setDoctorName("厦门市卫生与计划生育委员会");
            healthEduArticlePatient.setSendType(2);
            healthEduArticleES.setDoctorCode(wjwCode);
            healthEduArticleES.setSendName("厦门市卫生与计划生育委员会");
            healthEduArticleES.setDoctorName("厦门市卫生与计划生育委员会");
            healthEduArticleES.setSendType(2);
        }
        healthEduArticlePatient.setBatchNo(batchNo);
        Date czrqDate = DateUtil.strToDate(czrq);
        healthEduArticlePatient.setCreateTime(czrqDate);
        healthEduArticleES.setAdminTeamCode(Long.valueOf(adminTeamId));
        AdminTeam adminTeam = doctorAdminTeamDao.findOne(Long.valueOf(adminTeamId));
        if (adminTeam!=null){
            healthEduArticleES.setAdminTeamName(adminTeam.getName());
        }
        Date czrqDate = DateUtil.strToDate(czrq.substring(0,czrq.lastIndexOf(".")));
        healthEduArticleES.setCreateTime(czrqDate);
        //获取文章详情
        HealthEduArticle healthEduArticle = healthEduArticleDao.findByCode(article);
        healthEduArticlePatient.setArticleId(healthEduArticle.getCode());
        healthEduArticlePatient.setAttachedTitle(healthEduArticle.getTitle());
        healthEduArticlePatient.setAttachedContent(healthEduArticle.getContent());
        healthEduArticlePatient.setArticleType("2");
        healthEduArticlePatient.setLevel("1");
        healthEduArticlePatient.setType("1");//文章
        //healthEduArticlePatient.setAttachedPic("");
        //healthEduArticlePatient.setAttachedMessage(sendMessage);
        //healthEduArticlePatient.setLevel1Type(article.get("firstLevelCategoryId") + "");
        //healthEduArticlePatient.setLevel2Type(article.get("secondLevelCategoryId") + "");
        return  healthEduArticlePatient;
        healthEduArticleES.setArticleId(healthEduArticle.getCode());
        healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
        healthEduArticleES.setArticleContent(healthEduArticle.getSummary());
        //healthEduArticleES.setArticleContent("abc");
        healthEduArticleES.setOperatorId(wjwCode);
        healthEduArticleES.setIsRead(Integer.valueOf(map.get("is_read")+""));
        healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");
        if (map.get("send_type")!=null){
            healthEduArticleES.setSendSource(Integer.valueOf(map.get("send_type")+""));
        }
        return  healthEduArticleES;
    }
    /**
     * 保存数据
     *
     * @param
     */
    private Boolean saveDate(List<HealthEduArticleES> sms)throws Exception {
        return SpringUtil.getBean(SaveEduArticleHelper.class).save(sms);
    }
    @Transactional
    public void save(){
        NewArticleModel newArticleModel = new NewArticleModel();

+ 112 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/vo/save/ElastricSearchSaveEduArticle.java

@ -0,0 +1,112 @@
package com.yihu.wlyy.web.third.jkedu.vo.save;
import com.alibaba.fastjson.JSONObject;
import com.yihu.es.entity.HealthEduArticleES;
import com.yihu.wlyy.config.es.ElasticFactory;
import io.searchbox.client.JestClient;
import io.searchbox.core.Bulk;
import io.searchbox.core.BulkResult;
import io.searchbox.core.Index;
import io.searchbox.core.Update;
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.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
;
/**
 * Created by chenweida on 2017/6/2.
 */
@Component
@Scope("prototype")
public class ElastricSearchSaveEduArticle {
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
    @Value("${es.index.HealthEduArticlePatient}")
    private String esIndex;
    private Logger logger = LoggerFactory.getLogger(ElastricSearchSaveEduArticle.class);
    @Autowired
    private ElasticFactory elasticFactory;
    public Boolean save(List<HealthEduArticleES> sms) {
        JestClient jestClient = null;
        try {
            //得到链接
            jestClient = elasticFactory.getJestClient();
            int success = 0;
            int error = 0;
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (HealthEduArticleES obj : sms) {
                try {
                    Index index = new Index.Builder(obj).build();
                    success++;
                    bulk.addAction(index);
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    error++;
                }
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("save flag:" + br.isSucceeded());
            logger.info("save success:" + success);
            logger.info("save error:" + error);
            return br.isSucceeded();
        } catch (Exception e) {
            logger.error(" save error :" + e.getMessage());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return null;
    }
    public Boolean update(List<HealthEduArticleES> sms) {
        JestClient jestClient = null;
        try {
            //得到链接
            jestClient = elasticFactory.getJestClient();
            int success = 0;
            int error = 0;
            boolean isSuccessed = true;
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (HealthEduArticleES obj : sms) {
                try {
                    JSONObject jo = new JSONObject();
                    jo.put("doc", obj);
                    Update index = new Update.Builder(jo.toString()).index(esIndex).type(esType).id(obj.getId()).build();
                    bulk.addAction(index);
                    success++;
                } catch (Exception e) {
                    error++;
                    isSuccessed = false;
                }
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("update flag:" + br.isSucceeded());
            logger.info("update success:" + success);
            logger.info("update error:" + error);
            jestClient.shutdownClient();
            return isSuccessed;
        } catch (Exception e) {
            logger.error(" update error :" + e.getMessage());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return null;
    }
}

+ 28 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/vo/save/SaveEduArticleHelper.java

@ -0,0 +1,28 @@
package com.yihu.wlyy.web.third.jkedu.vo.save;
import com.yihu.es.entity.HealthEduArticleES;
import com.yihu.wlyy.util.SpringUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.List;
/**
 * Created by chenweida on 2017/6/2.
 */
@Component
@Scope("prototype")
public class SaveEduArticleHelper {
    public Boolean save(List<HealthEduArticleES> sms) {
        return SpringUtil.getBean(ElastricSearchSaveEduArticle.class).save(sms);
    }
    public Boolean update(List<HealthEduArticleES> sms) {
        return SpringUtil.getBean(ElastricSearchSaveEduArticle.class).update(sms);
    }
}