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

import com.railway.business.baseinfo.service.IBaseStationService;
import com.railway.business.catenary.domain.BusJcebLbjghjl;
import com.railway.business.catenary.domain.vo.JcebQueryVo;
import com.railway.business.catenary.mapper.BusJcebLbjghjlMapper;
import com.railway.business.catenary.service.IBusJcebLbjghjlService;
import com.railway.business.catenary.util.JcebQueryUtil;
import com.railway.common.utils.StringUtils;
import com.railway.common.utils.poi.EasyExcelUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 检测表-零部件更换记录
 *
 * @author author
 * @date 2021/10/19
 */
@Service
public class BusJcebLbjghjlServiceImpl extends BusJcebServiceImpl<BusJcebLbjghjl>
    implements IBusJcebLbjghjlService {

  private final BusJcebLbjghjlMapper busJcebLbjghjlMapper;

  public BusJcebLbjghjlServiceImpl(BusJcebLbjghjlMapper busJcebLbjghjlMapper,
      IBaseStationService stationService) {
    super(busJcebLbjghjlMapper, stationService);
    this.busJcebLbjghjlMapper = busJcebLbjghjlMapper;
  }

  /**
   * 新增
   */
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int create(BusJcebLbjghjl busJcebLbjghjl) {
    setCreate(busJcebLbjghjl);
    return busJcebLbjghjlMapper.insert(busJcebLbjghjl);
  }

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

  /**
   * 更新
   */
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int update(BusJcebLbjghjl busJcebLbjghjl) {
    setUpdate(busJcebLbjghjl);
    return busJcebLbjghjlMapper.update(busJcebLbjghjl);
  }

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

  /**
   * 查询列表
   */
  @Override
  public List<BusJcebLbjghjl> getList(BusJcebLbjghjl busJcebLbjghjl) {
    setList(busJcebLbjghjl);
    return busJcebLbjghjlMapper.getList(busJcebLbjghjl);
  }

  /**
   * 提交
   *
   * @return 提交结果
   */
  @Override
  public int submit(BusJcebLbjghjl busJcebLbjghjl) {
    setSubmit(busJcebLbjghjl);
    if (StringUtils.isEmpty(busJcebLbjghjl.getId())) {
      return create(busJcebLbjghjl);
    } else {
      return update(busJcebLbjghjl);
    }
  }

  /**
   * 退回
   *
   * @return 退回结果
   */
  @Override
  public int reject(BusJcebLbjghjl busJcebLbjghjl) {
    setReject(busJcebLbjghjl);
    return update(busJcebLbjghjl);
  }

  /**
   * 确认
   *
   * @return 确认结果
   */
  @Override
  public int confirm(BusJcebLbjghjl busJcebLbjghjl) {
    setConfirm(busJcebLbjghjl);
    return update(busJcebLbjghjl);
  }

  @Override
  public String exportExcel(JcebQueryVo query) {
    JcebQueryUtil.setBusJcebQuery(query);
    List<BusJcebLbjghjl> list = busJcebLbjghjlMapper.getJcebList(query);
    String fileName = "零部件更换记录.xls";
    String templateFileName = "excel/template/零部件更换记录.xls";
    return new EasyExcelUtil().writeExcel(fileName, templateFileName, list);
  }

}
