f76b9f1b 张雷

Merge remote-tracking branch 'origin/master' into master

2 个父辈 163e910d 4c73019b
......@@ -21,7 +21,18 @@ import java.util.regex.Pattern;
* @version 1.0
*/
public class JSUtils {
/***
* 根据时间获取季度
* @param dateString
* @return
*/
public static int getQuarter(String dateString) {
// 将字符串解析为LocalDate对象
LocalDate date = LocalDate.parse(dateString);
// 获取月份并计算季度
int month = date.getMonthValue();
return (month - 1) / 3 + 1;
}
//判断一个字符串是否是整数,并相应地返回整数或原始字符串
public static String convertStringToInt(String str) {
if (StringUtils.isNotEmpty(str) && str.endsWith(".00")) {
......
......@@ -179,11 +179,13 @@ public class EquipmentStatisticsServiceImpl implements IEquipmentStatisticsServ
//清理数据
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 ";
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);
......@@ -196,32 +198,30 @@ public class EquipmentStatisticsServiceImpl implements IEquipmentStatisticsServ
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;
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 标签
metricYXTag = metricMap.get("yxExpress")+","+metricMap.get("gzExpress")+","+metricMap.get("tzExpress");
metricYXTag = metricYXTag.replaceAll(",,",",");
if(metricYXTag.endsWith(",")){
metricYXTag = metricYXTag.substring(0, metricYXTag.length() - 1);
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 ";
}
//运行时长
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);
dataList = pgCommonService.queryForList(pgSql);
//总时间长
}
}
......
......@@ -46,14 +46,19 @@ public class OperationReportServiceImpl implements IOperationReportService {
*/
public ProductDataVO handeReportMonthData(String departId,Integer year, Integer season,String startDate,String endDate){
ProductDataVO productDataVO = new ProductDataVO();//返回结果
int lastYear = year - 1;//去年
productDataVO.setLastYear(lastYear);
productDataVO.setYear( year );
SeasonTimeVO seasonTimeVO = new SeasonTimeVO(year ,season );
// SeasonTimeVO lastSeasonTimeVO = new SeasonTimeVO(lastYear ,season );
productDataVO.setSeansonEndDay(seasonTimeVO.getEndTime());//季度最后一天
productDataVO.setStartTime(seasonTimeVO.getStartTime());//季度开始时间
productDataVO.setEndTime( seasonTimeVO.getEndTime());//季度结束时间
if(year != null ){
int lastYear = year - 1;//去年
productDataVO.setLastYear(lastYear);
productDataVO.setYear( year );
}
if(year != null && season != null ){
SeasonTimeVO seasonTimeVO = new SeasonTimeVO(year ,season );
// SeasonTimeVO lastSeasonTimeVO = new SeasonTimeVO(lastYear ,season );
productDataVO.setSeansonEndDay(seasonTimeVO.getEndTime());//季度最后一天
productDataVO.setStartTime(seasonTimeVO.getStartTime());//季度开始时间
productDataVO.setEndTime( seasonTimeVO.getEndTime());//季度结束时间
}
if(StringUtils.isNotEmpty(startDate)){
productDataVO.setStartTime(startDate);//开始时间
}
......
......@@ -22,6 +22,9 @@ public class ProductDataVO {
@ApiModelProperty(value = "今年")
private Integer year;
@ApiModelProperty(value = "季度")
private Integer season;
@ApiModelProperty(value = "季度开始时间")
private String startTime;
@ApiModelProperty(value = "季度结束时间")
......@@ -121,5 +124,15 @@ public class ProductDataVO {
}
return deptName;
}
public ProductDataVO() {
}
public ProductDataVO(Integer year, Integer season, String startTime, String endTime) {
this.year = year;
this.season = season;
this.startTime = startTime;
this.endTime = endTime;
}
}
......
......@@ -4,6 +4,7 @@ import com.skua.core.api.vo.Result;
import com.skua.core.context.BaseContextHandler;
import com.skua.modules.inspection.service.IInspectionAnalysisService;
import com.skua.modules.inspection.vo.*;
import com.skua.modules.system.service.ISysDepartService;
import com.skua.tool.util.JSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -33,6 +34,8 @@ public class InspectionAnalysisController {
@Autowired
private IInspectionAnalysisService inspectionAnalysisService;
@Autowired
private ISysDepartService sysDepartService;
/**
* <pre>
......@@ -258,10 +261,13 @@ public class InspectionAnalysisController {
@GetMapping("/getInspectionEquipOverviewDetail")
public Result<List<InspectionEquipIndicatorsDetailVO>> getInspectionEquipOverviewDetail(String departId,String startDate, String endDate){
Result<List<InspectionEquipIndicatorsDetailVO>> result = new Result<>();
String departIds = departId;
if(StringUtils.isEmpty(departId)){
departId = BaseContextHandler.getDeparts();
departIds = BaseContextHandler.getDeparts();
}else{
departIds = sysDepartService.getChildDepartId(departId);
}
List<InspectionEquipIndicatorsDetailVO> dataList = inspectionAnalysisService.getInspectionEquipOverviewDetail(JSUtils.quoteEach(departId,","),startDate,endDate);
List<InspectionEquipIndicatorsDetailVO> dataList = inspectionAnalysisService.getInspectionEquipOverviewDetail(departIds,startDate,endDate);
result.setSuccess(true);
result.setResult(dataList);
return result;
......
......@@ -62,6 +62,7 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
private ICommonSqlService commonSqlService;
@Autowired
private InspectionAnalysisMapper inspectionAnalysisMapper;
private static NumberFormat numberFormat;
static {
......@@ -889,8 +890,29 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
* @return
*/
public List<InspectionEquipIndicatorsDetailVO> getInspectionEquipOverviewDetail(String departIds, String startDate, String endDate){
return inspectionAnalysisMapper.getInspectionEquipIndicatorsDetail( departIds, startDate, endDate);
// return inspectionAnalysisMapper.getInspectionEquipIndicatorsDetail( departIds, startDate, endDate);
//return null;
String sql = "select d.depart_name, d.id 'departId' , ifnull(kkk.total_count,0) 'totalInspectionEquipCount' , ifnull(kkk.yj_count,0) 'checkedInspectionEquipCount' ,ifnull(kkk.yc_count,0) 'abnormalInspectionEquipCount' ,(ifnull(kkk.yj_count,0) - ifnull(kkk.yc_count,0) ) 'normalInspectionEquipCount' , " +
" (ifnull(kkk.total_count,0) - ifnull(kkk.yj_count,0) ) 'notCheckedInspectionEquipCount' " +
" from sys_depart d ";
sql +=" left join ( select ei.depart_id ,count( eee.equip_info_id) 'total_count' ,ifnull( SUM( CASE WHEN fff.equip_info_id > '0' THEN 1 ELSE 0 END ),0) as 'yj_count',ifnull( SUM( CASE WHEN ggg.equip_info_id > '0' THEN 1 ELSE 0 END ),0) as 'yc_count'";
sql +=" from ( " + getInspectionEquipIdsSql(departIds, startDate, endDate) +") eee ";
sql += " left join ( "+ getCheckedInspectionEquipIds(departIds ,startDate, endDate,null)+" ) fff on fff.equip_info_id = eee.equip_info_id";
sql += " left join ( "+ getCheckedInspectionEquipIds(departIds ,startDate, endDate,"0")+" ) ggg on ggg.equip_info_id = eee.equip_info_id ";
sql += " left join equipment_info ei on eee.equip_info_id = ei.id ";
sql +=" group by ei.depart_id ";
sql +=" ) kkk on d.id = kkk.depart_id ";
sql +=" where d.depart_type = 1 ";
if(StringUtils.isNotEmpty(departIds)){
sql +=" and d.id in ("+JSUtils.quoteEach(departIds,",")+") ";
}
sql += " order by kkk.total_count desc ";
List<InspectionEquipIndicatorsDetailVO> dataList =getJdbcTemplate().query(sql,new BeanPropertyRowMapper<InspectionEquipIndicatorsDetailVO>(InspectionEquipIndicatorsDetailVO.class));
return dataList;
}
@Override
public List<InspectionAbnormalItemsTrendVO> getInspectionAbnormalItemsTrend(String startDate, String endDate) {
......@@ -984,7 +1006,7 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
public Map<String,Object> getInspectionEquipByStatus(String startDate, String endDate) {
Map<String,Object> map = new HashMap<>();
String departIds = BaseContextHandler.getDeparts();
//查询时间内已巡检任务信息
//查询时间内异常数量
String sql = " select ei.depart_id ,d.depart_name,d.parent_id , p.depart_name 'parent_name' ,ei.equipment_name as 'equipName',ec.des 'equipType' from (";
sql += getCheckedInspectionEquipIds(departIds ,startDate, endDate,"0");
sql += " ) ddd ";
......@@ -1032,6 +1054,7 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
sql += " and depart_id in ("+JSUtils.quoteEach(departIds,",")+")";
}
sql +=" ) AND equip_info_id IS NOT NULL AND equip_info_id <> '' ";
sql += " GROUP BY equip_info_id,inspection_point_fill_group_id,inspection_fill_group_id,inspection_task_id " ;
return sql;
}
//获取已检设备的id集合
......@@ -1048,7 +1071,7 @@ public class InspectionAnalysisServiceImpl implements IInspectionAnalysisService
sql += ")aaa on isfc.inspection_task_id = aaa.inspection_task_id and isfc.inspection_point_fill_group_id = aaa.inspection_point_fill_group_id and isfc.inspection_fill_group_id = aaa.inspection_fill_group_id ";
sql += " where isfc.fill_content IS NOT NULL AND isfc.fill_content <> '' AND aaa.equip_info_id IS NOT NULL AND aaa.equip_info_id <> '' ";
if(StringUtils.isNotEmpty(choice_state)){
sql += " AND choice_state = '0' ";
sql += " AND choice_state = '"+choice_state+"' ";
}
sql += " GROUP BY aaa.equip_info_id ";
return sql;
......
......@@ -52,13 +52,15 @@ public class InspectionEquipIndicatorsDetailVO {
public Integer getNormalInspectionEquipCount() {
normalInspectionEquipCount = 0 ;
normalInspectionEquipCount = checkedInspectionEquipCount - abnormalInspectionEquipCount;
if(checkedInspectionEquipCount != null && abnormalInspectionEquipCount != null ){
normalInspectionEquipCount = checkedInspectionEquipCount - abnormalInspectionEquipCount;
}
return normalInspectionEquipCount;
}
public String getCompletionRate() {
completionRate = "0";//完成率
if (totalInspectionEquipCount != 0) {
if ( totalInspectionEquipCount != null && totalInspectionEquipCount != 0 && checkedInspectionEquipCount != null) {
completionRate = JSUtils.divide( checkedInspectionEquipCount*100 ,totalInspectionEquipCount );
}
return completionRate;
......@@ -66,7 +68,10 @@ public class InspectionEquipIndicatorsDetailVO {
public Integer getNotCheckedInspectionEquipCount() {
notCheckedInspectionEquipCount = 0 ;
notCheckedInspectionEquipCount = totalInspectionEquipCount - checkedInspectionEquipCount;
if(totalInspectionEquipCount != null && checkedInspectionEquipCount != null){
notCheckedInspectionEquipCount = totalInspectionEquipCount - checkedInspectionEquipCount;
}
return notCheckedInspectionEquipCount;
}
......@@ -74,7 +79,7 @@ public class InspectionEquipIndicatorsDetailVO {
//未检率
unCompletionRate = "0";
//未检设备数量
if (totalInspectionEquipCount != 0) {
if (totalInspectionEquipCount != null && totalInspectionEquipCount != 0 && notCheckedInspectionEquipCount != null) {
unCompletionRate = JSUtils.divide(notCheckedInspectionEquipCount *100, totalInspectionEquipCount );
}
return unCompletionRate;
......@@ -83,7 +88,7 @@ public class InspectionEquipIndicatorsDetailVO {
public String getAbnormalRate() {
//异常率
abnormalRate = "0";
if (checkedInspectionEquipCount != 0) {
if (checkedInspectionEquipCount != null && checkedInspectionEquipCount != 0 && abnormalInspectionEquipCount != null) {
abnormalRate = JSUtils.divide(abnormalInspectionEquipCount *100, checkedInspectionEquipCount);
}
return abnormalRate;
......@@ -92,7 +97,7 @@ public class InspectionEquipIndicatorsDetailVO {
public String getProcessedAbnormalRate() {
//异常项处理率
processedAbnormalRate = "0";
if (abnormalItemsCount != 0) {
if ( abnormalItemsCount != null && abnormalItemsCount != 0 && processedAbnormalItemsCount != null ) {
processedAbnormalRate = JSUtils.divide(processedAbnormalItemsCount *100,abnormalItemsCount );
}
return processedAbnormalRate;
......@@ -101,7 +106,7 @@ public class InspectionEquipIndicatorsDetailVO {
//设备完成率
public String getFinishRate() {
finishRate = "0";//设备完成率
if (totalInspectionEquipCount != 0) {
if ( totalInspectionEquipCount != null && totalInspectionEquipCount != 0 && checkedInspectionEquipCount != null) {
finishRate = JSUtils.divide( checkedInspectionEquipCount*100 ,totalInspectionEquipCount );
}
return finishRate;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!