Files
SPC/ym-process-inspection/src/main/java/com/cnbm/processInspection/controller/InspectionSheetController.java
caixiang 5a9f5ee38b mark
2023-05-09 14:24:13 +08:00

228 lines
11 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.cnbm.processInspection.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.basic.dto.ProductFeaturesDTO;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.ExcelUtils;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
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.excel.InspectionSheetExcel;
import com.cnbm.processInspection.service.IInspectionSheetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* 检验单 表 前端控制器
*
* @author why
* @since 2022-08-17
*/
@RestController
@RequestMapping("/processInspection/inspectionSheet")
@Api(tags="检验单 表")
public class InspectionSheetController {
@Autowired
private IInspectionSheetService inspectionSheetService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataTypeClass = LocalDateTime.class),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataTypeClass = LocalDateTime.class),
@ApiImplicitParam(name = "inspectionSite", value = "检验站点", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = "productId", value = "产品id", paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "workingProcedureId", value = "工序id", paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "machineId", value = "机台id", paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "orderNumber", value = "订单号", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = "batchNumber", value = "批次号", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = "id", value = "检验单号", paramType = "query", dataTypeClass = Integer.class)
})
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:page')")
public Result<PageData<InspectionSheetDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<InspectionSheetDTO> page = inspectionSheetService.page(params);
return new Result<PageData<InspectionSheetDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:info')")
public Result<InspectionSheetDTO> get(@PathVariable("id") Long id){
InspectionSheetDTO data = inspectionSheetService.get(id);
return new Result<InspectionSheetDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:save')")
public Result<Long> save(@RequestBody InspectionSheetDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
// try {
// inspectionSheetService.saveSheet(dto);
// }catch (Exception e){
// return new Result<Long>().error(1,"没有发现检验参数");
// }
InspectionSheet entity = inspectionSheetService.saveSheet(dto);
if(entity.getNumberOfSamples()!=null){
inspectionSheetService.insert(entity);
return new Result<Long>().ok(entity.getId());
}
else{
return new Result<Long>().error(1,"没有发现检验参数");
}
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:update')")
public Result<Long> update(@RequestBody InspectionSheetDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
inspectionSheetService.update(dto);
return new Result<Long>().ok(dto.getId());
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
inspectionSheetService.delete(ids);
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@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);
ExcelUtils.exportExcelToTarget(response, null, list, InspectionSheetExcel.class);
}
@PostMapping(value = "list")
@ApiOperation(value = "获取检验单列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataTypeClass = LocalDateTime.class),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataTypeClass = LocalDateTime.class),
@ApiImplicitParam(name = "inspectionSite", value = "检验站点", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = "productId", value = "产品id", paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "workingProcedureId", value = "工序id", paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "machineId", value = "机台id", paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "orderNumber", value = "订单号", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = "batchNumber", value = "批次号", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = "id", value = "检验单号", paramType = "query", dataTypeClass = Integer.class)
})
private List<InspectionSheetDTO> list(@ApiIgnore @RequestParam Map<String, Object> params) {
return inspectionSheetService.list(params);
}
@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 = "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(value = "getFluxParamList3")
@ApiOperation(value = "从influxdb中获取检测参数3")
List<InspectionSampleDTO3> getFluxParamList3(@RequestParam("inspectionSheetId") Long inspectionSheetId){
return inspectionSheetService.getFluxParamList3(inspectionSheetId);
}
@PostMapping("saveFluxParamList")
@ApiOperation("将样本检测参数写入influxdb")
public Result saveFluxParamList(@RequestBody InspectionSampleDTO[] lists) throws InterruptedException{
inspectionSheetService.saveFluxParamList(lists);
Thread.sleep(1000);
//样本数据更新后 计算检验单缺陷数不良数
inspectionSheetService.calculate(Long.valueOf(lists[0].getInspectionSheetId()));
return new Result();
}
@PostMapping("saveFluxParamList2")
@ApiOperation("将样本检测参数写入influxdb2")
public Result saveFluxParamList2(@RequestBody InspectionSampleDTO2[] lists) throws InterruptedException{
inspectionSheetService.saveFluxParamList2(lists);
Thread.sleep(1000);
//样本数据更新后 计算检验单缺陷数不良数
inspectionSheetService.calculate(Long.valueOf(lists[0].getInspectionSheetId()));
return new Result();
}
@PostMapping("saveFluxParamList3")
@ApiOperation("将样本检测参数写入influxdb3")
public Result saveFluxParamList3(@RequestBody InspectionSampleDTO3[] lists) throws InterruptedException{
inspectionSheetService.saveFluxParamList3(lists);
Thread.sleep(1000);
//样本数据更新后 计算检验单缺陷数不良数
inspectionSheetService.calculate(Long.valueOf(lists[0].getInspectionSheetId()));
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);
}
@PostMapping(value = "calculate")
@ApiOperation(value = "检验单统计计算")
public Result<Long> calculate(@RequestParam("inspectionSheetId") Long inspectionSheetId){
inspectionSheetService.calculate(inspectionSheetId);
return new Result<Long>().ok(inspectionSheetId);
}
}