package com.ruoyi.web.work.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.Platform;
import com.ruoyi.web.work.service.IPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 平台信息
 * @author lsw
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/work/platform")
public class PlatformController extends BaseController {
    @Autowired
    private IPlatformService platformService;

    @Autowired
    private RedisCache redisCache;

    @GetMapping(value = "/detail")
    public AjaxResult detail(){
        return AjaxResult.success(platformService.getById(1));
    }


    @PreAuthorize("@ss.hasPermi('work:platform:edit')")
    @Log(title = "平台信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Platform platform){
        boolean row = platformService.updateById(platform);
        if (row) {
            redisCache.setCacheObject(CacheConstants.APP_PLATFORM, platform);
        }
        return toAjax(row);
    }
}
