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

import com.railway.business.baseinfo.service.IBaseStationService;
import com.railway.business.catenary.domain.BusJcebQmjcjl;
import com.railway.business.catenary.domain.vo.JcebQueryVo;
import com.railway.business.catenary.mapper.BusJcebQmjcjlMapper;
import com.railway.business.catenary.service.IBusJcebQmjcjlService;
import com.railway.business.catenary.util.JcebQueryUtil;
import com.railway.common.utils.StringUtils;
import com.railway.common.utils.poi.EasyExcelUtil;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 检测表-全面检查记录
 *
 * @author author
 * @date 2021/10/19
 */
@Service
public class BusJcebQmjcjlServiceImpl extends BusJcebServiceImpl<BusJcebQmjcjl>
    implements IBusJcebQmjcjlService {

  private final BusJcebQmjcjlMapper busJcebQmjcjlMapper;

  public BusJcebQmjcjlServiceImpl(BusJcebQmjcjlMapper busJcebQmjcjlMapper,
      IBaseStationService stationService) {
    super(busJcebQmjcjlMapper, stationService);
    this.busJcebQmjcjlMapper = busJcebQmjcjlMapper;
  }

  /**
   * 新增
   */
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int create(BusJcebQmjcjl busJcebQmjcjl) {
    setCreate(busJcebQmjcjl);
    return busJcebQmjcjlMapper.insert(busJcebQmjcjl);
  }

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

  /**
   * 更新
   */
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int update(BusJcebQmjcjl busJcebQmjcjl) {
    setUpdate(busJcebQmjcjl);
    return busJcebQmjcjlMapper.update(busJcebQmjcjl);
  }

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

  /**
   * 查询列表
   */
  @Override
  public List<BusJcebQmjcjl> getList(BusJcebQmjcjl busJcebQmjcjl) {
    setList(busJcebQmjcjl);
    return busJcebQmjcjlMapper.getList(busJcebQmjcjl);
  }

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

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

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

  @Override
  public String exportExcel(JcebQueryVo query) {
    JcebQueryUtil.setBusJcebQuery(query);
    List<BusJcebQmjcjl> list = busJcebQmjcjlMapper.getJcebList(query);
    String fileName = "全面检查记录.xls";
    String templateFileName = "excel/template/全面检查记录.xls";
    return new EasyExcelUtil().writeExcel(fileName, templateFileName, list);
  }
}
