| | |
| | | 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.ParaHolesToolsVo; |
| | | import org.jeecg.modules.tms.entity.vo.ParaMillToolVo; |
| | | import org.jeecg.modules.tms.entity.vo.ParaTurningToolsVo; |
| | | 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.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | @RequestMapping("/tms/toolsToDnc") |
| | |
| | | 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(@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); |
| | | 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, toolAliasName) |
| | | .eq(ToolsClassify::getAliasLabel, aliasLabel) |
| | | .eq(ToolsClassify::getStatus, CommonConstant.STATUS_1)); |
| | | if (CollectionUtil.isEmpty(classifyList)) { |
| | | return Result.error("未找到匹配的工具分类"); |
| | | result.put("records", CollectionUtil.newArrayList()); |
| | | result.put("total", 0); |
| | | result.put("current", pageNo); |
| | | result.put("size", pageSize); |
| | | res.setResult(result); |
| | | return res; |
| | | } |
| | | 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: |
| | | } |
| | | } |
| | | matchTypeSelectTools(queryParam, toolList, toolParaType); |
| | | } |
| | | return Result.OK(toolList); |
| | | } |
| | | |
| | | // ====== 分页逻辑 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 { |
| | | return Result.error("参数格式不正确"); |
| | | 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: |
| | | } |
| | | } |
| | | } |
| | | |