package com.education.api.controller.admin.education;

import com.education.business.service.education.StuGoalInfoService;
import com.education.common.base.BaseController;
import com.education.common.utils.Result;
import com.education.common.utils.ResultCode;
import com.education.model.entity.StuGoalInfo;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * 学生导向目标批改
 */
@RequestMapping("/system/stuGoalInfo")
@RestController
public class StuGoalInfoController extends BaseController {

    @Autowired
    private StuGoalInfoService stuGoalInfoService;

    /**
     * 答题
     * @param stuGoalInfo
     * @return
     */
    @PostMapping
    //@RequiresPermissions("system:stuGoalInfo:update")
    public Result correct(@RequestBody @Validated StuGoalInfo stuGoalInfo) {
        Integer id = stuGoalInfo.getId();
        if (id == null || id == 0 ) {
            stuGoalInfoService.saveOrUpdate(stuGoalInfo);
            return Result.success();
        }
        StuGoalInfo si = stuGoalInfoService.getById(stuGoalInfo.getGoalInfoId());
        if (si.getCorrectStatus() == 2 ||  si.getCorrectStatus() == 3 ) { //批改状态,2-待批改 3-已批改
            return Result.fail(ResultCode.FAIL,"批改状态为待修改或已批改不能修改");

        }
        stuGoalInfoService.saveOrUpdate(stuGoalInfo);
        return Result.success();
    }
}