Showing
1 changed file
with
31 additions
and
13 deletions
| ... | ... | @@ -234,21 +234,39 @@ |
| 234 | 234 | </select> |
| 235 | 235 | |
| 236 | 236 | <select id="getCustomerSpecificQualityRequirements" resultMap="ContractDistributorStandard"> |
| 237 | - WITH LatestContracts AS (SELECT cdl.product_id, | |
| 238 | - cdl.contract_id, | |
| 239 | - cds.*, | |
| 240 | - ROW_NUMBER() OVER (PARTITION BY cdl.product_id ORDER BY cds.create_time DESC, cds.id DESC) as rn | |
| 241 | - FROM tbl_contract_distributor_line cdl | |
| 242 | - INNER JOIN tbl_contract_distributor_standard cds ON cdl.contract_id = cds.id | |
| 243 | - WHERE cds.STATUS != 'DELETED' | |
| 244 | - and cds.buyer = #{customerId} | |
| 245 | - and cdl.product_id IN | |
| 246 | - <foreach collection="productIdList" open="(" separator="," close=")" item="item"> | |
| 247 | - #{item} | |
| 248 | - </foreach> | |
| 237 | + WITH ContractLines AS ( | |
| 238 | + SELECT | |
| 239 | + cdl.product_id, | |
| 240 | + cds.* | |
| 241 | + FROM tbl_contract_distributor_standard cds | |
| 242 | + INNER JOIN tbl_contract_distributor_line cdl ON cds.id = cdl.contract_id | |
| 243 | + WHERE cds.STATUS != 'DELETED' | |
| 244 | + AND cds.buyer = #{customerId} | |
| 245 | + AND cdl.product_id IN | |
| 246 | + <foreach collection="productIdList" open="(" separator="," close=")" item="item"> | |
| 247 | + #{item} | |
| 248 | + </foreach> | |
| 249 | + UNION ALL | |
| 250 | + SELECT | |
| 251 | + cspl.product_id, | |
| 252 | + cds.* | |
| 253 | + FROM tbl_contract_distributor_standard cds | |
| 254 | + INNER JOIN tbl_contract_std_processing_line cspl ON cds.id = cspl.contract_id | |
| 255 | + WHERE cds.STATUS != 'DELETED' | |
| 256 | + AND cds.buyer = #{customerId} | |
| 257 | + AND cspl.product_id IN | |
| 258 | + <foreach collection="productIdList" open="(" separator="," close=")" item="item"> | |
| 259 | + #{item} | |
| 260 | + </foreach> | |
| 261 | + ), | |
| 262 | + RankedContracts AS ( | |
| 263 | + SELECT | |
| 264 | + cl.*, | |
| 265 | + ROW_NUMBER() OVER (PARTITION BY cl.product_id ORDER BY cl.create_time DESC, cl.id DESC) as rn | |
| 266 | + FROM ContractLines cl | |
| 249 | 267 | ) |
| 250 | 268 | SELECT * |
| 251 | - FROM LatestContracts | |
| 269 | + FROM RankedContracts | |
| 252 | 270 | WHERE rn = 1 |
| 253 | 271 | ORDER BY create_time; |
| 254 | 272 | </select> | ... | ... |