/*
 *      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.ProjectEstablishment;
import org.security.trans.projectBudgetManagement.vo.ProjectEstablishmentVO;
import org.security.trans.projectBudgetManagement.mapper.ProjectEstablishmentMapper;
import org.security.trans.projectBudgetManagement.service.IProjectEstablishmentService;
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 ProjectEstablishmentServiceImpl extends ServiceImpl<ProjectEstablishmentMapper, ProjectEstablishment> implements IProjectEstablishmentService {

	private final IFileService fileService;

	@Override
	public ProjectEstablishmentVO getData(String id) {
		log.info("==============获取项目立项资料数据开始==============");
		ProjectEstablishment projectEstablishment = this.getOne(new QueryWrapper<ProjectEstablishment>().lambda().eq(Func.isNotEmpty(id), ProjectEstablishment::getProjectLinkId, id));
		ProjectEstablishmentVO vo = Func.copy(projectEstablishment, ProjectEstablishmentVO.class);
		//获取相关附件
//		Preconditions.checkArgument(Func.isNotEmpty(vo),"项目立项资料数据为空");
		if (Func.isNotEmpty(vo)) {
			vo.setDrawAttachments(fileService.getAttachments(projectEstablishment.getId(), projectEstablishment.getProjectEstablishmentDrawing()));
			vo.setCostAttachments(fileService.getAttachments(projectEstablishment.getId(), projectEstablishment.getManufacturingCostMaterials()));
			vo.setMaterialAttachments(fileService.getAttachments(projectEstablishment.getId(), projectEstablishment.getProjectEstablishmentMaterials()));
			vo.setFinancialAttachments(fileService.getAttachments(projectEstablishment.getId(), projectEstablishment.getFinancialAuditMaterials()));
			vo.setOtherAttachments(fileService.getAttachments(projectEstablishment.getId(), projectEstablishment.getOtherMaterials()));
		}
		log.info("==============获取项目立项资料数据结束==============");
		return vo;
	}
}
