feat(sys):合同导出
This commit is contained in:
+47
@@ -1124,4 +1124,51 @@ public class ContractManageApplicationService {
|
||||
public ContractManagePO getGeneralContract() {
|
||||
return contractManageDomainService.getGeneralContract();
|
||||
}
|
||||
|
||||
/**
|
||||
* 合同导出(合同头字段 + 明细拍平成一行一条明细)
|
||||
*/
|
||||
public List<ContractManageExportVO> buildExportList(ContractManageDO contractManageDO) {
|
||||
List<ContractManagePO> contractList = this.queryList(contractManageDO);
|
||||
List<ContractManageExportVO> exportList = new ArrayList<>();
|
||||
if (contractList == null || contractList.isEmpty()) {
|
||||
return exportList;
|
||||
}
|
||||
List<Long> contractManageIds = contractList.stream()
|
||||
.map(ContractManagePO::getContractManageId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, List<ContractManageDetailPO>> detailMap = contractManageDetailDomainService
|
||||
.queryListByManageIds(contractManageIds).stream()
|
||||
.collect(Collectors.groupingBy(ContractManageDetailPO::getContractManageId));
|
||||
|
||||
for (ContractManagePO contract : contractList) {
|
||||
List<ContractManageDetailPO> details = detailMap.get(contract.getContractManageId());
|
||||
if (details != null && !details.isEmpty()) {
|
||||
for (ContractManageDetailPO detail : details) {
|
||||
ContractManageExportVO vo = new ContractManageExportVO();
|
||||
// 合同头字段整体复制
|
||||
BeanUtils.copyProperties(contract, vo);
|
||||
// 明细字段显式赋值(合同头/明细存在同名字段,避免互相覆盖)
|
||||
vo.setSubjectType(detail.getSubjectType());
|
||||
vo.setFirstSubjectCode(detail.getFirstSubjectCode());
|
||||
vo.setFirstSubjectName(detail.getFirstSubjectName());
|
||||
vo.setSecondSubjectCode(detail.getSecondSubjectCode());
|
||||
vo.setSecondSubjectName(detail.getSecondSubjectName());
|
||||
vo.setAccountingStrategy(detail.getAccountingStrategy());
|
||||
vo.setBillingAttributes(detail.getBillingAttributes());
|
||||
vo.setSubjectEffectiveDate(detail.getSubjectEffectiveDate());
|
||||
vo.setSubjectExpirationDate(detail.getSubjectExpirationDate());
|
||||
vo.setDocumentType(detail.getDocumentType());
|
||||
vo.setServiceItemsName(detail.getServiceItemsName());
|
||||
exportList.add(vo);
|
||||
}
|
||||
} else {
|
||||
// 无明细的合同也保留一行头字段
|
||||
ContractManageExportVO vo = new ContractManageExportVO();
|
||||
BeanUtils.copyProperties(contract, vo);
|
||||
exportList.add(vo);
|
||||
}
|
||||
}
|
||||
return exportList;
|
||||
}
|
||||
}
|
||||
+25
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
/**
|
||||
* 合同管理详情
|
||||
@@ -95,5 +96,29 @@ public class ContractManageDetailDomainService {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据多个合同管理id批量查询合同科目详情(一次SQL查询,避免逐合同N+1)
|
||||
* @param contractManageIds 合同管理id集合
|
||||
* @return 合同科目详情列表
|
||||
*/
|
||||
public List<ContractManageDetailPO> queryListByManageIds(Collection<Long> contractManageIds) {
|
||||
List<ContractManageDetailPO> resultList = new ArrayList<>();
|
||||
if (contractManageIds == null || contractManageIds.isEmpty()) {
|
||||
return resultList;
|
||||
}
|
||||
LambdaQueryWrapper<ContractManageDetail> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(ContractManageDetail::getContractManageId, contractManageIds);
|
||||
queryWrapper.eq(ContractManageDetail::getDelFlag, 1);
|
||||
List<ContractManageDetail> contractManageDetails = contractManageDetailService.list(queryWrapper);
|
||||
if (contractManageDetails != null && contractManageDetails.size() > 0) {
|
||||
for (ContractManageDetail contractManageDetail : contractManageDetails) {
|
||||
ContractManageDetailPO contractManageDetailPO = new ContractManageDetailPO();
|
||||
BeanUtils.copyProperties(contractManageDetail, contractManageDetailPO);
|
||||
resultList.add(contractManageDetailPO);
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package com.mhd.basic.interfaces.dto.contractManage;
|
||||
|
||||
import com.mhd.common.core.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 合同管理导出对象(合同头字段 + 科目明细字段,拍平为一行一条明细)
|
||||
*
|
||||
* @author gen
|
||||
* @date 2024-06-07
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "合同管理导出对象", description = "合同管理导出对象(含明细)")
|
||||
public class ContractManageExportVO {
|
||||
|
||||
/** ====== 合同头字段(与 ContractManagePO 的 @Excel 一致) ====== */
|
||||
@Excel(name = "合同编号")
|
||||
private String contractNumber;
|
||||
|
||||
@Excel(name = "合同名称")
|
||||
private String contractName;
|
||||
|
||||
@Excel(name = "是否通用合同", readConverterExp = "1=是,2=否")
|
||||
private Integer commonContractFlag;
|
||||
|
||||
@Excel(name = "合同类型", readConverterExp = "1=仓储,2=运输,3=其他")
|
||||
private Integer contractType;
|
||||
|
||||
@Excel(name = "合同状态", readConverterExp = "1=未生效,2=使用中,3=已过期,4=已作废")
|
||||
private Integer contractState;
|
||||
|
||||
@Excel(name = "签订单位")
|
||||
private String signingUnit;
|
||||
|
||||
@Excel(name = "结算主体")
|
||||
private String settlementCustomers;
|
||||
|
||||
@Excel(name = "我司身份", readConverterExp = "1=甲方,2=乙方")
|
||||
private Integer ourIdentity;
|
||||
|
||||
@Excel(name = "账期", readConverterExp = "1=每月,2=双月,3=季度")
|
||||
private Integer accountingPeriod;
|
||||
|
||||
@Excel(name = "合同签订日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date signingDate;
|
||||
|
||||
@Excel(name = "合同生效日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date effectiveDate;
|
||||
|
||||
@Excel(name = "合同到期日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date expirationDate;
|
||||
|
||||
@Excel(name = "组织名称")
|
||||
private String organizationName;
|
||||
|
||||
@Excel(name = "客户类型")
|
||||
private String customerType;
|
||||
|
||||
@Excel(name = "是否自动出账", readConverterExp = "1=是,2=否")
|
||||
private Integer automaticFlag;
|
||||
|
||||
@Excel(name = "备注")
|
||||
private String remark;
|
||||
|
||||
/** ====== 明细字段(来源于 contract_manage_detail) ====== */
|
||||
@Excel(name = "结算科目类型", readConverterExp = "1=通用,2=临时")
|
||||
private Integer subjectType;
|
||||
|
||||
@Excel(name = "一级费用科目code")
|
||||
private String firstSubjectCode;
|
||||
|
||||
@Excel(name = "一级费用科目")
|
||||
private String firstSubjectName;
|
||||
|
||||
@Excel(name = "二级费用科目code")
|
||||
private String secondSubjectCode;
|
||||
|
||||
@Excel(name = "二级费用科目")
|
||||
private String secondSubjectName;
|
||||
|
||||
@Excel(name = "计费策略")
|
||||
private String accountingStrategy;
|
||||
|
||||
@Excel(name = "计费周期")
|
||||
private String billingAttributes;
|
||||
|
||||
@Excel(name = "科目生效日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date subjectEffectiveDate;
|
||||
|
||||
@Excel(name = "科目到期日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date subjectExpirationDate;
|
||||
|
||||
@Excel(name = "单据类型")
|
||||
private String documentType;
|
||||
|
||||
@Excel(name = "费用类别")
|
||||
private String serviceItemsName;
|
||||
}
|
||||
+22
@@ -1,8 +1,11 @@
|
||||
package com.mhd.basic.interfaces.facade.contractManage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
||||
import com.mhd.basic.interfaces.assember.contractManage.ContractManageAssembler;
|
||||
import com.mhd.basic.interfaces.dto.contractManage.ContractManageExportVO;
|
||||
import com.mhd.basic.interfaces.dto.contractManage.SubjectAndPriceDTO;
|
||||
import com.mhd.basic.interfaces.dto.contractManage.SubjectAndPriceReturn;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -14,9 +17,11 @@ import com.mhd.basic.domain.contractManage.repository.todo.ContractManageDO;
|
||||
import com.mhd.basic.domain.contractManage.repository.po.ContractManagePO;
|
||||
import com.mhd.basic.application.service.contractManage.ContractManageApplicationService;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import com.mhd.common.core.web.controller.BaseController;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.common.core.web.page.TableDataInfo;
|
||||
import com.mhd.common.core.utils.poi.ExcelUtil;
|
||||
|
||||
/**
|
||||
* 合同管理Api
|
||||
@@ -205,7 +210,24 @@ public class ContractManageApi extends BaseController{
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@ApiOperation("导出合同(含明细)")
|
||||
@GetMapping(value = "/export", produces = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
public void export(ContractManageDTO contractManageDTO, HttpServletResponse response) throws IOException
|
||||
{
|
||||
//转换实体
|
||||
ContractManageDO contractManageDO = new ContractManageDO();
|
||||
BeanUtils.copyProperties(contractManageDTO, contractManageDO);
|
||||
//查询全量(不分页)并拍平明细
|
||||
List<ContractManageExportVO> list = contractManageApplicationService.buildExportList(contractManageDO);
|
||||
|
||||
//设置下载头,防止浏览器乱码
|
||||
String fileName = URLEncoder.encode("合同导出", "UTF-8").replaceAll("\\+", "%20");
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
|
||||
ExcelUtil<ContractManageExportVO> util = new ExcelUtil<>(ContractManageExportVO.class);
|
||||
util.exportExcel(response, list, "合同导出");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user