030医疗项目-模块三:药品供应商目录模块——供货商药品目录查询功能----------Dao层:基本的查询语句的编写
我们安装显示的要求:
我们能看到显示的目录里面有:供货企业的名字(这个数据来自于供货商的表[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中的包装类。
红色框里面的是用逆向工程生成的。但是我们要查询的选项比自动生成的那些pojo类要复杂,所以我们就设计自定义的pojo类,绿色方框里面的GysypmlCustom.java就是自定义的pojo类。GysypmlQuery是页面传入的包装类。
我们看一下这些类的定义:
下面这个GysypmlCustom.java这个POJO类是从数据库里面查出来的数据保存到这个类中,然后把这个数据传到页面上。这个类里面的字段是根据下面这个页面来添加的。
- 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;
- }
- }
我们再来看一下我们的包装类:包装类根据页面搜索传入的。
我们看一下这个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语句独立出来。效果跟写在里面是一样的。
030医疗项目-模块三:药品供应商目录模块——供货商药品目录查询功能----------Dao层:基本的查询语句的编写的更多相关文章
- 033医疗项目-模块三:药品供应商目录模块——供货商药品目录t添加查询功能----------Dao层和Service层和Action层和调试
什么叫做供货商药品目录t添加查询功能?就是说我们前面的博客里面不是说供货商登录后看到了自己供应的药品了么如下: 现在供货商想要往里面添加别的药品,那么这个药品的来源就是卫生局提供的那个Ypxx表(药品 ...
- 032医疗项目-模块三:药品供应商目录模块——供货商药品目录查询功能----------Service层和Action层和调试
我们上一篇文章讲了Dao层代码: 这一篇我们讲解Service层和Action层: Service层: 分为接口和实现类,我们主要看实现类:GysemplServiceImpl package yyc ...
- 035医疗项目-模块三:药品供应商目录模块——供货商药品目录(批量)添加药品的功能---------Service
这篇文章我们重点介绍Service层.因为Dao层就是用Gysypml逆向生成的Mapper就可以了.所以这里重点讲解Service层. 业务逻辑如下: 1:我们从前端页面传入有两个值:1:userg ...
- 036医疗项目-模块三:药品供应商目录模块——供货商药品目录(批量)添加药品的功能---------Action层
这篇文章我们来讲Action层: 我们先讲开发步骤: 1:我们要根据Service层里面要传的参数,在Action层传入对应的参数. Service层是:public void insertGysym ...
- 031医疗项目-模块三:药品供应商目录模块——供货商药品目录查询功能----------sql补充知识
这个补充知识有一个点很有必要,视屏上的老师提出一点: 内链接关联查询: 如果表A和表B有一个外键关联 ,可以通过外键进行内链接查询 select dictinfo.*, dicttype.typena ...
- 023医疗项目-模块二:药品目录的导入导出-从数据库中查出数据用XSSF导出excel并存放在虚拟目录最后下载(包括调试)
我们要实现的效果: 进入到这个页面后,输入要查询的条件,查询出药品表的数据,然后按下导出按钮 ,就会在服务器的一个目录下生成一个药品表的excel表格. 点击"导出"之后 ...
- 044医疗项目-模块四:采购单模块—采购单保存(Dao,Service,Action三层)
我们上上一篇文章(042医疗项目-模块四:采购单模块-采购单明细添加查询,并且把数据添加到数据库中)做的工作是把数据插入到了数据库,我们这篇文章做的是042医疗项目-模块四:采购单模块-采购单明细添加 ...
- 005医疗项目-模块一:用户的查找:1.用户表查询的sql语句
这是医疗项目的第一个模块:做一个用户的查询,可以根据用户的账号,用户的名称,单位的名称,用户的类型去查询.要求效果如下:
- SSH项目搭建(三)——Maven多模块搭建项目
多模块开发,大致的思想就是把一个项目按某种方式分成多个模块,再把模块们连接成一个整体,我们在开发的时候,可以很清晰的操作每一个模块,可以大大提高开发的效率. Java web项目,最常见的就是按代码的 ...
随机推荐
- 从Eclipse迁移到Android Studio
Google正式推出了Android Studio 1.0,Android默认的开发工具也由Eclipse变成了intellij,对Eclipse的支持肯定会越来越少了,对于Android开发者来说, ...
- yii2 如何在页面底部加载css和js
作者:白狼 出处:www.manks.top/article/yii2_load_js_css_in_end 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 ...
- 一个简单的Java web服务器实现
前言 一个简单的Java web服务器实现,比较简单,基于java.net.Socket和java.net.ServerSocket实现: 程序执行步骤 创建一个ServerSocket对象: 调用S ...
- RPM方式安装MySQL5.5.48 (Aliyun CentOS 7.0 & 卸载MySQL5.7)
环境是阿里云的CentOS7.0,更新了yum源(更新yum源请参考https://help.aliyun.com/knowledge_detail/5974184.html)之后先是尝试安装了MyS ...
- ORACLE数据库异步IO介绍
异步IO概念 Linux 异步 I/O (AIO)是 Linux 内核中提供的一个增强的功能.它是Linux 2.6 版本内核的一个标准特性,当然我们在2.4 版本内核的补丁中也可以找到它.AIO 背 ...
- Javascript之旅——第二站:对象和数组
一觉睡到中午,本来准备起来洗洗继续睡,不过想想没辙,还得继续这个系列,走过变量的第一站,第二站我们再来看看对象和数组. 一:对象 说起对象,我们不自然就想起了面向对象中自封装的一个类,同样JS中也 ...
- Nginx问题定位之监控进程异常退出
nginx在运行过程中是否稳定,是否有异常退出过?这里总结几项平时会用到的小技巧. 1. 在error.log中查看是否有signal项,如果有,看看signal是多少. 比如,这是一个异常退出的情况 ...
- eclipse 启动报错\workspace\.metadata\.log
eclipse启动报错,让查看.metadata\.log日志 eclipse启动不了,让查看.metadata\.log日志,上面为日志中的错误提示. 解决办法:删除 .metadata\.plug ...
- javascript日历控件——纯javascript版
平时只有下班时间能code,闲来写了个纯javascript版.引用该calendar.js文件,然后给要设置成日历控件的input的id设置成calendar,该input就会变成日历控件. < ...
- Android Native 程序逆向入门(一)—— Native 程序的启动流程
八月的太阳晒得黄黄的,谁说这世界不是黄金?小雀儿在树荫里打盹,孩子们在草地里打滚.八月的太阳晒得黄黄的,谁说这世界不是黄金?金黄的树林,金黄的草地,小雀们合奏着欢畅的清音:金黄的茅舍,金黄的麦屯,金黄 ...