zhangherong
2025-07-07 18016ce1447b85d5ccbb873ef58c0ac79245b464
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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());
    }
}