更新数据库结构,重写订单接口,添加注释

This commit is contained in:
freeebird
2018-11-28 15:18:17 +08:00
parent 346dca6e65
commit 556e257d45
19 changed files with 554 additions and 245 deletions

View File

@@ -1,6 +1,5 @@
package cn.mafangui.hotel;
import cn.mafangui.hotel.utils.StaticString;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@@ -1,16 +1,13 @@
package cn.mafangui.hotel.controller;
import cn.mafangui.hotel.entity.Worker;
import cn.mafangui.hotel.service.RoomService;
import cn.mafangui.hotel.enums.Role;
import cn.mafangui.hotel.service.WorkerService;
import cn.mafangui.hotel.utils.StaticString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(value = "/admin")
public class AdminController {
@@ -27,11 +24,34 @@ public class AdminController {
*/
@RequestMapping(method = RequestMethod.POST,value = "/login")
public int login(String username,String password){
if(workerService.login(username,password, StaticString.ADMIN) != null)
if(workerService.login(username,password, Role.ADMIN.getValue()) != null)
return 1;
else return 0;
}
/**
* 管理员注册
* @param username
* @param password
* @param name
* @param gender
* @param phone
* @param email
* @param address
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/register")
public int register(String username,String password,String name,String gender,String phone,String email,String address){
Worker worker = new Worker(username,password,name,gender,phone,email,address);
worker.setRole(Role.ADMIN.getValue());
return workerService.insert(worker);
}
/**
* 根据 username查找
* @param username
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/withUsername")
public Worker getByUsername(String username) {
Worker res = workerService.selectByUsername(username);

View File

@@ -1,8 +1,8 @@
package cn.mafangui.hotel.controller;
import cn.mafangui.hotel.entity.Worker;
import cn.mafangui.hotel.enums.Role;
import cn.mafangui.hotel.service.WorkerService;
import cn.mafangui.hotel.utils.StaticString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -18,7 +18,7 @@ public class OperatorController {
@RequestMapping(method = RequestMethod.POST,value = "/login")
public int login(String username,String password){
if(workerService.login(username,password, StaticString.OPERATOR) != null)
if(workerService.login(username,password, Role.OPERATOR.getValue()) != null)
return 1;
else return 0;
}
@@ -30,7 +30,7 @@ public class OperatorController {
@RequestMapping(value = "/all")
public List<Worker> getAllOperator(){
return workerService.selectByRole(StaticString.OPERATOR);
return workerService.selectByRole(Role.OPERATOR.getValue());
}
@RequestMapping(method = RequestMethod.POST,value = "/withId")
@@ -41,7 +41,7 @@ public class OperatorController {
@RequestMapping(method = RequestMethod.POST,value = "/add")
public int addOperator(String username,String password,String name,String gender,String phone,String email,String address){
Worker worker = new Worker(username,password,name,gender,phone,email,address);
worker.setRole(StaticString.OPERATOR);
worker.setRole(Role.OPERATOR.getValue());
return workerService.insert(worker);
}

View File

@@ -1,8 +1,8 @@
package cn.mafangui.hotel.controller;
import cn.mafangui.hotel.entity.Order;
import cn.mafangui.hotel.enums.OrderStatus;
import cn.mafangui.hotel.service.OrderService;
import cn.mafangui.hotel.utils.StaticString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -11,73 +11,139 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
/**
* 订单接口
*/
@RestController
@RequestMapping(value = "/order")
public class OrderController {
@Autowired
private OrderService orderService;
/**
* 添加预订
* 订单状态默认为未付款状态
* @param orderTypeId
* @param orderType
* @param userId
* @param name
* @param phone
* @param roomTypeId
* @param roomType
* @param orderDate
* @param orderDays
* @param orderCost
* @return
*/
@RequestMapping(value = "/add")
public int addOrder(String orderType, int userId,String name, String phone, String roomType,
@DateTimeFormat(pattern = "yyyy-MM-dd") Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost){
Order order = new Order(orderType,userId,phone,roomType,orderDate,orderDays,orderStatus,orderCost);
order.setName(name);
return orderService.insert(order);
public int addOrder(int orderTypeId,String orderType, int userId,String name, String phone,int roomTypeId, String roomType,
@DateTimeFormat(pattern = "yyyy-MM-dd") Date orderDate, Integer orderDays, Double orderCost){
Order order = new Order(orderTypeId,orderType,userId,name,phone,roomTypeId,
roomType,orderDate,orderDays, OrderStatus.UNPAID.getCode(),orderCost);
return orderService.addOrder(order);
}
/**
* 删除订单
* @param orderId
* @return
*/
@RequestMapping(value = "/delete")
public int deleteOrder(int orderId){
return orderService.delete(orderId);
}
@RequestMapping(value = "/hide")
public int hideOrder(int orderId){
Order order = new Order();
order.setOrderId(orderId);
order.setOrderStatus(StaticString.WAS_DELETE);
/**
* 客户删除订单
* @param orderId
* @return
*/
@RequestMapping(value = "/deleteByUser")
public int deleteOrderByUser(int orderId){
Order order = new Order(orderId,OrderStatus.WAS_DELETED.getCode());
return orderService.update(order);
}
/**
* 修改订单
* @param orderId
* @param orderTypeId
* @param orderType
* @param userId
* @param name
* @param phone
* @param roomTypeId
* @param roomType
* @param orderDate
* @param orderDays
* @param orderCost
* @return
*/
@RequestMapping(value = "/update")
public int updateOrder(int orderId,String orderType,String roomType,
Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost){
Order order = new Order(orderType,roomType,orderDate,orderDays,orderStatus,orderCost);
order.setOrderId(orderId);
public int updateOrder(int orderId,int orderTypeId,String orderType, int userId,String name, String phone,int roomTypeId, String roomType,
@DateTimeFormat(pattern = "yyyy-MM-dd") Date orderDate, Integer orderDays, Double orderCost){
Order order = new Order(orderTypeId,orderType,userId,name,phone,roomTypeId,
roomType,orderDate,orderDays, OrderStatus.UNPAID.getCode(),orderCost);
return orderService.update(order);
}
/**
* 取消订单
* @param orderId
* @return
*/
@RequestMapping(value = "/cancel")
public int cancelOrder(int orderId){
Order order = new Order();
order.setOrderId(orderId);
order.setOrderStatus(StaticString.WAS_CANCELED);
Order order = new Order(orderId,OrderStatus.WAS_CANCELED.getCode());
return orderService.update(order);
}
/**
* 订单超时
* @param orderId
* @return
*/
@RequestMapping(value = "/overtime")
public int orderOver(int orderId){
Order order = new Order();
order.setOrderId(orderId);
order.setOrderStatus(StaticString.OVERTIME);
Order order = new Order(orderId,OrderStatus.OVERTIME.getCode());
return orderService.update(order);
}
/**
* 所有订单
* @return
*/
@RequestMapping(value = "/all")
public List<Order> getAllOrder(){
return orderService.selectAll();
return orderService.AllOrders();
}
/**
* 根据userID查询所有订单
* @param userId
* @return
*/
@RequestMapping(value = "/withUserId")
public List<Order> getByUser(int userId){
return orderService.selectByUserId(userId);
}
/**
* 客户查询个人所有订单(不包括被自己删除的)
* @param userId
* @return
*/
@RequestMapping(value = "/userOrder")
public List<Order> getAllByUser(int userId){
return orderService.userSelectAll(userId);
return orderService.UsersAllOrders(userId);
}
/**
* 根据订单号查询订单
* @param orderId
* @return
*/
@RequestMapping(value = "/withId")
public Order getById(int orderId){
return orderService.selectById(orderId);

View File

@@ -1,7 +1,9 @@
package cn.mafangui.hotel.controller;
import cn.mafangui.hotel.entity.Room;
import cn.mafangui.hotel.entity.RoomType;
import cn.mafangui.hotel.service.RoomService;
import cn.mafangui.hotel.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -15,11 +17,18 @@ public class RoomController {
@Autowired
private RoomService roomService;
@Autowired
private RoomTypeService roomTypeService;
@RequestMapping(value = "/add")
public int addRoom(String roomNumber,int typeId,String roomType,double roomPrice,double roomDiscount,int roomStatus,String remark){
Room room = new Room(roomNumber,typeId,roomType,roomPrice,roomDiscount,roomStatus,remark);
return roomService.insert(room);
RoomType rt = new RoomType();
if (roomService.insert(room) == 1){
rt.setTypeId(typeId);
rt.setRest(roomTypeService.selectById(typeId).getRest() + 1);
return roomTypeService.update(rt);
}else return 0;
}
@RequestMapping(method = RequestMethod.POST,value = "/delete")
@@ -54,4 +63,10 @@ public class RoomController {
public List<Room> getAll(){
return roomService.selectAll();
}
}
@RequestMapping(value = "/typeRest")
public int countTypeRest(){
return 0;
}
}

View File

@@ -32,6 +32,7 @@ public class RoomTypeController {
public int addRoomType(String roomType,Double price,Double discount,int area,
int bedNum,String bedSize,int window,String remark){
RoomType rt = new RoomType(roomType,remark,price,discount,area,bedNum,bedSize,window);
rt.setRest(0);
int result = 0;
result = roomTypeService.insert(rt);
return result;
@@ -39,9 +40,10 @@ public class RoomTypeController {
@RequestMapping(method = RequestMethod.POST,value = "/update")
public int updateRoomType(int typeId,String roomType,Double price,Double discount,int area,
int bedNum,String bedSize,int window,String remark){
int bedNum,String bedSize,int window,int rest,String remark){
RoomType rt = new RoomType(roomType,remark,price,discount,area,bedNum,bedSize,window);
rt.setTypeId(typeId);
rt.setRest(rest);
int result = 0;
result = roomTypeService.update(rt);
return result;

View File

@@ -5,22 +5,18 @@ import java.util.Date;
public class Order {
private Integer orderId;
private Integer orderTypeId;
private String orderType;
private int userId;
private Integer userId;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private String phone;
private Integer roomTypeId;
private String roomType;
private Date orderDate;
@@ -35,14 +31,6 @@ public class Order {
private Date updateTime;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public Integer getOrderId() {
return orderId;
}
@@ -51,6 +39,14 @@ public class Order {
this.orderId = orderId;
}
public Integer getOrderTypeId() {
return orderTypeId;
}
public void setOrderTypeId(Integer orderTypeId) {
this.orderTypeId = orderTypeId;
}
public String getOrderType() {
return orderType;
}
@@ -59,6 +55,22 @@ public class Order {
this.orderType = orderType == null ? null : orderType.trim();
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getPhone() {
return phone;
}
@@ -67,6 +79,14 @@ public class Order {
this.phone = phone == null ? null : phone.trim();
}
public Integer getRoomTypeId() {
return roomTypeId;
}
public void setRoomTypeId(Integer roomTypeId) {
this.roomTypeId = roomTypeId;
}
public String getRoomType() {
return roomType;
}
@@ -126,10 +146,13 @@ public class Order {
public Order() {
}
public Order(String orderType, int userId, String phone, String roomType, Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost) {
public Order(Integer orderTypeId, String orderType, Integer userId, String name, String phone, Integer roomTypeId, String roomType, Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost) {
this.orderTypeId = orderTypeId;
this.orderType = orderType;
this.userId = userId;
this.name = name;
this.phone = phone;
this.roomTypeId = roomTypeId;
this.roomType = roomType;
this.orderDate = orderDate;
this.orderDays = orderDays;
@@ -137,31 +160,22 @@ public class Order {
this.orderCost = orderCost;
}
public Order(String orderType, String roomType, Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost) {
this.orderType = orderType;
this.roomType = roomType;
this.orderDate = orderDate;
this.orderDays = orderDays;
public Order(Integer orderId, Integer orderStatus) {
this.orderId = orderId;
this.orderStatus = orderStatus;
this.orderCost = orderCost;
}
public Order(String orderType, int userId, String phone,String roomType,Integer orderDays, Integer orderStatus, Double orderCost) {
this.userId = userId;
this.phone = phone;
this.orderType = orderType;
this.roomType = roomType;
this.orderDays = orderDays;
this.orderStatus = orderStatus;
this.orderCost = orderCost;
}
@Override
public String toString() {
return "Order{" +
"orderId=" + orderId +
", orderTypeId=" + orderTypeId +
", orderType='" + orderType + '\'' +
", userId=" + userId +
", name='" + name + '\'' +
", phone='" + phone + '\'' +
", roomTypeId=" + roomTypeId +
", roomType='" + roomType + '\'' +
", orderDate=" + orderDate +
", orderDays=" + orderDays +

View File

@@ -21,6 +21,16 @@ public class RoomType {
private Integer window;
private Integer rest;
public Integer getRest() {
return rest;
}
public void setRest(Integer rest) {
this.rest = rest;
}
private Date createTime;
private Date updateTime;
@@ -114,6 +124,7 @@ public class RoomType {
}
public RoomType() {
this.rest = 0;
}
public RoomType(String roomType, String remark, Double price, Double discount, Integer area, Integer bedNum, String bedSize, Integer window) {
@@ -143,4 +154,4 @@ public class RoomType {
", updateTime=" + updateTime +
'}';
}
}
}

View File

@@ -0,0 +1,33 @@
package cn.mafangui.hotel.enums;
public enum OrderStatus {
WAS_DELETED(-3,"已删除"),
OVERTIME(-2,"支付超时"),
WAS_CANCELED(-1,"已取消"),
UNPAID(0,"未付款"),
PAID(1,"待入住"),
CHECK_IN(2,"已入住")
;
private int code;
private String status;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
OrderStatus(int code, String status) {
}
}

View File

@@ -0,0 +1,30 @@
package cn.mafangui.hotel.enums;
public enum Role {
ADMIN("admin","管理员"),
OPERATOR("operator","操作员")
;
private String value;
private String role;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
Role(String value, String role) {
}
}

View File

@@ -0,0 +1,31 @@
package cn.mafangui.hotel.enums;
public enum RoomStatus {
UNAVAILABLE(0,"不可用"),
AVAILABLE(1,"空闲"),
ORDERED(2,"被预订"),
IN_USE(3,"已入住")
;
private int code;
private String status;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
RoomStatus(int code,String status) {
}
}

View File

@@ -1,11 +1,7 @@
package cn.mafangui.hotel.mapper;
import cn.mafangui.hotel.entity.Order;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface OrderMapper {
int deleteByPrimaryKey(Integer orderId);
@@ -18,12 +14,4 @@ public interface OrderMapper {
int updateByPrimaryKeySelective(Order record);
int updateByPrimaryKey(Order record);
List<Order> selectByUserId(int userId);
List<Order> selectAll();
List<Order> userSelectAll(int userId);
}
}

View File

@@ -8,6 +8,8 @@ public interface OrderService {
int insert(Order order);
int addOrder(Order order);
int delete(Integer orderId);
Order selectById(Integer orderId);
@@ -16,7 +18,7 @@ public interface OrderService {
List<Order> selectByUserId(int userId);
List<Order> selectAll();
List<Order> AllOrders();
List<Order> userSelectAll(int userId);
List<Order> UsersAllOrders(int userId);
}

View File

@@ -1,17 +0,0 @@
package cn.mafangui.hotel.utils;
public class RoomStaticUtil {
public static final int UNAVAILABLE = 0;
public static final int AVAILABLE = 1;
public static final int OCCUPIED = 2;
public static final int IN_USE = 3;
public static final String[] STATUS = {"UNAVAILABLE","AVAILABLE","OCCUPIED","IN_USE",};
public RoomStaticUtil(){
}
public static String getRoomStatic(){
return null;
}
}

View File

@@ -1,43 +0,0 @@
package cn.mafangui.hotel.utils;
public class StaticString {
public static final String CODE = "code";
public static final String STATUS = "status";
public static final String DATA = "data";
/**
* 工作人员角色
*/
public static final String ADMIN = "admin";
public static final String OPERATOR = "operator";
/**
* 房间状态
* 不可用
* 空闲可用
* 已被预订
* 已被入住
*/
public static final int UNAVAILABLE = 0;
public static final int AVAILABLE = 1;
public static final int OCCUPIED = 2;
public static final int IN_USE = 3;
/**
* 订单状态
* 被用户删除-3
* 超时 -2
* 被取消-1
* 未付款0
* 已付款1
* 已入住2
*
*/
public static final int WAS_DELETE = -3;
public static final int OVERTIME = -2;
public static final int WAS_CANCELED = -1;
public static final int UNPAID = 0;
public static final int PAID = 1;
public static final int WAS_USED = 2;
}