package com.buy507.mall.service.impl;

import com.buy507.mall.dao.UmsTransferrecordDao;
import com.buy507.mall.model.UmsTransferrecord;
import com.buy507.mall.service.UmsTransferrecordService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
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 UmsTransferrecordServiceImpl implements UmsTransferrecordService {

    @Autowired
    private UmsTransferrecordDao dao;

    @Override
    public List<UmsTransferrecord> list(Integer pageSize, Integer pageNum,
                                        String memberName, String receiverName, String startTime, String endTime){
        PageHelper.startPage(pageNum, pageSize);
        Date start = null;
        Date end = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (!StringUtils.isEmpty(startTime)) {
            String startStr = startTime + " 00:00:00";
            try {
                start = sdf.parse(startStr);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        if(!StringUtils.isEmpty(endTime)) {
            String endStr = endTime + " 23:59:59";
            try {
                end = sdf.parse(endStr);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        List<UmsTransferrecord>   userLIst = (List<UmsTransferrecord>)dao.selectAll(memberName, receiverName, start, end);
        return userLIst;
    }
}
