销售管理数据分离修改

This commit is contained in:
ll
2026-02-05 21:56:49 +08:00
parent 51d1c5d145
commit 7cc0f806ba
8 changed files with 203 additions and 76 deletions

View File

@@ -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));
}
}
}

View File

@@ -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));
}

View File

@@ -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();
}
}
}

View File

@@ -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<String> 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<String> 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())

View File

@@ -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<SxCustomer> 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);
}
}
}

View File

@@ -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<SxSheepSale> 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("疾病类型为病残羊时,必须填写次要原因!");
}
}
}

View File

@@ -11,23 +11,26 @@
<result property="district" column="district"/>
<result property="address" column="address"/>
<result property="remark" column="remark"/>
<result property="userId" column="user_id"/>
<result property="deptId" column="dept_id"/>
</resultMap>
<sql id="selectSxCustomerVo">
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
</sql>
<select id="selectSxCustomerList" parameterType="SxCustomer" resultMap="SxCustomerResult">
<include refid="selectSxCustomerVo"/>
<where>
<if test="name != null and name != ''"> AND name LIKE CONCAT('%', #{name}, '%')</if>
<if test="name != null and name != ''"> AND c.name LIKE CONCAT('%', #{name}, '%')</if>
${params.dataScope}
</where>
</select>
<select id="selectSxCustomerById" parameterType="Long" resultMap="SxCustomerResult">
<include refid="selectSxCustomerVo"/>
WHERE id = #{id}
WHERE c.id = #{id}
</select>
<insert id="insertSxCustomer" parameterType="SxCustomer" useGeneratedKeys="true" keyProperty="id">
@@ -40,6 +43,8 @@
<if test="district != null">district,</if>
<if test="address != null">address,</if>
<if test="remark != null">remark,</if>
<if test="userId != null">user_id,</if>
<if test="deptId != null">dept_id,</if>
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if>
@@ -49,6 +54,8 @@
<if test="district != null">#{district},</if>
<if test="address != null">#{address},</if>
<if test="remark != null">#{remark},</if>
<if test="userId != null">#{userId},</if>
<if test="deptId != null">#{deptId},</if>
</trim>
</insert>
@@ -76,4 +83,4 @@
#{id}
</foreach>
</delete>
</mapper>
</mapper>

View File

@@ -36,33 +36,28 @@
<result property="createdBy" column="created_by" />
<result property="createdAt" column="created_at" />
<result property="remark" column="remark" />
<result property="customerName" column="customer_name" />
<result property="salesPersonName" column="sales_person_name" />
<result property="customerPhone" column="customer_phone" />
<result property="customerAddress" column="customer_address" />
<result property="userId" column="user_id" />
<result property="deptId" column="dept_id" />
</resultMap>
<sql id="selectSxSheepSaleVo">
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
</sql>
<sql id="selectSheepFileVo">
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
</sql>
@@ -74,20 +69,13 @@
<select id="selectSxSheepSaleList" parameterType="SxSheepSale" resultMap="SxSheepSaleResult">
<include refid="selectSxSheepSaleVo"/>
<where>
<if test="customerName != null and customerName != ''">
AND c.name LIKE CONCAT('%', #{customerName}, '%')
</if>
<if test="salesPersonName != null and salesPersonName != ''">
AND u.nick_name LIKE CONCAT('%', #{salesPersonName}, '%')
</if>
<if test="params.beginSaleDate != null and params.beginSaleDate != ''">
AND date_format(s.sale_date,'%y%m%d') &gt;= date_format(#{params.beginSaleDate},'%y%m%d')
</if>
<if test="params.endSaleDate != null and params.endSaleDate != ''">
AND date_format(s.sale_date,'%y%m%d') &lt;= date_format(#{params.endSaleDate},'%y%m%d')
</if>
<if test="bsManageTags != null and bsManageTags != ''"> and s.bs_manage_tags = #{bsManageTags}</if>
<if test="sheepfoldId != null "> and s.sheepfold_id = #{sheepfoldId}</if>
<if test="variety != null and variety != ''"> and s.variety = #{variety}</if>
<if test="sheepName != null and sheepName != ''"> and s.sheep_name = #{sheepName}</if>
<if test="saleDate != null"> and s.sale_date = #{saleDate}</if>
<if test="saleType != null and saleType != ''"> and s.sale_type = #{saleType}</if>
${params.dataScope}
</where>
</select>
@@ -131,6 +119,8 @@
<if test="createdBy != null">created_by,</if>
<if test="createdAt != null">created_at,</if>
<if test="remark != null">remark,</if>
<if test="userId != null">user_id,</if>
<if test="deptId != null">dept_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="bsManageTags != null and bsManageTags != ''">#{bsManageTags},</if>
@@ -165,6 +155,8 @@
<if test="createdBy != null">#{createdBy},</if>
<if test="createdAt != null">#{createdAt},</if>
<if test="remark != null">#{remark},</if>
<if test="userId != null">#{userId},</if>
<if test="deptId != null">#{deptId},</if>
</trim>
</insert>