删除部门类,修改房间、房型、订单相关接口

This commit is contained in:
freeebird 2018-11-28 18:48:04 +08:00
parent 556e257d45
commit ed0f7f87aa
18 changed files with 189 additions and 198 deletions

View File

@ -5,6 +5,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 跨域
*/
@Configuration
public class GlobalCrosConfig {
@Bean
@ -28,4 +31,4 @@ public class GlobalCrosConfig {
}
};
}
}
}

View File

@ -3,8 +3,10 @@ package cn.mafangui.hotel;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement
@MapperScan(basePackages = "cn.mafangui.hotel.mapper")
public class HotelApplication {

View File

@ -6,6 +6,7 @@ import cn.mafangui.hotel.service.OrderService;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@ -87,6 +88,16 @@ public class OrderController {
return orderService.update(order);
}
/**
* 订单支付
* @param orderId
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/pay")
public int payOrder(int orderId){
return orderService.payOrder(orderId);
}
/**
* 取消订单
* @param orderId

View File

@ -1,55 +0,0 @@
package cn.mafangui.hotel.entity;
import java.util.Date;
public class Department {
private Integer departmentId;
private String departmentName;
private String remark;
private Date createTime;
private Date updateTime;
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName == null ? null : departmentName.trim();
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}

View File

@ -0,0 +1,9 @@
package cn.mafangui.hotel.enums;
public enum OrderError {
NONE(0,"没有空房"),
;
OrderError(int code,String status) {
}
}

View File

@ -1,17 +0,0 @@
package cn.mafangui.hotel.mapper;
import cn.mafangui.hotel.entity.Department;
public interface DepartmentMapper {
int deleteByPrimaryKey(Integer departmentId);
int insert(Department record);
int insertSelective(Department record);
Department selectByPrimaryKey(Integer departmentId);
int updateByPrimaryKeySelective(Department record);
int updateByPrimaryKey(Department record);
}

View File

@ -1,7 +1,11 @@
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);
@ -14,4 +18,12 @@ public interface OrderMapper {
int updateByPrimaryKeySelective(Order record);
int updateByPrimaryKey(Order record);
}
List<Order> selectAll();
List<Order> selectByUserId(Integer userId);
List<Order> selectAllByUser(Integer userId,Integer orderStatus);
}

View File

@ -23,4 +23,6 @@ public interface RoomMapper {
List<Room> selectByStatus(Integer roomStatus);
List<Room> selectAll();
}
Room randomSelectByTypeAndStatus(Integer typeId,Integer roomStatus);
}

View File

@ -16,6 +16,8 @@ public interface OrderService {
int update(Order record);
int payOrder(int orderId);
List<Order> selectByUserId(int userId);
List<Order> AllOrders();

View File

@ -13,4 +13,8 @@ public interface RoomService {
List<Room> selectByStatus(int roomStatus);
List<Room> selectByType(int typeId);
List<Room> selectAll();
int orderRoom(int typeId);
int inRoom(int typeId);
int outRoom(int typeId);
}

View File

@ -19,4 +19,10 @@ public interface RoomTypeService {
RoomType selectById(int typeId);
List<RoomType> findAllType();
int updateRest(int typeId,int num);
int addRest(int typeId);
int minusRest(int typeId);
}

View File

@ -1,10 +1,18 @@
package cn.mafangui.hotel.service.impl;
import cn.mafangui.hotel.entity.Order;
import cn.mafangui.hotel.entity.Room;
import cn.mafangui.hotel.entity.RoomType;
import cn.mafangui.hotel.enums.OrderStatus;
import cn.mafangui.hotel.mapper.OrderMapper;
import cn.mafangui.hotel.mapper.RoomMapper;
import cn.mafangui.hotel.mapper.RoomTypeMapper;
import cn.mafangui.hotel.service.OrderService;
import cn.mafangui.hotel.service.RoomService;
import cn.mafangui.hotel.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -13,9 +21,18 @@ public class OrderServiceImpl implements OrderService {
@Autowired
private OrderMapper orderMapper;
@Autowired
private RoomTypeService roomTypeService;
@Autowired
private RoomService roomService;
@Override
public int insert(Order order) {
return orderMapper.insert(order);
}
@Override
public int addOrder(Order order) {
return orderMapper.insertSelective(order);
}
@ -34,18 +51,37 @@ public class OrderServiceImpl implements OrderService {
return orderMapper.updateByPrimaryKeySelective(order);
}
/**
* 订单支付
* 1.更改订单状态
* 2.修改房型余量
* 3.修改房间状态
* @param orderId
* @return
*/
@Override
@Transactional
public int payOrder(int orderId) {
Order order = orderMapper.selectByPrimaryKey(orderId);
if (order == null | order.getOrderStatus() != OrderStatus.UNPAID.getCode()) return -1;
if (roomTypeService.updateRest(order.getRoomTypeId(),-1) != 1) return -1;
return roomService.orderRoom(order.getRoomTypeId());
}
@Override
public List<Order> selectByUserId(int userId) {
return orderMapper.selectByUserId(userId);
}
@Override
public List<Order> selectAll() {
public List<Order> AllOrders() {
return orderMapper.selectAll();
}
@Override
public List<Order> userSelectAll(int userId) {
return orderMapper.userSelectAll(userId);
public List<Order> UsersAllOrders(int userId) {
return orderMapper.selectAllByUser(userId, OrderStatus.WAS_DELETED.getCode());
}
}

View File

@ -1,10 +1,12 @@
package cn.mafangui.hotel.service.impl;
import cn.mafangui.hotel.entity.Room;
import cn.mafangui.hotel.enums.RoomStatus;
import cn.mafangui.hotel.mapper.RoomMapper;
import cn.mafangui.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -47,4 +49,30 @@ public class RoomServiceImpl implements RoomService {
public List<Room> selectAll() {
return roomMapper.selectAll();
}
@Override
@Transactional
public int orderRoom(int typeId) {
Room room = roomMapper.randomSelectByTypeAndStatus(typeId,RoomStatus.AVAILABLE.getCode());
if (room == null) return -1;
room.setRoomStatus(RoomStatus.ORDERED.getCode());
return roomMapper.updateByPrimaryKeySelective(room);
}
@Override
public int inRoom(int typeId) {
Room room = roomMapper.randomSelectByTypeAndStatus(typeId,RoomStatus.ORDERED.getCode());
if (room == null) return -1;
room.setRoomStatus(RoomStatus.IN_USE.getCode());
return roomMapper.updateByPrimaryKeySelective(room);
}
@Override
public int outRoom(int typeId) {
Room room = roomMapper.randomSelectByTypeAndStatus(typeId,RoomStatus.IN_USE.getCode());
if (room == null) return -1;
room.setRoomStatus(RoomStatus.AVAILABLE.getCode());
return roomMapper.updateByPrimaryKeySelective(room);
}
}

View File

@ -43,4 +43,25 @@ public class RoomTypeServiceImpl implements RoomTypeService {
public List<RoomType> findAllType() {
return roomTypeMapper.selectAll();
}
@Override
public int updateRest(int typeId, int num) {
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
rt.setTypeId(rt.getRest() + num);
return roomTypeMapper.updateByPrimaryKeySelective(rt);
}
@Override
public int addRest(int typeId) {
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
rt.setTypeId(rt.getRest() +1);
return roomTypeMapper.updateByPrimaryKeySelective(rt);
}
@Override
public int minusRest(int typeId) {
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
rt.setTypeId(rt.getRest() -1);
return roomTypeMapper.updateByPrimaryKeySelective(rt);
}
}

View File

@ -94,11 +94,6 @@
<!--enableDeleteByExample="false" enableSelectByExample="false"-->
<!--enableUpdateByExample="false">-->
<!--</table>-->
<!--<table schema="hotel" tableName="department_info"-->
<!--domainObjectName="Department" enableCountByExample="false"-->
<!--enableDeleteByExample="false" enableSelectByExample="false"-->
<!--enableUpdateByExample="false">-->
<!--</table>-->
<!--<table schema="hotel" tableName="check_in"-->
<!--domainObjectName="CheckIn" enableCountByExample="false"-->
<!--enableDeleteByExample="false" enableSelectByExample="false"-->

View File

@ -1,93 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.mafangui.hotel.mapper.DepartmentMapper">
<resultMap id="BaseResultMap" type="cn.mafangui.hotel.entity.Department">
<id column="department_id" jdbcType="INTEGER" property="departmentId" />
<result column="department_name" jdbcType="VARCHAR" property="departmentName" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
department_id, department_name, remark, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from department_info
where department_id = #{departmentId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from department_info
where department_id = #{departmentId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="cn.mafangui.hotel.entity.Department">
insert into department_info (department_id, department_name, remark,
create_time, update_time)
values (#{departmentId,jdbcType=INTEGER}, #{departmentName,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.Department">
insert into department_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="departmentId != null">
department_id,
</if>
<if test="departmentName != null">
department_name,
</if>
<if test="remark != null">
remark,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="departmentId != null">
#{departmentId,jdbcType=INTEGER},
</if>
<if test="departmentName != null">
#{departmentName,jdbcType=VARCHAR},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Department">
update department_info
<set>
<if test="departmentName != null">
department_name = #{departmentName,jdbcType=VARCHAR},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where department_id = #{departmentId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="cn.mafangui.hotel.entity.Department">
update department_info
set department_name = #{departmentName,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where department_id = #{departmentId,jdbcType=INTEGER}
</update>
</mapper>

View File

@ -18,29 +18,41 @@
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
order_id, order_type_id, order_type, user_id, name, phone, room_type_id, room_type,
order_id, order_type_id, order_type, user_id, name, phone, room_type_id, room_type,
order_date, order_days, order_status, order_cost, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
select
<include refid="Base_Column_List" />
from order_info
where order_id = #{orderId,jdbcType=INTEGER}
</select>
<select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from order_info
where user_id = #{userId,jdbcType=INTEGER}
</select>
<select id="selectAllByUser" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from order_info
where user_id = #{userId,jdbcType=INTEGER} and order_status > #{orderStatus,jdbcType=INTEGER}
</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_id, order_type,
user_id, name, phone,
room_type_id, room_type, order_date,
order_days, order_status, order_cost,
insert into order_info (order_id, order_type_id, order_type,
user_id, name, phone,
room_type_id, room_type, order_date,
order_days, order_status, order_cost,
create_time, update_time)
values (#{orderId,jdbcType=INTEGER}, #{orderTypeId,jdbcType=INTEGER}, #{orderType,jdbcType=VARCHAR},
#{userId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
#{roomTypeId,jdbcType=INTEGER}, #{roomType,jdbcType=VARCHAR}, #{orderDate,jdbcType=DATE},
#{orderDays,jdbcType=INTEGER}, #{orderStatus,jdbcType=INTEGER}, #{orderCost,jdbcType=DOUBLE},
values (#{orderId,jdbcType=INTEGER}, #{orderTypeId,jdbcType=INTEGER}, #{orderType,jdbcType=VARCHAR},
#{userId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
#{roomTypeId,jdbcType=INTEGER}, #{roomType,jdbcType=VARCHAR}, #{orderDate,jdbcType=DATE},
#{orderDays,jdbcType=INTEGER}, #{orderStatus,jdbcType=INTEGER}, #{orderCost,jdbcType=DOUBLE},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.Order">
@ -367,4 +379,4 @@
update_time = now()
where order_id = #{orderId,jdbcType=INTEGER}
</update>
</mapper>
</mapper>

View File

@ -14,37 +14,50 @@
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
room_id, room_number, type_id, room_type, room_price, room_discount, room_status,
room_id, room_number, type_id, room_type, room_price, room_discount, room_status,
remark, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
select
<include refid="Base_Column_List" />
from room_info
where room_id = #{roomId,jdbcType=INTEGER}
</select>
<select id="selectByType" parameterType="Integer" resultMap="BaseResultMap">
select * from room_info
select
<include refid="Base_Column_List" />
from room_info
where type_id = #{typeId,jdbcType=INTEGER}
</select>
<select id="selectByStatus" parameterType="Integer" resultMap="BaseResultMap">
select * from room_info
select
<include refid="Base_Column_List" />
from room_info
where room_status = #{roomStatus,jdbcType=INTEGER}
</select>
<select id="randomSelectByTypeAndStatus" parameterType="Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from room_info
where type_id = #{typeId,jdbcType=INTEGER} and room_status = #{roomStatus,jdbcType=INTEGER}
ORDER BY RAND() LIMIT 1
</select>
<select id="selectAll" resultMap="BaseResultMap">
select * from room_info
select
<include refid="Base_Column_List" />
from room_info
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from room_info
where room_id = #{roomId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="cn.mafangui.hotel.entity.Room">
insert into room_info (room_id, room_number, type_id,
room_type, room_price, room_discount,
room_status, remark, create_time,
insert into room_info (room_id, room_number, type_id,
room_type, room_price, room_discount,
room_status, remark, create_time,
update_time)
values (#{roomId,jdbcType=INTEGER}, #{roomNumber,jdbcType=VARCHAR}, #{typeId,jdbcType=INTEGER},
#{roomType,jdbcType=VARCHAR}, #{roomPrice,jdbcType=DOUBLE}, #{roomDiscount,jdbcType=DOUBLE},
values (#{roomId,jdbcType=INTEGER}, #{roomNumber,jdbcType=VARCHAR}, #{typeId,jdbcType=INTEGER},
#{roomType,jdbcType=VARCHAR}, #{roomPrice,jdbcType=DOUBLE}, #{roomDiscount,jdbcType=DOUBLE},
#{roomStatus,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, now(),
now())
</insert>
@ -147,4 +160,4 @@
update_time = now()
where room_id = #{roomId,jdbcType=INTEGER}
</update>
</mapper>
</mapper>