Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/enums/GoodType.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/enums/GoodType.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/enums/GoodType.java (revision 15116) @@ -0,0 +1,38 @@ +package com.forgon.disinfectsystem.goodsBindingConfig.enums; + +/** + * Created by zhonghaowen on 2016/9/22. + * 绑定物品种类,主要绑定物或者次要绑定物 + */ +public enum GoodType { + + MAIN(0, "主要绑定物"), + SECOND(1, "次要绑定物"); + + private String desc; + private Integer val; + + GoodType(Integer val, String desc) { + this.val = val; + this.desc = desc; + } + + public String getDesc() { + return desc; + } + + public Integer getVal() { + return val; + } + + + public static GoodType parseOfDesc(String desc) { + GoodType[] values = GoodType.values(); + for (GoodType value : values) { + if (value.getDesc().equals(desc)) { + return value; + } + } + throw new IllegalArgumentException("找不到对应的类型"); + } +} Index: forgon-tools/src/main/java/com/forgon/tools/util/ExtJsUtil.java =================================================================== diff -u --- forgon-tools/src/main/java/com/forgon/tools/util/ExtJsUtil.java (revision 0) +++ forgon-tools/src/main/java/com/forgon/tools/util/ExtJsUtil.java (revision 15116) @@ -0,0 +1,30 @@ +package com.forgon.tools.util; + +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Created by zhonghaowen on 2016/8/12. + * ExtJs工具类 + */ +public class ExtJsUtil { + + /** + * 设置查询条件参数 + * + * @param parameterMap grid传进来的参数 + */ + public static void setGridSearchQuery(Map> parameterMap) { + if (!CollectionUtils.isEmpty(parameterMap) && !CollectionUtils.isEmpty(parameterMap.get("grid_search_query"))) { + List keyList = parameterMap.get("grid_search_query"); + List queryKey = new ArrayList(keyList.size()); + for (int i = 0; i < keyList.size(); i++) { + queryKey.add(((String) keyList.get(i)).toUpperCase()); + } + parameterMap.put("grid_search_query", queryKey); + } + } +} Index: ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigView.js =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigView.js (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigView.js (revision 15116) @@ -0,0 +1,157 @@ +var entityName = "物品绑定配置"; +var grid; + + +Ext.onReady(function () { + Ext.QuickTips.init(); + /** + * 检查是否有选中 + */ + function isSelected() { + var records = grid.getSelectedRow(); + if (isUndefinedOrNullOrEmpty(records)) { + showResult('请至少选择一个!'); + return false; + } + return true; + } + + //自定义render + var customRender = { + /** + * 捆绑比例render + * @param value 当前的值 + * @param cellMeta 单元格式ID + * @param record 当前行的所有数据 + * @param rowIndex 当前行的行号(分页后的) + * @param columnIndex 列号 + * @param store 数据集 + */ + bindRatioRender: function (value, cellMeta, record, rowIndex, columnIndex, store) { + var mainCount = record.get('mainCount'); + var secondaryCount = record.get('secondaryCount'); + return !isUndefinedOrNullOrEmpty(mainCount) && !isUndefinedOrNullOrEmpty(secondaryCount) ? mainCount + ":" + secondaryCount : ''; + }, + + /** + * 是否允许双向捆绑render + * @param value + */ + bidirectionalStatusRender: function (value) { + return isUndefinedOrNullOrEmpty(value) ? '' : value == 'NO' ? '否' : '是'; + }, + + /** + * 点击物品名称render + */ + modifyGoodsBindRender: function (value, p, record) { + var id = record.get('id'); + return "" + value + ""; + } + }; + + var filters = new Ext.grid.GridFilters({ + filters: [ + {type: 'string', dataIndex: 'id'}, + {type: 'string', dataIndex: 'mainGoodId'}, + {type: 'string', dataIndex: 'secondaryGoodId'}, + {type: 'string', dataIndex: 'mainGoodName'}, + {type: 'string', dataIndex: 'secondaryGoodName'}, + {type: 'string', dataIndex: 'mainCount'}, + {type: 'string', dataIndex: 'secondaryCount'}, + {type: 'string', dataIndex: 'mainGoodsType'}, + {type: 'string', dataIndex: 'secondaryGoodType'}, + {type: 'string', dataIndex: 'bidirectionalStatus'} + ] + } + ); + + var readerDetail = [ + {name: 'id'}, + {name: 'mainGoodId'}, + {name: 'secondaryGoodId'}, + {name: 'mainGoodName'}, + {name: 'secondaryGoodName'}, + {name: 'mainCount'}, + {name: 'secondaryCount'}, + {name: 'mainGoodsType'}, + {name: 'secondaryGoodType'}, + {name: 'bidirectionalStatus'} + ]; + + var columns = [ + {header: "记录id", width: 50, dataIndex: 'id', hidden: true}, + // {header: "主绑定物品名称", width: 200, dataIndex: 'mainGoodName'}, + {header: "主绑定物品名称", width: 200, dataIndex: 'mainGoodName', renderer: customRender.modifyGoodsBindRender}, + {header: "次绑定物品名称", width: 200, dataIndex: 'secondaryGoodName'}, + {header: "主数量", width: 100, dataIndex: 'mainCount'}, + {header: "次数量", width: 100, dataIndex: 'secondaryCount'}, + {header: "捆绑比例", width: 100, renderer: customRender.bindRatioRender}, + {header: "是否允许双向捆绑", width: 150, dataIndex: 'bidirectionalStatus', renderer: customRender.bidirectionalStatusRender} + ]; + + var tbar = [{ + text: '添加', hidden: SSTS_GoodsBindingConfig_Create, + iconCls: 'btn_ext_application_add', + handler: function () { + modifyGoodsBinding(); + } + }, '-', { + text: '修改', + hidden: SSTS_GoodsBindingConfig_Update, + iconCls: 'btn_ext_application_edit', + handler: function (btn) { + if (!isSelected()) { + return; + } + if (grid.getSelectedRow().length > 1) { + showResult('不能选择超过两个!'); + return; + } + modifyGoodsBinding(grid.getSelectedValues()); + } + }, '-', { + text: '删除', + hidden: SSTS_GoodsBindingConfig_Delete, + iconCls: 'btn_ext_application_del', + handler: function () { + if (!isSelected()) { + return; + } + Ext.Msg.confirm("删除物品", "是否要删除?", function (btn) { + if (btn == 'yes') { + deleteGoodsBinding(grid.getSelectedRow()); + } + }, this); + + } + }]; + + grid = new Ext.ux.ForgonPageGrid({ + tbar: tbar, + pageSize: 20, + defaultSortField: 'id', + defaultSortDirection: 'ASC', + title: entityName, + isCheckboxSelectionModel: true, + rememberSelected: false, + isShowSearchField: true, + columns: columns, + plugins: filters, + frame: false + }, + readerDetail, + goodsBindTableManager.findGoodsBindTableList, + null + ); + + var viewport = new Ext.Viewport({ + layout: 'border', + items: [{ + region: 'center', + margins: '0 0 0 0', + layout: 'fit', + items: grid + }] + }); +}); Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/dwr/table/GoodsBindTableManager.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/dwr/table/GoodsBindTableManager.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/dwr/table/GoodsBindTableManager.java (revision 15116) @@ -0,0 +1,31 @@ +package com.forgon.disinfectsystem.goodsBindingConfig.dwr.table; + +import com.forgon.component.grid.GridManager; +import com.forgon.disinfectsystem.goodsBindingConfig.entity.GoodsBindingConfig; +import com.forgon.tools.util.ExtJsUtil; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * Created by zhonghaowen on 2016/8/11. + */ +@Service("goodsBindTableManager") +public class GoodsBindTableManager { + + @Resource + private GridManager gridManager; + + /** + * 查找出所有的物品绑定 + * + * @param parameterMap grid传进来的参数 + * @return + */ + public String findGoodsBindTableList(Map> parameterMap) { + ExtJsUtil.setGridSearchQuery(parameterMap); + return gridManager.renderGrid(parameterMap, GoodsBindingConfig.class.getSimpleName(), null, new String[]{}); + } +} Index: ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js =================================================================== diff -u -r14984 -r15116 --- ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js (.../goodsTemplateApplicationView.js) (revision 14984) +++ ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js (.../goodsTemplateApplicationView.js) (revision 15116) @@ -12,6 +12,9 @@ var windowHeight = top.document.body.clientHeight > 650 ? 650 : top.document.body.clientHeight; var invoicePlanPrintButtonName = '发货计划'; var recyclingApplicationVersion = sstsConfig.recyclingApplicationVersion; +//是否生产环境模式,用于决定是否显示最小单位数量,原来的最小单位,中包装单位装换单位系数,生产环境模式默认true隐藏这三项,平时开发可以将此值设置成false,便于调试 +var productMode = true; +var firstLoad = true; if (sstsConfig.invoicePlanPrintButtonName != undefined){ invoicePlanPrintButtonName = sstsConfig.invoicePlanPrintButtonName; } @@ -301,40 +304,47 @@ //进度条 var loadMask; +//物品选择下拉框的proxy +var goodProxy = { + type : 'ajax', + url : WWWROOT + '/disinfectSystem/baseData/tousseDefinitionAction!searchComboGoodsData.do?showExternalCodeOfDisposableGoods='+sstsConfig.showExternalCodeOfDisposableGoods, + reader : { + type : 'json', + totalProperty : 'totalCount', + idProperty: 'noneExsist', + root : 'data' + } +}; + +//物品选择下拉框的model +var goodModel = [ + {name : 'id',mapping : 'id'}, + {name : 'spelling',mapping : 'spelling'}, + {name : 'name',mapping : 'name'}, + {name : 'tousseDefinitionID'}, + {name : 'type',mapping : 'type'}, + {name : 'tousseType',mapping : 'tousseType'}, + {name : 'isApplyEntireTousse',mapping : 'isApplyEntireTousse'}, + {name : 'displayName',mapping : 'displayName'}, + {name : 'price',mapping : 'price'}, + {name : 'packageSpec',mapping : 'packageSpec'}, + {name : 'unit',mapping : 'unit'}, + {name : 'amount',mapping : 'amount'}, + {name : 'middlePackageUnit',mapping : 'middlePackageUnit'}, + {name : 'middlePackageAmount',mapping : 'middlePackageAmount'}, + {name : 'transferScale',mapping : 'transferScale'}, + {name : 'urgentAmount',mapping : 'urgentAmount'}, + {name : 'materials',mapping : 'materials'}, + {name : 'minApplyAmount',mapping : 'minApplyAmount'}, + {name : 'maxApplyAmount',mapping : 'maxApplyAmount'} +]; + //物品选择下拉框数据源 var comboGoodsStore = new Ext4.data.JsonStore({ pageSize:100, - proxy : { - type : 'ajax', - url : WWWROOT + '/disinfectSystem/baseData/tousseDefinitionAction!searchComboGoodsData.do?showExternalCodeOfDisposableGoods='+sstsConfig.showExternalCodeOfDisposableGoods, - reader : { - type : 'json', - totalProperty : 'totalCount', - idProperty: 'noneExsist', - root : 'data' - } - }, - fields : [ - {name : 'id',mapping : 'id'}, - {name : 'spelling',mapping : 'spelling'}, - {name : 'name',mapping : 'name'}, - {name : 'tousseDefinitionID'}, - {name : 'type',mapping : 'type'}, - {name : 'tousseType',mapping : 'tousseType'}, - {name : 'isApplyEntireTousse',mapping : 'isApplyEntireTousse'}, - {name : 'displayName',mapping : 'displayName'}, - {name : 'price',mapping : 'price'}, - {name : 'packageSpec',mapping : 'packageSpec'}, - {name : 'unit',mapping : 'unit'}, - {name : 'amount',mapping : 'amount'}, - {name : 'middlePackageUnit',mapping : 'middlePackageUnit'}, - {name : 'middlePackageAmount',mapping : 'middlePackageAmount'}, - {name : 'transferScale',mapping : 'transferScale'}, - {name : 'urgentAmount',mapping : 'urgentAmount'}, - {name : 'materials',mapping : 'materials'}, - {name : 'minApplyAmount',mapping : 'minApplyAmount'}, - {name : 'maxApplyAmount',mapping : 'maxApplyAmount'} - ],listeners:{ + proxy : goodProxy, + fields : goodModel, + listeners:{ beforeload : function(){ if(loadMask){ loadMask.show(); @@ -348,6 +358,28 @@ } }); +//全部物品选择下拉框数据源,只在申请窗口弹出的时候加载一次,用于缓存所有数据,物品绑定的数据从这里读取 +var allGoodsComboStore = new Ext4.data.JsonStore({ + proxy : goodProxy, + fields : goodModel, + listeners:{ + beforeload : function(){ + //在加载前设定参数,limit要设置成空,这样才会加载到所有的数据 + allGoodsComboStore.proxy.extraParams.cssdOrgUnitCode = ""; + allGoodsComboStore.proxy.extraParams.spell = ""; + allGoodsComboStore.proxy.extraParams.limit = ""; + //暂时只绑定一次性物品,所以type用一次性物品 + allGoodsComboStore.proxy.extraParams.tousseType = "一次性物品"; + }, + load : function () { + // console.log(allGoodsComboStore.getCount()); + } + } +}); + + + + var tousseAndDiposableGoodsStore = new Ext.data.Store({ proxy : new Ext.data.HttpProxy({ url : WWWROOT + '/disinfectSystem/baseData/tousseDefinitionAction!searchInsideTousseData.do', @@ -833,6 +865,28 @@ 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; var name = top.Ext4.getCmp('package1').getValue(); @@ -887,36 +941,48 @@ return false; }else{ addItems(id,name,count,isDiposableGoods,isApplyEntireTousse,price,externalCode,storageAmount,tousseType,materials,unit,packageSpec,minApplyAmount,maxApplyAmount,urgentAmount,para); + afterAddItem(); } }); } else if(!isUndefinedOrNullOrEmpty(maxApplyAmount) && count > maxApplyAmount){ top.Ext4.Msg.alert("提示消息","申请数量大于最大可申请数量"); - //showResult("申请数量大于最大可申请数量"); clearCount(); addItems(id,name,count,isDiposableGoods,isApplyEntireTousse,price,externalCode,storageAmount,tousseType,materials,unit,packageSpec,minApplyAmount,maxApplyAmount,urgentAmount,para); + afterAddItem(); } else{ addItems(id,name,count,isDiposableGoods,isApplyEntireTousse,price,externalCode,storageAmount,tousseType,materials,unit,packageSpec,minApplyAmount,maxApplyAmount,urgentAmount,para); + afterAddItem(); } }else{ addItems(id,name,count,isDiposableGoods,isApplyEntireTousse,price,externalCode,storageAmount,tousseType,materials,unit,packageSpec,minApplyAmount,maxApplyAmount,urgentAmount,para); + afterAddItem(); } - - top.Ext4.getCmp('urgentAmount').setValue(''); - top.Ext4.getCmp('diposableGoodsAmount').setValue(''); - top.Ext4.getCmp('minApplyAmount').setValue(''); - top.Ext4.getCmp('maxApplyAmount').setValue(''); - top.Ext4.getCmp('isDiposableGoods').setValue(""); - top.Ext4.getCmp('package1').clearValue(); - top.Ext4.getCmp('count1').setValue(""); - top.Ext4.getCmp('price').setValue(""); - top.Ext4.getCmp('unitInfoDisplayField').setValue(""); - top.Ext4.getCmp('package1').focus(); - return true; } } + +/** + * 在点击了添加按钮后来进行判断是否有捆绑物品 + * @returns {boolean} + */ +function afterAddItem() { + var goodsBindHandler = new GoodsBindHandler(); + goodsBindHandler.handleBindGood(); + top.Ext4.getCmp('urgentAmount').setValue(''); + top.Ext4.getCmp('diposableGoodsAmount').setValue(''); + top.Ext4.getCmp('minApplyAmount').setValue(''); + top.Ext4.getCmp('maxApplyAmount').setValue(''); + top.Ext4.getCmp('isDiposableGoods').setValue(""); + top.Ext4.getCmp('package1').clearValue(); + top.Ext4.getCmp('count1').setValue(""); + top.Ext4.getCmp('price').setValue(""); + top.Ext4.getCmp('unitInfoDisplayField').setValue(""); + top.Ext4.getCmp('package1').focus(); + return true; +} + // 点击表单上的打印按钮,都打印申请单的原始内容(无论供应室或者临床科室用户) // 打印纸张的大小可以不同,通过printConfig.js文件设置 function applicationPrintBtnPressed(printMode, applicationId){ @@ -1551,17 +1617,17 @@ },{ header : "最小单位数量", dataIndex : 'unitCount', - hidden: true, + hidden: productMode, sortable: false },{ header : "原来的最小单位", dataIndex : 'minUnit', - hidden: true, + hidden: productMode, sortable: false },{ header : "中包装单位装换单位系数", dataIndex : 'transferScale', - hidden: true, + hidden: productMode, sortable: false },{ header : "包装规格", @@ -2548,6 +2614,8 @@ }); applicationWindow.show(); + + allGoodsComboStore.reload(); loadMask = new Ext4.LoadMask({msg:'数据处理中,请稍候......',target:applicationWindow}); @@ -3413,7 +3481,7 @@ },{ text : '申请外来器械', iconCls : 'btn_ext_add_customTousse', - hidden : SSTS_ForeignTousseApplication_Create, + hidden : SSTS_ForeignTousseApplication_Create || (sstsConfig.recyclingApplicationVersion == 2 && !isSupplyRoomUser), handler : function() { openForeignTousseForm("","apply"); } Index: ssts-web/src/main/resources/systemset/operationDefine.xml =================================================================== diff -u -r14967 -r15116 --- ssts-web/src/main/resources/systemset/operationDefine.xml (.../operationDefine.xml) (revision 14967) +++ ssts-web/src/main/resources/systemset/operationDefine.xml (.../operationDefine.xml) (revision 15116) @@ -456,6 +456,12 @@ + + + + + + Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/ctrl/GoodsBindingCtrl.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/ctrl/GoodsBindingCtrl.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/ctrl/GoodsBindingCtrl.java (revision 15116) @@ -0,0 +1,119 @@ +package com.forgon.disinfectsystem.goodsBindingConfig.ctrl; + +import com.forgon.disinfectsystem.goodsBindingConfig.entity.GoodsBindingConfig; +import com.forgon.disinfectsystem.goodsBindingConfig.enums.BidirectionalStatus; +import com.forgon.disinfectsystem.goodsBindingConfig.service.GoodsBindSrv; +import com.forgon.tools.StrutsResponseUtils; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; +import java.util.List; + +/** + * Created by zhonghaowen on 2016/8/17. + * 物品绑定控制层 + */ +@Controller +@RequestMapping("/disinfectSystem/goodsBindingConfig/goodsBindingCtrl") +public class GoodsBindingCtrl { + + /** + * 要通过xml注入不能用注解注入,不然服务层的事务会失效 + */ + // @Resource(name = "goodsBindSrvImpl") + private GoodsBindSrv goodsBindSrvImpl; + + + public void setGoodsBindSrvImpl(GoodsBindSrv goodsBindSrvImpl) { + this.goodsBindSrvImpl = goodsBindSrvImpl; + } + + private Logger logger = Logger.getLogger(this.getClass()); + + + /** + * 新增或者保存绑定物品 + * + * @param goodsBindingConfig {@link GoodsBindingConfig} + * @param isBidirectional 是否双向绑定 + * @param response + */ + @ResponseBody + @RequestMapping(value = "/saveGoodsBind") + public void saveGoodsBind(@ModelAttribute("goodsBindingConfig") GoodsBindingConfig goodsBindingConfig, @RequestParam("isBidirectional") String isBidirectional, HttpServletResponse response) { + try { + goodsBindingConfig.setBidirectionalStatus(BidirectionalStatus.parseOfDesc(isBidirectional)); + goodsBindSrvImpl.saveOrUpdate(goodsBindingConfig); + StrutsResponseUtils.output(true, "保存成功", response); + } + catch (Exception e) { + logger.error(e, e); + StrutsResponseUtils.output(false, "保存失败!\n" + e.getMessage(), response); + throw new RuntimeException(e); + } + } + + /** + * 根据id来加载对应的绑定物品 + * + * @param id 物品绑定主键 + * @param response + */ + @ResponseBody + @RequestMapping(value = "/loadGoodBind") + public void loadGoodBind(@RequestParam("id") Long id, HttpServletResponse response) { + GoodsBindingConfig goodsBindingConfig = goodsBindSrvImpl.findById(id); + logger.debug(String.format("goodsBindingConfig:%s", goodsBindingConfig)); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("data", JSONArray.fromObject(goodsBindingConfig)); + StrutsResponseUtils.output(jsonObject, response); + } + + /** + * 根据提供的id来删除绑定物品 + * + * @param ids 物品的id + * @param response + */ + @ResponseBody + @RequestMapping(value = "/deleteGoodBind") + public void deleteGoodBind(@RequestParam("ids") String[] ids, HttpServletResponse response) { + try { + List list = Arrays.asList(ids); + goodsBindSrvImpl.deleteGoodsBindByIds(list); + StrutsResponseUtils.output(true, "删除成功", response); + } + catch (Exception e) { + logger.error(e, e); + StrutsResponseUtils.output(false, "删除失败!\n" + e.getMessage(), response); + throw new RuntimeException(e); + } + } + + + @ResponseBody + @RequestMapping(value = "/handleBind") + public void handleBind(@RequestParam("name") String name, @RequestParam("count") Integer count, HttpServletResponse response) { + try { + JSONArray jsonArray = goodsBindSrvImpl.handleBind(name, count); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("data", jsonArray); + StrutsResponseUtils.output(jsonArray, response); + } + catch (Exception e) { + logger.error(e, e); + StrutsResponseUtils.output(false, "绑定失败!\n" + e.getMessage(), response); + throw new RuntimeException(e); + } + + } + +} Index: ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsConfig.js =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsConfig.js (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsConfig.js (revision 15116) @@ -0,0 +1,93 @@ +/** + * 物品设置类,里面封装了model,store,设置物品下拉框 + * @constructor + */ +var GoodsConfig = function () { + + //进度条 + var loadMask; + + //物品model + var goodsModel = [ + {name: 'id', mapping: 'id'}, + {name: 'spelling', mapping: 'spelling'}, + {name: 'name', mapping: 'name'}, + {name: 'tousseDefinitionID'}, + {name: 'type', mapping: 'type'}, + {name: 'tousseType', mapping: 'tousseType'}, + {name: 'isApplyEntireTousse', mapping: 'isApplyEntireTousse'}, + {name: 'displayName', mapping: 'displayName'}, + {name: 'amount', mapping: 'amount'}, + {name: 'materials', mapping: 'materials'} + ]; + + var url = WWWROOT + '/disinfectSystem/baseData/tousseDefinitionAction!searchComboGoodsData.do?'; + url += "tousseType=一次性物品"; + + //物品store + goodsStore = new Ext.data.Store({ + proxy: new Ext.data.HttpProxy({ + url: url, + // url: WWWROOT + '/disinfectSystem/baseData/tousseDefinitionAction!searchComboGoodsData.do?showExternalCodeOfDisposableGoods=' + sstsConfig.showExternalCodeOfDisposableGoods, + method: 'POST' + }), + reader: new Ext.data.JsonReader({ + totalProperty: 'totalCount', + root: 'data' + }, goodsModel + ), + listeners: { + beforeload: function () { + if (loadMask) { + loadMask.show(); + } + }, + load: function () { + if (loadMask) { + loadMask.hide(); + } + } + } + }); + + + this.getGoodsModel = function () { + return this.goodsModel; + } + + this.getGoodsStore = function () { + return this.goodsStore; + } + + + /** + * 设置物品下拉框 + * @param good 里面有id,name,label + */ + this.setGoodsCombo = function (good) { + var goods = { + xtype: 'combo', + id: good.id, + name: good.name, + fieldLabel: good.label, + queryParam: 'spell', + minChars: 0, + valueField: 'name', + displayField: 'name', + width: 320, + matchFieldWidth: false, + listConfig: {width: 600}, + store: goodsStore, + forceSelection: true, + lazyInit: true, + triggerAction: 'all', + hideTrigger: true, + typeAhead: false, + allowBlank: true, + listeners: { + select: comboSelectEvn + } + }; + return goods; + } +} \ No newline at end of file Index: ssts-web/src/main/webapp/homepage/menu.jsp =================================================================== diff -u -r14967 -r15116 --- ssts-web/src/main/webapp/homepage/menu.jsp (.../menu.jsp) (revision 14967) +++ ssts-web/src/main/webapp/homepage/menu.jsp (.../menu.jsp) (revision 15116) @@ -961,7 +961,10 @@ SSTS_Tousse_Update = false; -var SSTS_BaseData_Manager = SSTS_ImportBaseData &&SSTS_Qualitymonitoring &&SSTS_QualityItem &&SSTS_SerialNumber && SSTS_SupplyRoomType&&SSTS_Expiration && SSTS_Sterilizer && SSTS_Sterilisation &&SSTS_Rinser && SSTS_CleanMethod&&SSTS_Supplier &&SSTS_TaskGroup && SSTS_DiposableGoodsType && SSTS_PackType&& SSTS_ProjectName && SSTS_Operation && SSTS_Container &&SSTS_Material; +var SSTS_GoodsBindingConfig = true; + +SSTS_GoodsBindingConfig = false; +var SSTS_BaseData_Manager = SSTS_ImportBaseData &&SSTS_Qualitymonitoring &&SSTS_QualityItem &&SSTS_SerialNumber && SSTS_SupplyRoomType&&SSTS_Expiration && SSTS_Sterilizer && SSTS_Sterilisation &&SSTS_Rinser && SSTS_CleanMethod&&SSTS_Supplier &&SSTS_TaskGroup && SSTS_DiposableGoodsType && SSTS_PackType&& SSTS_ProjectName && SSTS_Operation && SSTS_Container &&SSTS_Material; Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/enums/BidirectionalStatus.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/enums/BidirectionalStatus.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/enums/BidirectionalStatus.java (revision 15116) @@ -0,0 +1,40 @@ +package com.forgon.disinfectsystem.goodsBindingConfig.enums; + +/** + * Created by zhonghaowen on 2016/8/11. + * 是否双向绑定枚举类 + */ +public enum BidirectionalStatus { + + IS(0, "是"), + NO(1, "否"); + + private String desc; + private Integer val; + + BidirectionalStatus(Integer val, String desc) { + this.val = val; + this.desc = desc; + } + + public String getDesc() { + return desc; + } + + public Integer getVal() { + return val; + } + + + public static BidirectionalStatus parseOfDesc(String desc) { + BidirectionalStatus[] values = BidirectionalStatus.values(); + for (BidirectionalStatus value : values) { + if (value.getDesc().equals(desc)) { + return value; + } + } + throw new IllegalArgumentException("找不到对应的类型"); + } + + +} Index: ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigView.jsp =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigView.jsp (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigView.jsp (revision 15116) @@ -0,0 +1,48 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ include file="/common/taglibs.jsp" %> + + + + 物品绑定 + + +<%@ include file="/common/includeExtJsAndCss.jsp" %> + + + + + + +<%----%> + + + + + + + + + +
+
+
+
+ +
+ + \ No newline at end of file Index: ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigEdit.js =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigEdit.js (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindingConfigEdit.js (revision 15116) @@ -0,0 +1,227 @@ +/** + * 删除绑定物品数据 + * @param records 该行的数据 + */ +function deleteGoodsBinding(records) { + var ids = new Array(); + Ext.each(records, function (item) { + ids.push(item.get('id')); + }); + var url = WWWROOT + '/disinfectSystem/goodsBindingConfig/goodsBindingCtrl/deleteGoodBind.mhtml'; + Ext.Ajax.request({ + url: url, + params: {ids: ids}, + method: 'POST', + success: function (response, options) { + var result = Ext.decode(response.responseText); + showResult(result.message); + grid.dwrReload(); + }, + failure: function (response, options) { + var result = Ext.decode(response.responseText); + showResult(result.message); + } + }); + + +} + + +/** + * 保存绑定,可以新增或者更新 + * @param goodBindForm 要提交的表单 + * @param win 对应的窗口 + */ +function saveGoodsBinding(goodBindForm, win) { + var url = WWWROOT + '/disinfectSystem/goodsBindingConfig/goodsBindingCtrl/saveGoodsBind.mhtml'; + var mc = goodBindForm.form.findField('mainCount').getValue(); + var sc = goodBindForm.form.findField('secondaryCount').getValue(); + if (!isAmount(mc) || !isAmount(sc)) { + showResult('请输入整数'); + return; + } + goodBindForm.form.submit({ + url: url, + method: 'POST', + waitMsg: '正在提交数据,请稍候', + waitTitle: '提交表单', + success: function (form, action) { + win.close(); + showResult(action.result.message); + if (grid) { + grid.dwrReload(); + } + }, + failure: function (form, action) { + showResult(action.result.message); + } + }); +} + + +/** + * 下拉框事件,当下拉选择了物品,填充对应单元格的数据 + * @param combo 下拉框对象 + * @param record 下拉框数据 + */ +function comboSelectEvn(combo, record) { + var id = record.get('id'); + var name = record.get('name'); + var tousseType = record.get('tousseType'); + var comboName = combo.name; + if ('mainGoodName' == comboName) { + top.Ext.getCmp('mainGoodId').setValue(id); + top.Ext.getCmp('mainGoodType').setValue(tousseType); + } + else if ('secondaryGoodName' == comboName) { + top.Ext.getCmp('secondaryGoodId').setValue(id); + top.Ext.getCmp('secondaryGoodType').setValue(tousseType); + } +} + +/** + * 更新或者新增物品绑定 + * @param id 物品绑定表的id + */ +function modifyGoodsBinding(id) { + + var goodsConfig = new GoodsConfig(); + + var mainGood = { + id: 'mainGoodName', + name: 'mainGoodName', + label: '主绑定物品名称' + }; + + var secondaryGood = { + id: 'secondaryGoodName', + name: 'secondaryGoodName', + label: '次绑定物品名称' + }; + + //绑定比例Item + var bindRatioItems = [ + { + layout: 'form', labelSeparator: ' ', + items: [ + {name: 'mainCount', id: 'mainCount', xtype: 'textfield', fieldLabel: '绑定比例', width: 30} + ] + }, + { + layout: 'form', labelSeparator: ' ', labelWidth: 5, + items: [ + {name: 'secondaryCount', id: 'secondaryCount', xtype: 'textfield', fieldLabel: ':', width: 30} + ] + } + ]; + //是否允许双向捆绑 + var bidirectionalStatus = new Ext.data.SimpleStore({ + fields: ['key', 'val'], + data: [['IS', '是'], ['NO', '否']] + }); + + + var formPanelItems = [ + {xtype: 'hidden', name: 'id', id: 'id'}, + {xtype: 'hidden', name: 'mainGoodId', id: 'mainGoodId'}, + {xtype: 'hidden', name: 'mainGoodType', id: 'mainGoodType'}, + goodsConfig.setGoodsCombo(mainGood), + goodsConfig.setGoodsCombo(secondaryGood), + {xtype: 'hidden', name: 'secondaryGoodId', id: 'secondaryGoodId'}, + {xtype: 'hidden', name: 'secondaryGoodType', id: 'secondaryGoodType'}, + // {xtype: 'textfield', name: 'secondaryGoodName', id: 'secondaryGoodName', fieldLabel: '次绑定物品名称'}, + {layout: 'column', labelSeparator: ' ', items: bindRatioItems}, + { + xtype: 'combo', + name: 'isBidirectional', + id: 'bidirectionalStatus', + fieldLabel: '是否允许双向捆绑', + width: 60, + store: bidirectionalStatus, + // 数据模式,local代表本地数据 + // mode: 'remote', + mode: 'local', + value: '是', + // 显示所有下列数据,一定要设置属性triggerAction为all + triggerAction: 'all', + // 不允许为空 + allowBlank: false, + // 显示文本 ,对应下面store里的'key', + displayField: 'val', + valueField: 'key', + //hiddenName用了样式会变 + // hiddenName : 'bidirectionalStatus', + // hiddenValue : 'key', + forceSelection: true, + // 是否允许输入 + editable: false + } + ]; + + + //绑定物品store + var goodsBindingStore = [ + {name: 'id', mapping: 'id'}, + {name: 'mainGoodId', mapping: 'mainGoodId'}, + {name: 'mainGoodName', mapping: 'mainGoodName'}, + {name: 'secondaryGoodId', mapping: 'secondaryGoodId'}, + {name: 'secondaryGoodName', mapping: 'secondaryGoodName'}, + {name: 'isBidirectional', mapping: 'bidirectionalStatus'}, + {name: 'mainCount', mapping: 'mainCount'}, + {name: 'secondaryCount', mapping: 'secondaryCount'}, + {name: 'mainGoodType', mapping: 'mainGoodType'}, + {name: 'secondaryGoodType', mapping: 'secondaryGoodType'} + ]; + + + //绑定物品面板 + var goodPanel = new top.Ext.FormPanel({ + id: 'addGoodsBindingForm', + frame: true, + labelSeparator: ' ', + labelAlign: 'right', + labelWidth: 120, + fileUpload: true, + bodyStyle: 'padding:5px 5px 0px 5px;', + autoWidth: true, + autoHeight: true, + layout: 'form', + items: formPanelItems, + reader: new Ext.data.JsonReader({root: 'data'}, goodsBindingStore) + }); + + //如果存在id,则表示要更新,所以加载数据 + if (!isUndefinedOrNullOrEmpty(id)) { + goodPanel.form.load({ + url: WWWROOT + '/disinfectSystem/goodsBindingConfig/goodsBindingCtrl/loadGoodBind.mhtml', + params: {id: id} + }); + } + + + //绑定物品窗口 + var goodsBindingWin = new top.Ext.Window({ + id: 'goodsBindingWin', + title: '物品绑定配置', + width: 600, + border: false, + modal: true, + plain: true, + buttonAlign: 'center', + items: goodPanel, + buttons: [{ + id: 'saveBtn', + text: '保存', + handler: function (btn, evn) { + saveGoodsBinding(goodPanel, goodsBindingWin); + } + }, { + text: '取消', + id: 'saveAndNewBtn', + handler: function () { + goodsBindingWin.close(); + } + }] + }); + goodsBindingWin.show(); +} Index: ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindHandler.js =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindHandler.js (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindHandler.js (revision 15116) @@ -0,0 +1,93 @@ +// 物品绑定处理类 +var GoodsBindHandler = function () { +}; + +/** + * 迭代从后端得到的需要绑定物品的数据,从comboGoodsStore里按照名字来寻找对应需要绑定的数据 + * @param records 需要绑定物品记录的数组 + * @param data 里面要寻找的名字和对应的绑定数量 + */ +GoodsBindHandler.prototype.findBindRecord = function (records, data) { + top.Ext4.each(data, function (item) { + var record = allGoodsComboStore.findRecord('name', item.name); + if (record != null) { + //如果找得到,设置数量为后端传过来的捆绑数量 + record.set('count', item.bindCount); + records.push(record); + } + }); +} + +/** + * 添加捆绑物 + * @param records 需要添加的捆绑物的对象 + * @returns {boolean} + */ +GoodsBindHandler.prototype.addBindGood = function (records) { + top.Ext4.each(records, function (record) { + var id = record.get('id'); + var name = record.get('name'); + var count = record.get('count'); + var materials = record.get('materials'); + var urgentAmount = record.get('urgentAmount'); + var transferScale = record.get('transferScale'); + var middlePackageUnit = record.get('middlePackageUnit'); + var price = record.get('price'); + var externalCode = record.get('externalCode'); + var unit = record.get('unit'); + var packageSpec = record.get('packageSpec'); + var isApplyEntireTousse = record.get('isApplyEntireTousse'); + var para = { + behavior: 'bind', + transferScale: transferScale, + middlePackageUnit: middlePackageUnit + }; + var storageAmount = record.get('amount'); + var minApplyAmount = record.get('minApplyAmount'); + var maxApplyAmount = record.get('maxApplyAmount'); + var tousseType = record.get('tousseType'); + var isDisposableGoods = '一次性物品' == tousseType ? '是' : '否'; + if (parseInt(count, 10) > storageAmount) { + if (!allowApplyDisposableGoodsWhenUnderstock) { + showResult("申请数量不能大于库存数量!"); + return false; + } + } + else if (!isUndefinedOrNullOrEmpty(maxApplyAmount) && count > maxApplyAmount) { + top.Ext4.Msg.alert("提示消息", "申请数量大于最大可申请数量"); + } + addItems(id, name, count, isDisposableGoods, isApplyEntireTousse, price, externalCode, storageAmount, tousseType, materials, unit, packageSpec, minApplyAmount, maxApplyAmount, urgentAmount, para); + }); + return true; +} + +/** + * 处理需要捆绑的物品,先得到对应选择的物品的名字和数量,然后从后台查询出该物品的所有绑定物和对应的捆绑数量,然后添加到表格上 + */ +GoodsBindHandler.prototype.handleBindGood = function () { + var me = this; + var applicationCount = top.Ext4.getCmp('count1').getValue(); + var applicationName = top.Ext4.getCmp('package1').getValue(); + Ext.Ajax.request({ + url: WWWROOT + '/disinfectSystem/goodsBindingConfig/goodsBindingCtrl/handleBind.mhtml', + params: {count: applicationCount, name: applicationName}, + timeout: 600000, + method: 'POST', + success: function (response, options) { + try { + var records = []; + var result = Ext.decode(response.responseText); + if (!isUndefinedOrNullOrEmpty(result)) { + me.findBindRecord(records, result); + me.addBindGood(records); + } + } + catch (e) { + alert("Exception : " + e); + } + }, + failure: function (response, options) { + showResult(response.responseText); + } + }); +} Index: ssts-web/src/main/webapp/homepage/menuconfigure.js =================================================================== diff -u -r15010 -r15116 --- ssts-web/src/main/webapp/homepage/menuconfigure.js (.../menuconfigure.js) (revision 15010) +++ ssts-web/src/main/webapp/homepage/menuconfigure.js (.../menuconfigure.js) (revision 15116) @@ -535,7 +535,8 @@ {hidden :SSTS_QualityItem,text:"质量监测项设置",href:WWWROOT+'/disinfectsystem/basedatamanager/qualitymonitoringConfig/qualitymonitoringConfigView.jsp?type=质量监测',hrefTarget:linkTarget,leaf:true}, {hidden :SSTS_Qualitymonitoring,text:"定期监测项设置",href:WWWROOT+'/disinfectsystem/basedatamanager/qualitymonitoringConfig/qualitymonitoringConfigView.jsp?type=定期监测',hrefTarget:linkTarget,leaf:true}, {hidden :SSTS_ImportBaseData,text:"导入导出基础数据",href:WWWROOT+'/disinfectsystem/basedatamanager/importbasedata/importBasedata.mhtml',hrefTarget:linkTarget,leaf:true}, - {hidden :!(SSTS_UserIPAndOrgUnitMapping || sstsConfig.enableUserIPAndOrgUnitMapping),text:"IP对应的默认科室配置",href:WWWROOT+'/disinfectsystem/basedatamanager/userIPAndOrgUnitMapping/userIPAndOrgUnitMappingView.jsp',hrefTarget:linkTarget,leaf:true} //用户当前科室的配置 + {hidden :!(SSTS_UserIPAndOrgUnitMapping || sstsConfig.enableUserIPAndOrgUnitMapping),text:"IP对应的默认科室配置",href:WWWROOT+'/disinfectsystem/basedatamanager/userIPAndOrgUnitMapping/userIPAndOrgUnitMappingView.jsp',hrefTarget:linkTarget,leaf:true}, //用户当前科室的配置 + {hidden :SSTS_GoodsBindingConfig,text:"物品绑定",href:WWWROOT+ '/disinfectsystem/goodsBindingConfig/goodsBindingConfigView.jsp',hrefTarget:linkTarget,leaf:true} // {hidden :false,text:"打印表单模板设置",href:WWWROOT+'/disinfectsystem/print/printForm.jsp',hrefTarget:linkTarget,leaf:true} ] },{ Index: ssts-web/src/main/resources/spring/applicationContext-disinfectsystem-service.xml =================================================================== diff -u -r15043 -r15116 --- ssts-web/src/main/resources/spring/applicationContext-disinfectsystem-service.xml (.../applicationContext-disinfectsystem-service.xml) (revision 15043) +++ ssts-web/src/main/resources/spring/applicationContext-disinfectsystem-service.xml (.../applicationContext-disinfectsystem-service.xml) (revision 15116) @@ -1931,4 +1931,10 @@ class="com.forgon.disinfectsystem.basedatamanager.useripandorgunitmapping.dwr.UserIPAndOrgUnitMappingTableManager"> + + + + + + \ No newline at end of file Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/impl/GoodsBindSrvImpl.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/impl/GoodsBindSrvImpl.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/impl/GoodsBindSrvImpl.java (revision 15116) @@ -0,0 +1,184 @@ +package com.forgon.disinfectsystem.goodsBindingConfig.impl; + +import com.beust.jcommander.ParameterException; +import com.forgon.disinfectsystem.goodsBindingConfig.entity.GoodsBindingConfig; +import com.forgon.disinfectsystem.goodsBindingConfig.enums.BidirectionalStatus; +import com.forgon.disinfectsystem.goodsBindingConfig.enums.GoodType; +import com.forgon.disinfectsystem.goodsBindingConfig.service.GoodsBindSrv; +import com.forgon.tools.hibernate.ObjectDao; +import com.forgon.tools.util.IntegerUtils; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +/** + * Created by zhonghaowen on 2016/8/11. + * 一次性物品绑定服务层实现类 + */ +// @Service("goodsBindSrvImpl") +public class GoodsBindSrvImpl implements GoodsBindSrv { + + private Logger logger = Logger.getLogger(this.getClass()); + + @Resource + private ObjectDao objectDao; + + @Override + public GoodsBindingConfig findById(Long id) { + return (GoodsBindingConfig) objectDao.getByProperty(GoodsBindingConfig.class.getSimpleName(), "id", id); + } + + @Override + @Transactional(propagation = Propagation.REQUIRED) + public void saveOrUpdate(GoodsBindingConfig goodsBindingConfig) { + try { + this.checkGoodsBindConfigPara(goodsBindingConfig); + logger.debug(String.format("goodsBindingConfig:%s", goodsBindingConfig)); + objectDao.merge(goodsBindingConfig); + } + catch (Exception e) { + logger.error(e, e); + throw new RuntimeException(e); + } + } + + @Override + public void checkGoodsBindConfigPara(GoodsBindingConfig entity) { + if (entity.getMainGoodId() == null || StringUtils.isEmpty(entity.getMainGoodName()) || entity.getMainCount() == null || + entity.getSecondaryGoodId() == null || StringUtils.isEmpty(entity.getSecondaryGoodName()) || entity.getSecondaryCount() == null || + entity.getBidirectionalStatus() == null || StringUtils.isEmpty(entity.getMainGoodType()) || StringUtils.isEmpty(entity.getSecondaryGoodType())) { + throw new RuntimeException("参数不能为空!"); + } + if (!IntegerUtils.isNumeric(entity.getMainCount().toString()) || !IntegerUtils.isNumeric(entity.getSecondaryCount().toString())) { + throw new RuntimeException("物品的数量要是整数!"); + } + if (entity.getMainGoodId().equals(entity.getSecondaryGoodId())) { + throw new RuntimeException("主要绑定物不能和次要绑定物相同!"); + } + // if (entity.getSecondaryCount() % entity.getMainCount() != 0) { + // throw new ParameterException("保存失败!次要捆绑物品数量要是主要捆绑物品的整数倍!"); + // } + this.checkIfExits(entity); + } + + @Override + @Transactional(propagation = Propagation.REQUIRED) + public void deleteGoodsBindByIds(List id) { + try { + objectDao.delete(GoodsBindingConfig.class.getSimpleName(), id); + } + catch (Exception e) { + logger.error(e, e); + throw new RuntimeException(e); + } + } + + + @Override + public JSONArray handleBind(String name, Integer count) { + if (count == null || count <= 0) { + throw new ParameterException("请输入大于0的数量!"); + } + JSONArray jsonArray = new JSONArray(); + //先用主绑定物名称找出对应的次要绑定物 + this.iterateHandleBindGoods(jsonArray, name, count, GoodType.MAIN); + //然后用次要绑定物名称去找双向绑定了的主要绑定物 + this.iterateHandleBindGoods(jsonArray, name, count, GoodType.SECOND); + logger.debug(String.format("[jsonArray]:%s", jsonArray)); + return jsonArray; + } + + + /** + * 检查是否已经存在该组物品的绑定 + * + * @param entity {@link GoodsBindingConfig} + */ + private void checkIfExits(GoodsBindingConfig entity) { + String hql = String.format("from GoodsBindingConfig po where po.mainGoodId = %s and po.secondaryGoodId = %s", entity.getMainGoodId(), entity.getSecondaryGoodId()); + //从数据库里查找是否存在该组的绑定存,如果没查到记录则允许插入 + List result = objectDao.findByHql(hql.toString()); + if (CollectionUtils.isNotEmpty(result)) { + //如果能查到记录,判断该记录的主键id是否和这次提交的id一致,如果不一致则不允许插入(1.此操作有可能插入操作,但填写了已经存在的绑定 2.此操作有肯能是更新操作,但把名字改成已经存在的绑定) + if (result.size() == 1) { + if (!result.get(0).getId().equals(entity.getId())) { + throw new RuntimeException("已经存在该组物品的绑定!请不要重复绑定!"); + } + } + else { + throw new RuntimeException("已经存在该组物品的绑定!请不要重复绑定!"); + } + } + } + + /** + * 迭代查找出来的对应绑定物品,并且计算好他们对应的绑定数量 + * + * @param jsonArray 最终需要返回的数组,里面有绑定物品的名字和最终绑定数量 + * @param name 绑定物品的名字 + * @param count 页面填写的对应数量 + * @param type {@link GoodType} 物品绑定的类型 + */ + private void iterateHandleBindGoods(JSONArray jsonArray, String name, Integer count, GoodType type) { + List goods = this.findAllBindBindingConfigByNameAndType(name, type); + logger.debug(String.format("[goods]:%s", goods)); + if (CollectionUtils.isNotEmpty(goods)) { + //迭代查找出来的list,并计算应该绑定的数量 + for (GoodsBindingConfig good : goods) { + JSONObject jsonObject = new JSONObject(); + if (GoodType.MAIN.equals(type)) { + //如果当前数量不能整除主要绑定物 + if (count % good.getMainCount() != 0) { + continue; + } + jsonObject.put("name", good.getSecondaryGoodName()); + //计算出比例,次绑定物的数量=当前数量/主绑定物数量*次要绑定物数量 + Integer rate = count / good.getMainCount(); + jsonObject.put("bindCount", rate * good.getSecondaryCount()); + jsonArray.add(jsonObject); + } + else if (GoodType.SECOND.equals(type)) { + //如果当前数量不能整除次要绑定物 + if (count % good.getSecondaryCount() != 0) { + continue; + } + jsonObject.put("name", good.getMainGoodName()); + //计算出比例,主绑定物的数量=当前数量/次要绑定物数量*主要绑定物数量 + Integer rate = count / good.getSecondaryCount(); + jsonObject.put("bindCount", rate * good.getMainCount()); + jsonArray.add(jsonObject); + } + } + } + } + + /** + * 根据名字和绑定物品类型查找所有对应的绑定物品 + * + * @param name 绑定物品的名字 + * @param type 绑定物品的类型,主绑定物品还是次要绑定物品 + * @return {@link GoodsBindingConfig} + */ + private List findAllBindBindingConfigByNameAndType(String name, GoodType type) { + try { + StringBuilder hql = new StringBuilder("from GoodsBindingConfig po where 1 = 1"); + hql.append(GoodType.MAIN.equals(type) ? String.format(" and po.mainGoodName = '%s' and po.mainGoodType = '一次性物品'", name) : + String.format(" and po.secondaryGoodName = '%s' and po.secondaryGoodType = '一次性物品' and bidirectionalStatus = %s", name, BidirectionalStatus.IS.getVal())); + List result = objectDao.findByHql(hql.toString()); + return result; + } + catch (Exception e) { + logger.error(e, e); + throw new RuntimeException(e); + } + } + + +} Index: ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsApplicationView.jsp =================================================================== diff -u -r14812 -r15116 --- ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsApplicationView.jsp (.../goodsApplicationView.jsp) (revision 14812) +++ ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsApplicationView.jsp (.../goodsApplicationView.jsp) (revision 15116) @@ -348,7 +348,8 @@ - + + Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/service/GoodsBindSrv.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/service/GoodsBindSrv.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/service/GoodsBindSrv.java (revision 15116) @@ -0,0 +1,56 @@ +package com.forgon.disinfectsystem.goodsBindingConfig.service; + + +import com.forgon.disinfectsystem.goodsBindingConfig.entity.GoodsBindingConfig; +import net.sf.json.JSONArray; + +import java.util.List; +import java.util.Map; + +/** + * Created by zhonghaowen on 2016/8/11. + * 物品绑定服务层 + */ +public interface GoodsBindSrv { + + + /** + * 根据id查询绑定物品的内容 + * + * @param id 主键id + * @return {@link GoodsBindingConfig} + */ + GoodsBindingConfig findById(Long id); + + /** + * 插入和更新 + * + * @param entity {@link GoodsBindingConfig} + */ + void saveOrUpdate(GoodsBindingConfig entity); + + /** + * 检查物品绑定参数 + * + * @param entity {@link GoodsBindingConfig} + */ + void checkGoodsBindConfigPara(GoodsBindingConfig entity); + + /** + * 根据id删除物品绑定 + * + * @param ids 物品绑定表的id + */ + void deleteGoodsBindByIds(List ids); + + + /** + * 处理对应的物品绑定 + * + * @param name 页面传进来的物品名字 + * @param count 页面传进来的物品数量 + * @return 最终需要绑定的物品(里面有name和bindCount) + */ + JSONArray handleBind(String name, Integer count); + +} Index: ssts-web/src/main/webapp/WEB-INF/dwr.xml =================================================================== diff -u -r15043 -r15116 --- ssts-web/src/main/webapp/WEB-INF/dwr.xml (.../dwr.xml) (revision 15043) +++ ssts-web/src/main/webapp/WEB-INF/dwr.xml (.../dwr.xml) (revision 15116) @@ -494,6 +494,12 @@ + + + + + + Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/entity/GoodsBindingConfig.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/entity/GoodsBindingConfig.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/entity/GoodsBindingConfig.java (revision 15116) @@ -0,0 +1,170 @@ +package com.forgon.disinfectsystem.goodsBindingConfig.entity; + +import com.forgon.disinfectsystem.goodsBindingConfig.enums.BidirectionalStatus; +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * Created by zhonghaowen on 2016/8/11. + * 物品绑定实体类 + */ +@Entity +@Table(name = "GoodsBindingConfig") +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class GoodsBindingConfig { + /** + * 自增主键 + */ + private Long id; + + /** + * 主绑定物品id + */ + private Long mainGoodId; + + /** + * 次绑定物品id + */ + private Long secondaryGoodId; + + /** + * 主绑定物品名称 + */ + private String mainGoodName; + + /** + * 次绑定物品名称 + */ + private String secondaryGoodName; + + /** + * 主绑定物品数量 + */ + private Integer mainCount; + + /** + * 绑定物品数量 + */ + private Integer secondaryCount; + + /** + * 主要绑定物品类型 + */ + private String mainGoodType; + + /** + * 次绑定物品类型 + */ + private String secondaryGoodType; + + /** + * 双向绑定状态 + */ + private BidirectionalStatus bidirectionalStatus; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getMainGoodId() { + return mainGoodId; + } + + public void setMainGoodId(Long mainGoodId) { + this.mainGoodId = mainGoodId; + } + + public Long getSecondaryGoodId() { + return secondaryGoodId; + } + + public void setSecondaryGoodId(Long secondaryGoodId) { + this.secondaryGoodId = secondaryGoodId; + } + + public String getMainGoodName() { + return mainGoodName; + } + + public void setMainGoodName(String mainGoodName) { + this.mainGoodName = mainGoodName; + } + + public String getSecondaryGoodName() { + return secondaryGoodName; + } + + public void setSecondaryGoodName(String secondaryGoodName) { + this.secondaryGoodName = secondaryGoodName; + } + + public Integer getMainCount() { + return mainCount; + } + + public void setMainCount(Integer mainCount) { + this.mainCount = mainCount; + } + + public Integer getSecondaryCount() { + return secondaryCount; + } + + public void setSecondaryCount(Integer secondaryCount) { + this.secondaryCount = secondaryCount; + } + + public BidirectionalStatus getBidirectionalStatus() { + return bidirectionalStatus; + } + + public void setBidirectionalStatus(BidirectionalStatus bidirectionalStatus) { + this.bidirectionalStatus = bidirectionalStatus; + } + + public String getMainGoodType() { + return mainGoodType; + } + + public void setMainGoodType(String mainGoodType) { + this.mainGoodType = mainGoodType; + } + + public String getSecondaryGoodType() { + return secondaryGoodType; + } + + public void setSecondaryGoodType(String secondaryGoodType) { + this.secondaryGoodType = secondaryGoodType; + } + + @Override + public String toString() { + return "GoodsBindingConfig{" + + "id=" + id + + ", mainGoodId=" + mainGoodId + + ", secondaryGoodId=" + secondaryGoodId + + ", mainGoodName='" + mainGoodName + '\'' + + ", secondaryGoodName='" + secondaryGoodName + '\'' + + ", mainCount=" + mainCount + + ", secondaryCount=" + secondaryCount + + ", mainGoodType='" + mainGoodType + '\'' + + ", secondaryGoodType='" + secondaryGoodType + '\'' + + ", bidirectionalStatus=" + bidirectionalStatus + + '}'; + } +}