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 - and datetime = #{datetime} + + and datetime >= #{params.beginTime} + + + and datetime <= #{params.endTime} + and factory = #{factory} diff --git a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml index 00ac0da..b8e1e2f 100644 --- a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml +++ b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml @@ -36,30 +36,36 @@ + + + + + - 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 + s.id, s.bs_manage_tags, s.sheepfold_id, s.variety, s.sheep_name, s.gender, s.month_age, s.parity, s.breed, + s.post_lambing_day, s.lactation_day, s.lambing_day, s.event_type, s.sale_date, s.pricing_method, + s.unit_price, s.total_price, s.total_weight, s.avg_weight, s.avg_price_per_sheep, s.sale_type, + s.disease_type, s.secondary_reason, s.group_code, s.customer_id, s.sales_person_id, + s.quarantine_no, s.approval_no, s.technician_id, s.handler_id, s.created_by, s.created_at, s.remark, + c.name AS customer_name, + c.phone AS customer_phone, + CONCAT(IFNULL(c.province,''), IFNULL(c.city,''), IFNULL(c.district,''), IFNULL(c.address,'')) AS customer_address, + u.nick_name AS sales_person_name + FROM sx_sheep_sale s + LEFT JOIN sx_customer c ON s.customer_id = c.id + LEFT JOIN sys_user u ON s.sales_person_id = u.user_id - select - bs_manage_tags, - variety, - name as sheep_name, - gender, - month_age, - parity, - breed, - post_lambing_day, - lactation_day, - lambing_day, - sheepfold_id + 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 - - and bs_manage_tags = #{bsManageTags} - and sheepfold_id = #{sheepfoldId} - and variety = #{variety} - and sheep_name = #{sheepName} - and sale_date = #{saleDate} - and sale_type = #{saleType} + + AND c.name LIKE CONCAT('%', #{customerName}, '%') + + + + AND u.nick_name LIKE CONCAT('%', #{salesPersonName}, '%') + + + + AND date_format(s.sale_date,'%y%m%d') >= date_format(#{params.beginSaleDate},'%y%m%d') + + + AND date_format(s.sale_date,'%y%m%d') <= date_format(#{params.endSaleDate},'%y%m%d') +