Bläddra i källkod

健康教育相关后台业务添加

8 år sedan
förälder
incheckning
dd7bfb458b

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

@ -5,6 +5,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.yihu.wlyy.entity.patient.PatientHealthRecordMedication;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -52,20 +54,23 @@ public class HealthEduArticleService extends BaseService {
	 * @param pagesize 分页大小
	 * @return 列表
	 */
	public Page<HealthEduArticle> findAll(long id, int pagesize) {
	public Page<HealthEduArticle> findAll(int page, int pagesize,String filter) {
		if (pagesize <= 0) {
			pagesize = 10;
		}
		if(page<0){
			page = 0;
		}
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		PageRequest pageRequest = new PageRequest(page, pagesize, sort);
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		if (id > 0) {
			filters.put("id", new SearchFilter("id", Operator.LT, id));
		if (StringUtils.isNotBlank(filter)) {
			filters.put("title", new SearchFilter("filter", Operator.LIKE, filter));
		}
		Specification<HealthEduArticle> spec = DynamicSpecifications.bySearchFilter(filters.values(), HealthEduArticle.class);
		Specification<HealthEduArticle> spec = DynamicSpecifications.bySearchFilter(filters.values(),HealthEduArticle.class);
		return healthEduArticleDao.findAll(spec, pageRequest);
	}

+ 95 - 14
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java

@ -1,11 +1,10 @@
package com.yihu.wlyy.web.doctor.health;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import com.yihu.wlyy.entity.education.HealthEduArticleOpHistory;
import com.yihu.wlyy.service.app.health.HealthEduArticleOpHistoryService;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@ -16,6 +15,7 @@ import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
@ -42,7 +42,11 @@ public class DoctorHealthEduArticleController extends BaseController {
	private HealthEduArticleService healthEduArticleService;
	@Autowired
	private DoctorService doctorService;
	@Autowired
	private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
	@Autowired
	private SignPatientLabelInfoService signPatientLabelInfoService;
	/**
	 * 查询
	 * @param pagesize 分页大小
@ -50,9 +54,9 @@ public class DoctorHealthEduArticleController extends BaseController {
	 */
	@RequestMapping(value = "list")
	@ResponseBody
	public String list(long id, int pagesize) {
	public String list(@RequestParam(value = "page",required = true)int page, @RequestParam(value = "pagesize",required = true)int pagesize,@RequestParam(value = "filter",required = false)String filter) {
		try {
			Page<HealthEduArticle> list = healthEduArticleService.findAll(id, pagesize);
			Page<HealthEduArticle> list = healthEduArticleService.findAll(page, pagesize,filter);
			JSONArray jsonArray = new JSONArray();
			if (list != null) {
				for (HealthEduArticle article : list) {
@ -68,6 +72,18 @@ public class DoctorHealthEduArticleController extends BaseController {
					json.put("content", article.getContent());
					// 添加日期
					json.put("czrq", DateUtil.dateToStrLong(article.getCzrq()));
					int collectionAmount =  healthEduArticleOpHistoryService.countCollectionAmount(article.getCode());
					int readAmount = healthEduArticleOpHistoryService.countReadAmount(article.getCode());
					int repeatAmount = healthEduArticleOpHistoryService.countRepeatAmount(article.getCode());
					//阅读量
					json.put("readAmount", readAmount);
					//收藏量
					json.put("collectionAmount", collectionAmount);
					//转发量
					json.put("repeatAmount", repeatAmount);
					//是否收藏
					json.put("collection",1);
					jsonArray.put(json);
				}
			}
@ -78,36 +94,90 @@ public class DoctorHealthEduArticleController extends BaseController {
		}
	}
	/**
	 * 查询文章列表
	 * @param code 数据文章唯一标示code
	 * @return 列表
	 */
	@RequestMapping(value = "article")
	@ResponseBody
	public String article(@RequestParam(value = "code",required = true) String code) {
		try {
			//获取单条文章记录
			HealthEduArticle healthEduArticle = healthEduArticleService.findArticleByCode(code);
			int isRead  = healthEduArticleOpHistoryService.countByUserStatus(getUID(), HealthEduArticleOpHistory.READ_STATUS);
			//插入文章读取状态第一次阅读记录浏览数量
			if(isRead==0){
				//更新浏览量
				healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.READ_STATUS,healthEduArticle.getCode(),healthEduArticle.getTitle(),getUID());
			}
			JSONObject json = new JSONObject();
			json.put("id", healthEduArticle.getId());
			// 文章标识
			json.put("code", healthEduArticle.getCode());
			// 文章标题
			json.put("title", healthEduArticle.getTitle());
			// 文章内容
			json.put("content", healthEduArticle.getContent());
			// 添加日期
			json.put("czrq", DateUtil.dateToStrLong(healthEduArticle.getCzrq()));
			int readAmount = healthEduArticleOpHistoryService.countReadAmount(code);
			json.put("readAmount",readAmount);
			json.put("collection",1);
			return write(200, "查询成功", "data", json);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 发送文章给患者
	 * @param article 文章标识,多个以逗号分隔
	 * @param code 文章标识,多个以逗号分隔
	 * @param patient 患者标识,多个以逗号分隔
	 * @param  group 所选群组,多个用逗号分隔
	 * @return
	 */
	@RequestMapping(value = "send")
	@ResponseBody
	public String send(String article, String patient) {
	public String send(@RequestParam(value = "code")String code,
					   @RequestParam(value = "patient",required = false)String patient,
					   @RequestParam(value = "group",required = false,defaultValue = "")String group,
					   @RequestParam(value = "labelType",required = false)String labelType,
					   @RequestParam(value = "labelCode",required = false)String labelCode,
					   @RequestParam(value = "teamCode",required = false)long teamCode) {
		try {
			List<HealthEduArticlePatient> list = new ArrayList<HealthEduArticlePatient>();
			if (StringUtils.isEmpty(article)) {
			if (StringUtils.isEmpty(code)) {
				return error(-1, "请至少选择一篇文章!");
			}
			if (StringUtils.isEmpty(patient)) {
			if (StringUtils.isEmpty(patient)&&StringUtils.isEmpty(group)) {
				return error(-1, "请至少选择一个患者!");
			}
			String[] articles = article.split(",");
			String[] articles = code.split(",");
			String[] patients = patient.split(",");
			String[] groups = group.split(",");
			if (articles.length == 0) {
				return error(-1, "请至少选择一篇文章!");
			}
			if (patients.length == 0) {
			if (patients.length == 0&&groups.length==0) {
				return error(-1, "请至少选择一个患者!");
			}
			Map<String, HealthEduArticle> maps = new HashMap<String, HealthEduArticle>();
			Set<String> patientSet = new HashSet<>();
			if(StringUtils.isNotBlank(group)&&groups.length>0){
				//递归患者数据
				getPatientByGroup(labelCode,labelType,teamCode,patientSet,1,100);
			}
			//去重操作
			for (String p : patients) {
				patientSet.add(p);
			}
			// 查询医生信息
			Doctor doctor = doctorService.findDoctorByCode(getUID());
			JSONArray messages = new JSONArray();
			for (String p : patients) {
			for (String p : patientSet) {
				for (String a : articles) {
					// 查询文章信息
					HealthEduArticle temp = maps.get(a);
@ -159,5 +229,16 @@ public class DoctorHealthEduArticleController extends BaseController {
			return error(-1, "发送失败!");
		}
	}
	private void getPatientByGroup(String labelCode, String labelType, Long teamCode,Set<String> patientSet,int page,int pagesize) throws Exception{
		JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page, pagesize);
		for(Object o : result){
			JSONObject json  = (JSONObject)o;
			String patient  = (String)json.get("code");
			patientSet.add(patient);
		}
		if(result.length()==100){
			getPatientByGroup( labelCode,labelType,teamCode,patientSet,page+1,pagesize);
		}
	}
}