From 0966fafc54a80ca6634d7020324a734d282e603c Mon Sep 17 00:00:00 2001
From: zyx <zyx123456>
Date: 星期五, 13 十月 2023 13:17:49 +0800
Subject: [PATCH] ERP单据上传用户名称

---
 src/main/java/com/zy/asrs/controller/OrderController.java |  159 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 151 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/OrderController.java b/src/main/java/com/zy/asrs/controller/OrderController.java
index de1f495..bccf4af 100644
--- a/src/main/java/com/zy/asrs/controller/OrderController.java
+++ b/src/main/java/com/zy/asrs/controller/OrderController.java
@@ -13,13 +13,24 @@
 import com.zy.asrs.service.*;
 import com.zy.common.model.DetlDto;
 import com.zy.common.web.BaseController;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.*;
 
+@Slf4j
 @RestController
 public class OrderController extends BaseController {
 
@@ -39,6 +50,8 @@
     private WrkMastLogService wrkMastLogService;
     @Autowired
     private LocDetlService locDetlService;
+    @Autowired
+    private MatService matService;
 
     @RequestMapping(value = "/order/nav/list/auth")
     @ManagerAuth
@@ -343,14 +356,14 @@
     @Transactional
     public R delete(@RequestParam Long orderId){
         orderService.remove(orderId);
-//        Order order = orderService.selectById(orderId);
-//        if (order != null) {
-//            order.setStatus(0);
-//        }
-//        if (!orderService.updateById(order)) {
-//            throw new CoolException("鍒犻櫎璁㈠崟澶辫触");
-//        }
-//        orderDetlService.modifyStatus(orderId, 0);
+        return R.ok();
+    }
+
+    @RequestMapping(value = "/order/report/auth")
+    @ManagerAuth(memo = "鎵嬪姩涓婁紶璁㈠崟")
+    @Transactional
+    public R report(@RequestParam Long orderId){
+        orderService.report(orderId,getUser().getUsername());
         return R.ok();
     }
 
@@ -391,4 +404,134 @@
         return R.ok();
     }
 
+    /*************************************** 鏁版嵁鐩稿叧 ***********************************************/
+
+    /**
+     * excel瀵煎叆
+     */
+    @PostMapping(value = "/order/excel/import/auth")
+    @ManagerAuth(memo = "閿�鍞崟Excel瀵煎叆")
+    @Transactional
+    public R cstmrExcelImport(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++) {
+            Row row = sheet.getRow(i);
+            // 璁㈠崟缂栧彿
+            String uuid = dataFormatter.formatCellValue(row.getCell(0));
+            // 鐗╂枡鍙�
+            String maktx = dataFormatter.formatCellValue(row.getCell(1));
+            // 鐗╂枡鍙�
+            String matnr = dataFormatter.formatCellValue(row.getCell(2));
+            // 鏁伴噺
+            Double anfme = Double.parseDouble(dataFormatter.formatCellValue(row.getCell(3)));
+            // 涓嬪崟鏃堕棿
+            String timeStr = dataFormatter.formatCellValue(row.getCell(4));
+            Date time = null;
+            try {
+                time = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss_F);
+            } catch (Exception e) {
+                throw new CoolException("绗�" + i + "琛屼笅鐨勯偅鏃堕棿瑙f瀽澶辫触锛岃閲嶆柊瀵煎叆锛�");
+            }
+            // 鍟嗗搧绯诲垪
+            String tagName = dataFormatter.formatCellValue(row.getCell(5));
+            // 瑙勬牸
+            String specs = dataFormatter.formatCellValue(row.getCell(6));
+
+            Mat mat = matService.selectByMatnr(matnr);
+            if (null == mat) {
+                throw new CoolException(matnr + "鍟嗗搧缂栫爜鐨勫晢鍝佷笉瀛樺湪锛岃閲嶆柊瀵煎叆锛�");
+            }
+
+            Order order = orderService.selectByNo(uuid);
+            if (null == order) {
+                order = new Order(
+                        String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
+                        uuid,    // 璁㈠崟缂栧彿
+                        timeStr,    // 鍗曟嵁鏃ユ湡
+                        14L,    // 鍗曟嵁绫诲瀷
+                        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("鐢熸垚鍗曟嵁涓绘。澶辫触锛岃閲嶆柊瀵煎叆锛�");
+                }
+            }
+
+            OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), matnr, null);
+            if (orderDetl == null) {
+                orderDetl = new OrderDetl();
+                orderDetl.sync(mat);
+                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.setStatus(1);
+                orderDetl.setQty(0.0D);
+                if (!orderDetlService.insert(orderDetl)) {
+                    throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃閲嶆柊瀵煎叆锛�");
+                }
+            } else {
+                if(!orderDetlService.increaseAnfme(order.getId(), matnr, null, anfme)) {
+                    throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃閲嶆柊瀵煎叆锛�");
+                }
+            }
+        }
+        return R.ok("瀵煎叆鎴愬姛");
+    }
+
 }

--
Gitblit v1.9.1