package com.ruoyi.project.ticket.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.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.ticket.domain.TTicketId;
import com.ruoyi.project.ticket.service.ITTicketIdService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 作业票编号Controller
 *
 * @author ruoyi
 * @date 2022-01-10
 */
@RestController
@RequestMapping("/ticket/id")
public class TTicketIdController extends BaseController
{
    @Autowired
    private ITTicketIdService tTicketIdService;

    //添加票据id
    public synchronized Long createId(TTicketId tTicketId){
        TTicketId t = tTicketIdService.selectTTicketIdById(tTicketId.getId());
        Long id = t.getTicketId();
        Long newId = id +1;
        t.setTicketId(newId);
        tTicketIdService.updateTTicketId(t);
        return newId;
    };

    /**
     * 查询作业票编号列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TTicketId tTicketId)
    {
        startPage();
        List<TTicketId> list = tTicketIdService.selectTTicketIdList(tTicketId);
        return getDataTable(list);
    }

    /**
     * 导出作业票编号列表
     */
    @Log(title = "作业票编号", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TTicketId tTicketId)
    {
        List<TTicketId> list = tTicketIdService.selectTTicketIdList(tTicketId);
        ExcelUtil<TTicketId> util = new ExcelUtil<TTicketId>(TTicketId.class);
        return util.exportExcel(list, "id");
    }

    /**
     * 获取作业票编号详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tTicketIdService.selectTTicketIdById(id));
    }

    /**
     * 新增作业票编号
     */
    @Log(title = "作业票编号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTicketId tTicketId)
    {
        return toAjax(tTicketIdService.insertTTicketId(tTicketId));
    }

    /**
     * 修改作业票编号
     */
    @Log(title = "作业票编号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTicketId tTicketId)
    {
        return toAjax(tTicketIdService.updateTTicketId(tTicketId));
    }

    /**
     * 删除作业票编号
     */
    @Log(title = "作业票编号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTicketIdService.deleteTTicketIdByIds(ids));
    }
}
