package cn.stylefeng.guns.zjxl.service;

import cn.stylefeng.guns.zjxl.dao.ZjxlNewsCenterDao;
import cn.stylefeng.guns.zjxl.model.ZjxlCompanyCase;
import cn.stylefeng.guns.zjxl.model.ZjxlNewsCenter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/***
 * @ClassName: ZjxlNewsCenterService
 * @Description:
 * @Auther: shi kejing
 * @Date: 2020/11/17 14:18
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class ZjxlNewsCenterService {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Autowired
    private ZjxlNewsCenterDao newsCenterDao;

    public List<ZjxlNewsCenter> findById(String id, Integer page, Integer pagesize){
        String sql = "select a.* from zjxl_news_center a where 1=1";
        if (StringUtils.isNotEmpty(id)){
            sql += " and news_center_id = '"+id+"'";
        }
        sql += " order by news_center_sort desc limit "+page+" , "+pagesize+"";
        List<ZjxlNewsCenter> companyCaseList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ZjxlNewsCenter.class));
        return companyCaseList;
    }

    public int allCount(){
        String sql = "select count(*) from zjxl_news_center ";
        Integer allCount = jdbcTemplate.queryForObject(sql, Integer.class);;
        return allCount;
    }

}
