From 859a5d22739533a14067eac6e0554bc3ecb45bb1 Mon Sep 17 00:00:00 2001
From: ll <1079863556@qq.com>
Date: Fri, 5 Dec 2025 17:43:37 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=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
---
.../service/impl/SxSheepSaleServiceImpl.java | 33 +++++------
.../dairyProducts/NpFreshMilkInspMapper.xml | 13 ++---
.../dairyProducts/NpRawMilkInspeMapper.xml | 7 ++-
.../dairyProducts/NpYogurtInspMapper.xml | 11 ++--
.../XzDryMatterCorrectionMapper.xml | 26 +++++----
.../dairyProducts/XzWegihCorrectionMapper.xml | 7 ++-
.../mapper/sale/SxSheepSaleMapper.xml | 56 ++++++++++++-------
7 files changed, 86 insertions(+), 67 deletions(-)
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 2c47d5c..8375af5 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,6 +5,8 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import com.zhyc.common.exception.ServiceException;
import com.zhyc.module.sale.mapper.SxSheepSaleMapper;
import com.zhyc.module.sale.domain.SxSheepSale;
import com.zhyc.module.sale.service.ISxSheepSaleService;
@@ -49,8 +51,9 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
* @return 结果
*/
@Override
+ @Transactional(rollbackFor = Exception.class) // 事务控制
public int insertSxSheepSale(SxSheepSale sxSheepSale) {
- // 1. 业务验证 (例如:销售日期不能为空,淘汰销售必须填写疾病类型等)
+ // 1. 业务验证
validateSalesFields(sxSheepSale);
// 2. 自动计算逻辑
@@ -77,6 +80,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
* @return 结果
*/
@Override
+ @Transactional(rollbackFor = Exception.class)
public int updateSxSheepSale(SxSheepSale sxSheepSale) {
// 1. 业务验证
validateSalesFields(sxSheepSale);
@@ -84,7 +88,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
// 2. 自动计算逻辑
calculateSalesFields(sxSheepSale);
- // 3. 处理耳号列表(多个耳号用逗号分隔)
+ // 3. 处理耳号列表
if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) {
sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList()));
}
@@ -116,7 +120,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
}
/**
- * 【新增】根据耳号查询羊只信息
+ * 根据耳号查询羊只信息
*/
@Override
public SxSheepSale selectSheepInfoByTag(String bsManageTags) {
@@ -124,7 +128,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
}
/**
- * 【新增】自动计算总价、平均体重、平均单只价格
+ * 自动计算总价、平均体重、平均单只价格
*/
private void calculateSalesFields(SxSheepSale sxSheepSale) {
String pricingMethod = sxSheepSale.getPricingMethod();
@@ -135,59 +139,48 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
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));
}
}
- // 可以添加其他计价方式的逻辑
}
/**
- * 【新增】业务字段验证
+ * 业务字段验证 (使用 ServiceException)
*/
private void validateSalesFields(SxSheepSale sxSheepSale) {
- // 验证销售日期不能为空
if (sxSheepSale.getSaleDate() == null) {
- throw new RuntimeException("销售日期不能为空!");
+ throw new ServiceException("销售日期不能为空!");
}
String saleType = sxSheepSale.getSaleType();
- // 如果销售类别是"淘汰销售"或"淘汰屠宰",则疾病类型和班组不能为空
if ("淘汰销售".equals(saleType) || "淘汰屠宰".equals(saleType)) {
if (sxSheepSale.getDiseaseType() == null) {
- throw new RuntimeException("淘汰销售或淘汰屠宰必须选择疾病类型!");
+ throw new ServiceException("淘汰销售或淘汰屠宰必须选择疾病类型!");
}
if (sxSheepSale.getGroupCode() == null) {
- throw new RuntimeException("淘汰销售或淘汰屠宰必须选择班组!");
+ throw new ServiceException("淘汰销售或淘汰屠宰必须选择班组!");
}
}
- // 如果疾病类型是"病残羊",则次要原因不能为空
if ("病残羊".equals(sxSheepSale.getDiseaseType())) {
if (sxSheepSale.getSecondaryReason() == null || sxSheepSale.getSecondaryReason().trim().isEmpty()) {
- throw new RuntimeException("疾病类型为病残羊时,必须填写次要原因!");
+ throw new ServiceException("疾病类型为病残羊时,必须填写次要原因!");
}
}
}
diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/NpFreshMilkInspMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/NpFreshMilkInspMapper.xml
index fcbb01c..edc367d 100644
--- a/zhyc-module/src/main/resources/mapper/dairyProducts/NpFreshMilkInspMapper.xml
+++ b/zhyc-module/src/main/resources/mapper/dairyProducts/NpFreshMilkInspMapper.xml
@@ -34,26 +34,26 @@
FROM np_fresh_milk_insp
-
-
-
INSERT INTO np_fresh_milk_insp
@@ -96,7 +96,6 @@
-
UPDATE np_fresh_milk_insp
@@ -119,12 +118,10 @@
WHERE id = #{id}
-
DELETE FROM np_fresh_milk_insp WHERE id = #{id}
-
DELETE FROM np_fresh_milk_insp WHERE id IN
diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/NpRawMilkInspeMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/NpRawMilkInspeMapper.xml
index c6aba37..86b7774 100644
--- a/zhyc-module/src/main/resources/mapper/dairyProducts/NpRawMilkInspeMapper.xml
+++ b/zhyc-module/src/main/resources/mapper/dairyProducts/NpRawMilkInspeMapper.xml
@@ -40,7 +40,12 @@
diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/NpYogurtInspMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/NpYogurtInspMapper.xml
index 1dcfa9f..0d47254 100644
--- a/zhyc-module/src/main/resources/mapper/dairyProducts/NpYogurtInspMapper.xml
+++ b/zhyc-module/src/main/resources/mapper/dairyProducts/NpYogurtInspMapper.xml
@@ -39,8 +39,11 @@
and source like concat('%', #{source}, '%')
-
- and datetime = #{datetime}
+
+ and datetime >= #{params.beginTime}
+
+
+ and datetime <= #{params.endTime}
@@ -70,7 +73,7 @@
comment,
create_by,
create_time,
-
+
#{source},
#{datetime},
@@ -89,7 +92,7 @@
#{comment},
#{createBy},
#{createTime},
-
+
diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml
index 0fd5b29..37ae656 100644
--- a/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml
+++ b/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml
@@ -13,26 +13,28 @@
-
SELECT
- 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
+ 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