|
@@ -0,0 +1,173 @@
|
|
|
+package com.gyee.power.fitting.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.gyee.power.fitting.common.config.StringUtils;
|
|
|
+import com.gyee.power.fitting.mapper.AlarmTsMapper;
|
|
|
+import com.gyee.power.fitting.model.AlarmTs;
|
|
|
+import com.gyee.power.fitting.model.vo.AlarmSimpleVo;
|
|
|
+import com.gyee.power.fitting.model.vo.AlarmTag;
|
|
|
+import com.gyee.power.fitting.model.vo.AlarmTsVo;
|
|
|
+import com.gyee.power.fitting.model.vo.AlarmVo;
|
|
|
+import com.gyee.power.fitting.service.IAlarmTsService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+public class AlarmTsServiceImpl extends ServiceImpl<AlarmTsMapper, AlarmTs> implements IAlarmTsService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AlarmTsMapper alarmTsMapper;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void createSuperTable(String type) {
|
|
|
+
|
|
|
+ alarmTsMapper.createAlarmSuperTable(type);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void dropSuperTable(String type) {
|
|
|
+
|
|
|
+ alarmTsMapper.dropSuperTable(type);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public int createTable(String tbName, String alarmid, String alarmtype,
|
|
|
+ String characteristic, String components,
|
|
|
+ String description,
|
|
|
+ String deviceid, String devicename,
|
|
|
+ String devicetype, Boolean enabled,
|
|
|
+ String lineid, String linename,
|
|
|
+ String modelId, String projectid,
|
|
|
+ String projectname, Integer rank,
|
|
|
+ Boolean resettable, String stationid,
|
|
|
+ String stationname, String subcomponents,
|
|
|
+ String suffix, String tagid,
|
|
|
+ Integer triggertype, String uniformcode,String superTableName
|
|
|
+
|
|
|
+ ) {
|
|
|
+ return alarmTsMapper.createTable(tbName, alarmid, alarmtype,
|
|
|
+ characteristic, components,
|
|
|
+ description,
|
|
|
+ deviceid, devicename,
|
|
|
+ devicetype, enabled,
|
|
|
+ lineid, linename,
|
|
|
+ modelId, projectid,
|
|
|
+ projectname, rank,
|
|
|
+ resettable, stationid,
|
|
|
+ stationname, subcomponents,
|
|
|
+ suffix, tagid,
|
|
|
+ triggertype, uniformcode,superTableName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public int createTable(AlarmVo vo) {
|
|
|
+ return alarmTsMapper.createTable(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int insertOne(AlarmTs one) {
|
|
|
+ return alarmTsMapper.insertOne(one);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void insertList(List<AlarmTag> alarmTags ) {
|
|
|
+
|
|
|
+ if(StringUtils.notEmp(alarmTags) && !alarmTags.isEmpty())
|
|
|
+ {
|
|
|
+
|
|
|
+ createSql(alarmTags);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void createSql(List<AlarmTag> alarmTags ) {
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder("INSERT INTO ");
|
|
|
+
|
|
|
+ int i=0;
|
|
|
+ for (AlarmTag tag:alarmTags) {
|
|
|
+
|
|
|
+
|
|
|
+ String tableName = tag.getId();
|
|
|
+ StringBuilder sub_sb = new StringBuilder(tableName);
|
|
|
+
|
|
|
+ sub_sb.append( " values ");
|
|
|
+ sub_sb.append(" (");
|
|
|
+ sub_sb.append(tag.getTs()).append(",").append(tag.getVal().intValue()).append(",").append(tag.getConfirmed()).append(",")
|
|
|
+ .append(tag.getEndts()).append(",").append(tag.getTimeLong());
|
|
|
+ sub_sb.append(" ) ");
|
|
|
+ i++;
|
|
|
+ if (i==100) {
|
|
|
+ alarmTsMapper.insertList(String.valueOf(sb));
|
|
|
+ sb = new StringBuilder("INSERT INTO ");
|
|
|
+ i=0;
|
|
|
+ }
|
|
|
+ sb.append(sub_sb);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(i!=0)
|
|
|
+ {
|
|
|
+ alarmTsMapper.insertList(String.valueOf(sb));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ public List<AlarmVo> findTags(String stbaleName)
|
|
|
+ {
|
|
|
+ List<AlarmVo> ls=new ArrayList<>();
|
|
|
+ if(StringUtils.notEmp(stbaleName))
|
|
|
+ {
|
|
|
+ ls= alarmTsMapper.findTags(stbaleName);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ls;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AlarmTsVo> selectByWpGroup(String superTableName, String stationid, long begin, long end) {
|
|
|
+ List<AlarmTsVo> ls=new ArrayList<>();
|
|
|
+ if(StringUtils.notEmp(superTableName) && StringUtils.notEmp(stationid) && StringUtils.notEmp(begin) && StringUtils.notEmp(end))
|
|
|
+ {
|
|
|
+ ls= alarmTsMapper.selectByWpGroup(superTableName, stationid, begin, end);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ls;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public List<AlarmVo> selectByTbName(String tbName,long limit,long offset)
|
|
|
+ {
|
|
|
+ List<AlarmVo> ls=new ArrayList<>();
|
|
|
+ if(StringUtils.notEmp(tbName) && StringUtils.notEmp(limit) && StringUtils.notEmp(offset))
|
|
|
+ {
|
|
|
+ ls= alarmTsMapper.selectByTbName(tbName, limit, offset);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ls;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<AlarmSimpleVo> selectLastRowByTbname(String superTableName, String tbnames){
|
|
|
+ List<AlarmSimpleVo> ls=new ArrayList<>();
|
|
|
+ if(StringUtils.notEmp(superTableName) && StringUtils.notEmp(tbnames))
|
|
|
+ {
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append("select last_row(*),tbname from ").append(superTableName).append(" where tbname in( ").append(tbnames).append(" ) group by tbname");
|
|
|
+
|
|
|
+ ls= alarmTsMapper.selectLastRowByTbname(String.valueOf(sb));
|
|
|
+ }
|
|
|
+
|
|
|
+ return ls;
|
|
|
+ }
|
|
|
+}
|