package com.sgbg18.service.impl;

import com.sgbg18.mapper.EmployeeMapper_ztb18326;
import com.sgbg18.entity.Employee_ztb18326;
import com.sgbg18.service.EmployeeService_ztb18326;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * 员工表(Employee)表服务实现类
 *
 * @author ztb18326
 * @since 2020-12-25 13:41:24
 */
@Service("employeeService")
public class EmployeeServiceImpl_ztb18326 implements EmployeeService_ztb18326 {
    @Autowired
    SqlSession sqlSession;
    /**
     * 通过ID查询单条数据
     *
     * @param empId 主键
     * @return 实例对象
     */
    @Override
    public Employee_ztb18326 queryById(Integer empId) {
        EmployeeMapper_ztb18326 employeeMapperztb18326 = sqlSession.getMapper(EmployeeMapper_ztb18326.class);
        return employeeMapperztb18326.queryById(empId);
    }
    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Employee_ztb18326> queryAllByLimit(int offset, int limit) {
        EmployeeMapper_ztb18326 employeeMapperztb18326 = sqlSession.getMapper(EmployeeMapper_ztb18326.class);
        return  employeeMapperztb18326.queryAllByLimit(offset, limit);
    }
    /**
     * 新增数据
     *
     * @param employee 实例对象
     * @return 实例对象
     */
    @Override
    public Employee_ztb18326 insert(Employee_ztb18326 employee) {
        EmployeeMapper_ztb18326 employeeMapperztb18326 = sqlSession.getMapper(EmployeeMapper_ztb18326.class);

         employeeMapperztb18326.insert(employee);
        return employee;
    }
    /**
     * 修改数据
     *
     * @param employee 实例对象
     * @return 实例对象
     */
    @Override
    public Employee_ztb18326 update(Employee_ztb18326 employee) {
        EmployeeMapper_ztb18326 employeeMapperztb18326 = sqlSession.getMapper(EmployeeMapper_ztb18326.class);

         employeeMapperztb18326.update(employee);
        return  queryById(employee.getEmpId());
    }
    /**
     * 通过主键删除数据
     *
     * @param empId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer empId) {
        EmployeeMapper_ztb18326 employeeMapperztb18326 = sqlSession.getMapper(EmployeeMapper_ztb18326.class);
        return  employeeMapperztb18326.deleteById(empId) > 0;
    }
}