This commit is contained in:
闫阳 2022-12-01 15:50:30 +08:00
parent 1b9c3499a3
commit 4864545f12
10 changed files with 68 additions and 20 deletions

View File

@ -95,7 +95,7 @@ public enum InfluxClient {
Point point = Point.measurement(measurement)
.addTag("transationId", event.getTransationId())
.addTag("inspectionSheetId", event.getInspectionSheetId())
.addTag("batchNum", event.getBatchNum().toString())
.addTag("batchNum", event.getBatchNum())
.addTag("argName", event.getArgName())
.addField("argValue", event.getArgValue())
.time(event.getTime().toEpochMilli(), WritePrecision.MS);

View File

@ -64,7 +64,7 @@ public class S7DemoController {
Double d = r.nextDouble() * 2.5 + 66;
event.setInspectionSheetId(j+"");
event.setArgValue(d);
event.setBatchNum(i);
event.setBatchNum(i+"");
list.add(event);
}
}
@ -91,7 +91,7 @@ public class S7DemoController {
event.setInspectionSheetId(i+"");
event.setBatchNum(i);
event.setBatchNum(i+"");
list.add(event);
}
InfluxClient.Client.batchInsert(list,"WeightHeiHei");

View File

@ -26,5 +26,5 @@ public class Event {
private Double argValue;
//批次号可选的
private Integer batchNum;
private String batchNum;
}

View File

@ -14,6 +14,8 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- fastjson -->
<fastjson.version>1.2.75</fastjson.version>
</properties>
<dependencies>
@ -38,5 +40,10 @@
<artifactId>ym-quality-planning</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -156,11 +156,11 @@ public class InspectionSheetController {
return inspectionSheetService.getFluxParamList(params);
}
@PutMapping("saveFluxParamList")
@PostMapping("saveFluxParamList")
@ApiOperation("将样本检测参数写入influxdb")
public Result saveFluxParamList(@RequestBody InspectionSampleDTO[] lists){
public Result saveFluxParamList(@RequestBody InspectionSampleDTO dto){
inspectionSheetService.saveFluxParamList(lists);
inspectionSheetService.saveFluxParamList(dto);
return new Result();
}

View File

@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 检验样本
@ -22,4 +23,13 @@ public class InspectionSampleDTO implements Serializable {
@ApiModelProperty(value = "检验单id")
private String inspectionSheetId;
@ApiModelProperty(value = "检验参数json格式")
private String jsonData;
@ApiModelProperty(value = "批次号")
private String batchNum;
@ApiModelProperty(value = "取样时间")
private LocalDateTime sampleTime;
}

View File

@ -17,4 +17,5 @@ import java.util.Map;
@Mapper
public interface InspectionSheetMapper extends BaseDao<InspectionSheet> {
List<InspectionSheetDTO> list(Map<String, Object> params);
Integer getNumberOfSamples(Long productId);
}

View File

@ -33,6 +33,6 @@ public interface IInspectionSheetService extends CrudService<InspectionSheet, In
List<FluxTable> getFluxParamList(Map<String, Object> params);
void saveFluxParamList(InspectionSampleDTO[] lists);
void saveFluxParamList(InspectionSampleDTO dto);
}

View File

@ -1,5 +1,7 @@
package com.cnbm.processInspection.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@ -36,6 +38,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
@ -61,7 +64,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
@Autowired
private ShiftServiceImpl shiftService;
@Override
public QueryWrapper<InspectionSheet> getWrapper(Map<String, Object> params){
Long id = (Long)params.get("id");
@ -131,6 +134,12 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
@Override
@Transactional(rollbackFor = Exception.class)
public void save(InspectionSheetDTO dto) {
//分组样本数=样本大小=检验特性分组数的最大值
Integer numbersOfSamples = getNumberOfSamples(dto.getProductId());
if(numbersOfSamples!=null){
dto.setNumberOfGroupedSamples(numbersOfSamples);
dto.setNumberOfSamples(numbersOfSamples);
}
InspectionSheet entity = ConvertUtils.sourceToTarget(dto, InspectionSheet.class);
insert(entity);
}
@ -149,7 +158,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
deleteBatchIds(Arrays.asList(ids));
}
@Autowired
@Resource
private InspectionSheetMapper mapper;
@Override
@ -176,25 +185,39 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
}
@Override
public void saveFluxParamList(@RequestBody InspectionSampleDTO[] lists){
for(InspectionSampleDTO dto:lists){
String equipmentName = dto.getWorkingProcedureName();
LocalDateTime eventTimestamp = LocalDateTime.now();
Instant eventTime = eventTimestamp.toInstant(ZoneOffset.UTC);
String inspectionSheetId =dto.getInspectionSheetId();
// Event event = new Event(eventTime,inspectionSheetId,"ppExecName",ppExecName);
// InfluxClient.Client.insert(event,equipmentName);
public void saveFluxParamList(InspectionSampleDTO dto){
//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 jsonData = dto.getJsonData();
JSONObject json = JSON.parseObject(jsonData);
// LocalDateTime sampleTime = dto.getSampleTime();
// Instant eventTime = sampleTime.toInstant(ZoneOffset.UTC);
Instant eventTime = new Date().toInstant();
List<Event> list = new ArrayList<>();
for (Map.Entry entry : json.entrySet()) {
String key = entry.getKey().toString();
Double v = Double.valueOf(entry.getValue().toString());
list.add(newEvent(eventTime,inspectionSheetId,key,v,batchNum));
}
InfluxClient.Client.batchInsert(list,workingProcedureName);
}
private Event newEvent(Instant time,String inspectionSheetId,String argName,Double argValue){
private Event newEvent(Instant time,String inspectionSheetId,String argName,Double argValue,String batchNum){
Event event = new Event();
event.setInspectionSheetId(inspectionSheetId);
event.setTime(time);
event.setBatchNum(batchNum);
event.setArgName(argName);
if(!Objects.equals(argValue, "") && argValue != null ){
event.setArgValue(argValue);
}
return event;
}
public Integer getNumberOfSamples(Long id) {
return mapper.getNumberOfSamples(id);
}
}

View File

@ -64,4 +64,11 @@
order by i.id asc
</select>
<select id="getNumberOfSamples" resultType="Integer">
select max(sample_size) from product_features
<where>
valid = 1 AND product_id = #{id}
</where>
</select>
</mapper>