package com.neusoft.smart.pos.printer.repository;


import com.neusoft.smart.pos.printer.persistent.domain.PrinterRuleAttribute;
import com.neusoft.smart.pos.printer.persistent.domain.PrinterRuleAttributeExample;
import com.neusoft.smart.pos.printer.persistent.mapper.PrinterRuleAttributeMapper;
import lombok.val;
import org.springframework.stereotype.Component;

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

/**
 * @author zcf
 * @date 2018-10-18 10：43
 * @description 打印机规则属性使用Repository
 */
@Component
public class PrinterRuleAttributeRepository {
    
    @Resource
    private PrinterRuleAttributeMapper printerRuleAttributeMapper;
    
    /**
     * 保存打印机规则详细值
     *
     * @param printerRuleAttribute
     */
    public void create(PrinterRuleAttribute printerRuleAttribute) {
        printerRuleAttributeMapper.insertSelective(printerRuleAttribute);
    }
    
    /**
     * @param refIds
     */
    public void deleteByRefIds(List<Long> refIds) {
        if (refIds.isEmpty()) return;
        PrinterRuleAttributeExample example = new PrinterRuleAttributeExample();
        example.createCriteria().andPrinterRuleIdIn(refIds);
        printerRuleAttributeMapper.deleteByExample(example);
    }
    
    
    /**
     * 根据规则ID查询规则属性列表信息方法
     *
     * @return
     */
    public List<PrinterRuleAttribute> queryPrinterRuleAttributeByRuleId(Long ruleId, Long printerRuleId) {
        val example = new PrinterRuleAttributeExample();
        example.createCriteria()
                .andRuleIdEqualTo(ruleId)
                .andPrinterRuleIdEqualTo(printerRuleId);
        return printerRuleAttributeMapper.selectByExample(example);
    }
    
    /**
     * @param ruleIds
     * @return
     */
    public List<PrinterRuleAttribute> queryPrinterRuleAttributeByRuleRefIds(List<Long> ruleIds) {
        val example = new PrinterRuleAttributeExample();
        example.createCriteria()
                .andPrinterRuleIdIn(ruleIds);
        return printerRuleAttributeMapper.selectByExample(example);
    }
    
    /**
     * @return
     */
    public List<PrinterRuleAttribute> queryPrinterRuleAttributeByRuleRefId(Long printerRuleId) {
        val example = new PrinterRuleAttributeExample();
        example.createCriteria()
                .andPrinterRuleIdEqualTo(printerRuleId);
        return printerRuleAttributeMapper.selectByExample(example);
    }
}
