insert into business_purchase_apply_detail
(id,operate,apply_order_id,b_id,res_id,quantity,remark,status_cd) values
(#{id},#{operate},#{applyOrderId},#{bId},#{resId},#{quantity},#{remark},#{statusCd})
select
t.operate,t.apply_order_id,t.apply_order_id applyOrderId,
t.b_id,t.b_id bId,t.res_id,t.res_id resId,t.id,t.price
from business_purchase_apply_detail t
where 1 = 1
and t.operate= #{operate}
and t.apply_order_id= #{applyOrderId}
and t.b_id= #{bId}
and t.res_id= #{resId}
insert into purchase_apply_detail(
apply_order_id,status_cd,id,b_id,res_id
) select t.apply_order_id,'0',t.id,t.b_id,t.res_id from business_purchase_apply_detail t where 1=1
and t.operate= 'ADD'
and t.apply_order_id= #{applyOrderId}
and t.id= #{id}
and t.b_id= #{bId}
and t.res_id= #{resId}
select
t.id,
t.apply_order_id applyOrderId,
t.status_cd statusCd,
t.b_id bId,
t.res_id resId,
t.rs_id rsId,
rs.res_name resName,
t.remark remark,
t.quantity quantity,
t.purchase_quantity purchaseQuantity,
t.purchase_remark purchaseRemark,
t.price,
pa.res_order_type resOrderType,
pa.user_id userId,
pa.user_name userName,
pa.description,
pa.state,
pa.end_user_name endUserName,
pa.end_user_tel endUserTel,
pa.warehousing_way warehousingWay,
pa.create_time createTime,
rsp.supplier_name supplierName,
td1.name resOrderTypeName,
td2.name stateName,
td3.name warehousingWayName,
rst.name rstName,
rst1.name parentRstName,
rss.spec_name specName,
rs.sh_id shId,
td4.name unitCodeName,
td5.name miniUnitCodeName,
sh.sh_name shName,
rs.is_fixed isFixed,
td6.name isFixedName
from purchase_apply_detail t
inner join purchase_apply pa on t.apply_order_id = pa.apply_order_id and pa.status_cd = '0'
left join resource_store rs on rs.res_id = t.res_id and rs.status_cd = '0'
left join t_dict td4 on rs.unit_code = td4.status_cd and td4.table_name = 'resource_store' and td4.table_columns = 'unit_code'
left join t_dict td5 on rs.mini_unit_code = td5.status_cd and td5.table_name = 'resource_store' and td5.table_columns = 'unit_code'
left join storehouse sh on rs.sh_id = sh.sh_id and sh.status_cd = '0'
left join resource_supplier rsp on rsp.rs_id = t.rs_id
left join t_dict td1 on pa.res_order_type = td1.status_cd and td1.table_name = 'purchase_apply' and
td1.table_columns = 'res_order_type'
left join t_dict td2 on pa.state = td2.status_cd and td2.table_name = 'purchase_apply' and td2.table_columns =
'state'
left join t_dict td3 on pa.warehousing_way = td3.status_cd and td3.table_name = 'purchase_apply' and
td3.table_columns = 'warehousing_way'
LEFT JOIN resource_store_type rst on rs.rst_id=rst.rst_id and rst.status_cd = '0'
LEFT JOIN resource_store_type rst1 on rs.parent_rst_id=rst1.rst_id and rst1.status_cd = '0'
LEFT JOIN resource_store_specification rss on rs.rss_id=rss.rss_id and rss.status_cd = '0'
left join t_dict td6 on rs.is_fixed = td6.status_cd and td6.table_name = 'resource_store' and td6.table_columns = 'is_fixed'
where 1 = 1
and t.apply_order_id like concat('%',#{applyOrderId},'%')
and rs.res_name like '%${resName}%'
and t.rs_id = #{rsId}
and t.remark= #{remark}
and t.quantity= #{quantity}
and t.purchase_quantity= #{purchaseQuantity}
and t.purchase_remark= #{purchaseRemark}
and t.price= #{price}
and pa.res_order_type= #{resOrderType}
and pa.create_user_id= #{createUserId}
and pa.user_name like '%${userName}%'
and pa.description= #{description}
and pa.state= #{state}
and pa.end_user_name like '%${endUserName}%'
and pa.end_user_tel= #{endUserTel}
and pa.warehousing_way= #{warehousingWay}
and t.status_cd= #{statusCd}
and t.id= #{id}
and t.b_id= #{bId}
and t.res_id= #{resId}
and pa.store_id= #{storeId}
and pa.community_id= #{communityId}
and rs.rss_id= #{rssId}
and rs.rst_id= #{rstId}
and rs.parent_rst_id= #{parentRstId}
and rsp.supplier_name= #{supplierName}
and pa.create_time >= #{startTime}
and pa.create_time <= #{endTime}
and rs.sh_id = #{shId}
order by pa.create_time desc
limit #{page}, #{row}
update purchase_apply_detail t
t.status_cd = #{statusCd},
t.b_id = #{newBId},
t.rs_id = #{rsId},
t.res_id= #{resId},
t.price= #{price},
t.purchase_quantity= #{purchaseQuantity},
t.purchase_remark= #{purchaseRemark},
where 1=1
and t.id= #{id}
and t.b_id= #{bId}
select count(1) count
from purchase_apply_detail t
inner join purchase_apply pa on t.apply_order_id = pa.apply_order_id and pa.status_cd = '0'
left join resource_store rs on rs.res_id = t.res_id and rs.status_cd = '0'
left join storehouse sh on rs.sh_id = sh.sh_id and sh.status_cd = '0'
left join resource_supplier rsp on rsp.rs_id = t.rs_id and rsp.status_cd = '0'
left join t_dict td1 on pa.res_order_type = td1.status_cd and td1.table_name = 'purchase_apply' and
td1.table_columns = 'res_order_type'
left join t_dict td2 on pa.state = td2.status_cd and td2.table_name = 'purchase_apply' and td2.table_columns =
'state'
left join t_dict td3 on pa.warehousing_way = td3.status_cd and td3.table_name = 'purchase_apply' and
td3.table_columns = 'warehousing_way'
LEFT JOIN resource_store_type rst on rs.rst_id=rst.rst_id and rst.status_cd = '0'
LEFT JOIN resource_store_type rst1 on rs.parent_rst_id=rst1.rst_id and rst1.status_cd = '0'
LEFT JOIN resource_store_specification rss on rs.rss_id=rss.rss_id and rss.status_cd = '0'
where 1 = 1
and t.apply_order_id like concat('%',#{applyOrderId},'%')
and rs.res_name like '%${resName}%'
and t.rs_id = #{rsId}
and t.remark= #{remark}
and t.quantity= #{quantity}
and t.purchase_quantity= #{purchaseQuantity}
and t.purchase_remark= #{purchaseRemark}
and t.price= #{price}
and pa.res_order_type= #{resOrderType}
and pa.create_user_id= #{createUserId}
and pa.user_name like '%${userName}%'
and pa.description= #{description}
and pa.state= #{state}
and pa.end_user_name like '%${endUserName}%'
and pa.end_user_tel= #{endUserTel}
and pa.warehousing_way= #{warehousingWay}
and rsp.supplier_name= #{supplierName}
and t.status_cd= #{statusCd}
and t.id= #{id}
and t.b_id= #{bId}
and t.res_id= #{resId}
and pa.store_id= #{storeId}
and pa.community_id= #{communityId}
and rs.rss_id= #{rssId}
and rs.rst_id= #{rstId}
and rs.parent_rst_id= #{parentRstId}
and pa.create_time >= #{startTime}
and pa.create_time <= #{endTime}
and rs.sh_id = #{shId}