新需求修改

This commit is contained in:
ll 2025-12-05 17:43:37 +08:00
parent 346ba1a966
commit 859a5d2273
7 changed files with 86 additions and 67 deletions

View File

@ -5,6 +5,8 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.mapper.SxSheepSaleMapper;
import com.zhyc.module.sale.domain.SxSheepSale; import com.zhyc.module.sale.domain.SxSheepSale;
import com.zhyc.module.sale.service.ISxSheepSaleService; import com.zhyc.module.sale.service.ISxSheepSaleService;
@ -49,8 +51,9 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) // 事务控制
public int insertSxSheepSale(SxSheepSale sxSheepSale) { public int insertSxSheepSale(SxSheepSale sxSheepSale) {
// 1. 业务验证 (例如销售日期不能为空淘汰销售必须填写疾病类型等) // 1. 业务验证
validateSalesFields(sxSheepSale); validateSalesFields(sxSheepSale);
// 2. 自动计算逻辑 // 2. 自动计算逻辑
@ -77,6 +80,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int updateSxSheepSale(SxSheepSale sxSheepSale) { public int updateSxSheepSale(SxSheepSale sxSheepSale) {
// 1. 业务验证 // 1. 业务验证
validateSalesFields(sxSheepSale); validateSalesFields(sxSheepSale);
@ -84,7 +88,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
// 2. 自动计算逻辑 // 2. 自动计算逻辑
calculateSalesFields(sxSheepSale); calculateSalesFields(sxSheepSale);
// 3. 处理耳号列表多个耳号用逗号分隔 // 3. 处理耳号列表
if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) {
sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList())); sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList()));
} }
@ -116,7 +120,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
} }
/** /**
* 新增根据耳号查询羊只信息 * 根据耳号查询羊只信息
*/ */
@Override @Override
public SxSheepSale selectSheepInfoByTag(String bsManageTags) { public SxSheepSale selectSheepInfoByTag(String bsManageTags) {
@ -124,7 +128,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
} }
/** /**
* 新增自动计算总价平均体重平均单只价格 * 自动计算总价平均体重平均单只价格
*/ */
private void calculateSalesFields(SxSheepSale sxSheepSale) { private void calculateSalesFields(SxSheepSale sxSheepSale) {
String pricingMethod = sxSheepSale.getPricingMethod(); String pricingMethod = sxSheepSale.getPricingMethod();
@ -135,59 +139,48 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) {
sheepCount = sxSheepSale.getBsManageTagsList().size(); sheepCount = sxSheepSale.getBsManageTagsList().size();
} else if (sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) { } else if (sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) {
// 如果前端没有传递列表但有逗号分隔的字符串也计算数量
sheepCount = sxSheepSale.getBsManageTags().split(",").length; sheepCount = sxSheepSale.getBsManageTags().split(",").length;
} }
if ("按个体".equals(pricingMethod)) { if ("按个体".equals(pricingMethod)) {
// 总价 = 单价 * 数量
if (unitPrice != null) { if (unitPrice != null) {
sxSheepSale.setTotalPrice(unitPrice.multiply(new BigDecimal(sheepCount))); sxSheepSale.setTotalPrice(unitPrice.multiply(new BigDecimal(sheepCount)));
} }
// 平均单只价格就是单价
sxSheepSale.setAvgPricePerSheep(unitPrice); sxSheepSale.setAvgPricePerSheep(unitPrice);
} else if ("按体重".equals(pricingMethod)) { } else if ("按体重".equals(pricingMethod)) {
BigDecimal totalWeight = sxSheepSale.getTotalWeight(); BigDecimal totalWeight = sxSheepSale.getTotalWeight();
// 总价 = 单价 * 总重量
if (unitPrice != null && totalWeight != null) { if (unitPrice != null && totalWeight != null) {
sxSheepSale.setTotalPrice(unitPrice.multiply(totalWeight)); sxSheepSale.setTotalPrice(unitPrice.multiply(totalWeight));
} }
// 平均体重 = 总重量 / 数量
if (totalWeight != null && sheepCount > 0) { if (totalWeight != null && sheepCount > 0) {
sxSheepSale.setAvgWeight(totalWeight.divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP)); sxSheepSale.setAvgWeight(totalWeight.divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP));
} }
// 平均单只价格 = 总价 / 数量
if (sxSheepSale.getTotalPrice() != null && sheepCount > 0) { if (sxSheepSale.getTotalPrice() != null && sheepCount > 0) {
sxSheepSale.setAvgPricePerSheep(sxSheepSale.getTotalPrice().divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP)); sxSheepSale.setAvgPricePerSheep(sxSheepSale.getTotalPrice().divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP));
} }
} }
// 可以添加其他计价方式的逻辑
} }
/** /**
* 新增业务字段验证 * 业务字段验证 (使用 ServiceException)
*/ */
private void validateSalesFields(SxSheepSale sxSheepSale) { private void validateSalesFields(SxSheepSale sxSheepSale) {
// 验证销售日期不能为空
if (sxSheepSale.getSaleDate() == null) { if (sxSheepSale.getSaleDate() == null) {
throw new RuntimeException("销售日期不能为空!"); throw new ServiceException("销售日期不能为空!");
} }
String saleType = sxSheepSale.getSaleType(); String saleType = sxSheepSale.getSaleType();
// 如果销售类别是"淘汰销售""淘汰屠宰"则疾病类型和班组不能为空
if ("淘汰销售".equals(saleType) || "淘汰屠宰".equals(saleType)) { if ("淘汰销售".equals(saleType) || "淘汰屠宰".equals(saleType)) {
if (sxSheepSale.getDiseaseType() == null) { if (sxSheepSale.getDiseaseType() == null) {
throw new RuntimeException("淘汰销售或淘汰屠宰必须选择疾病类型!"); throw new ServiceException("淘汰销售或淘汰屠宰必须选择疾病类型!");
} }
if (sxSheepSale.getGroupCode() == null) { if (sxSheepSale.getGroupCode() == null) {
throw new RuntimeException("淘汰销售或淘汰屠宰必须选择班组!"); throw new ServiceException("淘汰销售或淘汰屠宰必须选择班组!");
} }
} }
// 如果疾病类型是"病残羊"则次要原因不能为空
if ("病残羊".equals(sxSheepSale.getDiseaseType())) { if ("病残羊".equals(sxSheepSale.getDiseaseType())) {
if (sxSheepSale.getSecondaryReason() == null || sxSheepSale.getSecondaryReason().trim().isEmpty()) { 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 FROM np_fresh_milk_insp
</sql> </sql>
<!-- 查询列表(已修改为只按来源和日期查询) -->
<select id="selectNpFreshMilkInspList" parameterType="NpFreshMilkInsp" resultMap="NpFreshMilkInspResult"> <select id="selectNpFreshMilkInspList" parameterType="NpFreshMilkInsp" resultMap="NpFreshMilkInspResult">
<include refid="selectNpFreshMilkInspVo"/> <include refid="selectNpFreshMilkInspVo"/>
<where> <where>
<if test="source != null and source != ''"> <if test="source != null and source != ''">
AND source LIKE CONCAT('%', #{source}, '%') AND source LIKE CONCAT('%', #{source}, '%')
</if> </if>
<if test="datetime != null"> <if test="params.beginTime != null and params.beginTime != ''">
AND datetime = #{datetime} AND datetime &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
AND datetime &lt;= #{params.endTime}
</if> </if>
</where> </where>
</select> </select>
<!-- 根据ID查询 -->
<select id="selectNpFreshMilkInspById" parameterType="Long" resultMap="NpFreshMilkInspResult"> <select id="selectNpFreshMilkInspById" parameterType="Long" resultMap="NpFreshMilkInspResult">
<include refid="selectNpFreshMilkInspVo"/> <include refid="selectNpFreshMilkInspVo"/>
WHERE id = #{id} WHERE id = #{id}
</select> </select>
<!-- 新增 -->
<insert id="insertNpFreshMilkInsp" parameterType="NpFreshMilkInsp" useGeneratedKeys="true" keyProperty="id"> <insert id="insertNpFreshMilkInsp" parameterType="NpFreshMilkInsp" useGeneratedKeys="true" keyProperty="id">
INSERT INTO np_fresh_milk_insp INSERT INTO np_fresh_milk_insp
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@ -96,7 +96,6 @@
</trim> </trim>
</insert> </insert>
<!-- 修改 -->
<update id="updateNpFreshMilkInsp" parameterType="NpFreshMilkInsp"> <update id="updateNpFreshMilkInsp" parameterType="NpFreshMilkInsp">
UPDATE np_fresh_milk_insp UPDATE np_fresh_milk_insp
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
@ -119,12 +118,10 @@
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<!-- 单个删除 -->
<delete id="deleteNpFreshMilkInspById" parameterType="Long"> <delete id="deleteNpFreshMilkInspById" parameterType="Long">
DELETE FROM np_fresh_milk_insp WHERE id = #{id} DELETE FROM np_fresh_milk_insp WHERE id = #{id}
</delete> </delete>
<!-- 批量删除 -->
<delete id="deleteNpFreshMilkInspByIds" parameterType="String"> <delete id="deleteNpFreshMilkInspByIds" parameterType="String">
DELETE FROM np_fresh_milk_insp WHERE id IN DELETE FROM np_fresh_milk_insp WHERE id IN
<foreach item="id" collection="array" open="(" separator="," close=")"> <foreach item="id" collection="array" open="(" separator="," close=")">

View File

@ -40,7 +40,12 @@
<select id="selectNpRawMilkInspeList" parameterType="NpRawMilkInspe" resultMap="NpRawMilkInspeResult"> <select id="selectNpRawMilkInspeList" parameterType="NpRawMilkInspe" resultMap="NpRawMilkInspeResult">
<include refid="selectNpRawMilkInspeVo"/> <include refid="selectNpRawMilkInspeVo"/>
<where> <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> <if test="source != null and source != ''"> and source like concat('%', #{source}, '%')</if>
</where> </where>
</select> </select>

View File

@ -39,8 +39,11 @@
<if test="source != null and source != ''"> <if test="source != null and source != ''">
and source like concat('%', #{source}, '%') and source like concat('%', #{source}, '%')
</if> </if>
<if test="datetime != null "> <if test="params.beginTime != null and params.beginTime != ''">
and datetime = #{datetime} and datetime &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
and datetime &lt;= #{params.endTime}
</if> </if>
</where> </where>
</select> </select>

View File

@ -13,17 +13,16 @@
<result property="coefficient" column="coefficient"/> <result property="coefficient" column="coefficient"/>
</resultMap> </resultMap>
<!-- 修改SQL片段系数保留两位小数 -->
<sql id="selectXzDryMatterCorrectionVo"> <sql id="selectXzDryMatterCorrectionVo">
SELECT SELECT
id, id,
datetime, datetime,
factory, factory,
content, content,
COALESCE(standard, 18) as standard, <!-- 设置默认值为18 --> COALESCE(standard, 18) as standard,
CASE CASE
WHEN standard = 0 OR standard IS NULL THEN NULL WHEN standard = 0 OR standard IS NULL THEN NULL
ELSE ROUND(content / standard, 2) <!-- 系数保留两位小数 --> ELSE ROUND(content / standard, 2)
END AS coefficient END AS coefficient
FROM xz_dry_matter_correction FROM xz_dry_matter_correction
</sql> </sql>
@ -31,8 +30,11 @@
<select id="selectXzDryMatterCorrectionList" parameterType="XzDryMatterCorrection" resultMap="XzDryMatterCorrectionResult"> <select id="selectXzDryMatterCorrectionList" parameterType="XzDryMatterCorrection" resultMap="XzDryMatterCorrectionResult">
<include refid="selectXzDryMatterCorrectionVo"/> <include refid="selectXzDryMatterCorrectionVo"/>
<where> <where>
<if test="datetime != null"> <if test="params.beginTime != null and params.beginTime != ''">
AND DATE_FORMAT(datetime, '%Y-%m') = DATE_FORMAT(#{datetime}, '%Y-%m') 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>
<if test="factory != null and factory != ''"> <if test="factory != null and factory != ''">
AND factory = #{factory} AND factory = #{factory}

View File

@ -30,7 +30,12 @@
<select id="selectXzWegihCorrectionList" parameterType="XzWegihCorrection" resultMap="XzWegihCorrectionResult"> <select id="selectXzWegihCorrectionList" parameterType="XzWegihCorrection" resultMap="XzWegihCorrectionResult">
<include refid="selectXzWegihCorrectionVo"/> <include refid="selectXzWegihCorrectionVo"/>
<where> <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> <if test="factory != null and factory != ''"> and factory = #{factory}</if>
</where> </where>
</select> </select>

View File

@ -36,30 +36,36 @@
<result property="createdBy" column="created_by" /> <result property="createdBy" column="created_by" />
<result property="createdAt" column="created_at" /> <result property="createdAt" column="created_at" />
<result property="remark" column="remark" /> <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> </resultMap>
<sql id="selectSxSheepSaleVo"> <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片段 -->
<sql id="selectSheepFileVo"> <sql id="selectSheepFileVo">
select select
bs_manage_tags, bs_manage_tags, variety, name as sheep_name, gender, month_age, parity, breed,
variety, post_lambing_day, lactation_day, lambing_day, sheepfold_id
name as sheep_name,
gender,
month_age,
parity,
breed,
post_lambing_day,
lactation_day,
lambing_day,
sheepfold_id
from sheep_file from sheep_file
</sql> </sql>
<!-- 【新增】根据耳号查询羊只信息 -->
<select id="selectSheepInfoByTag" parameterType="String" resultMap="SxSheepSaleResult"> <select id="selectSheepInfoByTag" parameterType="String" resultMap="SxSheepSaleResult">
<include refid="selectSheepFileVo"/> <include refid="selectSheepFileVo"/>
where bs_manage_tags = #{bsManageTags} where bs_manage_tags = #{bsManageTags}
@ -68,18 +74,26 @@
<select id="selectSxSheepSaleList" parameterType="SxSheepSale" resultMap="SxSheepSaleResult"> <select id="selectSxSheepSaleList" parameterType="SxSheepSale" resultMap="SxSheepSaleResult">
<include refid="selectSxSheepSaleVo"/> <include refid="selectSxSheepSaleVo"/>
<where> <where>
<if test="bsManageTags != null and bsManageTags != ''"> and bs_manage_tags = #{bsManageTags}</if> <if test="customerName != null and customerName != ''">
<if test="sheepfoldId != null "> and sheepfold_id = #{sheepfoldId}</if> AND c.name LIKE CONCAT('%', #{customerName}, '%')
<if test="variety != null and variety != ''"> and variety = #{variety}</if> </if>
<if test="sheepName != null and sheepName != ''"> and sheep_name = #{sheepName}</if>
<if test="saleDate != null"> and sale_date = #{saleDate}</if> <if test="salesPersonName != null and salesPersonName != ''">
<if test="saleType != null and saleType != ''"> and sale_type = #{saleType}</if> 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> </where>
</select> </select>
<select id="selectSxSheepSaleById" parameterType="Long" resultMap="SxSheepSaleResult"> <select id="selectSxSheepSaleById" parameterType="Long" resultMap="SxSheepSaleResult">
<include refid="selectSxSheepSaleVo"/> <include refid="selectSxSheepSaleVo"/>
where id = #{id} where s.id = #{id}
</select> </select>
<insert id="insertSxSheepSale" parameterType="SxSheepSale" useGeneratedKeys="true" keyProperty="id"> <insert id="insertSxSheepSale" parameterType="SxSheepSale" useGeneratedKeys="true" keyProperty="id">