package com.xhkjedu.smarking.service.report.report;

import com.xhkjedu.smarking.mapper.report.reportclass.MsrClassSubjectGradeMapper;
import com.xhkjedu.smarking.mapper.report.reportother.MsrExamMapper;
import com.xhkjedu.smarking.mapper.report.reportstu.MsrStudentMapper;
import com.xhkjedu.smarking.mapper.report.reportsubject.MsrSubjectMapper;
import com.xhkjedu.smarking.model.report.reportsubject.MsrSubject;
import com.xhkjedu.smarking.vo.report.reportstu.StudentParams;
import com.xhkjedu.utils.N_Utils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 *@Description 科目报告查询服务
 *@Author ywx
 *Date 2025/1/3 14:32
 **/
@Service
public class MsrSubjectService {
    @Resource
    private MsrSubjectMapper msrSubjectMapper;
    @Resource
    private MsrStudentMapper msrStudentMapper;
    @Resource
    private MsrClassSubjectGradeMapper msrClassSubjectGradeMapper;
    @Resource
    private MsrExamMapper msrExamMapper;

    /**
     * @Description 总概览
     * @Date 2025/1/3 15:49
     * @Author YWX
     * @Param [subject]
     * @Return java.util.Map
     **/
    public Map<String, Object> listSubjectForZgl(MsrSubject subject) {
        Integer examid = subject.getExamid();
        Map<String, Object> map = new LinkedHashMap<>();
        //总人数、平均分、标准差、难度、差异系数分析
        map.put("subjects", msrSubjectMapper.listSubjectForZgl(examid));
        //整体分数分布分析
        map.put("scores", msrStudentMapper.listScoreForZgl(examid,"zf"));
        //整体四率分析
        map.put("scorerates", msrClassSubjectGradeMapper.getZfScoreRate(examid));
        return map;
    }

    /**
     * @Description 总分基本情况成绩分析
     * @Date 2025/1/10 15:00
     * @Author YWX
     * @Param [examid]
     * @Return java.util.Map
     **/
    public Map getExamForHzZf(Integer examid) {
        return msrExamMapper.getExamForHzZf(examid);
    }

    /**
     * @Description 总体情况汇总分析-各学科基本数据对比情况
     * @Date 2025/1/10 15:05
     * @Author YWX
     * @Param [params]
     * @Return java.lang.Object
     **/
    public Object listSubjectForHzXk(StudentParams params) {
        StringBuilder sql = new StringBuilder();
        sql.append("s.subjectid,s.subjectname,s.stunum,s.fullscore,s.maxscore,s.minscore,s.avgscore,s.bzc,s.cyxs,s.nd,s.axdxs");
        sql.append(" from msr_subject s ");
        sql.append(" where s.examid = " + params.getExamid());
        String fieldname = params.getFieldname();
        if (N_Utils.isNotEmpty(fieldname)) {
            Integer od = params.getOd();
            String order = "desc";
            if (N_Utils.isTrueInteger(od) && od.equals(1)) {
                order = "asc";
            }
            sql.append(" order by ").append(fieldname).append(" ").append(order);
        }
        return msrSubjectMapper.listSubjectBySql(sql.toString());
    }
}
