jiangping
2023-08-17 6365ab0a976afdd247742c9b3dca15deb3a7a7a1
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
<?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="doumeemes.dao.business.BackorderMapper">
  <resultMap id="BaseResultMap" type="doumeemes.dao.business.model.Backorder">
    <id column="ID" jdbcType="INTEGER" property="id"/>
    <result column="DELETED" jdbcType="TINYINT" property="deleted"/>
    <result column="CREATE_USER" jdbcType="INTEGER" property="createUser"/>
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/>
    <result column="UPDATE_USER" jdbcType="INTEGER" property="updateUser"/>
    <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/>
    <result column="REMARK" jdbcType="VARCHAR" property="remark"/>
    <result column="ROOT_DEPART_ID" jdbcType="INTEGER" property="rootDepartId"/>
    <result column="ORDER_DEPART_ID" jdbcType="INTEGER" property="orderDepartId"/>
    <result column="PROCEDURE_ID" jdbcType="INTEGER" property="procedureId"/>
    <result column="MATERIAL_ID" jdbcType="INTEGER" property="materialId"/>
    <result column="BATCH" jdbcType="VARCHAR" property="batch"/>
    <result column="TYPE" jdbcType="INTEGER" property="type"/>
    <result column="PLAN_DATE" jdbcType="TIMESTAMP" property="planDate"/>
    <result column="BACK_PROCEDURE_ID" jdbcType="INTEGER" property="backProcedureId"/>
    <result column="CONTENT" jdbcType="VARCHAR" property="content"/>
    <result column="STATUS" jdbcType="INTEGER" property="status"/>
    <result column="INSTANCE_ID" jdbcType="VARCHAR" property="instanceId"/>
    <result column="CODE" jdbcType="VARCHAR" property="code"/>
    <result column="NUM" jdbcType="DECIMAL" property="num"/>
    <result column="SALEORDER_ID" jdbcType="INTEGER" property="saleorderId"/>
    <result column="WAREHOUSE_ID" jdbcType="INTEGER" property="warehouseId"/>
    <result column="FACTORY_ID" jdbcType="INTEGER" property="factoryId"/>
    <result column="TITLE" jdbcType="VARCHAR" property="title"/>
    <result column="WAREHOUSE_OUT_ID" jdbcType="VARCHAR" property="warehouseOutId"/>
  </resultMap>
 
  <sql id="Base_Column_List">
    `ID`, `DELETED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `REMARK`, `ROOT_DEPART_ID`, `ORDER_DEPART_ID`, `PROCEDURE_ID`, `MATERIAL_ID`, `BATCH`, `TYPE`, `PLAN_DATE`, `BACK_PROCEDURE_ID`, `CONTENT`, `STATUS`, `INSTANCE_ID`, `CODE`, `NUM`, `SALEORDER_ID`, `WAREHOUSE_ID`
  </sql>
 
  <select id="selectByModel" parameterType="doumeemes.dao.business.model.Backorder" resultMap="BaseResultMap">
    select a.*,b.UNIT_ID as unitId,c.company_id as companyId,m.name as materialName,m.code as materialCode
    ,p.name as backProcedureName,cu.name as customerName,u.code as saleorderCode,f.name as factoryName
    ,w.name as warehouseName,ow.name as warehouseOutName
    from backorder a
    left join department c on a.ROOT_DEPART_ID=c.id
    left join material_distribute b on a.MATERIAL_ID=b.id
    left join material m on b.MATERIAL_ID=m.id
    left join procedures  p on a.BACK_PROCEDURE_ID=p.id
    left join salesorder u on a.SALEORDER_ID=u.id
    left join customer cu on cu.id=u.CUSTOMER_ID
    left join department f on a.FACTORY_ID=f.id
    left join warehouse w on a.WAREHOUSE_ID=w.id
    left join warehouse ow on a.WAREHOUSE_OUT_ID=ow.id
    <where>
      <if test="id != null">
        AND `a`.`ID` = #{id}
      </if>
      <if test="rootDepartId != null">
        AND `a`.`ROOT_DEPART_ID` = #{rootDepartId}
      </if>
      <if test="deleted != null">
        AND `a`.`DELETED` = #{deleted}
      </if>
      <if test="instanceId != null and instanceId!=''">
        AND `a`.`INSTANCE_ID` = #{instanceId}
      </if>
    </where>
    limit 1
  </select>
  <select id="selectList" parameterType="doumeemes.dao.business.model.Backorder" resultMap="BaseResultMap">
    select a.*,b.UNIT_ID as unitId,c.company_id as companyId,m.name as materialName,m.code as materialCode
    ,p.name as backProcedureName,cu.name as customerName,u.code as saleorderCode
    from backorder a
    left join department c on a.ROOT_DEPART_ID=c.id
    left join material_distribute b on a.MATERIAL_ID=b.id
    left join material m on b.MATERIAL_ID=m.id
    left join procedures  p on a.BACK_PROCEDURE_ID=p.id
    left join salesorder u on a.SALEORDER_ID=u.id
    left join customer cu on cu.id=u.CUSTOMER_ID
    <where>
      <if test="id != null">
        AND `a`.`ID` = #{id}
      </if>
      <if test="deleted != null">
        AND `a`.`DELETED` = #{deleted}
      </if>
      <if test="status != null">
        AND `a`.`status` = #{status}
      </if>
      <if test="type != null">
        AND `a`.`type` = #{type}
      </if>
      <if test="startDate != null">
        AND `a`.`CREATE_TIME` >= #{startDate}
      </if>
      <if test="endDate != null">
        AND #{endDate} >= `a`.`CREATE_TIME`
      </if>
      <if test="rootDepartId != null">
        AND `a`.`ROOT_DEPART_ID` = #{rootDepartId}
      </if>
      <if test="instanceId != null and instanceId!=''">
        AND `a`.`INSTANCE_ID` = #{instanceId}
      </if>
      <if test="queryParam != null and queryParam!=''">
        AND (`a`.`title` like concat('%', #{queryParam},'%') or `a`.`code` like concat('%', #{queryParam},'%') )
      </if>
 
        <choose>
          <when test="departIds != null and departIds.size()>0">
            AND (a.CREATE_USER=#{createUser}
            or exists (select d.id from company_user d where ( d.user_id =`a`.`CREATE_USER` and d.department_id
            in <foreach collection="departIds" item="item" separator="," open="(" close=")">#{item}</foreach>)
            )
            )
          </when>
        <otherwise>
          <if test="createUser!=null">
            and a.CREATE_USER=#{createUser}
          </if>
        </otherwise>
        </choose>
      order  by `a`.`CREATE_TIME`  desc
    </where>
  </select>
 
 
</mapper>