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

import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ModuleName;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.letter.EduLetterBoxConfig;
import com.yida.data.common.core.entity.system.enums.OperationLogTypeEnum;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.log.annotation.OperationLog;
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 java.util.List;
import javax.annotation.Resource;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ccl
 */

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

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

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

    @ApiOperation("滚动图列表")
    @GetMapping("/findConfig")
    public ResultBean<LetterBoxConfigDTO> findConfig() {
        return ResultBean.buildSuccess(configService.findConfig(FebsUtil.getCurrentUser().getDeptId()));
    }


    @ApiOperation("新增或修改配置")
    @PostMapping("/saveOrUpdateConfig")
    @OperationLog(module = ModuleName.LETTER_BOX, methods = "新增或修改配置", type = OperationLogTypeEnum.SAVE)
    public ResultBean saveOrUpdateConfig(@RequestBody LetterBoxConfigDTO config) {
        replyPersonService.saveOrUpdateConfig(config,FebsUtil.getCurrentUser().getDeptId());
        return ResultBean.buildSuccess();
    }
}
