@@ -6,14 +6,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils ;
import com.cnbm.basic.dto.ProductFeaturesDTO ;
import com.cnbm.basic.entity.Machine ;
import com.cnbm.basic.entity.Product ;
import com.cnbm.basic.entity.Shift ;
import com.cnbm.basic.entity.WorkingProcedure ;
import com.cnbm.basic.service.impl.MachineServiceImpl ;
import com.cnbm.basic.service.impl.ProductServiceImpl ;
import com.cnbm.basic.service.impl.ShiftServiceImpl ;
import com.cnbm.basic.service.impl.WorkingProcedureServiceImpl ;
import com.cnbm.basic.dto.WorkingProcedureDTO ;
import com.cnbm.basic.entity.* ;
import com.cnbm.basic.service.impl.* ;
import com.cnbm.common.page.PageData ;
import com.cnbm.common.service.impl.CrudServiceImpl ;
import com.cnbm.common.spc.util.DataUtils ;
@@ -25,8 +20,11 @@ import com.cnbm.influx.param.Range;
import com.cnbm.influx.param.Tag ;
import com.cnbm.influx.template.Event ;
import com.cnbm.influx.template.Sample ;
import com.cnbm.influx.template.SampleParam ;
import com.cnbm.processInspection.dto.InspectionSampleDTO ;
import com.cnbm.processInspection.dto.InspectionSampleDTO2 ;
import com.cnbm.processInspection.dto.InspectionSampleDTO3 ;
import com.cnbm.processInspection.dto.InspectionSheetDTO ;
import com.cnbm.processInspection.entity.InspectionSheet ;
import com.cnbm.processInspection.mapper.InspectionSheetMapper ;
@@ -69,6 +67,10 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
@Autowired
private ShiftServiceImpl shiftService ;
@Autowired
private ProductFeaturesServiceImpl productFeaturesService ;
@Override
public QueryWrapper < InspectionSheet > getWrapper ( Map < String , Object > params ) {
Long id = ( Long ) params . get ( " id " ) ;
@@ -133,9 +135,12 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
public InspectionSheetDTO get ( Long id ) {
InspectionSheet entity = baseDao . selectById ( id ) ;
InspectionSheetDTO dto = ConvertUtils . sourceToTarget ( entity , InspectionSheetDTO . class ) ;
WorkingProcedure workingProcedure = workingProcedureService . selectById ( dto . getWorkingProcedureId ( ) ) ;
if ( w orkingProcedure! = null ) {
dto . setW orkingProcedureName ( workingProcedure. getName ( ) ) ;
if ( dto . getW orkingProcedureId ( ) ! = null ) {
WorkingProcedure w orkingProcedure = workingProcedureService . selectById ( dto . getWorkingProcedureId ( ) ) ;
if ( workingProcedure ! = null ) {
dto . setWorkingProcedureName ( workingProcedure . getName ( ) ) ;
}
}
return dto ;
}
@@ -263,7 +268,6 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
@Override
public void saveFluxParamList ( InspectionSampleDTO [ ] lists ) {
for ( InspectionSampleDTO dto : lists ) {
//String jsonData = {"workingProcedureName":"test","inspectionSheetId":"116","param1":"0.47","param2":"0.687","param2":"0.53"};
String workingProcedureName = dto . getWorkingProcedureName ( ) ;
String inspectionSheetId = dto . getInspectionSheetId ( ) ;
// String batchNum = dto.getBatchNum();
@@ -328,48 +332,47 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
//计算并更新检验单缺陷数不良数
@Override
public void calculate ( Long inspectionSheetId ) {
List < InspectionSampleDTO > sampleDTOList = getFluxParamList ( inspectionSheetId ) ;
List < InspectionSampleDTO3 > sampleDTOList = getFluxParamList3 ( inspectionSheetId ) ;
if ( sampleDTOList ! = null | | sampleDTOList . size ( ) > 0 ) {
//缺陷
Integer numberOfDefects = 0 ;
//不良
Integer defectiveQuantity = 0 ;
//获取的产品特性参照值
InspectionSheetDTO dto = get ( inspectionSheetId ) ;
Map < String , Object > params2 = new HashMap < > ( ) ;
params2 . put ( " productId " , dto . getProductId ( ) ) ;
params2 . put ( " workingProcedureId " , dto . getWorkingProcedureId ( ) ) ;
params2 . put ( " inspectionStage " , dto . getInspectionStage ( ) ) ;
List < ProductFeaturesDTO > featuresList = getInspectionSheetFeaturesList ( params2 ) ;
Long productId = get ( inspectionSheetId ) . getProductId ( ) ;
List < ProductFeaturesDTO > featuresList = productFeaturesService . getProductFeaturesByProductId ( productId ) ;
Map < String , ProductFeaturesDTO > featureMap = featuresList . stream ( ) . collect ( Collectors . groupingBy ( ProductFeaturesDTO : : getName , Collectors . collectingAndThen ( Collectors . toList ( ) , f - > f . get ( 0 ) ) ) ) ;
//循环每个样本组
for ( InspectionSampleDTO sampleDTO : sampleDTOList ) {
for ( InspectionSampleDTO3 sampleDTO : sampleDTOList ) {
//该样本的缺陷数
Integer eventDefects = 0 ;
//该样本的属性列表
String jsonData = sampleDTO . getJsonData ( ) ;
JSONObject json = JSON . parseObject ( jsonData ) ;
for ( ProductFeaturesDTO featur e : featuresList ) {
String v = ( String ) json . get ( feature . getNam e ( ) ) ;
if ( ! Objects . equals ( v , " " ) & & v ! = null ) {
List < SampleParam > sampleParamList = sampleDTO . getSampleParamList ( ) ;
for ( SampleParam sampleParam : sampleParamList ) {
String argNam e = sampleParam . getArgName ( ) ;
String argValue = sampleParam . getArgValu e ( ) ;
ProductFeaturesDTO feature = featureMap . get ( argName ) ;
//属性值非空 对应产品特性非空
if ( ! Objects . equals ( argValue , " " ) & & argValue ! = null & & feature ! = null ) {
//1 计量型; 2 计数型
if ( feature . getType ( ) = = 1 ) {
Double featureValue = Double . valueOf ( v ) ;
Double featureValue = Double . valueOf ( argValue ) ;
if ( featureValue > feature . getUsl ( ) | | featureValue < feature . getLsl ( ) ) {
eventDefects = eventDefects + 1 ;
}
}
if ( feature . getType ( ) = = 2 ) {
Integer featureValue = Integer . valueOf ( v ) ;
Double featureValue = Double . valueOf ( argValue ) ;
if ( featureValue = = 1 ) {
eventDefects = eventDefects + 1 ;
}
}
}
if ( eventDefects ! = 0 ) {
numberOfDefects = numberOfDefects + eventDefects ;
defectiveQuantity = defectiveQuantity + 1 ;
}
}
//该样本是否有缺陷
if ( eventDefects ! = 0 ) {
numberOfDefects = numberOfDefects + eventDefects ;
defectiveQuantity = defectiveQuantity + 1 ;
}
}
InspectionSheetDTO updateDto = new InspectionSheetDTO ( ) ;
@@ -378,61 +381,112 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
updateDto . setDefectiveQuantity ( defectiveQuantity ) ;
update ( updateDto ) ;
}
}
/*
//获取该检验单的所有样本数据
List<Event> eventList = getFluxParamList(inspectionSheetId);
if (eventList != null || eventList.size() > 0) {
//根据样本号分组
Map<String, List<Event>> map = eventList.stream().collect(Collectors.groupingBy(Event::getSampleNumber));
//获取的产品特性参照值
InspectionSheetDTO dto = get(inspectionSheetId);
Map<String, Object> params2 = new HashMap<>();
params2.put("productId", dto.getProductId());
params2.put("workingProcedureId", dto.getWorkingProcedureId());
params2.put("inspectionStage", dto.getInspectionStage());
//缺陷
Integer numberOfDefects = 0;
//不良
Integer defectiveQuantity = 0;
List<ProductFeaturesDTO> featuresList = getInspectionSheetFeaturesList(params2);
//循环每个样本组
for (Map.Entry<String, List<Event>> entry : map.entrySet()) {
//该样本的缺陷数
Integer eventDefects = 0;
//该样本的属性列表
List<Event> eventList1 = entry.getValue();
for (Event event : eventList1) {
String featureName = event.getArgName();
ProductFeaturesDTO feature = featuresList.stream().filter(u -> u.getName().equals(featureName)).findAny().orElse(null);
if (feature != null && !Objects.equals(event.getArgValue(), "") && event.getArgValue() != null) {
//1 计量型; 2 计数型
if (feature.getType() == 1) {
Double featureValue = Double.valueOf(event.getArgValue());
if (featureValue > feature.getUsl() || featureValue < feature.getLsl()) {
eventDefects = eventDefects + 1;
}
}
if (feature.getType() == 2) {
Integer featureValue = Integer.valueOf(event.getArgValue());
if (featureValue == 1) {
eventDefects = eventDefects + 1;
}
}
}
if (eventDefects != 0) {
numberOfDefects = numberOfDefects + eventDefects;
defectiveQuantity = defectiveQuantity + 1;
}
@Override
public void saveFluxParamList3 ( InspectionSampleDTO3 [ ] lists ) {
for ( InspectionSampleDTO3 dto : lists ) {
String inspectionSheetId = dto . getInspectionSheetId ( ) ;
Instant eventTime = dto . getSampleTime ( ) ;
String sampleNumber = dto . getSampleNumber ( ) ;
List < SampleParam > sampleParamList = dto . getSampleParamList ( ) ;
for ( SampleParam sampleParam : sampleParamList ) {
String workingProcedureName = sampleParam . getWorkingProcedureName ( ) ;
String paramName = sampleParam . getArgName ( ) ;
String paramValue = sampleParam . getArgValue ( ) ;
Event event = newEvent ( eventTime , inspectionSheetId , paramName , paramValue , sampleNumber ) ;
InfluxClient . Client . insert ( event , workingProcedureName ) ;
}
}
}
@Override
public List < InspectionSampleDTO3 > getFluxParamList3 ( Long id ) {
List < Sample > sampleList = new ArrayList < > ( ) ;
//获取influx查询参数
InspectionSheetDTO dto = get ( id ) ;
if ( dto ! = null ) {
//检验单-单一工序
if ( dto . getWorkingProcedureName ( ) ! = null ) {
String workingProcedureName = dto . getWorkingProcedureName ( ) ;
sampleList = getEventList ( id . toString ( ) , workingProcedureName ) ;
}
//检验单-所有工序
else {
List < WorkingProcedureDTO > workingProcedureDTOList = workingProcedureService . getWorkingProcedureByProductId ( dto . getProductId ( ) ) ;
for ( WorkingProcedureDTO workingProcedureDTO : workingProcedureDTOList ) {
List < Sample > sampleList1 = getEventList ( id . toString ( ) , workingProcedureDTO . getName ( ) ) ;
sampleList . addAll ( sampleList1 ) ;
}
}
InspectionSheetDTO updateDto = new InspectionSheetDTO();
updateDto.setId(inspectionSheetId);
updateDto.setNumberOfDefects(numberOfDefects);
updateDto.setDefectiveQuantity(defectiveQuantity);
update(updateDto);
}
}*/
List < InspectionSampleDTO3 > list = new ArrayList < > ( ) ;
if ( sampleList ! = null | | sampleList . size ( ) > 0 ) {
//根据样本号分组
Map < String , List < Sample > > map = sampleList . stream ( ) . collect ( Collectors . groupingBy ( Sample : : getSampleNumber ) ) ;
for ( Map . Entry < String , List < Sample > > entry : map . entrySet ( ) ) {
String sampleNumber = entry . getKey ( ) ;
List < Sample > samples = entry . getValue ( ) ;
InspectionSampleDTO3 sampleDTO = new InspectionSampleDTO3 ( ) ;
sampleDTO . setSampleNumber ( sampleNumber ) ;
sampleDTO . setSampleTime ( samples . get ( 0 ) . getSampleTime ( ) ) ;
sampleDTO . setBatchNum ( dto . getBatchNumber ( ) ) ;
sampleDTO . setInspectionSheetId ( samples . get ( 0 ) . getInspectionSheetId ( ) ) ;
List < SampleParam > sampleParamList = new ArrayList < > ( ) ;
for ( Sample sample : samples ) {
SampleParam sampleParam = new SampleParam ( ) ;
sampleParam . setArgName ( sample . getArgName ( ) ) ;
sampleParam . setArgValue ( sample . getArgValue ( ) ) ;
sampleParam . setWorkingProcedureName ( sample . getWorkingProcedureName ( ) ) ;
sampleParamList . add ( sampleParam ) ;
}
sampleDTO . setSampleParamList ( sampleParamList ) ;
list . add ( sampleDTO ) ;
}
}
//返回先按时间排序 再按样本号排序
List < InspectionSampleDTO3 > sortedList = list . stream ( )
. sorted ( Comparator . comparing ( InspectionSampleDTO3 : : getSampleTime ) . thenComparing ( InspectionSampleDTO3 : : getSampleNumber ) )
. collect ( Collectors . toList ( ) ) ;
return sortedList ;
}
private List < Sample > getEventList ( String inspectionSheetId , String workingProcedureName ) {
List < Sample > sampleList = new ArrayList < > ( ) ;
QueryDataParam queryDataParam = new QueryDataParam ( ) ;
queryDataParam . setMeasurement ( workingProcedureName ) ;
queryDataParam . setBucket ( " qgs-bucket " ) ;
queryDataParam . setTags ( Arrays . asList ( new Tag ( " inspectionSheetId " , inspectionSheetId . toString ( ) ) ) ) ;
List < String > dropNames = new ArrayList < > ( ) ;
dropNames . add ( " transationId " ) ;
queryDataParam . setDropedTagNames ( dropNames ) ;
queryDataParam . setRange ( new Range ( DataUtils . getBeforeDate ( 999 ) . toInstant ( ) , DataUtils . getAfterDate ( 999 ) . toInstant ( ) ) ) ;
queryDataParam . setPageInfo ( new PageInfo ( 1 , 10 ) ) ;
List < FluxTable > fluxTableList = InfluxClient . Client . query ( queryDataParam ) ;
for ( FluxTable fluxTable : fluxTableList ) {
List < FluxRecord > records = fluxTable . getRecords ( ) ; // 获取实际的记录操作
for ( FluxRecord fluxRecord : records ) {
Instant time = fluxRecord . getTime ( ) ;
String argName = ( String ) fluxRecord . getValueByKey ( " argName " ) ;
String argValue = ( String ) fluxRecord . getValueByKey ( " _value " ) ;
String sampleNo = ( String ) fluxRecord . getValueByKey ( " sampleNumber " ) ;
sampleList . add ( newSample ( time , inspectionSheetId , workingProcedureName , argName , argValue , sampleNo ) ) ;
}
}
return sampleList ;
}
private Sample newSample ( Instant time , String inspectionSheetId , String workingProcedureName , String argName , String argValue , String sampleNo ) {
Sample sample = new Sample ( ) ;
sample . setInspectionSheetId ( inspectionSheetId ) ;
sample . setWorkingProcedureName ( workingProcedureName ) ;
sample . setSampleTime ( time ) ;
sample . setSampleNumber ( sampleNo ) ;
sample . setArgName ( argName ) ;
sample . setArgValue ( argValue ) ;
return sample ;
}
}