package com.fidms.web.controller;

import com.fidms.common.annotation.Log;
import com.fidms.common.core.controller.BaseController;
import com.fidms.common.core.domain.AjaxResult;
import com.fidms.common.core.page.TableDataInfo;
import com.fidms.common.enums.BusinessType;
import com.fidms.common.utils.poi.ExcelUtil;
import com.fidms.web.domain.Model3d;
import com.fidms.web.service.IModel3dService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 3d模型Controller
 * 
 * @author Allen
 * @date 2023-05-08
 */
@RestController
@RequestMapping("/data/model")
public class Model3dController extends BaseController
{
    @Autowired
    private IModel3dService model3dService;

    /**
     * 查询3d模型列表
     */
    @PreAuthorize("@ss.hasPermi('data:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(Model3d model3d)
    {
        startPage();
        List<Model3d> list = model3dService.selectModel3dList(model3d);
        return getDataTable(list);
    }

    /**
     * 导出3d模型列表
     */
    @PreAuthorize("@ss.hasPermi('data:model:export')")
    @Log(title = "3D模型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Model3d model3d)
    {
        List<Model3d> list = model3dService.selectModel3dList(model3d);
        ExcelUtil<Model3d> util = new ExcelUtil<Model3d>(Model3d.class);
        util.exportExcel(response, list, "3D模型数据");
    }

    /**
     * 获取3d模型详细信息
     */
    @PreAuthorize("@ss.hasPermi('data:model:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(model3dService.selectModel3dById(id));
    }

    /**
     * 新增3d模型
     */
    @PreAuthorize("@ss.hasPermi('data:model:add')")
    @Log(title = "3D模型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Model3d model3d)
    {
        model3d.setCreateBy(getUsername());
        model3d.setUpdateBy(getUsername());
        return toAjax(model3dService.insertModel3d(model3d));
    }

    /**
     * 修改3d模型
     */
    @PreAuthorize("@ss.hasPermi('data:model:edit')")
    @Log(title = "3D模型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Model3d model3d)
    {
        model3d.setUpdateBy(getUsername());
        return toAjax(model3dService.updateModel3d(model3d));
    }

    /**
     * 删除3d模型
     */
    @PreAuthorize("@ss.hasPermi('data:model:remove')")
    @Log(title = "3D模型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(model3dService.deleteModel3dByIds(ids));
    }

    @GetMapping("/getOption")
    public AjaxResult getOption()
    {
        return success(model3dService.getOption());
    }
}
