|
@@ -0,0 +1,79 @@
|
|
|
+package com.gyee.impala.service.impl.master.diagnose;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+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.mapper.master.diagnose.DiagnosepointMapper;
|
|
|
+import com.gyee.impala.model.master.diagnose.Diagnosepoint;
|
|
|
+import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
|
|
|
+import com.gyee.impala.service.master.diagnose.DiagnosepointService;
|
|
|
+import org.apache.kudu.client.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+public class DiagnosepointServiceImpl extends ServiceImpl<DiagnosepointMapper, Diagnosepoint> implements DiagnosepointService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private KuduDataSourceConfig kuduConfig;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Diagnosepoint> getDiagnosepointList() {
|
|
|
+
|
|
|
+ QueryWrapper<Diagnosepoint> wrapper = new QueryWrapper<>();
|
|
|
+ return baseMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void insertItem(Diagnosepoint obj) {
|
|
|
+ try {
|
|
|
+ insert(obj);
|
|
|
+
|
|
|
+ } catch (KuduException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 由于mybatis-plus存储的中文乱码
|
|
|
+ * 采用原生写法
|
|
|
+ * @param obj
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void insert(Diagnosepoint obj) throws KuduException {
|
|
|
+ KuduTable kuduTable = kuduConfig.kuduClient.openTable("impala::gyee_sample_kudu.diagnosepoint");
|
|
|
+ KuduSession kuduSession = kuduConfig.kuduSession();
|
|
|
+
|
|
|
+ Insert insert = kuduTable.newInsert();
|
|
|
+ // 获取Row对象,设置插入的值
|
|
|
+ PartialRow row = insert.getRow();
|
|
|
+ row.addObject("id", SnowFlakeUtil.generateId());
|
|
|
+ row.addObject("stationcn", obj.getStationcn());
|
|
|
+ row.addObject("stationen", obj.getStationen());
|
|
|
+ row.addObject("model", obj.getModel());
|
|
|
+ row.addObject("uniformcode", obj.getUniformcode());
|
|
|
+ row.addObject("name", obj.getName());
|
|
|
+ row.addObject("unit", obj.getUnit());
|
|
|
+ row.addObject("remark", obj.getRemark());
|
|
|
+ row.addObject("ordernum", obj.getOrdernum());
|
|
|
+
|
|
|
+ // 先不提交kudu
|
|
|
+ kuduSession.apply(insert);
|
|
|
+ // 最后,补加一条批量写入
|
|
|
+ kuduSession.flush();
|
|
|
+ // 关闭和kudu的会话
|
|
|
+ kuduSession.close();
|
|
|
+ }
|
|
|
+}
|