mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
订单支付完成
This commit is contained in:
parent
fe8d5e521a
commit
7ebdc00b16
3
pom.xml
3
pom.xml
@ -59,6 +59,9 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -20,13 +20,20 @@ public class CheckInController {
|
|||||||
this.checkInService = checkInService;
|
this.checkInService = checkInService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/add")
|
/**
|
||||||
public int addCheckIn(int peo_count, String persons, String ids){
|
* 入住登记
|
||||||
|
* @param peo_count
|
||||||
|
* @param persons
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/in")
|
||||||
|
public int addCheckIn(int orderId, int peo_count, String persons, String ids){
|
||||||
CheckIn checkIn = new CheckIn();
|
CheckIn checkIn = new CheckIn();
|
||||||
|
checkIn.setOrderId(orderId);
|
||||||
checkIn.setPeoCount(peo_count);
|
checkIn.setPeoCount(peo_count);
|
||||||
checkIn.setPersons(persons);
|
checkIn.setPersons(persons);
|
||||||
checkIn.setIds(ids);
|
checkIn.setIds(ids);
|
||||||
checkIn.setCheckInTime(new Date());
|
|
||||||
return checkInService.insert(checkIn);
|
return checkInService.insert(checkIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +50,7 @@ public class CheckInController {
|
|||||||
return checkInService.update(checkIn);
|
return checkInService.update(checkIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/checkOut")
|
@RequestMapping(value = "/out")
|
||||||
public int checkOut(String roomNumber){
|
public int checkOut(String roomNumber){
|
||||||
return checkInService.updateByRoomNumber(roomNumber);
|
return checkInService.updateByRoomNumber(roomNumber);
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,7 @@ public class OrderController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/cancel")
|
@RequestMapping(value = "/cancel")
|
||||||
public int cancelOrder(int orderId){
|
public int cancelOrder(int orderId){
|
||||||
Order order = new Order(orderId,OrderStatus.WAS_CANCELED.getCode());
|
return orderService.cancelOrder(orderId);
|
||||||
return orderService.update(order);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,6 +52,25 @@ public class UserController {
|
|||||||
return userService.insertUser(user);
|
return userService.insertUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户添加
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
* @param name
|
||||||
|
* @param gender
|
||||||
|
* @param phone
|
||||||
|
* @param email
|
||||||
|
* @param address
|
||||||
|
* @param idcard
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(method = RequestMethod.POST,value = "/add")
|
||||||
|
public int userAdd(String username,String password,String name,String gender,String phone,String email,String address,String idcard){
|
||||||
|
User user = new User(username,password,name,gender,phone,email,address,idcard);
|
||||||
|
return userService.addUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用户信息
|
* 更新用户信息
|
||||||
* @param userId
|
* @param userId
|
||||||
|
@ -12,6 +12,8 @@ public interface CheckInService {
|
|||||||
|
|
||||||
int update(CheckIn checkIn);
|
int update(CheckIn checkIn);
|
||||||
|
|
||||||
|
int checkOut(String roomNumber);
|
||||||
|
|
||||||
int updateByRoomNumber(String roomNumber);
|
int updateByRoomNumber(String roomNumber);
|
||||||
|
|
||||||
CheckIn selectById(int checkInId);
|
CheckIn selectById(int checkInId);
|
||||||
|
@ -18,6 +18,8 @@ public interface OrderService {
|
|||||||
|
|
||||||
int payOrder(int orderId);
|
int payOrder(int orderId);
|
||||||
|
|
||||||
|
int cancelOrder(int orderId);
|
||||||
|
|
||||||
List<Order> selectByUserId(int userId);
|
List<Order> selectByUserId(int userId);
|
||||||
|
|
||||||
List<Order> AllOrders();
|
List<Order> AllOrders();
|
||||||
|
@ -9,6 +9,8 @@ public interface UserService {
|
|||||||
|
|
||||||
User selectById(int userId);
|
User selectById(int userId);
|
||||||
|
|
||||||
|
int addUser(User user);
|
||||||
|
|
||||||
int insertUser(User user);
|
int insertUser(User user);
|
||||||
|
|
||||||
int deleteUser(int userId);
|
int deleteUser(int userId);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.mafangui.hotel.service.impl;
|
package cn.mafangui.hotel.service.impl;
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.CheckIn;
|
import cn.mafangui.hotel.entity.CheckIn;
|
||||||
|
import cn.mafangui.hotel.entity.Room;
|
||||||
import cn.mafangui.hotel.mapper.CheckInMapper;
|
import cn.mafangui.hotel.mapper.CheckInMapper;
|
||||||
import cn.mafangui.hotel.service.CheckInService;
|
import cn.mafangui.hotel.service.CheckInService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -29,6 +30,11 @@ public class CheckInServiceImpl implements CheckInService {
|
|||||||
return checkInMapper.updateByPrimaryKeySelective(checkIn);
|
return checkInMapper.updateByPrimaryKeySelective(checkIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int checkOut(String roomNumber) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int updateByRoomNumber(String roomNumber) {
|
public int updateByRoomNumber(String roomNumber) {
|
||||||
return checkInMapper.updateByRoomNumber(roomNumber);
|
return checkInMapper.updateByRoomNumber(roomNumber);
|
||||||
|
@ -71,10 +71,6 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (roomService.orderRoom(order.getRoomTypeId()) != 1){
|
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
order.setOrderStatus(OrderStatus.PAID.getCode());
|
order.setOrderStatus(OrderStatus.PAID.getCode());
|
||||||
if (orderMapper.updateByPrimaryKeySelective(order) != 1){
|
if (orderMapper.updateByPrimaryKeySelective(order) != 1){
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
@ -83,6 +79,24 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消订单
|
||||||
|
* 1. 更改订单状态 -3
|
||||||
|
* 2. 修改房型余量(已付款)-2
|
||||||
|
* @param orderId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int cancelOrder(int orderId) {
|
||||||
|
Order order = orderMapper.selectByPrimaryKey(orderId);
|
||||||
|
if (order == null ) return -3;
|
||||||
|
order.setOrderStatus(OrderStatus.WAS_CANCELED.getCode());
|
||||||
|
if (roomTypeService.updateRest(order.getRoomTypeId(),1) != 1){
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
return orderMapper.updateByPrimaryKeySelective(order);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Order> selectByUserId(int userId) {
|
public List<Order> selectByUserId(int userId) {
|
||||||
return orderMapper.selectByUserId(userId);
|
return orderMapper.selectByUserId(userId);
|
||||||
|
@ -47,7 +47,7 @@ public class RoomTypeServiceImpl implements RoomTypeService {
|
|||||||
@Override
|
@Override
|
||||||
public int updateRest(int typeId, int num) {
|
public int updateRest(int typeId, int num) {
|
||||||
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
|
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
|
||||||
if (rt.getRest() <= 0) return -1;
|
if (rt.getRest() <= 0 && num < 0) return -1;
|
||||||
rt.setRest(rt.getRest() + num);
|
rt.setRest(rt.getRest() + num);
|
||||||
return roomTypeMapper.updateByPrimaryKeySelective(rt);
|
return roomTypeMapper.updateByPrimaryKeySelective(rt);
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,15 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insertUser(User user) {
|
public int addUser(User user) {
|
||||||
return userMapper.insertSelective(user);
|
return userMapper.insertSelective(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertUser(User user) {
|
||||||
|
return userMapper.insert(user);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int deleteUser(int userId) {
|
public int deleteUser(int userId) {
|
||||||
return userMapper.deleteByPrimaryKey(userId);
|
return userMapper.deleteByPrimaryKey(userId);
|
||||||
|
146
src/main/java/cn/mafangui/hotel/utils/RandomCreation.java
Normal file
146
src/main/java/cn/mafangui/hotel/utils/RandomCreation.java
Normal file
File diff suppressed because one or more lines are too long
@ -2,13 +2,16 @@ server:
|
|||||||
port: 8080
|
port: 8080
|
||||||
servlet:
|
servlet:
|
||||||
context-path: "/hotel"
|
context-path: "/hotel"
|
||||||
|
ssl:
|
||||||
|
key-store: classpath:mafangui.cn.jks
|
||||||
|
key-store-password: 98cy27738t8
|
||||||
|
key-store-type: JKS
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
username: root
|
username: root
|
||||||
password: root
|
password: 1997liyiyong
|
||||||
url: jdbc:mysql://127.0.0.1:3306/hotel?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
url: jdbc:mysql://localhost: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
|
||||||
|
|
@ -2,12 +2,16 @@ server:
|
|||||||
port: 8080
|
port: 8080
|
||||||
servlet:
|
servlet:
|
||||||
context-path: "/hotel"
|
context-path: "/hotel"
|
||||||
|
# ssl:
|
||||||
|
# key-store: classpath:mafangui.cn.jks
|
||||||
|
# key-store-password: 98cy27738t8
|
||||||
|
# key-store-type: JKS
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
username: root
|
username: muamua
|
||||||
password: root
|
password: muamua
|
||||||
url: jdbc:mysql://127.0.0.1:3306/hotel?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
url: jdbc:mysql://localhost:3306/hotel?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=true
|
||||||
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
|
||||||
|
@ -27,6 +27,11 @@
|
|||||||
from order_info
|
from order_info
|
||||||
where order_id = #{orderId,jdbcType=INTEGER}
|
where order_id = #{orderId,jdbcType=INTEGER}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectAll" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from order_info
|
||||||
|
</select>
|
||||||
<select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
<select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||||
select
|
select
|
||||||
<include refid="Base_Column_List" />
|
<include refid="Base_Column_List" />
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
package cn.mafangui.hotel.controller;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class OperatorControllerTest {
|
|
||||||
@Autowired
|
|
||||||
OperatorController oc;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void login() {
|
|
||||||
Assert.assertEquals(1,oc.login("w1","w1"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteOperator() {
|
|
||||||
Assert.assertEquals(1,oc.deleteOperator(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAllOperator() {
|
|
||||||
Assert.assertEquals(1,oc.getAllOperator().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getOperator() {
|
|
||||||
Assert.assertNotNull(oc.getOperator(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addOperator() {
|
|
||||||
int res = oc.addOperator("op","op","杜锋","男","124342","assf","jfad");
|
|
||||||
Assert.assertEquals(1,res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateOperator() {
|
|
||||||
int res = oc.updateOperator(3,"疾风","女","32132","asdsa","assf");
|
|
||||||
Assert.assertEquals(1,res);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
package cn.mafangui.hotel.controller;
|
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.Room;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class RoomControllerTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
RoomController rc;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addRoom() {
|
|
||||||
|
|
||||||
Assert.assertEquals(1,rc.addRoom("100",2,"单人房",
|
|
||||||
108.0,20.0,1,"1 person"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteRoom() {
|
|
||||||
Assert.assertEquals(1,rc.deleteRoom(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateRoom() {
|
|
||||||
Assert.assertEquals(1,rc.updateRoom(2,"200",2,"单人房",
|
|
||||||
108.0,20.0,1,"1 person"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getById() {
|
|
||||||
int res = rc.getById(2).getTypeId();
|
|
||||||
Assert.assertEquals(2,res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getByType() {
|
|
||||||
int res = rc.getByType(2).size();
|
|
||||||
Assert.assertEquals(1,res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getByStatus() {
|
|
||||||
int res = rc.getByStatus(1).size();
|
|
||||||
Assert.assertEquals(2,res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAll() {
|
|
||||||
int res = rc.getAll().size();
|
|
||||||
Assert.assertEquals(2,res);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package cn.mafangui.hotel.controller;
|
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.User;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class UserControllerTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
UserController uc;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void userLogin() {
|
|
||||||
Assert.assertEquals(1,uc.userLogin("nihao","123456"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void userRegister() {
|
|
||||||
int res = uc.userRegister("hi","hi","海","男","1123","132","ddd","123");
|
|
||||||
Assert.assertEquals(1,res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void userUpdate() {
|
|
||||||
Assert.assertEquals(1,uc.userUpdate(3,null,null,null,null,"add",null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updatePassword() {
|
|
||||||
Assert.assertEquals(1,uc.updatePassword("hi","hi","123"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAllUser() {
|
|
||||||
Assert.assertEquals(2,uc.getAllUser().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isUsernameExist() {
|
|
||||||
Assert.assertEquals(0,uc.isUsernameExist("addd"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
package cn.mafangui.hotel.mapper;
|
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.Room;
|
|
||||||
import cn.mafangui.hotel.enums.RoomStatus;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class RoomMapperTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RoomMapper rm;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteByPrimaryKey() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void insert() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void insertSelective() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByPrimaryKey() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateByPrimaryKeySelective() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateByPrimaryKey() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByType() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByStatus() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectAll() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void randomSelectByTypeAndStatus() {
|
|
||||||
System.out.println(RoomStatus.AVAILABLE.getCode());
|
|
||||||
System.out.println(RoomStatus.AVAILABLE.getStatus());
|
|
||||||
System.out.println(rm.randomSelectByTypeAndStatus(2, RoomStatus.AVAILABLE.getCode()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package cn.mafangui.hotel.mapper;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class UserMapperTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserMapper userMapper;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testId(){
|
|
||||||
int id = 1;
|
|
||||||
System.out.println(userMapper.selectByPrimaryKey(1));
|
|
||||||
Assert.assertNotNull(userMapper.selectByPrimaryKey(1));
|
|
||||||
}
|
|
||||||
}
|
|
37
src/test/java/cn/mafangui/hotel/service/UserServiceTest.java
Normal file
37
src/test/java/cn/mafangui/hotel/service/UserServiceTest.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package cn.mafangui.hotel.service;
|
||||||
|
|
||||||
|
import cn.mafangui.hotel.entity.User;
|
||||||
|
import cn.mafangui.hotel.utils.RandomCreation;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
public class UserServiceTest {
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void insertUser() {
|
||||||
|
User user = new User();
|
||||||
|
for (int i = 0; i < 30; i++) {
|
||||||
|
Map m = RandomCreation.getAddress();
|
||||||
|
user.setName((String) m.get("name"));
|
||||||
|
user.setUsername((String) m.get("username"));
|
||||||
|
user.setPassword((String) m.get("password"));
|
||||||
|
user.setGender((String) m.get("gender"));
|
||||||
|
user.setPhone((String) m.get("phone"));
|
||||||
|
user.setAddress((String) m.get("road"));
|
||||||
|
user.setEmail((String) m.get("email"));
|
||||||
|
user.setIdcard((String) m.get("idcard"));
|
||||||
|
userService.insertUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
package cn.mafangui.hotel.service.impl;
|
|
||||||
|
|
||||||
import cn.mafangui.hotel.service.OrderService;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class OrderServiceImplTest {
|
|
||||||
@Autowired
|
|
||||||
private OrderService orderService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void payOrder() {
|
|
||||||
int orderId = 19;
|
|
||||||
System.out.println(orderService.payOrder(orderId));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
package cn.mafangui.hotel.service.impl;
|
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.Room;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class RoomServiceImplTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
RoomServiceImpl roomService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void insert() {
|
|
||||||
Room room = new Room();
|
|
||||||
room.setRoomNumber("101");
|
|
||||||
room.setRoomPrice(123.0);
|
|
||||||
room.setRoomDiscount(12.1);
|
|
||||||
room.setRoomStatus(0);
|
|
||||||
room.setTypeId(1);
|
|
||||||
room.setRoomType("ade");
|
|
||||||
Assert.assertEquals(1,roomService.insert(room));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete() {
|
|
||||||
Assert.assertEquals(1,roomService.delete(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update() {
|
|
||||||
Room room = new Room();
|
|
||||||
room.setRoomId(1);
|
|
||||||
room.setRoomNumber("222");
|
|
||||||
room.setRoomPrice(123.0);
|
|
||||||
room.setRoomDiscount(12.1);
|
|
||||||
room.setRoomStatus(0);
|
|
||||||
room.setTypeId(1);
|
|
||||||
room.setRoomType("ade");
|
|
||||||
Assert.assertEquals(1,roomService.update(room));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectById() {
|
|
||||||
System.out.println(roomService.selectById(1));
|
|
||||||
Assert.assertEquals("222",roomService.selectById(1).getRoomNumber());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByStatus() {
|
|
||||||
System.out.println(roomService.selectByStatus(0));
|
|
||||||
Assert.assertEquals(1,roomService.selectByStatus(0).size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByType() {
|
|
||||||
System.out.println(roomService.selectByType(1));
|
|
||||||
Assert.assertEquals(1,roomService.selectByType(1).size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectAll() {
|
|
||||||
System.out.println(roomService.selectAll());
|
|
||||||
Assert.assertEquals(1,roomService.selectAll().size());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
package cn.mafangui.hotel.service.impl;
|
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.RoomType;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class RoomTypeServiceImplTest {
|
|
||||||
@Autowired
|
|
||||||
RoomTypeServiceImpl roomTypeService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void insert() {
|
|
||||||
String typeName = "big";
|
|
||||||
double price = 123;
|
|
||||||
double discount = 12;
|
|
||||||
int area = 10;
|
|
||||||
int bedNum = 1;
|
|
||||||
String bedSize = "15*12";
|
|
||||||
int window = 0;
|
|
||||||
RoomType roomType = new RoomType();
|
|
||||||
roomType.setArea(area);
|
|
||||||
roomType.setBedNum(bedNum);
|
|
||||||
roomType.setBedSize(bedSize);
|
|
||||||
roomType.setDiscount(discount);
|
|
||||||
roomType.setPrice(price);
|
|
||||||
roomType.setRoomType(typeName);
|
|
||||||
roomType.setWindow(window);
|
|
||||||
Assert.assertEquals(1,roomTypeService.insert(roomType));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete() {
|
|
||||||
int id = 1;
|
|
||||||
Assert.assertEquals(1,roomTypeService.delete(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update() {
|
|
||||||
RoomType rt =roomTypeService.selectById(2);
|
|
||||||
rt.setRest(rt.getRest() -1);
|
|
||||||
System.out.println(rt);
|
|
||||||
System.out.println(roomTypeService.update(rt));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByName() {
|
|
||||||
String typeName = "single";
|
|
||||||
int id = roomTypeService.selectByName(typeName).getTypeId();
|
|
||||||
System.out.println(roomTypeService.selectByName(typeName));
|
|
||||||
Assert.assertEquals(1,id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectById() {
|
|
||||||
int id = 1;
|
|
||||||
String typeName = roomTypeService.selectById(id).getRoomType();
|
|
||||||
System.out.println(roomTypeService.selectById(id));
|
|
||||||
Assert.assertEquals("single",typeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findAllType() {
|
|
||||||
System.out.println(roomTypeService.findAllType());
|
|
||||||
Assert.assertNotNull(roomTypeService.findAllType());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package cn.mafangui.hotel.service.impl;
|
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.User;
|
|
||||||
import cn.mafangui.hotel.service.UserService;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class UserServiceImplTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
UserService userService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectById() {
|
|
||||||
String res = userService.selectById(1).getPassword();
|
|
||||||
Assert.assertEquals("aaa",res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void insertUser() {
|
|
||||||
User user = new User("nihao","nihao","你好","女",
|
|
||||||
"18749834","1239@w.c","street2.02d","123213213");
|
|
||||||
int res = userService.insertUser(user);
|
|
||||||
Assert.assertEquals(1,res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteUser() {
|
|
||||||
Assert.assertEquals(1,userService.deleteUser(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateUser() {
|
|
||||||
User user = new User("nihao","123456","你好","女",
|
|
||||||
"18749834","1239@w.c","street2.02d","123213213");
|
|
||||||
user.setUserId(2);
|
|
||||||
int res = userService.updateUser(user);
|
|
||||||
Assert.assertEquals(1,res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByUsernameAndPassword() {
|
|
||||||
int res = userService.selectByUsernameAndPassword("nihao","123456").getUserId();
|
|
||||||
Assert.assertEquals(2,res);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByUsername() {
|
|
||||||
int res = userService.selectByUsername("nihao").getUserId();
|
|
||||||
Assert.assertEquals(2,res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectAll() {
|
|
||||||
int res = userService.selectAll().size();
|
|
||||||
Assert.assertEquals(1,res);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
package cn.mafangui.hotel.service.impl;
|
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.Worker;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class WorkerServiceImplTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
WorkerServiceImpl workerService;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void insert() {
|
|
||||||
String role = "operator";
|
|
||||||
String username = "abc";
|
|
||||||
String password = "abc";
|
|
||||||
String name = "fdsa";
|
|
||||||
String gender = "女";
|
|
||||||
String phone = "242424";
|
|
||||||
Worker worker = new Worker();
|
|
||||||
worker.setPhone(phone);
|
|
||||||
worker.setGender(gender);
|
|
||||||
worker.setName(name);
|
|
||||||
worker.setPassword(password);
|
|
||||||
worker.setUsername(username);
|
|
||||||
worker.setRole(role);
|
|
||||||
Assert.assertEquals(1,workerService.insert(worker));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete() {
|
|
||||||
int id = 4;
|
|
||||||
Assert.assertEquals(1,workerService.delete(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateById() {
|
|
||||||
int id = 4;
|
|
||||||
String role = "operator";
|
|
||||||
String username = "abc";
|
|
||||||
String password = "abc";
|
|
||||||
String name = "fdsa";
|
|
||||||
String gender = "女";
|
|
||||||
String phone = "11111111";
|
|
||||||
Worker worker = new Worker();
|
|
||||||
worker.setWorkerId(4);
|
|
||||||
worker.setPhone(phone);
|
|
||||||
worker.setGender(gender);
|
|
||||||
worker.setName(name);
|
|
||||||
worker.setPassword(password);
|
|
||||||
worker.setUsername(username);
|
|
||||||
worker.setRole(role);
|
|
||||||
Assert.assertEquals(1,workerService.updateById(worker));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectById() {
|
|
||||||
int id = 4;
|
|
||||||
Assert.assertEquals("fdsa",workerService.selectById(id).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findAll() {
|
|
||||||
List<Worker> list = workerService.findAll();
|
|
||||||
System.out.println(list);
|
|
||||||
Assert.assertNotNull(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selectByRole() {
|
|
||||||
String role = "admin";
|
|
||||||
List<Worker> list = workerService.selectByRole(role);
|
|
||||||
System.out.println(list);
|
|
||||||
Assert.assertEquals(1,list.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void login() {
|
|
||||||
String username = "admin";
|
|
||||||
String password = "admin";
|
|
||||||
Worker worker = workerService.login(username,password,"admin");
|
|
||||||
Assert.assertNotNull(worker);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user