RmsMaterialController.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.steerinfo.dil.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.steerinfo.dil.component.ImageFileUtils;
  4. import com.steerinfo.dil.service.impl.RmsMaterialServiceImpl;
  5. import com.steerinfo.dil.util.BaseRESTfulController;
  6. import com.steerinfo.framework.controller.RESTfulResult;
  7. import com.steerinfo.framework.utils.misc.IdGenerator;
  8. import com.steerinfo.framework.utils.upload.UploadUtils;
  9. import io.swagger.annotations.ApiOperation;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.web.bind.annotation.*;
  13. import org.springframework.web.multipart.MultipartFile;
  14. import org.springframework.web.multipart.MultipartRequest;
  15. import java.io.File;
  16. import java.io.FileInputStream;
  17. import java.io.IOException;
  18. import java.lang.reflect.Field;
  19. import java.text.SimpleDateFormat;
  20. import java.util.ArrayList;
  21. import java.util.Calendar;
  22. import java.util.Date;
  23. import java.util.List;
  24. /**
  25. * @author luobang
  26. * @create 2021-10-10 17:59
  27. */
  28. @RestController
  29. @RequestMapping("${api.version}/material")
  30. public class RmsMaterialController extends BaseRESTfulController {
  31. @Autowired
  32. private ImageFileUtils imageFileUtils;
  33. @Value("${piction.path}")
  34. private String path;
  35. @Autowired
  36. RmsMaterialServiceImpl rmsMaterialServiceImpl;
  37. /**
  38. * 1.获取物资
  39. * @return
  40. */
  41. @ApiOperation(value = "获取物资下拉框列表")
  42. @GetMapping("/getMaterial")
  43. public RESTfulResult getMaterial(){
  44. return success(rmsMaterialServiceImpl.getMaterial());
  45. }
  46. @ApiOperation(value = "通过excel创建基础数据")
  47. @GetMapping("/createMaterial")
  48. public RESTfulResult createMaterial() throws IOException {
  49. int count= rmsMaterialServiceImpl.createMaterial();
  50. return success(count);
  51. }
  52. @PostMapping(value = "/updateFiles", headers = "content-type=multipart/form-data")
  53. public synchronized List<String> updateFiles( @RequestParam(value = "files") MultipartFile files[]) throws Exception {
  54. //首先通过Calendard对象获得年月日
  55. Calendar calendar=Calendar.getInstance();
  56. int year = calendar.get(Calendar.YEAR);
  57. int month = calendar.get(Calendar.MONTH);
  58. int day= calendar.get(Calendar.DAY_OF_MONTH);
  59. //上传文件夹路径
  60. List<String> urls=new ArrayList<>();
  61. for (int i=0;i<files.length;i++){
  62. String url = UploadUtils.uploadFile(files[i], new IdGenerator(i, 10), path, File.separator+year+File.separator+month+File.separator+day+File.separator);
  63. urls.add(url);
  64. }
  65. return urls;
  66. }
  67. @PostMapping(value = "/getFile")
  68. @ResponseBody
  69. public String getImgBytes(@RequestBody String url) throws Exception {
  70. String b = imageFileUtils.downloadFile(url).toString();
  71. return b;
  72. }
  73. }