mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
更新
This commit is contained in:
parent
3aba922a10
commit
08c024b0c3
@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@ -28,7 +29,7 @@ public class CheckInController {
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/in")
|
||||
public int addCheckIn(int orderId, int peoCount, String persons, String ids){
|
||||
public HashMap addCheckIn(int orderId, int peoCount, String persons, String ids){
|
||||
CheckIn checkIn = new CheckIn();
|
||||
checkIn.setOrderId(orderId);
|
||||
checkIn.setPeoCount(peoCount);
|
||||
@ -44,8 +45,13 @@ public class CheckInController {
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/out")
|
||||
public int checkOut(String roomNumber){
|
||||
return checkInService.updateByRoomNumber(roomNumber);
|
||||
public int checkOut(String roomNumber) {
|
||||
try {
|
||||
return checkInService.checkOut(roomNumber);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
package cn.mafangui.hotel.controller;
|
||||
|
||||
import cn.mafangui.hotel.service.WorkerService;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/worker")
|
||||
public class WorkerController {
|
||||
@Autowired
|
||||
private WorkerService workerService;
|
||||
|
||||
/**
|
||||
* 管理员登录
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST,value = "/login")
|
||||
public int login(String username,String password){
|
||||
if(workerService.login(username,password) != null )
|
||||
return 1;
|
||||
else return 0;
|
||||
}
|
||||
}
|
@ -22,6 +22,8 @@ public interface WorkerMapper {
|
||||
|
||||
Worker selectByUsernameAndPassword(@Param("username") String username, @Param("password") String password, @Param("role") String role);
|
||||
|
||||
Worker selectByUsernamePassword(@Param("username") String username, @Param("password") String password);
|
||||
|
||||
List<Worker> selectByRole(String role);
|
||||
|
||||
Worker selectByUsername(String username);
|
||||
|
@ -2,19 +2,20 @@ package cn.mafangui.hotel.service;
|
||||
|
||||
import cn.mafangui.hotel.entity.CheckIn;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public interface CheckInService {
|
||||
|
||||
int insert(CheckIn checkIn);
|
||||
|
||||
int checkIn(CheckIn checkIn);
|
||||
HashMap checkIn(CheckIn checkIn);
|
||||
|
||||
int delete(int checkInId);
|
||||
|
||||
int update(CheckIn checkIn);
|
||||
|
||||
int checkOut(String roomNumber);
|
||||
int checkOut(String roomNumber) throws Exception;
|
||||
|
||||
int updateByRoomNumber(String roomNumber);
|
||||
|
||||
|
@ -13,4 +13,5 @@ public interface WorkerService {
|
||||
List<Worker> findAll();
|
||||
List<Worker> selectByRole(String role);
|
||||
Worker login(String username,String password,String role);
|
||||
Worker login(String username,String password);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@ -44,17 +44,22 @@ public class CheckInServiceImpl implements CheckInService {
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int checkIn(CheckIn checkIn) {
|
||||
public HashMap checkIn(CheckIn checkIn) {
|
||||
HashMap resultMap = new HashMap();
|
||||
int code = 0;
|
||||
Order order = orderService.selectById(checkIn.getOrderId());
|
||||
RoomType rt = roomTypeService.selectById(order.getRoomTypeId());
|
||||
Room r=roomService.selectById(roomService.inRoom(order.getRoomTypeId()));
|
||||
if (r == null) return -3;
|
||||
if (r == null) code = -3;
|
||||
checkIn.setRoomId(r.getRoomId());
|
||||
checkIn.setRoomNumber(r.getRoomNumber());
|
||||
if (roomTypeService.updateRest(rt.getTypeId(),-1) <= 0) return -2;
|
||||
if (roomTypeService.updateRest(rt.getTypeId(),-1) <= 0) code = -2;
|
||||
order.setOrderStatus(OrderStatus.CHECK_IN.getCode());
|
||||
if (orderService.update(order) <=0 ) return -1;
|
||||
return checkInMapper.insert(checkIn);
|
||||
if (orderService.update(order) <=0 ) code = -1;
|
||||
code = checkInMapper.insert(checkIn);
|
||||
resultMap.put("code",code);
|
||||
resultMap.put("room",r);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +71,7 @@ public class CheckInServiceImpl implements CheckInService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int checkOut(String roomNumber) {
|
||||
public int checkOut(String roomNumber) throws Exception{
|
||||
Room r = roomService.selectByNumber(roomNumber);
|
||||
RoomType ty = roomTypeService.selectById(r.getTypeId());
|
||||
CheckIn checkIn = checkInMapper.selectLatestByRoomNumber(roomNumber);
|
||||
|
@ -52,6 +52,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
Order order = new Order();
|
||||
order.setName(name);
|
||||
order.setPhone(phone);
|
||||
order.setOrderStatus(OrderStatus.PAID.getCode());
|
||||
return orderMapper.selectByNameAndPhone(order);
|
||||
}
|
||||
|
||||
|
@ -53,4 +53,9 @@ public class WorkerServiceImpl implements WorkerService {
|
||||
public Worker login(String username, String password,String role) {
|
||||
return workerMapper.selectByUsernameAndPassword(username,password,role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Worker login(String username, String password) {
|
||||
return workerMapper.selectByUsernamePassword(username,password);
|
||||
}
|
||||
}
|
||||
|
@ -128,19 +128,19 @@ public class RandomCreation {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
User user = new User();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
Map m = 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);
|
||||
}
|
||||
}
|
||||
// public static void main(String[] args) {
|
||||
// User user = new User();
|
||||
// for (int i = 0; i < 30; i++) {
|
||||
// Map m = 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);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ server:
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: muamua
|
||||
password: muamua
|
||||
username: root
|
||||
password: liyiyong1997
|
||||
url: jdbc:mysql://localhost:3306/hotel?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=true
|
||||
mybatis:
|
||||
type-aliases-package: classpath*:cn.mafangui.hotel.entity
|
||||
|
@ -45,7 +45,7 @@
|
||||
update_time)
|
||||
values (#{checkInId,jdbcType=INTEGER}, #{orderId,jdbcType=INTEGER},#{roomId,jdbcType=INTEGER}, #{roomNumber,jdbcType=VARCHAR},
|
||||
#{peoCount,jdbcType=INTEGER}, #{persons,jdbcType=VARCHAR},
|
||||
#{ids,jdbcType=VARCHAR}, #{checkInTime,jdbcType=TIMESTAMP}, now(),now())
|
||||
#{ids,jdbcType=VARCHAR}, now(), now(),now())
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.CheckIn">
|
||||
insert into check_in
|
||||
|
@ -32,10 +32,11 @@
|
||||
<include refid="Base_Column_List" />
|
||||
from order_info
|
||||
</select>
|
||||
<select id="selectByNameAndPhone" parameterType="String" resultMap="BaseResultMap">
|
||||
<select id="selectByNameAndPhone" parameterType="cn.mafangui.hotel.entity.Order" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from order_info where name = #{name,jdbcType=VARCHAR} and phone = #{phone,jdbcType=VARCHAR}
|
||||
and order_status = #{orderStatus,jdbcType=INTEGER}
|
||||
</select>
|
||||
<select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
|
@ -34,6 +34,10 @@
|
||||
select * from worker_info
|
||||
where username = #{username,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR} and role = #{role,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectByUsernamePassword" parameterType="String" resultMap="BaseResultMap">
|
||||
select * from worker_info
|
||||
where username = #{username,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectByRole" parameterType="String" resultMap="BaseResultMap">
|
||||
select * from worker_info
|
||||
where role = #{role,jdbcType=VARCHAR}
|
||||
|
@ -1,37 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user