@@ -144,6 +144,52 @@ delete from base_inventory_summary
GROUP BY type_id,size_id,bi.org_id_int,location_id,bi.price) as t
GROUP BY t.locationId,t.type_id,t.size_id,t.orgId,t.unitPrice
</insert>
<insertid="insertInventorySummary">
INSERT INTO base_inventory_summary (id,org_id_int,org_name,location_id,location_name,type_id, type_name,size_id,size_name,number,unit_price,price, stock_number, outbound_number,destruction_number,expire_number,location_type,create_time,update_time)
select
MAX(t.id) as id,t.orgId,t.orgName,t.locationId,MAX(t.locationName),t.type_id,t.typeName,t.size_id,t.sizeName,sum(t.number) as number,t.unitPrice,sum(t.price)as price,sum(t.stockNumber)as stockNumber,sum(t.outboundNumber)as outboundNumber,sum(t.destructionNumber)as destructionNumber,sum(t.destructionNumber) as expireNumber,t.location_type,NOW(),NOW()
FROM
(SELECT
UUID() as id,
bi.org_id_int as orgId,
po.org_name as orgName,
MAX(bi.location_id) as locationId,
MAX(bw.name) as locationName,
bi.type_id,
t.name as typeName,
bi.size_id,
s.name as sizeName,
count(*) as number,
Max(bi.price) as unitPrice,
sum(bi.price) as price,
SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) AS stockNumber,
count(*) - SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) AS outboundNumber,
sum(case when bi.state = 'destory' then 1 else 0 end) as destructionNumber,
sum(case when bi.warranty_period=0 then 0 when DATE_ADD(bi.production_date,INTERVAL bi.warranty_period MONTH) < NOW() then 1
else 0 end )as expireNumber,
bi.location_type
FROM base_inventory bi
join base_warehouse bw on bi.location_id = bw.id
join base_equipment_type t on t.id = bi.type_id
join base_equipment_size s on s.id = bi.size_id
join pub_org po on bi.org_id_int = po.org_id
WHERE location_type = 0
<iftest="req.orgId!=null and req.orgId !=''">
and bi.org_id_int =#{req.orgId}
</if>
<iftest="req.locationId!=null and req.locationId !=''">
and bi.location_id=#{req.locationId}
</if>
<iftest="req.sizeId != null and req.sizeId !=''">
and bi.size_id =#{req.sizeId}
</if>
<iftest="req.typeId != null and req.typeId !=''">
and bi.type_id =#{req.typeId}
</if>
GROUP BY type_id,size_id,bi.org_id_int,location_id,bi.price) as t
GROUP BY t.locationId,t.type_id,t.size_id,t.orgId,t.unitPrice