package com.hfkj.service.order.impl;

import com.hfkj.dao.BsOrderDeductionMapper;
import com.hfkj.entity.BsOrderDeduction;
import com.hfkj.entity.BsOrderDeductionExample;
import com.hfkj.service.order.BsOrderDeductionService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsOrderDeductionServiceImpl
 * @author: HuRui
 * @date: 2024/4/30
 **/
@Service("orderDeductionService")
public class BsOrderDeductionServiceImpl implements BsOrderDeductionService {

    @Resource
    private BsOrderDeductionMapper orderDeductionMapper;

    @Override
    public BsOrderDeduction editData(BsOrderDeduction data) {
        if (data.getId() == null) {
            orderDeductionMapper.insert(data);
        } else {
            orderDeductionMapper.updateByPrimaryKey(data);
        }
        return data;
    }

    @Override
    public BsOrderDeduction getOrderDeduction(String orderNo) {
        BsOrderDeductionExample example = new BsOrderDeductionExample();
        example.createCriteria().andOrderNoEqualTo(orderNo);
        List<BsOrderDeduction> list = orderDeductionMapper.selectByExample(example);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }
}
