package com.bs.df.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bs.common.utils.DateUtils;
import com.bs.common.utils.StringUtils;
import com.bs.df.mapper.DfOrderMapper;
import com.bs.df.domain.DfOrder;
import com.bs.df.service.IDfOrderService;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 客户订单Service业务层处理
 *
 * @author bs
 * @date 2024-04-06
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DfOrderServiceImpl  extends MPJBaseServiceImpl<DfOrderMapper, DfOrder> implements IDfOrderService {
    @Resource
    private IDfOrderService dfOrderService;
    @Override
    public String getBillNumber(String billPrefix) {
        String billNo = "";
        if (StringUtils.isBlank(billPrefix)) {
            billPrefix = "DD";
        }
        String billDate = DateUtils.dateTimeNow("yyyyMMdd");
        List<DfOrder> lsBill = dfOrderService.list(new LambdaQueryWrapper<DfOrder>().like(DfOrder::getOrderNo, billPrefix + billDate)
                .orderByDesc(DfOrder::getId));
        if (lsBill.size() == 0) {
            billNo = billPrefix + billDate + String.format("%04d", 1);
            return billNo;
        }
        Long id = lsBill.get(0).getId();
        billNo = billPrefix + billDate + String.format("%04d", id + 1);
        return billNo;
    }
}
