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


import com.neusoft.smart.pos.constants.DictionaryConstant;
import com.neusoft.smart.pos.payorder.persistent.domain.PayTypeDict;
import com.neusoft.smart.pos.payorder.persistent.domain.PayTypeDictExample;
import com.neusoft.smart.pos.payorder.persistent.mapper.PayTypeDictMapper;
import lombok.val;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

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

/**
 * @author zcf
 * @date 2017-08-13 10：43
 * @description 支付方式字典管理使用Repository
 */
@Component
public class PayTypeRepository {

	@Resource
	private PayTypeDictMapper payTypeDictMapper;

	/**
	 * 支付方式信息查询方法
	 * @param isEnabled：是否启用@0未启用@1启用
	 * @param isShow：查询是否显示@0不显示@1显示(如现金默认忽略)
	 * @return
	 */
	public List<PayTypeDict> queryPayTypes(String isEnabled, String isShow){
		val example = new PayTypeDictExample();//new TradePayTypeDictExample();
		example.createCriteria();
		if(!StringUtils.isEmpty(isEnabled)){
			example.getOredCriteria().get(0).andIsEnableEqualTo(isEnabled);
		}
		if(!StringUtils.isEmpty(isShow)){
			example.getOredCriteria().get(0).andIsShowEqualTo(isShow);
		}
		example.setOrderByClause("priority desc");
		return payTypeDictMapper.selectByExample(example);
	}

	/**
	 * 支付方式信息查询方法
	 * @param payType：支付方式
	 * @return
	 */
	public PayTypeDict queryEnabledPayType(String payType){
		val example = new PayTypeDictExample();
		example.createCriteria()
				.andIsEnableEqualTo(DictionaryConstant.IS_ENABLE_QY.getCode())
				.andPayTypeEqualTo(payType);
		val tradePayTypeDicts = payTypeDictMapper.selectByExample(example);
		return tradePayTypeDicts.size()>0?tradePayTypeDicts.get(0):null;
	}

	/**
	 * 支付方式信息查询方法
	 * @param payType：支付方式
	 * @return
	 */
	public PayTypeDict queryPayType(String payType){
		val example = new PayTypeDictExample();
		example.createCriteria()
				.andPayTypeEqualTo(payType);
		val tradePayTypeDicts = payTypeDictMapper.selectByExample(example);
		return tradePayTypeDicts.size()>0?tradePayTypeDicts.get(0):null;
	}

	public List<PayTypeDict> queryPayTypesShowOnPos(String code) {
		val example = new PayTypeDictExample();
		example.createCriteria();
		example.getOredCriteria().get(0).andIsEnableEqualTo(DictionaryConstant.IS_ENABLE_QY.getCode());
		example.getOredCriteria().get(0).andIsShowOnPosEqualTo(DictionaryConstant.IS_SHOW_S.getCode());
		example.setOrderByClause("priority desc");
		return payTypeDictMapper.selectByExample(example);
	}
}
