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


import com.neusoft.smart.pos.constants.DictionaryConstant;
import com.neusoft.smart.pos.printer.persistent.domain.PrinterRuleRef;
import com.neusoft.smart.pos.printer.persistent.domain.PrinterRuleRefExample;
import com.neusoft.smart.pos.printer.persistent.mapper.PrinterRuleRefMapper;
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 PrinterRuleRefRepository {

	@Resource
	private PrinterRuleRefMapper printerRuleRefMapper;
	
	/**
	 * 保存打印机规则关系
	 * @param printerRuleRef
	 */
	public void create(PrinterRuleRef printerRuleRef){
		printerRuleRefMapper.insertSelective(printerRuleRef);
	}
	
	/**
	 *
	 * @param printerId
	 */
	public void deleteByPrinterId(Long printerId){
		PrinterRuleRefExample printerRuleRef = new PrinterRuleRefExample();
		printerRuleRef.createCriteria().andPrinterIdEqualTo(printerId);
		printerRuleRefMapper.deleteByExample(printerRuleRef);
	}
	/**
	 * 根据打印机ID查询打印规则方法
	 * @return
	 */
	public List<PrinterRuleRef> queryPrinterRulesByPrinterId(Long printerId){
		val example = new PrinterRuleRefExample();
		example.createCriteria()
				.andIsEnableEqualTo(DictionaryConstant.IS_ENABLE_QY.getCode())
				.andPrinterIdEqualTo(printerId);
		example.setOrderByClause("sort_no asc");
		return printerRuleRefMapper.selectByExample(example);
	}
	
	/**
	 * 根据打印机ID查询打印规则方法
	 * @return
	 */
	public List<PrinterRuleRef> queryPrinterRefRulesByPrinterId(Long printerId){
		val example = new PrinterRuleRefExample();
		example.createCriteria()
				.andPrinterIdEqualTo(printerId);
		example.setOrderByClause("sort_no asc");
		return printerRuleRefMapper.selectByExample(example);
	}
}
