From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master

---
 jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/LimsWendingxingFenxiController.java |  150 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 150 insertions(+), 0 deletions(-)

diff --git a/jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/LimsWendingxingFenxiController.java b/jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/LimsWendingxingFenxiController.java
new file mode 100644
index 0000000..fbc38a2
--- /dev/null
+++ b/jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/LimsWendingxingFenxiController.java
@@ -0,0 +1,150 @@
+package jnpf.limsController;
+
+import cn.dev33.satoken.annotation.SaCheckLogin;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jnpf.base.DictionaryDataApi;
+import jnpf.base.entity.DictionaryDataEntity;
+import jnpf.base.vo.DownloadVO;
+import jnpf.constant.FileTypeConstant;
+import jnpf.exception.DataException;
+import jnpf.file.FileUploadApi;
+import jnpf.limsEntity.LimsWendingxingFenxiDataVo;
+import jnpf.limsEntity.LimsWendingxingFenxiOptionsVo;
+import jnpf.limsEntity.LimsWendingxingFenxiParam;
+import jnpf.limsEntity.LimsWendingxingFenxiRowVo;
+import jnpf.limsController.export.LimsWendingxingFenxiWorkbookBuilder;
+import jnpf.limsService.LimsWendingxingFenxiService;
+import jnpf.util.R;
+import jnpf.util.ExcelUtil;
+import jnpf.util.UploaderUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.dromara.x.file.storage.core.FileInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+@Slf4j
+@Tag(name = "lims绋冲畾鎬ф暟鎹垎鏋�", description = "")
+@RestController
+@SaCheckLogin
+@RequestMapping("/lims/biz/wendingxing/fenxi")
+public class LimsWendingxingFenxiController {
+
+    @Autowired
+    private LimsWendingxingFenxiService fenxiService;
+
+    @Autowired
+    private FileUploadApi fileUploadApi;
+
+    @Autowired
+    private DictionaryDataApi dictionaryDataApi;
+
+    private final LimsWendingxingFenxiWorkbookBuilder workbookBuilder =
+            new LimsWendingxingFenxiWorkbookBuilder();
+
+    @Operation(summary = "绋冲畾鎬у垎鏋愮瓫閫夐�夐」")
+    @PostMapping("/options")
+    public R<LimsWendingxingFenxiOptionsVo> options(
+            @RequestBody(required = false) LimsWendingxingFenxiParam param) {
+        try {
+            return R.success(fenxiService.listOptions(
+                    param == null ? new LimsWendingxingFenxiParam() : param));
+        } catch (DataException e) {
+            return R.error(e.getMessage());
+        }
+    }
+
+    @Operation(summary = "绋冲畾鎬у垎鏋愭暟鎹�")
+    @PostMapping("/data")
+    public R<LimsWendingxingFenxiDataVo> data(@RequestBody LimsWendingxingFenxiParam param) {
+        String error = validateRequired(param);
+        if (error != null) {
+            return R.error(error);
+        }
+        try {
+            return R.success(fenxiService.listData(param));
+        } catch (DataException e) {
+            return R.error(e.getMessage());
+        }
+    }
+
+    @Operation(summary = "瀵煎嚭绋冲畾鎬ф暟鎹垎鏋愯〃")
+    @PostMapping("/export")
+    public R<DownloadVO> export(@RequestBody LimsWendingxingFenxiParam param) {
+        String error = validateRequired(param);
+        if (error != null) {
+            return R.error(error);
+        }
+
+        try {
+            List<LimsWendingxingFenxiRowVo> rows = fenxiService.listData(param).getRows();
+            if (rows.isEmpty()) {
+                throw new DataException("褰撳墠绛涢�夋潯浠舵病鏈夊彲瀵煎嚭鐨勫凡瀹℃牳鏁版嵁");
+            }
+            String suffix = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
+            String fileName = "绋冲畾鎬ф暟鎹垎鏋愯〃_"
+                    + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
+                    + "_" + suffix + ".xls";
+            FileInfo fileInfo;
+            try (Workbook workbook = workbookBuilder.build(rows, listPeriodUnits())) {
+                MultipartFile multipartFile =
+                        ExcelUtil.workbookToCommonsMultipartFile(workbook, fileName);
+                fileInfo = fileUploadApi.uploadFile(
+                        multipartFile, FileTypeConstant.TEMPORARY, fileName);
+            }
+            if (fileInfo == null || !StringUtils.hasText(fileInfo.getFilename())) {
+                throw new DataException("绋冲畾鎬ф暟鎹垎鏋愯〃涓婁紶鏂囦欢鏈嶅姟澶辫触");
+            }
+            DownloadVO download = DownloadVO.builder()
+                    .name(fileName)
+                    .url(UploaderUtil.uploaderFile(
+                            fileInfo.getFilename() + "#" + FileTypeConstant.TEMPORARY))
+                    .build();
+            return R.success(download);
+        } catch (DataException e) {
+            return R.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("绋冲畾鎬ф暟鎹垎鏋愯〃瀵煎嚭澶辫触", e);
+            return R.error("绋冲畾鎬ф暟鎹垎鏋愯〃瀵煎嚭澶辫触");
+        }
+    }
+
+    private List<DictionaryDataEntity> listPeriodUnits() {
+        try {
+            List<DictionaryDataEntity> units = dictionaryDataApi.getListByCode("zhouqiDanwei");
+            return units == null ? Collections.<DictionaryDataEntity>emptyList() : units;
+        } catch (Exception e) {
+            log.warn("璇诲彇鍛ㄦ湡鍗曚綅瀛楀吀 zhouqiDanwei 澶辫触锛屽鍑轰繚鐣欏師濮嬬紪鐮�", e);
+            return Collections.emptyList();
+        }
+    }
+
+    private String validateRequired(LimsWendingxingFenxiParam param) {
+        if (param == null) {
+            return "璇锋眰鍙傛暟涓嶈兘涓虹┖";
+        }
+        if (!StringUtils.hasText(param.getFenleiBianma())) {
+            return "鍒嗙被涓嶈兘涓虹┖";
+        }
+        if (!StringUtils.hasText(param.getYangpinId())) {
+            return "鍝佸悕涓嶈兘涓虹┖";
+        }
+        if (param.getXiangmuIds() == null || param.getXiangmuIds().isEmpty()) {
+            return "妫�楠岄」鐩笉鑳戒负绌�";
+        }
+        return null;
+    }
+
+}

--
Gitblit v1.8.0