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.StudyFormApplyQmxx;
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.StudyFormApplyQmxxMapper;
import com.hxhq.business.service.IStudyFormApplyQmxxService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 试验-填报单-签名信息Service业务层处理
 *
 * @author hxhq
 * @date 2025-12-31
 */
@Service
public class StudyFormApplyQmxxServiceImpl extends ServiceImpl<StudyFormApplyQmxxMapper, StudyFormApplyQmxx> implements IStudyFormApplyQmxxService
{

    /**
     * 查询试验-填报单-签名信息列表
     *
     * @param studyFormApplyQmxx 试验-填报单-签名信息
     * @return 试验-填报单-签名信息
     */
    @Override
    public List<StudyFormApplyQmxx> queryList(StudyFormApplyQmxx studyFormApplyQmxx)
    {
        QueryWrapper<StudyFormApplyQmxx> queryWrapper = Wrappers.query();
        if(studyFormApplyQmxx.getFormId()==null||studyFormApplyQmxx.getFormId().longValue()<0){
            throw new ServiceException("表单id不能为空");
        }
        queryWrapper.eq("form_id",studyFormApplyQmxx.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){
        StudyFormApplyQmxx studyFormApplyQmxx=new StudyFormApplyQmxx();
        studyFormApplyQmxx.setFormId(formId);
        studyFormApplyQmxx.setQmyy(qmyy);
        studyFormApplyQmxx.setQmyyEn(StudyFormUtil.getEn(qmyy));
        studyFormApplyQmxx.setQmrId(qmr.getUserId());
        studyFormApplyQmxx.setQmrMc(qmr.getNickName());
        studyFormApplyQmxx.setQmrMcEn(qmr.getUserName());
        studyFormApplyQmxx.setRemark(remark);
        this.save(studyFormApplyQmxx);
    }

}
