package com.ruoyi.web.controller.system.system;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TdIndenture;
import com.ruoyi.system.service.ITdIndentureService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修商Controller
 * 
 * @author ruoyi
 * @date 2024-04-08
 */
@Controller
@RequestMapping("/system/indenture")
public class TdIndentureController extends BaseController
{
    private String prefix = "system/indenture";

    @Autowired
    private ITdIndentureService tdIndentureService;

    @RequiresPermissions("system:indenture:view")
    @GetMapping()
    public String indenture()
    {
        return prefix + "/indenture";
    }

    /**
     * 查询维修商列表
     */
    @RequiresPermissions("system:indenture:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdIndenture tdIndenture)
    {
        startPage();
        List<TdIndenture> list = tdIndentureService.selectTdIndentureList(tdIndenture);
        return getDataTable(list);
    }

    /**
     * 导出维修商列表
     */
    @RequiresPermissions("system:indenture:export")
    @Log(title = "维修商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TdIndenture tdIndenture)
    {
        List<TdIndenture> list = tdIndentureService.selectTdIndentureList(tdIndenture);
        ExcelUtil<TdIndenture> util = new ExcelUtil<TdIndenture>(TdIndenture.class);
        return util.exportExcel(list, "维修商数据");
    }

    /**
     * 新增维修商
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("sysuser", getSysUser());
        return prefix + "/add";
    }

    /**
     * 新增保存维修商
     */
    @RequiresPermissions("system:indenture:add")
    @Log(title = "维修商", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TdIndenture tdIndenture)
    {
        tdIndenture.setCreateStaffid(getLoginName());
        tdIndenture.setCreateDate(new Date());
        return toAjax(tdIndentureService.insertTdIndenture(tdIndenture));
    }

    /**
     * 修改维修商
     */
    @RequiresPermissions("system:indenture:edit")
    @GetMapping("/edit/{indentureId}")
    public String edit(@PathVariable("indentureId") String indentureId, ModelMap mmap)
    {
        TdIndenture tdIndenture = tdIndentureService.selectTdIndentureByIndentureId(indentureId);
        mmap.put("tdIndenture", tdIndenture);
        return prefix + "/edit";
    }

    /**
     * 修改保存维修商
     */
    @RequiresPermissions("system:indenture:edit")
    @Log(title = "维修商", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TdIndenture tdIndenture)
    {
        return toAjax(tdIndentureService.updateTdIndenture(tdIndenture));
    }

    /**
     * 删除维修商
     */
    @RequiresPermissions("system:indenture:remove")
    @Log(title = "维修商", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tdIndentureService.deleteTdIndentureByIndentureIds(ids));
    }
}
