李林
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
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
<?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.technology.mapper.DocumentMapper">
 
    <resultMap id="documentMap" type="com.chinaztt.mes.technology.entity.Document">
        <id property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="number" column="number"/>
        <result property="projectNo" column="project_no"/>
        <result property="country" column="country"/>
        <result property="remark" column="remark"/>
        <result property="state" column="state"/>
        <result property="version" column="version"/>
        <result property="oaWorkflowId" column="oa_workflow_id"/>
        <result property="createTime" column="create_time"/>
        <result property="createUser" column="create_user"/>
        <result property="jgt" column="jgt"/>
        <result property="lct" column="lct"/>
        <result property="lctRemark" column="lct_remark"/>
        <result property="lctJson" column="lct_json"/>
        <result property="lctBase64" column="lct_base64"/>
        <result property="projectType" column="project_type"/>
        <result property="partId" column="part_id"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="insulationColor" column="insulation_color"/>
        <result property="sheathColor" column="sheath_color"/>
        <result property="testStandard" column="test_standard"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateUser" column="update_user"/>
        <result property="updateRealTime" column="update_real_time"/>
        <result property="updateRealUser" column="update_real_user"/>
    </resultMap>
 
    <resultMap id="documentMaterialCostMap" type="com.chinaztt.mes.technology.dto.DocumentMaterialCostDTO">
        <id property="documentId" column="document_id"/>
        <result property="bomId" column="bom_id"/>
        <result property="partId" column="part_id"/>
        <result property="quantity" column="quantity"/>
        <result property="unit" column="unit"/>
        <result property="finishedProduct" column="finished_product"/>
        <result property="bomNumber" column="bom_number"/>
        <result property="partName" column="part_name"/>
    </resultMap>
 
    <resultMap id="bomRoutingMap" type="com.chinaztt.mes.technology.dto.JoinDocumentBomRoutingDTO">
        <result property="documentId" column="document_id"/>
        <result property="bomId" column="bom_id"/>
        <result property="routingId" column="routing_id"/>
        <result property="bomNumber" column="bom_number"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="routingNo" column="routing_no"/>
        <result property="partId" column="part_id"/>
        <result property="routingVersion" column="routing_version"/>
        <result property="routingAlternativeNo" column="routing_alternative_no"/>
        <result property="routingAlternativeDesc" column="routing_alternative_desc"/>
    </resultMap>
 
    <sql id="routingJoinBomSql">
        SELECT
            A.*,
            b."number"         bom_number,
            b.version          bom_version,
            b.alternative_no   bom_alternative_no,
            b.alternative_desc bom_alternative_desc,
            r.routing_no,
            r.version          routing_version,
            r.alternative_no   routing_alternative_no,
            r.alternative_desc routing_alternative_desc,
            P.part_name,
            P.part_no
        FROM
            technology_join_document_bom_routing A
                LEFT JOIN technology_bom b ON b.ID = A.bom_id
                LEFT JOIN technology_routing r ON r.ID = A.routing_id
                LEFT JOIN basic_part P ON a.part_id = P.ID
    </sql>
 
    <select id="getBomRoutingDtoByDocId" resultMap="bomRoutingMap">
        select * from (<include refid="routingJoinBomSql"/>) aa
        WHERE
        aa.document_id = #{documentId}
        and aa.routing_id is not null
    </select>
 
    <select id="getRootBomRoutingDtoPartByDocId" resultMap="bomRoutingMap">
        select * from (<include refid="routingJoinBomSql"/>) aa
        WHERE
        aa.document_id = #{documentId} and aa.parent_id Is NULL
    </select>
 
 
    <select id="getBomRoutingDtoPartByDocId" resultMap="bomRoutingMap">
        select * from (<include refid="routingJoinBomSql"/>) aa
        WHERE
        aa.document_id = #{documentId}
        ORDER BY aa.ID ASC
    </select>
 
    <select id="exportList" resultType="com.chinaztt.mes.technology.excel.MaterialCostData">
        SELECT
            A.*,
            b.part_no   "partNo",
            b.part_name "partName",
            b.specs,
            b.description
        FROM
            technology_document_material_cost A,
            basic_part b
        WHERE
            A.bom_id = #{bomId}
          and A.document_id = #{documentId}
          AND A.part_id = b.ID
    </select>
 
    <select id="getMaterialCostByDocId" resultMap="documentMaterialCostMap">
        SELECT
            A.*,
            p1.part_name finished_product,
            p2.part_name,
            p2.unit,
            b."number"   bom_number,
            opt.name     operation_name
        FROM
            technology_document_material_cost A
                LEFT JOIN technology_bom b ON A.bom_id = b.ID
                LEFT JOIN basic_part p1 ON b.part_id = p1.ID
                LEFT JOIN basic_part p2 ON A.part_id = p2.ID
                LEFT JOIN technology_operation opt ON A.operation_id = opt.ID
        WHERE
            A.document_id = #{documentId}
        ORDER BY A.INDEX,p2.part_name
    </select>
 
 
</mapper>