package com.ydtech.modules.inv.controller; import com.ydtech.core.page.HttpResult; import com.ydtech.modules.inv.model.excel.InvSourceExcel; import com.ydtech.modules.inv.model.po.InvSource; import com.ydtech.modules.inv.service.InvSourceService; import com.ydtech.modules.inv.utils.EasyExcelUtils; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Arrays; /** * @author jianlong * @date 2024-01-20 10:38 */ @Api(tags = "来源表", value = "来源表") @RequestMapping("Source") @RestController public class InvSourceController { @Autowired private InvSourceService invSourceService; private static String concatenateWithSlash(String[] array) { StringBuilder result = new StringBuilder(); for (String segment : array) { result.append(segment).append("/"); } // Remove the trailing "/" if (result.length() > 0) { result.setLength(result.length() - 1); } return result.toString(); } private static int findIndex(String[] array, String target) { for (int i = 0; i < array.length; i++) { // Use the indexOf method to check for the target string if (array[i].indexOf(target) != -1) { return i; } } return -1; // Return -1 if the element is not found } @GetMapping("excel") public HttpResult readExcel(@RequestParam("file") String file ) { String[] pathSegments = file.split("/"); int index = findIndex(pathSegments,"upload"); String[] subarray = Arrays.copyOfRange(pathSegments, index+1, pathSegments.length); String filename = concatenateWithSlash(subarray); return invSourceService.readExcel(filename); } }