Compare commits
No commits in common. 'master' and 'main' have entirely different histories.
@ -0,0 +1,23 @@
|
|||||||
|
package com.test.bean;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class RoomType {
|
||||||
|
private Long typeId;
|
||||||
|
private String roomType;
|
||||||
|
private String remark;
|
||||||
|
private double price;
|
||||||
|
private String cover;
|
||||||
|
private int bedNum;
|
||||||
|
private Integer remain;
|
||||||
|
private int windows;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.test.controller;
|
||||||
|
|
||||||
|
import com.test.bean.Result;
|
||||||
|
import com.test.bean.RoomType;
|
||||||
|
import com.test.service.RoomTypeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/roomType")
|
||||||
|
public class RoomTypeController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RoomTypeService roomTypeService;
|
||||||
|
|
||||||
|
// @GetMapping("/")
|
||||||
|
public Result getAllRoomType(){
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getRoomTypeByPage")
|
||||||
|
public Result getRoomTypeByPage(@RequestParam(defaultValue = "1") int page,
|
||||||
|
@RequestParam(defaultValue = "5") int pageSize){
|
||||||
|
return Result.success(roomTypeService.getRoomTypeByPage(page, pageSize));
|
||||||
|
|
||||||
|
}
|
||||||
|
@GetMapping
|
||||||
|
public Result getRoomTypeById(@RequestParam Long id){
|
||||||
|
RoomType roomType = roomTypeService.getRoomTypeById(id);
|
||||||
|
if (roomType != null && roomType.getTypeId() == null ){
|
||||||
|
return Result.error("此房型不存在!");
|
||||||
|
}
|
||||||
|
return Result.success(roomType);
|
||||||
|
}
|
||||||
|
@PostMapping
|
||||||
|
public Result addRoomType(@RequestBody RoomType roomType){
|
||||||
|
if (roomTypeService.addRoomType(roomType)){
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
return Result.error("添加失败!");
|
||||||
|
}
|
||||||
|
@PutMapping
|
||||||
|
public Result updateRoomType(@RequestBody RoomType roomType){
|
||||||
|
if (roomTypeService.updateRoomType(roomType)){
|
||||||
|
return Result.success(roomTypeService.getRoomTypeById(roomType.getTypeId()));
|
||||||
|
}
|
||||||
|
return Result.error("修改失败!");
|
||||||
|
|
||||||
|
}
|
||||||
|
@DeleteMapping
|
||||||
|
public Result deleteRoomType(@RequestParam Long id){
|
||||||
|
if (roomTypeService.deleteRoomType(id)){
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
return Result.error("删除失败!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.test.mapper;
|
||||||
|
|
||||||
|
import com.test.bean.RoomType;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface RoomTypeMapper {
|
||||||
|
|
||||||
|
@Select("select count(*) from room_type")
|
||||||
|
public long getRoomTypeCount();
|
||||||
|
|
||||||
|
// start为起始索引
|
||||||
|
@Select("select * from room_type limit #{start}, #{pageSize}")
|
||||||
|
public ArrayList<RoomType> getRoomTypeByPage(int start, int pageSize);
|
||||||
|
|
||||||
|
@Select("select * from room_type")
|
||||||
|
public ArrayList<RoomType> getRoomType();
|
||||||
|
|
||||||
|
@Insert("insert into room_type(room_type, remark,price, cover,bed_num, remain,windows, create_time, update_time) VALUE (#{roomType}, #{remark}, #{price}, #{cover}, #{bedNum}, #{remain}, #{windows}, #{createTime}, #{updateTime})")
|
||||||
|
public boolean addRoomType(RoomType roomType);
|
||||||
|
|
||||||
|
@Select("select * from room_type where type_id = #{id}")
|
||||||
|
RoomType getRoomTypeById(Long id);
|
||||||
|
|
||||||
|
@Update("update room_type set room_type = #{roomType}, remark = #{remark}, price = #{price}, cover = #{cover}, bed_num = #{bedNum}, remain = #{remain}, windows = #{windows}, update_time = #{updateTime} where type_id = #{typeId}")
|
||||||
|
boolean updateRoomType(RoomType roomType);
|
||||||
|
|
||||||
|
@Delete("delete from room_type where type_id = #{id}")
|
||||||
|
boolean deleteRoomType(Long id);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.test.service;
|
||||||
|
|
||||||
|
import com.test.bean.PageBean;
|
||||||
|
import com.test.bean.RoomType;
|
||||||
|
|
||||||
|
|
||||||
|
public interface RoomTypeService {
|
||||||
|
|
||||||
|
|
||||||
|
PageBean getRoomTypeByPage(int page, int pageSize);
|
||||||
|
|
||||||
|
boolean addRoomType(RoomType roomType);
|
||||||
|
|
||||||
|
RoomType getRoomTypeById(Long id);
|
||||||
|
|
||||||
|
boolean updateRoomType(RoomType roomType);
|
||||||
|
|
||||||
|
boolean deleteRoomType(Long id);
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package com.test.service.impl;
|
package com.test.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.test.bean.Order;
|
import com.test.bean.Order;
|
||||||
import com.test.bean.PageBean;
|
import com.test.bean.PageBean;
|
||||||
import com.test.mapper.OrderMapper;
|
import com.test.mapper.OrderMapper;
|
||||||
|
import com.test.mapper.RoomTypeMapper;
|
||||||
import com.test.service.OrderService;
|
import com.test.service.OrderService;
|
||||||
import com.test.util.DateTimeUtils;
|
import com.test.util.DateTimeUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.test.service.impl;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.test.bean.PageBean;
|
||||||
|
import com.test.bean.RoomType;
|
||||||
|
import com.test.mapper.RoomTypeMapper;
|
||||||
|
import com.test.service.RoomTypeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RoomTypeServiceImpl implements RoomTypeService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RoomTypeMapper roomTypeMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageBean getRoomTypeByPage(int page, int pageSize) {
|
||||||
|
PageHelper.startPage(page, pageSize);
|
||||||
|
ArrayList<RoomType> roomType = roomTypeMapper.getRoomType();
|
||||||
|
Page<RoomType> roomTypePage = (Page<RoomType>) roomType;
|
||||||
|
return new PageBean(roomTypePage.getTotal(), roomTypePage.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addRoomType(RoomType roomType) {
|
||||||
|
roomType.setCreateTime(LocalDateTime.now());
|
||||||
|
roomType.setUpdateTime(LocalDateTime.now());
|
||||||
|
return roomTypeMapper.addRoomType(roomType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RoomType getRoomTypeById(Long id) {
|
||||||
|
return roomTypeMapper.getRoomTypeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateRoomType(RoomType roomType) {
|
||||||
|
roomType.setUpdateTime(LocalDateTime.now());
|
||||||
|
return roomTypeMapper.updateRoomType(roomType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteRoomType(Long id) {
|
||||||
|
return roomTypeMapper.deleteRoomType(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
Subproject commit 5c98ecced01b30a211ac291ab57e94d611705211
|
|
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
Subproject commit b74a1b10fea87ef0a55e24ea939fe330298aa241
|
@ -1 +0,0 @@
|
|||||||
Subproject commit 120a599f68718f4d7c2dc966bb526095e3c726fe
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue