fix (farm): 农事报表
- 农事任务统计 - 投入品金额统计 - 投入品金额趋势统计
This commit is contained in:
@@ -52,6 +52,68 @@
|
||||
ORDER BY recordCount DESC
|
||||
</select>
|
||||
|
||||
<select id="getFarmRecord4FarmTypeChart"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.FarmRecordForFarmTypeChartRespVO">
|
||||
SELECT
|
||||
fftm.id AS farmTypeId,
|
||||
fftm.farming_name AS farmTypeName,
|
||||
COUNT(ffr.id) AS farmRecordCount
|
||||
FROM farm_farming_type_maintenance fftm
|
||||
LEFT JOIN farm_farming_record ffr ON fftm.id = ffr.task_type
|
||||
AND ffr.deleted = 0
|
||||
<if test="baseId != null and baseId != ''">
|
||||
AND ffr.base_id = #{baseId}
|
||||
</if>
|
||||
<if test="plotId != null and plotId != ''">
|
||||
AND ffr.plot_id = #{plotId}
|
||||
</if>
|
||||
<if test="yearDate != null">
|
||||
AND YEAR(ffr.task_start_date) = #{yearDate}
|
||||
</if>
|
||||
<if test="state != null and state != ''">
|
||||
AND ffr.task_status = #{state}
|
||||
</if>
|
||||
WHERE fftm.deleted = 0 AND fftm.use_status = 1
|
||||
GROUP BY farmTypeId, farmTypeName
|
||||
ORDER BY farmRecordCount DESC
|
||||
</select>
|
||||
|
||||
<select id="getFarmRecord4FarmNameChart"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.FarmRecordForFarmNameChartRespVO">
|
||||
SELECT
|
||||
ffnm.farming_name AS farmName,
|
||||
COUNT(ffr.id) AS farmRecordCount
|
||||
FROM farm_farming_name_maintenance ffnm
|
||||
LEFT JOIN farm_farming_record ffr ON ffnm.id = ffr.task_name
|
||||
AND ffr.deleted = 0
|
||||
<if test="tenantId != null and tenantId != ''">
|
||||
AND ffr.tenant_id = #{tenantId}
|
||||
</if>
|
||||
<if test="baseId != null and baseId != ''">
|
||||
AND ffr.base_id = #{baseId}
|
||||
</if>
|
||||
<if test="plotId != null and plotId != ''">
|
||||
AND ffr.plot_id = #{plotId}
|
||||
</if>
|
||||
<if test="yearDate != null">
|
||||
AND YEAR(ffr.task_start_date) = #{yearDate}
|
||||
</if>
|
||||
<if test="state != null and state != ''">
|
||||
AND ffr.task_status = #{state}
|
||||
</if>
|
||||
|
||||
<where>
|
||||
ffnm.deleted = 0 AND ffnm.use_status = 1
|
||||
<if test="farmTypeId != null and farmTypeId != ''">
|
||||
AND ffnm.farming_type_code = #{farmTypeId}
|
||||
</if>
|
||||
</where>
|
||||
|
||||
GROUP BY ffnm.id, ffnm.farming_name
|
||||
ORDER BY farmRecordCount DESC
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -9,44 +9,44 @@
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
<select id="getInputUsageChart"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.InputUsageChartRespVO">
|
||||
<!-- <select id="getInputUsageChart"-->
|
||||
<!-- parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"-->
|
||||
<!-- resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.InputUsageByTypeChartRespVO">-->
|
||||
|
||||
SELECT
|
||||
fiur.input_name AS inputName,
|
||||
SUM(fiur.usage_amount) AS usageAmount,
|
||||
CASE
|
||||
WHEN fiur.current_spec_type = 1 THEN fiur.unit
|
||||
WHEN fiur.current_spec_type = 2 THEN fiur.spec
|
||||
ELSE fiur.unit
|
||||
END AS unit,
|
||||
fiur.current_spec_type AS currentSpecType,
|
||||
AVG(fiur.unit_price) AS unitPrice,
|
||||
SUM(fiur.total_price) AS totalPrice
|
||||
FROM farm_input_usage_records fiur
|
||||
<where>
|
||||
fiur.deleted = 0
|
||||
<if test="tenantId != null">
|
||||
AND fiur.tenant_id = #{tenantId}
|
||||
</if>
|
||||
<if test="baseId != null and baseId != ''">
|
||||
AND fiur.base_id = #{baseId}
|
||||
</if>
|
||||
<if test="plotId != null and plotId != ''">
|
||||
AND fiur.plot_id = #{plotId}
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY fiur.input_name,
|
||||
CASE
|
||||
WHEN fiur.current_spec_type = 1 THEN fiur.unit
|
||||
WHEN fiur.current_spec_type = 2 THEN fiur.spec
|
||||
ELSE fiur.unit
|
||||
END,
|
||||
fiur.current_spec_type
|
||||
ORDER BY usageAmount DESC
|
||||
<!-- SELECT-->
|
||||
<!-- fiur.input_name AS inputName,-->
|
||||
<!-- SUM(fiur.usage_amount) AS usageAmount,-->
|
||||
<!-- CASE-->
|
||||
<!-- WHEN fiur.current_spec_type = 1 THEN fiur.unit-->
|
||||
<!-- WHEN fiur.current_spec_type = 2 THEN fiur.spec-->
|
||||
<!-- ELSE fiur.unit-->
|
||||
<!-- END AS unit,-->
|
||||
<!-- fiur.current_spec_type AS currentSpecType,-->
|
||||
<!-- AVG(fiur.unit_price) AS unitPrice,-->
|
||||
<!-- SUM(fiur.total_price) AS totalPrice-->
|
||||
<!-- FROM farm_input_usage_records fiur-->
|
||||
<!-- <where>-->
|
||||
<!-- fiur.deleted = 0-->
|
||||
<!-- <if test="tenantId != null">-->
|
||||
<!-- AND fiur.tenant_id = #{tenantId}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="baseId != null and baseId != ''">-->
|
||||
<!-- AND fiur.base_id = #{baseId}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="plotId != null and plotId != ''">-->
|
||||
<!-- AND fiur.plot_id = #{plotId}-->
|
||||
<!-- </if>-->
|
||||
<!-- </where>-->
|
||||
<!-- GROUP BY fiur.input_name,-->
|
||||
<!-- CASE-->
|
||||
<!-- WHEN fiur.current_spec_type = 1 THEN fiur.unit-->
|
||||
<!-- WHEN fiur.current_spec_type = 2 THEN fiur.spec-->
|
||||
<!-- ELSE fiur.unit-->
|
||||
<!-- END,-->
|
||||
<!-- fiur.current_spec_type-->
|
||||
<!-- ORDER BY usageAmount DESC-->
|
||||
|
||||
</select>
|
||||
<!-- </select>-->
|
||||
|
||||
<select id="getFarmReport"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
@@ -88,4 +88,91 @@
|
||||
ORDER BY ffr.task_start_date DESC
|
||||
</select>
|
||||
|
||||
<select id="getInputUsageByTypeChart"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.InputUsageByTypeChartRespVO">
|
||||
SELECT
|
||||
sdd.value AS inputTypeId,
|
||||
sdd.label AS inputTypeName,
|
||||
COALESCE(SUM(fiur.usage_amount), 0) AS usageAmount,
|
||||
ROUND(COALESCE(AVG(fiur.unit_price), 0), 2) AS unitPrice,
|
||||
ROUND(COALESCE(SUM(fiur.total_price), 0), 2) AS totalPrice
|
||||
FROM system_dict_data sdd
|
||||
LEFT JOIN farm_inputs fi ON CONVERT(sdd.value USING utf8mb4) COLLATE utf8mb4_unicode_ci = fi.input_type
|
||||
AND fi.input_category = 2
|
||||
AND fi.deleted = 0
|
||||
LEFT JOIN farm_input_usage_records fiur ON fi.id = fiur.input_id
|
||||
AND fiur.deleted = 0
|
||||
<if test="baseId != null and baseId != ''">
|
||||
AND fiur.base_id = #{baseId}
|
||||
</if>
|
||||
<if test="plotId != null and plotId != ''">
|
||||
AND fiur.plot_id = #{plotId}
|
||||
</if>
|
||||
<if test="yearDate != null">
|
||||
AND YEAR(fiur.create_time) = #{yearDate}
|
||||
</if>
|
||||
WHERE sdd.dict_type = 'asset_type'
|
||||
AND sdd.deleted = 0
|
||||
AND sdd.status = 0
|
||||
GROUP BY sdd.id, sdd.label, sdd.value
|
||||
ORDER BY totalPrice DESC
|
||||
</select>
|
||||
|
||||
<select id="getInputUsageByNameChart"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.InputUsageByNameChartRespVO">
|
||||
SELECT
|
||||
fi.input_name AS inputName,
|
||||
COALESCE(SUM(fiur.usage_amount), 0) AS usageAmount,
|
||||
ROUND(COALESCE(AVG(fiur.unit_price), 0), 2) AS unitPrice,
|
||||
ROUND(COALESCE(SUM(fiur.total_price), 0), 2) AS totalPrice
|
||||
FROM farm_inputs fi
|
||||
LEFT JOIN farm_input_usage_records fiur ON fi.id = fiur.input_id
|
||||
AND fiur.deleted = 0
|
||||
<if test="baseId != null and baseId != ''">
|
||||
AND fiur.base_id = #{baseId}
|
||||
</if>
|
||||
<if test="plotId != null and plotId != ''">
|
||||
AND fiur.plot_id = #{plotId}
|
||||
</if>
|
||||
<if test="yearDate != null">
|
||||
AND YEAR(fiur.create_time) = #{yearDate}
|
||||
</if>
|
||||
WHERE fi.input_category = 2
|
||||
AND fi.deleted = 0
|
||||
<if test="inputTypeId != null and inputTypeId != ''">
|
||||
AND fi.input_type = #{inputTypeId}
|
||||
</if>
|
||||
GROUP BY fi.id, fi.input_name
|
||||
ORDER BY totalPrice DESC
|
||||
</select>
|
||||
|
||||
<select id="getInputUsageTrendChart"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.InputUsageTrendChartRespVO">
|
||||
SELECT
|
||||
year_range.year AS year,
|
||||
ROUND(COALESCE(SUM(fiur.total_price), 0), 2) AS totalPrice
|
||||
FROM (
|
||||
SELECT YEAR(CURDATE()) - 4 AS year
|
||||
UNION SELECT YEAR(CURDATE()) - 3
|
||||
UNION SELECT YEAR(CURDATE()) - 2
|
||||
UNION SELECT YEAR(CURDATE()) - 1
|
||||
UNION SELECT YEAR(CURDATE())
|
||||
) year_range
|
||||
LEFT JOIN farm_input_usage_records fiur ON YEAR(fiur.create_time) = year_range.year
|
||||
AND fiur.deleted = 0
|
||||
<if test="tenantId != null and tenantId != ''">
|
||||
AND fiur.tenant_id = #{tenantId}
|
||||
</if>
|
||||
<if test="baseId != null and baseId != ''">
|
||||
AND fiur.base_id = #{baseId}
|
||||
</if>
|
||||
<if test="plotId != null and plotId != ''">
|
||||
AND fiur.plot_id = #{plotId}
|
||||
</if>
|
||||
GROUP BY year_range.year
|
||||
ORDER BY year_range.year ASC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -111,9 +111,9 @@
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getPlantingAreaChart"
|
||||
<select id="getPlantChart"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.PlantingAreaChartRespVO">
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.PlantChartRespVO">
|
||||
|
||||
SELECT
|
||||
fsl.cultivar_name AS speciesName,
|
||||
@@ -161,4 +161,55 @@
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getBreedChart"
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.ChartCommonReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.chart.BreedChartRespVO">
|
||||
|
||||
SELECT
|
||||
fsl.cultivar_name AS speciesName,
|
||||
SUM(fpp.predicted_grid_number) AS predictedGridNumber,
|
||||
CASE
|
||||
WHEN #{plotId} IS NOT NULL AND #{plotId} != '' THEN
|
||||
MAX(fpp.plot_grid_number)
|
||||
WHEN #{baseId} IS NOT NULL AND #{baseId} != '' AND (#{plotId} IS NULL OR #{plotId} = '') THEN
|
||||
(
|
||||
SELECT SUM(plot_grid_number)
|
||||
FROM farm_production_plan
|
||||
WHERE base_id = #{baseId}
|
||||
AND tenant_id = #{tenantId}
|
||||
AND deleted = 0
|
||||
)
|
||||
ELSE
|
||||
(
|
||||
SELECT SUM(plot_grid_number)
|
||||
FROM farm_production_plan
|
||||
WHERE tenant_id = #{tenantId}
|
||||
AND deleted = 0
|
||||
)
|
||||
END AS plotGridNumber
|
||||
FROM farm_production_plan fpp
|
||||
LEFT JOIN farm_species_library fsl ON fpp.plant_species_code = fsl.id
|
||||
WHERE
|
||||
fpp.deleted = 0
|
||||
AND fsl.deleted = 0
|
||||
<if test="tenantId != null">
|
||||
AND fpp.tenant_id = #{tenantId}
|
||||
</if>
|
||||
<if test="yearDate != null">
|
||||
AND YEAR(fpp.production_start_date) = #{yearDate}
|
||||
</if>
|
||||
<if test="baseId != null and baseId != ''">
|
||||
AND fpp.base_id = #{baseId}
|
||||
</if>
|
||||
<if test="plotId != null and plotId != ''">
|
||||
AND fpp.plot_id = #{plotId}
|
||||
</if>
|
||||
<if test="state != null and state != ''">
|
||||
AND fpp.plan_status = #{state}
|
||||
</if>
|
||||
GROUP BY fsl.cultivar_name
|
||||
ORDER BY predictedGridNumber DESC
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user