|
|
@@ -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;
|
|
|
@@ -10,6 +12,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
+import org.junit.Test;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -28,6 +31,7 @@ import com.goafanti.common.constant.ErrorConstants;
|
|
|
import com.goafanti.common.controller.CertifyApiController;
|
|
|
import com.goafanti.common.enums.AchievementAuditStatus;
|
|
|
import com.goafanti.common.enums.AchievementFields;
|
|
|
+import com.goafanti.common.enums.AchievementImportFields;
|
|
|
import com.goafanti.common.enums.AttachmentType;
|
|
|
import com.goafanti.common.enums.DeleteStatus;
|
|
|
import com.goafanti.common.model.Achievement;
|
|
|
@@ -57,13 +61,11 @@ public class AdminAchievementApiController extends CertifyApiController {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- /*for (int i = 0; i < data.length; i++) {
|
|
|
- for(Field f : data[i].getClass().getDeclaredFields()){
|
|
|
- f.setAccessible(true);
|
|
|
- if(f.get(data[i]) == null){
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
+ res = disposeImportAchievement(res, data);
|
|
|
+ if (!res.getError().isEmpty()) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ data = (AchievementImportBo[]) res.getData();
|
|
|
achievementService.insertImport(data);
|
|
|
return res;
|
|
|
}
|
|
|
@@ -464,4 +466,116 @@ 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()) {
|
|
|
+ f.setAccessible(true);
|
|
|
+ try {
|
|
|
+ if (f.get(data[i]) == null || f.get(data[i]) == "") {
|
|
|
+ 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))));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ } catch (IllegalArgumentException | IllegalAccessException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getDataCategory().toString().length() > 1) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
|
|
|
+ AchievementImportFields.DATACATEGORY.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getName().length() > 31) {
|
|
|
+ res.getError()
|
|
|
+ .add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.NAME.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getCategory().toString().length() > 1) {
|
|
|
+ res.getError().add(
|
|
|
+ buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.CATEGORY.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getOwnerName().length() > 31) {
|
|
|
+ res.getError().add(
|
|
|
+ buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERNAME.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getOwnerType().toString().length() > 1) {
|
|
|
+ res.getError().add(
|
|
|
+ buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERTYPE.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getOwnerIdNumber().length() > 35) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
|
|
|
+ AchievementImportFields.OWNERIDNUMBER.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getOwnerMobile().length() > 11) {
|
|
|
+ res.getError().add(
|
|
|
+ buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERMOBILE.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getOwnerEmail().length() > 254) {
|
|
|
+ res.getError().add(
|
|
|
+ buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERMOBILE.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getOwnerPostalAddress().length() > 254) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
|
|
|
+ AchievementImportFields.OWNERPOSTALADDRESS.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getCooperationMode().toString().length() > 1) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
|
|
|
+ AchievementImportFields.COOPERATIONMODE.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data[i].getKeyword().length() > 44) {
|
|
|
+ res.getError().add(
|
|
|
+ buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.KEYWORD.getDesc()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] keywords = data[i].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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ data[i].setKeywords(list);
|
|
|
+ }
|
|
|
+ res.setData(data);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test() {
|
|
|
+ String[] s = new String(" , a").trim().split(",|,");
|
|
|
+ System.out.println(StringUtils.isBlank(" "));
|
|
|
+ System.out.println(s.length);
|
|
|
+ for (String ss : s) {
|
|
|
+ if (!StringUtils.isBlank(ss)) {
|
|
|
+ System.out.println("a" + ss.trim() + "b");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|