package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.entity.QuestionnaireTopic;
import com.ym.mec.biz.dal.page.QuestionnaireTopicQueryInfo;
import com.ym.mec.biz.service.QuestionnaireTopicService;
import com.ym.mec.common.controller.BaseController;
import com.yonge.log.model.AuditLogAnnotation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RequestMapping("questionnaireTopic")
@Api(tags = "问题分类")
@RestController
public class QuestionnaireTopicController extends BaseController {

    @Autowired
    private QuestionnaireTopicService questionnaireTopicService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('questionnaireTopic/add')")
    @AuditLogAnnotation(operateName = "新增")
    public Object add(@RequestBody QuestionnaireTopic questionnaireTopic) {
        questionnaireTopicService.add(questionnaireTopic);
        return succeed();
    }

    @ApiOperation(value = "获取详情")
    @GetMapping("/getDetail")
    @PreAuthorize("@pcs.hasPermissions('questionnaireTopic/getDetail')")
    @AuditLogAnnotation(operateName = "新增")
    public Object getDetail(Integer id) {
        return succeed(questionnaireTopicService.getDetail(id));
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    @PreAuthorize("@pcs.hasPermissions('questionnaireTopic/update')")
    @AuditLogAnnotation(operateName = "修改")
    public Object update(@RequestBody QuestionnaireTopic questionnaireTopic) {
        questionnaireTopicService.modify(questionnaireTopic);
        return succeed();
    }

    @ApiOperation(value = "启用/停用")
    @PostMapping("/updateStatus")
    @PreAuthorize("@pcs.hasPermissions('questionnaireTopic/updateStatus')")
    @AuditLogAnnotation(operateName = "启用/停用")
    public Object updateStatus(Integer topicId,Integer status) {
        QuestionnaireTopic questionnaireTopic = questionnaireTopicService.get(topicId);
        questionnaireTopic.setStatus(status);
        questionnaireTopicService.update(questionnaireTopic);
        return succeed();
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('questionnaireTopic/queryPage')")
    public Object queryPage(QuestionnaireTopicQueryInfo queryInfo) {
        return succeed(questionnaireTopicService.queryPage(queryInfo));
    }
}
