|
@@ -3,13 +3,14 @@ package com.gyee.impala.service.impl.master;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.gyee.impala.common.base.ExcludeQueryWrapper;
|
|
|
+import com.gyee.impala.common.config.datasource.KuduDataSourceConfig;
|
|
|
import com.gyee.impala.common.constant.Constants;
|
|
|
import com.gyee.impala.common.exception.CustomException;
|
|
|
import com.gyee.impala.common.feign.RemoteServiceBuilder;
|
|
|
import com.gyee.impala.common.result.ResultCode;
|
|
|
import com.gyee.impala.common.util.DateUtil;
|
|
|
import com.gyee.impala.common.util.SnowFlakeUtil;
|
|
|
-import com.gyee.impala.common.util.StationMapperUtil;
|
|
|
+import com.gyee.impala.common.util.GyeeUtil;
|
|
|
import com.gyee.impala.mapper.master.CaseperformanceMapper;
|
|
|
import com.gyee.impala.model.custom.TsDoubleData;
|
|
|
import com.gyee.impala.model.master.Caseperformance;
|
|
@@ -17,6 +18,7 @@ import com.gyee.impala.model.master.Windturbinepoint;
|
|
|
import com.gyee.impala.service.master.CaseperformanceService;
|
|
|
import com.gyee.impala.service.master.WindturbinepointService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.kudu.client.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -35,6 +37,8 @@ import java.util.stream.Collectors;
|
|
|
public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMapper, Caseperformance> implements CaseperformanceService {
|
|
|
|
|
|
@Autowired
|
|
|
+ private KuduDataSourceConfig kuduConfig;
|
|
|
+ @Autowired
|
|
|
private RemoteServiceBuilder remoteService;
|
|
|
@Autowired
|
|
|
private WindturbinepointService windturbinepointService;
|
|
@@ -54,63 +58,55 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
.le("intervals", Double.valueOf(temp[1]))
|
|
|
.ge("starttime", st)
|
|
|
.le("endtime", et);
|
|
|
-
|
|
|
- List<Caseperformance> list = null;
|
|
|
try {
|
|
|
- list = baseMapper.selectList(wrapper);
|
|
|
+ return baseMapper.selectList(wrapper);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
}
|
|
|
- return list;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean addPerformance(Caseperformance performance) {
|
|
|
- boolean flag = false;
|
|
|
- try {
|
|
|
- // 设置一个新ID
|
|
|
- if (StringUtils.isEmpty(performance.getId()))
|
|
|
- performance.setId(SnowFlakeUtil.generateId());
|
|
|
+ public boolean insertBatch(List<Caseperformance> list) {
|
|
|
+ if (list == null || list.size() == 0)
|
|
|
+ return false;
|
|
|
+ try{
|
|
|
+ insert(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- int code = baseMapper.insert(performance);
|
|
|
- if (code > 0) {
|
|
|
- flag = true;
|
|
|
- }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean deleteItem(Integer id) {
|
|
|
+ try {
|
|
|
+ baseMapper.deleteById(id);
|
|
|
+ return true;
|
|
|
} catch (CustomException e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
}
|
|
|
|
|
|
- return flag;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean removePerformance(Integer id) {
|
|
|
-
|
|
|
- int code = 0;
|
|
|
+ public boolean editItem(Caseperformance performance) {
|
|
|
try {
|
|
|
- code = baseMapper.deleteById(id);
|
|
|
- if (code > 0) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
+ baseMapper.updateById(performance);
|
|
|
+ return true;
|
|
|
} catch (CustomException e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean editPerformance(Caseperformance performance) {
|
|
|
+ public Caseperformance getPerformanceById(String id) {
|
|
|
try {
|
|
|
- int code = baseMapper.updateById(performance);
|
|
|
- if (code > 0) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
-
|
|
|
+ return baseMapper.selectById(id);
|
|
|
} catch (CustomException e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new CustomException(ResultCode.ERROR_DATA);
|
|
@@ -118,9 +114,15 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Caseperformance getPerformanceById(String id) {
|
|
|
- Caseperformance cp = baseMapper.selectById(id);
|
|
|
- return cp;
|
|
|
+ public Caseperformance getOneMaxTimeByWtId(String wtId) {
|
|
|
+ try {
|
|
|
+ List<Caseperformance> list = baseMapper.getOneMaxTimeByWtId(wtId);
|
|
|
+ if (list != null && list.size() > 0)
|
|
|
+ return list.get(0);
|
|
|
+ } catch (CustomException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -128,16 +130,16 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
Map<String, List> maps = new HashMap<>();
|
|
|
|
|
|
try {
|
|
|
- String[] codes = new String[]{Constants.POINT_SPEED, Constants.POINT_POWER};
|
|
|
+ String[] codes = new String[]{Constants.AI_SPEED, Constants.AI_POWER};
|
|
|
Caseperformance cp = getPerformanceById(id);
|
|
|
|
|
|
//查询测点名
|
|
|
List<Windturbinepoint> winds = windturbinepointService.getListByStationAndWtIdAndUniformCode(cp.getStationen(), cp.getWindturbineid(), codes);
|
|
|
|
|
|
//golden适配器取数据
|
|
|
- List<TsDoubleData> speedList = remoteService.ShardingService().getHistorySnapAI(winds.get(0).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ List<TsDoubleData> speedList = remoteService.adapter().getHistorySnapAI(winds.get(0).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
- List<TsDoubleData> powerList = remoteService.ShardingService().getHistorySnapAI(winds.get(1).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ List<TsDoubleData> powerList = remoteService.adapter().getHistorySnapAI(winds.get(1).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
|
|
|
if (speedList == null || powerList == null)
|
|
@@ -262,8 +264,7 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
.sorted(Comparator.comparing(Caseperformance::getWindturbineid))
|
|
|
.collect(Collectors.groupingBy(Caseperformance::getWindturbineid));
|
|
|
|
|
|
- String wtId = StationMapperUtil.stationCN(station);
|
|
|
- int i = 0; //前端树状展示,需要id
|
|
|
+ String wtId = GyeeUtil.stationCN(station);
|
|
|
for (Map.Entry<String, List<Caseperformance>> entry : singleMap.entrySet()){
|
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
|
String key = entry.getKey();
|
|
@@ -272,7 +273,7 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
List<Caseperformance> value = entry.getValue();
|
|
|
List childList = new ArrayList();
|
|
|
for (Caseperformance performance : value){
|
|
|
- Map<String, Object> childMap = new LinkedHashMap<>();
|
|
|
+ Map<String, Object> childMap = new TreeMap<>();
|
|
|
childMap.put("id", performance.getId());
|
|
|
childMap.put("wtId", key);
|
|
|
childMap.put("windturbineId", performance.getStarttime() + "性能下降");
|
|
@@ -280,12 +281,11 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
childMap.put("et", performance.getEndtime());
|
|
|
childList.add(childMap);
|
|
|
}
|
|
|
- map.put("id", i);
|
|
|
+ map.put("id", SnowFlakeUtil.generateId());
|
|
|
map.put("windturbineId", windId);
|
|
|
map.put("children", childList);
|
|
|
|
|
|
list.add(map);
|
|
|
- i++;
|
|
|
}
|
|
|
|
|
|
return list;
|
|
@@ -296,30 +296,6 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean insertOrUpdate(List<Caseperformance> list) {
|
|
|
- boolean flag = false;
|
|
|
-
|
|
|
- if (list == null || list.size() < 0)
|
|
|
- return flag;
|
|
|
-
|
|
|
- try{
|
|
|
- list.stream().forEach(obj -> {
|
|
|
- if (StringUtils.isEmpty(obj.getId())) {
|
|
|
- // 新增
|
|
|
- obj.setId(SnowFlakeUtil.generateId());
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- flag = saveOrUpdateBatch(list, list.size());
|
|
|
-
|
|
|
- } catch (CustomException e) {
|
|
|
- log.error(e.getMessage());
|
|
|
- throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
- }
|
|
|
-
|
|
|
- return flag;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 查询单台风机风速功率
|
|
@@ -335,17 +311,17 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
if (StringUtils.isEmpty(id))
|
|
|
return maps;
|
|
|
|
|
|
- String[] codes = new String[]{Constants.POINT_SPEED, Constants.POINT_POWER, Constants.POINT_POWER_LLGL};
|
|
|
+ String[] codes = new String[]{Constants.AI_SPEED, Constants.AI_POWER, Constants.AI_POWER_LLGL};
|
|
|
//单台风机
|
|
|
Caseperformance cp = getPerformanceById(id);
|
|
|
//查询测点名
|
|
|
List<Windturbinepoint> winds = windturbinepointService.getListByStationAndWtIdAndUniformCode(cp.getStationen(), cp.getWindturbineid(), codes);
|
|
|
//golden适配器取数据
|
|
|
- List<TsDoubleData> speedList = remoteService.ShardingService().getHistorySnapAI(winds.get(0).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ List<TsDoubleData> speedList = remoteService.adapter().getHistorySnapAI(winds.get(0).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
- List<TsDoubleData> powerList = remoteService.ShardingService().getHistorySnapAI(winds.get(1).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ List<TsDoubleData> powerList = remoteService.adapter().getHistorySnapAI(winds.get(1).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
- List<TsDoubleData> llglList = remoteService.ShardingService().getHistorySnapAI(winds.get(2).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ List<TsDoubleData> llglList = remoteService.adapter().getHistorySnapAI(winds.get(2).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
|
|
|
if (speedList == null || powerList == null || llglList == null)
|
|
@@ -378,4 +354,46 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 由于mybatis-plus存储的中文乱码
|
|
|
+ * 采用原生写法
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void insert(List<Caseperformance> list) throws KuduException {
|
|
|
+ KuduTable kuduTable = kuduConfig.kuduClient.openTable("impala::gyee_sample_kudu.caseperformance");
|
|
|
+ KuduSession kuduSession = kuduConfig.kuduSession();
|
|
|
+ int i = 0;
|
|
|
+ for (Caseperformance obj : list){
|
|
|
+ Insert insert = kuduTable.newInsert();
|
|
|
+ // 获取Row对象,设置插入的值
|
|
|
+ PartialRow row = insert.getRow();
|
|
|
+ row.addObject("id", SnowFlakeUtil.generateId());
|
|
|
+ row.addObject("tag", obj.getTag());
|
|
|
+ row.addObject("stationen", obj.getStationen());
|
|
|
+ row.addObject("windturbineid", obj.getWindturbineid());
|
|
|
+ row.addObject("starttime", obj.getStarttime());
|
|
|
+ row.addObject("endtime", obj.getEndtime());
|
|
|
+ row.addObject("intervals", obj.getIntervals());
|
|
|
+ row.addObject("algtype", obj.getAlgtype());
|
|
|
+ row.addObject("stationcn", obj.getStationcn());
|
|
|
+ row.addObject("manufacturer", obj.getManufacturer());
|
|
|
+ row.addObject("model", obj.getModel());
|
|
|
+ row.addObject("remark", obj.getRemark());
|
|
|
+ row.addObject("category", obj.getCategory());
|
|
|
+ row.addObject("createtime", DateUtil.getCurrentDate());
|
|
|
+
|
|
|
+ // 先不提交kudu
|
|
|
+ kuduSession.apply(insert);
|
|
|
+ i ++;
|
|
|
+ if (i % kuduConfig.getCount() == 0)
|
|
|
+ kuduSession.flush(); //批量写入kudu
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最后,补加一条批量写入
|
|
|
+ kuduSession.flush();
|
|
|
+
|
|
|
+ // 关闭和kudu的会话
|
|
|
+ kuduSession.close();
|
|
|
+ }
|
|
|
}
|