hsy
2026-08-28 a8e4132c3e2e9c3b3fcb0360901b35571b6464ea
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.ruoyi.projectManagement.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.enums.IsDeleteEnum;
import com.ruoyi.common.enums.SaleEnum;
import com.ruoyi.projectManagement.dto.ContractInfoDto;
import com.ruoyi.projectManagement.dto.SaveInfoDto;
import com.ruoyi.projectManagement.dto.ShippingAddressDto;
import com.ruoyi.projectManagement.dto.UpdateStateInfo;
import com.ruoyi.projectManagement.mapper.InfoMapper;
import com.ruoyi.projectManagement.pojo.Info;
import com.ruoyi.projectManagement.service.InfoService;
import com.ruoyi.projectManagement.service.impl.handle.ContractInfoHandleService;
import com.ruoyi.projectManagement.service.impl.handle.InfoHandleService;
import com.ruoyi.projectManagement.service.impl.handle.ShippingAddressHandleService;
import com.ruoyi.projectManagement.vo.InfoVo;
import com.ruoyi.projectManagement.vo.ListInfoVo;
import com.ruoyi.projectManagement.vo.SaveInfoVo;
import com.ruoyi.projectManagement.vo.SearchInfoVo;
import com.ruoyi.projectManagement.vo.AttachmentGroupVo;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.pojo.SalesLedger;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.basic.dto.StorageAttachmentDTO;
import com.ruoyi.basic.dto.StorageBlobVO;
import com.ruoyi.basic.enums.RecordTypeEnum;
import com.ruoyi.basic.service.StorageAttachmentService;
import com.ruoyi.sales.service.ISalesLedgerService;
import com.ruoyi.sales.pojo.SalesLawsuit;
import com.ruoyi.sales.service.ISalesLawsuitService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
 
import java.util.List;
import java.util.concurrent.CompletableFuture;
 
/**
 * @author buhuazhen
 * @date 2026/3/9
 * @email 3038525872@qq.com
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class InfoServiceImpl implements InfoService {
    private final InfoHandleService infoHandleService;
    private final InfoMapper infoMapper;
    private final ContractInfoHandleService contractInfoHandleService;
    private final ShippingAddressHandleService shippingAddressHandleService;
    private final ISalesLedgerService salesLedgerService;
    private final StorageAttachmentService storageAttachmentService;
    private final ISalesLawsuitService salesLawsuitService;
 
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void save(SaveInfoVo saveInfoVo) {
        // 保存主信息
        Long infoId = infoHandleService.save(saveInfoVo.getInfo());
        if(saveInfoVo.getShippingAddress() != null){
            shippingAddressHandleService.save(infoId, saveInfoVo.getShippingAddress());
        }
        if(saveInfoVo.getContractInfo() != null){
            contractInfoHandleService.save(infoId, saveInfoVo.getContractInfo());
        }
        if(saveInfoVo.getSalesLedgerProductList() != null){
            salesLedgerService.handleSalesLedgerProducts(infoId, saveInfoVo.getSalesLedgerProductList(), SaleEnum.MANAGEMENT);
        }
    }
 
    @Override
    @Transactional
    public void updateStatus(UpdateStateInfo updateStateInfo) {
        Info info = new Info();
        info.setId(updateStateInfo.getId());
        // 审批状态
        if(updateStateInfo.getReviewStatus() != null){
            info.setReviewStatus(updateStateInfo.getReviewStatus().getCode());
        }
 
        // 进度状态
        if(updateStateInfo.getStage() != null){
            info.setStatus(updateStateInfo.getStage().getCode());
        }
 
        infoMapper.updateById(info);
    }
 
    @Override
    @Transactional
    public void deleteInfo(Long id) {
        LambdaUpdateWrapper<Info> updateWrapper = new LambdaUpdateWrapper<Info>();
        updateWrapper.eq(Info::getId, id);
        updateWrapper.set(Info::getIsDelete, IsDeleteEnum.DELETED.getCode());
 
        // 对应附表信息是否删除待确定(因为后续可能会进行引用所以先不删除
    }
 
    @Override
    public Page<ListInfoVo> searchListInfo(SearchInfoVo vo) {
        Page<ListInfoVo> listInfoVoPage = infoMapper.searchListInfo(vo);
 
 
        return listInfoVoPage;
    }
 
    @Override
    @SneakyThrows
    public InfoVo getInfoById(Long id) {
 
        CompletableFuture<SaveInfoDto> infoFuture = CompletableFuture.supplyAsync(() -> infoHandleService.getInfoById(id));
        CompletableFuture<ContractInfoDto> contractFuture = CompletableFuture.supplyAsync(() -> contractInfoHandleService.getByInfoId(id));
        CompletableFuture<ShippingAddressDto> shippingFuture = CompletableFuture.supplyAsync(() -> shippingAddressHandleService.getByInfoId(id));
        // 商品
        CompletableFuture<List<SalesLedgerProduct>> listCompletableFuture = CompletableFuture.supplyAsync(() -> salesLedgerService.getSalesLedgerProductListByRelateId(id,SaleEnum.MANAGEMENT));
 
        // 下级项目信息
        CompletableFuture<List<SaveInfoDto>> subordinateInfoListFuture = CompletableFuture.supplyAsync(() -> infoHandleService.getSubordinateInfo(id));
 
 
        // 等待所有异步完成
        CompletableFuture.allOf(infoFuture, contractFuture, shippingFuture,listCompletableFuture,subordinateInfoListFuture).join();
 
        SaveInfoDto info = infoFuture.get();
        ContractInfoDto contract = contractFuture.get();
        ShippingAddressDto shippingAddress = shippingFuture.get();
        List<SalesLedgerProduct> salesLedgerProductList = listCompletableFuture.get();
        List<SaveInfoDto> saveInfoDtos = subordinateInfoListFuture.get();
        InfoVo vo = new InfoVo();
        vo.setInfo(info);
        vo.setContractInfo(contract);
        vo.setShippingAddress(shippingAddress);
        vo.setSalesLedgerProductList(salesLedgerProductList);
        vo.setSubordinateInfoList(saveInfoDtos);
        return vo;
    }
 
    @Override
    public List<AttachmentGroupVo> getProjectAttachments(Long id) {
        List<AttachmentGroupVo> result = new java.util.ArrayList<>();
        
        // 项目管理附件
        StorageAttachmentDTO infoDto = new StorageAttachmentDTO();
        infoDto.setRecordType(RecordTypeEnum.INFO.getType());
        infoDto.setRecordId(id);
        List<StorageBlobVO> infoFiles = storageAttachmentService.list(infoDto);
        if (infoFiles != null && !infoFiles.isEmpty()) {
            result.add(new AttachmentGroupVo("项目管理", infoFiles));
        }
 
        // 销售台账附件
        List<SalesLedger> ledgers = salesLedgerService.list(Wrappers.<SalesLedger>lambdaQuery().eq(SalesLedger::getProjectId, id));
        if (ledgers != null && !ledgers.isEmpty()) {
            List<StorageBlobVO> ledgerFiles = new java.util.ArrayList<>();
            for (SalesLedger ledger : ledgers) {
                StorageAttachmentDTO dto = new StorageAttachmentDTO();
                dto.setRecordType(RecordTypeEnum.SALES_LEDGER.getType());
                dto.setRecordId(ledger.getId());
                List<StorageBlobVO> files = storageAttachmentService.list(dto);
                if (files != null && !files.isEmpty()) {
                    ledgerFiles.addAll(files);
                }
            }
            if (!ledgerFiles.isEmpty()) {
                result.add(new AttachmentGroupVo("销售台账", ledgerFiles));
            }
        }
 
        // 诉讼管理附件
        List<SalesLawsuit> lawsuits = salesLawsuitService.list(Wrappers.<SalesLawsuit>lambdaQuery().eq(SalesLawsuit::getProjectId, id));
        if (lawsuits != null && !lawsuits.isEmpty()) {
            List<StorageBlobVO> lawsuitFiles = new java.util.ArrayList<>();
            for (SalesLawsuit lawsuit : lawsuits) {
                StorageAttachmentDTO dto = new StorageAttachmentDTO();
                dto.setRecordType(RecordTypeEnum.SALES_LAWSUIT.getType());
                dto.setRecordId(lawsuit.getId());
                List<StorageBlobVO> files = storageAttachmentService.list(dto);
                if (files != null && !files.isEmpty()) {
                    lawsuitFiles.addAll(files);
                }
            }
            if (!lawsuitFiles.isEmpty()) {
                result.add(new AttachmentGroupVo("诉讼管理", lawsuitFiles));
            }
        }
 
        return result;
    }
}