管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-18 cb9fbcd27a288d0c61d85fa13ff5fc8eb1f4deab
src/main/java/com/lf/server/service/data/PublishService.java
@@ -1,15 +1,25 @@
package com.lf.server.service.data;
import com.alibaba.fastjson.JSON;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.ctrl.PubEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.data.PublishEntity;
import com.lf.server.entity.show.ExportEntity;
import com.lf.server.helper.RestHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.data.PublishMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 数据发布
@@ -17,6 +27,9 @@
 */
@Service
public class PublishService implements PublishMapper {
    @Value("${sys.exportServer}")
    private String exportServer;
    @Autowired
    PublishMapper publishMapper;
@@ -95,9 +108,44 @@
    /**
     * 发送发布请求
     */
    public int postForPub(PubEntity entity, String method, HttpServletRequest req) throws Exception {
        Thread.sleep(30000);
    public long postForPub(PubEntity entity, String method, HttpServletRequest req) throws Exception {
        Map<String, Object> map = getMapData(entity);
        return 0;
        String str = RestHelper.postForRest(exportServer + method, map);
        if (StringHelper.isEmpty(str)) {
            return 0;
        }
        ResponseMsg<String> msg = JSON.parseObject(str, ResponseMsg.class);
        if (msg == null || msg.getCode() != StaticData.TWO_HUNDRED) {
            return 0;
        }
        return msg.getCount();
    }
    /**
     * 获取Map数据
     */
    private Map<String, Object> getMapData(PubEntity entity) {
        Map<String, Object> map = new HashMap<>(3);
        Field[] fields = entity.getClass().getDeclaredFields();
        for (Field field : fields) {
            try {
                if ("serialVersionUID".equals(field.getName())) {
                    continue;
                }
                field.setAccessible(true);
                Object obj = field.get(entity);
                map.put(field.getName(), obj);
            } catch (Exception ex) {
                //
            }
        }
        return map;
    }
}