|
|
@@ -2,11 +2,9 @@ package cn.iocoder.yudao.module.pms.service.iotoperationplan;
|
|
|
|
|
|
import cn.iocoder.yudao.module.pms.constant.PmsConstants;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
|
-import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationplandev.IotOperationPlanDevDO;
|
|
|
-import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillOrderMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationplandev.IotOperationPlanDevMapper;
|
|
|
@@ -36,8 +34,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationplan.IotOperationPlanMapper;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
-import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_DEVICE_NOT_EXISTS;
|
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_OPERATION_PLAN_NOT_EXISTS;
|
|
|
+import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.DEPT_NOT_FOUND;
|
|
|
import static cn.iocoder.yudao.module.pms.framework.config.MultiThreadConfiguration.PMS_THREAD_POOL_TASK_EXECUTOR;
|
|
|
|
|
|
|
|
|
@@ -56,8 +54,6 @@ public class IotOperationPlanServiceImpl implements IotOperationPlanService {
|
|
|
@Resource
|
|
|
private IotOperationPlanDevMapper planDevMapper;
|
|
|
@Resource
|
|
|
- private IotDeviceMapper iotDeviceMapper;
|
|
|
- @Resource
|
|
|
private IotOpeationFillMapper iotOpeationFillMapper;
|
|
|
@Resource
|
|
|
private IotOpeationFillOrderMapper iotOpeationFillOrderMapper;
|
|
|
@@ -137,16 +133,10 @@ public class IotOperationPlanServiceImpl implements IotOperationPlanService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public String manualGenerateByDeviceId(Long deviceId) {
|
|
|
- IotDeviceDO device = iotDeviceMapper.selectById(deviceId);
|
|
|
- if (device == null || device.getDeptId() == null) {
|
|
|
- throw exception(IOT_DEVICE_NOT_EXISTS);
|
|
|
- }
|
|
|
-
|
|
|
- Long deptId = device.getDeptId();
|
|
|
+ public String manualGenerateByDeptId(Long deptId) {
|
|
|
DeptDO dept = deptService.getDeptNoPermission(deptId);
|
|
|
if (dept == null) {
|
|
|
- throw exception(IOT_DEVICE_NOT_EXISTS);
|
|
|
+ throw exception(DEPT_NOT_FOUND);
|
|
|
}
|
|
|
|
|
|
IotOperationPlanDO plan = findNearestEnabledPlan(dept);
|
|
|
@@ -157,33 +147,31 @@ public class IotOperationPlanServiceImpl implements IotOperationPlanService {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
LocalDateTime beginTime = LocalDate.now().atStartOfDay();
|
|
|
LocalDateTime endTime = beginTime.plusDays(1);
|
|
|
- boolean deviceGeneratedToday = !iotOpeationFillMapper
|
|
|
- .selectOrderIdsByDeviceAndCreateTime(deviceId, beginTime, endTime).isEmpty();
|
|
|
+ List<Long> oldOrderIds = iotOpeationFillMapper
|
|
|
+ .selectOrderIdsByDeptAndCreateTime(deptId, beginTime, endTime);
|
|
|
|
|
|
- // 已经生成过的设备允许重建当天记录;尚未生成时必须先到达计划生成时间。
|
|
|
- if (!deviceGeneratedToday && now.isBefore(calculateNextCreateTime(plan))) {
|
|
|
+ // 已经生成过的部门允许重建当天记录;尚未生成时必须先到达计划生成时间。
|
|
|
+ if (oldOrderIds.isEmpty() && now.isBefore(calculateNextCreateTime(plan))) {
|
|
|
return "未到运行记录生成时间,无需生成";
|
|
|
}
|
|
|
- if (!deviceGeneratedToday && !"sg".equals(device.getDeviceStatus())) {
|
|
|
- return "当前设备不在施工状态,无需生成";
|
|
|
- }
|
|
|
|
|
|
- // 设备只是定位入口。重建时删除并重建它所在小部门当天的全部运行记录。
|
|
|
- List<Long> oldOrderIds = iotOpeationFillMapper
|
|
|
- .selectOrderIdsByDeptAndCreateTime(deptId, beginTime, endTime);
|
|
|
+ List<IotDeviceRespVO> constructionDevices = iotOpeationFillMapper
|
|
|
+ .getFillDevices2(Collections.singleton(deptId));
|
|
|
Set<Long> runLogDeviceIds = new HashSet<>();
|
|
|
- runLogDeviceIds.add(deviceId);
|
|
|
+ for (IotDeviceRespVO constructionDevice : constructionDevices) {
|
|
|
+ runLogDeviceIds.add(constructionDevice.getId());
|
|
|
+ }
|
|
|
if (!oldOrderIds.isEmpty()) {
|
|
|
runLogDeviceIds.addAll(iotOpeationFillMapper.selectDeviceIdsByOrderIds(oldOrderIds));
|
|
|
+ }
|
|
|
+ if (!runLogDeviceIds.isEmpty()) {
|
|
|
iotOpeationFillMapper.deleteManualRunLogs(runLogDeviceIds, beginTime, endTime);
|
|
|
+ }
|
|
|
+ if (!oldOrderIds.isEmpty()) {
|
|
|
iotOpeationFillMapper.logicalDeleteByOrderIds(oldOrderIds);
|
|
|
iotOpeationFillMapper.logicalDeleteOrdersByIds(oldOrderIds);
|
|
|
- } else {
|
|
|
- iotOpeationFillMapper.deleteManualRunLogs(runLogDeviceIds, beginTime, endTime);
|
|
|
}
|
|
|
|
|
|
- List<IotDeviceRespVO> constructionDevices = iotOpeationFillMapper
|
|
|
- .getFillDevices2(Collections.singleton(deptId));
|
|
|
if (constructionDevices.isEmpty()) {
|
|
|
return oldOrderIds.isEmpty()
|
|
|
? "当前小部门没有可生成运行记录的施工设备"
|