任务相关
This commit is contained in:
parent
0d3615bf86
commit
de1229fa61
|
@ -28,12 +28,12 @@ public class CodeGenerator {
|
|||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.parent("com.hivekion") // 设置父包名
|
||||
.moduleName("basedata") // 设置模块名(可选)
|
||||
.moduleName("supplier") // 设置模块名(可选)
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml,
|
||||
basePath + "/src/main/resources/mapper/tbl")); // 设置mapperXml生成路径
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude("IMG_VEHICLE_IMAGE".toLowerCase()) // 设置需要生成的表名(多个用逗号分隔)
|
||||
builder.addInclude("TBL_BATTLE_SUPPLIER".toLowerCase()) // 设置需要生成的表名(多个用逗号分隔)
|
||||
.addTablePrefix("tbl_"); // 设置过滤表前缀
|
||||
})
|
||||
.execute();
|
||||
|
|
|
@ -2,13 +2,23 @@ package com.hivekion.room.bean;
|
|||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.hivekion.common.redis.RedisUtil;
|
||||
import com.hivekion.common.uuid.IdUtils;
|
||||
import com.hivekion.room.RoomManager;
|
||||
import com.hivekion.room.func.TaskAction;
|
||||
import com.hivekion.scenario.entity.ScenarioResource;
|
||||
import com.hivekion.scenario.entity.ScenarioTask;
|
||||
import com.hivekion.scenario.service.impl.BattleSupplierServiceImpl;
|
||||
import com.hivekion.scenario.service.impl.ScenarioTaskServiceImpl;
|
||||
import com.hivekion.statistic.bean.StatisticBean;
|
||||
import com.hivekion.statistic.service.impl.StatisticServiceImpl;
|
||||
import com.hivekion.supplier.entity.SupplierRequest;
|
||||
import com.hivekion.supplier.service.impl.SupplierRequestServiceImpl;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
|
@ -28,7 +38,10 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
* 速度 换算为100Km/小时
|
||||
*/
|
||||
private final double SPEED = 27;
|
||||
|
||||
/**
|
||||
* 需求产生标志
|
||||
*/
|
||||
private final AtomicBoolean requestFlag = new AtomicBoolean(false);
|
||||
/**
|
||||
* 油料消耗速率
|
||||
*/
|
||||
|
@ -56,7 +69,7 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
initEnv(); //初始化环境
|
||||
initPath(); //初始化路径
|
||||
updatePath(SPEED,null); //更新路径
|
||||
updatePath(SPEED, null); //更新路径
|
||||
fuelConsumption();//油品消耗
|
||||
}
|
||||
|
||||
|
@ -65,19 +78,17 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
*/
|
||||
private void initEnv() {
|
||||
|
||||
|
||||
//获取油品消耗规则
|
||||
String fuelConsumptionStr = SpringUtil.getBean(Environment.class)
|
||||
.getProperty("fuel_spreed");
|
||||
fuelConsumption = Double.parseDouble(fuelConsumptionStr == null ? "0" : fuelConsumptionStr);
|
||||
fuelThreshold = Double.parseDouble(SpringUtil.getBean(Environment.class)
|
||||
.getProperty("fuel.warn ","0"));
|
||||
.getProperty("fuel.warn ", "0"));
|
||||
statisticBean = SpringUtil.getBean(StatisticServiceImpl.class)
|
||||
.statistic(scenarioTask.getResourceId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void fuelConsumption() {
|
||||
|
||||
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
||||
|
@ -94,19 +105,21 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
double fuel = Double.parseDouble(currentFuelObj.toString());
|
||||
fuel = fuel - currentUseUp;
|
||||
|
||||
redis.hset(
|
||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuelConsume", fuel);
|
||||
redis.hset(
|
||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuelConsume", fuel);
|
||||
|
||||
double totalFuel = statisticBean.getFuel().getTotal();
|
||||
if (fuel * 100 / totalFuel < fuelThreshold && !requestFlag.get()) {
|
||||
requestFlag.set(true);
|
||||
//需要产生需求
|
||||
produceFuelRequest();
|
||||
//产生任务
|
||||
produceTask();
|
||||
|
||||
double totalFuel = statisticBean.getFuel().getTotal();
|
||||
if(fuel*100/totalFuel<fuelThreshold){
|
||||
//需要产生需求
|
||||
//产生任务
|
||||
//插入消耗表
|
||||
}
|
||||
}
|
||||
|
||||
//插入消耗表
|
||||
}
|
||||
|
||||
|
||||
|
@ -114,8 +127,43 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
}
|
||||
|
||||
private void produceFuelRequest() {
|
||||
SupplierRequest supplierRequest = new SupplierRequest();
|
||||
supplierRequest.setId(IdUtils.simpleUUID());
|
||||
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
||||
supplierRequest.setSupplierNum(String.valueOf(statisticBean.getFuel().getTotal()));
|
||||
supplierRequest.setSupplierType("fuel");
|
||||
supplierRequest.setGeneralTime(LocalDateTime.now());
|
||||
supplierRequest.setLat(scenarioTask.getToLat());
|
||||
supplierRequest.setLng(scenarioTask.getToLng());
|
||||
supplierRequest.setHandleFlag(1);
|
||||
SpringUtil.getBean(SupplierRequestServiceImpl.class).save(supplierRequest);
|
||||
}
|
||||
|
||||
private void produceTask() {
|
||||
|
||||
List<ScenarioResource> resourceList = SpringUtil.getBean(BattleSupplierServiceImpl.class)
|
||||
.selectSupplierResource(scenarioTask.getResourceId());
|
||||
if (!resourceList.isEmpty()) {
|
||||
ScenarioTask task = new ScenarioTask();
|
||||
task.setId(IdUtils.simpleUUID());
|
||||
task.setScenarioId(scenarioTask.getScenarioId());
|
||||
task.setResourceId(scenarioTask.getResourceId());
|
||||
task.setTaskType("6");
|
||||
task.setSupplierNum(statisticBean.getFuel().getTotal());
|
||||
task.setToLat(scenarioTask.getToLat());
|
||||
task.setToLng(scenarioTask.getToLng());
|
||||
task.setStartTime(LocalDateTime.now());
|
||||
task.setFromLat(resourceList.get(0).getLat());
|
||||
task.setFromLng(resourceList.get(0).getLng());
|
||||
task.setFrom("general");
|
||||
SpringUtil.getBean(ScenarioTaskServiceImpl.class).save(task);
|
||||
//增加到房间任务
|
||||
SupplierTask supplierTask = new SupplierTask(task, roomId);
|
||||
//立即执行
|
||||
RoomManager.addAction(roomId, 0, supplierTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -119,9 +119,7 @@ public class Room implements AutoCloseable {
|
|||
return duringTime.get();
|
||||
}
|
||||
|
||||
public long getTotalTime() {
|
||||
return totalTime.get();
|
||||
}
|
||||
|
||||
|
||||
// 启动定时任务
|
||||
private void startTask() {
|
||||
|
|
|
@ -64,5 +64,5 @@ public class ScenarioTask implements Serializable {
|
|||
private String supplierResourceId;
|
||||
@TableField(value = "supplier_num")
|
||||
private double supplierNum;
|
||||
|
||||
private String from;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.hivekion.scenario.mapper;
|
|||
|
||||
import com.hivekion.scenario.entity.BattleSupplier;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.hivekion.scenario.entity.ScenarioResource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -12,5 +14,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
* @since 2025-09-15
|
||||
*/
|
||||
public interface BattleSupplierMapper extends BaseMapper<BattleSupplier> {
|
||||
|
||||
List<ScenarioResource> selectSupplierResource(String battleResourceId);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.hivekion.scenario.service;
|
|||
|
||||
import com.hivekion.scenario.entity.BattleSupplier;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.hivekion.scenario.entity.ScenarioResource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -16,4 +17,5 @@ import java.util.Set;
|
|||
public interface IBattleSupplierService extends IService<BattleSupplier> {
|
||||
public Set<String> getBattleResourceBySupplierId(String id);
|
||||
public Set<String> getSupplierIdByBattleId(String id);
|
||||
List<ScenarioResource> selectSupplierResource(String battleResourceId);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.hivekion.scenario.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.hivekion.scenario.entity.BattleSupplier;
|
||||
import com.hivekion.scenario.entity.ScenarioResource;
|
||||
import com.hivekion.scenario.mapper.BattleSupplierMapper;
|
||||
import com.hivekion.scenario.service.IBattleSupplierService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -13,19 +13,20 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author liDongYu
|
||||
* @since 2025-09-15
|
||||
*/
|
||||
@Service
|
||||
public class BattleSupplierServiceImpl extends ServiceImpl<BattleSupplierMapper, BattleSupplier> implements IBattleSupplierService {
|
||||
public class BattleSupplierServiceImpl extends
|
||||
ServiceImpl<BattleSupplierMapper, BattleSupplier> implements IBattleSupplierService {
|
||||
|
||||
@Override
|
||||
public Set<String> getBattleResourceBySupplierId(String id) {
|
||||
QueryWrapper<BattleSupplier> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("supplier_resource_id",id);
|
||||
queryWrapper.eq("supplier_resource_id", id);
|
||||
List<BattleSupplier> list = this.list(queryWrapper);
|
||||
return list.stream().map(BattleSupplier::getBattleResourceId).collect(Collectors.toSet());
|
||||
}
|
||||
|
@ -33,9 +34,14 @@ public class BattleSupplierServiceImpl extends ServiceImpl<BattleSupplierMapper,
|
|||
@Override
|
||||
public Set<String> getSupplierIdByBattleId(String id) {
|
||||
QueryWrapper<BattleSupplier> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("battle_resource_id",id);
|
||||
queryWrapper.eq("battle_resource_id", id);
|
||||
List<BattleSupplier> list = this.list(queryWrapper);
|
||||
|
||||
return list.stream().map(BattleSupplier::getSupplierResourceId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ScenarioResource> selectSupplierResource(String battleResourceId) {
|
||||
return this.baseMapper.selectSupplierResource(battleResourceId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,102 +2,54 @@ package com.hivekion.supplier.entity;
|
|||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author liDongYu
|
||||
* @since 2025-09-18
|
||||
*/
|
||||
@Data
|
||||
@TableName("TBL_SUPPLIER_REQUEST")
|
||||
@ApiModel(value = "SupplierRequest对象", description = "")
|
||||
public class SupplierRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableField(value="ID")
|
||||
private String id;
|
||||
@TableField(value = "ID")
|
||||
private String id;
|
||||
|
||||
@TableField(value="GENERAL_TIME")
|
||||
private LocalDateTime generalTime;
|
||||
@TableField(value = "GENERAL_TIME")
|
||||
private LocalDateTime generalTime;
|
||||
|
||||
@TableField(value="FROM_RESOURCE_ID")
|
||||
private String fromResourceId;
|
||||
@TableField(value = "FROM_RESOURCE_ID")
|
||||
private String fromResourceId;
|
||||
|
||||
@TableField(value="SUPPLIER_TYPE")
|
||||
private String supplierType;
|
||||
@TableField(value="SUPPLIER_NUM")
|
||||
private String supplierNum;
|
||||
@TableField(value="LAT")
|
||||
private String lat;
|
||||
@TableField(value="LNG")
|
||||
private String lng;
|
||||
@TableField(value = "SUPPLIER_TYPE")
|
||||
private String supplierType;
|
||||
@TableField(value = "SUPPLIER_NUM")
|
||||
private String supplierNum;
|
||||
@TableField(value = "LAT")
|
||||
private String lat;
|
||||
@TableField(value = "LNG")
|
||||
private String lng;
|
||||
/**
|
||||
* 0 未处理 ;1 处理
|
||||
*/
|
||||
@TableField(value = "handle_flag")
|
||||
private int handleFlag;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateTime getGeneralTime() {
|
||||
return generalTime;
|
||||
}
|
||||
|
||||
public void setGeneralTime(LocalDateTime generalTime) {
|
||||
this.generalTime = generalTime;
|
||||
}
|
||||
|
||||
public String getFromResourceId() {
|
||||
return fromResourceId;
|
||||
}
|
||||
|
||||
public void setFromResourceId(String fromResourceId) {
|
||||
this.fromResourceId = fromResourceId;
|
||||
}
|
||||
|
||||
public String getSupplierType() {
|
||||
return supplierType;
|
||||
}
|
||||
|
||||
public void setSupplierType(String supplierType) {
|
||||
this.supplierType = supplierType;
|
||||
}
|
||||
|
||||
public String getSupplierNum() {
|
||||
return supplierNum;
|
||||
}
|
||||
|
||||
public void setSupplierNum(String supplierNum) {
|
||||
this.supplierNum = supplierNum;
|
||||
}
|
||||
|
||||
public String getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(String lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public String getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
public void setLng(String lng) {
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SupplierRequest{" +
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SupplierRequest{" +
|
||||
"id = " + id +
|
||||
", generalTime = " + generalTime +
|
||||
", fromResourceId = " + fromResourceId +
|
||||
|
@ -106,5 +58,5 @@ public class SupplierRequest implements Serializable {
|
|||
", lat = " + lat +
|
||||
", lng = " + lng +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hivekion.scenario.mapper.BattleSupplierMapper">
|
||||
|
||||
<select id="selectSupplierResource" resultType="com.hivekion.scenario.entity.ScenarioResource">
|
||||
select id ,lng,lat,scenario_Id as scenarioId, resource_name as resourceName
|
||||
from tbl_scenario_resource
|
||||
where resource_id in
|
||||
(select supplier_resource_id from tbl_battle_supplier where battle_resoure_id = #{battleResourceId})
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue
Block a user