package com.ssm.manage.service.impl;

import com.ssm.manage.dao.BeisenUserListDao;
import com.ssm.manage.dto.BeisenUserListDto;
import com.ssm.manage.entity.BeisenUserList;
import com.ssm.manage.service.BeisenUserListService;
import com.ssm.manage.utils.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.core.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import com.ssm.manage.dao.BaseDao;
import com.ssm.core.impl.BaseDaoImpl;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import tk.mybatis.mapper.entity.Example;

/**
 * (BeisenUserList)表服务实现类
 *
 * @author makejava
 * @since 2024-01-12 15:26:23
 */
@Service("beisenUserListService")
public class BeisenUserListServiceImpl extends BaseServiceImpl<BeisenUserList> implements BeisenUserListService {
    @Autowired
    private BeisenUserListDao beisenUserListDao;

    @Override
    public BaseDao<BeisenUserList> getDao() {
        return beisenUserListDao;
    }

    @Override
    public PageInfo<BeisenUserList> selectPage(BeisenUserListDto dto) {
        Example example = new Example(BeisenUserList.class);
        example.setOrderByClause("input_date desc");
        Example.Criteria criteria = example.createCriteria();
        if (Objects.nonNull(dto.getStoreId())){
            criteria.andEqualTo(BeisenUserListDto.Fields.storeId,dto.getStoreId());
        }
        if (Objects.nonNull(dto.getStartTime())){
            criteria.andBetween(BeisenUserListDto.Fields.inputDate,dto.getStartTime(),dto.getLastTime());
        }
        if (StringUtils.isNotBlank(dto.getStaffName())){
            criteria.andLike(BeisenUserListDto.Fields.staffName,dto.getStaffName());
        }
        if (StringUtils.isNotBlank(dto.getStaffNum())){
            criteria.andLike(BeisenUserListDto.Fields.staffNum,dto.getStaffNum());
        }

        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<BeisenUserList> list = this.beisenUserListDao.selectByExample(example);
        PageInfo<BeisenUserList> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
