|
@@ -0,0 +1,295 @@
|
|
|
+package com.platform.service.remote.impl;
|
|
|
+
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.platform.common.exception.BusinessException;
|
|
|
+import com.platform.common.util.ListUtils;
|
|
|
+import com.platform.common.util.MapUtils;
|
|
|
+import com.platform.common.util.StringUtils;
|
|
|
+import com.platform.dao.bean.MyVOPage;
|
|
|
+import com.platform.dao.dto.remote.RemotePositionDTO;
|
|
|
+import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
|
|
|
+import com.platform.dao.entity.part.PartInfo;
|
|
|
+import com.platform.dao.entity.remote.RemotePosition;
|
|
|
+import com.platform.dao.entity.sb.SbInfo;
|
|
|
+import com.platform.dao.enums.DelFlagEnum;
|
|
|
+import com.platform.dao.enums.IconEnum;
|
|
|
+import com.platform.dao.enums.SbTreeTypeEnum;
|
|
|
+import com.platform.dao.enums.YesNoEnum;
|
|
|
+import com.platform.dao.mapper.part.PartInfoMapper;
|
|
|
+import com.platform.dao.mapper.remote.RemotePositionMapper;
|
|
|
+import com.platform.dao.mapper.sb.SbInfoMapper;
|
|
|
+import com.platform.dao.mapper.sqarepartmanage.SparePartUsedMapper;
|
|
|
+import com.platform.dao.pojo.CommonTreeScopedSlots;
|
|
|
+import com.platform.dao.pojo.MyCommonTree;
|
|
|
+import com.platform.dao.vo.remote.RemotePositionVO;
|
|
|
+import com.platform.dao.vo.spare.SparePartUsedVO;
|
|
|
+import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
+import com.platform.service.remote.RemotePositionService;
|
|
|
+import com.platform.service.util.ExecuteSql;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import tk.mybatis.mapper.weekend.Weekend;
|
|
|
+import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 设备位置 service 实现类
|
|
|
+ * @Author liuyu
|
|
|
+ * @Date 2020-04-21 20:52:22
|
|
|
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@Service("remotePositionService")
|
|
|
+public class RemotePositionServiceImpl extends BaseServiceImpl<RemotePositionMapper, RemotePosition, RemotePositionDTO> implements RemotePositionService {
|
|
|
+
|
|
|
+ private final PartInfoMapper partInfoMapper;
|
|
|
+
|
|
|
+ private final SparePartUsedMapper sparePartUsedMapper;
|
|
|
+
|
|
|
+ private final SbInfoMapper sbInfoMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteByPrimaryKey(String id) {
|
|
|
+
|
|
|
+ RemotePosition sbPosition = mapper.selectByPrimaryKey(id);
|
|
|
+ if(sbPosition!=null && sbPosition.getOpcFlag()== YesNoEnum.YES.getValue()){
|
|
|
+ throw new BusinessException("该车间是有工艺流程画面,无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ Weekend<SbInfo> weekend2 = new Weekend<>(SbInfo.class);
|
|
|
+ WeekendCriteria<SbInfo, Object> weekendCriteria2 = weekend2.weekendCriteria();
|
|
|
+ weekendCriteria2.andEqualTo(SbInfo::getPositionId, id);
|
|
|
+ List<SbInfo> sbInfoList = sbInfoMapper.selectByExample(weekend2);
|
|
|
+ if(!CollectionUtils.isEmpty(sbInfoList)){
|
|
|
+ throw new BusinessException("该车间下面有设备,无法删除,请先转移设备到其他车间");
|
|
|
+ }
|
|
|
+ sbPosition.setDelFlag(DelFlagEnum.DELETED.getValue());
|
|
|
+ mapper.updateByPrimaryKeySelective(sbPosition);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int batchDelete(List<String> ids) {
|
|
|
+ for(String id:ids){
|
|
|
+ this.deleteByPrimaryKey(id);
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RemotePosition saveModelByDTO(RemotePositionDTO model) {
|
|
|
+ // 获取父级
|
|
|
+ String parentId = model.getParentId();
|
|
|
+ RemotePosition parent = null;
|
|
|
+ /*if (StringUtils.isNotBlank(parentId)) {
|
|
|
+ parent = mapper.selectByPrimaryKeyForUpdate(parentId);
|
|
|
+ Weekend<RemotePosition> weekendCount = new Weekend<>(RemotePosition.class);
|
|
|
+ WeekendCriteria<RemotePosition, Object> weekendCriteriaCount = weekendCount.weekendCriteria();
|
|
|
+ weekendCriteriaCount.andEqualTo(RemotePosition::getParentId, parentId);
|
|
|
+ int i = mapper.selectCountByExample(weekendCount);
|
|
|
+ String code = IdGeneratorUtils.getStrNum(parent.getCode(), ++i);
|
|
|
+ model.setCode(code);
|
|
|
+ } else {
|
|
|
+ Weekend<RemotePosition> weekendCount = new Weekend<>(RemotePosition.class);
|
|
|
+ WeekendCriteria<RemotePosition, Object> weekendCriteriaCount = weekendCount.weekendCriteria();
|
|
|
+ weekendCriteriaCount.orEqualTo(RemotePosition::getParentId, "");
|
|
|
+ weekendCriteriaCount.orIsNull(RemotePosition::getParentId);
|
|
|
+ int i = mapper.selectCountByExample(weekendCount);
|
|
|
+ String code = IdGeneratorUtils.getStrNum("", ++i);
|
|
|
+ model.setCode(code);
|
|
|
+ }*/
|
|
|
+ Weekend<RemotePosition> weekend = new Weekend<>(RemotePosition.class);
|
|
|
+ WeekendCriteria<RemotePosition, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ weekendCriteria.andEqualTo(RemotePosition::getNo, model.getNo());
|
|
|
+ RemotePosition example = mapper.selectOneByExample(weekend);
|
|
|
+ if(example !=null){
|
|
|
+ throw new BusinessException("位号重复,请重新设置位号");
|
|
|
+ }
|
|
|
+ RemotePosition sbPosition = super.saveModelByDTO(model);
|
|
|
+ if (parent != null) {
|
|
|
+ mapper.updateByPrimaryKeySelective(new RemotePosition().setId(parentId).setUpdateTime(LocalDateTime.now()));
|
|
|
+ }
|
|
|
+ return sbPosition;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void modModelByDTO(RemotePositionDTO model) {
|
|
|
+ Weekend<RemotePosition> weekend = new Weekend<>(RemotePosition.class);
|
|
|
+ WeekendCriteria<RemotePosition, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ weekendCriteria.andEqualTo(RemotePosition::getNo, model.getNo());
|
|
|
+ RemotePosition example = mapper.selectOneByExample(weekend);
|
|
|
+ if(example !=null && !example.getId().equals(model.getId())){
|
|
|
+ throw new BusinessException("位号重复,请重新设置位号");
|
|
|
+ }
|
|
|
+ String parentId = model.getParentId();
|
|
|
+
|
|
|
+ // 之前没有编码,则设置编码
|
|
|
+ /* if(StringUtils.isBlank(model.getCode())){
|
|
|
+ if (StringUtils.isNotBlank(parentId)) {
|
|
|
+ Weekend<RemotePosition> weekendCount = new Weekend<>(RemotePosition.class);
|
|
|
+ WeekendCriteria<RemotePosition, Object> weekendCriteriaCount = weekendCount.weekendCriteria();
|
|
|
+ weekendCriteriaCount.andEqualTo(RemotePosition::getParentId, parentId);
|
|
|
+ int i = mapper.selectCountByExample(weekendCount);
|
|
|
+ String code = IdGeneratorUtils.getStrNum(parent.getCode(), ++i);
|
|
|
+ model.setCode(code);
|
|
|
+ } else {
|
|
|
+ Weekend<RemotePosition> weekendCount = new Weekend<>(RemotePosition.class);
|
|
|
+ WeekendCriteria<RemotePosition, Object> weekendCriteriaCount = weekendCount.weekendCriteria();
|
|
|
+ weekendCriteriaCount.orEqualTo(RemotePosition::getParentId, "");
|
|
|
+ weekendCriteriaCount.orIsNull(RemotePosition::getParentId);
|
|
|
+ int i = mapper.selectCountByExample(weekendCount);
|
|
|
+ String code = IdGeneratorUtils.getStrNum("",i);
|
|
|
+ model.setCode(code);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if (!entity.getParentId().equals(parentId)) {// 更换父级编码
|
|
|
+ if(StringUtils.isBlank(parent.getCode())){
|
|
|
+ throw new BusinessException("父级区域关联编码未设置,请联系技术,或者修改父级信息,重新保存");
|
|
|
+ }
|
|
|
+ String newCode = parent.getCode() + model.getCode().substring(model.getCode().length()-3);
|
|
|
+ model.setCode(newCode);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ super.modModelByDTO(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RemotePosition> getModelListByDTO(RemotePositionDTO model) {
|
|
|
+ Weekend<RemotePosition> weekend = new Weekend<>(RemotePosition.class);
|
|
|
+ setWeekendCriteria(weekend, model);
|
|
|
+ return mapper.selectByExample(weekend);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置查询条件
|
|
|
+ */
|
|
|
+ private void setWeekendCriteria(Weekend<RemotePosition> weekend, RemotePositionDTO model) {
|
|
|
+ WeekendCriteria<RemotePosition, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ ExecuteSql.executeNotNull(model.getId(), () -> weekendCriteria.andNotEqualTo(RemotePosition::getId, model.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<MyCommonTree> getSbTreeVOList(RemotePositionDTO model) {
|
|
|
+ List<SbInfo> sbInfoList = sbInfoMapper.selectAll();
|
|
|
+ // 查询所有的部位
|
|
|
+ List<PartInfo> partInfoList = partInfoMapper.selectAll();
|
|
|
+ // 查询所有使用备件
|
|
|
+ List<SparePartUsedVO> sparePartUsedList = sparePartUsedMapper.selectVOList(new SparePartUsedDTO());
|
|
|
+ // 查询所有设备位置
|
|
|
+ List<RemotePosition> sbPositions = mapper.selectAll();
|
|
|
+ // 处理设备类型
|
|
|
+ List<MyCommonTree> result = ListUtils.newArrayList();
|
|
|
+ Map<String, MyCommonTree> sbPositionTreeMap = MapUtils.newHashMap();
|
|
|
+ sbPositions.forEach(item -> {
|
|
|
+ MyCommonTree vo = new MyCommonTree();
|
|
|
+ vo.setId(item.getId());
|
|
|
+ vo.setKey(SbTreeTypeEnum.POSITION.getValue() + item.getId());
|
|
|
+ vo.setTitle(item.getName());
|
|
|
+ vo.setParentId(item.getParentId());
|
|
|
+ vo.setScopedSlots(new CommonTreeScopedSlots(IconEnum.POSITION.getValue()));
|
|
|
+ sbPositionTreeMap.put(vo.getId(), vo);
|
|
|
+ });
|
|
|
+ sbPositionTreeMap.forEach((key, item) -> {
|
|
|
+ String parentId = item.getParentId();
|
|
|
+ if (StringUtils.isBlank(parentId)) {
|
|
|
+ result.add(item);
|
|
|
+ } else {
|
|
|
+ MyCommonTree vo = sbPositionTreeMap.get(parentId);
|
|
|
+ if (vo != null) {
|
|
|
+ vo.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 处理设备
|
|
|
+ Map<String, MyCommonTree> sbInfoTreeMap = MapUtils.newHashMap();
|
|
|
+ sbInfoList.forEach(item -> {
|
|
|
+ MyCommonTree vo = new MyCommonTree();
|
|
|
+ vo.setId(item.getId());
|
|
|
+ vo.setKey(SbTreeTypeEnum.SB_INFO.getValue() + item.getId());
|
|
|
+ vo.setTitle(item.getName());
|
|
|
+ vo.setParentId(item.getParentId());
|
|
|
+ vo.setScopedSlots(new CommonTreeScopedSlots(IconEnum.SB_INFO.getValue()));
|
|
|
+ sbInfoTreeMap.put(vo.getId(), vo);
|
|
|
+ });
|
|
|
+ sbInfoList.forEach(item -> {
|
|
|
+ MyCommonTree vo = sbInfoTreeMap.get(item.getId());
|
|
|
+ if (StringUtils.isNotBlank(item.getParentId())) {
|
|
|
+ MyCommonTree sbInfoTreeVO = sbInfoTreeMap.get(item.getParentId());
|
|
|
+ sbInfoTreeVO.add(vo);
|
|
|
+ } else {
|
|
|
+ MyCommonTree sbPositionTreeVO = sbPositionTreeMap.get(item.getPositionId());
|
|
|
+ if (sbPositionTreeVO == null) {
|
|
|
+ result.add(vo);
|
|
|
+ } else {
|
|
|
+ sbPositionTreeVO.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 处理所有部位
|
|
|
+ Map<String, MyCommonTree> sbPartTreeMap = MapUtils.newHashMap();
|
|
|
+ partInfoList.forEach(item -> {
|
|
|
+ MyCommonTree vo = new MyCommonTree();
|
|
|
+ vo.setId(item.getId());
|
|
|
+ vo.setKey(SbTreeTypeEnum.PART_INFO.getValue() + item.getId());
|
|
|
+ vo.setTitle(item.getName());
|
|
|
+ vo.setParentId(item.getSbId());
|
|
|
+ vo.setScopedSlots(new CommonTreeScopedSlots(IconEnum.PART_INFO.getValue()));
|
|
|
+ sbPartTreeMap.put(vo.getId(), vo);
|
|
|
+ });
|
|
|
+ partInfoList.forEach(item -> {
|
|
|
+ MyCommonTree sbInfoTreeVO = sbInfoTreeMap.get(item.getSbId());
|
|
|
+ if (sbInfoTreeVO != null) {
|
|
|
+ sbInfoTreeVO.add(sbPartTreeMap.get(item.getId()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 处理所有备件
|
|
|
+ Map<String, MyCommonTree> sparePartUsedTreeMap = MapUtils.newHashMap();
|
|
|
+ sparePartUsedList.forEach(item -> {
|
|
|
+ MyCommonTree vo = new MyCommonTree();
|
|
|
+ vo.setId(item.getId());
|
|
|
+ vo.setKey(SbTreeTypeEnum.SPARE_PART_USED.getValue() + item.getId());
|
|
|
+ vo.setTitle(item.getSpareName());
|
|
|
+ vo.setParentId(item.getSbId());
|
|
|
+ vo.setScopedSlots(new CommonTreeScopedSlots(IconEnum.SPARE_PART_USED.getValue()));
|
|
|
+ sparePartUsedTreeMap.put(vo.getId(), vo);
|
|
|
+ });
|
|
|
+ sparePartUsedList.forEach(item -> {
|
|
|
+ MyCommonTree sbInfoTreeVO = sbPartTreeMap.get(item.getPartId());
|
|
|
+ MyCommonTree vo = sparePartUsedTreeMap.get(item.getId());
|
|
|
+ if (sbInfoTreeVO == null) {
|
|
|
+ sbInfoTreeMap.get(item.getSbId()).getChildren().add(vo);
|
|
|
+ } else {
|
|
|
+ sbInfoTreeVO.add(vo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RemotePositionVO> selectVOList(RemotePositionDTO model) {
|
|
|
+ return mapper.selectVOList(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MyVOPage<RemotePositionVO> selectVOPage(RemotePositionDTO model, int pageNum, int pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ return new MyVOPage<>(mapper.selectVOList(model));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RemotePositionVO getById(Object id) {
|
|
|
+ return mapper.getById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RemotePositionVO> selectLongYanList(RemotePositionDTO dto) {
|
|
|
+ return mapper.selectLongYanList(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|