package com.kmall.admin.service.impl;

import com.kmall.admin.dao.MerchDao;
import com.kmall.admin.entity.MerchEntity;
import com.kmall.admin.service.MerchService;
import com.kmall.common.utils.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * Service实现类
 *
 * @author emato
 * @email admin@qhdswl.com
 * @date 2018-12-06 09:41:34
 */
@Service("merchService")
public class MerchServiceImpl
        implements MerchService {
    @Autowired
    private MerchDao merchDao;

    @Override
    public MerchEntity queryObject(Integer id) {
        return merchDao.queryObject(id);
    }

    @Override
    public List<MerchEntity> queryList(Map<String, Object> map) {
        return merchDao.queryList(map);
    }

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

    @Override
    public int save(MerchEntity merch) {
        MerchEntity tempMerch = merchDao.findByMerchSn(merch.getMerchSn());
        if(tempMerch != null){
            throw new RRException("商户编号已经存在");
        }
        return merchDao.save(merch);
    }

    @Override
    public int update(MerchEntity merch) {
        MerchEntity tempMerch = merchDao.findByMerchSn(merch.getMerchSn());
        if(tempMerch != null && tempMerch.getId() != merch.getId()){
            throw new RRException("商户编号已经存在");
        }
        return merchDao.update(merch);
    }

    @Override
    public int delete(Integer id) {
        return merchDao.delete(id);
    }

    @Override
    public int deleteBatch(Integer[] ids) {
        return merchDao.deleteBatch(ids);
    }
}
