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


import com.neusoft.smart.pos.printer.persistent.domain.PrinterTemplate;
import com.neusoft.smart.pos.printer.persistent.domain.PrinterTemplateExample;
import com.neusoft.smart.pos.printer.persistent.mapper.PrinterTemplateMapper;
import lombok.val;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

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

/**
 * @author zcf
 * @date 2018-10-18 10：43
 * @description 打印机规则管理使用Repository
 */
@Component
public class PrinterTemplateRepository {

	@Resource
	private PrinterTemplateMapper printerTemplateMapper;
	
	/**
	 * 根据规则ID查询模板Bean信息方法
	 * @return
	 */
	public PrinterTemplate queryPrinterTemplateByTemplateId(Long templateId){
		return printerTemplateMapper.selectByPrimaryKey(templateId);
	}
	
	/**
	 * 打印模板字典列表查询方法
	 * @return
	 */
	public List<PrinterTemplate> queryPrinterTemplateList(String isEnable, String templateType){
		val example = new PrinterTemplateExample();
		example.createCriteria();
		if(!StringUtils.isEmpty(isEnable)){
			example.getOredCriteria().get(0).andIsEnableEqualTo(isEnable);
		}
		if(!StringUtils.isEmpty(templateType)){
			example.getOredCriteria().get(0).andTemplateTypeEqualTo(templateType);
		}
		example.setOrderByClause("created_at asc");
		return printerTemplateMapper.selectByExample(example);
	}
}
