|
15 | 15 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
16 | 16 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
17 | 17 | import com.wansenai.bo.CollectionBO;
|
| 18 | +import com.wansenai.bo.CollectionDataExportBO; |
18 | 19 | import com.wansenai.bo.FileDataBO;
|
19 | 20 | import com.wansenai.dto.financial.AddOrUpdateCollectionDTO;
|
20 | 21 | import com.wansenai.dto.financial.QueryCollectionDTO;
|
|
33 | 34 | import com.wansenai.utils.constants.CommonConstants;
|
34 | 35 | import com.wansenai.utils.enums.BaseCodeEnum;
|
35 | 36 | import com.wansenai.utils.enums.CollectionPaymentCodeEnum;
|
36 |
| -import com.wansenai.utils.enums.IncomeExpenseCodeEnum; |
| 37 | +import com.wansenai.utils.excel.ExcelUtils; |
37 | 38 | import com.wansenai.utils.response.Response;
|
38 | 39 | import com.wansenai.vo.financial.CollectionDetailVO;
|
39 | 40 | import com.wansenai.vo.financial.CollectionVO;
|
| 41 | +import jakarta.servlet.http.HttpServletResponse; |
40 | 42 | import org.springframework.stereotype.Service;
|
41 | 43 | import org.springframework.util.StringUtils;
|
42 | 44 |
|
|
46 | 48 | import java.util.Arrays;
|
47 | 49 | import java.util.List;
|
48 | 50 | import java.util.Optional;
|
| 51 | +import java.util.concurrent.ConcurrentHashMap; |
49 | 52 | import java.util.stream.Collectors;
|
50 | 53 |
|
51 | 54 | @Service
|
@@ -139,6 +142,41 @@ public Response<Page<CollectionVO>> getCollectionReceiptPageList(QueryCollection
|
139 | 142 | return Response.responseData(result);
|
140 | 143 | }
|
141 | 144 |
|
| 145 | + private List<CollectionVO> getCollectionReceiptList(QueryCollectionDTO queryCollectionDTO) { |
| 146 | + var financialMainList = lambdaQuery() |
| 147 | + .eq(queryCollectionDTO.getFinancialPersonId() != null, FinancialMain::getOperatorId, queryCollectionDTO.getFinancialPersonId()) |
| 148 | + .eq(queryCollectionDTO.getAccountId() != null, FinancialMain::getAccountId, queryCollectionDTO.getAccountId()) |
| 149 | + .eq(queryCollectionDTO.getStatus() != null, FinancialMain::getStatus, queryCollectionDTO.getStatus()) |
| 150 | + .eq(queryCollectionDTO.getCustomerId() != null, FinancialMain::getRelatedPersonId, queryCollectionDTO.getCustomerId()) |
| 151 | + .eq(StringUtils.hasLength(queryCollectionDTO.getReceiptNumber()), FinancialMain::getReceiptNumber, queryCollectionDTO.getReceiptNumber()) |
| 152 | + .like(StringUtils.hasLength(queryCollectionDTO.getRemark()), FinancialMain::getRemark, queryCollectionDTO.getRemark()) |
| 153 | + .ge(StringUtils.hasLength(queryCollectionDTO.getStartDate()), FinancialMain::getReceiptDate, queryCollectionDTO.getStartDate()) |
| 154 | + .le(StringUtils.hasLength(queryCollectionDTO.getEndDate()), FinancialMain::getReceiptDate, queryCollectionDTO.getEndDate()) |
| 155 | + .eq(FinancialMain::getType, "收款") |
| 156 | + .eq(FinancialMain::getDeleteFlag, CommonConstants.NOT_DELETED) |
| 157 | + .list(); |
| 158 | + |
| 159 | + var collectionVOList = new ArrayList<CollectionVO>(financialMainList.size() + 1); |
| 160 | + financialMainList.forEach(item -> { |
| 161 | + var collectionVo = CollectionVO.builder() |
| 162 | + .id(item.getId()) |
| 163 | + .receiptNumber(item.getReceiptNumber()) |
| 164 | + .customerName(commonService.getCustomerName(item.getRelatedPersonId())) |
| 165 | + .receiptDate(item.getReceiptDate()) |
| 166 | + .financialPerson(commonService.getOperatorName(item.getOperatorId())) |
| 167 | + .collectionAccountName(commonService.getAccountName(item.getAccountId())) |
| 168 | + .totalCollectionAmount(item.getTotalAmount()) |
| 169 | + .discountAmount(item.getDiscountAmount()) |
| 170 | + .actualCollectionAmount(item.getChangeAmount()) |
| 171 | + .status(item.getStatus()) |
| 172 | + .remark(item.getRemark()) |
| 173 | + .build(); |
| 174 | + |
| 175 | + collectionVOList.add(collectionVo); |
| 176 | + }); |
| 177 | + return collectionVOList; |
| 178 | + } |
| 179 | + |
142 | 180 | @Override
|
143 | 181 | public Response<CollectionDetailVO> getCollectionReceiptDetail(Long id) {
|
144 | 182 | if (id == null) {
|
@@ -352,4 +390,35 @@ public Response<String> updateCollectionReceiptStatus(List<Long> ids, Integer st
|
352 | 390 | }
|
353 | 391 | return Response.responseMsg(CollectionPaymentCodeEnum.UPDATE_COLLECTION_RECEIPT_SUCCESS);
|
354 | 392 | }
|
| 393 | + |
| 394 | + @Override |
| 395 | + public void exportCollectionReceipt(QueryCollectionDTO queryCollectionDTO, HttpServletResponse response) { |
| 396 | + var exportMap = new ConcurrentHashMap<String, List<List<Object>>>(); |
| 397 | + var mainData = getCollectionReceiptList(queryCollectionDTO); |
| 398 | + if (!mainData.isEmpty()) { |
| 399 | + exportMap.put("收款单", ExcelUtils.getSheetData(mainData)); |
| 400 | + if (queryCollectionDTO.getIsExportDetail()) { |
| 401 | + var subData = new ArrayList<CollectionDataExportBO>(); |
| 402 | + for (CollectionVO collectionVO : mainData) { |
| 403 | + var detail = getCollectionReceiptDetail(collectionVO.getId()).getData().getTableData(); |
| 404 | + if (!detail.isEmpty()) { |
| 405 | + detail.forEach(item -> { |
| 406 | + var data = CollectionDataExportBO.builder() |
| 407 | + .customerName(collectionVO.getCustomerName()) |
| 408 | + .receiptNumber(collectionVO.getReceiptNumber()) |
| 409 | + .saleReceiptNumber(item.getSaleReceiptNumber()) |
| 410 | + .receivableArrears(item.getReceivableArrears()) |
| 411 | + .receivedArrears(item.getReceivedArrears()) |
| 412 | + .thisCollectionAmount(item.getThisCollectionAmount()) |
| 413 | + .remark(item.getRemark()) |
| 414 | + .build(); |
| 415 | + subData.add(data); |
| 416 | + }); |
| 417 | + } |
| 418 | + } |
| 419 | + exportMap.put("收款单明细", ExcelUtils.getSheetData(subData)); |
| 420 | + } |
| 421 | + ExcelUtils.exportManySheet(response, "收款单", exportMap); |
| 422 | + } |
| 423 | + } |
355 | 424 | }
|
0 commit comments