package com.hxhq.business.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hxhq.business.domain.MjyJcgj;
import com.hxhq.business.domain.SjJcgj;
import com.hxhq.common.core.domain.MpBaseEntity;
import com.hxhq.common.core.utils.StringUtils;
import com.hxhq.system.api.domain.SysUser;
import org.springframework.stereotype.Service;
import com.hxhq.business.mapper.GspJcgjMapper;
import com.hxhq.business.domain.GspJcgj;
import com.hxhq.business.service.IGspJcgjService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 供试品管理-稽查轨迹Service业务层处理
 *
 * @author hxhq
 * @date 2025-12-30
 */
@Service
public class GspJcgjServiceImpl extends ServiceImpl<GspJcgjMapper, GspJcgj> implements IGspJcgjService
{
    /**
     * 查询供试品管理-稽查轨迹列表
     *
     * @param gspJcgj 供试品管理-稽查轨迹
     * @return 供试品管理-稽查轨迹
     */
    @Override
    public List<GspJcgj> queryList(GspJcgj gspJcgj)
    {
        LambdaQueryWrapper<GspJcgj> queryWrapper = new LambdaQueryWrapper<>();
        if (gspJcgj.getGspId() == null || gspJcgj.getGspId().longValue() < 0) {
            throw new SecurityException("供试品id不能为空");
        }
        queryWrapper.eq(GspJcgj::getGspId, gspJcgj.getGspId());
        if (gspJcgj.getJcgjlx() != null && gspJcgj.getJcgjlx().intValue() > 0) {
            queryWrapper.eq(GspJcgj::getJcgjlx, gspJcgj.getJcgjlx());
        }
        if (StringUtils.isNoneBlank(gspJcgj.getJcmc())) {
            queryWrapper.and(p -> p.like(GspJcgj::getJcmc, gspJcgj.getJcmc())
                    .or().like(GspJcgj::getJcgjlx, gspJcgj.getJcmc()));
        }
        queryWrapper.orderByDesc(MpBaseEntity::getId);
        return this.list(queryWrapper);
    }

    @Override
    public void saveJcgj(Long  gspId, Integer jcgjlx, String jcmc, String jcmcEn, Integer jcmcys, String jcnr, String jcnrEn, SysUser qmr) {
        GspJcgj gspJcgj = new GspJcgj();
        gspJcgj.setGspId(gspId);
        gspJcgj.setJcgjlx(jcgjlx);
        gspJcgj.setJcmc(jcmc);
        gspJcgj.setJcmcEn(jcmcEn);
        gspJcgj.setJcmcys(jcmcys);
        gspJcgj.setJcnr(jcnr);
        gspJcgj.setJcnr(jcnrEn);
        gspJcgj.setQmrId(qmr.getUserId());
        gspJcgj.setQmrMc(qmr.getNickName());
        gspJcgj.setQmrMcEn(qmr.getUserName());
        this.save(gspJcgj);
    }

}
