package com.hfkj.service.hlt;

import com.hfkj.dao.BsHltCardRecordMapper;
import com.hfkj.entity.BsHltCardRecord;
import com.hfkj.entity.BsHltCardRecordExample;
import com.hfkj.sysenum.hlt.HltCardRecordPayStatusEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @className: BsHltCardRecordService
 * @author: HuRui
 * @date: 2024/8/21
 **/
@Component
public class BsHltCardRecordService {
    @Resource
    private BsHltCardRecordMapper hltCardRecordMapper;

    /**
     * 创建
     * @param record
     */
    public void create(BsHltCardRecord record) {
        record.setCreateTime(new Date());
        record.setUpdateTime(new Date());
        hltCardRecordMapper.insert(record);
    }

    /**
     * 修改
     * @param record
     */
    public void update(BsHltCardRecord record) {
        record.setUpdateTime(new Date());
        hltCardRecordMapper.updateByPrimaryKey(record);
    }

    /**
     * 获取最新支付单号
     * @param orderNo 订单号
     * @return
     */
    public BsHltCardRecord getNewPayOrderNo(String orderNo) {
        BsHltCardRecordExample example = new BsHltCardRecordExample();
        example.createCriteria()
                .andOrderNoEqualTo(orderNo)
                .andPayStatusEqualTo(HltCardRecordPayStatusEnum.status2.getCode());
        List<BsHltCardRecord> list = hltCardRecordMapper.selectByExample(example);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

}
