init
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
package com.mgm.mcrm.approval.controller;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.mgm.mcrm.approval.dtos.GetApproverRequest;
|
||||
import com.mgm.mcrm.approval.dtos.RejectApprovalResponse;
|
||||
import com.mgm.mcrm.approval.dtos.SubmitApprovalResponse;
|
||||
import com.mgm.mcrm.approval.models.ApprovalDetail;
|
||||
import com.mgm.mcrm.approval.models.CfgRequestReason;
|
||||
import com.mgm.mcrm.approval.service.ApprovalService;
|
||||
import com.mgm.mcrm.authorization.services.SysGroupPermissionService;
|
||||
import com.mgm.mcrm.booking.models.Bookings;
|
||||
import com.mgm.mcrm.booking.models.BookingsView;
|
||||
import com.mgm.mcrm.common.annotation.logging.OperationLog;
|
||||
import com.mgm.mcrm.common.dtos.BaseApiResponse;
|
||||
import com.mgm.mcrm.common.dtos.mgm_api.ApproverResult;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.coyote.Response;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class ApprovalController {
|
||||
|
||||
@Resource
|
||||
private ApprovalService approvalService;
|
||||
@Resource
|
||||
private SysGroupPermissionService sysGroupPermissionService;
|
||||
|
||||
|
||||
@OperationLog(actionName = "Cancel Approval Booking", eventCode = "approval_booking_cancel")
|
||||
@RequestMapping(value = "/app/approval/cancel_approval", method = RequestMethod.POST, produces = "application/json;charset=UTF-8",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<Long>> cancelApprovalBooking(HttpServletRequest request, @RequestBody Map<String, Object> booking) {
|
||||
|
||||
String token = request.getHeader("Authorization");
|
||||
String userId = JWT.decode(token).getClaim("login_id").asString();
|
||||
BaseApiResponse<Long> result = approvalService.cancelApprovalBooking(booking, userId, request);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(result);
|
||||
}
|
||||
|
||||
@OperationLog(actionName = "Cancel Approval Booking", eventCode = "approval_booking_cancel")
|
||||
@RequestMapping(value = "/app/approval/batch_cancel_approval", method = RequestMethod.POST, produces = "application/json;charset=UTF-8",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<Bookings>> batchCancelApproval(HttpServletRequest request, @RequestBody Map<String, Object> booking) {
|
||||
|
||||
String token = request.getHeader("Authorization");
|
||||
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
token = token.replace("Bearer ", "").replace("bearer ", "");
|
||||
}
|
||||
|
||||
String userId = JWT.decode(token).getClaim("login_id").asString();
|
||||
BaseApiResponse<Bookings> result = approvalService.batchCancelApprovalBooking(booking, userId, request);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(result);
|
||||
}
|
||||
|
||||
@OperationLog(actionName = "Get Approval Reason", eventCode = "get_approval_reason")
|
||||
@RequestMapping(value = "/app/approval/get_reason", method = RequestMethod.POST, produces = "application/json;charset=UTF-8",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<List<CfgRequestReason>>> getApprovalReason(HttpServletRequest request, @RequestBody Map<String, Object> booking) throws Exception {
|
||||
BaseApiResponse<List<CfgRequestReason>> result = approvalService.getRequestReason();
|
||||
return ResponseEntity.status(HttpStatus.OK).body(result);
|
||||
}
|
||||
|
||||
@OperationLog(actionName = "Get Approver", eventCode = "get_approver")
|
||||
@RequestMapping(value = "/app/approval/get_approver", method = RequestMethod.POST, produces = "application/json;charset=UTF-8",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<ApproverResult>> getESBApprover(HttpServletRequest request, @RequestBody GetApproverRequest params) throws Exception {
|
||||
BaseApiResponse<ApproverResult> result = approvalService.getApprover(request, params);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(result);
|
||||
}
|
||||
|
||||
@PostMapping(value="/app/approval/approval_list",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<List<BookingsView>>> getPendingApprovalBookingList(HttpServletRequest request, @RequestBody Map<String, Object> params) throws Exception {
|
||||
BaseApiResponse<List<BookingsView>> pendingApprovalList = approvalService.getPendingApprovalList(request,params);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(pendingApprovalList);
|
||||
}
|
||||
|
||||
@PostMapping("/app/approval/get_approval_count")
|
||||
public ResponseEntity<BaseApiResponse<Long>> getPendingApprovalCount(HttpServletRequest request) {
|
||||
BaseApiResponse<Long> result = approvalService.getCountPendingApproval(request);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(result);
|
||||
}
|
||||
|
||||
@PostMapping(value="/app/approval/reject_approval",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<RejectApprovalResponse>> rejectApprovalRecord(HttpServletRequest request, @RequestBody Map<String, Object> params) throws Exception {
|
||||
String token = request.getHeader("Authorization");
|
||||
String userId = JWT.decode(token).getClaim("login_id").asString();
|
||||
Long bookingId = params.get("bookingId") == null ? null : Long.valueOf(params.get("bookingId").toString());
|
||||
BaseApiResponse<RejectApprovalResponse> result = approvalService.rejectApprovalBooking(bookingId, userId);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(result);
|
||||
}
|
||||
|
||||
@PostMapping(value="/app/approval/get_approval_data",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<ApprovalDetail>> getApprovalData(HttpServletRequest request, @RequestBody Map<String, Object> params) throws Exception {
|
||||
BaseApiResponse<ApprovalDetail> result = approvalService.getApprovalDetail(request, params);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(result);
|
||||
}
|
||||
|
||||
@PostMapping(value="/app/approval/submit_approval",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<SubmitApprovalResponse>> submitApproval(HttpServletRequest request, @RequestBody Map<String, Object> params) throws Exception {
|
||||
String token = request.getHeader("Authorization");
|
||||
String userId = JWT.decode(token).getClaim("login_id").asString();
|
||||
String checkinDate = params.get("checkinDate") == null ? null : params.get("checkinDate").toString();
|
||||
String checkoutDate = params.get("checkoutDate") == null ? null : params.get("checkoutDate").toString();
|
||||
String bookingId = params.get("bookingId") == null ? null : params.get("bookingId").toString();
|
||||
BaseApiResponse<SubmitApprovalResponse> serviceResult = new BaseApiResponse<>();
|
||||
try{
|
||||
serviceResult = approvalService.submitApproval(bookingId, checkinDate, checkoutDate, userId,request);
|
||||
} catch (Exception e) {
|
||||
approvalService.setFailApprovalRouting(bookingId);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.OK).body(serviceResult);
|
||||
}
|
||||
|
||||
@PostMapping(value="/app/approval/batch_submit_approval",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<List<Map<String, String>>>> batchApproveBooking(HttpServletRequest request, @RequestBody Map<String, Object> params) throws Exception {
|
||||
BaseApiResponse<List<Map<String, String>>> result = approvalService.batchApproval(request, params);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(result);
|
||||
}
|
||||
|
||||
@PostMapping(value="/app/approval/batch_submit_reject",consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<BaseApiResponse<List<String>>> batchRejectApproval(HttpServletRequest request, @RequestBody Map<String, Object> params) throws Exception {
|
||||
|
||||
String token = request.getHeader("Authorization");
|
||||
String userId = JWT.decode(token).getClaim("login_id").asString();
|
||||
// 修改这里:从 submitInfoList 获取数据
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> submitInfoList = params.get("submitInfoList") != null
|
||||
? (List<Map<String, Object>>) params.get("submitInfoList")
|
||||
: null;
|
||||
|
||||
|
||||
BaseApiResponse<List<String>> serviceResult = new BaseApiResponse<>();
|
||||
if (submitInfoList != null && !submitInfoList.isEmpty()) {
|
||||
// 提取 bookingId 列表
|
||||
List<String> bookingIdList = submitInfoList.stream()
|
||||
.map(item -> String.valueOf(item.get("bookingId")))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
serviceResult = approvalService.batchReject(bookingIdList, userId);
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.OK).body(serviceResult);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user