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

import java.util.Collections;
import java.util.List;

import com.ruoyi.common.utils.uuid.Seq;
import com.ruoyi.system.domain.TdPropertyInfo;
import com.ruoyi.system.service.ITdPropertyInfoService;
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.TdPropertyManager;
import com.ruoyi.system.service.ITdPropertyManagerService;
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-26
 */
@Controller
@RequestMapping("/system/property")
public class TdPropertyManagerController extends BaseController
{
    private String prefix = "system/property/property";

    @Autowired
    private ITdPropertyManagerService tdPropertyManagerService;
    @Autowired
    private ITdPropertyInfoService tdPropertyInfoService;

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

    /**
     * 查询资产登记列表
     */
    @RequiresPermissions("system:property:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdPropertyManager tdPropertyManager)
    {
        startPage();
        List<TdPropertyManager> list = tdPropertyManagerService.selectTdPropertyManagerList(tdPropertyManager);
        return getDataTable(list);
    }

    /**
     * 导出资产登记列表
     */
    @RequiresPermissions("system:property:export")
    @Log(title = "资产登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TdPropertyManager tdPropertyManager)
    {
        List<TdPropertyManager> list = tdPropertyManagerService.selectTdPropertyManagerList(tdPropertyManager);
        ExcelUtil<TdPropertyManager> util = new ExcelUtil<TdPropertyManager>(TdPropertyManager.class);
        return util.exportExcel(list, "资产登记数据");
    }

    /**
     * 新增资产登记
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("sysuser",getSysUser());
        return prefix + "/add";
    }

    /**
     * 新增保存资产登记
     */
    @RequiresPermissions("system:property:add")
    @Log(title = "资产登记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TdPropertyManager tdPropertyManager)
    {
        tdPropertyManager.setUseId("Property_"+ Seq.getId(Seq.commSeqType));
        return toAjax(tdPropertyManagerService.insertTdPropertyManager(tdPropertyManager));
    }

    /**
     * 修改资产登记
     */
    @RequiresPermissions("system:property:edit")
    @GetMapping("/edit/{useId}")
    public String edit(@PathVariable("useId") String useId, ModelMap mmap)
    {
        TdPropertyManager tdPropertyManager = tdPropertyManagerService.selectTdPropertyManagerByUseId(useId);
        mmap.put("tdPropertyManager", tdPropertyManager);
        return prefix + "/edit";
    }

    /**
     * 修改保存资产登记
     */
    @RequiresPermissions("system:property:edit")
    @Log(title = "资产登记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TdPropertyManager tdPropertyManager)
    {
        return toAjax(tdPropertyManagerService.updateTdPropertyManager(tdPropertyManager));
    }

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

    /**
     * 添加资产条目
     */
    @RequiresPermissions("system:property:list")
    @GetMapping("/detail/{useId}")
    public String detail(@PathVariable("useId") String useId, ModelMap mmap)
    {
        mmap.put("useId",useId);
        return "system/property/data/propertyinfo";
    }

}
