package beilv.shopping.controller;

import java.util.List;

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 beilv.common.annotation.Log;
import beilv.common.enums.BusinessType;
import beilv.shopping.domain.QmjsShoppingMall;
import beilv.shopping.service.IQmjsShoppingMallService;
import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.common.utils.poi.ExcelUtil;
import beilv.common.core.page.TableDataInfo;

/**
 * 商城Controller
 * 
 * @author lc
 * @date 2025-01-02
 */
@Controller
@RequestMapping("/system/mall")
public class QmjsShoppingMallController extends BaseController
{
    private String prefix = "system/mall";

    @Autowired
    private IQmjsShoppingMallService qmjsShoppingMallService;

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

    /**
     * 查询商城列表
     */
    @RequiresPermissions("system:mall:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QmjsShoppingMall qmjsShoppingMall)
    {
        startPage();
        List<QmjsShoppingMall> list = qmjsShoppingMallService.selectQmjsShoppingMallList(qmjsShoppingMall);
        return getDataTable(list);
    }

    /**
     * 导出商城列表
     */
    @RequiresPermissions("system:mall:export")
    @Log(title = "商城", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QmjsShoppingMall qmjsShoppingMall)
    {
        List<QmjsShoppingMall> list = qmjsShoppingMallService.selectQmjsShoppingMallList(qmjsShoppingMall);
        ExcelUtil<QmjsShoppingMall> util = new ExcelUtil<QmjsShoppingMall>(QmjsShoppingMall.class);
        return util.exportExcel(list, "商城数据");
    }

    /**
     * 新增商城
     */
    @RequiresPermissions("system:mall:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商城
     */
    @RequiresPermissions("system:mall:add")
    @Log(title = "商城", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QmjsShoppingMall qmjsShoppingMall)
    {
        qmjsShoppingMall.setGoodsState("1");
        return toAjax(qmjsShoppingMallService.insertQmjsShoppingMall(qmjsShoppingMall));
    }

    /**
     * 修改商城
     */
    @RequiresPermissions("system:mall:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QmjsShoppingMall qmjsShoppingMall = qmjsShoppingMallService.selectQmjsShoppingMallById(id);
        mmap.put("qmjsShoppingMall", qmjsShoppingMall);
        return prefix + "/edit";
    }

    /**
     * 修改保存商城
     */
    @RequiresPermissions("system:mall:edit")
    @Log(title = "商城", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QmjsShoppingMall qmjsShoppingMall)
    {
        return toAjax(qmjsShoppingMallService.updateQmjsShoppingMall(qmjsShoppingMall));
    }

    /**
     * 删除商城
     */
    @RequiresPermissions("system:mall:remove")
    @Log(title = "商城", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qmjsShoppingMallService.deleteQmjsShoppingMallByIds(ids));
    }

    /**
     * 商品状态修改
     */
    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:mall:edit")
    @PostMapping("/goodsStatus")
    @ResponseBody
    public AjaxResult goodsStatus(QmjsShoppingMall qmjsShoppingMall)
    {
        return toAjax(qmjsShoppingMallService.goodsStatus(qmjsShoppingMall));
    }
}
