UserSeerviceImp.java 1.2 KB
package com.shunzhi.mqtt2kanban.service;

import com.shunzhi.mqtt2kanban.bean.Attendance;
import com.shunzhi.mqtt2kanban.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserSeerviceImp implements UserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<User> getAllUsers(int index) {

        String sql ="";
        if (index==1){
            sql = "SELECT * FROM user limit "+2;
        }else {
            sql = String.format("SELECT * FROM user limit %s,10",index);
        }

        return jdbcTemplate.query(sql, new Object[]{}, new BeanPropertyRowMapper<User>(User.class));
    }

    @Override
    public List<Attendance> getAttendance(String user_id) {
        String sql = "SELECT * FROM SZ_AttendanceRecords201906  where school_id=27 and intime>'2019-06-19 16:00' and  intime<'2019-06-19 17:40' and user_id = '"+user_id+"'";

        return jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<Attendance>(Attendance.class));
    }


}