From 38dc069ca172299f9fe62ee7da7335a9fb24a120 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Tue, 10 Feb 2026 13:46:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=80=E5=94=AE=E8=AE=B0=E5=BD=95bug?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SxSheepSaleController.java | 30 ++- .../zhyc/module/sale/domain/SxSheepSale.java | 224 ++++++++++-------- .../module/sale/mapper/SxSheepSaleMapper.java | 15 ++ .../sale/service/ISxSheepSaleService.java | 14 +- .../service/impl/SxSheepSaleServiceImpl.java | 60 +++-- .../mapper/sale/SxSheepSaleMapper.xml | 117 +++++++-- 6 files changed, 334 insertions(+), 126 deletions(-) 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 index 5cef249..7f93c77 100644 --- 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 @@ -1,6 +1,7 @@ package com.zhyc.module.sale.controller; import java.util.List; +import java.util.Date; import javax.servlet.http.HttpServletResponse; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; @@ -65,7 +66,7 @@ public class SxSheepSaleController extends BaseController { public AjaxResult getInfo(@PathVariable("id") Long id) { SxSheepSale sxSheepSale = sxSheepSaleService.selectSxSheepSaleById(id); // 将数据库中的逗号分隔的耳号字符串转换为列表 - if (sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) { + if (sxSheepSale != null && sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) { sxSheepSale.setBsManageTagsList(java.util.Arrays.asList(sxSheepSale.getBsManageTags().split(","))); } return success(sxSheepSale); @@ -81,6 +82,11 @@ public class SxSheepSaleController extends BaseController { // 【新增】自动填充当前登录用户的 userId 和 deptId sxSheepSale.setUserId(getUserId()); sxSheepSale.setDeptId(getDeptId()); + + // 【新增】自动填充创建人和创建时间,以便列表查询时显示 + sxSheepSale.setCreatedBy(getUserId()); + sxSheepSale.setCreatedAt(new Date()); + return toAjax(sxSheepSaleService.insertSxSheepSale(sxSheepSale)); } @@ -117,4 +123,26 @@ public class SxSheepSaleController extends BaseController { } return AjaxResult.success(sheepInfo); } + + /** + * 根据羊舍ID获取羊只耳号列表 + */ + @GetMapping("/listSheepBySheepfoldId") + public AjaxResult listSheepBySheepfoldId(@RequestParam Long sheepfoldId) { + List list = sxSheepSaleService.selectSheepTagsBySheepfoldId(sheepfoldId); + return AjaxResult.success(list); + } + + /** + * 【新增】搜索耳号(模糊查询) + */ + @GetMapping("/searchEarNumbers") + public AjaxResult searchEarNumbers(@RequestParam("query") String query) { + try { + List earNumbers = sxSheepSaleService.searchEarNumbers(query); + return success(earNumbers); + } catch (Exception e) { + return error("搜索耳号失败:" + e.getMessage()); + } + } } \ 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 index 892727e..e3e0908 100644 --- 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 @@ -25,46 +25,10 @@ public class SxSheepSale extends BaseEntity { @Excel(name = "耳号") private String bsManageTags; - /** 羊舍ID(当时销售的羊舍) */ - @Excel(name = "羊舍ID", readConverterExp = "当=时销售的羊舍") - private Long sheepfoldId; - /** 品种快照 */ - @Excel(name = "品种快照") + @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; @@ -74,6 +38,26 @@ public class SxSheepSale extends BaseEntity { @Excel(name = "销售日期", width = 30, dateFormat = "yyyy-MM-dd") private Date saleDate; + /** 羊只类别快照 */ + @Excel(name = "羊只类别") + private String sheepName; + + /** 性别快照 */ + @Excel(name = "性别") + private String gender; + + /** 月龄快照 */ + @Excel(name = "月龄") + private Long monthAge; + + /** 胎次快照 */ + @Excel(name = "胎次") + private Long parity; + + /** 【新增】当前重量(档案关联生成) */ + @Excel(name = "当前重量(kg)") + private BigDecimal currentWeight; + /** 计价方式 */ @Excel(name = "计价方式") private String pricingMethod; @@ -82,45 +66,37 @@ public class SxSheepSale extends BaseEntity { @Excel(name = "单价") private BigDecimal unitPrice; - /** 总价(自动计算) */ - @Excel(name = "总价", readConverterExp = "自=动计算") - private BigDecimal totalPrice; - - /** 总体重(按体重时输入) */ - @Excel(name = "总体重", readConverterExp = "按=体重时输入") - private BigDecimal totalWeight; - - /** 平均体重(自动) */ - @Excel(name = "平均体重", readConverterExp = "自=动") + /** 重量(单只羊重量:单只时为总体重,多只时为平均重) - 对应数据库 avg_weight */ + @Excel(name = "重量(kg)") private BigDecimal avgWeight; - /** 平均单只价格(自动) */ - @Excel(name = "平均单只价格", readConverterExp = "自=动") + /** 单只羊价格(单只羊销售时填的总价或计算的总价;多只羊销售时计算出每只羊的平均价格) */ + @Excel(name = "单只羊价格(元)") private BigDecimal avgPricePerSheep; /** 销售类别(dict_type = sale_type) */ - @Excel(name = "销售类别", readConverterExp = "d=ict_type,==,s=ale_type") + @Excel(name = "销售类别", dictType = "sale_type") private String saleType; - /** 疾病类型(dict_type = disea_type) */ - @Excel(name = "疾病类型", readConverterExp = "d=ict_type,==,d=isea_type") - private String diseaseType; + /** 【非数据库字段】客户名称 */ + @Excel(name = "客户名称") + private String customerName; - /** 次要原因 */ - @Excel(name = "次要原因") - private String secondaryReason; + /** 【非数据库字段】客户电话 */ + @Excel(name = "客户电话") + private String customerPhone; - /** 班组(dict_type = group) */ - @Excel(name = "班组", readConverterExp = "d=ict_type,==,g=roup") - private String groupCode; + /** 【新增】【非数据库字段】所在地区 */ + @Excel(name = "所在地区") + private String customerArea; - /** 客户ID(sx_customer.id) */ - @Excel(name = "客户ID", readConverterExp = "s=x_customer.id") - private Long customerId; + /** 【非数据库字段】客户地址 */ + @Excel(name = "详细地址") + private String customerAddress; - /** 销售人员ID(sys_user.id) */ - @Excel(name = "销售人员ID", readConverterExp = "s=ys_user.id") - private Long salesPersonId; + /** 【非数据库字段】销售人员姓名 */ + @Excel(name = "销售人员") + private String salesPersonName; /** 检疫证号 */ @Excel(name = "检疫证号") @@ -130,48 +106,91 @@ public class SxSheepSale extends BaseEntity { @Excel(name = "审批编号") private String approvalNo; - /** 技术员ID(sys_user.id) */ - @Excel(name = "技术员ID", readConverterExp = "s=ys_user.id") - private Long technicianId; + /** 疾病类型(dict_type = disease_type) */ + @Excel(name = "疾病类型", dictType = "disease_type") + private String diseaseType; - /** 处理人ID(sys_user.id) */ - @Excel(name = "处理人ID", readConverterExp = "s=ys_user.id") - private Long handlerId; + /** 次要原因 */ + @Excel(name = "次要原因") + private String secondaryReason; - /** 创建人ID(sys_user.id) */ - @Excel(name = "创建人ID", readConverterExp = "s=ys_user.id") - private Long createdBy; + /** 【非数据库字段】羊舍名称 */ + @Excel(name = "羊舍") + private String sheepfoldName; + + /** 班组(dict_type = group) */ + @Excel(name = "班组", dictType = "group") + private String groupCode; + + /** 繁育状态快照 */ + @Excel(name = "繁育状态") + private String breed; + + /** 产后天数快照 */ + @Excel(name = "销售时产后天数") + private Long postLambingDay; + + /** 泌乳天数快照 */ + @Excel(name = "销售时泌乳天数") + private Long lactationDay; + + /** 怀孕天数快照 */ + @Excel(name = "销售时怀孕天数") + private Long lambingDay; + + /** 【非数据库字段】技术员姓名 */ + @Excel(name = "技术员") + private String technicianName; + + /** 【非数据库字段】处理人姓名 */ + @Excel(name = "处理人") + private String handlerName; + + /** 【非数据库字段】创建人姓名 */ + @Excel(name = "创建人") + private String createdByName; /** 创建时间 */ @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd") + @Excel(name = "创建日期", width = 30, dateFormat = "yyyy-MM-dd") private Date createdAt; + // --- 以下字段在导出中不显示,但在业务中需要 --- + + /** 总价(自动计算) */ + private BigDecimal totalPrice; + + /** 总体重(按体重时输入) */ + private BigDecimal totalWeight; + + /** 羊舍ID(当时销售的羊舍) */ + private Long sheepfoldId; + + /** 客户ID(sx_customer.id) */ + private Long customerId; + + /** 销售人员ID(sys_user.id) */ + private Long salesPersonId; + + /** 技术员ID(sys_user.id) */ + private Long technicianId; + + /** 处理人ID(sys_user.id) */ + private Long handlerId; + + /** 创建人ID(sys_user.id) */ + private Long createdBy; + /** 用户ID */ private Long userId; /** 部门ID */ private Long deptId; - // 【新增】非数据库字段:用于前端展示和选择羊舍后传递多个耳号 - 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; + /** 【新增】非数据库字段:用于前端展示和选择羊舍后传递多个耳号 */ + private List bsManageTagsList; public void setId(Long id) { this.id = id; @@ -445,7 +464,6 @@ public class SxSheepSale extends BaseEntity { this.deptId = deptId; } - // 【新增】getter 和 setter 方法 public List getBsManageTagsList() { return bsManageTagsList; } @@ -518,6 +536,22 @@ public class SxSheepSale extends BaseEntity { this.sheepfoldName = sheepfoldName; } + public BigDecimal getCurrentWeight() { + return currentWeight; + } + + public void setCurrentWeight(BigDecimal currentWeight) { + this.currentWeight = currentWeight; + } + + public String getCustomerArea() { + return customerArea; + } + + public void setCustomerArea(String customerArea) { + this.customerArea = customerArea; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) @@ -559,11 +593,13 @@ public class SxSheepSale extends BaseEntity { .append("customerName", getCustomerName()) .append("customerPhone", getCustomerPhone()) .append("customerAddress", getCustomerAddress()) + .append("customerArea", getCustomerArea()) .append("salesPersonName", getSalesPersonName()) .append("technicianName", getTechnicianName()) .append("handlerName", getHandlerName()) .append("createdByName", getCreatedByName()) .append("sheepfoldName", getSheepfoldName()) + .append("currentWeight", getCurrentWeight()) .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 index 8b6788f..a619358 100644 --- 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 @@ -65,4 +65,19 @@ public interface SxSheepSaleMapper { * @return 羊只信息 (只包含视图中的字段) */ public SxSheepSale selectSheepInfoByTag(@Param("bsManageTags") String bsManageTags); + + /** + * 根据羊舍ID查询存栏羊只耳号列表 + * @param sheepfoldId 羊舍ID + * @return 耳号列表 + */ + public List selectSheepTagsBySheepfoldId(Long sheepfoldId); + + /** + * 【新增】模糊查询羊只耳号列表(用于前端搜索补全) + * @param query 查询关键字 + * @return 耳号列表 + */ + public List searchEarNumbers(@Param("query") String query); + } \ 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 index bbdc73a..7d647e0 100644 --- 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 @@ -59,9 +59,21 @@ public interface ISxSheepSaleService { public int deleteSxSheepSaleById(Long id); /** - * 【新增】根据耳号查询羊只信息 + * 根据耳号查询羊只信息 * @param bsManageTags 耳号 * @return 羊只信息 */ public SxSheepSale selectSheepInfoByTag(String bsManageTags); + + /** + * 根据羊舍ID查询存栏羊只耳号列表 + */ + public List selectSheepTagsBySheepfoldId(Long sheepfoldId); + + /** + * 【新增】模糊查询羊只耳号列表 + * @param query 查询关键字 + * @return 耳号列表 + */ + public List searchEarNumbers(String query); } \ 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 index dc9c026..97cfaae 100644 --- 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 @@ -5,7 +5,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.zhyc.common.annotation.DataScope; // 【新增】引入数据权限注解 +import com.zhyc.common.annotation.DataScope; import com.zhyc.module.sale.mapper.SxSheepSaleMapper; import com.zhyc.module.sale.domain.SxSheepSale; import com.zhyc.module.sale.service.ISxSheepSaleService; @@ -34,7 +34,6 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { /** * 查询羊只销售记录列表 - * 【新增】添加数据权限过滤注解 * deptAlias = "s": 对应 Mapper.xml 中表 sx_sheep_sale 的别名 s * userAlias = "s": 对应 Mapper.xml 中表 sx_sheep_sale 的别名 s * @@ -55,10 +54,10 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { */ @Override public int insertSxSheepSale(SxSheepSale sxSheepSale) { - // 1. 业务验证 (例如:销售日期不能为空,淘汰销售必须填写疾病类型等) + // 1. 业务验证 (必填项校验、级联校验) validateSalesFields(sxSheepSale); - // 2. 自动计算逻辑 + // 2. 自动计算逻辑 (价格、体重) calculateSalesFields(sxSheepSale); // 3. 设置默认事件类型 @@ -121,21 +120,34 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { } /** - * 【新增】根据耳号查询羊只信息 + * 根据耳号查询羊只信息 */ @Override public SxSheepSale selectSheepInfoByTag(String bsManageTags) { return sxSheepSaleMapper.selectSheepInfoByTag(bsManageTags); } + @Override + public List selectSheepTagsBySheepfoldId(Long sheepfoldId) { + return sxSheepSaleMapper.selectSheepTagsBySheepfoldId(sheepfoldId); + } + /** - * 【新增】自动计算总价、平均体重、平均单只价格 + * 【新增】实现模糊查询耳号 + */ + @Override + public List searchEarNumbers(String query) { + return sxSheepSaleMapper.searchEarNumbers(query); + } + + /** + * 自动计算总价、平均体重、平均单只价格 */ private void calculateSalesFields(SxSheepSale sxSheepSale) { String pricingMethod = sxSheepSale.getPricingMethod(); BigDecimal unitPrice = sxSheepSale.getUnitPrice(); - // 获取羊只数量 + // 获取羊只数量,默认为1防止除零 int sheepCount = 1; if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { sheepCount = sxSheepSale.getBsManageTagsList().size(); @@ -145,6 +157,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { } if ("按个体".equals(pricingMethod)) { + // 按个体计算逻辑 // 总价 = 单价 * 数量 if (unitPrice != null) { sxSheepSale.setTotalPrice(unitPrice.multiply(new BigDecimal(sheepCount))); @@ -152,43 +165,60 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { // 平均单只价格就是单价 sxSheepSale.setAvgPricePerSheep(unitPrice); + // 按个体时,无需计算平均体重,清空相关字段避免混淆(可视需求决定是否保留) + sxSheepSale.setAvgWeight(null); + } 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) { - // 验证销售日期不能为空 + // 1. 基础必填校验 if (sxSheepSale.getSaleDate() == null) { throw new RuntimeException("销售日期不能为空!"); } + if (sxSheepSale.getTechnicianId() == null) { + throw new RuntimeException("技术员不能为空!"); + } + if (sxSheepSale.getHandlerId() == null) { + throw new RuntimeException("处理人不能为空!"); + } + if (sxSheepSale.getGroupCode() == null || sxSheepSale.getGroupCode().trim().isEmpty()) { + throw new RuntimeException("班组不能为空!"); + } + if (sxSheepSale.getPricingMethod() == null || sxSheepSale.getPricingMethod().trim().isEmpty()) { + throw new RuntimeException("计价方式不能为空!"); + } + // 2. 级联校验 String saleType = sxSheepSale.getSaleType(); - // 如果销售类别是"淘汰销售"或"淘汰屠宰",则疾病类型和班组不能为空 + // 如果销售类别是"淘汰销售"或"淘汰屠宰",则疾病类型不能为空 if ("淘汰销售".equals(saleType) || "淘汰屠宰".equals(saleType)) { - if (sxSheepSale.getDiseaseType() == null) { + if (sxSheepSale.getDiseaseType() == null || sxSheepSale.getDiseaseType().trim().isEmpty()) { throw new RuntimeException("淘汰销售或淘汰屠宰必须选择疾病类型!"); } - if (sxSheepSale.getGroupCode() == null) { - throw new RuntimeException("淘汰销售或淘汰屠宰必须选择班组!"); - } } + // 如果疾病类型是"病残羊",则次要原因不能为空 if ("病残羊".equals(sxSheepSale.getDiseaseType())) { if (sxSheepSale.getSecondaryReason() == null || sxSheepSale.getSecondaryReason().trim().isEmpty()) { diff --git a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml index b312e02..b4c64a0 100644 --- a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml +++ b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml @@ -38,6 +38,17 @@ + + + + + + + + + + + @@ -45,6 +56,85 @@ from sx_sheep_sale s + + + + select bs_manage_tags, @@ -57,7 +147,8 @@ post_lambing_day, lactation_day, lambing_day, - sheepfold_id + sheepfold_id, + current_weight from sheep_file @@ -66,22 +157,18 @@ where bs_manage_tags = #{bsManageTags} - + SELECT bs_manage_tags + FROM sheep_file + WHERE sheepfold_id = #{sheepfoldId} - + SELECT DISTINCT bs_manage_tags + FROM sheep_file + WHERE bs_manage_tags LIKE CONCAT(#{query}, '%') + ORDER BY bs_manage_tags + LIMIT 50