package com.hxhq.business.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hxhq.business.domain.StudyFormPreQmxx;
import com.hxhq.business.utils.lang.StudyFormUtil;
import com.hxhq.common.core.exception.ServiceException;
import com.hxhq.system.api.domain.SysUser;
import org.springframework.stereotype.Service;
import com.hxhq.business.mapper.StudyFormPreQmxxMapper;
import com.hxhq.business.service.IStudyFormPreQmxxService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 试验-预填单-签名信息Service业务层处理
 *
 * @author hxhq
 * @date 2025-12-31
 */
@Service
public class StudyFormPreQmxxServiceImpl extends ServiceImpl<StudyFormPreQmxxMapper, StudyFormPreQmxx> implements IStudyFormPreQmxxService
{
    /**
     * 查询试验-预填单-签名信息列表
     *
     * @param studyFormPreQmxx 试验-预填单-签名信息
     * @return 试验-预填单-签名信息
     */
    @Override
    public List<StudyFormPreQmxx> queryList(StudyFormPreQmxx studyFormPreQmxx)
    {
        QueryWrapper<StudyFormPreQmxx> queryWrapper = Wrappers.query();
        if(studyFormPreQmxx.getFormId()==null||studyFormPreQmxx.getFormId().longValue()<0){
            throw new ServiceException("表单id不能为空");
        }
        queryWrapper.eq("form_id",studyFormPreQmxx.getFormId());
        queryWrapper.orderByDesc("id");
        return this.list(queryWrapper);
    }

    /**
     * 新增签名信息
     * @param formId
     * @param qmyy
     * @param qmr
     * @param remark
     */
    @Override
    public  void saveQmxx(Long  formId, String qmyy, SysUser qmr, String remark){
        StudyFormPreQmxx studyFormPreQmxx=new StudyFormPreQmxx();
        studyFormPreQmxx.setFormId(formId);
        studyFormPreQmxx.setQmyy(qmyy);
        studyFormPreQmxx.setQmyyEn(StudyFormUtil.getEn(qmyy));
        studyFormPreQmxx.setQmrId(qmr.getUserId());
        studyFormPreQmxx.setQmrMc(qmr.getNickName());
        studyFormPreQmxx.setQmrMcEn(qmr.getUserName());
        studyFormPreQmxx.setRemark(remark);
        this.save(studyFormPreQmxx);
    }

}
