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
package com.mes.damage.controller;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mes.damage.entity.Damage;
import com.mes.damage.entity.DamagePrint;
import com.mes.damage.entity.dto.DamageDTO;
import com.mes.damage.entity.request.DamageRequest;
import com.mes.damage.entity.vo.FlowCardDamageVO;
import com.mes.damage.entity.vo.GlassDamageVO;
import com.mes.damage.service.DamageService;
import com.mes.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wu
 * @since 2024-06-25
 */
@Api(tags = "报工信息")
@RestController
@RequestMapping("/damage")
@ResponseBody
@Slf4j
public class DamageController {
 
    @Autowired(required = true)
    private DamageService damageService;
 
    @ApiOperation("报工数据查询")
    @PostMapping("/selectDamage")
    public Result<Page<DamageDTO>> selectDamage(@RequestBody Map map) {
        String startTime = map.get("startTime").toString();
        String endTime = map.get("endTime").toString();
        int type = Integer.parseInt(map.get("type").toString());
        int status = Integer.parseInt(map.get("status").toString());
        String workingProcedure = map.get("workingProcedure").toString();
        int pageNo = Integer.parseInt(map.get("pageNo").toString());
        int pageSize = Integer.parseInt(map.get("pageSize").toString());
        return Result.build(200, "查询成功", damageService.selectDamage(startTime, endTime, type, status, workingProcedure, pageNo, pageSize));
    }
 
    @ApiOperation("报工")
    @PostMapping("/submitDamage")
    public Result submitDamage(@RequestBody List<Damage> damageList) {
        damageService.submitDamage(damageList);
        if (damageList.get(0).getStatus() == 1) {
            damageList.forEach(damage -> damage.setStatus(3));
        } else {
            damageList.forEach(damage -> damage.setStatus(8));
        }
        damageService.updateBatchById(damageList);
        return Result.build(200, "报工成功", 1);
    }
 
    @ApiOperation("报工数据修改")
    @PostMapping("/updateDamage")
    public Result updateDamage(@RequestBody List<Damage> damageList) {
        damageService.updateBatchById(damageList);
        return Result.build(200, "修改成功", 1);
    }
 
    @ApiOperation("报工数据新增")
    @PostMapping("/insertDamage")
    public Result insertDamage(@RequestBody Damage damage) {
        damageService.insertDamage(damage);
        return Result.build(200, "新增成功", 1);
    }
 
    @ApiOperation("拿走数据查询")
    @PostMapping("/selectDamagePrint")
    public Result selectDamagePrint(@RequestBody Damage damage) {
        List<DamagePrint> damage2 = damageService.selectDamagePrint(damage);
        return Result.build(200, "查询成功", damage2);
    }
 
    @ApiOperation("拿走打印查询")
    @PostMapping("/selectDamagePrintDetails")
    public Result selectDamagePrintDetails(@RequestBody Damage damage) {
        List<DamagePrint> damage2 = damageService.selectDamagePrintDetails(damage);
        return Result.build(200, "查询成功", damage2);
    }
 
    @ApiOperation("自动报工")
    @PostMapping("/autoSubmitReport")
    public Result autoSubmitReport(String glassId, int deviceId, String workingProcedure, String remark, int type) {
        damageService.autoSubmitReport(glassId, deviceId, workingProcedure, remark, type);
        return Result.build(200, "查询成功", "");
    }
 
    @ApiOperation("自动报工测试")
    @PostMapping("/submitReport")
    public Result submitReport() {
//        for (int i = 0; i < 50; i++) {
            Damage damage = new Damage();
            damage.setProcessId("NG25110702A004");
            damage.setWorkingProcedure("磨边");
            damage.setOrderNumber(2);
            damage.setTechnologyNumber(2);
            damageService.submitReport(damage);
//            log.info("当前循环次数{}", i);
//            try {
//                // 方式1:使用Thread.sleep(推荐,直观)
//                Thread.sleep(5000); // 10000毫秒 = 10秒
//                // 方式2:使用TimeUnit(语义更清晰,可选)
//                // TimeUnit.SECONDS.sleep(10);
//            } catch (InterruptedException e) {
//                // 捕获中断异常,恢复线程中断状态(避免后续逻辑异常)
//                Thread.currentThread().interrupt();
//                // 日志记录中断信息
//                // 可选:中断后是否退出循环(根据业务需求调整)
//                // break; // 中断则退出循环
//                // continue; // 中断则跳过当前等待,继续下一次循环
//            }
//        }
        return Result.build(200, "查询成功", "");
    }
 
    @ApiOperation("玻璃进度查询")
    @PostMapping("/queryProgress")
    public Result<List<GlassDamageVO>> queryProgress(@RequestBody DamageRequest damageRequest) {
        return Result.build(200, "查询成功", damageService.queryProgress(damageRequest));
    }
 
    @ApiOperation("流程卡进度查询")
    @PostMapping("/queryFlowCardIdProgress")
    public Result<List<FlowCardDamageVO>> queryFlowCardIdProgress(@RequestBody DamageRequest damageRequest) {
        return Result.build(200, "查询成功", damageService.queryFlowCardIdProgress(damageRequest));
    }
}