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.Introduction;
import com.ruoyi.web.work.service.IIntroductionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 医院介绍
 *
 * @author lsw
 * @date 2024-07-10
 */
@RestController
@RequestMapping("/work/introduction")
public class IntroductionController extends BaseController {
    @Autowired
    private IIntroductionService introductionService;

    @Autowired
    private RedisCache redisCache;

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


    @PreAuthorize("@ss.hasPermi('work:introduction:edit')")
    @Log(title = "编辑医院介绍", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Introduction introduction) {
        introduction.setBrief(introduction.getBrief().replace("/dev-api", "").replace("/prod-api", ""));
        boolean row = introductionService.updateById(introduction);
        if (row) {
            redisCache.setCacheObject(CacheConstants.APP_INFO, introduction);
        }
        return toAjax(row);
    }

}
