feat(data): 更新公司记录计数服务并优化导入功能

- 在多个控制器中引入 CreditCompanyRecordCountService 依赖注入
- 添加 HashSet 和 Set 类型导入以支持公司ID集合操作
- 在Excel导入过程中跟踪受影响的公司ID集合
- 实现导入完成后批量刷新公司记录计数的功能
- 扩展 CreditCompany 实体类添加各类信用记录计数字段
- 优化导入逻辑确保公司记录计数实时更新
This commit is contained in:
2026-01-28 21:46:45 +08:00
parent 5e804bbf9a
commit a3e812a9c4
2 changed files with 48 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ import com.gxwebsoft.credit.entity.CreditCompany;
import com.gxwebsoft.credit.param.CreditCompanyImportParam;
import com.gxwebsoft.credit.param.CreditCompanyParam;
import com.gxwebsoft.credit.service.CreditCompanyService;
import com.gxwebsoft.credit.service.CreditCompanyRecordCountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.poi.ss.usermodel.Workbook;
@@ -47,6 +48,9 @@ public class CreditCompanyController extends BaseController {
@Resource
private BatchImportSupport batchImportSupport;
@Resource
private CreditCompanyRecordCountService creditCompanyRecordCountService;
@Operation(summary = "分页查询企业")
@GetMapping("/page")
public ApiResult<PageResult<CreditCompany>> page(CreditCompanyParam param) {
@@ -144,6 +148,7 @@ public class CreditCompanyController extends BaseController {
@RequestParam(value = "companyId", required = false) Integer companyId) {
List<String> errorMessages = new ArrayList<>();
int insertedCount = 0;
Set<String> touchedMatchNames = new HashSet<>();
try {
List<CreditCompanyImportParam> list = null;
@@ -216,6 +221,8 @@ public class CreditCompanyController extends BaseController {
// continue;
// }
touchedMatchNames.add(item.getMatchName().trim());
chunkItems.add(item);
chunkRowNumbers.add(excelRowNumber);
if (chunkItems.size() >= chunkSize) {
@@ -298,6 +305,28 @@ public class CreditCompanyController extends BaseController {
);
}
// 导入完成后,按 matchName 定位本次涉及的企业并回填“关联记录数”字段(避免 companyId/自增 id 在导入对象里拿不到)。
if (!touchedMatchNames.isEmpty()) {
Set<Integer> touchedCompanyIds = new HashSet<>();
List<String> allMatchNames = new ArrayList<>(touchedMatchNames);
final int inChunkSize = 800;
for (int i = 0; i < allMatchNames.size(); i += inChunkSize) {
List<String> chunk = allMatchNames.subList(i, Math.min(allMatchNames.size(), i + inChunkSize));
List<CreditCompany> dbRows = creditCompanyService.lambdaQuery()
.select(CreditCompany::getId)
.in(CreditCompany::getMatchName, chunk)
.list();
if (!CollectionUtils.isEmpty(dbRows)) {
for (CreditCompany row : dbRows) {
if (row != null && row.getId() != null) {
touchedCompanyIds.add(row.getId());
}
}
}
}
creditCompanyRecordCountService.refreshAll(touchedCompanyIds);
}
if (errorMessages.isEmpty()) {
return success("成功入库" + insertedCount + "条数据", null);
} else {

View File

@@ -10,6 +10,7 @@ import com.gxwebsoft.credit.entity.CreditXgxf;
import com.gxwebsoft.credit.param.CreditXgxfImportParam;
import com.gxwebsoft.credit.param.CreditXgxfParam;
import com.gxwebsoft.credit.service.CreditCompanyService;
import com.gxwebsoft.credit.service.CreditCompanyRecordCountService;
import com.gxwebsoft.credit.service.CreditXgxfService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -23,9 +24,11 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 限制高消费控制器
@@ -46,6 +49,9 @@ public class CreditXgxfController extends BaseController {
@Resource
private CreditCompanyService creditCompanyService;
@Resource
private CreditCompanyRecordCountService creditCompanyRecordCountService;
@Operation(summary = "分页查询限制高消费")
@GetMapping("/page")
public ApiResult<PageResult<CreditXgxf>> page(CreditXgxfParam param) {
@@ -187,6 +193,7 @@ public class CreditXgxfController extends BaseController {
@RequestParam(value = "companyId", required = false) Integer companyId) {
List<String> errorMessages = new ArrayList<>();
int successCount = 0;
Set<Integer> touchedCompanyIds = new HashSet<>();
try {
int sheetIndex = ExcelImportSupport.findSheetIndex(file, "限制高消费", 0);
@@ -226,6 +233,9 @@ public class CreditXgxfController extends BaseController {
if (item.getCompanyId() == null && companyId != null) {
item.setCompanyId(companyId);
}
if (item.getCompanyId() != null && item.getCompanyId() > 0) {
touchedCompanyIds.add(item.getCompanyId());
}
if (item.getUserId() == null && currentUserId != null) {
item.setUserId(currentUserId);
}
@@ -248,6 +258,10 @@ public class CreditXgxfController extends BaseController {
continue;
}
if (item.getCompanyId() != null && item.getCompanyId() > 0) {
touchedCompanyIds.add(item.getCompanyId());
}
chunkItems.add(item);
chunkRowNumbers.add(excelRowNumber);
if (chunkItems.size() >= chunkSize) {
@@ -332,6 +346,8 @@ public class CreditXgxfController extends BaseController {
);
}
creditCompanyRecordCountService.refresh(CreditCompanyRecordCountService.CountType.XGXF, touchedCompanyIds);
if (errorMessages.isEmpty()) {
return success("成功导入" + successCount + "条数据", null);
} else {
@@ -354,6 +370,7 @@ public class CreditXgxfController extends BaseController {
@RequestParam(value = "companyId", required = false) Integer companyId) {
List<String> errorMessages = new ArrayList<>();
int successCount = 0;
Set<Integer> touchedCompanyIds = new HashSet<>();
try {
int sheetIndex = ExcelImportSupport.findSheetIndex(file, "历史限制高消费");
@@ -533,6 +550,8 @@ public class CreditXgxfController extends BaseController {
);
}
creditCompanyRecordCountService.refresh(CreditCompanyRecordCountService.CountType.XGXF, touchedCompanyIds);
if (errorMessages.isEmpty()) {
return success("成功导入" + successCount + "条数据", null);
}