YZQ 5 months ago
parent b45d4fd12e
commit c42a5730a0

@ -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);
}
}

@ -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);
}
}

@ -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<String, Object> 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);
}
}
}

@ -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";
}
}
Loading…
Cancel
Save