From a6a6cb74f3cb3e647477838272687fdbf5929c26 Mon Sep 17 00:00:00 2001
From: zyx <zyx123456>
Date: 星期一, 16 十月 2023 16:30:16 +0800
Subject: [PATCH] 连接ERP 获取ERP库存信息

---
 src/main/webapp/views/inventoryVariance/inventoryVariance.html           |   57 +++
 src/main/java/com/zy/asrs/task/handler/OrderLogHandler.java              |   48 +++
 src/main/java/com/zy/common/service/erp/task/ErpScheduler.java           |   66 ---
 src/main/java/com/zy/asrs/task/OrderLogScheduler.java                    |   30 +
 src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java         |    2 
 src/main/java/com/zy/asrs/mapper/InventoryVarianceMapper.java            |    3 
 src/main/java/com/zy/asrs/service/InventoryVarianceService.java          |    1 
 src/main/java/com/zy/common/service/erp/entity/WlzhVStRd.java            |    6 
 src/main/java/com/zy/asrs/service/impl/InventoryVarianceServiceImpl.java |    5 
 src/main/java/com/zy/asrs/controller/InventoryVarianceController.java    |   55 +++
 src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java             |  101 -----
 src/main/webapp/static/js/inventoryVariance/inventoryVariance.js         |  566 +++++++++++++++++++++++++++++++++++
 src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java              |    4 
 src/main/java/com/zy/asrs/entity/InventoryVariance.java                  |    6 
 14 files changed, 797 insertions(+), 153 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/InventoryVarianceController.java b/src/main/java/com/zy/asrs/controller/InventoryVarianceController.java
new file mode 100644
index 0000000..606e673
--- /dev/null
+++ b/src/main/java/com/zy/asrs/controller/InventoryVarianceController.java
@@ -0,0 +1,55 @@
+package com.zy.asrs.controller;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.core.annotations.ManagerAuth;
+import com.core.common.DateUtils;
+import com.core.common.R;
+import com.zy.asrs.entity.InventoryVariance;
+import com.zy.asrs.service.InventoryVarianceService;
+import com.zy.common.web.BaseController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.Map;
+
+public class InventoryVarianceController extends BaseController {
+    @Autowired
+    private InventoryVarianceService inventoryVarianceService;
+
+    @RequestMapping(value = "/inventoryVariance/list/auth")
+    @ManagerAuth
+    public R list(@RequestParam(defaultValue = "1")Integer curr,
+                  @RequestParam(defaultValue = "10")Integer limit,
+                  @RequestParam(required = false)String orderByField,
+                  @RequestParam(required = false)String orderByType,
+                  @RequestParam(required = false)String condition,
+                  @RequestParam Map<String, Object> param,
+                  @RequestParam(required = false)Boolean unreason){
+
+        EntityWrapper<InventoryVariance> wrapper = new EntityWrapper<>();
+
+        excludeTrash(param);
+        convert(param, wrapper);
+        allLike(InventoryVariance.class, param.keySet(), wrapper, condition);
+
+        return R.ok(inventoryVarianceService.selectPage(new Page<>(curr, limit), wrapper));
+    }
+    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
+        for (Map.Entry<String, Object> entry : map.entrySet()){
+            String val = String.valueOf(entry.getValue());
+            if (val.contains(RANGE_TIME_LINK)){
+                String[] dates = val.split(RANGE_TIME_LINK);
+                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
+                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
+            } else {
+                if (entry.getKey().equals("locNo")) {
+                    wrapper.eq("loc_no", String.valueOf(entry.getValue()));
+                } else {
+                    wrapper.like(entry.getKey(), String.valueOf(entry.getValue()));
+                }
+            }
+        }
+    }
+}
diff --git a/src/main/java/com/zy/asrs/entity/InventoryVariance.java b/src/main/java/com/zy/asrs/entity/InventoryVariance.java
index 59beed6..537f3ed 100644
--- a/src/main/java/com/zy/asrs/entity/InventoryVariance.java
+++ b/src/main/java/com/zy/asrs/entity/InventoryVariance.java
@@ -16,15 +16,15 @@
     //閿�鍞鍗曡鍙�
     private String isoseq;
     //ERP瀛樿揣鏁伴噺
-    private Double iQuantity;
+    private Double iquantity;
     //绔嬪簱瀛樿揣鏁伴噺
     private Double anfme;
 
-    public InventoryVariance(String matnr, String csocode, String isoseq, Double iQuantity, Double anfme){
+    public InventoryVariance(String matnr, String csocode, String isoseq, Double iquantity, Double anfme){
         this.matnr = matnr;
         this.csocode = csocode;
         this.isoseq = isoseq;
-        this.iQuantity = iQuantity;
+        this.iquantity = iquantity;
         this.anfme = anfme;
     }
 }
diff --git a/src/main/java/com/zy/asrs/mapper/InventoryVarianceMapper.java b/src/main/java/com/zy/asrs/mapper/InventoryVarianceMapper.java
index 298dd11..e46be39 100644
--- a/src/main/java/com/zy/asrs/mapper/InventoryVarianceMapper.java
+++ b/src/main/java/com/zy/asrs/mapper/InventoryVarianceMapper.java
@@ -2,10 +2,13 @@
 
 import com.baomidou.mybatisplus.mapper.BaseMapper;
 import com.zy.asrs.entity.InventoryVariance;
+import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Mapper;
 import org.springframework.stereotype.Repository;
 
 @Mapper
 @Repository
 public interface InventoryVarianceMapper extends BaseMapper<InventoryVariance> {
+    @Delete("DELETE FROM inventory_variance")
+    public void deleteAll();
 }
diff --git a/src/main/java/com/zy/asrs/service/InventoryVarianceService.java b/src/main/java/com/zy/asrs/service/InventoryVarianceService.java
index 2117673..6868130 100644
--- a/src/main/java/com/zy/asrs/service/InventoryVarianceService.java
+++ b/src/main/java/com/zy/asrs/service/InventoryVarianceService.java
@@ -4,4 +4,5 @@
 import com.zy.asrs.entity.InventoryVariance;
 
 public interface InventoryVarianceService extends IService<InventoryVariance> {
+    public boolean deleteAll();
 }
diff --git a/src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java b/src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java
index c8b9ea2..db9685d 100644
--- a/src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java
+++ b/src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java
@@ -80,7 +80,7 @@
 
         getRequestParam(agvTaskCreateParam,agvWrkMastList);
 
-        return doHttpRequest(agvTaskCreateParam,"涓婃灦浠诲姟涓嬪彂",url, taskCreatePath,null,"127.0.0.1");
+        return doHttpRequest(agvTaskCreateParam,"鎼繍浠诲姟涓嬪彂",url, taskCreatePath,null,"127.0.0.1");
 
         //return containerMoveParam;
     }
diff --git a/src/main/java/com/zy/asrs/service/impl/InventoryVarianceServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/InventoryVarianceServiceImpl.java
index 8dd012b..330c666 100644
--- a/src/main/java/com/zy/asrs/service/impl/InventoryVarianceServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/InventoryVarianceServiceImpl.java
@@ -8,4 +8,9 @@
 
 @Service
 public class InventoryVarianceServiceImpl extends ServiceImpl<InventoryVarianceMapper, InventoryVariance> implements InventoryVarianceService {
+    @Override
+    public boolean deleteAll() {
+        this.baseMapper.deleteAll();
+        return true;
+    }
 }
diff --git a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
index b9e7d99..536b54f 100644
--- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -740,9 +740,9 @@
         order.setOrderNo(toString(param.get("id")));
         //涓氬姟绫诲瀷
         //order.setDefNumber(param.get("cBusType").toString());
-        order.setDefNumber(toString(param.get("cBusType")));
+        order.setDefNumber(toString(param.get("cVouchType")));
         //鍗曟嵁绫诲瀷
-        DocType docType = docTypeService.selectOrAdd(param.get("cVouchType").toString(), pakin);
+        DocType docType = docTypeService.selectOrAdd(param.get("cBusType").toString(), pakin);
         order.setDocType(docType.getDocId());
         //鍗曟嵁鏃ユ湡
         //order.setOrderTime(param.get("dDate").toString());
diff --git a/src/main/java/com/zy/asrs/task/OrderLogScheduler.java b/src/main/java/com/zy/asrs/task/OrderLogScheduler.java
new file mode 100644
index 0000000..ace63d7
--- /dev/null
+++ b/src/main/java/com/zy/asrs/task/OrderLogScheduler.java
@@ -0,0 +1,30 @@
+package com.zy.asrs.task;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class OrderLogScheduler {
+//    @Autowired
+//    private OrderLogHandler orderLogHandler;
+//    @Autowired
+//    private OrderService orderService;
+//
+//    @Value("${erp.enable}")
+//    private boolean isERP;
+//
+//    @Scheduled(cron = "0/10 * * * * ? ")
+//    private void execute(){
+//        List<Order> orders = orderService.selectToBeHistoryOrder(isERP);
+//        if (orders.isEmpty()) {
+//            return;
+//        }
+//        for (Order order : orders) {
+//            ReturnT<String> result = orderLogHandler.start(order);
+//            if (!result.isSuccess()) {
+//                log.error("鍗曟嵁妗orderNo={}]鍘嗗彶妗e鐞嗗け璐�", order.getOrderNo());
+//            }
+//        }
+//    }
+}
diff --git a/src/main/java/com/zy/asrs/task/handler/OrderLogHandler.java b/src/main/java/com/zy/asrs/task/handler/OrderLogHandler.java
new file mode 100644
index 0000000..5abd9df
--- /dev/null
+++ b/src/main/java/com/zy/asrs/task/handler/OrderLogHandler.java
@@ -0,0 +1,48 @@
+package com.zy.asrs.task.handler;
+import com.zy.asrs.task.AbstractHandler;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class OrderLogHandler extends AbstractHandler<String> {
+//    @Autowired
+//    private OrderService orderService;
+//    @Autowired
+//    private OrderDetlService orderDetlService;
+//    @Autowired
+//    private OrderLogService orderLogService;
+//    @Autowired
+//    private OrderDetlLogService orderDetlLogService;
+//
+//    @Transactional
+//    public ReturnT<String> start(Order order) {
+//        try {
+//            // 淇濆瓨鍗曟嵁涓绘。鍘嗗彶妗�
+//            if (!orderLogService.save(order.getOrderNo())) {
+//                exceptionHandle("淇濆瓨鍗曟嵁鍘嗗彶妗orderNo={0}]澶辫触", order.getOrderNo());
+//            }
+//            // 鍒犻櫎鍗曟嵁涓绘。
+//            if (!orderService.deleteById(order)) {
+//                exceptionHandle("鍒犻櫎鍗曟嵁涓绘。[orderNo={0}]澶辫触", order.getOrderNo());
+//            }
+//            // 淇濆瓨鍗曟嵁鏄庣粏妗e巻鍙叉。
+//            if (!orderDetlLogService.save(order.getOrderNo())) {
+//                exceptionHandle("淇濆瓨鍗曟嵁鏄庣粏鍘嗗彶妗orderNo={0}]澶辫触", order.getOrderNo());
+//            }
+//            // 鍒犻櫎宸ヤ綔鏄庣粏妗�
+//            if (!orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_no", order.getOrderNo()))) {
+//                exceptionHandle("鍒犻櫎鍗曟嵁鏄庣粏妗orderNo={0}]澶辫触", order.getOrderNo());
+//            }
+//
+//        } catch (Exception e) {
+//            log.error("fail", e);
+//            e.printStackTrace();
+//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+//            return FAIL.setMsg(e.getMessage());
+//        }
+//        return SUCCESS;
+//    }
+
+}
+
diff --git a/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java b/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
index 49b58a7..9da4362 100644
--- a/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
+++ b/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
@@ -4,6 +4,7 @@
 import com.alibaba.fastjson.JSONObject;
 import com.core.common.Cools;
 import com.core.exception.CoolException;
+import com.zy.asrs.entity.DocType;
 import com.zy.asrs.entity.Order;
 import com.zy.asrs.entity.OrderDetl;
 import com.zy.asrs.service.ApiLogService;
@@ -12,7 +13,6 @@
 import com.zy.asrs.service.OrderService;
 import com.zy.asrs.task.AbstractHandler;
 import com.zy.asrs.task.core.ReturnT;
-import com.zy.common.service.erp.ErpService;
 import com.zy.common.utils.HttpHandler;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,8 +41,6 @@
     private ApiLogService apiLogService;
     @Autowired
     private DocTypeService docTypeService;
-    @Autowired
-    private ErpService erpService;
 
     @Value("${u8.url}")
     private String url;
@@ -52,11 +50,23 @@
 
     @Transactional
     public ReturnT<String> start(Order order) {
+
+        DocType docType = docTypeService.selectById(order.getDocType());
+        if("鎵嬪姩鍑哄簱鍗�".equals(docType.getDocName())
+                || "鎵嬪姩鍏ュ簱鍗�".equals(docType.getDocName())
+                || "鑷姩琛ヨ揣鍗�".equals(docType.getDocName())
+                || "浜哄伐琛ヨ揣鍗�".equals(docType.getDocName())){
+            order.setSettle(8L);
+            orderService.updateById(order);
+            return SUCCESS;
+        }
+
+
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Map<String, Object> param = new HashMap<>();
         param.put("id",order.getOrderNo());
         param.put("dDate",sdf.format(new Date()));
-        param.put("cHandler","");
+        param.put("cHandler","WMS绯荤粺");
 
         List<Map<String,Object>> orderDetlsParam = new ArrayList<>();
         param.put("orderDetails",orderDetlsParam);
@@ -70,95 +80,12 @@
             orderDetlsParam.add(odMap);
         }
 
-//        Map<String, Object> param = new HashMap<>();
-//        param.put("id",order.getOrderNo());
-//        param.put("dDate",new Date());
-//        param.put("cHandler",9527);
-
         int code = doHttpRequest(param, "鍗曟嵁瀹℃牳", url, orderReportPath, null, "127.0.0.1");
         if(code == 0){
             order.setSettle(6L);
             orderService.updateById(order);
         }
 
-
-//        DocType docType = docTypeService.selectById(order.getDocType());
-//        if (null == docType) {
-//            return SUCCESS;
-//        }
-//        if (!Cools.isEmpty(docType.getMemo())) {
-//            if (docType.getMemo().equals("hand")) {
-//                // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
-//                if (!orderService.updateSettle(order.getId(), 6L, null)) {
-//                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
-//                }
-//                return SUCCESS;
-//            }
-//        }
-
-//        List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
-        // 鍏ュ簱瀹屾垚涓婃姤
-//        if (docType.getPakin() == 1) {
-//            try {
-//                // erp 鍚屾
-//                int state = 2;
-//                if (!erpService.updateStateForVoucher(order.getOrderNo(), state)) {
-//                    throw new CoolException(order.getOrderNo() + "璁㈠崟淇敼State涓�"+state+"澶辫触");
-//                } else {
-//                    erpService.updateTimeForVoucherDetail(order.getOrderNo());
-//                }
-//
-//                // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
-//                if (!orderService.updateSettle(order.getId(), 6L, null)) {
-//                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
-//                }
-//
-//            } catch (Exception e) {
-//                log.error("fail", e);
-//                return FAIL.setMsg(e.getMessage());
-//            }
-//        }
-//        // 鍑哄簱瀹屾垚涓婃姤
-//        if (docType.getPakout() == 1) {
-//            try {
-//                double TotalNum = 0.0;
-//                Integer TotalCount = orderDetls.size();
-//                // erp 鍚屾
-//                int state = 2;
-//                if (!erpService.updateStateForVoucher(order.getOrderNo(), state)) {
-//                    throw new CoolException(order.getOrderNo() + "璁㈠崟淇敼State涓�"+state+"澶辫触");
-//                } else {
-//                    Date now = new Date();
-//                    for (OrderDetl orderDetl : orderDetls) {
-//                        TotalNum = TotalNum + orderDetl.getAnfme();
-//                        if (null == erpService.selectVoucherDetail(order.getOrderNo(), orderDetl.getBatch())) {
-//                            VoucherDetail voucherDetail = new VoucherDetail();
-//                            voucherDetail.setVoucherID(order.getOrderNo());
-//                            voucherDetail.setPickID("fepvnn0496");
-//                            voucherDetail.setBarcode(orderDetl.getBatch());
-//                            voucherDetail.setLastUpdatedDate(DateUtils.convert(now));
-//                            if (!erpService.insertVoucherDetail(voucherDetail)) {
-//                                throw new CoolException(order.getOrderNo() + "璁㈠崟娣诲姞VoucherDetail"+ JSON.toJSONString(voucherDetail)+"澶辫触");
-//                            }
-//                        }
-//                    }
-//                }
-//                // 鏇存柊閲嶉噺鍜屾暟閲�
-//                if (!erpService.updateStateForVoucher(order.getOrderNo(), TotalNum, TotalCount)) {
-//                    throw new CoolException(order.getOrderNo() + "璁㈠崟淇敼閲嶉噺鍜屾暟閲忓け璐�");
-//                }
-//
-//                // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
-//                if (!orderService.updateSettle(order.getId(), 6L, null)) {
-//                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
-//                }
-//
-//            } catch (Exception e) {
-//                log.error("fail", e);
-//                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-//                return FAIL.setMsg(e.getMessage());
-//            }
-//        }
         return SUCCESS;
     }
 
diff --git a/src/main/java/com/zy/common/service/erp/entity/WlzhVStRd.java b/src/main/java/com/zy/common/service/erp/entity/WlzhVStRd.java
index f385dcd..8ca48da 100644
--- a/src/main/java/com/zy/common/service/erp/entity/WlzhVStRd.java
+++ b/src/main/java/com/zy/common/service/erp/entity/WlzhVStRd.java
@@ -16,10 +16,10 @@
     private String cWhName;
 
     //瀛樿揣缂栫爜
-    private String cInvCode;
+    private String cinvcode;
 
     //瑙勬牸鍨嬪彿
-    private String cInvStd;
+    private String cinvstd;
 
     //璁¢噺鍗曚綅
     private String cComUnitName;
@@ -28,7 +28,7 @@
     private String cinvdefine4;
 
     //鐜板瓨閲�
-    private Double iQuantity;
+    private Double iquantity;
 
     //閿�鍞鍗曞彿
     private String csocode;
diff --git a/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java b/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java
index 0b38dcd..9819fde 100644
--- a/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java
+++ b/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java
@@ -1,28 +1,20 @@
 package com.zy.common.service.erp.task;
 
-import com.core.common.Cools;
-import com.core.common.DateUtils;
-import com.core.exception.CoolException;
 import com.zy.asrs.entity.AllLocDetl;
 import com.zy.asrs.entity.InventoryVariance;
-import com.zy.asrs.entity.Mat;
-import com.zy.asrs.entity.Tag;
 import com.zy.asrs.service.AllLocDetlService;
 import com.zy.asrs.service.InventoryVarianceService;
 import com.zy.asrs.service.MatService;
 import com.zy.asrs.service.TagService;
 import com.zy.asrs.task.AbstractHandler;
 import com.zy.common.service.erp.ErpService;
-import com.zy.common.service.erp.entity.Goods;
 import com.zy.common.service.erp.entity.WlzhVStRd;
-import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -44,55 +36,17 @@
     @Autowired
     private InventoryVarianceService inventoryVarianceService;
 
-    //@Scheduled(cron = "0/5 * * * * ? ")
-    @Synchronized
-    @Transactional
-    public synchronized void syncMat() {
-        Tag top = tagService.getTop();
-        List<Goods> goods = erpService.selectGoods(0);
-        Date now = new Date();
-        if (!Cools.isEmpty(goods)) {
-            for (Goods good : goods) {
-                Mat mat = matService.selectByMatnr(good.getMaterialNO());
-                if (mat == null) {
-                    mat = new Mat();
-                    mat.setTagId(top.getId());
-                    mat.setMatnr(good.getMaterialNO());
-//                    mat.setMaktx(good.getBarCode());
-                    mat.setSpecs(good.getProdSpec());
-                    mat.setModel(good.getBatch());
-                    mat.setWeight(good.getNWT());
-                    mat.setUnits(good.getNumOfBobbins()==null?null:good.getNumOfBobbins().doubleValue());
-                    mat.setManuDate(good.getProdDate());
 
-                    mat.setCreateTime(now);
-                    mat.setSku(good.getLocation());
-                    if (!Cools.isEmpty(good.getLastUpdatedDate())) {
-                        mat.setUpdateTime(DateUtils.convert(good.getLastUpdatedDate().substring(0, 19)));
-                    }
-
-                    if (!matService.insert(mat)) {
-                        throw new CoolException(good.getBarCode() + "鍟嗗搧鍚屾澶辫触");
-                    }
-                }
-                int state = 1;
-                if (!erpService.updateStateForGoods(good.getBarCode(), state)) {
-                    throw new CoolException(good.getBarCode() + "鍟嗗搧淇敼State涓�"+state+"澶辫触");
-                }
-            }
-        }
-    }
-
-    //@Scheduled(cron = "0/5 * * * * ? ")
-    @Synchronized
-    @Transactional
+    @Scheduled(cron = "0 0 2 * * ? ")
     public void syncLocDetl(){
+        log.info("搴撳瓨宸紓淇℃伅娓呴櫎");
+        inventoryVarianceService.deleteAll();
 
-        List<InventoryVariance> inventoryVariances = new ArrayList<>();
-
+        log.info("涓嶦RP姣斿寮�濮�");
         int pageSize = 500;
         int pageNumber = 0;
         while (true){
+            List<InventoryVariance> inventoryVariances = new ArrayList<>();
             List<WlzhVStRd> wlzhVStRds = erpService.selectPage(pageSize, pageNumber);
             if(wlzhVStRds.size() < pageSize){
                 break;
@@ -101,19 +55,17 @@
             //ERP搴撳瓨涓庣珛搴撳簱瀛樻瘮瀵�
             compileStock(wlzhVStRds,inventoryVariances);
             pageNumber ++;
-
+            inventoryVarianceService.insertBatch(inventoryVariances);
         }
-
-        inventoryVarianceService.insertBatch(inventoryVariances);
 
     }
 
     private void compileStock(List<WlzhVStRd> wlzhVStRds, List<InventoryVariance> inventoryVariances){
         wlzhVStRds.forEach(wlzhVStRd -> {
-            String matnr = wlzhVStRd.getCInvCode();
+            String matnr = wlzhVStRd.getCinvcode();
             String csocode = wlzhVStRd.getCsocode();
             String isoseq = wlzhVStRd.getIsoseq();
-            Double iQuantity = wlzhVStRd.getIQuantity();
+            Double iQuantity = wlzhVStRd.getIquantity();
 
             Double anfme = 0.0;
 
diff --git a/src/main/webapp/static/js/inventoryVariance/inventoryVariance.js b/src/main/webapp/static/js/inventoryVariance/inventoryVariance.js
new file mode 100644
index 0000000..de55347
--- /dev/null
+++ b/src/main/webapp/static/js/inventoryVariance/inventoryVariance.js
@@ -0,0 +1,566 @@
+var pageCurr;
+var tableData;
+function getCol() {
+    var cols = [
+        {field: 'matnr', align: 'center',title: '瀛樿揣缂栫爜'}
+        ,{field: 'csocode', align: 'center',title: '閿�鍞鍗曞彿', sort:true}
+        ,{field: 'isoseq', align: 'center',title: '閿�鍞鍗曡鍙�', sort:true}
+        ,{field: 'iquantity', align: 'center',title: 'ERP瀛樿揣鏁伴噺', sort:true}
+        ,{field: 'anfme', align: 'center',title: '绔嬪簱瀛樿揣鏁伴噺', hide: false}
+    ];
+
+    return cols;
+}
+
+layui.use(['table','laydate', 'form'], function(){
+    var table = layui.table;
+    var $ = layui.jquery;
+    var layer = layui.layer;
+    var layDate = layui.laydate;
+    var form = layui.form;
+
+    // 鏁版嵁娓叉煋
+    tableIns = table.render({
+        elem: '#locDetl',
+        headers: {token: localStorage.getItem('token')},
+        url: baseUrl+'/inventoryVariance/list/auth',
+        page: true,
+        limit: 20,
+        where:{
+          unreason: false
+        },
+        limits: [20, 30, 50, 100, 200, 500],
+        even: true,
+        toolbar: '#toolbar',
+        cellMinWidth: 50,
+        cols: [getCol()],
+        request: {
+            pageName: 'curr',
+            pageSize: 'limit'
+        },
+        parseData: function (res) {
+            return {
+                'code': res.code,
+                'msg': res.msg,
+                'count': res.data.total,
+                'data': res.data.records
+            }
+        },
+        response: {
+            statusCode: 200
+        },
+        done: function(res, curr, count) {
+            if (res.code === 403) {
+                top.location.href = baseUrl+"/";
+            }
+            tableData = table.cache.locDetl;
+            pageCurr=curr;
+            limit();
+            form.on('checkbox(tableCheckbox)', function (data) {
+                var _index = $(data.elem).attr('table-index')||0;
+                if(data.elem.checked){
+                    res.data[_index][data.value] = 'Y';
+                }else{
+                    res.data[_index][data.value] = 'N';
+                }
+            });
+        }
+    });
+
+    // 鐩戝惉鎺掑簭浜嬩欢
+    table.on('sort(locDetl)', function (obj) {
+        var searchData = {};
+        $.each($('#search-box [name]').serializeArray(), function() {
+            searchData[this.name] = this.value;
+        });
+        searchData['orderByField'] = obj.field;
+        searchData['orderByType'] = obj.type;
+        tableIns.reload({
+            where: searchData,
+            page: {
+                curr: 1
+            },
+            done: function (res, curr, count) {
+                if (res.code === 403) {
+                    top.location.href = baseUrl+"/";
+                }
+                pageCurr=curr;
+                limit();
+            }
+        });
+    });
+
+    // 鐩戝惉澶村伐鍏锋爮浜嬩欢
+    table.on('toolbar(locDetl)', function (obj) {
+        var checkStatus = table.checkStatus(obj.config.id);
+        switch(obj.event) {
+            case 'addData':
+                layer.open({
+                    type: 2,
+                    title: '鏂板',
+                    maxmin: true,
+                    area: [top.detailWidth, top.detailHeight],
+                    shadeClose: false,
+                    content: 'locDetl_detail.html',
+                    success: function(layero, index){
+                        layer.getChildFrame('#data-detail-submit-edit', index).hide();
+                    	clearFormVal(layer.getChildFrame('#detail', index));
+                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
+                    }
+                });
+                break;
+            case 'refreshData':
+                tableIns.reload({
+                    page: {
+                        curr: pageCurr
+                    }
+                });
+                limit();
+                break;
+            case 'deleteData':
+                var data = checkStatus.data;
+                if (data.length === 0){
+                    layer.msg('璇烽�夋嫨鏁版嵁');
+                } else {
+                    layer.confirm('纭畾鍒犻櫎'+(data.length===1?'姝�':data.length)+'鏉℃暟鎹悧', function(){
+                        $.ajax({
+                            url: baseUrl+"/locDetl/delete/auth",
+                            headers: {'token': localStorage.getItem('token')},
+                            data: {param: JSON.stringify(data)},
+                            method: 'POST',
+                            traditional:true,
+                            success: function (res) {
+                                if (res.code === 200){
+                                    layer.closeAll();
+                                    tableReload(false);
+                                } else if (res.code === 403){
+                                    top.location.href = baseUrl+"/";
+                                } else {
+                                    layer.msg(res.msg)
+                                }
+                            }
+                        })
+                    });
+                }
+                break;
+            case 'exportData':
+                layer.confirm('纭畾瀵煎嚭Excel鍚�', {shadeClose: true}, function(){
+                    var titles=[];
+                    var fields=[];
+                    obj.config.cols[0].map(function (col) {
+                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
+                            titles.push(col.title);
+                            fields.push(col.field);
+                        }
+                    });
+                    var exportData = {};
+                    $.each($('#search-box [name]').serializeArray(), function() {
+                        exportData[this.name] = this.value;
+                    });
+                    var param = {
+                        'locDetl': exportData,
+                        'fields': fields
+                    };
+                    var loadIndex = layer.msg('姝e湪瀵煎嚭...', {icon: 16, shade: 0.01, time: false});
+                    $.ajax({
+                        url: baseUrl+"/locDetl/export/auth",
+                        headers: {'token': localStorage.getItem('token')},
+                        data: JSON.stringify(param),
+                        dataType:'json',
+                        contentType:'application/json;charset=UTF-8',
+                        method: 'POST',
+                        success: function (res) {
+                            layer.close(loadIndex);
+                            layer.closeAll();
+                            if (res.code === 200) {
+                                table.exportFile(titles,res.data,'xls');
+                            } else if (res.code === 403) {
+                                top.location.href = baseUrl+"/";
+                            } else {
+                                layer.msg(res.msg)
+                            }
+                        }
+                    });
+                });
+                break;
+        }
+    });
+
+    // 鐩戝惉琛屽伐鍏蜂簨浠�
+    table.on('tool(locDetl)', function(obj){
+        var data = obj.data;
+        switch (obj.event) {
+            // 璇︽儏
+            case 'detail':
+                layer.open({
+                    type: 2,
+                    title: '璇︽儏',
+                    maxmin: true,
+                    area: [top.detailWidth, top.detailHeight],
+                    shadeClose: false,
+                    content: 'locDetl_detail.html',
+                    success: function(layero, index){
+                        setFormVal(layer.getChildFrame('#detail', index), data, true);
+                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
+                        layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide();
+                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
+                        layero.find('iframe')[0].contentWindow.layui.form.render('select');
+                        layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
+                    }
+                });
+                break;
+            // 缂栬緫
+            case 'edit':
+                layer.open({
+                    type: 2,
+                    title: '淇敼',
+                    maxmin: true,
+                    area: [top.detailWidth, top.detailHeight],
+                    shadeClose: false,
+                    content: 'locDetl_detail.html',
+                    success: function(layero, index){
+                        layer.getChildFrame('#data-detail-submit-save', index).hide();
+                        setFormVal(layer.getChildFrame('#detail', index), data, false);
+                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
+                        top.convertDisabled(layer.getChildFrame('#locNo,#matnr', index), true);
+                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
+                        layero.find('iframe')[0].contentWindow.layui.form.render('select');
+                        layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
+                    }
+                });
+                break;
+            case 'locNo':
+                var param = top.reObject(data).locNo;
+                if (param === undefined) {
+                    layer.msg("鏃犳暟鎹�");
+                } else {
+                   layer.open({
+                       type: 2,
+                       title: '搴撲綅鍙疯鎯�',
+                       maxmin: true,
+                       area: [top.detailWidth, top.detailHeight],
+                       shadeClose: false,
+                       content: '../locMast/locMast_detail.html',
+                       success: function(layero, index){
+                           $.ajax({
+                               url: baseUrl+"/locMast/"+ param +"/auth",
+                               headers: {'token': localStorage.getItem('token')},
+                               method: 'GET',
+                               success: function (res) {
+                                   if (res.code === 200){
+                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
+                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
+                                       layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide();
+                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
+                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
+                                       layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
+                                   } else if (res.code === 403){
+                                       parent.location.href = "/";
+                                   }else {
+                                       layer.msg(res.msg)
+                                   }
+                               }
+                           })
+                       }
+                   });
+                }
+                break;
+            case 'modiUser':
+                var param = top.reObject(data).modiUser;
+                if (param === undefined) {
+                    layer.msg("鏃犳暟鎹�");
+                } else {
+                   layer.open({
+                       type: 2,
+                       title: '淇敼浜哄憳璇︽儏',
+                       maxmin: true,
+                       area: [top.detailWidth, top.detailHeight],
+                       shadeClose: false,
+                       content: '../user/user_detail.html',
+                       success: function(layero, index){
+                           $.ajax({
+                               url: baseUrl+"/user/"+ param +"/auth",
+                               headers: {'token': localStorage.getItem('token')},
+                               method: 'GET',
+                               success: function (res) {
+                                   if (res.code === 200){
+                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
+                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
+                                       layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide();
+                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
+                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
+                                       layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
+                                   } else if (res.code === 403){
+                                       parent.location.href = "/";
+                                   }else {
+                                       layer.msg(res.msg)
+                                   }
+                               }
+                           })
+                       }
+                   });
+                }
+                break;
+            case 'appeUser':
+                var param = top.reObject(data).appeUser;
+                if (param === undefined) {
+                    layer.msg("鏃犳暟鎹�");
+                } else {
+                   layer.open({
+                       type: 2,
+                       title: '鍒涘缓鑰呰鎯�',
+                       maxmin: true,
+                       area: [top.detailWidth, top.detailHeight],
+                       shadeClose: false,
+                       content: '../user/user_detail.html',
+                       success: function(layero, index){
+                           $.ajax({
+                               url: baseUrl+"/user/"+ param +"/auth",
+                               headers: {'token': localStorage.getItem('token')},
+                               method: 'GET',
+                               success: function (res) {
+                                   if (res.code === 200){
+                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
+                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
+                                       layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide();
+                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
+                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
+                                       layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
+                                   } else if (res.code === 403){
+                                       parent.location.href = "/";
+                                   }else {
+                                       layer.msg(res.msg)
+                                   }
+                               }
+                           })
+                       }
+                   });
+                }
+                break;
+
+        }
+    });
+
+    // 鏁版嵁淇濆瓨鍔ㄤ綔
+    form.on('submit(save)', function () {
+        if (banMsg != null){
+            layer.msg(banMsg);
+            return;
+        }
+        method("add");
+    });
+
+    // 鏁版嵁淇敼鍔ㄤ綔
+    form.on('submit(edit)', function () {
+        method("update")
+    });
+
+    function method(name){
+        var index = layer.load(1, {
+            shade: [0.5,'#000'] //0.1閫忔槑搴︾殑鑳屾櫙
+        });
+        var data = {
+//            id: $('#id').val(),
+            locNo: $('#locNo').val(),
+            matnr: $('#matnr').val(),
+            lgnum: $('#lgnum').val(),
+            tbnum: $('#tbnum').val(),
+            tbpos: $('#tbpos').val(),
+            zmatid: $('#zmatid').val(),
+            maktx: $('#maktx').val(),
+            werks: $('#werks').val(),
+            anfme: $('#anfme').val(),
+            altme: $('#altme').val(),
+            zpallet: $('#zpallet').val(),
+            bname: $('#bname').val(),
+            memo: $('#memo').val(),
+            modiUser: $('#modiUser').val(),
+            modiTime: top.strToDate($('#modiTime\\$').val()),
+            appeUser: $('#appeUser').val(),
+            appeTime: top.strToDate($('#appeTime\\$').val()),
+
+        };
+        $.ajax({
+            url: baseUrl+"/locDetl/"+name+"/auth",
+            headers: {'token': localStorage.getItem('token')},
+            data: top.reObject(data),
+            method: 'POST',
+            success: function (res) {
+                if (res.code === 200){
+                    parent.layer.closeAll();
+                    parent.$(".layui-laypage-btn")[0].click();
+                    $("#data-detail :input").each(function () {
+                        $(this).val("");
+                    });
+                } else if (res.code === 403){
+                    top.location.href = baseUrl+"/";
+                }else {
+                    layer.msg(res.msg)
+                }
+                layer.close(index);
+            }
+        })
+    }
+
+    // 澶嶉�夋浜嬩欢
+    form.on('checkbox(detailCheckbox)', function (data) {
+        var el = data.elem;
+        if (el.checked) {
+            $(el).val('Y');
+        } else {
+            $(el).val('N');
+        }
+    });
+
+    // 鎼滅储鏍忔悳绱簨浠�
+    form.on('submit(search)', function (data) {
+        pageCurr = 1;
+        tableReload(false);
+    });
+
+
+    // 鎼滅储鏍忛噸缃簨浠�
+    form.on('submit(reset)', function (data) {
+        pageCurr = 1;
+        clearFormVal($('#search-box'));
+        tableReload(false);
+    });
+
+    //鏌ョ湅寮傚父鏁版嵁
+    form.on('submit(unreason)', function (data) {
+        pageCurr = 1;
+
+        tableIns.reload({
+            where: {
+                unreason: true
+            },
+            page: {
+                curr: pageCurr
+            },
+            done: function (res, curr, count) {
+
+                if (res.code === 403) {
+                    top.location.href = baseUrl+"/";
+                }
+                pageCurr=curr;
+
+                limit(child);
+            }
+        });
+    });
+
+    // 鏃堕棿閫夋嫨鍣�
+    layDate.render({
+        elem: '#modiTime\\$',
+        type: 'datetime'
+    });
+    layDate.render({
+        elem: '#appeTime\\$',
+        type: 'datetime'
+    });
+
+    form.on('switch(stockFreezeSwitch)', function (obj) {
+        let index  = obj.othis.parents('tr').attr("data-index");
+        let data = tableData[index];
+        data[this.stockFreeze] = obj.elem.checked?1:0;
+        http.post(baseUrl + "/locDetl/updateStockFreeze/auth", {
+            locNo: data.locNo,
+            matnr: data.matnr,
+            stockFreeze: data[this.stockFreeze]
+        }, function (res) {
+            layer.msg(res.msg, {icon: 1});
+        });
+    })
+
+
+});
+
+// 鍏抽棴鍔ㄤ綔
+$(document).on('click','#data-detail-close', function () {
+    parent.layer.closeAll();
+});
+
+function tableReload(child) {
+    var searchData = {
+        unreason: false
+    };
+    $.each($('#search-box [name]').serializeArray(), function() {
+        searchData[this.name] = this.value;
+    });
+    (child ? parent.tableIns : tableIns).reload({
+        where: searchData,
+        page: {
+            curr: pageCurr
+        },
+        done: function (res, curr, count) {
+            if (res.code === 403) {
+                top.location.href = baseUrl+"/";
+            }
+            pageCurr=curr;
+            if (res.data.length === 0 && count !== 0) {
+                tableIns.reload({
+                    where: searchData,
+                    page: {
+                        curr: pageCurr-1
+                    }
+                });
+                pageCurr -= 1;
+            }
+            limit(child);
+        }
+    });
+}
+
+function setFormVal(el, data, showImg) {
+    for (var val in data) {
+        var find = el.find(":input[id='" + val + "']");
+        if (find[0]!=null){
+            if (find[0].type === 'checkbox'){
+                if (data[val]==='Y'){
+                    find.attr("checked","checked");
+                    find.val('Y');
+                } else {
+                    find.remove("checked");
+                    find.val('N');
+                }
+                continue;
+            }
+        }
+        find.val(data[val]);
+        if (showImg){
+            var next = find.next();
+            if (next.get(0)){
+                if (next.get(0).localName === "img") {
+                    find.hide();
+                    next.attr("src", data[val]);
+                    next.show();
+                }
+            }
+        }
+    }
+}
+
+function clearFormVal(el) {
+    $(':input', el)
+        .val('')
+        .removeAttr('checked')
+        .removeAttr('selected');
+}
+
+function detailScreen(index) {
+    var detail = layer.getChildFrame('#data-detail', index);
+    var height = detail.height()+60;
+    if (height > ($(window).height()*0.9)) {
+        height = ($(window).height()*0.8);
+    }
+    layer.style(index, {
+//        top: (($(window).height()-height)/3)+"px",
+        height: height+'px'
+    });
+}
+
+$('body').keydown(function () {
+    if (event.keyCode === 13) {
+        $("#search").click();
+    }
+});
diff --git a/src/main/webapp/views/inventoryVariance/inventoryVariance.html b/src/main/webapp/views/inventoryVariance/inventoryVariance.html
new file mode 100644
index 0000000..eaa94f3
--- /dev/null
+++ b/src/main/webapp/views/inventoryVariance/inventoryVariance.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title></title>
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
+    <link rel="stylesheet" href="../../static/css/cool.css" media="all">
+    <link rel="stylesheet" href="../../static/css/common.css" media="all">
+</head>
+<body>
+
+<!-- 鎼滅储鏍� -->
+<div id="search-box" class="layui-form layui-card-header">
+    <div class="layui-inline">
+        <div class="layui-input-inline">
+            <input class="layui-input" type="text" name="condition" placeholder="璇疯緭鍏�" autocomplete="off">
+        </div>
+    </div>
+
+    <!-- 寰呮坊鍔� -->
+    <div id="data-search-btn" class="layui-btn-container layui-form-item" style="display: inline-block">
+        <button id="search" class="layui-btn layui-btn-primary layui-btn-radius" lay-submit lay-filter="search">鎼滅储</button>
+        <button id="reset" class="layui-btn layui-btn-primary layui-btn-radius" lay-submit lay-filter="reset">閲嶇疆</button>
+        <button id="unreason" class="layui-btn layui-btn-primary layui-btn-radius" lay-submit lay-filter="unreason">鏌ョ湅寮傚父鏁版嵁</button>
+    </div>
+
+</div>
+
+<!-- 琛ㄦ牸 -->
+<div class="layui-form">
+    <table class="layui-hide" id="locDetl" lay-filter="locDetl"></table>
+</div>
+<script type="text/html" id="toolbar">
+    <div class="layui-btn-container">
+        <button class="layui-btn layui-btn-primary layui-btn-sm" id="btn-export" lay-event="exportData" style="margin-top: 10px">瀵煎嚭</button>
+    </div>
+</script>
+
+<script type="text/html" id="operate">
+    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">璇︽儏</a>
+</script>
+
+
+<script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script>
+<script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script>
+<script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
+<script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script>
+<script type="text/javascript" src="../../static/js/inventoryVariance/inventoryVariance.js" charset="utf-8"></script>
+
+<iframe id="detail-iframe" scrolling="auto" style="display:none;"></iframe>
+
+</body>
+</html>
+

--
Gitblit v1.9.1