hyingbo
11 小时以前 7e0152c5c1d1c0cd38b59ffaea3222dcde13012e
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
package org.jeecg.modules.tms.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
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.*;
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.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
@RestController
@RequestMapping("/tms/toolsToDnc")
public class ToolsToDncController {
 
    @Autowired
    private IToolsClassifyService toolsClassifyService;
    @Autowired
    private IParaHoleToolsService paraHoleToolsService;
    @Autowired
    private IParaMillToolService paraMillToolService;
    @Autowired
    private IParaTurningToolsService paraTurningToolsService;
    @Autowired
    private IParaThreadingToolService paraThreadingToolService;
    @Autowired
    private IParaBladeService paraBladeService;
 
    @ApiOperation(value = "通过工具简称查询工具分类信息,选刀页面工具类型下拉框用", notes = "通过工具简称查询工具分类信息,选刀页面工具类型下拉框用")
    @GetMapping("/queryToolClassifyByParam")
    public Result<?> queryToolClassifyByParam(@RequestParam("aliasLabel") String aliasLabel) {
        List<ToolsClassify> classifyList = toolsClassifyService.list(new LambdaQueryWrapper<ToolsClassify>()
                .eq(ToolsClassify::getAliasLabel, aliasLabel)
                .eq(ToolsClassify::getStatus, CommonConstant.STATUS_1));
        List<Map<String, String>> list = classifyList.stream()
                .map(classify -> new HashMap<String, String>() {{
                    put("value", classify.getId());
                    put("label", classify.getTypeName());
                }})
                .collect(Collectors.toList());
        return Result.ok(list);
    }
    /**
     * 通过工具简称/直径参数查询具体工具参数信息(给DNC提供接口),参数示例:3E(3为工具直径参数、E为加工中心刀具简称)
     *
     * @param queryParam
     * @return
     */
    @ApiOperation(value = "通过工具简称/直径参数查询具体工具参数信息(给DNC提供接口)", notes = "通过工具简称/直径参数查询具体工具参数信息(给DNC提供接口)")
    @GetMapping("/queryToolByParam")
    public Result<?> queryToolByParam(ToolQueryParamDto queryParam) {
        String aliasLabel = queryParam.getAliasLabel();
        String diameter = queryParam.getDiameter();
        if (StrUtil.isBlank(aliasLabel)) {
            return Result.error("缺少必要参数");
        }
 
        Result<Object> res = Result.OK();
        Map<String, Object> result = new HashMap<>();
        int pageNo = Objects.isNull(queryParam.getPageNo()) || queryParam.getPageNo() < 1 ? 1 : queryParam.getPageNo();
        int pageSize = Objects.isNull(queryParam.getPageSize()) || queryParam.getPageSize() < 1 ? 10 : queryParam.getPageSize();
 
        List<Object> toolList = CollectionUtil.newArrayList();
        String classifyId = queryParam.getClassifyId();
        if (StrUtil.isNotBlank(classifyId)) {
            //已经进入了选刀页面,工具分类已经确定
            ToolsClassify toolsClassify = toolsClassifyService.getById(classifyId);
            ToolParaType toolParaType = ToolParaType.fromValue(toolsClassify.getParaTypeFlag());
            matchTypeSelectTools(queryParam, toolList, toolParaType);
        } else {
            //第一次进入选刀页面,根据刀具简称和直径参数查询工具分类
            List<ToolsClassify> classifyList = toolsClassifyService.list(new LambdaQueryWrapper<ToolsClassify>()
                    .eq(ToolsClassify::getAliasLabel, aliasLabel)
                    .eq(ToolsClassify::getStatus, CommonConstant.STATUS_1));
            if (CollectionUtil.isEmpty(classifyList)) {
                result.put("records", CollectionUtil.newArrayList());
                result.put("total", 0);
                result.put("current", pageNo);
                result.put("size", pageSize);
                res.setResult(result);
                return res;
            }
            for (ToolsClassify classify : classifyList) {
                String paraTypeFlag = classify.getParaTypeFlag();
                queryParam.setClassifyId(classify.getId());
                queryParam.setDiameter(diameter);
                ToolParaType toolParaType = ToolParaType.fromValue(paraTypeFlag);
                matchTypeSelectTools(queryParam, toolList, toolParaType);
            }
        }
 
        // ====== 分页逻辑 start ======
        int total = toolList.size();
        int fromIndex = (pageNo - 1) * pageSize;
        int toIndex = Math.min(fromIndex + pageSize, total);
 
        List<Object> pagedList;
        if (fromIndex > total) {
            pagedList = Collections.emptyList();
        } else {
            pagedList = toolList.subList(fromIndex, toIndex);
        }
 
        result.put("records", pagedList);
        result.put("total", total);
        result.put("current", pageNo);
        result.put("size", pageSize);
        res.setResult(result);
        return res;
        // ====== 分页逻辑 end ======
    }
 
    private void matchTypeSelectTools(ToolQueryParamDto queryParam, List<Object> toolList, ToolParaType toolParaType) {
        if (toolParaType != null) {
            String diameter = queryParam.getDiameter();
            switch (toolParaType) {
                case HOLE:
                    List<ParaHolesToolsVo> paraHoleToolsList = paraHoleToolsService.selectByClassifyAndDiameter(queryParam);
                    toolList.addAll(paraHoleToolsList);
                    break;
                case THREADING://螺纹刀具没有直径参数,如果传入直径,直接略过
                    if (StrUtil.isBlank(diameter)) {
                        List<ParaThreadingToolVo> paraThreadingToolList = paraThreadingToolService.selectByClassifyAndParam(queryParam);
                        toolList.addAll(paraThreadingToolList);
                    }
                    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;
                case BLADE://刀片没有直径参数,如果传入直径,直接略过
                    if (StrUtil.isBlank(diameter)) {
                        List<ParaBladeVo> paraBladeToolsList = paraBladeService.selectByClassifyAndParam(queryParam);
                        toolList.addAll(paraBladeToolsList);
                    }
                    break;
                default:
            }
        }
    }
 
}