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


import com.neusoft.smart.pos.constants.DictionaryConstant;
import com.neusoft.smart.pos.printer.persistent.domain.PrinterTemplateRef;
import com.neusoft.smart.pos.printer.persistent.domain.PrinterTemplateRefExample;
import com.neusoft.smart.pos.printer.persistent.mapper.PrinterTemplateRefMapper;
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 PrinterTemplateRefRepository {

	@Resource
	private PrinterTemplateRefMapper printerTemplateRefMapper;
	
	public void create(PrinterTemplateRef printerTemplateRef){
		printerTemplateRefMapper.insertSelective(printerTemplateRef);
	}
	
	/**
	 *
	 * @param printerId
	 */
	public void deleteByPrinterId(Long printerId) {
		val example = new PrinterTemplateRefExample();
		example.createCriteria().andPrinterIdEqualTo(printerId);
		printerTemplateRefMapper.deleteByExample(example);
	}
	
	/**
	 * 根据打印机ID查询打印模板方法
	 * @return
	 */
	public PrinterTemplateRef queryPrinterTemplateByPrinterId(Long printerId){
		val example = new PrinterTemplateRefExample();
		example.createCriteria()
				.andIsEnableEqualTo(DictionaryConstant.IS_ENABLE_QY.getCode())
				.andPrinterIdEqualTo(printerId);
		val printerTemplates = printerTemplateRefMapper.selectByExample(example);
		return printerTemplates.size()>0?printerTemplates.get(0):null;
	}
	
	/**
	 * 根据打印机ID查询打印模板方法
	 * @return
	 */
	public List<PrinterTemplateRef> queryPrinterTemplateListByPrinterId(Long printerId){
		val example = new PrinterTemplateRefExample();
		example.createCriteria()
				.andIsEnableEqualTo(DictionaryConstant.IS_ENABLE_QY.getCode())
				.andPrinterIdEqualTo(printerId);
		return printerTemplateRefMapper.selectByExample(example);
	}
	
	/**
	 * 根据字典模板ID查询打印模板方法
	 * @return
	 */
	public List<PrinterTemplateRef> queryPrinterTemplateListByTemplateId(List<Long> templateIds,List<Long> printerIds){
		val example = new PrinterTemplateRefExample();
		example.createCriteria()
				.andIsEnableEqualTo(DictionaryConstant.IS_ENABLE_QY.getCode())
				.andTemplateIdIn(templateIds)
				.andPrinterIdIn(printerIds);
		return printerTemplateRefMapper.selectByExample(example);
	}

}
