Browse Source

容器管理导入

k 1 year ago
parent
commit
8c74330232

+ 25 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warewms/wms/box/WmsBoxInfoController.java

@@ -2,6 +2,8 @@ package com.ruoyi.web.controller.warewms.wms.box;
 
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.base.domain.BaseLocationInfo;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -20,10 +22,11 @@ import com.ruoyi.ams.box.domain.WmsBoxInfo;
 import com.ruoyi.ams.box.service.IWmsBoxInfoService;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 容器管理Controller
- * 
+ *
  * @author ruoyi
  * @date 2022-11-01
  */
@@ -59,6 +62,27 @@ public class WmsBoxInfoController extends BaseController
         util.exportExcel(response, list, "容器管理数据");
     }
 
+    /**
+     * 下载导入模版
+     * @param response
+     */
+    @PostMapping("/importTemplate")
+    public void importTemplate(HttpServletResponse response)
+    {
+        ExcelUtil<WmsBoxInfo> util = new ExcelUtil<>(WmsBoxInfo.class);
+        util.importTemplateExcel(response, "容器信息");
+    }
+
+    @Log(title = "容器导入", businessType = BusinessType.IMPORT)
+    @PostMapping("/importData")
+    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
+    {
+        ExcelUtil<WmsBoxInfo> util = new ExcelUtil<>(WmsBoxInfo.class);
+        List<WmsBoxInfo> list = util.importExcel(file.getInputStream());
+        String operName = getUsername();
+        return wmsBoxInfoService.importLocation(list, updateSupport, operName);
+    }
+
     /**
      * 获取容器管理详细信息
      */

+ 83 - 3
ruoyi-ui/src/views/wms/box/index.vue

@@ -107,6 +107,16 @@
           @click="handleExport"
           v-hasPermi="['box:boxInfo:export']"
         >导出</el-button>
+        <el-col :span="1.5">
+          <el-button
+            type="info"
+            plain
+            icon="el-icon-upload2"
+            size="mini"
+            @click="handleImport"
+            v-hasPermi="['base:locationInfo:export']"
+          >导入</el-button>
+        </el-col>
       </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
@@ -181,9 +191,9 @@
             ></el-option>
           </el-select>
         </el-form-item>
-        <el-form-item label="备注" prop="boxRemark">
-          <el-input v-model="form.boxRemark" placeholder="请输入备注" />
-        </el-form-item>
+<!--        <el-form-item label="备注" prop="boxRemark">-->
+<!--          <el-input v-model="form.boxRemark" placeholder="请输入备注" />-->
+<!--        </el-form-item>-->
         <el-form-item label="状态" prop="boxState">
           <el-select v-model="form.boxState" placeholder="请选择状态">
             <el-option
@@ -223,11 +233,41 @@
         <el-button @click="cancel">取 消</el-button>
       </div>
     </el-dialog>
+    <!-- 库位导入对话框 -->
+    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
+      <el-upload
+        ref="upload"
+        :limit="1"
+        accept=".xlsx, .xls"
+        :headers="upload.headers"
+        :action="upload.url + '?updateSupport=' + upload.updateSupport"
+        :disabled="upload.isUploading"
+        :on-progress="handleFileUploadProgress"
+        :on-success="handleFileSuccess"
+        :auto-upload="false"
+        drag
+      >
+        <i class="el-icon-upload"></i>
+        <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
+        <div class="el-upload__tip text-center" slot="tip">
+<!--          <div class="el-upload__tip" slot="tip">-->
+<!--            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的数据-->
+<!--          </div>-->
+          <span>仅允许导入xls、xlsx格式文件。</span>
+          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
+        </div>
+      </el-upload>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="submitFileForm">确 定</el-button>
+        <el-button @click="upload.open = false">取 消</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
 <script>
 import { listBoxInfo, getBoxInfo, delBoxInfo, addBoxInfo, updateBoxInfo } from "@/api/box/boxInfo";
+import {getToken} from "@/utils/auth";
 
 export default {
   name: "BoxInfo",
@@ -268,6 +308,20 @@ export default {
       form: {},
       // 表单校验
       rules: {
+      },
+      upload: {
+        // 是否显示弹出层(用户导入)
+        open: false,
+        // 弹出层标题(用户导入)
+        title: "",
+        // 是否禁用上传
+        isUploading: false,
+        // 是否更新已经存在的用户数据
+        updateSupport: 0,
+        // 设置上传的请求头部
+        headers: { Authorization: "Bearer " + getToken() },
+        // 上传的地址
+        url: process.env.VUE_APP_BASE_API + "/box/boxInfo/importData"
       }
     };
   },
@@ -377,6 +431,32 @@ export default {
       this.download('box/boxInfo/export', {
         ...this.queryParams
       }, `boxInfo_${new Date().getTime()}.xlsx`)
+    },
+    /** 导入按钮操作 */
+    handleImport() {
+      this.upload.title = "容器信息导入";
+      this.upload.open = true;
+    },
+    /** 下载模板操作 */
+    importTemplate() {
+      this.download('box/boxInfo/importTemplate', {
+      }, `location_${new Date().getTime()}.xlsx`)
+    },
+// 文件上传中处理
+    handleFileUploadProgress(event, file, fileList) {
+      this.upload.isUploading = true;
+    },
+// 文件上传成功处理
+    handleFileSuccess(response, file, fileList) {
+      this.upload.open = false;
+      this.upload.isUploading = false;
+      this.$refs.upload.clearFiles();
+      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
+      this.getList();
+    },
+// 提交上传文件
+    submitFileForm() {
+      this.$refs.upload.submit();
     }
   }
 };

+ 8 - 8
warewms-ams/src/main/java/com/ruoyi/ams/box/domain/WmsBoxInfo.java

@@ -23,37 +23,37 @@ public class WmsBoxInfo extends BaseEntity
     private String boxNo;
 
     /** 容器类型 */
-    @Excel(name = "容器类型")
+    @Excel(name = "容器类型",type = Excel.Type.EXPORT)
     private String boxType;
 
     /** 备注 */
-    @Excel(name = "备注")
+//    @Excel(name = "备注")
     private String boxRemark;
 
     /** 状态 */
-    @Excel(name = "状态")
+    @Excel(name = "状态",type = Excel.Type.EXPORT)
     private Integer boxState;
 
     /** 是否有货 */
-    @Excel(name = "是否有货")
+    @Excel(name = "是否有货",type = Excel.Type.EXPORT)
     private String isEmpty;
 
     /**  */
-    @Excel(name = "")
+//    @Excel(name = "")
     private String userdefine1;
 
     /**  */
-    @Excel(name = "")
+//    @Excel(name = "")
     private String userdefine2;
 
     /** 绑定库位 */
-    @Excel(name = "绑定库位")
+    @Excel(name = "绑定库位",type = Excel.Type.EXPORT)
     private String locationNo;
 
     private Long locationId;
 
     /** 是否满托 */
-    @Excel(name = "是否满托")
+    @Excel(name = "是否满托",type = Excel.Type.EXPORT)
     private String isFull;
 
     public Long getId() {

+ 11 - 0
warewms-ams/src/main/java/com/ruoyi/ams/box/service/IWmsBoxInfoService.java

@@ -4,6 +4,7 @@ import java.util.List;
 
 import com.ruoyi.ams.box.domain.WmsBoxInfo;
 import com.ruoyi.ams.box.form.AddBoxForm;
+import com.ruoyi.base.domain.BaseLocationInfo;
 import com.ruoyi.common.core.domain.AjaxResult;
 
 /**
@@ -118,4 +119,14 @@ public interface IWmsBoxInfoService {
      * @return
      */
     int updateLocationBind(String palletNo,Long locationTo,String isFull);
+
+
+    /**
+     * 导入库位
+     * @param list
+     * @param updateSupport
+     * @param opname
+     * @return
+     */
+    AjaxResult importLocation(List<WmsBoxInfo> list, boolean updateSupport, String opname);
 }

+ 49 - 0
warewms-ams/src/main/java/com/ruoyi/ams/box/service/impl/WmsBoxInfoServiceImpl.java

@@ -1,14 +1,19 @@
 package com.ruoyi.ams.box.service.impl;
 
+import java.util.Date;
 import java.util.List;
 
 import com.ruoyi.ams.box.form.AddBoxForm;
 import com.ruoyi.ams.inv.domain.InvLotAtt;
 import com.ruoyi.ams.inv.domain.InvLotLocId;
 import com.ruoyi.ams.inv.mapper.InvLotLocIdMapper;
+import com.ruoyi.base.constant.Constant;
+import com.ruoyi.base.domain.BaseLocationInfo;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -22,6 +27,7 @@ import com.ruoyi.ams.box.service.IWmsBoxInfoService;
  * @author ruoyi
  * @date 2022-11-01
  */
+@Slf4j
 @Service
 public class WmsBoxInfoServiceImpl implements IWmsBoxInfoService {
     @Autowired
@@ -192,4 +198,47 @@ public class WmsBoxInfoServiceImpl implements IWmsBoxInfoService {
     public int updateLocationBind(String palletNo, Long locationTo, String isFull) {
         return wmsBoxInfoMapper.updateLocationBindByPalletNo(palletNo, locationTo, isFull);
     }
+
+    @Override
+    public AjaxResult importLocation(List<WmsBoxInfo> list, boolean updateSupport, String opname) {
+        if (StringUtils.isNull(list) || list.size() == 0) {
+            throw new ServiceException("导入信息数据不能为空!");
+        }
+        int successNum = 0;
+        int failureNum = 0;
+        StringBuilder successMsg = new StringBuilder();
+        StringBuilder failureMsg = new StringBuilder();
+        for (WmsBoxInfo wmsBoxInfo : list) {
+            try {
+                WmsBoxInfo b = wmsBoxInfoMapper.selectWmsBoxInfoByBoxNo(wmsBoxInfo.getBoxNo());
+                if (b == null) {
+                    wmsBoxInfo.setBoxType("pallet");
+                    wmsBoxInfo.setBoxState(1);
+                    wmsBoxInfo.setIsEmpty("Y");
+                    wmsBoxInfo.setLocationId(null);
+                    wmsBoxInfo.setIsFull("N");
+                    wmsBoxInfo.setCreateBy(opname);
+                    wmsBoxInfo.setCreateTime(new Date());
+                    this.insertWmsBoxInfo(wmsBoxInfo);
+                    successNum++;
+                    successMsg.append("<br/>" + successNum + "、容器 " + wmsBoxInfo.getBoxNo() + " 导入成功");
+                } else {
+                    failureNum++;
+                    failureMsg.append("<br/>" + failureNum + "、容器 " + wmsBoxInfo.getBoxNo() + " 已存在");
+                }
+            } catch (Exception e) {
+                failureNum++;
+                String msg = "<br/>" + failureNum + "、容器 " + wmsBoxInfo.getBoxNo() + " 导入失败:";
+                failureMsg.append(msg + e.getMessage());
+                log.error(msg, e);
+            }
+        }
+        if (failureNum > 0) {
+            failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
+            throw new ServiceException(failureMsg.toString());
+        } else {
+            successMsg.insert(0, "数据已全部导入成功!共 " + successNum + " 条,数据如下:");
+        }
+        return AjaxResult.success(successMsg);
+    }
 }