From 01cc4fcf66ac7db57eded5048472eeb8435bf11c Mon Sep 17 00:00:00 2001 From: p87sjbg3f <1239676507@qq.com> Date: Fri, 28 Jun 2024 20:27:07 +0800 Subject: [PATCH] ADD file via upload --- RentController.java | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 RentController.java diff --git a/RentController.java b/RentController.java new file mode 100644 index 0000000..61fef3c --- /dev/null +++ b/RentController.java @@ -0,0 +1,97 @@ +package com.qsd.orange.controller; + +import com.qsd.orange.global.HttpResult; +import com.qsd.orange.global.R; +import com.qsd.orange.service.RentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.userdetails.User; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; +@RestController +@RequestMapping("rent") +public class RentController { + + @Autowired + private RentService rentService; + + @PostMapping("add") + public R add(String identity, String number, String returnTime, Authentication authentication){ + User users = (User)authentication.getPrincipal(); + String username = users.getUsername(); + int add = rentService.add(identity, number, returnTime, username); + switch (add){ + case -1: + return R.error(HttpResult.CAR_IS_RENTING); + case 0: + return R.error(HttpResult.USER_INFO_ERROR); + case 1: + return R.success(); + default: + return R.error(HttpResult.SERVER_ERROR); + } + } + + @GetMapping("all") + public R all( + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "limit", required = false, defaultValue = "9") Integer limit + ){ + return R.success().page(rentService.all(page, limit)); + } + + @GetMapping("search") + public R search( + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "limit", required = false, defaultValue = "9") Integer limit, + String keyword, + Integer type + ){ + switch (type){ + case 0: + return R.success().page(rentService.search(page, limit, "id", keyword)); + case 1: + return R.success().page(rentService.search(page, limit, "customer_identity", keyword)); + case 2: + return R.success().page(rentService.search(page, limit, "car_number", keyword)); + default: + return R.error(HttpResult.PARAM_ERROR); + } + } + + @PostMapping("update/returnTime") + public R update(String id, String returnTime){ + int i = rentService.updateReturnTime(id, returnTime); + switch (i){ + case -3: + return R.error(HttpResult.PARAM_ERROR); + case -2: + case -1: + return R.error(HttpResult.DATE_ERROR); + case 0: + return R.error(HttpResult.NOT_FOUND); + case 1: + return R.success(); + default: + return R.error(HttpResult.SERVER_ERROR); + } + } + + @GetMapping("info") + public R info(String id){ + Map info = rentService.info(id); + int status = (Integer) info.get("status"); + info.remove("status"); + switch (status){ + case -1: + return R.error(HttpResult.CAR_IS_RETURN); + case 0: + return R.error(HttpResult.NOT_FOUND); + default: + return R.success().data(info); + } + + } + +}