|
|
@@ -22,6 +22,7 @@ import org.dromara.system.domain.vo.*;
|
|
|
import org.dromara.system.mapper.TblDzbcSitePriceMapper;
|
|
|
import org.dromara.system.service.ITblDzbcAreaService;
|
|
|
import org.dromara.system.service.ITblDzbcPathService;
|
|
|
+import org.dromara.system.service.ITblDzbcPathSiteService;
|
|
|
import org.dromara.system.service.ITblDzbcSiteService;
|
|
|
import org.dromara.util.DistanceCalculator;
|
|
|
import org.springframework.util.Assert;
|
|
|
@@ -55,6 +56,7 @@ public class TblDzbcPathSchedulingController extends BaseController {
|
|
|
|
|
|
private final ITblDzbcPathSchedulingService tblDzbcPathSchedulingService;
|
|
|
private final ITblDzbcPathService tblDzbcPathService;
|
|
|
+ private final ITblDzbcPathSiteService tblDzbcPathSiteService;
|
|
|
private final ITblDzbcSiteService tblDzbcSiteService;
|
|
|
private final ITblDzbcAreaService tblDzbcAreaService;
|
|
|
private final TblDzbcSitePriceMapper sitePriceMapper;
|
|
|
@@ -284,6 +286,181 @@ public class TblDzbcPathSchedulingController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Log(title = "定制班车-多站点路线排班余票", businessType = BusinessType.FORCE)
|
|
|
+ @GetMapping("/getMultiSiteCarTickets")
|
|
|
+ public R<Object> getMultiSiteCarTickets(@RequestParam(required = true) String searchDate,
|
|
|
+ @RequestParam(required = true) Long pathId,
|
|
|
+ @RequestParam(required = true) Long fromsiteId,
|
|
|
+ @RequestParam(required = true) Long tositeId) {
|
|
|
+ Date date = new Date();
|
|
|
+ try{
|
|
|
+ date = DateUtil.parseDate(searchDate);
|
|
|
+ }catch (Exception e){
|
|
|
+ return R.fail("日期格式不正确 eg:2025-02-01");
|
|
|
+ }
|
|
|
+ if (Objects.equals(fromsiteId, tositeId)) {
|
|
|
+ return R.fail("起点和终点不能相同");
|
|
|
+ }
|
|
|
+ List<TblDzbcPathSiteVo> pathSites = tblDzbcPathSiteService.queryByPathId(pathId);
|
|
|
+ if (pathSites == null || pathSites.isEmpty()) {
|
|
|
+ return R.fail("未查询到路线站点");
|
|
|
+ }
|
|
|
+ Map<Long, Integer> siteOrderMap = pathSites.stream()
|
|
|
+ .filter(site -> site.getSiteId() != null && site.getSiteOrder() != null)
|
|
|
+ .collect(Collectors.toMap(TblDzbcPathSiteVo::getSiteId, TblDzbcPathSiteVo::getSiteOrder, (a, b) -> a));
|
|
|
+ Integer fromOrder = siteOrderMap.get(fromsiteId);
|
|
|
+ Integer toOrder = siteOrderMap.get(tositeId);
|
|
|
+ if (fromOrder == null || toOrder == null) {
|
|
|
+ return R.fail("站点不在该路线内");
|
|
|
+ }
|
|
|
+ if (fromOrder >= toOrder) {
|
|
|
+ return R.fail("站点顺序不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ Collection ret = RedisUtils.keys("dzbc_path_scheduling");
|
|
|
+ if (ret == null||ret.size()<1) {
|
|
|
+ TblDzbcPathSchedulingBo bo = new TblDzbcPathSchedulingBo();
|
|
|
+ bo.getParams().put("mdate", DateUtil.today());
|
|
|
+ List<TblDzbcPathSchedulingVo> allTblDzbcPathScheduling = tblDzbcPathSchedulingService.queryList(bo);
|
|
|
+ for (TblDzbcPathSchedulingVo tblDzbcPathSchedulingVo : allTblDzbcPathScheduling) {
|
|
|
+ Map<String, TblDzbcPathSchedulingVo> dataMap = RedisUtils.getCacheMap(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(tblDzbcPathSchedulingVo.getMdate())));
|
|
|
+ if(dataMap == null||dataMap.size()<1) dataMap =new HashMap<>();
|
|
|
+ dataMap.put(tblDzbcPathSchedulingVo.getId().toString(), tblDzbcPathSchedulingVo);
|
|
|
+ RedisUtils.setCacheMap(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(tblDzbcPathSchedulingVo.getMdate())), dataMap);
|
|
|
+ RedisUtils.expire(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(tblDzbcPathSchedulingVo.getMdate())), DateUtil.offset(tblDzbcPathSchedulingVo.getMdate(), DateField.HOUR_OF_DAY, 24).getTime() - DateUtil.current());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, TblDzbcPathSchedulingVo> dataMap = RedisUtils.getCacheMap(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(date)));
|
|
|
+ if(dataMap == null||dataMap.size()<1){
|
|
|
+ return R.fail("没有排班信息");
|
|
|
+ }else{
|
|
|
+ Date finalDate = date;
|
|
|
+ List<TblDzbcPathSchedulingVo> carTickets = dataMap.values().stream().filter(item -> {
|
|
|
+ if (item.getType() == null || item.getType() != 2) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!Objects.equals(item.getPathId(), pathId)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(item.getMdate().getTime()- finalDate.getTime()> 3600*1000){
|
|
|
+ dataMap.remove(item.getId());
|
|
|
+ RedisUtils.setCacheMap(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(finalDate)), dataMap);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(carTickets.size()<1){return R.fail("没有排班信息");}
|
|
|
+
|
|
|
+ for (TblDzbcPathSchedulingVo carTicket : carTickets) {
|
|
|
+ if(carTicket.getExt1() != null){
|
|
|
+ try {
|
|
|
+ JSONObject data = JSONUtil.parseObj(carTicket.getExt1());
|
|
|
+ JSONObject carInfo = data.getJSONObject("carInfo");
|
|
|
+ Integer zw = carInfo.getInt("carZw");
|
|
|
+ carTicket.setTicket(zw);
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ carTicket.setTicket(0);
|
|
|
+ carTicket.setCarStatus("已售罄");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ carTicket.setTicket(0);
|
|
|
+ carTicket.setCarStatus("已售罄");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (carTicket.getTicket() != null && carTicket.getTicket() > 0) {
|
|
|
+ int sold = 0;
|
|
|
+ if (StrUtil.isNotBlank(carTicket.getStartSites())) {
|
|
|
+ try {
|
|
|
+ JSONObject startSites = JSONUtil.parseObj(carTicket.getStartSites());
|
|
|
+ for (String siteKey : startSites.keySet()) {
|
|
|
+ JSONObject siteOrders = startSites.getJSONObject(siteKey);
|
|
|
+ if (siteOrders == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (String orderKey : siteOrders.keySet()) {
|
|
|
+ if ("siteInfo".equals(orderKey)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Object orderData = siteOrders.get(orderKey);
|
|
|
+ if (orderData == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject orderJson = JSONUtil.parseObj(orderData);
|
|
|
+ Integer zw = orderJson.getInt("zw");
|
|
|
+ Long orderStartId = orderJson.getLong("startSiteId");
|
|
|
+ Long orderEndId = orderJson.getLong("endSiteId");
|
|
|
+ if (zw == null || orderStartId == null || orderEndId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Integer orderStart = siteOrderMap.get(orderStartId);
|
|
|
+ Integer orderEnd = siteOrderMap.get(orderEndId);
|
|
|
+ if (orderStart == null || orderEnd == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (orderStart < toOrder && orderEnd > fromOrder) {
|
|
|
+ sold += zw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ carTicket.setTicket(carTicket.getTicket() - sold);
|
|
|
+ if(carTicket.getTicket()<1){
|
|
|
+ carTicket.setTicket(0);
|
|
|
+ carTicket.setCarStatus("已售罄");
|
|
|
+ }else{
|
|
|
+ if(carTicket.getTicket()<4){
|
|
|
+ carTicket.setCarStatus("余票紧张");
|
|
|
+ }else{
|
|
|
+ carTicket.setCarStatus("余票充足");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ if(carTicket.getMtime()!=null && !carTicket.getMtime().equals("")){
|
|
|
+ Date datec = DateUtil.parse(DateUtil.formatDate(carTicket.getMdate())+" "+carTicket.getMtime(), DatePattern.NORM_DATETIME_FORMAT);
|
|
|
+ if(datec.getTime() < DateUtil.current()){
|
|
|
+ carTicket.setTicket(0);
|
|
|
+ carTicket.setCarStatus("已发车");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(carTickets);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Log(title = "定制班车-多站点路线排班票价", businessType = BusinessType.FORCE)
|
|
|
+ @GetMapping("/getMultiSitePrice")
|
|
|
+ public R<Object> getMultiSitePrice(@RequestParam(required = true) Long schedulingId,
|
|
|
+ @RequestParam(required = true) Long fromsiteId,
|
|
|
+ @RequestParam(required = true) Long tositeId) {
|
|
|
+ TblDzbcPathSchedulingVo scheduling = tblDzbcPathSchedulingService.queryById(schedulingId);
|
|
|
+ if(scheduling==null) return R.fail("排班信息不存在");
|
|
|
+ if (scheduling.getType() == null || scheduling.getType() != 2) {
|
|
|
+ return R.fail("不是多站点路线排班");
|
|
|
+ }
|
|
|
+ TblDzbcSitePriceVo priceVo = sitePriceMapper.selectVoOne(
|
|
|
+ new LambdaQueryWrapper<TblDzbcSitePrice>()
|
|
|
+ .eq(TblDzbcSitePrice::getPathId, scheduling.getPathId())
|
|
|
+ .eq(TblDzbcSitePrice::getFromSiteId, fromsiteId)
|
|
|
+ .eq(TblDzbcSitePrice::getToSiteId, tositeId)
|
|
|
+ );
|
|
|
+ if (priceVo == null) {
|
|
|
+ return R.fail("未查询到该行程的票价信息");
|
|
|
+ }
|
|
|
+ int finalResult = Math.round(((int)Math.round(priceVo.getPrice() + scheduling.getPprice()) + 5) / 100) * 100;
|
|
|
+ scheduling.setPrice(finalResult);
|
|
|
+ return R.ok(scheduling);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取定制班车-票价
|
|
|
* @param schedulingId
|