/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.security.trans.projectBudgetManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.security.trans.common.service.IFileService;
import org.security.trans.projectBudgetManagement.entity.ProjectCheck;
import org.security.trans.projectBudgetManagement.vo.ProjectCheckVO;
import org.security.trans.projectBudgetManagement.mapper.ProjectCheckMapper;
import org.security.trans.projectBudgetManagement.service.IProjectCheckService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;

/**
 * 项目管理-项目验收材料 服务实现类
 *
 * @author BladeX
 * @since 2022-08-05
 */
@Service
@Slf4j
@AllArgsConstructor
public class ProjectCheckServiceImpl extends ServiceImpl<ProjectCheckMapper, ProjectCheck> implements IProjectCheckService {

	private final IFileService fileService;

	@Override
	public ProjectCheckVO getData(String id) {
		log.info("==============获取项目验收材料数据开始==============");
		ProjectCheck projectCheck = this.getOne(new QueryWrapper<ProjectCheck>().lambda().eq(Func.isNotEmpty(id), ProjectCheck::getProjectLinkId, id));
		ProjectCheckVO vo = Func.copy(projectCheck, ProjectCheckVO.class);
//		Preconditions.checkArgument(Func.isNotEmpty(vo),"项目验收材料数据为空");
		if (Func.isNotEmpty(vo)) {
			//获取相关附件
			vo.setCheckAttachments(fileService.getAttachments(projectCheck.getId(), projectCheck.getRelevantAttachments()));
		}
		log.info("==============获取项目验收材料数据结束==============");
		return vo;
	}
}
