|
@@ -0,0 +1,112 @@
|
|
|
+package com.idea.pro.wx.web;
|
|
|
+
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.rockstar.common.base.BaseController;
|
|
|
+import com.rockstar.common.domain.AjaxResult;
|
|
|
+import com.rockstar.common.file.FileUtils;
|
|
|
+import com.rockstar.frame.model.FrameData;
|
|
|
+import com.rockstar.frame.model.FrameFile;
|
|
|
+import com.rockstar.frame.model.extend.TableSplitResult;
|
|
|
+import com.rockstar.frame.model.extend.Tablepar;
|
|
|
+import com.rockstar.util.StringUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+@Controller
|
|
|
+@Api("文件上传")
|
|
|
+@RequestMapping({"/wx/FileController"})
|
|
|
+public class WxFileController extends BaseController {
|
|
|
+
|
|
|
+ @PostMapping({"list"})
|
|
|
+ @ResponseBody
|
|
|
+ public Object list(Tablepar tablepar, String searchTxt) {
|
|
|
+ PageInfo<FrameFile> page = this.frameFileService.list(tablepar, searchTxt);
|
|
|
+ TableSplitResult<FrameFile> result = new TableSplitResult(page.getPageNum(), page.getTotal(), page.getList());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping({"/upload"})
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxResult updateAvatar(@RequestParam("file") MultipartFile file) {
|
|
|
+ try {
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ String id = this.frameDataService.insertSelective(file);
|
|
|
+ if (id != null) {
|
|
|
+ return AjaxResult.successData(200, id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.error();
|
|
|
+ } catch (Exception var3) {
|
|
|
+ return this.error(var3.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping({"add"})
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxResult add(FrameFile file, String dataId) {
|
|
|
+ int b = this.frameFileService.insertSelective(file, dataId);
|
|
|
+ return b > 0 ? this.success() : this.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping({"remove"})
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxResult remove(String ids) {
|
|
|
+ int b = this.frameFileService.deleteByPrimaryKey(ids);
|
|
|
+ return b > 0 ? this.success() : this.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping({"checkNameUnique"})
|
|
|
+ @ResponseBody
|
|
|
+ public int checkNameUnique(FrameFile frameFile) {
|
|
|
+ int b = this.frameFileService.checkNameUnique(frameFile);
|
|
|
+ return b > 0 ? 1 : 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping({"/edit"})
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxResult editSave(FrameFile frameFile, String dataId) {
|
|
|
+ return this.toAjax(this.frameFileService.updateByPrimaryKey(frameFile, dataId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping({"/viewImg/{id}"})
|
|
|
+ public void viewIMG(@PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ FrameData frameData = this.frameDataService.selectByPrimaryKey(id);
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (null != frameData) {
|
|
|
+ String contentType = frameData.getFileContentType();
|
|
|
+ if (StringUtils.isNotEmpty(contentType) && contentType.indexOf("image/") == -1) {
|
|
|
+ FileUtils.downFile(response, frameData.getFileName(), frameData.getFilePath(), frameData.getFileContentType());
|
|
|
+ } else {
|
|
|
+ FileUtils.readIMGToHtml(request, response, frameData.getFilePath());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ FileUtils.readIMGToHtml(request, response, "error");
|
|
|
+ }
|
|
|
+ } catch (IOException var6) {
|
|
|
+ var6.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping({"/download/{id}"})
|
|
|
+ public void download(@PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ FrameData frameData = this.frameDataService.selectByPrimaryKey(id);
|
|
|
+ FileUtils.downFile(response, frameData.getFileName(), frameData.getFilePath(), frameData.getFileContentType());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|