李林
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
<?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.aps.mapper.ResourceMapper">
 
    <resultMap id="resourceMap" type="com.chinaztt.mes.aps.entity.Resource">
        <id property="id" column="id"/>
        <result property="resourceNo" column="resource_no"/>
        <result property="resourceName" column="resource_name"/>
        <result property="remark" column="remark"/>
        <result property="workstationId" column="workstation_id"/>
    </resultMap>
 
    <resultMap id="resourceBoMap" type="com.chinaztt.mes.aps.core.domain.ResourceBo">
        <id property="id" column="id"/>
        <result property="name" column="resource_name"/>
        <result property="no" column="resource_no"/>
        <result property="maxEndTime" column="maxEndTime"/>
    </resultMap>
 
    <resultMap id="resourceMapDTO" type="com.chinaztt.mes.aps.dto.ResourceDTO">
        <id property="id" column="id"/>
        <result property="resourceNo" column="resource_no"/>
        <result property="resourceName" column="resource_name"/>
        <result property="remark" column="remark"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="rscGroupName" column="rsc_group_name"/>
    </resultMap>
    <select id="getAllWithMaxTime" resultMap="resourceBoMap">
        SELECT
            r.*,
            GREATEST(A."maxTime", b."maxTime") "maxTime"
        FROM
            aps_resource r
                LEFT JOIN (SELECT
                               MAX(CASE
                                       WHEN T.actual_finish_date IS NULL THEN T.planned_finish_date
                                       ELSE T.actual_finish_date END) "maxTime",
                               T.resource_id
                           FROM
                               production_operation_task T
                           GROUP BY
                               T.resource_id) A ON r.ID = A.resource_id
                LEFT JOIN (SELECT
                               MAX(A.end_time) "maxTime",
                               A.resource_id
                           FROM aps_scene_task A
                           WHERE A.scene_id = #{sceneId}
                           GROUP BY A.resource_id) b ON b.resource_id = r.ID
    </select>
 
    <select id="getList" resultMap="resourceMap">
        SELECT
            aps_resource."id",
            aps_resource.resource_no,
            aps_resource.resource_name,
            aps_resource.remark,
            aps_resource.workstation_id
        FROM
            aps_resource
        WHERE aps_resource."id" in (
            SELECT
                aps_resource_connector.to_resource_id
            FROM aps_resource_connector
            WHERE aps_resource_connector.from_resource_id = #{param4})
   </select>
    <select id="fetch" resultMap="resourceMap">
        SELECT
            "public".aps_resource."id",
            "public".aps_resource.resource_no,
            "public".aps_resource.resource_name,
            "public".aps_resource.remark,
            "public".aps_resource.workstation_id
        FROM
            "public".aps_resource
        WHERE aps_resource."id" NOT in (SELECT
                                            aps_resource_connector.to_resource_id
                                        FROM
                                            "public".aps_resource_connector
                                        WHERE
                                            "public".aps_resource_connector.from_resource_id = #{param4})
   </select>
    <select id="getResourcePage" resultMap="resourceMap">
        SELECT
            ajrg."id",
            aps.resource_no,
            aps.resource_name,
            aps.workstation_id
        FROM
            aps_resource aps
                LEFT JOIN aps_join_res_group ajrg on ajrg.resource_id = aps."id"
                LEFT JOIN aps_resource_group asg on ajrg.rsc_group_id = asg."id"
        WHERE asg."id" = #{id}
        <if test="ew.emptyOfWhere == false">
            and    ${ew.SqlSegment}
        </if>
    </select>
    <select id="getNoRepetitive" resultMap="resourceMap">
        SELECT
            aps_resource."id",
            aps_resource.resource_no,
            aps_resource.resource_name,
            aps_resource.workstation_id
        FROM
            aps_resource
        WHERE aps_resource."id" NOT in (SELECT
                                            aps_resource."id"
                                        FROM
                                            aps_resource,
                                            aps_resource_group,
                                            aps_join_res_group
                                        WHERE
                                            aps_resource_group."id" = aps_join_res_group.rsc_group_id
                                          AND
                                            aps_join_res_group.resource_id = aps_resource."id"
                                          AND aps_resource_group."id" = #{param4})
    </select>
    <select id="query" resultMap="resourceMap">
        <bind name="searchKey" value="'%' + keyword + '%'"/>
        select * from aps_resource a where a.resource_no like #{searchKey} or a.resource_name like #{searchKey} order by
        id limit 100
    </select>
    <update id="updateNoById">
        UPDATE aps_resource
        SET resource_no= NULL,
            workstation_id=0
        WHERE aps_resource."id" = #{id}
    </update>
    <select id="selectDtoById" resultType="com.chinaztt.mes.aps.dto.ResourceDTO">
        select *
        from aps_resource
        where id = #{id}
    </select>
    <select id="getAllResourcePage" resultMap="resourceMapDTO">
        SELECT
            ajrg."id",
            aps.resource_no,
            aps.resource_name,
            aps.workstation_id,
            asg.rsc_group_name
        FROM
            aps_join_res_group ajrg
                LEFT JOIN aps_resource_group asg on ajrg.rsc_group_id = asg."id"
                LEFT JOIN aps_resource aps on aps."id" = ajrg.resource_id
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
</mapper>