| | |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.tool.api.IResultCode; |
| | | import org.springblade.core.tool.api.ResultCode; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.NumberUtil; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.mapper.FlowProgramFileMapper; |
| | | import org.springblade.mdm.flow.vo.ProgramUploadVO; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.service.ProcessProgRefService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class FlowProgramFileService extends BizServiceImpl<FlowProgramFileMapper, FlowProgramFile> { |
| | | private final OssTemplate ossTemplate; |
| | | private final RuntimeService runtimeService; |
| | | private final FlowCommonService flowCommonService; |
| | | @Autowired |
| | | private OssTemplate ossTemplate; |
| | | @Autowired |
| | | private RuntimeService runtimeService; |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | |
| | | public void uploadFlowProgramFile(ProgramUploadVO uploadVO) { |
| | | |
| | | //Map<String, Object> vars = runtimeService.getVariables(uploadVO.getProcessInstanceId()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查文件名合法性 |
| | | * @param filename |
| | | * @param programProperties |
| | | */ |
| | | void checkFilename(String filename,FlowProgramProperties programProperties){ |
| | | //程序名称:零件号加工序号,文件名应该以此开头 |
| | | String expectedProgramName = programProperties.getDrawingNo()+"-"+programProperties.getProcessNo(); |
| | | if(!StringUtils.startsWith(filename,expectedProgramName)){ |
| | | throw new ServiceException("程序文件名不合法,应为:"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[段数]-[段号].[文件扩展名]"); |
| | | |
| | | IResultCode rc = new IResultCode() { |
| | | @Override |
| | | public String getMessage() { |
| | | return "程序文件名不合法,应为:"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[段数]-[段号].[文件扩展名]"; |
| | | } |
| | | |
| | | @Override |
| | | public int getCode() { |
| | | return 1; |
| | | } |
| | | }; |
| | | throw new ServiceException(rc); |
| | | //throw new ServiceException("程序文件名不合法,应为:"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[段数]-[段号].[文件扩展名]"); |
| | | } |
| | | |
| | | //截取后面的段数和第几段 |
| | | String endPart = StringUtils.removeStart(filename,expectedProgramName+"-"+programProperties.getCraftEdition()+"-"); |
| | | |
| | | //去掉扩展名 |
| | | if(endPart.contains(".")){ |
| | | endPart = endPart.substring(0,endPart.indexOf(".")); |
| | | } |
| | | |
| | | int sepCount = StringUtils.countMatches(endPart,"-"); |
| | | if(sepCount != 1){//- 号应该是1个 |
| | | IResultCode rc = new IResultCode() { |
| | | @Override |
| | | public String getMessage() { |
| | | return "程序文件名不合法,应为:"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[段数]-[段号].[文件扩展名]"; |
| | | } |
| | | |
| | | @Override |
| | | public int getCode() { |
| | | return 2; |
| | | } |
| | | }; |
| | | throw new ServiceException(rc); |
| | | //throw new ServiceException("程序文件名不合法,应为:"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[段数]-[段号].[文件扩展名]"); |
| | | } |
| | | |
| | | String[] arr = StringUtils.split(endPart,"-"); |
| | | if(!StringUtils.isNumeric(arr[0]) || Func.toInt(arr[0]) >99 || Func.toInt(arr[0]) < 1){ |
| | | IResultCode rc = new IResultCode() { |
| | | @Override |
| | | public String getMessage() { |
| | | return "程序段数不合法,应为两位以内整数"; |
| | | } |
| | | |
| | | @Override |
| | | public int getCode() { |
| | | return 3; |
| | | } |
| | | }; |
| | | throw new ServiceException(rc); |
| | | } |
| | | int segCount = Func.toInt(arr[0]); |
| | | |
| | | if(!StringUtils.isNumeric(arr[1]) || Func.toInt(arr[1]) < 1 || Func.toInt(arr[1]) > segCount){ |
| | | IResultCode rc = new IResultCode() { |
| | | @Override |
| | | public String getMessage() { |
| | | return "程序段号不合法,应为两位以内整数且小于等于段数。"; |
| | | } |
| | | |
| | | @Override |
| | | public int getCode() { |
| | | return 4; |
| | | } |
| | | }; |
| | | throw new ServiceException(rc); |
| | | } |
| | | } |
| | | |