package com.ssj.dao.sys.menu.dao;

import com.ssj.bean.sys.menu.domain.WxMaterial;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface WxMaterialDao extends JpaRepository<WxMaterial, String>{
	
		@Query(nativeQuery = true, value = "select m.* from tb_wx_material m")
		public  List<WxMaterial>  listByWxMaterial();
		
		@Query(nativeQuery = true, value = "select m.* from tb_wx_material m where m.media_id =?1")
		public  List<WxMaterial> getByWxMaterialId(String materialId);
		
		@Query(nativeQuery = true, value = "insert into tb_wx_material ( "
				+ "id, media_id, msg_type, title, author,digest,content,content_source_url,thumb_media_id,show_cover_pic,url,thumb_url,create_date) "
				+ "values ( UUID(), ?1 , ?2, ?3 ,?4,?5,?6,?7,?8,?9,?10,?11,NOW() ) ")
		@Modifying
		public  void saveWxMaterial(String mediaId, String msgType, String title, String author, String digest, String content, String contentSourceUrl
                , String thumbMediaId, Integer showCoverPic, String url, String thumbUrl);
		
		
		@Query(nativeQuery = true, value = "UPDATE tb_wx_material SET content = ?2 ,msg_type=?3,create_date= NOW() WHERE id = ?1 ")
		@Modifying
		public  void  updateWxMaterial(String id, String content, String msg_type);
		
}
