| | |
| | | id, investment_task, investment_task_finish, investment_task_rating, create_time, create_by, update_time, update_by, disabled, storage_task, storage_task_finish, storage_task_rating |
| | | </sql> |
| | | |
| | | <!-- 存量项目情况分页列表(按年度分组) --> |
| | | <!-- <select id="selectStoragePageList" resultType="com.ruoyi.system.vo.InventoryStorageListVO">--> |
| | | <!-- SELECT --> |
| | | <!-- YEAR(ps.in_time) AS year,--> |
| | | <!-- COUNT(ps.id) AS storageCount,--> |
| | | <!-- COALESCE(SUM(ps.total_amount), 0) AS totalAmount,--> |
| | | <!-- COALESCE(SUM(ps.total_amount) - COALESCE(SUM(all_items.amount), 0), SUM(ps.total_amount)) AS remainingAmount,--> |
| | | <!-- COALESCE(SUM(year_items.amount), 0) AS yearAmount,--> |
| | | <!-- COALESCE(SUM(all_items.amount), 0) AS allAmount--> |
| | | <!-- FROM project_storage ps--> |
| | | <!-- LEFT JOIN (--> |
| | | <!-- SELECT --> |
| | | <!-- project_storage_id,--> |
| | | <!-- SUM(amount) AS amount--> |
| | | <!-- FROM project_storage_item --> |
| | | <!-- WHERE disabled = 0--> |
| | | <!-- GROUP BY project_storage_id--> |
| | | <!-- ) all_items ON ps.id = all_items.project_storage_id--> |
| | | <!-- LEFT JOIN (--> |
| | | <!-- SELECT --> |
| | | <!-- project_storage_id,--> |
| | | <!-- SUM(amount) AS amount--> |
| | | <!-- FROM project_storage_item --> |
| | | <!-- WHERE disabled = 0 --> |
| | | <!-- AND YEAR(STR_TO_DATE(CONCAT(month, '-01'), '%Y-%m-%d')) = YEAR(CURDATE())--> |
| | | <!-- GROUP BY project_storage_id--> |
| | | <!-- ) year_items ON ps.id = year_items.project_storage_id--> |
| | | <!-- WHERE ps.disabled = 0 --> |
| | | <!-- AND ps.status = 1--> |
| | | <!-- AND ps.in_time IS NOT NULL--> |
| | | <!-- GROUP BY YEAR(ps.in_time)--> |
| | | <!-- ORDER BY YEAR(ps.in_time) DESC--> |
| | | <!-- </select>--> |
| | | <select id="selectStoragePageList" resultType="com.ruoyi.system.vo.InventoryStorageListVO"> |
| | | SELECT |
| | | ps_year.year, |
| | | COUNT(ps_year.id) AS storageCount, |
| | | COALESCE(SUM(ps_year.total_amount), 0) AS totalAmount, |
| | | COALESCE(SUM(ps_year.total_amount) - COALESCE(SUM(all_items.amount), 0), SUM(ps_year.total_amount)) AS remainingAmount, |
| | | COALESCE(SUM(year_items.year_amount), 0) AS yearAmount, |
| | | COALESCE(SUM(all_items.amount), 0) AS allAmount |
| | | FROM ( |
| | | SELECT |
| | | id, |
| | | total_amount, |
| | | YEAR(in_time) as year |
| | | FROM project_storage |
| | | WHERE disabled = 0 |
| | | AND status = 1 |
| | | AND in_time IS NOT NULL |
| | | ) ps_year |
| | | LEFT JOIN ( |
| | | SELECT |
| | | project_storage_id, |
| | | SUM(amount) AS amount |
| | | FROM project_storage_item |
| | | WHERE disabled = 0 |
| | | GROUP BY project_storage_id |
| | | ) all_items ON ps_year.id = all_items.project_storage_id |
| | | LEFT JOIN ( |
| | | SELECT |
| | | psi.project_storage_id, |
| | | YEAR(STR_TO_DATE(CONCAT(psi.month, '-01'), '%Y-%m-%d')) as item_year, |
| | | SUM(psi.amount) AS year_amount |
| | | FROM project_storage_item psi |
| | | WHERE psi.disabled = 0 |
| | | GROUP BY psi.project_storage_id, YEAR(STR_TO_DATE(CONCAT(psi.month, '-01'), '%Y-%m-%d')) |
| | | ) year_items ON ps_year.id = year_items.project_storage_id AND ps_year.year = year_items.item_year |
| | | GROUP BY ps_year.year |
| | | ORDER BY ps_year.year DESC |
| | | </select> |
| | | <select id="inStoragePageList" resultType="com.ruoyi.system.vo.InStorageListVO"> |
| | | SELECT |
| | | DATE_FORMAT(ps.in_time, '%Y-%m') AS year, |
| | | COUNT(ps.id) AS storageCount, |
| | | COALESCE(SUM(ps.total_amount), 0) AS totalAmount |
| | | FROM project_storage ps |
| | | WHERE ps.disabled = 0 |
| | | AND ps.status = 1 |
| | | AND ps.in_time IS NOT NULL |
| | | GROUP BY DATE_FORMAT(ps.in_time, '%Y-%m') |
| | | ORDER BY DATE_FORMAT(ps.in_time, '%Y-%m') DESC |
| | | </select> |
| | | <select id="outStoragePageList" resultType="com.ruoyi.system.vo.OutStorageListVO"> |
| | | SELECT |
| | | DATE_FORMAT(ps.in_time, '%Y-%m') AS year, |
| | | COUNT(ps.id) AS storageCount, |
| | | COALESCE(SUM(ps.total_amount), 0) AS totalAmount |
| | | FROM project_storage ps |
| | | WHERE ps.disabled = 0 |
| | | AND ps.status = 2 |
| | | AND ps.in_time IS NOT NULL |
| | | GROUP BY DATE_FORMAT(ps.in_time, '%Y-%m') |
| | | ORDER BY DATE_FORMAT(ps.in_time, '%Y-%m') DESC |
| | | </select> |
| | | <select id="monthStoragePageList" resultType="com.ruoyi.system.vo.MonthStorageListVO"> |
| | | SELECT |
| | | DATE_FORMAT(ps.in_time, '%Y-%m') AS year, |
| | | COUNT(ps.id) AS storageCount, |
| | | COALESCE(SUM(ps.total_amount), 0) AS totalAmount, |
| | | COALESCE(SUM(ps.total_amount) - COALESCE(SUM(all_items.amount), 0), SUM(ps.total_amount)) AS remainingAmount, |
| | | COALESCE(SUM(year_items.year_amount), 0) AS yearAmount, |
| | | COALESCE(SUM(month_items.month_amount), 0) AS monthAmount, |
| | | COALESCE(SUM(all_items.amount), 0) AS allAmount |
| | | FROM project_storage ps |
| | | LEFT JOIN ( |
| | | SELECT |
| | | project_storage_id, |
| | | SUM(amount) AS amount |
| | | FROM project_storage_item |
| | | WHERE disabled = 0 |
| | | GROUP BY project_storage_id |
| | | ) all_items ON ps.id = all_items.project_storage_id |
| | | LEFT JOIN ( |
| | | SELECT |
| | | psi.project_storage_id, |
| | | YEAR(STR_TO_DATE(CONCAT(psi.month, '-01'), '%Y-%m-%d')) as item_year, |
| | | SUM(psi.amount) AS year_amount |
| | | FROM project_storage_item psi |
| | | WHERE psi.disabled = 0 |
| | | GROUP BY psi.project_storage_id, YEAR(STR_TO_DATE(CONCAT(psi.month, '-01'), '%Y-%m-%d')) |
| | | ) year_items ON ps.id = year_items.project_storage_id |
| | | AND YEAR(ps.in_time) = year_items.item_year |
| | | LEFT JOIN ( |
| | | SELECT |
| | | psi.project_storage_id, |
| | | psi.month, |
| | | SUM(psi.amount) AS month_amount |
| | | FROM project_storage_item psi |
| | | WHERE psi.disabled = 0 |
| | | GROUP BY psi.project_storage_id, psi.month |
| | | ) month_items ON ps.id = month_items.project_storage_id |
| | | AND DATE_FORMAT(ps.in_time, '%Y-%m') = month_items.month |
| | | WHERE ps.disabled = 0 |
| | | AND ps.status = 1 |
| | | AND ps.in_time IS NOT NULL |
| | | GROUP BY DATE_FORMAT(ps.in_time, '%Y-%m') |
| | | ORDER BY DATE_FORMAT(ps.in_time, '%Y-%m') DESC |
| | | </select> |
| | | </mapper> |