ConsumeDataServiceImpl.java 1.51 KB
package com.bsth.service.impl;

import com.bsth.data.history.entity.StationConsumeTime;
import com.bsth.service.ConsumeDataService;
import com.bsth.util.db_utils.DBUtils_InfoPublish;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConsumeDataServiceImpl implements ConsumeDataService {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public List<StationConsumeTime> search(String rq, String lineCode, String st, String et, String nbbm) {
        List<StationConsumeTime> list = null;
        try {

            rq = rq.replaceAll("-", "");
            st = st + "00";
            et = et + "00";
            String sql = "select * from bsth_h_consume_time where rq=" + rq + " and line_code='" + lineCode + "' and time_str>='" + st + "' and time_str<='" + et + "' ";
            if (StringUtils.isNotBlank(nbbm))
                sql += " and nbbm like '%" + nbbm + "%'";

            sql += " order by time_str";
            JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_InfoPublish.getDataSource());
            list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(StationConsumeTime.class));
        } catch (Exception e) {
            logger.error("", e);
        }
        return list;
    }
}