framework/src/main/java/com/yuanchu/mom/mapper/SystemLogMapper.java
@@ -28,5 +28,8 @@ @Select("select coalesce(count(id), 0) from ${tableName} where examine_time like concat('%', #{date}, '%') and laboratory=#{laboratory} and company_id=#{companyId}") int countRowsByNow3(String tableName, Long companyId, String laboratory, String date); @Select("select coalesce(count(id), 0) from ${tableName} where create_time like concat('%', #{date}, '%') and laboratory=#{laboratory} and company_id=#{companyId}") int countRowsByNow4(String tableName, Long companyId, String laboratory, String date); } framework/src/main/java/com/yuanchu/mom/utils/GiveCode.java
@@ -40,4 +40,18 @@ return code + (date2 == null ? date : date2) + symbol + nums; } //检验单生成外部委托编号的规则 public String giveCode3(String code, Long companyId, String laboratory, String tableName, String symbol, String patten) { String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); String date2 = LocalDate.now().format(DateTimeFormatter.ofPattern(patten)); int num; num = systemLogMapper.countRowsByNow4(tableName, companyId, laboratory, LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"))) + 1; String nums = num + ""; if (nums.length() == 1) nums = "0000" + num; else if (nums.length() == 2) nums = "000" + num; else if (nums.length() == 3) nums = "00" + num; else if (nums.length() == 4) nums = "0" + num; return code + (date2 == null ? date : date2) + symbol + nums; } } inspect-server/src/main/java/com/yuanchu/mom/controller/InsOrderController.java
@@ -51,12 +51,6 @@ return Result.success(insOrderService.selectInsOrderParameter(page, sampleOrderDto)); } // @ValueClassify("检验下单") // @ApiOperation(value = "查看所有检验单") // @PostMapping("/selectAllInsOrder") // public Result selectAllInsOrder(){ // return Result.success(); // } @ValueClassify("检验下单") @ApiOperation(value = "检验分配") inspect-server/src/main/java/com/yuanchu/mom/controller/InsReportController.java
@@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -133,4 +134,18 @@ writer.write("{\"error\":0}"); } } @ValueAuth @ApiOperation(value = "报告批量下载") @GetMapping("/downAll") public Result downAll(String ids) { return Result.success(insReportService.downAll(ids)); } @ValueAuth @ApiOperation(value = "报告批量上传") @PostMapping("/upAll") public Result upAll(MultipartFile file) throws IOException { return Result.success(insReportService.upAll(file)); } } inspect-server/src/main/java/com/yuanchu/mom/pojo/InsOrder.java
@@ -34,6 +34,15 @@ @Length(max= 255,message="编码长度不能超过255") private String entrustCode; /** * 外部委托编号 */ @ValueTableShow(1) @Size(max= 255,message="编码长度不能超过255") @ApiModelProperty(value = "外部委托编号") @Length(max= 255,message="编码长度不能超过255") private String outEntrustCode; @Size(max= 255,message="编码长度不能超过255") @ApiModelProperty(value = "检验类别") @Length(max= 255,message="编码长度不能超过255") inspect-server/src/main/java/com/yuanchu/mom/service/InsReportService.java
@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.yuanchu.mom.dto.ReportPageDto; import com.yuanchu.mom.pojo.InsReport; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.Map; /** @@ -32,4 +34,8 @@ int ratifyReport(Integer id, Integer isRatify, String ratifyTell); int wordInsertUrl(Map<String, Object> map, String url); String downAll(String ids); int upAll(MultipartFile file) throws IOException; } inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java
@@ -158,8 +158,21 @@ @Transactional(rollbackFor = Exception.class) public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing) { insOrder.setState(0); String code = customMapper.selectById(insOrder.getCompanyId()).getCode2(); //insOrder.setEntrustCode(giveCode.giveCode("JCZX-" + code + "-", "ins_order", "", "yyMMdd")); //客户代号 Custom custom = customMapper.selectById(insOrder.getCompanyId()); String code = custom.getCode2(); if (!custom.getCompany().equals(insOrder.getCompany())){ Custom one = customMapper.selectOne(Wrappers.<Custom>lambdaQuery().eq(Custom::getCompany, insOrder.getCompany())); insOrder.setCompanyId(one.getId()); code=one.getCode2(); } //实验室编号 String code2 = baseMapper.selLaboratoryCode(insOrder.getLaboratory()); if (StringUtils.isEmpty(code2)) { code2 = ""; } //外部委托编号 insOrder.setOutEntrustCode(giveCode.giveCode3("ZT/" + code2 + "-" + code + "-", insOrder.getCompanyId(), insOrder.getLaboratory(), "ins_order", "", "yyMM")); String giveCode = this.giveCode.giveCode("JCZX-" + code + "-", "ins_sample", "", "yyMMdd"); insOrderMapper.insert(insOrder); AtomicInteger count = new AtomicInteger(); inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
@@ -23,22 +23,30 @@ import com.yuanchu.mom.pojo.InsReport; import com.yuanchu.mom.service.InsReportService; import com.yuanchu.mom.utils.QueryWrappers; import com.yuanchu.mom.vo.Result; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; /** * @author Administrator @@ -223,6 +231,156 @@ return 1; } //报告批量下载 @Override @Transactional(rollbackFor = Exception.class) public String downAll(String ids) { List<Long> list = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList()); List<InsReport> insReports = insReportMapper.selectBatchIds(list); String zipFilePath = null; // 临时文件夹路径 try { String tempFolderPath = wordUrl + "/tempFolder"; File tempFolder = new File(tempFolderPath); if (tempFolder.exists()) { deleteDirectory(tempFolder); // 删除旧的临时文件夹 } tempFolder.mkdirs(); // 创建新的临时文件夹 for (InsReport insReport : insReports) { File sourceFile = new File((ObjectUtils.isNotEmpty(insReport.getUrlS()) ? insReport.getUrlS() : insReport.getUrl()).replace("/word", wordUrl)); File destinationFile = new File(tempFolder, sourceFile.getName()); Files.copy(sourceFile.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } // 压缩临时文件夹 zipFilePath = wordUrl + "/zip/output.zip"; zipDirectory(tempFolderPath, zipFilePath); // 清理临时文件夹 deleteDirectory(tempFolder); System.out.println("ZIP文件创建完成!"); } catch (IOException e) { e.printStackTrace(); } return "/word/zip/output.zip"; } //批量上传 @Override @Transactional(rollbackFor = Exception.class) public int upAll(MultipartFile file) throws IOException { File tempFile = null; File unzipDir = null; try { tempFile = File.createTempFile(wordUrl, ".zip"); file.transferTo(tempFile); unzipDir = new File("uploaded_files"); if (!unzipDir.exists()) { unzipDir.mkdir(); } unzip(tempFile, unzipDir); // 处理解压后的文件 File[] files = unzipDir.listFiles(); if (files != null) { for (File f : files) { // 根据文件名查询id String name = f.getName(); InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().like(InsReport::getCode, f.getName().replace(".docx", "").replace("JCZX", "JCZX/"))); if (ObjectUtils.isEmpty(insReport)) { throw new ErrorException("没有找到 " + f.getName() + " 这个文件对应的报告数据"); } String urlString; String pathName; try { String path = wordUrl; File realpath = new File(path); if (!realpath.exists()) { realpath.mkdirs(); } pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + f.getName(); urlString = realpath + "/" + pathName; // 复制文件到指定路径 Files.copy(f.toPath(), new File(urlString).toPath(), StandardCopyOption.REPLACE_EXISTING); inReport("/word/" + pathName, insReport.getId()); } catch (IOException e) { throw new ErrorException("文件上传失败"); } } } } catch (IOException e) { throw new ErrorException("文件处理失败"); } finally { if (tempFile != null && tempFile.exists()) { tempFile.delete(); } // 递归删除解压目录及其中的文件 if (unzipDir.exists()) { deleteDirectory(unzipDir); // 删除旧的临时文件夹 } } return 0; } //解压文件夹 private void unzip(File zipFile, File destDir) throws IOException { try (ZipFile zip = new ZipFile(zipFile)) { Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File file = new File(destDir, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); try (InputStream in = zip.getInputStream(entry); OutputStream out = new FileOutputStream(file)) { byte[] buffer = new byte[1024]; int len; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } } } } } } // 压缩文件夹 public static void zipDirectory(String sourceDirPath, String zipFilePath) throws IOException { try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFilePath))) { Path sourceDir = Paths.get(sourceDirPath); Files.walk(sourceDir) .filter(path -> !Files.isDirectory(path)) .forEach(path -> { ZipEntry zipEntry = new ZipEntry(sourceDir.relativize(path).toString()); try { zipOut.putNextEntry(zipEntry); Files.copy(path, zipOut); zipOut.closeEntry(); } catch (IOException e) { e.printStackTrace(); } }); } } // 删除文件夹及其内容 public static void deleteDirectory(File directory) throws IOException { if (directory.isDirectory()) { File[] files = directory.listFiles(); if (files != null) { for (File file : files) { deleteDirectory(file); } } } Files.delete(directory.toPath()); } @Override public void wordToPdf(String path,String sealUrl) { CompletableFuture.supplyAsync(() -> { @@ -290,6 +448,7 @@ /** * 切割图片 * * @param Path 图片路径 * @param n 切割份数 */ inspect-server/src/main/java/com/yuanchu/mom/service/impl/StandardProductListServiceImpl.java
@@ -75,8 +75,14 @@ } } String[] split1 = insSample.getFactory().split(" - "); //判断长度 if (split1.length > 3) { if (ObjectUtils.isNotEmpty(split1[3])){ list = list.stream().filter(list1 -> list1.getSample().equals(split1[3])).collect(Collectors.toList()); }else if (split1[3].equals("")) { list = list.stream().filter(list1 -> list1.getSampleType().equals(split1[2])).collect(Collectors.toList()); } } list = list.stream().filter(a -> { try { @@ -183,7 +189,8 @@ list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", standardTree2.getSample(), standardTree2.getModel(), tree2, trees[1])); list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + standardTree2.getSample() + "\"", standardTree2.getSample(), standardTree2.getModel(), tree2, trees[1])); } } else if (trees.length == 4) { } else if (trees.length == 4) { List<StandardTree> treeList = standardTreeMapper.selectList(Wrappers.<StandardTree>lambdaQuery().eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).eq(StandardTree::getSample, trees[3])); if (treeList.size() == 0) { StandardTree standardTree = new StandardTree(); @@ -198,7 +205,8 @@ list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", standardTree.getSample(), standardTree.getModel(), str, trees[1])); list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + trees[3] + "\"", standardTree.getSample(), standardTree.getModel(), str, trees[1])); } } else { } else { list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", trees[3].equals("null") ? null : trees[3], trees[4], tree, trees[1])); list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + trees[3] + "\"", trees[3].equals("null") ? null : trees[3], trees[4], tree, trees[1])); } @@ -272,7 +280,8 @@ a.setUpdateUser(userId); a.setStandardMethodListId(id); return a; }).collect(Collectors.toList()));; }).collect(Collectors.toList())); ; success = true; } catch (Exception e) { retryCount++; inspect-server/src/main/resources/mapper/InsOrderMapper.xml
@@ -6,6 +6,7 @@ <resultMap id="BaseResultMap" type="com.yuanchu.mom.pojo.InsOrder"> <id property="id" column="id" jdbcType="INTEGER"/> <result property="entrustCode" column="entrust_code" jdbcType="VARCHAR"/> <result property="outEntrustCode" column="out_entrust_code" jdbcType="VARCHAR"/> <result property="custom" column="custom" jdbcType="VARCHAR"/> <result property="company" column="company" jdbcType="VARCHAR"/> <result property="code" column="code" jdbcType="VARCHAR"/> inspect-server/src/main/resources/mapper/InsSampleMapper.xml
@@ -268,6 +268,7 @@ select name_en from `center-lims`.product where name = #{sample} limit 1 </select> <select id="selectSampleProductListByOrderId2" resultMap="sampleDto"> select isa.*, system-run/src/main/java/com/yuanchu/mom/backup/MysqlDataBackup.java
@@ -1,10 +1,14 @@ package com.yuanchu.mom.backup; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.yuanchu.mom.dto.PerformanceShiftAddDto; import com.yuanchu.mom.mapper.DepartmentLimsMapper; import com.yuanchu.mom.mapper.EnumMapper; import com.yuanchu.mom.pojo.DepartmentLims; import com.yuanchu.mom.pojo.Enums; import com.yuanchu.mom.pojo.PerformanceShift; import com.yuanchu.mom.pojo.User; import com.yuanchu.mom.service.DepartmentLimsService; import com.yuanchu.mom.service.EnumService; import com.yuanchu.mom.service.PerformanceShiftService; import com.yuanchu.mom.service.UserService; @@ -81,6 +85,9 @@ @Resource private UserService userService; @Resource private DepartmentLimsMapper departmentLimsMapper; /** * 每天晚上23点05秒执行 【 0 0 4 1/1 * ? 】 @@ -213,8 +220,8 @@ List<Enums> shiftType = enumService.selectEnumByCategory("班次类型"); List<String> collect = shiftType.stream().filter(enums -> enums.getLabel().equals("早")).map(enums -> enums.getValue()).collect(Collectors.toList()); performanceShiftAddDto.setShift(collect.get(0)); //人员--所有人 String userIds = userService.getDeviceManager().stream().map(user -> user.getId().toString()).distinct().collect(Collectors.joining(",")); //人员--(departlims表的两个实验室的人) String userIds = userService.getUser().stream().map(user -> user.getId().toString()).distinct().collect(Collectors.joining(",")); performanceShiftAddDto.setUserId(userIds); //周次--当月所有 // 获取当前日期 user-server/src/main/java/com/yuanchu/mom/mapper/UserMapper.java
@@ -23,4 +23,5 @@ User getCustom(Integer userId); List<User> getUser(); } user-server/src/main/java/com/yuanchu/mom/service/UserService.java
@@ -5,6 +5,7 @@ import com.yuanchu.mom.dto.UserPageDto; import com.yuanchu.mom.pojo.User; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -41,4 +42,5 @@ int delUserDepardLimsId(Integer id); List<User> getUser(); } user-server/src/main/java/com/yuanchu/mom/service/impl/UserServiceImp.java
@@ -196,4 +196,9 @@ public int delUserDepardLimsId(Integer id) { return userMapper.update(null, Wrappers.<User>lambdaUpdate().eq(User::getId, id).set(User::getDepartLimsId, null).set(User::getUpdateTime, LocalDateTime.now()).set(User::getUpdateUser, getLook.selectPowerByMethodAndUserId(null).get("userId"))); } @Override public List<User> getUser() { return userMapper.getUser(); } } user-server/src/main/resources/mapper/UserMapper.xml
@@ -44,4 +44,7 @@ left join custom c on u.company = c.id where u.id = #{userId} </select> <select id="getUser" resultType="com.yuanchu.mom.pojo.User"> select * from user where depart_lims_id=FIND_IN_SET(depart_lims_id, (select GROUP_CONCAT(id SEPARATOR ',') from department_lims where department_lims.name like '%实验室')) </select> </mapper>