package com.bonus.material.basic.service.impl;

import java.util.List;
import java.util.Optional;

import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.material.basic.mapper.BmCompanyAddressMapper;
import com.bonus.material.basic.domain.BmCompanyAddress;
import com.bonus.material.basic.service.IBmCompanyAddressService;

import javax.annotation.Resource;

/**
 * 企业地址Service业务层处理
 */
@Service
public class BmCompanyAddressServiceImpl implements IBmCompanyAddressService {
    
    @Resource
    private BmCompanyAddressMapper bmCompanyAddressMapper;

    /**
     * 查询企业地址
     * 
     * @param id 企业地址主键
     * @return 企业地址
     */
    @Override
    public BmCompanyAddress selectBmCompanyAddressById(Long id) {
        return bmCompanyAddressMapper.selectBmCompanyAddressById(id);
    }

    /**
     * 查询企业地址列表
     * 
     * @param bmCompanyAddress 企业地址
     * @return 企业地址
     */
    @Override
    public List<BmCompanyAddress> selectBmCompanyAddressList(BmCompanyAddress bmCompanyAddress) {
        return bmCompanyAddressMapper.selectBmCompanyAddressList(bmCompanyAddress);
    }

    /**
     * 新增企业地址
     * 
     * @param bmCompanyAddress 企业地址
     * @return 结果
     */
    @Override
    public int insertBmCompanyAddress(BmCompanyAddress bmCompanyAddress) {
        bmCompanyAddress.setCompanyId(Optional.ofNullable(SecurityUtils.getLoginUser().getSysUser().getCompanyId())
                .orElse(SecurityUtils.getLoginUser().getSysUser().getDeptId()));
        bmCompanyAddress.setCreateTime(DateUtils.getNowDate());
        try {
            return bmCompanyAddressMapper.insertBmCompanyAddress(bmCompanyAddress);
        } catch (Exception e) {
            throw new ServiceException("错误信息描述");
        }
    }

    /**
     * 修改企业地址
     * 
     * @param bmCompanyAddress 企业地址
     * @return 结果
     */
    @Override
    public int updateBmCompanyAddress(BmCompanyAddress bmCompanyAddress) {
        bmCompanyAddress.setUpdateTime(DateUtils.getNowDate());
        try {
            return bmCompanyAddressMapper.updateBmCompanyAddress(bmCompanyAddress);
        } catch (Exception e) {
            throw new ServiceException("错误信息描述");
        }
    }

    /**
     * 批量删除企业地址
     * 
     * @param ids 需要删除的企业地址主键
     * @return 结果
     */
    @Override
    public int deleteBmCompanyAddressByIds(Long[] ids) {
        return bmCompanyAddressMapper.deleteBmCompanyAddressByIds(ids);
    }

    /**
     * 删除企业地址信息
     * 
     * @param id 企业地址主键
     * @return 结果
     */
    @Override
    public int deleteBmCompanyAddressById(Long id) {
        return bmCompanyAddressMapper.deleteBmCompanyAddressById(id);
    }
}
