Forráskód Böngészése

update ---- 计量点数据改为原业务逻辑

QuietShadow 3 éve
szülő
commit
8e876b9846

+ 1 - 1
src/main/java/com/steerinfo/ems/emswaterrealtime/mapper/EmsWaterRealtimeMapper.xml

@@ -634,7 +634,7 @@
     (SELECT t.ITEMID FROM T_RM_CALPOINT t JOIN FORMULA f ON t.ITEMID =f.CODE)
   </select>
   <select id="getWaterTenMinutes" resultMap="BaseResultMap">
-    SELECT w.ADDRESSCODE,w.FORVALUE AS SUMVALUE,
+    SELECT c.ITEMID METERID,c.TAG_COL M_NAME,c.TAG_TABLE M_USERTYPE, w.ADDRESSCODE,w.FORVALUE AS SUMVALUE,
 <!--(w.FORVALUE - w.REVVALUE) -->
     c.BTYPE2 AS M_TYPE,  c.SOURCE_TYPE AS M_MATERIAL
     FROM T_RM_LOCATION l

+ 5 - 0
src/main/java/com/steerinfo/ems/emswaterrealtime/service/IEmsWaterRealtimeService.java

@@ -56,4 +56,9 @@ public interface IEmsWaterRealtimeService extends IBaseService<EmsWaterRealtime,
      * 传输大用户水数据历史表到小时表
      * */
     void getHistoryWaterToHour();
+
+    /**
+     * 获取异常数据到T_RM_Ex_Value表
+     */
+    void getAbnormalToExitValue();
 }

+ 198 - 98
src/main/java/com/steerinfo/ems/emswaterrealtime/service/impl/EmsWaterRealtimeServiceImpl.java

@@ -66,10 +66,11 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
     }
 
     //更换数据源使用
-    List<EmsWaterRealtime> emsWaterRealtimeList;
-    List<EmsWAiHourSumTab1> emsWAiHourSumTab1s;
-    List<EmsWAiHourSumTab1Org> emsWAiHourSumTab1Orgs;
-    List<EmsWaterRealtime>  emsWaterToMeterRelation;
+    static List<EmsWaterRealtime> emsWaterRealtimeList = new ArrayList<>();
+    static List<EmsWAiHourSumTab1> emsWAiHourSumTab1s = new ArrayList<>();
+    static List<EmsWAiHourSumTab1Org> emsWAiHourSumTab1Orgs = new ArrayList<>();
+    static List<EmsWaterRealtime>  emsWaterToMeterRelation = new ArrayList<>();
+    static List<TRmCalpointExValue> tRmCalpointExValues = new ArrayList<>();
 
 
     @Override
@@ -132,50 +133,49 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
 
     @Override
     public void getWaterTenMinutes() {
-        //int addSize = 0;
-        //int updateSize = 0;
-        //int i = 0;
-        //try {
-        //    EmsWaterRealtime model;
-        //    // emsWaterRealtimeMapper.selectByPrimaryKey("1");//.getWaterListByArmMeter();
-        //    String clock1 = DateUtils.dateStr(new Date(),"yyyy-MM-dd HH:mm:ss");
-        //    String clock2 = DateUtils.dateStr(new Date(),"yyyy-MM-dd HH:mm:ss");
-        //    HashMap<String,Object> hashMap = new HashMap<String,Object>();
-        //    hashMap.put("clock1",clock1);
-        //    hashMap.put("clock2",clock2);
-        //    try {
-        //        addSize += emsWaterRealtimeMapper.insertWaterTenMinutes(hashMap);
-        //    } catch (Exception e) {
-        //        logger.error("主键已存在");
-        //    } finally {
+        int addSize = 0;
+        int updateSize = 0;
+        int i = 0;
+        try {
+            EmsWaterRealtime model;
+            // emsWaterRealtimeMapper.selectByPrimaryKey("1");//.getWaterListByArmMeter();
+            String clock1 = DateUtils.dateStr(new Date(),"yyyy-MM-dd HH:mm:ss");
+            String clock2 = DateUtils.dateStr(new Date(),"yyyy-MM-dd HH:mm:ss");
+            HashMap<String,Object> hashMap = new HashMap<String,Object>();
+            hashMap.put("clock1",clock1);
+            hashMap.put("clock2",clock2);
+            try {
+                addSize += emsWaterRealtimeMapper.insertWaterTenMinutes(hashMap);
+            } catch (Exception e) {
+                logger.error("主键已存在");
+            } finally {
         emsWaterToMeterRelation = emsWaterRealtimeMapper.getWaterTenMinutes();
-        //        StringBuffer sub = new StringBuffer();
-        //        String table="EMS_WATER_TIMING";
-        //        String[] tens;
-        //        String tag;
-        //        String sql;
-        //        for (EmsWaterRealtime emsWaterRealtime : emsWaterToMeterRelation){
-        //            i++;
-        //            tens = emsWaterRealtime.getmType().split("\\.");
-        //            tag = tens[1];
-        //            //多个表生成数据就填加table;
-        //            table = tens[0];
-        //            sql = ","+tag + " = " + "'" + emsWaterRealtime.getSumvalue() + "'";
-        //            sub.append(sql);
-        //        }
-        //        clock2 = DateUtils.dateStr(new Date(),"yyyy-MM-dd HH:mm:ss");
-        //        hashMap.put("table",table);
-        //        hashMap.put("clock2",clock2);
-        //        hashMap.put("sql",sub.toString());
-        //        updateSize += emsWaterRealtimeMapper.updateWaterTenMinutes(hashMap);
-        //    }
-        //} catch (Exception e) {
-        //    e.printStackTrace();
-        //} finally {
-        //}
-        //logger.info("本次总共新增水数据条数:" + addSize);
-        //logger.info("本次总共更新水数据条数:" + updateSize+";总共更新数据项"+i);
-        //return addSize+updateSize;
+                StringBuffer sub = new StringBuffer();
+                String table="EMS_WATER_TIMING";
+                String[] tens;
+                String tag;
+                String sql;
+                for (EmsWaterRealtime emsWaterRealtime : emsWaterToMeterRelation){
+                    i++;
+                    tens = emsWaterRealtime.getmType().split("\\.");
+                    tag = tens[1];
+                    //多个表生成数据就填加table;
+                    table = tens[0];
+                    sql = ","+tag + " = " + "'" + emsWaterRealtime.getSumvalue() + "'";
+                    sub.append(sql);
+                }
+                clock2 = DateUtils.dateStr(new Date(),"yyyy-MM-dd HH:mm:ss");
+                hashMap.put("table",table);
+                hashMap.put("clock2",clock2);
+                hashMap.put("sql",sub.toString());
+                updateSize += emsWaterRealtimeMapper.updateWaterTenMinutes(hashMap);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+        }
+        logger.info("本次总共新增水数据条数:" + addSize);
+        logger.info("本次总共更新水数据条数:" + updateSize+";总共更新数据项"+i);
     }
 
     /***
@@ -257,8 +257,42 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
             StringBuffer whens = new StringBuffer();
             List<String> tagList = new ArrayList<>(size-1);
             List<String> codeList = new ArrayList<>(size-1);
+            // tag存储字段
+            String tag;
+            // 存储表
+            String table;
+            // 十分钟表字段
+            String tenvs;
+            TRmCalpointExValue tRmCalpointExValue;
+            String exTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
             for (EmsWaterRealtime emsWaterRealtime : emsWaterToMeterRelation){
+                // 获取配置
+                tag = emsWaterRealtime.getmName();
+                table = emsWaterRealtime.getmUsertype();
+                tenvs = emsWaterRealtime.getmType();
+                if (tag == null || table == null || tenvs == null || tag.trim().isEmpty() || table.trim().isEmpty() || tenvs.trim().isEmpty()) {
+                    tRmCalpointExValue=new TRmCalpointExValue();
+                    tRmCalpointExValue.setItemid(emsWaterRealtime.getMeterid());
+                    // 配置错误
+                    tRmCalpointExValue.setExtype("2");
+                    tRmCalpointExValue.setClock(clock);
+                    tRmCalpointExValue.setCreatetime(exTime);
+                    tRmCalpointExValue.setBz("配置不能为空");
+                    tRmCalpointExValues.add(tRmCalpointExValue);
+                    continue;
+                }
                 tens = emsWaterRealtime.getmType().split("\\.");
+                if (tens.length != 2) {
+                    tRmCalpointExValue = new TRmCalpointExValue();
+                    tRmCalpointExValue.setItemid(emsWaterRealtime.getMeterid());
+                    // 配置错误
+                    tRmCalpointExValue.setExtype("2");
+                    tRmCalpointExValue.setClock(clock);
+                    tRmCalpointExValue.setCreatetime(exTime);
+                    tRmCalpointExValue.setBz("十分钟表字段配置错误");
+                    tRmCalpointExValues.add(tRmCalpointExValue);
+                    continue;
+                }
                 whens.append(" when '");
                 whens.append(emsWaterRealtime.getAddresscode());
                 whens.append("' then '");
@@ -295,7 +329,42 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
             StringBuffer whens = new StringBuffer();
             List<String> tagList = new ArrayList<>(size-1);
             List<String> codeList = new ArrayList<>(size-1);
+            // tag存储字段
+            String tag;
+            // 存储表
+            String table;
+            // 十分钟表字段
+            String tenvs;
+            TRmCalpointExValue tRmCalpointExValue;
+            String exTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
             for (EmsWaterRealtime emsWaterRealtime : emsWaterToMeterRelation){
+                // 获取配置
+                tag = emsWaterRealtime.getmName();
+                table = emsWaterRealtime.getmUsertype();
+                tenvs = emsWaterRealtime.getmType();
+                if (tag == null || table == null || tenvs == null || tag.trim().isEmpty() || table.trim().isEmpty() || tenvs.trim().isEmpty()) {
+                    tRmCalpointExValue=new TRmCalpointExValue();
+                    tRmCalpointExValue.setItemid(emsWaterRealtime.getMeterid());
+                    // 配置错误
+                    tRmCalpointExValue.setExtype("2");
+                    tRmCalpointExValue.setClock(clock);
+                    tRmCalpointExValue.setCreatetime(exTime);
+                    tRmCalpointExValue.setBz("配置不能为空");
+                    tRmCalpointExValues.add(tRmCalpointExValue);
+                    continue;
+                }
+                tens = emsWaterRealtime.getmType().split("\\.");
+                if (tens.length != 2) {
+                    tRmCalpointExValue = new TRmCalpointExValue();
+                    tRmCalpointExValue.setItemid(emsWaterRealtime.getMeterid());
+                    // 配置错误
+                    tRmCalpointExValue.setExtype("2");
+                    tRmCalpointExValue.setClock(clock);
+                    tRmCalpointExValue.setCreatetime(exTime);
+                    tRmCalpointExValue.setBz("十分钟表字段配置错误");
+                    tRmCalpointExValues.add(tRmCalpointExValue);
+                    continue;
+                }
                 tens = emsWaterRealtime.getmType().split("\\.");
                 whens.append(" when '");
                 whens.append(emsWaterRealtime.getAddresscode());
@@ -349,12 +418,18 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
         //异常处理使用
         TRmCalpointExValue tce;
         try{
-        if(!emsWAiHourSumTab1Orgs.equals(null)&&emsWAiHourSumTab1Orgs.size()>0){
+            //获取用量值数据
+        if(!emsWAiHourSumTab1s.equals(null)&&emsWAiHourSumTab1s.size()>0){
         for(EmsWAiHourSumTab1 model : emsWAiHourSumTab1s) {
             fields = model.getClass().getDeclaredFields();
             for(int i = 0, len = fields.length; i < len; i++) {
+                if(val5s.length==0){
+                    val5s=new Double[fields.length];
+                    Arrays.fill(val5s,0.0d);
+                }
                 // 对于每个属性,获取属性名
                 varName = fields[i].getName().trim();
+                String finalI = varName;
                 try {
                     // 获取原来的访问控制权限
                     accessFlag = fields[i].isAccessible();
@@ -363,53 +438,60 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
                     try {
                         // 获取在对象f中属性fields[i]对应的对象中的变量
                         o = fields[i].get(model);
+                        if(i==0){
+                            clock5s[j]=o.toString();
+                        }
                         if("class java.lang.Double".equals(fields[i].getGenericType().toString())){
                             //Method m = model.getClass().getMethod("get"+name);
                             //Double value = (Double) m.invoke(model);
                             if(o != null){
+                                // 大于等于0
+                                //if ((Double) o >= 0) {
+                                //    //暂时不做判断,水数据四小时一次,等时间间距变小,再做处理
+                                //    // 数据增加500以上,异常记录
+                                //    if ((Double) o >= 500) {
+                                //        // 记录异常数据
+                                //        tce = gettRmCalpointExValue(clock5s[j],finalI,"8")
+                                //        // 水数据增大超过最大值
+                                //        tce.setBefvalue(val2);
+                                //        tce.setCurvalue(val1);
+                                //        tce.setClock(ma.get("TIM").toString());
+                                //        tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                                //        //tce.setBz("十分钟水数据增大超过500,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+                                //        tce.setBz("四小时水数据增大超过500,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+                                //        tRmCalpointExValueService.add(tce);
+                                //    }//else{
+                                //    hval = hval.add(tenval);
+                                //    //}
+                                //} else {
+                                //    // 清零处理
+                                //    if (tenval.doubleValue() < -20d && val2.doubleValue() < 500d) {
+                                //        hval = hval.add(val2);
+                                //    }
+                                //    // 记录异常数据
+                                //    TRmCalpointExValue tce = new TRmCalpointExValue();
+                                //    tce.setItemid(itemid);
+                                //    tce.setExtype("1"); // 十分钟数据变小
+                                //    tce.setBefvalue(val1);
+                                //    tce.setCurvalue(val2);
+                                //    tce.setClock(ma.get("TIM").toString());
+                                //    tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                                //    tce.setBz("十分钟数据变小,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+                                //    tRmCalpointExValueService.add(tce);
+                                //}
                                 //val=new BigDecimal(String.valueOf((Double) o));
                                 //fields[i].set(model,val.setScale(1, RoundingMode.HALF_UP).doubleValue());
                             } else {
-                                tce = new TRmCalpointExValue();
-                                tce.setItemid(varName);
-                                // 准点值错误
-                                tce.setExtype("3");
-                                tce.setClock(clock);
-                                tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
-                                        .format(new Date()));
-                                tce.setBz("准点用量值读取失败,clock:" + clock + ",col:" + varName + ",table:"
+                                // 历史用量值更新失败
+                                tce = gettRmCalpointExValue(clock5s[j], finalI,"6");
+                                tce.setBz("准点用量值读取失败,clock:" + clock5s[j] + ",col:" + varName + ",table:"
                                         + model.getClass().getName());
-                                tRmCalpointExValueService.add(tce);
+                                tRmCalpointExValues.add(tce);
                                 //用量直接赋值0
                                 val=0d;
                                 fields[i].set(model,val);
-                                //if(val5s[i].equals(BigDecimal.ZERO)){
-
-                                //logger.error("准点数据查询失败,clock:" + clock);
-                                // 当前小时准点值 用量直接赋值0
-                                //sql = "select " + varName + " from  EMS_W_AI_HOUR_SUM_TAB1 where CLOCK = '" + clock5+"'" ;
-                                //try {
-                                //    tab_val5 = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                                //    val5s[i]=tab_val5.setScale(0, RoundingMode.DOWN);
-                                //    val = tab_val5;
-                                //} catch (Exception e){
-                                //    val=BigDecimal.ZERO;
-                                //    tce.setItemid(varName);
-                                //    // 准点值错误
-                                //    tce.setExtype("11");
-                                //    tce.setClock(clock5);
-                                //    tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
-                                //            .format(new Date()));
-                                //    tce.setBz("5小时前准点用量值读取失败,clock:" + clock + ",col:" + varName + ",table:"
-                                //            + model.getClass().getName());
-                                //    tRmCalpointExValueService.add(tce);
-                                //}
-                                //} else {
-                                //    val = val5s[i];
-                                //}
                             }
                         }
-                        //System.err.println("传入的对象中包含一个如下的变量:" + varName + " = " + o);
                     } catch (IllegalAccessException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
@@ -425,7 +507,9 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
                 emsWAiHourSumTab1Mapper.insertSelective(model);
             }
         }
+            val5s = new Double[0];
         }
+        //获取仪表值数据
         if(!emsWAiHourSumTab1Orgs.equals(null)&&emsWAiHourSumTab1Orgs.size()>0){
             clock5s=new String[emsWAiHourSumTab1Orgs.size()];
             for(EmsWAiHourSumTab1Org model : emsWAiHourSumTab1Orgs) {
@@ -437,6 +521,7 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
                     }
                     // 对于每个属性,获取属性名
                     varName = fields[i].getName().trim();
+                    String finalI = varName;
                     try {
                         // 获取原来的访问控制权限
                         accessFlag = fields[i].isAccessible();
@@ -456,16 +541,10 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
                                     //fields[i].set(model,val.setScale(1, RoundingMode.HALF_UP).doubleValue());
                                 } else {
                                     // 准点值错误
-                                    tce = new TRmCalpointExValue();
-                                    tce.setItemid(varName);
-                                    tce.setExtype("3");
-                                    tce.setClock(clock);
-                                    tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
-                                            .format(new Date()));
+                                    tce = gettRmCalpointExValue(clock, finalI,"3");
                                     tce.setBz("准点仪表值读取失败,获取5小时前数据clock:" + clock + ",col:" + varName
                                             + ",table:" + model.getClass().getName());
-                                    tRmCalpointExValueService.add(tce);
-                                    //logger.error("准点数据查询失败,clock:" + clock);
+                                    tRmCalpointExValues.add(tce);
                                     if(val5s[i]==(0.0d)) {
                                         // 5小时前准点值,当前小时
                                         clock5s[j]+=":00:00";
@@ -479,16 +558,12 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
                                             val = val5s[i];
                                         } catch (Exception e) {
                                             val = 0d;
-                                            tce = new TRmCalpointExValue();
-                                            tce.setItemid(varName);
-                                            // 准点值错误
-                                            tce.setExtype("11");
-                                            tce.setClock(clock5);
+                                            tce = gettRmCalpointExValue(clock5, finalI,"3");
                                             tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                                                     .format(new Date()));
                                             tce.setBz("5小时前准点仪表值读取失败,clock:" + clock + ",col:" + varName + ",table:"
                                                     + model.getClass().getName());
-                                            tRmCalpointExValueService.add(tce);
+                                            tRmCalpointExValues.add(tce);
                                         }
                                     } else {
                                        val=val5s[i];
@@ -523,7 +598,7 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
             tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                     .format(new Date()));
             tce.setBz("数据传输错误,无数据;请联系管理员");
-            tRmCalpointExValueService.add(tce);
+            tRmCalpointExValues.add(tce);
         }
         } catch (Exception e) {
             tce = new TRmCalpointExValue();
@@ -534,10 +609,35 @@ public class EmsWaterRealtimeServiceImpl extends BaseServiceImpl<EmsWaterRealtim
             tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                     .format(new Date()));
             tce.setBz("数据传输错误,无数据;请联系管理员");
-            tRmCalpointExValueService.add(tce);
+            tRmCalpointExValues.add(tce);
+        }finally {
+            tRmCalpointExValueService.batchAdd(tRmCalpointExValues);
         }
     }
 
+    private TRmCalpointExValue gettRmCalpointExValue(String clock, String finalI,String type) {
+        String itemId;
+        TRmCalpointExValue tce;
+        itemId = emsWaterToMeterRelation.stream()
+                .filter(emsWaterToMeter -> finalI.toUpperCase()
+                        .equals(emsWaterToMeter.getmName().toUpperCase().trim()))
+                .findFirst()
+                .orElse(null).getMosaicid();
+        tce = new TRmCalpointExValue();
+        tce.setItemid(itemId);
+        tce.setExtype(type);
+        tce.setClock(clock);
+        tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+                .format(new Date()));
+        return tce;
+    }
+
+    @Override
+    public void getAbnormalToExitValue() {
+
+    }
+
+
     @Autowired
     IFormulaService formulaService;
 

+ 8 - 0
src/main/java/com/steerinfo/ems/trmcalpoint/controller/TRmCalpointController.java

@@ -154,6 +154,14 @@ public class TRmCalpointController extends BaseRESTfulController {
             return failed(null, "手抄或者自动不能为空");
         }else if (model.getLocateid() == null || "".equals(model.getLocateid())) {
             return failed(null, "位置不能为空");
+        } else if((model.getSourceType() != null || !"".equals(model.getSourceType())) ||
+                (model.getBtype2() != null || !"".equals(model.getBtype2())) ||
+                (model.getTagTable() != null || !"".equals(model.getBtype2()) &&
+                 model.getTagCol() != null || !"".equals(model.getTagCol()))
+        ){
+            if(tRmCalpointService.getSoleSource(model)>=1){
+                return failed(null, "绑定的数据来源不能重复!");
+            }
         }
         if(model.getEnergytypeid().equalsIgnoreCase("E") && (model.getNetworkid() == null || "".equals(model.getNetworkid()))){
         	return failed(null, "能介电的计量点站所不能为空");

+ 55 - 46
src/main/java/com/steerinfo/ems/trmcalpoint/mapper/TRmCalpointMapper.java

@@ -11,50 +11,59 @@ import java.util.Map;
 
 @Mapper
 public interface TRmCalpointMapper extends IBaseMapper<TRmCalpoint, String> {
-	/**
-	 * 获得计量层级列表(计量点数据录入)
-	 * 
-	 * @return
-	 */
-	List<Map> getRmCalpoint();
-
-	/**
-	 * 获取电计量点最大流水号
-	 * 
-	 * @param head
-	 * @return
-	 */
-	String getMaxId(@Param("head") String head);
-
-	/**
-	 * 能源调度管理-计量点数据管理-计量点数据录入列表
-	 * 
-	 * @param parmas
-	 * @return
-	 */
-	List<Map<String, Object>> getDate312(HashMap<String, Object> parmas);
-
-	/**
-	 * 能源调度管理-计量点数据管理-计量点数据趋势图
-	 * @param mp
-	 * @return
-	 */
-	List<Map<String, Object>> getDate312ForChart(Map<String, Object> mp);
-
-	void updateNewItem(Map<String, Object> parmas);
-	
-	/**
-	 * 获取计量点信息,按itemtype:自动、手动、虚拟排序
-	 * @param parameters
-	 * @return
-	 */
-	List<TRmCalpoint> selectCalpoints(Map<String, Object> parameters);
-
-	/**
-	 * 系统接口管理-能耗数据管理
-	 * 
-	 * @param parmas
-	 * @return
-	 */
-	List<Map<String, Object>> getInIdDate312(HashMap<String, Object> parmas);
+    /**
+     * 获得计量层级列表(计量点数据录入)
+     *
+     * @return
+     */
+    List<Map> getRmCalpoint();
+
+    /**
+     * 获取电计量点最大流水号
+     *
+     * @param head
+     * @return
+     */
+    String getMaxId(@Param("head") String head);
+
+    /**
+     * 能源调度管理-计量点数据管理-计量点数据录入列表
+     *
+     * @param parmas
+     * @return
+     */
+    List<Map<String, Object>> getDate312(HashMap<String, Object> parmas);
+
+    /**
+     * 能源调度管理-计量点数据管理-计量点数据趋势图
+     *
+     * @param mp
+     * @return
+     */
+    List<Map<String, Object>> getDate312ForChart(Map<String, Object> mp);
+
+    void updateNewItem(Map<String, Object> parmas);
+
+    /**
+     * 获取计量点信息,按itemtype:自动、手动、虚拟排序
+     *
+     * @param parameters
+     * @return
+     */
+    List<TRmCalpoint> selectCalpoints(Map<String, Object> parameters);
+
+    /**
+     * 系统接口管理-能耗数据管理
+     *
+     * @param parmas
+     * @return
+     */
+    List<Map<String, Object>> getInIdDate312(HashMap<String, Object> parmas);
+
+    /**
+     * 判断数据列是否重复
+     * @param tRmCalpoint
+     * @return
+     */
+    Integer getSoleSource(TRmCalpoint tRmCalpoint);
 }

+ 4 - 1
src/main/java/com/steerinfo/ems/trmcalpoint/mapper/TRmCalpointMapper.xml

@@ -1593,7 +1593,7 @@
         and ITEMTYPE = #{itemtype}
       </if>
       <if test="propertyid != null and propertyid != ''">
-        and PROPERTYID = #{propertyid}
+        and PROPERTYID = (${propertyid})
       </if>
       <if test="unitid != null and unitid != ''">
         and UNITID = #{unitid}
@@ -1664,4 +1664,7 @@
     </where>
     order by itemtype, seqno
   </select>
+  <select id="getSoleSource" resultType="int" parameterType="com.steerinfo.ems.trmcalpoint.model.TRmCalpoint">
+    SELECT COUNT(1) FROM T_RM_CALPOINT WHERE 1=1 AND BTYPE2=#{btype2} OR (TAG_TABLE=#{tagTable} AND TAG_COL=#{tagCol}) OR SOURCE_TYPE= #{sourceType}
+  </select>
 </mapper>

+ 7 - 0
src/main/java/com/steerinfo/ems/trmcalpoint/service/ITRmCalpointService.java

@@ -148,4 +148,11 @@ public interface ITRmCalpointService extends IBaseService<TRmCalpoint, String>{
 	 * @return
 	 */
 	void resData(String clock,String itemId);
+
+	/**
+	 * 判断数据列是否重复
+	 * @param tRmCalpoint
+	 * @return
+	 */
+	Integer getSoleSource(TRmCalpoint tRmCalpoint);
 }

+ 62 - 34
src/main/java/com/steerinfo/ems/trmcalpoint/service/impl/TRmCalpointServiceImpl.java

@@ -314,9 +314,9 @@ public class TRmCalpointServiceImpl extends BaseServiceImpl<TRmCalpoint, String>
         Map<String, Object> m = new HashMap<String, Object>();
         m.put("useflag", "1");
         m.put("itemtype", "AUTO");
-        //m.put("energytypeid", "'P','W'");
+        m.put("energytypeid", "'P','W'");
         //业务变更,暂时只读取动力
-        m.put("energytypeid", "'P'");
+        //m.put("energytypeid", "'P'");
         List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(m);
         int size = 0;
         if (l != null && l.size() > 0) {
@@ -481,9 +481,9 @@ public class TRmCalpointServiceImpl extends BaseServiceImpl<TRmCalpoint, String>
         Map<String, Object> m = new HashMap<String, Object>();
         m.put("useflag", "1");
         m.put("itemtype", "AUTO");
-        //m.put("energytypeid", "'P','W'");
+        m.put("energytypeid", "'P','W'");
         //业务变更,暂时只读取动力
-        m.put("energytypeid", "'P'");
+        //m.put("energytypeid", "'P'");
         List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(m);
         int size = 0;
         if (l != null && l.size() > 0) {
@@ -658,6 +658,8 @@ public class TRmCalpointServiceImpl extends BaseServiceImpl<TRmCalpoint, String>
         } catch (ParseException e) {
             return "日期格式错误";
         }
+        String maxValue = tc.getMaxVal() ==null||"".equals(tc.getMaxVal()) ? "9999" : tc.getMaxVal();
+        String minValue = tc.getMinVal() ==null||"".equals(tc.getMinVal()) ? "0" : tc.getMinVal();;
         Calendar cal = Calendar.getInstance();
         cal.setTime(date);
         cal.add(Calendar.HOUR_OF_DAY, -1);
@@ -794,49 +796,50 @@ public class TRmCalpointServiceImpl extends BaseServiceImpl<TRmCalpoint, String>
                     }
                     tenval = val2.subtract(val1);
                     // 水处理
-                    if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                    //if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
                         // 大于等于0
                         if (tenval.doubleValue() >= 0) {
+                            hval = hval.add(tenval);
                             //暂时不做判断,水数据四小时一次,等时间间距变小,再做处理
-                            if (tenval.doubleValue() >= 500) { // 数据增加500以上,异常,当0处理
+                            // 数据增加超过最大值以上,异常,预警
+                            if (tenval.doubleValue() >= new BigDecimal(maxValue).doubleValue()) {
                                 // 记录异常数据
                                 TRmCalpointExValue tce = new TRmCalpointExValue();
                                 tce.setItemid(itemid);
-                                tce.setExtype("8"); // 十分钟水数据增大超过500
+                                // 四小时水数据增大超过限值
+                                tce.setExtype("8");
                                 tce.setBefvalue(val2);
                                 tce.setCurvalue(val1);
                                 tce.setClock(ma.get("TIM").toString());
                                 tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                                 //tce.setBz("十分钟水数据增大超过500,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
-                                tce.setBz("四小时水数据增大超过500,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+                                tce.setBz("用量数据增大超过限值"+maxValue+",clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+                                tRmCalpointExValueService.add(tce);
+                            }else if(tenval.doubleValue() < new BigDecimal(minValue).doubleValue()){
+                                // 记录异常数据
+                                TRmCalpointExValue tce = new TRmCalpointExValue();
+                                tce.setItemid(itemid);
+                                // 十分钟水数据增大超过500
+                                tce.setExtype("8");
+                                tce.setBefvalue(val2);
+                                tce.setCurvalue(val1);
+                                tce.setClock(ma.get("TIM").toString());
+                                tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                                //tce.setBz("十分钟水数据增大超过500,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+                                tce.setBz("用量数据低于最小值"+minValue+",clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
                                 tRmCalpointExValueService.add(tce);
-                            }//else{
-                            hval = hval.add(tenval);
-                            //}
-                        } else {
-                            // 清零处理
-                            if (tenval.doubleValue() < -20d && val2.doubleValue() < 500d) {
-                                hval = hval.add(val2);
                             }
-                            // 记录异常数据
-                            TRmCalpointExValue tce = new TRmCalpointExValue();
-                            tce.setItemid(itemid);
-                            tce.setExtype("1"); // 十分钟数据变小
-                            tce.setBefvalue(val1);
-                            tce.setCurvalue(val2);
-                            tce.setClock(ma.get("TIM").toString());
-                            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-                            tce.setBz("十分钟数据变小,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
-                            tRmCalpointExValueService.add(tce);
-                        }
-                    } else {
-                        // 大于等于0
-                        if (tenval.doubleValue() >= 0) {
-                            hval = hval.add(tenval);
                         } else {
-                            // 清零处理
-                            if (tenval.doubleValue() < -20d) {
-                                hval = hval.add(val2);
+                            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                                // 清零处理
+                                if (tenval.doubleValue() < -20d && val2.doubleValue() < 500d) {
+                                    hval = hval.add(val2);
+                                }
+                            } else {
+                                // 动力清零处理
+                                if (tenval.doubleValue() < -20d) {
+                                    hval = hval.add(val2);
+                                }
                             }
                             // 记录异常数据
                             TRmCalpointExValue tce = new TRmCalpointExValue();
@@ -849,7 +852,27 @@ public class TRmCalpointServiceImpl extends BaseServiceImpl<TRmCalpoint, String>
                             tce.setBz("十分钟数据变小,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
                             tRmCalpointExValueService.add(tce);
                         }
-                    }
+                    //} else {
+                    //    // 大于等于0
+                    //    if (tenval.doubleValue() >= 0) {
+                    //        hval = hval.add(tenval);
+                    //    } else {
+                    //        // 清零处理
+                    //        if (tenval.doubleValue() < -20d) {
+                    //            hval = hval.add(val2);
+                    //        }
+                    //        // 记录异常数据
+                    //        TRmCalpointExValue tce = new TRmCalpointExValue();
+                    //        tce.setItemid(itemid);
+                    //        tce.setExtype("1"); // 十分钟数据变小
+                    //        tce.setBefvalue(val1);
+                    //        tce.setCurvalue(val2);
+                    //        tce.setClock(ma.get("TIM").toString());
+                    //        tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                    //        tce.setBz("十分钟数据变小,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+                    //        tRmCalpointExValueService.add(tce);
+                    //    }
+                    //}
                     // 处理后值作为下一条数据的仪表初始值。
                     val1 = val2;
                 }
@@ -1262,4 +1285,9 @@ public class TRmCalpointServiceImpl extends BaseServiceImpl<TRmCalpoint, String>
             logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 动力、水小时表统计完毕,个数:" + size);
         }
     }
+
+    @Override
+    public Integer getSoleSource(TRmCalpoint tRmCalpoint) {
+       return tRmCalpointMapper.getSoleSource(tRmCalpoint);
+    }
 }

+ 3 - 0
src/main/java/com/steerinfo/ems/trmcalpointvalue/service/impl/TRmCalpointValueServiceImpl.java

@@ -659,6 +659,9 @@ public class TRmCalpointValueServiceImpl extends BaseServiceImpl<TRmCalpointValu
 					if (qm == tagBad || qc == tagBad || qc == 0 || new BigDecimal(Double.toString(qm)).subtract(new BigDecimal(Double.toString(qc))).doubleValue() < 0
 							|| !energytypeid.equalsIgnoreCase("E")) {
 						sql = "select nvl(round(sum("+tagCol+")*"+mod+", "+digits+"),0) from "+tagTable+" where clock>=? and clock<?";
+						// 数据应该是0点到0点,次日0点的数据是今日23点到0点的数据,所以也应该计算在今日数据内.
+						// 但是今日0点数据是昨日今日23点到0点的数据,所以今日0点不计算在内
+						//sql = "select nvl(round(sum("+tagCol+")*"+mod+", "+digits+"),0) from "+tagTable+" where clock>? and clock<=?";
 						Double d = 0d;
 						try {
 							d = jdbcTemplate.queryForObject(sql, new Object[]{qck,qmk}, Double.class);

+ 10 - 9
src/main/java/com/steerinfo/task/SpringCronTask.java

@@ -45,9 +45,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
 import org.springframework.scheduling.support.CronTrigger;
 import org.springframework.stereotype.Service;
 
-import javax.script.ScriptException;
 import java.text.ParseException;
-import java.util.Properties;import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledFuture;
@@ -272,13 +270,16 @@ public class SpringCronTask implements SchedulingConfigurer{
 				}
 				 else if(taskId.equalsIgnoreCase("120")){
 					 long start = System.currentTimeMillis();
-					 // 获取大用户水系统数据 5分钟一次
+					 // 获取大用户水系统数据、获取动力数据 5分钟一次
 					 emsWaterRealtimeService.getWaterListByArmMeter();
 					 emsWaterRealtimeService.dataGeneration();
+					 rttableService.dataGeneration();
 					 logger.info("定时任务"+taskId+"执行时长:" + (System.currentTimeMillis() - start)/1000 + "秒");
 				 } else if(taskId.equalsIgnoreCase("121")){
-					 // 根据计量点配置生成水数据 10分钟一次,暂时弃用,只保留传输到mosaic
+					 // 根据计量点配置生成动力数据、水数据 10分钟一次,暂时弃用,只保留传输到mosaic
 					 long start = System.currentTimeMillis();
+					 emsWaterRealtimeService.getWaterTenMinutes();
+					 rttableService.getPowerTenMinutes();
 					 try {
 						 emsWaterRealtimeService.getWaterListToMosaic();
 					 } catch (AxisFault e) {
@@ -288,13 +289,13 @@ public class SpringCronTask implements SchedulingConfigurer{
 					 }
 				 }
 				 else if(taskId.equalsIgnoreCase("116")){
-					// 动力、水(计量点)小时表定时统计(自动补全24小时内的小时用量值),已改为只统计动力点位
+					// 动力、水(计量点)小时表定时统计(自动补全24小时内的小时用量值)
 					long start = System.currentTimeMillis();
 					tRmCalpointService.statHourData();
-					//水计量点统计
-					 emsWaterRealtimeService.getWaterTenMinutes();
-					 emsWaterRealtimeService.getWaterHour();
-					 emsWaterRealtimeService.getHistoryWaterToHour();
+					////水计量点统计,获取水系统历史数据,弃用不准确
+					// emsWaterRealtimeService.getWaterTenMinutes();
+					// emsWaterRealtimeService.getWaterHour();
+					// emsWaterRealtimeService.getHistoryWaterToHour();
 					logger.info("定时任务"+taskId+"执行时长:" + (System.currentTimeMillis() - start)/1000 + "秒");
 				}
 				 else if (taskId.equalsIgnoreCase("102")) {