package org.jeecg.modules.eam.service.impl;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import org.jeecg.common.util.FileUtil;
|
import org.jeecg.modules.eam.entity.EamEquipmentPurchasePlan;
|
import org.jeecg.modules.eam.entity.EamPurchasePlanAttachment;
|
import org.jeecg.modules.eam.mapper.EamPurchasePlanAttachmentMapper;
|
import org.jeecg.modules.eam.request.EamPurchasePlanAttachmentRequest;
|
import org.jeecg.modules.eam.service.IEamEquipmentPurchasePlanService;
|
import org.jeecg.modules.eam.service.IEamPurchasePlanAttachmentService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.ArrayList;
|
import java.util.Objects;
|
|
/**
|
* @Description: eam_purchase_plan_attachment
|
* @Author: jeecg-boot
|
* @Date: 2025-06-18
|
* @Version: V1.0
|
*/
|
@Service
|
public class EamPurchasePlanAttachmentServiceImpl extends ServiceImpl<EamPurchasePlanAttachmentMapper, EamPurchasePlanAttachment> implements IEamPurchasePlanAttachmentService {
|
|
@Autowired
|
private IEamEquipmentPurchasePlanService eamEquipmentPurchasePlanService;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void saveAttachmentList(EamPurchasePlanAttachmentRequest request) {
|
if (Objects.isNull(request) || CollectionUtil.isEmpty(request.getFileList())) {
|
throw new RuntimeException("请选择文档再上传!");
|
}
|
EamEquipmentPurchasePlan plan = eamEquipmentPurchasePlanService.getById(request.getPlanId());
|
if (Objects.isNull(plan)) {
|
throw new RuntimeException("请先选择设备采购计划再上传文档!");
|
}
|
ArrayList<EamPurchasePlanAttachment> attachmentList = CollectionUtil.newArrayList();
|
request.getFileList().forEach(fileUploadResult -> {
|
EamPurchasePlanAttachment attachment = new EamPurchasePlanAttachment()
|
.setPlanId(request.getPlanId())
|
.setFilePath(fileUploadResult.getFilePath())
|
.setFileName(fileUploadResult.getFileName())
|
.setFileEncodeName(fileUploadResult.getFileEncodeName())
|
.setFileSize(fileUploadResult.getFileSize())
|
.setFileSuffix(fileUploadResult.getFileSuffix())
|
.setDescription(request.getDescription());
|
attachmentList.add(attachment);
|
});
|
saveBatch(attachmentList);
|
}
|
|
@Override
|
public void downloadFile(HttpServletResponse response, EamPurchasePlanAttachment entity) {
|
FileUtil.downLoadFile(response, entity.getFilePath(), entity.getFileName());
|
}
|
}
|