package com.railway.business.baseinfo.service.impl;

import com.railway.business.baseinfo.domain.BusBlq;
import com.railway.business.baseinfo.mapper.BusBlqMapper;
import com.railway.business.baseinfo.service.IBusBlqService;
import com.railway.common.utils.SecurityUtils;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 基础数据-避雷器
 *
 * @author wuhonghao
 * @date 2021/10/17
 */
@Service
@Transactional(readOnly = true)
public class BusBlqServiceImpl implements IBusBlqService {

  private final BusBlqMapper busBlqMapper;

  public BusBlqServiceImpl(BusBlqMapper busBlqMapper) {
    this.busBlqMapper = busBlqMapper;
  }

  /**
   * 新增
   */
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int create(BusBlq busBlq) {
    busBlq.setCreateTime(new Date());
    busBlq.setCreateBy(SecurityUtils.getUsername());
    return busBlqMapper.insert(busBlq);
  }

  /**
   * 删除
   */
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int delete(String[] ids) {
    int r = 0;
    for (String id : ids) {
      int j = busBlqMapper.delete(id);
      r = r + j;
    }
    return r;
  }

  /**
   * 更新
   */
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int update(BusBlq busBlq) {
    busBlq.setUpdateTime(new Date());
    busBlq.setUpdateBy(SecurityUtils.getUsername());
    return busBlqMapper.update(busBlq);
  }

  /**
   * 获取单个
   */
  @Override
  public BusBlq getInfo(String id) {
    return busBlqMapper.getInfo(id);
  }

  /**
   * 查询列表
   */
  @Override
  public List<BusBlq> getList(BusBlq busBlq) {
    return busBlqMapper.getList(busBlq);
  }
}
