|
|
@@ -0,0 +1,89 @@
|
|
|
+package com.etotem.cfc.controller;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.dto.ServiceRoleApplyDTO;
|
|
|
+import com.etotem.cfc.entity.ServiceRoleApplication;
|
|
|
+import com.etotem.cfc.service.ServiceRoleApplicationService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+@Tag(name = "服务角色申请", description = "统一服务角色申请入口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/service-role")
|
|
|
+public class ServiceRoleApplicationController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ServiceRoleApplicationService serviceRoleApplicationService;
|
|
|
+
|
|
|
+ @PostMapping("/apply")
|
|
|
+ @Operation(summary = "提交服务角色申请")
|
|
|
+ public Result apply(@RequestAttribute("userId") Long userId,
|
|
|
+ @Valid @RequestBody ServiceRoleApplyDTO dto) {
|
|
|
+ return serviceRoleApplicationService.submit(userId, dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/my-apply")
|
|
|
+ @Operation(summary = "查询我的申请记录")
|
|
|
+ public Result myApply(@RequestAttribute("userId") Long userId) {
|
|
|
+ return serviceRoleApplicationService.getMyApplication(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/upload-image")
|
|
|
+ @Operation(summary = "上传图片(身份证/资质证书)")
|
|
|
+ public Result uploadImage(@RequestAttribute("userId") Long userId,
|
|
|
+ @RequestParam("file") MultipartFile file) {
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ return Result.error("请选择文件");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String uploadDir = System.getProperty("user.dir") + "/uploads/service-role/" + userId;
|
|
|
+ File dirFile = new File(uploadDir);
|
|
|
+ if (!dirFile.exists()) {
|
|
|
+ dirFile.mkdirs();
|
|
|
+ }
|
|
|
+ String originalName = file.getOriginalFilename();
|
|
|
+ String ext = originalName != null && originalName.contains(".")
|
|
|
+ ? originalName.substring(originalName.lastIndexOf(".")) : ".jpg";
|
|
|
+ String fileName = UUID.randomUUID().toString() + ext;
|
|
|
+ File dest = new File(dirFile, fileName);
|
|
|
+ file.transferTo(dest);
|
|
|
+ return Result.success(Map.of("url", "/uploads/service-role/" + userId + "/" + fileName));
|
|
|
+ } catch (IOException e) {
|
|
|
+ return Result.error("上传失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/admin/list")
|
|
|
+ @Operation(summary = "管理端: 获取申请列表")
|
|
|
+ public Result adminList(@RequestParam(required = false, defaultValue = "0") Integer status) {
|
|
|
+ List<ServiceRoleApplication> list = serviceRoleApplicationService.listApplications(status);
|
|
|
+ return Result.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/admin/approve")
|
|
|
+ @Operation(summary = "管理端: 批准申请")
|
|
|
+ public Result adminApprove(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("userId") Long adminId) {
|
|
|
+ Long id = Long.valueOf(params.get("id").toString());
|
|
|
+ return serviceRoleApplicationService.approve(id, adminId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/admin/reject")
|
|
|
+ @Operation(summary = "管理端: 驳回申请")
|
|
|
+ public Result adminReject(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("userId") Long adminId) {
|
|
|
+ Long id = Long.valueOf(params.get("id").toString());
|
|
|
+ String reason = params.get("reason") != null ? params.get("reason").toString() : "";
|
|
|
+ return serviceRoleApplicationService.reject(id, reason, adminId);
|
|
|
+ }
|
|
|
+}
|