package com.hxhq.business.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.hxhq.business.domain.Study;
import com.hxhq.business.form.common.SignForm;
import com.hxhq.business.form.study.StudySubjectSaveForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hxhq.business.domain.StudySubject;
import com.hxhq.business.service.IStudySubjectService;
import com.hxhq.common.core.web.controller.BaseController;
import com.hxhq.common.core.web.domain.AjaxResult;
import com.hxhq.common.core.web.page.TableDataInfo;


/**
 * 试验-学科Controller
 *
 * @author hxhq
 * @date 2025-12-29
 */
@RestController
@RequestMapping("/business/studySubject")
public class StudySubjectController extends BaseController
{
    @Autowired
    private IStudySubjectService studySubjectService;

    /**
     * 查询试验-学科列表
     */
    @GetMapping("/listByStudyId")
    public AjaxResult list(Long studyId)
    {
        if(studyId==null || studyId.longValue()<=0){
            return AjaxResult.success(new ArrayList<>());
        }
        List<StudySubject> list = studySubjectService.getListByStudyId(studyId);
        return AjaxResult.success(studySubjectService.initUserIdList(list));
    }

    /**
     * 查询试验-学科列表
     */
    @GetMapping("/getAllListByStudyId")
    public AjaxResult getAllListByStudyId(Long studyId)
    {
        return AjaxResult.success(studySubjectService.getAllListByStudyId(studyId));
    }

    /**
     * 新增试验-学科信息
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody StudySubjectSaveForm form)
    {
        if(form.getStudyId()==null || form.getStudyId().longValue()<=0 || form.getSubjectList()==null || form.getSign()==null){
            return AjaxResult.error("参数有误");
        }
        studySubjectService.saveInfo(form);
        return AjaxResult.success();
    }

    /**
     * 查询是否有新增功能（学科下的才能新增+详情的填报）
     */
    @GetMapping("/isMatchSubject")
    public AjaxResult isMatchSubject(Long studySubjectId)
    {
        return AjaxResult.success(studySubjectService.isMatchSubject(studySubjectId));
    }

    /**
     * 判断用户是否是QA部门
     */
    @GetMapping("/isQa")
    public AjaxResult isQa()
    {
        return AjaxResult.success(studySubjectService.isQA());
    }


}
