From 0379bbe120f509f8c330713958b59687d25b80b3 Mon Sep 17 00:00:00 2001
From: zhangc <zc@123>
Date: 星期六, 08 二月 2025 16:34:50 +0800
Subject: [PATCH] 兼容四期

---
 src/main/java/com/zy/asrs/controller/OrderController.java |  156 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 154 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/OrderController.java b/src/main/java/com/zy/asrs/controller/OrderController.java
index 29a40fd..a03bba3 100644
--- a/src/main/java/com/zy/asrs/controller/OrderController.java
+++ b/src/main/java/com/zy/asrs/controller/OrderController.java
@@ -1,6 +1,5 @@
 package com.zy.asrs.controller;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
@@ -31,7 +30,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.*;
-import java.util.stream.Collectors;
 
 @Slf4j
 @RestController
@@ -1320,6 +1318,160 @@
     }
 
 
+    /**
+     * excel瀵煎叆
+     */
+    @PostMapping(value = "/order/excel/import3/auth")
+    @ManagerAuth(memo = "鍗曟嵁Excel瀵煎叆")
+    @Transactional
+    public R cstmrExcelImport3(MultipartFile file) throws IOException {
+        InputStream inStream = file.getInputStream();
+        String fileMime = file.getContentType();
+        int excelVersion = 2007;
+        if ("application/vnd.ms-excel".equals(fileMime)) {
+            excelVersion = 2003;
+        }
+        Workbook book = null;
+        try {
+            if (excelVersion == 2003) {
+                book = new HSSFWorkbook(inStream);
+            } else {  // 褰� excel 鏄� 2007 鏃�
+                book = new XSSFWorkbook(inStream);
+            }
+        } catch (Exception e) {
+            log.error("fail", e);
+            return R.error("瀵煎叆鏂囦欢鏍煎紡閿欒锛岃浣跨敤xls鍚庣紑鐨勬枃浠讹紒");
+        }
+
+        Sheet sheet = book.getSheetAt(0);
+        int totalRows = sheet.getLastRowNum() + 1;    // 鎬�
+        Long userId = getUserId();
+        Date now = new Date();
+        DataFormatter dataFormatter = new DataFormatter();
+        for (int i = 1; i < totalRows; i++) {
+            Integer proSts = 0;
+            Row row = sheet.getRow(i);
+            //鍗曟嵁绫诲瀷
+            String docName = dataFormatter.formatCellValue(row.getCell(0)).trim();
+            //鍗曟嵁缂栧彿
+            String uuid = dataFormatter.formatCellValue(row.getCell(1)).trim();
+            //鐗╂枡鍙�
+            String matnr = dataFormatter.formatCellValue(row.getCell(2)).trim();
+            //閿�鍞崟鍙�
+            String csocode = dataFormatter.formatCellValue(row.getCell(3)).trim();
+            //鑷敱椤�
+            String isocode = dataFormatter.formatCellValue(row.getCell(4)).trim();
+            // 鏁伴噺
+            if (Cools.isEmpty(dataFormatter.formatCellValue(row.getCell(5)))) {
+                continue;
+            }
+            Double anfme = Double.parseDouble(dataFormatter.formatCellValue(row.getCell(5)));
+
+            Mat mat = matService.selectByMatnr(matnr);
+            if (null == mat) {
+                throw new CoolException(matnr + "鍟嗗搧缂栫爜鐨勫晢鍝佷笉瀛樺湪锛岃閲嶆柊瀵煎叆锛�");
+            }
+            DocType docType = docTypeService.selectOne(new EntityWrapper<DocType>().eq("doc_name", docName));
+
+            String odNo = uuid;
+            if (docName.contains("璋冩嫧鍗�")) {
+                odNo = "DB" + odNo;
+            } else if (docName.contains("鍔犲伐鍗�")) {
+                odNo = "JG" + odNo;
+            }else {
+                if (docType.getPakin() == 1) {
+                    odNo += "_I";
+                } else {
+                    odNo += "_O";
+                }
+            }
+            Date date = new Date();
+            Order order = orderService.selectByNo(odNo);
+            if (null == order) {
+                order = new Order(
+                        String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
+                        odNo,    // 璁㈠崟缂栧彿
+                        DateUtils.convert(date),    // 鍗曟嵁鏃ユ湡
+                        docType.getDocId(),    // 鍗曟嵁绫诲瀷
+                        null,    // 椤圭洰缂栧彿
+                        null,    //
+                        null,    // 璋冩嫧椤圭洰缂栧彿
+                        null,    // 鍒濆绁ㄦ嵁鍙�
+                        null,    // 绁ㄦ嵁鍙�
+                        null,    // 瀹㈡埛缂栧彿
+                        null,    // 瀹㈡埛
+                        null,    // 鑱旂郴鏂瑰紡
+                        null,    // 鎿嶄綔浜哄憳
+                        null,    // 鍚堣閲戦
+                        null,    // 浼樻儬鐜�
+                        null,    // 浼樻儬閲戦
+                        null,    // 閿�鍞垨閲囪喘璐圭敤鍚堣
+                        null,    // 瀹炰粯閲戦
+                        null,    // 浠樻绫诲瀷
+                        null,    // 涓氬姟鍛�
+                        null,    // 缁撶畻澶╂暟
+                        null,    // 閭垂鏀粯绫诲瀷
+                        null,    // 閭垂
+                        null,    // 浠樻鏃堕棿
+                        null,    // 鍙戣揣鏃堕棿
+                        null,    // 鐗╂祦鍚嶇О
+                        null,    // 鐗╂祦鍗曞彿
+                        1L,    // 璁㈠崟鐘舵��
+                        1,    // 鐘舵��
+                        userId,    // 娣诲姞浜哄憳
+                        now,    // 娣诲姞鏃堕棿
+                        userId,    // 淇敼浜哄憳
+                        now,    // 淇敼鏃堕棿
+                        null    // 澶囨敞
+                );
+                if (!orderService.insert(order)) {
+                    throw new CoolException("鐢熸垚鍗曟嵁涓绘。澶辫触锛岃閲嶆柊瀵煎叆锛�");
+                }
+            } else {
+                //  鏈夊師璁㈠崟鍦ㄧ殑鎯呭喌
+                DocType orderType = docTypeService.selectById(order.getDocType());
+                if (!orderType.getDocName().equals(docName)) {
+                    throw new CoolException("鏂拌鍗曪細" + uuid + " 涓庣郴缁熷唴鐨勮鍗曞彿鐩稿悓锛屽崟鎹被鍨嬩笉鍚屻�傝纭鏂拌鍗曞崟鎹被鍨嬶紒");
+                }
+                order.setSettle(order.getSettle() == 1L ? 1L : 2L);
+                orderService.updateById(order);
+            }
+
+            OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), matnr, null, csocode, isocode);
+            if (orderDetl == null) {
+                orderDetl = new OrderDetl();
+                orderDetl.sync(mat);
+                orderDetl.setSource(docType.getDocId().intValue());
+                orderDetl.setBatch(null);
+                orderDetl.setAnfme(anfme);
+                orderDetl.setOrderId(order.getId());
+                orderDetl.setOrderNo(order.getOrderNo());
+                orderDetl.setCreateBy(userId);
+                orderDetl.setCreateTime(now);
+                orderDetl.setUpdateBy(userId);
+                orderDetl.setUpdateTime(now);
+                orderDetl.setThreeCode(csocode);
+                orderDetl.setDeadTime(isocode);
+                orderDetl.setStatus(1);
+                orderDetl.setQty(0.0D);
+                orderDetl.setProcessSts(proSts);
+                if (!orderDetlService.insert(orderDetl)) {
+                    throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃閲嶆柊瀵煎叆锛�");
+                }
+            } else {
+                if (anfme < 0) {
+                    throw new CoolException("璁㈠崟鏁伴噺涓嶅厑璁镐负璐熸暟锛�");
+                }
+                if (!orderDetlService.increaseAnfme(order.getId(), matnr, null, anfme, csocode, isocode)) {
+                    throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃閲嶆柊瀵煎叆锛�");
+                }
+            }
+
+        }
+        return R.ok("瀵煎叆鎴愬姛");
+    }
+
+
 //    @RequestMapping(value = "/order/sync")
 //    @Transactional
 //    public R sync() {

--
Gitblit v1.9.1