package com.srs.diagnostic.service.impl;

import java.util.List;

import com.srs.common.core.domain.model.LoginUser;
import com.srs.common.utils.SecurityUtils;
import com.srs.diagnostic.domain.DiaFillOutReport;
import com.srs.diagnostic.domain.DiaStudentInfo;
import com.srs.diagnostic.mapper.DiaStudentInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.srs.diagnostic.mapper.DiaReportDetailsMapper;
import com.srs.diagnostic.domain.DiaReportDetails;
import com.srs.diagnostic.service.IDiaReportDetailsService;

/**
 * 诊断报告Service业务层处理
 *
 * @author srs
 * @date 2025-05-08
 */
@Service
public class DiaReportDetailsServiceImpl extends ServiceImpl<DiaReportDetailsMapper,DiaReportDetails> implements IDiaReportDetailsService {
    @Autowired
    private DiaReportDetailsMapper diaReportDetailsMapper;

    @Autowired
    private DiaStudentInfoMapper diaStudentInfoMapper;

    /**
     * 查询诊断报告
     *
     * @param id 诊断报告主键
     * @return 诊断报告
     */
    @Override
    public DiaReportDetails selectDiaReportDetailsById(Long id) {
        return diaReportDetailsMapper.selectDiaReportDetailsById(id);
    }

    /**
     * 查询诊断报告列表
     *
     * @param diaReportDetails 诊断报告
     * @return 诊断报告
     */
    @Override
    public List<DiaReportDetails> selectDiaReportDetailsList(DiaReportDetails diaReportDetails) {
        diaReportDetails.setCollegeId(SecurityUtils.getDeptId());
        diaReportDetails.setStuNo(SecurityUtils.getUsername());
        diaReportDetails.setUserId(SecurityUtils.getUserId());

        //调用修改名字
        diaReportDetailsMapper.updateStudentNameFromNickName(diaReportDetails);

        return diaReportDetailsMapper.selectDiaReportDetailsList(diaReportDetails);

    }

     /**
     * 批量修改诊断报告
     *
     * @param
     * @return 批量修改诊断报告
     */
    @Override
    public int batchUpdate(List<DiaReportDetails> list) {

        //获取DeptId遍历
        LoginUser user = SecurityUtils.getLoginUser();
        for (DiaReportDetails diaReportDetails : list) {
            diaReportDetails.setCollegeId(user.getDeptId());
        }
        return diaReportDetailsMapper.batchUpdate(list);

    }




    /**
     * 批量新增诊断报告
     *
     * @param list 批量新增诊断报告
     * @return 批量新增诊断报告
     */
     @Override
     public int batchInsertReportDetailsByHierarchy( List<DiaReportDetails> list) {


         LoginUser user = SecurityUtils.getLoginUser();

         for (DiaReportDetails diaReportDetails : list) {
             diaReportDetails.setCollegeId(SecurityUtils.getDeptId());
             diaReportDetails.setUserId(SecurityUtils.getUserId());
             diaReportDetails.setStuNo(SecurityUtils.getUsername());
         }
         return diaReportDetailsMapper.batchInsertReportDetailsByHierarchy(list);
     }

    /**
     * 新增诊断报告
     *
     * @param diaReportDetails 诊断报告
     * @return 结果
     */
    @Override
    public int insertDiaReportDetails(DiaReportDetails diaReportDetails) {
            return diaReportDetailsMapper.insertDiaReportDetails(diaReportDetails);
    }

    /**
     * 修改诊断报告
     *
     * @param diaReportDetails 诊断报告
     * @return 结果
     */
    @Override
    public int updateDiaReportDetails(DiaReportDetails diaReportDetails) {
        return diaReportDetailsMapper.updateDiaReportDetails(diaReportDetails);
    }

    /**
     * 批量删除诊断报告
     *
     * @param ids 需要删除的诊断报告主键
     * @return 结果
     */
    @Override
    public int deleteDiaReportDetailsByIds(Long[] ids) {
        return diaReportDetailsMapper.deleteDiaReportDetailsByIds(ids);
    }

    /**
     * 删除诊断报告信息
     *
     * @param id 诊断报告主键
     * @return 结果
     */
    @Override
    public int deleteDiaReportDetailsById(Long id) {
        return diaReportDetailsMapper.deleteDiaReportDetailsById(id);
    }
}
