Browse Source

转码功能和mes辅助支持30位

sunxianglong 1 tháng trước cách đây
mục cha
commit
98d229ec22

+ 9 - 1
src/main/java/com/jeesite/modules/mes/util/CommonUitl.java

@@ -477,7 +477,8 @@ public class CommonUitl {
     }
 
     /**
-     * 判段工件码是否符合要求
+     * 判段工件码是否符合要求。
+     * 30 位工件码直接视为通过(兼容旧码,无需转码)。
      * @param sn  工件码
      * @param spec  规格
      * @param specStart  规格开始位置
@@ -485,6 +486,13 @@ public class CommonUitl {
      * @return
      */
     public static Boolean checkSnByModel(String sn, String spec,Integer specStart, Integer length) {
+        if(StringUtils.isEmpty(sn) || length == null || StringUtils.isEmpty(spec) || specStart == null){
+            return false;
+        }
+        // 30位旧码直接通过,无需转码
+        if(sn.length() == 30){
+            return true;
+        }
         if(sn.length()!=length){
             return false;
         }

+ 9 - 0
src/main/java/com/jeesite/modules/mes/web/MesProductRecordController.java

@@ -254,6 +254,15 @@ public class MesProductRecordController extends BaseController {
 		return "modules/mes/mesProductRecordList";
 	}
 	/**
+	 * 条码转码页面
+	 */
+	@RequiresPermissions("mes:mesProductRecord:view")
+	@RequestMapping(value = "transcode")
+	public String transcode() {
+		return "modules/mes/mesProductRecordTranscode";
+	}
+
+	/**
 	 * 批量重置表单
 	 */
 	@RequiresPermissions("mes:mesProductRecord:reload")

+ 2 - 2
src/main/resources/config/application.yml

@@ -53,8 +53,8 @@ jdbc:
   # Mysql 数据库配置
   type: mysql
   driver: com.mysql.cj.jdbc.Driver
-#  url: jdbc:mysql://127.0.0.1:3306/mes_cloud_ljr?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
-  url: jdbc:mysql://10.0.20.10:3306/mes_cloud_ljr?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
+  url: jdbc:mysql://127.0.0.1:3306/mes_cloud_ljr?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
+#  url: jdbc:mysql://10.0.20.10:3306/mes_cloud_ljr?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
 #  url: jdbc:mysql://192.168.22.99:3306/mes_cloud?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
 #  username: mes_cloud
 #  password: YD57bSRabiyWBwkZ

+ 1 - 0
src/main/resources/views/modules/mes/mesProductRecordList.html

@@ -6,6 +6,7 @@
 				<i class="fa icon-notebook"></i> ${text('生产记录管理')}
 			</div>
 			<div class="box-tools pull-right">
+				<a href="${ctx}/mes/mesProductRecord/transcode" class="btn btn-default btnTool" title="${text('转码')}"><i class="fa fa-exchange"></i> ${text('转码')}</a>
 				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
 				<a href="#" class="btn btn-default" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a>
 				<% if(hasPermi('mes:mesProductRecord:edit')){ %>

+ 152 - 0
src/main/resources/views/modules/mes/mesProductRecordTranscode.html

@@ -0,0 +1,152 @@
+<% layout('/layouts/default.html', {title: '条码转码', libs: ['validate']}){ %>
+<div class="main-content">
+	<div class="box box-main">
+		<div class="box-header with-border">
+			<div class="box-title">
+				<i class="fa fa-exchange"></i> ${text('条码转码')}
+			</div>
+			<div class="box-tools pull-right">
+				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
+			</div>
+		</div>
+		<form id="transcodeForm" class="form-horizontal">
+			<div class="box-body">
+				<div class="form-unit">${text('转码:2400170 → AAB70;解码:AAB70 → 2400170')}</div>
+				<div class="row">
+					<div class="col-xs-10">
+						<div class="form-group">
+							<label class="control-label col-sm-2">
+								<span class="required">*</span> ${text('输入条码')}:
+							</label>
+							<div class="col-sm-8">
+								<input type="text" id="inputBarcode" name="inputBarcode" maxlength="30"
+									class="form-control required" placeholder="${text('请输入条码')}"
+									autocomplete="off"/>
+							</div>
+						</div>
+					</div>
+				</div>
+				<div class="row">
+					<div class="col-xs-10">
+						<div class="form-group">
+							<label class="control-label col-sm-2">${text('输出条码')}:</label>
+							<div class="col-sm-8">
+								<input type="text" id="outputBarcode" name="outputBarcode" readonly
+									class="form-control" placeholder="${text('转换结果')}"/>
+							</div>
+						</div>
+					</div>
+				</div>
+			</div>
+			<div class="box-footer">
+				<div class="row">
+					<div class="col-sm-offset-2 col-sm-10">
+						<button type="button" class="btn btn-sm btn-primary" id="btnTranscode"><i class="fa fa-exchange"></i> ${text('转 码')}</button>&nbsp;
+						<button type="button" class="btn btn-sm btn-success" id="btnDecode"><i class="fa fa-undo"></i> ${text('解 码')}</button>&nbsp;
+						<button type="button" class="btn btn-sm btn-default" id="btnClear"><i class="fa fa-eraser"></i> ${text('清 空')}</button>&nbsp;
+						<button type="button" class="btn btn-sm btn-default" id="btnCopy" disabled><i class="fa fa-copy"></i> ${text('复 制')}</button>&nbsp;
+						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
+					</div>
+				</div>
+			</div>
+		</form>
+	</div>
+</div>
+<% } %>
+<script>
+(function () {
+	var FROM = '2400170';
+	var TO = 'AAB70';
+
+	function resetOutput() {
+		$('#outputBarcode').val('');
+		$('#btnCopy').prop('disabled', true);
+	}
+
+	function setOutput(output) {
+		$('#outputBarcode').val(output);
+		$('#btnCopy').prop('disabled', false);
+	}
+
+	function doTranscode() {
+		var input = $.trim($('#inputBarcode').val());
+		if (!input) {
+			js.showMessage('${text("请输入条码")}');
+			resetOutput();
+			return;
+		}
+		if (input.length !== 30) {
+			js.showMessage('${text("转码条码长度必须为30位")}');
+			resetOutput();
+			return;
+		}
+		if (input.indexOf(FROM) < 0) {
+			js.showMessage('${text("条码中未找到 2400170,无法转码")}');
+			resetOutput();
+			return;
+		}
+		setOutput(input.replace(FROM, TO));
+	}
+
+	function doDecode() {
+		var input = $.trim($('#inputBarcode').val());
+		if (!input) {
+			js.showMessage('${text("请输入条码")}');
+			resetOutput();
+			return;
+		}
+		if (input.indexOf(TO) < 0) {
+			js.showMessage('${text("条码中未找到 AAB70,无法解码")}');
+			resetOutput();
+			return;
+		}
+		setOutput(input.replace(TO, FROM));
+	}
+
+	function copyOutput() {
+		var output = $('#outputBarcode').val();
+		if (!output) {
+			return;
+		}
+		if (navigator.clipboard && navigator.clipboard.writeText) {
+			navigator.clipboard.writeText(output).then(function () {
+				js.showMessage('${text("已复制到剪贴板")}');
+			}).catch(function () {
+				fallbackCopy(output);
+			});
+		} else {
+			fallbackCopy(output);
+		}
+	}
+
+	function fallbackCopy(text) {
+		var $tmp = $('<input>');
+		$('body').append($tmp);
+		$tmp.val(text).select();
+		try {
+			document.execCommand('copy');
+			js.showMessage('${text("已复制到剪贴板")}');
+		} catch (e) {
+			js.showMessage('${text("复制失败,请手动复制")}');
+		}
+		$tmp.remove();
+	}
+
+	function clearForm() {
+		$('#inputBarcode').val('');
+		resetOutput();
+		$('#inputBarcode').focus();
+	}
+
+	$('#btnTranscode').on('click', doTranscode);
+	$('#btnDecode').on('click', doDecode);
+	$('#btnClear').on('click', clearForm);
+	$('#btnCopy').on('click', copyOutput);
+	$('#inputBarcode').on('keydown', function (e) {
+		if (e.keyCode === 13) {
+			e.preventDefault();
+			doTranscode();
+		}
+	});
+})();
+</script>