kongzy
2023-11-01 dd8795a2675e32b25abe98f644f80d5f72fadb90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?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="com.nanometer.smartlab.dao.SysLaboratoryDao">
  <resultMap id="SysLaboratory" type="com.nanometer.smartlab.entity.SysLaboratory">
    <id property="id" column="id"/>
    <result property="type" column="type"></result>
    <result property="name" column="name"></result>
    <result property="infoCode" column="info_code"></result>
    <result property="barCode" column="bar_code"></result>
    <result property="location1" column="location1"></result>
    <result property="location2" column="location2"></result>
    <result property="department" column="department"></result>
    <result property="validFlag" column="valid_flag" typeHandler="com.nanometer.smartlab.entity.handler.ValidFlagHandler"></result>
    <result property="createTime" column="create_time"></result>
    <result property="updateTime" column="update_time"></result>
    <result property="project" column="project"></result>
  </resultMap>
 
  <sql id="queryWhereSql">
    <if test="type != null and type != ''">
      and su.type = #{type}
    </if>
    <if test="name != null and name != ''">
      and su.name like #{name}
    </if>
    <if test="barCode != null and barCode != ''">
      and su.bar_code = #{barCode}
    </if>
    <if test="editId != null and editId != ''">
      and su.id != #{editId}
    </if>
    <if test="department != null and department != ''">
      and su.department = #{department}
    </if>
    <if test="project != null and project != ''">
      and su.project like concat("%",#{project},"%")
    </if>
  </sql>
 
  <select id="getSysLaboratory" parameterType="java.lang.String"  resultMap="SysLaboratory" >
    select * from sys_laboratory
    where id = #{id} and valid_flag = 1
  </select>
 
  <select id="getSysLaboratoryList" parameterType="java.util.Map" resultMap="SysLaboratory">
    select su.* from sys_laboratory as su
    where su.valid_flag = 1
    <include refid="queryWhereSql"/>
    order by su.name ASC
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="getSysLaboratorySimpleInfoList" parameterType="java.util.Map" resultMap="SysLaboratory">
    select su.id,su.name,su.info_code,su.bar_code,su.location1,su.location2,su.project,su.create_time,su.update_time,bm1.meta_value as type,bm2.meta_value as department from sys_laboratory as su
    left join base_meta as bm1 on bm1.id=su.type
    left join base_meta as bm2 on bm2.id=su.department
    where su.valid_flag = 1
    <include refid="queryWhereSql"/>
    order by su.create_time desc
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="exportLabList" parameterType="java.util.Map" resultType="java.util.Map">
    SELECT bm1.meta_value type ,sl.name,sl.info_code infoCode,sl.bar_code barCode,
    CASE
    WHEN (ISNULL(location1)=1) || (LENGTH(trim(location1))=0)
    THEN
    CONCAT(location1,location2)
    ELSE
    CONCAT(location1,'-',location2)
    END
    location,
    bm2.meta_value department,
    sl.project
    from sys_laboratory as sl
    LEFT JOIN base_meta bm1 on bm1.id = sl.type
    left JOIN base_meta bm2 on bm2.id = sl.department
    where sl .valid_flag = 1
    <if test="name != null and name != ''">
      and sl.name like concat("%",#{name},"%")
    </if>
    <if test="type != null and type != ''">
      and sl.type = #{type};
    </if>
    <if test="project != null and project != ''">
      and sl.project like concat("%",#{project},"%")
    </if>
  </select>
 
  <select id="getSysLaboratoryTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1) from sys_laboratory as su
    where su.valid_flag = 1
    <include refid="queryWhereSql"/>
  </select>
 
  <select id="getAllSysLaboratoryList" resultMap="SysLaboratory">
    select * from sys_laboratory
    where valid_flag = 1
    order by name asc
  </select>
 
  <insert id="insertSysLaboratory" parameterType="com.nanometer.smartlab.entity.SysLaboratory">
    insert into sys_laboratory(id, type, name, info_code, bar_code, location1, location2, valid_flag,department, create_time, update_time,project)
    values (#{id}, #{type}, #{name}, #{infoCode}, #{barCode}, #{location1}, #{location2}, 1,#{department}, now(), now(),#{project})
  </insert>
 
  <update id="updateSysLaboratory" parameterType="com.nanometer.smartlab.entity.SysLaboratory">
    update sys_laboratory set type=#{type}, name=#{name}, info_code=#{infoCode}, bar_code=#{barCode}, location1=#{location1}, location2=#{location2},department=#{department},
    update_time=now(),project = #{project}
    where id=#{id}
  </update>
 
  <update id="deleteSysLaboratorys" parameterType="java.util.List">
    update sys_laboratory set valid_flag=0, update_time=now()
    where id in
    <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
      #{item}
    </foreach>
  </update>
 
  <select id="getSysLaboratoryByBarCode" parameterType="java.lang.String"  resultMap="SysLaboratory" >
    select * from sys_laboratory
    where bar_code = #{barCode} and valid_flag=1
  </select>
 
  <select id="getSysLaboratoryByBarCodeForExport" parameterType="java.lang.String"  resultMap="SysLaboratory" >
    select * from sys_laboratory
    where bar_code = #{barCode}
    and valid_flag=1
  </select>
  <select id="getLaboratoryByProject" resultType="com.nanometer.smartlab.entity.dto.LaboratoryVo$Laboratory">
    SELECT
    CONCAT('楼号:',sl.location1,'-地址号:',sl.location2) as address,
    bm.meta_value as department
    FROM
    sys_laboratory as sl
    LEFT JOIN base_meta bm on bm.id = sl.department
    WHERE
    sl.project LIKE CONCAT('%',#{project},'%')
  </select>
  <select id="getSysLaboratoryByName"  resultMap="SysLaboratory">
    select *
    from  sys_laboratory
    where name = #{0}
    and valid_flag = 1
  </select>
  <select id="getPersonInCharge" resultType="java.util.Map">
    select su.phone
    from sys_user as su
    left join base_role as br on su.role_id = br.id
    where su.project like concat("%",#{project},"%")
    and su.valid_flag = 1
    and br.`name` = '实验负责人'
 
  </select>
  <update id="updateLabExport" parameterType="com.nanometer.smartlab.entity.SysLaboratory">
    update sys_laboratory set
    type=#{type},
    name=#{name},
    info_code=#{infoCode},
    bar_code=#{barCode},
    location1=#{location1},
    location2=#{location2},
    department=#{department},
    update_time=now()
    where id=#{id}
  </update>
</mapper>