From 263b034b4058bb7a36c709278abdc88ca1ba26c1 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 30 三月 2026 18:01:25 +0800
Subject: [PATCH] feat: 生产成本导入数据入库
---
src/main/resources/mapper/production/ProductionCostMapper.xml | 89 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 89 insertions(+), 0 deletions(-)
diff --git a/src/main/resources/mapper/production/ProductionCostMapper.xml b/src/main/resources/mapper/production/ProductionCostMapper.xml
new file mode 100644
index 0000000..dcf503d
--- /dev/null
+++ b/src/main/resources/mapper/production/ProductionCostMapper.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.production.mapper.ProductionCostMapper">
+
+ <sql id="baseCostQuery">
+ SELECT
+ ppi.quantity,
+ pos.unit_price,
+ (ppi.quantity * IFNULL(pos.unit_price, 0)) as calculated_cost,
+ ppi.unit as unit,
+ ppm.product_order_id,
+ ppm.reporting_time as log_date,
+ po.nps_no as order_no,
+ pm_mat.product_name as material_name,
+ pms_mat.model as material_model,
+ po.strength as strength,
+ sdd_type.dict_label as category_label
+ FROM production_product_input ppi
+ JOIN production_product_main ppm ON ppi.product_main_id = ppm.id
+ JOIN product_order po ON ppm.product_order_id = po.id
+ LEFT JOIN production_order_route pr ON po.route_id = pr.id
+ LEFT JOIN sys_dict_data sdd_type ON pr.dict_code = sdd_type.dict_code
+ LEFT JOIN production_order_structure pos ON ppm.product_order_id = pos.order_id
+ AND ppi.product_id = pos.product_model_id
+ AND ppi.bom_id = pos.bom_id
+ LEFT JOIN product_material_sku pms_mat ON ppi.product_id = pms_mat.id
+ LEFT JOIN product_material pm_mat ON pms_mat.product_id = pm_mat.id
+ <where>
+ <if test="dto.startDate != null">
+ AND ppm.reporting_time >= #{dto.startDate}
+ </if>
+ <if test="dto.endDate != null">
+ AND ppm.reporting_time < #{dto.endDate}
+ </if>
+ <if test="dto.dictCode != null">
+ AND pr.dict_code = #{dto.dictCode}
+ </if>
+ <if test="dto.productOrderId != null">
+ AND ppm.product_order_id = #{dto.productOrderId}
+ </if>
+ </where>
+ </sql>
+
+ <select id="selectCostSummary" resultType="com.ruoyi.production.vo.ProductionCostSummaryVo">
+ SELECT
+ ROUND(IFNULL(SUM(calculated_cost), 0), 2) as totalCost,
+ COUNT(DISTINCT product_order_id) as orderCount,
+ CASE
+ WHEN COUNT(DISTINCT product_order_id) > 0
+ THEN ROUND(SUM(calculated_cost) / COUNT(DISTINCT product_order_id), 2)
+ ELSE 0
+ END as averageOrderCost
+ FROM (
+ <include refid="baseCostQuery"/>
+ ) t
+ </select>
+
+ <select id="selectCostAggregationByCategory" resultType="com.ruoyi.production.vo.ProductionCostAggregationVo">
+ SELECT
+ log_date as date,
+ IFNULL(material_name, '鏈煡浜у搧') as name,
+ material_model as model,
+ unit,
+ ROUND(IFNULL(SUM(quantity), 0), 6) as quantity,
+ ROUND(IFNULL(SUM(calculated_cost), 0), 2) as totalCost
+ FROM (
+ <include refid="baseCostQuery"/>
+ ) t
+ GROUP BY log_date, material_name, material_model, unit
+ </select>
+
+ <select id="selectCostAggregationByOrder" resultType="com.ruoyi.production.vo.ProductionCostAggregationVo">
+ SELECT
+ log_date as date,
+ IFNULL(order_no, '鏈煡鍗曞彿') as name,
+ material_name as model,
+ category_label as strength,
+ unit,
+ ROUND(IFNULL(SUM(quantity), 0), 6) as quantity,
+ ROUND(IFNULL(SUM(calculated_cost), 0), 2) as totalCost
+ FROM (
+ <include refid="baseCostQuery"/>
+ ) t
+ GROUP BY log_date, order_no, material_name, category_label, unit
+ </select>
+
+</mapper>
\ No newline at end of file
--
Gitblit v1.9.3