package com.ruoyi.project.invoice.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.ruoyi.project.invoice.mapper.TInvoiceTagMapper;
import com.ruoyi.project.system.domain.TAlarmtype;
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.invoice.domain.TInvoiceTag;
import com.ruoyi.project.invoice.service.ITInvoiceTagService;
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;

import javax.annotation.Resource;

/**
 * 工作票索引Controller
 *
 * @author ruoyi
 * @date 2022-10-09
 */
@RestController
@RequestMapping("/invoice/tag")
public class TInvoiceTagController extends BaseController {
    @Autowired
    private ITInvoiceTagService tInvoiceTagService;
    @Resource
    private TInvoiceTagMapper tInvoiceTagMapper;

    /**
     * 查询工作票索引列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInvoiceTag tInvoiceTag) {
        startPage();
        List<TInvoiceTag> list = tInvoiceTagService.selectTInvoiceTagList(tInvoiceTag);
        return getDataTable(list);
    }

    /**
     * 查询工作票索引列表
     */
    @GetMapping("/listAll")
    public List<TInvoiceTag> listAll(TInvoiceTag tInvoiceTag) {
        TInvoiceTag tag1 = new TInvoiceTag();
        tag1.setType("1");
        List<TInvoiceTag> list1 = tInvoiceTagService.selectTInvoiceTagList(tag1);
        TInvoiceTag tag0 = new TInvoiceTag();
        tag0.setType("0");
        List<TInvoiceTag> list0 = tInvoiceTagService.selectTInvoiceTagList(tag0);

        tag1.setChildren(list1);
        tag0.setChildren(list0);
        tag1.setTag("在用");
        tag0.setTag("停用");
        List<TInvoiceTag> listAll = new ArrayList<>();
        listAll.add(tag1);
        listAll.add(tag0);
        return listAll;
    }

    /**
     * 导出工作票索引列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:tag:export')")
    @Log(title = "工作票索引", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TInvoiceTag tInvoiceTag) {
        List<TInvoiceTag> list = tInvoiceTagService.selectTInvoiceTagList(tInvoiceTag);
        ExcelUtil<TInvoiceTag> util = new ExcelUtil<TInvoiceTag>(TInvoiceTag.class);
        return util.exportExcel(list, "tag");
    }

    /**
     * 获取工作票索引详细信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tInvoiceTagService.selectTInvoiceTagById(id));
    }

    /**
     * 新增工作票索引
     */
    @PreAuthorize("@ss.hasPermi('invoice:tag:add')")
    @Log(title = "工作票索引", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInvoiceTag tInvoiceTag) {
        return toAjax(tInvoiceTagService.insertTInvoiceTag(tInvoiceTag));
    }

    /**
     * 修改工作票索引
     */
    @PreAuthorize("@ss.hasPermi('invoice:tag:edit')")
    @Log(title = "工作票索引", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInvoiceTag tInvoiceTag) {

        return toAjax(tInvoiceTagService.updateTInvoiceTag(tInvoiceTag));
    }

    /**
     * 修改报警开启状态
     */
    @PreAuthorize("@ss.hasPermi('invoice:tag:edit')")
    @Log(title = "工作票索引", businessType = BusinessType.UPDATE)
    @PutMapping("/changeTagType")
    public AjaxResult changeTagType(@RequestBody TInvoiceTag tInvoiceTag) {
        return toAjax(tInvoiceTagMapper.updateType(tInvoiceTag));
    }

    /**
     * 删除工作票索引
     */
    @PreAuthorize("@ss.hasPermi('invoice:tag:remove')")
    @Log(title = "工作票索引", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tInvoiceTagService.deleteTInvoiceTagByIds(ids));
    }
}
