package com.pannk.demo.service.impl;

import com.pannk.demo.controller.Page;
import com.pannk.demo.entity.SysUserEntity;
import com.pannk.demo.mapper.SysUserMapper;
import com.pannk.demo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by wolf on 20-11-9.
 */
@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public List<SysUserEntity> list() {
        return sysUserMapper.list();
    }

    @Override
    public SysUserEntity save(SysUserEntity sysUserEntity) {
        sysUserEntity.setCreateDate(new Date());
        sysUserEntity.setCreateId(1L);
        sysUserMapper.save(sysUserEntity);
        return sysUserEntity;
    }

    @Override
    public void update(SysUserEntity sysUserEntity) {
        sysUserEntity.setUpdateDate(new Date());
        sysUserEntity.setUpdateId(1L);
        sysUserMapper.update(sysUserEntity);
    }

    @Override
    public void delete(Long id) {
        sysUserMapper.delete(id);
    }

    @Override
    public Page page(Page page) {
        int limit = (page.getCurrPage() - 1) * page.getPageSize();
        List<SysUserEntity> list = sysUserMapper.page(limit, page.getPageSize());
        int total = sysUserMapper.count();
        page.setList(list);
        page.setTotal(total);
        return page;
    }

    @Override
    public void batchDelete(List<Long> ids) {
        sysUserMapper.batchDelete(ids);
    }

    @Override
    public List<SysUserEntity> listByName(String userName) {
        return sysUserMapper.selectByName(userName);
    }

    @Override
    public List<SysUserEntity> listByCond(Map<String, Object> cond) {
        return sysUserMapper.selectByCond(cond);
    }
}
