p.apply_user, p.apply_time,p.del_flag,p.remark,file.url as photo_url
from purchase_quote as p
left join (
select
att.rel_id
,file.url
,min(file.create_time) as create_time
from sys_attach as att
left join sys_attach_file as file
on att.id = file.attach_id
where att.source_type = 'purchaseQuote' and att.source_sub_type = 'photo'
group by att.rel_id
)file
on p.purchase_quote_id = file.rel_id
<where>
and p.del_flag = '0'
<iftest="purchaseQuoteCode != null and purchaseQuoteCode != ''"> and p.purchase_quote_code = #{purchaseQuoteCode}</if>
<iftest="purchaseBuyer != null and purchaseBuyer != ''"> and p.purchaseBuyer = #{purchaseBuyer}</if>
<iftest="supplierQuoteCode != null and supplierQuoteCode != ''"> and p.supplier_quote_code = #{supplierQuoteCode}</if>
<iftest="supplierName != null and supplierName != ''"> and p.supplier_name like concat('%', #{supplierName}, '%')</if>
<iftest="materialAmount != null and materialAmount != ''"> and p.material_amount = #{materialAmount}</if>
<iftest="params.beginPricingDate != null and params.beginPricingDate != '' and params.endPricingDate != null and params.endPricingDate != ''"> and p.pricingDate between #{params.beginPricingDate} and #{params.endPricingDate}</if>
<iftest="materialNo != null and materialNo != ''"> and p.material_no = #{materialNo}</if>
<iftest="materialName != null and materialName != ''"> and p.material_name like concat('%', #{materialName}, '%')</if>
<iftest="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and p.create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<iftest="auditStatus != null and auditStatus != ''"> and p.audit_status = #{auditStatus}</if>
<iftest="useStatus != null and useStatus != ''"> and p.use_status = #{useStatus}</if>
<iftest="instanceId != null and instanceId != ''"> and p.instance_id = #{instanceId}</if>
<iftest="instanceType != null and instanceType != ''"> and p.instance_type = #{instanceType}</if>
<iftest="submitInstanceId != null and submitInstanceId != ''"> and p.submit_instance_id = #{submitInstanceId}</if>
<iftest="cancelInstanceId != null and cancelInstanceId != ''"> and p.cancel_instance_id = #{cancelInstanceId}</if>
<iftest="restoreInstanceId != null and restoreInstanceId != ''"> and p.restore_instance_id = #{restoreInstanceId}</if>
<iftest="applyTitle != null and applyTitle != ''"> and p.apply_title = #{applyTitle}</if>
<iftest="applyUser != null and applyUser != ''"> and p.apply_user = #{applyUser}</if>
<iftest="applyTime != null "> and p.apply_time = #{applyTime}</if>
<iftest="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''">
and p.create_time between #{params.beginCreateTime} and #{params.endCreateTime}
</if>
<iftest="keyword != null and keyword != ''"> and p.purchase_quote_code like concat('%',#{keyword},'%')</if>