yangys
2024-03-04 c51a042cfb8453265acf2b764b82bd17019b9b1b
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
<?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.qianwen.mdc.mapper.MachineAccountMapper">
  <resultMap id="BaseResultMap" type="com.qianwen.mdc.domain.MachineAccount">
  
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="machine_id" jdbcType="INTEGER" property="machineId" />
    <result column="machine_name" jdbcType="VARCHAR" property="machineName" />
    <result column="uuid" jdbcType="VARCHAR" property="uuid" />
    <result column="specification" jdbcType="VARCHAR" property="specification" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="device_type_id" jdbcType="INTEGER" property="deviceTypeId" />
    <result column="category" jdbcType="VARCHAR" property="category" />
    <result column="cnc_system" jdbcType="VARCHAR" property="cncSystem" />
    <result column="accounting_attribute" jdbcType="VARCHAR" property="accountingAttribute" />
    <result column="manage_type" jdbcType="VARCHAR" property="manageType" />
    <result column="location" jdbcType="VARCHAR" property="location" />
    <result column="department" jdbcType="INTEGER" property="department" />
    <result column="elec_comp_factor" jdbcType="INTEGER" property="elecCompFactor" />
    <result column="mech_comp_factor" jdbcType="INTEGER" property="mechCompFactor" />
    <result column="country" jdbcType="VARCHAR" property="country" />
    <result column="manufacturer" jdbcType="VARCHAR" property="manufacturer" />
    <result column="production_date" jdbcType="TIMESTAMP" property="productionDate" />
    <result column="original_value" jdbcType="REAL" property="originalValue" />
    <result column="present_value" jdbcType="REAL" property="presentValue" />
    <result column="weight" jdbcType="INTEGER" property="weight" />
    <result column="pic" jdbcType="VARCHAR" property="pic" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
  </resultMap>
 
  <select id="queryPage" parameterType="com.qianwen.mdc.dto.account.MachineAccountQueryDTO" resultType="com.qianwen.mdc.dto.account.MachineAccountDTO">
        select
            a.id,
            a.machine_id machineId,
            a.machine_name machineName,
            a.uuid,
            a.specification,
            a.type,
            a.device_type_id deviceTypeId,
            a.category,
            a.accounting_attribute accountingAttribute,
            a.location,
            a.department,
            ud.name as departmentName,
            a.elec_comp_factor elecCompFactor,
            a.mech_comp_factor mechCompFactor,
            a.country,
            a.manufacturer,
            a.production_date productionDate,
            a.original_value originalValue,
            a.present_value presentValue,
            a.weight,
            a.pic,
            a.remark,
            a.manage_type manageType,
            ms.status
        from machine_account a
        left join use_department ud on a.department=ud.id
        left join (select max(id) id,machine_id,status from machine_status group by machine_id,status) ms on a.machine_id=ms.machine_id
        <where>
         <if test="dto.uuid != null and dto.uuid != ''">
             <bind name="uuid" value="'%' + dto.uuid + '%'" />
            and a.uuid like #{uuid}
         </if>
         <if test="dto.type != null and dto.type != ''">
             <bind name="type" value="'%' + dto.type + '%'" />
            and a.type like #{type}
         </if>
         <if test="dto.specification != null and dto.specification != ''">
             <bind name="specification" value="'%' + dto.specification + '%'" />
            and a.specification like #{specification}
         </if>
         
         <if test="dto.productionDateBegin != null">
            and a.a.production_date &gt;= #{dto.productionDateBegin}
         </if>
         <if test="dto.productionDateEnd != null">
            and a.a.production_date &lt;= #{dto.productionDateEnd}
         </if>
         
         
         <if test="dto.manufacturer != null and dto.manufacturer != ''">
             <bind name="manufacturer" value="'%' + dto.manufacturer + '%'" />
            and a.manufacturer like #{manufacturer}
         </if>
         <if test="dto.country != null and dto.country != ''">
             <bind name="country" value="'%' + dto.country + '%'" />
            and a.country like #{country}
         </if>
         <if test="dto.remark != null and dto.remark != ''">
             <bind name="remark" value="'%' + dto.remark + '%'" />
            and a.remark like #{remark}
         </if>
         <if test="dto.category != null and dto.category != ''">
            and a.category = #{dto.category}
         </if>
         <if test="dto.department != null">
            and a.department = #{dto.department}
         </if>
        
         <if test="dto.accountingAttribute != null and dto.accountingAttribute != ''">
            and a.accounting_attribute = #{dto.accountingAttribute}
         </if>
         <if test="dto.manageType != null and dto.manageType != ''">
            and a.manage_type = #{dto.manageType}
         </if>
         <if test="dto.deviceTypeId != null">
            and a.device_type_id = #{dto.deviceTypeId}
         </if>
         
        </where>
    </select>
    
    <!-- 查询某个厂房id下的所有机床 -->
    <select id="queryRemainingAccount" resultType="com.qianwen.mdc.dto.account.MachineAccountDTO">
        select
            a.id,
            a.machine_name as machineName,
            a.machine_id machineId,
            a.uuid,            
            a.specification,
            a.type,
            a.category,
            a.accounting_attribute accountingAttribute,
            a.location,
            a.department,
            ud.name as departmentName,
            a.elec_comp_factor elecCompFactor,
            a.mech_comp_factor mechCompFactor,
            a.country,
            a.manufacturer,
            a.production_date productionDate,
            a.original_value originalValue,
            a.present_value presentValue,
            a.weight,
            a.pic,
            a.remark,
            a.manage_type manageType
        from machine_account a
        left join use_department ud on a.department=ud.id
        inner join machine m on a.machine_id=m.id
        where m.plant_id is null
    </select>
 
    <select id="selectSameTypes" parameterType="com.qianwen.mdc.domain.MachineAccount" resultType="String">
        select machine_name
        from mdc_machine_account
        where types_id = #{typesId} and machine_name != #{machineName}
    </select>
    
    
    <select id="lastByMachineId" resultType="com.qianwen.mdc.domain.MachineAccount">
        select
            a.machine_id machineId,
            a.uuid,
            a.id,
            a.specification,
            a.type,
            a.category,
            a.accounting_attribute accountingAttribute,
            a.location,
            a.department,
            a.elec_comp_factor elecCompFactor,
            a.mech_comp_factor mechCompFactor,
            a.country,
            a.manufacturer,
            a.production_date productionDate,
            a.original_value originalValue,
            a.present_value presentValue,
            a.weight,
            a.pic,
            a.remark,
            a.manage_type manageType
        from machine_account a
        where machine_id=#{machineId}
        limit 1
    </select>
</mapper>