| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package com.ydtech.modules.inv.controller;
- import cn.hutool.core.date.DateTime;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.modules.admin.model.SysUser;
- import com.ydtech.modules.base.controller.BaseController;
- import com.ydtech.modules.inv.model.po.InvSource;
- import com.ydtech.modules.inv.service.InvReceivableService;
- import com.ydtech.modules.inv.service.InvSourceService;
- import io.swagger.annotations.Api;
- 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.Arrays;
- import java.util.Date;
- /**
- * @author jianlong
- * @date 2024-01-20 10:38
- */
- @Api(tags = "来源表", value = "来源表")
- @RequestMapping("Source")
- @RestController
- public class InvSourceController {
- @Autowired
- private InvSourceService invSourceService;
- @Autowired
- private InvReceivableService invReceivableService;
- 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);
- HttpResult httpResult = invSourceService.readExcel(filename);
- invReceivableService.syncStatus();
- return httpResult;
- }
- }
|