ソースを参照

url api前缀追加

于俊龙 2 週間 前
コミット
041cf06407

+ 1 - 1
farm-common/src/main/java/jp/yamoto/farm/common/core/controller/BaseController.java

@@ -85,7 +85,7 @@ public class BaseController
     {
         TableDataInfo rspData = new TableDataInfo();
         rspData.setCode(HttpStatus.SUCCESS);
-        rspData.setMsg("Success");
+        rspData.setMessage("Success");
         rspData.setRows(list);
         rspData.setTotal(new PageInfo(list).getTotal());
         return rspData;

+ 5 - 5
farm-common/src/main/java/jp/yamoto/farm/common/core/page/TableDataInfo.java

@@ -22,7 +22,7 @@ public class TableDataInfo implements Serializable
     private int code;
 
     /** メッセージの内容 */
-    private String msg;
+    private String message;
 
     /**
      * 表データオブジェクト
@@ -73,13 +73,13 @@ public class TableDataInfo implements Serializable
         this.code = code;
     }
 
-    public String getMsg()
+    public String getMessage()
     {
-        return msg;
+        return message;
     }
 
-    public void setMsg(String msg)
+    public void setMessage(String msg)
     {
-        this.msg = msg;
+        this.message = message;
     }
 }

+ 1 - 1
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/common/CommonController.java

@@ -26,7 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
  * @author nextosd
  */
 @RestController
-@RequestMapping("/common")
+@RequestMapping("/api/common")
 public class CommonController
 {
     private static final Logger log = LoggerFactory.getLogger(CommonController.class);

+ 1 - 1
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/master/MastOkyakusamaController.java

@@ -23,7 +23,7 @@ import java.util.List;
  * @author nextosd
  */
 @RestController
-@RequestMapping("/master/mast_okyakusama")
+@RequestMapping("/api/master/mast_okyakusama")
 public class MastOkyakusamaController extends BaseController {
 
     @Autowired

+ 1 - 1
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/system/SysConfigController.java

@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @author nextosd
  */
 @RestController
-@RequestMapping("/system/config")
+@RequestMapping("/api/system/config")
 public class SysConfigController extends BaseController
 {
     @Autowired

+ 1 - 1
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/system/SysDictDataController.java

@@ -31,7 +31,7 @@ import jp.yamoto.farm.common.biz.service.ISysDictTypeService;
  * @author nextosd
  */
 @RestController
-@RequestMapping("/system/dict/data")
+@RequestMapping("/api/system/dict/data")
 public class SysDictDataController extends BaseController
 {
     @Autowired

+ 1 - 1
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/system/SysDictTypeController.java

@@ -28,7 +28,7 @@ import jp.yamoto.farm.common.biz.service.ISysDictTypeService;
  * @author nextosd
  */
 @RestController
-@RequestMapping("/system/dict/type")
+@RequestMapping("/api/system/dict/type")
 public class SysDictTypeController extends BaseController {
     @Autowired
     private ISysDictTypeService dictTypeService;

+ 0 - 25
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/system/SysIndexController.java

@@ -1,25 +0,0 @@
-package jp.yamoto.farm.crm.web.controller.system;
-
-import jp.yamoto.farm.common.config.AppConfig;
-import jp.yamoto.farm.common.utils.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * Home
- *
- * @author nextosd
- */
-@RestController
-public class SysIndexController
-{
-    @Autowired
-    private AppConfig appConfig;
-
-    @RequestMapping("/")
-    public String index()
-    {
-        return StringUtils.format("Welcome to the {} backend management framework, current version: v {}, please access it through the frontend address.", appConfig.getName(), appConfig.getVersion());
-    }
-}

+ 1 - 1
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/system/SysMenuController.java

@@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @author nextosd
  */
 @RestController
-@RequestMapping("/system/menu")
+@RequestMapping("/api/system/menu")
 public class SysMenuController extends BaseController {
     @Autowired
     private ISysMenuService menuService;

+ 1 - 1
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/system/SysProfileController.java

@@ -29,7 +29,7 @@ import org.springframework.web.multipart.MultipartFile;
  * @author nextosd
  */
 @RestController
-@RequestMapping("/system/user/profile")
+@RequestMapping("/api/system/user/profile")
 public class SysProfileController extends BaseController
 {
     @Autowired

+ 1 - 1
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/system/SysUserController.java

@@ -36,7 +36,7 @@ import org.springframework.web.multipart.MultipartFile;
  * @author nextosd
  */
 @RestController
-@RequestMapping("/system/user")
+@RequestMapping("/api/system/user")
 public class SysUserController extends BaseController
 {
     @Autowired

+ 2 - 4
farm-sankin/src/main/java/jp/yamoto/farm/sankin/web/controller/AuthController.java

@@ -9,10 +9,7 @@ import jp.yamoto.farm.common.core.domain.model.LoginUser;
 import jp.yamoto.farm.common.utils.SecurityUtils;
 import jp.yamoto.farm.sankin.biz.auth.service.AuthLoginService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * ログイン認証
@@ -20,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @author nextosd
  */
 @RestController
+@RequestMapping("/api/auth")
 public class AuthController
 {
     @Autowired

+ 177 - 0
farm-sankin/src/main/java/jp/yamoto/farm/sankin/web/controller/CommonController.java

@@ -0,0 +1,177 @@
+package jp.yamoto.farm.sankin.web.controller;
+
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import jp.yamoto.farm.common.biz.domain.bo.OptionsParamBo;
+import jp.yamoto.farm.common.biz.service.IFarmCommonService;
+import jp.yamoto.farm.common.config.AppConfig;
+import jp.yamoto.farm.common.config.ServerConfig;
+import jp.yamoto.farm.common.constant.Constants;
+import jp.yamoto.farm.common.core.domain.AjaxResult;
+import jp.yamoto.farm.common.utils.StringUtils;
+import jp.yamoto.farm.common.utils.file.FileUploadUtils;
+import jp.yamoto.farm.common.utils.file.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 汎用リクエスト処理
+ * 
+ * @author nextosd
+ */
+@RestController
+@RequestMapping("/api/common")
+public class CommonController
+{
+    private static final Logger log = LoggerFactory.getLogger(CommonController.class);
+
+    @Autowired
+    private ServerConfig serverConfig;
+
+    private static final String FILE_DELIMETER = ",";
+
+    @Autowired
+    private IFarmCommonService commonService;
+
+    /**
+     * コンボボックスデータを取得する
+     * @param optionsParam
+     * @return
+     */
+    @PostMapping(value = "/options")
+    public AjaxResult getCommonOptions(@RequestBody OptionsParamBo optionsParam) {
+        return AjaxResult.success(commonService.getCommonOptions(optionsParam));
+    }
+
+    /**
+     * 汎用ダウンロードリクエスト
+     * 
+     * @param fileName ファイル名
+     * @param delete 削除するかどうか
+     */
+    @GetMapping("/download")
+    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
+    {
+        try
+        {
+            if (!FileUtils.checkAllowDownload(fileName))
+            {
+                throw new Exception(StringUtils.format("ファイル名({})が不正で、ダウンロードは許可されていません。", fileName));
+            }
+            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
+            String filePath = AppConfig.getDownloadPath() + fileName;
+
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+            FileUtils.setAttachmentResponseHeader(response, realFileName);
+            FileUtils.writeBytes(filePath, response.getOutputStream());
+            if (delete)
+            {
+                FileUtils.deleteFile(filePath);
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("ファイルのダウンロードに失敗しました", e);
+        }
+    }
+
+    /**
+     * 汎用アップロードリクエスト(単一)
+     */
+    @PostMapping("/upload")
+    public AjaxResult uploadFile(MultipartFile file) throws Exception
+    {
+        try
+        {
+            // ファイルパスのアップロード
+            String filePath = AppConfig.getUploadPath();
+            // 新しいファイル名をアップロードして戻す
+            String fileName = FileUploadUtils.upload(filePath, file);
+            String url = serverConfig.getUrl() + fileName;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("url", url);
+            ajax.put("fileName", fileName);
+            ajax.put("newFileName", FileUtils.getName(fileName));
+            ajax.put("originalFilename", file.getOriginalFilename());
+            return ajax;
+        }
+        catch (Exception e)
+        {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 汎用アップロードリクエスト(複数)
+     */
+    @PostMapping("/uploads")
+    public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
+    {
+        try
+        {
+            // ファイルパスのアップロード
+            String filePath = AppConfig.getUploadPath();
+            List<String> urls = new ArrayList<String>();
+            List<String> fileNames = new ArrayList<String>();
+            List<String> newFileNames = new ArrayList<String>();
+            List<String> originalFilenames = new ArrayList<String>();
+            for (MultipartFile file : files)
+            {
+                // 新しいファイル名をアップロードして戻す
+                String fileName = FileUploadUtils.upload(filePath, file);
+                String url = serverConfig.getUrl() + fileName;
+                urls.add(url);
+                fileNames.add(fileName);
+                newFileNames.add(FileUtils.getName(fileName));
+                originalFilenames.add(file.getOriginalFilename());
+            }
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
+            ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
+            ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
+            ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
+            return ajax;
+        }
+        catch (Exception e)
+        {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+    /**
+     * ローカルリソースの一般的なダウンロード
+     */
+    @GetMapping("/download/resource")
+    public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
+            throws Exception
+    {
+        try
+        {
+            if (!FileUtils.checkAllowDownload(resource))
+            {
+                throw new Exception(StringUtils.format("リソースファイル({})は不正で、ダウンロードは許可されていません。 ", resource));
+            }
+
+            String localPath = AppConfig.getProfile();
+
+            String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
+
+            String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
+
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+            FileUtils.setAttachmentResponseHeader(response, downloadName);
+            FileUtils.writeBytes(downloadPath, response.getOutputStream());
+        }
+        catch (Exception e)
+        {
+            log.error("ファイルのダウンロードに失敗しました", e);
+        }
+    }
+}