Merge remote-tracking branch 'main/main'

This commit is contained in:
piaobo 2025-07-21 19:28:52 +08:00
commit 898add567d
7 changed files with 216 additions and 64 deletions

View File

@ -18,6 +18,11 @@ import com.zhyc.module.base.service.IBasSheepGroupMappingService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;
// 1. 导入
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 羊只分组关联Controller
*
@ -43,6 +48,10 @@ public class BasSheepGroupMappingController extends BaseController
return getDataTable(list);
}
// 2. 声明放在类内部方法外部
private static final Logger log = LoggerFactory.getLogger(BasSheepGroupMappingController.class);
@PreAuthorize("@ss.hasPermi('sheep_grouping:sheep_grouping:list')")
@GetMapping("/listJoin")
public TableDataInfo list(
@ -103,7 +112,11 @@ public class BasSheepGroupMappingController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody BasSheepGroupMapping basSheepGroupMapping)
{
return toAjax(basSheepGroupMappingService.updateBasSheepGroupMapping(basSheepGroupMapping));
try {
return toAjax(basSheepGroupMappingService.updateBasSheepGroupMapping(basSheepGroupMapping));
} catch (RuntimeException e) {
return error(e.getMessage());
}
}
/**
@ -116,4 +129,20 @@ public class BasSheepGroupMappingController extends BaseController
{
return toAjax(basSheepGroupMappingService.deleteBasSheepGroupMappingByIds(ids));
}
@PostMapping("/addByEarTags")
public AjaxResult addByEarTags(@RequestBody Map<String, Object> params) {
List<String> earTags = (List<String>) params.get("earTags");
Long groupId = Long.valueOf(params.get("groupId").toString());
if (earTags == null || earTags.isEmpty()) {
return error("耳号列表不能为空");
}
return basSheepGroupMappingService.addByEarTags(earTags, groupId);
}
}

View File

@ -76,4 +76,11 @@ public interface BasSheepGroupMappingMapper
public int deleteBasSheepGroupMappingByIds(Long[] ids);
List<Map<String, Object>> selectSheepIdsByEarTags(@Param("earTags") List<String> earTags);
int batchInsert(@Param("list") List<BasSheepGroupMapping> list);
List<BasSheepGroupMapping> selectListByGroupId(@Param("groupId") Long groupId);
}

View File

@ -3,6 +3,7 @@ package com.zhyc.module.base.service;
import java.util.List;
import java.util.Map;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.module.base.domain.BasSheepGroupMapping;
/**
@ -67,4 +68,6 @@ public interface IBasSheepGroupMappingService
* @return 结果
*/
public int deleteBasSheepGroupMappingById(Long id);
public AjaxResult addByEarTags(List<String> earTags, Long groupId);
}

View File

@ -1,8 +1,9 @@
package com.zhyc.module.base.service.impl;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.module.base.domain.BasSheepGroupMapping;
import com.zhyc.module.base.mapper.BasSheepGroupMappingMapper;
import com.zhyc.module.base.service.IBasSheepGroupMappingService;
@ -70,9 +71,21 @@ public class BasSheepGroupMappingServiceImpl implements IBasSheepGroupMappingSer
* @param basSheepGroupMapping 羊只分组关联
* @return 结果
*/
// @Override
// public int updateBasSheepGroupMapping(BasSheepGroupMapping basSheepGroupMapping)
// {
// return basSheepGroupMappingMapper.updateBasSheepGroupMapping(basSheepGroupMapping);
// }
@Override
public int updateBasSheepGroupMapping(BasSheepGroupMapping basSheepGroupMapping)
{
public int updateBasSheepGroupMapping(BasSheepGroupMapping basSheepGroupMapping) {
Long SheepId = basSheepGroupMapping.getSheepId();
Long GroupId = basSheepGroupMapping.getGroupId();
existsInGroup(SheepId,GroupId);
if (existsInGroup(basSheepGroupMapping.getSheepId(), basSheepGroupMapping.getGroupId())) {
throw new RuntimeException("该羊已在此分组,无需修改");
}
return basSheepGroupMappingMapper.updateBasSheepGroupMapping(basSheepGroupMapping);
}
@ -100,4 +113,77 @@ public class BasSheepGroupMappingServiceImpl implements IBasSheepGroupMappingSer
return basSheepGroupMappingMapper.deleteBasSheepGroupMappingById(id);
}
@Override
public AjaxResult addByEarTags(List<String> earTags, Long groupId) {
// 1. 参数判空
if (earTags == null || earTags.isEmpty()) {
return AjaxResult.error("耳号列表不能为空");
}
// 2. 根据耳号查询羊只manage_tags -> id
List<Map<String, Object>> sheepList = basSheepGroupMappingMapper.selectSheepIdsByEarTags(earTags);
Map<String, Long> tagToId = new HashMap<>();
for (Map<String, Object> s : sheepList) {
tagToId.put((String) s.get("manage_tags"), ((Number) s.get("id")).longValue());
}
// 3. 不存在的耳号
List<String> missing = new ArrayList<>();
for (String tag : earTags) {
if (!tagToId.containsKey(tag)) {
missing.add(tag);
}
}
if (!missing.isEmpty()) {
Map<String, Object> res = new HashMap<>();
res.put("success", false);
res.put("missing", missing);
return AjaxResult.success(res);
}
// 4. 查询该分组下已存在的羊只ID
List<BasSheepGroupMapping> existingRows = basSheepGroupMappingMapper.selectListByGroupId(groupId);
System.out.println("🔍 existingRows 类型 = " + existingRows.getClass());
Set<Long> existingIds = existingRows.stream()
.map(BasSheepGroupMapping::getSheepId)
.collect(Collectors.toSet());
System.out.println("🔍 existingIds = " + existingIds);
// 5. 过滤出未在该分组的羊只
List<BasSheepGroupMapping> toInsert = new ArrayList<>();
for (Map.Entry<String, Long> e : tagToId.entrySet()) {
Long sheepId = e.getValue();
if (!existingIds.contains(sheepId)) {
BasSheepGroupMapping m = new BasSheepGroupMapping();
m.setSheepId(sheepId);
m.setGroupId(groupId);
toInsert.add(m);
}
}
if (toInsert.isEmpty()) {
return AjaxResult.success("所选羊只已全部在该分组中");
}
// 6. 批量插入
int rows = basSheepGroupMappingMapper.batchInsert(toInsert);
Map<String, Object> res = new HashMap<>();
res.put("success", true);
res.put("inserted", rows);
return AjaxResult.success(res);
}
private boolean existsInGroup(Long sheepId, Long groupId) {
BasSheepGroupMapping param = new BasSheepGroupMapping();
List<Map<String, Object>> list = basSheepGroupMappingMapper
.selectBasSheepGroupMappingList(sheepId, groupId, null);
return !list.isEmpty();
}
}

View File

@ -52,19 +52,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="groupId != null"> AND m.group_id = #{groupId}</if>
<if test="bsManageTags != null and bsManageTags.size > 0">
AND s.bs_manage_tags IN
<foreach collection="bsManageTags" item="bsManageTag " open="(" separator="," close=")">
#{bsManageTag}
<foreach collection="bsManageTags" item="tag" open="(" separator="," close=")">
#{tag}
</foreach>
</if>
</where>
ORDER BY m.id
</select>
<select id="selectBasSheepGroupMappingById" parameterType="Long" resultMap="BasSheepGroupMappingResult">
<include refid="selectBasSheepGroupMappingVo"/>
@ -102,4 +97,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<!-- 根据耳号查询羊只ID -->
<select id="selectSheepIdsByEarTags" parameterType="list" resultType="map">
SELECT id, manage_tags
FROM bas_sheep
WHERE manage_tags IN
<foreach collection="earTags" item="tag" open="(" separator="," close=")">
#{tag}
</foreach>
</select>
<!-- 批量插入 -->
<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO bas_sheep_group_mapping (sheep_id, group_id)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.sheepId}, #{item.groupId})
</foreach>
</insert>
<select id="selectListByGroupId"
resultMap="BasSheepGroupMappingResult">
SELECT id, sheep_id, group_id
FROM bas_sheep_group_mapping
WHERE group_id = #{groupId}
</select>
</mapper>

View File

@ -1,62 +1,61 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhyc.module.dairyProducts.mapper.NpFreshMilkInspMapper">
<resultMap type="NpFreshMilkInsp" id="NpFreshMilkInspResult">
<result property="id" column="id" />
<result property="source" column="source" />
<result property="datetime" column="datetime" />
<result property="fat" column="fat" />
<result property="protein" column="protein" />
<result property="nonFat" column="non_fat" />
<result property="acidity" column="acidity" />
<result property="bacterialColony1" column="bacterial_colony_1" />
<result property="bacterialColony2" column="bacterial_colony_2" />
<result property="bacterialColony3" column="bacterial_colony_3" />
<result property="bacterialColony4" column="bacterial_colony_4" />
<result property="bacterialColony5" column="bacterial_colony_5" />
<result property="coli" column="coli" />
<result property="lactoferrin" column="lactoferrin" />
<result property="ig" column="ig" />
<result property="commnet" column="commnet" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="id" column="id" />
<result property="source" column="source" />
<result property="datetime" column="datetime" />
<result property="fat" column="fat" />
<result property="protein" column="protein" />
<result property="nonFat" column="non_fat" />
<result property="acidity" column="acidity" />
<result property="bacterialColony1" column="bacterial_colony_1" />
<result property="bacterialColony2" column="bacterial_colony_2" />
<result property="bacterialColony3" column="bacterial_colony_3" />
<result property="bacterialColony4" column="bacterial_colony_4" />
<result property="bacterialColony5" column="bacterial_colony_5" />
<result property="coli" column="coli" />
<result property="lactoferrin" column="lactoferrin" />
<result property="ig" column="ig" />
<result property="commnet" column="commnet" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
</resultMap>
<sql id="selectNpFreshMilkInspVo">
select id, source, datetime, fat, protein, non_fat, acidity, bacterial_colony_1, bacterial_colony_2, bacterial_colony_3, bacterial_colony_4, bacterial_colony_5, coli, lactoferrin, ig, commnet, create_by, create_time from np_fresh_milk_insp
SELECT
id, source, datetime, fat, protein, non_fat, acidity,
bacterial_colony_1, bacterial_colony_2, bacterial_colony_3,
bacterial_colony_4, bacterial_colony_5, coli, lactoferrin,
ig, commnet, create_by, create_time
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 = #{source}</if>
<if test="datetime != null "> and datetime = #{datetime}</if>
<if test="fat != null "> and fat = #{fat}</if>
<if test="protein != null "> and protein = #{protein}</if>
<if test="nonFat != null "> and non_fat = #{nonFat}</if>
<if test="acidity != null "> and acidity = #{acidity}</if>
<if test="bacterialColony1 != null "> and bacterial_colony_1 = #{bacterialColony1}</if>
<if test="bacterialColony2 != null "> and bacterial_colony_2 = #{bacterialColony2}</if>
<if test="bacterialColony3 != null "> and bacterial_colony_3 = #{bacterialColony3}</if>
<if test="bacterialColony4 != null "> and bacterial_colony_4 = #{bacterialColony4}</if>
<if test="bacterialColony5 != null "> and bacterial_colony_5 = #{bacterialColony5}</if>
<if test="coli != null "> and coli = #{coli}</if>
<if test="lactoferrin != null "> and lactoferrin = #{lactoferrin}</if>
<if test="ig != null "> and ig = #{ig}</if>
<if test="commnet != null and commnet != ''"> and commnet = #{commnet}</if>
<where>
<if test="source != null and source != ''">
AND source LIKE CONCAT('%', #{source}, '%')
</if>
<if test="datetime != null">
AND datetime = #{datetime}
</if>
</where>
</select>
<!-- 根据ID查询 -->
<select id="selectNpFreshMilkInspById" parameterType="Long" resultMap="NpFreshMilkInspResult">
<include refid="selectNpFreshMilkInspVo"/>
where id = #{id}
WHERE id = #{id}
</select>
<!-- 新增 -->
<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=",">
<if test="source != null">source,</if>
<if test="datetime != null">datetime,</if>
@ -75,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="commnet != null">commnet,</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>
@ -94,11 +93,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="commnet != null">#{commnet},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</trim>
</insert>
<!-- 修改 -->
<update id="updateNpFreshMilkInsp" parameterType="NpFreshMilkInsp">
update np_fresh_milk_insp
UPDATE np_fresh_milk_insp
<trim prefix="SET" suffixOverrides=",">
<if test="source != null">source = #{source},</if>
<if test="datetime != null">datetime = #{datetime},</if>
@ -115,18 +115,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="lactoferrin != null">lactoferrin = #{lactoferrin},</if>
<if test="ig != null">ig = #{ig},</if>
<if test="commnet != null">commnet = #{commnet},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where id = #{id}
WHERE id = #{id}
</update>
<!-- 单个删除 -->
<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 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=")">
#{id}
</foreach>

View File

@ -26,7 +26,11 @@
</resultMap>
<sql id="selectNpYogurtInspVo">
select id, source, datetime, fat, protein, non_fat, acidity, bacterial_colony_1, bacterial_clony_2, bacterial_clony_3, bacterial_clony_4, bacterial_clony_5, yeast, mould, lacto, comment, create_by, create_time from np_yogurt_insp
select id, source, datetime, fat, protein, non_fat,
acidity, bacterial_colony_1, bacterial_clony_2,
bacterial_clony_3, bacterial_clony_4, bacterial_clony_5,
yeast, mould, lacto, comment, create_by, create_time
from np_yogurt_insp
</sql>
<select id="selectNpYogurtInspList" parameterType="NpYogurtInsp" resultMap="NpYogurtInspResult">
@ -40,7 +44,7 @@
</if>
</where>
</select>
<select id="selectNpYogurtInspById" parameterType="Long" resultMap="NpYogurtInspResult">
<include refid="selectNpYogurtInspVo"/>
where id = #{id}
@ -117,7 +121,7 @@
</delete>
<delete id="deleteNpYogurtInspByIds" parameterType="String">
delete from np_yogurt_insp where id in
delete from np_yogurt_insp where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>