Forráskód Böngészése

add: uploadVideoInfoImgs v1

tujidelv 3 éve
szülő
commit
818669ecfc

+ 52 - 0
src/main/java/top/lvzhiqiang/controller/BgController.java

@@ -1,17 +1,25 @@
 package top.lvzhiqiang.controller;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.multipart.MultipartFile;
+import top.lvzhiqiang.config.WebAppConfig;
 import top.lvzhiqiang.dto.R;
 import top.lvzhiqiang.exception.ParameterException;
 import top.lvzhiqiang.service.BgService;
 import top.lvzhiqiang.util.StringUtils;
 
 import javax.annotation.Resource;
+import java.io.File;
 import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 
 /**
  * BG Controller
@@ -26,6 +34,9 @@ public class BgController {
     @Resource
     private BgService bgService;
 
+    @Value("${spring.profiles.active}")
+    private String env;
+
 
     /**
      * 初始化骑兵数据
@@ -302,4 +313,45 @@ public class BgController {
         bgService.insertVideoInfo(identificationCode.trim().toUpperCase(), videoName, parentType, parentName, type);
         return R.ok();
     }
+
+    /**
+     * 上传影片识别码
+     *
+     * @author lvzhiqiang
+     * 2022/9/30 19:46
+     */
+    @RequestMapping("/uploadVideoInfoImgs")
+    @ResponseBody
+    public R uploadVideoInfoImgs(@RequestParam("files") MultipartFile[] files, String identificationCode, String imgType) throws Exception {
+        if (StringUtils.isEmpty(identificationCode)) {
+            throw new ParameterException("识别码不能为空");
+        }
+
+        if (files == null || files.length == 0) {
+            throw new ParameterException("文件为空!");
+        }
+
+        String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
+        File imgParentFile = new File(qibingPath.concat("骑兵步兵/").concat(identificationCode.trim().toUpperCase()).concat("/").concat(imgType));
+        if (!imgParentFile.exists()) {
+            imgParentFile.mkdirs();
+        }
+
+        JSONObject result = new JSONObject();
+        int i = 0;
+        JSONArray jsonArray = new JSONArray();
+        for (MultipartFile file : files) {
+            String originalFilename = file.getOriginalFilename();
+
+            File imgFile = new File(imgParentFile, originalFilename);
+            file.transferTo(imgFile);
+
+            i++;
+            jsonArray.add(BigDecimal.valueOf(file.getSize()).divide(new BigDecimal("1024")).setScale(0, RoundingMode.UP).toPlainString().concat("KB"));
+        }
+        result.put("totalNum", i);
+        result.put("list", jsonArray);
+
+        return R.ok().data(result);
+    }
 }

+ 15 - 0
src/main/resources/static/bg.html

@@ -217,6 +217,21 @@
             <input type="submit" value="提交">
         </form>
     </div>
+    <div style="margin-right:20px;">
+        <span class="font">uploadVideoInfoImgs</span>
+        <form method="post" action="bg/uploadVideoInfoImgs" enctype="multipart/form-data">
+            <span>identificationCode</span>
+            <input type="text" name="identificationCode" placeholder="识别码,不可为空"/>
+            <span>imgType</span>
+            <select name="imgType" style="height: 21.43px;">
+                <option value="img_sy">sy</option>
+                <option value="img_gf">gs</option>
+            </select>
+            <span>file</span>
+            <input type="file" name="files" multiple/>
+            <input type="submit" value="提交">
+        </form>
+    </div>
 </div>
 </body>
 </html>