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


import com.neusoft.smart.pos.dto.trade.response.GetMchInfoResponse;
import com.neusoft.smart.pos.framework.exception.BusinessCommonException;
import com.neusoft.smart.pos.order.constants.TradeErrorCode;
import com.neusoft.smart.pos.trade.persistent.domain.TradeMchInfo;
import com.neusoft.smart.pos.trade.repository.TradeMchInfoRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service("mchInfoService")
public class MchInfoService {

	@Autowired
	private TradeMchInfoRepository tradeMchInfoRepository;

	
	/**
	 * 商户信息查询方法
	 * @return
	 */
	public GetMchInfoResponse queryMchInfo(String mcode){
		if(StringUtils.isEmpty(mcode)){
			throw new BusinessCommonException(TradeErrorCode.TRADE_MCH_MCODE_EMPTY);
		}
		TradeMchInfo tradeMchInfo = tradeMchInfoRepository.queryTradeMchInfo(mcode);
		if(null == tradeMchInfo){
			throw new BusinessCommonException(TradeErrorCode.TRADE_MCH_INFO_NOT_EXIST);
		}
		GetMchInfoResponse mchInfoResponse = new GetMchInfoResponse();
		BeanUtils.copyProperties(tradeMchInfo,mchInfoResponse);
		return mchInfoResponse;
	}
	
}
