MARK FOR PULL
This commit is contained in:
parent
6829169a4a
commit
b15ad64d76
@ -19,7 +19,6 @@ public class ProductFeaturesDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Long id;
|
||||
|
||||
|
@ -31,6 +31,6 @@ public class QueryDataParam extends BaseParam{
|
||||
private List<String> dropedTagNames;
|
||||
private String bucket;
|
||||
private String groupName;
|
||||
private String inspectionSheetId;
|
||||
//private String inspectionSheetId;
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.cnbm.processInspection.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cnbm.admin.annotation.LogOperation;
|
||||
import com.cnbm.basic.dto.FeaturesProcedureDTO;
|
||||
import com.cnbm.basic.dto.ProductFeaturesDTO;
|
||||
@ -64,7 +65,7 @@ public class InspectionSheetController {
|
||||
@ApiImplicitParam(name = "batchNumber", value = "批次号", paramType = "query", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "id", value = "检验单号", paramType = "query", dataTypeClass = Integer.class)
|
||||
})
|
||||
// @PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:page')")
|
||||
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:page')")
|
||||
public Result<PageData<InspectionSheetDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
|
||||
PageData<InspectionSheetDTO> page = inspectionSheetService.page(params);
|
||||
|
||||
@ -73,7 +74,7 @@ public class InspectionSheetController {
|
||||
|
||||
@GetMapping("{id}")
|
||||
@ApiOperation("信息")
|
||||
//@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:info')")
|
||||
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:info')")
|
||||
public Result<InspectionSheetDTO> get(@PathVariable("id") Long id){
|
||||
InspectionSheetDTO data = inspectionSheetService.get(id);
|
||||
|
||||
@ -83,7 +84,7 @@ public class InspectionSheetController {
|
||||
@PostMapping
|
||||
@ApiOperation("保存")
|
||||
@LogOperation("保存")
|
||||
// @PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:save')")
|
||||
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:save')")
|
||||
public Result save(@RequestBody InspectionSheetDTO dto){
|
||||
//效验数据
|
||||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
||||
@ -99,7 +100,7 @@ public class InspectionSheetController {
|
||||
@PutMapping
|
||||
@ApiOperation("修改")
|
||||
@LogOperation("修改")
|
||||
//@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:update')")
|
||||
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:update')")
|
||||
public Result<Long> update(@RequestBody InspectionSheetDTO dto){
|
||||
//效验数据
|
||||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
||||
@ -112,7 +113,7 @@ public class InspectionSheetController {
|
||||
@DeleteMapping
|
||||
@ApiOperation("删除")
|
||||
@LogOperation("删除")
|
||||
//@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:delete')")
|
||||
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:delete')")
|
||||
public Result delete(@RequestBody Long[] ids){
|
||||
//效验数据
|
||||
AssertUtils.isArrayEmpty(ids, "id");
|
||||
@ -125,7 +126,7 @@ public class InspectionSheetController {
|
||||
@GetMapping("export")
|
||||
@ApiOperation("导出")
|
||||
@LogOperation("导出")
|
||||
//@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:export')")
|
||||
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:export')")
|
||||
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
|
||||
List<InspectionSheetDTO> list = inspectionSheetService.list(params);
|
||||
|
||||
@ -151,14 +152,17 @@ public class InspectionSheetController {
|
||||
|
||||
@PostMapping(value = "getFluxParamList")
|
||||
@ApiOperation(value = "从influxdb中获取检测参数")
|
||||
@ApiImplicitParams({
|
||||
// @ApiImplicitParams({
|
||||
// @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataTypeClass = LocalDateTime.class),
|
||||
// @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataTypeClass = LocalDateTime.class),
|
||||
@ApiImplicitParam(name = "inspectionSheetId", value = "检验单号", paramType = "query", dataTypeClass = Long.class),
|
||||
@ApiImplicitParam(name = "workingProcedureName", value = "工序名称", paramType = "query", dataTypeClass = String.class)
|
||||
})
|
||||
List<Event> getFluxParamList(@ApiIgnore @RequestParam Map<String, Object> params){
|
||||
return inspectionSheetService.getFluxParamList(params);
|
||||
// @ApiImplicitParam(name = "inspectionSheetId", value = "检验单号", paramType = "query", dataTypeClass = String.class),
|
||||
// @ApiImplicitParam(name = "workingProcedureName", value = "工序名称", paramType = "query", dataTypeClass = String.class)
|
||||
// })
|
||||
// List<Event> getFluxParamList(@ApiIgnore @RequestParam Map<String, Object> params){
|
||||
// return inspectionSheetService.getFluxParamList(params);
|
||||
// }
|
||||
List<InspectionSampleDTO> getFluxParamList(@RequestParam("inspectionSheetId") Long inspectionSheetId){
|
||||
return inspectionSheetService.getFluxParamList(inspectionSheetId);
|
||||
}
|
||||
|
||||
@PostMapping("saveFluxParamList")
|
||||
@ -166,7 +170,8 @@ public class InspectionSheetController {
|
||||
public Result saveFluxParamList(@RequestBody InspectionSampleDTO[] lists){
|
||||
|
||||
inspectionSheetService.saveFluxParamList(lists);
|
||||
|
||||
//样本数据更新后 计算检验单缺陷数不良数
|
||||
inspectionSheetService.calculate(Long.valueOf(lists[0].getInspectionSheetId()));
|
||||
return new Result();
|
||||
}
|
||||
|
||||
@ -182,4 +187,11 @@ public class InspectionSheetController {
|
||||
return new Result<List<ProductFeaturesDTO>>().ok(list);
|
||||
}
|
||||
|
||||
@PostMapping(value = "calculate")
|
||||
@ApiOperation(value = "检验单统计计算")
|
||||
public Result<Long> calculate(@RequestParam("inspectionSheetId") Long inspectionSheetId){
|
||||
inspectionSheetService.calculate(inspectionSheetId);
|
||||
return new Result<Long>().ok(inspectionSheetId);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.cnbm.processInspection.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cnbm.basic.dto.ProductFeaturesDTO;
|
||||
import com.cnbm.common.page.PageData;
|
||||
import com.cnbm.common.service.CrudService;
|
||||
@ -33,10 +34,13 @@ public interface IInspectionSheetService extends CrudService<InspectionSheet, In
|
||||
|
||||
List<InspectionSheetDTO> list(Map<String, Object> params);
|
||||
|
||||
List<Event> getFluxParamList(Map<String, Object> params);
|
||||
// List<Event> getFluxParamList(Map<String, Object> params);
|
||||
List<InspectionSampleDTO> getFluxParamList(Long inspectionSheetId);
|
||||
|
||||
void saveFluxParamList(InspectionSampleDTO[] lists);
|
||||
|
||||
List<ProductFeaturesDTO> getInspectionSheetFeaturesList(Map<String, Object> params);
|
||||
|
||||
void calculate(Long inspectionSheetId);
|
||||
|
||||
}
|
@ -29,6 +29,7 @@ import com.cnbm.processInspection.dto.InspectionSheetDTO;
|
||||
import com.cnbm.processInspection.entity.InspectionSheet;
|
||||
import com.cnbm.processInspection.mapper.InspectionSheetMapper;
|
||||
import com.cnbm.processInspection.service.IInspectionSheetService;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.influxdb.query.FluxRecord;
|
||||
import com.influxdb.query.FluxTable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -40,6 +41,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -66,11 +68,11 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
private ShiftServiceImpl shiftService;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<InspectionSheet> getWrapper(Map<String, Object> params){
|
||||
Long id = (Long)params.get("id");
|
||||
String inspectionSite = (String)params.get("inspectionSite");
|
||||
String orderNumber = (String)params.get("orderNumber");
|
||||
String batchNumber = (String)params.get("batchNumber");
|
||||
public QueryWrapper<InspectionSheet> getWrapper(Map<String, Object> params) {
|
||||
Long id = (Long) params.get("id");
|
||||
String inspectionSite = (String) params.get("inspectionSite");
|
||||
String orderNumber = (String) params.get("orderNumber");
|
||||
String batchNumber = (String) params.get("batchNumber");
|
||||
|
||||
QueryWrapper<InspectionSheet> wrapper = new QueryWrapper<>();
|
||||
wrapper.like(ObjectUtils.isNotNull(id), "id", id);
|
||||
@ -84,15 +86,15 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<InspectionSheetDTO> page (Map<String, Object> params){
|
||||
public PageData<InspectionSheetDTO> page(Map<String, Object> params) {
|
||||
IPage<InspectionSheet> page = baseDao.selectPage(
|
||||
getPage(params, "id", true),
|
||||
getWrapper(params)
|
||||
);
|
||||
PageData<InspectionSheetDTO> inspectionSheetDTOPageData = getPageData(page, InspectionSheetDTO.class);
|
||||
|
||||
if(!inspectionSheetDTOPageData.getList().isEmpty()){
|
||||
for(InspectionSheetDTO dto:inspectionSheetDTOPageData.getList()){
|
||||
if (!inspectionSheetDTOPageData.getList().isEmpty()) {
|
||||
for (InspectionSheetDTO dto : inspectionSheetDTOPageData.getList()) {
|
||||
Product product = productService.selectById(dto.getProductId());
|
||||
WorkingProcedure workingProcedure = workingProcedureService.selectById(dto.getWorkingProcedureId());
|
||||
Machine machine = machineService.selectById(dto.getMachineId());
|
||||
@ -103,16 +105,16 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
String machineName = null;
|
||||
String shiftName = null;
|
||||
|
||||
if (product!=null){
|
||||
if (product != null) {
|
||||
productName = product.getName();
|
||||
}
|
||||
if (workingProcedure!=null){
|
||||
if (workingProcedure != null) {
|
||||
workingProcedureName = workingProcedure.getName();
|
||||
}
|
||||
if (machine!=null){
|
||||
if (machine != null) {
|
||||
machineName = machine.getName();
|
||||
}
|
||||
if (shift!=null){
|
||||
if (shift != null) {
|
||||
shiftName = shift.getName();
|
||||
}
|
||||
|
||||
@ -128,7 +130,12 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
@Override
|
||||
public InspectionSheetDTO get(Long id) {
|
||||
InspectionSheet entity = baseDao.selectById(id);
|
||||
return ConvertUtils.sourceToTarget(entity, InspectionSheetDTO.class);
|
||||
InspectionSheetDTO dto = ConvertUtils.sourceToTarget(entity, InspectionSheetDTO.class);
|
||||
WorkingProcedure workingProcedure = workingProcedureService.selectById(dto.getWorkingProcedureId());
|
||||
if(workingProcedure!=null){
|
||||
dto.setWorkingProcedureName(workingProcedure.getName());
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -136,16 +143,16 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
public void save(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());
|
||||
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){
|
||||
if (inspectionSheetFeaturesList == null || inspectionSheetFeaturesList.size() == 0) {
|
||||
throw new RuntimeException("没有发现检验参数");
|
||||
}else{
|
||||
} else {
|
||||
//分组样本数=样本大小=检验特性分组数的最大值
|
||||
Integer numbersOfSamples = inspectionSheetFeaturesList.stream().max(Comparator.comparing(ProductFeaturesDTO::getSampleSize)).get().getSampleSize();
|
||||
if(numbersOfSamples!=null){
|
||||
if (numbersOfSamples != null) {
|
||||
dto.setNumberOfGroupedSamples(numbersOfSamples);
|
||||
dto.setNumberOfSamples(numbersOfSamples);
|
||||
}
|
||||
@ -179,103 +186,65 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Event> getFluxParamList(Map<String, Object> params){
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
String workingProcedureName = (String)params.get("workingProcedureName");
|
||||
String inspectionSheetId = (String)params.get("inspectionSheetId");
|
||||
queryDataParam.setMeasurement(workingProcedureName);
|
||||
queryDataParam.setInspectionSheetId(inspectionSheetId);
|
||||
queryDataParam.setBucket("qgs-bucket");
|
||||
|
||||
// Instant startTime = (Instant) params.get("startTime");
|
||||
// Instant endTime = (Instant) params.get("endTime");
|
||||
// Range range = new Range(startTime,endTime);
|
||||
// queryDataParam.setRange(range);
|
||||
List<String> dropNames = new ArrayList<>();
|
||||
dropNames.add("transationId");
|
||||
// dropNames.add("inspectionSheetId");
|
||||
queryDataParam.setDropedTagNames(dropNames);
|
||||
// queryDataParam.setTag(new Tag("argName","forUpdate"));
|
||||
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);
|
||||
public List<InspectionSampleDTO> getFluxParamList(Long id) {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
InspectionSheetDTO dto = get(id);
|
||||
if (dto != null && dto.getWorkingProcedureName()!=null) {
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
String inspectionSheetId = id.toString();
|
||||
String workingProcedureName = dto.getWorkingProcedureName();
|
||||
queryDataParam.setMeasurement(workingProcedureName);
|
||||
//queryDataParam.setInspectionSheetId(inspectionSheetId);
|
||||
queryDataParam.setBucket("qgs-bucket");
|
||||
queryDataParam.setTag(new Tag("inspectionSheetId", inspectionSheetId));
|
||||
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));
|
||||
|
||||
for (FluxTable fluxTable : fluxTableList) {
|
||||
List<FluxRecord> records = fluxTable.getRecords(); // 获取实际的记录操作
|
||||
// List<FluxColumn> columns = fluxTable.getColumns(); // 获取返回的列
|
||||
// System.out.println(columns); // 下面的数据显示是按照当前的column中的label名称获取的数据
|
||||
//System.out.println(records);
|
||||
for (FluxRecord fluxRecord : records) {
|
||||
Instant time = fluxRecord.getTime();
|
||||
String argName = (String)fluxRecord.getValueByKey("argName");
|
||||
Double argValue = Double.valueOf(fluxRecord.getValueByKey("_value").toString());
|
||||
String batchNum = (String)fluxRecord.getValueByKey("batchNum");
|
||||
String sampleNo = (String)fluxRecord.getValueByKey("sampleNo");
|
||||
// System.out.println(fluxRecord.getTime() + ": " + fluxRecord.getValueByKey("argName") + ":"
|
||||
// + fluxRecord.getValueByKey("_value") + ": " + fluxRecord.getValueByKey("batchNum"));
|
||||
eventList.add(newEvent(time,inspectionSheetId,argName,argValue,batchNum,sampleNo));
|
||||
}
|
||||
}
|
||||
|
||||
//更新检验单缺陷数不良数
|
||||
//根据样本号分组
|
||||
Map<String,List<Event>> map = eventList.stream().collect(Collectors.groupingBy(Event::getSampleNumber));
|
||||
//获取的产品特性参照值
|
||||
InspectionSheetDTO dto = get((Long) params.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){
|
||||
//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;
|
||||
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 batchNum = (String) fluxRecord.getValueByKey("batchNum");
|
||||
String sampleNo = (String) fluxRecord.getValueByKey("sampleNumber");
|
||||
eventList.add(newEvent(time, inspectionSheetId, argName, argValue, batchNum, sampleNo));
|
||||
}
|
||||
}
|
||||
}
|
||||
InspectionSheetDTO updateDto = new InspectionSheetDTO();
|
||||
updateDto.setId((Long)params.get("inspectionSheetId"));
|
||||
updateDto.setNumberOfDefects(numberOfDefects);
|
||||
updateDto.setDefectiveQuantity(defectiveQuantity);
|
||||
update(updateDto);
|
||||
List<InspectionSampleDTO> list = new ArrayList<>();
|
||||
if (eventList != null || eventList.size() > 0) {
|
||||
//根据样本号分组
|
||||
Map<String, List<Event>> map = eventList.stream().collect(Collectors.groupingBy(Event::getSampleNumber));
|
||||
for (Map.Entry<String, List<Event>> entry : map.entrySet()) {
|
||||
String sampleNumber = entry.getKey();
|
||||
List<Event> events = entry.getValue();
|
||||
|
||||
return eventList;
|
||||
InspectionSampleDTO sampleDTO = new InspectionSampleDTO();
|
||||
sampleDTO.setSampleNumber(sampleNumber);
|
||||
sampleDTO.setSampleTime(LocalDateTime.ofInstant(events.get(0).getTime(), ZoneId.systemDefault()));
|
||||
sampleDTO.setBatchNum(events.get(0).getBatchNum());
|
||||
sampleDTO.setInspectionSheetId(events.get(0).getInspectionSheetId());
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
for(Event event:events){
|
||||
jsonObject.put(event.getArgName(),event.getArgValue());
|
||||
}
|
||||
sampleDTO.setJsonData(jsonObject.toString());
|
||||
|
||||
System.out.println(entry);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFluxParamList(InspectionSampleDTO[] lists){
|
||||
for(InspectionSampleDTO dto:lists) {
|
||||
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();
|
||||
@ -285,27 +254,37 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
JSONObject json = JSON.parseObject(jsonData);
|
||||
LocalDateTime sampleTime = dto.getSampleTime();
|
||||
Instant eventTime = sampleTime.toInstant(ZoneOffset.UTC);
|
||||
|
||||
List<Event> list = new ArrayList<>();
|
||||
for (Map.Entry entry : json.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
Double v = Double.valueOf(entry.getValue().toString());
|
||||
String v = entry.getValue().toString();
|
||||
// Double v = null;
|
||||
// try {
|
||||
// v= Double.valueOf(entry.getValue().toString());
|
||||
// }catch (Exception e){
|
||||
// }
|
||||
list.add(newEvent(eventTime, inspectionSheetId, key, v, batchNum, sampleNumber));
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list, workingProcedureName);
|
||||
}
|
||||
// //样本数据更新后 计算检验单缺陷数不良数
|
||||
// System.out.println("--------------------------------------");
|
||||
// calculate(Long.valueOf(lists[0].getInspectionSheetId()));
|
||||
}
|
||||
|
||||
private Event newEvent(Instant time,String inspectionSheetId,String argName,Double argValue,String batchNum,String sampleNo){
|
||||
private Event newEvent(Instant time, String inspectionSheetId, String argName, String argValue, String batchNum, String sampleNo) {
|
||||
Event event = new Event();
|
||||
event.setInspectionSheetId(inspectionSheetId);
|
||||
event.setTime(time);
|
||||
event.setBatchNum(batchNum);
|
||||
event.setSampleNumber(sampleNo);
|
||||
event.setArgName(argName);
|
||||
if(!Objects.equals(argValue, "") && argValue != null ){
|
||||
event.setArgValue(argValue.toString());
|
||||
}
|
||||
event.setArgValue(argValue);
|
||||
// if (Objects.equals(argValue, "")){
|
||||
// event.setArgValue("");
|
||||
// }else if (argValue != null) {
|
||||
// event.setArgValue(argValue.toString());
|
||||
// }
|
||||
return event;
|
||||
}
|
||||
|
||||
@ -318,4 +297,115 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
public List<ProductFeaturesDTO> getInspectionSheetFeaturesList(Map<String, Object> params) {
|
||||
return mapper.getInspectionSheetFeaturesList(params);
|
||||
}
|
||||
|
||||
//计算并更新检验单缺陷数不良数
|
||||
@Override
|
||||
public void calculate(Long inspectionSheetId) {
|
||||
List<InspectionSampleDTO> sampleDTOList = getFluxParamList(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);
|
||||
//循环每个样本组
|
||||
for (InspectionSampleDTO sampleDTO : sampleDTOList) {
|
||||
//该样本的缺陷数
|
||||
Integer eventDefects = 0;
|
||||
//该样本的属性列表
|
||||
String jsonData = sampleDTO.getJsonData();
|
||||
JSONObject json = JSON.parseObject(jsonData);
|
||||
for (ProductFeaturesDTO feature : featuresList) {
|
||||
String v = (String)json.get(feature.getName());
|
||||
if (!Objects.equals(v, "") && v != null) {
|
||||
//1 计量型;2 计数型
|
||||
if (feature.getType() == 1) {
|
||||
Double featureValue = Double.valueOf(v);
|
||||
if (featureValue > feature.getUsl() || featureValue < feature.getLsl()) {
|
||||
eventDefects = eventDefects + 1;
|
||||
}
|
||||
}
|
||||
if (feature.getType() == 2) {
|
||||
Integer featureValue = Integer.valueOf(v);
|
||||
if (featureValue == 1) {
|
||||
eventDefects = eventDefects + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (eventDefects != 0) {
|
||||
numberOfDefects = numberOfDefects + eventDefects;
|
||||
defectiveQuantity = defectiveQuantity + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
InspectionSheetDTO updateDto = new InspectionSheetDTO();
|
||||
updateDto.setId(inspectionSheetId);
|
||||
updateDto.setNumberOfDefects(numberOfDefects);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
InspectionSheetDTO updateDto = new InspectionSheetDTO();
|
||||
updateDto.setId(inspectionSheetId);
|
||||
updateDto.setNumberOfDefects(numberOfDefects);
|
||||
updateDto.setDefectiveQuantity(defectiveQuantity);
|
||||
update(updateDto);
|
||||
}
|
||||
}*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user