更新房间类型的接口

This commit is contained in:
freeebird 2018-11-05 19:13:40 +08:00
parent 6063878687
commit 4680160c2f
8 changed files with 101 additions and 42 deletions

View File

@ -8,10 +8,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.awt.print.PrinterException; import java.awt.print.PrinterException;
import java.util.HashMap;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping(value = "room") @RequestMapping(value = "roomInfo")
public class RoomController { public class RoomController {
@Autowired @Autowired
@ -91,12 +92,11 @@ public class RoomController {
* @return * @return
*/ */
@RequestMapping(value = "/all") @RequestMapping(value = "/all")
public List<Room> allRoom(){ public HashMap allRoom(){
try { HashMap result = new HashMap();
return roomService.findAll(); result.put("data",roomService.findAll());
}catch (Exception e){ result.put("code",20000);
return null; return result;
}
} }
/** /**

View File

@ -7,11 +7,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.HashMap;
@RestController @RestController
@RequestMapping(value = "/roomType") @RequestMapping(value = "/roomType")
public class RoomTypeController { public class RoomTypeController {
private final String CODE = "code";
private final String DATA = "data";
@Autowired @Autowired
private RoomTypeService roomTypeService; private RoomTypeService roomTypeService;
@ -22,26 +24,36 @@ public class RoomTypeController {
* @param typeName * @param typeName
* @param bookingPrice * @param bookingPrice
* @param bookingDiscount * @param bookingDiscount
* @param remark
* @return * @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 HashMap addNewType(int roomType,String typeName,double bookingPrice,double bookingDiscount,String remark){
RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount); HashMap result = new HashMap();
return roomTypeService.addRoomType(rt); 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 typeId
* @param typeName
* @return * @return
*/ */
@RequestMapping(method = RequestMethod.POST,value = "/del") @RequestMapping(method = RequestMethod.POST,value = "/del")
public int delType(int roomType,String typeName){ public HashMap delType(int typeId){
RoomType rt = new RoomType(); HashMap result = new HashMap();
rt.setRoomType(roomType); result.put(CODE,20000);
rt.setTypeName(typeName); result.put(DATA,roomTypeService.delById(typeId));
return roomTypeService.delRoomType(rt); 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 * @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 HashMap updateType(int typeId,int roomType,String typeName,double bookingPrice,double bookingDiscount,String remark){
RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount); HashMap result = new HashMap();
return roomTypeService.updateRoomType(rt); 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 * @return
*/ */
@RequestMapping(value = "/query") @RequestMapping(value = "/withId")
public RoomType findByRoomType(int roomType){ public HashMap findByRoomType(int typeId){
RoomType rt = new RoomType(); HashMap result = new HashMap();
rt.setRoomType(roomType); result.put(CODE,20000);
return roomTypeService.selectByName(rt); result.put(DATA, roomTypeService.selectById(typeId));
return result;
} }
/** /**
@ -75,7 +92,10 @@ public class RoomTypeController {
* @return * @return
*/ */
@RequestMapping(value = "/all") @RequestMapping(value = "/all")
public List<RoomType> findAllRoomType(){ public HashMap findAllRoomType(){
return roomTypeService.findAllType(); HashMap result = new HashMap();
result.put("code",20000);
result.put("data",roomTypeService.findAllType());
return result;
} }
} }

View File

@ -6,11 +6,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping(value = "/worker") @RequestMapping(value = "/worker")
public class WorkerController { public class WorkerController {
private final String CODE = "code";
private final String DATA = "data";
@Autowired @Autowired
private WorkerService workerService; private WorkerService workerService;
@ -87,8 +91,11 @@ public class WorkerController {
* @return * @return
*/ */
@RequestMapping(value = "/all") @RequestMapping(value = "/all")
public List<Worker> findAllWorkers(){ public HashMap findAllWorkers(){
return workerService.findAllWorker(); HashMap result = new HashMap();
result.put(CODE,20000);
result.put(DATA,workerService.findAllWorker());
return result;
} }
} }

View File

@ -1,6 +1,10 @@
package cn.mafangui.hotel.entity; 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; import java.util.Date;
public class RoomType { public class RoomType {
@ -14,10 +18,13 @@ public class RoomType {
private Double bookingDiscount; private Double bookingDiscount;
private String remark;
private Date createTime; private Date createTime;
private Date updateTime; private Date updateTime;
public Integer getTypeId() { public Integer getTypeId() {
return typeId; return typeId;
} }
@ -71,14 +78,23 @@ public class RoomType {
} }
public void setUpdateTime(Date updateTime) { 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.roomType = roomType;
this.typeName = typeName; this.typeName = typeName;
this.bookingPrice = bookingPrice; this.bookingPrice = bookingPrice;
this.bookingDiscount = bookingDiscount; this.bookingDiscount = bookingDiscount;
this.remark = remark;
} }
public RoomType(){} public RoomType(){}
@ -90,6 +106,7 @@ public class RoomType {
", typeName='" + typeName + '\'' + ", typeName='" + typeName + '\'' +
", bookingPrice=" + bookingPrice + ", bookingPrice=" + bookingPrice +
", bookingDiscount=" + bookingDiscount + ", bookingDiscount=" + bookingDiscount +
", remark='" + remark + '\'' +
", createTime=" + createTime + ", createTime=" + createTime +
", updateTime=" + updateTime + ", updateTime=" + updateTime +
'}'; '}';

View File

@ -10,9 +10,13 @@ public interface RoomTypeService {
int delRoomType(RoomType roomType); int delRoomType(RoomType roomType);
int delById(int typeId);
int updateRoomType(RoomType roomType); int updateRoomType(RoomType roomType);
RoomType selectByName(RoomType roomType); RoomType selectByName(RoomType roomType);
RoomType selectById(int typeId);
List<RoomType> findAllType(); List<RoomType> findAllType();
} }

View File

@ -23,9 +23,14 @@ public class RoomTypeServiceImpl implements RoomTypeService {
return roomTypeMapper.deleteByRoomType(roomType); return roomTypeMapper.deleteByRoomType(roomType);
} }
@Override
public int delById(int typeId) {
return roomTypeMapper.deleteByPrimaryKey(typeId);
}
@Override @Override
public int updateRoomType(RoomType roomType) { public int updateRoomType(RoomType roomType) {
return roomTypeMapper.updateByRoomTypeSelective(roomType); return roomTypeMapper.updateByPrimaryKeySelective(roomType);
} }
@Override @Override
@ -33,6 +38,11 @@ public class RoomTypeServiceImpl implements RoomTypeService {
return roomTypeMapper.selectByRoomType(roomType); return roomTypeMapper.selectByRoomType(roomType);
} }
@Override
public RoomType selectById(int typeId) {
return roomTypeMapper.selectByPrimaryKey(typeId);
}
@Override @Override
public List<RoomType> findAllType() { public List<RoomType> findAllType() {
return roomTypeMapper.findAll(); return roomTypeMapper.findAll();

View File

@ -0,0 +1,6 @@
package cn.mafangui.hotel.utils;
public class finalString {
private final String CODE = "code";
private final String DATA = "data";
}

View File

@ -8,7 +8,7 @@
<result column="booking_price" jdbcType="DOUBLE" property="bookingPrice" /> <result column="booking_price" jdbcType="DOUBLE" property="bookingPrice" />
<result column="booking_discount" jdbcType="DOUBLE" property="bookingDiscount" /> <result column="booking_discount" jdbcType="DOUBLE" property="bookingDiscount" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="DATE" property="updateTime" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
type_id, room_type, type_name, booking_price, booking_discount, create_time, update_time type_id, room_type, type_name, booking_price, booking_discount, create_time, update_time
@ -90,12 +90,7 @@
<if test="bookingDiscount != null"> <if test="bookingDiscount != null">
booking_discount = #{bookingDiscount,jdbcType=REAL}, booking_discount = #{bookingDiscount,jdbcType=REAL},
</if> </if>
<if test="createTime != null"> update_time = now(),
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set> </set>
where type_id = #{typeId,jdbcType=INTEGER} where type_id = #{typeId,jdbcType=INTEGER}
</update> </update>