|
|
@@ -33,6 +33,7 @@ import com.google.gson.JsonObject; |
|
|
|
import com.influxdb.query.FluxRecord; |
|
|
|
import com.influxdb.query.FluxTable; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@@ -140,13 +141,22 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(InspectionSheetDTO dto) { |
|
|
|
public InspectionSheet saveSheet(InspectionSheetDTO dto) { |
|
|
|
// 验证是否有检验参数 |
|
|
|
Map<String, Object> params = new HashMap<String, Object>(); |
|
|
|
params.put("productId", dto.getProductId()); |
|
|
|
params.put("workingProcedureId", dto.getWorkingProcedureId()); |
|
|
|
params.put("inspectionStage", dto.getInspectionStage()); |
|
|
|
List<ProductFeaturesDTO> inspectionSheetFeaturesList = getInspectionSheetFeaturesList(params); |
|
|
|
if (inspectionSheetFeaturesList != null && inspectionSheetFeaturesList.size() != 0) { |
|
|
|
//分组样本数=样本大小=检验特性分组数的最大值 |
|
|
|
Integer numbersOfSamples = inspectionSheetFeaturesList.stream().max(Comparator.comparing(ProductFeaturesDTO::getSampleSize)).get().getSampleSize(); |
|
|
|
if (numbersOfSamples != null) { |
|
|
|
dto.setNumberOfGroupedSamples(numbersOfSamples); |
|
|
|
dto.setNumberOfSamples(numbersOfSamples); |
|
|
|
} |
|
|
|
} |
|
|
|
/* |
|
|
|
if (inspectionSheetFeaturesList == null || inspectionSheetFeaturesList.size() == 0) { |
|
|
|
throw new RuntimeException("没有发现检验参数"); |
|
|
|
} else { |
|
|
@@ -157,8 +167,11 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM |
|
|
|
dto.setNumberOfSamples(numbersOfSamples); |
|
|
|
} |
|
|
|
} |
|
|
|
InspectionSheet entity = ConvertUtils.sourceToTarget(dto, InspectionSheet.class); |
|
|
|
insert(entity); |
|
|
|
*/ |
|
|
|
//InspectionSheet entity = ConvertUtils.sourceToTarget(dto, InspectionSheet.class); |
|
|
|
InspectionSheet entity = new InspectionSheet(); |
|
|
|
BeanUtils.copyProperties(dto, entity); |
|
|
|
return entity; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -210,9 +223,8 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM |
|
|
|
Instant time = fluxRecord.getTime(); |
|
|
|
String argName = (String) fluxRecord.getValueByKey("argName"); |
|
|
|
String argValue = (String)fluxRecord.getValueByKey("_value"); |
|
|
|
String batchNum = (String) fluxRecord.getValueByKey("batchNum"); |
|
|
|
String sampleNo = (String) fluxRecord.getValueByKey("sampleNumber"); |
|
|
|
eventList.add(newEvent(time, inspectionSheetId, argName, argValue, batchNum, sampleNo)); |
|
|
|
eventList.add(newEvent(time, inspectionSheetId, argName, argValue, sampleNo)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -227,7 +239,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM |
|
|
|
InspectionSampleDTO sampleDTO = new InspectionSampleDTO(); |
|
|
|
sampleDTO.setSampleNumber(sampleNumber); |
|
|
|
sampleDTO.setSampleTime(LocalDateTime.ofInstant(events.get(0).getTime(), ZoneId.systemDefault())); |
|
|
|
sampleDTO.setBatchNum(events.get(0).getBatchNum()); |
|
|
|
sampleDTO.setBatchNum(dto.getBatchNumber()); |
|
|
|
sampleDTO.setInspectionSheetId(events.get(0).getInspectionSheetId()); |
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
@@ -235,8 +247,8 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM |
|
|
|
jsonObject.put(event.getArgName(),event.getArgValue()); |
|
|
|
} |
|
|
|
sampleDTO.setJsonData(jsonObject.toString()); |
|
|
|
|
|
|
|
System.out.println(entry); |
|
|
|
//System.out.println(entry); |
|
|
|
list.add(sampleDTO); |
|
|
|
} |
|
|
|
} |
|
|
|
return list; |
|
|
@@ -248,7 +260,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM |
|
|
|
//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(); |
|
|
|
// String batchNum = dto.getBatchNum(); |
|
|
|
String sampleNumber = dto.getSampleNumber(); |
|
|
|
String jsonData = dto.getJsonData(); |
|
|
|
JSONObject json = JSON.parseObject(jsonData); |
|
|
@@ -263,7 +275,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM |
|
|
|
// v= Double.valueOf(entry.getValue().toString()); |
|
|
|
// }catch (Exception e){ |
|
|
|
// } |
|
|
|
list.add(newEvent(eventTime, inspectionSheetId, key, v, batchNum, sampleNumber)); |
|
|
|
list.add(newEvent(eventTime, inspectionSheetId, key, v, sampleNumber)); |
|
|
|
} |
|
|
|
InfluxClient.Client.batchInsert(list, workingProcedureName); |
|
|
|
} |
|
|
@@ -272,11 +284,11 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM |
|
|
|
// calculate(Long.valueOf(lists[0].getInspectionSheetId())); |
|
|
|
} |
|
|
|
|
|
|
|
private Event newEvent(Instant time, String inspectionSheetId, String argName, String argValue, String batchNum, String sampleNo) { |
|
|
|
private Event newEvent(Instant time, String inspectionSheetId, String argName, String argValue, String sampleNo) { |
|
|
|
Event event = new Event(); |
|
|
|
event.setInspectionSheetId(inspectionSheetId); |
|
|
|
event.setTime(time); |
|
|
|
event.setBatchNum(batchNum); |
|
|
|
// event.setBatchNum(batchNum); |
|
|
|
event.setSampleNumber(sampleNo); |
|
|
|
event.setArgName(argName); |
|
|
|
event.setArgValue(argValue); |
|
|
|