package com.buy507.mall.service.impl;

import com.buy507.mall.dao.TmsAdminIstratorDao;
import com.buy507.mall.model.SmsHomeAdvertiseExample;
import com.buy507.mall.model.TmsAdminIstrator;
import com.buy507.mall.service.TmsAdminIstratorService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class TmsAdminIstratorServiceImpl implements TmsAdminIstratorService {

    @Autowired
    private TmsAdminIstratorDao dao;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public List<TmsAdminIstrator> list(Integer pageSize, Integer pageNum){

        PageHelper.startPage(pageNum, pageSize);
        List<TmsAdminIstrator>   userLIst = (List<TmsAdminIstrator>)dao.selectAll();
        return userLIst;

    }

    @Override
    public int create(TmsAdminIstrator advertise) {
        String encodePassword = passwordEncoder.encode(advertise.getPassword());
        advertise.setPassword(encodePassword);
        return dao.insert(advertise);
    }

    @Override
    public TmsAdminIstrator getItem(Long id) {
        return dao.selectByPrimaryKey(id);
    }

    @Override
    public int update(Long id, TmsAdminIstrator advertise) {
        advertise.setId(id);
        return dao.updateByPrimaryKeySelective(advertise);
    }

    @Override
    public int delete(List<Long> ids) {
        SmsHomeAdvertiseExample example = new SmsHomeAdvertiseExample();
        example.createCriteria().andIdIn(ids);
        return dao.deleteByExample(example);
    }

}
