严智鑫
2025-11-13 945bc394f40d8af1072a53da9a94f24207124e6d
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
package com.northglass.service.countmachinetask;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.hibernate.transform.ResultTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import com.google.common.primitives.Ints;
import com.northglass.constants.StateConstants.CountMachineTaskState;
import com.northglass.entity.CountMachineTask;
import com.northglass.entity.Glass;
import com.northglass.entity.RawPackageTxt;
import com.northglass.repository.CountMachineTaskDao;
import com.northglass.repository.GlassDao;
import com.northglass.repository.RawPackageTxtDao;
import com.northglass.service.machinetask.MachineTaskService;
 
import freemarker.core.ReturnInstruction.Return;
 
@Component
@Transactional
public class CountMachineTaskService extends MachineTaskService {
 
    private static final Logger LOGGER = LoggerFactory.getLogger(CountMachineTaskService.class);
    
    @Autowired
    private CountMachineTaskDao countMachineTaskDao;
    
    @Autowired
    private GlassDao glassDao;
    
    @Autowired
    private  RawPackageTxtDao rawPackageTxtDao;
    
    /**
     * 用于预处理产线巡检,目前测量后是下片。
     * 在此过程中,若发现破损玻璃,则将玻璃移出产线,同时下片机相应任务也要移出队列;
     * 
     * 过期,使用下面方法,把巡检嵌在下片页面中
     * @return 
     */
    public String getCountMachineTaskForManualCheckHtml(long CountMachineid) {
        LOGGER.trace("> Start getCountMachineTaskForManualCheckHtml");
        
        List<CountMachineTask> taskList = countMachineTaskDao.findByCountMachine(CountMachineid);
        LOGGER.trace("taskList size: " + taskList.size());
        
        StringBuffer html = new StringBuffer("<table class='table table-striped table-hover'>");
        html.append("<thead><tr><th>状态</th><th>批次编号</th><th>下片机</th><th>玻璃信息</th>");
        html.append("<th>完成时间</th><th>操作</th></tr></thead><tbody>");
        
        for (CountMachineTask task : taskList) {
            if(task.getState().equals(CountMachineTaskState.COMPLETED)){
                continue;
            }
            html.append("<tr").append(getMachineTaskHtmlClass(task.getState())).append(">");
            html.append("<td>").append(task.getState()).append("</td>");
            html.append("<td>").append(task.getRawPackageTxt() == null ? "" : task.getRawPackageTxt().getTxt_name()).append("</td>");
            html.append("<td>").append(task.getCountMachine() == null ? "" : task.getCountMachine().getNumber()).append("</td>");
            html.append("<td>").append(task.getGlass() == null ? "" : task.getGlass().getDescription()).append("</td>");
            html.append("<td>").append(formatTime(task.getCompleteTime())).append("</td>");
            
            html.append("<td>");
            if (task.getState().equals(CountMachineTaskState.IN_WORK) || task.getState().equals(CountMachineTaskState.WAITING)) {
                html.append("<a href='/gmms/manage/manualCheckError/").append(task.getId())
                    .append("' class='btn btn-danger'>报错</a>&nbsp;&nbsp;");
            }
            html.append("</td>");
            
            html.append("</tr>");
        }
        
        html.append("</tbody></table>");
        LOGGER.trace("> End getCountMachineTaskForManualCheckHtml");
        return html.toString();
    }
    
//    /**
//     * 用于预处理产线巡检,目前测量后是双边磨。
//     * 在此过程中,若发现破损玻璃,则将玻璃移出产线,同时下片机相应任务也要移出队列;
//     * 
//     * @return
//     */
//    public String getGrindForManualCheckHtml() {
//        List<GrindEdgeMachineTask> taskList = new ArrayList<GrindEdgeMachineTask>();
//        
//        GrindEdgeMachineTask inWorkTask = grindEdgeMachineTaskDao.findInWorkTask();
//        if (inWorkTask != null) {
//            taskList.add(inWorkTask);
//        }
//        
//        taskList.addAll(grindEdgeMachineTaskDao.findWarningTasks());
//        taskList.addAll(grindEdgeMachineTaskDao.findWaitingTasks());
//        LOGGER.trace("taskList size: " + taskList.size());
//        
//        StringBuffer html = new StringBuffer("<table class='table table-striped table-hover'>");
//        html.append("<thead><tr><th>状态</th><th>批次编号</th><th>磨边机编号</th><th>玻璃信息</th>");
//        html.append("<th>完成时间</th><th>操作</th></tr></thead><tbody>");
//        
//        for (GrindEdgeMachineTask task : taskList) {
//            html.append("<tr ").append(getMachineTaskHtmlClass(task.getState())).append(">");
//            html.append("<td>").append(task.getState()).append("</td>");
//            html.append("<td>").append(task.getManufactureBatch() == null ? "" : task.getManufactureBatch().getNumber()).append("</td>");
//            html.append("<td>").append(task.getGrindEdgeMachine() == null ? "" : task.getGrindEdgeMachine().getNumber()).append("</td>");
//            html.append("<td>").append(task.getGlass() == null ? "" : task.getGlass().getDescription()).append("</td>");
//            html.append("<td>").append(formatTime(task.getCompleteTime())).append("</td>");
//            
//            html.append("<td>");
//            if (task.getState().equals(CountMachineTaskState.IN_WORK) || task.getState().equals(CountMachineTaskState.WAITING)) {
//                html.append("<a href='/gmms/manage/grindManualCheckError/").append(task.getId())
//                .append("' class='btn btn-danger'>报错</a>&nbsp;&nbsp;");
//            }
//            html.append("</td>");
//            
//            html.append("</tr>");
//        }
//        
//        html.append("</tbody></table>");
//        return html.toString();
//  
//    } 
    
    /**
     * 成都项目:巡检和下片集成在一个页面中
     * 
     * @return
     */
    public String getManualCheckHtml(long CountMachineid) {
        LOGGER.trace("> Start getCountMachineTaskForManualCheckHtml");
        List<CountMachineTask> taskList = countMachineTaskDao.findByCountMachine(CountMachineid);
        LOGGER.trace("taskList size: " + taskList.size());
        
        StringBuffer html = new StringBuffer("<table><tr>");
       
        int s=0;
        if (taskList.size()>2) {
            s=taskList.size()-2;
        }
        for(int i = taskList.size()-1 ; i>=s ; i-- ){
            CountMachineTask task = taskList.get(i);
            String color = "#039";
            if (i == taskList.size()-1) {
                color = "#FDB800";
            }
//            if(task.getState().equals(CountMachineTaskState.IN_WORK) || task.getState().equals(CountMachineTaskState.TWO_SEND)){
//                color = "#5EB212";
//                }else if(task.getState().equals(CountMachineTaskState.WAITING_COMPLETED) || task.getState().equals(CountMachineTaskState.WORKING)){
//                color = "#FDB800";
//                }
            html.append("<td style='margin-left:10px;'>");
            html.append("<div style=\"background-color:").append(color).append(";color:#fff;height:120px; width:160px;float:right;\">");
            html.append("    <div style=\"font-size:25px;\">").append(task.getGlass().getArrangeStatu());
            html.append("    </div><div style=\"font-size:20px;margin-left:20px;\">").append( task.getGlass().getLength()).append(" mm<span>&nbsp;X</span></div>");
            html.append("    <div style=\"font-size:20px;margin-left:50px;\">").append( task.getGlass().getWidth()).append(" mm</div><br>");
            html.append("    <div style=\"margin-left:40px;\" class =\"manualcheck\" id=\"").append(task.getId());
        //    html.append("\"><a style=\"text-align:center;\" href='/gmms/manage/manualCheckError1/").append(task.getId())
            html.append("\"></div>&nbsp;&nbsp;");
            html.append("</div>");
            html.append("</td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
        }
        
//        RawPackageTxt txt = rawPackageTxtDao.findAcceptedByGroup(String.valueOf(CountMachineid));
//        if(txt !=null){
//             List<Glass> glasses = glassDao.findByBatch(txt.getTxt_name());
//             List strings = new ArrayList();
//             for(Glass glass:glasses){
//                 if (strings.size() == 0) {
//                    strings.add(glass.getArrangeStatu());
//                }
//             }
//        }
       
        html.append("<tr></table>");
        LOGGER.trace("> End getCountMachineTaskForManualCheckHtml");
        return html.toString();
    }
    
    
    public String getCountMachineTaskHtml(Long countMachineId) {
        
        RawPackageTxt txt= rawPackageTxtDao.findAcceptedByGroup(countMachineId.toString());
        List<CountMachineTask> countMachineTaskList = new ArrayList<CountMachineTask>();
        if (txt!=null) {
            countMachineTaskList = countMachineTaskDao.findRawPackageTxtByid(txt.getId());
        }
        StringBuffer html = new StringBuffer("<table class='table table-striped table-hover'>");
        html.append("<thead><tr><th>状态</th><th>批次编号</th><th>下片机</th><th>玻璃信息</th>");
        html.append("<th>创建时间</th><th>开始时间</th><th>完成时间</th></tr></thead><tbody style='overflow-y:auto;'>");
        if (countMachineTaskList.size()>0) {
            
            int s=0;
            if (countMachineTaskList.size()>15) {
                s=countMachineTaskList.size()-15;
            } 
            for(int i = countMachineTaskList.size()-1 ; i>=s ; i-- ){
                CountMachineTask task = countMachineTaskList.get(i);
                html.append("<tr ").append(getMachineTaskHtmlClass(task.getState())).append(">");
                html.append("<td>").append(task.getState()).append("</td>");
                html.append("<td>").append(task.getRawPackageTxt() == null ? "" : task.getRawPackageTxt().getTxt_name()).append("</td>");
                html.append("<td>").append(task.getCountMachine() == null ? "" : task.getCountMachine().getNumber()).append("</td>");
                html.append("<td>").append(task.getGlass() == null ? "" : task.getGlass().getDescription()).append("</td>");
                html.append("<td>").append(formatTime(task.getCreateTime())).append("</td>");
                html.append("<td>").append(formatTime(task.getStartTime())).append("</td>");
                html.append("<td>").append(formatTime(task.getCompleteTime())).append("</td>");
                html.append("</tr>");
            }
        }
        html.append("</tbody></table>");
        return html.toString();
    }
    public Map<String, Object> getCountMachineTask(Long countMachineId) {
        Map<String, Object> param = new HashMap<String, Object>();
        RawPackageTxt rawPackageTxt = rawPackageTxtDao.findCutFinishByGroup("1");
         if (rawPackageTxt==null) {
             rawPackageTxt = rawPackageTxtDao.findAcceptedByGroup("1");
        }
        int sum = 0;
        int finishoieces = 0;
        int warning = 0;
        if (rawPackageTxt !=null) {
            List<Glass> glasses = glassDao.findByBatch(rawPackageTxt.getTxt_name());
            if(glasses.size()>0){
                for(Glass glass:glasses){
                    sum +=glass.getPieces();
                    finishoieces += glass.getCompletePieces();
                    warning += glass.getDamagePieces();
                }
            }
            List<CountMachineTask> countMachineList = countMachineTaskDao.findByCountMachine(countMachineId);
            
            if (countMachineList.size() > 0) {
                CountMachineTask inWorkTask = countMachineList.get(countMachineList.size()-1);
                param.put("countLength",inWorkTask.getGlass().getLength());
                param.put("countWidth",inWorkTask.getGlass().getWidth());
                param.put("countId",inWorkTask.getGlass().getId());
                param.put("apaId",inWorkTask.getGlass().getApart_id());
                param.put("color",inWorkTask.getGlass().getColor());
                param.put("customer",inWorkTask.getGlass().getCustomer());
                param.put("application",inWorkTask.getGlass().getApplication());
                param.put("piece_sign",inWorkTask.getGlass().getPiece_sign());
                param.put("floornumber",inWorkTask.getGlass().getFloor_number());
                param.put("remark",inWorkTask.getGlass().getRemark());
                param.put("thickness",inWorkTask.getGlass().getThickness());
                param.put("countGlassId",inWorkTask.getGlass().getArrangeStatu());
            }
        }
        param.put("sum",sum);
        param.put("countGlassCounts",finishoieces);
        param.put("countGlassSum",warning);
        return param;
    }
    
    //任务数量
    public int getMachineTaskCount(Long countMachineId){
        RawPackageTxt rawPackageTxt = rawPackageTxtDao.findAcceptedByGroup("1");
        List<Glass> glasses = glassDao.findByBatch(rawPackageTxt.getTxt_name());
        List<CountMachineTask> countMachineTaskList = countMachineTaskDao.findByCountMachine(countMachineId);
        List<CountMachineTask> countMachineList = countMachineTaskDao.findWarningTasksByCountMachine(countMachineId);
        int counts = 0;
        counts=countMachineTaskList.size()-countMachineList.size();
        return counts;
    }
    
    //破损数量
    public int getMachineTaskWarningCount(Long countMachineId){
        int sum=0;
        List<Glass> glassList = glassDao.findGlassBygroups(countMachineId.toString());
        for (Glass glass : glassList) {
            sum+=glass.getDamagePieces();
        }
        return sum;
    }
    
  //完成的数量
    public int getMachineTaskListCount(Long countMachineId){
        int sum=0;
        List<Glass> glassList = glassDao.findGlassBygroups(countMachineId.toString());
        for (Glass glass : glassList) {
            sum+=glass.getCompletePieces();
        }
        return sum;
    }
    
    //获取批次编号
    public String getMachinebatch(Long countMachineId){
        RawPackageTxt misiion = rawPackageTxtDao.findAcceptedByGroup(countMachineId.toString());
        String batch="";
        if(misiion!=null){
            batch = misiion.getTxt_name();
        }
        return batch;
    }
    
    //获得该任务的总数量
    public int getMachineTaskListSum(Long machineId){
        int sum=0;
        List<Glass> glassList = glassDao.findGlassBygroups(machineId.toString());
         for (Glass glass : glassList) {
             sum+=glass.getPieces();
         }
        return sum;
    }
    
    //得到需要的玻璃队列
    //得到下片玻璃
    public Map<String, Object> show(Long machineId){
        Map<String, Object> param=new HashMap<String, Object>();
        List<CountMachineTask> wait=countMachineTaskDao.findWaitingTasksByCountMachine(machineId);
        List<CountMachineTask> inworkTask=countMachineTaskDao.findInworkTaskByid(machineId);
        param.put("wait", wait);
        param.put("inworkTask", inworkTask);
        return param;
    }
    
    //得到一条队列
    public CountMachineTask update(Long id){
        CountMachineTask task=countMachineTaskDao.findOne(id);
        return task;
    }
}