Selaa lähdekoodia

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

8 vuotta sitten
vanhempi
commit
94bffbd9cd

+ 84 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/education/HealthEduArticleOpHistory.java

@ -0,0 +1,84 @@
package com.yihu.wlyy.entity.education;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * 健康教育文章操作历史表
 * @author linz
 *
 */
@Entity
@Table(name = "wlyy_health_edu_article_op_history")
public class HealthEduArticleOpHistory extends IdEntity {
	// 文章标识
	private String code;
	// 文章标题
	private String title;
	// 操作类型1.阅读 2.收藏 3.转发
	private String status;
	// 操作人
	private String creater;
	// 发布时间
	private Date createdTime;
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getCreater() {
		return creater;
	}
	public void setCreater(String creater) {
		this.creater = creater;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCreatedTime() {
		return createdTime;
	}
	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}
	/**
	 * 阅读状态
	 */
	public static final String READ_STATUS ="1";
	/**
	 * 收藏状态
	 */
	public static final String COLLECTION_STATUS ="2";
	/**
	 * 转发状态
	 */
	public static final String REPEAT_STATUS ="3";
}

+ 16 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/education/HealthEduArticleOpHistoryDao.java

@ -0,0 +1,16 @@
package com.yihu.wlyy.repository.education;
import com.yihu.wlyy.entity.education.HealthEduArticleOpHistory;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface HealthEduArticleOpHistoryDao extends PagingAndSortingRepository<HealthEduArticleOpHistory, Long>, JpaSpecificationExecutor<HealthEduArticleOpHistory> {
	@Query("select count(1) from HealthEduArticleOpHistory a where a.code = ?1 and a.status = ?2")
	int countByCodeStatus(String code,String status);
	@Query("select count(1) from HealthEduArticleOpHistory a where a.creater = ?1 and a.status = ?2")
	int countByUserStatus(String user,String status);
}

+ 2 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/education/HealthEduArticlePatientDao.java

@ -13,4 +13,6 @@ public interface HealthEduArticlePatientDao extends PagingAndSortingRepository<H
	@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);
}

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

@ -0,0 +1,89 @@
package com.yihu.wlyy.service.app.health;
import com.yihu.wlyy.entity.IdEntity;
import com.yihu.wlyy.entity.education.HealthEduArticleOpHistory;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.repository.education.HealthEduArticleOpHistoryDao;
import com.yihu.wlyy.repository.education.HealthEduArticlePatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
import java.util.HashMap;
import java.util.Map;
/**
 * 健康教育患者业务逻辑类
 * @author linz
 *
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class HealthEduArticleOpHistoryService extends BaseService {
	@Autowired
	private HealthEduArticleOpHistoryDao healthEduArticleOpHistoryDao;
	/**
	 * 汇总阅读量
	 * @param code
	 * @return
	 */
	public  int countReadAmount(String code){
		return healthEduArticleOpHistoryDao.countByCodeStatus(code,HealthEduArticleOpHistory.READ_STATUS);
	}
	/**
	 * 汇总转发量
	 * @param code
	 * @return
	 */
	public int countRepeatAmount(String code){
		return healthEduArticleOpHistoryDao.countByCodeStatus(code,HealthEduArticleOpHistory.COLLECTION_STATUS);
	}
	/**
	 * 获取收藏量
	 * @param code
	 * @return
	 */
	public  int countCollectionAmount(String code){
		return healthEduArticleOpHistoryDao.countByCodeStatus(code,HealthEduArticleOpHistory.REPEAT_STATUS);
	}
	public int countByUserStatus(String user,String status){
		return healthEduArticleOpHistoryDao.countByCodeStatus(user,status);
	}
	/**
	 *
	 * @param status 状态
	 * @param code 文章编号
	 * @param title 文章标题
	 * @param user 操作人
	 * @return
	 */
	public HealthEduArticleOpHistory saveByStatus(String status,String code,String title,String user){
		HealthEduArticleOpHistory healthEduArticleOpHistory = new HealthEduArticleOpHistory();
		healthEduArticleOpHistory.setCode(code);
		healthEduArticleOpHistory.setCreatedTime(DateUtil.getNow());
		healthEduArticleOpHistory.setStatus(status);
		healthEduArticleOpHistory.setTitle(title);
		healthEduArticleOpHistory.setCreater(user);
		healthEduArticleOpHistory.setId(0L);
		healthEduArticleOpHistoryDao.save(healthEduArticleOpHistory);
		return healthEduArticleOpHistory;
	}
}

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

@ -0,0 +1,81 @@
package com.yihu.wlyy.service.app.health;
import com.yihu.wlyy.entity.education.HealthEduArticle;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.repository.education.HealthEduArticleDao;
import com.yihu.wlyy.repository.education.HealthEduArticlePatientDao;
import com.yihu.wlyy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
 * 健康教育患者业务逻辑类
 * @author linz
 *
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class HealthEduArticlePatientService extends BaseService {
	@Autowired
	private HealthEduArticlePatientDao healthEduArticlePatientDao;
	/**
	 * 根据文章标示获取数据
	 * @param article
	 * @return
	 */
	public HealthEduArticlePatient findByArticle(String article) {
		return healthEduArticlePatientDao.findByArticle(article);
	}
	/**
	 * 查询患者文章
	 * @param patient 患者标识
	 * @param pagesize 分页大小
	 * @return
	 */
	public Page<HealthEduArticlePatient> findByPatient(String patient, long id, int pagesize) {
		if (pagesize <= 0) {
			pagesize = 10;
		}
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		// 患者过滤
		filters.put("patient", new SearchFilter("patient", Operator.EQ, patient));
		if (id > 0) {
			filters.put("id", new SearchFilter("id", Operator.LT, id));
		}
		Specification<HealthEduArticlePatient> spec = DynamicSpecifications.bySearchFilter(filters.values(), HealthEduArticlePatient.class);
		return healthEduArticlePatientDao.findAll(spec, pageRequest);
	}
	/**
	 * 文章更新为已读
	 * @param patient
	 * @param article
	 * @return
	 */
	public int updateRead(String patient, String article) {
		return healthEduArticlePatientDao.updateRead(patient, article);
	}
}

+ 46 - 6
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/HealthEduArticleController.java

@ -1,5 +1,8 @@
package com.yihu.wlyy.web.patient.health;
import com.yihu.wlyy.entity.education.HealthEduArticleOpHistory;
import com.yihu.wlyy.service.app.health.HealthEduArticleOpHistoryService;
import com.yihu.wlyy.service.app.health.HealthEduArticlePatientService;
import io.swagger.annotations.Api;
import org.json.JSONArray;
import org.json.JSONObject;
@ -9,6 +12,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.education.HealthEduArticlePatient;
@ -27,7 +31,10 @@ import com.yihu.wlyy.web.BaseController;
public class HealthEduArticleController extends BaseController {
	@Autowired
	private HealthEduArticleService healthEduArticleService;
	private HealthEduArticlePatientService healthEduArticlePatientService;
	@Autowired
	private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
	/**
	 * 查询文章列表
@ -36,9 +43,9 @@ public class HealthEduArticleController extends BaseController {
	 */
	@RequestMapping(value = "list")
	@ResponseBody
	public String list(long id, int pagesize) {
	public String list(@RequestParam("id")long id, @RequestParam("pagesize") int pagesize) {
		try {
			Page<HealthEduArticlePatient> list = healthEduArticleService.findByPatient(getUID(), id, pagesize);
			Page<HealthEduArticlePatient> list = healthEduArticlePatientService.findByPatient(getUID(), id, pagesize);
			JSONArray jsonArray = new JSONArray();
			if (list != null) {
				for (HealthEduArticlePatient article : list) {
@ -58,6 +65,15 @@ public class HealthEduArticleController extends BaseController {
					json.put("read", article.getRead());
					// 添加日期
					json.put("czrq", DateUtil.dateToStrLong(article.getCzrq()));
					int collectionAmount =  healthEduArticleOpHistoryService.countCollectionAmount(article.getArticle());
					int readAmount = healthEduArticleOpHistoryService.countReadAmount(article.getArticle());
					int repeatAmount = healthEduArticleOpHistoryService.countRepeatAmount(article.getArticle());
					//阅读量
					json.put("readAmount", readAmount);
					//收藏量
					json.put("collectionAmount", collectionAmount);
					//转发量
					json.put("repeatAmount", repeatAmount);
					jsonArray.put(json);
				}
			}
@ -67,7 +83,31 @@ public class HealthEduArticleController extends BaseController {
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 查询文章列表
	 * @param article 数据文章唯一标示article
	 * @return 列表
	 */
	@RequestMapping(value = "article")
	@ResponseBody
	public String article(@RequestParam("article") String article) {
		try {
			//获取单条文章记录
			HealthEduArticlePatient healthEduArticlePatient = healthEduArticlePatientService.findByArticle(article);
			int isRead  = healthEduArticleOpHistoryService.countByUserStatus(getUID(),HealthEduArticleOpHistory.READ_STATUS);
			//插入文章读取状态第一次阅读记录浏览数量
			if(isRead==0){
				//更新浏览量
				healthEduArticleOpHistoryService.saveByStatus(HealthEduArticleOpHistory.READ_STATUS,healthEduArticlePatient.getArticle(),healthEduArticlePatient.getTitle(),getUID());
				//将文章更新为已读
				healthEduArticlePatientService.updateRead(getUID(), article);
			}
			return write(200, "查询成功", "data", healthEduArticlePatient);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	/**
	 * 更新文章为已读
	 * @param article 文章标识
@ -75,9 +115,9 @@ public class HealthEduArticleController extends BaseController {
	 */
	@RequestMapping(value = "read")
	@ResponseBody
	public String read(String article) {
	public String read(@RequestParam("article") String article) {
		try {
			healthEduArticleService.updateRead(getUID(), article);
			healthEduArticlePatientService.updateRead(getUID(), article);
			return success("操作成功!");
		} catch (Exception ex) {
			error(ex);