package com.ruoyi.web.modules.store.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
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.web.modules.store.constant.ShopConstants;
import com.ruoyi.web.modules.store.dto.ShopSettingsDTO;
import com.ruoyi.web.modules.store.service.IShopGlobalConfigService;

/**
 * 平台端店铺全局设置（针对所有店铺）
 */
@RestController
@RequestMapping("/agri/shopSetting")
public class ShopGlobalSettingController extends BaseController
{
    @Autowired
    private IShopGlobalConfigService globalConfigService;

    @PreAuthorize("@ss.hasPermi('agri:shop:setting')")
    @GetMapping
    public AjaxResult getSettings()
    {
        return success(globalConfigService.getGlobalSettings());
    }

    @PreAuthorize("@ss.hasPermi('agri:shop:setting')")
    @Log(title = "店铺设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult updateSettings(@RequestBody ShopSettingsDTO dto)
    {
        globalConfigService.updateGlobalSettings(dto, getUsername());
        return AjaxResult.success(ShopConstants.MSG_SETTINGS_SAVED);
    }
}
