提交 85acb73d 编写于 作者: 刘兴
...@@ -8,4 +8,5 @@ import java.util.List; ...@@ -8,4 +8,5 @@ import java.util.List;
public interface CustomerDao { public interface CustomerDao {
List<Customer> queryAll(); List<Customer> queryAll();
int updataByCustomerIdToremainder(@Param("money") double money, @Param("id") int id); int updataByCustomerIdToremainder(@Param("money") double money, @Param("id") int id);
Customer queryByCustomer(int CustomerId);
} }
package com.hqyj.seven.dao; package com.hqyj.seven.dao;
import com.hqyj.seven.pojo.Enter; import com.hqyj.seven.pojo.Enter;
import org.apache.ibatis.annotations.Param;
public interface EnterDao { public interface EnterDao {
int inserintoEnter(Enter enter); int inserintoEnter(Enter enter);
Enter queryByHouseIdAndTime(@Param("HouseId") int HouseId, @Param("time") String time);
} }
...@@ -6,4 +6,5 @@ import com.hqyj.seven.pojo.Fee; ...@@ -6,4 +6,5 @@ import com.hqyj.seven.pojo.Fee;
public interface Feedao { public interface Feedao {
//插入数据 //插入数据
int inserintoFee(Fee fee); int inserintoFee(Fee fee);
} }
package com.hqyj.seven.service; package com.hqyj.seven.service;
import com.hqyj.seven.pojo.Customer;
public interface CustomerService { public interface CustomerService {
//住房更新金额
int updateByNameToRemainder(double money, int id); int updateByNameToRemainder(double money, int id);
//按id查找用户
Customer queryById(int customerId);
} }
...@@ -5,4 +5,6 @@ import com.hqyj.seven.pojo.Enter; ...@@ -5,4 +5,6 @@ import com.hqyj.seven.pojo.Enter;
public interface EnterService { public interface EnterService {
int insertEnter(Enter enter); int insertEnter(Enter enter);
//安照房间号和住房时间查找住房id
Enter queryByHouseIdAndTime(int CustomerId, String time);
} }
package com.hqyj.seven.service; package com.hqyj.seven.service;
import com.hqyj.seven.pojo.Enter;
import com.hqyj.seven.pojo.Fee; import com.hqyj.seven.pojo.Fee;
public interface FeeService { public interface FeeService {
//插入数据 //插入数据
int insertFee(Fee fee); int insertFee(Fee fee);
//安照房间号和住房时间查找住房id
} }
...@@ -4,6 +4,7 @@ import com.hqyj.seven.pojo.Enter; ...@@ -4,6 +4,7 @@ import com.hqyj.seven.pojo.Enter;
import com.hqyj.seven.pojo.House; import com.hqyj.seven.pojo.House;
import com.hqyj.seven.pojo.User; import com.hqyj.seven.pojo.User;
import java.text.ParseException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -27,5 +28,5 @@ public interface HouseService { ...@@ -27,5 +28,5 @@ public interface HouseService {
//删除客房 //删除客房
int deleteHouseI(int house_id); int deleteHouseI(int house_id);
//住房功能 //住房功能
int checkIn( int customerId,String name,int day); public Map<String, Object> checkIn(int customerId, String name,int day,int numberOfPeople,int userId) throws ParseException;
} }
package com.hqyj.seven.service.impl; package com.hqyj.seven.service.impl;
import com.hqyj.seven.dao.CustomerDao; import com.hqyj.seven.dao.CustomerDao;
import com.hqyj.seven.pojo.Customer;
import com.hqyj.seven.service.CustomerService; import com.hqyj.seven.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -9,9 +10,13 @@ import org.springframework.stereotype.Service; ...@@ -9,9 +10,13 @@ import org.springframework.stereotype.Service;
public class CustomerServiceImpl implements CustomerService { public class CustomerServiceImpl implements CustomerService {
@Autowired @Autowired
private CustomerDao customerDao; private CustomerDao customerDao;
@Override @Override
public int updateByNameToRemainder(double money, int id) { public int updateByNameToRemainder(double money, int id) {
return customerDao.updataByCustomerIdToremainder(money,id); return customerDao.updataByCustomerIdToremainder(money,id);
}
//按用户id查找信息
@Override
public Customer queryById(int customerId) {
return customerDao.queryByCustomer(customerId);
} }
} }
...@@ -15,4 +15,8 @@ public class EnterServiceImpl implements EnterService { ...@@ -15,4 +15,8 @@ public class EnterServiceImpl implements EnterService {
public int insertEnter(Enter enter) { public int insertEnter(Enter enter) {
return enterDao.inserintoEnter(enter); return enterDao.inserintoEnter(enter);
} }
@Override
public Enter queryByHouseIdAndTime(int CustomerId, String time) {
return enterDao.queryByHouseIdAndTime(CustomerId,time);
}
} }
package com.hqyj.seven.service.impl; package com.hqyj.seven.service.impl;
import com.hqyj.seven.dao.Feedao; import com.hqyj.seven.dao.Feedao;
import com.hqyj.seven.pojo.Enter;
import com.hqyj.seven.pojo.Fee; import com.hqyj.seven.pojo.Fee;
import com.hqyj.seven.service.FeeService; import com.hqyj.seven.service.FeeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -17,4 +18,6 @@ public class FeeServiceImpl implements FeeService { ...@@ -17,4 +18,6 @@ public class FeeServiceImpl implements FeeService {
return feedao.inserintoFee(fee); return feedao.inserintoFee(fee);
} }
} }
package com.hqyj.seven.service.impl; package com.hqyj.seven.service.impl;
import com.hqyj.seven.dao.CustomerDao;
import com.hqyj.seven.dao.EnterDao;
import com.hqyj.seven.dao.Feedao;
import com.hqyj.seven.dao.HouseDao; import com.hqyj.seven.dao.HouseDao;
import com.hqyj.seven.pojo.Customer;
import com.hqyj.seven.pojo.Enter; import com.hqyj.seven.pojo.Enter;
import com.hqyj.seven.pojo.Fee;
import com.hqyj.seven.pojo.House; import com.hqyj.seven.pojo.House;
import com.hqyj.seven.service.HouseService; import com.hqyj.seven.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -15,7 +23,12 @@ import java.util.Map; ...@@ -15,7 +23,12 @@ import java.util.Map;
public class HouseServiceImpl implements HouseService { public class HouseServiceImpl implements HouseService {
@Autowired @Autowired
private HouseDao houseDao; private HouseDao houseDao;
@Autowired
private CustomerDao customerDao;
@Autowired
private EnterDao enterDao;
@Autowired
private Feedao feedao;
@Override @Override
public Map<String, Object> reservation(int customerId, String name ) { public Map<String, Object> reservation(int customerId, String name ) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
...@@ -65,8 +78,91 @@ public class HouseServiceImpl implements HouseService { ...@@ -65,8 +78,91 @@ public class HouseServiceImpl implements HouseService {
return houseDao.deleteHouse(house_id); return houseDao.deleteHouse(house_id);
} }
@Override @Override
public int checkIn(int customerId, String name,int day) { //参数分别为顾客id,房间name,入住人数,userID
return houseDao.updateByHouseNametocheckIn(customerId,name,day); public Map<String, Object> checkIn(int customerId, String name,int day,int numberOfPeople,int userId) throws ParseException {
Map<String, Object> result = new HashMap<>();
//按照name获取house数据
House house=houseDao.queryByHousename(name);
//按照id获取customer数据
Customer customer=customerDao.queryByCustomer(customerId);
Date time=new Date();
//更新字符串 如果numberOfPeople=2,字符串则更新为2人已入住
String str1=numberOfPeople+"人已入住";
//预定时间+day为预定退房时间,实际退房时间 退房时更新
int day2 = day*24*60*60*1000;
long time2=time.getTime()+day2;
Date time3=new Date(time2);
System.out.println(time);
//如果房间是空闲则之间可以入住
if (house.getState().equals("空闲"))
{
double money=house.getPrice()*day;
//如果余额不足则会提示
if (money>customer.getRemainder())
result.put("用户余额不足可以尝试充值或者减少预定住房时间",-1);
else {
//更新顾客表余额的数据
customerDao.updataByCustomerIdToremainder(money,customerId);
//插入顾客表
enterDao.inserintoEnter(new Enter(house.getHouseId(),customerId,
numberOfPeople,time,time3,null,money,1,userId,"已结账",house.getPrice()));
//设置时间格式为yyyy-MM-dd HH:mm:ss以便插入
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
//规范化插入表时的时间和获取的时间有点误差
long day3 = time.getTime()+500;
Date time4=new Date(day3);
Enter enter= enterDao.queryByHouseIdAndTime(house.getHouseId(),sdf.format(time4));
//插入缴费表
feedao.inserintoFee(new Fee( enter.getEnter_id(),"缴费",customerId,money,house.getHouseId(),
str1,userId,"会员卡扣费"));
//更新房间为入住
houseDao.updateByHouseNametocheckIn(customerId,name,day);
result.put("入住成功",1);
}
}
else {
if ((house.getState().equals("已定"))) {
//判断预定房间号的顾客id和现在的顾客id是否一致
if (house.getCustomerId() == customerId) {
double money = house.getPrice() * day;
//如果余额不足则会提示
if (money > customer.getRemainder())
result.put("用户余额不足可以尝试充值或者减少预定住房时间", -1);
else {
//更新顾客表余额的数据
customerDao.updataByCustomerIdToremainder(money, customerId);
//插入顾客表
enterDao.inserintoEnter(new Enter(house.getHouseId(), customerId,
numberOfPeople, time, time3, null, money, 1, userId, "已结账", house.getPrice()));
//设置时间格式为yyyy-MM-dd HH:mm:ss以便插入
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//规范化插入表时的时间和获取的时间有点误差
long day3 = time.getTime() + 500;
Date time4 = new Date(day3);
Enter enter = enterDao.queryByHouseIdAndTime(house.getHouseId(), sdf.format(time4));
//插入缴费表
feedao.inserintoFee(new Fee(enter.getEnter_id(), "缴费", customerId, money, house.getHouseId(),
str1, userId, "会员卡扣费"));
//更新房间为入住
houseDao.updateByHouseNametocheckIn(customerId, name, day);
result.put("入住预定的房间成功", 2);
}
} else {
result.put("此房间不是该顾客预定的哟", -3);
}
} else {
result.put("房间预定或者已经入住", -2);
}
}
return result;
} }
} }
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
<update id="updataByCustomerIdToremainder" parameterType="com.hqyj.seven.pojo.Customer"> <update id="updataByCustomerIdToremainder" parameterType="com.hqyj.seven.pojo.Customer">
update customer set remainder=remainder-#{money} where customer_id=#{id} update customer set remainder=remainder-#{money} where customer_id=#{id}
</update> </update>
<select id="queryByCustomer" resultType="com.hqyj.seven.pojo.Customer">
select * from customer where customer_id=#{CustomerId}
</select>
<!-- <resultMap id="customerBaseResultMap" type="com.hqyj.seven.pojo.Customer">--> <!-- <resultMap id="customerBaseResultMap" type="com.hqyj.seven.pojo.Customer">-->
<!-- <id column="customer_id" property="customerId" />--> <!-- <id column="customer_id" property="customerId" />-->
<!-- <result column="cname" property="name" />--> <!-- <result column="cname" property="name" />-->
......
...@@ -11,5 +11,7 @@ ...@@ -11,5 +11,7 @@
(#{house_id},#{customer_id},#{customer_info},#{start_time},#{end_time_estimate},#{end_time_actual},#{fee_total}, (#{house_id},#{customer_id},#{customer_info},#{start_time},#{end_time_estimate},#{end_time_actual},#{fee_total},
#{fee_info},#{user_id},#{state},#{price}) #{fee_info},#{user_id},#{state},#{price})
</insert> </insert>
<select id="queryByHouseIdAndTime" resultType="com.hqyj.seven.pojo.Enter">
select * from enter where house_id=#{HouseId} and start_time=#{time}
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册