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.DbTodoItem;
import com.xtd.project.assets.service.IDbTodoItemService;
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-09
 */
@RestController
@RequestMapping("/assets/item")
public class DbTodoItemController extends BaseController
{
    @Autowired
    private IDbTodoItemService dbTodoItemService;

    /**
     * 查询待办事项列表
     */
    @PreAuthorize("@ss.hasPermi('assets:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbTodoItem dbTodoItem)
    {
        startPage();
        List<DbTodoItem> list = dbTodoItemService.selectDbTodoItemList(dbTodoItem);
        return getDataTable(list);
    }

    /**
     * 导出待办事项列表
     */
    @PreAuthorize("@ss.hasPermi('assets:item:export')")
    @Log(title = "待办事项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DbTodoItem dbTodoItem)
    {
        List<DbTodoItem> list = dbTodoItemService.selectDbTodoItemList(dbTodoItem);
        ExcelUtil<DbTodoItem> util = new ExcelUtil<DbTodoItem>(DbTodoItem.class);
        return util.exportExcel(list, "item");
    }

    /**
     * 获取待办事项详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dbTodoItemService.selectDbTodoItemById(id));
    }

    /**
     * 新增待办事项
     */
    @PreAuthorize("@ss.hasPermi('assets:item:add')")
    @Log(title = "待办事项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbTodoItem dbTodoItem)
    {
        return toAjax(dbTodoItemService.insertDbTodoItem(dbTodoItem));
    }

    /**
     * 修改待办事项
     */
    @PreAuthorize("@ss.hasPermi('assets:item:edit')")
    @Log(title = "待办事项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbTodoItem dbTodoItem)
    {
        return toAjax(dbTodoItemService.updateDbTodoItem(dbTodoItem));
    }

    /**
     * 删除待办事项
     */
    @PreAuthorize("@ss.hasPermi('assets:item:remove')")
    @Log(title = "待办事项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dbTodoItemService.deleteDbTodoItemByIds(ids));
    }
}
