package com.yida.data.system.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.common.ResultMsgType;
import com.yida.data.common.core.entity.instructions.EduInstructionsType;
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.system.service.EduInstructionsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Controller
 *
 * @author wjm
 * @date 2021-08-30 15:54:24
 */
@Api(tags = "系统指南")
@Slf4j
@Validated
@RestController
@RequestMapping("eduInstructionsType")
@RequiredArgsConstructor
public class EduInstructionsTypeController {

    private final EduInstructionsTypeService eduInstructionsTypeService;


    @ApiOperation("系统指南类型列表")
    @GetMapping("/findList")
    public ResultBean<List<EduInstructionsType>> selectInstructionsList() {
        try {
            return ResultBean.buildSuccess(eduInstructionsTypeService.selectInstructionsTypeList());
        } catch (Exception e) {
            log.error("系统指南类型列表失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }


    @ApiOperation("新增或修改系统指南类型")
    @PostMapping("/save")
    @OperationLog(module = ModuleName.INSTRUCTION, methods = "新增或修改系统指南类型", type = OperationLogTypeEnum.SAVE)
    public ResultBean insertInstructionsList(@RequestBody EduInstructionsType eduInstructionsType) {
        try {
            eduInstructionsTypeService.saveData(eduInstructionsType, FebsUtil.getCurrentUser());
            return ResultBean.buildSuccess();
        } catch (Exception e) {
            log.error("新增或修改系统指南类型失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }


    @ApiOperation("删除系统指南类型")
    @PostMapping("/removeBatch")
    @OperationLog(module = ModuleName.INSTRUCTION, methods = "删除系统指南类型", type = OperationLogTypeEnum.DELETE)
    public ResultBean removeBatch(@ApiParam("系统指南类型id") @RequestBody List<Integer> ids) {
        try {
            eduInstructionsTypeService.removeByIds(ids);
            return ResultBean.buildSuccess();
        } catch (Exception e) {
            log.error("删除系统指南类型失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

}
