yanps
2 months ago
9 changed files with 339 additions and 21 deletions
@ -0,0 +1,71 @@ |
|||
package org.nl.quartz.task; |
|||
|
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import lombok.SneakyThrows; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.config.SpringContextHolder; |
|||
import org.nl.system.service.param.dao.Param; |
|||
import org.nl.system.service.param.impl.SysParamServiceImpl; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Profile; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.io.File; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* @author LENOVO |
|||
* 定时清理日志文件 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@Profile("prod") |
|||
public class AutoCleanFile { |
|||
|
|||
private static long DAYS_TO_MILLIS = TimeUnit.DAYS.toMillis(14); |
|||
|
|||
@Value("${logging.file.path}") |
|||
private String logPath; |
|||
|
|||
@SneakyThrows |
|||
public void run() { |
|||
log.info("定时清理日志文件AutoCleanFile开始:"); |
|||
File directory = new File(logPath); |
|||
if (directory.exists() && directory.isDirectory()) { |
|||
cleanDirectory(directory); |
|||
} else { |
|||
System.out.println("指定的路径不存在或不是一个目录。"); |
|||
} |
|||
} |
|||
|
|||
// 递归清理文件夹内的过期文件
|
|||
private static void cleanDirectory(File directory) { |
|||
File[] files = directory.listFiles(); |
|||
if (files != null) { |
|||
long currentTime = System.currentTimeMillis(); |
|||
for (File file : files) { |
|||
if (file.isDirectory()) { |
|||
// 如果是目录,递归调用
|
|||
cleanDirectory(file); |
|||
} else if (file.isFile()) { |
|||
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class); |
|||
Param byCode = sysParamService.findByCode("log_time"); |
|||
if (ObjectUtil.isNotNull(byCode)) { |
|||
DAYS_TO_MILLIS = TimeUnit.DAYS.toMillis(Long.parseLong(byCode.getValue())); |
|||
} |
|||
if (currentTime - file.lastModified() > DAYS_TO_MILLIS) { |
|||
boolean deleted = file.delete(); |
|||
if (deleted) { |
|||
log.info("已删除文件: " + file.getAbsolutePath()); |
|||
} else { |
|||
log.info("无法删除文件: " + file.getAbsolutePath()); |
|||
} |
|||
} else { |
|||
log.info("文件未超过七天, 不做任何修改: " + file.getAbsolutePath()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,173 @@ |
|||
package org.nl.wms.sch.task_manage.task.tasks.handheld; |
|||
|
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.common.enums.GoodsEnum; |
|||
import org.nl.common.exception.BadRequestException; |
|||
import org.nl.system.service.notice.ISysNoticeService; |
|||
import org.nl.wms.ext.acs.service.dto.to.BaseResponse; |
|||
import org.nl.wms.ext.fab.service.dto.SendVehicleVo; |
|||
import org.nl.wms.sch.group.service.ISchBaseVehiclematerialgroupService; |
|||
import org.nl.wms.sch.group.service.dao.SchBaseVehiclematerialgroup; |
|||
import org.nl.wms.sch.point.service.ISchBasePointService; |
|||
import org.nl.wms.sch.point.service.dao.SchBasePoint; |
|||
import org.nl.wms.sch.task.service.ISchBaseTaskService; |
|||
import org.nl.wms.sch.task.service.ISchBaseTaskconfigService; |
|||
import org.nl.wms.sch.task.service.dao.SchBaseTask; |
|||
import org.nl.wms.sch.task_manage.AbstractTask; |
|||
import org.nl.wms.sch.task_manage.GeneralDefinition; |
|||
import org.nl.wms.sch.task_manage.enums.NoticeTypeEnum; |
|||
import org.nl.wms.sch.task_manage.enums.TaskFinishedTypeEnum; |
|||
import org.nl.wms.sch.task_manage.task.core.TaskStatus; |
|||
import org.nl.wms.util.PointUtils; |
|||
import org.nl.wms.util.TaskUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author LENOVO |
|||
* 空托盘送回 |
|||
*/ |
|||
@Slf4j |
|||
@Component(value = "ATTask") |
|||
public class AtTask extends AbstractTask { |
|||
|
|||
private static final String TASK_CONFIG_CODE = "ATTask"; |
|||
@Autowired |
|||
private ISchBasePointService pointService; |
|||
@Autowired |
|||
private ISchBaseTaskService taskService; |
|||
@Autowired |
|||
private ISchBaseTaskconfigService taskConfigService; |
|||
@Autowired |
|||
private ISysNoticeService noticeService; |
|||
@Autowired |
|||
private ISchBasePointService schBasePointService; |
|||
@Autowired |
|||
private ISchBaseVehiclematerialgroupService schBaseVehiclematerialgroupService; |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
protected void create() throws BadRequestException { |
|||
// 获取任务
|
|||
List<SchBaseTask> tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY); |
|||
|
|||
for (SchBaseTask task : tasks) { |
|||
TaskUtils.setUpdateByAcs(task); |
|||
SendVehicleVo sendVehicleVo = JSONObject.parseObject(task.getRequest_param(), SendVehicleVo.class); |
|||
//查询地面点位的载具编码
|
|||
// 根据对接位查找对应的载具类型
|
|||
SchBasePoint schBasePoint = schBasePointService.selectPointByEmpAndRegion(sendVehicleVo.getRegion_code(), task.getVehicle_code(), "0"); |
|||
if (ObjectUtil.isEmpty(schBasePoint)) { |
|||
task.setRemark("未找到所需点位!"); |
|||
taskService.updateById(task); |
|||
// 消息通知
|
|||
noticeService.createNotice("未找到所需点位!", TASK_CONFIG_CODE + task.getTask_code(), |
|||
NoticeTypeEnum.WARN.getCode()); |
|||
continue; |
|||
} |
|||
//删除组盘信息
|
|||
schBaseVehiclematerialgroupService.remove(new QueryWrapper<SchBaseVehiclematerialgroup>() |
|||
.eq("vehicle_code", schBasePoint.getVehicle_code())); |
|||
taskService.update(new UpdateWrapper<SchBaseTask>() |
|||
.set("task_status", TaskStatus.CREATED.getCode()) |
|||
.set("point_code2", schBasePoint.getPoint_code()) |
|||
.eq("task_id", task.getTask_id())); |
|||
|
|||
//更新点位信息
|
|||
schBasePoint.setIng_task_code(task.getTask_code()); |
|||
schBasePoint.setIs_lock(true); |
|||
schBasePoint.setPoint_status(GoodsEnum.EMPTY_PALLETS.getValue()); |
|||
PointUtils.setUpdateByAcs(schBasePoint); |
|||
pointService.updateById(schBasePoint); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
protected void updateStatus(String task_code, TaskStatus status) { |
|||
//TODO:完成任务的时候将int_task_code的清除
|
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void forceFinish(String task_code) { |
|||
SchBaseTask taskObj = taskService.getByCode(task_code); |
|||
if (ObjectUtil.isEmpty(taskObj)) { |
|||
throw new BadRequestException("该任务不存在"); |
|||
} |
|||
this.finishTask(taskObj, TaskFinishedTypeEnum.MANUAL_CONNECTOR); |
|||
} |
|||
|
|||
@Override |
|||
public void cancel(String task_code) { |
|||
//TODO:取消任务的时候将int_task_code的清除
|
|||
SchBaseTask taskObj = taskService.getByCode(task_code); |
|||
if (ObjectUtil.isEmpty(taskObj)) { |
|||
throw new BadRequestException("该任务不存在"); |
|||
} |
|||
this.cancelTask(taskObj, TaskFinishedTypeEnum.MANUAL_CONNECTOR); |
|||
} |
|||
|
|||
@Override |
|||
protected void feedbackTaskState(JSONObject param, SchBaseTask schBaseTask, BaseResponse result) { |
|||
|
|||
} |
|||
|
|||
public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { |
|||
// 获取参数
|
|||
String startPoint = taskObj.getPoint_code1(); |
|||
SchBasePoint schBasePoint = pointService.selectByPointCode(startPoint); |
|||
// 起点清空
|
|||
if (ObjectUtil.isNotEmpty(schBasePoint)) { |
|||
PointUtils.updateByIngTaskCode(schBasePoint); |
|||
pointService.update(Wrappers.lambdaUpdate(SchBasePoint.class).eq(SchBasePoint::getPoint_code, startPoint) |
|||
.set(SchBasePoint::getIs_lock, false) |
|||
.set(SchBasePoint::getVehicle_code, null)); |
|||
} |
|||
String point_code2 = taskObj.getPoint_code2(); |
|||
SchBasePoint schBasePoint2 = pointService.selectByPointCode(point_code2); |
|||
if (ObjectUtil.isNotEmpty(schBasePoint2)) { |
|||
PointUtils.updateByIngTaskCode(schBasePoint2); |
|||
pointService.update(Wrappers.lambdaUpdate(SchBasePoint.class).eq(SchBasePoint::getPoint_code, point_code2) |
|||
.set(SchBasePoint::getIs_lock, false) |
|||
.set(SchBasePoint::getVehicle_code, taskObj.getVehicle_code())); |
|||
} |
|||
// 任务完成
|
|||
taskObj.setTask_status(TaskStatus.FINISHED.getCode()); |
|||
taskObj.setRemark(GeneralDefinition.TASK_FINISH); |
|||
taskObj.setFinished_type(taskFinishedType.getCode()); |
|||
TaskUtils.setUpdateByType(taskObj, taskFinishedType); |
|||
taskService.updateById(taskObj); |
|||
} |
|||
|
|||
public void cancelTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { |
|||
// 获取参数
|
|||
String startPoint = taskObj.getPoint_code1(); |
|||
SchBasePoint schBasePoint = pointService.selectByPointCode(startPoint); |
|||
// 起点清空
|
|||
if (ObjectUtil.isNotEmpty(schBasePoint)) { |
|||
PointUtils.updateByIngTaskCode(schBasePoint); |
|||
pointService.updateById(schBasePoint); |
|||
} |
|||
String point_code2 = taskObj.getPoint_code2(); |
|||
SchBasePoint schBasePoint2 = pointService.selectByPointCode(point_code2); |
|||
if (ObjectUtil.isNotEmpty(schBasePoint2)) { |
|||
PointUtils.updateByIngTaskCode(schBasePoint2); |
|||
pointService.updateById(schBasePoint2); |
|||
} |
|||
taskObj.setTask_status(TaskStatus.CANCELED.getCode()); |
|||
taskObj.setRemark(GeneralDefinition.TASK_CANCEL); |
|||
taskObj.setTask_status(TaskStatus.CANCELED.getCode()); |
|||
taskObj.setFinished_type(taskFinishedType.getCode()); |
|||
TaskUtils.setUpdateByType(taskObj, taskFinishedType); |
|||
taskService.updateById(taskObj); |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue