|
|
@@ -1,7 +1,5 @@
|
|
|
package jp.yamoto.farm.crm.web.controller.common;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import jp.yamoto.farm.common.biz.domain.bo.OptionsParamBo;
|
|
|
@@ -13,6 +11,7 @@ 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 jp.yamoto.farm.crm.biz.master.service.IMastFarmerService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -20,15 +19,17 @@ 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
|
|
|
-{
|
|
|
+public class CommonController {
|
|
|
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
|
|
|
|
|
@Autowired
|
|
|
@@ -39,8 +40,12 @@ public class CommonController
|
|
|
@Autowired
|
|
|
private IFarmCommonService commonService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IMastFarmerService mastFarmerService;
|
|
|
+
|
|
|
/**
|
|
|
* コンボボックスデータを取得する
|
|
|
+ *
|
|
|
* @param optionsParam
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -51,17 +56,14 @@ public class CommonController
|
|
|
|
|
|
/**
|
|
|
* 汎用ダウンロードリクエスト
|
|
|
- *
|
|
|
+ *
|
|
|
* @param fileName ファイル名
|
|
|
- * @param delete 削除するかどうか
|
|
|
+ * @param delete 削除するかどうか
|
|
|
*/
|
|
|
@GetMapping("/download")
|
|
|
- public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (!FileUtils.checkAllowDownload(fileName))
|
|
|
- {
|
|
|
+ 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);
|
|
|
@@ -70,13 +72,10 @@ public class CommonController
|
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
FileUtils.setAttachmentResponseHeader(response, realFileName);
|
|
|
FileUtils.writeBytes(filePath, response.getOutputStream());
|
|
|
- if (delete)
|
|
|
- {
|
|
|
+ if (delete) {
|
|
|
FileUtils.deleteFile(filePath);
|
|
|
}
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("ファイルのダウンロードに失敗しました", e);
|
|
|
}
|
|
|
}
|
|
|
@@ -85,10 +84,8 @@ public class CommonController
|
|
|
* 汎用アップロードリクエスト(単一)
|
|
|
*/
|
|
|
@PostMapping("/upload")
|
|
|
- public AjaxResult uploadFile(MultipartFile file) throws Exception
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
+ public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
|
|
+ try {
|
|
|
// ファイルパスのアップロード
|
|
|
String filePath = AppConfig.getUploadPath();
|
|
|
// 新しいファイル名をアップロードして戻す
|
|
|
@@ -100,9 +97,7 @@ public class CommonController
|
|
|
ajax.put("newFileName", FileUtils.getName(fileName));
|
|
|
ajax.put("originalFilename", file.getOriginalFilename());
|
|
|
return ajax;
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
+ } catch (Exception e) {
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
@@ -111,18 +106,15 @@ public class CommonController
|
|
|
* 汎用アップロードリクエスト(複数)
|
|
|
*/
|
|
|
@PostMapping("/uploads")
|
|
|
- public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
+ 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)
|
|
|
- {
|
|
|
+ for (MultipartFile file : files) {
|
|
|
// 新しいファイル名をアップロードして戻す
|
|
|
String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
String url = serverConfig.getUrl() + fileName;
|
|
|
@@ -137,9 +129,7 @@ public class CommonController
|
|
|
ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
|
|
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
|
|
return ajax;
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
+ } catch (Exception e) {
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
@@ -149,12 +139,9 @@ public class CommonController
|
|
|
*/
|
|
|
@GetMapping("/download/resource")
|
|
|
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
|
|
|
- throws Exception
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (!FileUtils.checkAllowDownload(resource))
|
|
|
- {
|
|
|
+ throws Exception {
|
|
|
+ try {
|
|
|
+ if (!FileUtils.checkAllowDownload(resource)) {
|
|
|
throw new Exception(StringUtils.format("リソースファイル({})は不正で、ダウンロードは許可されていません。 ", resource));
|
|
|
}
|
|
|
|
|
|
@@ -167,10 +154,16 @@ public class CommonController
|
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
FileUtils.setAttachmentResponseHeader(response, downloadName);
|
|
|
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("ファイルのダウンロードに失敗しました", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注文IDに基づいて注文情報を検索します。
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/farmer/options")
|
|
|
+ public AjaxResult getFarmerCommonOptions() {
|
|
|
+ return AjaxResult.success(mastFarmerService.getFarmerOptions());
|
|
|
+ }
|
|
|
}
|