package com.kmall.admin.service.impl;

import com.kmall.admin.dao.ThirdMerchExpressDao;
import com.kmall.admin.entity.ThirdMerchExpressEntity;
import com.kmall.admin.service.ThirdMerchExpressService;
import com.kmall.admin.utils.ShiroUtils;
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 emato
 * @email admin@qhdswl.com
 * @date 2019-04-03 16:52:21
 */
@Service("thirdMerchExpressService")
public class ThirdMerchExpressServiceImpl implements ThirdMerchExpressService {
    @Autowired
    private ThirdMerchExpressDao thirdMerchExpressDao;

    @Override
    public ThirdMerchExpressEntity queryObject(Integer id) {
        return thirdMerchExpressDao.queryObject(id);
    }

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

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

    @Override
    public int save(ThirdMerchExpressEntity thirdMerchExpress) {
        ThirdMerchExpressEntity thirdMerchExpressEntity = thirdMerchExpressDao.getThirdMerchExpressByThirdCode(thirdMerchExpress.getThirdPartyMerchCode());
        if(thirdMerchExpressEntity != null){
            throw new RRException("第三方商户编号为【"+thirdMerchExpressEntity.getThirdPartyMerchCode()+"】的第三方商户快递信息已存在");
        }
        thirdMerchExpress.setCreateTime(new Date());
        thirdMerchExpress.setCreaterSn(ShiroUtils.getUserEntity().getUsername());
        return thirdMerchExpressDao.save(thirdMerchExpress);
    }

    @Override
    public int update(ThirdMerchExpressEntity thirdMerchExpress) {
        ThirdMerchExpressEntity thirdMerchExpressEntity = thirdMerchExpressDao.getThirdMerchExpressByThirdCode(thirdMerchExpress.getThirdPartyMerchCode());
        if (thirdMerchExpressEntity != null && !thirdMerchExpressEntity.getId().equals(thirdMerchExpress.getId())) {
            throw new RRException("第三方商户编号为【"+thirdMerchExpressEntity.getThirdPartyMerchCode()+"】的第三方商户快递信息已存在");
        }
        thirdMerchExpress.setModerSn(ShiroUtils.getUserEntity().getUsername());
        thirdMerchExpress.setModTime(new Date());
        return thirdMerchExpressDao.update(thirdMerchExpress);
    }

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

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