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.MjyTz;
import com.hxhq.business.domain.SjTz;
import com.hxhq.system.api.domain.SysUser;
import org.springframework.stereotype.Service;
import com.hxhq.business.mapper.GspTzMapper;
import com.hxhq.business.domain.GspTz;
import com.hxhq.business.service.IGspTzService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 供试品-台账Service业务层处理
 *
 * @author hxhq
 * @date 2025-12-30
 */
@Service
public class GspTzServiceImpl extends ServiceImpl<GspTzMapper, GspTz> implements IGspTzService
{
    /**
     * 查询供试品-台账列表
     *
     * @param form 供试品-台账
     * @return 供试品-台账
     */
    @Override
    public List<GspTz> queryList(GspTz form)
    {
        QueryWrapper<GspTz> queryWrapper = Wrappers.query();
        if(form.getGspId()==null||form.getGspId().longValue()<0){
            throw new SecurityException("供试品id不能为空");
        }
        queryWrapper.eq("gsp_id",form.getGspId());
        queryWrapper.orderByDesc("id");
        return this.list(queryWrapper);
    }

    @Override
    public void saveTz(Long gspId, SysUser qmr, String qmyy, String qmyyEn, String czl, String czldw, String remark) {
        GspTz gspTz = new GspTz();
        gspTz.setGspId(gspId);
        gspTz.setQmrId(qmr.getUserId());
        gspTz.setQmrMc(qmr.getNickName());
        gspTz.setQmrMcEn(qmr.getUserName());
        gspTz.setQmyy(qmyy);
        gspTz.setQmyyEn(qmyyEn);
        gspTz.setCzldw(czldw);
        gspTz.setCzl(czl);
        gspTz.setRemark(remark);
        this.save(gspTz);
    }

    @Override
    public void saveFfTz(Long  gspId, SysUser lqr1, SysUser lqr2, SysUser ffr1, SysUser ffr2, SysUser qmr, String qmyy, String qmyyEn,
                         String czl, String czldw, String remark){
        GspTz gspTz = new GspTz();
        gspTz.setGspId(gspId);
        gspTz.setLqrMc(lqr2 == null ? lqr1.getNickName() : lqr1.getNickName() + "," + lqr2.getNickName());
        gspTz.setLqrMcEn(lqr2 == null ? lqr1.getUserName() : lqr1.getUserName() + "," + lqr2.getUserName());
        gspTz.setFfrMc(ffr2 == null ? ffr1.getNickName() : ffr1.getNickName() + "," + ffr2.getNickName());
        gspTz.setFfrMcEn(ffr2 == null ? ffr1.getUserName() : ffr1.getUserName() + "," + ffr2.getUserName());
        gspTz.setQmrId(qmr.getUserId());
        gspTz.setQmrMc(qmr.getNickName());
        gspTz.setQmrMcEn(qmr.getUserName());
        gspTz.setQmyy(qmyy);
        gspTz.setQmyyEn(qmyyEn);
        gspTz.setCzldw(czldw);
        gspTz.setCzl(czl);
        gspTz.setRemark(remark);
        this.save(gspTz);
    }

    @Override
    public void saveGhTz(Long gspId, SysUser ghr1, SysUser ghr2, SysUser jsr1, SysUser jsr2, SysUser qmr, String qmyy, String qmyyEn, String czl, String czldw, String remark) {
        GspTz gspTz = new GspTz();
        gspTz.setGspId(gspId);
        gspTz.setGhrMc(ghr2 == null ? ghr1.getNickName() : ghr1.getNickName() + "," + ghr2.getNickName());
        gspTz.setGhrMcEn(ghr2 == null ? ghr1.getUserName() : ghr1.getUserName() + "," + ghr2.getUserName());
        gspTz.setJsrMc(jsr2 == null ? jsr1.getNickName() : jsr1.getNickName() + "," + jsr2.getNickName());
        gspTz.setFfrMcEn(jsr2 == null ? jsr1.getUserName() : jsr1.getUserName() + "," + jsr2.getUserName());
        gspTz.setQmrId(qmr.getUserId());
        gspTz.setQmrMc(qmr.getNickName());
        gspTz.setQmrMcEn(qmr.getUserName());
        gspTz.setQmyy(qmyy);
        gspTz.setQmyyEn(qmyyEn);
        gspTz.setCzldw(czldw);
        gspTz.setCzl(czl);
        gspTz.setRemark(remark);
        this.save(gspTz);
    }

}
