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

import java.util.List;

import com.ruoyi.common.utils.uuid.Seq;
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.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TdPropertyInfo;
import com.ruoyi.system.service.ITdPropertyInfoService;
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-29
 */
@Controller
@RequestMapping("/system/property/data")
public class TdPropertyInfoController extends BaseController
{
    private String prefix = "system/property/data";

    @Autowired
    private ITdPropertyInfoService tdPropertyInfoService;

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

    /**
     * 查询资产管理列表
     */
    @RequiresPermissions("system:property:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdPropertyInfo tdPropertyInfo)
    {
        startPage();
        List<TdPropertyInfo> tdPropertyInfos = tdPropertyInfoService.selectTdPropertyInfoList(tdPropertyInfo);
        return getDataTable(tdPropertyInfos);
    }

    /**
     * 导出资产管理列表
     */
    @RequiresPermissions("system:property:export")
    @Log(title = "资产管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TdPropertyInfo tdPropertyInfo)
    {
        List<TdPropertyInfo> list = tdPropertyInfoService.selectTdPropertyInfoList(tdPropertyInfo);
        ExcelUtil<TdPropertyInfo> util = new ExcelUtil<TdPropertyInfo>(TdPropertyInfo.class);
        return util.exportExcel(list, "资产管理数据");
    }

    /**
     * 新增资产管理
     */
    @RequiresPermissions("system:property:add")
    @GetMapping("/add/{useId}")
    public String add(@PathVariable("useId") String useId, ModelMap mmap)
    {
        mmap.put("useId", useId);
        return prefix + "/add";
    }

    /**
     * 新增保存资产管理
     */
    @RequiresPermissions("system:property:add")
    @Log(title = "资产管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TdPropertyInfo tdPropertyInfo)
    {
        tdPropertyInfo.setId("Register_" + Seq.getId(Seq.commSeqType));
        return toAjax(tdPropertyInfoService.insertTdPropertyInfo(tdPropertyInfo));
    }

    /**
     * 修改资产管理
     */
    @RequiresPermissions("system:property:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TdPropertyInfo tdPropertyInfo = tdPropertyInfoService.selectTdPropertyInfoById(id);
        mmap.put("tdPropertyInfo", tdPropertyInfo);
        return prefix + "/edit";
    }
    /**
     * 修改资产管理
     */
    @RequiresPermissions("system:property:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TdPropertyInfo tdPropertyInfo = tdPropertyInfoService.selectTdPropertyInfoById(id);
        mmap.put("tdPropertyInfo", tdPropertyInfo);
        return prefix + "/detail";
    }
    /**
     * 修改保存资产管理
     */
    @RequiresPermissions("system:property:edit")
    @Log(title = "资产管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TdPropertyInfo tdPropertyInfo)
    {
        return toAjax(tdPropertyInfoService.updateTdPropertyInfo(tdPropertyInfo));
    }

    /**
     * 删除资产管理
     */
    @RequiresPermissions("system:property:remove")
    @Log(title = "资产管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tdPropertyInfoService.deleteTdPropertyInfoByIds(ids));
    }


}
