mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
完成RoomTypeService类编写,通过单元测试
This commit is contained in:
parent
dbee98a4f0
commit
01475b6215
@ -3,7 +3,7 @@ package cn.mafangui.hotel.entity;
|
||||
import java.util.Date;
|
||||
|
||||
public class RoomType {
|
||||
private Long typeId;
|
||||
private Integer typeId;
|
||||
|
||||
private String roomType;
|
||||
|
||||
@ -25,11 +25,11 @@ public class RoomType {
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
public Long getTypeId() {
|
||||
public Integer getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(Long typeId) {
|
||||
public void setTypeId(Integer typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
@ -112,4 +112,21 @@ public class RoomType {
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RoomType{" +
|
||||
"typeId=" + typeId +
|
||||
", roomType='" + roomType + '\'' +
|
||||
", remark='" + remark + '\'' +
|
||||
", price=" + price +
|
||||
", discount=" + discount +
|
||||
", area=" + area +
|
||||
", bedNum=" + bedNum +
|
||||
", bedSize='" + bedSize + '\'' +
|
||||
", window=" + window +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,17 +1,25 @@
|
||||
package cn.mafangui.hotel.mapper;
|
||||
|
||||
import cn.mafangui.hotel.entity.RoomType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public interface RoomTypeMapper {
|
||||
int deleteByPrimaryKey(Long typeId);
|
||||
int deleteByPrimaryKey(Integer typeId);
|
||||
|
||||
int insert(RoomType record);
|
||||
|
||||
int insertSelective(RoomType record);
|
||||
|
||||
RoomType selectByPrimaryKey(Long typeId);
|
||||
RoomType selectByPrimaryKey(Integer typeId);
|
||||
|
||||
int updateByPrimaryKeySelective(RoomType record);
|
||||
|
||||
int updateByPrimaryKey(RoomType record);
|
||||
|
||||
List<RoomType> selectAll();
|
||||
|
||||
RoomType selectByRoomType(String roomType);
|
||||
}
|
@ -1,20 +1,20 @@
|
||||
package cn.mafangui.hotel.service;
|
||||
|
||||
import cn.mafangui.hotel.entity.RoomType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface RoomTypeService {
|
||||
|
||||
int addRoomType(RoomType roomType);
|
||||
int insert(RoomType roomType);
|
||||
|
||||
int delRoomType(RoomType roomType);
|
||||
int delete(int typeId);
|
||||
|
||||
int delById(int typeId);
|
||||
int update(RoomType roomType);
|
||||
|
||||
int updateRoomType(RoomType roomType);
|
||||
|
||||
RoomType selectByName(RoomType roomType);
|
||||
RoomType selectByName(String roomType);
|
||||
|
||||
RoomType selectById(int typeId);
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
package cn.mafangui.hotel.service.impl;
|
||||
|
||||
|
||||
import cn.mafangui.hotel.entity.RoomType;
|
||||
import cn.mafangui.hotel.mapper.RoomTypeMapper;
|
||||
import cn.mafangui.hotel.service.RoomTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class RoomTypeServiceImpl implements RoomTypeService {
|
||||
@Autowired
|
||||
private RoomTypeMapper roomTypeMapper;
|
||||
|
||||
@Override
|
||||
public int insert(RoomType roomType) {
|
||||
return roomTypeMapper.insertSelective(roomType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int typeId) {
|
||||
return roomTypeMapper.deleteByPrimaryKey(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(RoomType roomType) {
|
||||
return roomTypeMapper.updateByPrimaryKeySelective(roomType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoomType selectByName(String roomType) {
|
||||
return roomTypeMapper.selectByRoomType(roomType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoomType selectById(int typeId) {
|
||||
return roomTypeMapper.selectByPrimaryKey(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoomType> findAllType() {
|
||||
return roomTypeMapper.selectAll();
|
||||
}
|
||||
}
|
0
src/main/resources/TODO.md
Normal file
0
src/main/resources/TODO.md
Normal file
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.mafangui.hotel.mapper.RoomTypeMapper">
|
||||
<resultMap id="BaseResultMap" type="cn.mafangui.hotel.entity.RoomType">
|
||||
<id column="type_id" jdbcType="BIGINT" property="typeId" />
|
||||
<id column="type_id" jdbcType="INTEGER" property="typeId" />
|
||||
<result column="room_type" jdbcType="VARCHAR" property="roomType" />
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark" />
|
||||
<result column="price" jdbcType="DOUBLE" property="price" />
|
||||
@ -18,25 +18,31 @@
|
||||
type_id, room_type, remark, price, discount, area, bed_num, bed_size, window, create_time,
|
||||
update_time
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from room_type
|
||||
where type_id = #{typeId,jdbcType=BIGINT}
|
||||
where type_id = #{typeId,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||
<select id="selectAll" resultMap="BaseResultMap">
|
||||
select * from room_type
|
||||
</select>
|
||||
<select id="selectByRoomType" parameterType="String" resultMap="BaseResultMap">
|
||||
select * from room_type where room_type = #{roomType,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete from room_type
|
||||
where type_id = #{typeId,jdbcType=BIGINT}
|
||||
where type_id = #{typeId,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="cn.mafangui.hotel.entity.RoomType">
|
||||
insert into room_type (type_id, room_type, remark,
|
||||
price, discount, area,
|
||||
bed_num, bed_size, window,
|
||||
create_time, update_time)
|
||||
values (#{typeId,jdbcType=BIGINT}, #{roomType,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR},
|
||||
values (#{typeId,jdbcType=INTEGER}, #{roomType,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR},
|
||||
#{price,jdbcType=DOUBLE}, #{discount,jdbcType=DOUBLE}, #{area,jdbcType=INTEGER},
|
||||
#{bedNum,jdbcType=INTEGER}, #{bedSize,jdbcType=VARCHAR}, #{window,jdbcType=INTEGER},
|
||||
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
|
||||
now(), now())
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.RoomType">
|
||||
insert into room_type
|
||||
@ -68,16 +74,12 @@
|
||||
<if test="window != null">
|
||||
window,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="typeId != null">
|
||||
#{typeId,jdbcType=BIGINT},
|
||||
#{typeId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="roomType != null">
|
||||
#{roomType,jdbcType=VARCHAR},
|
||||
@ -103,12 +105,8 @@
|
||||
<if test="window != null">
|
||||
#{window,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
#{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
#{updateTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
now(),
|
||||
now(),
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.RoomType">
|
||||
@ -138,14 +136,9 @@
|
||||
<if test="window != null">
|
||||
window = #{window,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
update_time = now(),
|
||||
</set>
|
||||
where type_id = #{typeId,jdbcType=BIGINT}
|
||||
where type_id = #{typeId,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="cn.mafangui.hotel.entity.RoomType">
|
||||
update room_type
|
||||
@ -157,8 +150,7 @@
|
||||
bed_num = #{bedNum,jdbcType=INTEGER},
|
||||
bed_size = #{bedSize,jdbcType=VARCHAR},
|
||||
window = #{window,jdbcType=INTEGER},
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
||||
where type_id = #{typeId,jdbcType=BIGINT}
|
||||
update_time = now()
|
||||
where type_id = #{typeId,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
@ -0,0 +1,76 @@
|
||||
package cn.mafangui.hotel.service.impl;
|
||||
|
||||
import cn.mafangui.hotel.entity.RoomType;
|
||||
import org.junit.Assert;
|
||||
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 RoomTypeServiceImplTest {
|
||||
@Autowired
|
||||
RoomTypeServiceImpl roomTypeService;
|
||||
|
||||
@Test
|
||||
public void insert() {
|
||||
String typeName = "big";
|
||||
double price = 123;
|
||||
double discount = 12;
|
||||
int area = 10;
|
||||
int bedNum = 1;
|
||||
String bedSize = "15*12";
|
||||
int window = 0;
|
||||
RoomType roomType = new RoomType();
|
||||
roomType.setArea(area);
|
||||
roomType.setBedNum(bedNum);
|
||||
roomType.setBedSize(bedSize);
|
||||
roomType.setDiscount(discount);
|
||||
roomType.setPrice(price);
|
||||
roomType.setRoomType(typeName);
|
||||
roomType.setWindow(window);
|
||||
Assert.assertEquals(1,roomTypeService.insert(roomType));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete() {
|
||||
int id = 1;
|
||||
Assert.assertEquals(1,roomTypeService.delete(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update() {
|
||||
String typeName = "single";
|
||||
int id = 1;
|
||||
RoomType roomType = new RoomType();
|
||||
roomType.setTypeId(id);
|
||||
roomType.setRoomType(typeName);
|
||||
Assert.assertEquals(1,roomTypeService.update(roomType));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectByName() {
|
||||
String typeName = "single";
|
||||
int id = roomTypeService.selectByName(typeName).getTypeId();
|
||||
System.out.println(roomTypeService.selectByName(typeName));
|
||||
Assert.assertEquals(1,id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectById() {
|
||||
int id = 1;
|
||||
String typeName = roomTypeService.selectById(id).getRoomType();
|
||||
System.out.println(roomTypeService.selectById(id));
|
||||
Assert.assertEquals("single",typeName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllType() {
|
||||
System.out.println(roomTypeService.findAllType());
|
||||
Assert.assertNotNull(roomTypeService.findAllType());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user