mirror of
				https://github.com/FreeeBird/hotel.git
				synced 2025-10-30 12:04:49 +08:00 
			
		
		
		
	更新数据库结构,重写接口
This commit is contained in:
		| @@ -1,10 +1,7 @@ | ||||
| package cn.mafangui.hotel.controller; | ||||
|  | ||||
| import cn.mafangui.hotel.entity.Room; | ||||
| import cn.mafangui.hotel.entity.RoomType; | ||||
| import cn.mafangui.hotel.entity.Worker; | ||||
| import cn.mafangui.hotel.service.RoomService; | ||||
| import cn.mafangui.hotel.service.RoomTypeService; | ||||
| import cn.mafangui.hotel.service.WorkerService; | ||||
| import cn.mafangui.hotel.utils.StaticString; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -20,8 +17,6 @@ public class AdminController { | ||||
|  | ||||
|     @Autowired | ||||
|     private WorkerService workerService; | ||||
|     @Autowired | ||||
|     private RoomService roomService; | ||||
|  | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -4,6 +4,7 @@ import cn.mafangui.hotel.entity.Order; | ||||
| 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; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
|  | ||||
| @@ -17,9 +18,10 @@ public class OrderController { | ||||
|     private OrderService orderService; | ||||
|  | ||||
|     @RequestMapping(value = "/add") | ||||
|     public int addOrder(String orderType,int userId, String phone, String roomType, | ||||
|                         Integer numOfRoom, Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost){ | ||||
|     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); | ||||
|     } | ||||
|  | ||||
| @@ -44,6 +46,23 @@ public class OrderController { | ||||
|         return orderService.update(order); | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(value = "/cancel") | ||||
|     public int cancelOrder(int orderId){ | ||||
|         Order order = new Order(); | ||||
|         order.setOrderId(orderId); | ||||
|         order.setOrderStatus(StaticString.WAS_CANCELED); | ||||
|         return orderService.update(order); | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(value = "/overtime") | ||||
|     public int orderOver(int orderId){ | ||||
|         Order order = new Order(); | ||||
|         order.setOrderId(orderId); | ||||
|         order.setOrderStatus(StaticString.OVERTIME); | ||||
|         return orderService.update(order); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     @RequestMapping(value = "/all") | ||||
|     public List<Order> getAllOrder(){ | ||||
|         return orderService.selectAll(); | ||||
| @@ -54,6 +73,11 @@ public class OrderController { | ||||
|         return orderService.selectByUserId(userId); | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(value = "/userOrder") | ||||
|     public List<Order> getAllByUser(int userId){ | ||||
|         return orderService.userSelectAll(userId); | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(value = "/withId") | ||||
|     public Order getById(int orderId){ | ||||
|         return orderService.selectById(orderId); | ||||
|   | ||||
| @@ -127,6 +127,18 @@ public class UserController { | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(method = RequestMethod.POST,value = "/withUsername") | ||||
|     public User getByUsername(String username){ | ||||
|         User user = userService.selectByUsername(username); | ||||
|         user.setPassword(null); | ||||
|         return user; | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(method = RequestMethod.POST,value = "/withId") | ||||
|     public User getById(int userId){ | ||||
|         return userService.selectById(userId); | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(value = "/delete") | ||||
|     public int deleteUser(int userId){ | ||||
|         return userService.deleteUser(userId); | ||||
|   | ||||
| @@ -9,11 +9,20 @@ public class Order { | ||||
|  | ||||
|     private int userId; | ||||
|  | ||||
|     private String name; | ||||
|  | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     private String phone; | ||||
|  | ||||
|     private String roomType; | ||||
|  | ||||
|  | ||||
|     private Date orderDate; | ||||
|  | ||||
|     private Integer orderDays; | ||||
| @@ -136,6 +145,15 @@ public class Order { | ||||
|         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() { | ||||
|   | ||||
| @@ -1,7 +1,10 @@ | ||||
| package cn.mafangui.hotel.entity; | ||||
|  | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| @Component | ||||
| public class Worker { | ||||
|     private Integer workerId; | ||||
|  | ||||
|   | ||||
| @@ -23,5 +23,7 @@ public interface OrderMapper { | ||||
|  | ||||
|     List<Order> selectAll(); | ||||
|  | ||||
|     List<Order> userSelectAll(int userId); | ||||
|  | ||||
|  | ||||
| } | ||||
| @@ -17,4 +17,6 @@ public interface OrderService { | ||||
|     List<Order> selectByUserId(int userId); | ||||
|  | ||||
|     List<Order> selectAll(); | ||||
|  | ||||
|     List<Order> userSelectAll(int userId); | ||||
| } | ||||
|   | ||||
| @@ -43,4 +43,9 @@ public class OrderServiceImpl implements OrderService { | ||||
|     public List<Order> selectAll() { | ||||
|         return orderMapper.selectAll(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<Order> userSelectAll(int userId) { | ||||
|         return orderMapper.userSelectAll(userId); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -24,19 +24,20 @@ public class StaticString { | ||||
|     public static final int IN_USE = 3; | ||||
|     /** | ||||
|      * 订单状态 | ||||
|      * 被用户删除-2 | ||||
|      * 被用户删除-3 | ||||
|      * 超时 -2 | ||||
|      * 被取消-1 | ||||
|      * 未付款0 | ||||
|      * 已付款1 | ||||
|      * 已入住2 | ||||
|      * 超时3 | ||||
|      * | ||||
|      */ | ||||
|     public static final int WAS_DELETE = -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; | ||||
|     public static final int OVERTIME = 3; | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
							
								
								
									
										14
									
								
								src/main/resources/application-dev.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/main/resources/application-dev.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| server: | ||||
|   port: 8080 | ||||
|   servlet: | ||||
|     context-path: "/hotel" | ||||
| spring: | ||||
|   datasource: | ||||
|     driver-class-name: com.mysql.jdbc.Driver | ||||
|     username: root | ||||
|     password: root | ||||
|     url: jdbc:mysql://127.0.0.1:3306/hotel?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull | ||||
| mybatis: | ||||
|   type-aliases-package: classpath*:cn.mafangui.hotel.entity | ||||
|   mapper-locations: classpath*:mybatis/mapper/*.xml | ||||
|  | ||||
| @@ -7,7 +7,7 @@ spring: | ||||
|     driver-class-name: com.mysql.jdbc.Driver | ||||
|     username: root | ||||
|     password: root | ||||
|     url: jdbc:mysql://127.0.0.1:3306/hotel?useUnicode=true&characterEncoding=UTF-8 | ||||
|     url: jdbc:mysql://127.0.0.1:3306/hotel?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull | ||||
| mybatis: | ||||
|   type-aliases-package: classpath*:cn.mafangui.hotel.entity | ||||
|   mapper-locations: classpath*:mybatis/mapper/*.xml | ||||
|   | ||||
| @@ -5,6 +5,7 @@ | ||||
|     <id column="order_id" jdbcType="INTEGER" property="orderId" /> | ||||
|     <result column="order_type" jdbcType="VARCHAR" property="orderType" /> | ||||
|     <result column="user_id" jdbcType="INTEGER" property="userId" /> | ||||
|     <result column="name" jdbcType="VARCHAR" property="name" /> | ||||
|     <result column="phone" jdbcType="VARCHAR" property="phone" /> | ||||
|     <result column="room_type" jdbcType="VARCHAR" property="roomType" /> | ||||
|     <result column="order_date" jdbcType="DATE" property="orderDate" /> | ||||
| @@ -15,7 +16,7 @@ | ||||
|     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> | ||||
|   </resultMap> | ||||
|   <sql id="Base_Column_List"> | ||||
|     order_id, order_type, user_id, phone, room_type,  order_date, order_days, order_status, | ||||
|     order_id, order_type, user_id, name,phone, room_type,  order_date, order_days, order_status, | ||||
|     order_cost, create_time, update_time | ||||
|   </sql> | ||||
|   <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | ||||
| @@ -35,17 +36,24 @@ | ||||
|     <include refid="Base_Column_List" /> | ||||
|     from order_info | ||||
|   </select> | ||||
|   <select id="userSelectAll" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | ||||
|         select | ||||
|         * | ||||
|         from order_info | ||||
|         where order_status >= -2 and user_id = #{userId,jdbcType=VARCHAR} | ||||
|   </select> | ||||
|   <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> | ||||
|     delete from order_info | ||||
|     where order_id = #{orderId,jdbcType=INTEGER} | ||||
|   </delete> | ||||
|   <insert id="insert" parameterType="cn.mafangui.hotel.entity.Order"> | ||||
|     insert into order_info (order_id, order_type, phone,  | ||||
|       room_type, num_of_room, order_date,  | ||||
|     insert into order_info (order_id, order_type,name, phone, | ||||
|       room_type, order_date, | ||||
|       order_days, order_status, order_cost, | ||||
|       create_time, update_time) | ||||
|     values (#{orderId,jdbcType=INTEGER}, #{orderType,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},  | ||||
|       #{roomType,jdbcType=VARCHAR}, #{numOfRoom,jdbcType=INTEGER}, #{orderDate,jdbcType=DATE},  | ||||
|     values (#{orderId,jdbcType=INTEGER}, #{orderType,jdbcType=VARCHAR}, | ||||
|      #{name,jdbcType=VARCHAR},#{phone,jdbcType=VARCHAR}, | ||||
|       #{roomType,jdbcType=VARCHAR},#{orderDate,jdbcType=DATE}, | ||||
|       #{orderDays,jdbcType=INTEGER}, #{orderStatus,jdbcType=INTEGER}, #{orderCost,jdbcType=DOUBLE}, | ||||
|       #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}) | ||||
|   </insert> | ||||
| @@ -58,15 +66,18 @@ | ||||
|       <if test="orderType != null"> | ||||
|         order_type, | ||||
|       </if> | ||||
|       <if test="userId != null"> | ||||
|         user_id, | ||||
|       </if> | ||||
|       <if test="name != null"> | ||||
|           name, | ||||
|       </if> | ||||
|       <if test="phone != null"> | ||||
|         phone, | ||||
|       </if> | ||||
|       <if test="roomType != null"> | ||||
|         room_type, | ||||
|       </if> | ||||
|       <if test="numOfRoom != null"> | ||||
|         num_of_room, | ||||
|       </if> | ||||
|       <if test="orderDate != null"> | ||||
|         order_date, | ||||
|       </if> | ||||
| @@ -89,15 +100,18 @@ | ||||
|       <if test="orderType != null"> | ||||
|         #{orderType,jdbcType=VARCHAR}, | ||||
|       </if> | ||||
|       <if test="userId != null"> | ||||
|         #{userId,jdbcType=INTEGER}, | ||||
|       </if> | ||||
|       <if test="name != null"> | ||||
|          #{name,jdbcType=VARCHAR}, | ||||
|       </if> | ||||
|       <if test="phone != null"> | ||||
|         #{phone,jdbcType=VARCHAR}, | ||||
|       </if> | ||||
|       <if test="roomType != null"> | ||||
|         #{roomType,jdbcType=VARCHAR}, | ||||
|       </if> | ||||
|       <if test="numOfRoom != null"> | ||||
|         #{numOfRoom,jdbcType=INTEGER}, | ||||
|       </if> | ||||
|       <if test="orderDate != null"> | ||||
|         #{orderDate,jdbcType=DATE}, | ||||
|       </if> | ||||
| @@ -120,15 +134,15 @@ | ||||
|       <if test="orderType != null"> | ||||
|         order_type = #{orderType,jdbcType=VARCHAR}, | ||||
|       </if> | ||||
|       <if test="name != null"> | ||||
|         name =  #{name,jdbcType=VARCHAR} | ||||
|       </if> | ||||
|       <if test="phone != null"> | ||||
|         phone = #{phone,jdbcType=VARCHAR}, | ||||
|       </if> | ||||
|       <if test="roomType != null"> | ||||
|         room_type = #{roomType,jdbcType=VARCHAR}, | ||||
|       </if> | ||||
|       <if test="numOfRoom != null"> | ||||
|         num_of_room = #{numOfRoom,jdbcType=INTEGER}, | ||||
|       </if> | ||||
|       <if test="orderDate != null"> | ||||
|         order_date = #{orderDate,jdbcType=DATE}, | ||||
|       </if> | ||||
| @@ -148,9 +162,9 @@ | ||||
|   <update id="updateByPrimaryKey" parameterType="cn.mafangui.hotel.entity.Order"> | ||||
|     update order_info | ||||
|     set order_type = #{orderType,jdbcType=VARCHAR}, | ||||
|       name = #{name,jdbcType=VARCHAR}, | ||||
|       phone = #{phone,jdbcType=VARCHAR}, | ||||
|       room_type = #{roomType,jdbcType=VARCHAR}, | ||||
|       num_of_room = #{numOfRoom,jdbcType=INTEGER}, | ||||
|       order_date = #{orderDate,jdbcType=DATE}, | ||||
|       order_days = #{orderDays,jdbcType=INTEGER}, | ||||
|       order_status = #{orderStatus,jdbcType=INTEGER}, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user