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 classifyList = toolsClassifyService.list(new LambdaQueryWrapper() .eq(ToolsClassify::getAliasLabel, aliasLabel) .eq(ToolsClassify::getStatus, CommonConstant.STATUS_1)); List> list = classifyList.stream() .map(classify -> new HashMap() {{ 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 res = Result.OK(); Map 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 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 classifyList = toolsClassifyService.list(new LambdaQueryWrapper() .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 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 toolList, ToolParaType toolParaType) { if (toolParaType != null) { String diameter = queryParam.getDiameter(); switch (toolParaType) { case HOLE: List paraHoleToolsList = paraHoleToolsService.selectByClassifyAndDiameter(queryParam); toolList.addAll(paraHoleToolsList); break; case THREADING://螺纹刀具没有直径参数,如果传入直径,直接略过 if (StrUtil.isBlank(diameter)) { List paraThreadingToolList = paraThreadingToolService.selectByClassifyAndParam(queryParam); toolList.addAll(paraThreadingToolList); } break; case MILL: List paraMillToolList = paraMillToolService.selectByClassifyAndDiameter(queryParam); toolList.addAll(paraMillToolList); break; case TURNING: List paraTurningToolsList = paraTurningToolsService.selectByClassifyAndDiameter(queryParam); toolList.addAll(paraTurningToolsList); break; case BLADE://刀片没有直径参数,如果传入直径,直接略过 if (StrUtil.isBlank(diameter)) { List paraBladeToolsList = paraBladeService.selectByClassifyAndParam(queryParam); toolList.addAll(paraBladeToolsList); } break; default: } } } }