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("参数格式不正确");
|
}
|
}
|
|
}
|