- 将多个实体类中的involvedAmount字段由BigDecimal改为String类型 - 将CreditCustomer和CreditSupplier中的金额及日期字段调整为String类型 - 移除Excel导入时对金额字段的手动BigDecimal解析 - 增强ExcelImportSupport支持指定sheet索引读取功能 - 为CreditCustomer新增完整的Excel导入和模板下载接口 - 新增CreditCustomerImportParam用于导入数据映
279 lines
11 KiB
Java
279 lines
11 KiB
Java
package com.gxwebsoft.credit.controller;
|
||
|
||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||
import com.gxwebsoft.common.core.web.ApiResult;
|
||
import com.gxwebsoft.common.core.web.BaseController;
|
||
import com.gxwebsoft.common.core.web.BatchParam;
|
||
import com.gxwebsoft.common.core.web.PageResult;
|
||
import com.gxwebsoft.common.system.entity.User;
|
||
import com.gxwebsoft.credit.entity.CreditCaseFiling;
|
||
import com.gxwebsoft.credit.param.CreditJudicialImportParam;
|
||
import com.gxwebsoft.credit.param.CreditCaseFilingParam;
|
||
import com.gxwebsoft.credit.service.CreditCaseFilingService;
|
||
import io.swagger.v3.oas.annotations.Operation;
|
||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||
import org.apache.poi.ss.usermodel.Workbook;
|
||
import org.springframework.security.access.prepost.PreAuthorize;
|
||
import org.springframework.util.CollectionUtils;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import javax.annotation.Resource;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import java.io.IOException;
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
|
||
/**
|
||
* 司法大数据控制器
|
||
*
|
||
* @author 科技小王子
|
||
* @since 2025-12-19 19:47:23
|
||
*/
|
||
@Tag(name = "司法大数据管理")
|
||
@RestController
|
||
@RequestMapping("/api/credit/credit-case-filing")
|
||
public class CreditCaseFilingController extends BaseController {
|
||
@Resource
|
||
private CreditCaseFilingService creditCaseFilingService;
|
||
|
||
@Operation(summary = "分页查询司法大数据")
|
||
@GetMapping("/page")
|
||
public ApiResult<PageResult<CreditCaseFiling>> page(CreditCaseFilingParam param) {
|
||
// 使用关联查询
|
||
return success(creditCaseFilingService.pageRel(param));
|
||
}
|
||
|
||
@Operation(summary = "查询全部司法大数据")
|
||
@GetMapping()
|
||
public ApiResult<List<CreditCaseFiling>> list(CreditCaseFilingParam param) {
|
||
// 使用关联查询
|
||
return success(creditCaseFilingService.listRel(param));
|
||
}
|
||
|
||
@Operation(summary = "根据id查询司法大数据")
|
||
@GetMapping("/{id}")
|
||
public ApiResult<CreditCaseFiling> get(@PathVariable("id") Integer id) {
|
||
// 使用关联查询
|
||
return success(creditCaseFilingService.getByIdRel(id));
|
||
}
|
||
|
||
@PreAuthorize("hasAuthority('credit:creditCaseFiling:save')")
|
||
@OperationLog
|
||
@Operation(summary = "添加司法大数据")
|
||
@PostMapping()
|
||
public ApiResult<?> save(@RequestBody CreditCaseFiling creditCaseFiling) {
|
||
// 记录当前登录用户id
|
||
// User loginUser = getLoginUser();
|
||
// if (loginUser != null) {
|
||
// creditCaseFiling.setUserId(loginUser.getUserId());
|
||
// }
|
||
if (creditCaseFilingService.save(creditCaseFiling)) {
|
||
return success("添加成功");
|
||
}
|
||
return fail("添加失败");
|
||
}
|
||
|
||
@PreAuthorize("hasAuthority('credit:creditCaseFiling:update')")
|
||
@OperationLog
|
||
@Operation(summary = "修改司法大数据")
|
||
@PutMapping()
|
||
public ApiResult<?> update(@RequestBody CreditCaseFiling creditCaseFiling) {
|
||
if (creditCaseFilingService.updateById(creditCaseFiling)) {
|
||
return success("修改成功");
|
||
}
|
||
return fail("修改失败");
|
||
}
|
||
|
||
@PreAuthorize("hasAuthority('credit:creditCaseFiling:remove')")
|
||
@OperationLog
|
||
@Operation(summary = "删除司法大数据")
|
||
@DeleteMapping("/{id}")
|
||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||
if (creditCaseFilingService.removeById(id)) {
|
||
return success("删除成功");
|
||
}
|
||
return fail("删除失败");
|
||
}
|
||
|
||
@PreAuthorize("hasAuthority('credit:creditCaseFiling:save')")
|
||
@OperationLog
|
||
@Operation(summary = "批量添加司法大数据")
|
||
@PostMapping("/batch")
|
||
public ApiResult<?> saveBatch(@RequestBody List<CreditCaseFiling> list) {
|
||
if (creditCaseFilingService.saveBatch(list)) {
|
||
return success("添加成功");
|
||
}
|
||
return fail("添加失败");
|
||
}
|
||
|
||
@PreAuthorize("hasAuthority('credit:creditCaseFiling:update')")
|
||
@OperationLog
|
||
@Operation(summary = "批量修改司法大数据")
|
||
@PutMapping("/batch")
|
||
public ApiResult<?> removeBatch(@RequestBody BatchParam<CreditCaseFiling> batchParam) {
|
||
if (batchParam.update(creditCaseFilingService, "id")) {
|
||
return success("修改成功");
|
||
}
|
||
return fail("修改失败");
|
||
}
|
||
|
||
@PreAuthorize("hasAuthority('credit:creditCaseFiling:remove')")
|
||
@OperationLog
|
||
@Operation(summary = "批量删除司法大数据")
|
||
@DeleteMapping("/batch")
|
||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||
if (creditCaseFilingService.removeByIds(ids)) {
|
||
return success("删除成功");
|
||
}
|
||
return fail("删除失败");
|
||
}
|
||
|
||
/**
|
||
* 批量导入司法大数据
|
||
*/
|
||
@PreAuthorize("hasAuthority('credit:creditCaseFiling:save')")
|
||
@Operation(summary = "批量导入司法大数据")
|
||
@PostMapping("/import")
|
||
public ApiResult<List<String>> importBatch(@RequestParam("file") MultipartFile file) {
|
||
List<String> errorMessages = new ArrayList<>();
|
||
int successCount = 0;
|
||
|
||
try {
|
||
ExcelImportSupport.ImportResult<CreditJudicialImportParam> importResult = ExcelImportSupport.read(
|
||
file, CreditJudicialImportParam.class, this::isEmptyImportRow);
|
||
List<CreditJudicialImportParam> list = importResult.getData();
|
||
int usedTitleRows = importResult.getTitleRows();
|
||
int usedHeadRows = importResult.getHeadRows();
|
||
|
||
if (CollectionUtils.isEmpty(list)) {
|
||
return fail("未读取到数据,请确认模板表头与示例格式一致", null);
|
||
}
|
||
|
||
User loginUser = getLoginUser();
|
||
Integer currentUserId = loginUser != null ? loginUser.getUserId() : null;
|
||
Integer currentTenantId = loginUser != null ? loginUser.getTenantId() : null;
|
||
|
||
for (int i = 0; i < list.size(); i++) {
|
||
CreditJudicialImportParam param = list.get(i);
|
||
try {
|
||
CreditCaseFiling item = convertImportParamToEntity(param);
|
||
|
||
if (item.getUserId() == null && currentUserId != null) {
|
||
item.setUserId(currentUserId);
|
||
}
|
||
if (item.getTenantId() == null && currentTenantId != null) {
|
||
item.setTenantId(currentTenantId);
|
||
}
|
||
if (item.getStatus() == null) {
|
||
item.setStatus(0);
|
||
}
|
||
if (item.getRecommend() == null) {
|
||
item.setRecommend(0);
|
||
}
|
||
if (item.getDeleted() == null) {
|
||
item.setDeleted(0);
|
||
}
|
||
|
||
int excelRowNumber = i + 1 + usedTitleRows + usedHeadRows;
|
||
if (ImportHelper.isBlank(item.getCaseNumber())) {
|
||
errorMessages.add("第" + excelRowNumber + "行:案号不能为空");
|
||
continue;
|
||
}
|
||
|
||
boolean saved = creditCaseFilingService.save(item);
|
||
if (!saved) {
|
||
CreditCaseFiling existing = creditCaseFilingService.lambdaQuery()
|
||
.eq(CreditCaseFiling::getCaseNumber, item.getCaseNumber())
|
||
.one();
|
||
if (existing != null) {
|
||
item.setId(existing.getId());
|
||
if (creditCaseFilingService.updateById(item)) {
|
||
successCount++;
|
||
continue;
|
||
}
|
||
}
|
||
} else {
|
||
successCount++;
|
||
continue;
|
||
}
|
||
errorMessages.add("第" + excelRowNumber + "行:保存失败");
|
||
} catch (Exception e) {
|
||
int excelRowNumber = i + 1 + usedTitleRows + usedHeadRows;
|
||
errorMessages.add("第" + excelRowNumber + "行:" + e.getMessage());
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
if (errorMessages.isEmpty()) {
|
||
return success("成功导入" + successCount + "条数据", null);
|
||
} else {
|
||
return success("导入完成,成功" + successCount + "条,失败" + errorMessages.size() + "条", errorMessages);
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return fail("导入失败:" + e.getMessage(), null);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 下载司法大数据导入模板
|
||
*/
|
||
@Operation(summary = "下载司法大数据导入模板")
|
||
@GetMapping("/import/template")
|
||
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
||
List<CreditJudicialImportParam> templateList = new ArrayList<>();
|
||
|
||
CreditJudicialImportParam example = new CreditJudicialImportParam();
|
||
example.setDataType("司法大数据");
|
||
example.setPlaintiffAppellant("原告示例");
|
||
example.setAppellee("被告示例");
|
||
example.setOtherPartiesThirdParty("第三人示例");
|
||
example.setOccurrenceTime("2024-01-01");
|
||
example.setCaseNumber("(2024)示例案号");
|
||
example.setCauseOfAction("案由示例");
|
||
example.setInvolvedAmount("100000");
|
||
example.setCourtName("示例法院");
|
||
example.setDataStatus("已公开");
|
||
example.setComments("备注信息");
|
||
templateList.add(example);
|
||
|
||
Workbook workbook = ExcelImportSupport.buildTemplate("司法大数据导入模板", "司法大数据", CreditJudicialImportParam.class, templateList);
|
||
|
||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||
response.setHeader("Content-Disposition", "attachment; filename=credit_case_filing_import_template.xlsx");
|
||
|
||
workbook.write(response.getOutputStream());
|
||
workbook.close();
|
||
}
|
||
|
||
private boolean isEmptyImportRow(CreditJudicialImportParam param) {
|
||
if (param == null) {
|
||
return true;
|
||
}
|
||
return ImportHelper.isBlank(param.getCaseNumber())
|
||
&& ImportHelper.isBlank(param.getPlaintiffAppellant())
|
||
&& ImportHelper.isBlank(param.getAppellee())
|
||
&& ImportHelper.isBlank(param.getCauseOfAction());
|
||
}
|
||
|
||
private CreditCaseFiling convertImportParamToEntity(CreditJudicialImportParam param) {
|
||
CreditCaseFiling entity = new CreditCaseFiling();
|
||
|
||
entity.setDataType(param.getDataType());
|
||
entity.setPlaintiffAppellant(param.getPlaintiffAppellant());
|
||
entity.setAppellee(param.getAppellee());
|
||
entity.setOtherPartiesThirdParty(param.getOtherPartiesThirdParty());
|
||
entity.setOccurrenceTime(param.getOccurrenceTime());
|
||
entity.setCaseNumber(param.getCaseNumber());
|
||
entity.setCauseOfAction(param.getCauseOfAction());
|
||
entity.setInvolvedAmount(param.getInvolvedAmount());
|
||
entity.setCourtName(param.getCourtName());
|
||
entity.setDataStatus(param.getDataStatus());
|
||
entity.setComments(param.getComments());
|
||
|
||
return entity;
|
||
}
|
||
|
||
}
|