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


import com.neusoft.smart.pos.trade.persistent.domain.*;
import com.neusoft.smart.pos.trade.persistent.mapper.BillSettlementRuleDetailMapper;
import com.neusoft.smart.pos.trade.persistent.mapper.BillSettlementRuleMapper;
import lombok.val;
import org.springframework.stereotype.Component;

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

/**
 * @author zcf
 * @date 2018-10-31 10：43
 * @description 账单结算规则详细信息管理使用Repository
 */
@Component
public class BillSettlementRuleDetailRepository {

	@Resource
	private BillSettlementRuleDetailMapper billSettlementRuleDetailMapper;
	
	/**
	 * 结算规则列表查询方法
	 * @return
	 */
	public List<BillSettlementRuleDetail> queryBillSettlementRuleDetails(Integer ruleId){
		val example = new BillSettlementRuleDetailExample();
		example.createCriteria().andBillRuleIdEqualTo(ruleId);
		example.setOrderByClause("pay_type desc,is_bear desc,created_at desc");
		return billSettlementRuleDetailMapper.selectByExample(example);
	}
	
	/**
	 * 商户结算规则明细信息删除方法
	 * @return
	 */
	public Boolean deleteBillSettlementRule(Integer ruleId){
		val example = new BillSettlementRuleDetailExample();
		example.createCriteria()
				.andBillRuleIdEqualTo(ruleId);
		val count = billSettlementRuleDetailMapper.deleteByExample(example);
		return count>0?true:false;
	}
	
	/**
	 * 商户结算规则主体信息保存方法
	 * @return
	 */
	public Integer saveBillSettlemenDetailRule(BillSettlementRuleDetail billSettlementRuleDetail){
		return billSettlementRuleDetailMapper.insertSelective(billSettlementRuleDetail);
	}
	
	
}
