cuilei
2025-05-29 d4328b5fac8a01d685a3068f097668132095807d
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
package org.jeecg.modules.tms.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.tms.entity.ToolsClassify;
import org.jeecg.modules.tms.entity.dto.ToolQueryParamDto;
import org.jeecg.modules.tms.entity.vo.ParaHolesToolsVo;
import org.jeecg.modules.tms.entity.vo.ParaMillToolVo;
import org.jeecg.modules.tms.entity.vo.ParaTurningToolsVo;
import org.jeecg.modules.tms.enums.ToolParaType;
import org.jeecg.modules.tms.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
@RestController
@RequestMapping("/tms/toolsToDnc")
public class ToolsToDncController {
 
    @Autowired
    private IToolsClassifyService toolsClassifyService;
    @Autowired
    private IParaHoleToolsService paraHoleToolsService;
    @Autowired
    private IParaMillToolService paraMillToolService;
    @Autowired
    private IParaTurningToolsService paraTurningToolsService;
 
    /**
     * 通过工具简称/直径参数查询具体工具参数信息(给DNC提供接口),参数示例:3E(3为工具直径参数、E为加工中心刀具简称)
     * @param queryParam
     * @return
     */
    @ApiOperation(value = "通过工具简称/直径参数查询具体工具参数信息(给DNC提供接口)", notes = "通过工具简称/直径参数查询具体工具参数信息(给DNC提供接口)")
    @GetMapping("/queryToolByParam")
    public Result<?> queryToolByParam(@RequestParam("param") ToolQueryParamDto queryParam){
        String param = queryParam.getParam();
        // 正则表达式:前半部分为数字(支持小数),后半部分为大写或小写字母
        String regex = "^([\\d.]+)([A-Za-z]+)$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(param);
        if (matcher.find()) {
            String diameter = matcher.group(1);
            String toolAliasName = matcher.group(2);
 
            List<ToolsClassify> classifyList = toolsClassifyService.list(new LambdaQueryWrapper<ToolsClassify>()
                    .eq(ToolsClassify::getAliasLabel, toolAliasName)
                    .eq(ToolsClassify::getStatus, CommonConstant.STATUS_1));
            if (CollectionUtil.isEmpty(classifyList)) {
                return Result.error("未找到匹配的工具分类");
            }
            List<Object> toolList = CollectionUtil.newArrayList();
            for (ToolsClassify classify : classifyList) {
                String paraTypeFlag = classify.getParaTypeFlag();
                queryParam.setClassifyId(classify.getId());
                queryParam.setDiameter(diameter);
                ToolParaType toolParaType = ToolParaType.fromValue(paraTypeFlag);
                if (toolParaType != null) {
                    switch (toolParaType) {
                        case HOLE:
                            List<ParaHolesToolsVo> paraHoleToolsList = paraHoleToolsService.selectByClassifyAndDiameter(queryParam);
                            toolList.addAll(paraHoleToolsList);
                            break;
                        case MILL:
                            List<ParaMillToolVo> paraMillToolList = paraMillToolService.selectByClassifyAndDiameter(queryParam);
                            toolList.addAll(paraMillToolList);
                            break;
                        case TURNING:
                            List<ParaTurningToolsVo> paraTurningToolsList = paraTurningToolsService.selectByClassifyAndDiameter(queryParam);
                            toolList.addAll(paraTurningToolsList);
                            break;
                        default:
                    }
                }
            }
            return Result.OK(toolList);
        } else {
            return Result.error("参数格式不正确");
        }
    }
 
}