package com.xingxi.web.controller.master.designer.controller;

import com.xingxi.common.annotation.Log;
import com.xingxi.common.core.controller.BaseController;
import com.xingxi.common.core.domain.AjaxResult;
import com.xingxi.common.core.page.TableDataInfo;
import com.xingxi.common.enums.BusinessType;
import com.xingxi.common.enums.EDelFlag;
import com.xingxi.common.utils.poi.ExcelUtil;
import com.xingxi.master.designer.domain.Designer;
import com.xingxi.master.designer.service.IDesignerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设计师Controller
 *
 * @author ruoyi
 * @date 2025-03-09
 */
@Controller
@RequestMapping("/master/designer")
public class DesignerController extends BaseController {
    private final String prefix = "master/designer";

    @Resource
    private IDesignerService designerService;

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

    /**
     * 查询设计师列表
     */
    @RequiresPermissions("master:designer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Designer designer) {
        startPage();
        List<Designer> list = designerService.selectDesignerList(designer);
        return getDataTable(list);
    }

    /**
     * 导出设计师列表
     */
    @RequiresPermissions("master:designer:export")
    @Log(title = "设计师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Designer designer) {
        List<Designer> list = designerService.selectDesignerList(designer);
        ExcelUtil<Designer> util = new ExcelUtil<>(Designer.class);
        return util.exportExcel(list, "设计师数据");
    }

    /**
     * 新增设计师
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存设计师
     */
    @RequiresPermissions("master:designer:add")
    @Log(title = "设计师", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Designer designer) {
        return toAjax(designerService.insertDesigner(designer));
    }

    /**
     * 修改设计师
     */
    @RequiresPermissions("master:designer:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mMap) {
        Designer designer = designerService.selectDesignerById(id);
        mMap.put("designer", designer);
        return prefix + "/edit";
    }

    /**
     * 修改保存设计师
     */
    @RequiresPermissions("master:designer:edit")
    @Log(title = "设计师", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Designer designer) {
        return toAjax(designerService.updateDesigner(designer));
    }

    /**
     * 删除设计师
     */
    @RequiresPermissions("master:designer:remove")
    @Log(title = "设计师", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(designerService.logicDeleteDesignerByIds(ids));
    }
}
