Compare commits

..

2 Commits

Author SHA1 Message Date
ll
6043f22ee0 Merge remote-tracking branch 'origin/main' 2025-12-05 17:44:43 +08:00
ll
859a5d2273 新需求修改 2025-12-05 17:43:37 +08:00
7 changed files with 86 additions and 67 deletions

View File

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

View File

@ -34,26 +34,26 @@
FROM np_fresh_milk_insp
</sql>
<!-- 查询列表(已修改为只按来源和日期查询) -->
<select id="selectNpFreshMilkInspList" parameterType="NpFreshMilkInsp" resultMap="NpFreshMilkInspResult">
<include refid="selectNpFreshMilkInspVo"/>
<where>
<if test="source != null and source != ''">
AND source LIKE CONCAT('%', #{source}, '%')
</if>
<if test="datetime != null">
AND datetime = #{datetime}
<if test="params.beginTime != null and params.beginTime != ''">
AND datetime &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
AND datetime &lt;= #{params.endTime}
</if>
</where>
</select>
<!-- 根据ID查询 -->
<select id="selectNpFreshMilkInspById" parameterType="Long" resultMap="NpFreshMilkInspResult">
<include refid="selectNpFreshMilkInspVo"/>
WHERE id = #{id}
</select>
<!-- 新增 -->
<insert id="insertNpFreshMilkInsp" parameterType="NpFreshMilkInsp" useGeneratedKeys="true" keyProperty="id">
INSERT INTO np_fresh_milk_insp
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -96,7 +96,6 @@
</trim>
</insert>
<!-- 修改 -->
<update id="updateNpFreshMilkInsp" parameterType="NpFreshMilkInsp">
UPDATE np_fresh_milk_insp
<trim prefix="SET" suffixOverrides=",">
@ -119,12 +118,10 @@
WHERE id = #{id}
</update>
<!-- 单个删除 -->
<delete id="deleteNpFreshMilkInspById" parameterType="Long">
DELETE FROM np_fresh_milk_insp WHERE id = #{id}
</delete>
<!-- 批量删除 -->
<delete id="deleteNpFreshMilkInspByIds" parameterType="String">
DELETE FROM np_fresh_milk_insp WHERE id IN
<foreach item="id" collection="array" open="(" separator="," close=")">

View File

@ -40,7 +40,12 @@
<select id="selectNpRawMilkInspeList" parameterType="NpRawMilkInspe" resultMap="NpRawMilkInspeResult">
<include refid="selectNpRawMilkInspeVo"/>
<where>
<if test="datetime != null "> and datetime = #{datetime}</if>
<if test="params.beginTime != null and params.beginTime != ''">
and datetime &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
and datetime &lt;= #{params.endTime}
</if>
<if test="source != null and source != ''"> and source like concat('%', #{source}, '%')</if>
</where>
</select>

View File

@ -39,8 +39,11 @@
<if test="source != null and source != ''">
and source like concat('%', #{source}, '%')
</if>
<if test="datetime != null ">
and datetime = #{datetime}
<if test="params.beginTime != null and params.beginTime != ''">
and datetime &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
and datetime &lt;= #{params.endTime}
</if>
</where>
</select>
@ -70,7 +73,7 @@
<if test="comment != null">comment,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="source != null">#{source},</if>
<if test="datetime != null">#{datetime},</if>
@ -89,7 +92,7 @@
<if test="comment != null">#{comment},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</trim>
</insert>
<update id="updateNpYogurtInsp" parameterType="NpYogurtInsp">

View File

@ -13,26 +13,28 @@
<result property="coefficient" column="coefficient"/>
</resultMap>
<!-- 修改SQL片段系数保留两位小数 -->
<sql id="selectXzDryMatterCorrectionVo">
SELECT
id,
datetime,
factory,
content,
COALESCE(standard, 18) as standard, <!-- 设置默认值为18 -->
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
</sql>
<select id="selectXzDryMatterCorrectionList" parameterType="XzDryMatterCorrection" resultMap="XzDryMatterCorrectionResult">
<include refid="selectXzDryMatterCorrectionVo"/>
<where>
<if test="datetime != null">
AND DATE_FORMAT(datetime, '%Y-%m') = DATE_FORMAT(#{datetime}, '%Y-%m')
<if test="params.beginTime != null and params.beginTime != ''">
AND DATE_FORMAT(datetime, '%Y-%m') &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
AND DATE_FORMAT(datetime, '%Y-%m') &lt;= #{params.endTime}
</if>
<if test="factory != null and factory != ''">
AND factory = #{factory}

View File

@ -30,7 +30,12 @@
<select id="selectXzWegihCorrectionList" parameterType="XzWegihCorrection" resultMap="XzWegihCorrectionResult">
<include refid="selectXzWegihCorrectionVo"/>
<where>
<if test="datetime != null "> and datetime = #{datetime}</if>
<if test="params.beginTime != null and params.beginTime != ''">
and datetime &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
and datetime &lt;= #{params.endTime}
</if>
<if test="factory != null and factory != ''"> and factory = #{factory}</if>
</where>
</select>

View File

@ -36,30 +36,36 @@
<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" />
</resultMap>
<sql id="selectSxSheepSaleVo">
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
</sql>
<!-- 【新增】根据耳号查询羊只信息的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>
<!-- 【新增】根据耳号查询羊只信息 -->
<select id="selectSheepInfoByTag" parameterType="String" resultMap="SxSheepSaleResult">
<include refid="selectSheepFileVo"/>
where bs_manage_tags = #{bsManageTags}
@ -68,18 +74,26 @@
<select id="selectSxSheepSaleList" parameterType="SxSheepSale" resultMap="SxSheepSaleResult">
<include refid="selectSxSheepSaleVo"/>
<where>
<if test="bsManageTags != null and bsManageTags != ''"> and bs_manage_tags = #{bsManageTags}</if>
<if test="sheepfoldId != null "> and sheepfold_id = #{sheepfoldId}</if>
<if test="variety != null and variety != ''"> and variety = #{variety}</if>
<if test="sheepName != null and sheepName != ''"> and sheep_name = #{sheepName}</if>
<if test="saleDate != null"> and sale_date = #{saleDate}</if>
<if test="saleType != null and saleType != ''"> and sale_type = #{saleType}</if>
<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>
</where>
</select>
<select id="selectSxSheepSaleById" parameterType="Long" resultMap="SxSheepSaleResult">
<include refid="selectSxSheepSaleVo"/>
where id = #{id}
where s.id = #{id}
</select>
<insert id="insertSxSheepSale" parameterType="SxSheepSale" useGeneratedKeys="true" keyProperty="id">