|
@ -12,6 +12,7 @@ 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.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springside.modules.persistence.DynamicSpecifications;
|
|
@ -41,6 +42,8 @@ public class HealthEduArticleService extends BaseService {
|
|
|
private HealthEduArticleOpHistoryService healthEduArticleOpHistoryService;
|
|
|
@Autowired
|
|
|
private HealthEduArticleLabelService healthEduArticleLabelService;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
/**
|
|
|
* 查询文章信息
|
|
@ -57,51 +60,44 @@ public class HealthEduArticleService extends BaseService {
|
|
|
* @param pagesize 分页大小
|
|
|
* @return 列表
|
|
|
*/
|
|
|
public Page<HealthEduArticle> findAll(int page, int pagesize,String filter,String doctor) {
|
|
|
public List<Map<String, Object>> findAll(int page, int pagesize,String filter,String doctor,String patient) {
|
|
|
if (pagesize <= 0) {
|
|
|
pagesize = 10;
|
|
|
}
|
|
|
if(page<0){
|
|
|
page = 0;
|
|
|
}
|
|
|
// 排序
|
|
|
Sort sort = new Sort(Direction.DESC, "id");
|
|
|
// 分页信息
|
|
|
PageRequest pageRequest = new PageRequest(page, pagesize, sort);
|
|
|
// 设置查询条件
|
|
|
Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
|
|
|
if (StringUtils.isNotBlank(filter)) {
|
|
|
List<Object> params = new ArrayList<Object>();
|
|
|
StringBuffer sql = new StringBuffer();
|
|
|
sql.append("select a.id,a.code,a.title,a.url,a.czrq,a.content,a.keyword");
|
|
|
sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 1) as readAmount");
|
|
|
sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 2) as collectionAmount");
|
|
|
sql.append(",(select count(1) from wlyy_health_edu_article_op_history c where c.code = a.code and c.status = 3) as repeatAmount");
|
|
|
sql.append(",(select count(1) from wlyy_health_edu_article_doctor c where c.article = a.code and c.doctor =?) as collection");
|
|
|
params.add(doctor);
|
|
|
if(StringUtils.isNotBlank(patient)) {
|
|
|
sql.append(",(select count(1) from wlyy_health_edu_article_patient c where c.article = a.code and c.doctor = ?) as send");
|
|
|
params.add(doctor);
|
|
|
}
|
|
|
sql.append(" from wlyy_health_edu_article a ");//内联取文章内容
|
|
|
String where = " ";
|
|
|
if(StringUtils.isNotBlank(filter)){
|
|
|
//记录搜索记录
|
|
|
healthEduArticleLabelService.saveOrUpdateLabel(filter,doctor);
|
|
|
filter="%"+filter+"%";
|
|
|
return healthEduArticleDao.list(filter,filter, pageRequest);
|
|
|
where+=" where ( a.title like ? or a.keyword like ? )";
|
|
|
params.add(filter);
|
|
|
params.add(filter);
|
|
|
}
|
|
|
Specification<HealthEduArticle> spec = DynamicSpecifications.bySearchFilter(filters.values(),HealthEduArticle.class);
|
|
|
return healthEduArticleDao.findAll(spec, pageRequest);
|
|
|
}
|
|
|
int start = page * pagesize;
|
|
|
|
|
|
/**
|
|
|
* 查询患者文章
|
|
|
* @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);
|
|
|
String pageInfo = " limit "+start+","+pagesize;
|
|
|
|
|
|
String orderBy = " order by a.czrq,a.id desc";
|
|
|
|
|
|
sql.append(where).append(orderBy).append(pageInfo);
|
|
|
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql.toString(),params.toArray());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|