Browse Source

微浦MES,增加根据维护规则生成工单镭雕条码数据

xiaost 22 hours ago
parent
commit
f110f3482d

+ 240 - 0
WebContent/app/controller/pm/mes/MakeSNRuleMain.js

@@ -0,0 +1,240 @@
+Ext.QuickTips.init();
+Ext.define('erp.controller.pm.mes.MakeSNRuleMain', {
+	extend : 'Ext.app.Controller',
+	FormUtil : Ext.create('erp.util.FormUtil'),
+	GridUtil : Ext.create('erp.util.GridUtil'),
+	BaseUtil : Ext.create('erp.util.BaseUtil'),
+	views : [ 'pm.mes.MakeSNRuleMain', 'core.form.Panel',
+			'core.toolbar.Toolbar', 'core.button.Close', 'core.trigger.DbfindTrigger',
+			'core.trigger.TextAreaTrigger', 'core.trigger.MultiDbfindTrigger','core.button.Delete',
+			'core.form.YnField','core.button.DeleteAllDetails',
+		     'core.button.GenerateBarcode','core.button.SuppleGenBar'],
+	init : function() {
+		var me = this;
+		this.control({
+			'#mm_id':{
+				afterrender:function(field){
+					if(field.value != null && field.value != ''&&field.value != 0){
+						var macode = Ext.getCmp('mm_macode')
+						macode.setReadOnly(true);
+						macode.editable = false;
+						if(macode.xtype == 'dbfindtrigger'){
+							macode.setHideTrigger(true);
+						}
+						macode.fieldStyle = 'background:#EEEEEE';
+					}
+				}
+			},
+
+			/**
+			 * 生成条码
+			 */
+			'erpGenerateBarcodeButton':{
+				click : function(btn){
+					var form = Ext.getCmp('form');
+					if(! me.FormUtil.checkForm()){
+						return;
+					}
+                   //判断本次数量必填
+					var thisqty = Ext.getCmp("mm_thisqty");
+					if(!thisqty){
+						showError("必须配置并且维护本次数量字段!")
+					}
+					if(thisqty && (thisqty.value == null || thisqty.value == '' || thisqty.value<=0)){
+						showError("本次数量必须大于0,并且是整数!")
+					}
+
+					if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
+						me.BaseUtil.getRandomNumber();//自动添加编号
+					}
+					if(form.keyField){ //获取ID
+						if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
+							me.FormUtil.getSeqId(form);
+						}
+					}
+					if(form.getForm().isValid()){
+						Ext.each(form.items.items, function(item){
+							if(item.xtype == 'numberfield'){
+								if(item.value == null || item.value == ''){
+									item.setValue(0);
+								}
+							}
+						});
+						var r = form.getValues();
+						//去除ignore字段
+						var keys = Ext.Object.getKeys(r), f;
+						var reg = /[!@#$%^&*()'":,\/?]/;
+						Ext.each(keys, function(k){
+							f = form.down('#' + k);
+							if(f && f.logic == 'ignore') {
+								delete r[k];
+							}
+							//codeField值强制大写,自动过滤特殊字符
+							if(k == form.codeField && !Ext.isEmpty(r[k])) {
+								r[k] = r[k].trim().toUpperCase().replace(reg, '');
+							}
+						});
+						me.save(r, '/pm/mes/genSNRuleDetail.action',form);
+					}
+				}
+			},
+
+			/**
+			 * 补生成条码
+			 */
+			'erpSuppleGenBarButton': {
+				click: function (btn) {
+					var form = Ext.getCmp('form');
+					if (!me.FormUtil.checkForm()) {
+						return;
+					}
+					//判断本次数量必填
+					var addqty = Ext.getCmp("mm_addqty");
+					if (!addqty) {
+						showError("必须配置并且维护补生成数量字段!")
+					}
+					if (addqty && (addqty.value == null || addqty.value == '' || addqty.value <= 0)) {
+						showError("补生成数量必须大于0,并且是整数!")
+					}
+					if (Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == '') {
+						me.BaseUtil.getRandomNumber();//自动添加编号
+					}
+					if (form.keyField && (Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == '')) {
+						me.FormUtil.getSeqId(form);
+					}
+					if (form.getForm().isValid()) {
+						Ext.each(form.items.items, function (item) {
+							if (item.xtype == 'numberfield') {
+								if (item.value == null || item.value == '') {
+									item.setValue(0);
+								}
+							}
+						});
+						var r = form.getValues();
+						//去除ignore字段
+						var keys = Ext.Object.getKeys(r), f;
+						var reg = /[!@#$%^&*()'":,\/?]/;
+						Ext.each(keys, function (k) {
+							f = form.down('#' + k);
+							if (f && f.logic == 'ignore') {
+								delete r[k];
+							}
+							//codeField值强制大写,自动过滤特殊字符
+							if (k == form.codeField && !Ext.isEmpty(r[k])) {
+								r[k] = r[k].trim().toUpperCase().replace(reg, '');
+							}
+						});
+						me.save(r, '/pm/mes/suppleSNRuleDetail.action', form);
+					}
+				}
+			},
+
+			//删除全部条码明细
+			'erpDeleteAllDetailsButton':{
+				afterrender:function(btn){
+					var v_mid = Ext.getCmp("mm_id");
+					if(v_mid && (v_mid.value==0 ||null == v_mid.value ||'' == v_mid.value)){
+						btn.hide();
+					}
+				},
+				click:function (btn){
+					warnMsg("确定清空所有条码明细", function(btn){
+						if(btn == 'yes'){
+							Ext.Ajax.request({
+								url : basePath + "pm/mes/deleteSNRuleDetail.action",
+								params: {
+									caller: caller,
+									id:Ext.getCmp("mm_id").value
+								},
+								method : 'post',
+								callback : function(options,success,response){
+									var res = new Ext.decode(response.responseText);
+									if(res.exceptionInfo != null){
+										showError(res.exceptionInfo);return;
+									}else {
+										window.location.href = window.location.href;
+									}
+								}
+							})
+						}else{
+							return;
+						}
+					})
+				}
+			},
+			'erpCloseButton' : {
+				click : function(btn) {
+					me.FormUtil.beforeClose(me);
+				}
+			},
+			'erpDeleteButton':{
+				click: function(btn){
+					me.FormUtil.onDelete(Ext.getCmp('mm_id').value);
+				}
+			}
+		});
+	},
+
+	getForm : function(btn) {
+		return btn.ownerCt.ownerCt;
+	},
+
+	save: function(r,url,form){
+		var me = this;
+		var params = new Object();
+		Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
+			if(contains(k, 'ext-', true)){
+				delete r[k];
+			}
+		});
+		params.formStore = unescape(escape(Ext.JSON.encode(r)));
+		params.caller = caller;
+		form.setLoading(true);
+		Ext.Ajax.request({
+			url : basePath + url,
+			params : params,
+			method : 'post',
+			callback : function(options,success,response){
+				form.setLoading(false);
+				var localJson = new Ext.decode(response.responseText);
+				if(localJson.success){
+					showMessage('提示', '生成条码成功!', 1000);
+					//update成功后刷新页面进入可编辑的页面
+					var u = String(window.location.href);
+					if (u.indexOf('formCondition') == -1) {
+						var value = r[form.keyField];
+						var formCondition = form.keyField + "IS" + value ;
+						if(me.contains(window.location.href, '?', true)){
+							window.location.href = window.location.href + '&formCondition=' + formCondition ;
+						} else {
+							window.location.href = window.location.href + '?formCondition=' + formCondition ;
+						}
+					} else {
+						window.location.reload();
+					}
+				} else if(localJson.exceptionInfo){
+					var str = localJson.exceptionInfo;
+					if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
+						str = str.replace('AFTERSUCCESS', '');
+						//update成功后刷新页面进入可编辑的页面
+						var u = String(window.location.href);
+						if (u.indexOf('formCondition') == -1) {
+							var value = r[form.keyField];
+							var formCondition = form.keyField + "IS" + value ;
+							if(me.contains(window.location.href, '?', true)){
+								window.location.href = window.location.href + '&formCondition=' + formCondition ;
+							} else {
+								window.location.href = window.location.href + '?formCondition=' + formCondition ;
+							}
+						} else {
+							window.location.reload();
+						}
+					}
+					showError(str);return;
+				} else{
+					saveFailure();//@i18n/i18n.js
+				}
+			}
+		});
+	},
+});

+ 18 - 0
WebContent/app/view/core/button/SuppleGenBar.js

@@ -0,0 +1,18 @@
+/**
+ * 补生成条码按钮
+ */
+Ext.define('erp.view.core.button.SuppleGenBar',{
+    extend: 'Ext.Button',
+    alias: 'widget.erpSuppleGenBarButton',
+    iconCls: 'x-button-icon-add',
+    cls: 'x-btn-gray',
+    id: 'supplegenbarbutton',
+    text: $I18N.common.button.erpSuppleGenBarButton,
+    style: {
+        marginLeft: '10px'
+    },
+    width: 100,
+    initComponent : function(){
+        this.callParent(arguments);
+    }
+});

+ 21 - 0
WebContent/app/view/pm/mes/MakeSNRuleMain.js

@@ -0,0 +1,21 @@
+Ext.define('erp.view.pm.mes.MakeSNRuleMain',{
+	extend: 'Ext.Viewport', 
+	layout: 'fit', 
+	hideBorders: true, 
+	initComponent : function(){ 
+		var me = this; 
+		Ext.apply(me, { 
+			items: [{ 
+				layout: 'anchor', 
+				items: [{
+					xtype: 'erpFormPanel',
+					anchor: '100% 100%',
+					getIdUrl: 'common/getId.action?seq=MakeSNRuleMain_SEQ',
+					deleteUrl:'pm/mes/deleteSNRuleMain.action',
+					keyField: 'mm_id'
+				}]
+			}] 
+		});
+		me.callParent(arguments); 
+	} 
+});

+ 36 - 0
WebContent/jsps/pm/mes/makeSNRuleMain.jsp

@@ -0,0 +1,36 @@
+<%@ page language="java" contentType="text/html; charset=utf-8"
+    pageEncoding="utf-8"%>
+<%
+String path = request.getContextPath();
+String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
+%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<link rel="stylesheet" href="<%=basePath %>resource/ext/resources/css/ext-all-gray.css" type="text/css"></link>
+<link rel="stylesheet" href="<%=basePath %>resource/css/main.css" type="text/css"></link>
+<script type="text/javascript" src="<%=basePath %>resource/ext/ext-all.js"></script>
+<script type="text/javascript" src="<%=basePath %>resource/i18n/i18n.js"></script>
+<script type="text/javascript">	
+Ext.Loader.setConfig({
+	enabled: true
+});//开启动态加载
+Ext.application({
+    name: 'erp',//为应用程序起一个名字,相当于命名空间
+    appFolder: basePath+'app',//app文件夹所在路径
+    controllers: [//声明所用到的控制层
+        'pm.mes.MakeSNRuleMain'
+    ],
+    launch: function() {
+    	Ext.create('erp.view.pm.mes.MakeSNRuleMain');//创建视图
+    }
+});
+var caller ="MakeSNRuleMain";
+var formCondition = '';
+var gridCondition = '';
+</script>
+</head>
+<body >
+</body>
+</html>

+ 2 - 1
WebContent/resource/i18n/messages_zh_CN.js

@@ -687,7 +687,8 @@ var $I18N = {
                 erpExportScanLoginButton:'导出人员二维码信息',
                 erpBomDetailPanelImpButton:'BOM板面位号匹配',
                 erpGetMPBarcodeButton:'获取料卷号',
-                erpVastCheckAOIButton: '批量核对'
+                erpVastCheckAOIButton: '批量核对',
+				erpSuppleGenBarButton: '补生成条码',
 			},
 			status: {
 				

+ 77 - 0
src/com/uas/mes/pm/controller/MakeSNRuleMainController.java

@@ -0,0 +1,77 @@
+package com.uas.mes.pm.controller;
+
+import com.uas.mes.core.util.BaseController;
+import com.uas.mes.pm.service.MakeSNRuleMainService;
+import com.uas.mes.pm.service.MakeSNRuleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+@Controller
+public class MakeSNRuleMainController extends BaseController {
+	@Autowired
+	private MakeSNRuleMainService makeSNRuleMainService;
+
+
+	/**
+	 * 生成镭雕条码
+	 * @param formStore
+	 * @param caller
+	 * @return
+	 */
+	@RequestMapping("/pm/mes/genSNRuleDetail.action")
+	@ResponseBody
+	public Map<String, Object> genSNRuleDetail(String formStore, String caller) {
+		Map<String, Object> modelMap = new HashMap<String, Object>();
+		makeSNRuleMainService.genSNRuleDetail(formStore, caller);
+		modelMap.put("success", true);
+		return modelMap;
+	}
+
+
+	/**
+	 * 删除条码明细
+	 */
+	@RequestMapping("/pm/mes/deleteSNRuleDetail.action")
+	@ResponseBody
+	public Map<String, Object> deleteSNRuleDetail(String caller, int id) {
+    	Map<String, Object> modelMap = new HashMap<String, Object>();
+		makeSNRuleMainService.deleteSNRuleDetail(id, caller);
+		modelMap.put("success", true);
+		return modelMap;
+	}
+
+
+	/**
+	 * 补生成镭雕条码
+	 * @param formStore
+	 * @param caller
+	 * @return
+	 */
+	@RequestMapping("/pm/mes/suppleSNRuleDetail.action")
+	@ResponseBody
+	public Map<String, Object> suppleSNRuleDetail(String formStore, String caller) {
+		Map<String, Object> modelMap = new HashMap<String, Object>();
+		makeSNRuleMainService.suppleSNRuleDetail(formStore, caller);
+		modelMap.put("success", true);
+		return modelMap;
+	}
+
+	/**
+	 * 删除单据主表
+	 */
+	@RequestMapping("/pm/mes/deleteSNRuleMain.action")
+	@ResponseBody
+	public Map<String, Object> deleteSNRuleMain(String caller, int id) {
+		Map<String, Object> modelMap = new HashMap<String, Object>();
+		makeSNRuleMainService.deleteSNRuleMain(id, caller);
+		modelMap.put("success", true);
+		return modelMap;
+	}
+
+}

+ 13 - 0
src/com/uas/mes/pm/service/MakeSNRuleMainService.java

@@ -0,0 +1,13 @@
+package com.uas.mes.pm.service;
+
+import org.springframework.stereotype.Service;
+
+public interface MakeSNRuleMainService {
+    void genSNRuleDetail(String formStore, String caller);
+
+    void deleteSNRuleDetail(int id, String caller);
+
+    void suppleSNRuleDetail(String formStore, String caller);
+
+    void deleteSNRuleMain(int id, String caller);
+}

+ 122 - 0
src/com/uas/mes/pm/service/impl/MakeSNRuleMainServiceImpl.java

@@ -0,0 +1,122 @@
+package com.uas.mes.pm.service.impl;
+
+import com.uas.mes.common.data.BaseDao;
+import com.uas.mes.common.data.SqlUtil;
+import com.uas.mes.common.support.HandlerService;
+import com.uas.mes.common.support.SystemSession;
+import com.uas.mes.common.util.BaseUtil;
+import com.uas.mes.core.data.SqlRowList;
+import com.uas.mes.core.util.StringUtil;
+import com.uas.mes.pm.service.MakeSNRuleMainService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Map;
+
+@Service
+public class MakeSNRuleMainServiceImpl implements MakeSNRuleMainService {
+    @Autowired
+    private BaseDao baseDao;
+
+    @Autowired
+    private HandlerService handlerService;
+
+    /**
+     * 生成镭雕条码
+     * @param formStore
+     * @param caller
+     * @return
+     */
+    @Override
+    public void genSNRuleDetail(String formStore, String caller) {
+        Map<Object, Object> map = BaseUtil.parseFormStoreToMap(formStore);
+        String err = baseDao.getJdbcTemplate().queryForObject("select wm_concat(mm_code) " +
+                " from makesnrulemain where mm_macode=? and mm_id<>?",String.class,map.get("mm_macode"),map.get("mm_id"));
+        if(null != err){
+            BaseUtil.showError("一个工单只能维护一张数据,当前工单已经维护了单据:"+err);
+        }
+        int cn = baseDao.getJdbcTemplate().queryForObject("select count(1) from make where ma_code=?",Integer.class,map.get("mm_macode"));
+        if(cn == 0){
+            BaseUtil.showError("工单:"+map.get("mm_macode")+"不存在或者已删除!");
+        }
+        //已经生成数量+本次数量 跟工单数量 进行比较
+        SqlRowList rs = baseDao.queryForRowSet("select * from makesnrulemain where mm_id=?",map.get("mm_id"));
+        if(rs.next()) {
+            if(!rs.getGeneralString("mm_macode").equals(map.get("mm_macode"))){
+                BaseUtil.showError("工单不允许修改,原工单:"+rs.getGeneralString("mm_macode")+",新工单:"+map.get("mm_macode")+"!");
+            }
+            baseDao.execute(SqlUtil.getUpdateSqlByFormStore(map,"makesnrulemain","mm_id"));
+        }else{
+            baseDao.execute(SqlUtil.getInsertSqlByMap(map,"makesnrulemain"));
+        }
+        baseDao.logger.save(caller,"mm_id",map.get("mm_id"));
+        String da = baseDao.callProcedure("MA_GENMAKESNRULEDETAIL",map.get("mm_id"),"生成", SystemSession.getUser().getEm_name());
+        if(StringUtil.hasText(da)){
+            BaseUtil.showError(da);
+        }
+    }
+
+    /**
+     * 删除条码明细
+     */
+    @Override
+    public void deleteSNRuleDetail(int id, String caller) {
+        //判断有没有被获取的条码,如果有则不允许删除所有
+        SqlRowList rs = baseDao.queryForRowSet("select mm_code,mm_macode from makesnrulemain where mm_id=?",id);
+        if(rs.next()) {
+            int cn = baseDao.getCount("select count(1) from makesnruledetail where msd_mainid=" + id);
+            if(cn == 0){
+                BaseUtil.showError("当前单据未关联生成镭雕条码,无需删除明细!");
+            }
+            baseDao.execute("delete from makesnruledetail where msd_mainid=?", id);
+            baseDao.logger.others("删除所有条码明细", "删除有条码明细("+cn+"条)成功", caller, "mm_id", id);
+        }else{
+            BaseUtil.showError("当前单据不存在或者已经删除!");
+        }
+    }
+
+    /**
+     * 补生成镭雕条码
+     * @param formStore
+     * @param caller
+     * @return
+     */
+    @Override
+    public void suppleSNRuleDetail(String formStore, String caller) {
+        Map<Object, Object> map = BaseUtil.parseFormStoreToMap(formStore);
+        String err = baseDao.getJdbcTemplate().queryForObject("select wm_concat(mm_code) " +
+                " from makesnrulemain where mm_macode=? and mm_id<>?",String.class,map.get("mm_macode"),map.get("mm_id"));
+        if(null != err){
+            BaseUtil.showError("一个工单只能维护一张数据,当前工单已经维护了单据:"+err);
+        }
+        int cn = baseDao.getJdbcTemplate().queryForObject("select count(1) from make where ma_code=?",Integer.class,map.get("mm_macode"));
+        if(cn == 0){
+            BaseUtil.showError("工单:"+map.get("mm_macode")+"不存在或者已删除!");
+        }
+        //已经生成数量+本次数量 跟工单数量 进行比较
+        SqlRowList rs = baseDao.queryForRowSet("select * from makesnrulemain where mm_id=?",map.get("mm_id"));
+        if(rs.next()) {
+            if(!rs.getGeneralString("mm_macode").equals(map.get("mm_macode"))){
+                BaseUtil.showError("工单不允许修改,原工单:"+rs.getGeneralString("mm_macode")+",新工单:"+map.get("mm_macode")+"!");
+            }
+            baseDao.execute(SqlUtil.getUpdateSqlByFormStore(map,"makesnrulemain","mm_id"));
+        }else{
+            baseDao.execute(SqlUtil.getInsertSqlByMap(map,"makesnrulemain"));
+        }
+        String da = baseDao.callProcedure("MA_GENMAKESNRULEDETAIL",map.get("mm_id"),"补生成",SystemSession.getUser().getEm_name());
+        if(StringUtil.hasText(da)){
+            BaseUtil.showError(da);
+        }
+    }
+
+    /**
+     * 删除单据主表
+     * @param id
+     * @param caller
+     */
+    @Override
+    public void deleteSNRuleMain(int id, String caller) {
+
+    }
+}