|
|
@@ -678,6 +678,16 @@ public class VppCustomerServiceImpl implements VppCustomerService {
|
|
|
public Boolean deleteCustomer(Long id) {
|
|
|
VppCustomer customer = findCustomerById(id);
|
|
|
|
|
|
+ // 检查是否存在非草稿状态的合同,存在则不允许删除客户
|
|
|
+ LambdaQueryWrapper<VppContract> contractWrapper = new LambdaQueryWrapper<>();
|
|
|
+ contractWrapper.eq(VppContract::getCustomerId, id)
|
|
|
+ .eq(VppContract::getDeleteFlag, 0)
|
|
|
+ .ne(VppContract::getContractStatus, VppContractStatusHelper.DRAFT);
|
|
|
+ Integer nonDraftCount = contractMapper.selectCount(contractWrapper);
|
|
|
+ if (nonDraftCount != null && nonDraftCount > 0) {
|
|
|
+ throw new BusinessException("该客户下存在非草稿状态的合同,无法删除!");
|
|
|
+ }
|
|
|
+
|
|
|
VppAuditHelper.fillSoftDelete(customer);
|
|
|
int result = customerMapper.updateById(customer);
|
|
|
return result > 0;
|
|
|
@@ -736,23 +746,12 @@ public class VppCustomerServiceImpl implements VppCustomerService {
|
|
|
customers = Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
- // 批量查询关联合同
|
|
|
+ // 批量查询关联主联系人
|
|
|
final Set<Long> customerIds = customers.stream()
|
|
|
.map(VppCustomer::getId)
|
|
|
.filter(Objects::nonNull)
|
|
|
.collect(Collectors.toSet());
|
|
|
-
|
|
|
- final Map<Long, List<VppContract>> contractMap;
|
|
|
- if (!customerIds.isEmpty()) {
|
|
|
- LambdaQueryWrapper<VppContract> contractWrapper = new LambdaQueryWrapper<>();
|
|
|
- contractWrapper.in(VppContract::getCustomerId, customerIds)
|
|
|
- .eq(VppContract::getDeleteFlag, 0);
|
|
|
- List<VppContract> allContracts = contractMapper.selectList(contractWrapper);
|
|
|
- contractMap = allContracts.stream()
|
|
|
- .collect(Collectors.groupingBy(VppContract::getCustomerId));
|
|
|
- } else {
|
|
|
- contractMap = Collections.emptyMap();
|
|
|
- }
|
|
|
+ final Map<Long, VppCustomerContact> contactMap = loadPrimaryContactMap(customerIds);
|
|
|
|
|
|
// 生成 Excel
|
|
|
try (org.apache.poi.xssf.usermodel.XSSFWorkbook workbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook()) {
|
|
|
@@ -768,13 +767,8 @@ public class VppCustomerServiceImpl implements VppCustomerService {
|
|
|
|
|
|
// 表头
|
|
|
String[] headers = {
|
|
|
- "序号", "电力户号", "客户名称", "客户类型", "供电公司",
|
|
|
- "签约容量(kW)", "信用状态", "签约状态",
|
|
|
- "省", "市", "区/县", "地址", "用电地址",
|
|
|
- "是否VPP资源", "VPP分类", "需求响应资源分类",
|
|
|
- "VPP代理编码", "所属行业", "所属产业", "运行容量(kW)",
|
|
|
- "生产经营开始", "生产经营结束", "合同编号列表",
|
|
|
- "营业执照", "签约日期", "备注", "创建时间"
|
|
|
+ "序号", "客户名称", "客户类型", "联系人", "联系电话",
|
|
|
+ "供电单位", "用电容量", "信用状况", "企业地址", "营业执照"
|
|
|
};
|
|
|
org.apache.poi.xssf.usermodel.XSSFRow headerRow = sheet.createRow(0);
|
|
|
for (int i = 0; i < headers.length; i++) {
|
|
|
@@ -787,50 +781,30 @@ public class VppCustomerServiceImpl implements VppCustomerService {
|
|
|
int rowIdx = 1;
|
|
|
for (VppCustomer c : customers) {
|
|
|
org.apache.poi.xssf.usermodel.XSSFRow row = sheet.createRow(rowIdx++);
|
|
|
- List<VppContract> contracts = contractMap.getOrDefault(c.getId(), Collections.emptyList());
|
|
|
- String contractNos = contracts.stream()
|
|
|
- .map(VppContract::getContractNo)
|
|
|
- .collect(Collectors.joining("; "));
|
|
|
+ VppCustomerContact contact = contactMap.get(c.getId());
|
|
|
|
|
|
setCell(row, 0, rowIdx - 1); // 序号
|
|
|
- setCell(row, 1, c.getAccountNo());
|
|
|
- setCell(row, 2, c.getCustomerName());
|
|
|
- setCell(row, 3, typeLabel(c.getCustomerType(), "虚拟电厂", "售电客户"));
|
|
|
- setCell(row, 4, c.getPowerCompany());
|
|
|
- setCell(row, 5, numberStr(c.getContractCapacity()));
|
|
|
- setCell(row, 6, typeLabel(c.getCreditStatus(), "正常", "关注", "不良"));
|
|
|
- setCell(row, 7, typeLabel(c.getLifecycleStatus(), "待签约", "已签约", "履约中", "待续约", "已续约", "已解约"));
|
|
|
- setCell(row, 8, c.getProvince());
|
|
|
- setCell(row, 9, c.getCity());
|
|
|
- setCell(row, 10, c.getDistrict());
|
|
|
- setCell(row, 11, c.getAddress());
|
|
|
- setCell(row, 12, c.getPowerAddress());
|
|
|
- setCell(row, 13, c.getIsVppResource() != null && c.getIsVppResource() == 1 ? "是" : "否");
|
|
|
- setCell(row, 14, c.getVppCategory());
|
|
|
- setCell(row, 15, c.getDrResourceType());
|
|
|
- setCell(row, 16, c.getVppProxyCode());
|
|
|
- setCell(row, 17, c.getIndustry());
|
|
|
- setCell(row, 18, c.getIndustrySector());
|
|
|
- setCell(row, 19, numberStr(c.getRunningCapacity()));
|
|
|
- setCell(row, 20, timeStr(c.getProductionStartDate()));
|
|
|
- setCell(row, 21, timeStr(c.getProductionEndDate()));
|
|
|
- setCell(row, 22, contractNos);
|
|
|
- insertLicenseImage(workbook, sheet, row, 23, c.getBusinessLicenseUrl());
|
|
|
- setCell(row, 24, dateStr(c.getSigningDate()));
|
|
|
- setCell(row, 25, c.getRemark());
|
|
|
- setCell(row, 26, dateTimeStr(c.getCreateTime()));
|
|
|
+ setCell(row, 1, c.getCustomerName()); // 客户名称
|
|
|
+ setCell(row, 2, typeLabel(c.getCustomerType(), "虚拟电厂", "售电客户")); // 客户类型
|
|
|
+ setCell(row, 3, contact != null ? contact.getContactName() : ""); // 联系人
|
|
|
+ setCell(row, 4, contact != null ? contact.getContactPhone() : ""); // 联系电话
|
|
|
+ setCell(row, 5, c.getPowerCompany()); // 供电单位
|
|
|
+ setCell(row, 6, numberStr(c.getContractCapacity())); // 用电容量
|
|
|
+ setCell(row, 7, typeLabel(c.getCreditStatus(), "正常", "关注", "不良")); // 信用状况
|
|
|
+ setCell(row, 8, c.getAddress()); // 企业地址
|
|
|
+ insertLicenseImage(workbook, sheet, row, 9, c.getBusinessLicenseUrl()); // 营业执照
|
|
|
}
|
|
|
|
|
|
// 设置营业执照列宽度(固定宽度以适配图片)
|
|
|
- sheet.setColumnWidth(23, 28 * 256); // 约 28 字符宽
|
|
|
+ sheet.setColumnWidth(9, 28 * 256); // 约 28 字符宽
|
|
|
|
|
|
// 自动调整列宽
|
|
|
for (int i = 0; i < headers.length; i++) {
|
|
|
- if (i == 23) {
|
|
|
+ if (i == 9) {
|
|
|
continue; // 营业执照列已手动设置宽度
|
|
|
}
|
|
|
sheet.autoSizeColumn(i);
|
|
|
- // 限制最大宽度,避免营业执照URL列过宽
|
|
|
+ // 限制最大宽度
|
|
|
int width = sheet.getColumnWidth(i);
|
|
|
if (width > 15000) {
|
|
|
sheet.setColumnWidth(i, 15000);
|