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.common.core.domain.MpBaseEntity;
import com.hxhq.common.core.utils.DateUtils;
import com.hxhq.common.core.utils.StringUtils;
import com.hxhq.system.api.domain.SysUser;
import org.springframework.stereotype.Service;
import com.hxhq.business.mapper.StudyRoomJcgjMapper;
import com.hxhq.business.domain.StudyRoomJcgj;
import com.hxhq.business.service.IStudyRoomJcgjService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 试验-饲养间-稽查轨迹Service业务层处理
 *
 * @author hxhq
 * @date 2026-01-15
 */
@Service
public class StudyRoomJcgjServiceImpl extends ServiceImpl<StudyRoomJcgjMapper, StudyRoomJcgj> implements IStudyRoomJcgjService
{
    /**
     * 查询试验-饲养间-稽查轨迹列表
     *
     * @param studyRoomJcgj 试验-饲养间-稽查轨迹
     * @return 试验-饲养间-稽查轨迹
     */
    @Override
    public List<StudyRoomJcgj> queryList(StudyRoomJcgj studyRoomJcgj)
    {
        LambdaQueryWrapper<StudyRoomJcgj> queryWrapper = new LambdaQueryWrapper<>();
        if(studyRoomJcgj.getStudyRoomId() != null) {
            queryWrapper.eq(StudyRoomJcgj::getStudyRoomId, studyRoomJcgj.getStudyRoomId());
        }
        if(studyRoomJcgj.getJcgjlx() != null) {
            queryWrapper.eq(StudyRoomJcgj::getJcgjlx, studyRoomJcgj.getJcgjlx());
        }
        if(StringUtils.isNotEmpty(studyRoomJcgj.getJcmc())) {
            queryWrapper.and(p -> p.like(StudyRoomJcgj::getJcmc, studyRoomJcgj.getJcmc())
                    .or().like(StudyRoomJcgj::getQmrMc, studyRoomJcgj.getJcmc()));
        }
        queryWrapper.orderByDesc(MpBaseEntity::getId);
        return this.list(queryWrapper);
    }

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

}
