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.StudyFormPlanQmxx;
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.StudyFormPlanQmxxMapper;
import com.hxhq.business.service.IStudyFormPlanQmxxService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 试验-计划单-签名信息Service业务层处理
 *
 * @author hxhq
 * @date 2026-01-02
 */
@Service
public class StudyFormPlanQmxxServiceImpl extends ServiceImpl<StudyFormPlanQmxxMapper, StudyFormPlanQmxx> implements IStudyFormPlanQmxxService
{
    /**
     * 查询试验-填报单-签名信息列表
     *
     * @param studyFormPlanQmxx 试验-填报单-签名信息
     * @return 试验-填报单-签名信息
     */
    @Override
    public List<StudyFormPlanQmxx> queryList(StudyFormPlanQmxx studyFormPlanQmxx)
    {
        QueryWrapper<StudyFormPlanQmxx> queryWrapper = Wrappers.query();
        if(studyFormPlanQmxx.getFormId()==null||studyFormPlanQmxx.getFormId().longValue()<0){
            throw new ServiceException("表单id不能为空");
        }
        queryWrapper.eq("form_id",studyFormPlanQmxx.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){
        StudyFormPlanQmxx studyFormPlanQmxx=new StudyFormPlanQmxx();
        studyFormPlanQmxx.setFormId(formId);
        studyFormPlanQmxx.setQmyy(qmyy);
        studyFormPlanQmxx.setQmyyEn(StudyFormUtil.getEn(qmyy));
        studyFormPlanQmxx.setQmrId(qmr.getUserId());
        studyFormPlanQmxx.setQmrMc(qmr.getNickName());
        studyFormPlanQmxx.setQmrMcEn(qmr.getUserName());
        studyFormPlanQmxx.setRemark(remark);
        this.save(studyFormPlanQmxx);
    }


}
