MARK FOR PULL

This commit is contained in:
2022-12-07 11:07:31 +08:00
parent ab35b10130
commit b515eacbab
38 changed files with 828 additions and 65 deletions

View File

@@ -1,6 +1,7 @@
package com.cnbm.processInspection.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.basic.dto.FeaturesProcedureDTO;
import com.cnbm.basic.dto.ProductFeaturesDTO;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
@@ -12,6 +13,7 @@ import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.cnbm.influx.param.QueryDataParam;
import com.cnbm.influx.template.Event;
import com.cnbm.processInspection.dto.InspectionSampleDTO;
import com.cnbm.processInspection.dto.InspectionSheetDTO;
import com.cnbm.processInspection.excel.InspectionSheetExcel;
@@ -62,7 +64,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);
@@ -71,7 +73,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);
@@ -81,20 +83,23 @@ public class InspectionSheetController {
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:save')")
public Result<Long> save(@RequestBody InspectionSheetDTO dto){
// @PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:save')")
public Result save(@RequestBody InspectionSheetDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
inspectionSheetService.save(dto);
try {
inspectionSheetService.save(dto);
}catch (Exception e){
return new Result<Long>().error(1,"没有发现检验参数");
}
return new Result<Long>().ok(dto.getId());
}
@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);
@@ -107,7 +112,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");
@@ -120,7 +125,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);
@@ -147,22 +152,34 @@ public class InspectionSheetController {
@PostMapping(value = "getFluxParamList")
@ApiOperation(value = "从influxdb中获取检测参数")
@ApiImplicitParams({
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataTypeClass = LocalDateTime.class),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataTypeClass = LocalDateTime.class),
@ApiImplicitParam(name = "id", value = "检验单号", paramType = "query", dataTypeClass = Integer.class),
// @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<FluxTable> getFluxParamList(@ApiIgnore @RequestParam Map<String, Object> params){
List<Event> getFluxParamList(@ApiIgnore @RequestParam Map<String, Object> params){
return inspectionSheetService.getFluxParamList(params);
}
@PostMapping("saveFluxParamList")
@ApiOperation("将样本检测参数写入influxdb")
public Result saveFluxParamList(@RequestBody InspectionSampleDTO dto){
public Result saveFluxParamList(@RequestBody InspectionSampleDTO[] lists){
inspectionSheetService.saveFluxParamList(dto);
inspectionSheetService.saveFluxParamList(lists);
return new Result();
}
@PostMapping("getInspectionSheetFeaturesList")
@ApiOperation("获取检验单对应检验属性")
@ApiImplicitParams({
@ApiImplicitParam(name = "productId", value = "产品", paramType = "query", dataTypeClass = Long.class),
@ApiImplicitParam(name = "workingProcedureId", value = "工序", paramType = "query", dataTypeClass = Long.class),
@ApiImplicitParam(name = "inspectionStage", value = "检测阶段", paramType = "query", dataTypeClass = Integer.class)
})
public Result getInspectionSheetFeaturesList(@ApiIgnore @RequestParam Map<String, Object> params){
List<ProductFeaturesDTO> list = inspectionSheetService.getInspectionSheetFeaturesList(params);
return new Result<List<ProductFeaturesDTO>>().ok(list);
}
}

View File

@@ -32,4 +32,7 @@ public class InspectionSampleDTO implements Serializable {
@ApiModelProperty(value = "取样时间")
private LocalDateTime sampleTime;
@ApiModelProperty(value = "样本号")
private String sampleNumber;
}

View File

@@ -39,8 +39,8 @@ public class InspectionSheetDTO implements Serializable {
@ApiModelProperty(value = "产品名称关联product表")
private String productName;
@ApiModelProperty(value = "检验阶段1 进货检验、 2 过程检验、 3 成品检验、 4 出货检验;; 如果有多个用逗号隔开,比如 1,4 就代表选中了进货检验和出货检验")
private String inspectionStage;
@ApiModelProperty(value = "检验阶段1 进货检验、 2 过程检验、 3 成品检验、 4 出货检验")
private Integer inspectionStage;
@ApiModelProperty(value = "工序id关联working_procedure表")
private Long workingProcedureId;

View File

@@ -38,8 +38,8 @@ public class InspectionSheet implements Serializable {
@ApiModelProperty("产品id关联product表")
private Long productId;
@ApiModelProperty("检验阶段1 进货检验、 2 过程检验、 3 成品检验、 4 出货检验;; 如果有多个用逗号隔开,比如 1,4 就代表选中了进货检验和出货检验")
private String inspectionStage;
@ApiModelProperty("检验阶段1 进货检验、 2 过程检验、 3 成品检验、 4 出货检验")
private Integer inspectionStage;
@ApiModelProperty("工序id关联working_procedure表")
private Long workingProcedureId;

View File

@@ -23,8 +23,8 @@ public class InspectionSheetExcel {
private String inspectionSite;
@Excel(name = "产品id关联product表")
private Long productId;
@Excel(name = "检验阶段1 进货检验、 2 过程检验、 3 成品检验、 4 出货检验;; 如果有多个用逗号隔开,比如 1,4 就代表选中了进货检验和出货检验")
private String inspectionStage;
@Excel(name = "检验阶段1 进货检验、 2 过程检验、 3 成品检验、 4 出货检验")
private Integer inspectionStage;
@Excel(name = "工序id关联working_procedure表")
private Long workingProcedureId;
@Excel(name = "机台id关联machine表")

View File

@@ -1,5 +1,6 @@
package com.cnbm.processInspection.mapper;
import com.cnbm.basic.dto.ProductFeaturesDTO;
import com.cnbm.common.dao.BaseDao;
import com.cnbm.processInspection.dto.InspectionSheetDTO;
import com.cnbm.processInspection.entity.InspectionSheet;
@@ -17,5 +18,6 @@ import java.util.Map;
@Mapper
public interface InspectionSheetMapper extends BaseDao<InspectionSheet> {
List<InspectionSheetDTO> list(Map<String, Object> params);
Integer getNumberOfSamples(Long productId);
// Integer getNumberOfSamples(Map<String, Object> params);
List<ProductFeaturesDTO> getInspectionSheetFeaturesList(Map<String, Object> params);
}

View File

@@ -1,8 +1,10 @@
package com.cnbm.processInspection.service;
import com.cnbm.basic.dto.ProductFeaturesDTO;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.CrudService;
import com.cnbm.influx.param.QueryDataParam;
import com.cnbm.influx.template.Event;
import com.cnbm.processInspection.dto.InspectionSampleDTO;
import com.cnbm.processInspection.dto.InspectionSheetDTO;
import com.cnbm.processInspection.entity.InspectionSheet;
@@ -31,8 +33,10 @@ public interface IInspectionSheetService extends CrudService<InspectionSheet, In
List<InspectionSheetDTO> list(Map<String, Object> params);
List<FluxTable> getFluxParamList(Map<String, Object> params);
List<Event> getFluxParamList(Map<String, Object> params);
void saveFluxParamList(InspectionSampleDTO dto);
void saveFluxParamList(InspectionSampleDTO[] lists);
List<ProductFeaturesDTO> getInspectionSheetFeaturesList(Map<String, Object> params);
}

View File

@@ -5,6 +5,7 @@ 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;
import com.cnbm.basic.dto.ProductFeaturesDTO;
import com.cnbm.basic.entity.Machine;
import com.cnbm.basic.entity.Product;
import com.cnbm.basic.entity.Shift;
@@ -15,16 +16,20 @@ import com.cnbm.basic.service.impl.ShiftServiceImpl;
import com.cnbm.basic.service.impl.WorkingProcedureServiceImpl;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.CrudServiceImpl;
import com.cnbm.common.spc.util.DataUtils;
import com.cnbm.common.utils.ConvertUtils;
import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.param.PageInfo;
import com.cnbm.influx.param.QueryDataParam;
import com.cnbm.influx.param.Range;
import com.cnbm.influx.param.Tag;
import com.cnbm.influx.template.Event;
import com.cnbm.processInspection.dto.InspectionSampleDTO;
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.influxdb.query.FluxRecord;
import com.influxdb.query.FluxTable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,6 +42,7 @@ import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;
/**
* 检验单 表
@@ -128,11 +134,21 @@ 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);
// 验证是否有检验参数
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){
throw new RuntimeException("没有发现检验参数");
}else{
//分组样本数=样本大小=检验特性分组数的最大值
Integer numbersOfSamples = inspectionSheetFeaturesList.stream().max(Comparator.comparing(ProductFeaturesDTO::getSampleSize)).get().getSampleSize();
if(numbersOfSamples!=null){
dto.setNumberOfGroupedSamples(numbersOfSamples);
dto.setNumberOfSamples(numbersOfSamples);
}
}
InspectionSheet entity = ConvertUtils.sourceToTarget(dto, InspectionSheet.class);
insert(entity);
@@ -163,47 +179,129 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
}
@Override
public List<FluxTable> getFluxParamList(Map<String, Object> params){
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);
// 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> list = InfluxClient.Client.query(queryDataParam);
return list;
List<FluxTable> fluxTableList = InfluxClient.Client.query(queryDataParam);
List<Event> eventList = new ArrayList<>();
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;
}
}
}
InspectionSheetDTO updateDto = new InspectionSheetDTO();
updateDto.setId((Long)params.get("inspectionSheetId"));
updateDto.setNumberOfDefects(numberOfDefects);
updateDto.setDefectiveQuantity(defectiveQuantity);
update(updateDto);
return eventList;
}
@Override
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();
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();
String sampleNumber = dto.getSampleNumber();
String jsonData = dto.getJsonData();
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());
list.add(newEvent(eventTime,inspectionSheetId,key,v,batchNum));
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, sampleNumber));
}
InfluxClient.Client.batchInsert(list, workingProcedureName);
}
InfluxClient.Client.batchInsert(list,workingProcedureName);
}
private Event newEvent(Instant time,String inspectionSheetId,String argName,Double argValue,String batchNum){
private Event newEvent(Instant time,String inspectionSheetId,String argName,Double 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());
@@ -211,7 +309,13 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
return event;
}
public Integer getNumberOfSamples(Long id) {
return mapper.getNumberOfSamples(id);
// @Override
// public Integer getNumberOfSamples(Map<String, Object> params) {
// return mapper.getNumberOfSamples(params);
// }
@Override
public List<ProductFeaturesDTO> getInspectionSheetFeaturesList(Map<String, Object> params) {
return mapper.getInspectionSheetFeaturesList(params);
}
}