更新数据库结构,重写接口

This commit is contained in:
freeebird 2018-11-26 18:20:22 +08:00
parent ab33c31665
commit 346dca6e65
12 changed files with 125 additions and 35 deletions

View File

@ -1,10 +1,7 @@
package cn.mafangui.hotel.controller; 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.entity.Worker;
import cn.mafangui.hotel.service.RoomService; import cn.mafangui.hotel.service.RoomService;
import cn.mafangui.hotel.service.RoomTypeService;
import cn.mafangui.hotel.service.WorkerService; import cn.mafangui.hotel.service.WorkerService;
import cn.mafangui.hotel.utils.StaticString; import cn.mafangui.hotel.utils.StaticString;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -20,8 +17,6 @@ public class AdminController {
@Autowired @Autowired
private WorkerService workerService; private WorkerService workerService;
@Autowired
private RoomService roomService;
/** /**

View File

@ -4,6 +4,7 @@ import cn.mafangui.hotel.entity.Order;
import cn.mafangui.hotel.service.OrderService; import cn.mafangui.hotel.service.OrderService;
import cn.mafangui.hotel.utils.StaticString; import cn.mafangui.hotel.utils.StaticString;
import org.springframework.beans.factory.annotation.Autowired; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -17,9 +18,10 @@ public class OrderController {
private OrderService orderService; private OrderService orderService;
@RequestMapping(value = "/add") @RequestMapping(value = "/add")
public int addOrder(String orderType,int userId, String phone, String roomType, public int addOrder(String orderType, int userId,String name, String phone, String roomType,
Integer numOfRoom, Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost){ @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 order = new Order(orderType,userId,phone,roomType,orderDate,orderDays,orderStatus,orderCost);
order.setName(name);
return orderService.insert(order); return orderService.insert(order);
} }
@ -44,6 +46,23 @@ public class OrderController {
return orderService.update(order); 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") @RequestMapping(value = "/all")
public List<Order> getAllOrder(){ public List<Order> getAllOrder(){
return orderService.selectAll(); return orderService.selectAll();
@ -54,6 +73,11 @@ public class OrderController {
return orderService.selectByUserId(userId); return orderService.selectByUserId(userId);
} }
@RequestMapping(value = "/userOrder")
public List<Order> getAllByUser(int userId){
return orderService.userSelectAll(userId);
}
@RequestMapping(value = "/withId") @RequestMapping(value = "/withId")
public Order getById(int orderId){ public Order getById(int orderId){
return orderService.selectById(orderId); return orderService.selectById(orderId);

View File

@ -127,6 +127,18 @@ public class UserController {
return result; 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") @RequestMapping(value = "/delete")
public int deleteUser(int userId){ public int deleteUser(int userId){
return userService.deleteUser(userId); return userService.deleteUser(userId);

View File

@ -9,11 +9,20 @@ public class Order {
private int userId; private int userId;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private String phone; private String phone;
private String roomType; private String roomType;
private Date orderDate; private Date orderDate;
private Integer orderDays; private Integer orderDays;
@ -136,6 +145,15 @@ public class Order {
this.orderStatus = orderStatus; this.orderStatus = orderStatus;
this.orderCost = orderCost; 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 @Override
public String toString() { public String toString() {

View File

@ -1,7 +1,10 @@
package cn.mafangui.hotel.entity; package cn.mafangui.hotel.entity;
import org.springframework.stereotype.Component;
import java.util.Date; import java.util.Date;
@Component
public class Worker { public class Worker {
private Integer workerId; private Integer workerId;

View File

@ -23,5 +23,7 @@ public interface OrderMapper {
List<Order> selectAll(); List<Order> selectAll();
List<Order> userSelectAll(int userId);
} }

View File

@ -17,4 +17,6 @@ public interface OrderService {
List<Order> selectByUserId(int userId); List<Order> selectByUserId(int userId);
List<Order> selectAll(); List<Order> selectAll();
List<Order> userSelectAll(int userId);
} }

View File

@ -43,4 +43,9 @@ public class OrderServiceImpl implements OrderService {
public List<Order> selectAll() { public List<Order> selectAll() {
return orderMapper.selectAll(); return orderMapper.selectAll();
} }
@Override
public List<Order> userSelectAll(int userId) {
return orderMapper.userSelectAll(userId);
}
} }

View File

@ -24,19 +24,20 @@ public class StaticString {
public static final int IN_USE = 3; public static final int IN_USE = 3;
/** /**
* 订单状态 * 订单状态
* 被用户删除-2 * 被用户删除-3
* 超时 -2
* 被取消-1 * 被取消-1
* 未付款0 * 未付款0
* 已付款1 * 已付款1
* 已入住2 * 已入住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 WAS_CANCELED = -1;
public static final int UNPAID = 0; public static final int UNPAID = 0;
public static final int PAID = 1; public static final int PAID = 1;
public static final int WAS_USED = 2; public static final int WAS_USED = 2;
public static final int OVERTIME = 3;
} }

View 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

View File

@ -7,7 +7,7 @@ spring:
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
username: root username: root
password: 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: mybatis:
type-aliases-package: classpath*:cn.mafangui.hotel.entity type-aliases-package: classpath*:cn.mafangui.hotel.entity
mapper-locations: classpath*:mybatis/mapper/*.xml mapper-locations: classpath*:mybatis/mapper/*.xml

View File

@ -5,6 +5,7 @@
<id column="order_id" jdbcType="INTEGER" property="orderId" /> <id column="order_id" jdbcType="INTEGER" property="orderId" />
<result column="order_type" jdbcType="VARCHAR" property="orderType" /> <result column="order_type" jdbcType="VARCHAR" property="orderType" />
<result column="user_id" jdbcType="INTEGER" property="userId" /> <result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="phone" jdbcType="VARCHAR" property="phone" /> <result column="phone" jdbcType="VARCHAR" property="phone" />
<result column="room_type" jdbcType="VARCHAR" property="roomType" /> <result column="room_type" jdbcType="VARCHAR" property="roomType" />
<result column="order_date" jdbcType="DATE" property="orderDate" /> <result column="order_date" jdbcType="DATE" property="orderDate" />
@ -15,7 +16,7 @@
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <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 order_cost, create_time, update_time
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
@ -35,17 +36,24 @@
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from order_info from order_info
</select> </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 id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from order_info delete from order_info
where order_id = #{orderId,jdbcType=INTEGER} where order_id = #{orderId,jdbcType=INTEGER}
</delete> </delete>
<insert id="insert" parameterType="cn.mafangui.hotel.entity.Order"> <insert id="insert" parameterType="cn.mafangui.hotel.entity.Order">
insert into order_info (order_id, order_type, phone, insert into order_info (order_id, order_type,name, phone,
room_type, num_of_room, order_date, room_type, order_date,
order_days, order_status, order_cost, order_days, order_status, order_cost,
create_time, update_time) create_time, update_time)
values (#{orderId,jdbcType=INTEGER}, #{orderType,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, values (#{orderId,jdbcType=INTEGER}, #{orderType,jdbcType=VARCHAR},
#{roomType,jdbcType=VARCHAR}, #{numOfRoom,jdbcType=INTEGER}, #{orderDate,jdbcType=DATE}, #{name,jdbcType=VARCHAR},#{phone,jdbcType=VARCHAR},
#{roomType,jdbcType=VARCHAR},#{orderDate,jdbcType=DATE},
#{orderDays,jdbcType=INTEGER}, #{orderStatus,jdbcType=INTEGER}, #{orderCost,jdbcType=DOUBLE}, #{orderDays,jdbcType=INTEGER}, #{orderStatus,jdbcType=INTEGER}, #{orderCost,jdbcType=DOUBLE},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}) #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert> </insert>
@ -58,15 +66,18 @@
<if test="orderType != null"> <if test="orderType != null">
order_type, order_type,
</if> </if>
<if test="userId != null">
user_id,
</if>
<if test="name != null">
name,
</if>
<if test="phone != null"> <if test="phone != null">
phone, phone,
</if> </if>
<if test="roomType != null"> <if test="roomType != null">
room_type, room_type,
</if> </if>
<if test="numOfRoom != null">
num_of_room,
</if>
<if test="orderDate != null"> <if test="orderDate != null">
order_date, order_date,
</if> </if>
@ -89,15 +100,18 @@
<if test="orderType != null"> <if test="orderType != null">
#{orderType,jdbcType=VARCHAR}, #{orderType,jdbcType=VARCHAR},
</if> </if>
<if test="userId != null">
#{userId,jdbcType=INTEGER},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="phone != null"> <if test="phone != null">
#{phone,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
</if> </if>
<if test="roomType != null"> <if test="roomType != null">
#{roomType,jdbcType=VARCHAR}, #{roomType,jdbcType=VARCHAR},
</if> </if>
<if test="numOfRoom != null">
#{numOfRoom,jdbcType=INTEGER},
</if>
<if test="orderDate != null"> <if test="orderDate != null">
#{orderDate,jdbcType=DATE}, #{orderDate,jdbcType=DATE},
</if> </if>
@ -120,15 +134,15 @@
<if test="orderType != null"> <if test="orderType != null">
order_type = #{orderType,jdbcType=VARCHAR}, order_type = #{orderType,jdbcType=VARCHAR},
</if> </if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR}
</if>
<if test="phone != null"> <if test="phone != null">
phone = #{phone,jdbcType=VARCHAR}, phone = #{phone,jdbcType=VARCHAR},
</if> </if>
<if test="roomType != null"> <if test="roomType != null">
room_type = #{roomType,jdbcType=VARCHAR}, room_type = #{roomType,jdbcType=VARCHAR},
</if> </if>
<if test="numOfRoom != null">
num_of_room = #{numOfRoom,jdbcType=INTEGER},
</if>
<if test="orderDate != null"> <if test="orderDate != null">
order_date = #{orderDate,jdbcType=DATE}, order_date = #{orderDate,jdbcType=DATE},
</if> </if>
@ -148,9 +162,9 @@
<update id="updateByPrimaryKey" parameterType="cn.mafangui.hotel.entity.Order"> <update id="updateByPrimaryKey" parameterType="cn.mafangui.hotel.entity.Order">
update order_info update order_info
set order_type = #{orderType,jdbcType=VARCHAR}, set order_type = #{orderType,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR}, phone = #{phone,jdbcType=VARCHAR},
room_type = #{roomType,jdbcType=VARCHAR}, room_type = #{roomType,jdbcType=VARCHAR},
num_of_room = #{numOfRoom,jdbcType=INTEGER},
order_date = #{orderDate,jdbcType=DATE}, order_date = #{orderDate,jdbcType=DATE},
order_days = #{orderDays,jdbcType=INTEGER}, order_days = #{orderDays,jdbcType=INTEGER},
order_status = #{orderStatus,jdbcType=INTEGER}, order_status = #{orderStatus,jdbcType=INTEGER},