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

import com.railway.business.baseinfo.domain.BaseSubstation;
import com.railway.business.baseinfo.domain.vo.BaseDeptSubstationVo;
import com.railway.business.baseinfo.mapper.BaseSubstationMapper;
import com.railway.business.baseinfo.service.IBaseSubstationService;
import com.railway.common.utils.SecurityUtils;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * primary key (substation_id) using
 *
 * @author author
 * @date 2021/10/16
 */
@Service
@Transactional(readOnly = true)
public class BaseSubstationServiceImpl implements IBaseSubstationService {

  private final BaseSubstationMapper baseSubstationMapper;

  public BaseSubstationServiceImpl(BaseSubstationMapper baseSubstationMapper) {
    this.baseSubstationMapper = baseSubstationMapper;
  }

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

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

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

  /**
   * 获取单个
   */
  @Override
  public BaseSubstation getInfo(String substationId) {
    return baseSubstationMapper.getInfo(substationId);
  }

  /**
   * 查询列表
   */
  @Override
  public List<BaseSubstation> getList(BaseSubstation baseSubstation) {
    return baseSubstationMapper.getList(baseSubstation);
  }

  @Override
  public List<BaseDeptSubstationVo> getDeptSubList(Long lineId) {
    return baseSubstationMapper.getDeptSubList(lineId);
  }
}
