package com.xtd.project.assets.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xtd.framework.aspectj.lang.annotation.Log;
import com.xtd.framework.aspectj.lang.enums.BusinessType;
import com.xtd.project.assets.domain.DbTableHis;
import com.xtd.project.assets.service.IDbTableHisService;
import com.xtd.framework.web.controller.BaseController;
import com.xtd.framework.web.domain.AjaxResult;
import com.xtd.common.utils.poi.ExcelUtil;
import com.xtd.framework.web.page.TableDataInfo;

/**
 * 流程历史单Controller
 *
 * @author xtd
 * @date 2020-04-14
 */
@RestController
@RequestMapping("/assets/his")
public class DbTableHisController extends BaseController
{
    @Autowired
    private IDbTableHisService dbTableHisService;

    /**
     * 查询流程历史单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DbTableHis dbTableHis)
    {
        startPage();
        List<DbTableHis> list = dbTableHisService.selectDbTableHisList(dbTableHis);
        return getDataTable(list);
    }

    /**
     * 导出流程历史单列表
     */
    @Log(title = "流程历史单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DbTableHis dbTableHis)
    {
        List<DbTableHis> list = dbTableHisService.selectDbTableHisList(dbTableHis);
        ExcelUtil<DbTableHis> util = new ExcelUtil<DbTableHis>(DbTableHis.class);
        return util.exportExcel(list, "his");
    }

    /**
     * 获取流程历史单详细信息
     */
    @GetMapping(value = "/{instanceId}")
    public AjaxResult getInfo(@PathVariable("instanceId") String instanceId)
    {
        return AjaxResult.success(dbTableHisService.selectDbTableHisById(instanceId));
    }

    /**
     * 新增流程历史单
     */
    @Log(title = "流程历史单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbTableHis dbTableHis)
    {
        return toAjax(dbTableHisService.insertDbTableHis(dbTableHis));
    }

    /**
     * 修改流程历史单
     */
    @Log(title = "流程历史单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbTableHis dbTableHis)
    {
        return toAjax(dbTableHisService.updateDbTableHis(dbTableHis));
    }

    /**
     * 删除流程历史单
     */
    @Log(title = "流程历史单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instanceIds}")
    public AjaxResult remove(@PathVariable String[] instanceIds)
    {
        return toAjax(dbTableHisService.deleteDbTableHisByIds(instanceIds));
    }
}
