李林
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?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.production.mapper.SegmentationTaskRecordMapper">
    <resultMap id="segmentationTaskRecordMap" type="com.chinaztt.mes.production.entity.SegmentationTaskRecord">
        <id property="id" column="id"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="partBatchNo" column="part_batch_no"/>
        <result property="partId" column="part_id"/>
        <result property="ifsBatchNo" column="ifs_batch_no"/>
        <result property="createTime" column="create_time"/>
        <result property="createUser" column="create_user"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateUser" column="update_user"/>
        <result property="reelNumber" column="reel_number"/>
        <result property="productQty" column="product_qty"/>
        <result property="segmentDesc" column="segment_desc"/>
        <result property="remark" column="remark"/>
        <result property="taskId" column="task_id"/>
        <result property="status" column="status"/>
        <result property="locationId" column="location_id"/>
    </resultMap>
 
    <resultMap id="segmentationTaskRecordDto" type="com.chinaztt.mes.production.dto.SegmentationTaskRecordDTO">
        <id property="id" column="id"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="partBatchNo" column="part_batch_no"/>
        <result property="partId" column="part_id"/>
        <result property="ifsBatchNo" column="ifs_batch_no"/>
        <result property="createTime" column="create_time"/>
        <result property="createUser" column="create_user"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateUser" column="update_user"/>
        <result property="reelNumber" column="reel_number"/>
        <result property="productQty" column="product_qty"/>
        <result property="segmentDesc" column="segment_desc"/>
        <result property="remark" column="remark"/>
        <result property="taskId" column="task_id"/>
        <result property="taskType" column="task_type"/>
        <result property="status" column="status"/>
        <result property="productionUser" column="production_user"/>
        <result property="unit" column="unit"/>
        <result property="dutyRecordId" column="duty_record_id"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="taskNo" column="task_no"/>
        <result property="locationId" column="location_id"/>
        <result property="cusMaterialCode" column="cus_material_code"/>
    </resultMap>
 
    <select id="getPage" resultMap="segmentationTaskRecordDto">
        SELECT * FROM (
            SELECT
                pstr.*,
                pst.no task_no,
                pst.task_type,
                pst.production_user,
                pst.unit,
                pst.duty_record_id,
                pst.workstation_id
            FROM
                production_segmentation_task_record pstr
            LEFT JOIN production_segmentation_task pst ON pstr.task_id = pst.id
 
            <where>
                <if test="dto.startTime != null and dto.endTime != ''">
                    AND to_char( pstr.create_time, 'YYYYMMDD' ) between #{dto.startTime} and #{dto.endTime}
                </if>
            </where>
            ORDER BY
            pstr.id DESC
        ) temp
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <select id="batchLabelPrint" resultMap="segmentationTaskRecordDto">
        SELECT
            pstr.part_no,
            pstr.part_name,
            pstr.part_batch_no,
            pstr.ifs_batch_no,
            pstr.product_qty,
            pstr.create_time,
            pstr.segment_desc,
            pst.unit,
            bcprm.cus_material_code
        FROM
            production_segmentation_task_record pstr
            LEFT JOIN basic_customer_part_relation_map bcprm on bcprm.part_no = pstr.part_no
            LEFT JOIN production_segmentation_task pst ON pstr.task_id = pst.id
        WHERE
        pstr.id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="getListByIds" resultMap="segmentationTaskRecordDto">
        SELECT
            pstr.*,
            pst.task_type
        FROM
            production_segmentation_task_record pstr
            LEFT JOIN production_segmentation_task pst ON pstr.task_id = pst.id
        WHERE
        pstr.id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="getOutputListByDutyRecordId" resultType="com.chinaztt.mes.production.dto.ProductOutputDTO">
        SELECT DISTINCT
            ws.system_no,
            ws.part_batch_no out_batch_no,
            pstr.product_qty,
            bp.unit,
            bp.sunit,
            bp.part_no,
            bp.specs,
            pst."no" optask_no,
            ws.reel_number,
            puw.unit_work_factor,
            pdr.duty_no,
            pdr.now_duty_date,
            bst.NAME AS shift_name,
            round( pstr.product_qty * puw.unit_work_factor * 88, 2 ) AS qty_salary
        FROM
            production_segmentation_task pst
                LEFT JOIN production_segmentation_task_record pstr ON pst."id" = pstr.task_id
                LEFT JOIN warehouse_stock ws ON ws.part_id = pstr.part_id AND ws.location_id = pstr.location_id AND pstr.part_batch_no = ws.part_batch_no
                LEFT JOIN basic_part bp ON bp."id" = ws.part_id
                LEFT JOIN production_unit_work puw ON puw.part_id = ws.part_id
                AND puw.workstation_id = pst.workstation_id AND puw.operation_id IS NULL
                LEFT JOIN production_duty_record pdr ON pdr."id" = pst.duty_record_id
                LEFT JOIN basic_shift bst ON bst.ID = pdr.shift_id
        WHERE
            pst.duty_record_id IN
            <foreach collection="idList" item="dutyRecordId" index="index" open="(" close=")" separator=",">
                #{dutyRecordId}
            </foreach>
    </select>
 
    <select id="getStaffProductionWage" resultType="com.chinaztt.mes.production.dto.ProductOutputDTO">
        SELECT
            DISTINCT
            pstr."id",
            bs."id" staff_id,
            TRUE artificial_type,
            ws.part_id,
            ws.system_no,
            ws.part_batch_no out_batch_no,
            pstr.product_qty,
            bp.unit,
            bp.sunit,
            bp.part_no,
            bp.specs,
            bp.part_name,
            pst."no" optask_no,
            ws.reel_number,
            puw.unit_work_factor,
            bw."id" workstation_id,
            bw."name" workstation_name,
            round( pstr.product_qty * puw.unit_work_factor * 88, 2 ) AS qty_salary
        FROM
            production_segmentation_task pst
            LEFT JOIN production_segmentation_task_record pstr ON pst."id" = pstr.task_id
            LEFT JOIN warehouse_stock ws ON ws.part_id = pstr.part_id AND ws.location_id = pstr.location_id AND pstr.part_batch_no = ws.part_batch_no
            LEFT JOIN basic_part bp ON bp."id" = ws.part_id
            LEFT JOIN production_unit_work puw ON puw.part_id = ws.part_id
            AND puw.workstation_id = pst.workstation_id AND puw.operation_id IS NULL
            LEFT JOIN production_duty_record pdr ON pdr."id" = pst.duty_record_id
            LEFT JOIN basic_shift bst ON bst.ID = pdr.shift_id
            LEFT JOIN basic_staff bs ON bs.staff_no = pstr.create_user
            LEFT JOIN basic_workstation bw ON bw."id" = pst.workstation_id
        WHERE
            pst.duty_record_id = #{dutyRecordId}
    </select>
</mapper>