|
|
@@ -1,94 +1,258 @@
|
|
|
-package cn.iocoder.yudao.module.iscs.service.lotostation;
|
|
|
-
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import jakarta.annotation.Resource;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
-import cn.iocoder.yudao.module.iscs.controller.admin.lotostation.vo.*;
|
|
|
-import cn.iocoder.yudao.module.iscs.dal.dataobject.lotostation.LotoStationDO;
|
|
|
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-
|
|
|
-import cn.iocoder.yudao.module.iscs.dal.mysql.lotostation.LotoStationMapper;
|
|
|
-
|
|
|
-import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
|
|
-import static cn.iocoder.yudao.module.iscs.enums.ErrorCodeConstants.*;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-
|
|
|
-/**
|
|
|
- * 电柜 Service 实现类
|
|
|
- *
|
|
|
- * @author 芋道源码
|
|
|
- */
|
|
|
-@Service
|
|
|
-@Validated
|
|
|
-public class LotoStationServiceImpl extends ServiceImpl<LotoStationMapper, LotoStationDO> implements LotoStationService {
|
|
|
-
|
|
|
- @Resource
|
|
|
- private LotoStationMapper lotoStationMapper;
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long createLotoStation(LotoStationSaveReqVO createReqVO) {
|
|
|
- // 插入
|
|
|
- LotoStationDO lotoStation = BeanUtils.toBean(createReqVO, LotoStationDO.class);
|
|
|
- lotoStationMapper.insert(lotoStation);
|
|
|
-
|
|
|
- // 返回
|
|
|
- return lotoStation.getId();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void updateLotoStation(LotoStationSaveReqVO updateReqVO) {
|
|
|
- // 校验存在
|
|
|
- validateLotoStationExists(updateReqVO.getId());
|
|
|
- // 更新
|
|
|
- LotoStationDO updateObj = BeanUtils.toBean(updateReqVO, LotoStationDO.class);
|
|
|
- lotoStationMapper.updateById(updateObj);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void deleteLotoStation(Long id) {
|
|
|
- // 校验存在
|
|
|
- validateLotoStationExists(id);
|
|
|
- // 删除
|
|
|
- lotoStationMapper.deleteById(id);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void deleteLotoStationListByIds(List<Long> ids) {
|
|
|
- // 校验存在
|
|
|
- validateLotoStationExists(ids);
|
|
|
- // 删除
|
|
|
- lotoStationMapper.deleteByIds(ids);
|
|
|
- }
|
|
|
-
|
|
|
- private void validateLotoStationExists(List<Long> ids) {
|
|
|
- List<LotoStationDO> list = lotoStationMapper.selectByIds(ids);
|
|
|
- if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
|
|
- throw exception(LOTO_STATION_NOT_EXISTS);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void validateLotoStationExists(Long id) {
|
|
|
- if (lotoStationMapper.selectById(id) == null) {
|
|
|
- throw exception(LOTO_STATION_NOT_EXISTS);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public LotoStationDO getLotoStation(Long id) {
|
|
|
- return lotoStationMapper.selectById(id);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public PageResult<LotoStationDO> getLotoStationPage(LotoStationPageReqVO pageReqVO) {
|
|
|
- return lotoStationMapper.selectPage(pageReqVO);
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+package cn.iocoder.yudao.module.iscs.service.lotostation;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.isolationpoint.vo.BindingPointVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.isolationpoint.vo.PointDetailVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.lotostation.vo.LotoStationPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.lotostation.vo.LotoStationRespVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.lotostation.vo.LotoStationSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.lotostation.vo.PointsMapVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.isolationpoint.IsolationPointDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.jobticketpoints.JobTicketPointsDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.lotostation.LotoStationDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.map.MapDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.sop.SopPointsDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.mysql.lotostation.LotoStationMapper;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.isolationpoint.IsolationPointService;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.jobticketpoints.JobTicketPointsService;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.map.MapService;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.sop.SopPointsService;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.iocoder.yudao.module.iscs.enums.ErrorCodeConstants.LOTO_STATION_NOT_EXISTS;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 电柜 Service 实现类
|
|
|
+ *
|
|
|
+ * @author 芋道源码
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class LotoStationServiceImpl extends ServiceImpl<LotoStationMapper, LotoStationDO> implements LotoStationService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private LotoStationMapper lotoStationMapper;
|
|
|
+ @Resource
|
|
|
+ private MapService mapService;
|
|
|
+ @Resource
|
|
|
+ private IsolationPointService isolationPointService;
|
|
|
+ @Resource
|
|
|
+ private SopPointsService sopPointsService;
|
|
|
+ @Resource
|
|
|
+ private JobTicketPointsService jobTicketPointsService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long createLotoStation(LotoStationSaveReqVO createReqVO) {
|
|
|
+ Assert.notBlank(createReqVO.getLotoName(), "名称不可为空!");
|
|
|
+ // 判断名称重复
|
|
|
+ List<LotoStationDO> list = list(Wrappers.<LotoStationDO>lambdaQuery()
|
|
|
+ .eq(LotoStationDO::getLotoName, createReqVO.getLotoName()));
|
|
|
+ Assert.isTrue(list.isEmpty(), "该名称已被使用,请重新填写!");
|
|
|
+ // 判断序列号重复
|
|
|
+ List<LotoStationDO> list1 = list(Wrappers.<LotoStationDO>lambdaQuery()
|
|
|
+ .eq(LotoStationDO::getLotoSerialNumber, createReqVO.getLotoSerialNumber()));
|
|
|
+ Assert.isTrue(list1.isEmpty(), "该序列号已被使用,请重新填写!");
|
|
|
+ // 插入
|
|
|
+ LotoStationDO lotoStation = BeanUtils.toBean(createReqVO, LotoStationDO.class);
|
|
|
+ lotoStationMapper.insert(lotoStation);
|
|
|
+
|
|
|
+ // 返回
|
|
|
+ return lotoStation.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateLotoStation(LotoStationSaveReqVO updateReqVO) {
|
|
|
+ Assert.notNull(updateReqVO.getId(), "主键id不能为空!");
|
|
|
+ // 判断名称重复
|
|
|
+ List<LotoStationDO> list = list(Wrappers.<LotoStationDO>lambdaQuery()
|
|
|
+ .eq(LotoStationDO::getLotoName, updateReqVO.getLotoName())
|
|
|
+ .ne(LotoStationDO::getId, updateReqVO.getId()));
|
|
|
+ Assert.isTrue(list.isEmpty(), "该名称已被使用,请重新填写!");
|
|
|
+ // 判断序列号重复
|
|
|
+ List<LotoStationDO> list1 = list(Wrappers.<LotoStationDO>lambdaQuery()
|
|
|
+ .eq(LotoStationDO::getLotoSerialNumber, updateReqVO.getLotoSerialNumber())
|
|
|
+ .ne(LotoStationDO::getId, updateReqVO.getId()));
|
|
|
+ Assert.isTrue(list1.isEmpty(), "该序列号已被使用,请重新填写!");
|
|
|
+ update(Wrappers.<LotoStationDO>lambdaUpdate()
|
|
|
+ .eq(LotoStationDO::getId, updateReqVO.getId())
|
|
|
+ .set(LotoStationDO::getLotoName, updateReqVO.getLotoName())
|
|
|
+ .set(LotoStationDO::getLotoSerialNumber, updateReqVO.getLotoSerialNumber())
|
|
|
+ .set(LotoStationDO::getOrderNum, updateReqVO.getOrderNum())
|
|
|
+ .set(LotoStationDO::getMapId, updateReqVO.getMapId() != null ? updateReqVO.getMapId() : null)
|
|
|
+ .set(LotoStationDO::getWorkstationId, updateReqVO.getWorkstationId() != null ? updateReqVO.getWorkstationId() : null)
|
|
|
+ .set(LotoStationDO::getMap, StringUtils.isNotBlank(updateReqVO.getMap()) ? updateReqVO.getMap() : null));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteLotoStation(Long id) {
|
|
|
+ // 校验存在
|
|
|
+ validateLotoStationExists(id);
|
|
|
+ // 删除
|
|
|
+ lotoStationMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteLotoStationListByIds(List<Long> ids) {
|
|
|
+ // 校验存在
|
|
|
+ validateLotoStationExists(ids);
|
|
|
+ // 删除
|
|
|
+ lotoStationMapper.deleteByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateLotoStationExists(List<Long> ids) {
|
|
|
+ List<LotoStationDO> list = lotoStationMapper.selectByIds(ids);
|
|
|
+ if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
|
|
+ throw exception(LOTO_STATION_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateLotoStationExists(Long id) {
|
|
|
+ if (lotoStationMapper.selectById(id) == null) {
|
|
|
+ throw exception(LOTO_STATION_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LotoStationRespVO getLotoStation(Long id) {
|
|
|
+ LotoStationDO byId = getById(id);
|
|
|
+ LotoStationRespVO bean = BeanUtils.toBean(byId, LotoStationRespVO.class);
|
|
|
+ if (bean != null && bean.getMapId() != null) {
|
|
|
+ MapDO map = mapService.getById(bean.getMapId());
|
|
|
+ if (bean != null) {
|
|
|
+ bean.setMapName(map.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<LotoStationDO> getLotoStationPage(LotoStationPageReqVO pageReqVO) {
|
|
|
+ return lotoStationMapper.selectPage(pageReqVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LotoStationRespVO selectLotoBySerialNumber(String lotoSerialNumber) {
|
|
|
+ Assert.notBlank(lotoSerialNumber, "请提供loto柜序列号!");
|
|
|
+ LotoStationDO one = getOne(Wrappers.<LotoStationDO>lambdaQuery()
|
|
|
+ .eq(LotoStationDO::getLotoSerialNumber, lotoSerialNumber));
|
|
|
+ return BeanUtils.toBean(one, LotoStationRespVO.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PointsMapVO> selectLotoMapById(Long lotoId, Long sopId, Long ticketId) {
|
|
|
+ // 1.断言校验
|
|
|
+ Assert.notNull(lotoId, "请传入电柜id");
|
|
|
+ // 2.查询区域信息
|
|
|
+ LotoStationDO lotoStation = getById(lotoId);
|
|
|
+ // 3.解析map
|
|
|
+ List<PointsMapVO> points = new ArrayList<>();
|
|
|
+ if (lotoStation != null && StringUtils.isNotBlank(lotoStation.getMap())) {
|
|
|
+ String map = lotoStation.getMap();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ try {
|
|
|
+ points = objectMapper.readValue(map, new TypeReference<List<PointsMapVO>>(){});
|
|
|
+ // 4.补充点位name,隔离点类型,危险能量类型
|
|
|
+ List<Long> pointIds = points.stream().map(PointsMapVO::getPointId).collect(Collectors.toList());
|
|
|
+ List<PointDetailVO> pointDetailList = isolationPointService.getPointDetailList(pointIds);
|
|
|
+ // 5.获取sop信息
|
|
|
+ List<SopPointsDO> isSopPoints;
|
|
|
+ if (sopId != null) {
|
|
|
+ isSopPoints = sopPointsService.list(Wrappers.<SopPointsDO>lambdaQuery()
|
|
|
+ .eq(SopPointsDO::getSopId, sopId));
|
|
|
+ } else {
|
|
|
+ isSopPoints = new ArrayList<>();
|
|
|
+ }
|
|
|
+ // 6.获取作业票点位数据
|
|
|
+ List<JobTicketPointsDO> isJobTicketPoints;
|
|
|
+ if (ticketId != null) {
|
|
|
+ isJobTicketPoints = jobTicketPointsService.list(Wrappers.<JobTicketPointsDO>lambdaQuery()
|
|
|
+ .eq(JobTicketPointsDO::getTicketId, ticketId));
|
|
|
+ } else {
|
|
|
+ isJobTicketPoints = new ArrayList<>();
|
|
|
+ }
|
|
|
+ // 6.组装数据
|
|
|
+ points.stream().filter(o -> {
|
|
|
+ // 初始化选中状态
|
|
|
+ o.setState(false);
|
|
|
+ // 如果点位信息有,则填充
|
|
|
+ if (!pointDetailList.isEmpty()) {
|
|
|
+ for (PointDetailVO pointDetailVO : pointDetailList) {
|
|
|
+ if (o.getPointId().equals(pointDetailVO.getId())) {
|
|
|
+ o.setPointName(pointDetailVO.getPointName());
|
|
|
+ o.setPointType(pointDetailVO.getPointType());
|
|
|
+ o.setPointTypeName(pointDetailVO.getPointTypeName());
|
|
|
+ o.setPowerType(pointDetailVO.getPowerType());
|
|
|
+ o.setPowerTypeName(pointDetailVO.getPowerTypeName());
|
|
|
+ o.setPointIcon(pointDetailVO.getPointIcon());
|
|
|
+ o.setPointPicture(pointDetailVO.getPointPicture());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // sop如果选中信息有则开始标记
|
|
|
+ if (!isSopPoints.isEmpty()) {
|
|
|
+ for (SopPointsDO isSopPoint : isSopPoints) {
|
|
|
+ if (o.getPointId().equals(isSopPoint.getPointId())) {
|
|
|
+ o.setState(true);
|
|
|
+ // 根据sop的前置节点赋值
|
|
|
+ o.setPrePointId(isSopPoint.getPrePointId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 作业票如果选中信息有则开始标记
|
|
|
+ if (!isJobTicketPoints.isEmpty()) {
|
|
|
+ for (JobTicketPointsDO ticketPoint : isJobTicketPoints) {
|
|
|
+ if (o.getPointId().equals(ticketPoint.getPointId())) {
|
|
|
+ o.setState(true);
|
|
|
+ // 根据作业票的前置节点赋值
|
|
|
+ o.setPrePointId(ticketPoint.getPrePointId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ } catch (IOException e) {
|
|
|
+ Assert.isTrue(false, "map数据解析失败!");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return points;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updatePointsBindingLoto(BindingPointVO vo) {
|
|
|
+ Assert.notNull(vo.getLotoId(), "电柜ID不能为空!");
|
|
|
+ if (!vo.getBindingPointIds().isEmpty()) {
|
|
|
+ // 开始绑定
|
|
|
+ isolationPointService.update(Wrappers.<IsolationPointDO>lambdaUpdate()
|
|
|
+ .in(IsolationPointDO::getId, vo.getBindingPointIds())
|
|
|
+ .set(IsolationPointDO::getLotoId, vo.getLotoId()));
|
|
|
+ }
|
|
|
+ if (!vo.getUnbindPointIds().isEmpty()) {
|
|
|
+ // 开始解绑
|
|
|
+ isolationPointService.update(Wrappers.<IsolationPointDO>lambdaUpdate()
|
|
|
+ .in(IsolationPointDO::getId, vo.getUnbindPointIds())
|
|
|
+ .set(IsolationPointDO::getLotoId, null));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|