|
|
@@ -21,6 +21,7 @@ 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.achievement.bo.AchievementImportBo;
|
|
|
import com.goafanti.achievement.bo.InputAchievement;
|
|
|
import com.goafanti.achievement.service.AchievementService;
|
|
|
@@ -53,11 +54,13 @@ public class AdminAchievementApiController extends CertifyApiController {
|
|
|
/**
|
|
|
* 批量导入科技成果
|
|
|
*/
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
@RequestMapping(value = "/importAchievement", method = RequestMethod.POST)
|
|
|
- public Result importAchievement(@RequestParam(name = "data[]", required = false) AchievementImportBo[] data) {
|
|
|
+ public Result importAchievement(@RequestParam(name = "data", required = false)String d) {
|
|
|
Result res = new Result();
|
|
|
- if (data == null || data.length < 1) {
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "批量导入"));
|
|
|
+ List<AchievementImportBo> data = JSON.parseArray(d, AchievementImportBo.class);
|
|
|
+ if (data == null || data.isEmpty()) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
@@ -65,7 +68,7 @@ public class AdminAchievementApiController extends CertifyApiController {
|
|
|
if (!res.getError().isEmpty()) {
|
|
|
return res;
|
|
|
}
|
|
|
- data = (AchievementImportBo[]) res.getData();
|
|
|
+ data = (List<AchievementImportBo>) res.getData();
|
|
|
achievementService.insertImport(data);
|
|
|
return res;
|
|
|
}
|
|
|
@@ -466,12 +469,13 @@ public class AdminAchievementApiController extends CertifyApiController {
|
|
|
return fileName;
|
|
|
}
|
|
|
|
|
|
- private Result disposeImportAchievement(Result res, AchievementImportBo[] data) {
|
|
|
- for (int i = 0; i < data.length; i++) {
|
|
|
- for (Field f : data[i].getClass().getDeclaredFields()) {
|
|
|
+ private Result disposeImportAchievement(Result res, List<AchievementImportBo> data) {
|
|
|
+ Field[] field = AchievementImportBo.class.getDeclaredFields();
|
|
|
+ for (AchievementImportBo bo: data) {
|
|
|
+ for (Field f : field) {
|
|
|
f.setAccessible(true);
|
|
|
try {
|
|
|
- if (f.get(data[i]) == null || f.get(data[i]) == "") {
|
|
|
+ if (!f.getName().equals("keywords") && (f.get(bo) == null || "".equals(f.get(bo)))) {
|
|
|
AchievementImportFields.getFieldDesc(f.toString().substring(f.toString().lastIndexOf(".") + 1));
|
|
|
res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", AchievementImportFields
|
|
|
.getFieldDesc(f.toString().substring(f.toString().lastIndexOf(".") + 1))));
|
|
|
@@ -481,73 +485,73 @@ public class AdminAchievementApiController extends CertifyApiController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (data[i].getDataCategory().toString().length() > 1) {
|
|
|
+ if (bo.getDataCategory().toString().length() > 1) {
|
|
|
res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
|
|
|
AchievementImportFields.DATACATEGORY.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getName().length() > 31) {
|
|
|
+ if (bo.getName().length() > 31) {
|
|
|
res.getError()
|
|
|
.add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.NAME.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getCategory().toString().length() > 1) {
|
|
|
+ if (bo.getCategory().toString().length() > 1) {
|
|
|
res.getError().add(
|
|
|
buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.CATEGORY.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getOwnerName().length() > 31) {
|
|
|
+ if (bo.getOwnerName().length() > 31) {
|
|
|
res.getError().add(
|
|
|
buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERNAME.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getOwnerType().toString().length() > 1) {
|
|
|
+ if (bo.getOwnerType().toString().length() > 1) {
|
|
|
res.getError().add(
|
|
|
buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERTYPE.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getOwnerIdNumber().length() > 35) {
|
|
|
+ if (bo.getOwnerIdNumber().length() > 35) {
|
|
|
res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
|
|
|
AchievementImportFields.OWNERIDNUMBER.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getOwnerMobile().length() > 11) {
|
|
|
+ if (bo.getOwnerMobile().length() > 11) {
|
|
|
res.getError().add(
|
|
|
buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERMOBILE.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getOwnerEmail().length() > 254) {
|
|
|
+ if (bo.getOwnerEmail().length() > 254) {
|
|
|
res.getError().add(
|
|
|
buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERMOBILE.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getOwnerPostalAddress().length() > 254) {
|
|
|
+ if (bo.getOwnerPostalAddress().length() > 254) {
|
|
|
res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
|
|
|
AchievementImportFields.OWNERPOSTALADDRESS.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getCooperationMode().toString().length() > 1) {
|
|
|
+ if (bo.getCooperationMode().toString().length() > 1) {
|
|
|
res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
|
|
|
AchievementImportFields.COOPERATIONMODE.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- if (data[i].getKeyword().length() > 44) {
|
|
|
+ if (bo.getKeyword().length() > 44) {
|
|
|
res.getError().add(
|
|
|
buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.KEYWORD.getDesc()));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- String[] keywords = data[i].getKeyword().trim().split(",|,");
|
|
|
+ String[] keywords = bo.getKeyword().trim().split(",|,");
|
|
|
if (null == keywords || keywords.length < 1) {
|
|
|
res.getError()
|
|
|
.add(buildError(ErrorConstants.PARAM_ERROR, "", AchievementImportFields.KEYWORD.getDesc()));
|
|
|
@@ -560,7 +564,7 @@ public class AdminAchievementApiController extends CertifyApiController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- data[i].setKeywords(list);
|
|
|
+ bo.setKeywords(list);
|
|
|
}
|
|
|
res.setData(data);
|
|
|
return res;
|