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

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
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.*;

import java.util.List;

@Controller
@RequestMapping("/system/propertychange")
public class TdPropertyChangeController extends BaseController {
    private String prefix = "system/property/propertychange";
    @Autowired
    private ITdPropertyInfoService tdPropertyInfoService;

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

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

    /**
     * 涉密资产变更
     */
    @RequiresPermissions("system:changeproperty:change")
    @GetMapping("/edit/{id}")
    public String change(@PathVariable("id") String id, ModelMap mmap)
    {
        TdPropertyInfo tdPropertyInfo = tdPropertyInfoService.selectTdPropertyInfoById(id);
        mmap.put("tdPropertyInfo", tdPropertyInfo);
        return prefix + "/change";
    }

    /**
     * 保存变更修改
     */
    @RequiresPermissions("system:changeproperty:change")
    @Log(title = "资产变更", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult changeSave(TdPropertyInfo tdPropertyInfo)
    {
        return toAjax(tdPropertyInfoService.updateTdPropertyInfo(tdPropertyInfo));
    }

    /**
     * 涉密资产报废
     */
    @RequiresPermissions("system:changeproperty:destory")
    @GetMapping("/destory/{id}")
    public String destory(@PathVariable("id") String id, ModelMap mmap)
    {
        TdPropertyInfo tdPropertyInfo = tdPropertyInfoService.selectTdPropertyInfoById(id);
        mmap.put("tdPropertyInfo", tdPropertyInfo);
        return prefix + "/destory";
    }

    /**
     * 保存变更修改
     */
    @RequiresPermissions("system:changeproperty:destory")
    @Log(title = "资产变更", businessType = BusinessType.UPDATE)
    @PostMapping("/destory")
    @ResponseBody
    public AjaxResult destorySave(TdPropertyInfo tdPropertyInfo)
    {
        return toAjax(tdPropertyInfoService.updateTdPropertyInfo(tdPropertyInfo));
    }

}
