|
|
@@ -27,7 +27,17 @@ import com.uas.ps.product.sync.WaitSyncHelper;
|
|
|
import com.uas.ps.properties.UrlProperties;
|
|
|
import com.uas.ps.support.CodeType;
|
|
|
import com.uas.ps.support.ResultMap;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import javax.persistence.Column;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.log4j.Logger;
|
|
|
@@ -39,15 +49,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.sql.PreparedStatement;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
/**
|
|
|
* @author sunyj
|
|
|
* @since 2018/1/6 17:19
|
|
|
@@ -1029,9 +1030,38 @@ public class ProductServiceImpl implements ProductService {
|
|
|
|
|
|
// 配置data
|
|
|
product.setMatchResults(null);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String json = JSON.toJSONString(product);
|
|
|
- json = json.replace("\"\"", "\"null\"");
|
|
|
+
|
|
|
+ Field [] fields = product.getClass().getDeclaredFields();
|
|
|
+ for (Field field : fields) {
|
|
|
+ Column column = field.getAnnotation(Column.class);
|
|
|
+ if (column != null && !StringUtils.isEmpty(column.name())) {
|
|
|
+ json = json.replace(field.getName(), column.name());
|
|
|
+ // 处理date类型数据
|
|
|
+ if (field.getType().equals(Date.class) && json.indexOf(column.name()) > -1) {
|
|
|
+ String value = json.substring(json.indexOf(column.name()) + column.name().length(), ordinalIndexOf(json, "\"", json.indexOf(column.name()), 2));
|
|
|
+ json = json.replace(value, "\":\"" + sdf.format(Long.valueOf(value.replaceAll("\"", "").replace(":","").replace(",", ""))) + "\",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
map.put("data", json);
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取字符串在源字符串第几次出现的位置
|
|
|
+ * @param str 源字符串
|
|
|
+ * @param substr 判断字符串
|
|
|
+ * @param start 起始位置
|
|
|
+ * @param n 第几次出现
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public int ordinalIndexOf(String str, String substr, int start, int n) {
|
|
|
+ int pos = str.indexOf(substr, start);
|
|
|
+ while (--n > 0 && pos != -1)
|
|
|
+ pos = str.indexOf(substr, pos + 1);
|
|
|
+ return pos;
|
|
|
+ }
|
|
|
}
|