package com.yida.data.school.letter.controller;

import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.letter.EduLetterBoxConfig;
import com.yida.data.common.core.entity.letter.EduLetterBoxReplyPerson;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.dto.letterbox.LetterBoxConfigDTO;
import com.yida.data.school.letter.service.EduLetterBoxConfigService;
import com.yida.data.school.letter.service.EduLetterBoxReplyPersonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ccl
 */

@Api(tags = "校长信箱-后台配置")
@RestController
@RequestMapping("/letter/letterBoxConfig")
@RefreshScope
public class EduLetterBoxConfigController {
    @Resource
    private EduLetterBoxConfigService configService;
    @Resource
    private EduLetterBoxReplyPersonService replyPersonService;

    @ApiOperation("滚动图列表")
    @GetMapping("/findBannerList")
    @ControllerLog(operation = "撤回")
    public ResultBean<List<EduLetterBoxConfig>> findBannerList() {

        return ResultBean.buildSuccess(configService.findBannerList(FebsUtil.getCurrentUser().getDeptId()));
    }

    @ApiOperation("滚动图列表")
    @GetMapping("/findConfig")
    @ControllerLog(operation = "撤回")
    public ResultBean<LetterBoxConfigDTO> findConfig() {

        return ResultBean.buildSuccess(configService.findConfig(FebsUtil.getCurrentUser().getDeptId()));
    }


    @ApiOperation("新增或修改配置")
    @PostMapping("/saveOrUpdateConfig")
    @ControllerLog(operation = "撤回")
    public ResultBean saveOrUpdateConfig(@RequestBody LetterBoxConfigDTO config) {
        replyPersonService.saveOrUpdateConfig(config,FebsUtil.getCurrentUser().getDeptId());
        return ResultBean.buildSuccess();
    }
}
