| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.product.integration.service; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.common.collect.Maps; |
| | | import com.product.admin.service.PublicService; |
| | | import com.product.common.lang.StringUtils; |
| | | import com.product.core.dao.BaseDao; |
| | | import com.product.core.entity.DataTableEntity; |
| | | import com.product.core.entity.FieldSetEntity; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.integration.config.CmnConst; |
| | | import com.product.integration.config.IntegrationCode; |
| | | import com.product.integration.service.idel.IInterfaceIntegrationService; |
| | | import com.product.util.BaseUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * å®ç°åè½ï¼ |
| | | * |
| | | * @author ä½è
[å¤ä¸¶å
] |
| | | * @version 1.0.00 2025-12-01 11:15 |
| | | */ |
| | | @Service |
| | | public class InterfaceIntegrationService implements IInterfaceIntegrationService { |
| | | @Autowired |
| | | private BaseDao baseDao; |
| | | @Autowired |
| | | private PublicService publicService; |
| | | |
| | | /** |
| | | * æ¥è¯¢æ°æ® |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public FieldSetEntity find(FieldSetEntity fse) { |
| | | FieldSetEntity integrationFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION, fse.getUUID(), true); |
| | | DataTableEntity responseInfoDte = integrationFse.getSubDataTable(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO); |
| | | Map<String, String> acceptKayMap = Maps.newHashMap(); |
| | | acceptKayMap.put("uuid", "front_uuid"); |
| | | JSONArray arr = BaseUtil.dataTableToTreeData(responseInfoDte, CmnConst.TRICODE, acceptKayMap, null, null); |
| | | integrationFse.removeSubData(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO); |
| | | integrationFse.setValue(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO, arr.toString()); |
| | | return integrationFse; |
| | | } |
| | | |
| | | /** |
| | | * ä¿å |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String save(FieldSetEntity fse) { |
| | | String responseInfo = fse.getString(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO); |
| | | |
| | | // æ¸
çååºç»æå表 |
| | | String uuid = fse.getUUID(); |
| | | if (!StringUtils.isEmpty(uuid)) { |
| | | baseDao.delete(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO, String.format("%s=?", CmnConst.PARENT_UUID), new Object[]{uuid}); |
| | | } |
| | | |
| | | DataTableEntity responseInfoDte = dealResponseInfo(responseInfo); |
| | | fse.addSubDataTable(responseInfoDte); |
| | | return publicService.saveFieldSetEntity(fse); |
| | | } |
| | | /** |
| | | * å¤çååºæ°æ®ç»æ |
| | | * @param responseInfo ååºæ ç»æåè¡¨ä¿¡æ¯ |
| | | * @return |
| | | */ |
| | | private DataTableEntity dealResponseInfo(String responseInfo) { |
| | | DataTableEntity responseInfoDte = new DataTableEntity(); |
| | | try { |
| | | if (!StringUtils.isEmpty(responseInfo)) { |
| | | saveDealResponseInfoPart(responseInfoDte, JSONArray.parseArray(responseInfo), ""); |
| | | } |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(IntegrationCode.SAVE_DEAL_RESPONSE_INFO); |
| | | } |
| | | return responseInfoDte; |
| | | } |
| | | /** |
| | | * ä¿å-å¤çååºæ°æ®ç»æ-å¾ªç¯æ¹æ³ |
| | | * @param responseInfoDte åå¨å®¹å¨ï¼ååºåè¡¨æ°æ®dte |
| | | * @param responseInfoArr ååºåè¡¨æ°æ®å¾
å¤çæ°ç» |
| | | * @param parentCode ç¶ç¼ç |
| | | */ |
| | | private void saveDealResponseInfoPart(DataTableEntity responseInfoDte, JSONArray responseInfoArr, String parentCode) { |
| | | for (int i = 0; i < responseInfoArr.size(); i++) { |
| | | JSONObject responseInfoObj = responseInfoArr.getJSONObject(i); |
| | | FieldSetEntity fse = new FieldSetEntity(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO); |
| | | List<String> passList = Arrays.asList("promptName", "children", "front_uuid"); |
| | | List<String> fieldList = Arrays.asList("name", "type", "db_info", "unique_sign"); |
| | | String code = String.format("%s%0" + 3 + "d", parentCode, i + 1); |
| | | responseInfoObj.forEach((key, value) -> { |
| | | if (!passList.contains(key)) { |
| | | fse.setValue(key, value); |
| | | } |
| | | }); |
| | | fieldList.forEach(fieldName -> { |
| | | if (StringUtils.isEmpty(fse.getString(fieldName))) { |
| | | fse.setValue(fieldName, ""); |
| | | } |
| | | }); |
| | | fse.setValue(CmnConst.TRICODE, code); |
| | | responseInfoDte.addFieldSetEntity(fse); |
| | | saveDealResponseInfoPart(responseInfoDte, responseInfoObj.getJSONArray(CmnConst.CHILDREN), code); |
| | | } |
| | | } |
| | | } |