package com.talentcard.server.business.admin; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import com.talentcard.server.business.PageResult; import com.talentcard.server.business.admin.auth.AdminAuthInterceptor; import com.talentcard.server.common.ApiResponse; import com.talentcard.server.request.ParkingPlateStatusUpdateRequest; import com.talentcard.server.service.ParkingPlateSubmissionAdminService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @Tag(name = "后台-停车车牌管理", description = "后台查询、处理、导出人才提交的停车车牌记录") @RestController @RequestMapping("/api/admin/parking-plate-submissions") public class ParkingPlateSubmissionAdminController { private final ParkingPlateSubmissionAdminService service; public ParkingPlateSubmissionAdminController(ParkingPlateSubmissionAdminService service) { this.service = service; } @Operation(summary = "查询车牌提交记录", description = "分页查看车牌号、持卡人、手机号、提交时间、处理状态和处理结果") @GetMapping public ApiResponse>> page( @Parameter(description = "停车商家ID") @RequestParam(required = false) Long merchantId, @Parameter(description = "停车场ID") @RequestParam(required = false) Long parkingLotId, @Parameter(description = "通用关键词:持卡人、手机号、卡号、车牌号或提交单号") @RequestParam(required = false) String keyword, @Parameter(description = "持卡人姓名") @RequestParam(required = false) String talentName, @Parameter(description = "持卡人手机号") @RequestParam(required = false) String talentMobile, @Parameter(description = "车牌号") @RequestParam(required = false) String plateNumber, @Parameter(description = "停车商家或停车场关键词") @RequestParam(required = false) String serviceKeyword, @Parameter(description = "人才卡等级") @RequestParam(required = false) String cardLevel, @Parameter(description = "处理状态") @RequestParam(required = false) String status, @Parameter(description = "提交类型:新增/修改") @RequestParam(required = false) String submissionType, @Parameter(description = "提交开始日期,格式yyyy-MM-dd") @RequestParam(required = false) String submittedStart, @Parameter(description = "提交结束日期,格式yyyy-MM-dd") @RequestParam(required = false) String submittedEnd, @Parameter(description = "页码") @RequestParam(defaultValue = "1") int page, @Parameter(description = "每页条数") @RequestParam(defaultValue = "10") int size ) { return ApiResponse.success(service.page( merchantId, parkingLotId, keyword, talentName, talentMobile, plateNumber, serviceKeyword, cardLevel, status, submissionType, submittedStart, submittedEnd, page, size)); } @Operation(summary = "查询车牌提交详情", description = "查看持卡人、停车场、车牌提交和后台处理信息") @GetMapping("/{id}") public ApiResponse> detail(@PathVariable Long id) { return ApiResponse.success(service.detail(id)); } @Operation(summary = "查询车牌操作日志", description = "查看车牌提交状态变更及后台处理记录") @GetMapping("/{id}/operation-logs") public ApiResponse>> operationLogs(@PathVariable Long id) { return ApiResponse.success(service.operationLogs(id)); } @Operation(summary = "处理车牌提交", description = "更新车牌提交处理状态、处理结果和备注,并记录后台操作日志") @PatchMapping("/{id}/status") public ApiResponse> updateStatus( @PathVariable Long id, @Valid @RequestBody ParkingPlateStatusUpdateRequest request, @RequestAttribute(value = AdminAuthInterceptor.OPERATOR_ID_ATTRIBUTE, required = false) Long operatorId ) { return ApiResponse.success(service.updateStatus(id, request, operatorId)); } @Operation(summary = "批量导出车牌记录", description = "按当前筛选条件或勾选的记录导出车牌Excel,供商家录入") @GetMapping(value = "/export", produces = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") public void export( @Parameter(description = "停车商家ID") @RequestParam(required = false) Long merchantId, @Parameter(description = "停车场ID") @RequestParam(required = false) Long parkingLotId, @Parameter(description = "通用关键词:持卡人、手机号、卡号、车牌号或提交单号") @RequestParam(required = false) String keyword, @Parameter(description = "持卡人姓名") @RequestParam(required = false) String talentName, @Parameter(description = "持卡人手机号") @RequestParam(required = false) String talentMobile, @Parameter(description = "车牌号") @RequestParam(required = false) String plateNumber, @Parameter(description = "停车商家或停车场关键词") @RequestParam(required = false) String serviceKeyword, @Parameter(description = "人才卡等级") @RequestParam(required = false) String cardLevel, @Parameter(description = "处理状态") @RequestParam(required = false) String status, @Parameter(description = "提交类型:新增/修改") @RequestParam(required = false) String submissionType, @Parameter(description = "提交开始日期,格式yyyy-MM-dd") @RequestParam(required = false) String submittedStart, @Parameter(description = "提交结束日期,格式yyyy-MM-dd") @RequestParam(required = false) String submittedEnd, @Parameter(description = "勾选导出的车牌记录ID,可重复传入;不传则按筛选条件导出") @RequestParam(required = false) List ids, HttpServletResponse response ) throws IOException { byte[] data = service.exportExcel( merchantId, parkingLotId, keyword, talentName, talentMobile, plateNumber, serviceKeyword, cardLevel, status, submissionType, submittedStart, submittedEnd, ids); String filename = URLEncoder.encode("停车车牌记录.xlsx", StandardCharsets.UTF_8).replace("+", "%20"); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.setContentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet").toString()); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + filename); response.setContentLength(data.length); response.getOutputStream().write(data); response.flushBuffer(); } }