李林
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
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
<?xml version="1.0" encoding="UTF-8"?>
 
<!--
  ~
  ~      Copyright (c) 2018-2025, ztt All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the pig4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: ztt
  ~
  -->
 
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
<mapper namespace="com.chinaztt.mes.plan.mapper.MpsRequirementsMapper">
 
    <resultMap id="mpsRequirementsMap" type="com.chinaztt.mes.plan.dto.MpsRequirementsDTO">
        <id property="id" column="id"/>
        <result property="indeRequNo" column="inde_requ_no"/>
        <result property="qtyRequired" column="qty_required"/>
        <result property="requiredDate" column="required_date"/>
        <result property="state" column="state"/>
        <result property="remark" column="remark"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="partDescription" column="part_description"/>
        <result property="remainderRequired" column="remainder_required"/>
        <result property="qtyPlaned" column="remainder_required"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createUser" column="create_user"/>
        <result property="updateUser" column="update_user"/>
        <result property="sourceType" column="source_type"/>
        <result property="customerOrderNo" column="customer_order_no"/>
        <result property="customerName" column="customer_name"/>
        <result property="unit" column="unit"/>
    </resultMap>
    <select id="getMpsRequirementsPage" resultMap="mpsRequirementsMap">
        select
        D.id,
        D.inde_requ_no,
        D.qty_required,
        D.required_date,
        D.state,
        D.remark,
        D.part_no,
        D.part_name,
        D.part_description,
        D.remainder_required,
        D.create_time,
        D.update_time,
        D.create_user,
        D.update_user,
        D.source_type,
        D.plan_required,
        D.part_id,
        D.unit,
        D.customer_order_no,
        D.customer_name
        from (
        select
        pir.*,
        bp.part_no,bp.description part_description,bp.part_name,
        pir.qty_required - pir.plan_required remainder_required,
        pco.customer_order_no,pco.customer_name,bp.unit
        from plan_mps_requirements pir
        left join basic_part bp on bp."id" = pir.part_id
        left join plan_join_order_requirements pjor on pjor.mps_requirements_id=pir."id"
        left join plan_customer_order pco on pco."id"=pjor.customer_order_id
        )D
        <where>
            <if test="ew.emptyOfWhere == false">
                and ${ew.sqlSegment}
            </if>
        </where>
    </select>
 
    <select id="selectDtoById" resultMap="mpsRequirementsMap">
        select
        pir.*,
        bp.part_no,bp.part_name
        from plan_mps_requirements pir
        left join basic_part bp on bp."id" = pir.part_id
        where pir.id = #{id}
    </select>
 
    <select id="getQtyRequiredSumById" resultType="java.math.BigDecimal">
        select coalesce(sum(pir.qty_required),0) qty_required_sum
        from plan_join_order_requirements pjor
        left join plan_mps_requirements pir on pir."id"=pjor.mps_requirements_id
        where pir."id"!=#{id} and exists(select 1 from plan_join_order_requirements pjor_a
        where pjor_a.mps_requirements_id=#{id} and pjor_a.customer_order_id=pjor.customer_order_id)
    </select>
 
    <select id="getOrderQuantityById" resultType="java.math.BigDecimal">
        select pco.buy_qty_due
        from plan_customer_order pco
        left join plan_join_order_requirements pjor on pjor.customer_order_id=pco."id"
        where pjor.mps_requirements_id=#{id}
    </select>
 
    <update id="updatePlanRequiredById">
        update plan_mps_requirements set plan_required=plan_required + #{param.qtyPlaned}
        where id=#{param.id}
    </update>
 
    <select id="selectScheduleByRequirementsId" resultType="java.lang.String">
        select pmps.mps_no
        from plan_master_production_schedule pmps
        left join plan_mps_source pms on pms.mps_id=pmps."id"
        where pms.mps_requ_id=#{id}
    </select>
</mapper>