|
@@ -0,0 +1,73 @@
|
|
|
+package com.rongwei.bscommon.sys.utils;
|
|
|
+
|
|
|
+import com.rongwei.bsentity.dto.OrgApiDataConfigDTO;
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static com.rongwei.bscommon.sys.utils.JXKHConstant.DatePattern.DATE_PATTERN_YMD;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * ApiDattaOrgUtil class
|
|
|
+ *
|
|
|
+ * @author XH
|
|
|
+ * @date 2024/12/02
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ApiDattaOrgUtil {
|
|
|
+
|
|
|
+ public static final String IMG_SPLIT_SIGN = "\\^_\\^";
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ApiDattaOrgUtil.class.getName());
|
|
|
+
|
|
|
+ public static <T> Map<String, Object> assembleApiData(T infos,
|
|
|
+ List<OrgApiDataConfigDTO> orgApiDataConfigDTOS) {
|
|
|
+ Map<String, Object> apiData = new HashMap();
|
|
|
+
|
|
|
+ orgApiDataConfigDTOS.forEach(configDTO -> {
|
|
|
+ String key = configDTO.getKey();
|
|
|
+ Object apply = configDTO.getGetDataFunction().apply(infos);
|
|
|
+ apiData.put(key, ObjConver(apply, configDTO));
|
|
|
+ });
|
|
|
+ return apiData;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Object ObjConver(Object obj, OrgApiDataConfigDTO configDTO) {
|
|
|
+ log.info("开始进行数据转换:{}", obj);
|
|
|
+ Object renturnObj = obj;
|
|
|
+ if (obj == null) {
|
|
|
+ log.debug("数据为空");
|
|
|
+ return renturnObj;
|
|
|
+ }
|
|
|
+ if (configDTO.getDateFlag()) {
|
|
|
+ log.debug("开始进行时间格式转换");
|
|
|
+ if (obj instanceof java.util.Date) {
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(StringUtils.isBlank(configDTO.getDatePattern()) ? DATE_PATTERN_YMD : configDTO.getDatePattern());
|
|
|
+ renturnObj = simpleDateFormat.format(obj);
|
|
|
+ return renturnObj;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (configDTO.getFileFlag()) {
|
|
|
+ log.debug("图片数据处理");
|
|
|
+ String filesInfo = obj.toString();
|
|
|
+ if (StringUtils.isBlank(filesInfo)) {
|
|
|
+ return renturnObj;
|
|
|
+ }
|
|
|
+ return Arrays.asList(filesInfo.split(IMG_SPLIT_SIGN)).stream().map(data -> {
|
|
|
+ String fileId = data.split("-;-")[1];
|
|
|
+ // 执行附件上传方法 返回真实的id
|
|
|
+ return "";
|
|
|
+ }).collect(Collectors.joining(","));
|
|
|
+ }
|
|
|
+ log.debug("其他格式的数据");
|
|
|
+ return renturnObj;
|
|
|
+ }
|
|
|
+}
|