李宇
2021-11-12 43ee95fbdcb6fe0a9d548d0935c23c232d5ffeaa
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
<?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.SysWarehouseDao">
  <resultMap id="SysWarehouse" type="com.nanometer.smartlab.entity.SysWarehouse">
    <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="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="department" column="department"></result>
  </resultMap>
 
  <resultMap id="SysWarehouseDto" type="com.nanometer.smartlab.entity.dto.SysWarehouseDto">
    <id property="id" column="id"/>
    <result property="type" column="type"/>
    <result property="name" column="name"/>
    <result property="infoCode" column="info_code"/>
    <result property="barCode" column="bar_code"/>
    <result property="location1" column="location1"/>
    <result property="location2" column="location2"/>
    <collection property="sysWarehouseContainer" ofType="com.nanometer.smartlab.entity.dto.SysWarehouseContainerDto" fetchType="lazy">
      <id property="id" column="wc_id"/>
      <result property="type" column="wc_type"/>
      <result property="name" column="wc_name"/>
      <result property="containerCode" column="container_code"/>
      <result property="infoCode" column="info_code"/>
      <result property="structure" column="structure"/>
      <result property="warehouseContainerName" column="wc_name"/>
      <result property="warehouseContainerType" column="wc_type"/>
      <result property="controllerCode" column="controller_code"/>
    </collection>
  </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>
  </sql>
 
  <select id="getSysWarehouse" parameterType="java.lang.String"  resultMap="SysWarehouse" >
    select * from sys_warehouse
    where id = #{id} and valid_flag = 1
  </select>
 
  <select id="getSysWarehouseList" parameterType="java.util.Map" resultMap="SysWarehouse">
    select su.* from sys_warehouse as su
    where su.valid_flag = 1
    <include refid="queryWhereSql"/>
    order by su.type ASC
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="getSysWarehouseTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1) from sys_warehouse as su
    where su.valid_flag = 1
    <include refid="queryWhereSql"/>
  </select>
  
  <select id="getAllSysWarehouseList" resultMap="SysWarehouse">
    select * from sys_warehouse
    where valid_flag = 1
    order by name asc
  </select>
 
  <insert id="insertSysWarehouse" parameterType="com.nanometer.smartlab.entity.SysWarehouse">
    insert into sys_warehouse(id, type, name, info_code, bar_code, location1, location2, valid_flag, create_time, update_time,department)
    values (#{id}, #{type}, #{name}, #{infoCode}, #{barCode}, #{location1}, #{location2}, 1, now(), now(),#{department})
  </insert>
 
  <update id="updateSysWarehouse" parameterType="com.nanometer.smartlab.entity.SysWarehouse">
    update sys_warehouse set type=#{type}, name=#{name}, info_code=#{infoCode}, bar_code=#{barCode}, location1=#{location1}, location2=#{location2},
    update_time=now(),department=#{department}
    where id=#{id}
  </update>
 
  <update id="deleteSysWarehouses" parameterType="java.util.List">
    update sys_warehouse 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="getSysWarehouseByBarCode" parameterType="java.lang.String"  resultMap="SysWarehouse" >
    select * from sys_warehouse
    where bar_code = #{barCode}
  </select>
  
  
  <select id="selectWarehouse" resultMap="SysWarehouseDto">
 SELECT
    sw.id,
    bm1.meta_value type,
    sw.`name` name ,
    sw.info_code,
    sw.bar_code,
    sw.location1,
    sw.location2,
    swc.id wc_id,
    bm2.meta_value wc_type,
    swc.`name` wc_name,
    swc.info_code ,
    swc.controller_code,
    bm3.meta_value structure,
    swc.container_code
FROM
    `sys_warehouse` sw
    LEFT JOIN base_meta bm1 ON bm1.id = sw.type
    LEFT JOIN sys_warehouse_container swc ON swc.warehouse_id = sw.id
    LEFT JOIN base_meta bm2 ON bm2.id = swc.type
    LEFT JOIN base_meta bm3 ON bm3.id = swc.structure
    where sw.valid_flag = 1
    AND swc.valid_flag = 1
  </select>
</mapper>