package com.ruoyi.web.modules.mall.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.mall.constant.MallConfigConstants;
import com.ruoyi.web.modules.mall.dto.MallSettingSaveDTO;
import com.ruoyi.web.modules.mall.service.IMallConfigService;

/**
 * 平台 · 商城设置
 */
@RestController
@RequestMapping("/agri/mallSetting")
public class MallSettingController extends BaseController
{
    @Autowired
    private IMallConfigService mallConfigService;

    @PreAuthorize("@ss.hasPermi('agri:mall:setting:query')")
    @GetMapping
    public AjaxResult getSettings()
    {
        return success(mallConfigService.getSettings());
    }

    @PreAuthorize("@ss.hasPermi('agri:mall:setting:edit')")
    @Log(title = "商城设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult updateSettings(@RequestBody MallSettingSaveDTO dto)
    {
        mallConfigService.updateSettings(dto, getUsername());
        return AjaxResult.success(MallConfigConstants.MSG_SAVED);
    }
}
