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

import com.railway.business.app.domain.AppTask;
import com.railway.business.app.mapper.AppTaskMapper;
import com.railway.business.app.service.IAppTaskService;
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;

/**
 * apk更新任务
 *
 * @author ZhaoMn 
 * @date 2021/12/13
 */
@Service
public class AppTaskServiceImpl implements IAppTaskService {

  private final AppTaskMapper appTaskMapper;

  public AppTaskServiceImpl(AppTaskMapper appTaskMapper) {
    this.appTaskMapper = appTaskMapper;
  }

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

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

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

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

  /**
   * 查询列表
   */
  @Override
  public List<AppTask> getList(AppTask appTask) {
    return appTaskMapper.getList(appTask);
  }
}
