浏览代码

添加自动补全水,动,一段时间的小时值和重新生成日数据

zhangy 2 年之前
父节点
当前提交
067a901b5b

+ 160 - 158
src/main/java/com/steerinfo/ems/trmcalpoint/service/ITRmCalpointService.java

@@ -1,158 +1,160 @@
-package com.steerinfo.ems.trmcalpoint.service;
-
-import com.steerinfo.ems.trmcalpoint.model.TRmCalpoint;
-import com.steerinfo.framework.service.IBaseService;
-import com.steerinfo.framework.service.pagehelper.PageList;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * TRmCalpoint服务接口:
- * @author 王金涛
- * @version 1.0-SNAPSHORT 2019-10-11
- * 类描述
- * 修订历史:
- * 日期:2019-10-11
- * 作者:王金涛
- * 参考:
- * 描述:TRmCalpoint服务接口
- * @see null
- * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
- */
-public interface ITRmCalpointService extends IBaseService<TRmCalpoint, String>{
-	/**
-	 * 获得计量层级列表(计量点数据录入)
-	 * 
-	 * @return
-	 */
-	List<Map> getRmCalpoint();
-
-	/**
-	 * 获取最大流水号
-	 * 
-	 * @param head
-	 * @return
-	 */
-	String getMaxId(String head);
-
-	/**
-	 * 能源调度管理-计量点数据管理-准点数据查询
-	 * @param clock
-	 * @param clocke
-	 * @param itemid
-	 * @param datatype
-	 * @return
-	 */
-	List<Map<String, Object>> getRmCalpointVal(String clock, String clocke, String itemid, String datatype);
-
-	/**
-	 * 能源调度管理-计量点数据管理-准点数据查询(十分钟)
-	 * @param clock
-	 * @param clocke
-	 * @param itemid
-	 * @param datatype
-	 * @return
-	 */
-	List<Map<String, Object>> getRmCalpointValTim(String clock, String clocke, String itemid, String datatype);
-
-	/**
-	 * 能源调度管理-计量点数据管理-计量点数据录入列表
-	 * @param parmas
-	 * @param pageNum
-	 * @param pageSize
-	 * @return
-	 */
-	PageList<Map<String, Object>> getDate312ForPage(HashMap<String, Object> parmas, Integer pageNum, Integer pageSize);
-
-	/**
-	 * 能源调度管理-计量点数据管理-计量点数据趋势图
-	 * @param list
-	 * @param size
-	 * @return
-	 */
-	List<Map<String, Object>> getDate312ForChart(List<Map<String, Object>> list, int size);
-
-	TRmCalpoint updateNewItem(Map<String, Object> parmas);
-	
-	/**
-	 * 批量删除计量点信息
-	 * 
-	 * @param ids
-	 */
-	void delCalpoint(String[] ids);
-
-	/**
-	 * 系统接口管理-能耗数据管理
-	 * @param list
-	 * @return
-	 */
-	List<Map<String, Object>> getInIdDate312(HashMap<String, Object> parmas);
-	
-	/**
-	 * 动力、水小时表定时统计(自动补全24小时内的小时用量值)
-	 * 业务变更,只读取动力
-	 *  
-	 * @param date 统计时间
-	 */
-    void statHourData();
-    
-    /**
-	 * 动力、水小时表定时统计(自动补全24小时内的小时用量值)
-	 *  
-	 * @param date 统计时间
-	 */
-    void statHourData(String clockstart, String clockend);
-    
-    /**
-     * 重新计算单个计量点小时表数据(新增或者更新)(动力、水)
-     * 
-     * @param itemid 计量点编号
-     * @param clock	时间,格式:YYYY-MM-DD HH,(更新此时准点值,以及上一个小时用量值)
-     * @return
-     */
-    String restatHourData(String itemid, String clock);
-    
-    /**
-     * 重新计算单个计量点小时表数据(新增或者更新)(动力、水)
-     * 
-     * @param itemid 计量点编号
-     * @param clock 开始时间,格式:YYYY-MM-DD HH
-     * @param clockend 结束时间,格式:YYYY-MM-DD HH
-     * @return
-     */
-    String restatHourDate(String itemid, String clock, String clockend);
-    
-    /**
-     * 重新计算时间范围内小时表数据(新增或者更新)(电,不能指定单个点,只能指定时间范围)
-     * 
-     * @param clock 开始时间,格式:YYYY-MM-DD HH
-     * @param clockend 结束时间,格式:YYYY-MM-DD HH
-     * @return
-     */
-    String restatHourDateE(String clock, String clockend);
-    
-    /**
-     * 重新计算单个小时的表数据(新增或者更新)(电,不能指定单个点,只能指定时间范围)
-     * 
-     * @param clock	时间,格式:YYYY-MM-DD HH,(更新此时准点值,以及上一个小时用量值)
-     * @return
-     */
-    String restatHourDataE(String clock);
-
-	/**
-	 * 补全水数据
-	 *
-	 * @param clock	时间,格式:YYYY-MM-DD HH,(更新此时准点值,以及上一个小时用量值)
-	 * @return
-	 */
-	void resData(String clock,String itemId);
-
-	/**
-	 * 判断数据列是否重复
-	 * @param tRmCalpoint
-	 * @return
-	 */
-	Integer getSoleSource(TRmCalpoint tRmCalpoint);
-}
+package com.steerinfo.ems.trmcalpoint.service;
+
+import com.steerinfo.ems.trmcalpoint.model.TRmCalpoint;
+import com.steerinfo.framework.service.IBaseService;
+import com.steerinfo.framework.service.pagehelper.PageList;
+
+import java.text.ParseException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * TRmCalpoint服务接口:
+ * @author 王金涛
+ * @version 1.0-SNAPSHORT 2019-10-11
+ * 类描述
+ * 修订历史:
+ * 日期:2019-10-11
+ * 作者:王金涛
+ * 参考:
+ * 描述:TRmCalpoint服务接口
+ * @see null
+ * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
+ */
+public interface ITRmCalpointService extends IBaseService<TRmCalpoint, String>{
+	/**
+	 * 获得计量层级列表(计量点数据录入)
+	 * 
+	 * @return
+	 */
+	List<Map> getRmCalpoint();
+
+	/**
+	 * 获取最大流水号
+	 * 
+	 * @param head
+	 * @return
+	 */
+	String getMaxId(String head);
+
+	/**
+	 * 能源调度管理-计量点数据管理-准点数据查询
+	 * @param clock
+	 * @param clocke
+	 * @param itemid
+	 * @param datatype
+	 * @return
+	 */
+	List<Map<String, Object>> getRmCalpointVal(String clock, String clocke, String itemid, String datatype);
+
+	/**
+	 * 能源调度管理-计量点数据管理-准点数据查询(十分钟)
+	 * @param clock
+	 * @param clocke
+	 * @param itemid
+	 * @param datatype
+	 * @return
+	 */
+	List<Map<String, Object>> getRmCalpointValTim(String clock, String clocke, String itemid, String datatype);
+
+	/**
+	 * 能源调度管理-计量点数据管理-计量点数据录入列表
+	 * @param parmas
+	 * @param pageNum
+	 * @param pageSize
+	 * @return
+	 */
+	PageList<Map<String, Object>> getDate312ForPage(HashMap<String, Object> parmas, Integer pageNum, Integer pageSize);
+
+	/**
+	 * 能源调度管理-计量点数据管理-计量点数据趋势图
+	 * @param list
+	 * @param size
+	 * @return
+	 */
+	List<Map<String, Object>> getDate312ForChart(List<Map<String, Object>> list, int size);
+
+	TRmCalpoint updateNewItem(Map<String, Object> parmas);
+	
+	/**
+	 * 批量删除计量点信息
+	 * 
+	 * @param ids
+	 */
+	void delCalpoint(String[] ids);
+
+	/**
+	 * 系统接口管理-能耗数据管理
+	 * @param list
+	 * @return
+	 */
+	List<Map<String, Object>> getInIdDate312(HashMap<String, Object> parmas);
+	
+	/**
+	 * 动力、水小时表定时统计(自动补全24小时内的小时用量值)
+	 * 业务变更,只读取动力
+	 *  
+	 * @param date 统计时间
+	 */
+    void statHourData();
+    
+    /**
+	 * 动力、水小时表定时统计(自动补全24小时内的小时用量值)
+	 *  
+	 * @param date 统计时间
+	 */
+    void statHourData(String clockstart, String clockend) throws ParseException;
+
+    /**
+     * 重新计算单个计量点小时表数据(新增或者更新)(动力、水)
+     * 
+     * @param itemid 计量点编号
+     * @param clock	时间,格式:YYYY-MM-DD HH,(更新此时准点值,以及上一个小时用量值)
+     * @return
+     */
+    String restatHourData(String itemid, String clock);
+    
+    /**
+     * 重新计算单个计量点小时表数据(新增或者更新)(动力、水)
+     * 
+     * @param itemid 计量点编号
+     * @param clock 开始时间,格式:YYYY-MM-DD HH
+     * @param clockend 结束时间,格式:YYYY-MM-DD HH
+     * @return
+     */
+    String restatHourDate(String itemid, String clock, String clockend);
+    
+    /**
+     * 重新计算时间范围内小时表数据(新增或者更新)(电,不能指定单个点,只能指定时间范围)
+     *
+     * @param clock 开始时间,格式:YYYY-MM-DD HH
+     * @param clockend 结束时间,格式:YYYY-MM-DD HH
+     * @return
+     */
+    String restatHourDateE(String clock, String clockend);
+
+    /**
+     * 重新计算单个小时的表数据(新增或者更新)(电,不能指定单个点,只能指定时间范围)
+     *
+     * @param clock	时间,格式:YYYY-MM-DD HH,(更新此时准点值,以及上一个小时用量值)
+     * @return
+     */
+    String restatHourDataE(String clock);
+
+	/**
+	 * 补全水,动力数据
+	 *
+	 * @param startClock	时间,格式:YYYY-MM-DD HH,(更新这个开始到结束段的准点值)
+	 * @param endClock	时间,格式:YYYY-MM-DD HH,
+	 * @return
+	 */
+	void resData(String itemId, String startClock, String endClock) throws ParseException;
+
+	/**
+	 * 判断数据列是否重复
+	 * @param tRmCalpoint
+	 * @return
+	 */
+	Integer getSoleSource(TRmCalpoint tRmCalpoint);
+}

+ 1265 - 1359
src/main/java/com/steerinfo/ems/trmcalpoint/service/impl/TRmCalpointServiceImpl.java

@@ -1,1359 +1,1265 @@
-package com.steerinfo.ems.trmcalpoint.service.impl;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.steerinfo.ems.Utils.EmsEAiUtil;
-import com.steerinfo.ems.emseaihoursumtab1.mapper.EmsEAiHourSumTab1Mapper;
-import com.steerinfo.ems.emseaihoursumtab1.model.EmsEAiHourSumTab1;
-import com.steerinfo.ems.emseaihoursumtab1org.mapper.EmsEAiHourSumTab1OrgMapper;
-import com.steerinfo.ems.emseaihoursumtab1org.model.EmsEAiHourSumTab1Org;
-import com.steerinfo.ems.emsehistory.mapper.EmsEHistoryMapper;
-import com.steerinfo.ems.emsehistory.model.EmsEHistory;
-import com.steerinfo.ems.emsetiming.mapper.EmsETimingMapper;
-import com.steerinfo.ems.emsetiming.model.EmsETiming;
-import com.steerinfo.ems.emspaihoursumtab1.mapper.EmsPAiHourSumTab1Mapper;
-import com.steerinfo.ems.emspaihoursumtab1.model.EmsPAiHourSumTab1;
-import com.steerinfo.ems.emspaihoursumtab1org.mapper.EmsPAiHourSumTab1OrgMapper;
-import com.steerinfo.ems.emspaihoursumtab1org.model.EmsPAiHourSumTab1Org;
-import com.steerinfo.ems.emswaihoursumtab1.mapper.EmsWAiHourSumTab1Mapper;
-import com.steerinfo.ems.emswaihoursumtab1.model.EmsWAiHourSumTab1;
-import com.steerinfo.ems.emswaihoursumtab1org.mapper.EmsWAiHourSumTab1OrgMapper;
-import com.steerinfo.ems.emswaihoursumtab1org.model.EmsWAiHourSumTab1Org;
-import com.steerinfo.ems.emswebsocketlog.model.EmsWebsocketLog;
-import com.steerinfo.ems.emswebsocketlog.service.IEmsWebsocketLogService;
-import com.steerinfo.ems.formula.mapper.FormulaMapper;
-import com.steerinfo.ems.trmcalpoint.mapper.TRmCalpointMapper;
-import com.steerinfo.ems.trmcalpoint.model.TRmCalpoint;
-import com.steerinfo.ems.trmcalpoint.service.ITRmCalpointService;
-import com.steerinfo.ems.trmcalpointexvalue.model.TRmCalpointExValue;
-import com.steerinfo.ems.trmcalpointexvalue.service.ITRmCalpointExValueService;
-import com.steerinfo.ems.trmcalpointvalue.service.ITRmCalpointValueService;
-import com.steerinfo.framework.mapper.IBaseMapper;
-import com.steerinfo.framework.service.impl.BaseServiceImpl;
-import com.steerinfo.framework.service.pagehelper.PageHelper;
-import com.steerinfo.framework.service.pagehelper.PageList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-/**
- * TRmCalpoint服务实现:
- *
- * @author 王金涛
- * @version 1.0-SNAPSHORT 2019-10-11
- * 类描述
- * 修订历史:
- * 日期:2019-10-11
- * 作者:王金涛
- * 参考:
- * 描述:TRmCalpoint服务实现
- * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
- * @see null
- */
-@Service(value = "tRmCalpointService")
-public class TRmCalpointServiceImpl extends BaseServiceImpl<TRmCalpoint, String> implements ITRmCalpointService {
-    private static final Logger logger = LoggerFactory.getLogger(TRmCalpointServiceImpl.class);
-
-    @Autowired
-    private JdbcTemplate jdbcTemplate;
-
-    @Autowired
-    private TRmCalpointMapper tRmCalpointMapper;
-
-    @Autowired
-    private FormulaMapper formulaMapper;
-
-    @Autowired
-    ITRmCalpointValueService tRmCalpointValueService;
-
-    @Autowired
-    ITRmCalpointExValueService tRmCalpointExValueService;
-
-    @Autowired
-    EmsPAiHourSumTab1Mapper emsPAiHourSumTab1Mapper;
-
-    @Autowired
-    EmsPAiHourSumTab1OrgMapper emsPAiHourSumTab1OrgMapper;
-
-    @Autowired
-    EmsWAiHourSumTab1Mapper emsWAiHourSumTab1Mapper;
-
-    @Autowired
-    EmsWAiHourSumTab1OrgMapper emsWAiHourSumTab1OrgMapper;
-
-    @Autowired
-    private EmsEHistoryMapper emsEHistoryMapper;
-
-    @Autowired
-    private EmsETimingMapper emsETimingMapper;
-
-    @Autowired
-    private EmsEAiHourSumTab1OrgMapper emsEAiHourSumTab1OrgMapper;
-
-    @Autowired
-    private EmsEAiHourSumTab1Mapper emsEAiHourSumTab1Mapper;
-
-    @Override
-    protected IBaseMapper<TRmCalpoint, String> getMapper() {
-        return tRmCalpointMapper;
-    }
-
-    @Override
-    public List<Map> getRmCalpoint() {
-        return tRmCalpointMapper.getRmCalpoint();
-    }
-
-    @Override
-    synchronized public String getMaxId(String head) {
-        return this.tRmCalpointMapper.getMaxId(head);
-    }
-
-    @Override
-    public List<Map<String, Object>> getRmCalpointVal(String clock, String clocke, String itemid, String datatype) {
-        String sql = "";
-        String[] ids = itemid.split(",");
-        List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
-        Map<String, List<Map<String, Object>>> m = new HashMap<String, List<Map<String, Object>>>();
-        for (int i = 0; i < ids.length; i++) {
-            String id = ids[i];
-            TRmCalpoint tRmCalpoint = tRmCalpointMapper.selectByPrimaryKey(id);
-            String itemname = tRmCalpoint.getItemname();
-            // 累计来源数据表
-            String tagTable = tRmCalpoint.getTagTable();
-            // 累计来源数据列
-            String tagCol = tRmCalpoint.getTagCol();
-            if (datatype.equalsIgnoreCase("sum")) {
-                sql = "select clock," + tagCol + " val from " + tagTable + " where clock>='" + clock + "' and clock <='" + clocke + "' order by clock";
-                List<Map<String, Object>> l = jdbcTemplate.queryForList(sql);
-                m.put(id + "$" + itemname, l);
-            } else if (datatype.equalsIgnoreCase("ontime")) {
-                List<Map<String, Object>> l = new ArrayList<Map<String, Object>>();
-                sql = "select clock," + tagCol + " val from " + tagTable + "_org " + " where clock>='" + clock + "' and clock <='" + clocke + "' order by clock";
-                l = jdbcTemplate.queryForList(sql);
-                m.put(id + "$" + itemname, l);
-            }
-        }
-        try {
-            Date start = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
-            Date end = new SimpleDateFormat("yyyy-MM-dd HH").parse(clocke);
-            while (!start.after(end)) {
-                Map<String, Object> md = new HashMap<String, Object>();
-                md.put("tim", new SimpleDateFormat("yyyy-MM-dd HH").format(start));
-                for (String str : m.keySet()) {
-                    for (Map<String, Object> map : m.get(str)) {
-                        if (map != null && map.get("clock").toString().equals(new SimpleDateFormat("yyyy-MM-dd HH").format(start))) {
-                            Map<String, String> m1 = new HashMap<String, String>();
-                            m1.put("name", str.split("\\$")[1]);
-                            m1.put("val", map.get("val") == null ? "" : map.get("val").toString());
-                            md.put(str.split("\\$")[0], m1);
-                            break;
-                        }
-                    }
-                    if (md.get(str.split("\\$")[0]) == null) {
-                        Map<String, String> mm = new HashMap<String, String>();
-                        mm.put("name", str.split("\\$")[1]);
-                        mm.put("val", "");
-                        md.put(str.split("\\$")[0], mm);
-                    }
-                }
-                res.add(md);
-                start.setTime(start.getTime() + 3600 * 1000);
-            }
-        } catch (ParseException e) {
-            e.printStackTrace();
-            return null;
-        }
-        return res;
-    }
-
-    //十分钟查询
-    @Override
-    public List<Map<String, Object>> getRmCalpointValTim(String clock, String clocke, String itemid, String datatype) {
-        String sql = "";
-        String[] ids = itemid.split(",");
-        List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
-        Map<String, List<Map<String, Object>>> m = new HashMap<String, List<Map<String, Object>>>();
-        for (int i = 0; i < ids.length; i++) {
-            String id = ids[i];
-            TRmCalpoint tRmCalpoint = tRmCalpointMapper.selectByPrimaryKey(id);
-            String itemname = tRmCalpoint.getItemname();
-            String tagTable = tRmCalpoint.getBtype2(); // 十分钟来源数据表
-            String energytypeid = tRmCalpoint.getEnergytypeid();
-            String[] tens = tagTable.split("\\.");
-            String tenTab = tens[0]; // 十分钟表
-            String tagCol = tens[1]; // 十分钟字段
-            if (datatype.equalsIgnoreCase("ontime")) {
-                List<Map<String, Object>> l = new ArrayList<Map<String, Object>>();
-                if (energytypeid.equalsIgnoreCase("E")) {
-                    sql = "select clock," + tagCol + " val from " + tenTab + " where clock >='" + clock
-                            + "' and clock <='" + clocke + "' order by clock";
-                } else if (energytypeid.equalsIgnoreCase("W")) {
-                    //水数据有误,应记为10分钟开始;暂不清楚业务流程在哪里调用,不改
-                    sql = "select to_char(tim, 'YYYY-MM-DD HH24:mi') clock," + tagCol + " val from " + tenTab
-                            + " where to_char (tim, 'YYYY-MM-DD HH24:mi') >='" + clock
-                            + "' and to_char (tim, 'YYYY-MM-DD HH24:mi') <='" + clocke + "' order by tim";
-                } else {
-                    sql = "select to_char(tim, 'YYYY-MM-DD HH24:mi') clock," + tagCol + " val from " + tenTab
-                            + " where to_char (tim, 'YYYY-MM-DD HH24:mi') >='" + clock
-                            + "' and to_char (tim, 'YYYY-MM-DD HH24:mi') <='" + clocke + "' order by tim";
-                }
-                l = jdbcTemplate.queryForList(sql);
-                m.put(id + "$" + itemname, l);
-            } else {  //无累计值
-                return null;
-            }
-        }
-        try {
-            Date start = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
-            Date end = new SimpleDateFormat("yyyy-MM-dd HH").parse(clocke);
-            while (!start.after(end)) {
-                Map<String, Object> md = new HashMap<String, Object>();
-                md.put("tim", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(start));
-                for (String str : m.keySet()) {
-                    for (Map<String, Object> map : m.get(str)) {
-                        if (map != null && map.get("clock").toString()
-                                .equals(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(start))) {
-                            Map<String, String> m1 = new HashMap<String, String>();
-                            m1.put("name", str.split("\\$")[1]);
-                            m1.put("val", map.get("val") == null ? "" : map.get("val").toString());
-                            md.put(str.split("\\$")[0], m1);
-                            break;
-                        }
-                    }
-                    if (md.get(str.split("\\$")[0]) == null) {
-                        Map<String, String> mm = new HashMap<String, String>();
-                        mm.put("name", str.split("\\$")[1]);
-                        mm.put("val", "");
-                        md.put(str.split("\\$")[0], mm);
-                    }
-                }
-                res.add(md);
-                start.setTime(start.getTime() + 600 * 1000);
-            }
-        } catch (ParseException e) {
-            e.printStackTrace();
-            return null;
-        }
-        return res;
-    }
-
-    @Override
-    public PageList<Map<String, Object>> getDate312ForPage(HashMap<String, Object> parmas, Integer pageNum, Integer pageSize) {
-        PageHelper.startPage(pageNum, pageSize);
-        List<Map<String, Object>> rows = tRmCalpointMapper.getDate312(parmas);
-        PageList<Map<String, Object>> pageInfo = new PageList<Map<String, Object>>(rows);
-        return pageInfo;
-    }
-
-    @Override
-    public List<Map<String, Object>> getDate312ForChart(List<Map<String, Object>> list, int size) {
-        List<Map<String, Object>> rl = new ArrayList<Map<String, Object>>();
-        for (Map<String, Object> m : list) {
-            if (m.get("clock") != null && !m.get("clock").toString().isEmpty()) {
-                String clock = m.get("clock").toString();
-                if (clock.startsWith("[")) {
-                    JSONArray ja = JSONArray.parseArray(clock);
-                    m.put("clock", ja.get(0));
-                }
-            } else {
-                return null;
-            }
-            String itemid = m.get("itemid").toString();
-            // String timegranid = m.get("timegranid").toString();
-            m.put("size", size);
-            String itemname = tRmCalpointMapper.selectByPrimaryKey(itemid).getItemname();
-            List<Map<String, Object>> l = tRmCalpointMapper.getDate312ForChart(m);
-            Map<String, Object> mm = new HashMap<String, Object>();
-            mm.put(itemid + "$" + itemname, l);
-            rl.add(mm);
-        }
-        return rl;
-    }
-
-    @Override
-    public TRmCalpoint updateNewItem(Map<String, Object> parmas) {
-        tRmCalpointMapper.updateNewItem(parmas);
-        return tRmCalpointMapper.selectByPrimaryKey(parmas.get("itemid").toString());
-    }
-
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public void delCalpoint(String[] ids) {
-        logger.info("计量点维护表总共删除" + ids.length + "条数据");
-        for (int i = 0; i < ids.length; i++) {
-            logger.info("计量点维护表要删除的第" + (i + 1) + "条数据是" + getById(ids[i]).toString());
-            formulaMapper.deleteBycode(ids[i]);
-            this.delete(ids[i]);
-            Map<String, Object> params = new HashMap<String, Object>();
-            params.put("itemid", ids[i]);
-            tRmCalpointValueService.deleteByParams(params);
-        }
-        logger.info("计量点维护表总共成功删除" + ids.length + "条数据");
-    }
-
-    @Override
-    public List<Map<String, Object>> getInIdDate312(HashMap<String, Object> parmas) {
-        List<Map<String, Object>> rows = tRmCalpointMapper.getInIdDate312(parmas);
-        List<Map<String, Object>> pageInfo = new ArrayList<Map<String, Object>>(rows);
-        return pageInfo;
-    }
-
-    @Autowired
-    IEmsWebsocketLogService emsWebsocketLogService;
-    /**
-     *     每一种消息类型发送只存储一次
-     */
-    StringBuffer[] socketMessages;
-    @Override
-    /**
-     *  动力、水小时表定时统计(自动补全24小时内的小时用量值)
-     *  业务变更,暂时只读取动力
-     */
-    public void statHourData() {
-        Map<String, Object> m = new HashMap<String, Object>();
-        m.put("useflag", "1");
-        m.put("itemtype", "AUTO");
-        m.put("energytypeid", "'P','W','X'");
-        //业务变更,暂时只读取动力
-        //m.put("energytypeid", "'P'");
-        List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(m);
-        int size = 0;
-        if (l != null && l.size() > 0) {
-            List<EmsWebsocketLog> websocketLogs =new ArrayList<>();
-            socketMessages = new StringBuffer[12];
-            for(int i=0;i<socketMessages.length ;i++){
-                socketMessages[i] = new StringBuffer();
-            }
-            size = l.size();
-            Calendar cal = Calendar.getInstance();
-            cal.add(Calendar.HOUR_OF_DAY, -2);
-            // 2小时前
-            String clock2 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 1小时前
-            cal.add(Calendar.HOUR_OF_DAY, 1);
-            String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 当前小时
-            cal.add(Calendar.HOUR_OF_DAY, 1);
-            String clock = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 24小时前
-            cal.add(Calendar.DAY_OF_YEAR, -1);
-            String clock24 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            for (TRmCalpoint tc : l) {
-                // String source = tc.getSourceType(); // 数据源
-                String itemid = tc.getItemid();
-                String tag = tc.getTagCol(); // tag存储字段
-                String table = tc.getTagTable(); // 存储表
-                String tenvs = tc.getBtype2(); // 十分钟表字段
-                String r = this.restatHourData(itemid, clock);
-                if (!r.isEmpty()) {
-                    continue;
-                }
-                String[] tens = tenvs.split("\\.");
-                String tenTab = tens[0];
-                String tenCol = tens[1];
-                try {
-                    // 补齐之前24小时的缺失的用量值
-                    String sql = "select max(clock) from " + table + " where clock<'" + clock1 + "' and clock>'" + clock24 + "' and " + tag + " is not null";
-                    // 上个记录时间
-                    String ck = jdbcTemplate.queryForObject(sql, String.class);
-                    if (ck == null || ck.isEmpty() || ck.equals(clock2)) {
-                        continue;
-                    } else {
-                        // 上个已记录小时时间
-                        Date cls = new SimpleDateFormat("yyyy-MM-dd HH").parse(ck);
-                        String cksta = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cls);
-                        Date cle = new Date(cls.getTime() + 3600000l);
-                        String ckend = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cle);
-                        // 水系统数据四小时一次,读取上个记录小时最后仪表值,第十分钟数据作为起始值,确保数据无误差
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            cksta = new SimpleDateFormat("yyyy-MM-dd HH").format(cls);
-                            ckend = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + cksta + ":10"
-                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + ckend + ":10" + "') "
-                                    + "where rn = 1";
-                        } else {
-                            // 上个记录小时最后仪表值
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + cksta
-                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + ckend + "') "
-                                    + "where rn = 1";
-                        }
-                        BigDecimal hstrat = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                        // 水数据取整
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            hstrat = hstrat.setScale(4, RoundingMode.DOWN);
-                            // 当前小时开始仪表值, 水系统数据四小时一次,读取每小时第十分钟数据作为起始值,确保数据无误差
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + clock1
-                                    + ":10' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + clock + ":10') "
-                                    + "where rn = 1";
-                        } else {
-                            // 当前小时开始仪表值
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + clock1
-                                    + ":00' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + clock + ":00') "
-                                    + "where rn = 1";
-                        }
-                        BigDecimal hend = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                        // 水数据取整
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            hend = hend.setScale(4, RoundingMode.DOWN);
-                        }
-                        if (hend.doubleValue() >= hstrat.doubleValue()) {
-                            Date nowh = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1);
-                            // 计算小时数
-                            Long hos = ((nowh.getTime() - cls.getTime()) / 3600000) - 1;
-                            // 总差值
-                            BigDecimal tval = hend.subtract(hstrat);
-                            // 计算小时用量值
-                            BigDecimal val = BigDecimal.ZERO; // 小时用量值
-                            BigDecimal last = BigDecimal.ZERO; // 最后一小时
-                            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                                val = tval.divide(new BigDecimal(hos), 4, RoundingMode.DOWN);
-                                last = tval.subtract(val.multiply(new BigDecimal(hos - 1))).setScale(4, RoundingMode.DOWN);
-                            } else {
-                                val = tval.divide(new BigDecimal(hos), 5, RoundingMode.HALF_UP);
-                                last = val;
-                            }
-                            while (cle.before(nowh)) {
-                                // 用量值
-                                BigDecimal sval = val;
-                                // 需要补齐的clock
-                                String ckb = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
-                                // 最后1小时用量值(2小时间前)
-                                if (ckb.equals(clock2)) {
-                                    sval = last;
-                                }
-                                // 更新或者插入数据(小时用量值)
-                                if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
-                                    EmsPAiHourSumTab1 po = new EmsPAiHourSumTab1();
-                                    po.setClock(ckb);
-                                    po.setVal(sval.doubleValue(), tag);
-                                    if (emsPAiHourSumTab1Mapper.updateByPrimaryKeySelective(po) == 0) {
-                                        po.setInsertTime(new Date());
-                                        emsPAiHourSumTab1Mapper.insert(po);
-                                    }
-                                } else {
-                                    EmsWAiHourSumTab1 wo = new EmsWAiHourSumTab1();
-                                    wo.setClock(ckb);
-                                    wo.setVal(sval.doubleValue(), tag);
-                                    if (emsWAiHourSumTab1Mapper.updateByPrimaryKeySelective(wo) == 0) {
-                                        wo.setInsertTime(new Date());
-                                        emsWAiHourSumTab1Mapper.insert(wo);
-                                    }
-                                }
-                                cle = new Date(cle.getTime() + 3600000l);
-                            }
-                            // 如果补齐了昨天数据,重新计算昨天日数据
-                            if (ckend.substring(0, 10).equals(clock24.substring(0, 10))) {
-                                tRmCalpointValueService.restatCalpData(itemid, clock24.substring(0, 10), "DAY", "系统");
-                            }
-                        }
-                    }
-                } catch (Exception e) {
-                    TRmCalpointExValue tce = new TRmCalpointExValue();
-                    tce.setItemid(itemid);
-                    tce.setExtype("6"); // 历史用量值更新失败
-                    tce.setClock(clock1);
-                    tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-                    tce.setBz("历史用量值更新失败,clock:" + clock1 + ",tag:" + tag + ",table:" + table);
-                    tRmCalpointExValueService.add(tce);
-                    socketMessages[7].append(itemid + ",");
-                }
-            }
-            for(int o =0;o<socketMessages.length; o++){
-                if(socketMessages[o] != null && socketMessages[o].length()>0
-                        && !"null".equals(socketMessages[o].toString())
-                        && !"".equals(socketMessages[o].toString()))
-                {
-                    switch (o){
-                        case 1: socketMessages[1].append("十分钟数据变小"); break;
-                        case 2: socketMessages[2].append("配置不能为空"); break;
-                        case 3: socketMessages[3].append("十分钟表字段配置错误"); break;
-                        case 4: socketMessages[4].append("准点值读取失败"); break;
-                        case 5: socketMessages[5].append("十分钟数据不足以统计"); break;
-                        case 7: socketMessages[7].append("历史用量值更新失败"); break;
-                        case 8: socketMessages[8].append("十分钟数据查询错误"); break;
-                        case 9: socketMessages[9].append("用量数据增大超过限值"); break;
-                        case 10: socketMessages[10].append("用量数据低于最小值"); break;
-                    }
-                    EmsWebsocketLog websocketLog = new EmsWebsocketLog();
-                    websocketLog.setMessage(socketMessages[o].toString());
-                    websocketLog.setTitle("计控处");
-                    websocketLog.setState("0");
-                    websocketLog.setTips("计量点异常数据通知");
-                    websocketLogs.add(websocketLog);
-                }
-            }
-            if (websocketLogs != null && websocketLogs.size() > 0) {
-                emsWebsocketLogService.pushMessageByDataException(websocketLogs);
-            }
-        }
-        logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 动力、水小时表统计完毕,个数:" + size);
-    }
-
-    @Override
-    /**
-     *  动力、水小时表定时统计(自动补全24小时内的小时用量值)
-     */
-    public void statHourData(String clockstart, String clockend) {
-        Map<String, Object> m = new HashMap<String, Object>();
-        m.put("useflag", "1");
-        m.put("itemtype", "AUTO");
-        m.put("energytypeid", "'P','W','X'");
-        //业务变更,暂时只读取动力
-        //m.put("energytypeid", "'P'");
-        List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(m);
-        int size = 0;
-        if (l != null && l.size() > 0) {
-            size = l.size();
-            Calendar cal = Calendar.getInstance();
-            cal.add(Calendar.HOUR_OF_DAY, -2);
-            // 2小时前
-            String clock2 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 1小时前
-            cal.add(Calendar.HOUR_OF_DAY, 1);
-            String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 当前小时
-            cal.add(Calendar.HOUR_OF_DAY, 1);
-            String clock = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 24小时前
-            cal.add(Calendar.DAY_OF_YEAR, -1);
-            String clock24 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            for (TRmCalpoint tc : l) {
-                // String source = tc.getSourceType(); // 数据源
-                String itemid = tc.getItemid();
-                String tag = tc.getTagCol(); // tag存储字段
-                String table = tc.getTagTable(); // 存储表
-                String tenvs = tc.getBtype2(); // 十分钟表字段
-                String r = this.restatHourData(itemid, clock);
-                if (!r.isEmpty()) {
-                    continue;
-                }
-                String[] tens = tenvs.split("\\.");
-                String tenTab = tens[0];
-                String tenCol = tens[1];
-                try {
-                    // 补齐之前24小时的缺失的用量值
-                    String sql = "select max(clock) from " + table + " where clock<'" + clock1 + "' and clock>'" + clock24 + "' and " + tag + " is not null";
-                    // 上个记录时间
-                    String ck = jdbcTemplate.queryForObject(sql, String.class);
-                    if (ck == null || ck.isEmpty() || ck.equals(clock2)) {
-                        continue;
-                    } else {
-                        // 上个已记录小时时间
-                        Date cls = new SimpleDateFormat("yyyy-MM-dd HH").parse(ck);
-                        String cksta = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cls);
-                        Date cle = new Date(cls.getTime() + 3600000l);
-                        String ckend = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cle);
-                        // 水系统数据四小时一次,读取上个记录小时最后仪表值,第十分钟数据作为起始值,确保数据无误差
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            cksta = new SimpleDateFormat("yyyy-MM-dd HH").format(cls);
-                            ckend = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + cksta + ":10"
-                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + ckend + ":10" + "') "
-                                    + "where rn = 1";
-                        } else {
-                            // 上个记录小时最后仪表值
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + cksta
-                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + ckend + "') "
-                                    + "where rn = 1";
-                        }
-                        BigDecimal hstrat = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                        // 水数据取整
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            hstrat = hstrat.setScale(4, RoundingMode.DOWN);
-                            // 当前小时开始仪表值, 水系统数据四小时一次,读取每小时第十分钟数据作为起始值,确保数据无误差
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + clock1
-                                    + ":10' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + clock + ":10') "
-                                    + "where rn = 1";
-                        } else {
-                            // 当前小时开始仪表值
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + clock1
-                                    + ":00' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + clock + ":00') "
-                                    + "where rn = 1";
-                        }
-                        BigDecimal hend = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                        // 水数据取整
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            hend = hend.setScale(4, RoundingMode.DOWN);
-                        }
-                        if (hend.doubleValue() >= hstrat.doubleValue()) {
-                            Date nowh = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1);
-                            // 计算小时数
-                            Long hos = ((nowh.getTime() - cls.getTime()) / 3600000) - 1;
-                            // 总差值
-                            BigDecimal tval = hend.subtract(hstrat);
-                            // 计算小时用量值
-                            BigDecimal val = BigDecimal.ZERO; // 小时用量值
-                            BigDecimal last = BigDecimal.ZERO; // 最后一小时
-                            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                                val = tval.divide(new BigDecimal(hos), 4, RoundingMode.DOWN);
-                                last = tval.subtract(val.multiply(new BigDecimal(hos - 1))).setScale(0, RoundingMode.DOWN);
-                            } else {
-                                val = tval.divide(new BigDecimal(hos), 5, RoundingMode.HALF_UP);
-                                last = val;
-                            }
-                            while (cle.before(nowh)) {
-                                // 用量值
-                                BigDecimal sval = val;
-                                // 需要补齐的clock
-                                String ckb = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
-                                // 最后1小时用量值(2小时间前)
-                                if (ckb.equals(clock2)) {
-                                    sval = last;
-                                }
-                                // 更新或者插入数据(小时用量值)
-                                if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
-                                    EmsPAiHourSumTab1 po = new EmsPAiHourSumTab1();
-                                    po.setClock(ckb);
-                                    po.setVal(sval.doubleValue(), tag);
-                                    if (emsPAiHourSumTab1Mapper.updateByPrimaryKeySelective(po) == 0) {
-                                        po.setInsertTime(new Date());
-                                        emsPAiHourSumTab1Mapper.insert(po);
-                                    }
-                                } else {
-                                    EmsWAiHourSumTab1 wo = new EmsWAiHourSumTab1();
-                                    wo.setClock(ckb);
-                                    wo.setVal(sval.doubleValue(), tag);
-                                    if (emsWAiHourSumTab1Mapper.updateByPrimaryKeySelective(wo) == 0) {
-                                        wo.setInsertTime(new Date());
-                                        emsWAiHourSumTab1Mapper.insert(wo);
-                                    }
-                                }
-                                cle = new Date(cle.getTime() + 3600000l);
-                            }
-                            // 如果补齐了昨天数据,重新计算昨天日数据
-                            if (ckend.substring(0, 10).equals(clock24.substring(0, 10))) {
-                                tRmCalpointValueService.restatCalpData(itemid, clock24.substring(0, 10), "DAY", "系统");
-                            }
-                        }
-                    }
-                } catch (Exception e) {
-                    TRmCalpointExValue tce = new TRmCalpointExValue();
-                    tce.setItemid(itemid);
-                    tce.setExtype("6"); // 历史用量值更新失败
-                    tce.setClock(clock1);
-                    tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-                    tce.setBz("历史用量值更新失败,clock:" + clock1 + ",tag:" + tag + ",table:" + table);
-                    tRmCalpointExValueService.add(tce);
-                }
-            }
-        }
-        logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 动力、水小时表统计完毕,个数:" + size);
-    }
-
-    @Override
-    public String restatHourData(String itemid, String clock) {
-        TRmCalpoint tc = tRmCalpointMapper.selectByPrimaryKey(itemid);
-        if (!tc.getUseflag().equals("1")) {
-            return "计量点已经被禁用";
-        }
-        if (!tc.getItemtype().equalsIgnoreCase("AUTO")) {
-            return "只计算自动采集计量点";
-        }
-        if (!tc.getEnergytypeid().equalsIgnoreCase("W") && !tc.getEnergytypeid().equalsIgnoreCase("P") && !tc.getEnergytypeid().equalsIgnoreCase("X")) {
-            return "只计算水、动力计量点";
-        }
-        Date date = new Date();
-        try {
-            date = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
-        } 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();
-        BigDecimal avgValue = tc.getRangeVal() ==null ? new BigDecimal(999999) : tc.getRangeVal();
-        Calendar cal = Calendar.getInstance();
-        cal.setTime(date);
-        cal.add(Calendar.HOUR_OF_DAY, -1);
-        // 1小时前
-        String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-        // 获取配置
-        String tag = tc.getTagCol(); // tag存储字段
-        String table = tc.getTagTable(); // 存储表
-        String tenvs = tc.getBtype2(); // 十分钟表字段
-        if (tag == null || table == null || tenvs == null || tag.trim().isEmpty() || table.trim().isEmpty() || tenvs.trim().isEmpty()) {
-            TRmCalpointExValue tce = new TRmCalpointExValue();
-            tce.setItemid(itemid);
-            tce.setExtype("2"); // 配置错误
-            tce.setClock(clock);
-            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-            tce.setBz("配置不能为空");
-            tRmCalpointExValueService.add(tce);
-            socketMessages[2].append(itemid + ",");
-            return "配置不能为空";
-        }
-        String[] tens = tenvs.split("\\.");
-        if (tens.length != 2) {
-            TRmCalpointExValue tce = new TRmCalpointExValue();
-            tce.setItemid(itemid);
-            tce.setExtype("2"); // 配置错误
-            tce.setClock(clock);
-            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-            tce.setBz("十分钟表字段配置错误");
-            tRmCalpointExValueService.add(tce);
-            socketMessages[3].append(itemid + ",");
-            return "十分钟表字段配置错误";
-        }
-        String tenTab = tens[0];
-        String tenCol = tens[1];
-        String sql;
-        // 水系统数据四小时一次,读取每小时第十分钟数据作为起始值,确保数据无误差
-        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-            sql = "select " + tenCol + " val, to_char(tim,'YYYY-MM-DD HH24:MI:SS') tim from "
-                    + tenTab
-                    + " where " + tenCol + " is not null and to_char(tim, 'YYYY-MM-DD HH24:mi') >='" + clock1 + ":10'"
-                    + " and to_char(tim, 'YYYY-MM-DD HH24:mi')<='" + clock + ":10'"
-                    + " order by tim ";
-        } else {
-            sql = "select " + tenCol + " val, to_char(tim,'YYYY-MM-DD HH24:MI:SS') tim from "
-                    + tenTab
-                    + " where " + tenCol + " is not null and to_char(tim, 'YYYY-MM-DD HH24:mi') >='" + clock1 + ":00'"
-                    + " and to_char(tim, 'YYYY-MM-DD HH24:mi')<='" + clock + ":00'"
-                    + " order by tim ";
-        }
-        List<Map<String, Object>> lt = new ArrayList<Map<String, Object>>();
-        try {
-            lt = jdbcTemplate.queryForList(sql);
-        } catch (Exception e) {
-            TRmCalpointExValue tce = new TRmCalpointExValue();
-            tce.setItemid(itemid);
-            tce.setExtype("7"); // 十分钟数据错误
-            tce.setClock(clock1);
-            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-            tce.setBz("十分钟数据查询错误,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
-            tRmCalpointExValueService.add(tce);
-            socketMessages[8].append(itemid + ",");
-            return "十分钟数据查询错误";
-        }
-        if (lt == null || lt.size() < 1) {
-            TRmCalpointExValue tce = new TRmCalpointExValue();
-            tce.setItemid(itemid);
-            tce.setExtype("4"); // 十分钟数据不足以统计
-            tce.setClock(clock1);
-            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-            tce.setBz("十分钟数据不足以统计,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
-            tRmCalpointExValueService.add(tce);
-            socketMessages[5].append(itemid + ",");
-            return "十分钟数据不足以统计";
-        } else if (lt.size() == 1) {
-            TRmCalpointExValue tce = new TRmCalpointExValue();
-            tce.setItemid(itemid);
-            tce.setExtype("4"); // 十分钟数据不足以统计
-            tce.setClock(clock1);
-            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-            tce.setBz("十分钟数据不足以统计,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
-            tRmCalpointExValueService.add(tce);
-            socketMessages[5].append(itemid + ",");
-            // 当前小时准点值,水准点起始值从10分钟开始计算
-            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                sql = "select " + tenCol + " from " + tenTab + " where to_char(tim, 'YYYY-MM-DD HH24:mi') = '" + clock + ":10'";
-            } else {
-                sql = "select " + tenCol + " from " + tenTab + " where to_char(tim, 'YYYY-MM-DD HH24:mi') = '" + clock + ":00'";
-            }
-            try {
-                BigDecimal val = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                // 水数据取整
-                if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                    val = val.setScale(4, RoundingMode.DOWN);
-                }
-                if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
-                    EmsPAiHourSumTab1Org po = new EmsPAiHourSumTab1Org();
-                    po.setClock(clock);
-                    po.setVal(val.doubleValue(), tag);
-                    if (emsPAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(po) == 0) {
-                        po.setInsertTime(new Date());
-                        emsPAiHourSumTab1OrgMapper.insert(po);
-                    }
-                } else {
-                    EmsWAiHourSumTab1Org wo = new EmsWAiHourSumTab1Org();
-                    wo.setClock(clock);
-                    wo.setVal(val.doubleValue(), tag);
-                    if (emsWAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(wo) == 0) {
-                        wo.setInsertTime(new Date());
-                        emsWAiHourSumTab1OrgMapper.insert(wo);
-                    }
-                }
-            } catch (Exception e) {
-                tce = new TRmCalpointExValue();
-                tce.setItemid(itemid);
-                tce.setExtype("3"); // 准点值错误
-                tce.setClock(clock);
-                tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-                tce.setBz("准点值读取失败,clock:" + clock + ",col:" + tenCol + ",table:" + tenTab);
-                tRmCalpointExValueService.add(tce);
-                socketMessages[4].append(itemid + ",");
-                logger.error("准点数据查询失败,clock:" + clock);
-            }
-        } else {
-            BigDecimal hval = BigDecimal.ZERO; // 小时用量值计算(十分钟累加)
-            BigDecimal val1 = BigDecimal.ZERO; // 开始仪表值
-            BigDecimal val2 = BigDecimal.ZERO; // 结束仪表值
-            BigDecimal tenval = BigDecimal.ZERO; // 十分钟用量值
-            try {
-                for (int i = 0; i < lt.size(); i++) {
-                    Map<String, Object> ma = lt.get(i);
-                    // 水数据取整
-                    if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                        val2 = new BigDecimal(ma.get("VAL").toString()).setScale(4, RoundingMode.DOWN);
-                    } else {
-                        val2 = new BigDecimal(ma.get("VAL").toString());
-                    }
-                    if (i == 0) {
-                        val1 = val2;
-                        continue;
-                    }
-                    tenval = val2.subtract(val1);
-                    // 水处理
-                    //if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                        // 大于等于0
-                        if (tenval.doubleValue() >= 0) {
-                            // 检查流量计处理。如果十分钟数据超出跳变范围就是错误的数据
-                            if (tenval.compareTo(avgValue) == -1) {
-                                hval = hval.add(tenval);
-                            } else {
-                                hval = hval.add(BigDecimal.ZERO);
-                            }
-                            //暂时不做判断,水数据四小时一次,等时间间距变小,再做处理
-                            // 数据增加超过最大值以上,异常,预警
-                            if (tenval.doubleValue() >= new BigDecimal(maxValue).doubleValue()) {
-                                // 记录异常数据
-                                TRmCalpointExValue tce = new TRmCalpointExValue();
-                                tce.setItemid(itemid);
-                                // 四小时水数据增大超过限值
-                                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("用量数据增大超过限值"+maxValue+",clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
-                                tRmCalpointExValueService.add(tce);
-                                socketMessages[9].append(itemid + ",");
-                            }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);
-                                socketMessages[10].append(itemid + ",");
-                            }
-                        } else {
-                            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);
-                                }
-                            }
-                            //八万煤气柜柜容,特殊运算不计入
-                            if (!"DL421P00770002".equals(itemid)) {
-                            // 记录异常数据
-                            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);
-                            socketMessages[1].append(itemid + ",");
-                            }
-                        }
-                    //} 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;
-                }
-            } catch (Exception e) {
-                return "小时用量值统计错误";
-            }
-            // 更新或者插入数据(小时用量值)
-            if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
-                EmsPAiHourSumTab1 po = new EmsPAiHourSumTab1();
-                po.setClock(clock1);
-                po.setVal(hval.doubleValue(), tag);
-                try{
-                    if (emsPAiHourSumTab1Mapper.updateByPrimaryKeySelective(po) == 0) {
-                        po.setInsertTime(new Date());
-                        emsPAiHourSumTab1Mapper.insert(po);
-                    }
-                }catch (Exception e){
-                    logger.info("小时数据出错:" + itemid);
-                    e.printStackTrace();
-                }
-
-            } else {
-                EmsWAiHourSumTab1 wo = new EmsWAiHourSumTab1();
-                wo.setClock(clock1);
-                wo.setVal(hval.doubleValue(), tag);
-                if (emsWAiHourSumTab1Mapper.updateByPrimaryKeySelective(wo) == 0) {
-                    wo.setInsertTime(new Date());
-                    emsWAiHourSumTab1Mapper.insert(wo);
-                }
-            }
-            // 水处理
-            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                // 当前小时准点值
-                sql = "select " + tenCol + " from " + tenTab + " where to_char(tim, 'YYYY-MM-DD HH24:mi') = '" + clock + ":10'";
-            } else {
-                // 当前小时准点值
-                sql = "select " + tenCol + " from " + tenTab + " where to_char(tim, 'YYYY-MM-DD HH24:mi') = '" + clock + ":00'";
-            }
-            try {
-                BigDecimal val = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                // 水数据取整
-                if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                    val = val.setScale(4, RoundingMode.DOWN);
-                }
-                if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
-                    EmsPAiHourSumTab1Org po = new EmsPAiHourSumTab1Org();
-                    po.setClock(clock);
-                    po.setVal(val.doubleValue(), tag);
-                    if (emsPAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(po) == 0) {
-                        po.setInsertTime(new Date());
-                        emsPAiHourSumTab1OrgMapper.insert(po);
-                    }
-                } else {
-                    EmsWAiHourSumTab1Org wo = new EmsWAiHourSumTab1Org();
-                    wo.setClock(clock);
-                    wo.setVal(val.doubleValue(), tag);
-                    if (emsWAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(wo) == 0) {
-                        wo.setInsertTime(new Date());
-                        emsWAiHourSumTab1OrgMapper.insert(wo);
-                    }
-                }
-            } catch (Exception e) {
-                TRmCalpointExValue tce = new TRmCalpointExValue();
-                tce.setItemid(itemid);
-                tce.setExtype("3"); // 准点值错误
-                tce.setClock(clock);
-                tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-                tce.setBz("准点值读取失败,clock:" + clock + ",col:" + tenCol + ",table:" + tenTab);
-                tRmCalpointExValueService.add(tce);
-                socketMessages[4].append(itemid + ",");
-                logger.error("准点数据查询失败,clock:" + clock);
-            }
-        }
-        return "";
-    }
-
-    @Override
-    public String restatHourDate(String itemid, String clock, String clockend) {
-        Date start = new Date();
-        Date end = new Date();
-        String res = "";
-        try {
-            List<TRmCalpoint> l = null;
-            Map<String, Object> m = null;
-            if (itemid.equals("all")) {
-                m = new HashMap<String, Object>();
-                m.put("useflag", "1");
-                m.put("itemtype", "AUTO");
-                m.put("energytypeid", "'P','W','X'");
-            } else {
-                m = new HashMap<String, Object>();
-                m.put("itemid", itemid);
-            }
-            l = tRmCalpointMapper.selectLikeByParameters(m);
-            if (l.size() == 0) {
-                return "计量点数据为空";
-            }
-            end = new SimpleDateFormat("yyyy-MM-dd HH").parse(clockend);
-            for (TRmCalpoint tc : l) {
-                start = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
-                while (!start.after(end)) {
-                    String r = this.restatHourData(tc.getItemid(), new SimpleDateFormat("yyyy-MM-dd HH").format(start));
-                    if (res.isEmpty() && r != null) {
-                        res = r;
-                    }
-                    start = new Date(start.getTime() + 3600 * 1000);
-                }
-            }
-        } catch (ParseException e) {
-            return "日期格式错误";
-        }
-        return res;
-    }
-
-    @Override
-    public String restatHourDateE(String clock, String clockend) {
-        Date start = new Date();
-        Date end = new Date();
-        String res = "";
-        try {
-            end = new SimpleDateFormat("yyyy-MM-dd HH").parse(clockend);
-            start = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
-            while (!start.after(end)) {
-                String r = this.restatHourDataE(new SimpleDateFormat("yyyy-MM-dd HH").format(start));
-                if (res.isEmpty() && r != null) {
-                    res = r;
-                }
-                start = new Date(start.getTime() + 3600 * 1000);
-            }
-        } catch (ParseException e) {
-            return "日期格式错误";
-        }
-        return res;
-    }
-
-
-    @Override
-    public String restatHourDataE(String clock) {
-        Date date = new Date();
-        try {
-            // clock,  2021-04-22 09
-            date = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
-        } catch (ParseException e) {
-            return "日期格式错误";
-        }
-        Calendar cal = Calendar.getInstance();
-        cal.setTime(date);
-        cal.add(Calendar.HOUR_OF_DAY, -1);
-        // 1小时前 2021-04-22 09
-        String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-        Map<String, Object> parmas = new HashMap<String, Object>();
-        parmas.put("clock", clock + ":00:00");
-        parmas.put("clocke", clock + ":09:00"); // 由于采集数据写入延迟,这里整点后9分钟内的算作整点的数据,比如2021/4/22 9:04:12 会当成 2021/4/22 9:00:00 的数据
-        try {
-            // 数据量太多,这里只要整点值
-            List<EmsEHistory> ehList = emsEHistoryMapper.getEmsEHistoryByDate(parmas);
-            if (ehList.size() > 0) {
-                // 数据是否已经存在
-                boolean exists = true;
-                // 分钟clock - 2021-04-22 09:00
-                String clockM = clock + ":00";
-                EmsETiming e = emsETimingMapper.selectByPrimaryKey(clockM);
-                if (e == null) {
-                    exists = false;
-                    e = new EmsETiming();
-                    e.setInsertTime(new Date());
-                    e.setClock(clockM);
-                }
-                for (EmsEHistory eeh : ehList) {
-                    // 服务器-电开关号 例如:device/iec102-42-160/0637/totalpower
-                    String head = eeh.geteLine();
-                    if (head.split("/").length != 4) {
-                        logger.error(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "-数据格式错误-" + head);
-                        continue;
-                    }
-                    String line = "";
-                    if (head.split("/")[1].endsWith("13-200")) {
-                        line = "1";
-                    } else if (head.split("/")[1].endsWith("56-201")) {
-                        line = "2";
-                    } else if (head.split("/")[1].endsWith("56-202")) {
-                        line = "3";
-                    } else if (head.split("/")[1].endsWith("32-158")) {
-                        line = "4";
-                    } else if (head.split("/")[1].endsWith("42-158")) {
-                        line = "5";
-                    } else if (head.split("/")[1].endsWith("42-159")) {
-                        line = "6";
-                    } else if (head.split("/")[1].endsWith("42-160")) {
-                        line = "7";
-                    } else {
-                        continue;
-                    }
-                    // 电开关号,例如: 0637
-                    String code = line + head.split("/")[2];
-                    // 数据 例如:{"感性无功":27.09,"容性无功":3.71,"正向有功":143.42,"反向有功":16.38}
-                    String eData = eeh.geteData();
-                    JSONObject jo = JSONObject.parseObject(eData);
-                    e.setVal(code, jo.getString("正向有功"), "f");
-                    e.setVal(code, jo.getString("反向有功"), "r");
-                }
-                // 更新
-                if (exists) {
-                    emsETimingMapper.updateByPrimaryKeySelective(e);
-                } else {// 新增
-                    emsETimingMapper.insert(e);
-                }
-                // 从EMS_E_TIMING读取小时准点值-并且写入数据库
-                Map<String, Object> mp = emsETimingMapper.getHourPointVal(clockM);
-                // 整点数据 (clock)
-                EmsEAiHourSumTab1Org eeho = new EmsEAiHourSumTab1Org();
-                if (mp != null && mp.size() > 0) {
-                    eeho.setClock(clock);
-                    eeho = EmsEAiUtil.setValByMap(eeho, mp);
-                    int rs = emsEAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(eeho);
-                    if (rs == 0) {
-                        eeho.setInsertTime(new Date());
-                        emsEAiHourSumTab1OrgMapper.insert(eeho);
-                    }
-                }
-                // 上一个小时
-                EmsEAiHourSumTab1Org eeho1 = emsEAiHourSumTab1OrgMapper.selectByPrimaryKey(clock1);
-                // 小时累计值 = 当前小时准点值 - 前1小时小时准点值
-                if (eeho.getClock() == null || eeho.getClock().isEmpty() || eeho1 == null || eeho1.getClock() == null || eeho1.getClock().isEmpty()) {
-                    logger.error("数据表EMS_E_AI_HOUR_SUM_TAB1_ORG缺少数据:" + clock);
-                } else {
-                    EmsEAiHourSumTab1 eeh = new EmsEAiHourSumTab1();
-                    eeh.setClock(clock1);
-                    eeh = EmsEAiUtil.setVal(eeh, eeho, eeho1);
-                    int rs = emsEAiHourSumTab1Mapper.updateByPrimaryKeySelective(eeh);
-                    if (rs == 0) {
-                        eeh.setInsertTime(new Date());
-                        emsEAiHourSumTab1Mapper.insert(eeh);
-                    }
-                }
-            }
-        } catch (Exception e) {
-            logger.error("重新生成单个小时的电表数据错误", e);
-            return "重新计算单个小时的电表数据错误";
-        }
-        return null;
-    }
-
-    @Override
-    /**
-     *  从十分钟补全水数据,弃用
-     */
-    public void resData(String clockstart,String itemId) {
-        Map<String, Object> m = new HashMap<String, Object>();
-        m.put("useflag", "1");
-        m.put("itemtype", "AUTO");
-        m.put("energytypeid", "'W'");
-        m.put("itemid", itemId);
-        List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(m);
-        int size = 0;
-        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        if (l != null && l.size() > 0 && !"".equals(clockstart)) {
-            size = l.size();
-            Calendar cal = Calendar.getInstance();
-            Date start=new Date();
-            try {
-                start = sf.parse(clockstart + " 00:10:00");
-            } catch (ParseException e) {
-                e.printStackTrace();
-            }
-            cal.setTime(start);
-            cal.add(Calendar.HOUR_OF_DAY, -2);
-            // 2小时前
-            String clock2 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 1小时前
-            cal.add(Calendar.HOUR_OF_DAY, 1);
-            String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 当前小时
-            cal.add(Calendar.HOUR_OF_DAY, 1);
-            String clock = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            // 24小时前
-            cal.add(Calendar.DAY_OF_YEAR, -1);
-            String clock24 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
-            String sql = "";
-            //String ck = "";
-            for (TRmCalpoint tc : l) {
-                // String source = tc.getSourceType(); // 数据源
-                String itemid = tc.getItemid();
-                String tag = tc.getTagCol(); // tag存储字段
-                String table = tc.getTagTable(); // 存储表
-                String tenvs = tc.getBtype2(); // 十分钟表字段
-                String r = this.restatHourData(itemid, clock);
-                if (!r.isEmpty()) {
-                    continue;
-                }
-                String[] tens = tenvs.split("\\.");
-                String tenTab = tens[0];
-                String tenCol = tens[1];
-                try {
-                    // 补齐之前24小时的缺失的用量值
-                    //sql = "select max(clock) from " + table + " where clock<'" + clock1 + "' and clock>'" + clock24 + "' and " + tag + " is not null";
-                    //// 上个记录时间
-                    //String ck = jdbcTemplate.queryForObject(sql, String.class);
-                    //if (ck == null || ck.isEmpty() || ck.equals(clock2)) {
-                    //    continue;
-                    //} else {
-                        // 上个已记录小时时间
-                        Date cls = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock24);
-                        String cksta = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cls);
-                        Date cle = new Date(cls.getTime() + 3600000L);
-                        String ckend = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cle);
-                        // 水系统数据四小时一次,读取上个记录小时最后仪表值,第十分钟数据作为起始值,确保数据无误差
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            cksta = new SimpleDateFormat("yyyy-MM-dd HH").format(cls);
-                            ckend = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + cksta + ":10"
-                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + ckend + ":10" + "') "
-                                    + "where rn = 1";
-                        }// else {
-                        //    // 上个记录小时最后仪表值
-                        //    sql = "select val from "
-                        //            + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
-                        //            + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                        //            + cksta
-                        //            + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                        //            + ckend + "') "
-                        //            + "where rn = 1";
-                        //}
-                        BigDecimal hstrat = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                        // 水数据取整
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            hstrat = hstrat.setScale(4, RoundingMode.DOWN);
-                            // 当前小时开始仪表值, 水系统数据四小时一次,读取每小时第十分钟数据作为起始值,确保数据无误差
-                            sql = "select val from "
-                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
-                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                                    + clock1
-                                    + ":10' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                                    + clock + ":10') "
-                                    + "where rn = 1";
-                        }// else {
-                        //    // 当前小时开始仪表值
-                        //    sql = "select val from "
-                        //            + "(select " + tenCol + " val,row_number() over (order by tim) rn "
-                        //            + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
-                        //            + clock1
-                        //            + ":00' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
-                        //            + clock + ":00') "
-                        //            + "where rn = 1";
-                        //}
-                        BigDecimal hend = jdbcTemplate.queryForObject(sql, BigDecimal.class);
-                        // 水数据取整
-                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                            hend = hend.setScale(4, RoundingMode.DOWN);
-                        }
-                        if (hend.doubleValue() >= hstrat.doubleValue()) {
-                            Date nowh = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1);
-                            // 计算小时数
-                            Long hos = ((nowh.getTime() - cls.getTime()) / 3600000) - 1;
-                            // 总差值
-                            BigDecimal tval = hend.subtract(hstrat);
-                            // 计算小时用量值
-                            BigDecimal val = BigDecimal.ZERO; // 小时用量值
-                            BigDecimal last = BigDecimal.ZERO; // 最后一小时
-                            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
-                                if(!tval.equals( BigDecimal.ZERO)) {
-                                    val = tval.divide(new BigDecimal(hos), 0, RoundingMode.DOWN);
-                                }
-                                last = tval.subtract(val.multiply(new BigDecimal(hos - 1))).setScale(0, RoundingMode.DOWN);
-                            }// else {
-                            //    val = tval.divide(new BigDecimal(hos), 5, RoundingMode.HALF_UP);
-                            //    last = val;
-                            //}
-                            while (cle.before(nowh)) {
-                                // 用量值
-                                BigDecimal sval = val;
-                                // 需要补齐的clock
-                                String ckb = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
-                                // 最后1小时用量值(2小时间前)
-                                if (ckb.equals(clock2)) {
-                                    sval = last;
-                                }
-                                // 更新或者插入数据(小时用量值)
-                                //if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
-                                //    EmsPAiHourSumTab1 po = new EmsPAiHourSumTab1();
-                                //    po.setClock(ckb);
-                                //    po.setVal(sval.doubleValue(), tag);
-                                //    if (emsPAiHourSumTab1Mapper.updateByPrimaryKeySelective(po) == 0) {
-                                //        po.setInsertTime(new Date());
-                                //        emsPAiHourSumTab1Mapper.insert(po);
-                                //    }
-                                //} else {
-                                EmsWAiHourSumTab1 wo = new EmsWAiHourSumTab1();
-                                wo.setClock(ckb);
-                                wo.setVal(sval.doubleValue(), tag);
-                                if (emsWAiHourSumTab1Mapper.updateByPrimaryKeySelective(wo) == 0) {
-                                    wo.setInsertTime(new Date());
-                                    emsWAiHourSumTab1Mapper.insert(wo);
-                                }
-                                //}
-                                cle = new Date(cle.getTime() + 3600000L);
-                            }
-                            // 如果补齐了昨天数据,重新计算昨天日数据
-                            if (ckend.substring(0, 10).equals(clock24.substring(0, 10))) {
-                                tRmCalpointValueService.restatCalpData(itemid, clock24.substring(0, 10), "DAY", "系统");
-                            }
-                        }
-                } catch (Exception e) {
-                    TRmCalpointExValue tce = new TRmCalpointExValue();
-                    tce.setItemid(itemid);
-                    tce.setExtype("6"); // 历史用量值更新失败
-                    tce.setClock(clock1);
-                    tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-                    tce.setBz("历史用量值更新失败,clock:" + clock1 + ",tag:" + tag + ",table:" + table);
-                    tRmCalpointExValueService.add(tce);
-                }
-            }
-            logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 动力、水小时表统计完毕,个数:" + size);
-        }
-    }
-
-    @Override
-    public Integer getSoleSource(TRmCalpoint tRmCalpoint) {
-       return tRmCalpointMapper.getSoleSource(tRmCalpoint);
-    }
-}
+package com.steerinfo.ems.trmcalpoint.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.steerinfo.ems.Utils.EmsEAiUtil;
+import com.steerinfo.ems.emseaihoursumtab1.mapper.EmsEAiHourSumTab1Mapper;
+import com.steerinfo.ems.emseaihoursumtab1.model.EmsEAiHourSumTab1;
+import com.steerinfo.ems.emseaihoursumtab1org.mapper.EmsEAiHourSumTab1OrgMapper;
+import com.steerinfo.ems.emseaihoursumtab1org.model.EmsEAiHourSumTab1Org;
+import com.steerinfo.ems.emsehistory.mapper.EmsEHistoryMapper;
+import com.steerinfo.ems.emsehistory.model.EmsEHistory;
+import com.steerinfo.ems.emsetiming.mapper.EmsETimingMapper;
+import com.steerinfo.ems.emsetiming.model.EmsETiming;
+import com.steerinfo.ems.emspaihoursumtab1.mapper.EmsPAiHourSumTab1Mapper;
+import com.steerinfo.ems.emspaihoursumtab1.model.EmsPAiHourSumTab1;
+import com.steerinfo.ems.emspaihoursumtab1org.mapper.EmsPAiHourSumTab1OrgMapper;
+import com.steerinfo.ems.emspaihoursumtab1org.model.EmsPAiHourSumTab1Org;
+import com.steerinfo.ems.emswaihoursumtab1.mapper.EmsWAiHourSumTab1Mapper;
+import com.steerinfo.ems.emswaihoursumtab1.model.EmsWAiHourSumTab1;
+import com.steerinfo.ems.emswaihoursumtab1org.mapper.EmsWAiHourSumTab1OrgMapper;
+import com.steerinfo.ems.emswaihoursumtab1org.model.EmsWAiHourSumTab1Org;
+import com.steerinfo.ems.emswebsocketlog.model.EmsWebsocketLog;
+import com.steerinfo.ems.emswebsocketlog.service.IEmsWebsocketLogService;
+import com.steerinfo.ems.formula.mapper.FormulaMapper;
+import com.steerinfo.ems.trmcalpoint.mapper.TRmCalpointMapper;
+import com.steerinfo.ems.trmcalpoint.model.TRmCalpoint;
+import com.steerinfo.ems.trmcalpoint.service.ITRmCalpointService;
+import com.steerinfo.ems.trmcalpointexvalue.model.TRmCalpointExValue;
+import com.steerinfo.ems.trmcalpointexvalue.service.ITRmCalpointExValueService;
+import com.steerinfo.ems.trmcalpointvalue.service.ITRmCalpointValueService;
+import com.steerinfo.framework.mapper.IBaseMapper;
+import com.steerinfo.framework.service.impl.BaseServiceImpl;
+import com.steerinfo.framework.service.pagehelper.PageHelper;
+import com.steerinfo.framework.service.pagehelper.PageList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * TRmCalpoint服务实现:
+ *
+ * @author 王金涛
+ * @version 1.0-SNAPSHORT 2019-10-11
+ * 类描述
+ * 修订历史:
+ * 日期:2019-10-11
+ * 作者:王金涛
+ * 参考:
+ * 描述:TRmCalpoint服务实现
+ * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
+ * @see null
+ */
+@Service(value = "tRmCalpointService")
+public class TRmCalpointServiceImpl extends BaseServiceImpl<TRmCalpoint, String> implements ITRmCalpointService {
+    private static final Logger logger = LoggerFactory.getLogger(TRmCalpointServiceImpl.class);
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    private TRmCalpointMapper tRmCalpointMapper;
+
+    @Autowired
+    private FormulaMapper formulaMapper;
+
+    @Autowired
+    ITRmCalpointValueService tRmCalpointValueService;
+
+    @Autowired
+    ITRmCalpointExValueService tRmCalpointExValueService;
+
+    @Autowired
+    EmsPAiHourSumTab1Mapper emsPAiHourSumTab1Mapper;
+
+    @Autowired
+    EmsPAiHourSumTab1OrgMapper emsPAiHourSumTab1OrgMapper;
+
+    @Autowired
+    EmsWAiHourSumTab1Mapper emsWAiHourSumTab1Mapper;
+
+    @Autowired
+    EmsWAiHourSumTab1OrgMapper emsWAiHourSumTab1OrgMapper;
+
+    @Autowired
+    private EmsEHistoryMapper emsEHistoryMapper;
+
+    @Autowired
+    private EmsETimingMapper emsETimingMapper;
+
+    @Autowired
+    private EmsEAiHourSumTab1OrgMapper emsEAiHourSumTab1OrgMapper;
+
+    @Autowired
+    private EmsEAiHourSumTab1Mapper emsEAiHourSumTab1Mapper;
+
+    @Override
+    protected IBaseMapper<TRmCalpoint, String> getMapper() {
+        return tRmCalpointMapper;
+    }
+
+    @Override
+    public List<Map> getRmCalpoint() {
+        return tRmCalpointMapper.getRmCalpoint();
+    }
+
+    @Override
+    synchronized public String getMaxId(String head) {
+        return this.tRmCalpointMapper.getMaxId(head);
+    }
+
+    @Override
+    public List<Map<String, Object>> getRmCalpointVal(String clock, String clocke, String itemid, String datatype) {
+        String sql = "";
+        String[] ids = itemid.split(",");
+        List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
+        Map<String, List<Map<String, Object>>> m = new HashMap<String, List<Map<String, Object>>>();
+        for (int i = 0; i < ids.length; i++) {
+            String id = ids[i];
+            TRmCalpoint tRmCalpoint = tRmCalpointMapper.selectByPrimaryKey(id);
+            String itemname = tRmCalpoint.getItemname();
+            // 累计来源数据表
+            String tagTable = tRmCalpoint.getTagTable();
+            // 累计来源数据列
+            String tagCol = tRmCalpoint.getTagCol();
+            if (datatype.equalsIgnoreCase("sum")) {
+                sql = "select clock," + tagCol + " val from " + tagTable + " where clock>='" + clock + "' and clock <='" + clocke + "' order by clock";
+                List<Map<String, Object>> l = jdbcTemplate.queryForList(sql);
+                m.put(id + "$" + itemname, l);
+            } else if (datatype.equalsIgnoreCase("ontime")) {
+                List<Map<String, Object>> l = new ArrayList<Map<String, Object>>();
+                sql = "select clock," + tagCol + " val from " + tagTable + "_org " + " where clock>='" + clock + "' and clock <='" + clocke + "' order by clock";
+                l = jdbcTemplate.queryForList(sql);
+                m.put(id + "$" + itemname, l);
+            }
+        }
+        try {
+            Date start = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
+            Date end = new SimpleDateFormat("yyyy-MM-dd HH").parse(clocke);
+            while (!start.after(end)) {
+                Map<String, Object> md = new HashMap<String, Object>();
+                md.put("tim", new SimpleDateFormat("yyyy-MM-dd HH").format(start));
+                for (String str : m.keySet()) {
+                    for (Map<String, Object> map : m.get(str)) {
+                        if (map != null && map.get("clock").toString().equals(new SimpleDateFormat("yyyy-MM-dd HH").format(start))) {
+                            Map<String, String> m1 = new HashMap<String, String>();
+                            m1.put("name", str.split("\\$")[1]);
+                            m1.put("val", map.get("val") == null ? "" : map.get("val").toString());
+                            md.put(str.split("\\$")[0], m1);
+                            break;
+                        }
+                    }
+                    if (md.get(str.split("\\$")[0]) == null) {
+                        Map<String, String> mm = new HashMap<String, String>();
+                        mm.put("name", str.split("\\$")[1]);
+                        mm.put("val", "");
+                        md.put(str.split("\\$")[0], mm);
+                    }
+                }
+                res.add(md);
+                start.setTime(start.getTime() + 3600 * 1000);
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+            return null;
+        }
+        return res;
+    }
+
+    //十分钟查询
+    @Override
+    public List<Map<String, Object>> getRmCalpointValTim(String clock, String clocke, String itemid, String datatype) {
+        String sql = "";
+        String[] ids = itemid.split(",");
+        List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
+        Map<String, List<Map<String, Object>>> m = new HashMap<String, List<Map<String, Object>>>();
+        for (int i = 0; i < ids.length; i++) {
+            String id = ids[i];
+            TRmCalpoint tRmCalpoint = tRmCalpointMapper.selectByPrimaryKey(id);
+            String itemname = tRmCalpoint.getItemname();
+            String tagTable = tRmCalpoint.getBtype2(); // 十分钟来源数据表
+            String energytypeid = tRmCalpoint.getEnergytypeid();
+            String[] tens = tagTable.split("\\.");
+            String tenTab = tens[0]; // 十分钟表
+            String tagCol = tens[1]; // 十分钟字段
+            if (datatype.equalsIgnoreCase("ontime")) {
+                List<Map<String, Object>> l = new ArrayList<Map<String, Object>>();
+                if (energytypeid.equalsIgnoreCase("E")) {
+                    sql = "select clock," + tagCol + " val from " + tenTab + " where clock >='" + clock
+                            + "' and clock <='" + clocke + "' order by clock";
+                } else if (energytypeid.equalsIgnoreCase("W")) {
+                    //水数据有误,应记为10分钟开始;暂不清楚业务流程在哪里调用,不改
+                    sql = "select to_char(tim, 'YYYY-MM-DD HH24:mi') clock," + tagCol + " val from " + tenTab
+                            + " where to_char (tim, 'YYYY-MM-DD HH24:mi') >='" + clock
+                            + "' and to_char (tim, 'YYYY-MM-DD HH24:mi') <='" + clocke + "' order by tim";
+                } else {
+                    sql = "select to_char(tim, 'YYYY-MM-DD HH24:mi') clock," + tagCol + " val from " + tenTab
+                            + " where to_char (tim, 'YYYY-MM-DD HH24:mi') >='" + clock
+                            + "' and to_char (tim, 'YYYY-MM-DD HH24:mi') <='" + clocke + "' order by tim";
+                }
+                l = jdbcTemplate.queryForList(sql);
+                m.put(id + "$" + itemname, l);
+            } else {  //无累计值
+                return null;
+            }
+        }
+        try {
+            Date start = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
+            Date end = new SimpleDateFormat("yyyy-MM-dd HH").parse(clocke);
+            while (!start.after(end)) {
+                Map<String, Object> md = new HashMap<String, Object>();
+                md.put("tim", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(start));
+                for (String str : m.keySet()) {
+                    for (Map<String, Object> map : m.get(str)) {
+                        if (map != null && map.get("clock").toString()
+                                .equals(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(start))) {
+                            Map<String, String> m1 = new HashMap<String, String>();
+                            m1.put("name", str.split("\\$")[1]);
+                            m1.put("val", map.get("val") == null ? "" : map.get("val").toString());
+                            md.put(str.split("\\$")[0], m1);
+                            break;
+                        }
+                    }
+                    if (md.get(str.split("\\$")[0]) == null) {
+                        Map<String, String> mm = new HashMap<String, String>();
+                        mm.put("name", str.split("\\$")[1]);
+                        mm.put("val", "");
+                        md.put(str.split("\\$")[0], mm);
+                    }
+                }
+                res.add(md);
+                start.setTime(start.getTime() + 600 * 1000);
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+            return null;
+        }
+        return res;
+    }
+
+    @Override
+    public PageList<Map<String, Object>> getDate312ForPage(HashMap<String, Object> parmas, Integer pageNum, Integer pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<Map<String, Object>> rows = tRmCalpointMapper.getDate312(parmas);
+        PageList<Map<String, Object>> pageInfo = new PageList<Map<String, Object>>(rows);
+        return pageInfo;
+    }
+
+    @Override
+    public List<Map<String, Object>> getDate312ForChart(List<Map<String, Object>> list, int size) {
+        List<Map<String, Object>> rl = new ArrayList<Map<String, Object>>();
+        for (Map<String, Object> m : list) {
+            if (m.get("clock") != null && !m.get("clock").toString().isEmpty()) {
+                String clock = m.get("clock").toString();
+                if (clock.startsWith("[")) {
+                    JSONArray ja = JSONArray.parseArray(clock);
+                    m.put("clock", ja.get(0));
+                }
+            } else {
+                return null;
+            }
+            String itemid = m.get("itemid").toString();
+            // String timegranid = m.get("timegranid").toString();
+            m.put("size", size);
+            String itemname = tRmCalpointMapper.selectByPrimaryKey(itemid).getItemname();
+            List<Map<String, Object>> l = tRmCalpointMapper.getDate312ForChart(m);
+            Map<String, Object> mm = new HashMap<String, Object>();
+            mm.put(itemid + "$" + itemname, l);
+            rl.add(mm);
+        }
+        return rl;
+    }
+
+    @Override
+    public TRmCalpoint updateNewItem(Map<String, Object> parmas) {
+        tRmCalpointMapper.updateNewItem(parmas);
+        return tRmCalpointMapper.selectByPrimaryKey(parmas.get("itemid").toString());
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void delCalpoint(String[] ids) {
+        logger.info("计量点维护表总共删除" + ids.length + "条数据");
+        for (int i = 0; i < ids.length; i++) {
+            logger.info("计量点维护表要删除的第" + (i + 1) + "条数据是" + getById(ids[i]).toString());
+            formulaMapper.deleteBycode(ids[i]);
+            this.delete(ids[i]);
+            Map<String, Object> params = new HashMap<String, Object>();
+            params.put("itemid", ids[i]);
+            tRmCalpointValueService.deleteByParams(params);
+        }
+        logger.info("计量点维护表总共成功删除" + ids.length + "条数据");
+    }
+
+    @Override
+    public List<Map<String, Object>> getInIdDate312(HashMap<String, Object> parmas) {
+        List<Map<String, Object>> rows = tRmCalpointMapper.getInIdDate312(parmas);
+        List<Map<String, Object>> pageInfo = new ArrayList<Map<String, Object>>(rows);
+        return pageInfo;
+    }
+
+    @Autowired
+    IEmsWebsocketLogService emsWebsocketLogService;
+    /**
+     *     每一种消息类型发送只存储一次
+     */
+    StringBuffer[] socketMessages;
+    @Override
+    /**
+     *  动力、水小时表定时统计(自动补全24小时内的小时用量值)
+     *  业务变更,暂时只读取动力
+     */
+    public void statHourData() {
+        Map<String, Object> m = new HashMap<String, Object>();
+        m.put("useflag", "1");
+        m.put("itemtype", "AUTO");
+        m.put("energytypeid", "'P','W','X'");
+        //业务变更,暂时只读取动力
+        //m.put("energytypeid", "'P'");
+        List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(m);
+        int size = 0;
+        if (l != null && l.size() > 0) {
+            List<EmsWebsocketLog> websocketLogs =new ArrayList<>();
+            socketMessages = new StringBuffer[12];
+            for(int i=0;i<socketMessages.length ;i++){
+                socketMessages[i] = new StringBuffer();
+            }
+            size = l.size();
+            Calendar cal = Calendar.getInstance();
+            cal.add(Calendar.HOUR_OF_DAY, -2);
+            // 2小时前
+            String clock2 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+            // 1小时前
+            cal.add(Calendar.HOUR_OF_DAY, 1);
+            String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+            // 当前小时
+            cal.add(Calendar.HOUR_OF_DAY, 1);
+            String clock = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+            // 24小时前
+            cal.add(Calendar.DAY_OF_YEAR, -1);
+            String clock24 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+            for (TRmCalpoint tc : l) {
+                // String source = tc.getSourceType(); // 数据源
+                String itemid = tc.getItemid();
+                String tag = tc.getTagCol(); // tag存储字段
+                String table = tc.getTagTable(); // 存储表
+                String tenvs = tc.getBtype2(); // 十分钟表字段
+                String r = this.restatHourData(itemid, clock);
+                if (!r.isEmpty()) {
+                    continue;
+                }
+                String[] tens = tenvs.split("\\.");
+                String tenTab = tens[0];
+                String tenCol = tens[1];
+                try {
+                    // 补齐之前24小时的缺失的用量值
+                    String sql = "select max(clock) from " + table + " where clock<'" + clock1 + "' and clock>'" + clock24 + "' and " + tag + " is not null";
+                    // 上个记录时间
+                    String ck = jdbcTemplate.queryForObject(sql, String.class);
+                    if (ck == null || ck.isEmpty() || ck.equals(clock2)) {
+                        continue;
+                    } else {
+                        // 上个已记录小时时间
+                        Date cls = new SimpleDateFormat("yyyy-MM-dd HH").parse(ck);
+                        String cksta = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cls);
+                        Date cle = new Date(cls.getTime() + 3600000l);
+                        String ckend = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cle);
+                        // 水系统数据四小时一次,读取上个记录小时最后仪表值,第十分钟数据作为起始值,确保数据无误差
+                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                            cksta = new SimpleDateFormat("yyyy-MM-dd HH").format(cls);
+                            ckend = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
+                            sql = "select val from "
+                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
+                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
+                                    + cksta + ":10"
+                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
+                                    + ckend + ":10" + "') "
+                                    + "where rn = 1";
+                        } else {
+                            // 上个记录小时最后仪表值
+                            sql = "select val from "
+                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
+                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
+                                    + cksta
+                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
+                                    + ckend + "') "
+                                    + "where rn = 1";
+                        }
+                        BigDecimal hstrat = jdbcTemplate.queryForObject(sql, BigDecimal.class);
+                        // 水数据取整
+                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                            hstrat = hstrat.setScale(4, RoundingMode.DOWN);
+                            // 当前小时开始仪表值, 水系统数据四小时一次,读取每小时第十分钟数据作为起始值,确保数据无误差
+                            sql = "select val from "
+                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
+                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
+                                    + clock1
+                                    + ":10' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
+                                    + clock + ":10') "
+                                    + "where rn = 1";
+                        } else {
+                            // 当前小时开始仪表值
+                            sql = "select val from "
+                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
+                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
+                                    + clock1
+                                    + ":00' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
+                                    + clock + ":00') "
+                                    + "where rn = 1";
+                        }
+                        BigDecimal hend = jdbcTemplate.queryForObject(sql, BigDecimal.class);
+                        // 水数据取整
+                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                            hend = hend.setScale(4, RoundingMode.DOWN);
+                        }
+                        if (hend.doubleValue() >= hstrat.doubleValue()) {
+                            Date nowh = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1);
+                            // 计算小时数
+                            Long hos = ((nowh.getTime() - cls.getTime()) / 3600000) - 1;
+                            // 总差值
+                            BigDecimal tval = hend.subtract(hstrat);
+                            // 计算小时用量值
+                            BigDecimal val = BigDecimal.ZERO; // 小时用量值
+                            BigDecimal last = BigDecimal.ZERO; // 最后一小时
+                            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                                val = tval.divide(new BigDecimal(hos), 4, RoundingMode.DOWN);
+                                last = tval.subtract(val.multiply(new BigDecimal(hos - 1))).setScale(4, RoundingMode.DOWN);
+                            } else {
+                                val = tval.divide(new BigDecimal(hos), 5, RoundingMode.HALF_UP);
+                                last = val;
+                            }
+                            while (cle.before(nowh)) {
+                                // 用量值
+                                BigDecimal sval = val;
+                                // 需要补齐的clock
+                                String ckb = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
+                                // 最后1小时用量值(2小时间前)
+                                if (ckb.equals(clock2)) {
+                                    sval = last;
+                                }
+                                // 更新或者插入数据(小时用量值)
+                                if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
+                                    EmsPAiHourSumTab1 po = new EmsPAiHourSumTab1();
+                                    po.setClock(ckb);
+                                    po.setVal(sval.doubleValue(), tag);
+                                    if (emsPAiHourSumTab1Mapper.updateByPrimaryKeySelective(po) == 0) {
+                                        po.setInsertTime(new Date());
+                                        emsPAiHourSumTab1Mapper.insert(po);
+                                    }
+                                } else {
+                                    EmsWAiHourSumTab1 wo = new EmsWAiHourSumTab1();
+                                    wo.setClock(ckb);
+                                    wo.setVal(sval.doubleValue(), tag);
+                                    if (emsWAiHourSumTab1Mapper.updateByPrimaryKeySelective(wo) == 0) {
+                                        wo.setInsertTime(new Date());
+                                        emsWAiHourSumTab1Mapper.insert(wo);
+                                    }
+                                }
+                                cle = new Date(cle.getTime() + 3600000l);
+                            }
+                            // 如果补齐了昨天数据,重新计算昨天日数据
+                            if (ckend.substring(0, 10).equals(clock24.substring(0, 10))) {
+                                tRmCalpointValueService.restatCalpData(itemid, clock24.substring(0, 10), "DAY", "系统");
+                            }
+                        }
+                    }
+                } catch (Exception e) {
+                    TRmCalpointExValue tce = new TRmCalpointExValue();
+                    tce.setItemid(itemid);
+                    tce.setExtype("6"); // 历史用量值更新失败
+                    tce.setClock(clock1);
+                    tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                    tce.setBz("历史用量值更新失败,clock:" + clock1 + ",tag:" + tag + ",table:" + table);
+                    tRmCalpointExValueService.add(tce);
+                    socketMessages[7].append(itemid + ",");
+                }
+            }
+            for(int o =0;o<socketMessages.length; o++){
+                if(socketMessages[o] != null && socketMessages[o].length()>0
+                        && !"null".equals(socketMessages[o].toString())
+                        && !"".equals(socketMessages[o].toString()))
+                {
+                    switch (o){
+                        case 1: socketMessages[1].append("十分钟数据变小"); break;
+                        case 2: socketMessages[2].append("配置不能为空"); break;
+                        case 3: socketMessages[3].append("十分钟表字段配置错误"); break;
+                        case 4: socketMessages[4].append("准点值读取失败"); break;
+                        case 5: socketMessages[5].append("十分钟数据不足以统计"); break;
+                        case 7: socketMessages[7].append("历史用量值更新失败"); break;
+                        case 8: socketMessages[8].append("十分钟数据查询错误"); break;
+                        case 9: socketMessages[9].append("用量数据增大超过限值"); break;
+                        case 10: socketMessages[10].append("用量数据低于最小值"); break;
+                    }
+                    EmsWebsocketLog websocketLog = new EmsWebsocketLog();
+                    websocketLog.setMessage(socketMessages[o].toString());
+                    websocketLog.setTitle("计控处");
+                    websocketLog.setState("0");
+                    websocketLog.setTips("计量点异常数据通知");
+                    websocketLogs.add(websocketLog);
+                }
+            }
+            if (websocketLogs != null && websocketLogs.size() > 0) {
+                emsWebsocketLogService.pushMessageByDataException(websocketLogs);
+            }
+        }
+        logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 动力、水小时表统计完毕,个数:" + size);
+    }
+
+    @Override
+    /**
+     *  动力、水小时表定时统计(自动补全24小时内的小时用量值)
+     */
+    public void statHourData(String clockstart, String clockend) {
+        Map<String, Object> m = new HashMap<String, Object>();
+        m.put("useflag", "1");
+        m.put("itemtype", "AUTO");
+        m.put("energytypeid", "'P','W','X'");
+        //业务变更,暂时只读取动力
+        //m.put("energytypeid", "'P'");
+        List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(m);
+        int size = 0;
+        if (l != null && l.size() > 0) {
+            size = l.size();
+            Calendar cal = Calendar.getInstance();
+            cal.add(Calendar.HOUR_OF_DAY, -2);
+            // 2小时前
+            String clock2 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+            // 1小时前
+            cal.add(Calendar.HOUR_OF_DAY, 1);
+            String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+            // 当前小时
+            cal.add(Calendar.HOUR_OF_DAY, 1);
+            String clock = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+            // 24小时前
+            cal.add(Calendar.DAY_OF_YEAR, -1);
+            String clock24 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+            for (TRmCalpoint tc : l) {
+                // String source = tc.getSourceType(); // 数据源
+                String itemid = tc.getItemid();
+                String tag = tc.getTagCol(); // tag存储字段
+                String table = tc.getTagTable(); // 存储表
+                String tenvs = tc.getBtype2(); // 十分钟表字段
+                String r = this.restatHourData(itemid, clock);
+                if (!r.isEmpty()) {
+                    continue;
+                }
+                String[] tens = tenvs.split("\\.");
+                String tenTab = tens[0];
+                String tenCol = tens[1];
+                try {
+                    // 补齐之前24小时的缺失的用量值
+                    String sql = "select max(clock) from " + table + " where clock<'" + clock1 + "' and clock>'" + clock24 + "' and " + tag + " is not null";
+                    // 上个记录时间
+                    String ck = jdbcTemplate.queryForObject(sql, String.class);
+                    if (ck == null || ck.isEmpty() || ck.equals(clock2)) {
+                        continue;
+                    } else {
+                        // 上个已记录小时时间
+                        Date cls = new SimpleDateFormat("yyyy-MM-dd HH").parse(ck);
+                        String cksta = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cls);
+                        Date cle = new Date(cls.getTime() + 3600000l);
+                        String ckend = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cle);
+                        // 水系统数据四小时一次,读取上个记录小时最后仪表值,第十分钟数据作为起始值,确保数据无误差
+                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                            cksta = new SimpleDateFormat("yyyy-MM-dd HH").format(cls);
+                            ckend = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
+                            sql = "select val from "
+                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
+                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
+                                    + cksta + ":10"
+                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
+                                    + ckend + ":10" + "') "
+                                    + "where rn = 1";
+                        } else {
+                            // 上个记录小时最后仪表值
+                            sql = "select val from "
+                                    + "(select " + tenCol + " val,row_number() over (order by tim desc) rn "
+                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
+                                    + cksta
+                                    + "' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
+                                    + ckend + "') "
+                                    + "where rn = 1";
+                        }
+                        BigDecimal hstrat = jdbcTemplate.queryForObject(sql, BigDecimal.class);
+                        // 水数据取整
+                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                            hstrat = hstrat.setScale(4, RoundingMode.DOWN);
+                            // 当前小时开始仪表值, 水系统数据四小时一次,读取每小时第十分钟数据作为起始值,确保数据无误差
+                            sql = "select val from "
+                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
+                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
+                                    + clock1
+                                    + ":10' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
+                                    + clock + ":10') "
+                                    + "where rn = 1";
+                        } else {
+                            // 当前小时开始仪表值
+                            sql = "select val from "
+                                    + "(select " + tenCol + " val,row_number() over (order by tim) rn "
+                                    + "from " + tenTab + " where to_char(tim,'YYYY-MM-DD hh24:mi')>='"
+                                    + clock1
+                                    + ":00' and to_char(tim,'YYYY-MM-DD hh24:mi')<='"
+                                    + clock + ":00') "
+                                    + "where rn = 1";
+                        }
+                        BigDecimal hend = jdbcTemplate.queryForObject(sql, BigDecimal.class);
+                        // 水数据取整
+                        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                            hend = hend.setScale(4, RoundingMode.DOWN);
+                        }
+                        if (hend.doubleValue() >= hstrat.doubleValue()) {
+                            Date nowh = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1);
+                            // 计算小时数
+                            Long hos = ((nowh.getTime() - cls.getTime()) / 3600000) - 1;
+                            // 总差值
+                            BigDecimal tval = hend.subtract(hstrat);
+                            // 计算小时用量值
+                            BigDecimal val = BigDecimal.ZERO; // 小时用量值
+                            BigDecimal last = BigDecimal.ZERO; // 最后一小时
+                            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                                val = tval.divide(new BigDecimal(hos), 4, RoundingMode.DOWN);
+                                last = tval.subtract(val.multiply(new BigDecimal(hos - 1))).setScale(0, RoundingMode.DOWN);
+                            } else {
+                                val = tval.divide(new BigDecimal(hos), 5, RoundingMode.HALF_UP);
+                                last = val;
+                            }
+                            while (cle.before(nowh)) {
+                                // 用量值
+                                BigDecimal sval = val;
+                                // 需要补齐的clock
+                                String ckb = new SimpleDateFormat("yyyy-MM-dd HH").format(cle);
+                                // 最后1小时用量值(2小时间前)
+                                if (ckb.equals(clock2)) {
+                                    sval = last;
+                                }
+                                // 更新或者插入数据(小时用量值)
+                                if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
+                                    EmsPAiHourSumTab1 po = new EmsPAiHourSumTab1();
+                                    po.setClock(ckb);
+                                    po.setVal(sval.doubleValue(), tag);
+                                    if (emsPAiHourSumTab1Mapper.updateByPrimaryKeySelective(po) == 0) {
+                                        po.setInsertTime(new Date());
+                                        emsPAiHourSumTab1Mapper.insert(po);
+                                    }
+                                } else {
+                                    EmsWAiHourSumTab1 wo = new EmsWAiHourSumTab1();
+                                    wo.setClock(ckb);
+                                    wo.setVal(sval.doubleValue(), tag);
+                                    if (emsWAiHourSumTab1Mapper.updateByPrimaryKeySelective(wo) == 0) {
+                                        wo.setInsertTime(new Date());
+                                        emsWAiHourSumTab1Mapper.insert(wo);
+                                    }
+                                }
+                                cle = new Date(cle.getTime() + 3600000l);
+                            }
+                            // 如果补齐了昨天数据,重新计算昨天日数据
+                            if (ckend.substring(0, 10).equals(clock24.substring(0, 10))) {
+                                tRmCalpointValueService.restatCalpData(itemid, clock24.substring(0, 10), "DAY", "系统");
+                            }
+                        }
+                    }
+                } catch (Exception e) {
+                    TRmCalpointExValue tce = new TRmCalpointExValue();
+                    tce.setItemid(itemid);
+                    tce.setExtype("6"); // 历史用量值更新失败
+                    tce.setClock(clock1);
+                    tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                    tce.setBz("历史用量值更新失败,clock:" + clock1 + ",tag:" + tag + ",table:" + table);
+                    tRmCalpointExValueService.add(tce);
+                }
+            }
+        }
+        logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 动力、水小时表统计完毕,个数:" + size);
+    }
+
+    @Override
+    public String restatHourData(String itemid, String clock) {
+        TRmCalpoint tc = tRmCalpointMapper.selectByPrimaryKey(itemid);
+        if (!tc.getUseflag().equals("1")) {
+            return "计量点已经被禁用";
+        }
+        if (!tc.getItemtype().equalsIgnoreCase("AUTO")) {
+            return "只计算自动采集计量点";
+        }
+        if (!tc.getEnergytypeid().equalsIgnoreCase("W") && !tc.getEnergytypeid().equalsIgnoreCase("P") && !tc.getEnergytypeid().equalsIgnoreCase("X")) {
+            return "只计算水、动力计量点";
+        }
+        Date date = new Date();
+        try {
+            date = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
+        } 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();
+        BigDecimal avgValue = tc.getRangeVal() ==null ? new BigDecimal(999999) : tc.getRangeVal();
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.add(Calendar.HOUR_OF_DAY, -1);
+        // 1小时前
+        String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+        // 获取配置
+        String tag = tc.getTagCol(); // tag存储字段
+        String table = tc.getTagTable(); // 存储表
+        String tenvs = tc.getBtype2(); // 十分钟表字段
+        if (tag == null || table == null || tenvs == null || tag.trim().isEmpty() || table.trim().isEmpty() || tenvs.trim().isEmpty()) {
+            TRmCalpointExValue tce = new TRmCalpointExValue();
+            tce.setItemid(itemid);
+            tce.setExtype("2"); // 配置错误
+            tce.setClock(clock);
+            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+            tce.setBz("配置不能为空");
+            tRmCalpointExValueService.add(tce);
+            socketMessages[2].append(itemid + ",");
+            return "配置不能为空";
+        }
+        String[] tens = tenvs.split("\\.");
+        if (tens.length != 2) {
+            TRmCalpointExValue tce = new TRmCalpointExValue();
+            tce.setItemid(itemid);
+            tce.setExtype("2"); // 配置错误
+            tce.setClock(clock);
+            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+            tce.setBz("十分钟表字段配置错误");
+            tRmCalpointExValueService.add(tce);
+            socketMessages[3].append(itemid + ",");
+            return "十分钟表字段配置错误";
+        }
+        String tenTab = tens[0];
+        String tenCol = tens[1];
+        String sql;
+        // 水系统数据四小时一次,读取每小时第十分钟数据作为起始值,确保数据无误差
+        if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+            sql = "select " + tenCol + " val, to_char(tim,'YYYY-MM-DD HH24:MI:SS') tim from "
+                    + tenTab
+                    + " where " + tenCol + " is not null and to_char(tim, 'YYYY-MM-DD HH24:mi') >='" + clock1 + ":10'"
+                    + " and to_char(tim, 'YYYY-MM-DD HH24:mi')<='" + clock + ":10'"
+                    + " order by tim ";
+        } else {
+            sql = "select " + tenCol + " val, to_char(tim,'YYYY-MM-DD HH24:MI:SS') tim from "
+                    + tenTab
+                    + " where " + tenCol + " is not null and to_char(tim, 'YYYY-MM-DD HH24:mi') >='" + clock1 + ":00'"
+                    + " and to_char(tim, 'YYYY-MM-DD HH24:mi')<='" + clock + ":00'"
+                    + " order by tim ";
+        }
+        List<Map<String, Object>> lt = new ArrayList<Map<String, Object>>();
+        try {
+            lt = jdbcTemplate.queryForList(sql);
+        } catch (Exception e) {
+            TRmCalpointExValue tce = new TRmCalpointExValue();
+            tce.setItemid(itemid);
+            tce.setExtype("7"); // 十分钟数据错误
+            tce.setClock(clock1);
+            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+            tce.setBz("十分钟数据查询错误,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+            tRmCalpointExValueService.add(tce);
+            socketMessages[8].append(itemid + ",");
+            return "十分钟数据查询错误";
+        }
+        if (lt == null || lt.size() < 1) {
+            TRmCalpointExValue tce = new TRmCalpointExValue();
+            tce.setItemid(itemid);
+            tce.setExtype("4"); // 十分钟数据不足以统计
+            tce.setClock(clock1);
+            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+            tce.setBz("十分钟数据不足以统计,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+            tRmCalpointExValueService.add(tce);
+            socketMessages[5].append(itemid + ",");
+            return "十分钟数据不足以统计";
+        } else if (lt.size() == 1) {
+            TRmCalpointExValue tce = new TRmCalpointExValue();
+            tce.setItemid(itemid);
+            tce.setExtype("4"); // 十分钟数据不足以统计
+            tce.setClock(clock1);
+            tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+            tce.setBz("十分钟数据不足以统计,clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+            tRmCalpointExValueService.add(tce);
+            socketMessages[5].append(itemid + ",");
+            // 当前小时准点值,水准点起始值从10分钟开始计算
+            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                sql = "select " + tenCol + " from " + tenTab + " where to_char(tim, 'YYYY-MM-DD HH24:mi') = '" + clock + ":10'";
+            } else {
+                sql = "select " + tenCol + " from " + tenTab + " where to_char(tim, 'YYYY-MM-DD HH24:mi') = '" + clock + ":00'";
+            }
+            try {
+                BigDecimal val = jdbcTemplate.queryForObject(sql, BigDecimal.class);
+                // 水数据取整
+                if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                    val = val.setScale(4, RoundingMode.DOWN);
+                }
+                if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
+                    EmsPAiHourSumTab1Org po = new EmsPAiHourSumTab1Org();
+                    po.setClock(clock);
+                    po.setVal(val.doubleValue(), tag);
+                    if (emsPAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(po) == 0) {
+                        po.setInsertTime(new Date());
+                        emsPAiHourSumTab1OrgMapper.insert(po);
+                    }
+                } else {
+                    EmsWAiHourSumTab1Org wo = new EmsWAiHourSumTab1Org();
+                    wo.setClock(clock);
+                    wo.setVal(val.doubleValue(), tag);
+                    if (emsWAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(wo) == 0) {
+                        wo.setInsertTime(new Date());
+                        emsWAiHourSumTab1OrgMapper.insert(wo);
+                    }
+                }
+            } catch (Exception e) {
+                tce = new TRmCalpointExValue();
+                tce.setItemid(itemid);
+                tce.setExtype("3"); // 准点值错误
+                tce.setClock(clock);
+                tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                tce.setBz("准点值读取失败,clock:" + clock + ",col:" + tenCol + ",table:" + tenTab);
+                tRmCalpointExValueService.add(tce);
+                socketMessages[4].append(itemid + ",");
+                logger.error("准点数据查询失败,clock:" + clock);
+            }
+        } else {
+            BigDecimal hval = BigDecimal.ZERO; // 小时用量值计算(十分钟累加)
+            BigDecimal val1 = BigDecimal.ZERO; // 开始仪表值
+            BigDecimal val2 = BigDecimal.ZERO; // 结束仪表值
+            BigDecimal tenval = BigDecimal.ZERO; // 十分钟用量值
+            try {
+                for (int i = 0; i < lt.size(); i++) {
+                    Map<String, Object> ma = lt.get(i);
+                    // 水数据取整
+                    if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                        val2 = new BigDecimal(ma.get("VAL").toString()).setScale(4, RoundingMode.DOWN);
+                    } else {
+                        val2 = new BigDecimal(ma.get("VAL").toString());
+                    }
+                    if (i == 0) {
+                        val1 = val2;
+                        continue;
+                    }
+                    tenval = val2.subtract(val1);
+                    // 水处理
+                    //if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                        // 大于等于0
+                        if (tenval.doubleValue() >= 0) {
+                            // 检查流量计处理。如果十分钟数据超出跳变范围就是错误的数据
+                            if (tenval.compareTo(avgValue) == -1) {
+                                hval = hval.add(tenval);
+                            } else {
+                                hval = hval.add(BigDecimal.ZERO);
+                            }
+                            //暂时不做判断,水数据四小时一次,等时间间距变小,再做处理
+                            // 数据增加超过最大值以上,异常,预警
+                            if (tenval.doubleValue() >= new BigDecimal(maxValue).doubleValue()) {
+                                // 记录异常数据
+                                TRmCalpointExValue tce = new TRmCalpointExValue();
+                                tce.setItemid(itemid);
+                                // 四小时水数据增大超过限值
+                                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("用量数据增大超过限值"+maxValue+",clock:" + clock1 + ",col:" + tenCol + ",table:" + tenTab);
+                                tRmCalpointExValueService.add(tce);
+                                socketMessages[9].append(itemid + ",");
+                            }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);
+                                socketMessages[10].append(itemid + ",");
+                            }
+                        } else {
+                            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);
+                                }
+                            }
+                            //八万煤气柜柜容,特殊运算不计入
+                            if (!"DL421P00770002".equals(itemid)) {
+                            // 记录异常数据
+                            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);
+                            socketMessages[1].append(itemid + ",");
+                            }
+                        }
+                    //} 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;
+                }
+            } catch (Exception e) {
+                return "小时用量值统计错误";
+            }
+            // 更新或者插入数据(小时用量值)
+            if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
+                EmsPAiHourSumTab1 po = new EmsPAiHourSumTab1();
+                po.setClock(clock1);
+                po.setVal(hval.doubleValue(), tag);
+                try{
+                    if (emsPAiHourSumTab1Mapper.updateByPrimaryKeySelective(po) == 0) {
+                        po.setInsertTime(new Date());
+                        emsPAiHourSumTab1Mapper.insert(po);
+                    }
+                }catch (Exception e){
+                    logger.info("小时数据出错:" + itemid);
+                    e.printStackTrace();
+                }
+
+            } else {
+                EmsWAiHourSumTab1 wo = new EmsWAiHourSumTab1();
+                wo.setClock(clock1);
+                wo.setVal(hval.doubleValue(), tag);
+                if (emsWAiHourSumTab1Mapper.updateByPrimaryKeySelective(wo) == 0) {
+                    wo.setInsertTime(new Date());
+                    emsWAiHourSumTab1Mapper.insert(wo);
+                }
+            }
+            // 水处理
+            if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                // 当前小时准点值
+                sql = "select " + tenCol + " from " + tenTab + " where to_char(tim, 'YYYY-MM-DD HH24:mi') = '" + clock + ":10'";
+            } else {
+                // 当前小时准点值
+                sql = "select " + tenCol + " from " + tenTab + " where to_char(tim, 'YYYY-MM-DD HH24:mi') = '" + clock + ":00'";
+            }
+            try {
+                BigDecimal val = jdbcTemplate.queryForObject(sql, BigDecimal.class);
+                // 水数据取整
+                if (tc.getEnergytypeid().equalsIgnoreCase("W")) {
+                    val = val.setScale(4, RoundingMode.DOWN);
+                }
+                if (table.equalsIgnoreCase("EMS_P_AI_HOUR_SUM_TAB1")) {
+                    EmsPAiHourSumTab1Org po = new EmsPAiHourSumTab1Org();
+                    po.setClock(clock);
+                    po.setVal(val.doubleValue(), tag);
+                    if (emsPAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(po) == 0) {
+                        po.setInsertTime(new Date());
+                        emsPAiHourSumTab1OrgMapper.insert(po);
+                    }
+                } else {
+                    EmsWAiHourSumTab1Org wo = new EmsWAiHourSumTab1Org();
+                    wo.setClock(clock);
+                    wo.setVal(val.doubleValue(), tag);
+                    if (emsWAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(wo) == 0) {
+                        wo.setInsertTime(new Date());
+                        emsWAiHourSumTab1OrgMapper.insert(wo);
+                    }
+                }
+            } catch (Exception e) {
+                TRmCalpointExValue tce = new TRmCalpointExValue();
+                tce.setItemid(itemid);
+                tce.setExtype("3"); // 准点值错误
+                tce.setClock(clock);
+                tce.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                tce.setBz("准点值读取失败,clock:" + clock + ",col:" + tenCol + ",table:" + tenTab);
+                tRmCalpointExValueService.add(tce);
+                socketMessages[4].append(itemid + ",");
+                logger.error("准点数据查询失败,clock:" + clock);
+            }
+        }
+        return "";
+    }
+
+    @Override
+    public String restatHourDate(String itemid, String clock, String clockend) {
+        Date start = new Date();
+        Date end = new Date();
+        String res = "";
+        try {
+            List<TRmCalpoint> l = null;
+            Map<String, Object> m = null;
+            if (itemid.equals("all")) {
+                m = new HashMap<String, Object>();
+                m.put("useflag", "1");
+                m.put("itemtype", "AUTO");
+                m.put("energytypeid", "'P','W','X'");
+            } else {
+                m = new HashMap<String, Object>();
+                m.put("itemid", itemid);
+            }
+            l = tRmCalpointMapper.selectLikeByParameters(m);
+            if (l.size() == 0) {
+                return "计量点数据为空";
+            }
+            end = new SimpleDateFormat("yyyy-MM-dd HH").parse(clockend);
+            for (TRmCalpoint tc : l) {
+                start = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
+                while (!start.after(end)) {
+                    String r = this.restatHourData(tc.getItemid(), new SimpleDateFormat("yyyy-MM-dd HH").format(start));
+                    if (res.isEmpty() && r != null) {
+                        res = r;
+                    }
+                    start = new Date(start.getTime() + 3600 * 1000);
+                }
+            }
+        } catch (ParseException e) {
+            return "日期格式错误";
+        }
+        return res;
+    }
+
+    @Override
+    public String restatHourDateE(String clock, String clockend) {
+        Date start = new Date();
+        Date end = new Date();
+        String res = "";
+        try {
+            end = new SimpleDateFormat("yyyy-MM-dd HH").parse(clockend);
+            start = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
+            while (!start.after(end)) {
+                String r = this.restatHourDataE(new SimpleDateFormat("yyyy-MM-dd HH").format(start));
+                if (res.isEmpty() && r != null) {
+                    res = r;
+                }
+                start = new Date(start.getTime() + 3600 * 1000);
+            }
+        } catch (ParseException e) {
+            return "日期格式错误";
+        }
+        return res;
+    }
+
+
+    @Override
+    public String restatHourDataE(String clock) {
+        Date date = new Date();
+        try {
+            // clock,  2021-04-22 09
+            date = new SimpleDateFormat("yyyy-MM-dd HH").parse(clock);
+        } catch (ParseException e) {
+            return "日期格式错误";
+        }
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.add(Calendar.HOUR_OF_DAY, -1);
+        // 1小时前 2021-04-22 09
+        String clock1 = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
+        Map<String, Object> parmas = new HashMap<String, Object>();
+        parmas.put("clock", clock + ":00:00");
+        parmas.put("clocke", clock + ":09:00"); // 由于采集数据写入延迟,这里整点后9分钟内的算作整点的数据,比如2021/4/22 9:04:12 会当成 2021/4/22 9:00:00 的数据
+        try {
+            // 数据量太多,这里只要整点值
+            List<EmsEHistory> ehList = emsEHistoryMapper.getEmsEHistoryByDate(parmas);
+            if (ehList.size() > 0) {
+                // 数据是否已经存在
+                boolean exists = true;
+                // 分钟clock - 2021-04-22 09:00
+                String clockM = clock + ":00";
+                EmsETiming e = emsETimingMapper.selectByPrimaryKey(clockM);
+                if (e == null) {
+                    exists = false;
+                    e = new EmsETiming();
+                    e.setInsertTime(new Date());
+                    e.setClock(clockM);
+                }
+                for (EmsEHistory eeh : ehList) {
+                    // 服务器-电开关号 例如:device/iec102-42-160/0637/totalpower
+                    String head = eeh.geteLine();
+                    if (head.split("/").length != 4) {
+                        logger.error(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "-数据格式错误-" + head);
+                        continue;
+                    }
+                    String line = "";
+                    if (head.split("/")[1].endsWith("13-200")) {
+                        line = "1";
+                    } else if (head.split("/")[1].endsWith("56-201")) {
+                        line = "2";
+                    } else if (head.split("/")[1].endsWith("56-202")) {
+                        line = "3";
+                    } else if (head.split("/")[1].endsWith("32-158")) {
+                        line = "4";
+                    } else if (head.split("/")[1].endsWith("42-158")) {
+                        line = "5";
+                    } else if (head.split("/")[1].endsWith("42-159")) {
+                        line = "6";
+                    } else if (head.split("/")[1].endsWith("42-160")) {
+                        line = "7";
+                    } else {
+                        continue;
+                    }
+                    // 电开关号,例如: 0637
+                    String code = line + head.split("/")[2];
+                    // 数据 例如:{"感性无功":27.09,"容性无功":3.71,"正向有功":143.42,"反向有功":16.38}
+                    String eData = eeh.geteData();
+                    JSONObject jo = JSONObject.parseObject(eData);
+                    e.setVal(code, jo.getString("正向有功"), "f");
+                    e.setVal(code, jo.getString("反向有功"), "r");
+                }
+                // 更新
+                if (exists) {
+                    emsETimingMapper.updateByPrimaryKeySelective(e);
+                } else {// 新增
+                    emsETimingMapper.insert(e);
+                }
+                // 从EMS_E_TIMING读取小时准点值-并且写入数据库
+                Map<String, Object> mp = emsETimingMapper.getHourPointVal(clockM);
+                // 整点数据 (clock)
+                EmsEAiHourSumTab1Org eeho = new EmsEAiHourSumTab1Org();
+                if (mp != null && mp.size() > 0) {
+                    eeho.setClock(clock);
+                    eeho = EmsEAiUtil.setValByMap(eeho, mp);
+                    int rs = emsEAiHourSumTab1OrgMapper.updateByPrimaryKeySelective(eeho);
+                    if (rs == 0) {
+                        eeho.setInsertTime(new Date());
+                        emsEAiHourSumTab1OrgMapper.insert(eeho);
+                    }
+                }
+                // 上一个小时
+                EmsEAiHourSumTab1Org eeho1 = emsEAiHourSumTab1OrgMapper.selectByPrimaryKey(clock1);
+                // 小时累计值 = 当前小时准点值 - 前1小时小时准点值
+                if (eeho.getClock() == null || eeho.getClock().isEmpty() || eeho1 == null || eeho1.getClock() == null || eeho1.getClock().isEmpty()) {
+                    logger.error("数据表EMS_E_AI_HOUR_SUM_TAB1_ORG缺少数据:" + clock);
+                } else {
+                    EmsEAiHourSumTab1 eeh = new EmsEAiHourSumTab1();
+                    eeh.setClock(clock1);
+                    eeh = EmsEAiUtil.setVal(eeh, eeho, eeho1);
+                    int rs = emsEAiHourSumTab1Mapper.updateByPrimaryKeySelective(eeh);
+                    if (rs == 0) {
+                        eeh.setInsertTime(new Date());
+                        emsEAiHourSumTab1Mapper.insert(eeh);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            logger.error("重新生成单个小时的电表数据错误", e);
+            return "重新计算单个小时的电表数据错误";
+        }
+        return null;
+    }
+
+    @Override
+    /**
+     *  从十分钟补全水数据,弃用
+     */
+    public void resData(String itemId, String startClock, String endClock) throws Exception {
+        String format ="yyyy-MM-dd HH";
+
+        Date date = new Date();
+        try {
+            // clock,  2021-04-22 09
+            date = new SimpleDateFormat(format).parse(startClock);
+            date = new SimpleDateFormat(format).parse(startClock);
+        } catch (ParseException e) {
+            throw new Exception( "日期格式错误");
+        }
+
+        Map<String, Object> m = new HashMap<String, Object>();
+        m.put("useflag", "1");
+        m.put("itemtype", "AUTO");
+        m.put("energytypeid", "'P','W'");
+        if (itemId != null && !itemId.equals("")) {
+            m.put("itemid", "'" + itemId + "'");
+        }
+        List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(m);
+
+
+        int size1 = 0;
+
+        if (l != null && l.size() > 0 && !"".equals(endClock)) {
+            List<EmsWebsocketLog> websocketLogs = new ArrayList<>();
+            socketMessages = new StringBuffer[12];
+            for (int i = 0; i < socketMessages.length; i++) {
+                socketMessages[i] = new StringBuffer();
+            }
+
+
+
+            for (TRmCalpoint tc : l) {
+                try {
+                    String itemid = tc.getItemid();
+                    String tag = tc.getTagCol(); // tag存储字段
+                    String table = tc.getTagTable(); // 存储表
+
+                    String r = this.restatHourData(itemid, endClock);
+                    if (!r.isEmpty()) {
+                        continue;
+                    }
+
+                    // 上个已记录小时时间
+                    Date now = new SimpleDateFormat(format).parse(startClock);
+                    Date endDate = new SimpleDateFormat(format).parse(endClock);
+
+
+                    // 补齐之前缺失的用量值
+                    while (!now.after(endDate)) {
+                        Date now1 = new Date(now.getTime() - 3600000L);//前一小时(每次生成的是前一小时的值)
+                        String clock1 = new SimpleDateFormat(format).format(now1);
+
+                        String sql = "select max(clock) from " + table + " where clock='" + clock1 + "' and " + tag + " is not null";
+                        // 上个记录时间
+                        String ck = jdbcTemplate.queryForObject(sql, String.class);
+                        if (ck == null) {
+                            String clock = new SimpleDateFormat("yyyy-MM-dd HH").format(now);
+                            this.restatHourData(itemid, clock);
+
+                            // 如果补齐了昨天数据,重新计算昨天日数据
+                            if (clock1.substring(11, 13).equals("23")) {
+                                tRmCalpointValueService.restatCalpData(itemid, clock1.substring(0, 10), "DAY", "系统");
+                            }
+                        }
+                        now = new Date(now.getTime() + 3600000L);
+                    }
+
+                    size1++;
+                } catch (Exception e) {
+                    logger.info("小时表修复出现异常" + itemId);
+                    e.printStackTrace();
+                }
+            }
+            logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 动力、水小时表修复完毕,个数:" + size1);
+        }
+    }
+
+    @Override
+    public Integer getSoleSource(TRmCalpoint tRmCalpoint) {
+       return tRmCalpointMapper.getSoleSource(tRmCalpoint);
+    }
+}

+ 532 - 517
src/main/java/com/steerinfo/ems/trmcalpointvalue/controller/TRmCalpointValueController.java

@@ -1,517 +1,532 @@
-package com.steerinfo.ems.trmcalpointvalue.controller;
-
-import com.steerinfo.auth.utils.JwtUtil;
-import com.steerinfo.ems.formula.service.IFormulaService;
-import com.steerinfo.ems.trmcalpoint.mapper.TRmCalpointMapper;
-import com.steerinfo.ems.trmcalpoint.model.TRmCalpoint;
-import com.steerinfo.ems.trmcalpoint.service.ITRmCalpointService;
-import com.steerinfo.ems.trmcalpointvalue.model.TRmCalpointValue;
-import com.steerinfo.ems.trmcalpointvalue.service.ITRmCalpointValueService;
-import com.steerinfo.framework.controller.BaseRESTfulController;
-import com.steerinfo.framework.controller.RESTfulResult;
-import com.steerinfo.framework.service.pagehelper.PageList;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-/**
- * TRmCalpointValue RESTful接口:
- * @author generator
- * @version 1.0-SNAPSHORT 2019-10-17 03:55
- * 类描述
- * 修订历史:
- * 日期:2019-10-17
- * 作者:generator
- * 参考:
- * 描述:TRmCalpointValue RESTful接口
- * @see null
- * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
- */
-@RestController
-@RequestMapping("/${api.version}/trmcalpointvalues")
-public class TRmCalpointValueController extends BaseRESTfulController {
-	private static final Logger logger = LoggerFactory.getLogger(TRmCalpointValueController.class);
-
-    @Autowired
-    ITRmCalpointValueService tRmCalpointValueService;
-    
-    @Autowired
-    ITRmCalpointService tRmCalpointService;
-    
-    @Autowired
-    private TRmCalpointMapper tRmCalpointMapper;
-    
-    @Autowired
-    IFormulaService formulaService;
-
-    @ApiOperation(value="获取列表", notes="分页查询")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
-        @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
-    })
-    //@RequiresPermissions("trmcalpointvalue:view")
-    @GetMapping(value = "/")
-    public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
-        PageList<TRmCalpointValue> list = tRmCalpointValueService.queryForPage(parmas, pageNum, pageSize);
-        return success(list);
-    }
-
-    @ApiOperation(value="获取列表", notes="分页模糊查询")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
-        @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
-    })
-    //@RequiresPermissions("trmcalpointvalue:view")
-    @GetMapping(value = "/like/")
-    public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
-        PageList<TRmCalpointValue> list = tRmCalpointValueService.queryLikeForPage(parmas, pageNum, pageSize);
-        return success(list);
-    }
-    
-    @ApiOperation(value="创建", notes="根据TRmCalpointValue对象创建")
-    @ApiImplicitParam(name = "tRmCalpointValue", value = "详细实体tRmCalpointValue", required = true, dataType = "TRmCalpointValue")
-    //@RequiresPermissions("trmcalpointvalue:create")
-    @PostMapping(value = "/")
-    public RESTfulResult add(@ModelAttribute TRmCalpointValue model){
-        TRmCalpointValue tRmCalpointValue = tRmCalpointValueService.add(model);
-        return success(tRmCalpointValue);
-    }
-
-    @ApiOperation(value="获取详细信息", notes="根据主键来获取详细信息")
-    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
-    //@RequiresPermissions("trmcalpointvalue:view")
-    @PostMapping(value = "/info", produces  = "application/json;charset=UTF-8")
-    public RESTfulResult get(@RequestBody TRmCalpointValue model){
-    	if(model.getClock() == null || model.getClock().isEmpty()){
-    		return failed(null, "请传入时间");
-    	}
-    	if(model.getTimegranid() == null || model.getTimegranid().isEmpty()){
-    		return failed(null, "请传入时间粒度");
-    	}
-    	if(model.getItemid() == null || model.getItemid().isEmpty()){
-    		return failed(null, "请传入计量点编号");
-    	}
-    	HashMap<String, Object> m = new HashMap<String, Object>();
-    	m.put("clock", model.getClock());
-    	m.put("timegranid", model.getTimegranid());
-    	m.put("itemid", model.getItemid());
-        model.setId(m);
-        TRmCalpointValue tRmCalpointValue = tRmCalpointValueService.getById(m);
-        return success(tRmCalpointValue);
-    }
-
-    @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tRmCalpointValue信息来更新详细信息")
-    @ApiImplicitParams({
-        @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
-        @ApiImplicitParam(name = "tRmCalpointValue", value = "详细实体tRmCalpointValue", required = true, dataType = "TRmCalpointValue")
-    })
-    //@RequiresPermissions("trmcalpointvalue:update")
-    @PutMapping(value = "/update", produces  = "application/json;charset=UTF-8")
-    public RESTfulResult update(@RequestBody TRmCalpointValue model){
-    	if(model.getClock() == null || model.getClock().isEmpty()){
-    		return failed(null, "请传入开始时间");
-    	}
-    	if(model.getTimegranid() == null || model.getTimegranid().isEmpty()){
-    		return failed(null, "请传入时间粒度");
-    	}
-    	if(model.getItemid() == null || model.getItemid().isEmpty()){
-    		return failed(null, "请传入计量点编号");
-    	}
-    	if(model.getApportvalue() == null){
-    		return failed(null, "请传入最终值");
-    	}
-    	if(model.getActualvalue() == null){
-    		return failed(null, "请传入计算值");
-    	}
-    	if(model.getCorrectvalue() == null){
-    		return failed(null, "请传入修正值");
-    	}
-    	if(model.getActualvalue().add(model.getCorrectvalue()).compareTo(model.getApportvalue()) != 0){
-    		return failed(null, "数值错误,最终值 = 计算值 + 修正值");
-    	}
-    	HashMap<String, Object> m = new HashMap<String, Object>();
-    	m.put("clock", model.getClock());
-    	m.put("timegranid", model.getTimegranid());
-    	m.put("itemid", model.getItemid());
-        model.setId(m);
-        TRmCalpointValue tRmCalpointValue = tRmCalpointValueService.modifyAndCompute(model);
-        if(tRmCalpointValue == null){
-        	return failed(null, "修改对象不存在");
-        }
-        return success(tRmCalpointValue);
-    }
-
-    @ApiOperation(value="删除", notes="根据主键来指定删除对象")
-    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
-    //@RequiresPermissions("trmcalpointvalue:delete")
-    @DeleteMapping(value = "/delete", produces  = "application/json;charset=UTF-8")
-    public RESTfulResult delete(@RequestBody TRmCalpointValue model){
-    	if(model.getClock() == null || model.getClock().isEmpty()){
-    		return failed(null, "请传入开始时间");
-    	}
-    	if(model.getTimegranid() == null || model.getTimegranid().isEmpty()){
-    		return failed(null, "请传入时间粒度");
-    	}
-    	if(model.getItemid() == null || model.getItemid().isEmpty()){
-    		return failed(null, "请传入计量点编号");
-    	}
-    	HashMap<String, Object> m = new HashMap<String, Object>();
-    	m.put("clock", model.getClock());
-    	m.put("timegranid", model.getTimegranid());
-    	m.put("itemid", model.getItemid());
-        model.setId(m);
-        tRmCalpointValueService.delete(m);
-        return success();
-    }
-
-    @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tRmCalpointValue信息来更新详细信息")
-    @ApiImplicitParam(name = "tRmCalpointValue", value = "详细实体tRmCalpointValue", required = true, dataType = "TRmCalpointValue")
-    //@RequiresPermissions("trmcalpointvalue:update")
-    @PutMapping(value = "/batchupdate", produces  = "application/json;charset=UTF-8")
-    public RESTfulResult batchupdate(@RequestBody TRmCalpointValue[] model){
-        int failnum = 0;
-        String failmsg = "";
-        List<String> errorid = new ArrayList<>();
-        for (int i = 0; i< model.length; i++) {
-            if (model[i].getClock() == null || model[i].getClock().isEmpty()) {
-                failnum++;
-                errorid.add(model[i].getItemid());
-                failmsg+= "id为" + model[i].getItemid() + "数据请传入开始时间";
-                continue;
-            }
-            if (model[i].getTimegranid() == null || model[i].getTimegranid().isEmpty()) {
-                failnum++;
-                errorid.add(model[i].getItemid());
-                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入时间粒度";
-                continue;
-            }
-            if (model[i].getItemid() == null || model[i].getItemid().isEmpty()) {
-                failnum++;
-                errorid.add(model[i].getItemid());
-                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入计量点编号";
-                continue;
-            }
-            if (model[i].getApportvalue() == null) {
-                failnum++;
-                errorid.add(model[i].getItemid());
-                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入最终值";
-                continue;
-            }
-            if (model[i].getActualvalue() == null) {
-                failnum++;
-                errorid.add(model[i].getItemid());
-                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入计算值";
-                continue;
-            }
-            if (model[i].getCorrectvalue() == null) {
-                failnum++;
-                errorid.add(model[i].getItemid());
-                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入修正值";
-                continue;
-            }
-            if (model[i].getActualvalue().add(model[i].getCorrectvalue()).compareTo(model[i].getApportvalue()) != 0) {
-                failnum++;
-                errorid.add(model[i].getItemid());
-                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据数值错误,最终值 = 计算值 + 修正值";
-                continue;
-            }
-            HashMap<String, Object> m = new HashMap<String, Object>();
-            m.put("clock", model[i].getClock());
-            m.put("timegranid", model[i].getTimegranid());
-            m.put("itemid", model[i].getItemid());
-            model[i].setId(m);
-            model[i].setUpman(JwtUtil.getUseridByToken());
-            model[i].setUptime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-            TRmCalpointValue tRmCalpointValue = tRmCalpointValueService.modifyAndCompute(model[i]);
-            if (tRmCalpointValue == null) {
-                failnum++;
-                errorid.add(model[i].getItemid());
-                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")修改对象不存在";
-                continue;
-            }
-        }
-        if(failnum > 0){
-            return success(errorid,"51","本次共修改" + model.length + "条数据,其中成功" + (model.length - failnum) + "条,失败" + failnum + "条");
-        }
-        return success();
-    }
-    
-    @ApiOperation(value="批量重新计算", notes="根据url的id来指定更新对象,并根据传过来的tRmCalpointValue信息来更新详细信息,从小时表数据更新")
-    @ApiImplicitParam(name = "tRmCalpointValue", value = "详细实体tRmCalpointValue", required = true, dataType = "TRmCalpointValue")
-    //@RequiresPermissions("trmcalpointvalue:update")
-    @PutMapping(value = "/batchCompute", produces  = "application/json;charset=UTF-8")
-    public RESTfulResult batchCompute(@RequestBody TRmCalpointValue[] model){
-    	if(model.length<1){
-    		return failed(null, "请勾选计量点数据");
-    	}
-    	// 重排计算顺序
-    	List<String> l = new ArrayList<String>();
-    	for (int i = 0; i< model.length; i++) {
-    		TRmCalpointValue tv = model[i];
-    		TRmCalpoint tRmCalpoint = tRmCalpointService.getById(tv.getItemid());
-    		if(tRmCalpoint!=null && tv.getClock()!=null && tv.getTimegranid()!=null){
-    			String seq = tRmCalpoint.getSeqno()==null?"0":tRmCalpoint.getSeqno()+"";
-    			l.add(tRmCalpoint.getItemtype() + "," +tv.getTimegranid()+","+tv.getClock()+","+tv.getItemid()+","+seq);
-    		}
-    	}
-    	// 调整计算顺序,虚拟点靠后0
-		Collections.sort(l, new Comparator<String>() {
-			public int compare(String s1, String s2) {
-				String itemtype1 = s1.split(",")[0];
-				String timegranid1 = s1.split(",")[1];
-				String clock1 = s1.split(",")[2];
-				String seqno1 = s1.split(",")[4];
-				Date d1 = new Date();
-				String itemtype2 = s2.split(",")[0];
-				String timegranid2 = s2.split(",")[1];
-				String clock2 = s2.split(",")[2];
-				String seqno2 = s2.split(",")[4];
-				Date d2 = new Date();
-				try {
-					if (itemtype1.equalsIgnoreCase(itemtype2)) {
-						Calendar cal = Calendar.getInstance();
-						if (timegranid1.equalsIgnoreCase("year")) {
-							cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1 + "-12-31 23"));
-							d1 = cal.getTime();
-						}else if(timegranid1.equalsIgnoreCase("month")){
-							cal.setTime(new SimpleDateFormat("yyyy-MM").parse(clock1));
-							cal.add(Calendar.MONTH, 1);
-							cal.add(Calendar.HOUR_OF_DAY, -3);
-							d1 = cal.getTime();
-						}else if(timegranid1.equalsIgnoreCase("day")){
-							cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(clock1));
-							d1 = cal.getTime();
-						}else if(timegranid1.equalsIgnoreCase("shift")){
-							cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1));
-							d1 = cal.getTime();
-						}
-						if (timegranid2.equalsIgnoreCase("year")) {
-							cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH").parse(clock2 + "-12-31 23"));
-							d2 = cal.getTime();
-						}else if(timegranid2.equalsIgnoreCase("month")){
-							cal.setTime(new SimpleDateFormat("yyyy-MM").parse(clock2));
-							cal.add(Calendar.MONTH, 1);
-							cal.add(Calendar.HOUR_OF_DAY, -3);
-							d2 = cal.getTime();
-						}else if(timegranid2.equalsIgnoreCase("day")){
-							cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(clock2));
-							d2 = cal.getTime();
-						}else if(timegranid2.equalsIgnoreCase("shift")){
-							cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH").parse(clock2));
-							d2 = cal.getTime();
-						}
-						if(d1.getTime() > d2.getTime()){
-							return 1;
-						}else if(d1.getTime() < d2.getTime()){
-							return -1;
-						}else {
-							if(Integer.valueOf(seqno1) > Integer.valueOf(seqno2)){
-								return 1;
-							}else if(Integer.valueOf(seqno1) < Integer.valueOf(seqno2)){
-								return -1;
-							}else{
-								return 0;
-							}
-						}
-					} else {
-						if (itemtype1.equalsIgnoreCase("VIRTUAL")) {
-							return 1;
-						} else if (itemtype2.equalsIgnoreCase("VIRTUAL")) {
-							return -1;
-						} else {
-							return 0;
-						}
-					}
-				} catch (ParseException e) {
-					return 0;
-				}
-			}
-		});
-		for (int i = 0; i< l.size(); i++) {
-			tRmCalpointValueService.restatCalpData(l.get(i).split(",")[3], l.get(i).split(",")[2], l.get(i).split(",")[1], JwtUtil.getUseridByToken());
-		}
-    	return success();
-    }
-    
-    @ApiOperation(value="获得计量点时间段数据", notes="获得计量点时间段数据,期初、期末、计算值")
-    @GetMapping(value = "/getCalpointValue")
-    public RESTfulResult getCalpointValue(@RequestParam HashMap<String, Object> parmas){
-    	if(parmas.get("start")==null || parmas.get("start").toString().isEmpty()){
-    		return failed(null, "请传入起始时间");
-    	}
-    	if(parmas.get("end")==null || parmas.get("end").toString().isEmpty()){
-    		return failed(null, "请传入结束时间");
-    	}
-    	try {
-    		String start = parmas.get("start").toString();
-    		String end = parmas.get("end").toString();
-			if(new SimpleDateFormat("yyyy-MM-dd").parse(start).after(new Date())){
-				return failed(null, "起始时间不能在今天之后");
-			}
-			if(new SimpleDateFormat("yyyy-MM-dd").parse(end).after(new Date())){
-				return failed(null, "结束时间不能在今天之后");
-			}
-		} catch (ParseException e) {
-			return failed(null, "时间格式错误");
-		}
-    	if(parmas.get("ids")==null || parmas.get("ids").toString().isEmpty()){
-    		return failed(null, "请传入计量点");
-    	}
-    	List<Map<String, Object>> list  = tRmCalpointValueService.getCalpointValue(parmas);
-        return success(list);
-    }
-    
-    @ApiOperation(value="重新计算单个计量点数据")
-    //@RequiresPermissions("trmcalpointvalue:view")
-    @GetMapping(value = "/restatCal")
-    public RESTfulResult restatCal(@RequestParam HashMap<String, Object> parmas, String clock, String clocke, String timegranid){
-    	if (parmas == null) {
-    		parmas = new HashMap<String, Object>();
-    	}
-    	if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
-            String itemid = parmas.get("itemid").toString();
-            if(!itemid.startsWith("'")){
-            	itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-            }
-            parmas.put("itemid", itemid);
-        }
-		if (clock==null || clock.isEmpty()) {
-    		return failed(null, "请传入起始时间");
-    	}
-		if (timegranid==null || timegranid.isEmpty()) {
-    		return failed(null, "请传入时间粒度");
-    	}
-		parmas.put("useflag", "1");
-		// 查询需要统计的计量点信息
-		List<TRmCalpoint> l = tRmCalpointMapper.selectCalpoints(parmas);
-		String res = "";
-		for(TRmCalpoint tRmCalpoint : l){
-			res = formulaService.reItemVal(tRmCalpoint.getItemid(),clock,timegranid,clocke);
-		}
-		if(!res.isEmpty()){
-			return failed(null, res);
-		}
-        return success();
-    }
-    
-    @ApiOperation(value="重新生成数据", notes="")
-    //@RequiresPermissions("trmcalpointvalue:view")
-    @GetMapping(value = "/reData")
-    public RESTfulResult reData(@RequestParam HashMap<String, Object> parmas, String clock, String clocke, String timegranid){
-    	if (clock==null || clock.isEmpty()) {
-    		return failed(null, "请传入起始时间");
-    	}
-    	if (clocke==null || clocke.isEmpty()) {
-    		return failed(null, "请传入结束时间");
-    	}
-		if (timegranid==null || timegranid.isEmpty()) {
-			return failed(null, "请传入时间粒度");
-    	}
-		if(parmas.get("itemid") != null && !parmas.get("itemid").toString().isEmpty()){
-            String itemid = parmas.get("itemid").toString();
-            if(!itemid.startsWith("'")){
-            	itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-            }
-            parmas.put("itemid", itemid);
-        }
-    	if(parmas.get("locateid") != null && !parmas.get("locateid").toString().isEmpty()){
-            String locateid = parmas.get("locateid").toString();
-            if(!locateid.startsWith("'")){
-            	locateid = "'" + locateid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-            }
-            parmas.put("locateid", locateid);
-        }
-    	if(parmas.get("networkid") != null && !parmas.get("networkid").toString().isEmpty()){
-            String networkid = parmas.get("networkid").toString();
-            if(!networkid.startsWith("'")){
-            	networkid = "'" + networkid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-            }
-            parmas.put("networkid", networkid);
-        }
-    	if(parmas.get("energytypeid") != null && !parmas.get("energytypeid").toString().isEmpty()){
-            String energytypeid = parmas.get("energytypeid").toString();
-            if(!energytypeid.startsWith("'")){
-            	energytypeid = "'" + energytypeid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-            }
-            parmas.put("energytypeid", energytypeid);
-        }
-    	if(parmas.get("energyid") != null && !parmas.get("energyid").toString().isEmpty()){
-            String energyid = parmas.get("energyid").toString();
-            if(!energyid.startsWith("'")){
-            	energyid = "'" + energyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-            }
-            parmas.put("energyid", energyid);
-        }
-    	if(parmas.get("propertyid") != null && !parmas.get("propertyid").toString().isEmpty()){
-            String propertyid = parmas.get("propertyid").toString();
-            if(!propertyid.startsWith("'")){
-            	propertyid = "'" + propertyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-            }
-            parmas.put("propertyid", propertyid);
-        }
-    	String res = "";
-    	parmas.put("useflag", "1");
-		// 查询需要统计的计量点信息
-		List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(parmas);
-		int size = l.size();
-		for(int i = 0; i<l.size(); i++){
-			if(res.isEmpty()){
-				res = formulaService.reItemVal(l.get(i).getItemid(),clock,timegranid,clocke);
-			}else{
-				formulaService.reItemVal(l.get(i).getItemid(),clock,timegranid,clocke);
-			}
-			logger.info("剩下要处理的项目数:" + (size-1-i) + "(" + size + ")");
-		}
-		if(!res.isEmpty()){
-			return success(null, res);
-		}
-        return success(null, res);
-    }
-	@ApiOperation(value="补全", notes="")
-	//@RequiresPermissions("trmcalpointvalue:view")
-	@GetMapping(value = "/resData")
-	public RESTfulResult resData(@RequestParam HashMap<String, Object> parmas,String clock, String clocke) {
-		if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
-			String itemid = parmas.get("itemid").toString();
-			if(!itemid.startsWith("'")){
-				itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-			}
-			tRmCalpointValueService.resWData(clock,clocke);
-		}
-
-		return success();
-	}
-
-	@GetMapping(value = "/aaa")
-	public RESTfulResult aaa(){
-		tRmCalpointValueService.insetDataForBb();
-		return success();
-	}
-
-	@ApiOperation(value="从电力需求侧补全历史数据", notes="")
-	//@RequiresPermissions("trmcalpointvalue:view")
-	@GetMapping(value = "/resElData")
-	public RESTfulResult resElData(@RequestParam HashMap<String, Object> parmas,String clock, String clocke) {
-		if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
-			String itemid = parmas.get("itemid").toString();
-			if(!itemid.startsWith("'")){
-				itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
-			}
-			String message = tRmCalpointValueService.resEData(itemid,clock,clocke);
-			if(message == "") {
-				return  success();
-			} else {
-				return failed(null, message);
-			}
-		}
-		return failed(null, "参数错误!");
-	}
-}
+package com.steerinfo.ems.trmcalpointvalue.controller;
+
+import com.steerinfo.auth.utils.JwtUtil;
+import com.steerinfo.ems.formula.service.IFormulaService;
+import com.steerinfo.ems.trmcalpoint.mapper.TRmCalpointMapper;
+import com.steerinfo.ems.trmcalpoint.model.TRmCalpoint;
+import com.steerinfo.ems.trmcalpoint.service.ITRmCalpointService;
+import com.steerinfo.ems.trmcalpointvalue.model.TRmCalpointValue;
+import com.steerinfo.ems.trmcalpointvalue.service.ITRmCalpointValueService;
+import com.steerinfo.framework.controller.BaseRESTfulController;
+import com.steerinfo.framework.controller.RESTfulResult;
+import com.steerinfo.framework.service.pagehelper.PageList;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * TRmCalpointValue RESTful接口:
+ * @author generator
+ * @version 1.0-SNAPSHORT 2019-10-17 03:55
+ * 类描述
+ * 修订历史:
+ * 日期:2019-10-17
+ * 作者:generator
+ * 参考:
+ * 描述:TRmCalpointValue RESTful接口
+ * @see null
+ * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
+ */
+@RestController
+@RequestMapping("/${api.version}/trmcalpointvalues")
+public class TRmCalpointValueController extends BaseRESTfulController {
+	private static final Logger logger = LoggerFactory.getLogger(TRmCalpointValueController.class);
+
+    @Autowired
+    ITRmCalpointValueService tRmCalpointValueService;
+
+    @Autowired
+    ITRmCalpointService tRmCalpointService;
+
+    @Autowired
+    private TRmCalpointMapper tRmCalpointMapper;
+
+    @Autowired
+    IFormulaService formulaService;
+
+    @ApiOperation(value="获取列表", notes="分页查询")
+    @ApiImplicitParams({
+        @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
+        @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
+    })
+    //@RequiresPermissions("trmcalpointvalue:view")
+    @GetMapping(value = "/")
+    public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
+        PageList<TRmCalpointValue> list = tRmCalpointValueService.queryForPage(parmas, pageNum, pageSize);
+        return success(list);
+    }
+
+    @ApiOperation(value="获取列表", notes="分页模糊查询")
+    @ApiImplicitParams({
+        @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
+        @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
+    })
+    //@RequiresPermissions("trmcalpointvalue:view")
+    @GetMapping(value = "/like/")
+    public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
+        PageList<TRmCalpointValue> list = tRmCalpointValueService.queryLikeForPage(parmas, pageNum, pageSize);
+        return success(list);
+    }
+
+    @ApiOperation(value="创建", notes="根据TRmCalpointValue对象创建")
+    @ApiImplicitParam(name = "tRmCalpointValue", value = "详细实体tRmCalpointValue", required = true, dataType = "TRmCalpointValue")
+    //@RequiresPermissions("trmcalpointvalue:create")
+    @PostMapping(value = "/")
+    public RESTfulResult add(@ModelAttribute TRmCalpointValue model){
+        TRmCalpointValue tRmCalpointValue = tRmCalpointValueService.add(model);
+        return success(tRmCalpointValue);
+    }
+
+    @ApiOperation(value="获取详细信息", notes="根据主键来获取详细信息")
+    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
+    //@RequiresPermissions("trmcalpointvalue:view")
+    @PostMapping(value = "/info", produces  = "application/json;charset=UTF-8")
+    public RESTfulResult get(@RequestBody TRmCalpointValue model){
+    	if(model.getClock() == null || model.getClock().isEmpty()){
+    		return failed(null, "请传入时间");
+    	}
+    	if(model.getTimegranid() == null || model.getTimegranid().isEmpty()){
+    		return failed(null, "请传入时间粒度");
+    	}
+    	if(model.getItemid() == null || model.getItemid().isEmpty()){
+    		return failed(null, "请传入计量点编号");
+    	}
+    	HashMap<String, Object> m = new HashMap<String, Object>();
+    	m.put("clock", model.getClock());
+    	m.put("timegranid", model.getTimegranid());
+    	m.put("itemid", model.getItemid());
+        model.setId(m);
+        TRmCalpointValue tRmCalpointValue = tRmCalpointValueService.getById(m);
+        return success(tRmCalpointValue);
+    }
+
+    @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tRmCalpointValue信息来更新详细信息")
+    @ApiImplicitParams({
+        @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
+        @ApiImplicitParam(name = "tRmCalpointValue", value = "详细实体tRmCalpointValue", required = true, dataType = "TRmCalpointValue")
+    })
+    //@RequiresPermissions("trmcalpointvalue:update")
+    @PutMapping(value = "/update", produces  = "application/json;charset=UTF-8")
+    public RESTfulResult update(@RequestBody TRmCalpointValue model){
+    	if(model.getClock() == null || model.getClock().isEmpty()){
+    		return failed(null, "请传入开始时间");
+    	}
+    	if(model.getTimegranid() == null || model.getTimegranid().isEmpty()){
+    		return failed(null, "请传入时间粒度");
+    	}
+    	if(model.getItemid() == null || model.getItemid().isEmpty()){
+    		return failed(null, "请传入计量点编号");
+    	}
+    	if(model.getApportvalue() == null){
+    		return failed(null, "请传入最终值");
+    	}
+    	if(model.getActualvalue() == null){
+    		return failed(null, "请传入计算值");
+    	}
+    	if(model.getCorrectvalue() == null){
+    		return failed(null, "请传入修正值");
+    	}
+    	if(model.getActualvalue().add(model.getCorrectvalue()).compareTo(model.getApportvalue()) != 0){
+    		return failed(null, "数值错误,最终值 = 计算值 + 修正值");
+    	}
+    	HashMap<String, Object> m = new HashMap<String, Object>();
+    	m.put("clock", model.getClock());
+    	m.put("timegranid", model.getTimegranid());
+    	m.put("itemid", model.getItemid());
+        model.setId(m);
+        TRmCalpointValue tRmCalpointValue = tRmCalpointValueService.modifyAndCompute(model);
+        if(tRmCalpointValue == null){
+        	return failed(null, "修改对象不存在");
+        }
+        return success(tRmCalpointValue);
+    }
+
+    @ApiOperation(value="删除", notes="根据主键来指定删除对象")
+    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
+    //@RequiresPermissions("trmcalpointvalue:delete")
+    @DeleteMapping(value = "/delete", produces  = "application/json;charset=UTF-8")
+    public RESTfulResult delete(@RequestBody TRmCalpointValue model){
+    	if(model.getClock() == null || model.getClock().isEmpty()){
+    		return failed(null, "请传入开始时间");
+    	}
+    	if(model.getTimegranid() == null || model.getTimegranid().isEmpty()){
+    		return failed(null, "请传入时间粒度");
+    	}
+    	if(model.getItemid() == null || model.getItemid().isEmpty()){
+    		return failed(null, "请传入计量点编号");
+    	}
+    	HashMap<String, Object> m = new HashMap<String, Object>();
+    	m.put("clock", model.getClock());
+    	m.put("timegranid", model.getTimegranid());
+    	m.put("itemid", model.getItemid());
+        model.setId(m);
+        tRmCalpointValueService.delete(m);
+        return success();
+    }
+
+    @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tRmCalpointValue信息来更新详细信息")
+    @ApiImplicitParam(name = "tRmCalpointValue", value = "详细实体tRmCalpointValue", required = true, dataType = "TRmCalpointValue")
+    //@RequiresPermissions("trmcalpointvalue:update")
+    @PutMapping(value = "/batchupdate", produces  = "application/json;charset=UTF-8")
+    public RESTfulResult batchupdate(@RequestBody TRmCalpointValue[] model){
+        int failnum = 0;
+        String failmsg = "";
+        List<String> errorid = new ArrayList<>();
+        for (int i = 0; i< model.length; i++) {
+            if (model[i].getClock() == null || model[i].getClock().isEmpty()) {
+                failnum++;
+                errorid.add(model[i].getItemid());
+                failmsg+= "id为" + model[i].getItemid() + "数据请传入开始时间";
+                continue;
+            }
+            if (model[i].getTimegranid() == null || model[i].getTimegranid().isEmpty()) {
+                failnum++;
+                errorid.add(model[i].getItemid());
+                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入时间粒度";
+                continue;
+            }
+            if (model[i].getItemid() == null || model[i].getItemid().isEmpty()) {
+                failnum++;
+                errorid.add(model[i].getItemid());
+                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入计量点编号";
+                continue;
+            }
+            if (model[i].getApportvalue() == null) {
+                failnum++;
+                errorid.add(model[i].getItemid());
+                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入最终值";
+                continue;
+            }
+            if (model[i].getActualvalue() == null) {
+                failnum++;
+                errorid.add(model[i].getItemid());
+                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入计算值";
+                continue;
+            }
+            if (model[i].getCorrectvalue() == null) {
+                failnum++;
+                errorid.add(model[i].getItemid());
+                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据请传入修正值";
+                continue;
+            }
+            if (model[i].getActualvalue().add(model[i].getCorrectvalue()).compareTo(model[i].getApportvalue()) != 0) {
+                failnum++;
+                errorid.add(model[i].getItemid());
+                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")数据数值错误,最终值 = 计算值 + 修正值";
+                continue;
+            }
+            HashMap<String, Object> m = new HashMap<String, Object>();
+            m.put("clock", model[i].getClock());
+            m.put("timegranid", model[i].getTimegranid());
+            m.put("itemid", model[i].getItemid());
+            model[i].setId(m);
+            model[i].setUpman(JwtUtil.getUseridByToken());
+            model[i].setUptime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+            TRmCalpointValue tRmCalpointValue = tRmCalpointValueService.modifyAndCompute(model[i]);
+            if (tRmCalpointValue == null) {
+                failnum++;
+                errorid.add(model[i].getItemid());
+                failmsg+= "主键(id:" + model[i].getItemid() + "时间粒度:" + model[i].getTimegranid() + "时间:" + model[i].getClock() + ")修改对象不存在";
+                continue;
+            }
+        }
+        if(failnum > 0){
+            return success(errorid,"51","本次共修改" + model.length + "条数据,其中成功" + (model.length - failnum) + "条,失败" + failnum + "条");
+        }
+        return success();
+    }
+    
+    @ApiOperation(value="批量重新计算", notes="根据url的id来指定更新对象,并根据传过来的tRmCalpointValue信息来更新详细信息,从小时表数据更新")
+    @ApiImplicitParam(name = "tRmCalpointValue", value = "详细实体tRmCalpointValue", required = true, dataType = "TRmCalpointValue")
+    //@RequiresPermissions("trmcalpointvalue:update")
+    @PutMapping(value = "/batchCompute", produces  = "application/json;charset=UTF-8")
+    public RESTfulResult batchCompute(@RequestBody TRmCalpointValue[] model){
+    	if(model.length<1){
+    		return failed(null, "请勾选计量点数据");
+    	}
+    	// 重排计算顺序
+    	List<String> l = new ArrayList<String>();
+    	for (int i = 0; i< model.length; i++) {
+    		TRmCalpointValue tv = model[i];
+    		TRmCalpoint tRmCalpoint = tRmCalpointService.getById(tv.getItemid());
+    		if(tRmCalpoint!=null && tv.getClock()!=null && tv.getTimegranid()!=null){
+    			String seq = tRmCalpoint.getSeqno()==null?"0":tRmCalpoint.getSeqno()+"";
+    			l.add(tRmCalpoint.getItemtype() + "," +tv.getTimegranid()+","+tv.getClock()+","+tv.getItemid()+","+seq);
+    		}
+    	}
+    	// 调整计算顺序,虚拟点靠后0
+		Collections.sort(l, new Comparator<String>() {
+			public int compare(String s1, String s2) {
+				String itemtype1 = s1.split(",")[0];
+				String timegranid1 = s1.split(",")[1];
+				String clock1 = s1.split(",")[2];
+				String seqno1 = s1.split(",")[4];
+				Date d1 = new Date();
+				String itemtype2 = s2.split(",")[0];
+				String timegranid2 = s2.split(",")[1];
+				String clock2 = s2.split(",")[2];
+				String seqno2 = s2.split(",")[4];
+				Date d2 = new Date();
+				try {
+					if (itemtype1.equalsIgnoreCase(itemtype2)) {
+						Calendar cal = Calendar.getInstance();
+						if (timegranid1.equalsIgnoreCase("year")) {
+							cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1 + "-12-31 23"));
+							d1 = cal.getTime();
+						}else if(timegranid1.equalsIgnoreCase("month")){
+							cal.setTime(new SimpleDateFormat("yyyy-MM").parse(clock1));
+							cal.add(Calendar.MONTH, 1);
+							cal.add(Calendar.HOUR_OF_DAY, -3);
+							d1 = cal.getTime();
+						}else if(timegranid1.equalsIgnoreCase("day")){
+							cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(clock1));
+							d1 = cal.getTime();
+						}else if(timegranid1.equalsIgnoreCase("shift")){
+							cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH").parse(clock1));
+							d1 = cal.getTime();
+						}
+						if (timegranid2.equalsIgnoreCase("year")) {
+							cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH").parse(clock2 + "-12-31 23"));
+							d2 = cal.getTime();
+						}else if(timegranid2.equalsIgnoreCase("month")){
+							cal.setTime(new SimpleDateFormat("yyyy-MM").parse(clock2));
+							cal.add(Calendar.MONTH, 1);
+							cal.add(Calendar.HOUR_OF_DAY, -3);
+							d2 = cal.getTime();
+						}else if(timegranid2.equalsIgnoreCase("day")){
+							cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(clock2));
+							d2 = cal.getTime();
+						}else if(timegranid2.equalsIgnoreCase("shift")){
+							cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH").parse(clock2));
+							d2 = cal.getTime();
+						}
+						if(d1.getTime() > d2.getTime()){
+							return 1;
+						}else if(d1.getTime() < d2.getTime()){
+							return -1;
+						}else {
+							if(Integer.valueOf(seqno1) > Integer.valueOf(seqno2)){
+								return 1;
+							}else if(Integer.valueOf(seqno1) < Integer.valueOf(seqno2)){
+								return -1;
+							}else{
+								return 0;
+							}
+						}
+					} else {
+						if (itemtype1.equalsIgnoreCase("VIRTUAL")) {
+							return 1;
+						} else if (itemtype2.equalsIgnoreCase("VIRTUAL")) {
+							return -1;
+						} else {
+							return 0;
+						}
+					}
+				} catch (ParseException e) {
+					return 0;
+				}
+			}
+		});
+		for (int i = 0; i< l.size(); i++) {
+			tRmCalpointValueService.restatCalpData(l.get(i).split(",")[3], l.get(i).split(",")[2], l.get(i).split(",")[1], JwtUtil.getUseridByToken());
+		}
+    	return success();
+    }
+    
+    @ApiOperation(value="获得计量点时间段数据", notes="获得计量点时间段数据,期初、期末、计算值")
+    @GetMapping(value = "/getCalpointValue")
+    public RESTfulResult getCalpointValue(@RequestParam HashMap<String, Object> parmas){
+    	if(parmas.get("start")==null || parmas.get("start").toString().isEmpty()){
+    		return failed(null, "请传入起始时间");
+    	}
+    	if(parmas.get("end")==null || parmas.get("end").toString().isEmpty()){
+    		return failed(null, "请传入结束时间");
+    	}
+    	try {
+    		String start = parmas.get("start").toString();
+    		String end = parmas.get("end").toString();
+			if(new SimpleDateFormat("yyyy-MM-dd").parse(start).after(new Date())){
+				return failed(null, "起始时间不能在今天之后");
+			}
+			if(new SimpleDateFormat("yyyy-MM-dd").parse(end).after(new Date())){
+				return failed(null, "结束时间不能在今天之后");
+			}
+		} catch (ParseException e) {
+			return failed(null, "时间格式错误");
+		}
+    	if(parmas.get("ids")==null || parmas.get("ids").toString().isEmpty()){
+    		return failed(null, "请传入计量点");
+    	}
+    	List<Map<String, Object>> list  = tRmCalpointValueService.getCalpointValue(parmas);
+        return success(list);
+    }
+
+    @ApiOperation(value="重新计算单个计量点数据")
+    //@RequiresPermissions("trmcalpointvalue:view")
+    @GetMapping(value = "/restatCal")
+    public RESTfulResult restatCal(@RequestParam HashMap<String, Object> parmas, String clock, String clocke, String timegranid){
+    	if (parmas == null) {
+    		parmas = new HashMap<String, Object>();
+    	}
+    	if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
+            String itemid = parmas.get("itemid").toString();
+            if(!itemid.startsWith("'")){
+            	itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+            }
+            parmas.put("itemid", itemid);
+        }
+		if (clock==null || clock.isEmpty()) {
+    		return failed(null, "请传入起始时间");
+    	}
+		if (timegranid==null || timegranid.isEmpty()) {
+    		return failed(null, "请传入时间粒度");
+    	}
+		parmas.put("useflag", "1");
+		// 查询需要统计的计量点信息
+		List<TRmCalpoint> l = tRmCalpointMapper.selectCalpoints(parmas);
+		String res = "";
+		for(TRmCalpoint tRmCalpoint : l){
+			res = formulaService.reItemVal(tRmCalpoint.getItemid(),clock,timegranid,clocke);
+		}
+		if(!res.isEmpty()){
+			return failed(null, res);
+		}
+        return success();
+    }
+    
+    @ApiOperation(value="重新生成数据", notes="")
+    //@RequiresPermissions("trmcalpointvalue:view")
+    @GetMapping(value = "/reData")
+    public RESTfulResult reData(@RequestParam HashMap<String, Object> parmas, String clock, String clocke, String timegranid){
+    	if (clock==null || clock.isEmpty()) {
+    		return failed(null, "请传入起始时间");
+    	}
+    	if (clocke==null || clocke.isEmpty()) {
+    		return failed(null, "请传入结束时间");
+    	}
+		if (timegranid==null || timegranid.isEmpty()) {
+			return failed(null, "请传入时间粒度");
+    	}
+		if(parmas.get("itemid") != null && !parmas.get("itemid").toString().isEmpty()){
+            String itemid = parmas.get("itemid").toString();
+            if(!itemid.startsWith("'")){
+            	itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+            }
+            parmas.put("itemid", itemid);
+        }
+    	if(parmas.get("locateid") != null && !parmas.get("locateid").toString().isEmpty()){
+            String locateid = parmas.get("locateid").toString();
+            if(!locateid.startsWith("'")){
+            	locateid = "'" + locateid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+            }
+            parmas.put("locateid", locateid);
+        }
+    	if(parmas.get("networkid") != null && !parmas.get("networkid").toString().isEmpty()){
+            String networkid = parmas.get("networkid").toString();
+            if(!networkid.startsWith("'")){
+            	networkid = "'" + networkid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+            }
+            parmas.put("networkid", networkid);
+        }
+    	if(parmas.get("energytypeid") != null && !parmas.get("energytypeid").toString().isEmpty()){
+            String energytypeid = parmas.get("energytypeid").toString();
+            if(!energytypeid.startsWith("'")){
+            	energytypeid = "'" + energytypeid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+            }
+            parmas.put("energytypeid", energytypeid);
+        }
+    	if(parmas.get("energyid") != null && !parmas.get("energyid").toString().isEmpty()){
+            String energyid = parmas.get("energyid").toString();
+            if(!energyid.startsWith("'")){
+            	energyid = "'" + energyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+            }
+            parmas.put("energyid", energyid);
+        }
+    	if(parmas.get("propertyid") != null && !parmas.get("propertyid").toString().isEmpty()){
+            String propertyid = parmas.get("propertyid").toString();
+            if(!propertyid.startsWith("'")){
+            	propertyid = "'" + propertyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+            }
+            parmas.put("propertyid", propertyid);
+        }
+    	String res = "";
+    	parmas.put("useflag", "1");
+		// 查询需要统计的计量点信息
+		List<TRmCalpoint> l = tRmCalpointMapper.selectLikeByParameters(parmas);
+		int size = l.size();
+		for(int i = 0; i<l.size(); i++){
+			if(res.isEmpty()){
+				res = formulaService.reItemVal(l.get(i).getItemid(),clock,timegranid,clocke);
+			}else{
+				formulaService.reItemVal(l.get(i).getItemid(),clock,timegranid,clocke);
+			}
+			logger.info("剩下要处理的项目数:" + (size-1-i) + "(" + size + ")");
+		}
+		if(!res.isEmpty()){
+			return success(null, res);
+		}
+        return success(null, res);
+    }
+	@ApiOperation(value="补全", notes="")
+	//@RequiresPermissions("trmcalpointvalue:view")
+	@GetMapping(value = "/resData")
+	public RESTfulResult resData(@RequestParam HashMap<String, Object> parmas,String clock, String clocke) {
+		if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
+			String itemid = parmas.get("itemid").toString();
+			if(!itemid.startsWith("'")){
+				itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+			}
+			tRmCalpointValueService.resWData(clock,clocke);
+		}
+
+		return success();
+	}
+
+	@GetMapping(value = "/aaa")
+	public RESTfulResult aaa(){
+		tRmCalpointValueService.insetDataForBb();
+		return success();
+	}
+
+    /**
+     * 补全小时,日数据(有十分钟数据的基础上补全)
+     * @param itemId
+     * @param startClock
+     * @param endClock
+     * @return
+     * @throws ParseException
+     */
+	@GetMapping(value = "/restartWdata")
+	public RESTfulResult restartWdata(@RequestParam String itemId,@RequestParam String startClock,@RequestParam String endClock) throws ParseException {
+
+		tRmCalpointService.resData(itemId,startClock, endClock);
+		return success();
+	}
+
+	@ApiOperation(value="从电力需求侧补全历史数据", notes="")
+	//@RequiresPermissions("trmcalpointvalue:view")
+	@GetMapping(value = "/resElData")
+	public RESTfulResult resElData(@RequestParam HashMap<String, Object> parmas,String clock, String clocke) {
+		if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
+			String itemid = parmas.get("itemid").toString();
+			if(!itemid.startsWith("'")){
+				itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+			}
+			String message = tRmCalpointValueService.resEData(itemid,clock,clocke);
+			if(message == "") {
+				return  success();
+			} else {
+				return failed(null, message);
+			}
+		}
+		return failed(null, "参数错误!");
+	}
+}