package com.sqx.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.dao.*;
import com.sqx.modules.app.entity.RechargeRecord;
import com.sqx.modules.app.service.RechargeRecordService;
import com.sqx.modules.printInfo.entity.PrintInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RechargeRecordServiceImpl extends ServiceImpl<RechargeRecordDao, RechargeRecord> implements RechargeRecordService {

    @Override
    public Result selectRechargeRecordList(Integer page, Integer limit,String orderNo,String phone) {
        Page<RechargeRecord> pages = new Page<>(page, limit);
        QueryWrapper<RechargeRecord> queryWrapper = new QueryWrapper();
        queryWrapper.like(StringUtils.isNotBlank(orderNo),"order_no", orderNo);
        queryWrapper.like(StringUtils.isNotBlank(phone),"user_phone", phone);
        PageUtils pageUtils = new PageUtils(baseMapper.selectPage(pages,queryWrapper));
        return Result.success().put("data", pageUtils);
    }

    @Override
    public Result insertRechargeRecord(RechargeRecord rechargeRecord) {
        baseMapper.insert(rechargeRecord);
        return Result.success();
    }

    @Override
    public Result updateRechargeRecord(RechargeRecord rechargeRecord) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        rechargeRecord.setUpdateTime(format);
        int result = baseMapper.updateById(rechargeRecord);
        return result > 0 ? Result.success() : Result.error();
    }

    @Override
    public RechargeRecord selectRechargeRecordById(Integer id) {
        RechargeRecord rr = baseMapper.selectById(id);
        return rr;
    }
}
