package com.goer.project.model.modelProject.controller;

import java.util.List;

import com.goer.project.model.modelField.service.IModelFieldService;
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.goer.framework.aspectj.lang.annotation.Log;
import com.goer.framework.aspectj.lang.enums.BusinessType;
import com.goer.project.model.modelProject.domain.ModelProject;
import com.goer.project.model.modelProject.service.IModelProjectService;
import com.goer.framework.web.controller.BaseController;
import com.goer.framework.web.domain.AjaxResult;
import com.goer.common.utils.poi.ExcelUtil;
import com.goer.framework.web.page.TableDataInfo;

/**
 * 模型对象Controller
 * 
 * @author goer
 * @date 2022-01-17
 */
@Controller
@RequestMapping("/model/modelProject")
public class ModelProjectController extends BaseController
{
    private String prefix = "model/modelProject";

    @Autowired
    private IModelProjectService modelProjectService;

    @Autowired
    private IModelFieldService modelFieldService;

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

    /**
     * 查询模型对象列表
     */
    @RequiresPermissions("model:modelProject:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ModelProject modelProject)
    {
        startPage();
        List<ModelProject> list = modelProjectService.selectModelProjectList(modelProject);
        return getDataTable(list);
    }

    /**
     * 导出模型对象列表
     */
    @RequiresPermissions("model:modelProject:export")
    @Log(title = "模型对象", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ModelProject modelProject)
    {
        List<ModelProject> list = modelProjectService.selectModelProjectList(modelProject);
        ExcelUtil<ModelProject> util = new ExcelUtil<ModelProject>(ModelProject.class);
        return util.exportExcel(list, "模型对象数据");
    }

    /**
     * 新增模型对象
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存模型对象
     */
    @RequiresPermissions("model:modelProject:add")
    @Log(title = "模型对象", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ModelProject modelProject)
    {
        modelProject.setVersionId(0L);
        modelProject.setCreateBy(getLoginName());
        return toAjax(modelProjectService.insertModelProject(modelProject));
    }

    /**
     * 修改模型对象
     */
    @RequiresPermissions("model:modelProject:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ModelProject modelProject = modelProjectService.selectModelProjectById(id);
        mmap.put("modelProject", modelProject);
        return prefix + "/edit";
    }

    /**
     * 修改保存模型对象
     */
    @RequiresPermissions("model:modelProject:edit")
    @Log(title = "模型对象", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ModelProject modelProject)
    {
        modelProject.setUpdateBy(getLoginName());
        return toAjax(modelProjectService.updateModelProject(modelProject));
    }

    /**
     * 删除模型对象
     */
    @RequiresPermissions("model:modelProject:remove")
    @Log(title = "模型对象", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(modelProjectService.deleteModelProjectByIds(ids));
    }

}
