修改羊舍页面
This commit is contained in:
@@ -44,6 +44,17 @@ public class DaSheepfoldController extends BaseController
|
||||
List<DaSheepfold> list = daSheepfoldService.selectDaSheepfoldList(daSheepfold);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 主表格:羊舍级别汇总列表
|
||||
*/
|
||||
@GetMapping("/summaryList")
|
||||
public TableDataInfo summaryList(DaSheepfold daSheepfold) {
|
||||
startPage();
|
||||
List<DaSheepfold> list = daSheepfoldService.selectDaSheepfoldSummaryList(daSheepfold);
|
||||
return getDataTable(list);
|
||||
}
|
||||
/*
|
||||
* 根据羊舍ids查询羊只id
|
||||
* */
|
||||
|
||||
@@ -115,5 +115,10 @@ public class DaSheepfold extends BaseEntity
|
||||
@Excel(name = "备注")
|
||||
private String comment;
|
||||
|
||||
// 非数据库字段:单栏位羊数(子表格用)
|
||||
private Integer sheepCount;
|
||||
// 非数据库字段:羊舍总羊数(主表格用)
|
||||
private Integer totalSheepCount;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// 创建文件:ExportConfig.java
|
||||
package com.zhyc.module.base.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 导出配置类
|
||||
*/
|
||||
@Data
|
||||
public class ExportConfig {
|
||||
/**
|
||||
* 要导出的列名列表(前端传递的驼峰命名)
|
||||
*/
|
||||
private List<String> columnNames;
|
||||
|
||||
/**
|
||||
* 查询条件
|
||||
*/
|
||||
private Map<String, Object> queryParams;
|
||||
|
||||
/**
|
||||
* 自定义筛选条件
|
||||
*/
|
||||
private Map<String, Object> customFilterParams;
|
||||
}
|
||||
@@ -30,6 +30,12 @@ public interface DaSheepfoldMapper
|
||||
*/
|
||||
public List<DaSheepfold> selectDaSheepfoldList(DaSheepfold daSheepfold);
|
||||
|
||||
|
||||
/**
|
||||
* 羊舍级别汇总查询(主表格)
|
||||
*/
|
||||
List<DaSheepfold> selectDaSheepfoldSummaryList(DaSheepfold daSheepfold);
|
||||
|
||||
/**
|
||||
* 新增羊舍管理
|
||||
*
|
||||
|
||||
@@ -29,6 +29,8 @@ public interface IDaSheepfoldService
|
||||
*/
|
||||
public List<DaSheepfold> selectDaSheepfoldList(DaSheepfold daSheepfold);
|
||||
|
||||
public List<DaSheepfold> selectDaSheepfoldSummaryList(DaSheepfold daSheepfold);
|
||||
|
||||
/**
|
||||
* 新增羊舍管理
|
||||
*
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.zhyc.module.base.domain.DaSheepfold;
|
||||
import com.zhyc.module.base.mapper.BasSheepMapper;
|
||||
import com.zhyc.module.base.mapper.DaSheepfoldMapper;
|
||||
import com.zhyc.module.base.service.IDaSheepfoldService;
|
||||
import org.slf4j.Logger; // 核心修正:导入SLF4J的Logger
|
||||
import org.slf4j.LoggerFactory; // 核心修正:导入SLF4J的LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -24,6 +26,11 @@ public class DaSheepfoldServiceImpl implements IDaSheepfoldService
|
||||
@Autowired
|
||||
private BasSheepMapper basSheepMapper;
|
||||
|
||||
|
||||
// 新增:创建日志对象
|
||||
private static final Logger log = LoggerFactory.getLogger(DaSheepfoldServiceImpl.class);
|
||||
|
||||
|
||||
/**
|
||||
* 查询羊舍管理
|
||||
*
|
||||
@@ -45,9 +52,44 @@ public class DaSheepfoldServiceImpl implements IDaSheepfoldService
|
||||
@Override
|
||||
public List<DaSheepfold> selectDaSheepfoldList(DaSheepfold daSheepfold)
|
||||
{
|
||||
|
||||
List<DaSheepfold> sheepfoldList = daSheepfoldMapper.selectDaSheepfoldList(daSheepfold);
|
||||
|
||||
// 新增调试打印:输出每个栏位的羊数
|
||||
log.info("===== 栏位羊数调试 =====");
|
||||
log.info("查询条件:牧场ID={}, 羊舍类型ID={}, 羊舍编号={}",
|
||||
daSheepfold.getRanchId(), daSheepfold.getSheepfoldTypeId(), daSheepfold.getSheepfoldNo());
|
||||
log.info("共查询到{}个栏位", sheepfoldList.size());
|
||||
|
||||
for (DaSheepfold fold : sheepfoldList) {
|
||||
log.info("栏位ID={}, 羊舍编号={}, 排号={}, 栏数={}, 羊数={}",
|
||||
fold.getId(), fold.getSheepfoldNo(), fold.getRowNo(), fold.getColumns(), fold.getSheepCount());
|
||||
}
|
||||
log.info("===== 调试结束 =====\n");
|
||||
return daSheepfoldMapper.selectDaSheepfoldList(daSheepfold);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 羊舍级别汇总查询(主表格)
|
||||
*/
|
||||
public List<DaSheepfold> selectDaSheepfoldSummaryList(DaSheepfold daSheepfold) {
|
||||
// List<DaSheepfold> summaryList = daSheepfoldMapper.selectDaSheepfoldSummaryList(daSheepfold);
|
||||
//
|
||||
// // 新增调试打印:输出羊舍汇总羊数
|
||||
// log.info("===== 羊舍汇总羊数调试 =====");
|
||||
// log.info("查询条件:牧场ID={}, 羊舍类型ID={}",
|
||||
// daSheepfold.getRanchId(), daSheepfold.getSheepfoldTypeId());
|
||||
// log.info("共查询到{}个羊舍", summaryList.size());
|
||||
//
|
||||
// for (DaSheepfold fold : summaryList) {
|
||||
// log.info("羊舍编号={}, 羊舍名称={}, 总羊数={}",
|
||||
// fold.getSheepfoldNo(), fold.getSheepfoldName(), fold.getTotalSheepCount());
|
||||
// }
|
||||
// log.info("===== 汇总调试结束 =====\n");
|
||||
return daSheepfoldMapper.selectDaSheepfoldSummaryList(daSheepfold);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增羊舍管理
|
||||
*
|
||||
|
||||
@@ -13,33 +13,93 @@
|
||||
<result property="rowNo" column="row_no"/>
|
||||
<result property="columns" column="columns"/>
|
||||
<result property="comment" column="comment"/>
|
||||
<!-- 新增羊只数量映射 -->
|
||||
<result property="sheepCount" column="sheep_count"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础栏位表查询字段 -->
|
||||
<sql id="selectDaSheepfoldVo">
|
||||
select id,
|
||||
ranch_id,
|
||||
sheepfold_name,
|
||||
sheepfold_type_id,
|
||||
sheepfold_no,
|
||||
row_no,
|
||||
columns,
|
||||
comment
|
||||
from da_sheepfold
|
||||
|
||||
SELECT
|
||||
ds.id,
|
||||
ds.ranch_id,
|
||||
ds.sheepfold_name,
|
||||
ds.sheepfold_type_id,
|
||||
ds.sheepfold_no,
|
||||
ds.row_no,
|
||||
ds.columns,
|
||||
ds.comment
|
||||
FROM da_sheepfold ds
|
||||
</sql>
|
||||
|
||||
<select id="selectDaSheepfoldList" parameterType="DaSheepfold" resultMap="DaSheepfoldResult">
|
||||
<include refid="selectDaSheepfoldVo"/>
|
||||
<where>
|
||||
<if test="ranchId != null ">and ranch_id = #{ranchId}</if>
|
||||
<if test="sheepfoldTypeId != null ">and sheepfold_type_id = #{sheepfoldTypeId}</if>
|
||||
</where>
|
||||
|
||||
order by
|
||||
SUBSTRING_INDEX(row_no, '-', 1),
|
||||
CAST(columns AS UNSIGNED)
|
||||
<!-- 1. 主表格:羊舍级别汇总查询(统计每个羊舍的总羊数) -->
|
||||
<select id="selectDaSheepfoldSummaryList" parameterType="DaSheepfold" resultMap="DaSheepfoldSummaryResult">
|
||||
SELECT
|
||||
ds.ranch_id,
|
||||
ds.sheepfold_type_id,
|
||||
ds.sheepfold_no,
|
||||
-- 提取羊舍名称(截取栏位名称的羊舍部分,保证唯一)
|
||||
CONCAT(ds.sheepfold_no, '号', (SELECT dict_label FROM sys_dict_data WHERE dict_value = ds.sheepfold_type_id AND dict_type = 'bas_sheepfold_type')) as sheepfoldName,
|
||||
MAX(ds.comment) as comment,
|
||||
-- 汇总该羊舍下所有栏位的羊数总和
|
||||
SUM(IFNULL(sheep_group.sheep_count, 0)) as totalSheepCount
|
||||
FROM da_sheepfold ds
|
||||
-- 左关联羊只表,统计每个栏位的羊数
|
||||
LEFT JOIN (
|
||||
SELECT sheepfold_id, COUNT(id) as sheep_count
|
||||
FROM bas_sheep -- 羊只表
|
||||
GROUP BY sheepfold_id -- 按栏位ID分组统计羊数
|
||||
) sheep_group ON ds.id = sheep_group.sheepfold_id -- 关联字段修正为sheepfold_id
|
||||
<where>
|
||||
<if test="ranchId != null ">and ds.ranch_id = #{ranchId}</if>
|
||||
<if test="sheepfoldTypeId != null ">and ds.sheepfold_type_id = #{sheepfoldTypeId}</if>
|
||||
</where>
|
||||
-- 按羊舍维度分组(牧场+羊舍类型+羊舍编号 唯一标识一个羊舍)
|
||||
GROUP BY ds.ranch_id, ds.sheepfold_type_id, ds.sheepfold_no
|
||||
ORDER BY ds.sheepfold_no
|
||||
</select>
|
||||
|
||||
|
||||
<!-- 2. 子表格:栏位级别明细查询(统计单个栏位的羊数) -->
|
||||
<select id="selectDaSheepfoldList" parameterType="DaSheepfold" resultMap="DaSheepfoldResult">
|
||||
SELECT
|
||||
ds.id,
|
||||
ds.ranch_id,
|
||||
ds.sheepfold_name,
|
||||
ds.sheepfold_type_id,
|
||||
ds.sheepfold_no,
|
||||
ds.row_no,
|
||||
ds.columns,
|
||||
ds.comment,
|
||||
-- 统计当前栏位的羊数(关联羊只表)
|
||||
IFNULL(sheep_group.sheep_count, 0) as sheep_count
|
||||
FROM da_sheepfold ds
|
||||
-- 左关联羊只表,避免无羊的栏位被过滤
|
||||
LEFT JOIN (
|
||||
SELECT sheepfold_id, COUNT(id) as sheep_count
|
||||
FROM bas_sheep -- 羊只表
|
||||
GROUP BY sheepfold_id
|
||||
) sheep_group ON ds.id = sheep_group.sheepfold_id -- 关联字段修正为sheepfold_id
|
||||
<where>
|
||||
<if test="ranchId != null ">and ds.ranch_id = #{ranchId}</if>
|
||||
<if test="sheepfoldTypeId != null ">and ds.sheepfold_type_id = #{sheepfoldTypeId}</if>
|
||||
<if test="sheepfoldNo != null and sheepfoldNo != '' ">and ds.sheepfold_no = #{sheepfoldNo}</if>
|
||||
</where>
|
||||
GROUP BY ds.id,ds.ranch_id,ds.sheepfold_name,ds.sheepfold_type_id,ds.sheepfold_no,ds.row_no,ds.columns,ds.comment
|
||||
ORDER BY SUBSTRING_INDEX(ds.row_no, '-', 1), CAST(ds.columns AS UNSIGNED)
|
||||
</select>
|
||||
|
||||
<!-- 汇总结果映射(主表格用) -->
|
||||
<resultMap id="DaSheepfoldSummaryResult" type="DaSheepfold">
|
||||
<result property="ranchId" column="ranch_id"/>
|
||||
<result property="sheepfoldTypeId" column="sheepfold_type_id"/>
|
||||
<result property="sheepfoldNo" column="sheepfold_no"/>
|
||||
<result property="sheepfoldName" column="sheepfoldName"/>
|
||||
<result property="comment" column="comment"/>
|
||||
<result property="totalSheepCount" column="totalSheepCount"/> <!-- 羊舍总羊数 -->
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectDaSheepfoldById" parameterType="Long" resultMap="DaSheepfoldResult">
|
||||
<include refid="selectDaSheepfoldVo"/>
|
||||
where id = #{id}
|
||||
|
||||
Reference in New Issue
Block a user