@ -4,6 +4,9 @@ import cn.estsh.i3plus.ext.mes.api.base.IMesProductionRecordService;
import cn.estsh.i3plus.ext.mes.apiservice.dao.IMesProdRuleNosortCfgDao ;
import cn.estsh.i3plus.ext.mes.apiservice.utils.BeanUtil ;
import cn.estsh.i3plus.ext.mes.apiservice.utils.MesException ;
import cn.estsh.i3plus.ext.mes.pojo.model.MesLoadingListDetailModel ;
import cn.estsh.i3plus.ext.mes.pojo.model.MesShippingOrderManagementDetailModel ;
import cn.estsh.i3plus.platform.common.tool.TimeTool ;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean ;
import cn.estsh.i3plus.pojo.base.bean.ListPager ;
import cn.estsh.i3plus.pojo.base.common.Pager ;
@ -13,25 +16,34 @@ import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.util.StringUtil ;
import cn.estsh.i3plus.pojo.mes.bean.MesProdRuleNosortCfg ;
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn ;
import cn.estsh.i3plus.pojo.mes.bean.MesProductRecordLog ;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord ;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesLoadingListDetail ;
import cn.estsh.i3plus.pojo.mes.model.MesProductionRecordModel ;
import cn.estsh.i3plus.pojo.mes.model.report.MesProductAccountModel ;
import cn.estsh.i3plus.pojo.mes.model.report.MesProductAccountResModel ;
import cn.estsh.i3plus.pojo.mes.repository.MesProduceSnRepository ;
import cn.estsh.i3plus.pojo.mes.repository.MesProductRecordLogRepository ;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil ;
import com.google.common.base.Objects ;
import com.google.common.collect.Lists ;
import com.xxl.job.core.util.DateUtil ;
import lombok.extern.slf4j.Slf4j ;
import org.hibernate.SQLQuery ;
import org.hibernate.query.internal.NativeQueryImpl ;
import org.hibernate.transform.Transformers ;
import org.mvel2.util.Make ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.util.CollectionUtils ;
import org.springframework.util.StringUtils ;
import javax.persistence.EntityManager ;
import javax.persistence.Query ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.* ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
/ * *
* @Description : 设 备 加 工 记 录 表
@ -52,6 +64,9 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
@Autowired
private MesProduceSnRepository mesProduceSnRepository ;
@Autowired
private MesProductRecordLogRepository mesProductRecordLogRepository ;
@Override
public List < MesProductionRecord > findMesProductionRecord ( String organizeCode , String sn ) {
DdlPackBean packBean = DdlPackBean . getDdlPackBean ( organizeCode ) ;
@ -105,6 +120,305 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
Math . min ( pager . getPageSize ( ) * pager . getCurrentPage ( ) , mesProductionRecordModelList . size ( ) ) ) , pager ) ;
}
@Override
public ListPager < MesProductAccountResModel > queryProductAccount ( MesProductAccountModel productAccountModel , Pager pager ) {
List < MesProductAccountResModel > resList = new ArrayList < > ( ) ;
String sqlStr = "select mpr.part_no,mpr.equipment_code,mpr.equipment_name,mpr.work_cell_code,mpr.work_center_code," +
"mpr.product_count,mpr.detail_count,error_reason from (\n" +
"\n" +
"SELECT\n" +
"\tmpr.part_no ,\n" +
"\tmpr.equipment_code ,\n" +
"\tme.equipment_name ,\n" +
"\tme.work_cell_code ,\n" +
"\tme.work_center_code ,\n" +
"\tmpr.product_count ,\n" +
"\tmpr.detail_count , \n" +
"\t null error_reason\n" +
"\t\n" +
"FROM\n" +
"\t(\n" +
"\tSELECT\n" +
"\t\tequipment_code,\n" +
"\t\tpart_no,\n" +
"\t\tsum( CASE WHEN type = 'record' THEN 1 ELSE 0 END ) product_count,\n" +
"\t\tsum( CASE WHEN type = 'logdetail' THEN 1 ELSE 0 END ) detail_count \n" +
"\tFROM\n" +
"\t\tmes_product_record_log \n" +
"\tWHERE\n" +
"\t\tequipment_code LIKE '%HT%' \n" ;
if ( ! StringUtils . isEmpty ( productAccountModel . getEquipmentCode ( ) ) ) {
sqlStr + = " and equipment_code = :equipmentCode " ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getPartNo ( ) ) ) {
sqlStr + = " and part_no=:partNo " ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getStartTime ( ) ) ) {
sqlStr + = " and create_date_time >= :startTime " ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getEndTime ( ) ) ) {
sqlStr + = " and create_date_time < :endTime " ;
}
sqlStr + =
"\t\tAND part_no IS NOT NULL \n" +
"\tGROUP BY\n" +
"\t\tequipment_code,\n" +
"\t\tpart_no \n" +
"\t) mpr\n" +
"\tLEFT JOIN mes_wc_equipment me ON mpr.equipment_code = me.equipment_code \n" +
"\n" +
"\n" +
"UNION\n" +
"SELECT\n" +
"\tmprnc.out_part_no part_no,\n" +
"\tmprnc.equipment_code ,\n" +
"\tme.equipment_name ,\n" +
"\tme.work_cell_code ,\n" +
"\tme.work_center_code ,\n" +
"\teqcount.product_count ,\n" +
"\teqcount.detail_count , \n" +
"\t null error_reason \n" +
"FROM\n" +
"\tmes_prod_rule_nosort_cfg mprnc\n" +
"\tLEFT JOIN mes_wc_equipment me ON mprnc.equipment_code = me.equipment_code and me.is_deleted = 2 and me.is_valid = 1 \n" +
"\tLEFT JOIN (\n" +
"\tSELECT\n" +
"\t\tequipment_code,\n" +
"\t\tpart_no,\n" +
"\t\tsum( CASE WHEN type = 'record' THEN 1 ELSE 0 END ) product_count,\n" +
"\t\tsum(\n" +
"\t\tCASE\n" +
"\t\t\t\t\n" +
"\t\t\t\tWHEN type = 'logdetail' \n" +
"\t\t\t\tAND CATEGORY_LEVEL_TWO IN ( 'Product_finish', 'PART_OK', 'Part_Finish', 'Product_OK' ) \n" +
"\t\t\t\tAND EQUIP_VARIABLE_VALUE = 'True' THEN\n" +
"\t\t\t\t\t1 ELSE 0 \n" +
"\t\t\t\tEND \n" +
"\t\t\t\t) detail_count \n" +
"\t\t\tFROM\n" +
"\t\t\t\tmes_product_record_log \n" +
"\t\t\tWHERE 1 = 1 \n" ;
if ( ! StringUtils . isEmpty ( productAccountModel . getEquipmentCode ( ) ) ) {
sqlStr + = "\t\t\t and equipment_code = :equipmentCode \n" ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getPartNo ( ) ) ) {
sqlStr + = "\t\t\t and part_no= :partNo \n" ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getStartTime ( ) ) ) {
sqlStr + = "\t\t\t and create_date_time >= :startTime \n" ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getEndTime ( ) ) ) {
sqlStr + = "\t\t\t and create_date_time < :endTime \n" ;
}
sqlStr + =
"\t\t\t and \n" +
"\t\t\t\tpart_no IS NOT NULL \n" +
"\t\t\tGROUP BY\n" +
"\t\t\t\tequipment_code,\n" +
"\t\t\t\tpart_no \n" +
"\t\t\t) eqcount ON mprnc.equipment_code = eqcount.equipment_code \n" +
"\t AND mprnc.out_part_no = eqcount.part_no where 1=1 " ;
if ( ! StringUtils . isEmpty ( productAccountModel . getEquipmentCode ( ) ) ) {
sqlStr + = "and mprnc.equipment_code= :equipmentCode " ;
}
sqlStr + = "\tand eqcount.product_count is not null and eqcount.detail_count is not null ) mpr \n" +
"\t\n" +
"\tleft join mes_equipment me\n" +
"\ton mpr.equipment_code = me.equipment_code\n" +
"\n" +
"where mpr.product_count != 0 and mpr.detail_count != 0\n" +
"and me.equipment_type = 10" ;
Query query = entityManager . createNativeQuery ( sqlStr ) ;
if ( ! StringUtils . isEmpty ( productAccountModel . getEquipmentCode ( ) ) ) {
query . setParameter ( "equipmentCode" , productAccountModel . getEquipmentCode ( ) ) ;
}
if ( ! StringUtils . isEmpty ( productAccountModel . getPartNo ( ) ) ) {
query . setParameter ( "partNo" , productAccountModel . getPartNo ( ) ) ;
}
if ( ! StringUtils . isEmpty ( productAccountModel . getStartTime ( ) ) ) {
query . setParameter ( "startTime" , productAccountModel . getStartTime ( ) ) ;
}
if ( ! StringUtils . isEmpty ( productAccountModel . getEndTime ( ) ) ) {
query . setParameter ( "endTime" , productAccountModel . getEndTime ( ) ) ;
}
/ * query . unwrap ( NativeQueryImpl . class ) . setResultTransformer ( Transformers . aliasToBean ( MesProductAccountResModel . class ) ) ;
List < MesProductAccountResModel > results = query . getResultList ( ) ; * /
List results = query . getResultList ( ) ;
for ( Object result : results ) {
Object [ ] cells = ( Object [ ] ) result ;
MesProductAccountResModel model = new MesProductAccountResModel ( ) ;
model . setPartNo ( StringUtils . isEmpty ( cells [ 0 ] ) ? "" : String . valueOf ( cells [ 0 ] ) ) ;
model . setEquipmentCode ( StringUtils . isEmpty ( cells [ 1 ] ) ? "" : String . valueOf ( cells [ 1 ] ) ) ;
model . setWorkCellCode ( StringUtils . isEmpty ( cells [ 3 ] ) ? "" : String . valueOf ( cells [ 3 ] ) ) ;
model . setWorkCenterCode ( StringUtils . isEmpty ( cells [ 4 ] ) ? "" : String . valueOf ( cells [ 4 ] ) ) ;
model . setProductCount ( StringUtils . isEmpty ( cells [ 5 ] ) ? "" : String . valueOf ( cells [ 5 ] ) ) ;
model . setDetailCount ( StringUtils . isEmpty ( cells [ 6 ] ) ? "" : String . valueOf ( cells [ 6 ] ) ) ;
model . setErrorReason ( StringUtils . isEmpty ( cells [ 7 ] ) ? "" : String . valueOf ( cells [ 7 ] ) ) ;
resList . add ( model ) ;
}
//query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.aliasToBean(MesProductAccountResModel.class));
//List<MesProductAccountResModel> results = query.getResultList();
return new ListPager < > ( resList , pager ) ;
}
@Override
public List < MesProductAccountResModel > queryProductAccount ( MesProductAccountModel productAccountModel ) {
List < MesProductAccountResModel > resList = new ArrayList < > ( ) ;
String sqlStr = "select mpr.part_no,mpr.equipment_code,mpr.equipment_name,mpr.work_cell_code,mpr.work_center_code," +
"mpr.product_count,mpr.detail_count,error_reason from (\n" +
"\n" +
"SELECT\n" +
"\tmpr.part_no ,\n" +
"\tmpr.equipment_code ,\n" +
"\tme.equipment_name ,\n" +
"\tme.work_cell_code ,\n" +
"\tme.work_center_code ,\n" +
"\tmpr.product_count ,\n" +
"\tmpr.detail_count , \n" +
"\t null error_reason\n" +
"\t\n" +
"FROM\n" +
"\t(\n" +
"\tSELECT\n" +
"\t\tequipment_code,\n" +
"\t\tpart_no,\n" +
"\t\tsum( CASE WHEN type = 'record' THEN 1 ELSE 0 END ) product_count,\n" +
"\t\tsum( CASE WHEN type = 'logdetail' and CATEGORY_LEVEL_TWO ='shot_counter' and EQUIP_VARIABLE_VALUE > 0 THEN 1 ELSE 0 END ) detail_count \n" +
"\tFROM\n" +
"\t\tmes_product_record_log \n" +
"\tWHERE\n" +
"\t\tequipment_code LIKE '%HT%' \n" ;
if ( ! StringUtils . isEmpty ( productAccountModel . getEquipmentCode ( ) ) ) {
sqlStr + = " and equipment_code = :equipmentCode " ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getPartNo ( ) ) ) {
sqlStr + = " and part_no like '%' :partNo '%' " ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getStartTime ( ) ) ) {
sqlStr + = " and create_date_time >= :startTime " ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getEndTime ( ) ) ) {
sqlStr + = " and create_date_time < :endTime " ;
}
sqlStr + =
"\t\tAND part_no IS NOT NULL \n" +
"\tGROUP BY\n" +
"\t\tequipment_code,\n" +
"\t\tpart_no \n" +
"\t) mpr\n" +
"\tLEFT JOIN mes_wc_equipment me ON mpr.equipment_code = me.equipment_code \n" +
"\n" +
"\n" +
"UNION\n" +
"SELECT\n" +
"\teqcount.part_no,\n" +
"\teqcount.equipment_code ,\n" +
"\tme.equipment_name ,\n" +
"\tme.work_cell_code ,\n" +
"\tme.work_center_code ,\n" +
"\teqcount.product_count ,\n" +
"\teqcount.detail_count , \n" +
"\t null error_reason \n" +
"FROM\n" +
"\tmes_prod_rule_nosort_cfg mprnc\n" +
"\tRIGHT JOIN mes_wc_equipment me ON mprnc.equipment_code = me.equipment_code and me.is_deleted = 2 and me.is_valid = 1 \n" +
"\tRIGHT JOIN (\n" +
"\tSELECT\n" +
"\t\tequipment_code,\n" +
"\t\tpart_no,\n" +
"\t\tsum( CASE WHEN type = 'record' THEN 1 ELSE 0 END ) product_count,\n" +
"\t\tsum(\n" +
"\t\tCASE\n" +
"\t\t\t\t\n" +
"\t\t\t\tWHEN type = 'logdetail' \n" +
"AND ( (equipment_code != 'Geiss' and CATEGORY_LEVEL_TWO IN ( 'Product_finish', 'PART_OK', 'Part_Finish', 'Product_OK' ) )\n" +
"\t\t\t\tor (equipment_code = 'Geiss' and CATEGORY_LEVEL_TWO = 'Product_finish') )\n" +
"\t\t\t\tAND EQUIP_VARIABLE_VALUE = 'True' THEN\n" +
"\t\t\t\t\t1 ELSE 0 \n" +
"\t\t\t\tEND" +
"\t\t\t\t) detail_count \n" +
"\t\t\tFROM\n" +
"\t\t\t\tmes_product_record_log \n" +
"\t\t\tWHERE 1 = 1 and equipment_code not like '%HT%' \n" ;
if ( ! StringUtils . isEmpty ( productAccountModel . getEquipmentCode ( ) ) ) {
sqlStr + = "\t\t\t and equipment_code = :equipmentCode \n" ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getPartNo ( ) ) ) {
sqlStr + = " and part_no like '%' :partNo '%' " ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getStartTime ( ) ) ) {
sqlStr + = "\t\t\t and create_date_time >= :startTime \n" ;
} if ( ! StringUtils . isEmpty ( productAccountModel . getEndTime ( ) ) ) {
sqlStr + = "\t\t\t and create_date_time < :endTime \n" ;
}
sqlStr + =
"\t\t\t and \n" +
"\t\t\t\tpart_no IS NOT NULL \n" +
"\t\t\tGROUP BY\n" +
"\t\t\t\tequipment_code,\n" +
"\t\t\t\tpart_no \n" +
"\t\t\t) eqcount ON mprnc.equipment_code = eqcount.equipment_code \n" +
"\t AND mprnc.out_part_no = eqcount.part_no where eqcount.equipment_code not LIKE '%HT%' " ;
if ( ! StringUtils . isEmpty ( productAccountModel . getEquipmentCode ( ) ) ) {
sqlStr + = "and eqcount.equipment_code= :equipmentCode " ;
}
sqlStr + = "\tand eqcount.product_count is not null and eqcount.detail_count is not null ) mpr \n" +
"\t\n" +
"\tleft join mes_equipment me\n" +
"\ton mpr.equipment_code = me.equipment_code\n" +
"\n" +
"where (mpr.product_count != 0 or mpr.detail_count != 0)\n" +
"and me.equipment_type = 10 order by me.equipment_code asc" ;
Query query = entityManager . createNativeQuery ( sqlStr ) ;
if ( ! StringUtils . isEmpty ( productAccountModel . getEquipmentCode ( ) ) ) {
query . setParameter ( "equipmentCode" , productAccountModel . getEquipmentCode ( ) ) ;
}
if ( ! StringUtils . isEmpty ( productAccountModel . getPartNo ( ) ) ) {
query . setParameter ( "partNo" , productAccountModel . getPartNo ( ) ) ;
}
if ( ! StringUtils . isEmpty ( productAccountModel . getStartTime ( ) ) ) {
query . setParameter ( "startTime" , productAccountModel . getStartTime ( ) ) ;
}
if ( ! StringUtils . isEmpty ( productAccountModel . getEndTime ( ) ) ) {
query . setParameter ( "endTime" , productAccountModel . getEndTime ( ) ) ;
}
/ * query . unwrap ( NativeQueryImpl . class ) . setResultTransformer ( Transformers . aliasToBean ( MesProductAccountResModel . class ) ) ;
List < MesProductAccountResModel > results = query . getResultList ( ) ; * /
List results = query . getResultList ( ) ;
for ( Object result : results ) {
Object [ ] cells = ( Object [ ] ) result ;
MesProductAccountResModel model = new MesProductAccountResModel ( ) ;
model . setPartNo ( StringUtils . isEmpty ( cells [ 0 ] ) ? "" : String . valueOf ( cells [ 0 ] ) ) ;
model . setEquipmentCode ( StringUtils . isEmpty ( cells [ 1 ] ) ? "" : String . valueOf ( cells [ 1 ] ) ) ;
model . setEquipmentName ( StringUtils . isEmpty ( cells [ 2 ] ) ? "" : String . valueOf ( cells [ 2 ] ) ) ;
model . setWorkCellCode ( StringUtils . isEmpty ( cells [ 3 ] ) ? "" : String . valueOf ( cells [ 3 ] ) ) ;
model . setWorkCenterCode ( StringUtils . isEmpty ( cells [ 4 ] ) ? "" : String . valueOf ( cells [ 4 ] ) ) ;
model . setProductCount ( StringUtils . isEmpty ( cells [ 5 ] ) ? "" : String . valueOf ( cells [ 5 ] ) ) ;
model . setDetailCount ( StringUtils . isEmpty ( cells [ 6 ] ) ? "" : String . valueOf ( cells [ 6 ] ) ) ;
model . setErrorReason ( StringUtils . isEmpty ( cells [ 7 ] ) ? "" : String . valueOf ( cells [ 7 ] ) ) ;
resList . add ( model ) ;
}
//query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.aliasToBean(MesProductAccountResModel.class));
//List<MesProductAccountResModel> results = query.getResultList();
return resList ;
}
private List < MesProduceSn > getMesProduceSnList ( MesProductionRecordModel mesProductionRecordModel ) {
DdlPackBean packBean = DdlPackBean . getDdlPackBean ( mesProductionRecordModel . getOrganizeCode ( ) ) ;
DdlPreparedPack . getStringEqualPack ( mesProductionRecordModel . getPartNo ( ) , "partNo" , packBean ) ;
@ -215,4 +529,405 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
}
@Override
public List < MesProductAccountResModel > transferAccount ( List < MesProductAccountResModel > mesProductAccountResModels , MesProductAccountModel productAccountModel , Pager pager ) {
/ * *
* 760 B_A58_ReMaoHan 只 有 finish 信 号
* 760 BFoaming
* 760 B_LaserCutting
* ZhenKong
* /
List < String > equimentList = Stream . of ( "760B_A58_ReMaoHan" , "760BFoaming" , "760B_LaserCutting" , "ZhenKong" ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( mesProductAccountResModels ) ) {
return null ;
}
List < MesProductAccountResModel > partitionList = partition ( mesProductAccountResModels , pager . getPageSize ( ) , pager . getCurrentPage ( ) ) ;
for ( MesProductAccountResModel mesProductAccountResModel : partitionList ) {
boolean isErrorCount = false ;
int size = mesProductAccountResModel . getPartNo ( ) . split ( "," ) . length = = 1 ? mesProductAccountResModel . getPartNo ( ) . split ( ";" ) . length : mesProductAccountResModel . getPartNo ( ) . split ( "," ) . length ;
int productCount = Integer . valueOf ( mesProductAccountResModel . getProductCount ( ) ) ;
int detailCount = Integer . valueOf ( mesProductAccountResModel . getDetailCount ( ) ) ;
if ( detailCount * size > productCount ) {
isErrorCount = true ;
}
if ( ! isErrorCount ) {
continue ;
}
DdlPackBean packBean = DdlPackBean . getDdlPackBean ( "CK01" ) ;
DdlPreparedPack . getStringEqualPack ( mesProductAccountResModel . getEquipmentCode ( ) , "equipmentCode" , packBean ) ;
DdlPreparedPack . getStringSmallerNotEqualPack ( productAccountModel . getEndTime ( ) , "createDatetime" , packBean ) ;
DdlPreparedPack . getStringBiggerPack ( productAccountModel . getStartTime ( ) , "createDatetime" , packBean ) ;
DdlPreparedPack . getStringEqualPack ( mesProductAccountResModel . getPartNo ( ) , "partNo" , packBean ) ;
DdlPreparedPack . getOrderBy ( "createDatetime" , CommonEnumUtil . ASC_OR_DESC . ASC . getValue ( ) , packBean ) ;
List < MesProductRecordLog > recordLogs = mesProductRecordLogRepository . findByHqlWhere ( packBean ) ;
//
DdlPackBean packOffilinBean = DdlPackBean . getDdlPackBean ( "CK01" ) ;
DdlPreparedPack . getStringEqualPack ( mesProductAccountResModel . getEquipmentCode ( ) , "equipmentCode" , packOffilinBean ) ;
Date yesterday = TimeTool . getDateBefore ( DateUtil . parseDateTime ( productAccountModel . getStartTime ( ) ) , 1 ) ;
String yesterdayStr = DateUtil . formatDateTime ( yesterday ) ;
DdlPreparedPack . getStringSmallerNotEqualPack ( productAccountModel . getStartTime ( ) , "createDatetime" , packOffilinBean ) ;
DdlPreparedPack . getStringBiggerPack ( yesterdayStr , "createDatetime" , packOffilinBean ) ;
DdlPreparedPack . getStringEqualPack ( mesProductAccountResModel . getPartNo ( ) , "partNo" , packOffilinBean ) ;
DdlPreparedPack . getStringLikerPack ( "客户端" , "message" , packOffilinBean ) ;
DdlPreparedPack . getOrderBy ( "createDatetime" , CommonEnumUtil . ASC_OR_DESC . ASC . getValue ( ) , packOffilinBean ) ;
List < MesProductRecordLog > offlineRecordLogs = mesProductRecordLogRepository . findByHqlWhere ( packOffilinBean ) ;
recordLogs . addAll ( offlineRecordLogs ) ;
recordLogs = recordLogs . stream ( ) . sorted ( Comparator . comparing ( MesProductRecordLog : : getCreateDatetime ) ) . collect ( Collectors . toList ( ) ) ;
if ( mesProductAccountResModel . getEquipmentCode ( ) . contains ( "HT" ) ) {
// 1 判断2个 shotcount之间有没有加工记录, 如果没有, 就需要看 设备是不是192, 然后看是否是网络原因
String reason = handleHT ( recordLogs ) ;
mesProductAccountResModel . setErrorReason ( reason ) ;
} else if ( equimentList . contains ( mesProductAccountResModel . getEquipmentCode ( ) ) ) {
// 1 判断2个 shotcount之间有没有加工记录, 如果没有, 就需要看 设备是不是192, 然后看是否是网络原因
String reason = handleNotHT ( recordLogs ) ;
mesProductAccountResModel . setErrorReason ( reason ) ;
} else {
String reason = handleNotHTAndHasRelease ( recordLogs ) ;
mesProductAccountResModel . setErrorReason ( reason ) ;
}
}
return partitionList ;
}
private String handleNotHT ( List < MesProductRecordLog > recordLogs ) {
int result = 0 ;
String startTime = "" ;
String endTime = "" ;
String reason = "" ;
String offlineReason = "【%s】到【%s】,客户端下线,导致【%s】个完成信号丢失" ;
String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失;" ;
String reasonQuality = "【%s】设备信号质量为0, 导致【%s】个完成信号丢失;" ;
String reasonBypass = "【%s】的完成信号,设备打BYPASS,视为无效;" ;
// BYPASS 默认fasle
boolean bypassFlag = false ;
boolean offlineFlag = false ;
List < String > finishList = Stream . of ( "Product_finish" , "Part_Finish" ) . collect ( Collectors . toList ( ) ) ;
for ( MesProductRecordLog recordLog : recordLogs ) {
int errorCount = 0 ;
/ * if ( recordLog . getId ( ) = = 1834566428726444032l ) {
int a = 1 ;
} * /
if ( Objects . equal ( recordLog . getType ( ) , "monitor" ) & & recordLog . getMessage ( ) . contains ( "客户端下线" ) ) {
startTime = recordLog . getCreateDatetime ( ) ;
offlineFlag = true ;
continue ;
}
if ( Objects . equal ( recordLog . getType ( ) , "monitor" ) & & recordLog . getMessage ( ) . contains ( "客户端上线" ) ) {
endTime = recordLog . getCreateDatetime ( ) ;
offlineFlag = false ;
if ( errorCount > 0 ) {
reason + = String . format ( offlineReason , startTime , endTime , errorCount + "" ) ;
errorCount = 0 ;
}
//result = 0;
continue ;
}
if ( offlineFlag & & finishList . contains ( recordLog . getCategoryLevelTwo ( ) ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
if ( result > 0 ) {
//endTime = recordLog.getCreateDatetime();
errorCount + + ;
reason + = String . format ( offlineReason , startTime , startTime , errorCount + "" ) ;
continue ;
}
errorCount + + ;
result + + ;
continue ;
}
if ( Objects . equal ( recordLog . getCategoryLevelTwo ( ) , "BYPASS" ) ) {
if ( Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
if ( StringUtils . isEmpty ( startTime ) ) {
startTime = recordLog . getCreateDatetime ( ) ;
}
endTime = recordLog . getCreateDatetime ( ) ;
// 每次都取反,第一次是打开,那第二次就是关闭了
bypassFlag = true ;
continue ;
} else {
if ( bypassFlag ) {
bypassFlag = false ;
errorCount = 0 ;
continue ;
}
}
}
if ( bypassFlag & & recordLog . getType ( ) . equals ( "record" ) ) {
errorCount + + ;
reason + = String . format ( reasonBypass , startTime , errorCount + "" ) ;
continue ;
}
if ( result = = 0 ) {
if ( ! finishList . contains ( recordLog . getCategoryLevelTwo ( ) ) | | ! Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
continue ;
}
startTime = recordLog . getCreateDatetime ( ) ;
result + + ;
} else {
if ( finishList . contains ( recordLog . getCategoryLevelTwo ( ) ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
errorCount + + ;
if ( Objects . equal ( recordLog . getQuality ( ) , "192" ) ) {
reason + = String . format ( reasonOffline , startTime , errorCount + "" ) ;
} else {
reason + = String . format ( reasonQuality , startTime , errorCount + "" ) ;
}
startTime = recordLog . getCreateDatetime ( ) ;
}
if ( recordLog . getType ( ) . equals ( "record" ) ) {
result - - ;
}
}
}
return reason ;
}
private String handleNotHTAndHasRelease ( List < MesProductRecordLog > recordLogs ) {
int result = 0 ;
// 定义有问题的开始时间
String startTime = "" ;
// 定义有问题的结束时间
String endTime = "" ;
// 错误个数
// 异常原因
String reason = "" ;
String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失;" ;
String offlineReason = "【%s】到【%s】,客户端下线,导致【%s】个完成信号丢失;" ;
String reasonQuality = "【%s】设备信号质量为0, 视为无效;" ;
String reasonBypass = "【%s】的完成信号,设备打BYPASS,视为无效;" ;
String releaseBypass = "【%s】的完成信号,未发送Release信号,视为无效;" ;
// BYPASS 默认fasle
boolean bypassFlag = false ;
// release 默认false
boolean releaseFlag = false ;
// BYPASS 默认fasle
boolean offlineFlag = false ;
//List<String> finishList = Stream.of("Product_finish","PART_OK","Part_Finish","Product_OK").collect(Collectors.toList());
List < String > finishList = Stream . of ( "Product_finish" , "Part_Finish" ) . collect ( Collectors . toList ( ) ) ;
String preReason = "" ;
for ( MesProductRecordLog recordLog : recordLogs ) {
int errorCount = 0 ;
if ( recordLog . getId ( ) = = 1288411771211612170l ) {
int a = 1 ;
}
if ( Objects . equal ( recordLog . getType ( ) , "monitor" ) & & recordLog . getMessage ( ) . contains ( "客户端下线" ) ) {
startTime = recordLog . getCreateDatetime ( ) ;
offlineFlag = true ;
continue ;
}
if ( Objects . equal ( recordLog . getType ( ) , "monitor" ) & & recordLog . getMessage ( ) . contains ( "客户端上线" ) ) {
endTime = recordLog . getCreateDatetime ( ) ;
offlineFlag = false ;
if ( result > 0 ) {
reason + = String . format ( offlineReason , startTime , endTime , 1 + "" ) ;
errorCount = 0 ;
}
//result = 0;
continue ;
}
// 如果是bypass 遇到的所有加工完成指令 都计数并且原因是bypass导致
if ( bypassFlag & & finishList . contains ( recordLog . getCategoryLevelTwo ( ) ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
if ( ! StringUtils . isEmpty ( preReason ) ) {
reason + = preReason ;
}
preReason = String . format ( reasonBypass , startTime , 1 + "" ) ;
//reason += String.format(reasonBypass,startTime, 1 +"");
continue ;
}
if ( offlineFlag & & finishList . contains ( recordLog . getCategoryLevelTwo ( ) ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
// 如果经过了1个finish, 然后再经过客户端下线, 再遇到finish则认为是客户端下线引起
if ( result > 0 ) {
//endTime = recordLog.getCreateDatetime();
errorCount + + ;
reason + = String . format ( offlineReason , startTime , startTime , errorCount + "" ) ;
continue ;
}
errorCount + + ;
result + + ;
continue ;
}
if ( Objects . equal ( recordLog . getCategoryLevelTwo ( ) , "BYPASS" ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
startTime = recordLog . getCreateDatetime ( ) ;
endTime = recordLog . getCreateDatetime ( ) ;
bypassFlag = true ;
continue ;
}
// 遇到bypass = false 则重置错误次数
if ( bypassFlag & & Objects . equal ( recordLog . getCategoryLevelTwo ( ) , "BYPASS" ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "False" ) ) {
endTime = recordLog . getCreateDatetime ( ) ;
errorCount = 0 ;
bypassFlag = false ;
continue ;
}
// 如果没有发送release 就出现了加工完成信号,则记录错误原因,且预错误,遇到有加工记录则取消
/ * *
* 没 有 release 有 完 成 信 号 需 要 预 处 理 , 先 得 出 一 个 结 论 : 如 果 没 有 发 送 release 指 令 , 导 致 信 号 丢 失
* 后 面 如 果 没 有 加 工 记 录 , 则 预 处 理 结 果 变 成 实 际 结 果
* 后 面 有 加 工 记 录 则 预 处 理 结 果 清 空
* /
if ( ! releaseFlag ) {
if ( finishList . contains ( recordLog . getCategoryLevelTwo ( ) ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
if ( ! StringUtils . isEmpty ( preReason ) ) {
reason + = preReason ;
}
startTime = recordLog . getCreateDatetime ( ) ;
errorCount + + ;
preReason = String . format ( releaseBypass , startTime , errorCount + "" ) ;
continue ;
}
}
// BYPASS 逻辑结束 result = 1 代表一个成功新型号,遇到一个加工记录就会-1 变成0
if ( result = = 0 ) {
// 没有加工完成指令, 或者没有release指令, 但是有加工记录, 则也需要重置
if ( recordLog . getType ( ) . equals ( "record" ) ) {
releaseFlag = false ;
bypassFlag = false ;
preReason = "" ;
}
if ( Objects . equal ( recordLog . getCategoryLevelTwo ( ) , "Work_Allow" ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
releaseFlag = true ;
continue ;
}
if ( ! finishList . contains ( recordLog . getCategoryLevelTwo ( ) ) | | ! Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
continue ;
}
if ( ! releaseFlag ) {
reason + = preReason ;
startTime = recordLog . getCreateDatetime ( ) ;
preReason = String . format ( releaseBypass , startTime , 1 + "" ) ;
result + + ;
continue ;
} if ( ! StringUtils . isEmpty ( preReason ) ) {
reason + = preReason ;
}
result + + ;
startTime = recordLog . getCreateDatetime ( ) ;
} else {
if ( finishList . contains ( recordLog . getCategoryLevelTwo ( ) ) & & Objects . equal ( recordLog . getEquipVariableValue ( ) , "True" ) ) {
// 上一个加工记录信号还没走完, 这边又继续发一个加工记录, 且没有release 两个都要判定问题
if ( ! releaseFlag ) {
startTime = recordLog . getCreateDatetime ( ) ;
reason + = String . format ( releaseBypass , startTime , 1 + "" ) ;
} else {
if ( Objects . equal ( recordLog . getQuality ( ) , "192" ) ) {
reason + = String . format ( reasonOffline , startTime , 1 + "" ) ;
} else {
reason + = String . format ( reasonQuality , startTime , 1 + "" ) ;
}
}
}
if ( recordLog . getType ( ) . equals ( "record" ) ) {
releaseFlag = false ;
bypassFlag = false ;
offlineFlag = false ;
result - - ;
preReason = "" ;
startTime = "" ;
errorCount = 0 ;
}
}
}
// 如果走到最后,还有预编译的错误,则直接加上
if ( ! StringUtils . isEmpty ( preReason ) ) {
reason + = preReason ;
}
return reason ;
}
private String handleHT ( List < MesProductRecordLog > recordLogs ) {
int result = 0 ;
String startTime = "" ;
String endTime = "" ;
String reason = "" ;
String offlineReason = "【%s】到【%s】,客户端下线,导致【%s】个完成信号丢失" ;
String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失;" ;
String reasonQuality = "【%s】设备信号质量为0, 导致完成信号丢失;" ;
boolean offlineFlag = false ;
int errorCount = 0 ;
for ( MesProductRecordLog recordLog : recordLogs ) {
if ( recordLog . getId ( ) = = 1284126441587343426l ) {
int i = 1 ;
}
if ( Objects . equal ( recordLog . getType ( ) , "monitor" ) & & recordLog . getMessage ( ) . contains ( "客户端下线" ) ) {
startTime = recordLog . getCreateDatetime ( ) ;
offlineFlag = true ;
continue ;
}
if ( Objects . equal ( recordLog . getType ( ) , "monitor" ) & & recordLog . getMessage ( ) . contains ( "客户端上线" ) & & offlineFlag ) {
endTime = recordLog . getCreateDatetime ( ) ;
offlineFlag = false ;
if ( errorCount > 0 ) {
reason + = String . format ( offlineReason , startTime , endTime , errorCount + "" ) ;
errorCount = 0 ;
}
continue ;
}
if ( offlineFlag & & Objects . equal ( recordLog . getCategoryLevelTwo ( ) , "shot_counter" ) & & recordLog . getEquipVariableValue ( ) . compareTo ( "0" ) > 0 ) {
errorCount + + ;
continue ;
}
if ( result = = 0 ) {
if ( ! Objects . equal ( recordLog . getCategoryLevelTwo ( ) , "shot_counter" ) ) {
continue ;
}
if ( recordLog . getEquipVariableValue ( ) . compareTo ( "0" ) > 0 ) {
result + + ;
}
} else {
if ( Objects . equal ( recordLog . getCategoryLevelTwo ( ) , "shot_counter" ) & & recordLog . getEquipVariableValue ( ) . compareTo ( "0" ) > 0 ) {
startTime = recordLog . getCreateDatetime ( ) ;
endTime = recordLog . getCreateDatetime ( ) ;
if ( Objects . equal ( recordLog . getQuality ( ) , "192" ) ) {
reason + = String . format ( reasonOffline , startTime , 1 + "" ) ;
} else {
reason + = String . format ( reasonQuality , startTime , 1 + "" ) ;
}
}
if ( recordLog . getType ( ) . equals ( "record" ) ) {
result - - ;
}
}
}
if ( errorCount > 0 & & offlineFlag ) {
reason + = String . format ( offlineReason , startTime , "最后" , errorCount + "" ) ;
}
return reason ;
}
private List < MesProductAccountResModel > partition ( List < MesProductAccountResModel > list , int pageSize , int pageNum ) {
// 将 List 按照 PageSzie 拆分成多个List
List < List < MesProductAccountResModel > > partition = Lists . partition ( list , pageSize ) ;
// 总页数
int pages = partition . size ( ) ;
pageNum = pageNum - 1 ;
pageNum = pageNum < = 0 ? 0 : ( pageNum < = ( pages - 1 ) ? pageNum : ( pages - 1 ) ) ;
return partition . get ( pageNum ) ;
}
}