ソースを参照

内网PC,增加接口提供基卫调用,查询健康教育文章,

huangwenjie 7 年 前
コミット
67eecabe42

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

@ -1,6 +1,5 @@
package com.yihu.wlyy.repository.education;
import com.yihu.wlyy.entity.patient.PatientHealthRecordDiet;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@ -9,7 +8,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import com.yihu.wlyy.entity.education.HealthEduArticle;
import java.util.Date;
public interface HealthEduArticleDao extends PagingAndSortingRepository<HealthEduArticle, Long>, JpaSpecificationExecutor<HealthEduArticle> {

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

@ -299,4 +299,75 @@ public class HealthEduArticleService extends BaseService {
        }
    }
    
    public List<Map<String,Object>> zyfindAll(int page, int pagesize, String titlefilter, String keywordfilter, String contentfilter) {
        if (pagesize <= 0) {
            pagesize = 10;
        }
        if (page <=0) {
            page = 1;
        }
        page = page-1;
        List<Object> params = new ArrayList<Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select a.id,a.code,a.title,a.url,a.czrq,a.summary 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(" from wlyy_health_edu_article a  ");//内联取文章内容
        String where = " where 1=1 ";
        if (StringUtils.isNotBlank(titlefilter) ||
                StringUtils.isNotBlank(keywordfilter)||
                    StringUtils.isNotBlank(contentfilter)) {
            where += " and  ( ";
            
            boolean need_or = false;
    
            //文章标题关键字搜索
            if(StringUtils.isNotBlank(titlefilter)){
                titlefilter = "%" + titlefilter + "%";
                where +="a.title like ?";
    
                need_or = true;
                params.add(titlefilter);
            }
    
            //关键字搜索
            if(StringUtils.isNotBlank(keywordfilter)){
                keywordfilter = "%" + keywordfilter + "%";
                
                if(need_or){
                    where +=" or a.keyword like ?";
                }else{
                    where +="a.keyword like ?";
                    need_or = true;
                }
                params.add(keywordfilter);
            }
    
            //文章内容搜索
            if(StringUtils.isNotBlank(contentfilter)){
                contentfilter = "%" + contentfilter + "%";
        
                if(need_or){
                    where +=" or a.content like ?";
                }else{
                    where +="a.content like ?";
                }
                params.add(contentfilter);
            }
            
            where += " )";
        }
//        if(wheaType>=0){
//            where += " and  ( a.whea_type = ? )";
//            params.add(wheaType);
//        }
        int start = page * pagesize;
        String pageInfo = " limit " + start + "," + pagesize;
        String orderBy = " order by a.czrq desc";
        sql.append(where).append(orderBy).append(pageInfo);
        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql.toString(), params.toArray());
        return result;
    }
}

+ 95 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/zysoft/ZyHealthEduArticleController.java

@ -0,0 +1,95 @@
package com.yihu.wlyy.web.third.zysoft;
import com.yihu.wlyy.entity.education.HealthEduArticle;
import com.yihu.wlyy.service.app.health.HealthEduArticleService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 提供给智业调用的健康教育文章相关的接口:
 * @author huangwenjie
 * @date 2017/10/17 09:05
 */
@RestController
@RequestMapping("/wlyygc/zy/healthedu/article/")
public class ZyHealthEduArticleController extends BaseController {
	
	@Autowired
	private HealthEduArticleService healthEduArticleService;
	
	/**
	 * 查询健康教育文章列表
	 * @param titlefilter 文章标题搜索条件
	 * @param keywordfilter 关键字搜索条件
	 * @param contentfilter 文章内容搜索条件
	 * @param page 第几页(第一页传0)
	 * @param pagesize 分页大小
	 * @return 列表
	 */
	@ApiOperation("基卫查询健康教育文章列表")
	@RequestMapping(value = "list",method = RequestMethod.GET)
	@ResponseBody
	public String list(@RequestParam(value = "page", required = true) int page,
	                   @RequestParam(value = "pagesize", required = true) int pagesize,
	                   @RequestParam(value = "titlefilter", required = false) String titlefilter,
	                   @RequestParam(value = "keywordfilter", required = false) String keywordfilter,
	                   @RequestParam(value = "contentfilter", required = false) String contentfilter) {
		try {
			List<Map<String, Object>> list = healthEduArticleService.zyfindAll(page, pagesize, titlefilter, keywordfilter, contentfilter);
			JSONArray jsonArray = new JSONArray();
			if (list != null) {
				for (Map<String, Object> map : list) {
					JSONObject json = new JSONObject();
					json.put("id", map.get("id"));
					// 文章标识
					json.put("code", map.get("code"));
					// 文章标题
					json.put("title", map.get("title"));
					// 文章配图URL
					json.put("url", map.get("url"));
					// 文章简介
					json.put("content", String.valueOf(map.get("content"))==null?"":map.get("content"));
					// 添加日期
					json.put("czrq", DateUtil.dateToStrLong((Date) map.get("czrq")));
					// 关键字
					json.put("keyword", map.get("keyword") == null ? "" : map.get("keyword"));
					// 阅读量
					json.put("readAmount", map.get("readAmount"));
					// 收藏量
					json.put("collectionAmount", map.get("collectionAmount"));
					// 转发量
					json.put("repeatAmount", map.get("repeatAmount"));
					
					jsonArray.put(json);
				}
			}
			return write(200, "查询成功", "list", jsonArray);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
	
	@RequestMapping(value = "getArticalByCode",method = RequestMethod.GET)
	@ApiOperation("获取健康教育文章详情")
	public String getArticalById(@ApiParam(name = "articleCode", value = "教育文章Code",defaultValue = "1")
	                             @RequestParam(value = "articleCode", required = true) String articleCode){
		try {
			HealthEduArticle healthEduArticle = healthEduArticleService.findArticleByCode(articleCode);
			return write(200,"查询成功!","data",healthEduArticle);
		}catch (Exception e){
			e.printStackTrace();
			return error(-1,"查询失败!");
		}
	}
}