package com.yssh.service.impl;
|
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import com.yssh.utils.*;
|
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.LogFactory;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Service;
|
|
import com.google.common.collect.Lists;
|
import com.yssh.dao.DictRecordMapper;
|
import com.yssh.dao.FeedbackMapper;
|
import com.yssh.dao.SuYuanMapper;
|
import com.yssh.entity.DictRecord;
|
import com.yssh.entity.DistanceSuYuan;
|
import com.yssh.entity.FeedbackDetail;
|
import com.yssh.entity.MonitorPointPosition;
|
import com.yssh.entity.SuYuan;
|
import com.yssh.entity.SuYuan2d;
|
import com.yssh.entity.SuYuan3d;
|
import com.yssh.entity.SuYuanMonitorData;
|
import com.yssh.service.IAsyncService;
|
import com.yssh.service.ICommonService;
|
import com.yssh.service.ISuYuanService;
|
|
import javax.annotation.Resource;
|
|
@Service
|
public class SuYuanServiceImpl implements ISuYuanService {
|
|
protected final Log logger = LogFactory.getLog(this.getClass());
|
|
@Resource
|
private SuYuanMapper suYuanMapper;
|
|
@Resource
|
private IAsyncService asyncService;
|
|
@Resource
|
private DictRecordMapper dictRecordMapper;
|
|
@Resource
|
private ICommonService commonService;
|
|
@Resource
|
private FeedbackMapper feedbackMapper;
|
|
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH");
|
|
//@Transactional
|
@Override
|
@Async("threadPoolTaskExecutor")
|
public void insertSuYuanDatas(List<SuYuan> lists, String time) throws Exception {
|
//插入数据
|
List<List<SuYuan>> list = Lists.partition(lists, IAsyncService.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() + "条数据入库完成-----");
|
}
|
|
@Override
|
public Integer isTableExists(String tableName) {
|
return suYuanMapper.isTableExists(tableName);
|
}
|
|
@Override
|
public int createNewTable(String tableName) {
|
return suYuanMapper.createTable(tableName);
|
}
|
|
@Override
|
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);
|
}
|
|
@Override
|
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);
|
}
|
|
@Override
|
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;
|
}
|
|
@Override
|
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;
|
}
|
|
@Override
|
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;
|
}
|
|
@Override
|
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;
|
}
|
|
@Override
|
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>();
|
recordList.stream().forEach(s -> {
|
tableNames.add(s.getTableName());
|
});
|
return suYuanMapper.getMonitorData(tableNames, checkPoint.getX() + "_" + checkPoint.getY() + "_" + checkPoint.getZ());
|
}
|
|
@Override
|
public int updateVocsName(Date date, String id, String vocsName) {
|
String table = "su_yuan_" + dateFormat.format(new Date());
|
if (isTableExists(table) == 0) {
|
return 0;
|
}
|
|
return suYuanMapper.updateVocsName(table, id, vocsName);
|
}
|
}
|