/**
*预定场地信息
* @param params
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Object ordersFields(String params)throws Exception{
//获取预定信息
ResponseJson rs = new ResponseJson(StatusCode.SUCCESS.getCode(),StatusCode.SUCCESS.getMsg());
OrdersDTO ordersDTO = GsonUtils.str2T(params,OrdersDTO.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String rorderId = null;
String content = "";
if(ordersDTO.getStadiumTimePriceList()!=null){
for (StadiumTimePrice stadiumTimePrice:ordersDTO.getStadiumTimePriceList()){
//场地信息
StadiumFields stadiumFields = stadiumFieldsMapper.selectByPrimaryKey(stadiumTimePrice.getFieldId());
//允许预约最大人数
int num = Integer.parseInt(stadiumFields.getMaxNum());
//允许预约最小人数
int mnum = Integer.parseInt(stadiumFields.getMinNum());
//允许预约时限
int totime = Integer.parseInt(stadiumFields.getTogetherTime());
int sum = 0;
StadiumBook stadiumBook = new StadiumBook();
stadiumBook.setFieldId(stadiumTimePrice.getFieldId());
stadiumBook.setEnable(Enable.SUCCESS.getTips());
stadiumBook.setBookStartTime(stadiumTimePrice.getStartTm());
stadiumBook.setBookEndTime(stadiumTimePrice.getEndTm());
stadiumBook.setBookDate(stadiumTimePrice.getDate());
stadiumBook.setSportItem(ordersDTO.getSportItem());
stadiumBook.setFieldName(stadiumTimePrice.getFieldName());
List<StadiumBook> stadiumBooksList = stadiumBookMapper.selectAllTimeToBook(stadiumBook);
//统计当前预定人数
if(stadiumBooksList!=null){
for (StadiumBook std:stadiumBooksList){
sum=sum+std.getNum();
}
}
//统计预定的总人数
int usum = ordersDTO.getUserList().size();
if(ordersDTO.getNojoin()==null || "".equals(ordersDTO.getNojoin())){
usum++;
}
//预约的场地没达到预约上限,并且预约人数在场地设置范围内
if(num>sum && usum>=mnum && usum<=num ){
//判断预约时限
SimpleDateFormat ssdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
long a = ssdf.parse(ssdf.format(new Date())).getTime();
String sdate = stadiumTimePrice.getDate()+" "+stadiumTimePrice.getStartTm();
Date sdates = ssdf.parse(sdate);
long b = sdates.getTime();
long c = (b - a);
long d = totime*3600000;
if (c <= d) {
rs = new ResponseJson(StatusCode.FAIL.getCode(),"超过可预定时间,不可预定,请联系管理员!");
return result(rs);
}
stadiumBook.setVipId(ordersDTO.getMembershipId());
StadiumBook book = stadiumBookMapper.selectTimeToBook(stadiumBook);
if(book!=null && ( ordersDTO.getNojoin()==null || "".equals(ordersDTO.getNojoin()))){
rs = new ResponseJson(StatusCode.FAIL.getCode(),"您已经预定了该场地于"
+stadiumTimePrice.getDate()+" "+stadiumTimePrice.getStartTm()
+"至"+stadiumTimePrice.getEndTm()+"的"+ordersDTO.getSportItem());
return result(rs);
}else {
StadiumBook bk = new StadiumBook();
bk.setEnable(Enable.SUCCESS.getTips());
bk.setBookStartTime(stadiumTimePrice.getStartTm());
bk.setBookEndTime(stadiumTimePrice.getEndTm());
bk.setBookDate(stadiumTimePrice.getDate());
bk.setVipId(ordersDTO.getMembershipId());
bk = stadiumBookMapper.selectTimeToBook(bk);
if(bk!=null && ( ordersDTO.getNojoin()==null || "".equals(ordersDTO.getNojoin()))){
rs = new ResponseJson(StatusCode.FAIL.getCode(),"您已经预定了时间"
+stadiumTimePrice.getDate()+" "+stadiumTimePrice.getStartTm()
+"至"+stadiumTimePrice.getEndTm()+",不可再次预订改日期时间段");
return result(rs);
} else {
if("tmo".equals(ordersDTO.getOrderSource())){
int bnum = ordersDTO.getUserList().size()+1;
sum=sum+bnum;
if(num>=sum){
String bookId = sequenceUtil.getIDNoDate(Constant.STADIUM_BOOK,18);
stadiumBook.setBookId(bookId);
stadiumBook.setNum(bnum);
String pid = sequenceUtil.getIDNoDate(Constant.FIELD_ORDER,18);
for(int i = 0;i<ordersDTO.getUserList().size();i++){
StadiumBook ubk = new StadiumBook();
ubk.setEnable(Enable.SUCCESS.getTips());
ubk.setBookStartTime(stadiumTimePrice.getStartTm());
ubk.setBookEndTime(stadiumTimePrice.getEndTm());
ubk.setBookDate(stadiumTimePrice.getDate());
ubk.setVipId(ordersDTO.getUserList().get(i).getMembershipId());
ubk = stadiumBookMapper.selectTimeToBook(ubk);
if(ubk!=null){
rs = new ResponseJson(StatusCode.FAIL.getCode(),"您选择的人员"+ordersDTO.getUserList().get(i).getMembershipName()+"已经预定了时间"
+stadiumTimePrice.getDate()+" "+stadiumTimePrice.getStartTm()
+"至"+stadiumTimePrice.getEndTm()+",不可再次预订改日期时间段");
return result(rs);
}
}
for(int i = 0;i<=ordersDTO.getUserList().size();i++){
StadiumOrders stadiumOrders = new StadiumOrders();
BeanUtils.copyProperties(ordersDTO,stadiumOrders);
String orderId = null;
if(i!=ordersDTO.getUserList().size()){
UserOrderDto userOrderDto = ordersDTO.getUserList().get(i);
stadiumOrders.setMembershipName(userOrderDto.getMembershipName());
stadiumOrders.setMembershipId(userOrderDto.getMembershipId());
stadiumOrders.setOrderStatus(OrderState.WAITEQ.getCode());
stadiumOrders.setPid(pid);
orderId = sequenceUtil.getIDNoDate(Constant.FIELD_ORDER,18);
}else {
if(ordersDTO.getNojoin()!=null && !"".equals(ordersDTO.getNojoin())){
stadiumOrders.setOrderStatus(OrderState.NOJOIN.getCode());
}else {
stadiumOrders.setOrderStatus(OrderState.WAITEQ.getCode());
}
orderId = pid;
rorderId=pid;
stadiumBook.setOrderId(rorderId);
content="您已经成功预定了时间"+stadiumTimePrice.getDate()+stadiumTimePrice.getStartTm()+
"至"+stadiumTimePrice.getEndTm()+"的"+ordersDTO.getSportItem();
stadiumBookMapper.insert(stadiumBook);
}
stadiumOrders.setOrderType(OrderType.field.getOrderType());
stadiumOrders.setSportItem(ordersDTO.getSportItem());
stadiumOrders.setOrderId(orderId);
stadiumOrders.setCreateUser(this.getAcctName());
stadiumOrders.setCreateTm(new Date());
stadiumOrders.setFieldType("3");
stadiumOrders.setMembershipType("1");
ordersDTO.setFieldType("3");
ordersDTO.setMembershipType("1");
stadiumOrders.setAmountPrice(this.amount(ordersDTO.getStadiumTimePriceList()));
stadiumOrders.setPayPrice(stadiumOrders.getAmountPrice().multiply(stadiumOrders.getDiscount()));
stadiumOrders.setDeleteFlag(DeleteFlag.lock.getFalg());
SysStadium sysStadium=sysStadiumMapper.selectByPrimaryKey(stadiumOrders.getStadiumId());
stadiumOrders.setStadiumName(sysStadium.getStadiumName());
stadiumOrdersMapper.insert(stadiumOrders);
}
}else {
rs = new ResponseJson(StatusCode.FAIL.getCode(),Msg.ABMAXFIELDS.getTips());
return result(rs);
}
}else {
//单人预订逻辑,该项不开放,则返回状态2
Map map=new HashMap();
map.put("date",sdf.format(new Date()));
map.put("status","2");
map.put("orderId",0);
rs.setData(map);
return result(rs);
}
}
}
}else {
//场地预约达到上限
if(num<=sum){
rs = new ResponseJson(StatusCode.FAIL.getCode(),Msg.MAXFIELDS.getTips());
return result(rs);
}
//低于场地设定人数
if(usum<mnum){
rs = new ResponseJson(StatusCode.FAIL.getCode(),Msg.MINFIELDS.getTips());
return result(rs);
}
//高于场地设定人数
if (usum > num) {
rs = new ResponseJson(StatusCode.FAIL.getCode(),Msg.ABMAXFIELDS.getTips());
return result(rs);
}
}
}
}
//生成系统消息msg
String msgId = sequenceUtil.getIDNoDate(Constant.MSG_PERFIX,16);
SysMsg sysMsg = new SysMsg();
sysMsg.setMsgId(msgId);
sysMsg.setCreateUser(this.getAcctName());
sysMsg.setCreateTm(this.getCurrentDate());
sysMsg.setMsgType("1");
sysMsg.setTitle("预定成功");
sysMsg.setContent(content);
sysMsg.setAcctId(ordersDTO.getMembershipId());
sysMsg.setIsRead("0");
SysMsgMapper.insert(sysMsg);
Map map=new HashMap();
map.put("date",sdf.format(new Date()));
map.put("status","1");
map.put("orderId",rorderId);
rs.setData(map);
return result(rs);
}
预订逻辑关键代码
于 2023-08-23 10:27:47 首次发布