From 7cc0f806bae53eb68173c17d9a389e07a77de688 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Thu, 5 Feb 2026 21:56:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=80=E5=94=AE=E7=AE=A1=E7=90=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=88=86=E7=A6=BB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sale/controller/SxCustomerController.java | 5 +- .../controller/SxSheepSaleController.java | 3 + .../zhyc/module/sale/domain/SxCustomer.java | 122 ++++++++++++++---- .../zhyc/module/sale/domain/SxSheepSale.java | 24 ++++ .../service/impl/SxCustomerServiceImpl.java | 10 +- .../service/impl/SxSheepSaleServiceImpl.java | 38 ++++-- .../mapper/sale/SxCustomerMapper.xml | 17 ++- .../mapper/sale/SxSheepSaleMapper.xml | 60 ++++----- 8 files changed, 203 insertions(+), 76 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxCustomerController.java b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxCustomerController.java index 5d1bf65..5fc7735 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxCustomerController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxCustomerController.java @@ -66,6 +66,9 @@ public class SxCustomerController extends BaseController { @Log(title = "客户管理", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody SxCustomer sxCustomer) { + // 【新增】自动填充当前登录用户的 userId 和 deptId + sxCustomer.setUserId(getUserId()); + sxCustomer.setDeptId(getDeptId()); return toAjax(sxCustomerService.insertSxCustomer(sxCustomer)); } @@ -82,4 +85,4 @@ public class SxCustomerController extends BaseController { public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(sxCustomerService.deleteSxCustomerByIds(ids)); } -} +} \ No newline at end of file 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 307ac92..5cef249 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 @@ -78,6 +78,9 @@ public class SxSheepSaleController extends BaseController { @Log(title = "羊只销售记录", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody SxSheepSale sxSheepSale) { + // 【新增】自动填充当前登录用户的 userId 和 deptId + sxSheepSale.setUserId(getUserId()); + sxSheepSale.setDeptId(getDeptId()); return toAjax(sxSheepSaleService.insertSxSheepSale(sxSheepSale)); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomer.java b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomer.java index 458b1c4..c6f717b 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomer.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomer.java @@ -5,56 +5,134 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.zhyc.common.annotation.Excel; import com.zhyc.common.core.domain.BaseEntity; +/** + * 客户管理对象 sx_customer + * * @author ruoyi + * @date 2025-08-18 + */ public class SxCustomer extends BaseEntity { private static final long serialVersionUID = 1L; + /** 主键ID */ private Long id; + /** 客户名称 */ @Excel(name = "客户名称") private String name; + /** 客户电话 */ @Excel(name = "客户电话") private String phone; + /** 省 */ @Excel(name = "省") private String province; + /** 市 */ @Excel(name = "市") private String city; + /** 区县 */ @Excel(name = "区县") private String district; + /** 详细地址 */ @Excel(name = "详细地址") private String address; + /** 用户ID */ + private Long userId; + + /** 部门ID */ + private Long deptId; + // Getters and Setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - 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 getProvince() { return province; } - public void setProvince(String province) { this.province = province; } - public String getCity() { return city; } - public void setCity(String city) { this.city = city; } - public String getDistrict() { return district; } - public void setDistrict(String district) { this.district = district; } - public String getAddress() { return address; } - public void setAddress(String address) { this.address = address; } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + 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 getProvince() { + return province; + } + + public void setProvince(String province) { + this.province = province; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getDistrict() { + return district; + } + + public void setDistrict(String district) { + this.district = district; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - .append("id", id) - .append("name", name) - .append("phone", phone) - .append("province", province) - .append("city", city) - .append("district", district) - .append("address", address) + .append("id", getId()) + .append("name", getName()) + .append("phone", getPhone()) + .append("province", getProvince()) + .append("city", getCity()) + .append("district", getDistrict()) + .append("address", getAddress()) .append("remark", getRemark()) + .append("userId", getUserId()) + .append("deptId", getDeptId()) .toString(); } -} +} \ 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 aab27dc..892727e 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 @@ -147,6 +147,12 @@ public class SxSheepSale extends BaseEntity { @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd") private Date createdAt; + /** 用户ID */ + private Long userId; + + /** 部门ID */ + private Long deptId; + // 【新增】非数据库字段:用于前端展示和选择羊舍后传递多个耳号 private List bsManageTagsList; @@ -423,6 +429,22 @@ public class SxSheepSale extends BaseEntity { return createdAt; } + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } + // 【新增】getter 和 setter 方法 public List getBsManageTagsList() { return bsManageTagsList; @@ -531,6 +553,8 @@ public class SxSheepSale extends BaseEntity { .append("handlerId", getHandlerId()) .append("createdBy", getCreatedBy()) .append("createdAt", getCreatedAt()) + .append("userId", getUserId()) + .append("deptId", getDeptId()) .append("remark", getRemark()) .append("customerName", getCustomerName()) .append("customerPhone", getCustomerPhone()) diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxCustomerServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxCustomerServiceImpl.java index 2973e30..1e43d69 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxCustomerServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxCustomerServiceImpl.java @@ -3,6 +3,7 @@ package com.zhyc.module.sale.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.zhyc.common.annotation.DataScope; // 【新增】引入数据权限注解 import com.zhyc.module.sale.mapper.SxCustomerMapper; import com.zhyc.module.sale.domain.SxCustomer; import com.zhyc.module.sale.service.ISxCustomerService; @@ -17,7 +18,14 @@ public class SxCustomerServiceImpl implements ISxCustomerService { return sxCustomerMapper.selectSxCustomerById(id); } + /** + * 查询客户管理列表 + * 【新增】添加数据权限过滤注解 + * deptAlias = "c": 对应 Mapper.xml 中表 sx_customer 的别名 c + * userAlias = "c": 对应 Mapper.xml 中表 sx_customer 的别名 c + */ @Override + @DataScope(deptAlias = "c", userAlias = "c") public List selectSxCustomerList(SxCustomer sxCustomer) { return sxCustomerMapper.selectSxCustomerList(sxCustomer); } @@ -41,4 +49,4 @@ public class SxCustomerServiceImpl implements ISxCustomerService { public int deleteSxCustomerById(Long id) { return sxCustomerMapper.deleteSxCustomerById(id); } -} +} \ 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 8375af5..dc9c026 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,8 +5,7 @@ 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.common.annotation.DataScope; // 【新增】引入数据权限注解 import com.zhyc.module.sale.mapper.SxSheepSaleMapper; import com.zhyc.module.sale.domain.SxSheepSale; import com.zhyc.module.sale.service.ISxSheepSaleService; @@ -35,11 +34,15 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { /** * 查询羊只销售记录列表 + * 【新增】添加数据权限过滤注解 + * deptAlias = "s": 对应 Mapper.xml 中表 sx_sheep_sale 的别名 s + * userAlias = "s": 对应 Mapper.xml 中表 sx_sheep_sale 的别名 s * * @param sxSheepSale 羊只销售记录 * @return 羊只销售记录 */ @Override + @DataScope(deptAlias = "s", userAlias = "s") public List selectSxSheepSaleList(SxSheepSale sxSheepSale) { return sxSheepSaleMapper.selectSxSheepSaleList(sxSheepSale); } @@ -51,9 +54,8 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { * @return 结果 */ @Override - @Transactional(rollbackFor = Exception.class) // 事务控制 public int insertSxSheepSale(SxSheepSale sxSheepSale) { - // 1. 业务验证 + // 1. 业务验证 (例如:销售日期不能为空,淘汰销售必须填写疾病类型等) validateSalesFields(sxSheepSale); // 2. 自动计算逻辑 @@ -80,7 +82,6 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { * @return 结果 */ @Override - @Transactional(rollbackFor = Exception.class) public int updateSxSheepSale(SxSheepSale sxSheepSale) { // 1. 业务验证 validateSalesFields(sxSheepSale); @@ -88,7 +89,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { // 2. 自动计算逻辑 calculateSalesFields(sxSheepSale); - // 3. 处理耳号列表 + // 3. 处理耳号列表(多个耳号用逗号分隔) if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList())); } @@ -120,7 +121,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { } /** - * 根据耳号查询羊只信息 + * 【新增】根据耳号查询羊只信息 */ @Override public SxSheepSale selectSheepInfoByTag(String bsManageTags) { @@ -128,7 +129,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { } /** - * 自动计算总价、平均体重、平均单只价格 + * 【新增】自动计算总价、平均体重、平均单只价格 */ private void calculateSalesFields(SxSheepSale sxSheepSale) { String pricingMethod = sxSheepSale.getPricingMethod(); @@ -139,48 +140,59 @@ 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 ServiceException("销售日期不能为空!"); + throw new RuntimeException("销售日期不能为空!"); } String saleType = sxSheepSale.getSaleType(); + // 如果销售类别是"淘汰销售"或"淘汰屠宰",则疾病类型和班组不能为空 if ("淘汰销售".equals(saleType) || "淘汰屠宰".equals(saleType)) { if (sxSheepSale.getDiseaseType() == null) { - throw new ServiceException("淘汰销售或淘汰屠宰必须选择疾病类型!"); + throw new RuntimeException("淘汰销售或淘汰屠宰必须选择疾病类型!"); } if (sxSheepSale.getGroupCode() == null) { - throw new ServiceException("淘汰销售或淘汰屠宰必须选择班组!"); + throw new RuntimeException("淘汰销售或淘汰屠宰必须选择班组!"); } } + // 如果疾病类型是"病残羊",则次要原因不能为空 if ("病残羊".equals(sxSheepSale.getDiseaseType())) { if (sxSheepSale.getSecondaryReason() == null || sxSheepSale.getSecondaryReason().trim().isEmpty()) { - throw new ServiceException("疾病类型为病残羊时,必须填写次要原因!"); + throw new RuntimeException("疾病类型为病残羊时,必须填写次要原因!"); } } } diff --git a/zhyc-module/src/main/resources/mapper/sale/SxCustomerMapper.xml b/zhyc-module/src/main/resources/mapper/sale/SxCustomerMapper.xml index 97c0954..b6f20ac 100644 --- a/zhyc-module/src/main/resources/mapper/sale/SxCustomerMapper.xml +++ b/zhyc-module/src/main/resources/mapper/sale/SxCustomerMapper.xml @@ -11,23 +11,26 @@ + + - SELECT id, name, phone, province, city, district, address, remark - FROM sx_customer + SELECT c.id, c.name, c.phone, c.province, c.city, c.district, c.address, c.remark, c.user_id, c.dept_id + FROM sx_customer c @@ -40,6 +43,8 @@ district, address, remark, + user_id, + dept_id, #{name}, @@ -49,6 +54,8 @@ #{district}, #{address}, #{remark}, + #{userId}, + #{deptId}, @@ -76,4 +83,4 @@ #{id} - + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml index b8e1e2f..b312e02 100644 --- a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml +++ b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml @@ -36,33 +36,28 @@ - - - - - + + - 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 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, s.user_id, s.dept_id + from sx_sheep_sale s 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 @@ -74,20 +69,13 @@ @@ -131,6 +119,8 @@ created_by, created_at, remark, + user_id, + dept_id, #{bsManageTags}, @@ -165,6 +155,8 @@ #{createdBy}, #{createdAt}, #{remark}, + #{userId}, + #{deptId},