前一篇文章我们做的是在医院的角度上添加在采购单里面添加药品。这一篇文章是查看我们添加的采购单信息。
我们先看一下要实现的效果:当:
按下确认添加时,会在这里
显示出刚才添加的数据。
好,我们就来做这个效果:
还是三层:Sql->Mapper->Service->Action。
sql的写法我们要看需求 (看需要查什么)
sql如下:
一共两个Sql:
<!-- 采购单药品明细查询列表 -->
select yycgdmx.id yycgdmxid,
useryy.id useryyid,
useryy.mc useryymc,
ypxx.id,
ypxx.bm,
ypxx.mc,
ypxx.jx,
ypxx.gg,
ypxx.zhxs,
ypxx.scqymc,
ypxx.spmc, ypxx.jyzt, (select info
from dictinfo
where ypxx.jyzt = dictcode
and typecode = '') jyztmc,
yycgdmx.zbjg,
yycgdmx.jyjg,
yycgdmx.cgl,
yycgdmx.cgje,
yycgdmx.cgzt,
(select info
from dictinfo
where typecode = ''
and dictcode = yycgdmx.cgzt) cgztmc,
usergys.mc usergysmc,
usergys.id usergysid from yycgdmx2014 yycgdmx, yycgd2014 yycgd, useryy, ypxx, usergys
where yycgdmx.yycgdid = yycgd.id
and yycgd.useryyid = useryy.id
and yycgdmx.ypxxid = ypxx.id
and yycgdmx.usergysid = usergys.id --数据范围设定
--只查询某个采购单下药品明细
and yycgdmx.yycgdid = ''
<!-- 采购单药品明细查询列表总数 -->
select
count(*)
from yycgdmx2014 yycgdmx, yycgd2014 yycgd, useryy, ypxx, usergys
where yycgdmx.yycgdid = yycgd.id
and yycgd.useryyid = useryy.id
and yycgdmx.ypxxid = ypxx.id
and yycgdmx.usergysid = usergys.id --数据范围设定
--只查询某个采购单下药品明细
and yycgdmx.yycgdid = ''
我们再去写Mapper:
<!-- 采购单药品明细查询列表 -->
<select id="findYycgdmxList" parameterType="yycg.business.pojo.vo.YycgdQueryVo"
resultType="yycg.business.pojo.vo.YycgdmxCustom">
<!-- 引入分页头 -->
<include refid="yycg.base.commonSql.page_start" /> select yycgdmx.id yycgdmxid,
useryy.id useryyid,
useryy.mc useryymc,
ypxx.id,
ypxx.bm,
ypxx.mc,
ypxx.jx,
ypxx.gg,
ypxx.zhxs,
ypxx.scqymc,
ypxx.spmc, ypxx.jyzt, (select info
from dictinfo
where ypxx.jyzt =
dictcode
and typecode = '003') jyztmc,
yycgdmx.zbjg,
yycgdmx.jyjg,
yycgdmx.cgl,
yycgdmx.cgje,
yycgdmx.cgzt,
(select info
from dictinfo
where
typecode = '011'
and dictcode = yycgdmx.cgzt) cgztmc,
usergys.mc
usergysmc,
usergys.id usergysid from yycgdmx${businessyear} yycgdmx,
yycgd${businessyear} yycgd, useryy,
ypxx, usergys
where yycgdmx.yycgdid
= yycgd.id
and yycgd.useryyid = useryy.id
and yycgdmx.ypxxid = ypxx.id
and yycgdmx.usergysid = usergys.id <!-- 只查询某个采购单下药品明细 -->
<include refid="query_yycgdmx_where" />
<!-- 药品查询条件 -->
<include refid="yycg.business.dao.mapper.YpxxMapperCustom.query_ypxx_where" /> <!-- 分页尾部 -->
<include refid="yycg.base.commonSql.page_end" />
</select>
<!-- 采购单药品明细查询列表总数 -->的mapper代码
<!-- 采购单药品明细查询列表总数 -->
<select id="findYycgdmxCount" parameterType="yycg.business.pojo.vo.YycgdQueryVo"
resultType="int"> select count(*) from yycgdmx${businessyear} yycgdmx,
yycgd${businessyear} yycgd, useryy,
ypxx, usergys
where yycgdmx.yycgdid
= yycgd.id
and yycgd.useryyid = useryy.id
and yycgdmx.ypxxid = ypxx.id
and yycgdmx.usergysid = usergys.id <!-- 只查询某个采购单下药品明细 -->
<include refid="query_yycgdmx_where" />
<!-- 药品查询条件 -->
<include refid="yycg.business.dao.mapper.YpxxMapperCustom.query_ypxx_where" /> </select>
我们再去写Service:
先写接口public interface YycdgService
/* <!-- 添加采购药品明细查询列表 -->*/
public List<YycgdmxCustom> findYycgdmxList(String yycgdid,
YycgdQueryVo yycgdQueryVo) throws Exception; /* <!-- 添加采购药品明细查询列表总数 -->*/
public int findYycgdmxCount(String yycgdid, YycgdQueryVo yycgdQueryVo)
throws Exception;
再写继承类,函数:
/* <!-- 添加采购药品明细查询列表 -->*/
@Override
public List<YycgdmxCustom> findYycgdmxList(String yycgdid,
YycgdQueryVo yycgdQueryVo) throws Exception {
// 非空判断
yycgdQueryVo = yycgdQueryVo != null ? yycgdQueryVo : new YycgdQueryVo(); // 通过采购单id得到年份
String businessyear = yycgdid.substring(0, 4); // 在service设置固定业务参数
YycgdmxCustom yycgdmxCustom = yycgdQueryVo.getYycgdmxCustom();
if (yycgdmxCustom == null) {
yycgdmxCustom = new YycgdmxCustom();
}
yycgdmxCustom.setYycgdid(yycgdid);
yycgdQueryVo.setYycgdmxCustom(yycgdmxCustom); // 设置年份
yycgdQueryVo.setBusinessyear(businessyear); return yycgdMapperCustom.findYycgdmxList(yycgdQueryVo);
}
/* <!-- 添加采购药品明细查询列表总数 -->*/
@Override
public int findYycgdmxCount(String yycgdid, YycgdQueryVo yycgdQueryVo)
throws Exception {
// 非空判断
yycgdQueryVo = yycgdQueryVo != null ? yycgdQueryVo : new YycgdQueryVo();
// 通过采购单id得到年份
String businessyear = yycgdid.substring(0, 4);
// 在service设置固定业务参数
YycgdmxCustom yycgdmxCustom = yycgdQueryVo.getYycgdmxCustom();
if (yycgdmxCustom == null) {
yycgdmxCustom = new YycgdmxCustom();
}
yycgdmxCustom.setYycgdid(yycgdid);
yycgdQueryVo.setYycgdmxCustom(yycgdmxCustom);
// 设置年份
yycgdQueryVo.setBusinessyear(businessyear);
return yycgdMapperCustom.findYycgdmxCount(yycgdQueryVo);
}
最后写Action层:
/* <!-- 添加采购药品明细查询列表 -->*/
@RequestMapping("/queryYycgdmx_result")
public @ResponseBody DataGridResultInfo queryYycgdmx_result(String id,YycgdQueryVo yycgdQueryVo,int page,int rows) throws Exception
{ // 查询数据总数
int total = yycdgService.findYycgdmxCount(id, yycgdQueryVo); // 分页参数
PageQuery pageQuery = new PageQuery();
pageQuery.setPageParams(total, rows, page);
// 设置分页参数
yycgdQueryVo.setPageQuery(pageQuery); // 分页查询
List<YycgdmxCustom> list = yycdgService.findYycgdmxList(id,
yycgdQueryVo); DataGridResultInfo dataGridResultInfo = new DataGridResultInfo();
dataGridResultInfo.setTotal(total);
dataGridResultInfo.setRows(list); // dataGridResultInfo.setFooter(footer);
return dataGridResultInfo; }
页面代码如下:
//加载datagrid(采购单明细列表)
$(function() {
$('#yycgdmxlist').datagrid({
title : '采购药品列表',
showFooter:true,//是否显示总计行
striped : true,
url : '${baseurl}cgd/queryYycgdmx_result.action',//这里边后边带了一个参数,所以form中不需要此参数yycgdid
queryParams:{//url的参数,初始加载datagrid时使用的参数
id:'${yycgd.id}'//yycgdid是参数名称,如果参数名称中间有点,将参数用单引号括起来
},
idField : 'yycgdmxid',//采购药品明细id
//frozenColumns : frozenColumns,
columns : columns,
pagination : true,
rownumbers : true,
showFooter:true,//显示总计
toolbar : toolbar,
loadMsg:"",
pageList:[15,30,50,100]
} );
});