Browse Source

增加性能接口

wangchangsheng 3 years ago
parent
commit
16c64b4066

+ 31 - 20
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/common/base/ExcludeQueryWrapper.java

@@ -1,92 +1,103 @@
 package com.gyee.sampleimpala.common.base;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 
+import java.util.Collection;
 import java.util.Objects;
 
 public class ExcludeQueryWrapper<T> extends QueryWrapper<T> {
 
     @Override
     public QueryWrapper<T> eq(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.eq(condition, column, val);
     }
 
     @Override
+    public QueryWrapper<T> in(boolean condition, String column, Collection<?> val) {
+        condition = !(null == val || val.size() <= 0);
+//        condition = !ObjectUtils.isEmpty(val);
+        return super.in(condition, column, val);
+    }
+
+    @Override
     public QueryWrapper<T> ne(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.ne(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> gt(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.gt(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> ge(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.ge(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> lt(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.lt(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> le(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.le(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> like(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.like(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> notLike(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.notLike(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> likeLeft(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.likeLeft(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> likeRight(boolean condition, String column, Object val) {
-        condition = !Objects.isNull(val);
+        condition = !ObjectUtils.isEmpty(val);
         return super.likeRight(condition, column, val);
     }
 
     @Override
     public QueryWrapper<T> between(boolean condition, String column, Object val1, Object val2) {
-        if(Objects.isNull(val1) && Objects.isNull(val2)){
+        if (ObjectUtils.isEmpty(val1) && ObjectUtils.isEmpty(val2)) {
             condition = false;
-        }else if(Objects.isNull(val1)){
-            return super.lt(true,column,val2);
-        }else if(Objects.isNull(val2)){
-            return super.ge(true,column,val1);
+        } else if (ObjectUtils.isEmpty(val1)) {
+            return super.lt(true, column, val2);
+        } else if (ObjectUtils.isEmpty(val2)) {
+            return super.ge(true, column, val1);
         }
         return super.between(condition, column, val1, val2);
     }
 
     @Override
     public QueryWrapper<T> notBetween(boolean condition, String column, Object val1, Object val2) {
-        if(Objects.isNull(val1) && Objects.isNull(val2)){
+        if (ObjectUtils.isEmpty(val1) && ObjectUtils.isEmpty(val2)) {
             condition = false;
-        }else if(Objects.isNull(val1)){
-            return super.lt(true,column,val2);
-        }else if(Objects.isNull(val2)){
-            return super.ge(true,column,val1);
+        } else if (ObjectUtils.isEmpty(val1)) {
+            return super.lt(true, column, val2);
+        } else if (ObjectUtils.isEmpty(val2)) {
+            return super.ge(true, column, val1);
         }
         return super.notBetween(condition, column, val1, val2);
     }
+
+
 }

+ 4 - 4
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/controller/CaseFaultController.java

@@ -32,7 +32,7 @@ public class CaseFaultController {
      * @return
      */
     @GetMapping("/fault/list")
-    public JSONObject stationAll(String station, String[] model, String[] widget,
+    public JSONObject faultList(String station, String[] model, String[] widget,
                                  String st, String et){
         List<Casefault> list = casefaultService.getAll(station, model, widget, st, et);
         return JsonResult.successData(ResultCode.SUCCESS, list);
@@ -45,7 +45,7 @@ public class CaseFaultController {
      * @return
      */
     @PostMapping("/item/insert")
-    public JSONObject stationInsert(@RequestBody Casefault obj){
+    public JSONObject faultInsert(@RequestBody Casefault obj){
         boolean flag = casefaultService.insertItem(obj);
         if (flag){
             return JsonResult.success(ResultCode.SUCCESS);
@@ -61,7 +61,7 @@ public class CaseFaultController {
      * @return
      */
     @PostMapping("/item/edit")
-    public JSONObject stationEdit(@RequestBody Casefault obj){
+    public JSONObject faultEdit(@RequestBody Casefault obj){
         System.out.println(obj.toString());
         boolean flag = casefaultService.editItem(obj);
         if (flag){
@@ -79,7 +79,7 @@ public class CaseFaultController {
      */
     @PostMapping("/item/delete")
     @ResponseBody
-    public JSONObject stationDelete(String id){
+    public JSONObject faultDelete(String id){
         boolean flag = casefaultService.deleteItem(id);
         if (flag){
             return JsonResult.success(ResultCode.SUCCESS);

+ 10 - 2
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/controller/CaseperformanceController.java

@@ -105,8 +105,16 @@ public class CaseperformanceController {
     }
 
 
-
-    public JSONObject  getCurve() {
+    /**
+     *
+     * @param id 样本id(数组)
+     * @param interval 数据时间间隔
+     * @return
+     */
+    public JSONObject getCurve(
+            @RequestParam(value = "id",required = false) Integer[] id,
+            @RequestParam(value = "interval",required = false) Integer interval
+    ) {
 
         return null;
     }

+ 3 - 3
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/model/kudu/Caseperformance.java

@@ -8,7 +8,7 @@ import lombok.EqualsAndHashCode;
 
 /**
  * <p>
- * 
+ *
  * </p>
  *
  * @author chenmh
@@ -19,9 +19,9 @@ import lombok.EqualsAndHashCode;
 @TableName("caseperformance")
 public class Caseperformance extends Model<Caseperformance> {
 
-    private static final long serialVersionUID=1L;
+    private static final long serialVersionUID = 1L;
 
-      private Integer id;
+    private Long id;
 
     private Integer tag;
 

+ 5 - 3
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/model/kudu/Windturbine.java

@@ -2,13 +2,15 @@ package com.gyee.sampleimpala.model.kudu;
 
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+
 import java.io.Serializable;
+
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
 /**
  * <p>
- * 
+ *
  * </p>
  *
  * @author chenmh
@@ -19,9 +21,9 @@ import lombok.EqualsAndHashCode;
 @TableName("windturbine")
 public class Windturbine extends Model<Windturbine> {
 
-    private static final long serialVersionUID=1L;
+    private static final long serialVersionUID = 1L;
 
-      private String id;
+    private String id;
 
     private String station;
 

+ 46 - 7
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/service/custom/GoldenService.java

@@ -5,12 +5,18 @@ import com.gyee.sampleimpala.common.exception.CustomException;
 import com.gyee.sampleimpala.common.feign.RemoteServiceBuilder;
 import com.gyee.sampleimpala.common.result.ResultCode;
 import com.gyee.sampleimpala.model.custom.TsPointData;
+import com.gyee.sampleimpala.model.kudu.Caseperformance;
+import com.gyee.sampleimpala.model.kudu.Windturbinepoint;
+import com.gyee.sampleimpala.service.kudu.CaseperformanceService;
+import com.gyee.sampleimpala.service.kudu.WindturbinepointService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Slf4j
 @Service
@@ -19,25 +25,44 @@ public class GoldenService {
     @Autowired
     private RemoteServiceBuilder remoteService;
 
+    @Autowired
+    private WindturbinepointService windturbinepointService;
+
+
+    @Autowired
+    private CaseperformanceService caseperformanceService;
+
 
     /**
      * 查询原始数据
-     * @param point
+     * @param points
      * @param startTs  精确到毫秒
      * @param endTs
      * @param interval
      * @return
      */
-    public List<TsPointData> getOriginalData(String point, long startTs, long endTs, int interval){
+    public List<Map> getOriginalData(String[] points, long startTs, long endTs, int interval){
 
-        List<TsPointData> list = new ArrayList<>();
+        List<Map> list = new ArrayList<>();
 
         try{
-            if (interval <= 0){
-                list = remoteService.ShardingService().getHistoryRaw(point, startTs, endTs);
-            }else {
-                list = remoteService.ShardingService().getHistorySnap(point, startTs, endTs, interval);
+
+            for (String point :points){
+                Windturbinepoint w =  windturbinepointService.getByPoint(point);
+                List<TsPointData> data = new ArrayList<>();
+                Map m = new HashMap();
+                if (interval <= 0){
+                    data = remoteService.ShardingService().getHistoryRaw(point, startTs, endTs);
+                }else {
+                    data = remoteService.ShardingService().getHistorySnap(point, startTs, endTs, interval);
+                }
+                m.put("name",w.getPointdes());
+                m.put("code",w.getWidgetcode());
+                m.put("point",w.getPoint());
+                m.put("list",data);
+                list.add(m);
             }
+
         } catch (Exception e){
             log.error(e.getMessage());
             throw new CustomException(ResultCode.ERROR_DATA);
@@ -45,4 +70,18 @@ public class GoldenService {
 
         return list;
     }
+
+
+
+
+    public List<Map> getOriginalData(Integer[] id, int interval){
+        for (Integer i :id ){
+            Caseperformance cp = caseperformanceService.getPerformanceByid(i);
+
+//            data = remoteService.ShardingService().getHistorySnap(point, startTs, endTs, interval);
+        }
+
+        return null;
+
+    }
 }

+ 43 - 3
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/service/impl/kudu/CasefaultalgServiceImpl.java

@@ -1,10 +1,13 @@
 package com.gyee.sampleimpala.service.impl.kudu;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.sampleimpala.common.base.ExcludeQueryWrapper;
 import com.gyee.sampleimpala.common.exception.CustomException;
 import com.gyee.sampleimpala.common.result.ResultCode;
 import com.gyee.sampleimpala.mapper.kudu.CasefaultalgMapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.sampleimpala.model.kudu.Casefault;
 import com.gyee.sampleimpala.model.kudu.Casefaultalg;
 import com.gyee.sampleimpala.service.kudu.CasefaultalgService;
 import org.springframework.stereotype.Service;
@@ -17,7 +20,7 @@ import java.util.stream.Collectors;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author chenmh
@@ -32,7 +35,7 @@ public class CasefaultalgServiceImpl extends ServiceImpl<CasefaultalgMapper, Cas
         if (StringUtils.isEmpty(ids))
             return list;
 
-        try{
+        try {
             // string数组转成List<Integer>
             List<Integer> ls = Arrays.stream(ids).map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
             list = baseMapper.selectBatchIds(ls);
@@ -49,7 +52,7 @@ public class CasefaultalgServiceImpl extends ServiceImpl<CasefaultalgMapper, Cas
     public boolean insertOrUpdate(List<Casefaultalg> list) {
         boolean flag = false;
 
-        try{
+        try {
             flag = saveOrUpdateBatch(list);
         } catch (CustomException e) {
             log.error(e.getMessage());
@@ -58,4 +61,41 @@ public class CasefaultalgServiceImpl extends ServiceImpl<CasefaultalgMapper, Cas
 
         return flag;
     }
+
+    @Override
+    public List<Casefaultalg> getAll(String station, String[] model, String[] widget, String st, String et) {
+
+        ExcludeQueryWrapper<Casefaultalg> wrapper = new ExcludeQueryWrapper<>();
+        wrapper.eq("stationid", station)
+                .in("modelid", model)
+                .in("labels", widget)
+                .ge("faultTime", st)
+                .le("faultTime", et);
+
+        List<Casefaultalg> list = new ArrayList<>();
+        try {
+            list = baseMapper.selectList(wrapper);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+
+        return list;
+    }
+
+    @Override
+    public boolean removeFaultAlgById(String id) {
+        QueryWrapper<Casefaultalg> query = new QueryWrapper<>();
+        query.eq("id", id);
+
+        try {
+            baseMapper.delete(query);
+            return true;
+        } catch (CustomException e) {
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+    }
+
+
 }

+ 84 - 1
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/service/impl/kudu/CaseperformanceServiceImpl.java

@@ -2,14 +2,21 @@ package com.gyee.sampleimpala.service.impl.kudu;
 
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.sampleimpala.common.base.ExcludeQueryWrapper;
+import com.gyee.sampleimpala.common.exception.CustomException;
+import com.gyee.sampleimpala.common.result.ResultCode;
+import com.gyee.sampleimpala.common.util.SnowFlakeGenerator;
 import com.gyee.sampleimpala.mapper.kudu.CaseperformanceMapper;
 import com.gyee.sampleimpala.model.kudu.Caseperformance;
 import com.gyee.sampleimpala.service.kudu.CaseperformanceService;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author chenmh
@@ -18,4 +25,80 @@ import org.springframework.stereotype.Service;
 @Service
 public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMapper, Caseperformance> implements CaseperformanceService {
 
+    @Override
+    public List<Caseperformance> getPerformanceList(String station, String[] model, Integer tag, String st, String et) {
+        ExcludeQueryWrapper<Caseperformance> wrapper = new ExcludeQueryWrapper<>();
+        wrapper.eq("stationen", station)
+                .in("model", model)
+                .eq("tag", tag)
+                .ge("starttime", st)
+                .le("endtime", et);
+
+        List<Caseperformance> list = new ArrayList<>();
+        try {
+            list = baseMapper.selectList(wrapper);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+        return list;
+    }
+
+    @Override
+    public boolean addPerformance(Caseperformance performance) {
+        try {
+            // 设置一个新ID
+            if (performance != null && performance.getId() <= 0)
+                performance.setId(Long.valueOf(SnowFlakeGenerator.generateId()));
+
+            int code = baseMapper.insert(performance);
+            if (code > 0) {
+                return true;
+            }
+            return false;
+        } catch (CustomException e) {
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+    }
+
+    @Override
+    public boolean removePerformance(Integer id) {
+
+        int code = 0;
+        try {
+            code = baseMapper.deleteById(id);
+            if (code > 0) {
+                return true;
+            }
+            return false;
+        } catch (CustomException e) {
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+
+    }
+
+    @Override
+    public boolean editPerformance(Caseperformance performance) {
+        try {
+            int code = baseMapper.updateById(performance);
+            if (code > 0) {
+                return true;
+            }
+            return false;
+
+        } catch (CustomException e) {
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+    }
+
+    @Override
+    public Caseperformance getPerformanceByid(Integer id) {
+        Caseperformance cp = baseMapper.selectById(id);
+        return cp;
+    }
+
+
 }

+ 16 - 0
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/service/impl/kudu/WindturbinepointServiceImpl.java

@@ -101,4 +101,20 @@ public class WindturbinepointServiceImpl extends ServiceImpl<WindturbinepointMap
             throw new CustomException(ResultCode.ERROR_DATA);
         }
     }
+
+    @Override
+    public Windturbinepoint getByPoint(String point) {
+        List<Windturbinepoint> list = new ArrayList<>();
+        try {
+            ExcludeQueryWrapper<Windturbinepoint> wrapper = new ExcludeQueryWrapper<>();
+            wrapper.eq("point", point);
+
+            list = baseMapper.selectList(wrapper);
+
+        } catch (CustomException e){
+            log.error(e.getMessage());
+            throw new CustomException(ResultCode.ERROR_DATA);
+        }
+        return list.get(0);
+    }
 }

+ 19 - 0
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/service/kudu/CasefaultalgService.java

@@ -28,4 +28,23 @@ public interface CasefaultalgService extends IService<Casefaultalg> {
      * @return
      */
     boolean insertOrUpdate(List<Casefaultalg> list);
+
+    /**
+     * 根据条查询故障
+     * @param station  场站
+     * @param model    风机型号
+     * @param widget   故障部件
+     * @param st       开始时间
+     * @param et       结束时间
+     * @return
+     */
+    List<Casefaultalg> getAll(String station, String[] model, String[] widget, String st, String et);
+
+
+    /**
+     * 通过id删除数据
+     * @param id ID
+     * @return
+     */
+    boolean removeFaultAlgById(String id);
 }

+ 52 - 1
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/service/kudu/CaseperformanceService.java

@@ -3,9 +3,11 @@ package com.gyee.sampleimpala.service.kudu;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.gyee.sampleimpala.model.kudu.Caseperformance;
 
+import java.util.List;
+
 /**
  * <p>
- *  服务类
+ * 服务类
  * </p>
  *
  * @author chenmh
@@ -13,4 +15,53 @@ import com.gyee.sampleimpala.model.kudu.Caseperformance;
  */
 public interface CaseperformanceService extends IService<Caseperformance> {
 
+    /**
+     * 获取样本数据
+     *
+     * @param station 场站
+     * @param model   风机模型
+     * @param tag     样本类型
+     * @param st      开始时间
+     * @param et      结束时间
+     * @return
+     */
+    List<Caseperformance> getPerformanceList(String station, String[] model, Integer tag,
+                                             String st, String et);
+
+
+    /**
+     * 编辑样本
+     *
+     * @param performance 样本对象
+     * @return
+     */
+    boolean addPerformance(Caseperformance performance);
+
+
+    /**
+     * 删除样本
+     *
+     * @param id 样本id
+     * @return
+     */
+    boolean removePerformance(Integer id);
+
+
+    /**
+     * 编辑样本
+     *
+     * @param performance 样本对象
+     * @return
+     */
+    boolean editPerformance(Caseperformance performance);
+
+    /**
+     * 根据id获取样本
+     *
+     * @param id 样本id
+     * @return
+     */
+    Caseperformance getPerformanceByid(Integer id);
+
+
 }

+ 7 - 0
gyee-sample-impala/src/main/java/com/gyee/sampleimpala/service/kudu/WindturbinepointService.java

@@ -51,4 +51,11 @@ public interface WindturbinepointService extends IService<Windturbinepoint> {
      * @return
      */
     boolean deleteItem(String id);
+
+    /**
+     * 通过point获取一条数据
+     * @param point
+     * @return
+     */
+    Windturbinepoint getByPoint(String point);
 }

+ 2 - 2
gyee-sample-impala/src/main/resources/mapper/CaseperformanceMapper.xml

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.gyee.sampleimpala.mapper.CaseperformanceMapper">
+<mapper namespace="com.gyee.sampleimpala.mapper.kudu.CaseperformanceMapper">
 
     <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.gyee.sampleimpala.model.Caseperformance">
+    <resultMap id="BaseResultMap" type="com.gyee.sampleimpala.model.kudu.Caseperformance">
         <id column="id" property="id" />
         <result column="tag" property="tag" />
         <result column="stationen" property="stationen" />