|
|
@ -1,22 +1,34 @@ |
|
|
|
package cn.iocoder.yudao.module.lock.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
|
|
|
import cn.iocoder.yudao.module.lock.dal.PointDO; |
|
|
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; |
|
|
|
import cn.iocoder.yudao.module.lock.dal.*; |
|
|
|
import cn.iocoder.yudao.module.lock.dal.entity.*; |
|
|
|
import cn.iocoder.yudao.module.lock.enums.ErrorCodeConstants; |
|
|
|
import cn.iocoder.yudao.module.lock.mapper.PointMapper; |
|
|
|
import cn.iocoder.yudao.module.lock.mapper.*; |
|
|
|
import cn.iocoder.yudao.module.lock.service.LockWorkRecordService; |
|
|
|
import cn.iocoder.yudao.module.lock.service.PointService; |
|
|
|
import cn.iocoder.yudao.module.lock.vo.PointPageReqVO; |
|
|
|
import cn.iocoder.yudao.module.lock.vo.PointSaveReqVO; |
|
|
|
import cn.iocoder.yudao.module.lock.util.WordUtils; |
|
|
|
import cn.iocoder.yudao.module.lock.vo.*; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static java.util.stream.Collectors.groupingBy; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -28,13 +40,42 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU |
|
|
|
@Validated |
|
|
|
public class PointServiceImpl implements PointService { |
|
|
|
|
|
|
|
private static final int LOCK_STATUS_UNLOCKED = 0; |
|
|
|
private static final int LOCK_STATUS_LOCKED = 5; |
|
|
|
private static final int UNLOCK_STATUS_LOCKED = 4; |
|
|
|
private static final int PLAN_ITEM_STATUS_UNLOCKED = 1; |
|
|
|
private static final int PLAN_STATUS_PARTIALLY_UNLOCKED = 2; |
|
|
|
private static final int LOCK_MAIN_STATUS_UNLOCKED = 2; |
|
|
|
private static final int CREATE_LOCK_STATUS = 7; |
|
|
|
private static final int VERITY_STATUS_UNLOCKED = 3; |
|
|
|
@Resource |
|
|
|
private PointMapper pointMapper; |
|
|
|
@Resource |
|
|
|
private IsolationPointMapper isolationPointMapper; |
|
|
|
@Resource |
|
|
|
private LockGuideMapper lockGuideMapper; |
|
|
|
@Resource |
|
|
|
private PlanItemDetailMapper planItemDetailMapper; |
|
|
|
@Resource |
|
|
|
private PlanItemMapper planItemMapper; |
|
|
|
@Resource |
|
|
|
private PlanLifeLockMapper planLifeLockMapper; |
|
|
|
@Resource |
|
|
|
private LockMapper lockMapper; |
|
|
|
@Resource |
|
|
|
private PlanMapper planMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Long createPoint(PointSaveReqVO createReqVO) { |
|
|
|
// 插入
|
|
|
|
PointDO point = BeanUtils.toBean(createReqVO, PointDO.class); |
|
|
|
|
|
|
|
QueryWrapper<PointDO> objectQueryWrapper = new QueryWrapper<>(); |
|
|
|
objectQueryWrapper.eq("ip_number", point.getIpNumber()); |
|
|
|
PointDO pointDO = pointMapper.selectOne(objectQueryWrapper); |
|
|
|
if (pointDO != null) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.POINT_NUMBER_EXISTS); |
|
|
|
} |
|
|
|
pointMapper.insert(point); |
|
|
|
|
|
|
|
// 返回
|
|
|
@ -45,6 +86,14 @@ public class PointServiceImpl implements PointService { |
|
|
|
public void updatePoint(PointSaveReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
validatePointExists(updateReqVO.getId()); |
|
|
|
|
|
|
|
QueryWrapper<PointDO> objectQueryWrapper = new QueryWrapper<>(); |
|
|
|
objectQueryWrapper.eq("ip_number", updateReqVO.getIpNumber()); |
|
|
|
PointDO pointDO = pointMapper.selectOne(objectQueryWrapper); |
|
|
|
if (pointDO != null && !pointDO.getId().equals(updateReqVO.getId())) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.POINT_NUMBER_EXISTS); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新
|
|
|
|
PointDO updateObj = BeanUtils.toBean(updateReqVO, PointDO.class); |
|
|
|
pointMapper.updateById(updateObj); |
|
|
@ -59,10 +108,10 @@ public class PointServiceImpl implements PointService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deletePointListByIds(List<Long> ids) { |
|
|
|
public void deletePointListByIds(List<Long> ids) { |
|
|
|
// 删除
|
|
|
|
pointMapper.deleteByIds(ids); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void validatePointExists(Long id) { |
|
|
@ -81,4 +130,224 @@ public class PointServiceImpl implements PointService { |
|
|
|
return pointMapper.selectPage(pageReqVO); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public LockEntity getListAll() { |
|
|
|
LockEntity lockEntity = new LockEntity(); |
|
|
|
lockEntity.setPointList(pointMapper.selectList()); |
|
|
|
lockEntity.setIsolationPointList(isolationPointMapper.selectList()); |
|
|
|
lockEntity.setLockGuideList(lockGuideMapper.selectList()); |
|
|
|
lockEntity.setPlanItemDetailList(planItemDetailMapper.selectList()); |
|
|
|
lockEntity.setPlanItemList(planItemMapper.selectList()); |
|
|
|
lockEntity.setPlanLifeLockList(planLifeLockMapper.selectList()); |
|
|
|
lockEntity.setLockList(lockMapper.selectList()); |
|
|
|
lockEntity.setPlanList(planMapper.selectList()); |
|
|
|
return lockEntity; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void bindlock(LockStatusVo updateReqVO) { |
|
|
|
|
|
|
|
QueryWrapper<PlanItemDetailDO> objectQueryWrapper = new QueryWrapper<>(); |
|
|
|
objectQueryWrapper.eq("id", updateReqVO.getPlanItemDetailId()); |
|
|
|
|
|
|
|
List<PlanItemDetailDO> planItemDetailDOS = planItemDetailMapper.selectList(objectQueryWrapper); |
|
|
|
if (CollectionUtils.isEmpty(planItemDetailDOS)) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.PLAN_ITEM_DETAIL_NOT_EXISTS); |
|
|
|
} |
|
|
|
if (planItemDetailDOS.get(0).getLockStatus().equals(1)) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.PLAN_ITEM_DETAIL_LOCK_STATUS_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
lockMapper.updateStatus(updateReqVO.getLockId(), 7);//上锁已验证
|
|
|
|
|
|
|
|
List<Long> pointIdList = planItemDetailDOS.stream().map(PlanItemDetailDO::getIsolationPointId).toList(); |
|
|
|
pointMapper.updateStatusBatch(pointIdList, 1); |
|
|
|
|
|
|
|
planItemDetailMapper.updateDetailLockStatus(1, updateReqVO.getPlanItemDetailId(), updateReqVO.getLockId(), null, null); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void createLock(LockStatusVo updateReqVO) { |
|
|
|
PlanItemDetailDO planItemDetailDO = planItemDetailMapper.selectById(updateReqVO.getPlanItemDetailId()); |
|
|
|
if (planItemDetailDO == null) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.PLAN_ITEM_DETAIL_NOT_EXISTS); |
|
|
|
} |
|
|
|
LockDO lockDO = lockMapper.selectById(planItemDetailDO.getLockId()); |
|
|
|
if (lockDO == null) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.LOCK_NOT_EXISTS); |
|
|
|
} |
|
|
|
if (lockDO.getLockStatus() != CREATE_LOCK_STATUS) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.LOCK_STATUS_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
lockMapper.updateStatus(lockDO.getId(), 3); |
|
|
|
planItemDetailMapper.updateDetailLockStatus(2, updateReqVO.getPlanItemDetailId(), null, updateReqVO.getOperateRecordld(), null); |
|
|
|
|
|
|
|
|
|
|
|
createPlanLiteLock(1, updateReqVO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void verifyLock(LockStatusVo updateReqVO) { |
|
|
|
PlanItemDetailDO planItemDetailDO = planItemDetailMapper.selectById(updateReqVO.getPlanItemDetailId()); |
|
|
|
if (planItemDetailDO == null) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.PLAN_ITEM_DETAIL_NOT_EXISTS); |
|
|
|
} |
|
|
|
if (planItemDetailDO.getLockStatus() != PLAN_STATUS_PARTIALLY_UNLOCKED) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.DETAIL_LOCK_VERITY_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
createPlanLiteLock(3, updateReqVO); |
|
|
|
planItemDetailMapper.updateDetailLockStatus(3, updateReqVO.getPlanItemDetailId(), null, null, updateReqVO.getVerifyRecordId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void verifyUnLock(LockStatusVo updateReqVO) { |
|
|
|
PlanItemDetailDO planItemDetailDO = planItemDetailMapper.selectById(updateReqVO.getPlanItemDetailId()); |
|
|
|
if (planItemDetailDO == null) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.PLAN_ITEM_DETAIL_NOT_EXISTS); |
|
|
|
} |
|
|
|
if (planItemDetailDO.getLockStatus() != VERITY_STATUS_UNLOCKED) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.DETAIL_LOCK_STATUS_ERROR); |
|
|
|
} |
|
|
|
QueryWrapper<PlanLifeLockDO> lockDOQueryWrapper = new QueryWrapper<>(); |
|
|
|
lockDOQueryWrapper.eq("isolation_plan_item_detail_id", planItemDetailDO.getId()); |
|
|
|
lockDOQueryWrapper.eq("lock_type", 5); |
|
|
|
List<PlanLifeLockDO> lockDOS = planLifeLockMapper.selectList(lockDOQueryWrapper); |
|
|
|
|
|
|
|
boolean lockStatus = lockDOS.stream().anyMatch(plan -> plan.getLockStatus() == 1); |
|
|
|
if (lockStatus) { |
|
|
|
throw exception(ErrorCodeConstants.PLAN_LIFE_LOCK_EXISTS); |
|
|
|
} |
|
|
|
planItemDetailDO.setLockStatus(UNLOCK_STATUS_LOCKED); |
|
|
|
|
|
|
|
planItemDetailMapper.updateById(planItemDetailDO); |
|
|
|
planLifeLockMapper.updateStatus(updateReqVO.getLifelockId(), 0, new Date()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void unLock(LockStatusVo updateReqVO) { |
|
|
|
|
|
|
|
PlanItemDetailDO planItemDetailDO = planItemDetailMapper.selectById(updateReqVO.getPlanItemDetailId()); |
|
|
|
if (planItemDetailDO == null) { |
|
|
|
throw exception(ErrorCodeConstants.PLAN_ITEM_DETAIL_NOT_EXISTS); |
|
|
|
} |
|
|
|
if (planItemDetailDO.getLockStatus() != UNLOCK_STATUS_LOCKED) { |
|
|
|
throw exception(ErrorCodeConstants.DETAIL_UNLOCK_STATUS_ERROR); |
|
|
|
} |
|
|
|
QueryWrapper<PlanLifeLockDO> lockDOQueryWrapper = new QueryWrapper<>(); |
|
|
|
lockDOQueryWrapper.eq("isolation_plan_item_detail_id", planItemDetailDO.getId()); |
|
|
|
lockDOQueryWrapper.eq("lock_type", 5); |
|
|
|
List<PlanLifeLockDO> lockDOS = planLifeLockMapper.selectList(lockDOQueryWrapper); |
|
|
|
|
|
|
|
boolean lockStatus = lockDOS.stream().anyMatch(plan -> plan.getLockStatus() == 1); |
|
|
|
if (lockStatus) { |
|
|
|
throw exception(ErrorCodeConstants.PLAN_LIFE_LOCK_EXISTS); |
|
|
|
} |
|
|
|
|
|
|
|
planItemDetailMapper.updateDetailLockStatus(LOCK_STATUS_LOCKED, updateReqVO.getPlanItemDetailId(), |
|
|
|
null, null, null); |
|
|
|
|
|
|
|
planLifeLockMapper.updateStatus(updateReqVO.getLifelockId(), LOCK_STATUS_UNLOCKED, new Date()); |
|
|
|
|
|
|
|
|
|
|
|
lockMapper.updateStatus(planItemDetailDO.getLockId(), LOCK_MAIN_STATUS_UNLOCKED); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 查询关联的生命锁状态
|
|
|
|
QueryWrapper<PlanLifeLockDO> lifeLockQuery = new QueryWrapper<PlanLifeLockDO>() |
|
|
|
.eq("isolation_plan_item_detail_id", updateReqVO.getPlanItemDetailId()); |
|
|
|
List<PlanLifeLockDO> lifeLocks = planLifeLockMapper.selectList(lifeLockQuery); |
|
|
|
|
|
|
|
|
|
|
|
boolean allUnlocked = lifeLocks.stream().allMatch(plan -> plan.getLockStatus() == LOCK_STATUS_UNLOCKED); |
|
|
|
|
|
|
|
|
|
|
|
QueryWrapper<PlanItemDetailDO> objectQueryWrapper11 = new QueryWrapper<>(); |
|
|
|
objectQueryWrapper11.eq("isolation_plan_item_id", planItemDetailDO.getIsolationPlanItemId()); |
|
|
|
List<PlanItemDetailDO> planItemDetailDOS1 = planItemDetailMapper.selectList(objectQueryWrapper11); |
|
|
|
|
|
|
|
boolean detailLocked = planItemDetailDOS1.stream().allMatch(plan -> plan.getLockStatus() == LOCK_STATUS_LOCKED); |
|
|
|
|
|
|
|
|
|
|
|
if (allUnlocked && detailLocked) { |
|
|
|
updatePlanAndItemStatus(planItemDetailDO.getIsolationPlanItemId(), updateReqVO.getPlanId()); |
|
|
|
} |
|
|
|
// 3. 更新隔离点位状态
|
|
|
|
QueryWrapper<PlanItemDetailDO> objectQueryWrapper1 = new QueryWrapper<>(); |
|
|
|
objectQueryWrapper1.eq("isolation_point_id", planItemDetailDO.getIsolationPointId()); |
|
|
|
List<PlanItemDetailDO> planItemDetailDOS = planItemDetailMapper.selectList(objectQueryWrapper1); |
|
|
|
boolean pointStatus = planItemDetailDOS.stream().allMatch(plan -> plan.getLockStatus() == LOCK_STATUS_LOCKED); |
|
|
|
if (pointStatus) { |
|
|
|
pointMapper.updateStatusBatch(Collections.singletonList(planItemDetailDO.getIsolationPointId()), 0); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void importPointsFromWord(MultipartFile file) { |
|
|
|
try { |
|
|
|
String rawContent = WordUtils.extractTextFromWord(file); |
|
|
|
LockWordPointVo lockWordPointVo = WordUtils.parseAndPrintStructuredContent(rawContent); |
|
|
|
|
|
|
|
ArrayList<PointDO> objects = new ArrayList<>(); |
|
|
|
if (CollectionUtil.isNotEmpty(lockWordPointVo.getDataVoList())) { |
|
|
|
for (LockWordPointDataVo lockWordPointDataVo : lockWordPointVo.getDataVoList()) { |
|
|
|
PointDO pointDO = new PointDO(); |
|
|
|
pointDO.setStatus(0); |
|
|
|
pointDO.setIpName(lockWordPointDataVo.getLocation()); |
|
|
|
pointDO.setIpNumber(lockWordPointDataVo.getSequence()); |
|
|
|
pointDO.setIpType("1"); |
|
|
|
pointDO.setGuideLockNums(Integer.valueOf(lockWordPointVo.getDeviceLock())); |
|
|
|
objects.add(pointDO); |
|
|
|
} |
|
|
|
} |
|
|
|
pointMapper.insertBatch(objects); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.IMPORT_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void updatePlanAndItemStatus(Long isolationPlanItemId, Long planId) { |
|
|
|
// 更新计划项状态
|
|
|
|
planItemMapper.updateStatus(isolationPlanItemId, PLAN_ITEM_STATUS_UNLOCKED); |
|
|
|
|
|
|
|
// 检查是否需要更新主计划的状态
|
|
|
|
QueryWrapper<PlanItemDO> planItemQuery = new QueryWrapper<PlanItemDO>() |
|
|
|
.eq("isolation_plan_id", planId); |
|
|
|
List<PlanItemDO> planItems = planItemMapper.selectList(planItemQuery); |
|
|
|
|
|
|
|
boolean anyPlanItemUnlocked = planItems.stream() |
|
|
|
.allMatch(plan -> plan.getStatus() == PLAN_ITEM_STATUS_UNLOCKED); |
|
|
|
|
|
|
|
|
|
|
|
if (anyPlanItemUnlocked) { |
|
|
|
planMapper.updateStatus(planId, PLAN_ITEM_STATUS_UNLOCKED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void createPlanLiteLock(Integer type, LockStatusVo updateReqVO) { |
|
|
|
Long userId = WebFrameworkUtils.getLoginUserId(); |
|
|
|
|
|
|
|
PlanLifeLockDO planLifeLockDO = new PlanLifeLockDO(); |
|
|
|
planLifeLockDO.setIsolationPlanItemDetailId(updateReqVO.getPlanItemDetailId()); |
|
|
|
planLifeLockDO.setUserId(userId); |
|
|
|
planLifeLockDO.setLockType(type); |
|
|
|
planLifeLockDO.setLockStatus(1); |
|
|
|
planLifeLockDO.setLockTime(LocalDateTime.now()); |
|
|
|
planLifeLockMapper.insert(planLifeLockDO); |
|
|
|
} |
|
|
|
|
|
|
|
} |