Sfoglia il codice sorgente

Merge branch 'dev' of wujunjie/patient-management into dev

linzhuo 8 anni fa
parent
commit
28ed769a6e

+ 0 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/deviece/PatientHealthTimeDao.java

@ -12,7 +12,4 @@ public interface PatientHealthTimeDao extends PagingAndSortingRepository<Patient
    @Query(value = "select t.* from wlyy_patient_health_time t where t.del = 1 and t.user = ?1 and t.device_sn = ?2 ", nativeQuery = true)
    PatientHealthTime findByUserAndSN(String user, String deviceSN);
    //    根据居民和设备sn码查询自定义的血糖时间段
    @Query(value = "select t.* from wlyy_patient_health_time t where t.del = 1 and t.user = ?1 and t.device_sn = ?2 ", nativeQuery = true)
    PatientHealthTime findBycUserAndSN(String user, String deviceSN);
}

+ 12 - 6
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/education/HealthEduArticlePatientDao.java

@ -11,12 +11,18 @@ import java.util.List;
public interface HealthEduArticlePatientDao extends PagingAndSortingRepository<HealthEduArticlePatient, Long>, JpaSpecificationExecutor<HealthEduArticlePatient> {
	// 更新为已读
	@Modifying
	@Query("update HealthEduArticlePatient a set a.read = 0 where a.patient = ?1 and a.article = ?2 ")
	int updateRead(String patient, String article);
	HealthEduArticlePatient findByArticle(String article);
    // 更新为已读
    @Modifying
    @Query("update HealthEduArticlePatient a set a.read = 0 where a.patient = ?1 and a.article = ?2 ")
    int updateRead(String patient, String article);
	List<HealthEduArticlePatient> findByArticleAndPatient(String article,String patient);
    HealthEduArticlePatient findByArticle(String article);
    List<HealthEduArticlePatient> findByArticleAndPatient(String article, String patient);
    // 当前用户的所有未读文章设置为已读
    @Modifying
    @Query("update HealthEduArticlePatient a set a.read = 0 where a.read = 1 and a.patient = ?1 ")
    int readAllArticle(String patient);
}

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java

@ -505,7 +505,7 @@ public class PatientDeviceService extends BaseService {
     */
    public void setBloodTime(String user, String deviceSN, String fastingStart, String fastingEnd, String afterBreakfastStart, String afterBreakfastEnd, String beforeLunchStart, String beforeLunchEnd,
                             String afterLunchStart, String afterLunchEnd, String beforeDinnerStart, String beforeDinnerEnd, String afterDinnerStart, String afterDinnerEnd,
                             String beforeSleepStart, String beforeSleepEnd) {
                             String beforeSleepStart, String beforeSleepEnd) throws  Exception{
        PatientHealthTime patientHealthTime = new PatientHealthTime();
        patientHealthTime.setUser(user);
        patientHealthTime.setDeviceSN(deviceSN);

+ 10 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticleService.java

@ -256,6 +256,16 @@ public class HealthEduArticleService extends BaseService {
        return healthEduArticlePatientDao.updateRead(patient, article);
    }
    /**
     * 对当前用户的所有未读文章设置为已读
     *
     * @param patient
     * @return
     */
    public int readAllArticle(String patient) {
        return healthEduArticlePatientDao.readAllArticle(patient);
    }
    /**
     * 发送文章列表
     *

+ 10 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java

@ -66,10 +66,16 @@ public class PatientDeviceController extends BaseController {
                               @RequestParam String beforeSleepStart,
                               @RequestParam String beforeSleepEnd,
                               @RequestParam String deviceSN) {
        String user = getUID();
        patientDeviceService.setBloodTime(user,deviceSN,fastingStart,fastingEnd,afterBreakfastStart,afterBreakfastEnd,beforeLunchStart,beforeLunchEnd,
                afterLunchStart,afterLunchEnd,beforeDinnerStart,beforeDinnerEnd,afterDinnerStart,afterDinnerEnd,beforeSleepStart,beforeSleepEnd);
        return null;
        try {
            String user = getUID();
            patientDeviceService.setBloodTime(user,deviceSN,fastingStart,fastingEnd,afterBreakfastStart,afterBreakfastEnd,beforeLunchStart,beforeLunchEnd,
                    afterLunchStart,afterLunchEnd,beforeDinnerStart,beforeDinnerEnd,afterDinnerStart,afterDinnerEnd,beforeSleepStart,beforeSleepEnd);
            return write(200,"设置成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e,-1,"设置失败!");
        }
    }
    /**

+ 165 - 138
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/HealthEduArticleController.java

@ -33,148 +33,175 @@ import java.util.Map;
/**
 * 患者端:健康教育控制类
 * @author George
 *
 * @author George
 */
@Controller
@RequestMapping(value = "/patient/health/edu", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "患者端-健康教育")
public class HealthEduArticleController extends BaseController {
	@Autowired
	private HealthEduArticlePatientService healthEduArticlePatientService;
	@Autowired
	private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
	@Autowired
	private HealthEduArticleService healthEduArticleService;
	@Autowired
	private DoctorService doctorService;
	/**
	 * 查询文章列表
	 * @param pagesize 分页大小
	 * @return 列表
	 */
	@RequestMapping(value = "list")
	@ResponseBody
	public String list(@RequestParam("id")long id, @RequestParam("pagesize") int pagesize,@RequestParam(required = true,value="wheaType")int wheaType) {
		try {
			List<HealthEduArticlePatient> list = healthEduArticlePatientService.findByPatient(getUID(),wheaType, id, pagesize);
			JSONArray jsonArray = new JSONArray();
			Map<String,Doctor> docMap = new HashMap<>();
			if (list != null) {
				for (HealthEduArticlePatient article : list) {
					JSONObject json = new JSONObject();
					json.put("id", article.getId());
					// 文章标识
					json.put("article", article.getArticle());
					// 医生姓名
					json.put("doctorName", article.getDoctorName());
					// 文章标题
					json.put("title", article.getTitle());
					// 文章查看URL
					json.put("url", article.getUrl());
					// 文章简介
					//json.put("content", parsrHtml(article.getContent()));
					json.put("content", article.getContent());
					// 是否已读:0已读,1未读
					json.put("read", article.getRead());
					// 添加日期
					json.put("czrq", DateUtil.dateToStrLong(article.getCzrq()));
					//附加内容
					json.put("attached_content", article.getAttachedContent());
					if(docMap.get(article.getDoctor())==null){
						Doctor doctor = doctorService.findDoctorByCode(article.getDoctor());
						docMap.put(article.getDoctor(),doctor);
						json.put("photo",doctor.getPhoto());
					}else{
						json.put("photo",docMap.get(article.getDoctor()).getPhoto());
					}
					jsonArray.put(json);
				}
			}
			return write(200, "查询成功", "list", jsonArray);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 查询文章列表
	 * @param article 数据文章唯一标示article
	 * @return 列表
	 */
	@RequestMapping(value = "article")
	@ResponseBody
	public String article(@RequestParam(value = "article",required = true) String article) {
		try {
			//获取单条文章记录
			List<HealthEduArticlePatient> healthEduArticlePatients = healthEduArticlePatientService.findByArticleAndPatient(article,getUID());
			if(healthEduArticlePatients==null||healthEduArticlePatients.size()==0){
				return error(-2,"对不起,该消息不是您的消息,您无法查看哦~");
			}
			int isRead  = healthEduArticleOpHistoryService.countByUserStatus(getUID(),HealthEduArticleOpHistory.READ_STATUS);
			//插入文章读取状态第一次阅读记录浏览数量//暂时更新每次都算一次浏览量
			HealthEduArticlePatient healthEduArticlePatient = healthEduArticlePatients.get(0);
			healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.READ_STATUS,healthEduArticlePatient.getArticle(),healthEduArticlePatient.getTitle(),getUID());
			if(isRead==0){
				//将文章更新为已读
				healthEduArticlePatientService.updateRead(getUID(), healthEduArticlePatient.getArticle());
			}
			HealthEduArticle healthEduArticle = healthEduArticleService.findArticleByCode(healthEduArticlePatient.getArticle());
			JSONObject json = new JSONObject();
			json.put("id", healthEduArticle.getId());
			// 文章标识
			json.put("article", healthEduArticlePatient.getArticle());
			// 医生姓名
			json.put("doctorName", healthEduArticlePatient.getDoctorName());
			// 文章标题
			json.put("title", healthEduArticle.getTitle());
			// 文章内容
			json.put("content", healthEduArticle.getContent());
			json.put("url", healthEduArticle.getUrl());
			// 添加日期
			json.put("czrq", DateUtil.dateToStrLong(healthEduArticlePatient.getCzrq()));
			int readAmount = healthEduArticleOpHistoryService.countReadAmount(healthEduArticlePatient.getArticle());
			json.put("readAmount",readAmount);
			return write(200, "查询成功", "data", json);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 更新文章为已读
	 * @param article 文章标识
	 * @return
	 */
	@RequestMapping(value = "read")
	@ResponseBody
	public String read(@RequestParam("article") String article) {
		try {
			healthEduArticlePatientService.updateRead(getUID(), article);
			return success("操作成功!");
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "操作失败!");
		}
	}
	private String parsrHtml(String html) throws ParserException {
		Parser parser = null;
		html = ("<span>"+html+"<span>");
		try{
			parser = new Parser(html);
		}catch (ParserException e){
			return html;//纯文本内容会转换失败,直接返回文本内容
		}
		TextExtractingVisitor visitor = new TextExtractingVisitor();
		parser.visitAllNodesWith(visitor);
		return StringUtils.isNotBlank(visitor.getExtractedText())?visitor.getExtractedText():"内容为图集,请点击查看";
	}
}
    @Autowired
    private HealthEduArticlePatientService healthEduArticlePatientService;
    @Autowired
    private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
    @Autowired
    private HealthEduArticleService healthEduArticleService;
    @Autowired
    private DoctorService doctorService;
    /**
     * 查询文章列表
     *
     * @param pagesize 分页大小
     * @return 列表
     */
    @RequestMapping(value = "list")
    @ResponseBody
    public String list(@RequestParam("id") long id, @RequestParam("pagesize") int pagesize, @RequestParam(required = true, value = "wheaType") int wheaType) {
        try {
            List<HealthEduArticlePatient> list = healthEduArticlePatientService.findByPatient(getUID(), wheaType, id, pagesize);
            JSONArray jsonArray = new JSONArray();
            Map<String, Doctor> docMap = new HashMap<>();
            if (list != null) {
                for (HealthEduArticlePatient article : list) {
                    JSONObject json = new JSONObject();
                    json.put("id", article.getId());
                    // 文章标识
                    json.put("article", article.getArticle());
                    // 医生姓名
                    json.put("doctorName", article.getDoctorName());
                    // 文章标题
                    json.put("title", article.getTitle());
                    // 文章查看URL
                    json.put("url", article.getUrl());
                    // 文章简介
                    //json.put("content", parsrHtml(article.getContent()));
                    json.put("content", article.getContent());
                    // 是否已读:0已读,1未读
                    json.put("read", article.getRead());
                    // 添加日期
                    json.put("czrq", DateUtil.dateToStrLong(article.getCzrq()));
                    //附加内容
                    json.put("attached_content", article.getAttachedContent());
                    if (docMap.get(article.getDoctor()) == null) {
                        Doctor doctor = doctorService.findDoctorByCode(article.getDoctor());
                        docMap.put(article.getDoctor(), doctor);
                        json.put("photo", doctor.getPhoto());
                    } else {
                        json.put("photo", docMap.get(article.getDoctor()).getPhoto());
                    }
                    jsonArray.put(json);
                }
            }
            return write(200, "查询成功", "list", jsonArray);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
    /**
     * 查询文章列表
     *
     * @param article 数据文章唯一标示article
     * @return 列表
     */
    @RequestMapping(value = "article")
    @ResponseBody
    public String article(@RequestParam(value = "article", required = true) String article) {
        try {
            //获取单条文章记录
            List<HealthEduArticlePatient> healthEduArticlePatients = healthEduArticlePatientService.findByArticleAndPatient(article, getUID());
            if (healthEduArticlePatients == null || healthEduArticlePatients.size() == 0) {
                return error(-2, "对不起,该消息不是您的消息,您无法查看哦~");
            }
            int isRead = healthEduArticleOpHistoryService.countByUserStatus(getUID(), HealthEduArticleOpHistory.READ_STATUS);
            //插入文章读取状态第一次阅读记录浏览数量//暂时更新每次都算一次浏览量
            HealthEduArticlePatient healthEduArticlePatient = healthEduArticlePatients.get(0);
            healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.READ_STATUS, healthEduArticlePatient.getArticle(), healthEduArticlePatient.getTitle(), getUID());
            if (isRead == 0) {
                //将文章更新为已读
                healthEduArticlePatientService.updateRead(getUID(), healthEduArticlePatient.getArticle());
            }
            HealthEduArticle healthEduArticle = healthEduArticleService.findArticleByCode(healthEduArticlePatient.getArticle());
            JSONObject json = new JSONObject();
            json.put("id", healthEduArticle.getId());
            // 文章标识
            json.put("article", healthEduArticlePatient.getArticle());
            // 医生姓名
            json.put("doctorName", healthEduArticlePatient.getDoctorName());
            // 文章标题
            json.put("title", healthEduArticle.getTitle());
            // 文章内容
            json.put("content", healthEduArticle.getContent());
            json.put("url", healthEduArticle.getUrl());
            // 添加日期
            json.put("czrq", DateUtil.dateToStrLong(healthEduArticlePatient.getCzrq()));
            int readAmount = healthEduArticleOpHistoryService.countReadAmount(healthEduArticlePatient.getArticle());
            json.put("readAmount", readAmount);
            return write(200, "查询成功", "data", json);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
    /**
     * 更新文章为已读
     *
     * @param article 文章标识
     * @return
     */
    @RequestMapping(value = "read")
    @ResponseBody
    public String read(@RequestParam("article") String article) {
        try {
            healthEduArticlePatientService.updateRead(getUID(), article);
            return success("操作成功!");
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "操作失败!");
        }
    }
    private String parsrHtml(String html) throws ParserException {
        Parser parser = null;
        html = ("<span>" + html + "<span>");
        try {
            parser = new Parser(html);
        } catch (ParserException e) {
            return html;//纯文本内容会转换失败,直接返回文本内容
        }
        TextExtractingVisitor visitor = new TextExtractingVisitor();
        parser.visitAllNodesWith(visitor);
        return StringUtils.isNotBlank(visitor.getExtractedText()) ? visitor.getExtractedText() : "内容为图集,请点击查看";
    }
    /**
     * 对当前用户的所有未读文章设置为已读
     *
     * @return
     */
    @RequestMapping(value = "/readAllArticle",method = RequestMethod.GET)
    @ResponseBody
    public String readAllArticle() {
        try {
            String patient = getUID();
//            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
            int row = healthEduArticleService.readAllArticle(patient);
            System.out.println(row);
            return write(200,"更改状态成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e,-1,"更改状态失败!");
        }
    }
    }