package com.ruoyi.web.controller.jarvis;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jarvis.domain.PrdErrorTip;
import com.ruoyi.jarvis.service.IPrdErrorTipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品错误提示Controller
 *
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/jarvis/prdErrorTip")
public class PrdErrorTipController extends BaseController
{
    @Autowired
    private IPrdErrorTipService prdErrorTipService;

    /**
     * 查询商品错误提示列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PrdErrorTip prdErrorTip)
    {
        startPage();
        List<PrdErrorTip> list = prdErrorTipService.selectPrdErrorTipList(prdErrorTip);
        return getDataTable(list);
    }

    /**
     * 导出商品错误提示列表
     */
    @Log(title = "商品错误提示", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrdErrorTip prdErrorTip)
    {
        List<PrdErrorTip> list = prdErrorTipService.selectPrdErrorTipList(prdErrorTip);
        ExcelUtil<PrdErrorTip> util = new ExcelUtil<PrdErrorTip>(PrdErrorTip.class);
        return util.exportExcel(list, "商品错误提示数据");
    }

    /**
     * 获取商品错误提示详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(prdErrorTipService.selectPrdErrorTipById(id));
    }

    /**
     * 新增商品错误提示
     */
    @Log(title = "商品错误提示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrdErrorTip prdErrorTip)
    {
        return toAjax(prdErrorTipService.insertPrdErrorTip(prdErrorTip));
    }

    /**
     * 修改商品错误提示
     */
    @Log(title = "商品错误提示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrdErrorTip prdErrorTip)
    {
        return toAjax(prdErrorTipService.updatePrdErrorTip(prdErrorTip));
    }

    /**
     * 删除商品错误提示
     */
    @Log(title = "商品错误提示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prdErrorTipService.deletePrdErrorTipByIds(ids));
    }

    /**
     * 根据错误代码和子代码查询错误提示
     */
    @GetMapping("/getByCode/{errCode}/{errSubCode}")
    public AjaxResult getByCode(@PathVariable String errCode, @PathVariable String errSubCode)
    {
        return success(prdErrorTipService.selectPrdErrorTipByCode(errCode, errSubCode));
    }
}
