| | |
| | | package com.xiaopeng.map.service.serviceimpl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.api.model.operation.XpPoint; |
| | |
| | | /** |
| | | * 判断场站运营策略 |
| | | * ["06:00-12:00", "13:00-21:00"] |
| | | * @param effectivePeriod 生效周期 1=每日 2=仅工作日 3=仅非工作日 4=仅节假日 |
| | | * @param effectiveTimePeriod 场站生效时间段 json |
| | | * @param effectiveTimePeriod 围栏运营json |
| | | * |
| | | * [{"name": "策略组1", "time": ["09:00-18:00"], "type": 0, "typeStr": []}, |
| | | * {"name": "策略组2", "time": ["08:00-21:00"], "type": 2, "typeStr": []}, |
| | | * {"name": "策略组3", "time": ["07:00-22:00"], "type": 1, "typeStr": []}, |
| | | * {"name": "策略组4", "time": ["12:00-19:00"], "type": 3, "typeStr": [1, 3, 5, 7]}] |
| | | * [{"name": "策略组1", "time": ["08:00-22:00"], "type": 3, "typeStr": [0]}] |
| | | * @return |
| | | */ |
| | | public boolean getStationTime_fenceOperationStrategy(Integer effectivePeriod, String effectiveTimePeriod,String fenceOperationStrategy){ |
| | | if(StrUtil.isNotBlank(effectiveTimePeriod) && StrUtil.isNotBlank(fenceOperationStrategy) ){ |
| | | // 直接解析为JSONArray |
| | | JSONArray effectiveTimePeriodS = JSON.parseArray(effectiveTimePeriod); |
| | | |
| | | JSONArray jsonArray = JSONArray.parseArray(fenceOperationStrategy); |
| | | for (Object et : effectiveTimePeriodS) { |
| | | String timeRange = et.toString(); |
| | | |
| | | String[] parts = timeRange.split("-"); |
| | | |
| | | LocalTime start = LocalTime.parse(parts[0].trim(), TimeRangeChecker.TIME_FORMATTER); |
| | | LocalTime end = LocalTime.parse(parts[1].trim(), TimeRangeChecker.TIME_FORMATTER); |
| | | |
| | | // type = 0工作日 1法定节假日 2非工作日 3自定义时间 typeStr 代表周 = [1,2,3,4,5,6,7] typeStr= 0的时候代表每天 |
| | | for (Object o : jsonArray) { |
| | | JSONObject jsonObject =JSONObject.parseObject(o.toString()); |
| | | String type = jsonObject.getString("type"); |
| | | String timeStr = null; |
| | | if(effectivePeriod == 1){ //生效周期 1=每日 2=仅工作日 3=仅非工作日 4=仅节假日 |
| | | // 判断是什么类型 0每天 1-7 想起 |
| | | String typeStr = jsonObject.getString("typeStr"); |
| | | if("3".equals(type) && typeStr.contains("0") ){ |
| | | timeStr = jsonObject.getString("time"); |
| | | } |
| | | }else if(effectivePeriod == 2){ |
| | | if("0".equals(type) ){ |
| | | timeStr = jsonObject.getString("time"); |
| | | } |
| | | }else if(effectivePeriod == 3){ |
| | | if("2".equals(type) ){ |
| | | timeStr = jsonObject.getString("time"); |
| | | } |
| | | }else if(effectivePeriod == 4){ |
| | | if("1".equals(type) ){ |
| | | timeStr = jsonObject.getString("time"); |
| | | } |
| | | } |
| | | if(StrUtil.isNotBlank(timeStr)){ |
| | | JSONArray time = jsonObject.getJSONArray("time"); |
| | | // 判断当前时间 是否在time时间段中 |
| | | for (Object object : time) { |
| | | String[] timeArray = object.toString().split("-"); |
| | | String startTime = timeArray[0]; |
| | | String endTime = timeArray[1]; |
| | | System.err.println("start="+start+";startTime="+startTime+";endTime="+endTime); |
| | | boolean currentTimeInRange = DateUtils.isCurrentTimeInRangeEq(start,startTime, endTime); |
| | | if(!currentTimeInRange){ |
| | | return false; |
| | | } |
| | | System.err.println("end="+end+";startTime="+startTime+";endTime="+endTime); |
| | | currentTimeInRange = DateUtils.isCurrentTimeInRangeEq(end,startTime, endTime); |
| | | if(!currentTimeInRange){ |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 判断场站运营策略 |
| | | * ["06:00-12:00", "13:00-21:00"] |
| | | * @param localTime |
| | | * @param operationType 运营类型 1=与运营区同步 2=自定义时间段 |
| | | * @param effectivePeriod 生效周期 1=每日 2=仅工作日 3=仅非工作日 4=仅节假日 |
| | |
| | | * @return |
| | | */ |
| | | public boolean getPointOperation(LocalTime localTime, XpPoint xpPoint){ |
| | | if(xpPoint.getOperationType()==2){//运营类型 1=与运营区同步 2=自定义时间段 |
| | | return getPointOperation(localTime,xpPoint.getEffectivePeriod(),xpPoint.getEffectiveTimePeriod()); |
| | | }else { |
| | | if(xpPoint.getStationId()==null){//调用围栏运营策略 |
| | | return getFenceOperation(localTime,xpPoint.getFenceOperationStrategy()); |
| | | }else { |
| | | return this.getStationOperation(localTime,xpPoint.getStationOperationType(),xpPoint.getStationEffectivePeriod(),xpPoint.getStationEffectiveTimePeriod(),xpPoint.getFenceOperationStrategy()); |
| | | if(xpPoint.getOperationStatus() == 2 && xpPoint.getVerificationStatus() == 5){ |
| | | if(xpPoint.getOperationType() != null){ |
| | | if(xpPoint.getOperationType()==2){//运营类型 1=与运营区同步 2=自定义时间段 |
| | | return getPointOperation(localTime,xpPoint.getEffectivePeriod(),xpPoint.getEffectiveTimePeriod()); |
| | | }else { |
| | | if (xpPoint.getStationId() == null) {//调用围栏运营策略 |
| | | return getFenceOperation(localTime, xpPoint.getFenceOperationStrategy()); |
| | | } else { |
| | | return this.getStationOperation(localTime, xpPoint.getStationOperationType(), xpPoint.getStationEffectivePeriod(), xpPoint.getStationEffectiveTimePeriod(), xpPoint.getFenceOperationStrategy()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | public boolean getPointOperation_vo(LocalTime localTime, XpPointsListVo xpPoint){ |
| | | if(xpPoint.getOperationType()==2){//运营类型 1=与运营区同步 2=自定义时间段 |