From c42a5730a0385e19de08770b2347a952fd054716 Mon Sep 17 00:00:00 2001 From: YZQ <1239676507@qq.com> Date: Fri, 28 Jun 2024 19:33:35 +0800 Subject: [PATCH] 11 --- controller/CheckController.java | 32 ++++++++++ controller/CustomerController.java | 63 +++++++++++++++++++ controller/RentController.java | 97 ++++++++++++++++++++++++++++++ controller/RouteController.java | 35 +++++++++++ 4 files changed, 227 insertions(+) create mode 100644 controller/CheckController.java create mode 100644 controller/CustomerController.java create mode 100644 controller/RentController.java create mode 100644 controller/RouteController.java diff --git a/controller/CheckController.java b/controller/CheckController.java new file mode 100644 index 0000000..e4a9eda --- /dev/null +++ b/controller/CheckController.java @@ -0,0 +1,32 @@ +package com.qsd.orange.controller; + +import com.qsd.orange.service.CheckService; +import com.qsd.orange.global.R; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("check") +public class CheckController { + + @Autowired + private CheckService checkService; + + @PostMapping("add") + public R add( + String id, + @RequestParam(value = "problem", required = false, defaultValue = "无") String problem, + @RequestParam(value = "compensate", required = false, defaultValue = "0") Double compensate, + @RequestParam(value = "description", required = false, defaultValue = "无") String description, + Authentication authentication + ){ + User users = (User)authentication.getPrincipal(); + return R.choose(checkService.add(id, problem, compensate, description, users.getUsername()) > 0); + } + +} diff --git a/controller/CustomerController.java b/controller/CustomerController.java new file mode 100644 index 0000000..0907879 --- /dev/null +++ b/controller/CustomerController.java @@ -0,0 +1,63 @@ +package com.qsd.orange.controller; + +import com.qsd.orange.po.BusCustomer; +import com.qsd.orange.service.CustomerService; +import com.qsd.orange.global.R; +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 javax.validation.Valid; + +@RestController +@RequestMapping("customer") +public class CustomerController { + + @Autowired + private CustomerService customerService; + + @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(customerService.queryCustomers(page, limit)); + } + + @GetMapping("search/identity") + public R searchByIdentity( + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "limit", required = false, defaultValue = "9") Integer limit, + String keyword + ){ + return R.success().page(customerService.queryByCustomer(page, limit, "identity", keyword)); + } + + @GetMapping("search/name") + public R searchByName( + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "limit", required = false, defaultValue = "9") Integer limit, + String keyword + ){ + return R.success().page(customerService.queryByCustomer(page, limit, "name", keyword)); + } + + @GetMapping("search/one/identity") + public R searchOneIdentity(String identity){ + return R.success().data("item", customerService.queryOne(identity)); + } + + @PostMapping("add") + public R add(@Valid BusCustomer customer, Authentication authentication){ + User user = (User)authentication.getPrincipal(); + String username = user.getUsername(); + return R.choose(customerService.addCustomer(username, customer) > 0); + } + + @PostMapping("update") + public R update(@Valid BusCustomer customer){ + return R.choose(customerService.updateCustomer(customer) > 0); + } + +} diff --git a/controller/RentController.java b/controller/RentController.java new file mode 100644 index 0000000..d68a456 --- /dev/null +++ b/controller/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); + } + + } + +} diff --git a/controller/RouteController.java b/controller/RouteController.java new file mode 100644 index 0000000..dcff47f --- /dev/null +++ b/controller/RouteController.java @@ -0,0 +1,35 @@ +package com.qsd.orange.controller; + +import com.qsd.orange.po.SysUser; +import com.qsd.orange.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.userdetails.User; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class RouteController { + + @Autowired + private UserService userService; + + @GetMapping("") + public String index(Model model, Authentication authentication){ + User users = (User)authentication.getPrincipal(); + SysUser user = userService.getInfo(users.getUsername()); + model.addAttribute("name", user.getName()); + model.addAttribute("type", user.getType()); + return "index"; + } + + @GetMapping("self") + public String self(Model model, Authentication authentication){ + User users = (User)authentication.getPrincipal(); + SysUser user = userService.getInfo(users.getUsername()); + model.addAttribute("user", user); + return "self"; + } + +}