/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.workflow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codvision.commoncore.common.ResponseEntity;
import com.codvision.commoncore.exception.BusinessException;
import com.codvision.webcore.bean.QueryPage;
import com.codvision.workflow.entity.QuestionnaireResult;
import com.codvision.workflow.service.QuestionnaireResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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;

import java.util.Map;

/**
 * @author codvision
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/questionnaireResult")
@Api(tags = "动态表单填报存值模块")
public class QuestionnaireResultController {

    private final QuestionnaireResultService service;

    @PostMapping("/getPageResult")
    @ApiOperation("分页列表")
    public ResponseEntity<IPage<QuestionnaireResult>> getPageResult(@RequestBody QueryPage<Map<String, Object>> queryPage) {
        return new ResponseEntity<IPage<QuestionnaireResult>>().data(service.getPageResult(queryPage));
    }

    @PostMapping("/add")
    @ApiOperation("添加")
    public ResponseEntity<String> add(@Validated @RequestBody QuestionnaireResult questionnaireresult) {
        service.save(questionnaireresult);
        return new ResponseEntity<String>().ok();
    }

    @PostMapping("/update")
    @ApiOperation("编辑")
    public ResponseEntity<String> update(@RequestBody QuestionnaireResult questionnaireresult) {
        ResponseEntity<String> responseEntity = new ResponseEntity<>();
        if (questionnaireresult.getId() == null) {
            throw new BusinessException(30002);
        }
        service.updateById(questionnaireresult);
        return responseEntity.ok();
    }
}
