package com.activiti6.service.activiti.impl;

import com.activiti6.common.utils.DateUtils;
import com.activiti6.domain.DbTableHis;
import com.activiti6.mapper.DbTableHisMapper;
import com.activiti6.service.activiti.IDbTableHisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 流程历史单Service业务层处理
 *
 * @author xtd
 * @date 2020-04-14
 */
@Service
public class DbTableHisServiceImpl implements IDbTableHisService {
    @Autowired
    private DbTableHisMapper dbTableHisMapper;

    /**
     * 查询流程历史单
     *
     * @param instanceId 流程历史单ID
     * @return 流程历史单
     */
    @Override
    public DbTableHis selectDbTableHisById(String instanceId) {
        return dbTableHisMapper.selectDbTableHisById(instanceId);
    }

    /**
     * 查询流程历史单列表
     *
     * @param dbTableHis 流程历史单
     * @return 流程历史单
     */
    @Override
    public List<DbTableHis> selectDbTableHisList(DbTableHis dbTableHis) {
        return dbTableHisMapper.selectDbTableHisList(dbTableHis);
    }

    /**
     * 新增流程历史单
     *
     * @param dbTableHis 流程历史单
     * @return 结果
     */
    @Override
    public int insertDbTableHis(DbTableHis dbTableHis) {
        dbTableHis.setCreateTime(DateUtils.getNowDate());
        return dbTableHisMapper.insertDbTableHis(dbTableHis);
    }

    /**
     * 修改流程历史单
     *
     * @param dbTableHis 流程历史单
     * @return 结果
     */
    @Override
    public int updateDbTableHis(DbTableHis dbTableHis) {
        dbTableHis.setUpdateTime(DateUtils.getNowDate());
        return dbTableHisMapper.updateDbTableHis(dbTableHis);
    }

    /**
     * 批量删除流程历史单
     *
     * @param instanceIds 需要删除的流程历史单ID
     * @return 结果
     */
    @Override
    public int deleteDbTableHisByIds(String[] instanceIds) {
        return dbTableHisMapper.deleteDbTableHisByIds(instanceIds);
    }

    /**
     * 删除流程历史单信息
     *
     * @param instanceId 流程历史单ID
     * @return 结果
     */
    @Override
    public int deleteDbTableHisById(String instanceId) {
        return dbTableHisMapper.deleteDbTableHisById(instanceId);
    }

    @Override
    public int insertDbTableHis(String processInstanceId, Long tableId, String tableName) {
        DbTableHis dbTableHis = new DbTableHis();
        dbTableHis.setInstanceId(processInstanceId);
        dbTableHis.setTableId(tableId);
        dbTableHis.setTableName(tableName);
        dbTableHis.setCreateTime(new Date());
        return dbTableHisMapper.insertDbTableHis(dbTableHis);
    }
}
