b80ca998 康伟

kangwei:设备分析补充:添加排序,时间格式化

1 个父辈 08331463
......@@ -13,11 +13,15 @@ import com.skua.modules.statistics.vo.EquipmentFailurelVO;
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 lombok.SneakyThrows;
import netscape.javascript.JSUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.text.ParseException;
......@@ -59,6 +63,8 @@ public class EquipmentStatisticsServiceImpl implements IEquipmentStatisticsServ
if(StringUtils.isNotEmpty(departIds)){
sql += " and d.id in ("+ departIds +") ";
}
sql += " order by aaa.repair_cost desc ";
List<EquipmentRepairMaintainTaskCostVO> dataList = getJdbcTemplate().query(sql,new BeanPropertyRowMapper<EquipmentRepairMaintainTaskCostVO>(EquipmentRepairMaintainTaskCostVO.class));
return dataList;
}
......@@ -72,7 +78,7 @@ public class EquipmentStatisticsServiceImpl implements IEquipmentStatisticsServ
*/
public List<EquipmentRepairMaintainTaskCostDetailVO> repairMaintainTaskCostDetailList(String departId, String startTime, String endTime){
String sql = "select d.depart_name, aaa.* from ( ";
sql +=" select er.depart_id , ei.equipment_name 'name' , '维修费用' as 'cost_type',er.total_cost 'cost',er.repair_date 'time' from equipment_repair er , equipment_info ei ";
sql +=" select er.depart_id , ei.equipment_name 'name' , '维修费用' as 'cost_type',er.total_cost 'cost',\tDATE_FORMAT( er.repair_date, '%Y-%m-%d' ) 'time' from equipment_repair er , equipment_info ei ";
sql += " where er.info_id = ei.id and er.total_cost > 0 and er.repair_date >= '"+startTime+" 00:00:00' and er.repair_date <='"+endTime+" 23:59:59' and er.depart_id = '"+departId+"' ";
sql += " UNION " ;
sql += " select emt.depart_id, emt.maintain_plan_name 'name',";
......@@ -80,10 +86,12 @@ public class EquipmentStatisticsServiceImpl implements IEquipmentStatisticsServ
sql += " WHEN emp.maintenance_type='sbwh' THEN '维护费用'";
sql += " WHEN emp.maintenance_type='sbby' THEN '保养费用'";
sql += " WHEN emp.maintenance_type='jjwx' THEN '基建维修费用'";
sql += " ELSE '其他保养' END AS cost_type, emt.maintenance_cost 'cost', DATE_FORMAT(emt.maintain_time,'%Y-%m-%d') 'time', ";
sql += " ELSE '其他保养' END AS cost_type, emt.maintenance_cost 'cost', DATE_FORMAT(emt.maintain_time,'%Y-%m-%d') 'time' ";
sql += " from equipment_maintain_task emt ,equipment_maintain_plan emp where emt.plan_id = emp.id ";
sql += " and emt.depart_id = '"+departId+"' and emt.maintain_time >= '"+startTime+" 00:00:00' and emt.maintain_time <='"+endTime+" 23:59:59' ";
sql += " ) aaa left join sys_depart d on d.id = aaa.depart_id ";
sql += " order by aaa.time desc ";
List<EquipmentRepairMaintainTaskCostDetailVO> dataList = getJdbcTemplate().query(sql,new BeanPropertyRowMapper<EquipmentRepairMaintainTaskCostDetailVO>(EquipmentRepairMaintainTaskCostDetailVO.class));
return dataList;
}
......@@ -153,10 +161,6 @@ public class EquipmentStatisticsServiceImpl implements IEquipmentStatisticsServ
sql += " ) aaa group by aaa.time order by aaa.time asc";
dataList = pgCommonService.queryForList(sql);
}
} catch (ParseException e) {
e.printStackTrace();
}
......@@ -166,6 +170,68 @@ 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);
String metric_sql = "select fd.device_id 'countTableName', ei.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 " +
" left join sys_factory_device fd on fd.depart_id = t.depart_id " +
"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 metricYXTag = null;
List<Map<String, Object>> yx_dataList = null;
List<Map<String, Object>> total_dataList = null;
if(metricMapList != null && !metricMapList.isEmpty()){
for(Map<String, Object> metricMap : metricMapList){ //遍历设备记录以及metric 标签
metricYXTag = metricMap.get("yxExpress")+","+metricMap.get("gzExpress")+","+metricMap.get("tzExpress");
metricYXTag = metricYXTag.replaceAll(",,",",");
if(metricYXTag.endsWith(",")){
metricYXTag = metricYXTag.substring(0, metricYXTag.length() - 1);
}
//运行时长
String yx_sql = " select aaa.time , ROUND(SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) ) / 60 ,2)as duration from (";
yx_sql += " select TO_TIMESTAMP(ts ::BIGINT)::DATE AS time,nm as monitorId,v as monitorValue from " + metricMap.get("countTableName") + "_count where nm = '"+metricMap.get("yxExpress")+"' and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' " ;
yx_sql += " ) aaa group by aaa.time order by aaa.time asc";
yx_dataList = pgCommonService.queryForList(yx_sql);
String total_sql = " select aaa.time , ROUND(SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) ) / 60 ,2)as duration from (";
total_sql += " select TO_TIMESTAMP(ts ::BIGINT)::DATE AS time,nm as monitorId,v as monitorValue from " + metricMap.get("countTableName") + "_count where nm in ("+ JSUtils.quoteEach(metricYXTag,",") +") ' and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' " ;
total_sql += " ) aaa group by aaa.time order by aaa.time asc";
total_dataList = pgCommonService.queryForList(total_sql);
//总时间长
}
}
return false;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!