/*
 *      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.ProjectPurchase;
import org.security.trans.projectBudgetManagement.vo.ProjectPurchaseVO;
import org.security.trans.projectBudgetManagement.mapper.ProjectPurchaseMapper;
import org.security.trans.projectBudgetManagement.service.IProjectPurchaseService;
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 ProjectPurchaseServiceImpl extends ServiceImpl<ProjectPurchaseMapper, ProjectPurchase> implements IProjectPurchaseService {

	private final IFileService fileService;

	@Override
	public ProjectPurchaseVO getData(String id) {
		log.info("==============获取项目采购材料数据开始==============");
		ProjectPurchase projectPurchase = this.getOne(new QueryWrapper<ProjectPurchase>().lambda().eq(Func.isNotEmpty(id), ProjectPurchase::getProjectLinkId, id));
		ProjectPurchaseVO vo = Func.copy(projectPurchase, ProjectPurchaseVO.class);
		//获取相关附件
//		Preconditions.checkArgument(Func.isNotEmpty(vo),"项目采购材料数据为空");
		if (Func.isNotEmpty(vo)) {
			vo.setPublicBiddingAttachments(fileService.getAttachments(projectPurchase.getId(), projectPurchase.getPublicBiddingMaterials()));
			vo.setCompetitiveAttachments(fileService.getAttachments(projectPurchase.getId(), projectPurchase.getCompetitiveNegotiationMaterials()));
			vo.setInquiryAttachments(fileService.getAttachments(projectPurchase.getId(), projectPurchase.getInquiryPurchaseMaterials()));
			vo.setInviteBiddingAttachments(fileService.getAttachments(projectPurchase.getId(), projectPurchase.getInviteBiddingMaterials()));
			vo.setSingleSourceAttachments(fileService.getAttachments(projectPurchase.getId(), projectPurchase.getSingleSourcePurchaseMaterials()));
			vo.setOtherAttachments(fileService.getAttachments(projectPurchase.getId(), projectPurchase.getOtherMaterials()));
		}
		log.info("==============获取项目采购材料数据开始==============");
		return vo;
	}
}
