为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > 农产品交易平台毕业设计

农产品交易平台毕业设计

2018-03-23 50页 doc 482KB 24阅读

用户头像

is_281650

暂无简介

举报
农产品交易平台毕业设计农产品交易平台毕业设计 毕 业 实 训 任 务 书 2012年3月1日 201007132143 学生姓名 学号 专 业 软件技术(JAVA方向) 班级 编码J101 课题名称 兵团农五师农产品交易平台 课题来源 校外指导老师提供 指导教师 专业 职称 课题说明: 新疆建设兵团携手普科国际共同研发了农产品电子交易平台,对促进农村经济转型,加速农业发展具有重要的作用。农产品电子交易平台交易主体主要分为:1. 农产品生产者2. 农产品供应商3. 农产品需求商4. 农产品服务商。交易平台的交易主体申请进入农产品电子交...
农产品交易平台毕业设计
农产品交易平台毕业 毕 业 实 训 任 务 书 2012年3月1日 201007132143 学生姓名 学号 专 业 软件技术(JAVA方向) 班级 编码J101 课名称 兵团农五师农产品交易平台 课题来源 校外指导老师提供 指导教师 专业 职称 课题说明: 新疆建设兵团携手普科国际共同研发了农产品电子交易平台,对促进农村经济转型,加速农业发展具有重要的作用。农产品电子交易平台交易主体主要分为:1. 农产品生产者2. 农产品供应商3. 农产品需求商4. 农产品服务商。交易平台的交易主体申请进入农产品电子交易系统。申请需提供交易主体的相关信息和证明文件,参与交易的农场品供应方提供产品相关证明,参与交易的采购方,需要提供企业资质或者个人信用记录,经过审核后方可进入电子交易平台。电子交易平台实时发布各地市场,农产品期货市场价格信息,农产品供应方发布农产品供应信息,以实时市场价格作为参考,发布农产品价格信息,并提供农产品供应时间,类型,数量,单位(或者非标准交易单位)交易地点,交割方式等。系统为农产品采购方提供供应方的价格信息,采用价格优先的撮合方式,根据供应方根据价格、数量和交易方式等平衡选择,最终确定交易方,交易价格,交易时间,交易方式,系统最终完成撮合 承担的任务:编写了此系统的核心模块:1、供应管理模块:主要是发布和查询供应农产品信息。2、挂拍交易模块:添加挂拍信息和管理挂拍交易 I 中 原 工 学 院 毕 业 实 训 任 务 书 2012年3月1日 工作进度安排: 第一周 (3.5~3.11) 完成需求分析,对项目总体有清晰地认识,对项目中需要的对象、变量进行规定,明确自己的任务方向,准备好自己所需要的参考资料。 第二~四周 (3.12~4.1) 完成数据库设计,对系统中需要用到的表,做到尽量的无遗漏,小组各成员进行各自的编程,完成相应的功能实现。 第五~六周 (4.2~4.15) 小组成员完成最后的编程,测试各自的功能实现,并进行初步的项目合并。 第七~八周 (4.16~4.29) 对项目进行整合,进行综合、测试BUG。 指导教师签字: 年 月 日 实训单位意见 签章: 年 月 日 学院意见 签章: 年 月 日 II 中 原 工 学 院 毕 业 实 训 评 审 表 软件技术(JAVA201007132143 学号 姓名 王猛 专业 班级 编码J101 方向) 题目 兵团农五师农产品交易平台 指 导 教 师 评 语 成绩(百分制): 指导教师签名: 年 月 日 III 毕业实训报告 课题名称: 兵团农五师农产品交易平台 专 业: 软件技术(JAVA方向) 班 级: 编码J101 学 号: 201007132143 学生姓名: 王猛 指导教师: 郭丽 年 月 日 IV 摘 要 农产品供过于求和加入WTO,标志着我国农业发展进入了新的阶段。因此应用比较利益原则、相对价格,加快农业结构调整步伐才能克服我国农业发展上的悲观情绪,政府运用价格机制,改变目前的定价机制,帮助农民面向市场,向农民提供充分的价格信息,是发展农业农村经济的主要途径,也是现代农业发展的方向和支撑,积极应用信息化革命的最新成果,不断推进现代农业的市场化,提升现代农业的发展层次和水平。 本文详细的论述兵团农五师农产品交易平台界面的设计和实现全过程。该设计主要包括四部分,第一部分绪论(项目背景分析,可行性分析),第二部分系统需求分析(系统功能需求分析,运行环境,接口设计),第三部分系统功能设计(数据库分析与设计、系统数据流图、用例图、时序图),第四部分系统功能的实现(系统目标的实现、模块的实现)。 关键词: 定价机制 ;需求分析;功能实现 II 目 录 摘 要 ............................................................................................................................................ II 第1章 项目分析 ........................................................................................................................... 1 1.1 相关背景 .............................................................................................................................. 1 1.2可行性分析 ........................................................................................................................... 1 1.3工程进度 ....................................................................................................................... 2 第2章 系统分析与设计 ............................................................................................................... 3 2.1系统分析 ............................................................................................................................... 3 2.1.1 参与者 ........................................................................................................................... 3 2.1.2 用例及用例规约 ........................................................................................................... 3 2.1.3 用例图 ........................................................................................................................... 3 2.2 系统设计 .............................................................................................................................. 4 2.2.1顺序图 ............................................................................................................................ 4 2.2.2类图 ................................................................................................................................ 8 2.2.3系统体系结构设计 ........................................................................................................ 9 2.3 数据库设计 ........................................................................................................................ 10 2.3表的设计 ......................................................................................................................... 12 第3章 实现与测试 ..................................................................................................................... 14 3.1农五师后台人员登录 ......................................................................................................... 14 3.1.1活动图 .......................................................................................................................... 14 3.1.2界面 .............................................................................................................................. 14 3.1.3代码 .............................................................................................................................. 15 3.1.4登录时序图 .................................................................................................................. 15 3.2 供应管理:发布和查询供应农产品信息 ........................................................................ 15 3.2.1活动图 .......................................................................................................................... 15 3.2.2界面 .............................................................................................................................. 16 3.2.3代码 .............................................................................................................................. 17 3.2.4用例 .............................................................................................................................. 18 3.3 添加挂拍信息和管理挂拍交易 ........................................................................................ 18 3.3.1活动图 .......................................................................................................................... 19 3.3.2界面 .............................................................................................................................. 20 3.3.3代码 .............................................................................................................................. 21 }3.3.4用例 ........................................................................................................................... 23 第4章 结束语 ............................................................................................................................. 25 附录A: 主要源程序.................................................................................................................... 27 III 王猛 兵团农五师农产品交易平台 第1章 项目分析 1.1 相关背景 农产品供过于求和加入WTO,标志着我国农业发展进入了新的阶段。因此应用比较利益原则、相对价格机制,加快农业结构调整步伐才能克服我国农业发展上的悲观情绪,才能寻找到我国农业发展的新契机。同时2011年国家把发展农业,加快农业结构调整放到国民经济中统筹部署,可见农业,农村经济在国民经济中的重要位置。如何促使农业和农村经济快速发展,农民收入稳定增加,减少城乡居民收入差距,是我国社会各界关注的焦点问题之一。 农业生产周期长,抗风险能力弱,农民在农产品交易中没有定价权,以及产品销售渠道不畅,都会导致农民纯收入增长减缓。在市场经济中,政府运用价格机制,加快农业结构调整,发挥区域优势,理顺销售渠道,建立抗风险更强的农产品交易联合体,取得农产品交易的主动权,改变目前的定价机制,帮助农民面向市场,向农民提供充分的价格信息,是发展农业农村经济的主要途径,也是解决目前农业农村问题的重要手段。信息化是现代农业的重要组成和经营手段,也是现代农业发展的方向和支撑,积极应用信息化革命的最新成果,不断推进现代农业的市场化,提升现代农业的发展层次和水平。 1.2可行性分析 <1> 经济可行性:该平台改变了我国农业发展的悲观情绪,增加农民的收入稳定性,对 促进农村经济转型有重要作用。由政府履行监督功能,帮助农民建立公平的议价体 系。从一定程度上来讲,还是有可观的利润的。 <2> 技术可行性: 1. 使用的技术:开发此系统主要用到了Struts2,Spring,和Hibernate三大框架,页面上用到El表达式,jsp,但主要是Struts2标签.。本系统采用的是Struts2,Spring和Hibernate三大框架的结合。Struts2的核心控制器是ActionServlet,业务控制器是Action, 所以Struts2主要用于业务逻辑和异常处理,还有文Struts2对JSP的标签的封装,所以页面主要用Struts2的标签。Hibernate是持久层框架主要用于数据库,管理表之间的关系。Spring是Bean工厂管理着对象的创建和消亡并且对Struts2和Hibernate都有补充。所以说本系统才用SSH技术编写。 1 王猛 兵团农五师农产品交易平台 2. 部署环境:Windows 3. 服务器:Tomcat+Apache集群 4. 数据库:Oracle 5. 硬件平台:硬件最低要求:CPU主频在500MHZ以上的PC服务器,内存在512MB 以上,硬盘在8GB以上。 6. 开发环境: Myeclipse开环境:其功能强大而受广大的编程人员的喜爱。 <3> 运行可行性:已经经过了调试,可以正常运行。 <4> 法律可行性:该平台的开发不会在社会上引起侵权和其他责任问题。因此在法律上 是可行的。 1.3工程进度计划 此系统预计会使用2个月的时间,两个核心模块大概会使用两周的时间。 第一周:做项目分析,系统分析与设计。 第二周: 第一天:初始化数据库、搭建web工程、登录和注销 第二天:供应管理 第三天:临时挂拍管理 第四天:挂拍管理 第五天:竞拍管理 第六天:总结项目 2 王猛 兵团农五师农产品交易平台 第2章 系统分析与设计 2.1系统分析 兵团农五师农产品交易平台是为了给农五师官兵们提供更好的交易信息处理和管理库存的平台,也更好的处理商家与农五师之间的关系。 2.1.1 参与者 1. 农产品生产者:农产品生产者是农产品生产的主体,包括农民个体,农场,主要为电子市场交易提供原始农产品。 2. 农产品供应商:农产品供应商是从农产品生产者处购买农产品,经过仓储,或者简单加工、包装等,形成具有购买单位的农产品,是产品主要受让方。 3. 农产品需求商:农产品需求商是农产品的消费者,在市场购买具有购买单位的农产品,是产品主要购买商。 4. 农产品服务商:农产品服务商是包括生产服务,仓储,物流,生产加工,包装,信息发布,交易保证等对农产品交易提供第三方服务的用户。 2.1.2 用例及用例规约 规约:1.用例自身应当是安全的; 2.用例必需可以在测试源出现问题时收集到特定信息并正确返回; 3用例应当使用易读的代码来编写; 4用例本身应当先通过测试; 2.1.3 用例图 图2.1农五师后台用例 3 王猛 兵团农五师农产品交易平台 农五师后台有一个超级管理员,下面有库管员和交易员,他们两个做着自己的不同是不同的事互不干扰。他们两个都有自己的权利,菜单只显示他们权利范围之内的。 2.2 系统设计 本系统采用的是Struts2,Spring和Hibernate三大框架的结合。Struts2的核心控制器是ActionServlet,业务控制器是Action, 所以Struts2主要用于业务逻辑和异常处理,还有文Struts2对JSP的标签的封装,所以页面主要用Struts2的标签。Hibernate是持久层框架主要用于数据库,管理表之间的关系。Spring是Bean工厂管理着对象的创建和消亡并且对Struts2和Hibernate都有补充。所以说本系统才用SSH技术编写。 2.2.1顺序图 图2.2登录顺序图 用户登录有JSP发出请求到GuserAction的login方法,login方法调用GuserService 的login方法,GuserService 的login方法调用GuserDao的login方法,判断用户密码是否正确,若是正确返回一个GuserloginInfo对象。若是不成功抛出用户找不到异常。 图2.3添加库存顺序图 在添加库存JSP上填写填加的信息,在点击添加时现有页面的JS判断,符合要求,发送请求到PurchaseinfoAction的savePurchaseinfo方法,PurchaseinfoAction的 4 王猛 兵团农五师农产品交易平台 savePurchaseinfo方法调用PurchaseinfoService的savePurchaseinfo的方法。PurchaseinfoService的savePurchaseinfo的方法调用PurchaseinfoDao的savePurchaseinfo方法将数据保存到数据库。 图2.4查询库存顺序图 有JSP发送一个请求到PurchaseinfoAction的listpurchaseinfo方法,listpurchaseinfo方法调用PurchaseinfoService的findPurchaseinfo方法,PurchaseinfoService的findPurchaseinfo方法调用PurchaseinfoDao的findPurchaseinfocount和findPurchaseinfos方法查询库存信息。 图2.5添加临时挂拍顺序图 先有JSP发送一个请求到PurchaseinfoAction的listPurchaseinfo方法查出库存信息。再有listJSP发送一个根据id查询一条库存信息的请求,到TradetempinfoAction的findPurchaseinfo的方法,TradetempinfoAction的findPurchaseinfo的方法调用PurchaseinfoService的findPurchaseinfo方法,PurchaseinfoService的findPurchaseinfo方法 5 王猛 兵团农五师农产品交易平台 调用PurchaseinfoDao的findPurchaseinfo的方法,将结果返回到页面。 填好临时挂拍信息,页面JS校验通过后,发送请求到TradetempinfoAction的saveTradeteminfo的方法,TradetempinfoAction的saveTradeteminfo的方法调用TradetemService的saveTradeteminfo的方法,TradetemService的saveTradeteminfo的方法调用PurchaseinfoDao的的Update方法和TradetemDao的save方法,保存到数据库中。 图2.6查询临时挂拍顺序图 有页面发出请求到TradeteminfoAction的findTradeteminfos方法,TradeteminfoAction 的findTradeteminfos方法调用TradeteminfoService的findTradeteminfos的方法,TradeteminfoService的findTradeteminfos的方法调用TradeteminfoDao的findTradeteminfos 方法,将结果list返回到JSP. 图2.7添加挂拍顺序图 有页面发出请求到TradeinfoAction的saveTradeinfo方法,TradeinfoAction的saveTradeinfo方法调用TradeinfoService的saveTradeinfo方法,TradeinfoService的saveTradeinfo方法调用TradeinfoDao的save方法和TradeteminfoDao的delete方法。 6 王猛 兵团农五师农产品交易平台 图2.8查看挂拍销售顺序图 有JSP发出请求到SaleinfoAction的listSaleinfo方法,SaleinfoAction的listSaleinfo方法调用SaleinfoService的listSaleinfo方法,SaleinfoService的listSaleinfo方法调用SaleinfoDao的findSaleinfoCount和findSaleinfos; 图2.9审核订单顺序图 有JSP发出请求到SaleinfoAction的updateSaleinfo方法, SaleinfoAction的updateSaleinfo方法调用SaleinfoService的updateSaleinfo方法。 图2.10批量审核订单顺序图 7 王猛 兵团农五师农产品交易平台 有JSP发出请求到SaleinfoAction的updateSaleinfo方法, SaleinfoAction的updateSaleinfos方法调用SaleinfoService的updateSaleinfos方法。 2.2.2类图 图2.11 Action类图 所有的Action继承BaseAction,BaseAction里面封装了我们常用的request和response等对象方便我在Action中使用。 图2.12 Dao类图 所有的Dao类继承BaseDao这个抽象类,里面封装了hibernatetemplate对象,方便我们在Dao层使用。 8 王猛 兵团农五师农产品交易平台 图2.13临时挂Service类图 图2.14 用户Service类图 图2.15 挂拍Service类图 图2.16库存Service类图 图2.17订单 Service类图 2.2.3系统体系结构设计 农五师后台管理,有一个超级管理员,对任何一个角色都可以管理,没一个角色的权利不一样,是根据他们所在的部门不一样且他们的部门编号不一样,根据每个角色的部门编号来管理权限。我只编写了两个模块,所以我把这两个模块的设计大致叙述一下。 1、供应管理模块:它主要用于添加库存和库存查看两部分,只有仓管和他的上级可以看到这个模块。2、挂拍交易:是交易员和他的上司可以看到这个功能模块,其他人没 添加临时挂有权利,这个模块有两部分,一个是添加临时挂拍,一个是挂拍交易管理。1>拍:是交易员先查看到仓库的库存想把库存的多少挂拍交易,添加到临时挂拍,为减少失误操作先添加到临时挂拍,再添到正式挂拍,如是临时挂拍想改可以把临时挂拍删除。2> 9 王猛 兵团农五师农产品交易平台 挂拍交易管理:正式挂拍列表,可以修该挂拍的状态,要是商品出现质量问题,可以把挂 拍打回,也可以查看分某个商品的销售情况,在查看的同时也可以审核订单。 2.3 数据库设计 供应管理数据分析: 表2.1 Po表字段含义 Po Vo 属性含义 保存 查询 条件 字段 字段 字段 * Id Id * * * Name name 品种名称 * * *-1 Producestate Producestate 货物状态 * * *-1 Qualitylevel Qualitylevel 质量的级 别 * * Impurity Impurity 杂质 * * Moisture Moisture 水分 * * Szqwinfo Szqwinfo 色泽气味 * * * Place Place 产地 * * * Producedate Producedate 生产日期 * * quantity quantity 供货数量 * * unit Unit 单位 * * savecompnayname Savecompnayname 承储单位 名称 * address Address 库存地址 * * remainquantity Remainquantity 剩余数量 * * adddate Adddate 入库时间 * isdel 是否删除 * * deptcode 该货存所 属单位的 编码 * guser 发布供应 信息的用 户 tradeinfos 挂拍的信 息 tradeinfotemps 临时挂拍 的信息 * dname 部门名称 *-1 producetype 品种类型 *1 pn 当前页号 *1 flag 是否有货 存 10 王猛 兵团农五师农产品交易平台 Name:小麦、玉米、大豆、花生、棉花 Producetype:-1(全部),0(未知),1(小麦),2(玉米),3(大豆),4(花生),5(棉花) Producestate:-1(全部),0(未知),1(现货),2(期货) -1(全部),0(未知),1(一级),2(二级),3(三级),4(四级) Qualitylevel: Isdel:0(无删除),1(删除) Flag: 0(无货存),1(有货存) 订单状态 0 未中标 1中标 2取消中标 交易状态 0 未开始 1 交易中 2已结束 表2.2 Vo表字段含义 Vo Po 临时 保存 查询 字段 id *t * * id 序号 name *p * 名称 place *p * 产地 producestate *p * 是否现 货 quantity *t * * quantity 数量 remainquantity * 剩余数 量 unit *p * 单位 price *t * * price 起拍价 qualitylevel *p * 级别 priceinterval *t * * priceinterval 价差幅 度 producedate *p * 生产年 份 savecompnayname *p * 承储单 位 dname *d * 所属单 位 adddate * 添加时 间 tradestate * 交易状 态 state * 要更改 交易状 态 purchaseinfoId *p 货存id description 描述 杂质 impurity moisture 水分 11 王猛 兵团农五师农产品交易平台 szqwinfo 色泽气 味 Bid 农用户 id address 存储库 点 * deptcode 部门编 号 * description 描述 * guser 用户 * purchaseinfo 货存 表2.3 Po表字段含义 Po Vo 属性含义 保存 查询 条件 字段 字段 字段 * id Id * * * price price 拍卖价格 * * * Priceinterval Priceinterval 价格幅度 * * *01 Isdel 是否删除 * * Tradestate Tradestate 拍卖状态 * * Orderstate Orderstate 0表示是农 五师挂拍 的,1是用 户的 * * Adddate Szqwinfo 添加到拍 卖的时间 * * quantity quantity 数量 2.3表的设计 全系统18张表,一共使用15张表,核心模块8张表,如下图: 12 王猛 兵团农五师农产品交易平台 图2.18 数据库表图 13 王猛 兵团农五师农产品交易平台 第3章 实现与测试 目标功能:1、农五师后台人员登录;2、供应管理:发布和查询供应农产品信息;3、挂拍交易:添加挂拍信息和管理挂拍交易。 3.1农五师后台人员登录 农五师后台人员用自己的账号和密码登录到系统中,每个人都有自己的部门编号,和自己的登录名。登录到系统中,根据登录人员的部门编号来显示菜单,不同部门人员看到的菜单不一样。 3.1.1活动图 图3.1 登录活动图 用户登录:用户名和密码正确,可以成功登录到系统中,若是任意一个错误,系统将会提示有错误请从新填写信息登录。 3.1.2界面 图 3.2 登录界面 14 王猛 兵团农五师农产品交易平台 3.1.3代码 public String login() throws Exception { GuserLoginInfo guserLoginInfo=guserService.login(uname, pwd); HttpSession session=this.getRequest().getSession(); session.setAttribute(Constants.GUSER_LOGIN_INFO, guserLoginInfo); return Action.SUCCESS; } 3.1.4登录时序图 图3.3 登录时序图 3.2 供应管理:发布和查询供应农产品信息 这个功能是农五师采购人员,向库仓库里面添加农商品和查询仓库中剩余的农商品,这个功能方便了采购人员向仓库中添加商品,并且这个功能模块多条件的查询方便查找。 3.2.1活动图 图3.4添加活动图 填写添加页面信息页面校验无误,提交请求提示添加成功并跳转到添加页面将信息存入数据库。 15 王猛 兵团农五师农产品交易平台 图3.5 查询活动图 可以根据不同的条件查询到你想要的信息。 3.2.2界面 图3.6 添加库存界面 添加库存信息,根据上面页面提示信息填写入库的农作物信息,填好点击入库,若页面没有错误将提示添加成功,跳转到添加页面。要是有误提示信息有,如填写有误可以重置页面信息,还原为初始状态。 16 王猛 兵团农五师农产品交易平台 图3.7 查询库存界面 查询库存信息,这个是多条件查询,可以根据上面显示的条件查询,也可以不填查询 出所有的库存信息,并且这个是分页的。 3.2.3代码 public String savePurchaseinfo() throws Exception { // 1.获得表单数据 PurchaseinfoVo // 2.Vo -> Po Purchaseinfo purchaseinfo = new Purchaseinfo(); BeanUtils.copyProperties(purchaseinfoVo, purchaseinfo); // 3.Po purchaseinfo.setAdddate(new Date()); purchaseinfo.setIsdel(0); purchaseinfo.setDeptcode(guserLoginInfo.getDcode()); purchaseinfo.setRemainquantity(purchaseinfo.getQuantity()); purchaseinfo.setGuser(new Guser(guserLoginInfo.getId())); // 4.service.save purchaseinfoService.savePurchaseInfo(purchaseinfo); // 5.return return Action.SUCCESS; } public String listPurchaseinfo() throws Exception { String place = purchaseinfoVo.getPlace(); place = new String(place.getBytes("ISO-8859-1"), "GBK"); purchaseinfoVo.setPlace(place); page = purchaseinfoService.findPurchaseInfos(guserLoginInfo.getDcode(), guserLoginInfo.getDlevel(), purchaseinfoVo.getProducedate(), 17 王猛 兵团农五师农产品交易平台 purchaseinfoVo.getPlace(), purchaseinfoVo.getProducetype(), purchaseinfoVo.getProducestate(), purchaseinfoVo .getQualitylevel(), 1, purchaseinfoVo.getPn()); return Action.SUCCESS; } 3.2.4用例 图3.8 供应管理用例 据图所知,仓库管理员管理供应管理这个模块,这个模块分两个功能一个是添加供应 一个是查询供应列表,其余的没有其他权利。 3.3 添加挂拍信息和管理挂拍交易 这个功能分两模块: 1、是添加挂拍信息:把需要卖的东西先添加临时挂拍,检查一下是否有误,若没误,添加到正式挂拍就可以出售了同时库存也减少,要是有误可以删除临时挂拍同时库存会增 加。 2、管理挂拍交易:可以多条件查询挂拍信息,还可以更改挂拍的状态,还有打回挂 拍同时库存会增加,还有会查看在交易中的挂拍信息。 18 王猛 兵团农五师农产品交易平台 3.3.1活动图 图3.9 添加临时挂拍活动图 现有页面发送请求查询库存列表,点击某个按钮时那个作物的库存信息查询出来可以再页面填写挂牌信息,挂拍数量不能大于库存数量添加成功后有提示信息。成功之后跳转到添加页面。 图3.10 管理挂拍活动图 挂牌管理先查询挂拍信息,在列表中可以修改挂拍的状态,可以查看交易中的订单信息。可以批量审核订单,可以把挂拍打回。 19 王猛 兵团农五师农产品交易平台 3.3.2界面 图3.11 添加临时挂拍前查询库存界面 当点击添加挂拍时,查询出所有的库存信息,并且是个多条件查询,要添加那个农作物点击前面的按钮会查询出本作物的详细信息,填写添加的数量并提交。 图3.12 添加临时挂拍界面 图3.13 添加临时挂拍成功后界面 图3.13 挂拍交易管理界面 这个是交易管理页面,可以修改交易状态,要是以完成及没法修改了,查看就是查 20 王猛 兵团农五师农产品交易平台 看 在交易中的挂拍,在查看页面还可以审核订单。要是农作物出现问题,可以在这个页 面将农作物打回,这样就会在挂拍列表看不到,就没法下订单。 3.3.3代码 1.临时挂拍: public String listTradeinfotemp() throws Exception { System.out.println(tradeinfotempService); tradeinfotemps = tradeinfotempService.findTradeinfotemps(guserLoginInfo .getId()); return Action.SUCCESS; } public String deleteTradeinfotemp() throws Exception { tradeinfotempService.deleteTradeinfoTemp(tradeinfoVo.getId(), tradeinfoVo.getPurchaseinfoId(), tradeinfoVo.getQuantity()); return Action.SUCCESS; } public String addTradeinfotemp() throws Exception { purchaseinfo = purchaseinfoService .findPurchaseInfo(tradeinfoVo.getId()); return Action.SUCCESS; } public String saveTradeinfotemp() throws Exception { HttpServletResponse response = this.getResponse(); response.setContentType("text/html;charset=GBK"); PrintWriter out = response.getWriter(); try { Tradeinfotemp tradeinfotemp = new Tradeinfotemp(); BeanUtils.copyProperties(tradeinfoVo, tradeinfotemp); tradeinfotemp.setDeptcode(guserLoginInfo.getDcode()); tradeinfotemp.setGuser(new Guser(guserLoginInfo.getId())); tradeinfotemp.setPurchaseinfo(new Purchaseinfo(tradeinfoVo 21 王猛 兵团农五师农产品交易平台 .getPurchaseinfoId())); tradeinfotempService.saveTradeinfotemp(tradeinfotemp); out.print(0); } catch (Exception e) { out.print(5); } out.flush(); out.close(); return null; } public String saveTradeinfo() throws Exception { tradeinfoService.saveTradeinfos(tradeinfoVo.getIds(), tradeinfoVo.getAdddate()); return Action.SUCCESS; 2.正式挂拍: public String listTradeinfo() throws Exception { page = tradeinfoService.findTradeinfos(guserLoginInfo.getDcode(), tradeinfoVo.getTradestate(), tradeinfoVo.getProducetype(), tradeinfoVo.getProducestate(), tradeinfoVo.getQualitylevel(), tradeinfoVo.getPn()); return Action.SUCCESS; } public String updateTradeinfoState() throws Exception { tradeinfoService.updateTradeinfoState(tradeinfoVo.getId(), tradeinfoVo .getState()); return Action.SUCCESS; } public String clearRemainquantity() throws Exception { tradeinfoService.clearRemainquantity(tradeinfoVo.getId(), tradeinfoVo .getPurchaseinfoId(), tradeinfoVo.getQuantity()); return Action.SUCCESS; 22 王猛 兵团农五师农产品交易平台 } 3.出售: public String listSaleinfo() throws Exception { page = saleinfoService.findSaleinfos(saleinfoVo.getTradeinfoId(), saleinfoVo.getPriceOrder(), saleinfoVo.getQuantityOrder(), saleinfoVo.getPn()); return Action.SUCCESS; } public String updateSaleinfoOrderstate() throws Exception { saleinfoService.updateSaleinfoOrderstate(saleinfoVo.getId(), saleinfoVo .getUserinfoId(), saleinfoVo.getTradeinfoId(), saleinfoVo .getState(), saleinfoVo.getQuantity(), saleinfoVo.getMoney()); return Action.SUCCESS; } public String updateSaleinfoOrderstates() throws Exception { saleinfoService.updateSaleinfoOrderstates(saleinfoVo.getTradeinfoId()); return Action.SUCCESS; } 3.3.4用例 23 王猛 兵团农五师农产品交易平台 图3.14 挂拍交易管理用例 24 王猛 兵团农五师农产品交易平台 第4章 结束语 在八个周的课程设计实践里,我们组遇到了很多困难,刚开始起步时,我基本上“一无所知”,用什么做数据库都还不知道,所有的东西,我都得去潜心学习,我在开始做之前,列了一张简短的表,主要关于的是工程的计划安排,以及每个人的分工,安排完之后,我便开始了两个周的学习实践,把那些看似与课程设计有关的书籍,都每样借了好些本,也学到了很多东西,但是还不知道效果怎样,毕竟这个东西我以前都没有碰过,只能走一步算一步,摸着石头过河。 两个周之后我们便开始动工了,我们每个人都尝试着去做一些小模块,先练练手,这一段时间过的极其艰难,因为各种工具都不熟,数据库,图形界面,需求分析图形格式,按照各人的专长分工让我明白,合理而明确的分工会大大地提高我们个人的工作效率,个人效率的提高,也会大大的影响到集体的效率。 在后来的几个周里,我们基本上沉浸在了自己的小模块里、、、、在最后的两个周里,其他同学的任务基本完成,由于项目经理的工作量很大,基本上每天都是很晚才下班,现在想起来,也突然间觉得,这或许也是分工太过明确,分工不均的后果,每个人的内容都不是很重合,有的人工作量少,于是做完了也帮不上忙,这样就会导致组内有些人的任务过于沉重,尤其是项目经理,基本上所有的汇总工作和资料采集工作都是她做的,在承担一个项目的时候,应该更加的考虑到每个组员的感受,虽然自己也努力了。 不管怎么样,项目还是顺利做完了,这个里面凝聚了每个人的汗水,也夹杂了我们八周里的经验与教训,这些宝贵的财富将随着我们的成长而愈益珍贵。 25 王猛 兵团农五师农产品交易平台 参考文献 [1] 常建功. JAVA Web项目实战大全[M]. 北京:清华大学出版社,2011.1 [2] 孙卫琴. JAVA Web开发技术详解[M] 北京:电子工业出版社,2010.4 [3] 韩玉民. 计算机专业英语教学研究与实践 [J].计算机与信息技术,2008,(6):106-107. 26 王猛 兵团农五师农产品交易平台 附录A: 主要源程序 持久层的工具类: public class HibernateTemplate extends org.springframework.orm.hibernate3.HibernateTemplate { public HibernateTemplate() { super(); } public HibernateTemplate(SessionFactory sessionFactory, boolean allowCreate){ super(sessionFactory, allowCreate); } public HibernateTemplate(SessionFactory sessionFactory) { super(sessionFactory); } //通过hql语句,查询出满足条件的可以分页的数据 public List queryForList(final String hql, final Object[] params, final int firstResult, final int maxResults) { List) super.execute(new HibernateCallback() { return ( public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(hql); initParams(query, params); return query.setFirstResult(firstResult).setMaxResults( maxResults).list(); } }); } //通过hql语句和参数查询单条数据 public Object queryForObject(final String hql, final Object[] params) { return super.execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(hql); initParams(query, params); return query.uniqueResult(); } }); } //通过sql语句更新数据 public int updateWithSQL(final String sql, final Object[] params) { 27 王猛 兵团农五师农产品交易平台 return (Integer) super.execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery(sql); initParams(query, params); return query.executeUpdate(); } }); } //通过sql语句,查询出满足条件的数据 public List queryForListWithSQL(final String sql, final Object[] params) { return queryForListWithSQL(sql, params, 0, 0); } //通过sql语句,查询出满足条件的可以分页的数据 public List queryForListWithSQL(final String sql, final Object[] params, final int firstResult, final int maxResults) { return (List) super.execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery(sql); initParams(query, params); if (firstResult >= 0 && maxResults > 0) { query.setFirstResult(firstResult).setMaxResults(maxResults); } return query.list(); } }); } //通过sql语句和参数查询单条数据 public Object queryForObjectWithSQL(final String sql, final Object[] params){ return (Object) super.execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery(sql); initParams(query, params); return query.uniqueResult(); } }); } protected void initParams(Query query, Object[] params) { if (params != null && params.length > 0) { 28 王猛 兵团农五师农产品交易平台 for (int i = 0; i < params.length; i++) { query.setParameter(i, params[i]); } } } Dao层继承的父类: public abstract class BaseDao { protected HibernateTemplate hibernateTemplate; public void setSessionFactory(SessionFactory sessionFactory) { this.hibernateTemplate = new HibernateTemplate(sessionFactory); } public HibernateTemplate getHibernateTemplate() { return hibernateTemplate; } 处理异常的类: public class DaoAspect { public void handleException(Exception e) throws Exception { if (e instanceof HibernateOptimisticLockingFailureException) { throw new UpdateException(e); } if ("com.nws.exception".equals(e.getClass().getPackage().getName())) { throw e; } else { throw new DaoException(e); } } } 登录登出模块: Dao层 public class GuserShDao extends BaseDao implements IGuserDao { public class GuserShDao extends BaseDao implements IGuserDao { //通过用户名,密码查找用户信息 public GuserLoginInfo login(String uname, String pwd) { String hql = "select new com.nws.vo.GuserLoginInfo(g.id,g.name,g.uname,g.pwd,g.glevel,d.id,d.dcode,d.dname,d.dlevel)" + "from Guser g inner join g.dept d where g.isdel=? and d.isdel=? and lower(g.uname)=lower(?) and lower(g.pwd)=lower(?)"; GuserLoginInfo guserLoginInfo = (GuserLoginInfo) hibernateTemplate .queryForObject(hql, new Object[] { 0, 0, uname, pwd }); if (guserLoginInfo == null) { 29 王猛 兵团农五师农产品交易平台 throw new GuserLoginFailException(); } return guserLoginInfo; } //通过用户id查找具有用户权限的菜单 public List findMenus(int uid) { String hql = "select distinct(m) from Menu m inner join m.roles r inner join r.gusers g " + "where r.isdel=? and g.isdel=? and g.id=? order by m.code"; return hibernateTemplate.find(hql, new Object[]{0,0,uid}); } } Service 层: public class GuserServiceImpl implements IGuserService { private IGuserDao guserDao = null; public GuserLoginInfo login(String uname, String pwd) { GuserLoginInfo guserLoginInfo = guserDao.login(uname, pwd); List list = guserDao.findMenus(guserLoginInfo.getId()); List menuTrees = new ArrayList(); for(Menu menu:list){ String code = menu.getCode(); if(GenericValidator.isBlankOrNull(code)) continue; if(code.matches("^[0-9]{2}0{4}$")){ MenuTree menuTree = new MenuTree(menu); menuTrees.add(menuTree); findSubMenuTrees(list, menuTree, 1); } } guserLoginInfo.setMenus(menuTrees); return guserLoginInfo; } public void findSubMenuTrees(List list,MenuTree menuTree,int level){ String code = menuTree.getRoot().getCode(); String prefix = code.substring(0,level*2); for(Menu subMenu : list){ String subCode = subMenu.getCode(); if(GenericValidator.isBlankOrNull(subCode)) continue; if(subCode.matches("^"+prefix+"[0-9]{2}0{"+(2-level)*2+"}$")&&!subCode.equals(code)){ MenuTree subMenuTree = new MenuTree(subMenu); menuTree.addSubTree(subMenuTree); 30 王猛 兵团农五师农产品交易平台 if(level<2){ findSubMenuTrees(list, subMenuTree,level+1); } } } } } Action层; public class GuserAction extends BaseAction{ private String uname; private String pwd; private IGuserService guserService; //处理登录 public String login(){ GuserLoginInfo guserLoginInfo = guserService.login(uname, pwd); getSessionScope().put(Constants.GUSER_LOGIN_INFO, guserLoginInfo); return SUCCESS; } //处理登出 public String logout() throws Exception { HttpSession session = getRequest().getSession(false); if(session!=null){ session.invalidate(); } return SUCCESS; } } 供应管理模块: Dao层: public class PurchaseShDao extends BaseDao implements IPurchaseinfoDao{ //保存purchaseinfo 信息 public void savePurchaseInfo(Purchaseinfo purchaseinfo) { hibernateTemplate.save(purchaseinfo); } //多条件查询总数据 public List findPurchaseInfos(String deptcode, int dlevel, Date producedate, String place, int producetype, int producestate, int qualitylevel, int flag, int firstresult, int maxresults) { StringBuffer hql = new StringBuffer(); List params = new ArrayList(); hql.append("select new 31 王猛 兵团农五师农产品交易平台 com.nws.vo.PurchaseinfoVo( p.id,p.name,p.place,p.producestate,p.quantity,p.remainquantity,p.unit,p.qualityle vel,p.moisture,p.impurity,p.szqwinfo, p.adddate,p.producedate,p.savecompnayname,d.dname) "); hql.append("from Purchaseinfo p,Dept d where p.deptcode = d.dcode and p.isdel=? and d.isdel=? and substr(p.deptcode,0,?)=substr(?,0,?) "); params.add(0); params.add(0); params.add(dlevel*2); params.add(deptcode); params.add(dlevel*2); if(producedate!=null){ hql.append("and p.producedate = ? "); params.add(producedate); } if(!GenericValidator.isBlankOrNull(place)){ hql.append("and p.place like ? "); params.add("%"+place+"%"); } if(producetype>0){ hql.append("and p.producetype =? "); params.add(producetype); } if(producestate>0){ hql.append("and p.producestate=? "); params.add(producestate); } if(qualitylevel>0){ hql.append("and p.qualitylevel=? "); params.add(qualitylevel); } if(flag==1){ hql.append("and p.remainquantity > ? "); params.add(0); } hql.append("order by p.adddate desc"); return hibernateTemplate.queryForList(hql.toString(), params.toArray(), firstresult, maxresults); } //多条件查询数据总数,为分页用 public int findPurchaseInfoCount(String deptcode, int dlevel, Date producedate, String place, int producetype, int producestate, int qualitylevel, int flag) { 32 王猛 兵团农五师农产品交易平台 StringBuffer hql = new StringBuffer(); List params = new ArrayList(); hql.append("select count(p.id) "); hql.append("from Purchaseinfo p where p.isdel=? and substr(p.deptcode,0,?)=substr(?,0,?) "); params.add(0); params.add(dlevel*2); params.add(deptcode); params.add(dlevel*2); if(producedate!=null){ hql.append("and p.producedate = ? "); params.add(producedate); } if(!GenericValidator.isBlankOrNull(place)){ hql.append("and p.place like ? "); params.add("%"+place+"%"); } if(producetype>0){ hql.append("and p.producetype =? "); params.add(producetype); } if(producestate>0){ hql.append("and p.producestate=? "); params.add(producestate); } if(qualitylevel>0){ hql.append("and p.qualitylevel=? "); params.add(qualitylevel); } if(flag==1){ hql.append("and p.remainquantity > ? "); params.add(0); } return ((Long)hibernateTemplate.queryForObject(hql.toString(), params.toArray())).intValue(); } //通过id属性查询单个对象 public Purchaseinfo findPurchaseInfo(int id) { String hql = "select new com.nws.po.Purchaseinfo( p.id, p.name, p.producestate, p.qualitylevel, p.place, p.unit,"+ " p.remainquantity) from Purchaseinfo p where id=? and isdel=?"; return (Purchaseinfo) hibernateTemplate.queryForObject(hql, new Object[]{id,0}); 33 王猛 兵团农五师农产品交易平台 } //更新某固定id对象的数量 public void updateRemainquantity(int id, int quantity) { String hql = "update Purchaseinfo set remainquantity = remainquantity + ? where id=? and isdel=?"; int row = hibernateTemplate.bulkUpdate(hql, new Object[]{quantity,id,0}); if(row!=1){ throw new UpdateException(); } } } Service层: public class PurchaseServiceImpl implements IPurchaseinfoService{ private IPurchaseinfoDao purchaseinfoDao; public IPurchaseinfoDao getPurchaseinfoDao() { return purchaseinfoDao; } public void setPurchaseinfoDao(IPurchaseinfoDao purchaseinfoDao) { this.purchaseinfoDao = purchaseinfoDao; } public void savePurchaseInfo(Purchaseinfo purchaseinfo) { purchaseinfoDao.savePurchaseInfo(purchaseinfo); } public Page findPurchaseInfos(String deptcode, int dlevel, Date producedate, String place, int producetype, int producestate, int qualitylevel, int flag, int pn) { Page page = null; int count = purchaseinfoDao.findPurchaseInfoCount(deptcode, dlevel, producedate, place, producetype, producestate, qualitylevel, flag); page = new Page(count,pn,Constants.PAGE_SIZE); List result = purchaseinfoDao.findPurchaseInfos(deptcode, dlevel, producedate, place, producetype, producestate, qualitylevel, flag, page.getFirstResult(), page.getMaxResults()); page.setResult(result); return page; } public Purchaseinfo findPurchaseInfo(int id) { return purchaseinfoDao.findPurchaseInfo(id); } } Action层: 34 王猛 兵团农五师农产品交易平台 public class PurchaseInfoAction extends BaseAction { private PurchaseinfoVo purchaseinfoVo = new PurchaseinfoVo(); private IPurchaseinfoService purchaseinfoService; private GuserLoginInfo guserLoginInfo; private Purchaseinfo purchaseinfo; private Page page; @Override public Object getModel() { return purchaseinfoVo; } @Override public void setSession(Map sessionScope) { super.setSession(sessionScope); guserLoginInfo = (GuserLoginInfo) sessionScope.get(Constants.GUSER_LOGIN_INFO); } //处理保存单条数据 public String savePurchaseInfo() throws Exception { Purchaseinfo purchaseinfo = new Purchaseinfo(); BeanUtils.copyProperties(purchaseinfoVo, purchaseinfo); purchaseinfo.setAdddate(new Date()); purchaseinfo.setIsdel(0); purchaseinfo.setDeptcode(guserLoginInfo.getDcode()); purchaseinfo.setRemainquantity(purchaseinfo.getQuantity()); purchaseinfo.setGuser(new Guser(guserLoginInfo.getId())); purchaseinfoService.savePurchaseInfo(purchaseinfo); return Action.SUCCESS; } //处理查询总数据 public String listPurchaseinfo() throws Exception{ String deptcode = guserLoginInfo.getDcode(); int dlevel = guserLoginInfo.getDlevel(); Date producedate = purchaseinfoVo.getProducedate(); String place = purchaseinfoVo.getPlace(); place = new String(place.getBytes("ISO-8859-1"),"gbk"); purchaseinfoVo.setPlace(place); int producetype = purchaseinfoVo.getProducetype(); int producestate = purchaseinfoVo.getProducestate(); int qualitylevel = purchaseinfoVo.getQualitylevel(); int flag = purchaseinfoVo.getFlag(); int pn = purchaseinfoVo.getPn(); page = purchaseinfoService.findPurchaseInfos(deptcode, dlevel, producedate, place, 35 王猛 兵团农五师农产品交易平台 producetype, producestate, qualitylevel, flag, pn); return Action.SUCCESS; } } 挂拍交易模块: 临时挂牌交易: Dao层: public class TradeinfotempShDao extends BaseDao implements ITradeinfotempDao{ //通过id删除临时挂牌信息 public void deleteTradeinfoTemp(int id) { this.getHibernateTemplate().delete(new Tradeinfotemp(id)); } //通过id的集合批量删除临时挂牌信息 public void deleteTradeinfoTemps(int[] ids) { if(ids==null||ids.length<1) return; StringBuffer hql=new StringBuffer(); List params=new ArrayList(); hql.append("delete from Tradeinfotemp where id in ("); for(int id:ids){ hql.append("?,"); params.add(id); } hql.deleteCharAt(hql.length()-1).append(")"); int row=this.getHibernateTemplate().bulkUpdate(hql.toString(),params.toArray()); if(row!=ids.length) throw new UpdateException(); } //保存单条临时挂牌信息 public void saveTradeinfotemp(Tradeinfotemp tradeinfotemp) { this.getHibernateTemplate().save(tradeinfotemp); } //通过用户id查询所有数据 public List findTradeinfotemps(int bid) { String hql="select new com.nws.vo.TradeinfoVo(t.id,p.id,t.quantity,t.price,t.priceinterval,p.name,p.place,p.producestate,p.unit,p.qualit ylevel,p.producedate,p.savecompnayname,d.dname) " + "from Tradeinfotemp t,Dept d inner join t.purchaseinfo p " + "where t.deptcode=d.dcode and p.isdel = ? and d.isdel = ? and t.guser.id = ? order by t.id asc "; return this.getHibernateTemplate().find(hql, new Object[]{0,0,bid}); 36 王猛 兵团农五师农产品交易平台 } } Service层: public class TradeinfotempServiceImpl implements ITradeinfotempService { private ITradeinfotempDao tradeinfotempDao; private IPurchaseinfoDao purchaseinfoDao; public List findTradeinfotemps(int bid) { return tradeinfotempDao.findTradeinfotemps(bid); } public void deleteTradeinfoTemp(int tid, int pid, int quantity) { tradeinfotempDao.deleteTradeinfoTemp(tid); purchaseinfoDao.updateRemainquantity(pid, quantity); } public void saveTradeinfotemp(Tradeinfotemp tradeinfotemp) { tradeinfotempDao.saveTradeinfotemp(tradeinfotemp); purchaseinfoDao.updateRemainquantity(tradeinfotemp.getPurchaseinfo().getId(), -tradeinfotemp.getQuantity()); } Action层: public class TradeinfotempAction extends BaseAction { private ITradeinfotempService tradeinfotempService; private IPurchaseinfoService purchaseinfoService; private ITradeinfoService tradeinfoService; private TradeinfoVo tradeinfoVo = new TradeinfoVo();// 所有操作的请求参数 private GuserLoginInfo guserLoginInfo;// 用户登录信息 private List tradeinfotemps;// 查询临时挂牌返回值 private Purchaseinfo purchaseinfo;// 查询单个库存返回值 public TradeinfoVo getModel() { return tradeinfoVo; } @Override public void setSession(Map sessionScope) { guserLoginInfo = (GuserLoginInfo) sessionScope .get(Constants.GUSER_LOGIN_INFO); } public String listTradeinfotemp() throws Exception { System.out.println(tradeinfotempService); tradeinfotemps = tradeinfotempService.findTradeinfotemps(guserLoginInfo .getId()); return Action.SUCCESS; } 37 王猛 兵团农五师农产品交易平台 public String deleteTradeinfotemp() throws Exception { tradeinfotempService.deleteTradeinfoTemp(tradeinfoVo.getId(), tradeinfoVo.getPurchaseinfoId(), tradeinfoVo.getQuantity()); return Action.SUCCESS; } public String addTradeinfotemp() throws Exception { purchaseinfo = purchaseinfoService .findPurchaseInfo(tradeinfoVo.getId()); return Action.SUCCESS; } public String saveTradeinfotemp() throws Exception { HttpServletResponse response = this.getResponse(); response.setContentType("text/html;charset=GBK"); PrintWriter out = response.getWriter(); try { Tradeinfotemp tradeinfotemp = new Tradeinfotemp(); BeanUtils.copyProperties(tradeinfoVo, tradeinfotemp); tradeinfotemp.setDeptcode(guserLoginInfo.getDcode()); tradeinfotemp.setGuser(new Guser(guserLoginInfo.getId())); tradeinfotemp.setPurchaseinfo(new Purchaseinfo(tradeinfoVo .getPurchaseinfoId())); tradeinfotempService.saveTradeinfotemp(tradeinfotemp); out.print(0); } catch (Exception e) { out.print(5); } out.flush(); out.close(); return null; } public String saveTradeinfo() throws Exception { tradeinfoService.saveTradeinfos(tradeinfoVo.getIds(), tradeinfoVo.getAdddate()); return Action.SUCCESS; } } 正式挂牌模块: Dao层: public class TradeinfoShDao extends BaseDao implements ITradeinfoDao{ public int findTradeinfoCount(String deptcode, int tradestate, int producetype, int producestate, int qualitylevel) { StringBuffer hql = new StringBuffer( 38 王猛 兵团农五师农产品交易平台 "select count(t.id) from Tradeinfo t,Dept d inner join t.purchaseinfo p " + "where t.deptcode=d.dcode and t.isdel = ? and d.isdel = ? and p.isdel = ? and t.deptcode = ? "); List params = new ArrayList(); params.add(0); params.add(0); params.add(0); params.add(deptcode); if (tradestate > 0) { hql.append("and tradestate = ? "); params.add(tradestate); } if (producetype > 0) { hql.append("and producetype = ? "); params.add(producetype); } if (producestate > 0) { hql.append("and producestate = ? "); params.add(producestate); } if (qualitylevel > 0) { hql.append("and qualitylevel = ? "); params.add(qualitylevel); } return ((Long) this.getHibernateTemplate().queryForObject( hql.toString(), params.toArray())).intValue(); } public List findTradeinfos(String deptcode, int tradestate, int producetype, int producestate, int qualitylevel, int firstresult, int maxresults) { StringBuffer hql = new StringBuffer( "select new com.nws.vo.TradeinfoVo(t.id,t.quantity,t.remainquantity,t.price,t.priceinterval,t.adddate,t.tradestate," + "p.id,p.name,p.place,p.producestate,p.unit,p.qualitylevel,p.producedate,p.savecompnayname,d.dname) " + "from Tradeinfo t,Dept d inner join t.purchaseinfo p " + "where t.deptcode=d.dcode and t.isdel = ? and d.isdel = ? and p.isdel = ? and t.deptcode = ? "); List params = new ArrayList(); params.add(0); params.add(0); 39 王猛 兵团农五师农产品交易平台 params.add(0); params.add(deptcode); if (tradestate > 0) { hql.append("and tradestate = ? "); params.add(tradestate); } if (producetype > 0) { hql.append("and producetype = ? "); params.add(producetype); } if (producestate > 0) { hql.append("and producestate = ? "); params.add(producestate); } if (qualitylevel > 0) { hql.append("and qualitylevel = ? "); params.add(qualitylevel); } hql.append("order by t.adddate desc "); return this.getHibernateTemplate().queryForList(hql.toString(), params.toArray(), firstresult, maxresults); } public void saveTradeinfos(int[] ids, Date adddate) { if (ids == null || ids.length < 1) return; StringBuffer sql = new StringBuffer(); List params = new ArrayList(); sql .append( "insert into tradeinfo (id,quantity,bid,isdel,tradestate,purchaseinfo_id,adddate,price,priceinterval,deptcode,description,remainquantit y) ") .append( "select seq_tradeinfo_id.nextval, quantity,bid,0,1,purchaseinfo_id,sysdate,price,priceinterval,deptcode,description,quantity from tradeinfotemp where id in ( "); for (int id : ids) { sql.append("?,"); params.add(id); } sql.deleteCharAt(sql.length() - 1).append(")"); 40 王猛 兵团农五师农产品交易平台 int row = this.getHibernateTemplate().updateWithSQL(sql.toString(), params.toArray()); if (row != ids.length) throw new UpdateException(); } public void updateRemainquantity(int id, int quantity) { String hql="update Tradeinfo t set t.remainquantity =t.remainquantity+ ? where t.id = ? and t.isdel = ? "; int row=this.getHibernateTemplate().bulkUpdate(hql,new Object[]{quantity,id,0}); if(row!=1) throw new UpdateException(); } public void updateTradeinfoState(int id, int tradestate) { StringBuffer hql=new StringBuffer(); List params=new ArrayList(); hql.append("update Tradeinfo set tradestate = ? where tradestate+1 =? and id = ? and isdel =? "); params.add(tradestate); params.add(tradestate); params.add(id); params.add(0); if(tradestate==3){ hql.append("and remainquantity = ?"); params.add(0); } int row=this.getHibernateTemplate().bulkUpdate(hql.toString(),params.toArray()); if(row!=1){ if(tradestate==3){ throw new TradeFinishException(); } throw new UpdateException(); } } } Service层: public class TradeinfoServiceImpl implements ITradeinfoService { private ITradeinfoDao tradeinfoDao; private ITradeinfotempDao tradeinfotempDao; private IPurchaseinfoDao purchaseinfoDao; private ISaleinfoService saleinfoService; public Page findTradeinfos(String deptcode, int tradestate, 41 王猛 兵团农五师农产品交易平台 int producetype, int producestate, int qualitylevel, int pn) { int count = tradeinfoDao.findTradeinfoCount(deptcode, tradestate, producetype, producestate, qualitylevel); Page page = new Page(count, pn, Constants.PAGE_SIZE); List result = tradeinfoDao.findTradeinfos(deptcode, tradestate, producetype, producestate, qualitylevel, page.getFirstResult(), page.getMaxResults()); page.setResult(result); return page; } public void updateTradeinfoState(int id, int tradestate) { tradeinfoDao.updateTradeinfoState(id, tradestate); } public void saveTradeinfos(int[] ids, Date addDate) { tradeinfoDao.saveTradeinfos(ids, addDate); tradeinfotempDao.deleteTradeinfoTemps(ids); } public void clearRemainquantity(int tid, int pid, int quantity) { tradeinfoDao.updateRemainquantity(tid, -quantity); purchaseinfoDao.updateRemainquantity(pid, quantity); saleinfoService.updateSaleinfoOrderstates(tid); } } Action层: public class TradeinfoAction extends BaseAction { private ITradeinfoService tradeinfoService; private GuserLoginInfo guserLoginInfo;// 用户登录信息 private TradeinfoVo tradeinfoVo = new TradeinfoVo();// 所有操作的请求参数 private Page page; private String referer; public TradeinfoVo getModel() { return tradeinfoVo; } @Override public void setSession(Map sessionScope) { guserLoginInfo = (GuserLoginInfo) sessionScope .get(Constants.GUSER_LOGIN_INFO); } @Override public void setServletRequest(HttpServletRequest request) { 42 王猛 兵团农五师农产品交易平台 super.setServletRequest(request); referer = request.getHeader("referer"); } public String listTradeinfo() throws Exception { page = tradeinfoService.findTradeinfos(guserLoginInfo.getDcode(), tradeinfoVo.getTradestate(), tradeinfoVo.getProducetype(), tradeinfoVo.getProducestate(), tradeinfoVo.getQualitylevel(), tradeinfoVo.getPn()); return Action.SUCCESS; } public String updateTradeinfoState() throws Exception { tradeinfoService.updateTradeinfoState(tradeinfoVo.getId(), tradeinfoVo .getState()); return Action.SUCCESS; } public String clearRemainquantity() throws Exception { tradeinfoService.clearRemainquantity(tradeinfoVo.getId(), tradeinfoVo .getPurchaseinfoId(), tradeinfoVo.getQuantity()); return Action.SUCCESS; } } 配置连接工厂和事务以及事务的作用范围的代码: 43 王猛 兵团农五师农产品交易平台 44
/
本文档为【农产品交易平台毕业设计】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索