package com.ssj.dao.sys.analysis.dao;

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 com.ssj.bean.sys.analysis.bean.AnalysisWeek;

/**
 * @author Mount Liu
 * @date 2019/3/17
 */
@Repository
public interface AnalysisWeekDao extends JpaRepository<AnalysisWeek, String> {

	@Query(nativeQuery = true,value = " SELECT * from tb_analysis_week t WHERE t.lib_id=?1 AND t.year_week=concat(DATE_FORMAT(NOW(),'%Y'),DATE_FORMAT(NOW(),'%u')) LIMIT 1 ")
	AnalysisWeek getAnalysisWeekByCurWeek(String libId);
	
	@Modifying
	@Query(nativeQuery = true, value = "insert into tb_analysis_week ( id, lib_id, year_week, member_num, active_num,active_ratio,create_time) values ( UUID(), ?1 , concat(DATE_FORMAT(NOW(),'%Y'),DATE_FORMAT(NOW(),'%u')), ?2 ,?3,?4,NOW() )  ")
	void saveAnalysisWeek(String libId, Integer memberNum, Integer activeNum, Integer activeRatio);
	
}
