我们安装显示的要求:
030医疗项目-模块三:药品供应商目录模块——供货商药品目录查询功能----------Dao层:基本的查询语句的编写-LMLPHP

我们能看到显示的目录里面有:供货企业的名字(这个数据来自于供货商的表[usergys]),流水号,通用名,剂型(这些都来自药品信息表),供货的状态(这个呢在gysypml_control中其实就是一个数字1或者0,但是我们要显示的是正常或者暂停 啊,这样的话这个信息就要查找数据字典表dictinfo才能达到这个功能的 )。。。。

所以我们在查上面要显示的内容的时候:要关联的表有

gysypml, usergys, gysypml_control, ypxx,dictinfo等

我们来看一下sql语句:

select gysypml.ypxxid,
gysypml.usergysid,
usergys.mc usergysmc,
gysypml_control.control,
(select info
from dictinfo
where typecode = ''
and dictcode = gysypml_control.control) controlmc, --这里去查的是数据字典,就是为了把0,1对应显示为暂停,正常。
ypxx.id,
ypxx.bm,
ypxx.mc,
ypxx.jx,
ypxx.gg,
ypxx.zhxs,
ypxx.scqymc,
ypxx.spmc,
ypxx.zbjg,
ypxx.jyzt, (select info
from dictinfo
where ypxx.jyzt = dictcode
and typecode = '') jyztmc from gysypml, usergys, gysypml_control, ypxx
where gysypml.usergysid = usergys.id
and gysypml.ypxxid = gysypml_control.ypxxid
and gysypml.usergysid = gysypml_control.usergysid
and gysypml.ypxxid = ypxx.id --数据范围权限,这个功能就是一个药品供应商只能看到自己能供应的药品不能看到别人的药品,所以要传一个供应商的id过来,这个id是从Action层到service层再到Dao层这样来的。
and gysypml.usergysid = '5197cdd2-08cf-11e3-8a4f-60a44cea4388'

到这里我们的sql语句就写完了。

我们在来看POJO类,以及从页面传入到Action中的包装类。

030医疗项目-模块三:药品供应商目录模块——供货商药品目录查询功能----------Dao层:基本的查询语句的编写-LMLPHP

红色框里面的是用逆向工程生成的。但是我们要查询的选项比自动生成的那些pojo类要复杂,所以我们就设计自定义的pojo类,绿色方框里面的GysypmlCustom.java就是自定义的pojo类。GysypmlQuery是页面传入的包装类。

我们看一下这些类的定义:

下面这个GysypmlCustom.java这个POJO类是从数据库里面查出来的数据保存到这个类中,然后把这个数据传到页面上。这个类里面的字段是根据下面这个页面来添加的。

030医疗项目-模块三:药品供应商目录模块——供货商药品目录查询功能----------Dao层:基本的查询语句的编写-LMLPHP

package yycg.business.pojo.vo;
/*
* 自定义供应商药品目录,这个类里面的字段要包含我们之前写的sql里面要查询的字段。之前要查询的信息中,
* 药品信息的字段是最多的,所以我们这里去继承药品信息表对应的pojo类
*/
public class GysypmlCustom extends YpxxCustom{
private String controlmc;//控制状态的别名1:正常。0:暂停
private String control;//控制状态(1,0)
private String usergysid;//供应商的id
public String getGysypmlid() {
return gysypmlid;
}
public void setGysypmlid(String gysypmlid) {
this.gysypmlid = gysypmlid;
}
private String ypxxid;//
private String gysypmlid;//这个是自己的加的主键。(假设的主键)gysypmlid
public String getUsergysid() {
return usergysid;
}
public void setUsergysid(String usergysid) {
this.usergysid = usergysid;
}
public String getYpxxid() {
return ypxxid;
}
public void setYpxxid(String ypxxid) {
this.ypxxid = ypxxid;
}
public String getControlmc() {
return controlmc;
}
public void setControlmc(String controlmc) {
this.controlmc = controlmc;
}
public String getControl() {
return control;
}
public void setControl(String control) {
this.control = control;
} }

我们再来看一下我们的包装类:包装类根据页面搜索传入的。

030医疗项目-模块三:药品供应商目录模块——供货商药品目录查询功能----------Dao层:基本的查询语句的编写-LMLPHP

我们看一下这个GysypmlQuery.java:这个包装类

package yycg.business.pojo.vo;

import yycg.base.pojo.vo.PageQuery;
/*
*
* 查询GysymplCustom对应的包装类。也就是从页面上输入的字段所对应的包装类。
*
*/
public class GysypmlQueryVo { private PageQuery pageQuery;//页面分页
private YpxxCustom ypxxCustom; //药品信息
private GysypmlCustom gysypmlCustom;//供应商目录
public YpxxCustom getYpxxCustom() {
return ypxxCustom;
} public void setYpxxCustom(YpxxCustom ypxxCustom) {
this.ypxxCustom = ypxxCustom;
} public PageQuery getPageQuery() {
return pageQuery;
} public void setPageQuery(PageQuery pageQuery) {
this.pageQuery = pageQuery;
} public GysypmlCustom getGysymplCustom() {
return gysypmlCustom;
}
public void setGysymplCustom(GysypmlCustom gysymplCustom) {
this.gysypmlCustom = gysymplCustom;
} }

我们来看一下Dao层的代码:

也就是Mapper接口,以及xml文件。

我们看一下Mapper的编写:

package yycg.business.dao.mapper;

import java.util.List;

import yycg.business.pojo.vo.GysypmlCustom;
import yycg.business.pojo.vo.GysypmlQueryVo; public interface GysypmlMapperCustom {
public List<GysypmlCustom> findGysymplList(GysypmlQueryVo gysypmlQueryVo) throws Exception; public int findGysypmlCount(GysypmlQueryVo gysypmlQueryVo)throws Exception;
}

我们再来看一下xml文件的编写:

GysypmlMapperCustom.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="yycg.business.dao.mapper.GysypmlMapperCustom" > <!-- 供货商药品目录查询条件 -->
<sql id="query_gysympl_where">
<if test="gysypmlCustom!=null"> <if test="gysypmlCustom.usergysid!=null and gysypmlCustom.usergysid!=''">
and gysypml.usergysid = #{gysypmlCustom.usergysid}
</if>
<if test="gysypmlCustom.ypxxid!=null and gysypmlCustom.ypxxid!=''">
and gysypml.ypxxid = #{gysypmlCustom.ypxxid}
</if> </if>
</sql> <!-- 供货商目录控制查询条件 -->
<sql id="query_gysypmlcontrol_where">
<if test="gysypmlCustom!=null">
<if test="gysypmlCustom.control!=null and gysypmlCustom.control!=''">
and gysypml_control.control = #{gysypmlCustom.control}
</if>
<if test="gysypmlCustom.usergysid!=null and gysypmlCustom.usergysid!=''">
and gysypml_control.usergysid = #{gysypmlCustom.usergysid}
</if>
<if test="gysypmlCustom.ypxxid!=null and gysypmlCustom.ypxxid!=''">
and gysypml_control.ypxxid = #{gysypmlCustom.ypxxid}
</if>
</if> </sql> <!-- 供应商药品目录查询 -->
<select id="findGysymplList" parameterType="yycg.business.pojo.vo.GysypmlQueryVo" resultType="yycg.business.pojo.vo.GysypmlCustom">
<if test="pageQuery!=null">
select page_2.*
from (select page_1.*, rownum page_num
from
(
</if>
select
gysypml.id gysypmlid,
gysypml.ypxxid,
gysypml.usergysid,
usergys.mc usergysmc,
gysypml_control.control,
(select info
from dictinfo
where typecode = '008'
and dictcode = gysypml_control.control) controlmc,
ypxx.id,
ypxx.bm,
ypxx.mc,
ypxx.jx,
ypxx.gg,
ypxx.zhxs,
ypxx.scqymc,
ypxx.spmc,
ypxx.zbjg,
ypxx.jyzt, (select info
from dictinfo
where ypxx.jyzt = dictcode
and typecode = '003') jyztmc from gysypml, usergys, gysypml_control, ypxx
where gysypml.usergysid = usergys.id
and gysypml.ypxxid = gysypml_control.ypxxid
and gysypml.usergysid = gysypml_control.usergysid
and gysypml.ypxxid = ypxx.id
<!-- 传入供应商的id,供应商只能看到自己供应的药品,所以需要传入供应商的id -->
<include refid="query_gysympl_where"></include>
<!-- 根据 -->
<include refid="query_gysypmlcontrol_where" />
<!-- 药品查询条件 -->
<include refid="yycg.business.dao.mapper.YpxxMapperCustom.query_ypxx_where" />
<!-- 分页尾 -->
<if test="pageQuery!=null">
) page_1
<![CDATA[
where rownum <= ${pageQuery.PageQuery_end}) page_2
where page_2.page_num >= ${pageQuery.PageQuery_start}
]]>
</if>
</select> <!-- 供应商药品目录总数查询 -->
<select id="findGysypmlCount" parameterType="yycg.business.pojo.vo.GysypmlQueryVo" resultType="int"> select
count(1) from gysypml, usergys, gysypml_control, ypxx
where gysypml.usergysid = usergys.id
and gysypml.ypxxid = gysypml_control.ypxxid
and gysypml.usergysid = gysypml_control.usergysid
and gysypml.ypxxid = ypxx.id
<!-- 传入供应商的id,供应商只能看到自己供应的药品,所以需要传入供应商的id -->
<include refid="query_gysympl_where"></include>
<!-- 根据 -->
<include refid="query_gysypmlcontrol_where" />
<!-- 药品查询条件 -->
<include refid="yycg.business.dao.mapper.YpxxMapperCustom.query_ypxx_where" /> </select> </mapper>

这里的:

    <include refid="query_gysympl_where"></include>
<!-- 根据 -->
<include refid="query_gysypmlcontrol_where" />
<!-- 药品查询条件 -->
<include refid="yycg.business.dao.mapper.YpxxMapperCustom.query_ypxx_where" />
就是相当于把这些sql语句独立出来。效果跟写在里面是一样的。
04-18 13:38