郑永安
2023-06-19 59e91a4e9ddaf23cebb12993c774aa899ab22d16
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
173
174
175
176
177
178
179
<?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.gk.firework.Mapper.DeliveryOrderInfoMapper" >
  <resultMap id="BaseResultMap" type="com.gk.firework.Domain.DeliveryOrderInfo" >
    <!--          -->
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="ordercode" property="ordercode" jdbcType="VARCHAR" />
    <result column="createat" property="createat" jdbcType="TIMESTAMP" />
    <result column="createby" property="createby" jdbcType="VARCHAR" />
    <result column="operator" property="operator" jdbcType="VARCHAR" />
    <result column="operatat" property="operatat" jdbcType="TIMESTAMP" />
    <result column="shop" property="shop" jdbcType="VARCHAR" />
    <result column="boxnum" property="boxnum" jdbcType="INTEGER" />
    <result column="type" property="type" jdbcType="TINYINT" />
    <result column="companynumber" property="companynumber" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    <!--          -->
    id, ordercode, createat, createby, operator, operatat, shop, boxnum, `type`, companynumber
  </sql>
    <select id="selectPages" resultType="com.gk.firework.Domain.Vo.DeliveryOrderInfoVo">
      select
      do.id,
      do.ordercode,
      do.createat,
      do.createby,
      do.operator,
      do.operatat,
      do.shop,
      sum(do.num) realboxnum,
      do.transportcert,
      do.`type`,
      do.companynumber
      from (
          select
          do.id,
          do.ordercode,
          do.createat,
          do.createby,
          do.operator,
          do.operatat,
          do.shop,
          sum(dd.num/p.boxnumber) num,
          do.transportcert,
          do.`type`,
          do.companynumber
          from deliveryorder as do
          left join deliverydetail as dd on dd.deliverycode = do.ordercode
          left join product as p on p.directioncode = dd.itemcode and p.isdel = 0
          <where>
            <if test="params.starttime != null and params.starttime != ''">
              and  do.operatat &gt;= #{params.starttime}
            </if>
            <if test="params.endtime != null and params.endtime != ''">
              and do.operatat &lt; #{params.endtime}
            </if>
            <if test="params.transportcert != null and params.transportcert != ''">
              and do.transportcert like concat("%",#{params.transportcert},"%")
            </if>
            <if test="params.type != null and params.type != ''">
              and do.type = #{params.type}
            </if>
            <if test="params.code != null and params.code != ''">
              and do.ordercode like concat("%",#{params.code},"%")
            </if>
          </where>
          group by do.ordercode,dd.itemcode
      ) as do
      left join enterprise as e on e.enterprisenumber = do.companynumber
      <where>
         e.validflag = 1
         and e.enterprisestatus = 'ON'
        <choose>
          <when test="params.enterprisenumber != null and params.enterprisenumber != ''">
            and do.companynumber = #{params.enterprisenumber}
          </when>
          <otherwise>
            <if test="params.province != null and params.province != ''">
              and e.province = #{params.province}
            </if>
            <if test="params.city != null and params.city != ''">
              and e.city = #{params.city}
            </if>
            <if test="params.district != null and params.district != ''">
              and e.district = #{params.district}
            </if>
            <if test="params.street != null and params.street != ''">
              and e.street = #{params.street}
            </if>
            <if test="params.committee != null and params.committee != ''">
              and e.committee = #{params.committee}
            </if>
          </otherwise>
        </choose>
        <if test="params.filterProvince != null and params.filterProvince  != ''">
          and e.province = #{params.filterProvince}
        </if>
        <if test="params.filterCity != null and  params.filterCity  != ''">
          and e.city = #{params.filterCity}
        </if>
        <if test="params.filterDistrict != null and params.filterDistrict  != ''">
          and e.district = #{params.filterDistrict}
        </if>
        <if test="params.filterStreet != null and params.filterStreet  != ''">
          and e.street = #{params.filterStreet}
        </if>
        <if test="params.filterCommittee != null and params.filterCommittee  != ''">
          and e.committee = #{params.filterCommittee}
        </if>
        <if test="params.filterType != null and params.filterType != ''">
          and do.type = #{params.filterType}
        </if>
        <if test="params.enterprisename != null and params.enterprisename != ''">
          and e.enterprisename like concat("%",#{params.enterprisename},"%")
        </if>
        <if test="params.safetysupervision != null and params.safetysupervision != ''">
          and e.safetysupervision = #{params.safetysupervision}
        </if>
      </where>
 
      group by do.ordercode
      order by do.operatat desc
    </select>
 
  <select id="getDeliveryNum" resultType="decimal">
    select
    sum(detail.num/product.boxnumber)
    from deliverydetail as detail
    left join deliveryorder as delivery on delivery.ordercode = detail.deliverycode
    left join product on detail.itemcode = product.directioncode and product.isdel = 0
    <where>
      delivery.type = 1
      and delivery.operatat &gt;= #{condition.beginDate}
      and delivery.operatat &lt;= #{condition.endDate}
      and delivery.companynumber = #{condition.companyNumber}
      <if test="condition.itemCode != null">
        and product.directioncode = #{condition.itemCode}
      </if>
    </where>
  </select>
 
  <select id="getReturnDeliveryNum" resultType="decimal">
    select
    sum(detail.num/product.boxnumber)
    from deliverydetail as detail
    left join deliveryorder as delivery on delivery.ordercode = detail.deliverycode
    left join product on detail.itemcode = product.directioncode and product.isdel = 0
    <where>
      delivery.type = 2
      and delivery.operatat &gt;= #{condition.beginDate}
      and delivery.operatat &lt;= #{condition.endDate}
      and delivery.companynumber = #{condition.companyNumber}
      <if test="condition.itemCode != null">
        and product.directioncode = #{condition.itemCode}
      </if>
    </where>
  </select>
  <select id="selectDeliveryOrderByTimeAndUser" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from deliveryorder
    <where>
      operator = #{username}
      and operatat = #{datetime}
    </where>
    limit 1
  </select>
 
  <select id="getProductVosByCert" resultType="com.gk.firework.Domain.Vo.ProductVo">
    select
    detail.itemcode as itemCode,
    detail.itemname as name,
    COUNT(detail.id)as num
    from deliverydetail_slice1 as detail
    LEFT JOIN deliveryorder_slice1 as dor on dor.ordercode = detail.deliverycode
    where dor.transportcert = #{cert}
    group by detail.itemcode
  </select>
</mapper>