小车充电任务
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package com.ruoyi.device.cdz.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.device.cdz.domain.DeviceCdz;
|
||||
import com.ruoyi.device.cdz.service.IDeviceCdzService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 充电桩设备Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-11-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/device/cdz")
|
||||
public class DeviceCdzController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IDeviceCdzService deviceCdzService;
|
||||
|
||||
/**
|
||||
* 查询充电桩设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('device:cdz:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(DeviceCdz deviceCdz)
|
||||
{
|
||||
startPage();
|
||||
List<DeviceCdz> list = deviceCdzService.selectDeviceCdzList(deviceCdz);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出充电桩设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('device:cdz:export')")
|
||||
@Log(title = "充电桩设备", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DeviceCdz deviceCdz)
|
||||
{
|
||||
List<DeviceCdz> list = deviceCdzService.selectDeviceCdzList(deviceCdz);
|
||||
ExcelUtil<DeviceCdz> util = new ExcelUtil<DeviceCdz>(DeviceCdz.class);
|
||||
util.exportExcel(response, list, "充电桩设备数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取充电桩设备详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('device:cdz:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(deviceCdzService.selectDeviceCdzById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增充电桩设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('device:cdz:add')")
|
||||
@Log(title = "充电桩设备", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody DeviceCdz deviceCdz)
|
||||
{
|
||||
return toAjax(deviceCdzService.insertDeviceCdz(deviceCdz));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改充电桩设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('device:cdz:edit')")
|
||||
@Log(title = "充电桩设备", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody DeviceCdz deviceCdz)
|
||||
{
|
||||
return toAjax(deviceCdzService.updateDeviceCdz(deviceCdz));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除充电桩设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('device:cdz:remove')")
|
||||
@Log(title = "充电桩设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(deviceCdzService.deleteDeviceCdzByIds(ids));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.ruoyi.device.cdz.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 充电桩设备对象 device_cdz
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-11-27
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DeviceCdz extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** id */
|
||||
private Integer id;
|
||||
|
||||
/** 设备名称 */
|
||||
@Excel(name = "设备名称")
|
||||
private String name;
|
||||
|
||||
/** ip */
|
||||
@Excel(name = "ip")
|
||||
private String ip;
|
||||
|
||||
/** 端口 */
|
||||
@Excel(name = "端口")
|
||||
private String port;
|
||||
|
||||
/** plc读取地址 */
|
||||
@Excel(name = "plc读取地址")
|
||||
private String plcDbReadAddress;
|
||||
|
||||
/** plc写入地址 */
|
||||
@Excel(name = "plc写入地址")
|
||||
private String plcDbWriteAddress;
|
||||
|
||||
/** 任务号 */
|
||||
@Excel(name = "任务号")
|
||||
private Integer rwh;
|
||||
|
||||
/** 充电桩状态 */
|
||||
@Excel(name = "充电桩状态")
|
||||
private Integer status;
|
||||
|
||||
/** 心跳信号 */
|
||||
@Excel(name = "心跳信号")
|
||||
private Integer xtxh;
|
||||
|
||||
/** 层数 */
|
||||
@Excel(name = "层数")
|
||||
private Integer szcs;
|
||||
|
||||
/** 充电模式 */
|
||||
@Excel(name = "充电模式")
|
||||
private Integer model;
|
||||
|
||||
/** 站点 */
|
||||
@Excel(name = "站点")
|
||||
private String siteId;
|
||||
|
||||
/** 备用1 */
|
||||
@Excel(name = "备用1")
|
||||
private String spare1;
|
||||
|
||||
/** 备用2 */
|
||||
@Excel(name = "备用2")
|
||||
private String spare2;
|
||||
|
||||
/** 备用3 */
|
||||
@Excel(name = "备用3")
|
||||
private String spare3;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.ruoyi.device.cdz.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.device.cdz.domain.DeviceCdz;
|
||||
|
||||
/**
|
||||
* 充电桩设备Mapper接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-11-27
|
||||
*/
|
||||
public interface DeviceCdzMapper
|
||||
{
|
||||
/**
|
||||
* 查询充电桩设备
|
||||
*
|
||||
* @param id 充电桩设备主键
|
||||
* @return 充电桩设备
|
||||
*/
|
||||
public DeviceCdz selectDeviceCdzById(Long id);
|
||||
|
||||
/**
|
||||
* 查询充电桩设备列表
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 充电桩设备集合
|
||||
*/
|
||||
public List<DeviceCdz> selectDeviceCdzList(DeviceCdz deviceCdz);
|
||||
|
||||
/**
|
||||
* 新增充电桩设备
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDeviceCdz(DeviceCdz deviceCdz);
|
||||
|
||||
/**
|
||||
* 修改充电桩设备
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDeviceCdz(DeviceCdz deviceCdz);
|
||||
|
||||
/**
|
||||
* 删除充电桩设备
|
||||
*
|
||||
* @param id 充电桩设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceCdzById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除充电桩设备
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceCdzByIds(Long[] ids);
|
||||
/**
|
||||
* 查询没有SRGV的充电桩设备
|
||||
* @return
|
||||
*/
|
||||
List<DeviceCdz> selectDeviceCdzListNoSRgvId();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.ruoyi.device.cdz.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.device.cdz.domain.DeviceCdz;
|
||||
|
||||
/**
|
||||
* 充电桩设备Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-11-27
|
||||
*/
|
||||
public interface IDeviceCdzService
|
||||
{
|
||||
/**
|
||||
* 查询充电桩设备
|
||||
*
|
||||
* @param id 充电桩设备主键
|
||||
* @return 充电桩设备
|
||||
*/
|
||||
public DeviceCdz selectDeviceCdzById(Long id);
|
||||
|
||||
/**
|
||||
* 查询充电桩设备列表
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 充电桩设备集合
|
||||
*/
|
||||
public List<DeviceCdz> selectDeviceCdzList(DeviceCdz deviceCdz);
|
||||
|
||||
/**
|
||||
* 新增充电桩设备
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDeviceCdz(DeviceCdz deviceCdz);
|
||||
|
||||
/**
|
||||
* 修改充电桩设备
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDeviceCdz(DeviceCdz deviceCdz);
|
||||
|
||||
/**
|
||||
* 批量删除充电桩设备
|
||||
*
|
||||
* @param ids 需要删除的充电桩设备主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceCdzByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除充电桩设备信息
|
||||
*
|
||||
* @param id 充电桩设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceCdzById(Long id);
|
||||
/**
|
||||
* 查询没有SRgvId的充电桩设备列表
|
||||
* @return
|
||||
*/
|
||||
List<DeviceCdz> selectDeviceCdzListNoSRgvId();
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.ruoyi.device.cdz.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.device.cdz.mapper.DeviceCdzMapper;
|
||||
import com.ruoyi.device.cdz.domain.DeviceCdz;
|
||||
import com.ruoyi.device.cdz.service.IDeviceCdzService;
|
||||
|
||||
/**
|
||||
* 充电桩设备Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-11-27
|
||||
*/
|
||||
@Service
|
||||
public class DeviceCdzServiceImpl implements IDeviceCdzService
|
||||
{
|
||||
@Autowired
|
||||
private DeviceCdzMapper deviceCdzMapper;
|
||||
|
||||
/**
|
||||
* 查询充电桩设备
|
||||
*
|
||||
* @param id 充电桩设备主键
|
||||
* @return 充电桩设备
|
||||
*/
|
||||
@Override
|
||||
public DeviceCdz selectDeviceCdzById(Long id)
|
||||
{
|
||||
return deviceCdzMapper.selectDeviceCdzById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询充电桩设备列表
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 充电桩设备
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceCdz> selectDeviceCdzList(DeviceCdz deviceCdz)
|
||||
{
|
||||
return deviceCdzMapper.selectDeviceCdzList(deviceCdz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增充电桩设备
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertDeviceCdz(DeviceCdz deviceCdz)
|
||||
{
|
||||
return deviceCdzMapper.insertDeviceCdz(deviceCdz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改充电桩设备
|
||||
*
|
||||
* @param deviceCdz 充电桩设备
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateDeviceCdz(DeviceCdz deviceCdz)
|
||||
{
|
||||
return deviceCdzMapper.updateDeviceCdz(deviceCdz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除充电桩设备
|
||||
*
|
||||
* @param ids 需要删除的充电桩设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceCdzByIds(Long[] ids)
|
||||
{
|
||||
return deviceCdzMapper.deleteDeviceCdzByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除充电桩设备信息
|
||||
*
|
||||
* @param id 充电桩设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceCdzById(Long id)
|
||||
{
|
||||
return deviceCdzMapper.deleteDeviceCdzById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceCdz> selectDeviceCdzListNoSRgvId() {
|
||||
return deviceCdzMapper.selectDeviceCdzListNoSRgvId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.ruoyi.schedule.plcRead.cdz;
|
||||
|
||||
import HslCommunication.BasicFramework.SoftBasic;
|
||||
import HslCommunication.Core.Net.IReadWriteNet;
|
||||
import HslCommunication.Core.Types.OperateResult;
|
||||
import HslCommunication.Core.Types.OperateResultExOne;
|
||||
import HslCommunication.Profinet.Siemens.SiemensPLCS;
|
||||
import HslCommunication.Profinet.Siemens.SiemensS7Net;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.common.domain.HslRead;
|
||||
import com.ruoyi.common.domain.PlcConnectInfo;
|
||||
import com.ruoyi.device.cdz.domain.DeviceCdz;
|
||||
import com.ruoyi.device.tsj.domain.DeviceTsj;
|
||||
import com.ruoyi.schedule.plcRead.util.ParseUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
public class PlcCdzRead implements Runnable {
|
||||
|
||||
public static ConcurrentHashMap<String, DeviceCdz> deviceCdzMap;
|
||||
public volatile boolean isRun = true;
|
||||
|
||||
public SiemensS7Net siemensS7Net = null;
|
||||
public static IReadWriteNet readWriteNet = null;
|
||||
private final String ip;
|
||||
private final int port;
|
||||
private boolean success = false;
|
||||
|
||||
public PlcCdzRead(ConcurrentHashMap<String, DeviceCdz> deviceCdzMap, PlcConnectInfo plcConnectInfo) {
|
||||
PlcCdzRead.deviceCdzMap = deviceCdzMap;
|
||||
this.ip = plcConnectInfo.getIp();
|
||||
this.port = plcConnectInfo.getPort();
|
||||
}
|
||||
|
||||
public static int WriteToCdz(String address, byte[] data) {
|
||||
int a = 0;
|
||||
if (readWriteNet != null) {
|
||||
a = HslRead.WriteResultRender(readWriteNet.Write(address, data), address);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (isRun) {
|
||||
try {
|
||||
if (IsConnect()) {
|
||||
for (String cdzCode : deviceCdzMap.keySet()) {
|
||||
DeviceCdz deviceCdz = deviceCdzMap.get(cdzCode);
|
||||
plcRead(deviceCdz);
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
} else {
|
||||
reConnect();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// 捕获中断异常,退出循环
|
||||
Thread.currentThread().interrupt(); // 重新设置中断标志
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
log.info("********IP:" + this.ip + " port:" + this.port + "读取数据异常 " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void plcRead(DeviceCdz deviceCdz) {
|
||||
OperateResultExOne<byte[]> read2 = readWriteNet.Read(deviceCdz.getPlcDbReadAddress(), Short.parseShort("20"));
|
||||
String ddsx1 = "0";
|
||||
if (read2.IsSuccess) {
|
||||
ddsx1 = SoftBasic.ByteToHexString(read2.Content);
|
||||
deviceCdz.setStatus(ParseUtil.optInt(0, ddsx1));
|
||||
deviceCdz.setModel(ParseUtil.optInt(2, ddsx1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConnectServer() {
|
||||
siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500);
|
||||
try {
|
||||
siemensS7Net.setIpAddress(this.ip);
|
||||
siemensS7Net.setPort(this.port);
|
||||
siemensS7Net.setRack((byte) 0);
|
||||
siemensS7Net.setSlot((byte) 1);
|
||||
|
||||
OperateResult connect = siemensS7Net.ConnectServer();
|
||||
if (connect.IsSuccess) {
|
||||
setIsConnect(true);
|
||||
readWriteNet = siemensS7Net;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.info("********IP:" + this.ip + " port:" + this.port + "连接失败 " + ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setIsConnect(boolean bflag) {
|
||||
if (!success) {
|
||||
success = bflag;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean IsConnect() {
|
||||
if (success) {
|
||||
return success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void reConnect() {
|
||||
closeServer();
|
||||
ConnectServer();
|
||||
log.info("重新连接 CDZ-PLC");
|
||||
}
|
||||
|
||||
void closeServer() {
|
||||
if (readWriteNet != null) {
|
||||
readWriteNet.ConnectClose();
|
||||
}
|
||||
setIsConnect(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.ruoyi.schedule.scheduleTask.cdz;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.ruoyi.device.cdz.domain.DeviceCdz;
|
||||
import com.ruoyi.device.cdz.service.IDeviceCdzService;
|
||||
import com.ruoyi.device.srgv.domain.DeviceSrgv;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.charg.domain.SrgvChargingJob;
|
||||
import com.ruoyi.job.charg.service.ISrgvChargingJobService;
|
||||
import com.ruoyi.schedule.plcRead.srgv.PlcSrgvRead;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class CdzThread implements Runnable {
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
private final Integer LITTLE_BETTERY = 30;
|
||||
private final Integer MIDDLE_BETTERY = 70;
|
||||
|
||||
private ISrgvChargingJobService chargingJobService;
|
||||
private IDeviceCdzService deviceCdzService;
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void inDispatch() {
|
||||
|
||||
//获取低电量小车
|
||||
List<DeviceSrgv> littleBatterySRgv = new ArrayList<>();
|
||||
//获取中电量小车
|
||||
List<DeviceSrgv> middleBatterySRgv = new ArrayList<>();
|
||||
for (String sRgv : PlcSrgvRead.deviceSrgvMap.keySet()) {
|
||||
DeviceSrgv deviceSrgv = PlcSrgvRead.deviceSrgvMap.get(sRgv);
|
||||
if (deviceSrgv.getWorkMode()==5 && deviceSrgv.getStatus()!=3 ){
|
||||
if (deviceSrgv.getBattery()<=LITTLE_BETTERY){
|
||||
littleBatterySRgv.add(deviceSrgv);
|
||||
}else if (deviceSrgv.getBattery()<=MIDDLE_BETTERY){
|
||||
middleBatterySRgv.add(deviceSrgv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//优先低电量小车充电
|
||||
if (CollUtil.isNotEmpty(littleBatterySRgv)){
|
||||
//排序
|
||||
createChargingInJob(littleBatterySRgv);
|
||||
|
||||
}else {
|
||||
if (CollUtil.isNotEmpty(middleBatterySRgv)){
|
||||
//排序
|
||||
createChargingInJob(middleBatterySRgv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建充电任务
|
||||
* @param srgvList
|
||||
*/
|
||||
private void createChargingInJob(List<DeviceSrgv> srgvList) {
|
||||
srgvList.sort((o1, o2) -> o2.getBattery()-o1.getBattery());
|
||||
|
||||
for (DeviceSrgv deviceSrgv : srgvList) {
|
||||
SrgvChargingJob wcsChargingJob = new SrgvChargingJob();
|
||||
wcsChargingJob.setJobType("1");
|
||||
wcsChargingJob.setAgvId(deviceSrgv.getDeviceId().toString());
|
||||
List<SrgvChargingJob> srgvChargingJobs = chargingJobService.selectSrgvChargingJobList(wcsChargingJob);
|
||||
if (CollUtil.isEmpty(srgvChargingJobs)){
|
||||
List<DeviceCdz> cdzList = deviceCdzService.selectDeviceCdzListNoSRgvId();
|
||||
if (CollUtil.isNotEmpty(cdzList)){
|
||||
//寻找最接近的充电桩
|
||||
Integer floor = deviceSrgv.getCurrFloor();
|
||||
DeviceCdz cdz = cdzList.stream().filter(c -> c.getSzcs().equals(floor)).min((o1, o2) -> {
|
||||
Integer distance1 = Math.abs(o1.getSzcs());
|
||||
Integer distance2 = Math.abs(floor);
|
||||
return distance1 - distance2;
|
||||
}).get();
|
||||
|
||||
//生成充电任务
|
||||
SrgvChargingJob srgvChargingJobParam = new SrgvChargingJob();
|
||||
srgvChargingJobParam.setAgvId(deviceSrgv.getDeviceId().toString());
|
||||
srgvChargingJobParam.setChargingSite(cdz.getSiteId());
|
||||
srgvChargingJobParam.setChargingId(cdz.getId().toString());
|
||||
List<SrgvChargingJob> wcsChargingJobs = chargingJobService.selectSrgvChargingJobList(srgvChargingJobParam);
|
||||
if (CollUtil.isEmpty(wcsChargingJobs)) {
|
||||
SrgvChargingJob scj = new SrgvChargingJob();
|
||||
scj.setGuid(IdUtil.fastSimpleUUID());
|
||||
scj.setChargingSite(cdz.getSiteId());
|
||||
scj.setJobStatus("1");
|
||||
scj.setChargingStatus("0");
|
||||
scj.setStartDate(DateUtil.now());
|
||||
scj.setJobType("1");//到充电桩
|
||||
scj.setAgvId(deviceSrgv.getDeviceId().toString());
|
||||
scj.setChargingId(deviceSrgv.getDeviceId().toString());
|
||||
chargingJobService.insertSrgvChargingJob(scj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.ruoyi.bas.srgvmap.service.IWcsSrgvMapService;
|
||||
import com.ruoyi.bas.srgvmap.service.RoadCacheService;
|
||||
import com.ruoyi.common.domain.SendData2;
|
||||
import com.ruoyi.device.srgv.domain.DeviceSrgv;
|
||||
import com.ruoyi.job.charg.domain.SrgvChargingJob;
|
||||
import com.ruoyi.job.charg.service.ISrgvChargingJobService;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
@@ -74,12 +75,17 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
|
||||
if (ObjUtil.isNotNull(PlcSrgvRead.deviceSrgvMap.get(code))) {
|
||||
|
||||
DeviceSrgv deviceSrgv = PlcSrgvRead.deviceSrgvMap.get(code);
|
||||
|
||||
sRgvTask(deviceSrgv);
|
||||
|
||||
createCarInQueue();
|
||||
|
||||
createCarOutQueue();
|
||||
|
||||
inCharging(deviceSrgv);
|
||||
|
||||
outCharging(deviceSrgv);
|
||||
|
||||
} else {
|
||||
log.error("小车设备为空");
|
||||
}
|
||||
@@ -100,6 +106,63 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 离开电桩
|
||||
*
|
||||
* @param deviceSrgv
|
||||
*/
|
||||
private void outCharging(DeviceSrgv deviceSrgv) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 小车充电任务
|
||||
*
|
||||
* @param deviceSrgv
|
||||
*/
|
||||
private void inCharging(DeviceSrgv deviceSrgv) {
|
||||
SrgvChargingJob param = new SrgvChargingJob();
|
||||
param.setJobStatus("1");
|
||||
param.setJobType("1");
|
||||
param.setAgvId(deviceSrgv.getDeviceId().toString());
|
||||
List<SrgvChargingJob> srgvChargingJobs = srgvChargingJobMapper.selectSrgvChargingJobList(param);
|
||||
if (CollUtil.isNotEmpty(srgvChargingJobs)){
|
||||
SrgvChargingJob srgvChargingJob = srgvChargingJobs.get(0);
|
||||
String chargingSite = srgvChargingJob.getChargingSite();//充电桩站点
|
||||
WcsSrgvQueue wcsSrgvQueueParam = new WcsSrgvQueue();
|
||||
wcsSrgvQueueParam.setAgvId(deviceSrgv.getDeviceId().toString());
|
||||
List<WcsSrgvQueue> wcsSrgvQueues = wcsSagvQueueMapper.selectWcsSrgvQueueList(wcsSrgvQueueParam);
|
||||
if (CollUtil.isEmpty(wcsSrgvQueues)){
|
||||
//生成队列
|
||||
WcsSrgvQueue wcsSrgvQueue = new WcsSrgvQueue();
|
||||
wcsSrgvQueue.setGuid(UUID.randomUUID().toString());
|
||||
wcsSrgvQueue.setTaskNo("");
|
||||
wcsSrgvQueue.setTaskType("3");
|
||||
wcsSrgvQueue.setPriority(Long.parseLong("2"));
|
||||
wcsSrgvQueue.setCargo("0");
|
||||
wcsSrgvQueue.setIssued("0");
|
||||
wcsSrgvQueue.setExecutionStatus("1");
|
||||
wcsSrgvQueue.setCargoPickSite("");
|
||||
wcsSrgvQueue.setCargoPlaceSite("");
|
||||
wcsSrgvQueue.setStartSite(deviceSrgv.getCurrSite());
|
||||
|
||||
WcsSrgvMap wcsSrgvMap = wcsSrgvMapService.selectWcsSrgvMapBySiteId(chargingSite);
|
||||
if (wcsSrgvMap.getZ().equals(deviceSrgv.getCurrFloor())){
|
||||
wcsSrgvQueue.setEndSite(chargingSite);
|
||||
}else {
|
||||
wcsSrgvQueue.setEndSite("tsj");
|
||||
}
|
||||
wcsSrgvQueue.setTheFloor(deviceSrgv.getCurrFloor().toString());
|
||||
wcsSrgvQueue.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
wcsSrgvQueue.setAgvId(deviceSrgv.getDeviceId().toString());
|
||||
wcsSrgvQueue.setDefault02("3");
|
||||
wcsSrgvQueue.setDefault07(Convert.toStr(wcsSrgvMap.getZ()));
|
||||
wcsSagvQueueMapper.insertWcsSrgvQueue(wcsSrgvQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 四向小车任务处理
|
||||
*/
|
||||
|
||||
127
ruoyi-admin/src/main/resources/mapper/device/DeviceCdzMapper.xml
Normal file
127
ruoyi-admin/src/main/resources/mapper/device/DeviceCdzMapper.xml
Normal file
@@ -0,0 +1,127 @@
|
||||
<?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">
|
||||
<mapper namespace="com.ruoyi.device.cdz.mapper.DeviceCdzMapper">
|
||||
|
||||
<resultMap type="DeviceCdz" id="DeviceCdzResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="ip" column="ip" />
|
||||
<result property="port" column="port" />
|
||||
<result property="plcDbReadAddress" column="plc_db_read_address" />
|
||||
<result property="plcDbWriteAddress" column="plc_db_write_address" />
|
||||
<result property="rwh" column="rwh" />
|
||||
<result property="status" column="status" />
|
||||
<result property="xtxh" column="xtxh" />
|
||||
<result property="szcs" column="szcs" />
|
||||
<result property="model" column="model" />
|
||||
<result property="siteId" column="site_id" />
|
||||
<result property="spare1" column="spare1" />
|
||||
<result property="spare2" column="spare2" />
|
||||
<result property="spare3" column="spare3" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDeviceCdzVo">
|
||||
select id, name, ip, port, plc_db_read_address, plc_db_write_address, rwh, status, xtxh, szcs, model, site_id, spare1, spare2, spare3 from device_cdz
|
||||
</sql>
|
||||
|
||||
<select id="selectDeviceCdzList" parameterType="DeviceCdz" resultMap="DeviceCdzResult">
|
||||
<include refid="selectDeviceCdzVo"/>
|
||||
<where>
|
||||
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
||||
<if test="ip != null and ip != ''"> and ip = #{ip}</if>
|
||||
<if test="port != null and port != ''"> and port = #{port}</if>
|
||||
<if test="plcDbReadAddress != null and plcDbReadAddress != ''"> and plc_db_read_address = #{plcDbReadAddress}</if>
|
||||
<if test="plcDbWriteAddress != null and plcDbWriteAddress != ''"> and plc_db_write_address = #{plcDbWriteAddress}</if>
|
||||
<if test="rwh != null "> and rwh = #{rwh}</if>
|
||||
<if test="status != null "> and status = #{status}</if>
|
||||
<if test="xtxh != null "> and xtxh = #{xtxh}</if>
|
||||
<if test="szcs != null "> and szcs = #{szcs}</if>
|
||||
<if test="model != null "> and model = #{model}</if>
|
||||
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
||||
<if test="spare1 != null and spare1 != ''"> and spare1 = #{spare1}</if>
|
||||
<if test="spare2 != null and spare2 != ''"> and spare2 = #{spare2}</if>
|
||||
<if test="spare3 != null and spare3 != ''"> and spare3 = #{spare3}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceCdzById" parameterType="Long" resultMap="DeviceCdzResult">
|
||||
<include refid="selectDeviceCdzVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectDeviceCdzListNoSRgvId" resultMap="DeviceCdzResult">
|
||||
<include refid="selectDeviceCdzVo"/>
|
||||
where spare1 is null
|
||||
</select>
|
||||
|
||||
<insert id="insertDeviceCdz" parameterType="DeviceCdz">
|
||||
insert into device_cdz
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="ip != null">ip,</if>
|
||||
<if test="port != null">port,</if>
|
||||
<if test="plcDbReadAddress != null">plc_db_read_address,</if>
|
||||
<if test="plcDbWriteAddress != null">plc_db_write_address,</if>
|
||||
<if test="rwh != null">rwh,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="xtxh != null">xtxh,</if>
|
||||
<if test="szcs != null">szcs,</if>
|
||||
<if test="model != null">model,</if>
|
||||
<if test="siteId != null">site_id,</if>
|
||||
<if test="spare1 != null">spare1,</if>
|
||||
<if test="spare2 != null">spare2,</if>
|
||||
<if test="spare3 != null">spare3,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="ip != null">#{ip},</if>
|
||||
<if test="port != null">#{port},</if>
|
||||
<if test="plcDbReadAddress != null">#{plcDbReadAddress},</if>
|
||||
<if test="plcDbWriteAddress != null">#{plcDbWriteAddress},</if>
|
||||
<if test="rwh != null">#{rwh},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="xtxh != null">#{xtxh},</if>
|
||||
<if test="szcs != null">#{szcs},</if>
|
||||
<if test="model != null">#{model},</if>
|
||||
<if test="siteId != null">#{siteId},</if>
|
||||
<if test="spare1 != null">#{spare1},</if>
|
||||
<if test="spare2 != null">#{spare2},</if>
|
||||
<if test="spare3 != null">#{spare3},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateDeviceCdz" parameterType="DeviceCdz">
|
||||
update device_cdz
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="ip != null">ip = #{ip},</if>
|
||||
<if test="port != null">port = #{port},</if>
|
||||
<if test="plcDbReadAddress != null">plc_db_read_address = #{plcDbReadAddress},</if>
|
||||
<if test="plcDbWriteAddress != null">plc_db_write_address = #{plcDbWriteAddress},</if>
|
||||
<if test="rwh != null">rwh = #{rwh},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="xtxh != null">xtxh = #{xtxh},</if>
|
||||
<if test="szcs != null">szcs = #{szcs},</if>
|
||||
<if test="model != null">model = #{model},</if>
|
||||
<if test="siteId != null">site_id = #{siteId},</if>
|
||||
<if test="spare1 != null">spare1 = #{spare1},</if>
|
||||
<if test="spare2 != null">spare2 = #{spare2},</if>
|
||||
<if test="spare3 != null">spare3 = #{spare3},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteDeviceCdzById" parameterType="Long">
|
||||
delete from device_cdz where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteDeviceCdzByIds" parameterType="String">
|
||||
delete from device_cdz where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user