李林
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
<?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.production.mapper.HandymanTypeMapper">
 
    <resultMap id="dtoResultMap" type="com.chinaztt.mes.production.dto.HandymanTypeDTO">
        <id property="id" column="id"/>
        <result property="handymanNo" column="handyman_no"/>
        <result property="handymanName" column="handyman_name"/>
        <result property="conversionCoefficient" column="conversion_coefficient"/>
        <result property="standardHourWage" column="standard_hour_wage"/>
        <result property="discountFactor" column="discount_factor"/>
        <result property="comment" column="comment"/>
        <result property="wageType" column="wage_type"/>
        <result property="loadType" column="load_type"/>
        <result property="unit" column="unit"/>
        <result property="handymanTemplateId" column="handyman_template_id"/>
        <result property="partFamilyId" column="part_family_id"/>
        <result property="partFamilyNo" column="part_family_no"/>
    </resultMap>
    <resultMap id="optaskHandymanTypeMap" type="com.chinaztt.mes.production.entity.HandymanType">
        <id property="id" column="id"/>
        <result property="handymanNo" column="handyman_no"/>
        <result property="handymanName" column="handyman_name"/>
        <result property="conversionCoefficient" column="conversion_coefficient"/>
        <result property="standardHourWage" column="standard_hour_wage"/>
        <result property="discountFactor" column="discount_factor"/>
        <result property="comment" column="comment"/>
        <result property="wageType" column="wage_type"/>
        <result property="loadType" column="load_type"/>
        <result property="unit" column="unit"/>
        <result property="partFamilyId" column="part_family_id"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="workstationName" column="workstation_name"/>
    </resultMap>
    <select id="getHandymanType" resultMap="optaskHandymanTypeMap">
        SELECT A."id",
        A.handyman_no,
        A.handyman_name,
        A.conversion_coefficient,
        A."comment" ,
        A.unit
        FROM
        production_handyman_type
        A LEFT JOIN production_artificial_information_relation b ON b.production_handyman_id = A."id"
        WHERE
        b.production_handyman_join_id = #{id}
        <if test="ew.emptyOfWhere == false">
            and ${ew.SqlSegment}
        </if>
    </select>
    <select id="getHandyman" resultMap="optaskHandymanTypeMap">
        SELECT A
        ."id",
        A.handyman_no,
        A.handyman_name,
        A.conversion_coefficient,
        A."comment" ,
        A.unit
        FROM
        production_handyman_type A
        WHERE NOT EXISTS (SELECT b.production_handyman_join_id FROM production_artificial_information_relation b WHERE
        b.production_handyman_id = A."id"
        AND b.production_handyman_join_id = #{id})
        <if test="ew.emptyOfWhere == false">
            and ${ew.SqlSegment}
        </if>
    </select>
    <select id="fetchListByTemplateId" resultMap="dtoResultMap">
        select distinct * from (
        select pht.*,pjtt.handyman_template_id from production_handyman_type pht
        left join production_join_type_template pjtt on pjtt.handyman_type_id=pht."id"
        ) tempA
        where active=true
        <if test="ew.emptyOfWhere == false">
            and ${ew.SqlSegment}
        </if>
    </select>
    <select id="fetchListFilterTemplateId" resultMap="dtoResultMap">
        select pht.* from production_handyman_type pht
        where not exists(select 1 from production_join_type_template pjtt
        where pjtt.handyman_type_id=pht."id" and pjtt.handyman_template_id=#{handymanTemplateId})
        and active=true
        <if test="ew.emptyOfWhere == false">
            and ${ew.SqlSegment}
        </if>
    </select>
    <select id="getHandymanTypeById" resultMap="dtoResultMap">
        SELECT
            A.*,
            B.part_family_no
        FROM
            production_handyman_type A
                LEFT JOIN basic_part_family B ON B."id" = A.part_family_id
        WHERE
            A."id" = #{id}
    </select>
 
    <select id="getHandymanTypeByDutyRecordId" resultMap="dtoResultMap">
        SELECT *
        FROM production_handyman_type pht
        WHERE exists(SELECT 1
                     FROM production_artificial_information pai
                     WHERE pai.duty_record_id in
                    <foreach collection="dutyRecordIdList" item="dutyRecordId" index="index" open="(" close=")" separator=",">
                    #{dutyRecordId}
                    </foreach>
                    AND pht."id" = pai.handyman_type_id)
        ORDER BY pht."id"
    </select>
    <select id="selectByWorkstationIdAndPartId" resultMap="optaskHandymanTypeMap">
        SELECT phty.*
        FROM basic_workstation bw
                 LEFT JOIN basic_join_workstation_template bjwt ON bjwt.workstation_id = bw."id"
                 LEFT JOIN production_handyman_template pht ON pht."id" = bjwt.handyman_template_id
                 LEFT JOIN production_join_type_template pjtt ON pjtt.handyman_template_id = pht."id"
                 LEFT JOIN production_handyman_type phty ON phty."id" = pjtt.handyman_type_id
                 LEFT JOIN basic_part_family bpf ON phty.part_family_id = bpf."id" AND bpf.active = TRUE
        WHERE bw."id" = #{workstationId}
          AND exists(SELECT 1 FROM basic_part bp WHERE bp."id" = #{partId} AND bp.part_family_id = bpf."id")
        LIMIT 1
    </select>
</mapper>