yangys
2025-11-21 e8ed1a91c77ab62a924f12acd55777f227bacd7e
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
package com.qianwen.smartman.modules.smis.service.impl;
 
import java.util.List;
import java.util.stream.Collectors;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.common.utils.MessageUtils;
import com.qianwen.smartman.modules.smis.convert.WorkstationWorkbenchConvert;
import com.qianwen.smartman.modules.smis.entity.WorkstationWorkbench;
import com.qianwen.smartman.modules.smis.mapper.WorkstationWorkbenchMapper;
import com.qianwen.smartman.modules.smis.service.IWorkstationService;
import com.qianwen.smartman.modules.smis.service.IWorkstationWorkbenchService;
import com.qianwen.smartman.modules.smis.vo.MachineInformationVO;
import com.qianwen.smartman.modules.smis.vo.WorkstationOfWorkbenchVO;
import com.qianwen.smartman.modules.smis.vo.WorkstationVO;
import com.qianwen.smartman.modules.smis.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;
 
@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
    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
    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));
        
        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(DncWsRelationTd::getWorkstationId, workstationId));
        machineInformationVO.setTransmissionMode(workstationVO.getTransmissionMethod());
        if (Func.isNotEmpty(relationTd) && (transferDirectory = this.transferDirectoryService.getById(relationTd.getTransferDirectorId())) != null) {
            machineInformationVO.setFtpCatalogue(transferDirectory.getName());
        }*/
        return machineInformationVO;
    }
 
    @Override
    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 
    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]));
    }
 
    
    public List<WorkstationOfWorkbenchVO> listByGroupId(Long groupId, Long settingsId, String keyWord) {
        List<Long> groupIds = this.workstationService.productionLineList(groupId);
        if (Func.isEmpty(groupId)) {
            return 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 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);
    }
}