package com.xingxi.web.controller.master.product.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.enums.BusinessType;
import com.xingxi.web.controller.master.product.domain.ProdTagVo;
import com.xingxi.web.controller.master.product.service.IProdTagVoService;
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.ArrayList;
import java.util.List;

/**
 * 商品标签Controller
 *
 * @author ruoyi
 * @date 2025-03-09
 */
@Controller
@RequestMapping("/master/product/prodTag")
public class ProdTagController extends BaseController {
    private final String prefix = "master/product/prodTag";

    @Resource
    private IProdTagVoService prodTagVoService;

    /**
     * 修改商品标签
     */
    @RequiresPermissions("master:product:editTag")
    @GetMapping("/editTag/{id}")
    public String editTag(@PathVariable("id") Long id, ModelMap mMap) {
        ProdTagVo cond = new ProdTagVo();
        cond.setProdId(id);
        List<ProdTagVo> prodTagVoList = new ArrayList<>();
        List<ProdTagVo> resultList = prodTagVoService.selectProdTagVoList(cond);
        if (resultList != null && resultList.size() > 0) {
            prodTagVoList = resultList;
        }
        mMap.put("prodId", id);
        mMap.put("prodTagVoList", prodTagVoList);
        return prefix + "/editTag";
    }

    /**
     * 添加商品标签
     */
    @RequiresPermissions("master:product:addTag")
    @Log(title = "商品标签", businessType = BusinessType.INSERT)
    @PostMapping("/addTags")
    @ResponseBody
    public AjaxResult addProdTags(ProdTagVo prodTagVo) {
        return toAjax(prodTagVoService.addProdTags(prodTagVo));
    }

    /**
     * 删除商品标签
     */
    @RequiresPermissions("master:product:tag:remove")
    @Log(title = "商品标签", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(ProdTagVo prodTagVo) {
        return toAjax(prodTagVoService.logicDeleteProdTagByCondition(prodTagVo));
    }
}
