507acdb6 康伟

kangwei:运行设备时长日报录入数据接口

1 个父辈 4c73019b
......@@ -229,6 +229,7 @@ public class EquipmentStatisticsController {
return result;
}
/* @ApiOperation(value = "设备看板-设备故障分页列表", notes = "设备看板-设备故障分页列表")
@GetMapping(value = "/equipmentFailurePage")
public Result<IPage<EquipmentInfo>> queryEquipmentFailurePage(EquipmentInfo equipmentInfo,
......
......@@ -17,4 +17,14 @@ public interface IEquipmentInfoDurationService extends IService<EquipmentInfoDur
* @return
*/
IPage<EquipmentInfoDuration> queryPageList(Page page, EquipmentInfoDuration equipmentInfo);
/***
* 填报数据
* @param departId
* @param startTime
* @param endTime
* @return
* @throws Exception
*/
public boolean fillOutEquipmentInfoDuration(String departId,String startTime,String endTime) throws Exception;
}
......
......@@ -65,4 +65,6 @@ public interface IEquipmentStatisticsService {
* @return
*/
List<Map<String, Object>> queryEquipmentOperationRecordDetail(String departId, String equipmentId, String startTime, String endTime);
}
......
......@@ -3,12 +3,26 @@ package com.skua.modules.statistics.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.util.ConvertUtils;
import com.skua.core.util.DateUtils;
import com.skua.core.util.DoubleOperaUtils;
import com.skua.modules.common.service.ICommonSqlService;
import com.skua.modules.common.service.IPgCommonService;
import com.skua.modules.statistics.entity.EquipmentInfoDuration;
import com.skua.modules.statistics.mapper.EquipmentInfoDurationMapper;
import com.skua.modules.statistics.service.IEquipmentInfoDurationService;
import com.skua.tool.util.UniqIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 设备时长日报
......@@ -16,6 +30,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class EquipmentInfoDurationServiceImpl extends ServiceImpl<EquipmentInfoDurationMapper, EquipmentInfoDuration> implements IEquipmentInfoDurationService {
@Autowired
private ICommonSqlService commonSqlService;
@Autowired
private IPgCommonService pgCommonService;
/***
* 分页列表
* @param page
......@@ -25,4 +43,95 @@ public class EquipmentInfoDurationServiceImpl extends ServiceImpl<EquipmentInfoD
public IPage<EquipmentInfoDuration> queryPageList(Page page, EquipmentInfoDuration equipmentInfoDuration){
return this.baseMapper.queryPageList(page,equipmentInfoDuration);
}
/***
* 设备运行时长填报数据
* @param departId
* @param startTime
* @param endTime
* @return
*/
@Transactional
public boolean fillOutEquipmentInfoDuration(String departId,String startTime,String endTime) throws Exception{
//清理数据
String deleteSql = " delete from equipment_info_duration where depart_id = '"+departId+"' and date_time >= '"+startTime+"' and data_time <='"+endTime+"' ";
commonSqlService.delete(deleteSql);
//2
String countTableName = commonSqlService.queryForString("select device_id from sys_factory_device where depart_id = '" + departId + "'");
// 步骤3
String metric_sql = "select t.equipment_code as 'info_id', ei.equipment_name , t.metric_express1 'gzExpress' , t.metric_express2 'yxExpress' ,t.metric_express3 'tzExpress' from sys_monitor_metric_info t ";
metric_sql += " left join equipment_info ei on ei.id = t.equipment_code where t.metric_type = 1 and t.depart_id = '"+departId+"' and t.equipment_code > 0 ";
List<Map<String, Object>> metricMapList = commonSqlService.queryForList(metric_sql);
if(startTime.length() < 11 ){
startTime = startTime +" 00:00:00";
}
if(endTime.length() < 11 ){
endTime = endTime +" 23:59:59";
}
String tsStartTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(startTime, "yyyy-MM-dd HH:mm:ss")) / 1000L);
String tsEndTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(endTime, "yyyy-MM-dd HH:mm:ss")) / 1000L);
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String pgSql = null;
//步骤4 查询 pg数据库
try{
List<Map<String, Object>> dataList = null;
// Object[] obj = null;
List<String> insertSqlList= new ArrayList<>();
List<Object[]> batchArgs=new ArrayList<Object[]>();
if(metricMapList != null && !metricMapList.isEmpty()){
for(Map<String, Object> metricMap : metricMapList){ //遍历设备记录以及metric 标签
pgSql = "select aaaaa.time , aaaaa.yx_duration ,bbbbb.gz_duration from ( ";
pgSql += " select '11111111' info_id , aaa.time , ROUND(SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) ) / 60 ,2)as yx_duration from ( ";
pgSql += " select TO_TIMESTAMP(ts ::BIGINT)::DATE AS time,nm as monitorId,v as monitorValue from TCSWSCLC_count where nm ='"+metricMap.get("yxExpress")+"' and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' ";
pgSql += " ) aaa group by aaa.time order by aaa.time asc ";
pgSql += " ) aaaaa ";
pgSql += " left join ( ";
pgSql += " select aaa.time , ROUND(SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) ) / 60 ,2)as gz_duration from ( ";
pgSql += " select TO_TIMESTAMP(ts ::BIGINT)::DATE AS time,nm as monitorId,v as monitorValue from TCSWSCLC_count where nm ='"+ ConvertUtils.getString(metricMap.get("gzExpress"),"-")+"' and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' ";
pgSql += " ) aaa group by aaa.time order by aaa.time asc ";
pgSql += " )bbbbb on aaaaa.time = bbbbb.time ";
pgSql += " left join ( ";
pgSql += " select '11111111' info_id , ROUND(SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) ) / 60 ,2)as total_duration from ( ";
pgSql += " select TO_TIMESTAMP(ts ::BIGINT)::DATE AS time,nm as monitorId,v as monitorValue from TCSWSCLC_count where nm in('"+metricMap.get("yxExpress")+"','"+ConvertUtils.getString(metricMap.get("gzExpress"),"-")+"','"+ConvertUtils.getString(metricMap.get("tzExpress"),"-")+"') and ts <'"+tsEndTime+"' ";
pgSql += " ) aaa ";
pgSql += ")ccccc on aaaaa.info_id = ccccc.info_id ";
dataList = pgDb.queryForList(pgSql);
//总时间长
if(dataList != null && !dataList.isEmpty()){
for(Map<String,Object > dataMap : dataList){
Object[] obj = { UniqIdUtils.getInstance().getUniqID() ,departId ,metricMap.get("info_id"),dataMap.get("time"),dataMap.get("yx_duration"),dataMap.get("gz_duration"),dataMap.get("total_duration"),DateUtils.now()};
batchArgs.add(obj);
}
}
}
// this.getJdbcTemplate().batchUpdate();
if(batchArgs != null && !batchArgs.isEmpty()){
this.getJdbcTemplate().batchUpdate("insert into equipment_info_duration (id,depart_id,info_id,data_time,gz_duration,yz_duration,total_duration,create_time) value(?,?,?,?,?,?,?,?)",batchArgs);
}
//计算总时长
}
}catch (Exception e){
e.printStackTrace();
}
return true;
}
private JdbcTemplate getJdbcTemplate(){
JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringContextUtils.getBean("master");
return jdbcTemplate;
}
}
......
......@@ -14,6 +14,7 @@ import com.skua.modules.statistics.vo.EquipmentOperationRecordVO;
import com.skua.modules.statistics.vo.EquipmentRepairMaintainTaskCostDetailVO;
import com.skua.modules.statistics.vo.EquipmentRepairMaintainTaskCostVO;
import com.skua.tool.util.JSUtils;
import com.skua.tool.util.UniqIdUtils;
import lombok.SneakyThrows;
import netscape.javascript.JSUtil;
import org.apache.commons.lang3.StringUtils;
......@@ -170,71 +171,6 @@ public class EquipmentStatisticsServiceImpl implements IEquipmentStatisticsServ
return dataList;
}
/***
* 设备运行时长填报数据
* @param departId
* @param startTime
* @param endTime
* @return
*/
@Transactional
public boolean fillOutEquipmentInfoDuration(String departId,String startTime,String endTime) throws Exception{
//清理数据
String deleteSql = " delete from equipment_info_duration where depart_id = '"+departId+"' and date_time >= '"+startTime+"' and date_time <='"+endTime+"' ";
commonSqlService.delete(deleteSql);
//2
String countTableName = commonSqlService.queryForString("select device_id from sys_factory_device where depart_id = '" + departId + "'");
// 步骤3
String metric_sql = "select t.equipment_code as 'info_id', ei.equipment_name , t.metric_express1 'gzExpress' , t.metric_express2 'yxExpress' ,t.metric_express3 'tzExpress' from sys_monitor_metric_info t ";
metric_sql += " left join equipment_info ei on ei.id = t.equipment_code where t.metric_type = 1 and t.depart_id = '"+departId+"' and t.equipment_code > 0 ";
List<Map<String, Object>> metricMapList = commonSqlService.queryForList(metric_sql);
if(startTime.length() < 11 ){
startTime = startTime +" 00:00:00";
}
if(endTime.length() < 11 ){
endTime = endTime +" 23:59:59";
}
String tsStartTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(startTime, "yyyy-MM-dd HH:mm:ss")) / 1000L);
String tsEndTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(endTime, "yyyy-MM-dd HH:mm:ss")) / 1000L);
String pgSql = null;
//步骤4 查询 pg数据库
List<Map<String, Object>> dataList = null;
String insertSql = null;
if(metricMapList != null && !metricMapList.isEmpty()){
for(Map<String, Object> metricMap : metricMapList){ //遍历设备记录以及metric 标签
pgSql = "select aaaaa.depart_id, aaaaa.info_id, aaaaa.time data_time, aaaaa.yx_duration ,bbbbb.gz_duration from (";
pgSql += " select '"+departId+"' depart_id, '"+metricMap.get("info_id")+"' info_id , aaa.time , ROUND(SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) ) / 60 ,2)as yx_duration from ( ";
pgSql += " select TO_TIMESTAMP(ts ::BIGINT)::DATE AS time,nm as monitorId,v as monitorValue from TCSWSCLC_count where nm ='"+metricMap.get("yxExpress")+"' and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' ";
pgSql += " ) aaa group by aaa.time order by aaa.time asc ";
pgSql += " ) aaaaa ";
if(metricMap.get("gzExpress") != null ){
pgSql += " left join ( ";
pgSql += " select aaa.time , ROUND(SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) ) / 60 ,2)as gz_duration from ( ";
pgSql += " select TO_TIMESTAMP(ts ::BIGINT)::DATE AS time,nm as monitorId,v as monitorValue from TCSWSCLC_count where nm ='"+metricMap.get("yxExpress")+"' and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' ";
pgSql += " ) aaa group by aaa.time order by aaa.time asc ";
pgSql += " )bbbbb on aaaaa.time = bbbbb.time ";
}
dataList = pgCommonService.queryForList(pgSql);
//总时间长
}
}
return false;
}
private JdbcTemplate getJdbcTemplate(){
JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringContextUtils.getBean("master");
return jdbcTemplate;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!