package com.kmall.admin.service.impl;

import com.kmall.admin.dao.ThirdMerchantBizDao;
import com.kmall.admin.entity.ThirdMerchantBizEntity;
import com.kmall.admin.service.ThirdMerchantBizService;
import com.kmall.common.utils.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 第三方商户表Service实现类
 *
 * @author huangyq
 * @email admin@qhdswl.com
 * @date 2019-02-15 11:43:32
 */
@Service("thirdMerchantBizService")
public class ThirdMerchantBizServiceImpl implements ThirdMerchantBizService {
    @Autowired
    private ThirdMerchantBizDao thirdMerchantBizDao;

    @Override
    public ThirdMerchantBizEntity queryObject(Integer thirdMerchSn) {
        return thirdMerchantBizDao.queryObject(thirdMerchSn);
    }
    @Override
    public ThirdMerchantBizEntity getThirdMerchangByCode(String thirdMerchCode){
        return thirdMerchantBizDao.getThirdMerchangByCode(thirdMerchCode);
    }
    @Override
    public List<ThirdMerchantBizEntity> queryList(Map<String, Object> map) {
        return thirdMerchantBizDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return thirdMerchantBizDao.queryTotal(map);
    }

    @Override
    public int save(ThirdMerchantBizEntity thirdMerchantBiz) {
        ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(thirdMerchantBiz.getThirdPartyMerchCode());
        if(thirdMerchantBizEntity != null){
            throw new RRException("第三方商户编号为【"+thirdMerchantBiz.getThirdPartyMerchCode()+"】的第三方商户信息已存在");
        }
        thirdMerchantBiz.setCreateTime(new Date());
        thirdMerchantBiz.setModTime(new Date());
        return thirdMerchantBizDao.save(thirdMerchantBiz);
    }

    @Override
    public int update(ThirdMerchantBizEntity thirdMerchantBiz) {
        ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(thirdMerchantBiz.getThirdPartyMerchCode());
        if (thirdMerchantBizEntity != null && !thirdMerchantBizEntity.getThirdMerchSn().equals(thirdMerchantBiz.getThirdMerchSn())) {
            throw new RRException("第三方商户编号为【"+thirdMerchantBiz.getThirdPartyMerchCode()+"】的第三方商户信息已存在");
        }
        thirdMerchantBiz.setModTime(new Date());
        return thirdMerchantBizDao.update(thirdMerchantBiz);
    }

    @Override
    public int delete(Integer thirdMerchSn) {
        return thirdMerchantBizDao.delete(thirdMerchSn);
    }

    @Override
    public int deleteBatch(Integer[]thirdMerchSns) {
        return thirdMerchantBizDao.deleteBatch(thirdMerchSns);
    }
}
