package com.qianwen.smartman.modules.cps.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
import com.qianwen.smartman.common.cache.RegionCache;
|
import com.qianwen.smartman.common.utils.Lambda;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.mp.base.BaseServiceImpl;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.cps.convert.WorkstationWorkbenchConvert;
|
import com.qianwen.smartman.modules.cps.entity.WorkstationWorkbench;
|
import com.qianwen.smartman.modules.cps.mapper.WorkstationWorkbenchMapper;
|
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
|
import com.qianwen.smartman.modules.cps.service.IWorkstationWorkbenchService;
|
import com.qianwen.smartman.modules.cps.vo.MachineInformationVO;
|
import com.qianwen.smartman.modules.cps.vo.WorkstationOfWorkbenchVO;
|
import com.qianwen.smartman.modules.cps.vo.WorkstationVO;
|
import com.qianwen.smartman.modules.cps.vo.WorkstationWorkbenchVO;
|
import com.qianwen.smartman.modules.dnc.entity.DncWsRelationTd;
|
import com.qianwen.smartman.modules.dnc.entity.TransferDirectory;
|
import com.qianwen.smartman.modules.dnc.service.IDncWsRelationTdService;
|
import com.qianwen.smartman.modules.dnc.service.ITransferDirectoryService;
|
import com.qianwen.smartman.modules.trace.entity.TraceFlowSettings;
|
import com.qianwen.smartman.modules.trace.entity.TraceRelatedWorkstation;
|
import com.qianwen.smartman.modules.trace.service.ITraceFlowSettingsService;
|
import com.qianwen.smartman.modules.trace.service.ITraceRelatedWorkstationService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
|
@Service
|
public class WorkstationWorkbenchServiceImpl extends BaseServiceImpl<WorkstationWorkbenchMapper, WorkstationWorkbench> implements IWorkstationWorkbenchService {
|
@Autowired
|
@Lazy
|
private IWorkstationService workstationService;
|
@Autowired
|
private ITraceFlowSettingsService traceFlowSettingsService;
|
@Autowired
|
private ITraceRelatedWorkstationService traceRelatedWorkstationService;
|
@Autowired
|
private IDncWsRelationTdService dncWsRelationTdService;
|
@Autowired
|
private ITransferDirectoryService transferDirectoryService;
|
private final Integer SORT = 1;
|
private final Integer DEFAULT = 1;
|
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWorkbenchService
|
public Boolean saveWorkstationWorkbench(WorkstationWorkbenchVO vo) {
|
WorkstationWorkbench workbench = (WorkstationWorkbench)getOne(Wrappers.<WorkstationWorkbench>query().lambda()
|
.eq(WorkstationWorkbench::getWorkstationId, vo.getWorkstationId())
|
.eq(WorkstationWorkbench::getName, vo.getName()));
|
/*
|
WorkstationWorkbench workbench = (WorkstationWorkbench) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, vo.getWorkstationId())).eq((v0) -> {
|
return v0.getName();
|
}, vo.getName()));*/
|
if (Func.isNull(workbench)) {
|
WorkstationWorkbench workstationWorkbench = WorkstationWorkbenchConvert.INSTANCE.convert(vo);
|
workstationWorkbench.setId(vo.getId());
|
boolean save = save(workstationWorkbench);
|
return Boolean.valueOf(save);
|
}
|
throw new ServiceException(MessageUtils.message("work.station.work.bench.name.already.exist", new Object[0]));
|
}
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWorkbenchService
|
public MachineInformationVO listWorkstationWorkbench(Long workstationId) {
|
TransferDirectory transferDirectory;
|
MachineInformationVO machineInformationVO = new MachineInformationVO();
|
|
List<WorkstationWorkbench> workbenchList = list(Wrappers.<WorkstationWorkbench>query().lambda()
|
.eq(WorkstationWorkbench::getWorkstationId, workstationId)
|
.orderByAsc(WorkstationWorkbench::getSort));
|
/*
|
List<WorkstationWorkbench> workbenchList = list((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId)).orderByAsc((v0) -> {
|
return v0.getSort();
|
}));*/
|
WorkstationVO workstationVO = this.workstationService.getDetail(workstationId);
|
if (Func.isEmpty(workstationVO)) {
|
return machineInformationVO;
|
}
|
machineInformationVO.setWorkstationId(workstationId);
|
machineInformationVO.setWorkstationCode(workstationVO.getCode());
|
machineInformationVO.setAvatar(workstationVO.getAvatar());
|
machineInformationVO.setWorkstationList(workbenchList);
|
machineInformationVO.setDeviceType(workstationVO.getDeviceType());
|
machineInformationVO.setWorkstationName(workstationVO.getName());
|
machineInformationVO.setProperties(workstationVO.getProperties());
|
DncWsRelationTd relationTd = (DncWsRelationTd) this.dncWsRelationTdService.getOne(Lambda.eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId));
|
machineInformationVO.setTransmissionMode(workstationVO.getTransmissionMethod());
|
if (Func.isNotEmpty(relationTd) && (transferDirectory = (TransferDirectory) this.transferDirectoryService.getById(relationTd.getTransferDirectorId())) != null) {
|
machineInformationVO.setFtpCatalogue(transferDirectory.getName());
|
}
|
return machineInformationVO;
|
}
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWorkbenchService
|
public Boolean deleteWorkstationWorkbench(WorkstationWorkbenchVO vo) {
|
if (vo.getWorkbenchDefault().equals(this.DEFAULT)) {
|
throw new ServiceException(MessageUtils.message("work.station.default.work.bench.not.delete", new Object[0]));
|
}
|
List<WorkstationWorkbench> list = list(Wrappers.<WorkstationWorkbench>query().lambda()
|
.eq(WorkstationWorkbench::getWorkstationId, vo.getWorkstationId()));
|
/*
|
List<WorkstationWorkbench> list = list((Wrapper) Wrappers.query().lambda().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, vo.getWorkstationId()));*/
|
if (list.size() <= 1) {
|
throw new ServiceException(MessageUtils.message("work.station.work.bench.is.only.so.not.delete", new Object[0]));
|
}
|
|
boolean remove = remove(Wrappers.<WorkstationWorkbench>update().lambda()
|
.eq(WorkstationWorkbench::getWorkstationId, vo.getWorkstationId())
|
.eq(WorkstationWorkbench::getName, vo.getName()));
|
/*
|
boolean remove = remove((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, vo.getWorkstationId())).eq((v0) -> {
|
return v0.getName();
|
}, vo.getName()));*/
|
|
if (remove) {
|
List<WorkstationWorkbench> workbenchList = list(Wrappers.<WorkstationWorkbench>query().lambda()
|
.eq(WorkstationWorkbench::getWorkstationId, vo.getWorkstationId())
|
.ge(WorkstationWorkbench::getSort, vo.getSort()));
|
/*
|
List<WorkstationWorkbench> workbenchList = list((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, vo.getWorkstationId())).ge((v0) -> {
|
return v0.getSort();
|
}, vo.getSort()));*/
|
if (Func.isNotEmpty(workbenchList)) {
|
workbenchList.forEach(workbench -> {
|
workbench.setSort(Integer.valueOf(workbench.getSort().intValue() - this.SORT.intValue()));
|
});
|
return Boolean.valueOf(updateBatchById(workbenchList));
|
}
|
}
|
return Boolean.valueOf(remove);
|
}
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWorkbenchService
|
public Boolean updateWorkstationWorkbench(WorkstationWorkbenchVO vo) {
|
WorkstationWorkbench workbench = getOne(Wrappers.<WorkstationWorkbench>query().lambda()
|
.eq(WorkstationWorkbench::getWorkstationId, vo.getWorkstationId())
|
.eq(WorkstationWorkbench::getName, vo.getName()));
|
/*
|
WorkstationWorkbench workbench = (WorkstationWorkbench) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, vo.getWorkstationId())).eq((v0) -> {
|
return v0.getName();
|
}, vo.getName()));
|
*/
|
if (Func.isNull(workbench) || vo.getId().equals(workbench.getId())) {
|
return Boolean.valueOf(update(Wrappers.<WorkstationWorkbench>update().lambda()
|
.eq(WorkstationWorkbench::getId, vo.getId())
|
.set(WorkstationWorkbench::getName, vo.getName())));
|
/*
|
return Boolean.valueOf(update((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> {
|
return v0.getId();
|
}, vo.getId())).set((v0) -> {
|
return v0.getName();
|
}, vo.getName())));*/
|
}
|
throw new ServiceException(MessageUtils.message("work.station.work.bench.name.already.exist", new Object[0]));
|
}
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWorkbenchService
|
public List<WorkstationOfWorkbenchVO> listByGroupId(Long groupId, Long settingsId, String keyWord) {
|
List<Long> groupIds = this.workstationService.productionLineList(groupId);
|
if (Func.isEmpty(groupId)) {
|
return ((WorkstationWorkbenchMapper) this.baseMapper).listByGroupId(groupIds, keyWord);
|
}
|
List<Long> settingsIdList = this.traceFlowSettingsService.list(Wrappers.<TraceFlowSettings>lambdaQuery()
|
.eq(TraceFlowSettings::getWorkstationGroupId, groupId)
|
.ne(Func.isNotEmpty(settingsId), TraceFlowSettings::getId, settingsId))
|
.stream().map(TraceFlowSettings::getId).collect(Collectors.toList());
|
/*
|
List<Long> settingsIdList = (List) this.traceFlowSettingsService.list(((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getWorkstationGroupId();
|
}, groupId)).ne(Func.isNotEmpty(settingsId), (v0) -> {
|
return v0.getId();
|
}, settingsId)).stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());*/
|
if (Func.isEmpty(settingsIdList)) {
|
return ((WorkstationWorkbenchMapper) this.baseMapper).listByGroupId(groupIds, keyWord);
|
}
|
List<Long> workstationIdList = this.traceRelatedWorkstationService.list(Wrappers.<TraceRelatedWorkstation>lambdaQuery()
|
.in(TraceRelatedWorkstation::getTraceFlowSettingId, settingsIdList))
|
.stream().map(TraceRelatedWorkstation::getWorkstationId).collect(Collectors.toList());
|
/*
|
List<Long> workstationIdList = (List) this.traceRelatedWorkstationService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getTraceFlowSettingId();
|
}, settingsIdList)).stream().map((v0) -> {
|
return v0.getWorkstationId();
|
}).collect(Collectors.toList());*/
|
return ((WorkstationWorkbenchMapper) this.baseMapper).listByGroupIdAndWorkstationNotIn(groupIds, keyWord, workstationIdList);
|
}
|
}
|