package com.yssh.service;
|
|
import java.util.*;
|
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import com.yssh.entity.*;
|
import com.yssh.mapper.*;
|
import com.yssh.utils.CalculateUtils;
|
import com.yssh.utils.DateUtils;
|
import com.yssh.utils.StringUtils;
|
import com.yssh.utils.TableStrategy;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Service;
|
|
import com.google.common.collect.Lists;
|
|
import javax.annotation.Resource;
|
|
@Service
|
public class SuYuanService {
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@Resource
|
private SuYuanMapper suYuanMapper;
|
|
@Resource
|
private AsyncService asyncService;
|
|
@Resource
|
private DictRecordMapper dictRecordMapper;
|
|
@Resource
|
private CommonService commonService;
|
|
@Resource
|
private FeedbackMapper feedbackMapper;
|
|
@Resource
|
private QxshMapper qxshMapper;
|
|
@Resource
|
private LocationMapper locationMapper;
|
|
@Resource
|
private LocationService locService;
|
|
//@Transactional
|
@Async("threadPoolTaskExecutor")
|
public void insertSuYuanDatasAsync(List<SuYuan> lists, String time) throws Exception {
|
//插入数据
|
List<List<SuYuan>> list = Lists.partition(lists, AsyncService.BATCH_INSERT_NUMBER);
|
CountDownLatch countDownLatch = new CountDownLatch(list.size());
|
for (List<SuYuan> corpReserveList : list) {
|
asyncService.executeAsync(TableStrategy.getTableStrategy(time), corpReserveList, suYuanMapper, countDownLatch);
|
}
|
countDownLatch.await();
|
logger.info(lists.size() + "条数据入库完成-----");
|
}
|
|
public void insertSuYuanDatas(List<SuYuan> lists, String time) {
|
List<List<SuYuan>> subLists = Lists.partition(lists, AsyncService.BATCH_INSERT_NUMBER);
|
for (List<SuYuan> sub : subLists) {
|
suYuanMapper.batchInsert(TableStrategy.getTableStrategy(time), sub);
|
}
|
|
logger.info("------ " + time + ".csv," + lists.size() + " 条数据已入库 ------");
|
}
|
|
public Integer isTableExists(String tableName) {
|
return suYuanMapper.isTableExists(tableName);
|
}
|
|
public int createNewTable(String tableName) {
|
return suYuanMapper.createTable(tableName);
|
}
|
|
public List<SuYuan2d> selectSuYuan2d(Date date) {
|
String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
|
List<String> ids2d = CalculateUtils.assembleId(commonService.getCheckPoints2d());
|
DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
|
if (StringUtils.isNull(dictRecord)) {
|
return null;
|
}
|
return suYuanMapper.get2d(dictRecord.getTableName(), ids2d);
|
}
|
|
public List<SuYuan3d> selectSuYuan3d(String name, Date date) {
|
MonitorPointPosition checkPoint = commonService.select3dCheckPointByName(name);
|
if (StringUtils.isNull(checkPoint)) {
|
return null;
|
}
|
int range = 10;
|
String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
|
List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(checkPoint, range);
|
DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
|
if (StringUtils.isNull(dictRecord)) {
|
return null;
|
}
|
return suYuanMapper.get3d(dictRecord.getTableName(), ids3d);
|
}
|
|
public Map<String, Object> selectSuYuan100(String name, Date date) {
|
Map<String, Object> result = new HashMap<String, Object>();
|
MonitorPointPosition checkPoint = commonService.select3dCheckPointByName(name);
|
if (StringUtils.isNull(checkPoint)) {
|
return null;
|
}
|
int range = 10;
|
String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
|
List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(checkPoint, range);
|
DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
|
if (StringUtils.isNull(dictRecord)) {
|
return null;
|
}
|
List<DistanceSuYuan> list = suYuanMapper.getDistanceSuYuan(dictRecord.getTableName(), ids3d);
|
AtomicInteger i = new AtomicInteger(0);
|
list.stream().forEach(s -> {
|
s.setName(checkPoint.getName());
|
i.getAndIncrement();
|
s.setVocsName(checkPoint.getName() + "-" + i.longValue());
|
});
|
if (StringUtils.isNotEmpty(list)) {
|
Collections.sort(list);
|
DistanceSuYuan max = list.get(0);
|
FeedbackDetail feedbackDetail = new FeedbackDetail(null, dictRecord.getTableName(),
|
max.getName(), max.getId(), max.getVocsName(), max.getVocsValue(), null, null, null, DateUtils.getNowDate());
|
feedbackMapper.insert(feedbackDetail);
|
result.put("feedbackId", feedbackDetail.getId());
|
}
|
result.put("data", list);
|
return result;
|
}
|
|
public Map<String, Object> selectSuYuan200(String name, Date date) {
|
Map<String, Object> result = new HashMap<String, Object>();
|
MonitorPointPosition checkPoint = commonService.select3dCheckPointByName(name);
|
if (StringUtils.isNull(checkPoint)) {
|
return null;
|
}
|
int range = 20;
|
String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
|
List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(checkPoint, range);
|
DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
|
if (StringUtils.isNull(dictRecord)) {
|
return null;
|
}
|
List<DistanceSuYuan> list = suYuanMapper.getDistanceSuYuan(dictRecord.getTableName(), ids3d);
|
AtomicInteger i = new AtomicInteger(0);
|
list.stream().forEach(s -> {
|
s.setName(checkPoint.getName());
|
i.getAndIncrement();
|
s.setVocsName(checkPoint.getName() + "-" + i.longValue());
|
});
|
if (StringUtils.isNotEmpty(list)) {
|
Collections.sort(list);
|
DistanceSuYuan max = list.get(0);
|
FeedbackDetail feedbackDetail = new FeedbackDetail(null, dictRecord.getTableName(),
|
max.getName(), max.getId(), max.getVocsName(), max.getVocsValue(), null, null, null, DateUtils.getNowDate());
|
feedbackMapper.insert(feedbackDetail);
|
result.put("feedbackId", feedbackDetail.getId());
|
}
|
result.put("data", list);
|
return result;
|
}
|
|
public Map<String, Object> selectSuYuan300(String name, Date date) {
|
Map<String, Object> result = new HashMap<String, Object>();
|
MonitorPointPosition checkPoint = commonService.select3dCheckPointByName(name);
|
if (StringUtils.isNull(checkPoint)) {
|
return null;
|
}
|
int range = 30;
|
String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
|
List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(checkPoint, range);
|
DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
|
if (StringUtils.isNull(dictRecord)) {
|
return null;
|
}
|
List<DistanceSuYuan> list = suYuanMapper.getDistanceSuYuan(dictRecord.getTableName(), ids3d);
|
AtomicInteger i = new AtomicInteger(0);
|
list.stream().forEach(s -> {
|
s.setName(checkPoint.getName());
|
i.getAndIncrement();
|
s.setVocsName(checkPoint.getName() + "-" + i.longValue());
|
});
|
if (StringUtils.isNotEmpty(list)) {
|
Collections.sort(list);
|
DistanceSuYuan max = list.get(0);
|
FeedbackDetail feedbackDetail = new FeedbackDetail(null, dictRecord.getTableName(),
|
max.getName(), max.getId(), max.getVocsName(), max.getVocsValue(), null, null, null, DateUtils.getNowDate());
|
feedbackMapper.insert(feedbackDetail);
|
result.put("feedbackId", feedbackDetail.getId());
|
}
|
result.put("data", list);
|
return result;
|
}
|
|
public Map<String, Object> selectSuYuan500(String name, Date date) {
|
Map<String, Object> result = new HashMap<String, Object>();
|
MonitorPointPosition checkPoint = commonService.select3dCheckPointByName(name);
|
if (StringUtils.isNull(checkPoint)) {
|
return null;
|
}
|
int range = 50;
|
String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
|
List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(checkPoint, range);
|
DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
|
if (StringUtils.isNull(dictRecord)) {
|
return null;
|
}
|
List<DistanceSuYuan> list = suYuanMapper.getDistanceSuYuan(dictRecord.getTableName(), ids3d);
|
AtomicInteger i = new AtomicInteger(0);
|
list.stream().forEach(s -> {
|
s.setName(checkPoint.getName());
|
i.getAndIncrement();
|
s.setVocsName(checkPoint.getName() + "-" + i.longValue());
|
});
|
if (StringUtils.isNotEmpty(list)) {
|
Collections.sort(list);
|
DistanceSuYuan max = list.get(0);
|
FeedbackDetail feedbackDetail = new FeedbackDetail(null, dictRecord.getTableName(),
|
max.getName(), max.getId(), max.getVocsName(), max.getVocsValue(), null, null, null, DateUtils.getNowDate());
|
feedbackMapper.insert(feedbackDetail);
|
result.put("feedbackId", feedbackDetail.getId());
|
}
|
result.put("data", list);
|
return result;
|
}
|
|
public List<SuYuanMonitorData> getMonitorData(String name) {
|
MonitorPointPosition checkPoint = commonService.select3dCheckPointByName(name);
|
if (StringUtils.isNull(checkPoint)) {
|
return null;
|
}
|
|
/*List<DictRecord> recordList = dictRecordMapper.selectDictRecordList(new DictRecord());
|
|
List<String> tableNames = new ArrayList<String>();
|
for (DictRecord dr : recordList) {
|
if (suYuanMapper.isTableExists(dr.getTableName()) > 0) {
|
tableNames.add(dr.getTableName());
|
}
|
}
|
|
return suYuanMapper.getMonitorData(tableNames, checkPoint.getX() + "_" + checkPoint.getY() + "_" + checkPoint.getZ());*/
|
|
Calendar calendar = Calendar.getInstance();
|
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
String end = DateUtils.getYyyyMmDdHh(calendar.getTime()); //dateFormat.format(calendar.getTime());
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
calendar.add(Calendar.DATE, -7);
|
String start = DateUtils.getYyyyMmDdHh(calendar.getTime());
|
|
return suYuanMapper.getNewMonitorData(checkPoint.getName(), start, end);
|
}
|
|
public int updateVocsName(Date date, String id, String vocsName) {
|
String table = "su_yuan_" + DateUtils.getYyyyMmDdHh(date); // new Date()
|
if (isTableExists(table) == 0) {
|
return 0;
|
}
|
|
//return suYuanMapper.updateVocsName(table, id, vocsName);
|
return 1;
|
}
|
|
public List<Qxsh> queryQxsh(Date date) {
|
String time = DateUtils.getYyyyMmDdHh(date);
|
|
return qxshMapper.selectByTime(time);
|
}
|
|
public List<List<Coordinate>> selectRects(Double[] x, Double[] y) {
|
List<List<Coordinate>> list = new ArrayList<>();
|
for (int i = 0; i < x.length; i++) {
|
list.add(CalculateUtils.calcRect(x[i], y[i]));
|
}
|
|
return list;
|
}
|
|
public SuYuan700 selectSuYuan700ById(String id, Date date) {
|
id = id.substring(0, id.lastIndexOf("_") + 1) + "0";
|
String time = DateUtils.getYyyyMmDdHhMmSs(date).substring(0, 13) + ":00:00";
|
|
return suYuanMapper.selectSuYuan700ById(id, time);
|
}
|
|
public SuYuan700 selectSuYuan46ById(String id, Date date) {
|
id = id.substring(0, id.lastIndexOf("_") + 1) + "0";
|
String time = DateUtils.getYyyyMmDdHhMmSs(date).substring(0, 13) + ":00:00";
|
|
return suYuanMapper.selectSuYuan46ById(id, time);
|
}
|
|
public String selectAddrByXY(double x, double y) {
|
List<Location> locations = locationMapper.selectByXY(x, y);
|
if (null != locations && locations.size() > 0) {
|
return locations.get(0).getName();
|
}
|
|
locations = locService.selectVocAddrs(x, y);
|
if (null != locations && locations.size() > 0) {
|
return locations.get(0).getName();
|
}
|
|
return null;
|
}
|
}
|