Index: ssts-web/src/main/webapp/js/Ext4CompUtil.js =================================================================== diff -u -r15527 -r15924 --- ssts-web/src/main/webapp/js/Ext4CompUtil.js (.../Ext4CompUtil.js) (revision 15527) +++ ssts-web/src/main/webapp/js/Ext4CompUtil.js (.../Ext4CompUtil.js) (revision 15924) @@ -24,6 +24,8 @@ */ comboBuilder.getStore = function (storeConfig) { var store = Ext4.create('Ext.data.Store', { + //limit参数,每页显示条数,默认为25 + pageSize: storeConfig.pageSize || 25, model: storeConfig.model, proxy: { type: 'ajax', @@ -42,8 +44,7 @@ /** * 创建并获得combo对象 * @param comboConfig 相关的配置 - * 1.(必选:store,valueField,displayField,fieldLabel,id,name) - * 2.(可选:width,allowBlank,listeners) + * (必选:store,valueField,displayField,fieldLabel,id,name) * @returns {Ext4.form.ComboBox} */ comboBuilder.getCombo = function (comboConfig) { @@ -54,7 +55,8 @@ fieldLabel: comboConfig.fieldLabel, id: comboConfig.id, name: comboConfig.name, - queryParam: 'spell', + //查询参数,Ext默认为 query,现在改成spell + queryParam: comboConfig.queryParam || 'spell', triggerAction: 'all', minChars: 0, width: comboConfig.width || 600, @@ -63,6 +65,8 @@ triggerAction: 'all', hideTrigger: true, typeAhead: false, + //下拉列表框的分页大小,非false的数字就会创建分页 + pageSize : comboConfig.pageSize || false, allowBlank: comboConfig.allowBlank || true, anchor: '97%', listeners: comboConfig.listeners || { Index: ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsApplicationView.jsp =================================================================== diff -u -r15855 -r15924 --- ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsApplicationView.jsp (.../goodsApplicationView.jsp) (revision 15855) +++ ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsApplicationView.jsp (.../goodsApplicationView.jsp) (revision 15924) @@ -274,6 +274,7 @@ + Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/basedatamanager/supplyroomconfig/action/SupplyRoomConfigAction.java =================================================================== diff -u -r15685 -r15924 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/basedatamanager/supplyroomconfig/action/SupplyRoomConfigAction.java (.../SupplyRoomConfigAction.java) (revision 15685) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/basedatamanager/supplyroomconfig/action/SupplyRoomConfigAction.java (.../SupplyRoomConfigAction.java) (revision 15924) @@ -12,6 +12,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.forgon.entity.PageEntity; +import com.forgon.tools.util.PageUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -21,7 +23,6 @@ import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ParentPackage; -import org.apache.struts2.util.StrutsUtil; import com.forgon.directory.acegi.tools.AcegiHelper; import com.forgon.directory.model.OrgUnit; @@ -858,6 +859,8 @@ * 获取申请科室Json */ public void getApplicationDepartJson() { + int start = StrutsParamUtils.getPraramValue("start", -1); + int limit = StrutsParamUtils.getPraramValue("limit", -1); String spell = StrutsParamUtils.getPraramValue("spell", ""); String withoutBaseOrg = StrutsParamUtils.getPraramValue( "withoutBaseOrg", "true"); @@ -871,9 +874,11 @@ map.put(supplyRoomConfig.getOrgUnitCoding(), supplyRoomConfig.getOrgUnitName()); } - StringBuffer buff = new StringBuffer(); + // StringBuffer buff = new StringBuffer(); + List> list = new LinkedList<>(); if (orgUnitList != null) { for (int j = 0; j < orgUnitList.size(); j++) { + Map reMap = new HashMap<>(); String orgCoding = orgUnitList.get(j).getOrgUnitCoding(); if(map.get(orgCoding) != null){//是否属于结算配置科室 String orgName = null; @@ -884,18 +889,27 @@ orgName = orgName.replace("组织机构-", ""); } orgName = StringEscapeUtils.escapeEcmaScript(orgName); - buff.append("{\"id\":\"").append(orgCoding).append("\""); + reMap.put("id",orgCoding); + reMap.put("departCode",orgCoding); + reMap.put("name",orgName); + list.add(reMap); + /*buff.append("{\"id\":\"").append(orgCoding).append("\""); buff.append(",\"departCode\":\"").append(orgCoding).append("\""); buff.append(",\"name\":\"").append(orgName).append("\"}"); - buff.append(","); + buff.append(",");*/ } else{ //广医二院未配置为申请科室的科室有两百多条,每次进入科室申领页面都会打印,数据量太大,先注释 //logger.warn("找不到orgUnitCoding对应的部门,orgUnitCoding的值为:" + orgCoding); } } } - String jsonStr = ""; + PageEntity pageEntity = new PageEntity(); + pageEntity.setStart(start); + pageEntity.setLimit(limit); + pageEntity.setNeedToEscape(true); + PageUtil.outPutResult(pageEntity, list); + /*String jsonStr = ""; if(buff.length() > 0){ jsonStr = buff.substring(0,buff.length()-1); } @@ -904,15 +918,17 @@ response.setCharacterEncoding("utf-8"); response.getWriter().print("{\"data\":[" + jsonStr + "]}"); response.getWriter().close(); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); - } + }*/ } /** * 获取结算科室Json */ public void getSettleAccountsDepartJson() { + // int start = StrutsParamUtils.getPraramValue("start", 0); + // int limit = StrutsParamUtils.getPraramValue("limit", 0); String spell = StrutsParamUtils.getPraramValue("spell", ""); String withoutBaseOrg = StrutsParamUtils.getPraramValue( "withoutBaseOrg", "true"); @@ -926,9 +942,10 @@ map.put(supplyRoomConfig.getOrgUnitCoding(), supplyRoomConfig.getOrgUnitName()); } - StringBuffer buff = new StringBuffer(); + List> list = new LinkedList<>(); if (orgUnitList != null) { for (int j = 0; j < orgUnitList.size(); j++) { + Map reMap = new HashMap<>(); String orgCoding = orgUnitList.get(j).getOrgUnitCoding(); if(map.get(orgCoding) != null){//是否属于结算配置科室 String orgName = null; @@ -939,24 +956,16 @@ orgName = orgName.replace("组织机构-", ""); } orgName = StringEscapeUtils.escapeEcmaScript(orgName); - buff.append("{\"id\":\"").append(orgCoding).append("\""); - buff.append(",\"name\":\"").append(orgName).append("\"}"); - buff.append(","); + reMap.put("id",orgCoding); + reMap.put("name",orgName); + list.add(reMap); } } } - String jsonStr = ""; - if(buff.length() > 0){ - jsonStr = buff.substring(0,buff.length()-1); - } - HttpServletResponse response = StrutsParamUtils.getResponse(); - try { - response.setCharacterEncoding("utf-8"); - response.getWriter().print("{\"data\":[" + jsonStr + "]}"); - response.getWriter().close(); - } catch (IOException e) { - e.printStackTrace(); - } + PageEntity pageEntity = new PageEntity(); + pageEntity.setNeedToEscape(true); + //结算科室不能分页,因为结算科室是根据申领科室改变而改变的,页面上的申领科室改变了不会请求后台,只会从js的store里查找数据,所以这里要一次加载所有的数据出来 + PageUtil.outPutResult(pageEntity, list); } public void getAllOrgUnitName() { Index: ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js =================================================================== diff -u -r15878 -r15924 --- ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js (.../goodsTemplateApplicationView.js) (revision 15878) +++ ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js (.../goodsTemplateApplicationView.js) (revision 15924) @@ -226,11 +226,14 @@ //Ext4 结算科室Store var departJsonStore = new Ext4.data.JsonStore({ + // pageSize : 15, + autoLoad : false, proxy : { type : 'ajax', url : WWWROOT + '/disinfectSystem/baseData/supplyRoomConfigAction!getSettleAccountsDepartJson.do', reader : { type : 'json', + totalProperty : 'totalCount', root : 'data' } }, @@ -275,11 +278,15 @@ //Ext4 申请科室Store var appDepartJsonStore = new Ext4.data.Store({ + //limit参数,每页显示条数,默认为25 + pageSize: 15, + autoLoad:false, proxy : { type : 'ajax', url : WWWROOT + '/disinfectSystem/baseData/supplyRoomConfigAction!getApplicationDepartJson.do', reader : { type : 'json', + totalProperty : 'totalCount', root : 'data' } }, @@ -638,6 +645,7 @@ return validateFlag; } + function getExsistNode(treeStore, nodeName){ var foundNode = null; var rootNode = treeStore.getRootNode(); @@ -729,13 +737,19 @@ //TODO 5 取消科室申请模板 function addItems(tousseDefinitionID,name,count,diposable,isApplyEntireTousse,price,externalCode,storageAmount,tousseType,materials,unit,packageSpec,minApplyAmount,maxApplyAmount,urgentAmount,para){ var foundNode = null; + var needToCheckNode = { + tousseDefinitionID : tousseDefinitionID + } + var goodsAppDomObj = GoodsAppHelper.getGoodsAppDomObj(); if('是' == diposable){ - foundNode = getExsistNode(rightTemplateStore, name); + foundNode = goodsAppDomObj.getExitsNodeByNode(rightTemplateStore, needToCheckNode); + // foundNode = getExsistNode(rightTemplateStore, name); if (foundNode != null){ updateNode('diposableTreeGrid', foundNode, count, price,urgentAmount,para); } }else{ - foundNode = getExsistNodeByTousseDefinitionID(leftTemplateStore, tousseDefinitionID); + foundNode = goodsAppDomObj.getExitsNodeByNode(leftTemplateStore, needToCheckNode); + // foundNode = getExsistNodeByTousseDefinitionID(leftTemplateStore, tousseDefinitionID); if (foundNode != null){ updateNode('tousseTreeGrid', foundNode, count, price,urgentAmount); if(tousseType == tousseType_disinfectGoods){ @@ -902,27 +916,6 @@ top.Ext4.getCmp('count1').focus(); } -/** - * 判断表格是否已经存在该物品 - * @param name 新添加物品的名字 - * @param type 新添加物品的类型 - * @returns {boolean} true就是存在,false就是不存在 - */ -function judgeIfExits(name,type) { - var node = "一次性物品" == type ? rightTemplateStore.getRootNode().childNodes:leftTemplateStore.getRootNode().childNodes; - var isExits = false; - if (!isUndefinedOrNullOrEmpty(node)) { - Ext.each(node,function (record) { - if (record.get('name') == name){ - showResult("已经存在" + name + ",不能重复添加!"); - isExits = true; - //此return false只是用于中断extJs的迭代,不是函数的返回 - return false; - } - }); - } - return isExits; -} function addRecyclingApplicationItem(){ var id = curSelectedGoods.id; @@ -939,6 +932,30 @@ var unit = top.Ext4.getCmp('unit').getValue(); var packageSpec = top.Ext4.getCmp('packageSpec').getValue(); var isApplyEntireTousse = top.Ext4.getCmp('isApplyEntireTousse').getValue(); + + + var needToCheckNode = { + tousseDefinitionID : id, + name : name, + tousseType : tousseType + } + var findNode = null; + var goodsAppDomObj = GoodsAppHelper.getGoodsAppDomObj(); + // 从左边和右边分别寻找,看看是否已经存在相同的物品(用于提交了器械包申请单,但下次打开这张单,申请的器械包会去到右边,这时又申请了同样的物品,这时就需要判断左边和右边的store了 + //如果是器械包则校验TousseDefinitionID,如果是消毒物品则校验checkNameAndType + if (tousseType != tousseType_disinfectGoods){ + findNode = goodsAppDomObj.getExitsNodeByNode(rightTemplateStore, needToCheckNode) || goodsAppDomObj.getExitsNodeByNode(leftTemplateStore, needToCheckNode); + } + else { + findNode = goodsAppDomObj.getExitsNodeByNode(rightTemplateStore, needToCheckNode, goodsAppDomObj.checkNameAndType) || goodsAppDomObj.getExitsNodeByNode(leftTemplateStore, needToCheckNode, goodsAppDomObj.checkNameAndType); + } + if (!Ext4.isEmpty(findNode) && !Ext4.isEmpty(findNode.get('count'))){ + showResult("已经存在:" + name + ",请不要重复添加!"); + return false; + } + + + //para对象,里面可以有多钟属性,方便以后扩展addItems用 var para = { behavior : 'add', @@ -2232,6 +2249,10 @@ triggerAction : 'all', hideTrigger : true, typeAhead : false, + pageSize : 100, + width : 400, + matchFieldWidth: false, + listConfig: {width: 300}, allowBlank : false, flex : 1, listeners:{ @@ -2307,6 +2328,10 @@ triggerAction : 'all', hideTrigger : true, typeAhead : false, + // pageSize : 100, + width : 400, + matchFieldWidth: false, + listConfig: {width: 300}, allowBlank : false, flex : 1, listeners:{ @@ -2640,6 +2665,9 @@ ] }); + if (Ext4.isEmpty(applicationWindow)){ + allGoodsComboStore.reload(); + } applicationWindow = new top.Ext4.window.Window({ @@ -2657,8 +2685,7 @@ applicationWindow.show(); - allGoodsComboStore.reload(); - + // loadMask = new Ext4.LoadMask({msg:'数据处理中,请稍候......',target:applicationWindow}); if (!top.Ext4.isIE6 && !top.Ext4.isIE7){ createExt4Mask.call(objMask,'loadMask','数据处理中,请稍候......',applicationWindow); Index: forgon-tools/src/main/java/com/forgon/tools/util/PageUtil.java =================================================================== diff -u --- forgon-tools/src/main/java/com/forgon/tools/util/PageUtil.java (revision 0) +++ forgon-tools/src/main/java/com/forgon/tools/util/PageUtil.java (revision 15924) @@ -0,0 +1,78 @@ +package com.forgon.tools.util; + +import com.forgon.entity.PageEntity; +import com.forgon.tools.StrutsResponseUtils; +import net.sf.json.JSONObject; +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.log4j.Logger; + +import java.util.List; +import java.util.Map; + +/** + * Created by zhonghaowen on 2016/11/23. + * 分页工具类 + */ +public class PageUtil { + + private static final Logger logger = Logger.getLogger(PageUtil.class); + + /** + * 分页方法 + * + * @param start 从第几条开始 + * @param limit 取多少条 + * @param list 要分页的list + * @return 分页好了的list + */ + public static List startPage(int start, int limit, List list) { + List reList = list; + //当limit和start大于0的时候才需要分页 + if (limit > 0 && start >= 0) { + int end = start + limit; + if (CollectionUtils.isNotEmpty(list)) { + end = end > list.size() - 1 ? list.size() : end; + reList = list.subList(start, end); + } + } + return reList; + } + + /** + * 输出结果到页面 + * + * @param list 需要输出的list + * @param pageEntity 分页的实体类 + */ + public static void outPutResult(PageEntity pageEntity, List list) { + try { + List> reList = PageUtil.startPage(pageEntity.getStart(), pageEntity.getLimit(), list); + JSONObject jsonObject = new JSONObject(); + Map map = pageEntity.getMap(); + if (!map.isEmpty()) { + BeanUtils.populate(jsonObject, map); + } + if (list.size() > 0) { + jsonObject.put("data", reList); + jsonObject.put("totalCount", list.size()); + String result = jsonObject.toString(); + //是否需要做转义处理 + if (pageEntity.getNeedToEscape() == true) { + //这里一定要将\\转成\,因为返回页面的jsonObject是以toString的形式返回的,如果这里有属性使用了escapeEcmaScript转码,那么toString会在转码之后再加上一个反斜杠,所以要在这里做处理 + result = result.replace("\\\\", "\\"); + } + StrutsResponseUtils.output(result); + } + else { + jsonObject.put("data", ""); + jsonObject.put("totalCount", 0); + StrutsResponseUtils.output(jsonObject); + } + } + catch (Exception e) { + logger.error(e, e); + throw new RuntimeException(e); + } + } +} Index: ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsAppHelper.js =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsAppHelper.js (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsAppHelper.js (revision 15924) @@ -0,0 +1,80 @@ +/** + * Created by zhonghaowen on 2016/11/25. + */ +//科室申领帮助类,用于封装一些逻辑业务的方法 +var GoodsAppHelper = (function () { + + var GoodsAppHelperFactory = function () { + this.getGoodsAppDomObj = function () { + return goodsAppDomObj; + } + } + + //科室申请操作节点的对象 + var goodsAppDomObj = {}; + + /** + * 根据名字和种类查找是否存在相同的节点 + * @param treeStore 树的store + * @param node 需要校验的节点(里面可以有name,tousseType,tousseDefinitionID) + * @param checkFn 需要调用校验的节点的方法(可选,暂时有checkNameAndType,checkTousseDefinitionID),默认调用checkTousseDefinitionID + * @returns {*} + */ + goodsAppDomObj.getExitsNodeByNode = function (treeStore, node, checkFn) { + var me = this; + var foundNode = null; + var rootNode = treeStore.getRootNode(); + checkFn = checkFn || me.checkTousseDefinitionID; + rootNode.cascadeBy(function (n) { + var checkNode = checkFn(n, rootNode, node); + if (!Ext4.isEmpty(checkNode)) { + foundNode = checkNode; + //return false是终止循环遍历,但好像不无效,所以这里要多加一个checkNode赋值 + return false; + } + }); + return foundNode; + } + + /** + * 检验名字和类型 + * @param storeNode store的节点 + * @param rootNode 根节点 + * @param needToCheckNode 需要校验的节点 + * @returns {*} + */ + goodsAppDomObj.checkNameAndType = function (storeNode, rootNode, needToCheckNode) { + var tousseType = needToCheckNode.tousseType; + var name = needToCheckNode.name; + // var foundNode = null; + if (storeNode.get('name') == name && storeNode.get('tousseType') == tousseType) { + if (storeNode.parentNode == rootNode) { + return storeNode; + } + } + return null; + } + + /** + * 检验tousseDefinitionID + * @param storeNode store的节点 + * @param rootNode 根节点 + * @param needToCheckNode 需要校验的节点 + * @returns {*} + */ + goodsAppDomObj.checkTousseDefinitionID = function (storeNode, rootNode, needToCheckNode) { + var foundNode = null; + // var foundNode = null; + var tousseDefinitionID = needToCheckNode.tousseDefinitionID; + if (storeNode.get('tousseDefinitionID') == tousseDefinitionID) { + if (storeNode.parentNode == rootNode) { + return storeNode; + } + } + return null; + } + + return new GoodsAppHelperFactory(); + +})(); + Index: forgon-tools/src/main/java/com/forgon/entity/PageEntity.java =================================================================== diff -u --- forgon-tools/src/main/java/com/forgon/entity/PageEntity.java (revision 0) +++ forgon-tools/src/main/java/com/forgon/entity/PageEntity.java (revision 15924) @@ -0,0 +1,75 @@ +package com.forgon.entity; + + +import org.apache.commons.collections.map.HashedMap; + +import java.util.Map; + +/** + * Created by zhonghaowen on 2016/11/24. + * 分页实体类 + */ +public class PageEntity { + + /** + * 分页的开始(小于0是默认不做分页处理) + */ + private int start = -1; + + /** + * 分页取多少数据(小于0是默认不做分页处理) + */ + private int limit = -1; + + /** + * 结果是否需要转义 + */ + private boolean needToEscape; + + /** + * 输出到页面有可能需要用到的参数 + */ + private Map map = new HashedMap(); + + public int getStart() { + return start; + } + + public void setStart(int start) { + this.start = start; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + + public boolean getNeedToEscape() { + return needToEscape; + } + + public void setNeedToEscape(boolean needToEscape) { + this.needToEscape = needToEscape; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + + @Override + public String toString() { + return "PageEntity{" + + "start=" + start + + ", limit=" + limit + + ", needToEscape=" + needToEscape + + ", map=" + map + + '}'; + } +} \ No newline at end of file