From 4b613344b3b84419f11c88b287d524fb0dd70d5e Mon Sep 17 00:00:00 2001 From: p87sjbg3f <1239676507@qq.com> Date: Fri, 28 Jun 2024 20:22:08 +0800 Subject: [PATCH 1/7] ADD file via upload --- SpringSecurityConfig.java | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 SpringSecurityConfig.java diff --git a/SpringSecurityConfig.java b/SpringSecurityConfig.java new file mode 100644 index 0000000..ceeccef --- /dev/null +++ b/SpringSecurityConfig.java @@ -0,0 +1,82 @@ +package com.qsd.orange.config; + +import com.qsd.orange.security.AccessFailureHandler; +import com.qsd.orange.security.LoginFailureHandler; +import com.qsd.orange.security.LoginSuccessHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +@EnableWebSecurity +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + @Qualifier("userDetailsServiceImpl") + private UserDetailsService userDetailsService; + @Autowired + private LoginSuccessHandler loginSuccessHandler; + @Autowired + private LoginFailureHandler loginFailureHandler; + @Autowired + private AccessFailureHandler accessFailureHandler; + @Autowired + private BCryptPasswordEncoder passwordEncoder; + + //授权规则 + @Override + protected void configure(HttpSecurity http) throws Exception { + //拦截规则 + http.authorizeRequests() + .antMatchers("/user/login").permitAll() + .antMatchers("/login.html").permitAll() + .antMatchers("/image/**").permitAll() + .antMatchers("/system/**").hasRole("1") + .antMatchers("/statistics/**").hasRole("1") + .anyRequest().authenticated(); + + //登录配置 + http.formLogin() + .loginPage("/login.html") + .loginProcessingUrl("/user/login") + .usernameParameter("username") + .passwordParameter("password") + .successHandler(loginSuccessHandler) + .failureHandler(loginFailureHandler); + + //注销配置 + http.logout() + .logoutUrl("/user/logout") + .logoutSuccessUrl("/login.html"); + + //关闭csrf防护 + http.csrf().disable(); + + //配置iframe请求 + http.headers().frameOptions().disable(); + + //处理认证失败请求 + http.exceptionHandling().accessDeniedHandler(accessFailureHandler); + + } + + //认证配置 + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService) + .passwordEncoder(passwordEncoder); + } + + @Bean + public BCryptPasswordEncoder passwordEncoder(){ + return new BCryptPasswordEncoder(); + } + +} From fd24b9232047a5355ff29fe5a3499961b7489d9f Mon Sep 17 00:00:00 2001 From: p87sjbg3f <1239676507@qq.com> Date: Fri, 28 Jun 2024 20:22:26 +0800 Subject: [PATCH 2/7] ADD file via upload --- WebConfig.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 WebConfig.java diff --git a/WebConfig.java b/WebConfig.java new file mode 100644 index 0000000..8c54724 --- /dev/null +++ b/WebConfig.java @@ -0,0 +1,9 @@ +package com.qsd.orange.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + +} From cf82ad88822fc9afcd492a860985e951fb419d0f Mon Sep 17 00:00:00 2001 From: p87sjbg3f <1239676507@qq.com> Date: Fri, 28 Jun 2024 20:22:54 +0800 Subject: [PATCH 3/7] ADD file via upload --- AnnouncementController.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 AnnouncementController.java diff --git a/AnnouncementController.java b/AnnouncementController.java new file mode 100644 index 0000000..819784e --- /dev/null +++ b/AnnouncementController.java @@ -0,0 +1,26 @@ +package com.qsd.orange.controller; + +import com.qsd.orange.service.AnnouncementService; +import com.qsd.orange.global.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("announcement") +public class AnnouncementController { + + @Autowired + private AnnouncementService announcementService; + + @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(announcementService.all(page, limit)); + } + +} From 93cc176101f59951dbb20964d4d02a8058f511d5 Mon Sep 17 00:00:00 2001 From: p87sjbg3f <1239676507@qq.com> Date: Fri, 28 Jun 2024 20:23:45 +0800 Subject: [PATCH 4/7] ADD file via upload --- CarController.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 CarController.java diff --git a/CarController.java b/CarController.java new file mode 100644 index 0000000..0c2e633 --- /dev/null +++ b/CarController.java @@ -0,0 +1,56 @@ +package com.qsd.orange.controller; + +import com.qsd.orange.po.BusCar; +import com.qsd.orange.service.CarService; +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("car") +public class CarController { + + @Autowired + private CarService carService; + + @GetMapping("all") + public R all( + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "limit", required = false, defaultValue = "9") Integer limit, + @RequestParam(value = "status", required = false, defaultValue = "-1")Integer status + ){ + return R.success().page(carService.queryAllCar(page, limit, status)); + } + + @GetMapping("search") + public R search( + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "limit", required = false, defaultValue = "9") Integer limit, + @RequestParam(value = "status", required = false, defaultValue = "-1") Integer status, + @RequestParam(value = "brand", required = false, defaultValue = "") String brand, + @RequestParam(value = "color", required = false, defaultValue = "") String color + ){ + return R.success().page(carService.queryCar(page, limit, status, brand, color)); + } + + @GetMapping("search/number") + public R number( + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "limit", required = false, defaultValue = "9") Integer limit, + @RequestParam(value = "number", required = false, defaultValue = "") String number + ){ + return R.success().page(carService.queryCarByNumber(page, limit, number)); + } + + @PostMapping("add") + public R add(@Valid BusCar car, Authentication authentication){ + User users = (User)authentication.getPrincipal(); + String username = users.getUsername(); + return R.choose(carService.add(username, car) > 0); + } + +} From ee29c4ffb6923e315b7f1b34b41d0b489706d6fe Mon Sep 17 00:00:00 2001 From: p87sjbg3f <1239676507@qq.com> Date: Fri, 28 Jun 2024 20:23:52 +0800 Subject: [PATCH 5/7] ADD file via upload --- CheckController.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 CheckController.java diff --git a/CheckController.java b/CheckController.java new file mode 100644 index 0000000..c567b8d --- /dev/null +++ b/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); + } + +} From a5b0f3c1996914a0e037b5a27f861a880912da11 Mon Sep 17 00:00:00 2001 From: p87sjbg3f <1239676507@qq.com> Date: Fri, 28 Jun 2024 20:24:08 +0800 Subject: [PATCH 6/7] ADD file via upload --- CustomerController.java | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 CustomerController.java diff --git a/CustomerController.java b/CustomerController.java new file mode 100644 index 0000000..8465593 --- /dev/null +++ b/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); + } + +} From b054774e4d1ec339cba5b1a56f480150172f99d4 Mon Sep 17 00:00:00 2001 From: p87sjbg3f <1239676507@qq.com> Date: Fri, 28 Jun 2024 20:24:23 +0800 Subject: [PATCH 7/7] 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); + } + + } + +}