package com.ruoyi.web.controller.jarvis;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
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.ProductJdConfig;
import com.ruoyi.jarvis.service.IProductJdConfigService;

/**
 * 产品京东配置Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/jarvis/productJdConfig")
public class ProductJdConfigController extends BaseController
{
    @Autowired
    private IProductJdConfigService productJdConfigService;

    /**
     * 查询产品京东配置列表
     */
    @GetMapping("/list")
    public AjaxResult list()
    {
        List<ProductJdConfig> list = productJdConfigService.selectProductJdConfigList();
        return AjaxResult.success(list);
    }

    /**
     * 获取产品京东配置详细信息
     */

    @GetMapping(value = "/{productModel}")
    public AjaxResult getInfo(@PathVariable("productModel") String productModel)
    {
        return success(productJdConfigService.selectProductJdConfigByModel(productModel));
    }

    /**
     * 新增产品京东配置
     */

    @Log(title = "产品京东配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductJdConfig productJdConfig)
    {
        // 检查是否已存在
        ProductJdConfig existing = productJdConfigService.selectProductJdConfigByModel(productJdConfig.getProductModel());
        if (existing != null) {
            return error("产品型号已存在");
        }
        return toAjax(productJdConfigService.insertProductJdConfig(productJdConfig));
    }

    /**
     * 修改产品京东配置
     */

    @Log(title = "产品京东配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductJdConfig productJdConfig)
    {
        return toAjax(productJdConfigService.updateProductJdConfig(productJdConfig));
    }

    /**
     * 删除产品京东配置
     */

    @Log(title = "产品京东配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{productModels}")
    public AjaxResult remove(@PathVariable String[] productModels)
    {
        return toAjax(productJdConfigService.deleteProductJdConfigByModels(productModels));
    }

    /**
     * 初始化默认数据
     */

    @Log(title = "产品京东配置", businessType = BusinessType.OTHER)
    @PostMapping("/initData")
    public AjaxResult initData()
    {
        productJdConfigService.initDefaultData();
        return success("初始化成功");
    }
}

