039医疗项目-模块四:采购单模块—采购单的创建-----------Dao层,service层,Acion层...
我們根據(jù)數(shù)據(jù)庫里面的表格:生成對(duì)應(yīng)的Mapper接口文件和...Mapperxml文件:
YYCGD:采購單模板表。
YYCGD2014:采購單動(dòng)態(tài)生成表,由存儲(chǔ)過程生成。
YYCGDMX:采購單明細(xì)模板表。
YYCGDMX2014:采購單明細(xì)表,由存儲(chǔ)過程生成。
在逆向工程中:
??? File configFile = new File("generatorConfig-business.xml")
---->
<table schema="" tableName="yycgd" >
?? ??? ?</table>
?? ??? ?
?? ??? ?<table schema="" tableName="yycgdmx" >
?? ??? ??? <columnOverride column="zbjg" javaType="java.lang.Float" />
?? ??? ??? <columnOverride column="jyjg" javaType="java.lang.Float" />
?? ??? ??? <columnOverride column="cgl" javaType="java.lang.Integer" />
?? ??? ??? <columnOverride column="cgje" javaType="java.lang.Float" />
?? ??? ?</table>
?
這么一來,對(duì)應(yīng)的Mapper和Mapperxml文件,和PO類文件就生成了。如下:
PO類:
Mapper接口:
?
?和MapperXML文件:
前面說過我們采用的是分表的方法。所以在逆向工程自動(dòng)生成的YycgdMapper.xml中把from YYCGD改為from YYCGD${businessyear}我們這樣就是在操作動(dòng)態(tài)的數(shù)據(jù)庫表。
這樣的話我們可以這么理解了。我們?cè)跀?shù)據(jù)庫中可能會(huì)生成很多的表(由存儲(chǔ)過程創(chuàng)建)比如YYCGD2014,YYCDG2015等。我們就要采用YYCGD${businessyear}這種形式去查找對(duì)應(yīng)的表。
也就是YycgdMapper.java可以應(yīng)對(duì)各種的表。
?
?
?
?
?
?
-----------------------------------------------------------------------------------------------------------------------------------------------------------
正式開始采購單的業(yè)務(wù):
?
?
?
?
?
我們?cè)趧?chuàng)建采購單時(shí),需要填寫采購單的基本信息。基本信息填寫完成之后,再填寫采購單明細(xì)信息。
采購單的基本信息填寫如下:
?
?
采購單基本信息包括:采購年份、采購單名稱、建單時(shí)間、提交時(shí)間、聯(lián)系人、聯(lián)系電話、備注、采購單狀態(tài)。
?
?
我們來看一下他的Dao是怎么實(shí)現(xiàn)的:
我們針對(duì)的就是藥品采購單的基本表。我們自定義Mapper:把逆向工程生成的Mapperl接口復(fù)制,改為YycgdMapperCusom.java,里面寫我們自己的需求。然后把逆向工程生成的YycgdMapper.xml復(fù)制生成YycgdMapperCustom.xml文件。里面寫我們自己的需求。
需求1:插入一條采購單記錄
YycgdMapperCusom.java中我們先寫第一個(gè)應(yīng)用:我們要插入采購單記錄的話,我們先要構(gòu)造出采購單的基本信息啊,比如采購單的編號(hào),采購單的狀態(tài)等等。其他的信息都是
因?yàn)槲覀兊乃幤凡少弳蔚牟少従幪?hào)是4位年+6位流水號(hào);
所以我們要想怎么去得到這個(gè)采購單編號(hào)呢。
我們?cè)赑L/SQL中寫:
yycgdbm2014就是我們的序列。
select? yycgdbm2014.nextval bm from dual的結(jié)果是:
?
然后我們拼接我們的藥品采購單的采購編號(hào)是4位年+6位流水號(hào);
?
select 2014||yycgdbm2014.nextval bm from dual結(jié)果:
?
?2014100053就是我們的采購單的編號(hào)。
當(dāng)然我們這是寫死了年份2014,在后續(xù)的開發(fā)中我們的年份值是要傳進(jìn)來的。不能這么直接寫死了。
所以在Mapperxml中可以這么寫:
得到采購單的編號(hào)
<mapper namespace=" yycg.business.dao.mapper.YycgdMapperCustom" ><!-- 動(dòng)態(tài)sql的拼接,相當(dāng)于當(dāng)傳入的sring 是2014那么語句就變成了 select 2014||yycgdbm2014.nextval bm from dual 查出來的就是拼接而成的采購單的編號(hào)--><select id="getYycgdBm" parameterType="string" resultType="string" >select '${value}'||yycgdbm${value}.nextval bm from dual</select>
?
Dao層:YycgdMapperCustom.java:
public interface YycgdMapperCustom {//采購單編號(hào)生成public String getYycgdBm(String year)throws Exception;}Service 層:
package yycg.business.service.impl;import java.util.Date;import org.springframework.beans.factory.annotation.Autowired;import yycg.business.dao.mapper.YycgdMapper; import yycg.business.dao.mapper.YycgdMapperCustom; import yycg.business.pojo.vo.YycgdCustom; import yycg.business.service.YycdgService;public class YycdgServiceImpl implements YycdgService{@AutowiredYycgdMapper yycgdMapper;@AutowiredYycgdMapperCustom yycgdMapperCustom;/*** 從頁面上傳入年份。用這個(gè)年份來生成采購單的編號(hào)。* 這里面?zhèn)魅肓薡ycgdCusom這個(gè)對(duì)象,但是傳入的對(duì)象里面的屬性是不完整的。我們?cè)谶@個(gè)insertYycgd方法里面* 設(shè)置好其余的屬性,然后插入到數(shù)據(jù)庫中。*/@Overridepublic void insertYycgd(String useryyid, String year,YycgdCustom yycgdCustom) throws Exception {String bm=yycgdMapperCustom.getYycgdBm(year);//生成采購單的編號(hào)yycgdCustom.setBm(bm);//設(shè)置采購單的編號(hào)yycgdCustom.setBusinessyear(year);//把年加入,這樣就可以在MapperXml中使用這個(gè)year.用來拼接yycgdCustom.setId(bm);//采購單id的主鍵和bm一致,目的是為了方便操作采購單。yycgdCustom.setUseryyid(useryyid);//創(chuàng)建采購單醫(yī)院yycgdCustom.setCjtime(new Date());//創(chuàng)建時(shí)間yycgdCustom.setZt("1");//設(shè)置狀態(tài)/**調(diào)用原生自帶的Mapper接口,把這個(gè)數(shù)據(jù)插入到數(shù)據(jù)庫中。*insert里面的參數(shù)是Yycgd。那我們?cè)谶@里插入的是YycgdCustom類型的*沒事啊,這是多態(tài)么,子類就是父類。當(dāng)然可以把這個(gè)數(shù)據(jù)插入進(jìn)去。**/yycgdMapper.insert(yycgdCustom); //調(diào)用逆向工程自動(dòng)生成的Mapper來插入數(shù)據(jù) }}?
Action層:
總體順序:先經(jīng)過Action,進(jìn)入到addcgd函數(shù),在addcgd函數(shù)里面會(huì)得到有些數(shù)據(jù)然后跳轉(zhuǎn)到新增頁面(在新增頁面上顯示剛才得到的數(shù)據(jù)),然后在新增頁面上輸入數(shù)據(jù)。然后跳轉(zhuǎn)到插入函數(shù)。
?
在menu.json中:
{"icon" : "icon-sys","menuid" : "1","menuname" : "采購單管理 ","url" : "","menus" : [{"icon" : "icon-log","menuid" : "1_1","menuname" : "創(chuàng)建采購單","url" : "/yycgproject/cgd/addcgd.action"}]點(diǎn)擊按鈕之后執(zhí)行 "/yycgproject/cgd/addcgd.action
?
?
?
?
?
/*** * @author Sxq * @Title: addcgd * @Description: * 1:得到當(dāng)前登錄單位的名稱 * 2:生成采購單的名稱 * 3:跳轉(zhuǎn)到新增頁面。 * @param @return * @return String * @throws*/ @RequestMapping("/addcgd") public String addcgd(HttpSession session,Model model) {ActiveUser activeUser=(ActiveUser)session.getAttribute(Config.ACTIVEUSER_KEY);String sysmc=activeUser.getSysmc();//得到所屬單位的名稱//準(zhǔn)備頁面所需要的數(shù)據(jù):因?yàn)槲覀冊(cè)诓少弳雾撁嫔巷@示兩個(gè)內(nèi)容://1:藥品的采購時(shí)間(年)//2:采購單的名稱//所以我們要把這些數(shù)據(jù)加入到Modele,然后把這些數(shù)據(jù)傳入到下一個(gè)頁面。 String yycgdmc=sysmc+MyUtil.getDate()+"采購單";model.addAttribute("yycgdmc",yycgdmc);String year=MyUtil.get_YYYY(MyUtil.getDate());//得到年model.addAttribute("year",year);return "/business/cgd/addcgd";//跳轉(zhuǎn)到新增頁面 }?
?
?
?
?
跳轉(zhuǎn)到新增頁面之后,輸入數(shù)據(jù),然后按下保存按鈕。就會(huì)進(jìn)入到提交函數(shù)(如下):
// 創(chuàng)建采購單基本信息保存方法@RequestMapping("/addcgdsubmit")public @ResponseBodySubmitResultInfo addcgdsubmit(HttpSession session, String year,YycgdQueryVo yycgdQueryVo) throws Exception {ActiveUser activeUser = (ActiveUser) session.getAttribute(Config.ACTIVEUSER_KEY);// 醫(yī)院idString useryyid = activeUser.getSysid();// 獲取采購單idString yycgdid = cgdService.insertYycgd(useryyid, year,yycgdQueryVo.getYycgdCustom());ResultInfo resultInfo = ResultUtil.createSuccess(Config.MESSAGE, 906,null);// 獲取采購單id,將id通過ResultInfo中sysdata傳到頁面resultInfo.getSysdata().put("yycgdid", yycgdid);return ResultUtil.createSubmitResult(resultInfo);}?
?
這個(gè)提交函數(shù)調(diào)用完之后會(huì)執(zhí)行jisp頁面上的回調(diào)函數(shù) 。回調(diào)函數(shù)里面就會(huì)跳轉(zhuǎn)到采購單修改頁面。
function yycgdsave_callback(data) {//由服務(wù)端統(tǒng)一返回submitResultInfo的json數(shù)據(jù),所以客戶端統(tǒng)一使用_alert統(tǒng)一解析方法_alert(data.resultInfo);//獲取新添加的采購單的id//alert(data.resultInfo.sysdata.yycgdid);//在這里必須拿新添加的 采購單的idif(data.resultInfo.type==TYPE_RESULT_SUCCESS){//如果成功跳轉(zhuǎn)至修改頁面//alert(data.resultInfo.sysdata.yycgdid);var yycgdid=data.resultInfo.sysdata.yycgdid; window.location='${baseurl}cgd/editcgd.action?id='+yycgdid;} }?下面一篇博客就要講采購單明細(xì)表了,就從editcgd.action為入口講。
?到這里基本采購單就創(chuàng)建好了。信息也插入到了數(shù)據(jù)庫中。
數(shù)據(jù)庫信息如下:
?
?--------------------------------------------------------------------------------------------------------------------------------------------
addcgd.jsp頁面的代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%@ page contentType="text/html; charset=UTF-8"%> <%@ include file="/WEB-INF/jsp/base/tag.jsp"%> <html> <head> <title>采購單創(chuàng)建</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"><%@ include file="/WEB-INF/jsp/base/common_css.jsp"%> <%@ include file="/WEB-INF/jsp/base/common_js.jsp"%><script type="text/javascript">//采購單保存 function yycgdsave(){jquerySubByFId('yycgdsaveForm', yycgdsave_callback, null); } /*** 采購單保存回調(diào)* data是服務(wù)端響應(yīng)的數(shù)據(jù),服務(wù)端統(tǒng)一響應(yīng)了submitResultInfo對(duì)象的json數(shù)據(jù)*/ function yycgdsave_callback(data) {//由服務(wù)端統(tǒng)一返回submitResultInfo的json數(shù)據(jù),所以客戶端統(tǒng)一使用_alert統(tǒng)一解析方法 _alert(data.resultInfo);//獲取新添加的采購單的id//alert(data.resultInfo.sysdata.yycgdid);//在這里必須拿新添加的 采購單的idif(data.resultInfo.type==TYPE_RESULT_SUCCESS){//如果成功跳轉(zhuǎn)至修改頁面//alert(data.resultInfo.sysdata.yycgdid);var yycgdid=data.resultInfo.sysdata.yycgdid;window.location='${baseurl}cgd/editcgd.action?id='+yycgdid;} }</script> </HEAD> <BODY><form id="yycgdsaveForm" name="yycgdsaveForm" action="${baseurl}cgd/addcgdsubmit.action" method="post"> <TABLE border=0 cellSpacing=0 cellPadding=0 width="70%" bgColor=#c4d8ed align=center><TBODY><TR><TD background=images/r_0.gif width="100%"><TABLE cellSpacing=0 cellPadding=0 width="100%"><TBODY><TR><TD> 藥品采購單</TD><TD align=right> </TD></TR></TBODY></TABLE></TD></TR><TR><TD><TABLE class="toptable grid" border=1 cellSpacing=1 cellPadding=4align=center><TBODY><TR><TD height=30 width="15%" align=right>藥品采購年份<br>(如2014):</TD><TD class=category width="35%">${year}<input type="hidden" name="year" value="${year}" /></TD><TD height=30 width="15%" align=right >采購單名稱:</TD><TD class=category width="35%"><div><input type="text" id="yycgd_mc" name="yycgdCustom.mc" value="${yycgdmc}" style="width:260px" /></div><div id="yycgd_mcTip"></div></TD></TR><TR><TD height=30 width="15%" align=right >建單時(shí)間:</TD><TD class=category width="35%"></TD><TD height=30 width="15%" align=right >提交時(shí)間:</TD><TD class=category width="35%"></TD></TR><TR><TD height=30 width="15%" align=right>聯(lián)系人:</TD><TD class=category width="35%"><input type="text" name="yycgdCustom.lxr" id="yycgdCustom.lxr" style="width:260px" /></TD><TD height=30 width="15%" align=right >聯(lián)系電話:</TD><TD class=category width="35%"><input type="text" name="yycgdCustom.lxdh" id="yycgdCustom.lxdh" style="width:260px" /></TD></TR><TR><TD height=30 width="15%" align=right>采購單狀態(tài):</TD><TD class=category width="35%"></TD><TD height=30 width="15%" align=right>備注:</TD><TD colspan=3><textarea rows="2" cols="30" name="yycgdCustom.bz"></textarea></TD></TR><TR><TD height=30 width="15%" align=right>審核時(shí)間:</TD><TD class=category width="35%"></TD><TD height=30 width="15%" align=right >審核意見:</TD><TD class=category width="35%"></TD></TR><tr><td colspan=4 align=center class=category><a href="#" onclick="yycgdsave()" class="easyui-linkbutton" iconCls='icon-save'>保存</a></td></tr></TBODY></TABLE></TD></TR></TBODY></TABLE> </form></BODY> </HTML>?
結(jié)束。
?
總結(jié)
以上是生活随笔為你收集整理的039医疗项目-模块四:采购单模块—采购单的创建-----------Dao层,service层,Acion层...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言随机数的产生方法
- 下一篇: fir1截止频率计算_如何快速设计一个F