package com.rongwei.training.controller;

import com.rongwei.rwcommon.base.R;
import com.rongwei.rwcommon.utils.StringUtils;
import com.rongwei.trainingcommon.sys.service.SubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * SubjectController class
 *
 * @author XH
 * @date 2020/11/23
 */
@RestController
@RequestMapping("subject")
@Slf4j
public class SubjectController {
    @Autowired
    private SubjectService subjectService;


    @PostMapping("/check")
    public R saveEmpExam(@RequestBody List<String> subjectIds) {
        try {
            log.info("开始校验考题是否被试卷所引用");
            return subjectService.checkInfo(subjectIds);
        } catch (Exception e) {
            log.error(StringUtils.spliceErrorMsg(e), e.fillInStackTrace());
            return R.queryError();
        }

    }


    @PostMapping("/importFile")
    public R importFile(@RequestParam("file") MultipartFile multipartFile){
        if (multipartFile == null) {
            return R.error("文件解析失败");
        }
        try {
            log.info("进入接口：/importFile/importFile");
            return subjectService.importFile(multipartFile);
            // return null;
        }catch (Exception e){
            return R.error(e.getMessage());
        }
    }
}
