InvSourceController.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.ydtech.modules.inv.controller;
  2. import cn.hutool.core.date.DateTime;
  3. import com.ydtech.core.page.HttpResult;
  4. import com.ydtech.modules.admin.model.SysUser;
  5. import com.ydtech.modules.base.controller.BaseController;
  6. import com.ydtech.modules.inv.model.po.InvSource;
  7. import com.ydtech.modules.inv.service.InvReceivableService;
  8. import com.ydtech.modules.inv.service.InvSourceService;
  9. import io.swagger.annotations.Api;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.util.Arrays;
  16. import java.util.Date;
  17. /**
  18. * @author jianlong
  19. * @date 2024-01-20 10:38
  20. */
  21. @Api(tags = "来源表", value = "来源表")
  22. @RequestMapping("Source")
  23. @RestController
  24. public class InvSourceController {
  25. @Autowired
  26. private InvSourceService invSourceService;
  27. @Autowired
  28. private InvReceivableService invReceivableService;
  29. private static String concatenateWithSlash(String[] array) {
  30. StringBuilder result = new StringBuilder();
  31. for (String segment : array) {
  32. result.append(segment).append("/");
  33. }
  34. // Remove the trailing "/"
  35. if (result.length() > 0) {
  36. result.setLength(result.length() - 1);
  37. }
  38. return result.toString();
  39. }
  40. private static int findIndex(String[] array, String target) {
  41. for (int i = 0; i < array.length; i++) {
  42. // Use the indexOf method to check for the target string
  43. if (array[i].indexOf(target) != -1) {
  44. return i;
  45. }
  46. }
  47. return -1; // Return -1 if the element is not found
  48. }
  49. @GetMapping("excel")
  50. public HttpResult readExcel(@RequestParam("file") String file ) {
  51. String[] pathSegments = file.split("/");
  52. int index = findIndex(pathSegments,"upload");
  53. String[] subarray = Arrays.copyOfRange(pathSegments, index+1, pathSegments.length);
  54. String filename = concatenateWithSlash(subarray);
  55. HttpResult httpResult = invSourceService.readExcel(filename);
  56. invReceivableService.syncStatus();
  57. return httpResult;
  58. }
  59. }