From 02d95fc51fc98de8a25b4884a47f04b1daa4f8c5 Mon Sep 17 00:00:00 2001 From: HashMap Date: Sun, 24 Aug 2025 23:40:21 +0800 Subject: [PATCH 01/10] =?UTF-8?q?feat(module):=20=E9=A5=B2=E5=96=82?= =?UTF-8?q?=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + 添加量饲喂量统计功能 + 解决了其他两个页面的若干逻辑错误 + 优化了配料清单的缓存结构: + 将缓存和同步过程移动到Service层, 以便其他模块调用 --- .../feed/controller/SgFeedListController.java | 110 +---------- .../controller/SgFeedStatisticController.java | 129 +++++++++++++ .../module/feed/domain/SgFeedStatistic.java | 98 ++++++++++ .../module/feed/domain/SgFormulaList.java | 15 +- .../feed/mapper/SgFeedStatisticMapper.java | 63 +++++++ .../TypeHandler/DaSheepfoldHandler.java | 38 ++++ .../mapper/TypeHandler/JsonTypeHandler.java | 42 +++++ .../TypeHandler/SgFormulaListHandler.java | 37 ++++ .../feed/service/ISgFeedListService.java | 6 +- .../feed/service/ISgFeedStatisticService.java | 65 +++++++ .../service/impl/SgFeedListServiceImpl.java | 126 +++++++++++-- .../impl/SgFeedStatisticServiceImpl.java | 176 ++++++++++++++++++ .../mapper/feed/SgFeedListMapper.xml | 1 + .../mapper/feed/SgFeedStatisticMapper.xml | 100 ++++++++++ 14 files changed, 881 insertions(+), 125 deletions(-) create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedStatisticController.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedStatistic.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedStatisticMapper.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/DaSheepfoldHandler.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/JsonTypeHandler.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/SgFormulaListHandler.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedStatisticService.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedStatisticServiceImpl.java create mode 100644 zhyc-module/src/main/resources/mapper/feed/SgFeedStatisticMapper.xml diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedListController.java b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedListController.java index 446327d..895f061 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedListController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedListController.java @@ -1,15 +1,10 @@ package com.zhyc.module.feed.controller; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.servlet.http.HttpServletResponse; -import com.zhyc.module.feed.domain.SgFeedPlan; -import com.zhyc.module.feed.domain.SgFormulaManagement; -import com.zhyc.module.feed.service.ISgFeedPlanService; -import com.zhyc.module.feed.service.ISgFormulaManagementService; +import com.zhyc.module.feed.service.impl.SgFeedListServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -41,19 +36,12 @@ import com.zhyc.common.core.page.TableDataInfo; public class SgFeedListController extends BaseController { private final ISgFeedListService sgFeedListService; - private final ISgFormulaManagementService sgFormulaManagementService; - - private final ISgFeedPlanService sgFeedPlanService; - - private final Map sgFeedListMap = new HashMap<>(); public static boolean refresh = true; @Autowired - public SgFeedListController(ISgFeedListService sgFeedListService, ISgFormulaManagementService sgFormulaManagementService, ISgFeedPlanService sgFeedPlanService) { + public SgFeedListController(ISgFeedListService sgFeedListService) { this.sgFeedListService = sgFeedListService; - this.sgFormulaManagementService = sgFormulaManagementService; - this.sgFeedPlanService = sgFeedPlanService; } /** @@ -68,7 +56,7 @@ public class SgFeedListController extends BaseController { 当配方管理表出现更新 或 饲喂计划表出现增删改时会将refresh置为true 通知此处进行刷新 */ if (refresh) { - SyncFeedList(); + sgFeedListService.SyncFeedList(); refresh = false; } startPage(); @@ -78,7 +66,7 @@ public class SgFeedListController extends BaseController { for (SgFeedList item : list) { String key = item.getFormulaId() + "_" + item.getFormulaBatchId(); // 从缓存中取出完整对象 - SgFeedList itemInCache = sgFeedListMap.getOrDefault(key, item); + SgFeedList itemInCache = SgFeedListServiceImpl.getSgFeedListMap().getOrDefault(key, item); // 将数据库查询的基本信息替换掉缓存中去除的内容 - 前端展示与修改需要 itemInCache.setId(item.getId()); itemInCache.setFormulaBatchId(item.getFormulaBatchId()); @@ -143,94 +131,4 @@ public class SgFeedListController extends BaseController { return toAjax(sgFeedListService.deleteSgFeedListByIds(ids)); } - - public void SyncFeedList() { - // 清空旧缓存 - sgFeedListMap.clear(); - // 获取配方管理和现有配料清单内容 - List formulaManagementList = sgFormulaManagementService.selectSgFormulaManagementList(new SgFormulaManagement()); - List feedLists = sgFeedListService.selectSgFeedListList(new SgFeedList()); - // 将最新查询的配料清单加入缓存 - for (SgFeedList sgFeedList : feedLists) { - sgFeedListMap.put(sgFeedList.getFormulaId() + "_" + sgFeedList.getFormulaBatchId(), sgFeedList); - } - // 与新的配方管理列表同步 - 如果配料清单没有对应数据则加入 - for (SgFormulaManagement sgFormulaManagement : formulaManagementList) { - // 匹配 但忽略模板配方 - if (sgFormulaManagement.getFormulaId() != null && sgFormulaManagement.getBatchId() != null && !sgFormulaManagement.getBatchId().equals("0")) { - // 查询当前配方管理项是否存在现有配料计划中 (不论是否存在都要设置,因为缓存被清空,存在则更新,不存在则插入) - boolean isExist = sgFeedListMap.containsKey(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId()); - // 标志位 : 如果当前配方不在饲喂计划中则不生成配量清单 - boolean isPlan = true; - // 设置缓存对象具体值 - SgFeedList sgFeedList = new SgFeedList(); - sgFeedList.setFormulaId(sgFormulaManagement.getFormulaId()); - sgFeedList.setFormulaBatchId(sgFormulaManagement.getBatchId()); - sgFeedList.setFormulaList(sgFormulaManagement.getSgFormulaList()); - sgFeedList.setRootFormula(sgFormulaManagement); - - - // 从饲喂计划列表中查出对应值(饲喂量需要计划中的比例计算) - SgFeedPlan rootPlanQuery = new SgFeedPlan(); - rootPlanQuery.setFormulaId(sgFormulaManagement.getFormulaId()); - rootPlanQuery.setBatchId(sgFormulaManagement.getBatchId()); - List sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(rootPlanQuery); - // 为空则标识当前配方不在饲喂计划中 && 不在缓存中设置 - if (sgFeedPlans.isEmpty()) { - isPlan = false; - } else { - // rootPlan中存储的是该配方批号的总量 - SgFeedPlan rootPlan = computePlanTotal(sgFeedPlans); - - // 将计划实体对象设置到配料清单中 - sgFeedList.setRootPlan(rootPlan); - - // 完整的配料清单对象加入缓存 - sgFeedListMap.put(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId(), sgFeedList); - } - - // 不存在则插入 - if (!isExist && isPlan) { - sgFeedListService.insertSgFeedList(sgFeedList); - } - } - } - } - - /** - * 计算某个配方某个批次的总和值 - * - * @param sgFeedPlans 配方计划列表 - * @return 各个值总和 - */ - private static SgFeedPlan computePlanTotal(List sgFeedPlans) { - SgFeedPlan rootPlan = new SgFeedPlan(); - if (!sgFeedPlans.isEmpty()) { - int sheepCountTotal = 0; - double sheepDailySize = 0.0; - double planFeedMorningSize = 0.0; - double planFeedNoonSize = 0.0; - double planFeedAfternoonSize = 0.0; - double planFeedTotalSize = 0.0; - for (SgFeedPlan sgFeedPlan : sgFeedPlans) { - sheepCountTotal += sgFeedPlan.getSheepCount(); - sheepDailySize += sgFeedPlan.getPlanDailySize(); - planFeedMorningSize += sgFeedPlan.getPlanMorningSize(); - planFeedNoonSize += sgFeedPlan.getPlanNoonSize(); - planFeedAfternoonSize += sgFeedPlan.getPlanAfternoonSize(); - planFeedTotalSize += sgFeedPlan.getPlanFeedTotal(); - } - - rootPlan.setSheepCount(sheepCountTotal); - rootPlan.setPlanDailySize(sheepDailySize); - rootPlan.setPlanMorningSize(planFeedMorningSize); - rootPlan.setPlanNoonSize(planFeedNoonSize); - rootPlan.setPlanAfternoonSize(planFeedAfternoonSize); - rootPlan.setPlanFeedTotal(planFeedTotalSize); - - // 设置计划日期 - rootPlan.setPlanDate(sgFeedPlans.get(0).getPlanDate()); - } - return rootPlan; - } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedStatisticController.java b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedStatisticController.java new file mode 100644 index 0000000..de0334f --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedStatisticController.java @@ -0,0 +1,129 @@ +package com.zhyc.module.feed.controller; + +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import com.zhyc.common.utils.uuid.UUID; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.zhyc.common.annotation.Log; +import com.zhyc.common.core.controller.BaseController; +import com.zhyc.common.core.domain.AjaxResult; +import com.zhyc.common.enums.BusinessType; +import com.zhyc.module.feed.domain.SgFeedStatistic; +import com.zhyc.module.feed.service.ISgFeedStatisticService; +import com.zhyc.common.utils.poi.ExcelUtil; +import com.zhyc.common.core.page.TableDataInfo; + +/** + * 饲喂量统计Controller + * + * @author HashMap + * @date 2025-08-23 + */ +@RestController +@RequestMapping("/feed/FeedStatistic") +@Transactional(rollbackFor = Exception.class) +public class SgFeedStatisticController extends BaseController { + private final ISgFeedStatisticService sgFeedStatisticService; + + + + public SgFeedStatisticController(ISgFeedStatisticService sgFeedStatisticService) { + this.sgFeedStatisticService = sgFeedStatisticService; + } + + /** + * 查询饲喂量统计列表 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:list')") + @GetMapping("/list") + public TableDataInfo list(SgFeedStatistic sgFeedStatistic) { + startPage(); + List list = sgFeedStatisticService.selectSgFeedStatisticList(sgFeedStatistic); + return getDataTable(list); + } + + /** + * 导出饲喂量统计列表 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:export')") + @Log(title = "饲喂量统计", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SgFeedStatistic sgFeedStatistic) { + List list = sgFeedStatisticService.selectSgFeedStatisticList(sgFeedStatistic); + ExcelUtil util = new ExcelUtil<>(SgFeedStatistic.class); + util.exportExcel(response, list, "饲喂量统计数据"); + } + + /** + * 获取饲喂量统计详细信息 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") String id) { + return success(sgFeedStatisticService.selectSgFeedStatisticById(id)); + } + + /** + * 新增饲喂量统计 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:add')") + @Log(title = "饲喂量统计", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SgFeedStatistic sgFeedStatistic) { + if (null == sgFeedStatistic.getFormulaId() && null == sgFeedStatistic.getFormulaBatchId()) { + throw new RuntimeException("ERROR: 数据为空"); + } + List isExist = sgFeedStatisticService.selectSgFeedStatisticList(sgFeedStatistic); + if (null != isExist && !isExist.isEmpty()) { + throw new RuntimeException("WARNING: 数据重复"); + } + // 设定唯一标识符主键 + sgFeedStatistic.setId(UUID.randomUUID().toString()); + /* + * 初始化数据 + * 弃用: 此处不再需要初始化,前端选定批号后会触发预载, 此处再初始化会覆盖前端后续的自定义数据 + */ + // sgFeedStatisticService.getInitSgFeedStatistic(sgFeedStatistic); + return toAjax(sgFeedStatisticService.insertSgFeedStatistic(sgFeedStatistic)); + } + + /** + * 修改饲喂量统计 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:edit')") + @Log(title = "饲喂量统计", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SgFeedStatistic sgFeedStatistic) { + return toAjax(sgFeedStatisticService.updateSgFeedStatistic(sgFeedStatistic)); + } + + /** + * 删除饲喂量统计 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:remove')") + @Log(title = "饲喂量统计", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable String[] ids) { + return toAjax(sgFeedStatisticService.deleteSgFeedStatisticByIds(ids)); + } + + @GetMapping("/init") + public TableDataInfo getInitData(SgFeedStatistic sgFeedStatistic){ + sgFeedStatisticService.getInitSgFeedStatistic(sgFeedStatistic); + // 兼容写法 - 实际只是为了返回一个 sgFeedStatistic + List list = new ArrayList<>(); + list.add(sgFeedStatistic); + return getDataTable(list); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedStatistic.java b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedStatistic.java new file mode 100644 index 0000000..2cdc21e --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedStatistic.java @@ -0,0 +1,98 @@ +package com.zhyc.module.feed.domain; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.zhyc.module.base.domain.DaSheepfold; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.zhyc.common.annotation.Excel; +import com.zhyc.common.core.domain.BaseEntity; + +import java.util.Date; +import java.util.List; + +/** + * 饲喂量统计对象 sg_feed_statistic + * + * @author HashMap + * @date 2025-08-23 + */ +@Setter +@Getter +public class SgFeedStatistic extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * UUID + */ + private String id; + + /** + * 配方编号 + */ + @Excel(name = "配方编号") + private String formulaId; + + /** + * 配方批号 + */ + @Excel(name = "配方批号") + private String formulaBatchId; + + /** + * 羊只数量 + */ + @Excel(name = "羊只数量") + private Long sheepFoldCount; + + /** + * 青贮损耗比例 + */ + @Excel(name = "青贮损耗比例") + private String silageLossRate; + + /** + * 总饲喂量 + */ + @Excel(name = "总饲喂量") + private Double feedTotalSize; + + /** + * 日均饲喂量 + */ + @Excel(name = "日均饲喂量") + private Double feedDailySize; + + /** + * 配方列表 + */ + @Excel(name = "配方列表") + private List materialList; + + /** + * 羊舍列表 + */ + @Excel(name = "羊舍列表") + private List sheepFoldList; + + @Excel(name = "日期") + @JsonFormat(pattern = "yyyy-MM-dd") + private Date feedDate; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("formulaId", getFormulaId()) + .append("formulaBatchId", getFormulaBatchId()) + .append("sheepFoldCount", getSheepFoldCount()) + .append("silageLossRate", getSilageLossRate()) + .append("feedTotalSize", getFeedTotalSize()) + .append("feedDailySize", getFeedDailySize()) + .append("materialList", getMaterialList()) + .append("sheepFoldList", getSheepFoldList()) + .toString(); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFormulaList.java b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFormulaList.java index 03ab542..aac1fc9 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFormulaList.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFormulaList.java @@ -39,14 +39,25 @@ public class SgFormulaList extends BaseEntity @Excel(name = "比例") private Long ratio; - /** 颗粒原料 */ + /** + * 颗粒原料 + * 当前不局限于 "是否颗粒原料" 而且多种类型的标识符 + */ @Excel(name = "颗粒原料") private String isGranular; - /** 补饲 */ + /** + * 补饲 + * 当前用作饲喂类型标识 + */ @Excel(name = "补饲") private String isSupplement; + /** + * 添加量 - 供其他一些统计模块使用 + */ + private Double feedSize; + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedStatisticMapper.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedStatisticMapper.java new file mode 100644 index 0000000..abee631 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedStatisticMapper.java @@ -0,0 +1,63 @@ +package com.zhyc.module.feed.mapper; + +import java.util.List; +import com.zhyc.module.feed.domain.SgFeedStatistic; +import org.apache.ibatis.annotations.Mapper; + +/** + * 饲喂量统计Mapper接口 + * + * @author HashMap + * @date 2025-08-23 + */ +@Mapper +public interface SgFeedStatisticMapper +{ + /** + * 查询饲喂量统计 + * + * @param id 饲喂量统计主键 + * @return 饲喂量统计 + */ + SgFeedStatistic selectSgFeedStatisticById(String id); + + /** + * 查询饲喂量统计列表 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 饲喂量统计集合 + */ + List selectSgFeedStatisticList(SgFeedStatistic sgFeedStatistic); + + /** + * 新增饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + int insertSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + /** + * 修改饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + int updateSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + /** + * 删除饲喂量统计 + * + * @param id 饲喂量统计主键 + * @return 结果 + */ + int deleteSgFeedStatisticById(String id); + + /** + * 批量删除饲喂量统计 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + int deleteSgFeedStatisticByIds(String[] ids); +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/DaSheepfoldHandler.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/DaSheepfoldHandler.java new file mode 100644 index 0000000..af89abc --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/DaSheepfoldHandler.java @@ -0,0 +1,38 @@ +package com.zhyc.module.feed.mapper.TypeHandler; + +import com.alibaba.fastjson2.JSON; +import com.zhyc.module.base.domain.DaSheepfold; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +@MappedTypes(List.class) +public class DaSheepfoldHandler extends BaseTypeHandler> { + @Override + public void setNonNullParameter(PreparedStatement ps, int i, + List parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, JSON.toJSONString(parameter)); + } + + @Override + public List getNullableResult(ResultSet rs, String columnName) throws SQLException { + return JSON.parseArray(rs.getString(columnName), DaSheepfold.class); + } + + @Override + public List getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + return JSON.parseArray(rs.getString(columnIndex), DaSheepfold.class); + } + + @Override + public List getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + return JSON.parseArray(cs.getString(columnIndex), DaSheepfold.class); + } +} + diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/JsonTypeHandler.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/JsonTypeHandler.java new file mode 100644 index 0000000..dd0d22f --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/JsonTypeHandler.java @@ -0,0 +1,42 @@ +package com.zhyc.module.feed.mapper.TypeHandler; + +import com.alibaba.fastjson2.JSON; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class JsonTypeHandler extends BaseTypeHandler { + private final Class type; + + public JsonTypeHandler(Class type) { + this.type = type; + } + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, JSON.toJSONString(parameter)); + } + + @Override + public T getNullableResult(ResultSet rs, String columnName) throws SQLException { + String json = rs.getString(columnName); + return JSON.parseObject(json, type); + } + + @Override + public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + String json = rs.getString(columnIndex); + return JSON.parseObject(json, type); + } + + @Override + public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + String json = cs.getString(columnIndex); + return JSON.parseObject(json, type); + } +} + diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/SgFormulaListHandler.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/SgFormulaListHandler.java new file mode 100644 index 0000000..10d857b --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/SgFormulaListHandler.java @@ -0,0 +1,37 @@ +package com.zhyc.module.feed.mapper.TypeHandler; + +import com.alibaba.fastjson2.JSON; +import com.zhyc.module.feed.domain.SgFormulaList; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +@MappedTypes(List.class) +public class SgFormulaListHandler extends BaseTypeHandler> { + @Override + public void setNonNullParameter(PreparedStatement ps, int i, + List parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, JSON.toJSONString(parameter)); + } + + @Override + public List getNullableResult(ResultSet rs, String columnName) throws SQLException { + return JSON.parseArray(rs.getString(columnName), SgFormulaList.class); + } + + @Override + public List getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + return JSON.parseArray(rs.getString(columnIndex), SgFormulaList.class); + } + + @Override + public List getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + return JSON.parseArray(cs.getString(columnIndex), SgFormulaList.class); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedListService.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedListService.java index b293d84..b3c5a5f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedListService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedListService.java @@ -1,6 +1,7 @@ package com.zhyc.module.feed.service; import java.util.List; + import com.zhyc.module.feed.domain.SgFeedList; /** @@ -9,8 +10,7 @@ import com.zhyc.module.feed.domain.SgFeedList; * @author HashMap * @date 2025-08-19 */ -public interface ISgFeedListService -{ +public interface ISgFeedListService { /** * 查询配料清单 * @@ -58,4 +58,6 @@ public interface ISgFeedListService * @return 结果 */ int deleteSgFeedListById(Long id); + + void SyncFeedList(); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedStatisticService.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedStatisticService.java new file mode 100644 index 0000000..9bdad7a --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedStatisticService.java @@ -0,0 +1,65 @@ +package com.zhyc.module.feed.service; + +import java.util.List; +import com.zhyc.module.feed.domain.SgFeedStatistic; + +/** + * 饲喂量统计Service接口 + * + * @author HashMap + * @date 2025-08-23 + */ +public interface ISgFeedStatisticService +{ + /** + * 查询饲喂量统计 + * + * @param id 饲喂量统计主键 + * @return 饲喂量统计 + */ + SgFeedStatistic selectSgFeedStatisticById(String id); + + /** + * 查询饲喂量统计列表 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 饲喂量统计集合 + */ + List selectSgFeedStatisticList(SgFeedStatistic sgFeedStatistic); + + /** + * 新增饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + int insertSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + /** + * 修改饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + int updateSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + /** + * 批量删除饲喂量统计 + * + * @param ids 需要删除的饲喂量统计主键集合 + * @return 结果 + */ + int deleteSgFeedStatisticByIds(String[] ids); + + /** + * 删除饲喂量统计信息 + * + * @param id 饲喂量统计主键 + * @return 结果 + */ + int deleteSgFeedStatisticById(String id); + + void getInitSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedListServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedListServiceImpl.java index 704d45d..225d851 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedListServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedListServiceImpl.java @@ -1,7 +1,14 @@ package com.zhyc.module.feed.service.impl; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import com.zhyc.module.feed.domain.SgFeedPlan; +import com.zhyc.module.feed.domain.SgFormulaManagement; +import com.zhyc.module.feed.service.ISgFeedPlanService; +import com.zhyc.module.feed.service.ISgFormulaManagementService; +import lombok.Getter; import org.springframework.stereotype.Service; import com.zhyc.module.feed.mapper.SgFeedListMapper; import com.zhyc.module.feed.domain.SgFeedList; @@ -14,12 +21,17 @@ import com.zhyc.module.feed.service.ISgFeedListService; * @date 2025-08-19 */ @Service -public class SgFeedListServiceImpl implements ISgFeedListService -{ +public class SgFeedListServiceImpl implements ISgFeedListService { private final SgFeedListMapper sgFeedListMapper; + private final ISgFormulaManagementService sgFormulaManagementService; + private final ISgFeedPlanService sgFeedPlanService; + @Getter + private final static Map sgFeedListMap = new HashMap<>(); - public SgFeedListServiceImpl(SgFeedListMapper sgFeedListMapper) { + public SgFeedListServiceImpl(SgFeedListMapper sgFeedListMapper, ISgFormulaManagementService sgFormulaManagementService, ISgFeedPlanService sgFeedPlanService) { this.sgFeedListMapper = sgFeedListMapper; + this.sgFormulaManagementService = sgFormulaManagementService; + this.sgFeedPlanService = sgFeedPlanService; } /** @@ -29,8 +41,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 配料清单 */ @Override - public SgFeedList selectSgFeedListById(Long id) - { + public SgFeedList selectSgFeedListById(Long id) { return sgFeedListMapper.selectSgFeedListById(id); } @@ -41,8 +52,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 配料清单 */ @Override - public List selectSgFeedListList(SgFeedList sgFeedList) - { + public List selectSgFeedListList(SgFeedList sgFeedList) { return sgFeedListMapper.selectSgFeedListList(sgFeedList); } @@ -53,8 +63,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 结果 */ @Override - public int insertSgFeedList(SgFeedList sgFeedList) - { + public int insertSgFeedList(SgFeedList sgFeedList) { return sgFeedListMapper.insertSgFeedList(sgFeedList); } @@ -65,8 +74,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 结果 */ @Override - public int updateSgFeedList(SgFeedList sgFeedList) - { + public int updateSgFeedList(SgFeedList sgFeedList) { return sgFeedListMapper.updateSgFeedList(sgFeedList); } @@ -77,8 +85,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 结果 */ @Override - public int deleteSgFeedListByIds(Long[] ids) - { + public int deleteSgFeedListByIds(Long[] ids) { return sgFeedListMapper.deleteSgFeedListByIds(ids); } @@ -89,8 +96,97 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 结果 */ @Override - public int deleteSgFeedListById(Long id) - { + public int deleteSgFeedListById(Long id) { return sgFeedListMapper.deleteSgFeedListById(id); } + + public void SyncFeedList() { + // 清空旧缓存 + sgFeedListMap.clear(); + // 获取配方管理和现有配料清单内容 + List formulaManagementList = sgFormulaManagementService.selectSgFormulaManagementList(new SgFormulaManagement()); + List feedLists = this.selectSgFeedListList(new SgFeedList()); + // 将最新查询的配料清单加入缓存 + for (SgFeedList sgFeedList : feedLists) { + sgFeedListMap.put(sgFeedList.getFormulaId() + "_" + sgFeedList.getFormulaBatchId(), sgFeedList); + } + // 与新的配方管理列表同步 - 如果配料清单没有对应数据则加入 + for (SgFormulaManagement sgFormulaManagement : formulaManagementList) { + // 匹配 但忽略模板配方 + if (sgFormulaManagement.getFormulaId() != null && sgFormulaManagement.getBatchId() != null && !sgFormulaManagement.getBatchId().equals("0")) { + // 查询当前配方管理项是否存在现有配料计划中 (不论是否存在都要设置,因为缓存被清空,存在则更新,不存在则插入) + boolean isExist = sgFeedListMap.containsKey(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId()); + // 标志位 : 如果当前配方不在饲喂计划中则不生成配量清单 + boolean isPlan = true; + // 设置缓存对象具体值 + SgFeedList sgFeedList = new SgFeedList(); + sgFeedList.setFormulaId(sgFormulaManagement.getFormulaId()); + sgFeedList.setFormulaBatchId(sgFormulaManagement.getBatchId()); + sgFeedList.setFormulaList(sgFormulaManagement.getSgFormulaList()); + sgFeedList.setRootFormula(sgFormulaManagement); + + + // 从饲喂计划列表中查出对应值(饲喂量需要计划中的比例计算) + SgFeedPlan rootPlanQuery = new SgFeedPlan(); + rootPlanQuery.setFormulaId(sgFormulaManagement.getFormulaId()); + rootPlanQuery.setBatchId(sgFormulaManagement.getBatchId()); + List sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(rootPlanQuery); + // 为空则标识当前配方不在饲喂计划中 && 不在缓存中设置 + if (sgFeedPlans.isEmpty()) { + isPlan = false; + } else { + // rootPlan中存储的是该配方批号的总量 + SgFeedPlan rootPlan = computePlanTotal(sgFeedPlans); + + // 将计划实体对象设置到配料清单中 + sgFeedList.setRootPlan(rootPlan); + + // 完整的配料清单对象加入缓存 + sgFeedListMap.put(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId(), sgFeedList); + } + + // 不存在则插入 + if (!isExist && isPlan) { + this.insertSgFeedList(sgFeedList); + } + } + } + } + + /** + * 计算某个配方某个批次的总和值 + * + * @param sgFeedPlans 配方计划列表 + * @return 各个值总和 + */ + private static SgFeedPlan computePlanTotal(List sgFeedPlans) { + SgFeedPlan rootPlan = new SgFeedPlan(); + if (!sgFeedPlans.isEmpty()) { + int sheepCountTotal = 0; + double sheepDailySize = 0.0; + double planFeedMorningSize = 0.0; + double planFeedNoonSize = 0.0; + double planFeedAfternoonSize = 0.0; + double planFeedTotalSize = 0.0; + for (SgFeedPlan sgFeedPlan : sgFeedPlans) { + sheepCountTotal += sgFeedPlan.getSheepCount(); + sheepDailySize += sgFeedPlan.getPlanDailySize(); + planFeedMorningSize += sgFeedPlan.getPlanMorningSize(); + planFeedNoonSize += sgFeedPlan.getPlanNoonSize(); + planFeedAfternoonSize += sgFeedPlan.getPlanAfternoonSize(); + planFeedTotalSize += sgFeedPlan.getPlanFeedTotal(); + } + + rootPlan.setSheepCount(sheepCountTotal); + rootPlan.setPlanDailySize(sheepDailySize); + rootPlan.setPlanMorningSize(planFeedMorningSize); + rootPlan.setPlanNoonSize(planFeedNoonSize); + rootPlan.setPlanAfternoonSize(planFeedAfternoonSize); + rootPlan.setPlanFeedTotal(planFeedTotalSize); + + // 设置计划日期 + rootPlan.setPlanDate(sgFeedPlans.get(0).getPlanDate()); + } + return rootPlan; + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedStatisticServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedStatisticServiceImpl.java new file mode 100644 index 0000000..b1766bd --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedStatisticServiceImpl.java @@ -0,0 +1,176 @@ +package com.zhyc.module.feed.service.impl; + +import java.util.List; +import java.util.stream.Collectors; + +import com.zhyc.module.base.domain.DaSheepfold; +import com.zhyc.module.feed.domain.SgFeedList; +import com.zhyc.module.feed.domain.SgFeedPlan; +import com.zhyc.module.feed.domain.SgFormulaList; +import com.zhyc.module.feed.service.ISgFeedListService; +import com.zhyc.module.feed.service.ISgFeedPlanService; +import org.springframework.stereotype.Service; +import com.zhyc.module.feed.mapper.SgFeedStatisticMapper; +import com.zhyc.module.feed.domain.SgFeedStatistic; +import com.zhyc.module.feed.service.ISgFeedStatisticService; + +/** + * 饲喂量统计Service业务层处理 + * + * @author HashMap + * @date 2025-08-23 + */ +@Service +public class SgFeedStatisticServiceImpl implements ISgFeedStatisticService { + private final SgFeedStatisticMapper sgFeedStatisticMapper; + + private final ISgFeedListService sgFeedListService; + private final ISgFeedPlanService sgFeedPlanService; + + public SgFeedStatisticServiceImpl(SgFeedStatisticMapper sgFeedStatisticMapper, ISgFeedListService sgFeedListService, ISgFeedPlanService sgFeedPlanService) { + this.sgFeedStatisticMapper = sgFeedStatisticMapper; + this.sgFeedListService = sgFeedListService; + this.sgFeedPlanService = sgFeedPlanService; + } + + /** + * 查询饲喂量统计 + * + * @param id 饲喂量统计主键 + * @return 饲喂量统计 + */ + @Override + public SgFeedStatistic selectSgFeedStatisticById(String id) { + return sgFeedStatisticMapper.selectSgFeedStatisticById(id); + } + + /** + * 查询饲喂量统计列表 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 饲喂量统计 + */ + @Override + public List selectSgFeedStatisticList(SgFeedStatistic sgFeedStatistic) { + return sgFeedStatisticMapper.selectSgFeedStatisticList(sgFeedStatistic); + } + + /** + * 新增饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + @Override + public int insertSgFeedStatistic(SgFeedStatistic sgFeedStatistic) { + return sgFeedStatisticMapper.insertSgFeedStatistic(sgFeedStatistic); + } + + /** + * 修改饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + @Override + public int updateSgFeedStatistic(SgFeedStatistic sgFeedStatistic) { + return sgFeedStatisticMapper.updateSgFeedStatistic(sgFeedStatistic); + } + + /** + * 批量删除饲喂量统计 + * + * @param ids 需要删除的饲喂量统计主键 + * @return 结果 + */ + @Override + public int deleteSgFeedStatisticByIds(String[] ids) { + return sgFeedStatisticMapper.deleteSgFeedStatisticByIds(ids); + } + + /** + * 删除饲喂量统计信息 + * + * @param id 饲喂量统计主键 + * @return 结果 + */ + @Override + public int deleteSgFeedStatisticById(String id) { + return sgFeedStatisticMapper.deleteSgFeedStatisticById(id); + } + + /** + * 向待插入数据表单提供数据预载服务 + * + * @param sgFeedStatistic 待填充的初始化数据 + * @author ShiHan Wang + */ + @Override + public void getInitSgFeedStatistic(SgFeedStatistic sgFeedStatistic) { + // 1. 查找饲料清单 + SgFeedList sgFeedListQuery = new SgFeedList(); + sgFeedListQuery.setFormulaId(sgFeedStatistic.getFormulaId()); + sgFeedListQuery.setFormulaBatchId(sgFeedStatistic.getFormulaBatchId()); + + List feedLists = sgFeedListService.selectSgFeedListList(sgFeedListQuery); + + if (!feedLists.isEmpty()) { + // 刷新缓存 + sgFeedListService.SyncFeedList(); + + // 从缓存获取完整配方清单 + String cacheKey = sgFeedStatistic.getFormulaId() + "_" + sgFeedStatistic.getFormulaBatchId(); + SgFeedList sgFeedList = SgFeedListServiceImpl.getSgFeedListMap().get(cacheKey); + + if (sgFeedList != null && sgFeedList.getFormulaList() != null) { + // 并行流式计算 提高性能 + sgFeedList.getFormulaList().parallelStream().forEach(item -> { + double ratio = item.getRatio() / 100.0; + double feedSize = sgFeedList.getRootPlan().getPlanMorningSize() * ratio + + sgFeedList.getRootPlan().getPlanNoonSize() * ratio + + sgFeedList.getRootPlan().getPlanAfternoonSize() * ratio; + item.setFeedSize(feedSize); + }); + + // 统计总和 + double totalFeedSize = sgFeedList.getFormulaList() + .parallelStream() + .mapToDouble(SgFormulaList::getFeedSize) + .sum(); + sgFeedStatistic.setMaterialList(sgFeedList.getFormulaList()); + sgFeedStatistic.setFeedTotalSize(totalFeedSize); + } else { + throw new RuntimeException("WARNING: 原料数据为空"); + } + } + + // 2. 查找饲喂计划并填充羊舍信息 + SgFeedPlan sgFeedPlanQuery = new SgFeedPlan(); + sgFeedPlanQuery.setFormulaId(sgFeedStatistic.getFormulaId()); + sgFeedPlanQuery.setBatchId(sgFeedStatistic.getFormulaBatchId()); + + List sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(sgFeedPlanQuery); + + if (!sgFeedPlans.isEmpty()) { + // 并行计算提高查询性能 + List sheepfolds = sgFeedPlans.parallelStream() + .map(plan -> { + DaSheepfold sheepfold = new DaSheepfold(); + sheepfold.setId((long) plan.getSheepHouseId()); + return sheepfold; + }) + .collect(Collectors.toList()); + + long sheepCount = sgFeedPlans.parallelStream() + .mapToLong(SgFeedPlan::getSheepCount) + .sum(); + sgFeedStatistic.setSheepFoldList(sheepfolds); + sgFeedStatistic.setSheepFoldCount(sheepCount); + // 计算日均饲喂量 + sgFeedStatistic.setFeedDailySize(sgFeedStatistic.getFeedTotalSize() / sgFeedStatistic.getSheepFoldCount()); + } else { + throw new RuntimeException("WARNING: 不存在该计划"); + } + } + +} diff --git a/zhyc-module/src/main/resources/mapper/feed/SgFeedListMapper.xml b/zhyc-module/src/main/resources/mapper/feed/SgFeedListMapper.xml index 25e0143..0c10e17 100644 --- a/zhyc-module/src/main/resources/mapper/feed/SgFeedListMapper.xml +++ b/zhyc-module/src/main/resources/mapper/feed/SgFeedListMapper.xml @@ -20,6 +20,7 @@ and formula_id = #{formulaId} + and formula_batch_id = #{formulaBatchId} and zookeeper = #{zookeeper} and deploy_date = #{deployDate} diff --git a/zhyc-module/src/main/resources/mapper/feed/SgFeedStatisticMapper.xml b/zhyc-module/src/main/resources/mapper/feed/SgFeedStatisticMapper.xml new file mode 100644 index 0000000..0bd9657 --- /dev/null +++ b/zhyc-module/src/main/resources/mapper/feed/SgFeedStatisticMapper.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + select id, formula_id, formula_batch_id, sheep_fold_count, silage_loss_rate, feed_total_size, feed_daily_size, material_list, sheep_fold_list,feed_date from sg_feed_statistic + + + + + + + + insert into sg_feed_statistic + + id, + formula_id, + formula_batch_id, + sheep_fold_count, + silage_loss_rate, + feed_total_size, + feed_daily_size, + material_list, + sheep_fold_list, + feed_date, + + + #{id}, + #{formulaId}, + #{formulaBatchId}, + #{sheepFoldCount}, + #{silageLossRate}, + #{feedTotalSize}, + #{feedDailySize}, +# 写入操作需要手动指定 TypeHandler 参数 + #{materialList, typeHandler=com.zhyc.module.feed.mapper.TypeHandler.SgFormulaListHandler}, + #{sheepFoldList, typeHandler=com.zhyc.module.feed.mapper.TypeHandler.DaSheepfoldHandler}, + #{feedDate}, + + + + + update sg_feed_statistic + + formula_id = #{formulaId}, + formula_batch_id = #{formulaBatchId}, + sheep_fold_count = #{sheepFoldCount}, + silage_loss_rate = #{silageLossRate}, + feed_total_size = #{feedTotalSize}, + feed_daily_size = #{feedDailySize}, + material_list = #{materialList, typeHandler=com.zhyc.module.feed.mapper.TypeHandler.SgFormulaListHandler}, + sheep_fold_list = #{sheepFoldList, typeHandler=com.zhyc.module.feed.mapper.TypeHandler.DaSheepfoldHandler}, + feed_date = #{feedDate}, + + where id = #{id} + + + + delete from sg_feed_statistic where id = #{id} + + + + delete from sg_feed_statistic where id in + + #{id} + + + \ No newline at end of file From a04ccfa5cf89189a41683175c5bd4fe2caa3e72d Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Mon, 25 Aug 2025 16:33:58 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E9=9C=80=E6=B1=82=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XzParityCorrectionController.java | 20 +- .../domain/XzParityCorrection.java | 46 +- .../mapper/XzParityCorrectionMapper.java | 4 +- .../service/IXzParityCorrectionService.java | 3 +- .../XzDryMatterCorrectionServiceImpl.java | 49 +- .../impl/XzParityCorrectionServiceImpl.java | 5 +- .../impl/XzWegihCorrectionServiceImpl.java | 48 +- .../controller/SxSheepSaleController.java | 117 ++++ .../module/sale/domain/SxCustomerExport.java | 49 ++ .../zhyc/module/sale/domain/SxSheepSale.java | 545 ++++++++++++++++++ .../module/sale/mapper/SxSheepSaleMapper.java | 68 +++ .../sale/service/ISxSheepSaleService.java | 67 +++ .../service/impl/SxSheepSaleServiceImpl.java | 194 +++++++ .../XzDryMatterCorrectionMapper.xml | 19 +- .../mapper/sale/SxSheepSaleMapper.xml | 207 +++++++ 15 files changed, 1389 insertions(+), 52 deletions(-) create mode 100644 zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomerExport.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/sale/mapper/SxSheepSaleMapper.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/sale/service/ISxSheepSaleService.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java create mode 100644 zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java index ee52381..8b1869f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java @@ -25,7 +25,7 @@ import com.zhyc.common.core.page.TableDataInfo; * 胎次校正Controller * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ @RestController @RequestMapping("/parityCorrection/parityCorrection") @@ -38,20 +38,12 @@ public class XzParityCorrectionController extends BaseController * 查询胎次校正列表 */ @PreAuthorize("@ss.hasPermi('parityCorrection:parityCorrection:list')") -// @GetMapping("/list") -// public TableDataInfo list(XzParityCorrection xzParityCorrection) -// { -// startPage(); -// List list = xzParityCorrectionService.selectXzParityCorrectionList(xzParityCorrection); -// return getDataTable(list); -// } - /** - * 获取全部胎次校正(无需分页,供下拉/列表直接显示) - */ - @GetMapping("/listAll") - public AjaxResult listAll(XzParityCorrection xzParityCorrection){ + @GetMapping("/list") + public TableDataInfo list(XzParityCorrection xzParityCorrection) + { + startPage(); List list = xzParityCorrectionService.selectXzParityCorrectionList(xzParityCorrection); - return success(list); // 直接返回数组 + return getDataTable(list); } /** diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java index d1a93e6..9d803a6 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java @@ -1,8 +1,5 @@ package com.zhyc.module.dairyProducts.domain; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.zhyc.common.annotation.Excel; @@ -12,11 +9,8 @@ import com.zhyc.common.core.domain.BaseEntity; * 胎次校正对象 xz_parity_correction * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ -@Data -@NoArgsConstructor -@AllArgsConstructor public class XzParityCorrection extends BaseEntity { private static final long serialVersionUID = 1L; @@ -32,4 +26,42 @@ public class XzParityCorrection extends BaseEntity @Excel(name = "系数") private Double coef; + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setParity(Integer parity) + { + this.parity = parity; + } + + public Integer getParity() + { + return parity; + } + + public void setCoef(Double coef) + { + this.coef = coef; + } + + public Double getCoef() + { + return coef; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("parity", getParity()) + .append("coef", getCoef()) + .toString(); + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java index d2f4654..f6d1f12 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java @@ -2,15 +2,13 @@ package com.zhyc.module.dairyProducts.mapper; import java.util.List; import com.zhyc.module.dairyProducts.domain.XzParityCorrection; -import org.apache.ibatis.annotations.Mapper; /** * 胎次校正Mapper接口 * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ -@Mapper public interface XzParityCorrectionMapper { /** diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java index d5c9ce2..f7acf95 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java @@ -1,14 +1,13 @@ package com.zhyc.module.dairyProducts.service; import java.util.List; - import com.zhyc.module.dairyProducts.domain.XzParityCorrection; /** * 胎次校正Service接口 * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ public interface IXzParityCorrectionService { diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzDryMatterCorrectionServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzDryMatterCorrectionServiceImpl.java index 4bf9fb2..88894c8 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzDryMatterCorrectionServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzDryMatterCorrectionServiceImpl.java @@ -44,29 +44,62 @@ public class XzDryMatterCorrectionServiceImpl implements IXzDryMatterCorrectionS } /** - * 新增干物质校正 - * - * @param xzDryMatterCorrection 干物质校正 - * @return 结果 + * 新增干物质校正 - 添加默认值和重复校验 */ @Override public int insertXzDryMatterCorrection(XzDryMatterCorrection xzDryMatterCorrection) { + // 设置干物质标准默认值为18(如果未提供) + if (xzDryMatterCorrection.getStandard() == null) { + xzDryMatterCorrection.setStandard(18.0); + } + + // 检查同年月同厂区是否已存在 + if (isDuplicateRecord(xzDryMatterCorrection)) { + throw new RuntimeException("该厂区在同一年月已存在记录,不能重复添加"); + } + return xzDryMatterCorrectionMapper.insertXzDryMatterCorrection(xzDryMatterCorrection); } /** - * 修改干物质校正 - * - * @param xzDryMatterCorrection 干物质校正 - * @return 结果 + * 修改干物质校正 - 添加重复校验 */ @Override public int updateXzDryMatterCorrection(XzDryMatterCorrection xzDryMatterCorrection) { + // 检查同年月同厂区是否已存在(排除当前记录) + if (isDuplicateRecord(xzDryMatterCorrection)) { + throw new RuntimeException("该厂区在同一年月已存在记录,不能重复添加"); + } + return xzDryMatterCorrectionMapper.updateXzDryMatterCorrection(xzDryMatterCorrection); } + + /** + * 检查是否存在重复记录(同年月同厂区) + */ + private boolean isDuplicateRecord(XzDryMatterCorrection xzDryMatterCorrection) { + // 查询相同年月和厂区的记录 + XzDryMatterCorrection query = new XzDryMatterCorrection(); + query.setDatetime(xzDryMatterCorrection.getDatetime()); + query.setFactory(xzDryMatterCorrection.getFactory()); + + List existingRecords = xzDryMatterCorrectionMapper.selectXzDryMatterCorrectionList(query); + + // 如果是更新操作,需要排除当前记录 + if (xzDryMatterCorrection.getId() != null) { + return existingRecords.stream() + .anyMatch(record -> + !record.getId().equals(xzDryMatterCorrection.getId()) + ); + } + + // 如果是新增操作,只要存在记录就返回true + return !existingRecords.isEmpty(); + } + /** * 批量删除干物质校正 * diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java index 49f5731..40f4d3f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java @@ -1,10 +1,9 @@ package com.zhyc.module.dairyProducts.service.impl; import java.util.List; - -import com.zhyc.module.dairyProducts.mapper.XzParityCorrectionMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.zhyc.module.dairyProducts.mapper.XzParityCorrectionMapper; import com.zhyc.module.dairyProducts.domain.XzParityCorrection; import com.zhyc.module.dairyProducts.service.IXzParityCorrectionService; @@ -12,7 +11,7 @@ import com.zhyc.module.dairyProducts.service.IXzParityCorrectionService; * 胎次校正Service业务层处理 * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ @Service public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzWegihCorrectionServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzWegihCorrectionServiceImpl.java index 7869c42..c27e6df 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzWegihCorrectionServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzWegihCorrectionServiceImpl.java @@ -1,7 +1,10 @@ package com.zhyc.module.dairyProducts.service.impl; +import java.util.Date; import java.util.List; +import java.util.stream.Collectors; +import com.zhyc.common.exception.ServiceException; import com.zhyc.module.dairyProducts.domain.XzWegihCorrection; import com.zhyc.module.dairyProducts.mapper.XzWegihCorrectionMapper; import com.zhyc.module.dairyProducts.service.IXzWegihCorrectionService; @@ -44,27 +47,60 @@ public class XzWegihCorrectionServiceImpl implements IXzWegihCorrectionService return xzWegihCorrectionMapper.selectXzWegihCorrectionList(xzWegihCorrection); } + /** + * 检查是否已存在相同日期和厂区的记录 + * @param datetime 日期 + * @param factory 厂区 + * @param excludeId 需要排除的ID(用于更新操作时排除自身) + * @return 如果存在返回true,否则返回false + */ + private boolean existsSameDateAndFactory(Date datetime, String factory, Long excludeId) { + // 创建一个查询条件对象 + XzWegihCorrection query = new XzWegihCorrection(); + query.setDatetime(datetime); + query.setFactory(factory); + + // 查询符合条件的记录 + List existingRecords = xzWegihCorrectionMapper.selectXzWegihCorrectionList(query); + + // 如果有需要排除的ID(更新操作),则过滤掉自身 + if (excludeId != null) { + existingRecords = existingRecords.stream() + .filter(record -> !record.getId().equals(excludeId)) + .collect(Collectors.toList()); + } + + // 如果找到记录,返回true + return !existingRecords.isEmpty(); + } + /** * 新增称重校正 - * - * @param xzWegihCorrection 称重校正 - * @return 结果 */ @Override public int insertXzWegihCorrection(XzWegihCorrection xzWegihCorrection) { + // 新增前检查是否已存在相同日期和厂区的记录 + if (existsSameDateAndFactory(xzWegihCorrection.getDatetime(), xzWegihCorrection.getFactory(), null)) { + // 抛出异常,提示用户已存在相同记录 + throw new ServiceException("已存在相同日期和厂区的记录,请勿重复添加"); + } + return xzWegihCorrectionMapper.insertXzWegihCorrection(xzWegihCorrection); } /** * 修改称重校正 - * - * @param xzWegihCorrection 称重校正 - * @return 结果 */ @Override public int updateXzWegihCorrection(XzWegihCorrection xzWegihCorrection) { + // 更新前检查是否已存在相同日期和厂区的记录(排除自身) + if (existsSameDateAndFactory(xzWegihCorrection.getDatetime(), xzWegihCorrection.getFactory(), xzWegihCorrection.getId())) { + // 抛出异常,提示用户已存在相同记录 + throw new ServiceException("已存在相同日期和厂区的记录,无法修改"); + } + return xzWegihCorrectionMapper.updateXzWegihCorrection(xzWegihCorrection); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java new file mode 100644 index 0000000..307ac92 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java @@ -0,0 +1,117 @@ +package com.zhyc.module.sale.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import com.zhyc.common.annotation.Log; +import com.zhyc.common.core.controller.BaseController; +import com.zhyc.common.core.domain.AjaxResult; +import com.zhyc.common.enums.BusinessType; +import com.zhyc.module.sale.domain.SxSheepSale; +import com.zhyc.module.sale.service.ISxSheepSaleService; +import com.zhyc.common.utils.poi.ExcelUtil; +import com.zhyc.common.core.page.TableDataInfo; + +/** + * 羊只销售记录Controller + * + * @author ruoyi + * @date 2025-08-19 + */ +@RestController +@RequestMapping("/saleRecord/saleRecord") +public class SxSheepSaleController extends BaseController { + @Autowired + private ISxSheepSaleService sxSheepSaleService; + + /** + * 查询羊只销售记录列表 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:list')") + @GetMapping("/list") + public TableDataInfo list(SxSheepSale sxSheepSale) { + startPage(); + List list = sxSheepSaleService.selectSxSheepSaleList(sxSheepSale); + return getDataTable(list); + } + + /** + * 导出羊只销售记录列表 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:export')") + @Log(title = "羊只销售记录", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SxSheepSale sxSheepSale) { + List list = sxSheepSaleService.selectSxSheepSaleList(sxSheepSale); + ExcelUtil util = new ExcelUtil(SxSheepSale.class); + util.exportExcel(response, list, "羊只销售记录数据"); + } + + /** + * 获取羊只销售记录详细信息 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) { + SxSheepSale sxSheepSale = sxSheepSaleService.selectSxSheepSaleById(id); + // 将数据库中的逗号分隔的耳号字符串转换为列表 + if (sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) { + sxSheepSale.setBsManageTagsList(java.util.Arrays.asList(sxSheepSale.getBsManageTags().split(","))); + } + return success(sxSheepSale); + } + + /** + * 新增羊只销售记录 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:add')") + @Log(title = "羊只销售记录", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SxSheepSale sxSheepSale) { + return toAjax(sxSheepSaleService.insertSxSheepSale(sxSheepSale)); + } + + /** + * 修改羊只销售记录 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:edit')") + @Log(title = "羊只销售记录", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SxSheepSale sxSheepSale) { + return toAjax(sxSheepSaleService.updateSxSheepSale(sxSheepSale)); + } + + /** + * 删除羊只销售记录 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:remove')") + @Log(title = "羊只销售记录", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(sxSheepSaleService.deleteSxSheepSaleByIds(ids)); + } + + /** + * 【新增】根据耳号查询羊只信息 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:add')" + "|| @ss.hasPermi('saleRecord:saleRecord:edit')") + @GetMapping("/getSheepInfo") + public AjaxResult getSheepInfo(@RequestParam String bsManageTags) { + // 调用Service方法查询信息 + SxSheepSale sheepInfo = sxSheepSaleService.selectSheepInfoByTag(bsManageTags); + if (sheepInfo == null) { + return AjaxResult.error("未找到耳号为 [" + bsManageTags + "] 的羊只信息"); + } + return AjaxResult.success(sheepInfo); + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomerExport.java b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomerExport.java new file mode 100644 index 0000000..a7d8833 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomerExport.java @@ -0,0 +1,49 @@ +package com.zhyc.module.sale.domain; + +import com.zhyc.common.annotation.Excel; + +public class SxCustomerExport { + @Excel(name = "客户名称") + private String name; + + @Excel(name = "客户电话") + private String phone; + + @Excel(name = "客户地址") + private String fullAddress; + + @Excel(name = "备注") + private String remark; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getFullAddress() { + return fullAddress; + } + + public void setFullAddress(String fullAddress) { + this.fullAddress = fullAddress; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java new file mode 100644 index 0000000..aab27dc --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java @@ -0,0 +1,545 @@ +package com.zhyc.module.sale.domain; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.zhyc.common.annotation.Excel; +import com.zhyc.common.core.domain.BaseEntity; + +/** + * 羊只销售记录对象 sx_sheep_sale + * + * @author ruoyi + * @date 2025-08-19 + */ +public class SxSheepSale extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** 主键ID */ + private Long id; + + /** 耳号 */ + @Excel(name = "耳号") + private String bsManageTags; + + /** 羊舍ID(当时销售的羊舍) */ + @Excel(name = "羊舍ID", readConverterExp = "当=时销售的羊舍") + private Long sheepfoldId; + + /** 品种快照 */ + @Excel(name = "品种快照") + private String variety; + + /** 羊只类别快照 */ + @Excel(name = "羊只类别快照") + private String sheepName; + + /** 性别快照 */ + @Excel(name = "性别快照") + private String gender; + + /** 月龄快照 */ + @Excel(name = "月龄快照") + private Long monthAge; + + /** 胎次快照 */ + @Excel(name = "胎次快照") + private Long parity; + + /** 繁育状态快照 */ + @Excel(name = "繁育状态快照") + private String breed; + + /** 产后天数快照 */ + @Excel(name = "产后天数快照") + private Long postLambingDay; + + /** 泌乳天数快照 */ + @Excel(name = "泌乳天数快照") + private Long lactationDay; + + /** 怀孕天数快照 */ + @Excel(name = "怀孕天数快照") + private Long lambingDay; + + /** 事件类型 */ + @Excel(name = "事件类型") + private String eventType; + + /** 销售日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "销售日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date saleDate; + + /** 计价方式 */ + @Excel(name = "计价方式") + private String pricingMethod; + + /** 单价 */ + @Excel(name = "单价") + private BigDecimal unitPrice; + + /** 总价(自动计算) */ + @Excel(name = "总价", readConverterExp = "自=动计算") + private BigDecimal totalPrice; + + /** 总体重(按体重时输入) */ + @Excel(name = "总体重", readConverterExp = "按=体重时输入") + private BigDecimal totalWeight; + + /** 平均体重(自动) */ + @Excel(name = "平均体重", readConverterExp = "自=动") + private BigDecimal avgWeight; + + /** 平均单只价格(自动) */ + @Excel(name = "平均单只价格", readConverterExp = "自=动") + private BigDecimal avgPricePerSheep; + + /** 销售类别(dict_type = sale_type) */ + @Excel(name = "销售类别", readConverterExp = "d=ict_type,==,s=ale_type") + private String saleType; + + /** 疾病类型(dict_type = disea_type) */ + @Excel(name = "疾病类型", readConverterExp = "d=ict_type,==,d=isea_type") + private String diseaseType; + + /** 次要原因 */ + @Excel(name = "次要原因") + private String secondaryReason; + + /** 班组(dict_type = group) */ + @Excel(name = "班组", readConverterExp = "d=ict_type,==,g=roup") + private String groupCode; + + /** 客户ID(sx_customer.id) */ + @Excel(name = "客户ID", readConverterExp = "s=x_customer.id") + private Long customerId; + + /** 销售人员ID(sys_user.id) */ + @Excel(name = "销售人员ID", readConverterExp = "s=ys_user.id") + private Long salesPersonId; + + /** 检疫证号 */ + @Excel(name = "检疫证号") + private String quarantineNo; + + /** 审批编号 */ + @Excel(name = "审批编号") + private String approvalNo; + + /** 技术员ID(sys_user.id) */ + @Excel(name = "技术员ID", readConverterExp = "s=ys_user.id") + private Long technicianId; + + /** 处理人ID(sys_user.id) */ + @Excel(name = "处理人ID", readConverterExp = "s=ys_user.id") + private Long handlerId; + + /** 创建人ID(sys_user.id) */ + @Excel(name = "创建人ID", readConverterExp = "s=ys_user.id") + private Long createdBy; + + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date createdAt; + + // 【新增】非数据库字段:用于前端展示和选择羊舍后传递多个耳号 + private List bsManageTagsList; + + // 【新增】非数据库字段:客户名称(从客户表查询) + private String customerName; + // 【新增】非数据库字段:客户电话 + private String customerPhone; + // 【新增】非数据库字段:客户地址 + private String customerAddress; + // 【新增】非数据库字段:销售人员姓名 + private String salesPersonName; + // 【新增】非数据库字段:技术员姓名 + private String technicianName; + // 【新增】非数据库字段:处理人姓名 + private String handlerName; + // 【新增】非数据库字段:创建人姓名 + private String createdByName; + // 【新增】非数据库字段:羊舍名称 + private String sheepfoldName; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setBsManageTags(String bsManageTags) { + this.bsManageTags = bsManageTags; + } + + public String getBsManageTags() { + return bsManageTags; + } + + public void setSheepfoldId(Long sheepfoldId) { + this.sheepfoldId = sheepfoldId; + } + + public Long getSheepfoldId() { + return sheepfoldId; + } + + public void setVariety(String variety) { + this.variety = variety; + } + + public String getVariety() { + return variety; + } + + public void setSheepName(String sheepName) { + this.sheepName = sheepName; + } + + public String getSheepName() { + return sheepName; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getGender() { + return gender; + } + + public void setMonthAge(Long monthAge) { + this.monthAge = monthAge; + } + + public Long getMonthAge() { + return monthAge; + } + + public void setParity(Long parity) { + this.parity = parity; + } + + public Long getParity() { + return parity; + } + + public void setBreed(String breed) { + this.breed = breed; + } + + public String getBreed() { + return breed; + } + + public void setPostLambingDay(Long postLambingDay) { + this.postLambingDay = postLambingDay; + } + + public Long getPostLambingDay() { + return postLambingDay; + } + + public void setLactationDay(Long lactationDay) { + this.lactationDay = lactationDay; + } + + public Long getLactationDay() { + return lactationDay; + } + + public void setLambingDay(Long lambingDay) { + this.lambingDay = lambingDay; + } + + public Long getLambingDay() { + return lambingDay; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public String getEventType() { + return eventType; + } + + public void setSaleDate(Date saleDate) { + this.saleDate = saleDate; + } + + public Date getSaleDate() { + return saleDate; + } + + public void setPricingMethod(String pricingMethod) { + this.pricingMethod = pricingMethod; + } + + public String getPricingMethod() { + return pricingMethod; + } + + public void setUnitPrice(BigDecimal unitPrice) { + this.unitPrice = unitPrice; + } + + public BigDecimal getUnitPrice() { + return unitPrice; + } + + public void setTotalPrice(BigDecimal totalPrice) { + this.totalPrice = totalPrice; + } + + public BigDecimal getTotalPrice() { + return totalPrice; + } + + public void setTotalWeight(BigDecimal totalWeight) { + this.totalWeight = totalWeight; + } + + public BigDecimal getTotalWeight() { + return totalWeight; + } + + public void setAvgWeight(BigDecimal avgWeight) { + this.avgWeight = avgWeight; + } + + public BigDecimal getAvgWeight() { + return avgWeight; + } + + public void setAvgPricePerSheep(BigDecimal avgPricePerSheep) { + this.avgPricePerSheep = avgPricePerSheep; + } + + public BigDecimal getAvgPricePerSheep() { + return avgPricePerSheep; + } + + public void setSaleType(String saleType) { + this.saleType = saleType; + } + + public String getSaleType() { + return saleType; + } + + public void setDiseaseType(String diseaseType) { + this.diseaseType = diseaseType; + } + + public String getDiseaseType() { + return diseaseType; + } + + public void setSecondaryReason(String secondaryReason) { + this.secondaryReason = secondaryReason; + } + + public String getSecondaryReason() { + return secondaryReason; + } + + public void setGroupCode(String groupCode) { + this.groupCode = groupCode; + } + + public String getGroupCode() { + return groupCode; + } + + public void setCustomerId(Long customerId) { + this.customerId = customerId; + } + + public Long getCustomerId() { + return customerId; + } + + public void setSalesPersonId(Long salesPersonId) { + this.salesPersonId = salesPersonId; + } + + public Long getSalesPersonId() { + return salesPersonId; + } + + public void setQuarantineNo(String quarantineNo) { + this.quarantineNo = quarantineNo; + } + + public String getQuarantineNo() { + return quarantineNo; + } + + public void setApprovalNo(String approvalNo) { + this.approvalNo = approvalNo; + } + + public String getApprovalNo() { + return approvalNo; + } + + public void setTechnicianId(Long technicianId) { + this.technicianId = technicianId; + } + + public Long getTechnicianId() { + return technicianId; + } + + public void setHandlerId(Long handlerId) { + this.handlerId = handlerId; + } + + public Long getHandlerId() { + return handlerId; + } + + public void setCreatedBy(Long createdBy) { + this.createdBy = createdBy; + } + + public Long getCreatedBy() { + return createdBy; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getCreatedAt() { + return createdAt; + } + + // 【新增】getter 和 setter 方法 + public List getBsManageTagsList() { + return bsManageTagsList; + } + + public void setBsManageTagsList(List bsManageTagsList) { + this.bsManageTagsList = bsManageTagsList; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getCustomerPhone() { + return customerPhone; + } + + public void setCustomerPhone(String customerPhone) { + this.customerPhone = customerPhone; + } + + public String getCustomerAddress() { + return customerAddress; + } + + public void setCustomerAddress(String customerAddress) { + this.customerAddress = customerAddress; + } + + public String getSalesPersonName() { + return salesPersonName; + } + + public void setSalesPersonName(String salesPersonName) { + this.salesPersonName = salesPersonName; + } + + public String getTechnicianName() { + return technicianName; + } + + public void setTechnicianName(String technicianName) { + this.technicianName = technicianName; + } + + public String getHandlerName() { + return handlerName; + } + + public void setHandlerName(String handlerName) { + this.handlerName = handlerName; + } + + public String getCreatedByName() { + return createdByName; + } + + public void setCreatedByName(String createdByName) { + this.createdByName = createdByName; + } + + public String getSheepfoldName() { + return sheepfoldName; + } + + public void setSheepfoldName(String sheepfoldName) { + this.sheepfoldName = sheepfoldName; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("bsManageTags", getBsManageTags()) + .append("sheepfoldId", getSheepfoldId()) + .append("variety", getVariety()) + .append("sheepName", getSheepName()) + .append("gender", getGender()) + .append("monthAge", getMonthAge()) + .append("parity", getParity()) + .append("breed", getBreed()) + .append("postLambingDay", getPostLambingDay()) + .append("lactationDay", getLactationDay()) + .append("lambingDay", getLambingDay()) + .append("eventType", getEventType()) + .append("saleDate", getSaleDate()) + .append("pricingMethod", getPricingMethod()) + .append("unitPrice", getUnitPrice()) + .append("totalPrice", getTotalPrice()) + .append("totalWeight", getTotalWeight()) + .append("avgWeight", getAvgWeight()) + .append("avgPricePerSheep", getAvgPricePerSheep()) + .append("saleType", getSaleType()) + .append("diseaseType", getDiseaseType()) + .append("secondaryReason", getSecondaryReason()) + .append("groupCode", getGroupCode()) + .append("customerId", getCustomerId()) + .append("salesPersonId", getSalesPersonId()) + .append("quarantineNo", getQuarantineNo()) + .append("approvalNo", getApprovalNo()) + .append("technicianId", getTechnicianId()) + .append("handlerId", getHandlerId()) + .append("createdBy", getCreatedBy()) + .append("createdAt", getCreatedAt()) + .append("remark", getRemark()) + .append("customerName", getCustomerName()) + .append("customerPhone", getCustomerPhone()) + .append("customerAddress", getCustomerAddress()) + .append("salesPersonName", getSalesPersonName()) + .append("technicianName", getTechnicianName()) + .append("handlerName", getHandlerName()) + .append("createdByName", getCreatedByName()) + .append("sheepfoldName", getSheepfoldName()) + .toString(); + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/mapper/SxSheepSaleMapper.java b/zhyc-module/src/main/java/com/zhyc/module/sale/mapper/SxSheepSaleMapper.java new file mode 100644 index 0000000..8b6788f --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/mapper/SxSheepSaleMapper.java @@ -0,0 +1,68 @@ +package com.zhyc.module.sale.mapper; + +import java.util.List; +import com.zhyc.module.sale.domain.SxSheepSale; +import org.apache.ibatis.annotations.Param; + +/** + * 羊只销售记录Mapper接口 + * + * @author ruoyi + * @date 2025-08-19 + */ +public interface SxSheepSaleMapper { + /** + * 查询羊只销售记录 + * + * @param id 羊只销售记录主键 + * @return 羊只销售记录 + */ + public SxSheepSale selectSxSheepSaleById(Long id); + + /** + * 查询羊只销售记录列表 + * + * @param sxSheepSale 羊只销售记录 + * @return 羊只销售记录集合 + */ + public List selectSxSheepSaleList(SxSheepSale sxSheepSale); + + /** + * 新增羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + public int insertSxSheepSale(SxSheepSale sxSheepSale); + + /** + * 修改羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + public int updateSxSheepSale(SxSheepSale sxSheepSale); + + /** + * 删除羊只销售记录 + * + * @param id 羊只销售记录主键 + * @return 结果 + */ + public int deleteSxSheepSaleById(Long id); + + /** + * 批量删除羊只销售记录 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSxSheepSaleByIds(Long[] ids); + + /** + * 【新增】从sheep_file视图查询羊只信息 + * @param bsManageTags 耳号 + * @return 羊只信息 (只包含视图中的字段) + */ + public SxSheepSale selectSheepInfoByTag(@Param("bsManageTags") String bsManageTags); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/service/ISxSheepSaleService.java b/zhyc-module/src/main/java/com/zhyc/module/sale/service/ISxSheepSaleService.java new file mode 100644 index 0000000..bbdc73a --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/service/ISxSheepSaleService.java @@ -0,0 +1,67 @@ +package com.zhyc.module.sale.service; + +import java.util.List; +import com.zhyc.module.sale.domain.SxSheepSale; + +/** + * 羊只销售记录Service接口 + * + * @author ruoyi + * @date 2025-08-19 + */ +public interface ISxSheepSaleService { + /** + * 查询羊只销售记录 + * + * @param id 羊只销售记录主键 + * @return 羊只销售记录 + */ + public SxSheepSale selectSxSheepSaleById(Long id); + + /** + * 查询羊只销售记录列表 + * + * @param sxSheepSale 羊只销售记录 + * @return 羊只销售记录集合 + */ + public List selectSxSheepSaleList(SxSheepSale sxSheepSale); + + /** + * 新增羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + public int insertSxSheepSale(SxSheepSale sxSheepSale); + + /** + * 修改羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + public int updateSxSheepSale(SxSheepSale sxSheepSale); + + /** + * 批量删除羊只销售记录 + * + * @param ids 需要删除的羊只销售记录主键集合 + * @return 结果 + */ + public int deleteSxSheepSaleByIds(Long[] ids); + + /** + * 删除羊只销售记录信息 + * + * @param id 羊只销售记录主键 + * @return 结果 + */ + public int deleteSxSheepSaleById(Long id); + + /** + * 【新增】根据耳号查询羊只信息 + * @param bsManageTags 耳号 + * @return 羊只信息 + */ + public SxSheepSale selectSheepInfoByTag(String bsManageTags); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java new file mode 100644 index 0000000..2c47d5c --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java @@ -0,0 +1,194 @@ +package com.zhyc.module.sale.service.impl; + +import java.util.List; +import java.math.BigDecimal; +import java.math.RoundingMode; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.zhyc.module.sale.mapper.SxSheepSaleMapper; +import com.zhyc.module.sale.domain.SxSheepSale; +import com.zhyc.module.sale.service.ISxSheepSaleService; + +/** + * 羊只销售记录Service业务层处理 + * + * @author ruoyi + * @date 2025-08-19 + */ +@Service +public class SxSheepSaleServiceImpl implements ISxSheepSaleService { + @Autowired + private SxSheepSaleMapper sxSheepSaleMapper; + + /** + * 查询羊只销售记录 + * + * @param id 羊只销售记录主键 + * @return 羊只销售记录 + */ + @Override + public SxSheepSale selectSxSheepSaleById(Long id) { + return sxSheepSaleMapper.selectSxSheepSaleById(id); + } + + /** + * 查询羊只销售记录列表 + * + * @param sxSheepSale 羊只销售记录 + * @return 羊只销售记录 + */ + @Override + public List selectSxSheepSaleList(SxSheepSale sxSheepSale) { + return sxSheepSaleMapper.selectSxSheepSaleList(sxSheepSale); + } + + /** + * 新增羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + @Override + public int insertSxSheepSale(SxSheepSale sxSheepSale) { + // 1. 业务验证 (例如:销售日期不能为空,淘汰销售必须填写疾病类型等) + validateSalesFields(sxSheepSale); + + // 2. 自动计算逻辑 + calculateSalesFields(sxSheepSale); + + // 3. 设置默认事件类型 + if (sxSheepSale.getEventType() == null) { + sxSheepSale.setEventType("销售"); + } + + // 4. 处理耳号列表(多个耳号用逗号分隔) + if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { + sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList())); + } + + // 5. 调用Mapper插入数据 + return sxSheepSaleMapper.insertSxSheepSale(sxSheepSale); + } + + /** + * 修改羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + @Override + public int updateSxSheepSale(SxSheepSale sxSheepSale) { + // 1. 业务验证 + validateSalesFields(sxSheepSale); + + // 2. 自动计算逻辑 + calculateSalesFields(sxSheepSale); + + // 3. 处理耳号列表(多个耳号用逗号分隔) + if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { + sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList())); + } + + // 4. 调用Mapper更新数据 + return sxSheepSaleMapper.updateSxSheepSale(sxSheepSale); + } + + /** + * 批量删除羊只销售记录 + * + * @param ids 需要删除的羊只销售记录主键 + * @return 结果 + */ + @Override + public int deleteSxSheepSaleByIds(Long[] ids) { + return sxSheepSaleMapper.deleteSxSheepSaleByIds(ids); + } + + /** + * 删除羊只销售记录信息 + * + * @param id 羊只销售记录主键 + * @return 结果 + */ + @Override + public int deleteSxSheepSaleById(Long id) { + return sxSheepSaleMapper.deleteSxSheepSaleById(id); + } + + /** + * 【新增】根据耳号查询羊只信息 + */ + @Override + public SxSheepSale selectSheepInfoByTag(String bsManageTags) { + return sxSheepSaleMapper.selectSheepInfoByTag(bsManageTags); + } + + /** + * 【新增】自动计算总价、平均体重、平均单只价格 + */ + private void calculateSalesFields(SxSheepSale sxSheepSale) { + String pricingMethod = sxSheepSale.getPricingMethod(); + BigDecimal unitPrice = sxSheepSale.getUnitPrice(); + + // 获取羊只数量 + int sheepCount = 1; + if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { + sheepCount = sxSheepSale.getBsManageTagsList().size(); + } else if (sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) { + // 如果前端没有传递列表,但有逗号分隔的字符串,也计算数量 + sheepCount = sxSheepSale.getBsManageTags().split(",").length; + } + + if ("按个体".equals(pricingMethod)) { + // 总价 = 单价 * 数量 + if (unitPrice != null) { + sxSheepSale.setTotalPrice(unitPrice.multiply(new BigDecimal(sheepCount))); + } + // 平均单只价格就是单价 + sxSheepSale.setAvgPricePerSheep(unitPrice); + + } else if ("按体重".equals(pricingMethod)) { + BigDecimal totalWeight = sxSheepSale.getTotalWeight(); + // 总价 = 单价 * 总重量 + if (unitPrice != null && totalWeight != null) { + sxSheepSale.setTotalPrice(unitPrice.multiply(totalWeight)); + } + // 平均体重 = 总重量 / 数量 + if (totalWeight != null && sheepCount > 0) { + sxSheepSale.setAvgWeight(totalWeight.divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP)); + } + // 平均单只价格 = 总价 / 数量 + if (sxSheepSale.getTotalPrice() != null && sheepCount > 0) { + sxSheepSale.setAvgPricePerSheep(sxSheepSale.getTotalPrice().divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP)); + } + } + // 可以添加其他计价方式的逻辑 + } + + /** + * 【新增】业务字段验证 + */ + private void validateSalesFields(SxSheepSale sxSheepSale) { + // 验证销售日期不能为空 + if (sxSheepSale.getSaleDate() == null) { + throw new RuntimeException("销售日期不能为空!"); + } + + String saleType = sxSheepSale.getSaleType(); + // 如果销售类别是"淘汰销售"或"淘汰屠宰",则疾病类型和班组不能为空 + if ("淘汰销售".equals(saleType) || "淘汰屠宰".equals(saleType)) { + if (sxSheepSale.getDiseaseType() == null) { + throw new RuntimeException("淘汰销售或淘汰屠宰必须选择疾病类型!"); + } + if (sxSheepSale.getGroupCode() == null) { + throw new RuntimeException("淘汰销售或淘汰屠宰必须选择班组!"); + } + } + // 如果疾病类型是"病残羊",则次要原因不能为空 + if ("病残羊".equals(sxSheepSale.getDiseaseType())) { + if (sxSheepSale.getSecondaryReason() == null || sxSheepSale.getSecondaryReason().trim().isEmpty()) { + throw new RuntimeException("疾病类型为病残羊时,必须填写次要原因!"); + } + } + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml index eb20ee1..0fd5b29 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml @@ -13,17 +13,18 @@ + SELECT - id, - datetime, - factory, - content, - standard, - CASE - WHEN standard = 0 OR standard IS NULL THEN NULL - ELSE content / standard - END AS coefficient + id, + datetime, + factory, + content, + COALESCE(standard, 18) as standard, + CASE + WHEN standard = 0 OR standard IS NULL THEN NULL + ELSE ROUND(content / standard, 2) + END AS coefficient FROM xz_dry_matter_correction diff --git a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml new file mode 100644 index 0000000..00ac0da --- /dev/null +++ b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id, bs_manage_tags, sheepfold_id, variety, sheep_name, gender, month_age, parity, breed, post_lambing_day, lactation_day, lambing_day, event_type, sale_date, pricing_method, unit_price, total_price, total_weight, avg_weight, avg_price_per_sheep, sale_type, disease_type, secondary_reason, group_code, customer_id, sales_person_id, quarantine_no, approval_no, technician_id, handler_id, created_by, created_at, remark from sx_sheep_sale + + + + + select + bs_manage_tags, + variety, + name as sheep_name, + gender, + month_age, + parity, + breed, + post_lambing_day, + lactation_day, + lambing_day, + sheepfold_id + from sheep_file + + + + + + + + + + + insert into sx_sheep_sale + + bs_manage_tags, + sheepfold_id, + variety, + sheep_name, + gender, + month_age, + parity, + breed, + post_lambing_day, + lactation_day, + lambing_day, + event_type, + sale_date, + pricing_method, + unit_price, + total_price, + total_weight, + avg_weight, + avg_price_per_sheep, + sale_type, + disease_type, + secondary_reason, + group_code, + customer_id, + sales_person_id, + quarantine_no, + approval_no, + technician_id, + handler_id, + created_by, + created_at, + remark, + + + #{bsManageTags}, + #{sheepfoldId}, + #{variety}, + #{sheepName}, + #{gender}, + #{monthAge}, + #{parity}, + #{breed}, + #{postLambingDay}, + #{lactationDay}, + #{lambingDay}, + #{eventType}, + #{saleDate}, + #{pricingMethod}, + #{unitPrice}, + #{totalPrice}, + #{totalWeight}, + #{avgWeight}, + #{avgPricePerSheep}, + #{saleType}, + #{diseaseType}, + #{secondaryReason}, + #{groupCode}, + #{customerId}, + #{salesPersonId}, + #{quarantineNo}, + #{approvalNo}, + #{technicianId}, + #{handlerId}, + #{createdBy}, + #{createdAt}, + #{remark}, + + + + + update sx_sheep_sale + + bs_manage_tags = #{bsManageTags}, + sheepfold_id = #{sheepfoldId}, + variety = #{variety}, + sheep_name = #{sheepName}, + gender = #{gender}, + month_age = #{monthAge}, + parity = #{parity}, + breed = #{breed}, + post_lambing_day = #{postLambingDay}, + lactation_day = #{lactationDay}, + lambing_day = #{lambingDay}, + event_type = #{eventType}, + sale_date = #{saleDate}, + pricing_method = #{pricingMethod}, + unit_price = #{unitPrice}, + total_price = #{totalPrice}, + total_weight = #{totalWeight}, + avg_weight = #{avgWeight}, + avg_price_per_sheep = #{avgPricePerSheep}, + sale_type = #{saleType}, + disease_type = #{diseaseType}, + secondary_reason = #{secondaryReason}, + group_code = #{groupCode}, + customer_id = #{customerId}, + sales_person_id = #{salesPersonId}, + quarantine_no = #{quarantineNo}, + approval_no = #{approvalNo}, + technician_id = #{technicianId}, + handler_id = #{handlerId}, + created_by = #{createdBy}, + created_at = #{createdAt}, + remark = #{remark}, + + where id = #{id} + + + + delete from sx_sheep_sale where id = #{id} + + + + delete from sx_sheep_sale where id in + + #{id} + + + + \ No newline at end of file From 84bc8946685f7f7242a17381a4ae4453c02c40e2 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Mon, 25 Aug 2025 17:01:10 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E9=9C=80=E6=B1=82=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XzParityCorrectionController.java | 5 ++- .../domain/XzParityCorrection.java | 40 ++++++++++++++++++- .../mapper/XzParityCorrectionMapper.java | 16 ++++---- .../service/IXzParityCorrectionService.java | 16 ++++---- .../impl/XzParityCorrectionServiceImpl.java | 16 ++++---- .../XzParityCorrectionMapper.xml | 16 ++++---- 6 files changed, 74 insertions(+), 35 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java index 6b6ea52..db13670 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java @@ -19,10 +19,11 @@ import com.zhyc.common.enums.BusinessType; import com.zhyc.module.dairyProducts.domain.XzParityCorrection; import com.zhyc.module.dairyProducts.service.IXzParityCorrectionService; import com.zhyc.common.utils.poi.ExcelUtil; +import com.zhyc.common.core.page.TableDataInfo; /** * 胎次校正Controller - * + * * @author ruoyi * @date 2025-08-24 */ @@ -95,7 +96,7 @@ public class XzParityCorrectionController extends BaseController */ @PreAuthorize("@ss.hasPermi('parityCorrection:parityCorrection:remove')") @Log(title = "胎次校正", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") + @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(xzParityCorrectionService.deleteXzParityCorrectionByIds(ids)); diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java index 9b6b3d1..9c14456 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java @@ -7,7 +7,7 @@ import com.zhyc.common.core.domain.BaseEntity; /** * 胎次校正对象 xz_parity_correction - * + * * @author ruoyi * @date 2025-08-24 */ @@ -26,4 +26,42 @@ public class XzParityCorrection extends BaseEntity @Excel(name = "系数") private Double coef; + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setParity(Integer parity) + { + this.parity = parity; + } + + public Integer getParity() + { + return parity; + } + + public void setCoef(Double coef) + { + this.coef = coef; + } + + public Double getCoef() + { + return coef; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("parity", getParity()) + .append("coef", getCoef()) + .toString(); + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java index f6d1f12..3d9cf45 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java @@ -5,15 +5,15 @@ import com.zhyc.module.dairyProducts.domain.XzParityCorrection; /** * 胎次校正Mapper接口 - * + * * @author ruoyi * @date 2025-08-24 */ -public interface XzParityCorrectionMapper +public interface XzParityCorrectionMapper { /** * 查询胎次校正 - * + * * @param id 胎次校正主键 * @return 胎次校正 */ @@ -21,7 +21,7 @@ public interface XzParityCorrectionMapper /** * 查询胎次校正列表 - * + * * @param xzParityCorrection 胎次校正 * @return 胎次校正集合 */ @@ -29,7 +29,7 @@ public interface XzParityCorrectionMapper /** * 新增胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -37,7 +37,7 @@ public interface XzParityCorrectionMapper /** * 修改胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -45,7 +45,7 @@ public interface XzParityCorrectionMapper /** * 删除胎次校正 - * + * * @param id 胎次校正主键 * @return 结果 */ @@ -53,7 +53,7 @@ public interface XzParityCorrectionMapper /** * 批量删除胎次校正 - * + * * @param ids 需要删除的数据主键集合 * @return 结果 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java index f7acf95..8246bdd 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java @@ -5,15 +5,15 @@ import com.zhyc.module.dairyProducts.domain.XzParityCorrection; /** * 胎次校正Service接口 - * + * * @author ruoyi * @date 2025-08-24 */ -public interface IXzParityCorrectionService +public interface IXzParityCorrectionService { /** * 查询胎次校正 - * + * * @param id 胎次校正主键 * @return 胎次校正 */ @@ -21,7 +21,7 @@ public interface IXzParityCorrectionService /** * 查询胎次校正列表 - * + * * @param xzParityCorrection 胎次校正 * @return 胎次校正集合 */ @@ -29,7 +29,7 @@ public interface IXzParityCorrectionService /** * 新增胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -37,7 +37,7 @@ public interface IXzParityCorrectionService /** * 修改胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -45,7 +45,7 @@ public interface IXzParityCorrectionService /** * 批量删除胎次校正 - * + * * @param ids 需要删除的胎次校正主键集合 * @return 结果 */ @@ -53,7 +53,7 @@ public interface IXzParityCorrectionService /** * 删除胎次校正信息 - * + * * @param id 胎次校正主键 * @return 结果 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java index 40f4d3f..caff850 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java @@ -9,19 +9,19 @@ import com.zhyc.module.dairyProducts.service.IXzParityCorrectionService; /** * 胎次校正Service业务层处理 - * + * * @author ruoyi * @date 2025-08-24 */ @Service -public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService +public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService { @Autowired private XzParityCorrectionMapper xzParityCorrectionMapper; /** * 查询胎次校正 - * + * * @param id 胎次校正主键 * @return 胎次校正 */ @@ -33,7 +33,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 查询胎次校正列表 - * + * * @param xzParityCorrection 胎次校正 * @return 胎次校正 */ @@ -45,7 +45,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 新增胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -57,7 +57,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 修改胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -69,7 +69,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 批量删除胎次校正 - * + * * @param ids 需要删除的胎次校正主键 * @return 结果 */ @@ -81,7 +81,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 删除胎次校正信息 - * + * * @param id 胎次校正主键 * @return 结果 */ diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/XzParityCorrectionMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/XzParityCorrectionMapper.xml index 9cf78ff..c9101f6 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/XzParityCorrectionMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/XzParityCorrectionMapper.xml @@ -1,9 +1,9 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -16,12 +16,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + - + select s.id, datetime, sheep_id, usage_id, variety, sheep_type, s.gender, month_age, s.parity, breed, technical, + s.comment, s.update_by, s.update_time, s.create_by, s.create_time, + bs.manage_tags sheep_no + from sw_health s + left join bas_sheep bs on s.sheep_id = bs.id + and datetime = #{datetime} + and bs.manage_tags like concat('%',#{sheepNo},'%') + and datetime between #{params.beginDatetime} and #{params.endDatetime} and technical = #{technical} ORDER BY datetime DESC diff --git a/zhyc-module/src/main/resources/mapper/biosafety/ImmunityMapper.xml b/zhyc-module/src/main/resources/mapper/biosafety/ImmunityMapper.xml index ad52e4e..9265410 100644 --- a/zhyc-module/src/main/resources/mapper/biosafety/ImmunityMapper.xml +++ b/zhyc-module/src/main/resources/mapper/biosafety/ImmunityMapper.xml @@ -32,10 +32,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + select t.id, diag_id, sheep_id, variety, sheep_type, month_age, t.gender, t.parity, breed, lact_day, gest_day, datetime, disease_id, disease_pid, veterinary, usage_id,status, t.comment, t.update_by, t.update_time, t.create_by, t.create_time, + bs.manage_tags, + sd.name disease_name, + sd2.name disease_pname + from sw_treatment t + left join bas_sheep bs on t.sheep_id = bs.id + left join sw_disease sd on t.disease_id = sd.id + left join sw_disease sd2 on t.disease_pid = sd2.id and sheep_id = #{sheepId} + and bs.manage_tags like concat('%',#{sheepNo},'%') and datetime between #{params.beginDatetime} and #{params.endDatetime} and disease_id = #{diseaseId} and status = #{status} From a7fd5f303faa1eb8b24aada9e236a81b468529d7 Mon Sep 17 00:00:00 2001 From: HashMap Date: Tue, 26 Aug 2025 17:08:12 +0800 Subject: [PATCH 07/10] =?UTF-8?q?fix(Mapper/stock):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E6=9F=A5=E8=AF=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + 修复了入库记录无法根据日期查询的问题 + 通过改进SQL解决 + 修复了物资管理无法根据日期查询的问题 + 通过改进SQL解决 --- .../com/zhyc/module/stock/controller/WzStockInController.java | 1 + .../resources/mapper/stock/WzMaterialsManagementMapper.xml | 3 ++- .../src/main/resources/mapper/stock/WzStockInMapper.xml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/stock/controller/WzStockInController.java b/zhyc-module/src/main/java/com/zhyc/module/stock/controller/WzStockInController.java index 6705202..4eef0ae 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/stock/controller/WzStockInController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/stock/controller/WzStockInController.java @@ -47,6 +47,7 @@ public class WzStockInController extends BaseController { startPage(); List list = wzStockInService.selectWzStockInList(wzStockIn); + logger.debug(wzStockIn.toString()); return getDataTable(list); } diff --git a/zhyc-module/src/main/resources/mapper/stock/WzMaterialsManagementMapper.xml b/zhyc-module/src/main/resources/mapper/stock/WzMaterialsManagementMapper.xml index d2347c4..7caa4fd 100644 --- a/zhyc-module/src/main/resources/mapper/stock/WzMaterialsManagementMapper.xml +++ b/zhyc-module/src/main/resources/mapper/stock/WzMaterialsManagementMapper.xml @@ -26,7 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and material_name like concat('%', #{materialName}, '%') - and production_date between #{params.beginProductionDate} and #{params.endProductionDate} + and production_date between #{params.beginProductionDate} and #{params.endProductionDate} + and production_date = #{productionDate} diff --git a/zhyc-module/src/main/resources/mapper/stock/WzStockInMapper.xml b/zhyc-module/src/main/resources/mapper/stock/WzStockInMapper.xml index 55c5c1e..d472047 100644 --- a/zhyc-module/src/main/resources/mapper/stock/WzStockInMapper.xml +++ b/zhyc-module/src/main/resources/mapper/stock/WzStockInMapper.xml @@ -41,6 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and business_type = #{businessType} and repository_name like concat('%', #{repositoryName}, '%') and material_name like concat('%', #{materialName}, '%') + and doc_date = #{docDate} From 29efc433927e35e104778587e22428e164059465 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Thu, 28 Aug 2025 11:12:31 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E7=8F=AD=E6=AC=A1=E5=A5=B6=E9=87=8F?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zhyc/common/annotation/Excel.java | 5 + .../com/zhyc/common/utils/poi/ExcelUtil.java | 116 +++++++++++------- .../NpMilkProdClassesController.java | 6 +- .../domain/NpMilkProdClasses.java | 6 +- 4 files changed, 85 insertions(+), 48 deletions(-) diff --git a/zhyc-common/src/main/java/com/zhyc/common/annotation/Excel.java b/zhyc-common/src/main/java/com/zhyc/common/annotation/Excel.java index e9d66a7..47402dc 100644 --- a/zhyc-common/src/main/java/com/zhyc/common/annotation/Excel.java +++ b/zhyc-common/src/main/java/com/zhyc/common/annotation/Excel.java @@ -33,6 +33,11 @@ public @interface Excel */ public String dateFormat() default ""; + /** + * 数字格式, 如: 0.00 + */ + public String numFormat() default ""; // 新增数字格式属性 + /** * 如果是字典类型,请设置字典的type值 (如: sys_user_sex) */ diff --git a/zhyc-common/src/main/java/com/zhyc/common/utils/poi/ExcelUtil.java b/zhyc-common/src/main/java/com/zhyc/common/utils/poi/ExcelUtil.java index d595cee..35269b0 100644 --- a/zhyc-common/src/main/java/com/zhyc/common/utils/poi/ExcelUtil.java +++ b/zhyc-common/src/main/java/com/zhyc/common/utils/poi/ExcelUtil.java @@ -88,7 +88,7 @@ import com.zhyc.common.utils.reflect.ReflectUtils; /** * Excel相关处理 - * + * * @author ruoyi */ public class ExcelUtil @@ -307,7 +307,7 @@ public class ExcelUtil /** * 对excel表单默认第一个索引名转换成list - * + * * @param is 输入流 * @return 转换后集合 */ @@ -318,7 +318,7 @@ public class ExcelUtil /** * 对excel表单默认第一个索引名转换成list - * + * * @param is 输入流 * @param titleNum 标题占用行数 * @return 转换后集合 @@ -344,7 +344,7 @@ public class ExcelUtil /** * 对excel表单指定表格索引名转换成list - * + * * @param sheetName 表格索引名 * @param titleNum 标题占用行数 * @param is 输入流 @@ -527,7 +527,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param list 导出数据集合 * @param sheetName 工作表的名称 * @return 结果 @@ -539,7 +539,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param list 导出数据集合 * @param sheetName 工作表的名称 * @param title 标题 @@ -553,7 +553,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param response 返回数据 * @param list 导出数据集合 * @param sheetName 工作表的名称 @@ -566,7 +566,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param response 返回数据 * @param list 导出数据集合 * @param sheetName 工作表的名称 @@ -583,7 +583,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param sheetName 工作表的名称 * @return 结果 */ @@ -594,7 +594,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param sheetName 工作表的名称 * @param title 标题 * @return 结果 @@ -607,7 +607,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param sheetName 工作表的名称 * @return 结果 */ @@ -618,7 +618,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param sheetName 工作表的名称 * @param title 标题 * @return 结果 @@ -633,7 +633,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @return 结果 */ public void exportExcel(HttpServletResponse response) @@ -655,7 +655,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @return 结果 */ public AjaxResult exportExcel() @@ -723,7 +723,7 @@ public class ExcelUtil /** * 填充excel数据 - * + * * @param index 序号 * @param row 单元格行 */ @@ -821,7 +821,7 @@ public class ExcelUtil /** * 创建表格样式 - * + * * @param wb 工作薄对象 * @return 样式列表 */ @@ -876,7 +876,7 @@ public class ExcelUtil /** * 根据Excel注解创建表格头样式 - * + * * @param wb 工作薄对象 * @return 自定义样式列表 */ @@ -912,7 +912,7 @@ public class ExcelUtil /** * 根据Excel注解创建表格列样式 - * + * * @param wb 工作薄对象 * @return 自定义样式列表 */ @@ -944,7 +944,7 @@ public class ExcelUtil /** * 根据Excel注解创建表格列样式 - * + * * @param styles 自定义样式列表 * @param field 属性列信息 * @param excel 注解信息 @@ -1007,7 +1007,7 @@ public class ExcelUtil /** * 设置单元格信息 - * + * * @param value 单元格值 * @param attr 注解相关 * @param cell 单元格信息 @@ -1142,7 +1142,6 @@ public class ExcelUtil sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column)); } } - cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText()))); // 用于读取对象中的属性 Object value = getTargetValue(vo, field, attr); @@ -1150,14 +1149,33 @@ public class ExcelUtil String readConverterExp = attr.readConverterExp(); String separator = attr.separator(); String dictType = attr.dictType(); - if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) + String numFormat = attr.numFormat(); // 获取数字格式 + + // 创建单元格样式 + CellStyle cellStyle = wb.createCellStyle(); + cellStyle.cloneStyleFrom(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", + attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText()))); + + // 处理日期格式 + if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value) && value instanceof Date) { - cell.getCellStyle().setDataFormat(this.wb.getCreationHelper().createDataFormat().getFormat(dateFormat)); - cell.setCellValue(parseDateToStr(dateFormat, value)); + DataFormat format = wb.createDataFormat(); + cellStyle.setDataFormat(format.getFormat(dateFormat)); + cell.setCellValue((Date) value); + cell.setCellStyle(cellStyle); + } + // 处理数字格式 + else if (StringUtils.isNotEmpty(numFormat) && StringUtils.isNotNull(value) && value instanceof Number) + { + DataFormat format = wb.createDataFormat(); + cellStyle.setDataFormat(format.getFormat(numFormat)); + cell.setCellValue(((Number) value).doubleValue()); + cell.setCellStyle(cellStyle); } else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) { cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator)); + cell.setCellStyle(cellStyle); } else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value)) { @@ -1167,20 +1185,32 @@ public class ExcelUtil sysDictMap.put(dictType + value, lable); } cell.setCellValue(sysDictMap.get(dictType + value)); + cell.setCellStyle(cellStyle); } else if (value instanceof BigDecimal && -1 != attr.scale()) { cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue()); + cell.setCellStyle(cellStyle); } else if (!attr.handler().equals(ExcelHandlerAdapter.class)) { cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell)); + cell.setCellStyle(cellStyle); } else { // 设置列类型 setCellVo(value, attr, cell); + // 对于日期类型,确保应用日期格式 + if (value instanceof Date && StringUtils.isNotEmpty(dateFormat)) { + DataFormat format = wb.createDataFormat(); + CellStyle dateStyle = wb.createCellStyle(); + dateStyle.cloneStyleFrom(cell.getCellStyle()); + dateStyle.setDataFormat(format.getFormat(dateFormat)); + cell.setCellStyle(dateStyle); + } } + addStatisticsData(column, Convert.toStr(value), attr); } } @@ -1193,7 +1223,7 @@ public class ExcelUtil /** * 设置 POI XSSFSheet 单元格提示或选择框 - * + * * @param sheet 表单 * @param textlist 下拉框显示的内容 * @param promptContent 提示内容 @@ -1203,7 +1233,7 @@ public class ExcelUtil * @param endCol 结束列 */ public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, - int firstCol, int endCol) + int firstCol, int endCol) { DataValidationHelper helper = sheet.getDataValidationHelper(); DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1"); @@ -1230,7 +1260,7 @@ public class ExcelUtil /** * 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框). - * + * * @param sheet 要设置的sheet. * @param textlist 下拉框显示的内容 * @param promptContent 提示内容 @@ -1254,7 +1284,7 @@ public class ExcelUtil DataValidationHelper helper = sheet.getDataValidationHelper(); // 加载下拉列表内容 DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data"); - // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列 + // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列 CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); // 数据有效性对象 DataValidation dataValidation = helper.createValidation(constraint, regions); @@ -1282,7 +1312,7 @@ public class ExcelUtil /** * 解析导出值 0=男,1=女,2=未知 - * + * * @param propertyValue 参数值 * @param converterExp 翻译注解 * @param separator 分隔符 @@ -1319,7 +1349,7 @@ public class ExcelUtil /** * 反向解析值 男=0,女=1,未知=2 - * + * * @param propertyValue 参数值 * @param converterExp 翻译注解 * @param separator 分隔符 @@ -1356,7 +1386,7 @@ public class ExcelUtil /** * 解析字典值 - * + * * @param dictValue 字典值 * @param dictType 字典类型 * @param separator 分隔符 @@ -1369,7 +1399,7 @@ public class ExcelUtil /** * 反向解析值字典值 - * + * * @param dictLabel 字典标签 * @param dictType 字典类型 * @param separator 分隔符 @@ -1382,7 +1412,7 @@ public class ExcelUtil /** * 数据处理器 - * + * * @param value 数据值 * @param excel 数据注解 * @return @@ -1458,7 +1488,7 @@ public class ExcelUtil /** * 获取下载路径 - * + * * @param filename 文件名称 */ public String getAbsoluteFile(String filename) @@ -1474,7 +1504,7 @@ public class ExcelUtil /** * 获取bean中的属性值 - * + * * @param vo 实体对象 * @param field 字段 * @param excel 注解 @@ -1506,7 +1536,7 @@ public class ExcelUtil /** * 以类的属性的get方法方法形式获取值 - * + * * @param o * @param name * @return value @@ -1649,7 +1679,7 @@ public class ExcelUtil /** * 创建工作表 - * + * * @param sheetNo sheet数量 * @param index 序号 */ @@ -1666,7 +1696,7 @@ public class ExcelUtil /** * 获取单元格值 - * + * * @param row 获取的行 * @param column 获取单元格列号 * @return 单元格值 @@ -1726,7 +1756,7 @@ public class ExcelUtil /** * 判断是否是空行 - * + * * @param row 判断的行 * @return */ @@ -1754,7 +1784,7 @@ public class ExcelUtil * @param workbook 工作簿对象 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData */ - public static Map> getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook) + public static Map > getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook) { Map> sheetIndexPicMap = new HashMap<>(); List pictures = workbook.getAllPictures(); @@ -1807,7 +1837,7 @@ public class ExcelUtil /** * 格式化不同类型的日期对象 - * + * * @param dateFormat 日期格式 * @param val 被格式化的日期对象 * @return 格式化后的日期字符 @@ -1873,7 +1903,7 @@ public class ExcelUtil /** * 获取对象的子列表方法 - * + * * @param name 名称 * @param pojoClass 类对象 * @return 子列表方法 @@ -1894,4 +1924,4 @@ public class ExcelUtil } return method; } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpMilkProdClassesController.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpMilkProdClassesController.java index 32e7db8..da0cde1 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpMilkProdClassesController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpMilkProdClassesController.java @@ -58,10 +58,12 @@ public class NpMilkProdClassesController extends BaseController { public void export(HttpServletResponse response, @RequestParam(required = false) Date datetimeStart, @RequestParam(required = false) Date datetimeEnd, - @RequestParam(required = false) String manageEarNos, + @RequestParam(required = false) String manageEarNo, @RequestParam(required = false) String factory, @RequestParam(required = false) Integer classes) { - List list = npMilkProdClassesService.selectNpMilkProdClassesList(datetimeStart, datetimeEnd, manageEarNos, factory, classes); + List list = npMilkProdClassesService.selectNpMilkProdClassesList( + datetimeStart, datetimeEnd, manageEarNo, factory, classes); + ExcelUtil util = new ExcelUtil<>(NpMilkProdClasses.class); util.exportExcel(response, list, "班次产奶数据"); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpMilkProdClasses.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpMilkProdClasses.java index 19e2ce9..43d388d 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpMilkProdClasses.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpMilkProdClasses.java @@ -15,7 +15,7 @@ public class NpMilkProdClasses implements Serializable { private Date updateTime; // 更新时间 @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "日期") + @Excel(name = "日期", dateFormat = "yyyy-MM-dd") // 添加日期格式 private Date datetime; @Excel(name = "管理耳号") @@ -33,10 +33,10 @@ public class NpMilkProdClasses implements Serializable { @Excel(name = "班次") private Integer classes; - @Excel(name = "班次产奶量") + @Excel(name = "班次产奶量", numFormat = "0.00") private Double milk; - @Excel(name = "班次校正奶量") + @Excel(name = "班次校正奶量", numFormat = "0.00") private Double correctedMilk; private String sheepId; From c8f7b6baffc1255f67abd667b6506451f22cb6fe Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Fri, 29 Aug 2025 17:24:43 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E9=85=B8=E5=A5=B6=E6=A3=80=E9=AA=8C?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=EF=BC=8C=E9=B2=9C=E5=A5=B6=E6=A3=80=E9=AA=8C?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E3=80=81=E7=94=9F=E4=B9=B3=E6=A3=80=E9=AA=8C?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=A1=B5=E9=9D=A2=E5=AF=BC=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=A5=B6=E4=BA=A7=E9=87=8F=E5=88=86=E6=9E=90?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=8A=A5=E9=94=99=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NpSheepMilkAnalysisController.java | 11 +-- .../domain/NpSheepMilkAnalysis.java | 75 +++++++++++++++++-- .../mapper/NpSheepMilkAnalysisMapper.java | 9 ++- .../service/INpSheepMilkAnalysisService.java | 7 +- .../impl/NpSheepMilkAnalysisServiceImpl.java | 18 +++-- .../NpSheepMilkAnalysisMapper.xml | 30 ++++++-- 6 files changed, 124 insertions(+), 26 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpSheepMilkAnalysisController.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpSheepMilkAnalysisController.java index 3e4f07a..bce4136 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpSheepMilkAnalysisController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpSheepMilkAnalysisController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; /** + * 奶产量分析控制器 * 只保留:分页列表(只读) + 单条查询 + 导出 */ @RestController @@ -29,13 +30,13 @@ public class NpSheepMilkAnalysisController extends BaseController { */ @GetMapping("/list") public TableDataInfo list(NpSheepMilkAnalysis analysis) { - startPage(); // 使用 PageHelper 分页(注意 service 中第一个 DB 调用是 distinct sheep id) + startPage(); // 使用PageHelper分页(注意service中第一个DB调用是distinct sheep id) List list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisList(analysis); return getDataTable(list); } /** - * 获取单个分析记录详细信息(按 sheepId) + * 获取单个分析记录详细信息(按sheepId) */ @GetMapping(value = "/{sheepId}") public AjaxResult getInfo(@PathVariable("sheepId") String sheepId) { @@ -44,13 +45,13 @@ public class NpSheepMilkAnalysisController extends BaseController { /** * 导出奶产量分析记录(Excel) - * 支持 manageEarTag 与 screenDays 两个查询条件 + * 支持manageEarTag与screenDays两个查询条件 */ @Log(title = "奶产量分析 导出", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(NpSheepMilkAnalysis analysis) { - List list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisList(analysis); + List list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisForExport(analysis); ExcelUtil util = new ExcelUtil<>(NpSheepMilkAnalysis.class); return util.exportExcel(list, "羊奶产量分析数据"); } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpSheepMilkAnalysis.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpSheepMilkAnalysis.java index 0573a0d..84cedc0 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpSheepMilkAnalysis.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpSheepMilkAnalysis.java @@ -1,78 +1,141 @@ package com.zhyc.module.dairyProducts.domain; +import com.zhyc.common.annotation.Excel; import java.util.Date; public class NpSheepMilkAnalysis { // 唯一键(可用于前端 row-key) + @Excel(name = "羊只ID") private String sheepId; // 耳号(从 sheep_file.bs_manage_tags) + @Excel(name = "耳号") private String manageEarTag; + @Excel(name = "品种") private String variety; // 最高校正胎次的挤奶开始时间 & 干奶时间 + @Excel(name = "挤奶开始时间", dateFormat = "yyyy-MM-dd") private Date milkingStartTime; + + @Excel(name = "干奶时间", dateFormat = "yyyy-MM-dd") private Date dryEndTime; // 挤奶天数(该胎次) + @Excel(name = "挤奶天数") private Integer milkingDays; // 前端传入的筛选天数(screenDays) + @Excel(name = "筛选天数") private Integer screenDays; // 分析天数(若你有不同命名,可忽略) private Integer analysisDays; // 校正后最大胎次(即校正奶量之和最大的胎次) + @Excel(name = "校正后最大胎次") private Integer maxParity; // 最高校正胎次区间内的系统奶量与校正奶量(按筛选窗口) + @Excel(name = "系统奶量合计") private Double sumSystemMilk; + + @Excel(name = "校正奶量合计") private Double sumCorrectedMilk; - // 校正日平均奶量(按 min(挤奶天数, 筛选天数)) + // 校正日平均奶量(按min(挤奶天数,筛选天数)) + @Excel(name = "校正日平均奶量") private Double avgCorrectedDaily; // 各胎次总奶量(校正) + @Excel(name = "胎次1总奶量") private Double sumParity1Milk; + + @Excel(name = "胎次2总奶量") private Double sumParity2Milk; + + @Excel(name = "胎次3总奶量") private Double sumParity3Milk; + + @Excel(name = "胎次4总奶量") private Double sumParity4Milk; // 各胎次日平均(按规则) + @Excel(name = "胎次1日平均") private Double avgParity1Daily; + + @Excel(name = "胎次2日平均") private Double avgParity2Daily; + + @Excel(name = "胎次3日平均") private Double avgParity3Daily; + + @Excel(name = "胎次4日平均") private Double avgParity4Daily; // 泌乳天数(sheep_file.lactation_day) + @Excel(name = "泌乳天数") private Integer lactationDays; - // 过去 7 / 14 / 30 日平均(系统奶量) + // 过去7/14/30日平均(系统奶量) + @Excel(name = "过去7日均奶量") private Double avgLast7Milk; - private Double avgLast7Corrected; // = avgLast7Milk * weightCoefficient (默认 1.0) + + @Excel(name = "校正过去7日均") + private Double avgLast7Corrected; + + @Excel(name = "过去14日均奶量") private Double avgLast14Milk; + + @Excel(name = "过去30日均奶量") private Double avgLast30Milk; - // 羊只基础信息(来自 sheep_file) + // 羊只基础信息(来自sheep_file) + @Excel(name = "羊只类别") private String sheepCategory; + + @Excel(name = "生日", dateFormat = "yyyy-MM-dd") private Date birthday; - private Integer parity; // 当前胎次 + + @Excel(name = "当前胎次") + private Integer parity; + + @Excel(name = "月龄") private Integer monthAge; + + @Excel(name = "当前体重") private Double currentWeight; + + @Excel(name = "繁育状态") private String breedStatus; + + @Excel(name = "父号") private String fatherManageTags; + + @Excel(name = "母号") private String motherManageTags; + + @Excel(name = "牧场") private String ranchName; + + @Excel(name = "家系") private String family; // 母亲相关字段(由已计算的母亲分析结果中取值) + @Excel(name = "母亲挤奶天数") private Integer motherMilkingDays; + + @Excel(name = "母亲校正奶量合计") private Double motherSumCorrected; + + @Excel(name = "母亲校正后最大胎次") private Integer motherMaxParity; + + @Excel(name = "母亲校正日平均奶量") private Double motherAvgCorrectedDaily; + @Excel(name = "最后更新时间", dateFormat = "yyyy-MM-dd") private Date lastUpdate; // getters and setters @@ -195,4 +258,4 @@ public class NpSheepMilkAnalysis { public Date getLastUpdate() { return lastUpdate; } public void setLastUpdate(Date lastUpdate) { this.lastUpdate = lastUpdate; } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/NpSheepMilkAnalysisMapper.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/NpSheepMilkAnalysisMapper.java index 002e009..1e35d56 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/NpSheepMilkAnalysisMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/NpSheepMilkAnalysisMapper.java @@ -9,7 +9,7 @@ import java.util.Map; public interface NpSheepMilkAnalysisMapper { /** - * 按筛选天数 screenDays 统计并返回所有羊只的奶产量分析 + * 按筛选天数screenDays统计并返回所有羊只的奶产量分析 */ List selectAnalysisForExport(@Param("screenDays") Integer screenDays); @@ -33,4 +33,9 @@ public interface NpSheepMilkAnalysisMapper { */ List> selectMilkRecordsBySheepId(@Param("sheepId") String sheepId); -} + /** + * 导出奶产量分析记录 + */ + List selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis); + +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/INpSheepMilkAnalysisService.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/INpSheepMilkAnalysisService.java index 8760789..5dded5c 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/INpSheepMilkAnalysisService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/INpSheepMilkAnalysisService.java @@ -9,4 +9,9 @@ public interface INpSheepMilkAnalysisService { List selectNpSheepMilkAnalysisList(NpSheepMilkAnalysis analysis); -} + /** + * 导出奶产量分析记录 + */ + List selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis); + +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/NpSheepMilkAnalysisServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/NpSheepMilkAnalysisServiceImpl.java index 161a381..7100ca4 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/NpSheepMilkAnalysisServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/NpSheepMilkAnalysisServiceImpl.java @@ -19,7 +19,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi @Autowired private NpSheepMilkAnalysisMapper npSheepMilkAnalysisMapper; - // 将 Rec 定义为静态内部类 + // 将Rec定义为静态内部类 private static class Rec { LocalDate date; double systemMilk; @@ -27,7 +27,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi int parity; } - // 将 ParityStat 定义为静态内部类 + // 将ParityStat定义为静态内部类 private static class ParityStat { int parity; double sumCorrected; @@ -85,7 +85,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi continue; } - // 使用静态内部类 Rec + // 使用静态内部类Rec List recs = new ArrayList<>(); for (Map r : records) { Rec rr = new Rec(); @@ -98,7 +98,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi Map> byParity = recs.stream().collect(Collectors.groupingBy(r -> r.parity)); - // 使用静态内部类 ParityStat + // 使用静态内部类ParityStat List parityStats = new ArrayList<>(); for (Map.Entry> e : byParity.entrySet()) { List 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 sumParity4 = parityStats.stream().filter(p -> p.parity == 4).mapToDouble(p -> p.sumCorrected).sum(); - // 你之前的 computeParityAvg 方法里没实现,保留调用0 + // 你之前的computeParityAvg方法里没实现,保留调用0 double avgP1 = computeParityAvg(parityStats, 1, screenDays); double avgP2 = computeParityAvg(parityStats, 2, screenDays); double avgP3 = computeParityAvg(parityStats, 3, screenDays); @@ -219,6 +219,12 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi return resultList; } + @Override + public List selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis) { + // 直接调用Mapper的导出方法,避免复杂的业务逻辑 + return npSheepMilkAnalysisMapper.selectNpSheepMilkAnalysisForExport(analysis); + } + private static Date convertToDate(Object obj) { if (obj == null) return null; if (obj instanceof Date) { @@ -283,4 +289,4 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi } return (count > 0) ? (sum / count) : 0.0; } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/NpSheepMilkAnalysisMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/NpSheepMilkAnalysisMapper.xml index 8069e16..af77171 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/NpSheepMilkAnalysisMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/NpSheepMilkAnalysisMapper.xml @@ -4,7 +4,7 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + - - + - + - + + + + \ No newline at end of file From e78e0c039bce605844f2adedc08ac0c65a7c9b6f Mon Sep 17 00:00:00 2001 From: wyt <414651037@qq.com> Date: Wed, 3 Sep 2025 10:35:09 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=A0=A1=E9=AA=8C=E4=BB=A5=E5=8F=8A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/base/mapper/BasSheepGroupMapper.java | 5 +++++ .../base/service/impl/BasSheepGroupServiceImpl.java | 13 +++++++++++++ .../resources/mapper/base/BasSheepGroupMapper.xml | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepGroupMapper.java b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepGroupMapper.java index 52abe57..c14eb81 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepGroupMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepGroupMapper.java @@ -2,6 +2,7 @@ package com.zhyc.module.base.mapper; import com.zhyc.module.base.domain.BasSheepGroup; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -64,4 +65,8 @@ public interface BasSheepGroupMapper List selectLeafNodes(); + + // 新增方法:根据父节点和分组名称查询是否存在 + BasSheepGroup selectByParentIdAndGroupName(@Param("parentId") Long parentId, @Param("groupName") String groupName); + } diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepGroupServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepGroupServiceImpl.java index 3d375b3..d67a55b 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepGroupServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/BasSheepGroupServiceImpl.java @@ -1,5 +1,6 @@ package com.zhyc.module.base.service.impl; +import com.zhyc.common.exception.ServiceException; import com.zhyc.common.utils.DateUtils; import com.zhyc.module.base.domain.BasSheepGroup; import com.zhyc.module.base.mapper.BasSheepGroupMapper; @@ -68,6 +69,12 @@ public class BasSheepGroupServiceImpl implements IBasSheepGroupService @Override public int insertBasSheepGroup(BasSheepGroup basSheepGroup) { + // ✅ 新增唯一性校验 + BasSheepGroup existing = basSheepGroupMapper.selectByParentIdAndGroupName( + basSheepGroup.getParentId(), basSheepGroup.getGroupName()); + if (existing != null) { + throw new ServiceException("同一分支下已存在该分组名称"); + } basSheepGroup.setCreateTime(DateUtils.getNowDate()); return basSheepGroupMapper.insertBasSheepGroup(basSheepGroup); } @@ -81,6 +88,12 @@ public class BasSheepGroupServiceImpl implements IBasSheepGroupService @Override public int updateBasSheepGroup(BasSheepGroup basSheepGroup) { + // ✅ 新增唯一性校验(排除当前记录) + BasSheepGroup existing = basSheepGroupMapper.selectByParentIdAndGroupName( + basSheepGroup.getParentId(), basSheepGroup.getGroupName()); + if (existing != null && !existing.getGroupId().equals(basSheepGroup.getGroupId())) { + throw new ServiceException("同一分支下已存在该分组名称"); + } basSheepGroup.setUpdateTime(DateUtils.getNowDate()); return basSheepGroupMapper.updateBasSheepGroup(basSheepGroup); } diff --git a/zhyc-module/src/main/resources/mapper/base/BasSheepGroupMapper.xml b/zhyc-module/src/main/resources/mapper/base/BasSheepGroupMapper.xml index 5f0aab6..bb0ff09 100644 --- a/zhyc-module/src/main/resources/mapper/base/BasSheepGroupMapper.xml +++ b/zhyc-module/src/main/resources/mapper/base/BasSheepGroupMapper.xml @@ -126,5 +126,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + \ No newline at end of file