package com.xingxi.web.controller.master.ipInfo.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.utils.poi.ExcelUtil;
import com.xingxi.master.ipInfo.domain.IpInfo;
import com.xingxi.master.ipInfo.service.IIpInfoService;
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/ipInfo")
public class IpInfoController extends BaseController {
    private final String prefix = "master/ipInfo";

    @Resource
    private IIpInfoService iIpInfoService;

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

    /**
     * 查询文创品牌列表
     */
    @RequiresPermissions("system:ipInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IpInfo ipInfo) {
        startPage();
        List<IpInfo> list = iIpInfoService.selectIpInfoList(ipInfo);
        return getDataTable(list);
    }

    /**
     * 导出文创品牌列表
     */
    @RequiresPermissions("system:ipInfo:export")
    @Log(title = "文创品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IpInfo ipInfo) {
        List<IpInfo> list = iIpInfoService.selectIpInfoList(ipInfo);
        ExcelUtil<IpInfo> util = new ExcelUtil<>(IpInfo.class);
        return util.exportExcel(list, "文创品牌数据");
    }

    /**
     * 新增文创品牌
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存文创品牌
     */
    @RequiresPermissions("system:ipInfo:add")
    @Log(title = "文创品牌", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IpInfo ipInfo) {
        return toAjax(iIpInfoService.insertIpInfo(ipInfo));
    }

    /**
     * 修改文创品牌
     */
    @RequiresPermissions("system:ipInfo:edit")
    @GetMapping("/edit/{ipInfoId}")
    public String edit(@PathVariable("ipInfoId") Long ipInfoId, ModelMap mMap) {
        IpInfo ipInfo = iIpInfoService.selectIpInfoByIpId(ipInfoId);
        mMap.put("ipInfo", ipInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存文创品牌
     */
    @RequiresPermissions("system:ipInfo:edit")
    @Log(title = "文创品牌", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IpInfo ipInfo) {
        return toAjax(iIpInfoService.updateIpInfo(ipInfo));
    }

    /**
     * 删除文创品牌
     */
    @RequiresPermissions("system:ipInfo:remove")
    @Log(title = "文创品牌", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(iIpInfoService.logicDeleteIpInfoByIpIds(ids));
    }
}
