package com.hxhq.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxhq.business.domain.MjyTz;
import com.hxhq.business.domain.SjTz;
import com.hxhq.business.mapper.MjyTzMapper;
import com.hxhq.business.mapper.SjTzMapper;
import com.hxhq.business.service.IMjyTzService;
import com.hxhq.business.service.ISjTzService;
import com.hxhq.system.api.domain.SysUser;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 试剂-台账Service业务层处理
 *
 * @author HanLong
 * @date 2025-12-18
 */
@Service
public class SjTzServiceImpl extends ServiceImpl<SjTzMapper, SjTz> implements ISjTzService
{

    @Override
    public List<SjTz> queryList(SjTz form) {
        QueryWrapper<SjTz> queryWrapper = Wrappers.query();
        if(form.getSjId()==null||form.getSjId().longValue()<0){
            throw new SecurityException("试剂id不能为空");
        }
        queryWrapper.eq("sj_id",form.getSjId());
        queryWrapper.orderByDesc("id");
        return this.list(queryWrapper);
    }

    @Override
    public void saveTz(Long  sjId, Long qmrId,String qmrMc, String qmrMcEn, String qmyy,String qmyyEn, String czl,String czldw,String remark) {
        SjTz sjTz = new SjTz();
        sjTz.setSjId(sjId);
        sjTz.setQmrId(qmrId);
        sjTz.setQmrMc(qmrMc);
        sjTz.setQmrMcEn(qmrMcEn);
        sjTz.setQmyy(qmyy);
        sjTz.setQmyyEn(qmyyEn);
        sjTz.setCzl(czl);
        sjTz.setCzldw(czldw);
        sjTz.setRemark(remark);
        save(sjTz);
    }

    @Override
    public SjTz genTz(Long sjId, String qmyy, String qmyyEn, String czl, String czldw, String remark, SysUser qmr) {
        SjTz sjTz = new SjTz();
        sjTz.setSjId(sjId);
        sjTz.setQmrId(qmr.getUserId());
        sjTz.setQmrMc(qmr.getNickName());
        sjTz.setQmrMcEn(qmr.getUserName());
        sjTz.setQmyy(qmyy);
        sjTz.setQmyyEn(qmyyEn);
        sjTz.setCzl(czl);
        sjTz.setCzldw(czldw);
        sjTz.setRemark(remark);
        return sjTz;
    }
}
