Compare commits

..

No commits in common. "6043f22ee0c4e4433f38242e198cebbfea0f16c2" and "f95798707973edcd482234d43afc7d2c8255f244" have entirely different histories.

7 changed files with 67 additions and 86 deletions

View File

@ -5,8 +5,6 @@ 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;
@ -51,9 +49,8 @@ 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. 自动计算逻辑
@ -80,7 +77,6 @@ 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);
@ -88,7 +84,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()));
} }
@ -120,7 +116,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
} }
/** /**
* 根据耳号查询羊只信息 * 新增根据耳号查询羊只信息
*/ */
@Override @Override
public SxSheepSale selectSheepInfoByTag(String bsManageTags) { public SxSheepSale selectSheepInfoByTag(String bsManageTags) {
@ -128,7 +124,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService {
} }
/** /**
* 自动计算总价平均体重平均单只价格 * 新增自动计算总价平均体重平均单只价格
*/ */
private void calculateSalesFields(SxSheepSale sxSheepSale) { private void calculateSalesFields(SxSheepSale sxSheepSale) {
String pricingMethod = sxSheepSale.getPricingMethod(); String pricingMethod = sxSheepSale.getPricingMethod();
@ -139,48 +135,59 @@ 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 ServiceException("销售日期不能为空!"); throw new RuntimeException("销售日期不能为空!");
} }
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 ServiceException("淘汰销售或淘汰屠宰必须选择疾病类型!"); throw new RuntimeException("淘汰销售或淘汰屠宰必须选择疾病类型!");
} }
if (sxSheepSale.getGroupCode() == null) { if (sxSheepSale.getGroupCode() == null) {
throw new ServiceException("淘汰销售或淘汰屠宰必须选择班组!"); throw new RuntimeException("淘汰销售或淘汰屠宰必须选择班组!");
} }
} }
// 如果疾病类型是"病残羊"则次要原因不能为空
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 ServiceException("疾病类型为病残羊时,必须填写次要原因!"); throw new RuntimeException("疾病类型为病残羊时,必须填写次要原因!");
} }
} }
} }

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="params.beginTime != null and params.beginTime != ''"> <if test="datetime != null">
AND datetime &gt;= #{params.beginTime} AND datetime = #{datetime}
</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,6 +96,7 @@
</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=",">
@ -118,10 +119,12 @@
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,12 +40,7 @@
<select id="selectNpRawMilkInspeList" parameterType="NpRawMilkInspe" resultMap="NpRawMilkInspeResult"> <select id="selectNpRawMilkInspeList" parameterType="NpRawMilkInspe" resultMap="NpRawMilkInspeResult">
<include refid="selectNpRawMilkInspeVo"/> <include refid="selectNpRawMilkInspeVo"/>
<where> <where>
<if test="params.beginTime != null and params.beginTime != ''"> <if test="datetime != null "> and datetime = #{datetime}</if>
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,11 +39,8 @@
<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="params.beginTime != null and params.beginTime != ''"> <if test="datetime != null ">
and datetime &gt;= #{params.beginTime} and datetime = #{datetime}
</if>
<if test="params.endTime != null and params.endTime != ''">
and datetime &lt;= #{params.endTime}
</if> </if>
</where> </where>
</select> </select>
@ -73,7 +70,7 @@
<if test="comment != null">comment,</if> <if test="comment != null">comment,</if>
<if test="createBy != null">create_by,</if> <if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="source != null">#{source},</if> <if test="source != null">#{source},</if>
<if test="datetime != null">#{datetime},</if> <if test="datetime != null">#{datetime},</if>
@ -92,7 +89,7 @@
<if test="comment != null">#{comment},</if> <if test="comment != null">#{comment},</if>
<if test="createBy != null">#{createBy},</if> <if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
</trim> </trim>
</insert> </insert>
<update id="updateNpYogurtInsp" parameterType="NpYogurtInsp"> <update id="updateNpYogurtInsp" parameterType="NpYogurtInsp">

View File

@ -13,28 +13,26 @@
<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, COALESCE(standard, 18) as standard, <!-- 设置默认值为18 -->
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>
<select id="selectXzDryMatterCorrectionList" parameterType="XzDryMatterCorrection" resultMap="XzDryMatterCorrectionResult"> <select id="selectXzDryMatterCorrectionList" parameterType="XzDryMatterCorrection" resultMap="XzDryMatterCorrectionResult">
<include refid="selectXzDryMatterCorrectionVo"/> <include refid="selectXzDryMatterCorrectionVo"/>
<where> <where>
<if test="params.beginTime != null and params.beginTime != ''"> <if test="datetime != null">
AND DATE_FORMAT(datetime, '%Y-%m') &gt;= #{params.beginTime} AND DATE_FORMAT(datetime, '%Y-%m') = DATE_FORMAT(#{datetime}, '%Y-%m')
</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,12 +30,7 @@
<select id="selectXzWegihCorrectionList" parameterType="XzWegihCorrection" resultMap="XzWegihCorrectionResult"> <select id="selectXzWegihCorrectionList" parameterType="XzWegihCorrection" resultMap="XzWegihCorrectionResult">
<include refid="selectXzWegihCorrectionVo"/> <include refid="selectXzWegihCorrectionVo"/>
<where> <where>
<if test="params.beginTime != null and params.beginTime != ''"> <if test="datetime != null "> and datetime = #{datetime}</if>
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,36 +36,30 @@
<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 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
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, variety, name as sheep_name, gender, month_age, parity, breed, bs_manage_tags,
post_lambing_day, lactation_day, lambing_day, sheepfold_id variety,
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}
@ -74,26 +68,18 @@
<select id="selectSxSheepSaleList" parameterType="SxSheepSale" resultMap="SxSheepSaleResult"> <select id="selectSxSheepSaleList" parameterType="SxSheepSale" resultMap="SxSheepSaleResult">
<include refid="selectSxSheepSaleVo"/> <include refid="selectSxSheepSaleVo"/>
<where> <where>
<if test="customerName != null and customerName != ''"> <if test="bsManageTags != null and bsManageTags != ''"> and bs_manage_tags = #{bsManageTags}</if>
AND c.name LIKE CONCAT('%', #{customerName}, '%') <if test="sheepfoldId != null "> and sheepfold_id = #{sheepfoldId}</if>
</if> <if test="variety != null and variety != ''"> and variety = #{variety}</if>
<if test="sheepName != null and sheepName != ''"> and sheep_name = #{sheepName}</if>
<if test="salesPersonName != null and salesPersonName != ''"> <if test="saleDate != null"> and sale_date = #{saleDate}</if>
AND u.nick_name LIKE CONCAT('%', #{salesPersonName}, '%') <if test="saleType != null and saleType != ''"> and sale_type = #{saleType}</if>
</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 s.id = #{id} where id = #{id}
</select> </select>
<insert id="insertSxSheepSale" parameterType="SxSheepSale" useGeneratedKeys="true" keyProperty="id"> <insert id="insertSxSheepSale" parameterType="SxSheepSale" useGeneratedKeys="true" keyProperty="id">