From d43eafe0983ddc7f76c2e1fe77b81a38ad86920c Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 14 Apr 2021 16:30:07 +0800
Subject: [PATCH] 20210413 后台订单管理修改

---
 zq-erp/src/main/resources/templates/views/admin/shop/shopOrder-list.html       |   64 ++++++++++++++-
 zq-erp/src/main/resources/templates/views/admin/shop/logisticsImport-form.html |    2 
 zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopOrderAction.java     |  138 ++++++++++++++++++++++++++++------
 zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderDao.xml              |    2 
 zq-erp/src/main/java/com/matrix/system/shopXcx/vo/LogisticsImportVo.java       |   14 ++-
 5 files changed, 184 insertions(+), 36 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopOrderAction.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopOrderAction.java
index 7d133fd..7b7cdc0 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopOrderAction.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopOrderAction.java
@@ -81,6 +81,8 @@
     //记录编辑前的值Before_Edit_Value
     public static final String BEV = "ShopOrder_BEV";
 
+    public static final List<LogisticsImportVo> logisticsImportVoLists = new ArrayList<>();
+
     @Value("${evn}")
     private String evn;
     
@@ -107,16 +109,65 @@
         AjaxResult ajaxResult = new AjaxResult();
         List<LogisticsImportVo> logisticsImportVos = logisticsImportFile(saveFile);
         if(CollUtil.isNotEmpty(logisticsImportVos)){
-            for(LogisticsImportVo logisticsImportVo : logisticsImportVos){
-                infoRemind = infoRemind + logisticsImportVo.getRemark()+";";
-            }
-            ajaxResult = AjaxResult.buildSuccessInstance(infoRemind);
+            ajaxResult = AjaxResult.buildSuccessInstance("部分数据导入失败");
             ajaxResult.setStatus(AjaxResult.STATUS_FAIL);
         }else{
             ajaxResult = AjaxResult.buildSuccessInstance("导入成功");
             ajaxResult.setStatus(AjaxResult.STATUS_SUCCESS);
         }
         return ajaxResult;
+    }
+
+    @RequestMapping(value = "/exportLogisticsImportExcel")
+    public void exportLogisticsImportExcel(HttpServletResponse res) {
+        OutputStream os = null;
+        try {
+            res.setCharacterEncoding("UTF-8");
+            res.setHeader("content-type", "application/octet-stream;charset=UTF-8");
+            res.setContentType("application/octet-stream;charset=UTF-8");
+            Date date = new Date();
+            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss");
+            res.setHeader("Content-Disposition", "attachment;filename=" +
+                    java.net.URLEncoder.encode("快递单导入列表" + dateFormat.format(date) + ".xls".trim(), "UTF-8"));
+
+            os = res.getOutputStream();
+            ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, disPoseLogisticsImportExcel(logisticsImportVoLists), os, true);
+            logisticsImportVoLists.clear();
+        } catch (Exception e) {
+            LogUtil.error("快递单导入异常", e);
+        } finally {
+            if (os != null) {
+                try {
+                    os.close();
+                } catch (IOException e) {
+                    LogUtil.error("关闭资源异常", e);
+                }
+            }
+        }
+    }
+    private List<ExcelSheetPO> disPoseLogisticsImportExcel(List<LogisticsImportVo> logisticsImportVos) {
+        List<ExcelSheetPO> res = new ArrayList<>();
+        ExcelSheetPO orderSheet = new ExcelSheetPO();
+        orderSheet.setSheetName("快递单导入");
+        orderSheet.setTitle("快递单导入失败列表");
+        String[] header = new String[]{"订单编号", "物流公司编码", "物流公司名称", "快递单号", "失败原因"};
+        orderSheet.setHeaders(header);
+        List<List<Object>> body = new ArrayList<>();
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
+        if(CollUtil.isNotEmpty(logisticsImportVos)){
+            for (LogisticsImportVo logisticsImportVo : logisticsImportVos) {
+                List<Object> bodyItem = new ArrayList<>();
+                bodyItem.add(logisticsImportVo.getOrderNo());
+                bodyItem.add(logisticsImportVo.getLogisticsCompanyCode());
+                bodyItem.add(logisticsImportVo.getLogisticsCompany());
+                bodyItem.add(logisticsImportVo.getWaybillNo());
+                bodyItem.add(logisticsImportVo.getFailReason());
+                body.add(bodyItem);
+            }
+        }
+        orderSheet.setDataList(body);
+        res.add(orderSheet);
+        return res;
     }
     
     public List<LogisticsImportVo> logisticsImportFile(File file) throws IOException {
@@ -132,8 +183,9 @@
                      * 订单处于【待付款】【待配送】【待收货】都可以导入
                      * 其他状态生成一个提示
                      */
+
+                    LogisticsImportVo logisticsImportVo = new LogisticsImportVo();
 					List<Object> objects = dataList.get(j);
-					ShopDeliveryInfo shopDeliveryInfo = new ShopDeliveryInfo();
 					//订单编号
 					String orderNo = objects.get(0).toString();
                     ShopOrder shopOrder = shopOrderDao.selectShopOrderByOrderNo(orderNo);
@@ -146,29 +198,65 @@
                         String logisticsCompany = objects.get(2).toString();
                         //快递单号
                         String waybillNo = objects.get(3).toString();
-                        shopDeliveryInfo.setOrderNo(orderNo);
-                        shopDeliveryInfo.setLogisticsCompanyCode(logisticsCompanyCode);
-                        shopDeliveryInfo.setLogisticsCompany(logisticsCompany);
-                        shopDeliveryInfo.setWaybillNo(waybillNo);
-                        shopDeliveryInfo.setUpdateBy(sysUsers.getSuName());
-                        shopDeliveryInfo.setLogisticsStatus(AppConstance.LOGISTICS_STATUS_OF_RECEIVE);
-                        shopDeliveryInfo.setDeliveryTime(new Date());
-                        shopDeliveryInfoDao.updateByModel(shopDeliveryInfo);
 
-                        //构建需要修改订单信息Map
-                        Map<String, Object> modifyMap = new HashMap<>();
-                        modifyMap.put("id", shopOrder.getId());
-                        modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE);
-                        shopOrderDao.updateByMap(modifyMap);
+                        ShopDeliveryInfo shopDeliveryInfo = new ShopDeliveryInfo();
+                        shopDeliveryInfo.setOrderId(shopOrder.getId());
+                        List<ShopDeliveryInfo> infoList = shopDeliveryInfoDao.selectByModel(shopDeliveryInfo);
+                        if (CollectionUtils.isEmpty(infoList)) {
+                            logisticsImportVo.setOrderNo(objects.get(0).toString());
+                            logisticsImportVo.setLogisticsCompanyCode(objects.get(1).toString());
+                            logisticsImportVo.setLogisticsCompany(objects.get(2).toString());
+                            logisticsImportVo.setWaybillNo(objects.get(3).toString());
+                            logisticsImportVo.setFailReason("未找到发货信息");
+                            logisticsImportVos.add(logisticsImportVo);
+                            logisticsImportVoLists.add(logisticsImportVo);
+                        }else{
+                            shopDeliveryInfo = infoList.get(0);
+                            shopDeliveryInfo.setOrderNo(orderNo);
+                            shopDeliveryInfo.setLogisticsCompanyCode(logisticsCompanyCode);
+                            shopDeliveryInfo.setLogisticsCompany(logisticsCompany);
+                            shopDeliveryInfo.setWaybillNo(waybillNo);
+                            shopDeliveryInfo.setUpdateBy(sysUsers.getSuName());
+                            shopDeliveryInfo.setLogisticsStatus(AppConstance.LOGISTICS_STATUS_OF_RECEIVE);
+                            shopDeliveryInfo.setDeliveryTime(new Date());
+                            shopDeliveryInfoDao.updateByModel(shopDeliveryInfo);
 
-                        //发送创建订单的消息
-                        rabiitMqTemplate.sendMsg(MQTaskRouting.ORDER_OUT_SOTORE+evn, orderNo);
+                            //构建需要修改订单信息Map
+                            Map<String, Object> modifyMap = new HashMap<>();
+                            modifyMap.put("id", shopOrder.getId());
+                            modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE);
+                            shopOrderDao.updateByMap(modifyMap);
+
+                            //发送创建订单的消息
+                            rabiitMqTemplate.sendMsg(MQTaskRouting.ORDER_OUT_SOTORE+evn, orderNo);
+                        }
                     }else{
-                        LogisticsImportVo logisticsImportVo = new LogisticsImportVo();
-                        logisticsImportVo.setWaybillNo(orderNo);
-                        logisticsImportVo.setColNum(j);
-                        logisticsImportVo.setRemark("第"+j+"行导入失败");
-                        logisticsImportVos.add(logisticsImportVo);
+                        if(ObjectUtil.isEmpty(shopOrder)){
+                            logisticsImportVo.setOrderNo(objects.get(0).toString());
+                            logisticsImportVo.setLogisticsCompanyCode(objects.get(1).toString());
+                            logisticsImportVo.setLogisticsCompany(objects.get(2).toString());
+                            logisticsImportVo.setWaybillNo(objects.get(3).toString());
+                            logisticsImportVo.setFailReason("未找到订单信息");
+                            logisticsImportVos.add(logisticsImportVo);
+                            logisticsImportVoLists.add(logisticsImportVo);
+                        }else if(shopOrder.getOrderStatus() != ShopOrder.ORDER_STATUS_WAIT_SEND ||
+                                shopOrder.getOrderStatus() != ShopOrder.ORDER_STATUS_WAIT_RECEIVE ){
+                            logisticsImportVo.setOrderNo(objects.get(0).toString());
+                            logisticsImportVo.setLogisticsCompanyCode(objects.get(1).toString());
+                            logisticsImportVo.setLogisticsCompany(objects.get(2).toString());
+                            logisticsImportVo.setWaybillNo(objects.get(3).toString());
+                            logisticsImportVo.setFailReason("订单状态不允许发货");
+                            logisticsImportVos.add(logisticsImportVo);
+                            logisticsImportVoLists.add(logisticsImportVo);
+                        }else{
+                            logisticsImportVo.setOrderNo(objects.get(0).toString());
+                            logisticsImportVo.setLogisticsCompanyCode(objects.get(1).toString());
+                            logisticsImportVo.setLogisticsCompany(objects.get(2).toString());
+                            logisticsImportVo.setWaybillNo(objects.get(3).toString());
+                            logisticsImportVo.setFailReason("导入失败");
+                            logisticsImportVos.add(logisticsImportVo);
+                            logisticsImportVoLists.add(logisticsImportVo);
+                        }
                     }
 				}
 			}
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/vo/LogisticsImportVo.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/vo/LogisticsImportVo.java
index f20f52e..5630c47 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/vo/LogisticsImportVo.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/vo/LogisticsImportVo.java
@@ -7,10 +7,14 @@
 @Data
 @ApiModel(value = "LogisticsImportVo", description = "信息返回类")
 public class LogisticsImportVo {
-    @ApiModelProperty(value = "单号")
+    @ApiModelProperty(value = "订单号")
+    private String orderNo;
+    @ApiModelProperty(value = "快递公司编码")
+    private String logisticsCompanyCode;
+    @ApiModelProperty(value = "快递公司名称")
+    private String logisticsCompany;
+    @ApiModelProperty(value = "快递单号")
     private String waybillNo;
-    @ApiModelProperty(value = "备注")
-    private String remark;
-    @ApiModelProperty(value = "行数")
-    private int colNum;
+    @ApiModelProperty(value = "失败原因")
+    private String failReason;
 }
diff --git a/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderDao.xml b/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderDao.xml
index 50e3463..ba616cb 100644
--- a/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderDao.xml
+++ b/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderDao.xml
@@ -548,7 +548,7 @@
 	</select>
 
 	<!-- 分页查询 -->
-	<select id="selectInPageByQuery" resultMap="ShopOrderMap">
+	<select id="selectInPageByQuery" resultMap="ShopOrderComplexMap">
 		select
 		o.*,
 		s.shop_name
diff --git a/zq-erp/src/main/resources/templates/views/admin/shop/logisticsImport-form.html b/zq-erp/src/main/resources/templates/views/admin/shop/logisticsImport-form.html
index fc68800..a1ea86c 100644
--- a/zq-erp/src/main/resources/templates/views/admin/shop/logisticsImport-form.html
+++ b/zq-erp/src/main/resources/templates/views/admin/shop/logisticsImport-form.html
@@ -105,6 +105,8 @@
                     title: '导入快递单,部分失败',
                     content: data.info
                 });
+                var url = basePath + "/admin/shopOrder/exportLogisticsImportExcel";
+                window.open(url);
                 parent.myGrid.serchData();
             }
             $("#showFileName").val('');
diff --git a/zq-erp/src/main/resources/templates/views/admin/shop/shopOrder-list.html b/zq-erp/src/main/resources/templates/views/admin/shop/shopOrder-list.html
index 7d02c7a..6fae16b 100644
--- a/zq-erp/src/main/resources/templates/views/admin/shop/shopOrder-list.html
+++ b/zq-erp/src/main/resources/templates/views/admin/shop/shopOrder-list.html
@@ -130,10 +130,11 @@
                     <th data-checkbox="true"></th>
                     <th data-formatter="MGrid.indexfn" data-align="center" data-width="30px">序号</th>
                     <th data-align="center" data-width="195px" data-field="id" data-formatter="buidOperate">操作</th>
-                    <th data-field="userName">客户姓名</th>
-                    <th data-field="userTel">客户电话</th>
-                    <th data-field="storeName">店铺名称</th>
+                    <th data-field="deliveryInfo.receiveAddress" data-formatter="buildLogistics">发货信息</th>
+                    <!--<th data-field="userName">客户姓名</th>-->
+                    <!--<th data-field="userTel">客户电话</th>-->
                     <th data-field="orderStatus" data-formatter="buildOrderStatus">订单状态</th>
+                    <th data-field="deliveryInfo.waybillNo" data-formatter="buildDelivery">物流信息</th>
                     <th data-field="orderTime" data-formatter="MGrid.getTime">下单时间</th>
                     <th data-field="details" data-formatter="buildDetails">购买商品</th>
                     <!--<th data-field="purchaseQuantity">购买件数</th>-->
@@ -142,6 +143,7 @@
                     <th data-field="shippingMethod"  data-formatter="buildShippingMethod" >配送方式</th>
                     <!--<th data-field="orderType" data-formatter="orderTypeFormatter">订单类型</th>-->
                     <th data-field="orderNo">订单编号</th>
+                    <th data-field="storeName">店铺名称</th>
                     <!--<th data-field="applyStatus" data-formatter="applyStatusFormatter">是否已提现</th>-->
                 </tr>
                 </thead>
@@ -225,6 +227,17 @@
         return details;
     }
 
+    // 发货信息
+    function buildLogistics(value, row, index) {
+        return (row.userName==null?"":row.userName)+" <br/>"+ (row.userTel==null?"":row.userTel) +" <br/>"+value  ;
+    }
+    // 物流信息
+    function buildDelivery(value, row, index) {
+        return (row.deliveryInfo.logisticsCompanyCode==null?"":"快递编码:"+row.deliveryInfo.logisticsCompanyCode)
+            +" <br/>"+ (row.deliveryInfo.logisticsCompany==null?"":"快递名称:"+row.deliveryInfo.logisticsCompany)
+            +" <br/>"+(value==null?"":"快递单号:"+value)  ;
+    }
+
 
     function buildOrderStatus(value, row, index) {
         if (value == 1) {
@@ -269,11 +282,16 @@
             + '操作 <span class="caret"></span>' + '</button>'
             + '<ul class="dropdown-menu" role="menu">'
             + btns[0].replace('VALUE', value)
+        if (row.deliveryInfo.waybillNo != null && typeof row.deliveryInfo.waybillNo != 'undefined' && row.deliveryInfo.waybillNo != '') {
+            html += btns[3].replace('orderId',row.id).replace('waybillNo',row.deliveryInfo.waybillNo);
+        }
         if (row.orderStatus == 2) {
-            html += btns[1].replace('VALUE', value)
+            html += btns[1].replace('VALUE', value);
+            html += btns[4].replace('orderId',row.id);
         }
         if (row.orderStatus == 3) {
-            html += btns[2].replace('VALUE', value)
+            html += btns[2].replace('VALUE', value);
+            html += btns[4].replace('orderId',row.id);
         }
         html += '</ul>' + '</div>';
         return html;
@@ -290,6 +308,40 @@
                 content: [basePath + '/admin/shopOrder/editForm?id=' + id]
             })
         )
+    }
+
+    /**
+     * 查看物流信息
+     * @param id
+     */
+    function showLogisticsInfo(orderId,waybillNo){
+        if(waybillNo == '' || waybillNo == null){
+            layer.msg("订单还未发货,暂无物流信息", {
+                icon : 2,
+                time : 2000
+            });
+            return false;
+        }
+        layer.open({
+            type : 2,
+            title : "查看物流信息",
+            area : [ MUI.SIZE_L, '500px' ],
+            maxmin : true,
+            content : [ basePath+'/admin/redirect/shop/shopLogisticsInfo-list?orderId=' + orderId]
+        });
+    }
+    /**
+     * 编辑物流信息
+     * @param id
+     */
+    function editDeliveryInfo(orderId){
+        layer.open({
+            type : 2,
+            title : "编辑物流信息",
+            area : [ MUI.SIZE_L, '500px' ],
+            maxmin : true,
+            content : [ basePath + '/admin/shopDeliveryInfo/editDeliveryInfoForm?orderId=' + orderId]
+        });
     }
 
     //修改订单为发货
@@ -366,6 +418,8 @@
 btns[0] = '<li><a href="javascript:void(0)" onClick="openEdit(\'VALUE\')" title="编辑">编辑</a></li>'
 btns[1] = '<li><a href="javascript:void(0)" onClick="openSendPackage(\'VALUE\')" title="开始发货">开始发货</a></li>'
 btns[2] = '<li><a href="javascript:void(0)" onClick="openSendPackageOver(\'VALUE\')" title="配送完成">配送完成</a></li>'
+btns[3] = '<li><a href="javascript:void(0)" onclick="showLogisticsInfo(\'orderId\',\'waybillNo\')" title="查看物流">查看物流</a></li>'
+btns[4] = '<li><a href="javascript:void(0)" onclick="editDeliveryInfo(\'orderId\')" title="编辑快递">编辑快递</a></li>'
 
 </script>
 

--
Gitblit v1.9.1