/*
 *      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 com.google.common.base.Preconditions;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.security.trans.common.service.IFileService;
import org.security.trans.projectBudgetManagement.entity.ProjectImplementation;
import org.security.trans.projectBudgetManagement.vo.ProjectImplementationVO;
import org.security.trans.projectBudgetManagement.mapper.ProjectImplementationMapper;
import org.security.trans.projectBudgetManagement.service.IProjectImplementationService;
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 ProjectImplementationServiceImpl extends ServiceImpl<ProjectImplementationMapper, ProjectImplementation> implements IProjectImplementationService {

	private final IFileService fileService;

	@Override
	public ProjectImplementationVO getData(String id) {
		log.info("==============获取项目实施材料数据开始==============");
		ProjectImplementation projectImplementation = this.getOne(new QueryWrapper<ProjectImplementation>().lambda().eq(Func.isNotEmpty(id), ProjectImplementation::getProjectLinkId, id));
		ProjectImplementationVO vo = Func.copy(projectImplementation, ProjectImplementationVO.class);
		//获取相关附件
//		Preconditions.checkArgument(Func.isNotEmpty(vo),"项目实施材料数据为空");
		if (Func.isNotEmpty(vo)) {
			vo.setEngineeringAttachments(fileService.getAttachments(projectImplementation.getId(), projectImplementation.getEngineeringLetter()));
			vo.setImplementationAttachments(fileService.getAttachments(projectImplementation.getId(), projectImplementation.getImplementationMaterials()));
			vo.setDeviceAttachments(fileService.getAttachments(projectImplementation.getId(), projectImplementation.getDeviceQualifiedMaterials()));
			vo.setOtherAttachments(fileService.getAttachments(projectImplementation.getId(), projectImplementation.getOtherMaterials()));
		}
		log.info("==============获取项目实施材料数据结束==============");
		return vo;
	}
}
