酸奶检验记录,鲜奶检验记录、生乳检验记录页面导出功能,奶产量分析页面报错修复

This commit is contained in:
ll 2025-08-29 17:24:43 +08:00
parent 3a6dac3130
commit c8f7b6baff
6 changed files with 124 additions and 26 deletions

View File

@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
/** /**
* 奶产量分析控制器
* 只保留分页列表只读 + 单条查询 + 导出 * 只保留分页列表只读 + 单条查询 + 导出
*/ */
@RestController @RestController
@ -29,13 +30,13 @@ public class NpSheepMilkAnalysisController extends BaseController {
*/ */
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(NpSheepMilkAnalysis analysis) { public TableDataInfo list(NpSheepMilkAnalysis analysis) {
startPage(); // 使用 PageHelper 分页注意 service 中第一个 DB 调用是 distinct sheep id startPage(); // 使用PageHelper分页注意service中第一个DB调用是distinct sheep id
List<NpSheepMilkAnalysis> list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisList(analysis); List<NpSheepMilkAnalysis> list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisList(analysis);
return getDataTable(list); return getDataTable(list);
} }
/** /**
* 获取单个分析记录详细信息 sheepId * 获取单个分析记录详细信息sheepId
*/ */
@GetMapping(value = "/{sheepId}") @GetMapping(value = "/{sheepId}")
public AjaxResult getInfo(@PathVariable("sheepId") String sheepId) { public AjaxResult getInfo(@PathVariable("sheepId") String sheepId) {
@ -44,12 +45,12 @@ public class NpSheepMilkAnalysisController extends BaseController {
/** /**
* 导出奶产量分析记录Excel * 导出奶产量分析记录Excel
* 支持 manageEarTag screenDays 两个查询条件 * 支持manageEarTag与screenDays两个查询条件
*/ */
@Log(title = "奶产量分析 导出", businessType = BusinessType.EXPORT) @Log(title = "奶产量分析 导出", businessType = BusinessType.EXPORT)
@GetMapping("/export") @GetMapping("/export")
public AjaxResult export(NpSheepMilkAnalysis analysis) { public AjaxResult export(NpSheepMilkAnalysis analysis) {
List<NpSheepMilkAnalysis> list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisList(analysis); List<NpSheepMilkAnalysis> list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisForExport(analysis);
ExcelUtil<NpSheepMilkAnalysis> util = new ExcelUtil<>(NpSheepMilkAnalysis.class); ExcelUtil<NpSheepMilkAnalysis> util = new ExcelUtil<>(NpSheepMilkAnalysis.class);
return util.exportExcel(list, "羊奶产量分析数据"); return util.exportExcel(list, "羊奶产量分析数据");
} }

View File

@ -1,78 +1,141 @@
package com.zhyc.module.dairyProducts.domain; package com.zhyc.module.dairyProducts.domain;
import com.zhyc.common.annotation.Excel;
import java.util.Date; import java.util.Date;
public class NpSheepMilkAnalysis { public class NpSheepMilkAnalysis {
// 唯一键可用于前端 row-key // 唯一键可用于前端 row-key
@Excel(name = "羊只ID")
private String sheepId; private String sheepId;
// 耳号 sheep_file.bs_manage_tags // 耳号 sheep_file.bs_manage_tags
@Excel(name = "耳号")
private String manageEarTag; private String manageEarTag;
@Excel(name = "品种")
private String variety; private String variety;
// 最高校正胎次的挤奶开始时间 & 干奶时间 // 最高校正胎次的挤奶开始时间 & 干奶时间
@Excel(name = "挤奶开始时间", dateFormat = "yyyy-MM-dd")
private Date milkingStartTime; private Date milkingStartTime;
@Excel(name = "干奶时间", dateFormat = "yyyy-MM-dd")
private Date dryEndTime; private Date dryEndTime;
// 挤奶天数该胎次 // 挤奶天数该胎次
@Excel(name = "挤奶天数")
private Integer milkingDays; private Integer milkingDays;
// 前端传入的筛选天数screenDays // 前端传入的筛选天数screenDays
@Excel(name = "筛选天数")
private Integer screenDays; private Integer screenDays;
// 分析天数若你有不同命名可忽略 // 分析天数若你有不同命名可忽略
private Integer analysisDays; private Integer analysisDays;
// 校正后最大胎次即校正奶量之和最大的胎次 // 校正后最大胎次即校正奶量之和最大的胎次
@Excel(name = "校正后最大胎次")
private Integer maxParity; private Integer maxParity;
// 最高校正胎次区间内的系统奶量与校正奶量按筛选窗口 // 最高校正胎次区间内的系统奶量与校正奶量按筛选窗口
@Excel(name = "系统奶量合计")
private Double sumSystemMilk; private Double sumSystemMilk;
@Excel(name = "校正奶量合计")
private Double sumCorrectedMilk; private Double sumCorrectedMilk;
// 校正日平均奶量 min(挤奶天数, 筛选天数) // 校正日平均奶量按min(挤奶天数,筛选天数)
@Excel(name = "校正日平均奶量")
private Double avgCorrectedDaily; private Double avgCorrectedDaily;
// 各胎次总奶量校正 // 各胎次总奶量校正
@Excel(name = "胎次1总奶量")
private Double sumParity1Milk; private Double sumParity1Milk;
@Excel(name = "胎次2总奶量")
private Double sumParity2Milk; private Double sumParity2Milk;
@Excel(name = "胎次3总奶量")
private Double sumParity3Milk; private Double sumParity3Milk;
@Excel(name = "胎次4总奶量")
private Double sumParity4Milk; private Double sumParity4Milk;
// 各胎次日平均按规则 // 各胎次日平均按规则
@Excel(name = "胎次1日平均")
private Double avgParity1Daily; private Double avgParity1Daily;
@Excel(name = "胎次2日平均")
private Double avgParity2Daily; private Double avgParity2Daily;
@Excel(name = "胎次3日平均")
private Double avgParity3Daily; private Double avgParity3Daily;
@Excel(name = "胎次4日平均")
private Double avgParity4Daily; private Double avgParity4Daily;
// 泌乳天数sheep_file.lactation_day // 泌乳天数sheep_file.lactation_day
@Excel(name = "泌乳天数")
private Integer lactationDays; private Integer lactationDays;
// 过去 7 / 14 / 30 日平均系统奶量 // 过去7/14/30日平均系统奶量
@Excel(name = "过去7日均奶量")
private Double avgLast7Milk; private Double avgLast7Milk;
private Double avgLast7Corrected; // = avgLast7Milk * weightCoefficient 默认 1.0
@Excel(name = "校正过去7日均")
private Double avgLast7Corrected;
@Excel(name = "过去14日均奶量")
private Double avgLast14Milk; private Double avgLast14Milk;
@Excel(name = "过去30日均奶量")
private Double avgLast30Milk; private Double avgLast30Milk;
// 羊只基础信息来自 sheep_file // 羊只基础信息来自sheep_file
@Excel(name = "羊只类别")
private String sheepCategory; private String sheepCategory;
@Excel(name = "生日", dateFormat = "yyyy-MM-dd")
private Date birthday; private Date birthday;
private Integer parity; // 当前胎次
@Excel(name = "当前胎次")
private Integer parity;
@Excel(name = "月龄")
private Integer monthAge; private Integer monthAge;
@Excel(name = "当前体重")
private Double currentWeight; private Double currentWeight;
@Excel(name = "繁育状态")
private String breedStatus; private String breedStatus;
@Excel(name = "父号")
private String fatherManageTags; private String fatherManageTags;
@Excel(name = "母号")
private String motherManageTags; private String motherManageTags;
@Excel(name = "牧场")
private String ranchName; private String ranchName;
@Excel(name = "家系")
private String family; private String family;
// 母亲相关字段由已计算的母亲分析结果中取值 // 母亲相关字段由已计算的母亲分析结果中取值
@Excel(name = "母亲挤奶天数")
private Integer motherMilkingDays; private Integer motherMilkingDays;
@Excel(name = "母亲校正奶量合计")
private Double motherSumCorrected; private Double motherSumCorrected;
@Excel(name = "母亲校正后最大胎次")
private Integer motherMaxParity; private Integer motherMaxParity;
@Excel(name = "母亲校正日平均奶量")
private Double motherAvgCorrectedDaily; private Double motherAvgCorrectedDaily;
@Excel(name = "最后更新时间", dateFormat = "yyyy-MM-dd")
private Date lastUpdate; private Date lastUpdate;
// getters and setters // getters and setters

View File

@ -9,7 +9,7 @@ import java.util.Map;
public interface NpSheepMilkAnalysisMapper { public interface NpSheepMilkAnalysisMapper {
/** /**
* 按筛选天数 screenDays 统计并返回所有羊只的奶产量分析 * 按筛选天数screenDays统计并返回所有羊只的奶产量分析
*/ */
List<NpSheepMilkAnalysis> selectAnalysisForExport(@Param("screenDays") Integer screenDays); List<NpSheepMilkAnalysis> selectAnalysisForExport(@Param("screenDays") Integer screenDays);
@ -33,4 +33,9 @@ public interface NpSheepMilkAnalysisMapper {
*/ */
List<Map<String, Object>> selectMilkRecordsBySheepId(@Param("sheepId") String sheepId); List<Map<String, Object>> selectMilkRecordsBySheepId(@Param("sheepId") String sheepId);
/**
* 导出奶产量分析记录
*/
List<NpSheepMilkAnalysis> selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis);
} }

View File

@ -9,4 +9,9 @@ public interface INpSheepMilkAnalysisService {
List<NpSheepMilkAnalysis> selectNpSheepMilkAnalysisList(NpSheepMilkAnalysis analysis); List<NpSheepMilkAnalysis> selectNpSheepMilkAnalysisList(NpSheepMilkAnalysis analysis);
/**
* 导出奶产量分析记录
*/
List<NpSheepMilkAnalysis> selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis);
} }

View File

@ -19,7 +19,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi
@Autowired @Autowired
private NpSheepMilkAnalysisMapper npSheepMilkAnalysisMapper; private NpSheepMilkAnalysisMapper npSheepMilkAnalysisMapper;
// Rec 定义为静态内部类 // Rec定义为静态内部类
private static class Rec { private static class Rec {
LocalDate date; LocalDate date;
double systemMilk; double systemMilk;
@ -27,7 +27,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi
int parity; int parity;
} }
// ParityStat 定义为静态内部类 // ParityStat定义为静态内部类
private static class ParityStat { private static class ParityStat {
int parity; int parity;
double sumCorrected; double sumCorrected;
@ -85,7 +85,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi
continue; continue;
} }
// 使用静态内部类 Rec // 使用静态内部类Rec
List<Rec> recs = new ArrayList<>(); List<Rec> recs = new ArrayList<>();
for (Map<String, Object> r : records) { for (Map<String, Object> r : records) {
Rec rr = new Rec(); Rec rr = new Rec();
@ -98,7 +98,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi
Map<Integer, List<Rec>> byParity = recs.stream().collect(Collectors.groupingBy(r -> r.parity)); Map<Integer, List<Rec>> byParity = recs.stream().collect(Collectors.groupingBy(r -> r.parity));
// 使用静态内部类 ParityStat // 使用静态内部类ParityStat
List<ParityStat> parityStats = new ArrayList<>(); List<ParityStat> parityStats = new ArrayList<>();
for (Map.Entry<Integer, List<Rec>> e : byParity.entrySet()) { for (Map.Entry<Integer, List<Rec>> e : byParity.entrySet()) {
List<Rec> list = e.getValue(); List<Rec> list = e.getValue();
@ -142,7 +142,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi
double sumParity3 = parityStats.stream().filter(p -> p.parity == 3).mapToDouble(p -> p.sumCorrected).sum(); double sumParity3 = parityStats.stream().filter(p -> p.parity == 3).mapToDouble(p -> p.sumCorrected).sum();
double sumParity4 = parityStats.stream().filter(p -> p.parity == 4).mapToDouble(p -> p.sumCorrected).sum(); double sumParity4 = parityStats.stream().filter(p -> p.parity == 4).mapToDouble(p -> p.sumCorrected).sum();
// 你之前的 computeParityAvg 方法里没实现保留调用0 // 你之前的computeParityAvg方法里没实现保留调用0
double avgP1 = computeParityAvg(parityStats, 1, screenDays); double avgP1 = computeParityAvg(parityStats, 1, screenDays);
double avgP2 = computeParityAvg(parityStats, 2, screenDays); double avgP2 = computeParityAvg(parityStats, 2, screenDays);
double avgP3 = computeParityAvg(parityStats, 3, screenDays); double avgP3 = computeParityAvg(parityStats, 3, screenDays);
@ -219,6 +219,12 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi
return resultList; return resultList;
} }
@Override
public List<NpSheepMilkAnalysis> selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis) {
// 直接调用Mapper的导出方法避免复杂的业务逻辑
return npSheepMilkAnalysisMapper.selectNpSheepMilkAnalysisForExport(analysis);
}
private static Date convertToDate(Object obj) { private static Date convertToDate(Object obj) {
if (obj == null) return null; if (obj == null) return null;
if (obj instanceof Date) { if (obj instanceof Date) {

View File

@ -4,7 +4,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhyc.module.dairyProducts.mapper.NpSheepMilkAnalysisMapper"> <mapper namespace="com.zhyc.module.dairyProducts.mapper.NpSheepMilkAnalysisMapper">
<!-- 1) 获取 distinct sheep_id支持按 sheep_file.bs_manage_tags 模糊搜索) --> <!-- 1) 获取distinct sheep_id支持按sheep_file.bs_manage_tags模糊搜索 -->
<select id="selectDistinctSheepIds" resultType="string" parameterType="map"> <select id="selectDistinctSheepIds" resultType="string" parameterType="map">
SELECT DISTINCT a.sheep_id SELECT DISTINCT a.sheep_id
FROM np_milk_prod_classes a FROM np_milk_prod_classes a
@ -30,8 +30,7 @@
ORDER BY datetime ASC ORDER BY datetime ASC
</select> </select>
<!-- 3) 获取该羊在sheep_file视图中的基础信息 -->
<!-- 3) 获取该羊在 sheep_file 视图中的基础信息 -->
<!-- 假设字段名称bs_manage_tags、variety、lactation_day、name、birthday、parity、month_age、current_weight、breed、father_manage_tags、mother_manage_tags、dr_ranch、family --> <!-- 假设字段名称bs_manage_tags、variety、lactation_day、name、birthday、parity、month_age、current_weight、breed、father_manage_tags、mother_manage_tags、dr_ranch、family -->
<select id="selectSheepFileBySheepId" resultType="map" parameterType="string"> <select id="selectSheepFileBySheepId" resultType="map" parameterType="string">
SELECT SELECT
@ -53,10 +52,29 @@
WHERE id = #{sheepId} WHERE id = #{sheepId}
</select> </select>
<!-- 4) 兼容旧 list 查询(返回 domain 对象列表),但在我们的实现中 service 会构造最终的 NpSheepMilkAnalysis 列表 --> <!-- 4) 兼容旧list查询返回domain对象列表但在我们的实现中service会构造最终的NpSheepMilkAnalysis列表 -->
<select id="selectNpSheepMilkAnalysisList" resultType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis" parameterType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis"> <select id="selectNpSheepMilkAnalysisList" resultType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis" parameterType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis">
<!-- 如果你仍需基于某张表的简单映射,可在此实现;当前我们在 ServiceImpl 中组装对象,所以该查询不做复杂实现 --> <!-- 如果你仍需基于某张表的简单映射,可在此实现;当前我们在ServiceImpl中组装对象所以该查询不做复杂实现 -->
SELECT 1 FROM dual WHERE 1=0 SELECT 1 FROM dual WHERE 1=0
</select> </select>
<!-- 5) 导出奶产量分析记录 -->
<select id="selectNpSheepMilkAnalysisForExport" resultType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis" parameterType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis">
<!-- 这里需要根据实际表结构编写SQL查询 -->
<!-- 示例SQL需要根据实际表结构调整 -->
SELECT
sf.id as sheepId,
sf.bs_manage_tags as manageEarTag,
sf.variety,
<!-- 其他字段 -->
FROM sheep_file sf
LEFT JOIN np_milk_prod_classes m ON sf.id = m.sheep_id
<where>
<if test="manageEarTag != null and manageEarTag != ''">
AND sf.bs_manage_tags LIKE CONCAT('%', #{manageEarTag}, '%')
</if>
</where>
GROUP BY sf.id
</select>
</mapper> </mapper>