package com.hfkj.service.discount.impl;

import com.hfkj.dao.BsDiscountPkRelMapper;
import com.hfkj.entity.BsDiscountPk;
import com.hfkj.entity.BsDiscountPkRel;
import com.hfkj.entity.BsDiscountPkRelExample;
import com.hfkj.service.discount.BsDiscountPkRelService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsDiscountPkRelServiceImpl
 * @author: HuRui
 * @date: 2024/9/2
 **/
@Service("discountPkRelService")
public class BsDiscountPkRelServiceImpl implements BsDiscountPkRelService {
    @Resource
    private BsDiscountPkRelMapper discountPkRelMapper;

    @Override
    public void editData(BsDiscountPkRel data) {
        data.setUpdateTime(new Date());
        if (data.getId() == null) {
            data.setCreateTime(new Date());
            data.setStatus(1);
            discountPkRelMapper.insert(data);
        } else {
            discountPkRelMapper.updateByPrimaryKey(data);
        }
    }

    @Override
    public void delete(String discountPkNo) {
        BsDiscountPkRelExample example = new BsDiscountPkRelExample();
        example.createCriteria().andDiscountPkNoEqualTo(discountPkNo).andStatusEqualTo(1);

        BsDiscountPkRel rel = new BsDiscountPkRel();
        rel.setStatus(0);
        discountPkRelMapper.updateByExampleSelective(rel, example);
    }

    @Override
    public List<BsDiscountPkRel> getList(String discountPkNo) {
        BsDiscountPkRelExample example = new BsDiscountPkRelExample();
        example.createCriteria().andDiscountPkNoEqualTo(discountPkNo).andStatusNotEqualTo(0);
        return discountPkRelMapper.selectByExample(example);
    }
}
