package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ZccmUserTeacherMapper;
import com.hc.business.model.ZccmUserTeacher;
import com.hc.business.service.ZccmUserTeacherService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (ZccmUserTeacher)表服务实现类
 *
 * @author java
 * @since 2020-11-20 11:08:20
 */

@Service("userTeacherService")
public class ZccmUserTeacherServiceImpl implements ZccmUserTeacherService {

    private final ZccmUserTeacherMapper userTeacherMapper;

    public ZccmUserTeacherServiceImpl(ZccmUserTeacherMapper userTeacherMapper) {
        this.userTeacherMapper = userTeacherMapper;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param teacherId 主键
     * @return 实例对象
     */
    @Override
    public ZccmUserTeacher queryById(Integer teacherId) {
        return this.userTeacherMapper.selectByPrimaryKey(teacherId);
    }

    /**
     * 新增数据
     *
     * @param userTeacher 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmUserTeacher insert(ZccmUserTeacher userTeacher) {
        userTeacher.setCreateTime(System.currentTimeMillis());
        this.userTeacherMapper.insert(userTeacher);
        return userTeacher;
    }

    /**
     * 修改数据
     *
     * @param userTeacher 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmUserTeacher update(ZccmUserTeacher userTeacher) {
        this.userTeacherMapper.updateByPrimaryKeySelective(userTeacher);
        return this.queryById(userTeacher.getTeacherId());
    }

    /**
     * 通过主键删除数据
     *
     * @param teacherId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer teacherId) {
        return this.userTeacherMapper.deleteByPrimaryKey(teacherId) > 0;
    }

    /**
     * 分页查询多条数据
     *
     * @param page 页码
     * @param size 查询条数
     * @return 对象列表
     */
    @Override
    public PageInfo queryAllByLimit(int page, int size) {
        return PageHelper.startPage(page, size).doSelectPageInfo(this.userTeacherMapper::selectAll);
    }

    @Override
    public List<ZccmUserTeacher> queryByName(String name) {
        return this.userTeacherMapper.queryByName(name);
    }


}