|
@@ -2,12 +2,17 @@ package com.gyee.impala.service.impl.master;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.gyee.impala.common.base.ExcludeQueryWrapper;
|
|
|
+import com.gyee.impala.common.config.datasource.KuduDataSourceConfig;
|
|
|
import com.gyee.impala.common.exception.CustomException;
|
|
|
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.model.master.Windturbinepoint;
|
|
|
import com.gyee.impala.mapper.master.WindturbinepointMapper;
|
|
|
import com.gyee.impala.service.master.WindturbinepointService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.apache.kudu.client.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -26,14 +31,18 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class WindturbinepointServiceImpl extends ServiceImpl<WindturbinepointMapper, Windturbinepoint> implements WindturbinepointService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private KuduDataSourceConfig kuduConfig;
|
|
|
|
|
|
@Cacheable(value = "windturbinepointall")
|
|
|
@Override
|
|
|
- public List<Windturbinepoint> getAll(String wtId, String widget) {
|
|
|
+ public List<Windturbinepoint> getAll(String wtId, String widget, String type) {
|
|
|
try {
|
|
|
ExcludeQueryWrapper<Windturbinepoint> wrapper = new ExcludeQueryWrapper<>();
|
|
|
wrapper.eq("windturbineid", wtId)
|
|
|
- .eq("widgetcode", widget);
|
|
|
+ .eq("widgetcode", widget)
|
|
|
+ .eq("pointtype", type)
|
|
|
+ .orderByAsc("point");
|
|
|
|
|
|
List<Windturbinepoint> list = baseMapper.selectList(wrapper);
|
|
|
|
|
@@ -66,10 +75,9 @@ public class WindturbinepointServiceImpl extends ServiceImpl<WindturbinepointMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean editItem(Windturbinepoint obj) {
|
|
|
+ public void editItem(Windturbinepoint obj) {
|
|
|
try {
|
|
|
baseMapper.updateById(obj);
|
|
|
- return true;
|
|
|
} catch (CustomException e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new CustomException(ResultCode.ERROR_DATA);
|
|
@@ -77,24 +85,22 @@ public class WindturbinepointServiceImpl extends ServiceImpl<WindturbinepointMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean insertItem(Windturbinepoint obj) {
|
|
|
+ public void insertBatch(List<Windturbinepoint> list) {
|
|
|
try {
|
|
|
- baseMapper.insert(obj);
|
|
|
- return true;
|
|
|
- } catch (CustomException e) {
|
|
|
+ insert(list);
|
|
|
+ } catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean deleteItem(String id) {
|
|
|
+ public void deleteItem(String id) {
|
|
|
QueryWrapper<Windturbinepoint> wrapper = new QueryWrapper<>();
|
|
|
wrapper.eq("id", id);
|
|
|
|
|
|
try {
|
|
|
baseMapper.delete(wrapper);
|
|
|
- return true;
|
|
|
} catch (CustomException e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new CustomException(ResultCode.ERROR_DATA);
|
|
@@ -144,7 +150,7 @@ public class WindturbinepointServiceImpl extends ServiceImpl<WindturbinepointMap
|
|
|
wrapper.eq("stationen", station)
|
|
|
.eq("windturbineid", wtId)
|
|
|
.in("uniformcode", uniformCode)
|
|
|
- .orderByAsc("uniformcode");
|
|
|
+ .orderByAsc("uniformcode");
|
|
|
|
|
|
List<Windturbinepoint> list = baseMapper.selectList(wrapper);
|
|
|
|
|
@@ -173,4 +179,50 @@ public class WindturbinepointServiceImpl extends ServiceImpl<WindturbinepointMap
|
|
|
throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 由于mybatis-plus存储的中文乱码
|
|
|
+ * 采用原生写法
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void insert(List<Windturbinepoint> list) throws KuduException {
|
|
|
+ KuduTable kuduTable = kuduConfig.kuduClient.openTable("impala::gyee_sample_kudu.windturbinepoint");
|
|
|
+ KuduSession kuduSession = kuduConfig.kuduSession();
|
|
|
+ int i = 0;
|
|
|
+ for (Windturbinepoint obj : list){
|
|
|
+ Insert insert = kuduTable.newInsert();
|
|
|
+ // 获取Row对象,设置插入的值
|
|
|
+ PartialRow row = insert.getRow();
|
|
|
+ row.addObject("id", SnowFlakeUtil.generateId());
|
|
|
+ row.addObject("windturbineid", obj.getWindturbineid());
|
|
|
+ row.addObject("widget", obj.getWidget());
|
|
|
+ row.addObject("widgetcode", obj.getWidgetcode());
|
|
|
+ row.addObject("point", obj.getPoint());
|
|
|
+ row.addObject("pointdes", obj.getPointdes());
|
|
|
+ row.addObject("widget2", obj.getWidget2());
|
|
|
+ row.addObject("widgetcode2", obj.getWidgetcode2());
|
|
|
+ row.addObject("uniformcode", obj.getUniformcode());
|
|
|
+ row.addObject("windturbinename", obj.getWindturbinename());
|
|
|
+ row.addObject("model", obj.getModel());
|
|
|
+ row.addObject("pointtype", obj.getPointtype());
|
|
|
+ row.addObject("stationcn", obj.getStationcn());
|
|
|
+ row.addObject("stationen", obj.getStationen());
|
|
|
+ row.addObject("manufacturer", obj.getManufacturer());
|
|
|
+ row.addObject("remark", obj.getRemark());
|
|
|
+ row.addObject("category", obj.getCategory());
|
|
|
+
|
|
|
+ // 先不提交kudu
|
|
|
+ kuduSession.apply(insert);
|
|
|
+ i ++;
|
|
|
+ if (i % kuduConfig.getCount() == 0)
|
|
|
+ kuduSession.flush(); //批量写入kudu
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最后,补加一条批量写入
|
|
|
+ kuduSession.flush();
|
|
|
+ // 关闭和kudu的会话
|
|
|
+ kuduSession.close();
|
|
|
+ }
|
|
|
+
|
|
|
}
|