mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
1.添加对房间信息的简单操作
2.新增时间格式化的工具类
This commit is contained in:
parent
931447aa39
commit
833ff34b64
@ -17,7 +17,7 @@ public class AdminController {
|
|||||||
private AdminService adminService;
|
private AdminService adminService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 管理员登录
|
||||||
* @param userName
|
* @param userName
|
||||||
* @param password
|
* @param password
|
||||||
* @return
|
* @return
|
||||||
@ -34,7 +34,7 @@ public class AdminController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册
|
* 管理员注册
|
||||||
* @param userName
|
* @param userName
|
||||||
* @param password
|
* @param password
|
||||||
* @return
|
* @return
|
||||||
|
143
src/main/java/cn/mafangui/hotel/controller/RoomController.java
Normal file
143
src/main/java/cn/mafangui/hotel/controller/RoomController.java
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
package cn.mafangui.hotel.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.mafangui.hotel.entity.Room;
|
||||||
|
import cn.mafangui.hotel.service.RoomService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.awt.print.PrinterException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "room")
|
||||||
|
public class RoomController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoomService roomService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加房间
|
||||||
|
* @param roomNumber
|
||||||
|
* @param roomFloor
|
||||||
|
* @param roomType
|
||||||
|
* @param typeName
|
||||||
|
* @param roomPrice
|
||||||
|
* @param roomDiscount
|
||||||
|
* @param roomStatus
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "add")
|
||||||
|
public int addRoom(String roomNumber, int roomFloor, int roomType, String typeName, double roomPrice,double roomDiscount,String roomStatus){
|
||||||
|
int result = 0;
|
||||||
|
Room room = new Room(roomNumber,roomFloor,roomType,typeName,roomPrice,roomDiscount,roomStatus);
|
||||||
|
try {
|
||||||
|
result = roomService.addRoom(room);
|
||||||
|
}catch (Exception e){
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据房间id或者房间号码删除房间
|
||||||
|
* @param roomId
|
||||||
|
* @param roomNumber
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "delete")
|
||||||
|
public int deleteRoom(int roomId,String roomNumber){
|
||||||
|
int result = 0;
|
||||||
|
try {
|
||||||
|
if (roomNumber == null || "".equals(roomNumber)){
|
||||||
|
result = roomService.deleteRoom(roomId);
|
||||||
|
}else {
|
||||||
|
result = roomService.deleteRoom(roomNumber);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更改房间信息
|
||||||
|
* @param roomId
|
||||||
|
* @param roomNumber
|
||||||
|
* @param roomFloor
|
||||||
|
* @param roomType
|
||||||
|
* @param typeName
|
||||||
|
* @param roomPrice
|
||||||
|
* @param roomDiscount
|
||||||
|
* @param roomStatus
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "update")
|
||||||
|
public int updateRoom(int roomId,String roomNumber, int roomFloor, int roomType, String typeName, double roomPrice,double roomDiscount,String roomStatus){
|
||||||
|
int result = 0;
|
||||||
|
Room room = new Room(roomNumber,roomFloor,roomType,typeName,roomPrice,roomDiscount,roomStatus);
|
||||||
|
room.setRoomId(roomId);
|
||||||
|
try {
|
||||||
|
result = roomService.updateRoom(room);
|
||||||
|
}catch (Exception e){
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有房间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/all")
|
||||||
|
public List<Room> allRoom(){
|
||||||
|
try {
|
||||||
|
return roomService.findAll();
|
||||||
|
}catch (Exception e){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据状态查询房间信息
|
||||||
|
* @param roomNumber
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/withRoomNumber")
|
||||||
|
public Room findRoomByNumber(String roomNumber){
|
||||||
|
try{
|
||||||
|
return roomService.findByNumber(roomNumber);
|
||||||
|
}catch (Exception e){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据状态查询房间信息
|
||||||
|
* @param roomStatus
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/withStatus")
|
||||||
|
public List<Room> findRoomByStatus(String roomStatus){
|
||||||
|
try{
|
||||||
|
return roomService.findByStatus(roomStatus);
|
||||||
|
}catch (Exception e){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据类型查询房间信息
|
||||||
|
* @param typeName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/withType")
|
||||||
|
public List<Room> findRoomByType(String typeName){
|
||||||
|
try{
|
||||||
|
return roomService.findByType(typeName);
|
||||||
|
}catch (Exception e){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,12 +16,26 @@ public class RoomTypeController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RoomTypeService roomTypeService;
|
private RoomTypeService roomTypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加房间类型
|
||||||
|
* @param roomType
|
||||||
|
* @param typeName
|
||||||
|
* @param bookingPrice
|
||||||
|
* @param bookingDiscount
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/add")
|
@RequestMapping(method = RequestMethod.POST,value = "/add")
|
||||||
public int addNewType(int roomType,String typeName,double bookingPrice,double bookingDiscount){
|
public int addNewType(int roomType,String typeName,double bookingPrice,double bookingDiscount){
|
||||||
RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount);
|
RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount);
|
||||||
return roomTypeService.addRoomType(rt);
|
return roomTypeService.addRoomType(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除房间类型
|
||||||
|
* @param roomType
|
||||||
|
* @param typeName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/del")
|
@RequestMapping(method = RequestMethod.POST,value = "/del")
|
||||||
public int delType(int roomType,String typeName){
|
public int delType(int roomType,String typeName){
|
||||||
RoomType rt = new RoomType();
|
RoomType rt = new RoomType();
|
||||||
@ -30,12 +44,25 @@ public class RoomTypeController {
|
|||||||
return roomTypeService.delRoomType(rt);
|
return roomTypeService.delRoomType(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更改房间类型
|
||||||
|
* @param roomType
|
||||||
|
* @param typeName
|
||||||
|
* @param bookingPrice
|
||||||
|
* @param bookingDiscount
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/update")
|
@RequestMapping(method = RequestMethod.POST,value = "/update")
|
||||||
public int updateType(int roomType,String typeName,double bookingPrice,double bookingDiscount){
|
public int updateType(int roomType,String typeName,double bookingPrice,double bookingDiscount){
|
||||||
RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount);
|
RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount);
|
||||||
return roomTypeService.updateRoomType(rt);
|
return roomTypeService.updateRoomType(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询房间类型
|
||||||
|
* @param roomType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(value = "/query")
|
@RequestMapping(value = "/query")
|
||||||
public RoomType findByRoomType(int roomType){
|
public RoomType findByRoomType(int roomType){
|
||||||
RoomType rt = new RoomType();
|
RoomType rt = new RoomType();
|
||||||
@ -43,6 +70,10 @@ public class RoomTypeController {
|
|||||||
return roomTypeService.selectByName(rt);
|
return roomTypeService.selectByName(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有房间类型
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(value = "/all")
|
@RequestMapping(value = "/all")
|
||||||
public List<RoomType> findAllRoomType(){
|
public List<RoomType> findAllRoomType(){
|
||||||
return roomTypeService.findAllType();
|
return roomTypeService.findAllType();
|
||||||
|
@ -14,6 +14,12 @@ public class WorkerController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private WorkerService workerService;
|
private WorkerService workerService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作员登录
|
||||||
|
* @param userName
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/login")
|
@RequestMapping(method = RequestMethod.POST,value = "/login")
|
||||||
public int login(String userName,String password){
|
public int login(String userName,String password){
|
||||||
Worker worker = new Worker(userName,password);
|
Worker worker = new Worker(userName,password);
|
||||||
@ -24,28 +30,62 @@ public class WorkerController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加操作员
|
||||||
|
* @param userName
|
||||||
|
* @param password
|
||||||
|
* @param workerName
|
||||||
|
* @param phone
|
||||||
|
* @param email
|
||||||
|
* @param address
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/add")
|
@RequestMapping(method = RequestMethod.POST,value = "/add")
|
||||||
public int addWorker(String userName,String password,String workerName,String phone,String email,String address){
|
public int addWorker(String userName,String password,String workerName,String phone,String email,String address){
|
||||||
Worker worker = new Worker(userName,password,workerName,phone,email,address);
|
Worker worker = new Worker(userName,password,workerName,phone,email,address);
|
||||||
return workerService.addWorker(worker);
|
return workerService.addWorker(worker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除操作员
|
||||||
|
* @param userName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/del")
|
@RequestMapping(method = RequestMethod.POST,value = "/del")
|
||||||
public int delWorker(String userName){
|
public int delWorker(String userName){
|
||||||
return workerService.delWorker(userName);
|
return workerService.delWorker(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更改操作员信息
|
||||||
|
* @param userName
|
||||||
|
* @param password
|
||||||
|
* @param workerName
|
||||||
|
* @param phone
|
||||||
|
* @param email
|
||||||
|
* @param address
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/update")
|
@RequestMapping(method = RequestMethod.POST,value = "/update")
|
||||||
public int updateWorker(String userName,String password,String workerName,String phone,String email,String address){
|
public int updateWorker(String userName,String password,String workerName,String phone,String email,String address){
|
||||||
Worker worker = new Worker(userName,password,workerName,phone,email,address);
|
Worker worker = new Worker(userName,password,workerName,phone,email,address);
|
||||||
return workerService.updateWorker(worker);
|
return workerService.updateWorker(worker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找操作员
|
||||||
|
* @param userName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(value = "/query")
|
@RequestMapping(value = "/query")
|
||||||
public Worker queryWorker(String userName){
|
public Worker queryWorker(String userName){
|
||||||
return workerService.selectWorker(userName);
|
return workerService.selectWorker(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找所有操作员
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(value = "/all")
|
@RequestMapping(value = "/all")
|
||||||
public List<Worker> findAllWorkers(){
|
public List<Worker> findAllWorkers(){
|
||||||
return workerService.findAllWorker();
|
return workerService.findAllWorker();
|
||||||
|
@ -12,9 +12,11 @@ public class Room {
|
|||||||
|
|
||||||
private Integer roomType;
|
private Integer roomType;
|
||||||
|
|
||||||
private BigDecimal roomPrice;
|
private String typeName;
|
||||||
|
|
||||||
private Float roomDiscount;
|
private Double roomPrice;
|
||||||
|
|
||||||
|
private Double roomDiscount;
|
||||||
|
|
||||||
private String roomStatus;
|
private String roomStatus;
|
||||||
|
|
||||||
@ -54,19 +56,27 @@ public class Room {
|
|||||||
this.roomType = roomType;
|
this.roomType = roomType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getRoomPrice() {
|
public String getTypeName() {
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTypeName(String typeName) {
|
||||||
|
this.typeName = typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getRoomPrice() {
|
||||||
return roomPrice;
|
return roomPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoomPrice(BigDecimal roomPrice) {
|
public void setRoomPrice(Double roomPrice) {
|
||||||
this.roomPrice = roomPrice;
|
this.roomPrice = roomPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Float getRoomDiscount() {
|
public Double getRoomDiscount() {
|
||||||
return roomDiscount;
|
return roomDiscount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoomDiscount(Float roomDiscount) {
|
public void setRoomDiscount(Double roomDiscount) {
|
||||||
this.roomDiscount = roomDiscount;
|
this.roomDiscount = roomDiscount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,4 +103,33 @@ public class Room {
|
|||||||
public void setUpdateTime(Date updateTime) {
|
public void setUpdateTime(Date updateTime) {
|
||||||
this.updateTime = updateTime;
|
this.updateTime = updateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Room() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Room(String roomNumber, Integer roomFloor, Integer roomType, String typeName, Double roomPrice, Double roomDiscount, String roomStatus) {
|
||||||
|
this.roomNumber = roomNumber;
|
||||||
|
this.roomFloor = roomFloor;
|
||||||
|
this.roomType = roomType;
|
||||||
|
this.typeName = typeName;
|
||||||
|
this.roomPrice = roomPrice;
|
||||||
|
this.roomDiscount = roomDiscount;
|
||||||
|
this.roomStatus = roomStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Room{" +
|
||||||
|
"roomId=" + roomId +
|
||||||
|
", roomNumber='" + roomNumber + '\'' +
|
||||||
|
", roomFloor=" + roomFloor +
|
||||||
|
", roomType=" + roomType +
|
||||||
|
", typeName='" + typeName + '\'' +
|
||||||
|
", roomPrice=" + roomPrice +
|
||||||
|
", roomDiscount=" + roomDiscount +
|
||||||
|
", roomStatus='" + roomStatus + '\'' +
|
||||||
|
", createTime=" + createTime +
|
||||||
|
", updateTime=" + updateTime +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,17 +1,25 @@
|
|||||||
package cn.mafangui.hotel.mapper;
|
package cn.mafangui.hotel.mapper;
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.Room;
|
import cn.mafangui.hotel.entity.Room;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
public interface RoomMapper {
|
public interface RoomMapper {
|
||||||
int deleteByPrimaryKey(Integer roomId);
|
|
||||||
|
|
||||||
int insert(Room record);
|
|
||||||
|
|
||||||
int insertSelective(Room record);
|
int insertSelective(Room record);
|
||||||
|
|
||||||
Room selectByPrimaryKey(Integer roomId);
|
Room selectByPrimaryKey(Integer roomId);
|
||||||
|
|
||||||
int updateByPrimaryKeySelective(Room record);
|
|
||||||
|
|
||||||
int updateByPrimaryKey(Room record);
|
int updateByPrimaryKey(Room record);
|
||||||
|
|
||||||
|
int insert(Room record);
|
||||||
|
int deleteByPrimaryKey(Integer roomId);
|
||||||
|
int deleteByRoomNumber(String roomNumber);
|
||||||
|
int updateByPrimaryKeySelective(Room record);
|
||||||
|
Room selectByRoomId(Integer roomId);
|
||||||
|
Room selectByRoomNumber(String roomNumber);
|
||||||
|
List<Room> selectAllRoom();
|
||||||
|
List<Room> selectByType(String typeName);
|
||||||
|
List<Room> selectByStatus(String status);
|
||||||
|
|
||||||
}
|
}
|
18
src/main/java/cn/mafangui/hotel/service/RoomService.java
Normal file
18
src/main/java/cn/mafangui/hotel/service/RoomService.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package cn.mafangui.hotel.service;
|
||||||
|
|
||||||
|
import cn.mafangui.hotel.entity.Room;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface RoomService {
|
||||||
|
int addRoom(Room room);
|
||||||
|
int deleteRoom(int roomId);
|
||||||
|
int deleteRoom(String roomNumber);
|
||||||
|
int updateRoom(Room room);
|
||||||
|
Room findById(int roomId);
|
||||||
|
Room findByNumber(String roomNumber);
|
||||||
|
List<Room> findByStatus(String status);
|
||||||
|
List<Room> findByType(String typeName);
|
||||||
|
List<Room> findAll();
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package cn.mafangui.hotel.service.impl;
|
||||||
|
|
||||||
|
import cn.mafangui.hotel.entity.Room;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RoomServiceImpl implements RoomService {
|
||||||
|
@Autowired
|
||||||
|
private RoomMapper roomMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addRoom(Room room) {
|
||||||
|
return roomMapper.insert(room);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteRoom(int roomId) {
|
||||||
|
return roomMapper.deleteByPrimaryKey(roomId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteRoom(String roomNumber) {
|
||||||
|
return roomMapper.deleteByRoomNumber(roomNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateRoom(Room room) {
|
||||||
|
return roomMapper.updateByPrimaryKeySelective(room);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Room findById(int roomId) {
|
||||||
|
return roomMapper.selectByPrimaryKey(roomId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Room findByNumber(String roomNumber) {
|
||||||
|
return roomMapper.selectByRoomNumber(roomNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Room> findByStatus(String status) {
|
||||||
|
return roomMapper.selectByStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Room> findByType(String typeName) {
|
||||||
|
return roomMapper.selectByType(typeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Room> findAll() {
|
||||||
|
return roomMapper.selectAllRoom();
|
||||||
|
}
|
||||||
|
}
|
103
src/main/java/cn/mafangui/hotel/utils/MyDateTimeFormat.java
Normal file
103
src/main/java/cn/mafangui/hotel/utils/MyDateTimeFormat.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package cn.mafangui.hotel.utils;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
public class MyDateTimeFormat {
|
||||||
|
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得年份
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getYear(Date date) {
|
||||||
|
simpleDateFormat.applyPattern("yyyy");
|
||||||
|
return Integer.parseInt(simpleDateFormat.format(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得月份
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getMonth(Date date) {
|
||||||
|
simpleDateFormat.applyPattern("MM");
|
||||||
|
return Integer.parseInt(simpleDateFormat.format(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得日子
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getDay(Date date){
|
||||||
|
simpleDateFormat.applyPattern("dd");
|
||||||
|
return Integer.parseInt(simpleDateFormat.format(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回某天是周几
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getWeek(Date date){
|
||||||
|
simpleDateFormat.applyPattern("yyyy-MM-dd");
|
||||||
|
calendar.setTime(date);
|
||||||
|
int w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
|
if (w < 0) w = 0;
|
||||||
|
return weekDays[w];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化为年份
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String formatYear(Date date){
|
||||||
|
simpleDateFormat.applyPattern("yyyy");
|
||||||
|
return simpleDateFormat.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化为年月
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String formatMonth(Date date){
|
||||||
|
simpleDateFormat.applyPattern("yyyy-MM");
|
||||||
|
return simpleDateFormat.format(date);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 格式化为年月日
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String formatDay(Date date){
|
||||||
|
simpleDateFormat.applyPattern("yyyy-MM-dd");
|
||||||
|
return simpleDateFormat.format(date);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 格式化为年月日时分
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String formatMinute(Date date){
|
||||||
|
simpleDateFormat.applyPattern("yyyy-MM-dd HH:mm");
|
||||||
|
return simpleDateFormat.format(date);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 格式化为年月日时分秒
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String formatSecond(Date date){
|
||||||
|
simpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
return simpleDateFormat.format(date);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@
|
|||||||
<result column="room_number" jdbcType="VARCHAR" property="roomNumber" />
|
<result column="room_number" jdbcType="VARCHAR" property="roomNumber" />
|
||||||
<result column="room_floor" jdbcType="INTEGER" property="roomFloor" />
|
<result column="room_floor" jdbcType="INTEGER" property="roomFloor" />
|
||||||
<result column="room_type" jdbcType="INTEGER" property="roomType" />
|
<result column="room_type" jdbcType="INTEGER" property="roomType" />
|
||||||
|
<result column="type_name" jdbcType="VARCHAR" property="typeName" />
|
||||||
<result column="room_price" jdbcType="DECIMAL" property="roomPrice" />
|
<result column="room_price" jdbcType="DECIMAL" property="roomPrice" />
|
||||||
<result column="room_discount" jdbcType="REAL" property="roomDiscount" />
|
<result column="room_discount" jdbcType="REAL" property="roomDiscount" />
|
||||||
<result column="room_status" jdbcType="VARCHAR" property="roomStatus" />
|
<result column="room_status" jdbcType="VARCHAR" property="roomStatus" />
|
||||||
@ -13,7 +14,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">
|
||||||
room_id, room_number, room_floor, room_type, room_price, room_discount, room_status,
|
room_id, room_number, room_floor, room_type, type_name, room_price, room_discount, room_status,
|
||||||
create_time, update_time
|
create_time, update_time
|
||||||
</sql>
|
</sql>
|
||||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||||
@ -26,16 +27,7 @@
|
|||||||
delete from room_info
|
delete from room_info
|
||||||
where room_id = #{roomId,jdbcType=INTEGER}
|
where room_id = #{roomId,jdbcType=INTEGER}
|
||||||
</delete>
|
</delete>
|
||||||
<insert id="insert" parameterType="cn.mafangui.hotel.entity.Room">
|
|
||||||
insert into room_info (room_id, room_number, room_floor,
|
|
||||||
room_type, room_price, room_discount,
|
|
||||||
room_status, create_time, update_time
|
|
||||||
)
|
|
||||||
values (#{roomId,jdbcType=INTEGER}, #{roomNumber,jdbcType=VARCHAR}, #{roomFloor,jdbcType=INTEGER},
|
|
||||||
#{roomType,jdbcType=INTEGER}, #{roomPrice,jdbcType=DECIMAL}, #{roomDiscount,jdbcType=REAL},
|
|
||||||
#{roomStatus,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
|
|
||||||
)
|
|
||||||
</insert>
|
|
||||||
<insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.Room">
|
<insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.Room">
|
||||||
insert into room_info
|
insert into room_info
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
@ -97,36 +89,7 @@
|
|||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Room">
|
|
||||||
update room_info
|
|
||||||
<set>
|
|
||||||
<if test="roomNumber != null">
|
|
||||||
room_number = #{roomNumber,jdbcType=VARCHAR},
|
|
||||||
</if>
|
|
||||||
<if test="roomFloor != null">
|
|
||||||
room_floor = #{roomFloor,jdbcType=INTEGER},
|
|
||||||
</if>
|
|
||||||
<if test="roomType != null">
|
|
||||||
room_type = #{roomType,jdbcType=INTEGER},
|
|
||||||
</if>
|
|
||||||
<if test="roomPrice != null">
|
|
||||||
room_price = #{roomPrice,jdbcType=DECIMAL},
|
|
||||||
</if>
|
|
||||||
<if test="roomDiscount != null">
|
|
||||||
room_discount = #{roomDiscount,jdbcType=REAL},
|
|
||||||
</if>
|
|
||||||
<if test="roomStatus != null">
|
|
||||||
room_status = #{roomStatus,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 room_id = #{roomId,jdbcType=INTEGER}
|
|
||||||
</update>
|
|
||||||
<update id="updateByPrimaryKey" parameterType="cn.mafangui.hotel.entity.Room">
|
<update id="updateByPrimaryKey" parameterType="cn.mafangui.hotel.entity.Room">
|
||||||
update room_info
|
update room_info
|
||||||
set room_number = #{roomNumber,jdbcType=VARCHAR},
|
set room_number = #{roomNumber,jdbcType=VARCHAR},
|
||||||
@ -139,4 +102,69 @@
|
|||||||
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
||||||
where room_id = #{roomId,jdbcType=INTEGER}
|
where room_id = #{roomId,jdbcType=INTEGER}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<insert id="insert" parameterType="cn.mafangui.hotel.entity.Room">
|
||||||
|
insert into room_info ( room_number, room_floor,
|
||||||
|
room_type, type_name, room_price, room_discount,
|
||||||
|
room_status, create_time, update_time
|
||||||
|
)
|
||||||
|
values (#{roomNumber,jdbcType=VARCHAR}, #{roomFloor,jdbcType=INTEGER},
|
||||||
|
#{roomType,jdbcType=INTEGER}, #{typeName,jdbcType=VARCHAR}, #{roomPrice,jdbcType=DECIMAL}, #{roomDiscount,jdbcType=REAL},
|
||||||
|
#{roomStatus,jdbcType=VARCHAR}, now(), now()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
<delete id="deleteByRoomNumber" parameterType="String">
|
||||||
|
delete from room_info where room_number = #{roomNumber,jdbcType=VARCHAR}
|
||||||
|
</delete>
|
||||||
|
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Room">
|
||||||
|
update room_info
|
||||||
|
<set>
|
||||||
|
<if test="roomNumber != null">
|
||||||
|
room_number = #{roomNumber,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="roomFloor != null">
|
||||||
|
room_floor = #{roomFloor,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
<if test="roomType != null">
|
||||||
|
room_type = #{roomType,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
<if test="typeName != null">
|
||||||
|
type_name = #{typeName,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="roomPrice != null">
|
||||||
|
room_price = #{roomPrice,jdbcType=DECIMAL},
|
||||||
|
</if>
|
||||||
|
<if test="roomDiscount != null">
|
||||||
|
room_discount = #{roomDiscount,jdbcType=REAL},
|
||||||
|
</if>
|
||||||
|
<if test="roomStatus != null">
|
||||||
|
room_status = #{roomStatus,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
update_time = now(),
|
||||||
|
</set>
|
||||||
|
where room_id = #{roomId,jdbcType=INTEGER}
|
||||||
|
</update>
|
||||||
|
<select id="selectByRoomNumber" parameterType="String" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from room_info
|
||||||
|
where room_number = #{roomNumber,jdbcType=VARCHAR}
|
||||||
|
</select>
|
||||||
|
<select id="selectAllRoom" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from room_info
|
||||||
|
</select>
|
||||||
|
<select id="selectByType" parameterType="String" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from room_info
|
||||||
|
where type_name = #{typeName,jdbcType=VARCHAR}
|
||||||
|
</select>
|
||||||
|
<select id="selectByStatus" parameterType="String" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from room_info
|
||||||
|
where room_status = #{status,jdbcType=VARCHAR}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
@ -0,0 +1,54 @@
|
|||||||
|
package cn.mafangui.hotel.controller;
|
||||||
|
|
||||||
|
import cn.mafangui.hotel.entity.Room;
|
||||||
|
import cn.mafangui.hotel.utils.MyDateTimeFormat;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
public class RoomControllerTest {
|
||||||
|
@Autowired
|
||||||
|
private RoomController roomController;
|
||||||
|
|
||||||
|
MyDateTimeFormat df = new MyDateTimeFormat();
|
||||||
|
|
||||||
|
Room room = new Room();
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
room.setRoomNumber("502");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addRoom() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteRoom() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateRoom() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void allRoom() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findRoomByNumber() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findRoomByStatus() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findRoomByType() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package cn.mafangui.hotel.service.impl;
|
||||||
|
|
||||||
|
import cn.mafangui.hotel.entity.Room;
|
||||||
|
import cn.mafangui.hotel.service.RoomService;
|
||||||
|
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 static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
public class RoomServiceImplTest {
|
||||||
|
Room room = new Room();
|
||||||
|
@Autowired
|
||||||
|
RoomService roomService;
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
room.setRoomId(4);
|
||||||
|
room.setRoomNumber("102");
|
||||||
|
room.setRoomFloor(1);
|
||||||
|
room.setRoomDiscount(10.0);
|
||||||
|
room.setRoomPrice(119.0);
|
||||||
|
room.setRoomStatus("已预订");
|
||||||
|
room.setRoomType(1);
|
||||||
|
room.setTypeName("单人房");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addRoom() {
|
||||||
|
Assert.assertEquals(1, roomService.addRoom(room));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteRoom() {
|
||||||
|
Assert.assertEquals(1, roomService.deleteRoom(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteRoom1() {
|
||||||
|
Assert.assertEquals(1, roomService.deleteRoom("100"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateRoom() {
|
||||||
|
Assert.assertEquals(1, roomService.updateRoom(room));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findById() {
|
||||||
|
Assert.assertEquals("102", roomService.findById(4).getRoomNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByNumber() {
|
||||||
|
Assert.assertEquals("单人房", roomService.findByNumber("102").getTypeName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByStatus() {
|
||||||
|
Assert.assertTrue(!roomService.findByStatus("空闲").isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByType() {
|
||||||
|
Assert.assertTrue(!roomService.findByType("单人房").isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAll() {
|
||||||
|
Assert.assertTrue(roomService.findAll().size() == 3);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user