|
|
@@ -1,6 +1,8 @@
|
|
|
package com.goafanti.admin.controller;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
@@ -18,11 +20,13 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.goafanti.admin.service.AftFileService;
|
|
|
import com.goafanti.common.bo.Result;
|
|
|
import com.goafanti.common.constant.AFTConstants;
|
|
|
import com.goafanti.common.constant.ErrorConstants;
|
|
|
import com.goafanti.common.controller.CertifyApiController;
|
|
|
+import com.goafanti.common.enums.AchievementImportFields;
|
|
|
import com.goafanti.common.enums.AttachmentType;
|
|
|
import com.goafanti.common.enums.DeleteStatus;
|
|
|
import com.goafanti.common.enums.DemandAuditStatus;
|
|
|
@@ -46,30 +50,43 @@ public class AdminDemandApiController extends CertifyApiController {
|
|
|
private UserService userService;
|
|
|
@Resource
|
|
|
private AftFileService aftFileService;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 批量导入科技需求
|
|
|
*/
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
@RequestMapping(value = "/importDemand", method = RequestMethod.POST)
|
|
|
- public Result importDemand(@RequestParam(name = "data[]", required = false) DemandImportBo[] data){
|
|
|
+ public Result importDemand(@RequestParam(name = "data[]", required = false) String d) {
|
|
|
Result res = new Result();
|
|
|
-
|
|
|
+ List<DemandImportBo> data = JSON.parseArray(d, DemandImportBo.class);
|
|
|
+ if (data == null || data.isEmpty()) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "导入数据"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data.size() > AFTConstants.IMPORTMAXLENTH) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "导入数据量"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ res = disposeImportDemand(res, data);
|
|
|
+ if (!res.getError().isEmpty()) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ data = (List<DemandImportBo>) res.getData();
|
|
|
+ demandService.insertImport(data);
|
|
|
return res;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 成果需求匹配列表
|
|
|
*/
|
|
|
@RequestMapping(value = "/achievementDemand", method = RequestMethod.GET)
|
|
|
- public Result achievementDemand(String id){
|
|
|
+ public Result achievementDemand(String id) {
|
|
|
Result res = new Result();
|
|
|
res.setData(demandService.selectAchievementDemandListByDemandId(id));
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 上传技术需求批量导入Excel模板
|
|
|
@@ -108,7 +125,7 @@ public class AdminDemandApiController extends CertifyApiController {
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 下载技术需求批量导入Excel模板
|
|
|
*
|
|
|
@@ -475,4 +492,37 @@ public class AdminDemandApiController extends CertifyApiController {
|
|
|
return fileName;
|
|
|
}
|
|
|
|
|
|
+ private Result disposeImportDemand(Result res, List<DemandImportBo> data) {
|
|
|
+ Field[] field = DemandImportBo.class.getDeclaredFields();
|
|
|
+ for (DemandImportBo bo : data) {
|
|
|
+ for (Field f : field) {
|
|
|
+ f.setAccessible(true);
|
|
|
+ try {
|
|
|
+ if (!f.getName().equals("keywords") && (f.get(bo) == null || "".equals(f.get(bo)))) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "",
|
|
|
+ AchievementImportFields.getFieldDesc(f.getName())));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ } catch (IllegalArgumentException | IllegalAccessException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String[] keywords = bo.getKeyword().trim().split(",|,");
|
|
|
+ if (null == keywords || keywords.length < 1) {
|
|
|
+ res.getError()
|
|
|
+ .add(buildError(ErrorConstants.PARAM_ERROR, "", AchievementImportFields.KEYWORD.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (String s : keywords) {
|
|
|
+ if (!StringUtils.isBlank(s)) {
|
|
|
+ list.add(s.trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bo.setKeywords(list);
|
|
|
+ }
|
|
|
+ res.setData(data);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
}
|