#
lsh
2024-09-05 7f9ad8362df4f5c0ddf652055002e1a4cef2b06b
#
3个文件已修改
2个文件已添加
282 ■■■■■ 已修改文件
zy-asrs-common/src/main/java/com/zy/asrs/common/domain/entity/LocInPrintMatExcel.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-common/src/main/java/com/zy/asrs/common/utils/LocInPrintMatExcelListener.java 143 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wms/src/main/java/com/zy/asrs/wms/controller/TagController.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wms/src/main/webapp/static/js/locInPrintMat/locInPrintMat.js 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wms/src/main/webapp/views/locInPrintMat/locInPrintMat.html 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-common/src/main/java/com/zy/asrs/common/domain/entity/LocInPrintMatExcel.java
New file
@@ -0,0 +1,23 @@
package com.zy.asrs.common.domain.entity;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.zy.asrs.common.wms.entity.Mat;
import lombok.Data;
/**
 * 0.A 1.B 2.C 3.D 4.E 5.F 6.G 7.H 8.I
 * 9.J 10.K 11.L 12.M 13.N 14.O 15.P 16.Q 17.R 18.S
 * 19.T 20.U 21.V 22.W 23.X 24.Y 25.Z
 */
@Data
@ExcelIgnoreUnannotated
public class LocInPrintMatExcel extends Mat {
    @ExcelProperty(index = 0, value = "品号")
    private String matnr;
    @ExcelProperty(index = 1, value = "品名")
    private String matax;
    @ExcelProperty(index = 2, value = "打印数量")
    private String anfme;
}
zy-asrs-common/src/main/java/com/zy/asrs/common/utils/LocInPrintMatExcelListener.java
New file
@@ -0,0 +1,143 @@
package com.zy.asrs.common.utils;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.generator.config.IFileCreate;
import com.zy.asrs.common.domain.entity.LocInPrintMatExcel;
import com.zy.asrs.common.wms.entity.LocInPrintMat;
import com.zy.asrs.common.wms.service.LocInPrintMatService;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.SpringUtils;
import com.zy.asrs.framework.exception.CoolException;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by vincent on 2019-11-25
 */
@Slf4j
public class LocInPrintMatExcelListener extends AnalysisEventListener<LocInPrintMatExcel> {
    private int total = 0;
    private int totalAnfme = 0;
    private Long userId;
    private Long hostId;
    List<String[]> OutLocBoxCs = new ArrayList<>();
    public LocInPrintMatExcelListener() {
    }
    public LocInPrintMatExcelListener(Long userId, Long hostId) {
        this.userId = userId;
        this.hostId = hostId;
    }
    /**
     * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
     */
    private static final int BATCH_COUNT = 50;
    private final List<LocInPrintMatExcel> list = new ArrayList<>();
    /**
     * 这里会一行行的返回头
     */
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
    }
    /**
     * 这个每一条数据解析都会来调用
     */
    @Override
    public void invoke(LocInPrintMatExcel excel, AnalysisContext ctx) {
        String matnr = "";
        try{
            matnr =  excel.getMatnr();
            if (Cools.isEmpty(matnr)){
                throw new CoolException("品号参数为空");
            }
        } catch (Exception e){
            throw new CoolException("品号参数为空");
        }
        String matax = "";
        try{
            matax =  excel.getMatax();
        } catch (Exception e){
            matax = "";
        }
        String anfme = "1";
        try{
            String anfme1 = excel.getAnfme();
            try{
                Integer anfmeInt = Integer.parseInt(anfme1);
                if (!Cools.isEmpty(anfmeInt) && anfmeInt>1){
                    anfme = anfmeInt.toString();
                } else {
                    anfme =  "1";
                }
            } catch (Exception e){
                anfme =  "1";
            }
        } catch (Exception e){
            anfme = "1";
        }
        String[] s=new String[3];
        s[0] = matnr;
        s[1] = matax;
        s[2] = anfme;
        OutLocBoxCs.add(s);
        total++;
        totalAnfme = totalAnfme+Integer.parseInt(anfme);
    }
    /**
     * 所有数据解析完成了调用
     * 适合事务
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext ctx) {
        if (!Cools.isEmpty(OutLocBoxCs) && OutLocBoxCs.size() != 0) {
            LocInPrintMatService locInPrintMatService = SpringUtils.getBean(LocInPrintMatService.class);
            Date now = new Date();
            for (String[] outLocBoxC:OutLocBoxCs){
                String matnr = outLocBoxC[0];
                String matax = outLocBoxC[1];
                String anfme = outLocBoxC[2];
                Integer intAnfme = 1;
                try{
                    Integer intAnfme1 = Integer.parseInt(anfme);
                    if (!Cools.isEmpty(intAnfme1) && intAnfme1 > 1){
                        intAnfme = intAnfme1;
                    }
                } catch (Exception e){
                }
                for (int i = 0 ; i < intAnfme ; i++){
                    LocInPrintMat locInPrintMat = new LocInPrintMat();
                    locInPrintMat.setMatnr(matnr);
                    locInPrintMat.setMaktx(matax);
                    locInPrintMat.setCreateBy(userId);
                    locInPrintMat.setUpdateBy(userId);
                    locInPrintMat.setCreateTime(now);
                    locInPrintMat.setUpdateTime(now);
                    locInPrintMatService.save(locInPrintMat);
                }
            }
        }
        log.info("新增{}种待打印物料信息,共生成{}条待打印条码!", total,totalAnfme);
    }
    public int[] getTotal() {
        return new int[]{total,totalAnfme};
    }
}
zy-asrs-wms/src/main/java/com/zy/asrs/wms/controller/TagController.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.common.domain.CodeRes;
import com.zy.asrs.common.domain.entity.LocInPrintMatExcel;
import com.zy.asrs.common.domain.entity.MatExcel;
import com.zy.asrs.common.domain.entity.MatPrint;
import com.zy.asrs.common.utils.*;
@@ -296,4 +297,31 @@
        return R.ok("成功同步"+listener.getTotal()+"条商品数据");
    }
    /**
     * excel导入模板下载
     */
    @RequestMapping(value = "/out/loc/box/excel/import/mould")
    public void outLocBoxExcelImportMould(HttpServletResponse response) throws IOException {
        List<LocInPrintMatExcel> excels = new ArrayList<>();
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("导入待打印物料模板", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        EasyExcel.write(response.getOutputStream(), LocInPrintMatExcel.class)
                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                .sheet("待打印物料模板")
                .doWrite(excels);
    }
    // excel导入
    @PostMapping(value = "/out/loc/box/excel/import/auth")
    @ManagerAuth(memo = "导入待打印物料模板")
    @Transactional
    public R outLocBoxExcelImport(MultipartFile file) throws IOException {
        LocInPrintMatExcelListener listener = new LocInPrintMatExcelListener(getUserId(), getHostId());
        EasyExcel.read(file.getInputStream(), LocInPrintMatExcel.class, listener).sheet().doRead();
        return R.ok("成功导入"+listener.getTotal()[0]+"种待打印物料信息,共生成"+listener.getTotal()[1]+"条待打印条码!");
    }
}
zy-asrs-wms/src/main/webapp/static/js/locInPrintMat/locInPrintMat.js
@@ -1,5 +1,6 @@
var pageCurr;
var pageCount = 0;
var admin;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin', 'xmSelect'], function(){
@@ -8,7 +9,7 @@
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
    admin = layui.admin;
    var xmSelect = layui.xmSelect;
    // 数据渲染
@@ -326,6 +327,16 @@
});
// excel导入模板下载
function excelMouldDownload(){
    layer.load(1, {shade: [0.1,'#fff']});
    location.href = baseUrl + "/out/loc/box/excel/import/mould";
    layer.closeAll('loading');
}
// excel导入
function importExcel() {
    $("#importExcel").trigger("click");
}
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
@@ -341,3 +352,46 @@
        page: {curr: pageCurr}
    });
}
function upload(obj){
    if(!obj.files) {
        return;
    }
    var file = obj.files[0];
    admin.confirm('确认同步 [' + file.name +'] 文件吗?', function (index) {
        layer.load(1, {shade: [0.1,'#fff']});
        var url = baseUrl + "/out/loc/box/excel/import/auth";
        var form = new FormData();
        form.append("file", file);
        xhr = new XMLHttpRequest();
        xhr.open("post", url, true); //post方式,url为服务器请求地址,true 该参数规定请求是否异步处理。
        xhr.setRequestHeader('token', localStorage.getItem('token'));
        xhr.onload = uploadComplete; //请求完成
        xhr.onerror =  uploadFailed; //请求失败
        xhr.onloadend = function () { // // 上传完成重置文件流
            layer.closeAll('loading');
            $("#importExcel").val("");
        };
        // xhr.upload.onprogress = progressFunction;//【上传进度调用方法实现】
        xhr.upload.onloadstart = function(){//上传开始执行方法
            ot = new Date().getTime();   //设置上传开始时间
            oloaded = 0;//设置上传开始时,以上传的文件大小为0
        };
        xhr.send(form);
    }, function(index){
        $("#importExcel").val("");
    });
}
function uploadComplete(evt) {
    var res = JSON.parse(evt.target.responseText);
    if(res.code === 200) {
        layer.msg(res.msg, {icon: 1});
        loadTree("");
    } else {
        layer.msg(res.msg, {icon: 2});
    }
}
function uploadFailed(evt) {
    var res = JSON.parse(evt.target.responseText);
    layer.msg(res.msg, {icon: 2});
}
zy-asrs-wms/src/main/webapp/views/locInPrintMat/locInPrintMat.html
@@ -72,6 +72,21 @@
            padding: 8px;
        }
        /*----------------------------------*/
        .function-area {
            padding: 20px 50px;
        }
        .function-btn:hover {
            background-color: #2b425b;
            color: #fff;
        }
        #mat-query {
            display: none;
        }
        #btn-outbound {
            display: none;
        }
    </style>
</head>
<body>
@@ -109,6 +124,10 @@
                        <button class="layui-btn icon-btn" lay-filter="reset" lay-submit>
                            <i class="layui-icon">&#xe666;</i>重置
                        </button>
                        <!-- 功能区 -->
                    </div>
                    <div class="layui-inline">
                        <button class="function-btn layui-btn icon-btn" style="width: auto;float:right;" onclick="excelMouldDownload()">导入待打印物料模板下载</button>
                    </div>
                </div>
            </div>
@@ -117,23 +136,34 @@
    </div>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" id="btn-add" lay-event="addData">新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" id="btn-delete" lay-event="deleteData">删除</button>
        <button class="layui-btn layui-btn-sm" id="btn-print-batch" lay-event="btnPrintBatch">批量打印</button>
        <button class="layui-btn layui-btn-lg" onclick="importExcel()" style="font-size: 12px;width: auto;">导入物料打印</button>
        <span style="display: none"><input id="importExcel" type="file" onchange="upload(this)">导入物料信息</span>
        <button class="layui-btn layui-btn-primary layui-btn-sm" id="btn-export" lay-event="exportData" style="float: right">导出</button>
    </div>
</script>
<!-- 表格 -->
<div style="padding-bottom: 5px; margin-bottom: 45px">
    <!-- 头部 -->
<script type="text/html" id="operate">
    <a class="layui-btn layui-btn-primary layui-btn-xs btn-edit" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs btn-edit" lay-event="del">删除</a>
        <!-- 3.导入箱号出库 -->
    <!--    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs btn-complete" lay-event="btnPrint">打印</a>-->
</script>
    <table class="layui-table" id="chooseData" lay-filter="chooseData"></table>
</div>
<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/jquery/jQuery.print.js"></script>