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


import com.neusoft.smart.pos.trade.persistent.domain.BillSettlementCycle;
import com.neusoft.smart.pos.trade.persistent.domain.BillSettlementCycleExample;
import com.neusoft.smart.pos.trade.persistent.mapper.BillSettlementCycleMapper;
import lombok.val;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author zcf
 * @date 2018-10-30 10：43
 * @description 账单结算周期信息管理使用Repository
 */
@Component
public class BillSettlementCycleRepository {

	@Resource
	private BillSettlementCycleMapper billSettlementCycleMapper;
	
	/**
	 * 根据集团编号查询结算周期信息方法
	 * @param orgId：集团编号
	 * @return
	 */
	public BillSettlementCycle queryBillSettlementCycleByOrgId(Integer orgId){
		val example = new BillSettlementCycleExample();
		example.createCriteria()
				.andOrgIdEqualTo(orgId)
				.andShopIdEqualTo(0);
		val billSettlementCycleList = billSettlementCycleMapper.selectByExample(example);
		return billSettlementCycleList.size()>0?billSettlementCycleList.get(0):null;
	}
	
	/**
	 * 结算周期信息保存方法
	 * @return
	 */
	public Boolean saveBillSettlementCycleByOrgId(BillSettlementCycle billSettlementCycle){
		val count = billSettlementCycleMapper.insertSelective(billSettlementCycle);
		return count>0?true:false;
	}
	
	/**
	 * 结算周期信息更新方法
	 * @return
	 */
	public Boolean updateBillSettlementCycleByOrgId(Integer orgId,BillSettlementCycle billSettlementCycle){
		val example = new BillSettlementCycleExample();
		example.createCriteria().andOrgIdEqualTo(orgId);
		val result = billSettlementCycleMapper.updateByExampleSelective(billSettlementCycle,example);
		return result>0?true:false;
	}
	
}
