chenweida 8 роки тому
батько
коміт
54e8a6da03

+ 57 - 0
patient-co-figure/src/main/java/com/yihu/figure/controller/health/HealthEduArticleController.java

@ -0,0 +1,57 @@
package com.yihu.figure.controller.health;
import com.yihu.figure.controller.BaseController;
import com.yihu.figure.model.health.HealthEduArticle;
import com.yihu.figure.service.health.HealthEduArticleService;
import io.swagger.annotations.Api;
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.stereotype.Controller;
import org.springframework.util.StringUtils;
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 java.util.List;
/**
 * Created by chenweida on 2017/3/15.
 */
@Controller
@RequestMapping(value = "/health/article")
@Api(description = "健康教育文章")
public class HealthEduArticleController extends BaseController {
    @Autowired
    private HealthEduArticleService healthEduArticleService;
    @RequestMapping(value = "/findByKeyword", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据keyword查找文章")
    public String findByKeyword(@ApiParam(name = "keyword", value = "关键字",required = false)
                                @RequestParam(value = "keyword", required = false) String keyword) {
        try {
            if(StringUtils.isEmpty(keyword)){
                keyword="";
            }
            List<HealthEduArticle> healthEduArticle= healthEduArticleService.findByKeyword(keyword);
            JSONArray ja=new JSONArray();
            if(healthEduArticle!=null&&healthEduArticle.size()>0){
                healthEduArticle.stream().forEach( h->{
                    JSONObject jo=new JSONObject();
                    jo.put("title",h.getTitle());
                    jo.put("content",h.getContent());
                    ja.put(jo);
                });
            }
            return write(200, "成功","data",ja);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "生成失败");
        }
    }
}

+ 15 - 0
patient-co-figure/src/main/java/com/yihu/figure/controller/patient/PatientController.java

@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
/**
/**
@ -85,4 +86,18 @@ public class PatientController extends BaseController {
            return error(-1, e.getMessage());
            return error(-1, e.getMessage());
        }
        }
    }
    }
    public static void main(String[] args) {
        List<Integer> values=new ArrayList<>();
        values.add(0);
        values.add(3);
        values.add(5);
        values.add(11);
        values.add(33);
        values.add(22);
        values.add(31);
        values.stream().filter( n-> n > 5).forEach( n-> System.out.println(n));
    }
}
}

+ 21 - 0
patient-co-figure/src/main/java/com/yihu/figure/dao/health/HealthEduArticleDao.java

@ -0,0 +1,21 @@
package com.yihu.figure.dao.health;
import com.yihu.figure.model.health.HealthEduArticle;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface HealthEduArticleDao extends PagingAndSortingRepository<HealthEduArticle, Long>, JpaSpecificationExecutor<HealthEduArticle> {
	HealthEduArticle findByCode(String code);
	@Query("SELECT a FROM HealthEduArticle a WHERE (a.title like ?1 or a.keyword like ?2) ORDER BY a.czrq DESC")
	Page<HealthEduArticle> list(String title, String keyword, Pageable pageRequest);
	@Query("SELECT a FROM HealthEduArticle a WHERE  a.keyword like ?1 ORDER BY a.czrq DESC")
	List<HealthEduArticle> findByKeyword(String keyword);
}

+ 96 - 0
patient-co-figure/src/main/java/com/yihu/figure/model/health/HealthEduArticle.java

@ -0,0 +1,96 @@
package com.yihu.figure.model.health;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.figure.model.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * 健康教育
 * @author George
 *
 */
@Entity
@Table(name = "wlyy_health_edu_article")
public class HealthEduArticle extends IdEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 149974966956355735L;
	// 文章标识
	private String code;
	// 文章标题
	private String title;
	// 文章链接
	private String url;
	// 简介
	private String summary;
	// 文章内容
	private String content;
	// 发布时间
	private Date czrq;
	//文章关键字
	private String keyword;
	public String getKeyword(){
		return keyword;
	}
	public void setKeyword(String keyword){
		this.keyword = keyword;
	}
	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 getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCzrq() {
		return czrq;
	}
	public void setCzrq(Date czrq) {
		this.czrq = czrq;
	}
}

+ 23 - 0
patient-co-figure/src/main/java/com/yihu/figure/service/health/HealthEduArticleService.java

@ -0,0 +1,23 @@
package com.yihu.figure.service.health;
import com.yihu.figure.dao.health.HealthEduArticleDao;
import com.yihu.figure.model.health.HealthEduArticle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.util.List;
/**
 * Created by chenweida on 2017/3/15.
 */
@Component
public class HealthEduArticleService {
    @Autowired
    private HealthEduArticleDao healthEduArticleDao;
    public List<HealthEduArticle> findByKeyword(String keyword) {
        return healthEduArticleDao.findByKeyword("%"+keyword+"%");
    }
}

BIN
patient-co-figure/文档/接口文档.docx