forked from wuweidong/hzims-back-huoshan
				
			
				 47 changed files with 2642 additions and 0 deletions
			
			
		@ -0,0 +1,110 @@
					 | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<project xmlns="http://maven.apache.org/POM/4.0.0" | 
				
			||||
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 
				
			||||
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | 
				
			||||
    <modelVersion>4.0.0</modelVersion> | 
				
			||||
    <parent> | 
				
			||||
        <artifactId>hzims-service</artifactId> | 
				
			||||
        <groupId>com.hnac.hzims</groupId> | 
				
			||||
        <version>4.0.0-SNAPSHOT</version> | 
				
			||||
    </parent> | 
				
			||||
 | 
				
			||||
    <artifactId>hzims-simulate</artifactId> | 
				
			||||
 | 
				
			||||
    <properties> | 
				
			||||
        <maven.compiler.source>8</maven.compiler.source> | 
				
			||||
        <maven.compiler.target>8</maven.compiler.target> | 
				
			||||
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | 
				
			||||
    </properties> | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    <dependencies> | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>com.xuxueli</groupId> | 
				
			||||
            <artifactId>xxl-job-core</artifactId> | 
				
			||||
        </dependency> | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>org.springblade</groupId> | 
				
			||||
            <artifactId>blade-common</artifactId> | 
				
			||||
        </dependency> | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>org.springblade</groupId> | 
				
			||||
            <artifactId>blade-core-boot</artifactId> | 
				
			||||
            <exclusions> | 
				
			||||
                <exclusion> | 
				
			||||
                    <groupId>org.springblade</groupId> | 
				
			||||
                    <artifactId>blade-core-cloud</artifactId> | 
				
			||||
                </exclusion> | 
				
			||||
            </exclusions> | 
				
			||||
        </dependency> | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>org.springblade</groupId> | 
				
			||||
            <artifactId>blade-starter-http</artifactId> | 
				
			||||
        </dependency> | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>org.springblade</groupId> | 
				
			||||
            <artifactId>blade-core-cloud</artifactId> | 
				
			||||
            <scope>compile</scope> | 
				
			||||
        </dependency> | 
				
			||||
 | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>org.springblade</groupId> | 
				
			||||
            <artifactId>blade-starter-datascope</artifactId> | 
				
			||||
            <scope>compile</scope> | 
				
			||||
        </dependency> | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>org.projectlombok</groupId> | 
				
			||||
            <artifactId>lombok</artifactId> | 
				
			||||
        </dependency> | 
				
			||||
 | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>com.hzinfo.framework</groupId> | 
				
			||||
            <artifactId>hnac-framework-mqtt-starters</artifactId> | 
				
			||||
            <version>${bladex.project.version}</version> | 
				
			||||
        </dependency> | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>com.hnac.hzinfo.data</groupId> | 
				
			||||
            <artifactId>hzinfo-data-sdk</artifactId> | 
				
			||||
            <version>${hzinfo.data.sdk.version}</version> | 
				
			||||
        </dependency> | 
				
			||||
 | 
				
			||||
        <dependency> | 
				
			||||
            <groupId>dom4j</groupId> | 
				
			||||
            <artifactId>dom4j</artifactId> | 
				
			||||
            <version>1.6.1</version> | 
				
			||||
            <scope>compile</scope> | 
				
			||||
        </dependency> | 
				
			||||
 | 
				
			||||
    </dependencies> | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    <build> | 
				
			||||
        <resources> | 
				
			||||
            <resource> | 
				
			||||
                <directory>src/main/java</directory> | 
				
			||||
                <includes> | 
				
			||||
                    <include>**/*.xml</include> | 
				
			||||
                </includes> | 
				
			||||
                <filtering>false</filtering> | 
				
			||||
            </resource> | 
				
			||||
        </resources> | 
				
			||||
        <plugins> | 
				
			||||
            <plugin> | 
				
			||||
                <groupId>org.springframework.boot</groupId> | 
				
			||||
                <artifactId>spring-boot-maven-plugin</artifactId> | 
				
			||||
                <version>2.6.6</version> | 
				
			||||
                <executions> | 
				
			||||
                    <execution> | 
				
			||||
                        <goals> | 
				
			||||
                            <goal>repackage</goal> | 
				
			||||
                        </goals> | 
				
			||||
<!--                        <configuration>--> | 
				
			||||
<!--                            <classifier>exec</classifier>--> | 
				
			||||
<!--                        </configuration>--> | 
				
			||||
                    </execution> | 
				
			||||
                </executions> | 
				
			||||
            </plugin> | 
				
			||||
        </plugins> | 
				
			||||
    </build> | 
				
			||||
 | 
				
			||||
</project> | 
				
			||||
@ -0,0 +1,29 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate; | 
				
			||||
 | 
				
			||||
import org.mybatis.spring.annotation.MapperScan; | 
				
			||||
import org.springblade.core.cloud.feign.EnableBladeFeign; | 
				
			||||
import org.springblade.core.launch.BladeApplication; | 
				
			||||
import org.springframework.boot.builder.SpringApplicationBuilder; | 
				
			||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | 
				
			||||
import org.springframework.cloud.client.SpringCloudApplication; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author admin | 
				
			||||
 */ | 
				
			||||
@EnableBladeFeign | 
				
			||||
@SpringCloudApplication | 
				
			||||
@MapperScan(basePackages = {"com.hnac.hzinfo.**.mapper"}) | 
				
			||||
//@ComponentScan(basePackages = {"com.hnac.hzinfo.simulate"})
 | 
				
			||||
public class HzimsSimulateApplication extends SpringBootServletInitializer { | 
				
			||||
    static String APPLICATION_NAME = "hzims-simulate"; | 
				
			||||
 | 
				
			||||
    public static void main(String[] args) { | 
				
			||||
        BladeApplication.run(APPLICATION_NAME, HzimsSimulateApplication.class, args); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { | 
				
			||||
        return BladeApplication.createSpringApplicationBuilder(builder, APPLICATION_NAME, HzimsSimulateApplication.class); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,43 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.constants; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 * @describe 实时数据写入常量 | 
				
			||||
 */ | 
				
			||||
public interface WriteRealDataConstant { | 
				
			||||
 | 
				
			||||
   String REAL_DATA_V3 = "3"; | 
				
			||||
 | 
				
			||||
   String REAL_DATA_V4 = "4"; | 
				
			||||
 | 
				
			||||
   String GATE_FLOW = "过闸流量(m³/s)"; | 
				
			||||
 | 
				
			||||
   String OPENING_DEGREE = "开度(m)"; | 
				
			||||
 | 
				
			||||
   String GATE_STATUS = "闸门状态"; | 
				
			||||
 | 
				
			||||
   String WRITE_REAL_GATE_DATA = "writeRealGateData"; | 
				
			||||
 | 
				
			||||
   String WRITE_REAL_RAIN_DATA = "writeRealRainData"; | 
				
			||||
 | 
				
			||||
   Long OPEN = 0L; | 
				
			||||
 | 
				
			||||
   Long CLOSE = 1L; | 
				
			||||
 | 
				
			||||
   String WRITE_GATE = "1"; | 
				
			||||
 | 
				
			||||
   String WRITE_RAIN = "2"; | 
				
			||||
 | 
				
			||||
   // 降雨站属性标识
 | 
				
			||||
   String ATTR_RAIN = "attr_rain"; | 
				
			||||
   String ATTR_WIND360 = "wind360"; | 
				
			||||
   String ATTR_WIND_SCALE = "wind_scale"; | 
				
			||||
   String ATTR_WIND_SPEED = "wind_speed "; | 
				
			||||
   String ATTR_HUMIDITY = "humidity"; | 
				
			||||
   String ATTR_PRESSURE = "pressure"; | 
				
			||||
   String ATTR_VIS = "vis"; | 
				
			||||
   String ATTR_CLOUD = "cloud"; | 
				
			||||
   String ATTR_DEW = "dew"; | 
				
			||||
   String ATTR_FEELS_LIKE = "feels_like"; | 
				
			||||
   String ATTR_TEMP = "temp"; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,31 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.controller; | 
				
			||||
 | 
				
			||||
import com.hnac.hzinfo.simulate.service.WriteRealDataService; | 
				
			||||
import io.swagger.annotations.Api; | 
				
			||||
import io.swagger.annotations.ApiOperation; | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
import org.springblade.core.tool.api.R; | 
				
			||||
import org.springframework.web.bind.annotation.GetMapping; | 
				
			||||
import org.springframework.web.bind.annotation.RequestMapping; | 
				
			||||
import org.springframework.web.bind.annotation.RequestParam; | 
				
			||||
import org.springframework.web.bind.annotation.RestController; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 */ | 
				
			||||
@RestController | 
				
			||||
@AllArgsConstructor | 
				
			||||
@RequestMapping("/gate") | 
				
			||||
@Api(value = "闸门开关机模拟服务", tags = "闸门开关机模拟服务") | 
				
			||||
public class GageController { | 
				
			||||
 | 
				
			||||
   private final WriteRealDataService writeRealDataService; | 
				
			||||
 | 
				
			||||
    @GetMapping("/isOpen") | 
				
			||||
    @ApiOperation(value = "枢纽天气情况") | 
				
			||||
    public R<Boolean> weather(@RequestParam("deviceCode") String deviceCode, | 
				
			||||
                                            @RequestParam("isOpen") Long isOpen){ | 
				
			||||
        return R.data(writeRealDataService.isOpen(deviceCode,isOpen)); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,181 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.controller; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
				
			||||
import com.baomidou.mybatisplus.core.metadata.IPage; | 
				
			||||
import com.google.common.collect.Maps; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DataModel; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.Device; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceField; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceFieldGap; | 
				
			||||
import com.hnac.hzinfo.simulate.enums.ExceptionEnum; | 
				
			||||
import com.hnac.hzinfo.simulate.service.DeviceFieldGapService; | 
				
			||||
import com.hnac.hzinfo.simulate.service.DeviceFieldService; | 
				
			||||
import com.hnac.hzinfo.simulate.service.SimulationService; | 
				
			||||
import com.hnac.hzinfo.simulate.util.ParseFacUtils; | 
				
			||||
import com.hnac.hzinfo.simulate.util.TopicConstant; | 
				
			||||
import io.swagger.annotations.Api; | 
				
			||||
import io.swagger.annotations.ApiOperation; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
import org.springblade.core.log.exception.ServiceException; | 
				
			||||
import org.springblade.core.mp.support.Condition; | 
				
			||||
import org.springblade.core.mp.support.Query; | 
				
			||||
import org.springblade.core.tool.api.R; | 
				
			||||
import org.springblade.core.tool.jackson.JsonUtil; | 
				
			||||
import org.springblade.core.tool.utils.Func; | 
				
			||||
import org.springblade.mqtt.producer.IMqttSender; | 
				
			||||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			||||
import org.springframework.beans.factory.annotation.Value; | 
				
			||||
import org.springframework.web.bind.annotation.*; | 
				
			||||
 | 
				
			||||
import java.io.File; | 
				
			||||
import java.io.FileInputStream; | 
				
			||||
import java.io.IOException; | 
				
			||||
import java.io.InputStream; | 
				
			||||
import java.math.BigDecimal; | 
				
			||||
import java.util.List; | 
				
			||||
import java.util.Map; | 
				
			||||
import java.util.stream.Collectors; | 
				
			||||
 | 
				
			||||
@RestController | 
				
			||||
@RequestMapping("/simulationData") | 
				
			||||
@Api(value = "数据模拟服务", tags = "数据模拟服务") | 
				
			||||
@Slf4j | 
				
			||||
public class SimulationDataController { | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    private SimulationService simulationService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    private DeviceFieldService deviceFieldService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    private DeviceFieldGapService deviceFieldGapService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    private IMqttSender mqttSender; | 
				
			||||
 | 
				
			||||
    @Value("fac.path") | 
				
			||||
    private String facPath; | 
				
			||||
 | 
				
			||||
    public static Map<String, String> cacheMap = Maps.newHashMap(); | 
				
			||||
 | 
				
			||||
    @ApiOperation(value = "解析v3.0场信息文件", notes = "解析场信息文件") | 
				
			||||
    @GetMapping("/readFac") | 
				
			||||
    public R<Void> readFac() { | 
				
			||||
        InputStream inputStream = null; | 
				
			||||
        try { | 
				
			||||
            inputStream = new FileInputStream(new File(facPath + File.separator + "factory.fac")); | 
				
			||||
            List<DataModel> list = ParseFacUtils.parsePoint(inputStream); | 
				
			||||
            list.forEach(entity -> { | 
				
			||||
                mqttSender.sendToMqtt(TopicConstant.TOPIC_DEVICE_MODEL, JsonUtil.toJson(entity)); | 
				
			||||
            }); | 
				
			||||
            return R.success("解析场信息文件成功"); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            log.error(e.getMessage(), e); | 
				
			||||
            return R.fail("解析场信息文件失败"); | 
				
			||||
        } finally { | 
				
			||||
            if (inputStream != null) { | 
				
			||||
                try { | 
				
			||||
                    inputStream.close(); | 
				
			||||
                } catch (IOException e) { | 
				
			||||
                    e.printStackTrace(); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @ApiOperation(value = "分页范围配置", notes = "分页范围配置") | 
				
			||||
    @GetMapping("/pageGap") | 
				
			||||
    public R<IPage<DeviceFieldGap>> pageGap(String stationId, Query query) { | 
				
			||||
        List<Device> list = simulationService.getDeviceListByStationId(stationId); | 
				
			||||
        List<String> ids = list.stream().map(Device::getId).collect(Collectors.toList()); | 
				
			||||
        LambdaQueryWrapper<DeviceFieldGap> lambdaQueryWrapper = new LambdaQueryWrapper(); | 
				
			||||
        lambdaQueryWrapper.in(DeviceFieldGap::getFacDeviceId, ids); | 
				
			||||
        IPage<DeviceFieldGap> pageList = deviceFieldGapService.page(Condition.getPage(query), lambdaQueryWrapper); | 
				
			||||
        return R.data(pageList); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @ApiOperation(value = "更新设备属性范围配置", notes = "更新设备属性范围配置") | 
				
			||||
    @PostMapping("/updateGap") | 
				
			||||
    public R updateGap(@RequestBody DeviceFieldGap deviceFieldGap) { | 
				
			||||
        deviceFieldGapService.updateById(deviceFieldGap); | 
				
			||||
        return R.status(true); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @ApiOperation(value = "第一次同步设备属性", notes = "第一次同步设备属性") | 
				
			||||
    @GetMapping("/syncOneGap") | 
				
			||||
    public R syncGap() { | 
				
			||||
        //存在表
 | 
				
			||||
        int count = deviceFieldService.existGapTable(); | 
				
			||||
        if (count <= 0) {//建表
 | 
				
			||||
            deviceFieldService.createGapTable(); | 
				
			||||
        } | 
				
			||||
        //同步
 | 
				
			||||
        List<DeviceField> list = deviceFieldService.list(); | 
				
			||||
        List<DeviceFieldGap> gaps = list.stream().map(result -> new DeviceFieldGap(result.getId(), result.getFacDeviceId(), | 
				
			||||
                        result.getSignage(), result.getName(), BigDecimal.ZERO, BigDecimal.ZERO)) | 
				
			||||
                .collect(Collectors.toList()); | 
				
			||||
        deviceFieldGapService.saveOrUpdateBatch(gaps); | 
				
			||||
 | 
				
			||||
        return R.status(true); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @ApiOperation(value = "第二次同步设备属性", notes = "第二次同步设备属性") | 
				
			||||
    @GetMapping("/syncTwoGap") | 
				
			||||
    public R syncTwoGap() { | 
				
			||||
        //同步
 | 
				
			||||
        List<DeviceField> list = deviceFieldService.queryNewInsert(); | 
				
			||||
        if (list != null && !list.isEmpty()) { | 
				
			||||
            List<DeviceFieldGap> gaps = list.stream().map(result -> new DeviceFieldGap(result.getId(), result.getFacDeviceId(), | 
				
			||||
                            result.getSignage(), result.getName(), BigDecimal.ZERO, BigDecimal.ZERO)) | 
				
			||||
                    .collect(Collectors.toList()); | 
				
			||||
            deviceFieldGapService.saveBatch(gaps); | 
				
			||||
        } | 
				
			||||
        return R.status(true); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    @ApiOperation(value = "模拟单站的数据(循环,每隔sleepTime时长发送一次整站数据)", notes = "模拟单站的数据") | 
				
			||||
    @GetMapping("/simulationMultiple") | 
				
			||||
    public R<Void> simulationMultipleV3(String stationId, Long sleepTime) { | 
				
			||||
        String key = "simulation:" + stationId; | 
				
			||||
        String hasExc = cacheMap.get(key); | 
				
			||||
        if (Func.isNotBlank(hasExc)) { | 
				
			||||
            return R.fail("该站已经在模拟数据了"); | 
				
			||||
        } | 
				
			||||
        try { | 
				
			||||
            simulationService.simulationMultiple(stationId, sleepTime); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new ServiceException(ExceptionEnum.SIMULATE_ERROR); | 
				
			||||
        } | 
				
			||||
        cacheMap.put(key, "true"); | 
				
			||||
        return R.status(true); | 
				
			||||
 | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @ApiOperation(value = "模拟单站的数据(循环,每隔sleepTime时长发送一次整站数据)", notes = "模拟单站的数据") | 
				
			||||
    @GetMapping("/simulationMultipleV4") | 
				
			||||
    public R<Void> simulationMultipleV4(String stationId, Long sleepTime) { | 
				
			||||
        String key = "simulation:" + stationId; | 
				
			||||
        String hasExc = cacheMap.get(key); | 
				
			||||
        if (Func.isNotBlank(hasExc)) { | 
				
			||||
            return R.fail("该站已经在模拟数据了"); | 
				
			||||
        } | 
				
			||||
        try { | 
				
			||||
            simulationService.simulationMultipleV4(stationId, sleepTime); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new ServiceException(ExceptionEnum.SIMULATE_ERROR); | 
				
			||||
        } | 
				
			||||
        cacheMap.put(key, "true"); | 
				
			||||
        return R.status(true); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @ApiOperation(value = "停止模拟", notes = "停止模拟") | 
				
			||||
    @GetMapping("/stopStart") | 
				
			||||
    public R<Void> stopStart() { | 
				
			||||
        simulationService.stopStart(); | 
				
			||||
        return R.status(true); | 
				
			||||
 | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,20 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.Builder; | 
				
			||||
import lombok.Data; | 
				
			||||
import lombok.NoArgsConstructor; | 
				
			||||
 | 
				
			||||
@Data | 
				
			||||
@AllArgsConstructor | 
				
			||||
@NoArgsConstructor | 
				
			||||
@Builder | 
				
			||||
public class DataItem { | 
				
			||||
 | 
				
			||||
    private String id; | 
				
			||||
    private String signage;//hz3000定义的id
 | 
				
			||||
    private String name; | 
				
			||||
    private String type; | 
				
			||||
    private String soeType; | 
				
			||||
    private String eventType; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,46 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import lombok.Data; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * { | 
				
			||||
 * 	"station": "4543", | 
				
			||||
 * 	"structType": "dataGroup", | 
				
			||||
 * 	"id": "5016387599_0", | 
				
			||||
 * 	"pid": "5016387585", | 
				
			||||
 * 	"name": "温度传感器", | 
				
			||||
 * 	"children": [{ | 
				
			||||
 * 			"id": "5016387607", | 
				
			||||
 * 			"name": "温度", | 
				
			||||
 * 			"type": "YC" | 
				
			||||
 *                },{ | 
				
			||||
 * 			"id": "5016387617", | 
				
			||||
 * 			"name": "高度", | 
				
			||||
 * 			"type": "YC" | 
				
			||||
 *        },{ | 
				
			||||
 * 			"id": "5016387608", | 
				
			||||
 * 			"name": "工作状态", | 
				
			||||
 * 			"type": "YX" | 
				
			||||
 *        },{ | 
				
			||||
 * 			"id": "5016387609", | 
				
			||||
 * 			"name": "工作状态", | 
				
			||||
 * 			"type": "SOE", | 
				
			||||
 * 			"eventType": "" | 
				
			||||
 * 		}] | 
				
			||||
 * } | 
				
			||||
 * 数据组 | 
				
			||||
 * @author ninglong | 
				
			||||
 */ | 
				
			||||
@Data | 
				
			||||
public class DataModel { | 
				
			||||
    private String station; | 
				
			||||
    private String structType; | 
				
			||||
    private String id; | 
				
			||||
    private String signage;//hz3000定义的id
 | 
				
			||||
    private String pid; | 
				
			||||
    private String name; | 
				
			||||
    private List<DataItem> children; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
@ -0,0 +1,63 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.annotation.IdType; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableId; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableName; | 
				
			||||
import com.fasterxml.jackson.annotation.JsonFormat; | 
				
			||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | 
				
			||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | 
				
			||||
import io.swagger.annotations.ApiModelProperty; | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.Builder; | 
				
			||||
import lombok.Data; | 
				
			||||
import lombok.NoArgsConstructor; | 
				
			||||
import org.springframework.format.annotation.DateTimeFormat; | 
				
			||||
 | 
				
			||||
import java.io.Serializable; | 
				
			||||
import java.util.Date; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * 数据组 | 
				
			||||
 * | 
				
			||||
 * @author ninglong | 
				
			||||
 */ | 
				
			||||
@TableName(value = "hzinfo_fac_device") | 
				
			||||
@Data | 
				
			||||
@AllArgsConstructor | 
				
			||||
@NoArgsConstructor | 
				
			||||
@Builder | 
				
			||||
public class Device implements Serializable { | 
				
			||||
 | 
				
			||||
    @ApiModelProperty(value = "id") | 
				
			||||
    @TableId(type = IdType.INPUT) | 
				
			||||
    private String id; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty(value = "名称") | 
				
			||||
    private String name; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty(value = "0-云端cms,1-站端直传") | 
				
			||||
    private Integer source; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("hz3000定义的id,如果定义的是大id则值与id字段值相同") | 
				
			||||
    private String sid; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("version=v3,version=v4") | 
				
			||||
    private String modelKind; | 
				
			||||
 | 
				
			||||
    @DateTimeFormat( | 
				
			||||
            pattern = "yyyy-MM-dd HH:mm:ss" | 
				
			||||
    ) | 
				
			||||
    @JsonFormat( | 
				
			||||
            pattern = "yyyy-MM-dd HH:mm:ss" | 
				
			||||
    ) | 
				
			||||
    @ApiModelProperty("创建时间") | 
				
			||||
    private Date createTime; | 
				
			||||
 | 
				
			||||
    @JsonSerialize( | 
				
			||||
            using = ToStringSerializer.class | 
				
			||||
    ) | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("项目id") | 
				
			||||
    private String projectId; | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,22 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import com.google.common.collect.Lists; | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.Builder; | 
				
			||||
import lombok.Data; | 
				
			||||
import lombok.NoArgsConstructor; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * 设备数据 | 
				
			||||
 */ | 
				
			||||
@Data | 
				
			||||
@AllArgsConstructor | 
				
			||||
@NoArgsConstructor | 
				
			||||
@Builder | 
				
			||||
public class DeviceData { | 
				
			||||
    private String station; | 
				
			||||
    private String time; | 
				
			||||
    private List<Kvtq> children = Lists.newArrayList(); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,19 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import com.google.common.collect.Lists; | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.Builder; | 
				
			||||
import lombok.Data; | 
				
			||||
import lombok.NoArgsConstructor; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@Data | 
				
			||||
@AllArgsConstructor | 
				
			||||
@NoArgsConstructor | 
				
			||||
@Builder | 
				
			||||
public class DeviceDataV4 { | 
				
			||||
    private String stationId; | 
				
			||||
    private String time; | 
				
			||||
    private List<KvtqV4> children = Lists.newArrayList(); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,38 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.annotation.IdType; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableId; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableName; | 
				
			||||
import io.swagger.annotations.ApiModelProperty; | 
				
			||||
import lombok.Data; | 
				
			||||
 | 
				
			||||
import java.io.Serializable; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 */ | 
				
			||||
@TableName("hzinfo_fac_device_config") | 
				
			||||
@Data | 
				
			||||
public class DeviceFacConfig implements Serializable { | 
				
			||||
    @ApiModelProperty("id") | 
				
			||||
    @TableId(type = IdType.INPUT) | 
				
			||||
    private String id; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("设备id") | 
				
			||||
    private String deviceCode; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("字段标识") | 
				
			||||
    private String facDeviceId; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("站点Id") | 
				
			||||
    private String stationId; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("站点类型") | 
				
			||||
    private String modelKind; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("sid") | 
				
			||||
    private String sid; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("数据写入方式: 1-闸门,2-天气") | 
				
			||||
    private String writeMethod; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,42 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.annotation.IdType; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableId; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableName; | 
				
			||||
import com.fasterxml.jackson.annotation.JsonFormat; | 
				
			||||
import io.swagger.annotations.ApiModelProperty; | 
				
			||||
import lombok.Data; | 
				
			||||
import org.springframework.format.annotation.DateTimeFormat; | 
				
			||||
 | 
				
			||||
import java.io.Serializable; | 
				
			||||
import java.util.Date; | 
				
			||||
 | 
				
			||||
@TableName("hzinfo_fac_device_attr") | 
				
			||||
@Data | 
				
			||||
public class DeviceField implements Serializable { | 
				
			||||
    @ApiModelProperty("id") | 
				
			||||
    @TableId(type = IdType.INPUT) | 
				
			||||
    private String id; | 
				
			||||
    @ApiModelProperty("设备id") | 
				
			||||
    private String facDeviceId; | 
				
			||||
    @ApiModelProperty("字段标识") | 
				
			||||
    private String signage; | 
				
			||||
    @ApiModelProperty("字段名称") | 
				
			||||
    private String name; | 
				
			||||
    @ApiModelProperty("最大值") | 
				
			||||
    private String projectId; | 
				
			||||
 | 
				
			||||
    @DateTimeFormat( | 
				
			||||
            pattern = "yyyy-MM-dd HH:mm:ss" | 
				
			||||
    ) | 
				
			||||
    @JsonFormat( | 
				
			||||
            pattern = "yyyy-MM-dd HH:mm:ss" | 
				
			||||
    ) | 
				
			||||
    @ApiModelProperty("创建时间") | 
				
			||||
    private Date createTime; | 
				
			||||
 | 
				
			||||
    private Long modelClassifyId; | 
				
			||||
    private String alarmType; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,30 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.annotation.IdType; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableId; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableName; | 
				
			||||
import io.swagger.annotations.ApiModelProperty; | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.Data; | 
				
			||||
 | 
				
			||||
import java.io.Serializable; | 
				
			||||
import java.math.BigDecimal; | 
				
			||||
 | 
				
			||||
@TableName("hzinfo_fac_device_attr_gap") | 
				
			||||
@Data | 
				
			||||
@AllArgsConstructor | 
				
			||||
public class DeviceFieldGap implements Serializable { | 
				
			||||
        @ApiModelProperty("id") | 
				
			||||
        @TableId(type = IdType.INPUT) | 
				
			||||
        private String id; | 
				
			||||
        @ApiModelProperty("设备id") | 
				
			||||
        private String facDeviceId; | 
				
			||||
        @ApiModelProperty("字段标识") | 
				
			||||
        private String signage; | 
				
			||||
        @ApiModelProperty("字段名称") | 
				
			||||
        private String name; | 
				
			||||
        @ApiModelProperty("最大值") | 
				
			||||
        private BigDecimal maxVal; | 
				
			||||
        @ApiModelProperty("最小值") | 
				
			||||
        private BigDecimal minVal; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,33 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.annotation.IdType; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableId; | 
				
			||||
import com.baomidou.mybatisplus.annotation.TableName; | 
				
			||||
import io.swagger.annotations.ApiModelProperty; | 
				
			||||
import lombok.Data; | 
				
			||||
 | 
				
			||||
import java.io.Serializable; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 */ | 
				
			||||
@TableName("hzinfo_fac_device_rain_gap") | 
				
			||||
@Data | 
				
			||||
public class DeviceRainGap implements Serializable { | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("id") | 
				
			||||
    @TableId(type = IdType.INPUT) | 
				
			||||
    private String id; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("设备id") | 
				
			||||
    private String facDeviceId; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("属性标识名称") | 
				
			||||
    private String name; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("属性标识") | 
				
			||||
    private String attribute; | 
				
			||||
 | 
				
			||||
    @ApiModelProperty("字段标识") | 
				
			||||
    private String signage; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,18 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.Builder; | 
				
			||||
import lombok.Data; | 
				
			||||
import lombok.NoArgsConstructor; | 
				
			||||
 | 
				
			||||
@Data | 
				
			||||
@AllArgsConstructor | 
				
			||||
@NoArgsConstructor | 
				
			||||
@Builder | 
				
			||||
public class Kvtq { | 
				
			||||
 | 
				
			||||
    private String k; | 
				
			||||
    private String v; | 
				
			||||
    private String t; | 
				
			||||
    private Integer q; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,18 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.entity; | 
				
			||||
 | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.Builder; | 
				
			||||
import lombok.Data; | 
				
			||||
import lombok.NoArgsConstructor; | 
				
			||||
 | 
				
			||||
@Data | 
				
			||||
@AllArgsConstructor | 
				
			||||
@NoArgsConstructor | 
				
			||||
@Builder | 
				
			||||
public class KvtqV4 { | 
				
			||||
    private String sid; | 
				
			||||
    private String k; | 
				
			||||
    private String v; | 
				
			||||
    private String t; | 
				
			||||
    private Integer q; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,102 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.enums; | 
				
			||||
 | 
				
			||||
import lombok.AllArgsConstructor; | 
				
			||||
import lombok.Getter; | 
				
			||||
import org.springblade.core.tool.api.IResultCode; | 
				
			||||
 | 
				
			||||
import javax.servlet.http.HttpServletResponse; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * 异常码枚举类 | 
				
			||||
 */ | 
				
			||||
@Getter | 
				
			||||
@AllArgsConstructor | 
				
			||||
public enum ExceptionEnum implements IResultCode { | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 操作成功 | 
				
			||||
     */ | 
				
			||||
    SUCCESS(HttpServletResponse.SC_OK, "操作成功"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 业务异常 | 
				
			||||
     */ | 
				
			||||
    FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 请求未授权 | 
				
			||||
     */ | 
				
			||||
    UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 客户端请求未授权 | 
				
			||||
     */ | 
				
			||||
    CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 404 没找到请求 | 
				
			||||
     */ | 
				
			||||
    NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 消息不能读取 | 
				
			||||
     */ | 
				
			||||
    MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 不支持当前请求方法 | 
				
			||||
     */ | 
				
			||||
    METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 不支持当前媒体类型 | 
				
			||||
     */ | 
				
			||||
    MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 请求被拒绝 | 
				
			||||
     */ | 
				
			||||
    REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 服务器异常 | 
				
			||||
     */ | 
				
			||||
    INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 缺少必要的请求参数 | 
				
			||||
     */ | 
				
			||||
    PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 请求参数类型错误 | 
				
			||||
     */ | 
				
			||||
    PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 请求参数绑定错误 | 
				
			||||
     */ | 
				
			||||
    PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 参数校验失败 | 
				
			||||
     */ | 
				
			||||
    PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 模拟数据失败 | 
				
			||||
     */ | 
				
			||||
    SIMULATE_ERROR(400, "模拟数据失败"), | 
				
			||||
 | 
				
			||||
    ; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * code编码 | 
				
			||||
     */ | 
				
			||||
    final int code; | 
				
			||||
    /** | 
				
			||||
     * 中文信息描述 | 
				
			||||
     */ | 
				
			||||
    final String message; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,19 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.mapper; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceFacConfig; | 
				
			||||
import org.apache.ibatis.annotations.Mapper; | 
				
			||||
import org.apache.ibatis.annotations.Param; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 */ | 
				
			||||
@Mapper | 
				
			||||
public interface DeviceFacConfigMapper extends BaseMapper<DeviceFacConfig> { | 
				
			||||
 | 
				
			||||
    List<DeviceFacConfig> queryConfigDevice(@Param("method") String method); | 
				
			||||
 | 
				
			||||
    DeviceFacConfig configByDeviceCode(@Param("deviceCode") String deviceCode); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,13 @@
					 | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
				
			||||
<mapper namespace="com.hnac.hzinfo.simulate.mapper.DeviceFacConfigMapper"> | 
				
			||||
 | 
				
			||||
    <select id="queryConfigDevice" resultType="com.hnac.hzinfo.simulate.entity.DeviceFacConfig"> | 
				
			||||
        SELECT * FROM hzinfo_device_fac_config | 
				
			||||
        WHERE WRITE_METHOD = #{method} | 
				
			||||
    </select> | 
				
			||||
    <select id="configByDeviceCode" resultType="com.hnac.hzinfo.simulate.entity.DeviceFacConfig"> | 
				
			||||
        SELECT * FROM hzinfo_device_fac_config | 
				
			||||
        WHERE DEVICE_CODE = #{deviceCode} | 
				
			||||
    </select> | 
				
			||||
</mapper> | 
				
			||||
@ -0,0 +1,16 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.mapper; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceFieldGap; | 
				
			||||
import org.apache.ibatis.annotations.Mapper; | 
				
			||||
import org.apache.ibatis.annotations.Param; | 
				
			||||
 | 
				
			||||
import java.math.BigDecimal; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@Mapper | 
				
			||||
public interface DeviceFieldGapMapper extends BaseMapper<DeviceFieldGap> { | 
				
			||||
    List<DeviceFieldGap> queryDeviceLimits(@Param("signages") List<String> signages); | 
				
			||||
 | 
				
			||||
    void updateLimitById(@Param("maxValue") BigDecimal maxValue, @Param("minValue") BigDecimal minValue,@Param("id") String id); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,18 @@
					 | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
				
			||||
<mapper namespace="com.hnac.hzinfo.simulate.mapper.DeviceFieldGapMapper"> | 
				
			||||
    <select id="queryDeviceLimits" resultType="com.hnac.hzinfo.simulate.entity.DeviceFieldGap"> | 
				
			||||
        select * from hzinfo_fac_device_attr_gap | 
				
			||||
        where signage in | 
				
			||||
        <foreach collection="signages" item="item" open="(" close=")" separator="," > | 
				
			||||
            #{item} | 
				
			||||
        </foreach> | 
				
			||||
    </select> | 
				
			||||
 | 
				
			||||
    <update id="updateLimitById"> | 
				
			||||
        UPDATE hzinfo_fac_device_attr_gap | 
				
			||||
        SET max_val = #{maxValue}, | 
				
			||||
            min_val = #{minValue} | 
				
			||||
        WHERE id = #{id} | 
				
			||||
    </update> | 
				
			||||
</mapper> | 
				
			||||
@ -0,0 +1,19 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.mapper; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceField; | 
				
			||||
import org.apache.ibatis.annotations.Mapper; | 
				
			||||
import org.apache.ibatis.annotations.Param; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@Mapper | 
				
			||||
public interface DeviceFieldMapper extends BaseMapper<DeviceField> { | 
				
			||||
    int existGapTable(); | 
				
			||||
    int createGapTable(); | 
				
			||||
    List<DeviceField> queryNewInsert(); | 
				
			||||
 | 
				
			||||
    List<DeviceField> queryDeviceFields(@Param("devices") List<String> devices); | 
				
			||||
 | 
				
			||||
    List<DeviceField> querySignages(@Param("facDeviceId") String facDeviceId); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,34 @@
					 | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
				
			||||
<mapper namespace="com.hnac.hzinfo.simulate.mapper.DeviceFieldMapper"> | 
				
			||||
    <select id="existGapTable" resultType="int"> | 
				
			||||
        select count(*) from information_schema.TABLES where table_name = 'hzinfo_device_field_gap' | 
				
			||||
    </select> | 
				
			||||
    <update id="createGapTable"> | 
				
			||||
        CREATE TABLE hzinfo_device_field_gap ( | 
				
			||||
          id varchar(64) COLLATE utf8mb4_bin NOT NULL COMMENT '字段类型', | 
				
			||||
          fac_device_id varchar(50) COLLATE utf8mb4_bin NOT NULL COMMENT '设备实例id', | 
				
			||||
          signage varchar(25) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '字段标识', | 
				
			||||
          name varchar(100) COLLATE utf8mb4_bin NOT NULL COMMENT '字段名称', | 
				
			||||
          max_val decimal(9,3) DEFAULT NULL, | 
				
			||||
          min_val decimal(9,3) DEFAULT NULL, | 
				
			||||
          PRIMARY KEY (id) | 
				
			||||
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='设备字段' | 
				
			||||
 | 
				
			||||
    </update> | 
				
			||||
 | 
				
			||||
    <select id="queryNewInsert" resultType="com.hnac.hzinfo.simulate.entity.DeviceField"> | 
				
			||||
        select * from hzinfo_fac_device_attr field where NOT EXISTS (select id from hzinfo_fac_device_attr_gap gap where field.id=gap.id) | 
				
			||||
    </select> | 
				
			||||
    <select id="queryDeviceFields" resultType="com.hnac.hzinfo.simulate.entity.DeviceField"> | 
				
			||||
        select * from hzinfo_fac_device_attr | 
				
			||||
        where  fac_device_id in | 
				
			||||
        <foreach collection="devices" item="item" open="(" close=")" separator="," > | 
				
			||||
            #{item} | 
				
			||||
        </foreach> | 
				
			||||
    </select> | 
				
			||||
    <select id="querySignages" resultType="com.hnac.hzinfo.simulate.entity.DeviceField"> | 
				
			||||
        SELECT * FROM hzinfo_fac_device_attr | 
				
			||||
        WHERE FAC_DEVICE_ID = #{facDeviceId} | 
				
			||||
    </select> | 
				
			||||
</mapper> | 
				
			||||
@ -0,0 +1,18 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.mapper; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.Device; | 
				
			||||
import org.apache.ibatis.annotations.Mapper; | 
				
			||||
import org.apache.ibatis.annotations.Param; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
import java.util.Map; | 
				
			||||
 | 
				
			||||
@Mapper | 
				
			||||
public interface DeviceMapper extends BaseMapper<Device> { | 
				
			||||
    String getSid(@Param("stationId") String stationId); | 
				
			||||
 | 
				
			||||
    List<String> selectStcd(); | 
				
			||||
 | 
				
			||||
    int insertData(@Param("param") Map<String, Object> param); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,15 @@
					 | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
				
			||||
<mapper namespace="com.hnac.hzinfo.simulate.mapper.DeviceMapper"> | 
				
			||||
    <select id="getSid" resultType="java.lang.String"> | 
				
			||||
        select DISTINCT sid from hzinfo_fac_device where project_id=#{stationId} and sid is not null limit 1 | 
				
			||||
    </select> | 
				
			||||
 | 
				
			||||
    <select id="selectStcd" resultType="java.lang.String"> | 
				
			||||
        select rscd from blade_ris.st_rsr_bsin where is_deleted=0 | 
				
			||||
    </select> | 
				
			||||
 | 
				
			||||
    <insert id="insertData" keyProperty="id" useGeneratedKeys="true"> | 
				
			||||
        insert into  blade_ris.reservoir_data(STCD,DT,INFLOW) values (#{param.stcd},#{param.dt},#{param.inflow}) | 
				
			||||
    </insert> | 
				
			||||
</mapper> | 
				
			||||
@ -0,0 +1,17 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.mapper; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceRainGap; | 
				
			||||
import org.apache.ibatis.annotations.Mapper; | 
				
			||||
import org.apache.ibatis.annotations.Param; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 */ | 
				
			||||
@Mapper | 
				
			||||
public interface DeviceRainGapMapper extends BaseMapper<DeviceRainGap> { | 
				
			||||
 | 
				
			||||
    List<DeviceRainGap> RainGapByFacDeviceId(@Param("facDeviceId") String facDeviceId); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,9 @@
					 | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
				
			||||
<mapper namespace="com.hnac.hzinfo.simulate.mapper.DeviceRainGapMapper"> | 
				
			||||
 | 
				
			||||
    <select id="RainGapByFacDeviceId" resultType="com.hnac.hzinfo.simulate.entity.DeviceRainGap"> | 
				
			||||
        SELECT * FROM hzinfo_fac_device_rain_gap | 
				
			||||
        WHERE FAC_DEVICE_ID = #{facDeviceId} | 
				
			||||
    </select> | 
				
			||||
</mapper> | 
				
			||||
@ -0,0 +1,113 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.scheduled; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceField; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceFieldGap; | 
				
			||||
import com.hnac.hzinfo.simulate.service.DeviceFieldGapService; | 
				
			||||
import com.hnac.hzinfo.simulate.service.DeviceFieldService; | 
				
			||||
import com.hnac.hzinfo.simulate.service.ISimulateService; | 
				
			||||
import com.xxl.job.core.biz.model.ReturnT; | 
				
			||||
import com.xxl.job.core.handler.annotation.XxlJob; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
import org.apache.commons.lang3.StringUtils; | 
				
			||||
import org.springblade.xxljob.annotation.XxlRegister; | 
				
			||||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			||||
import org.springframework.beans.factory.annotation.Value; | 
				
			||||
import org.springframework.stereotype.Component; | 
				
			||||
 | 
				
			||||
import java.math.BigDecimal; | 
				
			||||
import java.util.List; | 
				
			||||
import java.util.stream.Collectors; | 
				
			||||
 | 
				
			||||
@Slf4j | 
				
			||||
@Component | 
				
			||||
public class SimulateJob { | 
				
			||||
 | 
				
			||||
    @Value("${simulate.stationIds}") | 
				
			||||
    String stationId; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    ISimulateService simulateService; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    @XxlJob("v3Simulate") | 
				
			||||
    @XxlRegister(cron = "0 0/1 * * * ?", jobDesc = "模拟V3数据 传入stationId,多个用逗号隔开") | 
				
			||||
    public ReturnT<String> v3Simulate(String param) { | 
				
			||||
        if (StringUtils.isNotBlank(param)) { | 
				
			||||
            String[] stationIds = param.split(","); | 
				
			||||
            simulateService.simulationMultipleV3(stationIds); | 
				
			||||
        } else { | 
				
			||||
            String[] stationIds = stationId.split(","); | 
				
			||||
            simulateService.simulationMultipleV3(stationIds); | 
				
			||||
        } | 
				
			||||
        return ReturnT.SUCCESS; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @XxlJob("v4Simulate") | 
				
			||||
    @XxlRegister(cron = "0 0/1 * * * ?", jobDesc = "模拟V4数据 传入stationId,多个用逗号隔开", triggerStatus = 1) | 
				
			||||
    public ReturnT<String> v4Simulate(String param) { | 
				
			||||
        if (StringUtils.isNotBlank(param)) { | 
				
			||||
            String[] stationIds = param.split(","); | 
				
			||||
            simulateService.simulationMultipleV4(stationIds); | 
				
			||||
        } else { | 
				
			||||
            String[] stationIds = stationId.split(","); | 
				
			||||
            simulateService.simulationMultipleV4(stationIds); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        return ReturnT.SUCCESS; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @XxlJob("simulationMultipleInFlow") | 
				
			||||
    @XxlRegister(cron = "0 0/1 * * * ?", jobDesc = "模拟入库流量") | 
				
			||||
    public ReturnT<String> simulationMultipleInFlow(String param) { | 
				
			||||
        simulateService.simulationMultipleInFlow(); | 
				
			||||
        return ReturnT.SUCCESS; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @XxlJob("simulationStandard") | 
				
			||||
    @XxlRegister(cron = "0 0/1 * * * ?", jobDesc = "模拟标准设备 传入stationId") | 
				
			||||
    public ReturnT<String> simulationStandard(String param) { | 
				
			||||
        String[] ids = StringUtils.isNotBlank(param) ? param.split(",") : stationId.split(","); | 
				
			||||
        for (String id : ids) { | 
				
			||||
            simulateService.simulationStandard(id); | 
				
			||||
        } | 
				
			||||
        return ReturnT.SUCCESS; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    DeviceFieldService deviceFieldService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    DeviceFieldGapService deviceFieldGapService; | 
				
			||||
 | 
				
			||||
    //第一次同步设备属性 执行一次就行
 | 
				
			||||
    @XxlJob("syncOneGap") | 
				
			||||
    public ReturnT<String> syncOneGap(String param) { | 
				
			||||
        //存在表
 | 
				
			||||
        int count = deviceFieldService.existGapTable(); | 
				
			||||
        if (count <= 0) {//建表
 | 
				
			||||
            deviceFieldService.createGapTable(); | 
				
			||||
        } | 
				
			||||
        //同步
 | 
				
			||||
        List<DeviceField> list = deviceFieldService.list(); | 
				
			||||
        List<DeviceFieldGap> gaps = list.stream().map(result -> new DeviceFieldGap(result.getId(), result.getFacDeviceId(), | 
				
			||||
                        result.getSignage(), result.getName(), BigDecimal.ZERO, BigDecimal.ZERO)) | 
				
			||||
                .collect(Collectors.toList()); | 
				
			||||
        deviceFieldGapService.saveOrUpdateBatch(gaps); | 
				
			||||
        return ReturnT.SUCCESS; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    //第二次同步设备属性 执行一次就行
 | 
				
			||||
    @XxlJob("syncTwoGap") | 
				
			||||
    public ReturnT<String> syncTwoGap(String param) { | 
				
			||||
        //同步
 | 
				
			||||
        List<DeviceField> list = deviceFieldService.queryNewInsert(); | 
				
			||||
        if (list != null && !list.isEmpty()) { | 
				
			||||
            List<DeviceFieldGap> gaps = list.stream().map(result -> new DeviceFieldGap(result.getId(), result.getFacDeviceId(), | 
				
			||||
                            result.getSignage(), result.getName(), BigDecimal.ZERO, BigDecimal.ZERO)) | 
				
			||||
                    .collect(Collectors.toList()); | 
				
			||||
            deviceFieldGapService.saveBatch(gaps); | 
				
			||||
        } | 
				
			||||
        return ReturnT.SUCCESS; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,41 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.scheduled; | 
				
			||||
 | 
				
			||||
import com.hnac.hzinfo.simulate.service.WriteRealDataService; | 
				
			||||
import com.xxl.job.core.biz.model.ReturnT; | 
				
			||||
import com.xxl.job.core.handler.annotation.XxlJob; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
import org.springblade.core.tool.utils.DateUtil; | 
				
			||||
import org.springblade.core.tool.utils.Func; | 
				
			||||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			||||
import org.springframework.stereotype.Component; | 
				
			||||
 | 
				
			||||
import java.util.Date; | 
				
			||||
 | 
				
			||||
import static com.hnac.hzinfo.simulate.constants.WriteRealDataConstant.WRITE_REAL_GATE_DATA; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 * @describe 实时数据写入定时任务 | 
				
			||||
 */ | 
				
			||||
@Slf4j | 
				
			||||
@Component | 
				
			||||
public class WriteRealDataTask { | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    private WriteRealDataService writeRealDataService; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 设备模型信息 | 
				
			||||
     */ | 
				
			||||
    @XxlJob(WRITE_REAL_GATE_DATA) | 
				
			||||
    //@Scheduled(cron = "0/40 * * * * ? ")
 | 
				
			||||
    public ReturnT<String> writeRealGateData(String param) { | 
				
			||||
        if (Func.isBlank(param)) { | 
				
			||||
            param = DateUtil.format(new Date(), "yyyy-MM"); | 
				
			||||
        } | 
				
			||||
        writeRealDataService.writeRealGateData(param); | 
				
			||||
        return new ReturnT<>("SUCCESS"); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,11 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.service; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceFieldGap; | 
				
			||||
import com.hnac.hzinfo.simulate.mapper.DeviceFieldGapMapper; | 
				
			||||
import org.springframework.stereotype.Service; | 
				
			||||
 | 
				
			||||
@Service | 
				
			||||
public class DeviceFieldGapService extends ServiceImpl<DeviceFieldGapMapper, DeviceFieldGap> { | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,24 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.service; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DeviceField; | 
				
			||||
import com.hnac.hzinfo.simulate.mapper.DeviceFieldMapper; | 
				
			||||
import org.springframework.stereotype.Service; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@Service | 
				
			||||
public class DeviceFieldService extends ServiceImpl<DeviceFieldMapper, DeviceField> { | 
				
			||||
 | 
				
			||||
    public int existGapTable(){ | 
				
			||||
        return this.baseMapper.existGapTable(); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public int createGapTable(){ | 
				
			||||
        return this.baseMapper.createGapTable(); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<DeviceField> queryNewInsert(){ | 
				
			||||
        return this.baseMapper.queryNewInsert(); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,24 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.service; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.Device; | 
				
			||||
import com.hnac.hzinfo.simulate.mapper.DeviceMapper; | 
				
			||||
import org.springframework.stereotype.Service; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
import java.util.Map; | 
				
			||||
 | 
				
			||||
@Service | 
				
			||||
public class DeviceService extends ServiceImpl<DeviceMapper, Device> { | 
				
			||||
    public String getSid(String stationId) { | 
				
			||||
        return this.baseMapper.getSid(stationId); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<String> selectStcd() { | 
				
			||||
        return this.baseMapper.selectStcd(); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public int insertData(Map<String, Object> param) { | 
				
			||||
        return this.baseMapper.insertData(param); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,18 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.service; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import com.hnac.hzinfo.simulate.vo.GenerateFactoryDeviceVo; | 
				
			||||
 | 
				
			||||
public interface ISimulateService { | 
				
			||||
    void simulationMultipleV3(String[] stationIds); | 
				
			||||
 | 
				
			||||
    void simulationMultipleV4(String[] stationIds); | 
				
			||||
 | 
				
			||||
    void simulationStandard(String projectId); | 
				
			||||
 | 
				
			||||
    void stopStart(); | 
				
			||||
 | 
				
			||||
    void simulationMultipleInFlow(); | 
				
			||||
 | 
				
			||||
    Boolean generateFactoryData(GenerateFactoryDeviceVo deviceInfo); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,279 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.service; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
				
			||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
				
			||||
import com.google.common.collect.Lists; | 
				
			||||
import com.google.common.collect.Maps; | 
				
			||||
import com.hnac.hzinfo.simulate.util.DataConstants; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
import org.springblade.core.tool.jackson.JsonUtil; | 
				
			||||
import org.springblade.core.tool.utils.DateTimeUtil; | 
				
			||||
import org.springblade.core.tool.utils.ThreadUtil; | 
				
			||||
import org.springblade.mqtt.producer.IMqttSender; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.*; | 
				
			||||
import com.hnac.hzinfo.simulate.util.TopicConstant; | 
				
			||||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			||||
import org.springframework.scheduling.annotation.Async; | 
				
			||||
import org.springframework.stereotype.Service; | 
				
			||||
 | 
				
			||||
import java.math.BigDecimal; | 
				
			||||
import java.text.SimpleDateFormat; | 
				
			||||
import java.time.LocalDateTime; | 
				
			||||
import java.util.*; | 
				
			||||
import java.util.stream.Collectors; | 
				
			||||
 | 
				
			||||
@Service | 
				
			||||
@Slf4j | 
				
			||||
public class SimulationService { | 
				
			||||
    @Autowired | 
				
			||||
    IMqttSender mqttSender; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    DeviceService deviceService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    DeviceFieldService deviceFieldService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
     DeviceFieldGapService  deviceFieldGapService; | 
				
			||||
 | 
				
			||||
    public List<Device> getDeviceListByStationId(String projectId){ | 
				
			||||
        LambdaQueryWrapper<Device> lambdaQueryWrapper=new LambdaQueryWrapper(); | 
				
			||||
        lambdaQueryWrapper.eq(Device::getProjectId,projectId); | 
				
			||||
        List<Device> list = deviceService.list(lambdaQueryWrapper); | 
				
			||||
        return list; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    String getSid(String stationId){ | 
				
			||||
        return deviceService.getSid(stationId); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    //模拟启停标识
 | 
				
			||||
    private volatile boolean flag=true; | 
				
			||||
 | 
				
			||||
    public void stopStart(){ | 
				
			||||
        flag = !flag; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Async | 
				
			||||
    public void simulationMultiple(String stationId, Long sleepTime) { | 
				
			||||
 | 
				
			||||
        List<Device> list = getDeviceListByStationId(stationId); | 
				
			||||
        //查询所有属性
 | 
				
			||||
        List<DeviceField> fieldList = deviceFieldService.list(); | 
				
			||||
        List<DeviceFieldGap> gapList = deviceFieldGapService.list(); | 
				
			||||
 | 
				
			||||
        log.info("本站{}有{}个设备实例,每{}毫秒发送{}条数据", stationId, list.size(), sleepTime, list.size()); | 
				
			||||
        while (true) { | 
				
			||||
            if (flag) {//启动或关闭模拟
 | 
				
			||||
                for (Device device : list) { | 
				
			||||
                    Map<String, DeviceData> map = simulation(stationId, device,fieldList,gapList); | 
				
			||||
//                    log.info("map data: "+ JsonUtil.toJson(map));
 | 
				
			||||
                    if (map.get("yc") != null && map.get("yc").getChildren().size() > 0) { | 
				
			||||
                        log.info("模拟推送遥测,主题:topic_hzinfo_props:{}", JsonUtil.toJson(map.get("yc"))); | 
				
			||||
                        mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_PROPS, JsonUtil.toJson(map.get("yc"))); | 
				
			||||
                    } | 
				
			||||
//                if (map.get("dd") != null && map.get("dd").getChildren().size() > 0) {
 | 
				
			||||
//                    mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_DD, JsonUtil.toJson(map.get("dd")));
 | 
				
			||||
//                }
 | 
				
			||||
                    if (map.get("yx") != null && map.get("yx").getChildren().size() > 0) { | 
				
			||||
                        mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_YX, JsonUtil.toJson(map.get("yx"))); | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
                //最小10毫秒
 | 
				
			||||
                if (sleepTime == null || sleepTime == 0) { | 
				
			||||
                    sleepTime = 10L; | 
				
			||||
                } | 
				
			||||
                ThreadUtil.sleep(sleepTime); | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
//    @Async
 | 
				
			||||
//    public void simulationMultipleInFlow(){
 | 
				
			||||
//        List<String> list=deviceService.selectStcd();
 | 
				
			||||
//        while (true) {
 | 
				
			||||
//            List<Map<String,Object>> datas = simulationFlow(list);
 | 
				
			||||
//            for(Map<String,Object> param:datas){
 | 
				
			||||
//                deviceService.insertData(param);
 | 
				
			||||
//            }
 | 
				
			||||
//            ThreadUtil.sleep(3600000);
 | 
				
			||||
//        }
 | 
				
			||||
//    }
 | 
				
			||||
 | 
				
			||||
    private List<Map<String,Object>> simulationFlow(List<String> list){ | 
				
			||||
        List<Map<String,Object>> datas =new ArrayList<>(); | 
				
			||||
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
				
			||||
        String dt=sdf.format(new Date()); | 
				
			||||
        for(String stcd:list){ | 
				
			||||
            Map<String,Object> data=new HashMap<>(); | 
				
			||||
            String value = getRandomRedPacketBetweenMinAndMax(new BigDecimal("0"), new BigDecimal("20")).toString(); | 
				
			||||
            data.put("stcd",stcd); | 
				
			||||
            data.put("dt",dt); | 
				
			||||
            data.put("inflow",value); | 
				
			||||
            datas.add(data); | 
				
			||||
        } | 
				
			||||
        return datas; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    @Async | 
				
			||||
    public void simulationMultipleV4(String stationId, Long sleepTime){ | 
				
			||||
        String sid=getSid(stationId); | 
				
			||||
        List<Device> list = getDeviceListByStationId(stationId); | 
				
			||||
        //查询所有属性
 | 
				
			||||
        List<DeviceField> fieldList = deviceFieldService.list(); | 
				
			||||
        List<DeviceFieldGap> gapList = deviceFieldGapService.list(); | 
				
			||||
 | 
				
			||||
        log.info("本站{}有{}个设备实例,每{}毫秒发送{}条数据", stationId, list.size(), sleepTime, list.size()); | 
				
			||||
        while (true) { | 
				
			||||
            if (flag) {//启动或关闭模拟
 | 
				
			||||
                for (Device device : list) { | 
				
			||||
                    Map<String, DeviceDataV4> map = simulationV4(stationId,sid, device,fieldList,gapList); | 
				
			||||
                    //log.info("map data: "+ JsonUtil.toJson(map));
 | 
				
			||||
                    if (map.get("yc") != null && map.get("yc").getChildren().size() > 0) { | 
				
			||||
                        mqttSender.sendToMqtt("hzinfo_v4_yc", JsonUtil.toJson(map.get("yc"))); | 
				
			||||
                    } | 
				
			||||
//                if (map.get("dd") != null && map.get("dd").getChildren().size() > 0) {
 | 
				
			||||
//                    mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_DD, JsonUtil.toJson(map.get("dd")));
 | 
				
			||||
//                }
 | 
				
			||||
                    if (map.get("yx") != null && map.get("yx").getChildren().size() > 0) { | 
				
			||||
                        mqttSender.sendToMqtt("hzinfo_v4_yx", JsonUtil.toJson(map.get("yx"))); | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
                //最小10毫秒
 | 
				
			||||
                if (sleepTime == null || sleepTime == 0) { | 
				
			||||
                    sleepTime = 10L; | 
				
			||||
                } | 
				
			||||
                ThreadUtil.sleep(sleepTime); | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public static BigDecimal getRandomRedPacketBetweenMinAndMax(BigDecimal min, BigDecimal max){ | 
				
			||||
        float minF = min.floatValue(); | 
				
			||||
        float maxF = max.floatValue(); | 
				
			||||
        //生成随机数
 | 
				
			||||
        BigDecimal db = new BigDecimal(Math.random() * (maxF - minF) + minF); | 
				
			||||
        //返回保留两位小数的随机数。不进行四舍五入
 | 
				
			||||
        return db.setScale(3,BigDecimal.ROUND_DOWN); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public static int getIntBetweenMinAndMax(int min, int max){ | 
				
			||||
        //生成随机数
 | 
				
			||||
        int randomNum = min + (int)(Math.random() * ((max - min) + 1)); | 
				
			||||
        //返回保留两位小数的随机数。不进行四舍五入
 | 
				
			||||
        return randomNum; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 模拟一条数据 | 
				
			||||
     */ | 
				
			||||
    private Map<String, DeviceData> simulation(String stationId, Device device,List<DeviceField> fieldListAll,List<DeviceFieldGap> gapListAll) { | 
				
			||||
//        List<DeviceField> fieldList = getListByDeviceId(device.getId());
 | 
				
			||||
//        List<DeviceFieldGap> gapList = getListByDeviceGapId(device.getId());
 | 
				
			||||
        List<DeviceField> fieldList =fieldListAll.stream().filter(e->e.getFacDeviceId().equals(device.getId())).collect(Collectors.toList()); | 
				
			||||
        List<DeviceFieldGap> gapList =gapListAll.stream().filter(e->e.getFacDeviceId().equals(device.getId())).collect(Collectors.toList()); | 
				
			||||
//        log.info("fieldList data: "+ JsonUtil.toJson(fieldList));
 | 
				
			||||
//        log.info("gapList data: "+ JsonUtil.toJson(gapList));
 | 
				
			||||
        List<Kvtq> ycList = Lists.newArrayList(); | 
				
			||||
        List<Kvtq> yxList = Lists.newArrayList(); | 
				
			||||
        //List<Kvtq> ddList = Lists.newArrayList();
 | 
				
			||||
        for (DeviceField field : fieldList) { | 
				
			||||
            Optional<DeviceFieldGap> gapOpt=gapList.stream().filter(e->e.getSignage().equals(field.getSignage())).findFirst(); | 
				
			||||
 | 
				
			||||
            if (DataConstants.DeviceDataType.YC.ordinal()== field.getModelClassifyId().intValue()) { | 
				
			||||
                if(gapOpt!=null) { | 
				
			||||
                    DeviceFieldGap gap=gapOpt.get(); | 
				
			||||
                    String value = getRandomRedPacketBetweenMinAndMax(gap.getMinVal(), gap.getMaxVal()).toString(); | 
				
			||||
                    Kvtq kvtq = Kvtq.builder().k(field.getSignage()).v(value).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build(); | 
				
			||||
                    ycList.add(kvtq); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
//            if (DataConstants.DeviceDataType.DD.name().equals(field.getType())) {
 | 
				
			||||
//                String value = Func.random(1, RandomType.INT) + "." + Func.random(1, RandomType.INT);
 | 
				
			||||
//                Kvtq kvtq = Kvtq.builder().k(field.getId()).v(value).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build();
 | 
				
			||||
//                ddList.add(kvtq);
 | 
				
			||||
//            }
 | 
				
			||||
            if (DataConstants.DeviceDataType.YX.ordinal()== field.getModelClassifyId().intValue()) { | 
				
			||||
                if(gapOpt!=null) { | 
				
			||||
                    DeviceFieldGap gap=gapOpt.get(); | 
				
			||||
                    int value = getIntBetweenMinAndMax(gap.getMinVal().intValue(), gap.getMaxVal().intValue()); | 
				
			||||
                    Kvtq kvtq = Kvtq.builder().k(field.getSignage()).v(String.valueOf(value)).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build(); | 
				
			||||
                    yxList.add(kvtq); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        Map<String, DeviceData> map = Maps.newHashMap(); | 
				
			||||
        if (ycList.size() > 0) { | 
				
			||||
            map.put("yc", DeviceData.builder().station(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ycList).build()); | 
				
			||||
        } | 
				
			||||
//        if (ddList.size() > 0) {
 | 
				
			||||
//            map.put("dd", DeviceData.builder().station(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ddList).build());
 | 
				
			||||
//        }
 | 
				
			||||
        if (yxList.size() > 0) { | 
				
			||||
            map.put("yx", DeviceData.builder().station(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(yxList).build()); | 
				
			||||
        } | 
				
			||||
        return map; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    private Map<String, DeviceDataV4> simulationV4(String stationId,String sid, Device device,List<DeviceField> fieldListAll,List<DeviceFieldGap> gapListAll) { | 
				
			||||
 | 
				
			||||
//        List<DeviceField> fieldList = getListByDeviceId(device.getId());
 | 
				
			||||
//        List<DeviceFieldGap> gapList = getListByDeviceGapId(device.getId());
 | 
				
			||||
        List<DeviceField> fieldList =fieldListAll.stream().filter(e->e.getFacDeviceId().equals(device.getId())).collect(Collectors.toList()); | 
				
			||||
        List<DeviceFieldGap> gapList =gapListAll.stream().filter(e->e.getFacDeviceId().equals(device.getId())).collect(Collectors.toList()); | 
				
			||||
//        log.info("fieldList data: "+ JsonUtil.toJson(fieldList));
 | 
				
			||||
//        log.info("gapList data: "+ JsonUtil.toJson(gapList));
 | 
				
			||||
        List<KvtqV4> ycList = Lists.newArrayList(); | 
				
			||||
        List<KvtqV4> yxList = Lists.newArrayList(); | 
				
			||||
        //List<Kvtq> ddList = Lists.newArrayList();
 | 
				
			||||
        for (DeviceField field : fieldList) { | 
				
			||||
            Optional<DeviceFieldGap> gapOpt=gapList.stream().filter(e->e.getSignage().equals(field.getSignage())).findFirst(); | 
				
			||||
 | 
				
			||||
            if (DataConstants.DeviceDataType.YC.ordinal()== field.getModelClassifyId().intValue()) { | 
				
			||||
                if(gapOpt!=null) { | 
				
			||||
                    DeviceFieldGap gap=gapOpt.get(); | 
				
			||||
                    String value = getRandomRedPacketBetweenMinAndMax(gap.getMinVal(), gap.getMaxVal()).toString(); | 
				
			||||
                    KvtqV4 kvtq = KvtqV4.builder().sid(sid).k(field.getSignage()).v(value).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build(); | 
				
			||||
                    ycList.add(kvtq); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
//            if (DataConstants.DeviceDataType.DD.name().equals(field.getType())) {
 | 
				
			||||
//                String value = Func.random(1, RandomType.INT) + "." + Func.random(1, RandomType.INT);
 | 
				
			||||
//                Kvtq kvtq = Kvtq.builder().k(field.getId()).v(value).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build();
 | 
				
			||||
//                ddList.add(kvtq);
 | 
				
			||||
//            }
 | 
				
			||||
            if (DataConstants.DeviceDataType.YX.ordinal()== field.getModelClassifyId().intValue()) { | 
				
			||||
                if(gapOpt!=null) { | 
				
			||||
                    DeviceFieldGap gap=gapOpt.get(); | 
				
			||||
                    int value = getIntBetweenMinAndMax(gap.getMinVal().intValue(), gap.getMaxVal().intValue()); | 
				
			||||
                    KvtqV4 kvtq = KvtqV4.builder().sid(sid).k(field.getSignage()).v(String.valueOf(value)).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build(); | 
				
			||||
                    yxList.add(kvtq); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        Map<String, DeviceDataV4> map = Maps.newHashMap(); | 
				
			||||
        if (ycList.size() > 0) { | 
				
			||||
            map.put("yc", DeviceDataV4.builder().stationId(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ycList).build()); | 
				
			||||
        } | 
				
			||||
//        if (ddList.size() > 0) {
 | 
				
			||||
//            map.put("dd", DeviceData.builder().station(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ddList).build());
 | 
				
			||||
//        }
 | 
				
			||||
        if (yxList.size() > 0) { | 
				
			||||
            map.put("yx", DeviceDataV4.builder().stationId(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(yxList).build()); | 
				
			||||
        } | 
				
			||||
        return map; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private List<DeviceField> getListByDeviceId(String deviceId) { | 
				
			||||
        return deviceFieldService.list(Wrappers.<DeviceField>lambdaQuery().ne(DeviceField::getModelClassifyId, DataConstants.DeviceDataType.SOE.name()).eq(DeviceField::getFacDeviceId, deviceId)); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private List<DeviceFieldGap> getListByDeviceGapId(String deviceId){ | 
				
			||||
        return deviceFieldGapService.list(Wrappers.<DeviceFieldGap>lambdaQuery().eq(DeviceFieldGap::getFacDeviceId, deviceId)); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,12 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.service; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 */ | 
				
			||||
public interface WriteRealDataService { | 
				
			||||
 | 
				
			||||
    void writeRealGateData(String param); | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    Boolean isOpen(String deviceCode, Long isOpen); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,276 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.service.impl; | 
				
			||||
 | 
				
			||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
				
			||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
				
			||||
import com.google.common.collect.Lists; | 
				
			||||
import com.google.common.collect.Maps; | 
				
			||||
import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; | 
				
			||||
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO; | 
				
			||||
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceVO; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.*; | 
				
			||||
import com.hnac.hzinfo.simulate.service.DeviceFieldGapService; | 
				
			||||
import com.hnac.hzinfo.simulate.service.DeviceFieldService; | 
				
			||||
import com.hnac.hzinfo.simulate.service.DeviceService; | 
				
			||||
import com.hnac.hzinfo.simulate.service.ISimulateService; | 
				
			||||
import com.hnac.hzinfo.simulate.util.DataConstants; | 
				
			||||
import com.hnac.hzinfo.simulate.util.TopicConstant; | 
				
			||||
import com.hnac.hzinfo.simulate.vo.GenerateFactoryDeviceVo; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
import org.apache.commons.lang.StringUtils; | 
				
			||||
import org.springblade.core.tool.api.R; | 
				
			||||
import org.springblade.core.tool.jackson.JsonUtil; | 
				
			||||
import org.springblade.core.tool.utils.DateTimeUtil; | 
				
			||||
import org.springblade.core.tool.utils.ThreadUtil; | 
				
			||||
import org.springblade.mqtt.producer.IMqttSender; | 
				
			||||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			||||
import org.springframework.scheduling.annotation.Async; | 
				
			||||
import org.springframework.stereotype.Service; | 
				
			||||
 | 
				
			||||
import java.math.BigDecimal; | 
				
			||||
import java.text.SimpleDateFormat; | 
				
			||||
import java.time.LocalDateTime; | 
				
			||||
import java.time.ZoneId; | 
				
			||||
import java.util.*; | 
				
			||||
import java.util.stream.Collectors; | 
				
			||||
 | 
				
			||||
@Service | 
				
			||||
@Slf4j | 
				
			||||
public class SimulateServiceImpl implements ISimulateService { | 
				
			||||
 | 
				
			||||
    //模拟启停标识
 | 
				
			||||
    private volatile boolean flag = true; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    IMqttSender mqttSender; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    DeviceService deviceService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    DeviceFieldService deviceFieldService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    DeviceFieldGapService deviceFieldGapService; | 
				
			||||
 | 
				
			||||
    @Autowired | 
				
			||||
    DeviceClient deviceClient; | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    @Async | 
				
			||||
    public void simulationStandard(String projectId) { | 
				
			||||
        R<List<DeviceInstanceVO>> r = deviceClient.getStandardOnlineDeviceInstance(projectId); | 
				
			||||
        List<DeviceInstanceVO> vos = r.getData(); | 
				
			||||
        if (vos == null || vos.isEmpty()) { | 
				
			||||
            return; | 
				
			||||
        } | 
				
			||||
        for (DeviceInstanceVO vo : vos) { | 
				
			||||
            String deviceCode = vo.getCode(); | 
				
			||||
            R<List<DeviceInstanceAttrVO>> listR = deviceClient.getOnlineAttr(deviceCode); | 
				
			||||
            List<DeviceInstanceAttrVO> attrVOS = listR.getData(); | 
				
			||||
            Map<String, String> map = new HashMap<>(); | 
				
			||||
            for (DeviceInstanceAttrVO attrVO : attrVOS) { | 
				
			||||
                if (StringUtils.isBlank(attrVO.getSignage())) { | 
				
			||||
                    continue; | 
				
			||||
                } | 
				
			||||
                String value = getRandomRedPacketBetweenMinAndMax(new BigDecimal("0"), new BigDecimal("20")).toString(); | 
				
			||||
                map.put(attrVO.getSignage(), value); | 
				
			||||
            } | 
				
			||||
            LocalDateTime now = LocalDateTime.now(); | 
				
			||||
            map.put("ts", "" + now.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); | 
				
			||||
            mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_DATA + "/" + deviceCode, JsonUtil.toJson(map)); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    public void stopStart() { | 
				
			||||
        flag = !flag; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    @Async | 
				
			||||
    public void simulationMultipleInFlow() { | 
				
			||||
        List<String> list = deviceService.selectStcd(); | 
				
			||||
        while (true) { | 
				
			||||
            List<Map<String, Object>> datas = simulationFlow(list); | 
				
			||||
            for (Map<String, Object> param : datas) { | 
				
			||||
                deviceService.insertData(param); | 
				
			||||
            } | 
				
			||||
            ThreadUtil.sleep(3600000); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    public Boolean generateFactoryData(GenerateFactoryDeviceVo deviceInfo) { | 
				
			||||
        Device device = deviceService.getOne(Wrappers.lambdaQuery(Device.class).eq(Device::getId, deviceInfo.getDeviceId())); | 
				
			||||
        return Boolean.TRUE; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    private List<Map<String, Object>> simulationFlow(List<String> list) { | 
				
			||||
        List<Map<String, Object>> datas = new ArrayList<>(); | 
				
			||||
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
				
			||||
        String dt = sdf.format(new Date()); | 
				
			||||
        for (String stcd : list) { | 
				
			||||
            Map<String, Object> data = new HashMap<>(); | 
				
			||||
            String value = getRandomRedPacketBetweenMinAndMax(new BigDecimal("0"), new BigDecimal("20")).toString(); | 
				
			||||
            data.put("stcd", stcd); | 
				
			||||
            data.put("dt", dt); | 
				
			||||
            data.put("inflow", value); | 
				
			||||
            datas.add(data); | 
				
			||||
        } | 
				
			||||
        return datas; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    @Async | 
				
			||||
    public void simulationMultipleV3(String[] stationIds) { | 
				
			||||
        for (String stationId : stationIds) { | 
				
			||||
            List<Device> list = getDeviceListByStationId(stationId); | 
				
			||||
            //查询所有属性
 | 
				
			||||
            List<DeviceField> fieldList = deviceFieldService.list(); | 
				
			||||
            List<DeviceFieldGap> gapList = deviceFieldGapService.list(); | 
				
			||||
 | 
				
			||||
            log.info("本站{}有{}个设备实例,发送{}条数据", stationId, list.size(), list.size()); | 
				
			||||
 | 
				
			||||
            for (Device device : list) { | 
				
			||||
                Map<String, DeviceData> map = simulationV3(stationId, device, fieldList, gapList); | 
				
			||||
                if (map.get("yc") != null && !map.get("yc").getChildren().isEmpty()) { | 
				
			||||
                    mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_PROPS, JsonUtil.toJson(map.get("yc"))); | 
				
			||||
                } | 
				
			||||
                if (map.get("yx") != null && !map.get("yx").getChildren().isEmpty()) { | 
				
			||||
                    mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_YX, JsonUtil.toJson(map.get("yx"))); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 模拟一条数据 | 
				
			||||
     */ | 
				
			||||
    private Map<String, DeviceData> simulationV3(String stationId, Device device, List<DeviceField> fieldListAll, List<DeviceFieldGap> gapListAll) { | 
				
			||||
        List<DeviceField> fieldList = fieldListAll.stream().filter(e -> e.getFacDeviceId().equals(device.getId())).collect(Collectors.toList()); | 
				
			||||
        List<DeviceFieldGap> gapList = gapListAll.stream().filter(e -> e.getFacDeviceId().equals(device.getId())).collect(Collectors.toList()); | 
				
			||||
        List<Kvtq> ycList = Lists.newArrayList(); | 
				
			||||
        List<Kvtq> yxList = Lists.newArrayList(); | 
				
			||||
        for (DeviceField field : fieldList) { | 
				
			||||
            Optional<DeviceFieldGap> gapOpt = gapList.stream().filter(e -> e.getSignage().equals(field.getSignage())).findFirst(); | 
				
			||||
            BigDecimal max = BigDecimal.ONE, min = BigDecimal.ZERO; | 
				
			||||
            if (gapOpt.isPresent()) { | 
				
			||||
                DeviceFieldGap gap = gapOpt.get(); | 
				
			||||
                max = gap.getMaxVal(); | 
				
			||||
                min = gap.getMinVal(); | 
				
			||||
            } | 
				
			||||
            if (DataConstants.DeviceDataType.YC.ordinal() == field.getModelClassifyId().intValue()) { | 
				
			||||
                String value = getRandomRedPacketBetweenMinAndMax(min, max).toString(); | 
				
			||||
                Kvtq kvtq = Kvtq.builder().k(field.getSignage()).v(value).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build(); | 
				
			||||
                ycList.add(kvtq); | 
				
			||||
            } | 
				
			||||
            if (DataConstants.DeviceDataType.YX.ordinal() == field.getModelClassifyId().intValue()) { | 
				
			||||
                int value = getIntBetweenMinAndMax(min.intValue(), max.intValue()); | 
				
			||||
                Kvtq kvtq = Kvtq.builder().k(field.getSignage()).v(String.valueOf(value)).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build(); | 
				
			||||
                yxList.add(kvtq); | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        Map<String, DeviceData> map = Maps.newHashMap(); | 
				
			||||
        if (!ycList.isEmpty()) { | 
				
			||||
            map.put("yc", DeviceData.builder().station(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ycList).build()); | 
				
			||||
        } | 
				
			||||
        if (!yxList.isEmpty()) { | 
				
			||||
            map.put("yx", DeviceData.builder().station(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(yxList).build()); | 
				
			||||
        } | 
				
			||||
        return map; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    String getSid(String stationId) { | 
				
			||||
        return deviceService.getSid(stationId); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<Device> getDeviceListByStationId(String projectId) { | 
				
			||||
        LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>(); | 
				
			||||
        wrapper.eq(Device::getProjectId, projectId); | 
				
			||||
        List<Device> list = deviceService.list(wrapper); | 
				
			||||
        return list; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    @Async | 
				
			||||
    public void simulationMultipleV4(String[] stationIds) { | 
				
			||||
        for (String stationId : stationIds) { | 
				
			||||
            String sid = getSid(stationId); | 
				
			||||
            List<Device> list = getDeviceListByStationId(stationId); | 
				
			||||
            //查询所有属性
 | 
				
			||||
            List<DeviceField> fieldList = deviceFieldService.list(); | 
				
			||||
            List<DeviceFieldGap> gapList = deviceFieldGapService.list(); | 
				
			||||
 | 
				
			||||
            log.info("本站{}有{}个设备实例,发送{}条数据", stationId, list.size(), list.size()); | 
				
			||||
 | 
				
			||||
            for (Device device : list) { | 
				
			||||
                Map<String, DeviceDataV4> map = simulationV4(stationId, sid, device, fieldList, gapList); | 
				
			||||
                log.info("模拟数据{}", map); | 
				
			||||
                if (map.get("yc") != null && !map.get("yc").getChildren().isEmpty()) { | 
				
			||||
                    mqttSender.sendToMqtt("hzinfo_v4_yc", JsonUtil.toJson(map.get("yc"))); | 
				
			||||
                } | 
				
			||||
                if (map.get("yx") != null && !map.get("yx").getChildren().isEmpty()) { | 
				
			||||
                    mqttSender.sendToMqtt("hzinfo_v4_yx", JsonUtil.toJson(map.get("yx"))); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private Map<String, DeviceDataV4> simulationV4(String stationId, String sid, Device device, List<DeviceField> fieldListAll, List<DeviceFieldGap> gapListAll) { | 
				
			||||
        List<DeviceField> fieldList = fieldListAll.stream().filter(e -> e.getFacDeviceId().equals(device.getId())).collect(Collectors.toList()); | 
				
			||||
        List<DeviceFieldGap> gapList = gapListAll.stream().filter(e -> e.getFacDeviceId().equals(device.getId())).collect(Collectors.toList()); | 
				
			||||
        List<KvtqV4> ycList = Lists.newArrayList(); | 
				
			||||
        List<KvtqV4> yxList = Lists.newArrayList(); | 
				
			||||
        for (DeviceField field : fieldList) { | 
				
			||||
            Optional<DeviceFieldGap> gapOpt = gapList.stream().filter(e -> e.getSignage().equals(field.getSignage())).findFirst(); | 
				
			||||
            BigDecimal max = BigDecimal.ONE; | 
				
			||||
            BigDecimal min = BigDecimal.ZERO; | 
				
			||||
            if (gapOpt.isPresent()) { | 
				
			||||
                DeviceFieldGap gap = gapOpt.get(); | 
				
			||||
                max = gap.getMaxVal(); | 
				
			||||
                min = gap.getMinVal(); | 
				
			||||
            } | 
				
			||||
            if (DataConstants.DeviceDataType.YC.ordinal() == field.getModelClassifyId().intValue()) { | 
				
			||||
                String value = getRandomRedPacketBetweenMinAndMax(min, max).toString(); | 
				
			||||
                KvtqV4 kvtq = KvtqV4.builder().sid(sid).k(field.getSignage()).v(value).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build(); | 
				
			||||
                ycList.add(kvtq); | 
				
			||||
            } | 
				
			||||
            if (DataConstants.DeviceDataType.YX.ordinal() == field.getModelClassifyId().intValue()) { | 
				
			||||
                int value = getIntBetweenMinAndMax(min.intValue(), max.intValue()); | 
				
			||||
                KvtqV4 kvtq = KvtqV4.builder().sid(sid).k(field.getSignage()).v(String.valueOf(value)).t(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).q(0).build(); | 
				
			||||
                yxList.add(kvtq); | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        Map<String, DeviceDataV4> map = Maps.newHashMap(); | 
				
			||||
        if (!ycList.isEmpty()) { | 
				
			||||
            map.put("yc", DeviceDataV4.builder().stationId(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ycList).build()); | 
				
			||||
        } | 
				
			||||
        if (!yxList.isEmpty()) { | 
				
			||||
            map.put("yx", DeviceDataV4.builder().stationId(stationId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(yxList).build()); | 
				
			||||
        } | 
				
			||||
        return map; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    public static BigDecimal getRandomRedPacketBetweenMinAndMax(BigDecimal min, BigDecimal max) { | 
				
			||||
        float minF = min.floatValue(); | 
				
			||||
        float maxF = max.floatValue(); | 
				
			||||
        //生成随机数
 | 
				
			||||
        BigDecimal db = new BigDecimal(Math.random() * (maxF - minF) + minF); | 
				
			||||
        //返回保留两位小数的随机数。不进行四舍五入
 | 
				
			||||
        return db.setScale(3, BigDecimal.ROUND_DOWN); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public static int getIntBetweenMinAndMax(int min, int max) { | 
				
			||||
        //生成随机数
 | 
				
			||||
        int randomNum = min + (int) (Math.random() * ((max - min) + 1)); | 
				
			||||
        //返回保留两位小数的随机数。不进行四舍五入
 | 
				
			||||
        return randomNum; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,232 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.service.impl; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import com.hnac.hzinfo.simulate.constants.WriteRealDataConstant; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.*; | 
				
			||||
import com.hnac.hzinfo.simulate.mapper.DeviceFacConfigMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.mapper.DeviceFieldGapMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.mapper.DeviceFieldMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.mapper.DeviceRainGapMapper; | 
				
			||||
import com.hnac.hzinfo.simulate.service.WriteRealDataService; | 
				
			||||
import com.hnac.hzinfo.simulate.util.DataConstants; | 
				
			||||
import com.hnac.hzinfo.simulate.util.TopicConstant; | 
				
			||||
import lombok.RequiredArgsConstructor; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
import org.springblade.core.tool.jackson.JsonUtil; | 
				
			||||
import org.springblade.core.tool.utils.CollectionUtil; | 
				
			||||
import org.springblade.core.tool.utils.DateTimeUtil; | 
				
			||||
import org.springblade.core.tool.utils.DateUtil; | 
				
			||||
import org.springblade.core.tool.utils.ObjectUtil; | 
				
			||||
import org.springblade.mqtt.producer.IMqttSender; | 
				
			||||
import org.springframework.stereotype.Service; | 
				
			||||
 | 
				
			||||
import java.math.BigDecimal; | 
				
			||||
import java.text.DecimalFormat; | 
				
			||||
import java.time.LocalDateTime; | 
				
			||||
import java.util.Date; | 
				
			||||
import java.util.List; | 
				
			||||
import java.util.Optional; | 
				
			||||
import java.util.stream.Collectors; | 
				
			||||
 | 
				
			||||
import static com.hnac.hzinfo.simulate.constants.WriteRealDataConstant.REAL_DATA_V3; | 
				
			||||
import static com.hnac.hzinfo.simulate.constants.WriteRealDataConstant.REAL_DATA_V4; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @author ysj | 
				
			||||
 */ | 
				
			||||
@Service | 
				
			||||
@Slf4j | 
				
			||||
@RequiredArgsConstructor | 
				
			||||
public class WriteRealDataServiceImpl implements WriteRealDataService { | 
				
			||||
 | 
				
			||||
    private final IMqttSender mqttSender; | 
				
			||||
 | 
				
			||||
    private final DeviceFieldMapper fieldMapper; | 
				
			||||
 | 
				
			||||
    private final DeviceFieldGapMapper limitMapper; | 
				
			||||
 | 
				
			||||
    private final DeviceFacConfigMapper configMapper; | 
				
			||||
 | 
				
			||||
    private final DeviceRainGapMapper deviceRainGapMapper; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 实时数据写入 | 
				
			||||
     * | 
				
			||||
     * @param param | 
				
			||||
     */ | 
				
			||||
    @Override | 
				
			||||
    public void writeRealGateData(String param) { | 
				
			||||
        // 查询设备配置
 | 
				
			||||
        List<DeviceFacConfig> configs = configMapper.queryConfigDevice(WriteRealDataConstant.WRITE_GATE); | 
				
			||||
        if (CollectionUtil.isEmpty(configs)) { | 
				
			||||
            return; | 
				
			||||
        } | 
				
			||||
        //#.000 表示三位小数
 | 
				
			||||
        DecimalFormat df = new DecimalFormat("#0.000"); | 
				
			||||
        // 遍历发送mqtt实时数据
 | 
				
			||||
        configs.stream().collect(Collectors.groupingBy(DeviceFacConfig::getModelKind)).forEach((modeKind, groups) -> { | 
				
			||||
            // 查询设备属性
 | 
				
			||||
            List<DeviceField> fields = fieldMapper.queryDeviceFields(groups.stream().map(DeviceFacConfig::getFacDeviceId).collect(Collectors.toList())); | 
				
			||||
            if (CollectionUtil.isEmpty(fields)) { | 
				
			||||
                return; | 
				
			||||
            } | 
				
			||||
            // 查询设备限制
 | 
				
			||||
            List<DeviceFieldGap> limits = limitMapper.queryDeviceLimits(fields.stream().map(DeviceField::getSignage).collect(Collectors.toList())); | 
				
			||||
            if (CollectionUtil.isEmpty(limits)) { | 
				
			||||
                return; | 
				
			||||
            } | 
				
			||||
            // v3
 | 
				
			||||
            if (REAL_DATA_V3.equals(modeKind)) { | 
				
			||||
                fields.stream().collect(Collectors.groupingBy(DeviceField::getModelClassifyId)).forEach((key, models) -> { | 
				
			||||
                    models.stream().collect(Collectors.groupingBy(DeviceField::getProjectId)).forEach((projectId, value) -> { | 
				
			||||
                        // 遥测实时数据对象
 | 
				
			||||
                        List<Kvtq> ycs = value.stream().filter(o -> DataConstants.DeviceDataType.YC.ordinal() == o.getModelClassifyId()).map(field -> { | 
				
			||||
                            List<DeviceFieldGap> limit = limits.stream().filter(e -> e.getSignage().equals(field.getSignage())).collect(Collectors.toList()); | 
				
			||||
                            if (CollectionUtil.isEmpty(limit)) { | 
				
			||||
                                return new Kvtq(); | 
				
			||||
                            } | 
				
			||||
                            Kvtq real = new Kvtq(); | 
				
			||||
                            double random = Math.random() * limit.get(0).getMaxVal().subtract(limit.get(0).getMinVal()).doubleValue() + limit.get(0).getMinVal().doubleValue(); | 
				
			||||
                            real.setK(field.getSignage()); | 
				
			||||
                            real.setV(df.format(random)); | 
				
			||||
                            real.setT(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")); | 
				
			||||
                            real.setQ(0); | 
				
			||||
                            return real; | 
				
			||||
                        }).filter(ObjectUtil::isNotEmpty).collect(Collectors.toList()); | 
				
			||||
                        if (CollectionUtil.isNotEmpty(ycs)) { | 
				
			||||
                            log.info("yc_real_data_v3 : {}", JsonUtil.toJson(DeviceData.builder().station(projectId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ycs).build())); | 
				
			||||
                            mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_PROPS, JsonUtil.toJson(DeviceData.builder().station(projectId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ycs).build())); | 
				
			||||
                        } | 
				
			||||
                        // 遥信实时数据对象
 | 
				
			||||
                        List<Kvtq> yxs = value.stream().filter(o -> DataConstants.DeviceDataType.YX.ordinal() == o.getModelClassifyId()).map(field -> { | 
				
			||||
                            List<DeviceFieldGap> limit = limits.stream().filter(e -> e.getSignage().equals(field.getSignage())).collect(Collectors.toList()); | 
				
			||||
                            if (CollectionUtil.isEmpty(limit)) { | 
				
			||||
                                return new Kvtq(); | 
				
			||||
                            } | 
				
			||||
                            Kvtq real = new Kvtq(); | 
				
			||||
                            double random = limit.get(0).getMaxVal().subtract(limit.get(0).getMinVal()).doubleValue() + limit.get(0).getMinVal().doubleValue(); | 
				
			||||
                            real.setK(field.getSignage()); | 
				
			||||
                            real.setV(df.format(random)); | 
				
			||||
                            real.setT(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")); | 
				
			||||
                            real.setQ(0); | 
				
			||||
                            return real; | 
				
			||||
                        }).collect(Collectors.toList()); | 
				
			||||
                        if (CollectionUtil.isNotEmpty(yxs)) { | 
				
			||||
                            log.info("yx_real_data_v3 : {}", JsonUtil.toJson(DeviceData.builder().station(projectId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(yxs).build())); | 
				
			||||
                            mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_YX, JsonUtil.toJson(DeviceData.builder().station(projectId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(yxs).build())); | 
				
			||||
                        } | 
				
			||||
                    }); | 
				
			||||
                }); | 
				
			||||
            } | 
				
			||||
            // v4
 | 
				
			||||
            if (REAL_DATA_V4.equals(modeKind)) { | 
				
			||||
                fields.stream().collect(Collectors.groupingBy(DeviceField::getModelClassifyId)).forEach((key, models) -> { | 
				
			||||
                    models.stream().collect(Collectors.groupingBy(DeviceField::getProjectId)).forEach((projectId, value) -> { | 
				
			||||
                        // 遥测实时数据对象
 | 
				
			||||
                        List<KvtqV4> ycs = value.stream().filter(o -> DataConstants.DeviceDataType.YC.ordinal() == o.getModelClassifyId()).map(field -> { | 
				
			||||
                            List<DeviceFieldGap> limit = limits.stream().filter(e -> e.getSignage().equals(field.getSignage())).collect(Collectors.toList()); | 
				
			||||
                            if (CollectionUtil.isEmpty(limit)) { | 
				
			||||
                                return new KvtqV4(); | 
				
			||||
                            } | 
				
			||||
                            // 查找sid
 | 
				
			||||
                            Optional<DeviceFacConfig> sid = groups.stream().filter(group -> field.getFacDeviceId().equals(group.getFacDeviceId())).findFirst(); | 
				
			||||
                            if (!sid.isPresent()) { | 
				
			||||
                                return new KvtqV4(); | 
				
			||||
                            } | 
				
			||||
                            KvtqV4 real = new KvtqV4(); | 
				
			||||
                            double random = Math.random() * limit.get(0).getMaxVal().subtract(limit.get(0).getMinVal()).doubleValue() + limit.get(0).getMinVal().doubleValue(); | 
				
			||||
                            real.setSid(sid.get().getSid()); | 
				
			||||
                            real.setK(field.getSignage()); | 
				
			||||
                            real.setV(df.format(random)); | 
				
			||||
                            real.setT(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")); | 
				
			||||
                            real.setQ(0); | 
				
			||||
                            return real; | 
				
			||||
                        }).filter(ObjectUtil::isNotEmpty).collect(Collectors.toList()); | 
				
			||||
                        if (CollectionUtil.isNotEmpty(ycs)) { | 
				
			||||
                            log.info("yc_real_data_v4 : {}", JsonUtil.toJson(DeviceDataV4.builder().stationId(projectId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ycs).build())); | 
				
			||||
                            mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_V4_YC, JsonUtil.toJson(DeviceDataV4.builder().stationId(projectId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(ycs).build())); | 
				
			||||
                        } | 
				
			||||
                        // 遥信实时数据对象
 | 
				
			||||
                        List<KvtqV4> yxs = value.stream().filter(o -> DataConstants.DeviceDataType.YX.ordinal() == o.getModelClassifyId()).map(field -> { | 
				
			||||
                            List<DeviceFieldGap> limit = limits.stream().filter(e -> e.getSignage().equals(field.getSignage())).collect(Collectors.toList()); | 
				
			||||
                            if (CollectionUtil.isEmpty(limit)) { | 
				
			||||
                                return new KvtqV4(); | 
				
			||||
                            } | 
				
			||||
                            // 查找sid
 | 
				
			||||
                            Optional<DeviceFacConfig> sid = groups.stream().filter(group -> field.getFacDeviceId().equals(group.getFacDeviceId())).findFirst(); | 
				
			||||
                            if (!sid.isPresent()) { | 
				
			||||
                                return new KvtqV4(); | 
				
			||||
                            } | 
				
			||||
                            KvtqV4 real = new KvtqV4(); | 
				
			||||
                            double random = limit.get(0).getMaxVal().subtract(limit.get(0).getMinVal()).doubleValue() + limit.get(0).getMinVal().doubleValue(); | 
				
			||||
                            real.setSid(sid.get().getSid()); | 
				
			||||
                            real.setK(field.getSignage()); | 
				
			||||
                            real.setV(df.format(random)); | 
				
			||||
                            real.setT(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")); | 
				
			||||
                            real.setQ(0); | 
				
			||||
                            return real; | 
				
			||||
                        }).collect(Collectors.toList()); | 
				
			||||
                        if (CollectionUtil.isNotEmpty(yxs)) { | 
				
			||||
                            log.info("yx_real_data_v4 : {}", JsonUtil.toJson(DeviceDataV4.builder().stationId(projectId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(yxs).build())); | 
				
			||||
                            mqttSender.sendToMqtt(TopicConstant.TOPIC_HZINFO_V4_YX, JsonUtil.toJson(DeviceDataV4.builder().stationId(projectId).time(DateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS")).children(yxs).build())); | 
				
			||||
                        } | 
				
			||||
                    }); | 
				
			||||
                }); | 
				
			||||
            } | 
				
			||||
        }); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 开启/关闭闸门数据 | 
				
			||||
     * | 
				
			||||
     * @param deviceCode | 
				
			||||
     * @param isOpen | 
				
			||||
     * @return | 
				
			||||
     */ | 
				
			||||
    @Override | 
				
			||||
    public Boolean isOpen(String deviceCode, Long isOpen) { | 
				
			||||
        // 查询写入设备配置
 | 
				
			||||
        DeviceFacConfig config = configMapper.configByDeviceCode(deviceCode); | 
				
			||||
        if (ObjectUtil.isEmpty(config)) { | 
				
			||||
            return false; | 
				
			||||
        } | 
				
			||||
        // 查询设备属性
 | 
				
			||||
        List<DeviceField> fields = fieldMapper.querySignages(config.getFacDeviceId()); | 
				
			||||
        if (CollectionUtil.isEmpty(fields)) { | 
				
			||||
            return false; | 
				
			||||
        } | 
				
			||||
        // 查询属性限制
 | 
				
			||||
        List<DeviceFieldGap> limits = limitMapper.queryDeviceLimits(fields.stream().map(DeviceField::getSignage).collect(Collectors.toList())); | 
				
			||||
        if (CollectionUtil.isEmpty(limits)) { | 
				
			||||
            return false; | 
				
			||||
        } | 
				
			||||
        limits.forEach(limit -> { | 
				
			||||
            Optional<DeviceField> optional = fields.stream().filter(o -> o.getSignage().equals(limit.getSignage())).findFirst(); | 
				
			||||
            if (!optional.isPresent()) { | 
				
			||||
                return; | 
				
			||||
            } | 
				
			||||
            String signage = optional.get().getName(); | 
				
			||||
            if (WriteRealDataConstant.GATE_STATUS.equals(signage)) { | 
				
			||||
                if (WriteRealDataConstant.OPEN.equals(isOpen)) { | 
				
			||||
                    limitMapper.updateLimitById(BigDecimal.ONE, BigDecimal.ZERO, limit.getId()); | 
				
			||||
                } else { | 
				
			||||
                    limitMapper.updateLimitById(BigDecimal.ZERO, BigDecimal.ZERO, limit.getId()); | 
				
			||||
                } | 
				
			||||
            } else if (WriteRealDataConstant.GATE_FLOW.equals(signage)) { | 
				
			||||
                if (WriteRealDataConstant.OPEN.equals(isOpen)) { | 
				
			||||
                    limitMapper.updateLimitById(BigDecimal.valueOf(3560.000), BigDecimal.valueOf(0.000), limit.getId()); | 
				
			||||
                } else { | 
				
			||||
                    limitMapper.updateLimitById(BigDecimal.ZERO, BigDecimal.ZERO, limit.getId()); | 
				
			||||
                } | 
				
			||||
            } else if (WriteRealDataConstant.OPENING_DEGREE.equals(signage)) { | 
				
			||||
                if (WriteRealDataConstant.OPEN.equals(isOpen)) { | 
				
			||||
                    limitMapper.updateLimitById(BigDecimal.valueOf(10), BigDecimal.valueOf(0.000), limit.getId()); | 
				
			||||
                } else { | 
				
			||||
                    limitMapper.updateLimitById(BigDecimal.ZERO, BigDecimal.ZERO, limit.getId()); | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        }); | 
				
			||||
        return true; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,357 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.util; | 
				
			||||
 | 
				
			||||
public interface DataConstants { | 
				
			||||
        String REDIS_MESSAGE_TOPIC = "hzinfo_config_message_topic"; | 
				
			||||
        String TIME_COLUMN = "ts"; | 
				
			||||
        String VALUE_COLUMN = "val"; | 
				
			||||
        String Q_COLUMN = "q"; | 
				
			||||
        String REAL_ID_COLUMN = "realid"; | 
				
			||||
        String TBNAME = "tbname"; | 
				
			||||
        String YC_TABLE_PREFIX = "yc_"; | 
				
			||||
        String YX_TABLE_PREFIX = "yx_"; | 
				
			||||
        String SOE_TABLE_PREFIX = "soe_"; | 
				
			||||
        String SOE_ALARM_TABLE_PREFIX = "soe_alarm_"; | 
				
			||||
        String YC = "YC"; | 
				
			||||
        String YX = "YX"; | 
				
			||||
        String SOE = "SOE"; | 
				
			||||
        String YK_RETURN_PREFIX = "ykfj:"; | 
				
			||||
        String REALID_CALCULATE = "16777215"; | 
				
			||||
        String DEVICE_SUPER_TABLE_PREFIX = "hz_"; | 
				
			||||
        String DEVICE_TABLE_PREFIX = "d_"; | 
				
			||||
 | 
				
			||||
        public static enum DataStructTypeEnum { | 
				
			||||
            struct, | 
				
			||||
            dataGroup; | 
				
			||||
 | 
				
			||||
            private DataStructTypeEnum() { | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum EYkRetStatus { | 
				
			||||
            yrsSuccess, | 
				
			||||
            yrsServerErr, | 
				
			||||
            yrsChannelErr, | 
				
			||||
            yrsModuleErr, | 
				
			||||
            yrsDeviceTimeOut, | 
				
			||||
            yrsDeviceFail, | 
				
			||||
            yrsExpired; | 
				
			||||
 | 
				
			||||
            private EYkRetStatus() { | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum SoeType { | 
				
			||||
            skNone(0, "0", "默认"), | 
				
			||||
            skSys(1, "1", "系统"), | 
				
			||||
            skAlarm(2, "2", "报警"), | 
				
			||||
            skAct(3, "3", "事故"), | 
				
			||||
            skOperate(4, "4", "用户操作"), | 
				
			||||
            skYcOut(5, "5,11,12", "遥测越限"), | 
				
			||||
            skYxChange(6, "6,10", "遥信变位"), | 
				
			||||
            skReg(7, "7", "注册信息"), | 
				
			||||
            skHint(8, "8", "信息提示"), | 
				
			||||
            skInspect(9, "9", "设备巡检"), | 
				
			||||
            skMonitorOperate(10, "13,14", "遥控操作"), | 
				
			||||
            skRDSYcOutOfLimitResume(11, "15", "遥测越限恢复"), | 
				
			||||
            skUndefine(12, "16,17,18", "未定义"), | 
				
			||||
            skNetworkAnomaly(13, "-1", "通讯异常"), | 
				
			||||
            skCommunicateAnomaly(14, "-2", "数据异常"); | 
				
			||||
 | 
				
			||||
            private Integer index; | 
				
			||||
            private String soeKind; | 
				
			||||
            private String name; | 
				
			||||
 | 
				
			||||
            private SoeType(Integer index, String soeKind, String name) { | 
				
			||||
                this.index = index; | 
				
			||||
                this.soeKind = soeKind; | 
				
			||||
                this.name = name; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public static String getName(Integer id) { | 
				
			||||
                SoeType[] values = values(); | 
				
			||||
 | 
				
			||||
                for (int i = 0; i < values.length; ++i) { | 
				
			||||
                    if (values[i].index.equals(id)) { | 
				
			||||
                        return values[i].getName(); | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                return null; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public static Integer getIndexBySoeKind(String soeType) { | 
				
			||||
                SoeType[] values = values(); | 
				
			||||
                SoeType[] var2 = values; | 
				
			||||
                int var3 = values.length; | 
				
			||||
 | 
				
			||||
                for (int var4 = 0; var4 < var3; ++var4) { | 
				
			||||
                    SoeType type = var2[var4]; | 
				
			||||
                    if (type.getSoeKind().contains(soeType)) { | 
				
			||||
                        return type.getIndex(); | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                return skUndefine.getIndex(); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public static String getSoeKindByIndex(Integer index) { | 
				
			||||
                SoeType[] values = values(); | 
				
			||||
                SoeType[] var2 = values; | 
				
			||||
                int var3 = values.length; | 
				
			||||
 | 
				
			||||
                for (int var4 = 0; var4 < var3; ++var4) { | 
				
			||||
                    SoeType type = var2[var4]; | 
				
			||||
                    if (type.getIndex().equals(index)) { | 
				
			||||
                        return type.getSoeKind(); | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                return ""; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public Integer getIndex() { | 
				
			||||
                return this.index; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getSoeKind() { | 
				
			||||
                return this.soeKind; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getName() { | 
				
			||||
                return this.name; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum SoeKind { | 
				
			||||
            skNone(0, "默认"), | 
				
			||||
            skSys(1, "系统"), | 
				
			||||
            skAlarm(2, "报警"), | 
				
			||||
            skAct(3, "事故"), | 
				
			||||
            skOperate(4, "操作"), | 
				
			||||
            skYcOut(5, "遥测越限(告警)"), | 
				
			||||
            skYxChange(6, "遥信变位(告警)"), | 
				
			||||
            skReg(7, "注册信息"), | 
				
			||||
            skHint(8, "信息提示"), | 
				
			||||
            skInspect(9, "设备巡检"), | 
				
			||||
            skRDSYxChange(10, "遥信变位(数据)"), | 
				
			||||
            skRDSYcOutOfLimit(11, "遥测越上/下限(数据)"), | 
				
			||||
            skRDSYcOutOfLimit2(12, "遥测越上上/下下限(数据)"), | 
				
			||||
            skMonitorOperate(13, "操作记录(遥控)"), | 
				
			||||
            skMonitorOperateII(14, "操作记录(写定值)"), | 
				
			||||
            skRDSYcOutOfLimitResume(15, "越限恢复"), | 
				
			||||
            bak_7(16, "备用7"), | 
				
			||||
            bak_8(17, "备用8"), | 
				
			||||
            skUndefine(18, "未定义"); | 
				
			||||
 | 
				
			||||
            private Integer index; | 
				
			||||
            private String name; | 
				
			||||
 | 
				
			||||
            private SoeKind(Integer index, String name) { | 
				
			||||
                this.index = index; | 
				
			||||
                this.name = name; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public static String getName(Integer id) { | 
				
			||||
                SoeKind[] values = values(); | 
				
			||||
 | 
				
			||||
                for (int i = 0; i < values.length; ++i) { | 
				
			||||
                    if (values[i].index.equals(id)) { | 
				
			||||
                        return values[i].getName(); | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                return null; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public Integer getIndex() { | 
				
			||||
                return this.index; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getName() { | 
				
			||||
                return this.name; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum DeviceDataType { | 
				
			||||
            YC("遥测"), | 
				
			||||
            YX("遥信"), | 
				
			||||
            DD("电渡"), | 
				
			||||
            YK("遥控"), | 
				
			||||
            YT("遥调"), | 
				
			||||
            SOE("事件"), | 
				
			||||
            STR("字符串"), | 
				
			||||
            OTHER("其它"); | 
				
			||||
 | 
				
			||||
            private String displayName; | 
				
			||||
 | 
				
			||||
            private DeviceDataType(String displayName) { | 
				
			||||
                this.displayName = displayName; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public static String getDisplayName(String name) { | 
				
			||||
                DeviceDataType type = valueOf(name); | 
				
			||||
                return type.getDisplayName(); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getDisplayName() { | 
				
			||||
                return this.displayName; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum YkDelayType { | 
				
			||||
            none_store, | 
				
			||||
            store, | 
				
			||||
            delay_store; | 
				
			||||
 | 
				
			||||
            private YkDelayType() { | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum RedisGroupMessageTypeEnum { | 
				
			||||
            NOTICE_CLEAN_LOCAL_CACHE_DEVICE("clean.local.cache.device"), | 
				
			||||
            NOTICE_CLEAN_LOCAL_CACHE_DEVICE_GROUP("clean.local.cache.group"), | 
				
			||||
            NOTICE_CLEAN_LOCAL_CACHE_ALARM("clean.local.cache.alarm"), | 
				
			||||
            NOTICE_CLEAN_LOCAL_CACHE_YK("clean.local.cache.yk"); | 
				
			||||
 | 
				
			||||
            private String value; | 
				
			||||
 | 
				
			||||
            private RedisGroupMessageTypeEnum(String value) { | 
				
			||||
                this.value = value; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getValue() { | 
				
			||||
                return this.value; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum DataStatusEnum { | 
				
			||||
            offline, | 
				
			||||
            online; | 
				
			||||
 | 
				
			||||
            private DataStatusEnum() { | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum StatisticsType { | 
				
			||||
            avg("AVG"), | 
				
			||||
            max("MAX"), | 
				
			||||
            min("MIN"); | 
				
			||||
 | 
				
			||||
            private String computeStrategy; | 
				
			||||
 | 
				
			||||
            private StatisticsType(String fun) { | 
				
			||||
                this.computeStrategy = fun; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public static StatisticsType getStatisticsType(int index) { | 
				
			||||
                StatisticsType[] values = values(); | 
				
			||||
                StatisticsType[] var2 = values; | 
				
			||||
                int var3 = values.length; | 
				
			||||
 | 
				
			||||
                for (int var4 = 0; var4 < var3; ++var4) { | 
				
			||||
                    StatisticsType value = var2[var4]; | 
				
			||||
                    if (index == value.ordinal()) { | 
				
			||||
                        return value; | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                return null; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getComputeStrategy() { | 
				
			||||
                return this.computeStrategy; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public void setComputeStrategy(final String computeStrategy) { | 
				
			||||
                this.computeStrategy = computeStrategy; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum AnalyzeInstanceAlarmConfType { | 
				
			||||
            changeAlarm("变化告警"), | 
				
			||||
            supassAlarm("越限告警"); | 
				
			||||
 | 
				
			||||
            private String name; | 
				
			||||
 | 
				
			||||
            private AnalyzeInstanceAlarmConfType(String name) { | 
				
			||||
                this.name = name; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getName() { | 
				
			||||
                return this.name; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum StatisticsAnalyEnum { | 
				
			||||
            Hour("h"), | 
				
			||||
            Day("d"), | 
				
			||||
            Month("n"), | 
				
			||||
            Year("h"); | 
				
			||||
 | 
				
			||||
            private String type; | 
				
			||||
 | 
				
			||||
            private StatisticsAnalyEnum(String fun) { | 
				
			||||
                this.type = fun; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public static StatisticsAnalyEnum getStatisticsAnalyEnum(int index) { | 
				
			||||
                StatisticsAnalyEnum[] values = values(); | 
				
			||||
                StatisticsAnalyEnum[] var2 = values; | 
				
			||||
                int var3 = values.length; | 
				
			||||
 | 
				
			||||
                for (int var4 = 0; var4 < var3; ++var4) { | 
				
			||||
                    StatisticsAnalyEnum value = var2[var4]; | 
				
			||||
                    if (value.ordinal() == index) { | 
				
			||||
                        return value; | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                return null; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getType() { | 
				
			||||
                return this.type; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum StationFromSouceEnum { | 
				
			||||
            cloud, | 
				
			||||
            station; | 
				
			||||
 | 
				
			||||
            private StationFromSouceEnum() { | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum AnalyzeInstanceDataResoureEnum { | 
				
			||||
            deviceUp("设备上报"), | 
				
			||||
            hz3000Up("华自网关上报"); | 
				
			||||
 | 
				
			||||
            private String name; | 
				
			||||
 | 
				
			||||
            private AnalyzeInstanceDataResoureEnum(String name) { | 
				
			||||
                this.name = name; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            public String getName() { | 
				
			||||
                return this.name; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum ThresholdLevelEnum { | 
				
			||||
            one, | 
				
			||||
            two, | 
				
			||||
            three; | 
				
			||||
 | 
				
			||||
            private ThresholdLevelEnum() { | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        public static enum Hz3000VersionEnum { | 
				
			||||
            v3, | 
				
			||||
            v4; | 
				
			||||
 | 
				
			||||
            private Hz3000VersionEnum() { | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,105 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.util; | 
				
			||||
 | 
				
			||||
import com.fasterxml.jackson.core.JsonProcessingException; | 
				
			||||
import com.google.common.collect.Lists; | 
				
			||||
import org.dom4j.Document; | 
				
			||||
import org.dom4j.DocumentException; | 
				
			||||
import org.dom4j.Element; | 
				
			||||
import org.dom4j.io.SAXReader; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DataItem; | 
				
			||||
import com.hnac.hzinfo.simulate.entity.DataModel; | 
				
			||||
import org.xml.sax.SAXException; | 
				
			||||
 | 
				
			||||
import java.io.InputStream; | 
				
			||||
import java.math.BigInteger; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * 解析厂信息工具类 | 
				
			||||
 * @author ninglong | 
				
			||||
 */ | 
				
			||||
public class ParseFacUtils { | 
				
			||||
 | 
				
			||||
    public static List<DataModel> parsePoint(InputStream inputStream) throws SAXException, DocumentException, JsonProcessingException { | 
				
			||||
        SAXReader saxReader = new SAXReader(); | 
				
			||||
        Document document = saxReader.read(inputStream); | 
				
			||||
        List groupElements = document.selectNodes("/Factorys/Factory/Group"); | 
				
			||||
        List<DataModel> list = parseDataGroup(groupElements); | 
				
			||||
        List ycElements = document.selectNodes("/Factorys/Factory/Group/AIS/AI"); | 
				
			||||
        list = pastePointElement(ycElements, DataConstants.DeviceDataType.YC.name(),list); | 
				
			||||
 | 
				
			||||
        List yxElements = document.selectNodes("/Factorys/Factory/Group/DIS/DI"); | 
				
			||||
        list = pastePointElement(yxElements, DataConstants.DeviceDataType.YX.name(),list); | 
				
			||||
 | 
				
			||||
        List ddElements = document.selectNodes("/Factorys/Factory/Group/DDS/DD"); | 
				
			||||
        list = pastePointElement(ddElements, DataConstants.DeviceDataType.DD.name(),list); | 
				
			||||
 | 
				
			||||
        List soeElements = document.selectNodes("/Factorys/Factory/Group/SOES/SOE"); | 
				
			||||
        list = pastePointElement(soeElements, DataConstants.DeviceDataType.SOE.name(),list); | 
				
			||||
 | 
				
			||||
        List ykElements = document.selectNodes("/Factorys/Factory/Group/DOS/DO"); | 
				
			||||
        list = pastePointElement(ykElements, DataConstants.DeviceDataType.YK.name(),list); | 
				
			||||
        return list; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 解析数据组 | 
				
			||||
     */ | 
				
			||||
    private static List<DataModel> parseDataGroup(List elements){ | 
				
			||||
        List<DataModel> list = Lists.newArrayList(); | 
				
			||||
        for (Element element : (List<Element>) elements) { | 
				
			||||
            DataModel model = new DataModel(); | 
				
			||||
            model.setStructType(DataConstants.DataStructTypeEnum.dataGroup.name()); | 
				
			||||
            model.setId(element.attribute("ID").getValue()); | 
				
			||||
            model.setSignage(bigId2SmallId(element.attribute("ID").getValue())); | 
				
			||||
            model.setName(element.attribute("Name").getValue()); | 
				
			||||
            String stationNumStr = element.getParent().attribute("StationNum").getValue(); | 
				
			||||
            model.setStation(stationNumStr); | 
				
			||||
            list.add(model); | 
				
			||||
        } | 
				
			||||
        return list; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 将大id转换成小id | 
				
			||||
     */ | 
				
			||||
    public static String bigId2SmallId(String realId){ | 
				
			||||
        BigInteger bigRealId = new BigInteger(realId); | 
				
			||||
        return bigRealId.and(new BigInteger(DataConstants.REALID_CALCULATE)).toString(); | 
				
			||||
    } | 
				
			||||
    /** | 
				
			||||
     * 解析数据点 | 
				
			||||
     */ | 
				
			||||
    private static List<DataModel> pastePointElement(List elements, String type, List<DataModel> list) throws JsonProcessingException { | 
				
			||||
        for (Element element : (List<Element>) elements) { | 
				
			||||
            String groupId = element.getParent().getParent().attribute("ID").getValue(); | 
				
			||||
            for(DataModel dm:list){ | 
				
			||||
                if(!groupId.equals(dm.getId())){ | 
				
			||||
                    continue; | 
				
			||||
                } | 
				
			||||
                DataItem dataItem = DataItem.builder() | 
				
			||||
                        .id(element.attribute("ID").getValue()) | 
				
			||||
                        .signage(bigId2SmallId(element.attribute("ID").getValue())) | 
				
			||||
                        .name(element.attribute("Name").getValue()) | 
				
			||||
                        .type(type) | 
				
			||||
                        .build(); | 
				
			||||
                if(DataConstants.DeviceDataType.SOE.name().equals(type)){ | 
				
			||||
                    dataItem.setEventType(element.attribute("SOEAlarmType").getValue()); | 
				
			||||
                    dataItem.setSoeType(element.attribute("SOEType").getValue()); | 
				
			||||
                } | 
				
			||||
                if(DataConstants.DeviceDataType.YX.name().equals(type)){ | 
				
			||||
                    dataItem.setEventType(element.attribute("YXAlarmType").getValue()); | 
				
			||||
                    dataItem.setSoeType(element.attribute("SOEType").getValue()); | 
				
			||||
                } | 
				
			||||
                List<DataItem> childrens = dm.getChildren(); | 
				
			||||
                if(childrens==null){ | 
				
			||||
                    childrens = Lists.newArrayList(); | 
				
			||||
                } | 
				
			||||
                childrens.add(dataItem); | 
				
			||||
                dm.setChildren(childrens); | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        return list; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
 | 
				
			||||
@ -0,0 +1,52 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.util; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import java.math.BigInteger; | 
				
			||||
 | 
				
			||||
public class RealIdConvertUtils { | 
				
			||||
 | 
				
			||||
    private void demo() { | 
				
			||||
        BigInteger ss = new BigInteger("16777215"); | 
				
			||||
        BigInteger s = new BigInteger("15122982502953650999"); | 
				
			||||
        BigInteger stationId = s.shiftRight(24); | 
				
			||||
        System.out.println(stationId.toString()); | 
				
			||||
        BigInteger realId = s.and(ss); | 
				
			||||
        System.out.println(realId.toString()); | 
				
			||||
 | 
				
			||||
        BigInteger xxx = stationId.shiftLeft(24); | 
				
			||||
        BigInteger yyy = xxx.or(realId); | 
				
			||||
        System.out.println(s.toString()); | 
				
			||||
        System.out.println(yyy.toString()); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 将大id转换成小id | 
				
			||||
     */ | 
				
			||||
    public static String bigId2SmallId(String realId) { | 
				
			||||
        BigInteger bigRealId = new BigInteger(realId); | 
				
			||||
        return bigRealId.and(new BigInteger(DataConstants.REALID_CALCULATE)).toString(); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 将小id转换成大id | 
				
			||||
     */ | 
				
			||||
    public static String smallId2BigId(String station, String realId) { | 
				
			||||
        BigInteger stationId = new BigInteger(station); | 
				
			||||
        BigInteger BigRealId = stationId.shiftLeft(24).or(new BigInteger(realId)); | 
				
			||||
        return BigRealId.toString(); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
//    public static void main(String[] args) {
 | 
				
			||||
//        System.out.println(RealIdConvertUtils.getStationId("262952509021093892"));
 | 
				
			||||
//        System.out.println(RealIdConvertUtils.bigId2SmallId("262952509021093892"));
 | 
				
			||||
//        System.out.println(smallId2BigId("15673190893", "32"));
 | 
				
			||||
//    }
 | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * 获取站点id | 
				
			||||
     */ | 
				
			||||
    public static String getStationId(String realId) { | 
				
			||||
        BigInteger bigRealId = new BigInteger(realId); | 
				
			||||
        return bigRealId.shiftRight(24).toString(); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,18 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.util; | 
				
			||||
 | 
				
			||||
public interface TopicConstant { | 
				
			||||
    String TOPIC_DEVICE_MODEL = "topic_device_model"; | 
				
			||||
    String TOPIC_HZINFO_PROPS = "topic_hzinfo_props"; | 
				
			||||
    String TOPIC_HZINFO_V4_YC = "hzinfo_v4_yc"; | 
				
			||||
 | 
				
			||||
    String TOPIC_HZINFO_V4_YX = "hzinfo_v4_yx"; | 
				
			||||
 | 
				
			||||
    String TOPIC_HZINFO_YX = "topic_hzinfo_yx"; | 
				
			||||
    String TOPIC_HZINFO_DD = "topic_hzinfo_dd"; | 
				
			||||
    String TOPIC_HZINFO_EVENTS = "topic_hzinfo_events"; | 
				
			||||
    String TOPIC_HZINFO_EVENTS_ALARM = "topic_hzinfo_events_alarm"; | 
				
			||||
    String TOPIC_HZINFO_CONTROL_RETURN = "topic_hzinfo_control_return"; | 
				
			||||
    String TOPIC_HZINFO_HEART_BEAT = "topic_hzinfo_heart_beat"; | 
				
			||||
    String TOPIC_HZINFO_BROADCAST = "topic_hzinfo_broadcast"; | 
				
			||||
    String TOPIC_HZINFO_DATA = "topic_hzinfo_data"; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,16 @@
					 | 
				
			||||
package com.hnac.hzinfo.simulate.vo; | 
				
			||||
 | 
				
			||||
import lombok.Data; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * 生成hz3000场数据 | 
				
			||||
 * | 
				
			||||
 * @author ypj | 
				
			||||
 * @date 2025-04-17 | 
				
			||||
 */ | 
				
			||||
@Data | 
				
			||||
public class GenerateFactoryDeviceVo { | 
				
			||||
    private String deviceId; | 
				
			||||
 | 
				
			||||
    private String facDeviceId; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,13 @@
					 | 
				
			||||
#服务器端口 | 
				
			||||
server: | 
				
			||||
  port: 8211 | 
				
			||||
 | 
				
			||||
#数据源配置 | 
				
			||||
spring: | 
				
			||||
  datasource: | 
				
			||||
    url: ${blade.datasource.dev.url} | 
				
			||||
    username: ${blade.datasource.dev.username} | 
				
			||||
    password: ${blade.datasource.dev.password} | 
				
			||||
  cloud: | 
				
			||||
    inetutils: | 
				
			||||
      preferred-networks: 192.168.65 | 
				
			||||
@ -0,0 +1,6 @@
					 | 
				
			||||
#数据源配置 | 
				
			||||
spring: | 
				
			||||
  datasource: | 
				
			||||
    url: ${blade.datasource.prod.url} | 
				
			||||
    username: ${blade.datasource.prod.username} | 
				
			||||
    password: ${blade.datasource.prod.password} | 
				
			||||
@ -0,0 +1,6 @@
					 | 
				
			||||
#数据源配置 | 
				
			||||
spring: | 
				
			||||
  datasource: | 
				
			||||
    url: ${blade.datasource.test.url} | 
				
			||||
    username: ${blade.datasource.test.username} | 
				
			||||
    password: ${blade.datasource.test.password} | 
				
			||||
@ -0,0 +1,15 @@
					 | 
				
			||||
spring: | 
				
			||||
  application: | 
				
			||||
    name: lewa-simulate | 
				
			||||
 | 
				
			||||
#mybatis-plus配置 | 
				
			||||
mybatis-plus: | 
				
			||||
  mapper-locations: classpath:org/springbalde/**/mapper/*Mapper.xml,classpath:com/hnac/hzinfo/**/mapper/*Mapper.xml | 
				
			||||
  #实体扫描,多个package用逗号或者分号分隔 | 
				
			||||
  typeAliasesPackage: org.springbalde.**.entity,com.hnac.hzinfo.**.entity | 
				
			||||
 | 
				
			||||
#swagger扫描路径配置 | 
				
			||||
swagger: | 
				
			||||
  base-packages: | 
				
			||||
    - org.springbalde | 
				
			||||
    - com.hnac.hzinfo | 
				
			||||
					Loading…
					
					
				
		Reference in new issue