package cn.com.ty.lift.ud.payment.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.ty.lift.ud.utils.UUIDUtil;
import cn.com.ty.lift.ud.payment.mapper.UserRechargeDetailMapper;
import cn.com.ty.lift.ud.payment.mapper.entity.UserRechargeDetailEntity;
import cn.com.ty.lift.ud.payment.service.IUserRechargeDetailService;
import cn.com.xwy.boot.web.dto.RestResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * 用户充值记录表-ServiceImpl
 *
 * @author Xson
 * @date 2020-06-05
 */
@Slf4j
@Service
@Transactional
public class UserRechargeDetailServiceImpl extends ServiceImpl<UserRechargeDetailMapper, UserRechargeDetailEntity>
    implements IUserRechargeDetailService {

    private @Autowired UserRechargeDetailMapper rechargeDetailMapper;

    @Override
    public RestResponse createRecharge(UserRechargeDetailEntity request) {

        if (null == request.getUserId()) {
            log.info("用户id不能为空");
            return RestResponse.fail("用户id不能为空");
        } else if (null == request.getPayType()) {
            log.info("支付类型必填");
            return RestResponse.fail("支付类型必填");
        }

        // 订单号（22位） = 时间戳+上随机生成8位数
        final String orderNo = UUIDUtil.getUuidByTime(8);
        request.setOrderSn(orderNo);
        request.setPayStatus(1);
        rechargeDetailMapper.insert(request);
        return RestResponse.success(request.getOrderSn(), "success");
    }

}
