Commit 3acd0fc7 authored by jiaorz's avatar jiaorz

车辆预定重新排班bug

parent 49341425
package com.github.wxiaoqi.security.common.util; package com.github.wxiaoqi.security.common.util;
import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.Set;
/** /**
* 随机数工具 * 随机数工具
...@@ -31,10 +33,41 @@ public class RandomUtil ...@@ -31,10 +33,41 @@ public class RandomUtil
return String.valueOf((int) (random * num)); return String.valueOf((int) (random * num));
} }
/**
* 获取随机数字集合
* @param max
* @param n
* @param set
*/
public static void randomSet(int max, int n, Set<Integer> set) {
if (n > (max + 1) || max < 0) {
return;
}
for (int i = 0; i < n; i++) {
int num = (int) (Math.random() * (max));
set.add(num);
}
int setSize = set.size();
// 如果存入的数小于指定生成的个数,则调用递归再生成剩余个数的随机数,如此循环,直到达到指定大小
if (setSize < n) {
randomSet( max, n-setSize, set);// 递归
}
}
public static synchronized String gencRan(){ public static synchronized String gencRan(){
Random ran = new Random(System.nanoTime()); Random ran = new Random(System.nanoTime());
double nextDouble = ran.nextDouble(); double nextDouble = ran.nextDouble();
return String.valueOf(nextDouble).substring(2, 6); return String.valueOf(nextDouble).substring(2, 6);
} }
public static void main(String[] args) {
int max = 20;
int n = 5;
Set<Integer> set = new HashSet<>();
randomSet(max, n, set);
for(Integer a : set) {
System.out.println(a);
}
}
} }
...@@ -9,6 +9,7 @@ import com.github.wxiaoqi.security.admin.feign.UserFeign; ...@@ -9,6 +9,7 @@ import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.constant.RestCode; import com.github.wxiaoqi.security.common.constant.RestCode;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.RandomUtil;
import com.github.wxiaoqi.security.common.util.process.ResultCode; import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.GoodDataVO; import com.github.wxiaoqi.security.common.vo.GoodDataVO;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
...@@ -18,15 +19,13 @@ import com.xxfc.platform.tour.mapper.*; ...@@ -18,15 +19,13 @@ import com.xxfc.platform.tour.mapper.*;
import com.xxfc.platform.tour.vo.TourGoodVo; import com.xxfc.platform.tour.vo.TourGoodVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
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.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* 旅游商品表 * 旅游商品表
...@@ -325,6 +324,27 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> { ...@@ -325,6 +324,27 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
return mapper.findAllByHome((page-1)*limit,limit); return mapper.findAllByHome((page-1)*limit,limit);
}; };
/**
* 获取指定数量的随机旅游路线
* @return
*/
public ObjectRestResponse findRandomVehicle(Integer number) {
number = number == null ? 3 : number;
Map<String, Object> param = new HashMap<>();
List<TourGood> list = mapper.getCoordinateList(param);
Set<TourGood> resultList = new HashSet<>();
if(CollectionUtils.isNotEmpty(list)) {
if(number == list.size()) {
return ObjectRestResponse.succ(list);
}
Set<Integer> set = new HashSet<>();
RandomUtil.randomSet(list.size(), number, set);
for(Integer i : set) {
resultList.add(list.get(i));
}
}
return ObjectRestResponse.succ(resultList);
}
} }
...@@ -52,5 +52,10 @@ public class TourGoodController extends BaseController<TourGoodBiz, TourGood> { ...@@ -52,5 +52,10 @@ public class TourGoodController extends BaseController<TourGoodBiz, TourGood> {
return baseBiz.getAllByHome(page,limit); return baseBiz.getAllByHome(page,limit);
} }
@ApiOperation("随机获取旅游路线")
@GetMapping(value = "/app/unauth/findRandomVehicle")
public ObjectRestResponse findRandomVehicle(Integer number) {
return baseBiz.findRandomVehicle(number);
}
} }
\ No newline at end of file
...@@ -528,11 +528,9 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR ...@@ -528,11 +528,9 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
Integer andOperationFactor = andOpratorParam.get("andOperationFactor"); Integer andOperationFactor = andOpratorParam.get("andOperationFactor");
Integer andOperationRs = andOpratorParam.get("andOperationRs"); Integer andOperationRs = andOpratorParam.get("andOperationRs");
if(vehicleBookInfo != null && vehicleBookInfo.getBookedDate() != null && if(vehicleBookInfo != null && vehicleBookInfo.getBookedDate() != null &&
((vehicleBookInfo.getBookedDate() & andOperationFactor) != andOperationRs)){//已经被预定 ((vehicleBookInfo.getBookedDate() & andOperationFactor) != 0)){//已经被预定
//当天已经被预定检查小时是否也被预定 //当天已经被预定检查小时是否也被预定
return filterHourInfoBooked(vehicleId, hourInfo); return filterHourInfoBooked(vehicleId, hourInfo);
} else if (vehicleBookInfo != null && vehicleBookInfo.getBookedDate() != null &&(vehicleBookInfo.getBookedDate() & andOperationFactor) == 0){//未被预定,查看时间是否被预定
return filterHourInfoBooked(vehicleId, hourInfo);
} }
return Boolean.TRUE; return Boolean.TRUE;
} }
......
...@@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper; ...@@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.RandomUtil;
import com.github.wxiaoqi.security.common.vo.GoodDataVO; import com.github.wxiaoqi.security.common.vo.GoodDataVO;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.constant.ResCode.ResCode; import com.xxfc.platform.vehicle.constant.ResCode.ResCode;
...@@ -20,8 +21,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; ...@@ -20,8 +21,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls; import tk.mybatis.mapper.weekend.WeekendSqls;
import java.util.ArrayList; import java.util.*;
import java.util.List;
/** /**
* 车型 * 车型
...@@ -71,7 +71,28 @@ public class VehicleModelBiz extends BaseBiz<VehicleModelMapper, VehicleModel> { ...@@ -71,7 +71,28 @@ public class VehicleModelBiz extends BaseBiz<VehicleModelMapper, VehicleModel> {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
} }
return null; return null;
}
/**
* 获取指定数量的随机车型
* @return
*/
public ObjectRestResponse findRandomVehicle(Integer number) {
number = number == null ? 3 : number;
VehicleModelQueryCondition vmqc = new VehicleModelQueryCondition();
List<VehicleModelVo> list = mapper.findVehicleModelPage(vmqc);
Set<VehicleModelVo> resultList = new HashSet<>();
if(CollectionUtils.isNotEmpty(list)) {
if(number == list.size()) {
return ObjectRestResponse.succ(list);
}
Set<Integer> set = new HashSet<>();
RandomUtil.randomSet(list.size(), number, set);
for(Integer i : set) {
resultList.add(list.get(i));
}
}
return ObjectRestResponse.succ(resultList);
} }
/** /**
......
...@@ -125,6 +125,13 @@ public class VehicleModelController extends BaseController<VehicleModelBiz, Vehi ...@@ -125,6 +125,13 @@ public class VehicleModelController extends BaseController<VehicleModelBiz, Vehi
return vehicleModelBiz.findVehicleModelPage(vmqc); return vehicleModelBiz.findVehicleModelPage(vmqc);
} }
@GetMapping(value = "/app/unauth/findRandomVehicle")
@IgnoreUserToken
@ApiOperation("获取随机车型")
public ObjectRestResponse findRandomVehicle(Integer number) {
return vehicleModelBiz.findRandomVehicle(number);
}
/** /**
* 添加车型 * 添加车型
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment