yangys
2024-03-29 7d18c733d4c4109f2bc8e5b176cfde74c490a207
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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);
    }
}