李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
<?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.chinaztt.mes.warehouse.mapper.EscortMapper">
 
    <resultMap id="escortDtoMap" type="com.chinaztt.mes.warehouse.dto.EscortDTO">
        <id property="id" column="id"/>
        <result property="escortNo" column="escort_no"/>
        <result property="orderNo" column="order_no"/>
        <result property="requestDate" column="request_date"/>
        <result property="customerOrderNo" column="customer_order_no"/>
        <result property="entityName" column="entity_name"/>
        <result property="customerName" column="customer_name"/>
        <result property="customerNo" column="customer_no"/>
        <result property="address" column="address"/>
        <result property="receiver" column="receiver"/>
        <result property="phone" column="phone"/>
        <result property="deliveryDate" column="delivery_date"/>
        <result property="carrier" column="carrier"/>
        <result property="salesman" column="salesman"/>
        <result property="salesmanWorkCode" column="salesman_work_code"/>
        <result property="remark" column="remark"/>
        <result property="status" column="status"/>
        <result property="escortAutoId" column="escort_auto_id"/>
    </resultMap>
 
    <select id="getEscortInfoByOrder" resultMap="escortDtoMap">
        select pco.wanted_delivery_date                                       request_date,
               pco.customer_order_no,
               pco.customer_name,
               max(case when pop.item = '订单号' then pcop."value" else '' end)  order_no,
               max(case when pop.item = '工程名称' then pcop."value" else '' end) entity_name,
               max(case when pop.item = '交货地址' then pcop."value" else '' end) address,
               max(case when pop.item = '联系人' then pcop."value" else '' end)  receiver,
               max(case when pop.item = '联系电话' then pcop."value" else '' end) phone,
               max(case when pop.item = '业务员' then pcop."value" else '' end)  salesman
        from plan_customer_order pco
                 left join plan_customer_order_param pcop on pcop.order_id = pco."id"
                 left join plan_order_param pop on pop."id" = pcop.order_param_id
        where pco."id" in
        <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
        group by pco.wanted_delivery_date,pco.customer_order_no,pco.customer_name
    </select>
 
    <update id="updateStockOrderById">
        update warehouse_join_stock_order wjso set delivery_quantity = wjso.delivery_quantity ${plusOrMinus} wed.delivery_qty
        from warehouse_escort_detail wed
        left join warehouse_escort we on wed.escort_id=we."id"
        where wjso."id"=wed.stock_order_id and wed.active=true and we."id"=#{id}
    </update>
 
    <update id="updateCustomerOrderById">
        update plan_customer_order pco
        set delivery_quantity=tempA.delivery_quantity
        from (select wjso.customer_order_id,sum(wjso.delivery_quantity) delivery_quantity
              from warehouse_escort we
                       left join warehouse_escort_detail wed on wed.escort_id = we."id"
                       left join warehouse_join_stock_order wjso on wjso."id" = wed.stock_order_id
              where we."id" = #{id}
                and wed.active = true
              group by wjso.customer_order_id) tempA
        where pco."id" = tempA.customer_order_id
    </update>
 
    <select id="selectCustomerOrder" resultType="java.lang.Long">
        SELECT auto_id
        FROM plan_customer_order
        WHERE "id" = #{id}
    </select>
</mapper>