wisdomisite-java/src/main/java/com/zhgd/xmgl/task/DevTestDataTask.java
2024-04-14 21:05:01 +08:00

247 lines
11 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zhgd.xmgl.task;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhgd.xmgl.modules.bigdevice.entity.Lifter;
import com.zhgd.xmgl.modules.bigdevice.entity.LifterCurrentData;
import com.zhgd.xmgl.modules.bigdevice.entity.Tower;
import com.zhgd.xmgl.modules.bigdevice.entity.TowerCurrentData;
import com.zhgd.xmgl.modules.bigdevice.mapper.LifterMapper;
import com.zhgd.xmgl.modules.bigdevice.mapper.TowerMapper;
import com.zhgd.xmgl.modules.bigdevice.service.ILifterCurrentDataService;
import com.zhgd.xmgl.modules.bigdevice.service.ITowerCurrentDataService;
import com.zhgd.xmgl.modules.discharging.entity.DischargingPlatformCurrentData;
import com.zhgd.xmgl.modules.discharging.entity.DischargingPlatformDev;
import com.zhgd.xmgl.modules.discharging.mapper.DischargingPlatformDevMapper;
import com.zhgd.xmgl.modules.discharging.service.IDischargingPlatformCurrentDataService;
import com.zhgd.xmgl.modules.environment.entity.DustNoiseData;
import com.zhgd.xmgl.modules.environment.entity.EnvironmentDev;
import com.zhgd.xmgl.modules.environment.mapper.EnvironmentDevMapper;
import com.zhgd.xmgl.modules.environment.service.IDustNoiseDataService;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
/**
* @program: wisdomSite
* @description: 自动创建设备测试数据
* @author: Mr.Peng
* @create: 2021-06-28 16:54
**/
@Slf4j
@Component
public class DevTestDataTask {
@Autowired
private IDustNoiseDataService dustNoiseDataService;
@Autowired
private EnvironmentDevMapper environmentDevMapper;
@Autowired
private IDischargingPlatformCurrentDataService dischargingPlatformCurrentDataService;
@Autowired
private DischargingPlatformDevMapper dischargingPlatformDevMapper;
@Autowired
private TowerMapper towerMapper;
@Autowired
private ITowerCurrentDataService towerCurrentDataService;
@Autowired
private LifterMapper lifterMapper;
@Autowired
private ILifterCurrentDataService lifterCurrentDataService;
/**
* 创建扬尘数据
*/
@Scheduled(cron = "0 0/9 * * * ?")
@SchedulerLock(name = "createEnvironmentData", lockAtMostFor = 1000 * 60 * 3, lockAtLeastFor = 1000 * 60 * 1)
public void createEnvironmentData() {
try {
QueryWrapper<EnvironmentDev> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(EnvironmentDev::getCreateDataType, 1);
List<EnvironmentDev> list = environmentDevMapper.selectList(queryWrapper);
Random random = new Random();
if (list != null && list.size() > 0) {
for (EnvironmentDev dev : list) {
DustNoiseData dustNoiseData = new DustNoiseData();
dustNoiseData.setProjectSn(dev.getProjectSn());
dustNoiseData.setDeviceId(dev.getDeviceId());
dustNoiseData.setPm10(getRandomNum());
dustNoiseData.setPm25(getRandomNum());
dustNoiseData.setNoise(getRandomNum());
dustNoiseData.setTsp(getRandomNum());
dustNoiseData.setTemperature(getRandomNum(20, 5));
dustNoiseData.setHumidity(getRandomNum(60, 6));
dustNoiseData.setWindspeed(getFloatRandomNum());
dustNoiseData.setWinddirection(random.nextInt(10) + "");
dustNoiseData.setVoltage(getRandomNum());
dustNoiseDataService.insertDustNoiseData(dustNoiseData, dev);
EnvironmentDev tempenvironmentDev = new EnvironmentDev();
tempenvironmentDev.setId(dev.getId());
tempenvironmentDev.setRealTime(new Date());
environmentDevMapper.updateById(tempenvironmentDev);
}
}
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 创建卸料平台数据
*/
@Scheduled(cron = "0 0/9 * * * ?")
@SchedulerLock(name = "createDischargingPlatformData", lockAtMostFor = 1000 * 60 * 3, lockAtLeastFor = 1000 * 60 * 1)
public void createDischargingPlatformData() {
try {
QueryWrapper<DischargingPlatformDev> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(DischargingPlatformDev::getCreateDataType, 1);
List<DischargingPlatformDev> list = dischargingPlatformDevMapper.selectList(queryWrapper);
if (list != null && list.size() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (DischargingPlatformDev dev : list) {
DischargingPlatformCurrentData platformCurrentData = new DischargingPlatformCurrentData();
platformCurrentData.setProjectSn(dev.getProjectSn());
platformCurrentData.setDevSn(dev.getDevSn());
//random.nextDouble()
platformCurrentData.setLoading(getFloatRandomNum() + "");
platformCurrentData.setXDipAngle("0");
platformCurrentData.setYDipAngle("0");
platformCurrentData.setDisplacement("0");
platformCurrentData.setReciveTime(sdf.format(new Date()));
dischargingPlatformCurrentDataService.save(platformCurrentData);
DischargingPlatformDev tempDischargingPlatformDev = new DischargingPlatformDev();
tempDischargingPlatformDev.setId(dev.getId());
tempDischargingPlatformDev.setRealTime(new Date());
dischargingPlatformDevMapper.updateById(tempDischargingPlatformDev);
}
}
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 创建塔吊数据
*/
@Scheduled(cron = "0 0/10 * * * ?")
//@Scheduled(cron = "0/5 * * * * ?")
@SchedulerLock(name = "createTowerData", lockAtMostFor = 1000 * 60 * 5, lockAtLeastFor = 1000 * 60 * 2)
public void createTowerData() {
try {
QueryWrapper<Tower> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Tower::getCreateDataType, 1);
List<Tower> list = towerMapper.selectList(queryWrapper);
Random random = new Random();
if (list != null && list.size() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (Tower dev : list) {
TowerCurrentData currentData = new TowerCurrentData();
currentData.setProjectSn(dev.getProjectSn());
currentData.setDevSn(dev.getDevSn());
currentData.setLoading(getDoubleRandomNum(10).toString());
currentData.setLoadRatio(getDoubleRandomNum(0).toString());
currentData.setTorque(getRandomNum().toString());
currentData.setAngle((random.nextInt(50) + 50) + "");
currentData.setAngle(getDoubleRandomNum(20).toString());
currentData.setHeight(getDoubleRandomNum(30).toString());
currentData.setWindspeed(getDoubleRandomNum(10).toString());
currentData.setRate("2");
Date date = new Date();
currentData.setStartTime(date);
currentData.setReciveTime(date);
towerCurrentDataService.save(currentData);
Tower tempTower = new Tower();
tempTower.setId(dev.getId());
tempTower.setRealTime(date);
towerMapper.updateById(tempTower);
}
}
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 创建塔吊数据
*/
@Scheduled(cron = "0 0/9 * * * ?")
@SchedulerLock(name = "createLifterData", lockAtMostFor = 1000 * 60 * 3, lockAtLeastFor = 1000 * 60 * 1)
public void createLifterData() {
try {
QueryWrapper<Lifter> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Lifter::getCreateDataType, 1);
List<Lifter> list = lifterMapper.selectList(queryWrapper);
Random random = new Random();
if (list != null && list.size() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (Lifter dev : list) {
LifterCurrentData currentData = new LifterCurrentData();
currentData.setProjectSn(dev.getProjectSn());
currentData.setDevSn(dev.getDevSn());
currentData.setHeight(getDoubleRandomNum(40).toString());
currentData.setType("0");
currentData.setMaxLoad("500");
currentData.setLoading(getDoubleRandomNum(80).toString());
currentData.setLoadRatio(random.nextInt(4) + "");
currentData.setRealFlag("0");
currentData.setBiasAngle("0");
currentData.setBrakingDistance("0");
currentData.setRunningState(1);
currentData.setSpeed(getDoubleRandomNum(0).toString());
currentData.setStartTime(sdf.format(new Date()));
currentData.setReciveTime(sdf.format(new Date()));
currentData.setIsOnline(1);
lifterCurrentDataService.save(currentData);
Lifter tempLifter = new Lifter();
tempLifter.setId(dev.getId());
tempLifter.setRealTime(new Date());
lifterMapper.updateById(tempLifter);
}
}
} catch (Exception e) {
log.error("error", e);
}
}
public static Double getRandomNum(int startNum, int randomNum) {
Random random = new Random();
DecimalFormat df = new DecimalFormat("0.00");
return Double.valueOf(df.format(startNum + random.nextInt(randomNum) + random.nextDouble()));
}
public static Double getRandomNum() {
Random random = new Random();
DecimalFormat df = new DecimalFormat("0.00");
return Double.valueOf(df.format(20 + random.nextInt(30) + random.nextDouble()));
}
public static Double getDoubleRandomNum(int num) {
Random random = new Random();
DecimalFormat df = new DecimalFormat("0.00");
if (num == 0) {
return Double.valueOf(df.format(random.nextDouble()));
} else {
return Double.valueOf(df.format(random.nextInt(num) + random.nextDouble()));
}
}
public static Double getFloatRandomNum() {
Random random = new Random();
DecimalFormat df = new DecimalFormat("0.0");
return Double.valueOf(df.format(random.nextDouble()));
}
public static void main(String[] args) {
//log.info(getRandomNum(10, 15));
}
}