From 4680160c2f6b4cb15c620e0d2fa7383f1e8639c4 Mon Sep 17 00:00:00 2001 From: freeebird <1032796097@qq.com> Date: Mon, 5 Nov 2018 19:13:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=88=BF=E9=97=B4=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hotel/controller/RoomController.java | 14 ++-- .../hotel/controller/RoomTypeController.java | 64 ++++++++++++------- .../hotel/controller/WorkerController.java | 11 +++- .../cn/mafangui/hotel/entity/RoomType.java | 23 ++++++- .../hotel/service/RoomTypeService.java | 4 ++ .../service/impl/RoomTypeServiceImpl.java | 12 +++- .../cn/mafangui/hotel/utils/finalString.java | 6 ++ .../mybatis/mapper/RoomTypeMapper.xml | 9 +-- 8 files changed, 101 insertions(+), 42 deletions(-) create mode 100644 src/main/java/cn/mafangui/hotel/utils/finalString.java diff --git a/src/main/java/cn/mafangui/hotel/controller/RoomController.java b/src/main/java/cn/mafangui/hotel/controller/RoomController.java index b238e84..01578d4 100644 --- a/src/main/java/cn/mafangui/hotel/controller/RoomController.java +++ b/src/main/java/cn/mafangui/hotel/controller/RoomController.java @@ -8,10 +8,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.awt.print.PrinterException; +import java.util.HashMap; import java.util.List; @RestController -@RequestMapping(value = "room") +@RequestMapping(value = "roomInfo") public class RoomController { @Autowired @@ -91,12 +92,11 @@ public class RoomController { * @return */ @RequestMapping(value = "/all") - public List allRoom(){ - try { - return roomService.findAll(); - }catch (Exception e){ - return null; - } + public HashMap allRoom(){ + HashMap result = new HashMap(); + result.put("data",roomService.findAll()); + result.put("code",20000); + return result; } /** diff --git a/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java b/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java index 13b67a7..60c45b4 100644 --- a/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java +++ b/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java @@ -7,11 +7,13 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import java.util.List; +import java.util.HashMap; @RestController @RequestMapping(value = "/roomType") public class RoomTypeController { + private final String CODE = "code"; + private final String DATA = "data"; @Autowired private RoomTypeService roomTypeService; @@ -22,26 +24,36 @@ public class RoomTypeController { * @param typeName * @param bookingPrice * @param bookingDiscount + * @param remark * @return */ @RequestMapping(method = RequestMethod.POST,value = "/add") - public int addNewType(int roomType,String typeName,double bookingPrice,double bookingDiscount){ - RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount); - return roomTypeService.addRoomType(rt); + public HashMap addNewType(int roomType,String typeName,double bookingPrice,double bookingDiscount,String remark){ + HashMap result = new HashMap(); + result.put(CODE,20000); + RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount,remark); + result.put(DATA,roomTypeService.addRoomType(rt)); + return result; } /** + * 根据id * 删除房间类型 - * @param roomType - * @param typeName + * @param typeId * @return */ @RequestMapping(method = RequestMethod.POST,value = "/del") - public int delType(int roomType,String typeName){ - RoomType rt = new RoomType(); - rt.setRoomType(roomType); - rt.setTypeName(typeName); - return roomTypeService.delRoomType(rt); + public HashMap delType(int typeId){ + HashMap result = new HashMap(); + result.put(CODE,20000); + result.put(DATA,roomTypeService.delById(typeId)); + return result; + } + + public HashMap massDeletion(int[] typeId){ + HashMap result = new HashMap(); + result.put(CODE,20000); + return result; } /** @@ -53,21 +65,26 @@ public class RoomTypeController { * @return */ @RequestMapping(method = RequestMethod.POST,value = "/update") - public int updateType(int roomType,String typeName,double bookingPrice,double bookingDiscount){ - RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount); - return roomTypeService.updateRoomType(rt); + public HashMap updateType(int typeId,int roomType,String typeName,double bookingPrice,double bookingDiscount,String remark){ + HashMap result = new HashMap(); + result.put(CODE,20000); + RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount,remark); + rt.setTypeId(typeId); + result.put(DATA,roomTypeService.updateRoomType(rt)); + return result; } /** * 查询房间类型 - * @param roomType + * @param typeId * @return */ - @RequestMapping(value = "/query") - public RoomType findByRoomType(int roomType){ - RoomType rt = new RoomType(); - rt.setRoomType(roomType); - return roomTypeService.selectByName(rt); + @RequestMapping(value = "/withId") + public HashMap findByRoomType(int typeId){ + HashMap result = new HashMap(); + result.put(CODE,20000); + result.put(DATA, roomTypeService.selectById(typeId)); + return result; } /** @@ -75,7 +92,10 @@ public class RoomTypeController { * @return */ @RequestMapping(value = "/all") - public List findAllRoomType(){ - return roomTypeService.findAllType(); + public HashMap findAllRoomType(){ + HashMap result = new HashMap(); + result.put("code",20000); + result.put("data",roomTypeService.findAllType()); + return result; } } diff --git a/src/main/java/cn/mafangui/hotel/controller/WorkerController.java b/src/main/java/cn/mafangui/hotel/controller/WorkerController.java index d5b29a0..519d637 100644 --- a/src/main/java/cn/mafangui/hotel/controller/WorkerController.java +++ b/src/main/java/cn/mafangui/hotel/controller/WorkerController.java @@ -6,11 +6,15 @@ 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; + +import java.util.HashMap; import java.util.List; @RestController @RequestMapping(value = "/worker") public class WorkerController { + private final String CODE = "code"; + private final String DATA = "data"; @Autowired private WorkerService workerService; @@ -87,8 +91,11 @@ public class WorkerController { * @return */ @RequestMapping(value = "/all") - public List findAllWorkers(){ - return workerService.findAllWorker(); + public HashMap findAllWorkers(){ + HashMap result = new HashMap(); + result.put(CODE,20000); + result.put(DATA,workerService.findAllWorker()); + return result; } } diff --git a/src/main/java/cn/mafangui/hotel/entity/RoomType.java b/src/main/java/cn/mafangui/hotel/entity/RoomType.java index bb0302b..54ef2f3 100644 --- a/src/main/java/cn/mafangui/hotel/entity/RoomType.java +++ b/src/main/java/cn/mafangui/hotel/entity/RoomType.java @@ -1,6 +1,10 @@ package cn.mafangui.hotel.entity; -import java.math.BigDecimal; + +import cn.mafangui.hotel.utils.MyDateTimeFormat; + +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; public class RoomType { @@ -14,10 +18,13 @@ public class RoomType { private Double bookingDiscount; + private String remark; + private Date createTime; private Date updateTime; + public Integer getTypeId() { return typeId; } @@ -71,14 +78,23 @@ public class RoomType { } public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; + this.updateTime = updateTime; } - public RoomType(Integer roomType, String typeName, Double bookingPrice, Double bookingDiscount) { + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public RoomType(Integer roomType, String typeName, Double bookingPrice, Double bookingDiscount,String remark) { this.roomType = roomType; this.typeName = typeName; this.bookingPrice = bookingPrice; this.bookingDiscount = bookingDiscount; + this.remark = remark; } public RoomType(){} @@ -90,6 +106,7 @@ public class RoomType { ", typeName='" + typeName + '\'' + ", bookingPrice=" + bookingPrice + ", bookingDiscount=" + bookingDiscount + + ", remark='" + remark + '\'' + ", createTime=" + createTime + ", updateTime=" + updateTime + '}'; diff --git a/src/main/java/cn/mafangui/hotel/service/RoomTypeService.java b/src/main/java/cn/mafangui/hotel/service/RoomTypeService.java index 33d1924..9800dbe 100644 --- a/src/main/java/cn/mafangui/hotel/service/RoomTypeService.java +++ b/src/main/java/cn/mafangui/hotel/service/RoomTypeService.java @@ -10,9 +10,13 @@ public interface RoomTypeService { int delRoomType(RoomType roomType); + int delById(int typeId); + int updateRoomType(RoomType roomType); RoomType selectByName(RoomType roomType); + RoomType selectById(int typeId); + List findAllType(); } diff --git a/src/main/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImpl.java b/src/main/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImpl.java index 2739de7..9dfa266 100644 --- a/src/main/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImpl.java +++ b/src/main/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImpl.java @@ -23,9 +23,14 @@ public class RoomTypeServiceImpl implements RoomTypeService { return roomTypeMapper.deleteByRoomType(roomType); } + @Override + public int delById(int typeId) { + return roomTypeMapper.deleteByPrimaryKey(typeId); + } + @Override public int updateRoomType(RoomType roomType) { - return roomTypeMapper.updateByRoomTypeSelective(roomType); + return roomTypeMapper.updateByPrimaryKeySelective(roomType); } @Override @@ -33,6 +38,11 @@ public class RoomTypeServiceImpl implements RoomTypeService { return roomTypeMapper.selectByRoomType(roomType); } + @Override + public RoomType selectById(int typeId) { + return roomTypeMapper.selectByPrimaryKey(typeId); + } + @Override public List findAllType() { return roomTypeMapper.findAll(); diff --git a/src/main/java/cn/mafangui/hotel/utils/finalString.java b/src/main/java/cn/mafangui/hotel/utils/finalString.java new file mode 100644 index 0000000..ba6e2ad --- /dev/null +++ b/src/main/java/cn/mafangui/hotel/utils/finalString.java @@ -0,0 +1,6 @@ +package cn.mafangui.hotel.utils; + +public class finalString { + private final String CODE = "code"; + private final String DATA = "data"; +} diff --git a/src/main/resources/mybatis/mapper/RoomTypeMapper.xml b/src/main/resources/mybatis/mapper/RoomTypeMapper.xml index fa5f8d5..2025c39 100644 --- a/src/main/resources/mybatis/mapper/RoomTypeMapper.xml +++ b/src/main/resources/mybatis/mapper/RoomTypeMapper.xml @@ -8,7 +8,7 @@ - + type_id, room_type, type_name, booking_price, booking_discount, create_time, update_time @@ -90,12 +90,7 @@ booking_discount = #{bookingDiscount,jdbcType=REAL}, - - create_time = #{createTime,jdbcType=TIMESTAMP}, - - - update_time = #{updateTime,jdbcType=TIMESTAMP}, - + update_time = now(), where type_id = #{typeId,jdbcType=INTEGER}