package com.yeejoin.amos.boot.module.jg.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgMaintenanceRecordInfoService;
import com.yeejoin.amos.boot.module.ymt.api.dto.IdxBizJgMaintenanceRecordInfoDto;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgMaintenanceRecordInfo;
import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgMaintenanceRecordInfoMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;

import java.util.List;

/**
 * 安全追溯-维保备案信息表服务实现类
 *
 * @author system_generator
 * @date 2023-08-17
 */
@Service
public class IdxBizJgMaintenanceRecordInfoServiceImpl extends BaseService<IdxBizJgMaintenanceRecordInfoDto,IdxBizJgMaintenanceRecordInfo,IdxBizJgMaintenanceRecordInfoMapper> implements IIdxBizJgMaintenanceRecordInfoService {

    public boolean saveOrUpdateData(IdxBizJgMaintenanceRecordInfo maintenanceRecordInfo){
        return this.saveOrUpdate(maintenanceRecordInfo);
    }

    /**
     * 查询最新的维保记录
     */
    @Override
    public IdxBizJgMaintenanceRecordInfo queryNewestDetailByRecord(String record) {
        QueryWrapper<IdxBizJgMaintenanceRecordInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(IdxBizJgMaintenanceRecordInfo::getRecord,record).orderByDesc(IdxBizJgMaintenanceRecordInfo::getRecDate).last("limit 1");
        IdxBizJgMaintenanceRecordInfo init = new IdxBizJgMaintenanceRecordInfo();
        IdxBizJgMaintenanceRecordInfo last = getOne(queryWrapper);
        if(last != null){
            init = last;
        }
        return init;
    }


}