diff --git a/src/main/java/com/iflytop/nuclear/controller/CheckController.java b/src/main/java/com/iflytop/nuclear/controller/CheckController.java index ddcae26..8e58bd3 100644 --- a/src/main/java/com/iflytop/nuclear/controller/CheckController.java +++ b/src/main/java/com/iflytop/nuclear/controller/CheckController.java @@ -1,14 +1,21 @@ package com.iflytop.nuclear.controller; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.iflytop.nuclear.entity.CheckInfo; import com.iflytop.nuclear.entity.CheckResult; +import com.iflytop.nuclear.model.NuclearCoreConfig; import com.iflytop.nuclear.service.CheckService; +import com.iflytop.nuclear.service.NuclearCoreConfigService; +import com.iflytop.nuclear.utils.ImageUtils; import com.iflytop.nuclear.utils.ResponseData; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.IOException; +import java.util.Map; /** * @author cool @@ -22,6 +29,8 @@ public class CheckController { @Autowired CheckService checkService; + @Autowired + NuclearCoreConfigService nuclearCoreConfigService; @GetMapping("/auto/{id}") public ResponseData checkAuto(@PathVariable(name = "id") int taskId) throws IOException { @@ -43,4 +52,42 @@ public class CheckController { checkService.breakOffByTaskId(taskId); return ResponseData.success(); } + + @PostMapping("/save") + public ResponseData saveResult(@RequestBody Map taskInfo){ + String checkNumber = taskInfo.get("checkNumber"); + String taskId = taskInfo.get("taskId"); + String resultSerial = taskInfo.get("result_serial"); + String resultImg = taskInfo.get("result_img"); + UpdateWrapper updateWrapper = new UpdateWrapper(); + updateWrapper.eq("task_id", taskId).eq("serial_number", checkNumber); + // 对结果进行判断 而后存入result + // 暂且写为1 正确 2错误 + // 查询当前config中的first 而后对比 + QueryWrapper nuclearCoreConfigQueryWrapper = new QueryWrapper<>(); + nuclearCoreConfigQueryWrapper.eq("task_id", taskId).eq("serial_number", checkNumber); + NuclearCoreConfig one = nuclearCoreConfigService.getOne(nuclearCoreConfigQueryWrapper); + int result = 0; + if ("".equals(resultSerial)) { + result = 2; + }else { + String firstSign = one.getFirstSign(); + if (firstSign.equals("result_serial")) { + result = 1; + } + } + // result_img为本地图片,需要读取到而后转为base64存储在数据库中 + String base64 = ImageUtils.convertImageToBase64Str(resultImg); + String imgResult = "data:image/png;base64," + base64; + NuclearCoreConfig nuclearCoreConfig = NuclearCoreConfig.builder() + .resultImg(imgResult) + .resultSerial(resultSerial) + .result(result) + .taskId(Integer.parseInt(taskId)) + .build(); + boolean update = nuclearCoreConfigService.update(nuclearCoreConfig, updateWrapper); + JSONObject jo = new JSONObject(); + jo.put("result", update); + return ResponseData.success(jo); + } } diff --git a/src/main/java/com/iflytop/nuclear/utils/ImageUtils.java b/src/main/java/com/iflytop/nuclear/utils/ImageUtils.java new file mode 100644 index 0000000..a8fcffc --- /dev/null +++ b/src/main/java/com/iflytop/nuclear/utils/ImageUtils.java @@ -0,0 +1,69 @@ +package com.iflytop.nuclear.utils; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.*; +import java.util.Base64; + +/** + * @author cool + * @date 2023/7/10 15:53 + */ +public class ImageUtils { + /** + * 图片转Base64码 + * @param src + * @return + */ + public static String convertImageToBase64Str(String src) { + ByteArrayOutputStream baos = null; + try { + String suffix = src.substring(src.lastIndexOf(".") + 1); + File imageFile = new File(src); + BufferedImage bufferedImage = ImageIO.read(imageFile); + baos = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, suffix, baos); + byte[] bytes = baos.toByteArray(); + return Base64.getEncoder().encodeToString(bytes); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (baos != null) { + baos.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * Base64码转图片 + * @param base64String + * @param newSrc + */ + public static void convertBase64StrToImage(String base64String, String newSrc) { + ByteArrayInputStream bais = null; + try { + String suffix = newSrc.substring(newSrc.lastIndexOf(".") + 1); + byte[] bytes = Base64.getDecoder().decode(base64String); + bais = new ByteArrayInputStream(bytes); + BufferedImage bufferedImage = ImageIO.read(bais); + File imageFile = new File(newSrc); + ImageIO.write(bufferedImage, suffix, imageFile); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (bais != null) { + bais.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/uploadfiles/xlsx/20230710/堆芯模版-27.xlsx b/uploadfiles/xlsx/20230710/堆芯模版-27.xlsx new file mode 100644 index 0000000..1b0a04e Binary files /dev/null and b/uploadfiles/xlsx/20230710/堆芯模版-27.xlsx differ