Compare commits

...

4 Commits

Author SHA1 Message Date
wyt
f33bf93714 修改羊只分组功能 2025-07-18 12:57:42 +08:00
wyt
a2d5c34995 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/trans_group/domain/ScTransGroup.java
#	zhyc-module/src/main/resources/mapper/produce/other/fixHoof/ScFixHoofMapper.xml
2025-07-18 12:52:26 +08:00
wyt
0aeff5f82f 修改羊只分组功能 2025-07-18 12:51:57 +08:00
wyt
21f2df110e 修改接口包导入路径 2025-07-17 10:19:16 +08:00
11 changed files with 183 additions and 118 deletions

1
.gitignore vendored
View File

@ -45,3 +45,4 @@ nbdist/
!*/build/*.java
!*/build/*.html
!*/build/*.xml
/zhyc-module/src/main/java/com/zhyc/module/group_management/service/impl/GroupServiceImpl.java

View File

@ -23,6 +23,10 @@
<version>1.18.38</version> <!-- 使用最新版本 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,17 +1,14 @@
package com.zhyc.module.fileManagement.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.zhyc.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
@ -46,6 +43,24 @@ public class BasSheepGroupMappingController extends BaseController
return getDataTable(list);
}
@PreAuthorize("@ss.hasPermi('sheep_grouping:sheep_grouping:list')")
@GetMapping("/listJoin")
public TableDataInfo list(
@RequestParam(required = false) Long sheepId,
@RequestParam(required = false) Long groupId,
@RequestParam(required = false) String bsManageTags) {
List<String> earList = null;
if (StringUtils.hasText(bsManageTags)) {
earList = Arrays.asList(bsManageTags.split("[,\\s]+"));
}
startPage();
List<Map<String,Object>> list = basSheepGroupMappingService
.selectBasSheepGroupMappingList(sheepId, groupId, earList);
return getDataTable(list);
}
/**
* 导出羊只分组关联列表
*/

View File

@ -1,8 +1,10 @@
package com.zhyc.module.fileManagement.mapper;
import java.util.List;
import com.zhyc.module.fileManagement.domain.BasSheepGroupMapping;
import java.util.Map;
import com.zhyc.module.fileManagement.domain.BasSheepGroupMapping;
import org.apache.ibatis.annotations.Param;
/**
* 羊只分组关联Mapper接口
*
@ -27,6 +29,20 @@ public interface BasSheepGroupMappingMapper
*/
public List<BasSheepGroupMapping> selectBasSheepGroupMappingList(BasSheepGroupMapping basSheepGroupMapping);
/**
* 联表查询羊只分组关联列表支持耳号列表
*/
List<Map<String, Object>> selectBasSheepGroupMappingList(
@Param("sheepId") Long sheepId,
@Param("groupId") Long groupId,
@Param("bsManageTags") List<String> bsManageTags
);
/**
* 新增羊只分组关联
*

View File

@ -1,6 +1,8 @@
package com.zhyc.module.fileManagement.service;
import java.util.List;
import java.util.Map;
import com.zhyc.module.fileManagement.domain.BasSheepGroupMapping;
/**
@ -27,6 +29,13 @@ public interface IBasSheepGroupMappingService
*/
public List<BasSheepGroupMapping> selectBasSheepGroupMappingList(BasSheepGroupMapping basSheepGroupMapping);
/**
* 联表查询羊只分组关联列表支持耳号列表
*/
List<Map<String, Object>> selectBasSheepGroupMappingList(Long sheepId, Long groupId, List<String> bsManageTags);
/**
* 新增羊只分组关联
*
@ -58,6 +67,4 @@ public interface IBasSheepGroupMappingService
* @return 结果
*/
public int deleteBasSheepGroupMappingById(Long id);
}

View File

@ -1,6 +1,8 @@
package com.zhyc.module.fileManagement.service.impl;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhyc.module.fileManagement.mapper.BasSheepGroupMappingMapper;
@ -43,6 +45,13 @@ public class BasSheepGroupMappingServiceImpl implements IBasSheepGroupMappingSer
return basSheepGroupMappingMapper.selectBasSheepGroupMappingList(basSheepGroupMapping);
}
@Override
public List<Map<String, Object>> selectBasSheepGroupMappingList(
Long sheepId, Long groupId, List<String> bsManageTags) {
return basSheepGroupMappingMapper.selectBasSheepGroupMappingList(sheepId, groupId, bsManageTags);
}
/**
* 新增羊只分组关联
*
@ -91,6 +100,4 @@ public class BasSheepGroupMappingServiceImpl implements IBasSheepGroupMappingSer
return basSheepGroupMappingMapper.deleteBasSheepGroupMappingById(id);
}
}

View File

@ -5,12 +5,10 @@ import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.common.exception.ServiceException;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.module.base.variety.domain.BasSheepVariety;
import com.zhyc.module.base.variety.service.IBasSheepVarietyService;
import com.zhyc.module.fileManagement.domain.DaSheepfold;
import com.zhyc.module.fileManagement.service.IDaSheepfoldService;
import com.zhyc.module.produce.manage_sheep.add_sheep.domain.ScAddSheep;
import com.zhyc.module.produce.manage_sheep.add_sheep.service.IScAddSheepService;
import com.zhyc.module.fileManagement.domain.DaSheepfold;
import com.zhyc.module.fileManagement.service.IDaSheepfoldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
@ -35,8 +33,6 @@ public class ScAddSheepController {
@Autowired
private IDaSheepfoldService daSheepfoldMapper;
@Autowired
private IBasSheepVarietyService basSheepVarietyService;
//新增羊只验证
@PreAuthorize("@ss.hasPermi('produce:add_sheep:add')")
@Log(title = "新增", businessType = BusinessType.INSERT)
@ -87,12 +83,7 @@ public class ScAddSheepController {
scAddSheep.setSheepfoldNameExcel(fold.getSheepfoldName());
}
}
if (scAddSheep.getVarietyId() != null) {
BasSheepVariety variety = basSheepVarietyService.selectBasSheepVarietyById(scAddSheep.getVarietyId().longValue());
if (variety != null) {
scAddSheep.setVarietyName(variety.getVariety());
}
}
list.add(scAddSheep);
util.exportExcel(response, list, "羊只信息");
}

View File

@ -2,23 +2,20 @@ package com.zhyc.module.produce.manage_sheep.add_sheep.service.impl;
import com.zhyc.common.exception.ServiceException;
import com.zhyc.common.utils.StringUtils;
import com.zhyc.module.base.variety.domain.BasSheepVariety;
import com.zhyc.module.base.variety.service.IBasSheepVarietyService;
import com.zhyc.module.fileManagement.domain.DaSheepfold;
import com.zhyc.module.fileManagement.mapper.DaSheepfoldMapper;
import com.zhyc.module.produce.manage_sheep.add_sheep.domain.ScAddSheep;
import com.zhyc.module.produce.manage_sheep.add_sheep.mapper.ScAddSheepMapper;
import com.zhyc.module.produce.manage_sheep.add_sheep.service.IScAddSheepService;
import com.zhyc.module.produce.sheep.domain.BasSheep;
import com.zhyc.module.produce.sheep.mapper.BasSheepMapper;
import com.zhyc.module.produce.sheep.service.IBasSheepService;
import com.zhyc.module.produce.sheep.service.impl.BasSheepServiceImpl;
import com.zhyc.module.fileManagement.domain.DaSheepfold;
import com.zhyc.module.fileManagement.mapper.DaSheepfoldMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class ScAddSheepServiceImpl implements IScAddSheepService {
@ -32,9 +29,6 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
@Autowired
private IBasSheepService basSheepService;
@Autowired
private IBasSheepVarietyService basSheepVarietyService;
@Override
public boolean insertScAddSheep(ScAddSheep scAddSheep) {
// 1. 重复校验
@ -68,7 +62,6 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
basSheepService.insertBasSheep(bs);
return true;
}
@Override
public List<ScAddSheep> selectScAddSheepList(ScAddSheep scAddSheep) {
return scAddSheepMapper.selectScAddSheepList(scAddSheep);
@ -86,7 +79,6 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
/* ------------------ 导入:羊舍名称 → ID ------------------ */
@Override
@Transactional(rollbackFor = Exception.class)
public String importSheep(List<ScAddSheep> list, boolean updateSupport, String operName) {
if (list == null || list.isEmpty()) {
throw new ServiceException("导入数据不能为空!");
@ -95,58 +87,50 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
int success = 0, failure = 0;
StringBuilder failureMsg = new StringBuilder();
// 1. 一次性加载全部品种和羊舍避免循环查库
Map<String, Long> varietyNameToIdMap = basSheepVarietyService
.selectBasSheepVarietyList(new BasSheepVariety())
.stream()
.collect(Collectors.toMap(
BasSheepVariety::getVariety,
BasSheepVariety::getId,
(existing, replacement) -> existing // 保留第一个
));
Map<String, Long> sheepfoldNameToIdMap = daSheepfoldMapper
.selectDaSheepfoldList(new DaSheepfold())
.stream()
.collect(Collectors.toMap(
DaSheepfold::getSheepfoldName,
DaSheepfold::getId,
(existing, replacement) -> existing // 保留第一个
));
for (int i = 0; i < list.size(); i++) {
ScAddSheep sheep = list.get(i);
try {
// 2. 羊舍名称 ID
/* 1. 羊舍名称 → ID */
if (StringUtils.isNotBlank(sheep.getSheepfoldNameExcel())) {
Long sheepfoldId = sheepfoldNameToIdMap.get(sheep.getSheepfoldNameExcel());
if (sheepfoldId == null) {
throw new ServiceException("羊舍名称不存在:" + sheep.getSheepfoldNameExcel());
DaSheepfold param = new DaSheepfold();
param.setSheepfoldName(sheep.getSheepfoldNameExcel());
List<DaSheepfold> foldList = daSheepfoldMapper.selectDaSheepfoldList(param);
if (foldList == null || foldList.isEmpty()) {
failure++;
failureMsg.append("<br/>第")
.append(i + 1)
.append("行:羊舍名称不存在【")
.append(sheep.getSheepfoldNameExcel())
.append("");
continue;
}
sheep.setSheepfold(sheepfoldId.intValue());
sheep.setSheepfold(foldList.get(0).getId().intValue());
}
// 3. 品种名称 ID
if (StringUtils.isNotBlank(sheep.getVarietyName())) {
Long varietyId = varietyNameToIdMap.get(sheep.getVarietyName());
if (varietyId == null) {
throw new ServiceException("品种名称不存在:" + sheep.getVarietyName());
}
sheep.setVarietyId(varietyId.intValue());
}
// 4. 耳号非空校验
/* 2. 耳号非空校验 */
if (StringUtils.isBlank(sheep.getEarNumber())) {
throw new ServiceException("耳号不能为空");
failure++;
failureMsg.append("<br/>第")
.append(i + 1)
.append("行:耳号不能为空");
continue;
}
// 5. 耳号重复校验
/* 3. 耳号重复校验(增量导入核心) */
ScAddSheep exist = scAddSheepMapper.selectByEarNumber(sheep.getEarNumber());
if (exist != null) {
if (!updateSupport) {
throw new ServiceException("耳号已存在:" + sheep.getEarNumber());
}
sheep.setId(exist.getId());
failure++;
failureMsg.append("<br/>第")
.append(i + 1)
.append("行:耳号已存在【")
.append(sheep.getEarNumber())
.append("");
continue;
}
/* 4. 插入或更新 */
if (updateSupport && sheep.getId() != null) {
sheep.setUpdateBy(operName);
updateScAddSheep(sheep);
} else {
@ -156,7 +140,10 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
success++;
} catch (Exception e) {
failure++;
failureMsg.append("<br/>第").append(i + 1).append("行:").append(e.getMessage());
failureMsg.append("<br/>第")
.append(i + 1)
.append("行:")
.append(e.getMessage());
}
}

View File

@ -66,6 +66,13 @@ public class ScTransGroup extends BaseEntity {
@Excel(name = "品种")
private String varietyName;
/** 品种id */
private Long varietyId;
/** 品种名称(联表查询返回,非数据库字段) */
@Excel(name = "品种")
private String varietyName;
private Integer reason;
/**
* 转群原因描述 用于导出

View File

@ -14,13 +14,57 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id, sheep_id, group_id from bas_sheep_group_mapping
</sql>
<select id="selectBasSheepGroupMappingList" parameterType="BasSheepGroupMapping" resultMap="BasSheepGroupMappingResult">
<include refid="selectBasSheepGroupMappingVo"/>
<where>
<if test="sheepId != null "> and sheep_id = #{sheepId}</if>
<if test="groupId != null "> and group_id = #{groupId}</if>
<!-- <select id="selectBasSheepGroupMappingList" parameterType="BasSheepGroupMapping" resultMap="BasSheepGroupMappingResult">-->
<!-- <include refid="selectBasSheepGroupMappingVo"/>-->
<!-- <where> -->
<!-- <if test="sheepId != null "> and sheep_id = #{sheepId}</if>-->
<!-- <if test="groupId != null "> and group_id = #{groupId}</if>-->
<!-- </where>-->
<!-- </select>-->
<select id="selectBasSheepGroupMappingList"
parameterType="map"
resultType="map"> <!-- 1. 返回 map 方便前端直接取值 -->
SELECT
m.id,
m.sheep_id,
m.group_id,
s.id AS bs_sheep_id,
s.bs_manage_tags,
s.variety,
s.gender,
s.name,
s.birthday,
s.parity,
s.month_age,
s.breed,
s.birth_weight,
s.weaning_weight,
s.current_weight,
s.father_manage_tags,
s.mother_manage_tags,
s.family
FROM bas_sheep_group_mapping m
JOIN sheep_file s ON s.id = m.sheep_id
<where>
<if test="sheepId != null"> AND m.sheep_id = #{sheepId}</if>
<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>
</if>
</where>
ORDER BY m.id
</select>
<select id="selectBasSheepGroupMappingById" parameterType="Long" resultMap="BasSheepGroupMappingResult">
<include refid="selectBasSheepGroupMappingVo"/>

View File

@ -6,9 +6,8 @@
<resultMap type="ScFixHoof" id="ScFixHoofResult">
<result property="id" column="id"/>
<result property="manageTags" column="manageTags"/>
<result property="sheepId" column="sheep_id"/>
<result property="sheepfold" column="sheepfold"/>
<result property="varietyId" column="variety_id"/>
<result property="sheepfoldName" column="sheepfoldName"/>
<result property="comment" column="comment"/>
<result property="technician" column="technician"/>
@ -18,19 +17,15 @@
<sql id="selectScFixHoofVo">
select fh.id,
bs.manage_tags AS manageTags,
fh.sheep_id,
fh.sheepfold,
sf.sheepfold_name AS sheepfoldName,
fh.variety_id,
bv.variety AS varietyName,
sf.sheepfold_name as sheepfoldName,
fh.comment,
fh.technician,
fh.create_by,
fh.create_time
from sc_fix_hoof fh
left join bas_sheep bs on fh.sheep_id = bs.id
left join da_sheepfold sf on fh.sheepfold = sf.id
left join bas_sheep_variety bv on fh.variety_id = bv.id
</sql>
<select id="selectScFixHoofList" parameterType="ScFixHoof" resultMap="ScFixHoofResult">
@ -38,15 +33,9 @@
<where>
<if test="sheepId != null ">and sheep_id = #{sheepId}</if>
<if test="sheepfold != null ">and sheepfold = #{sheepfold}</if>
<if test="varietyId != null">
and fh.variety_id = #{varietyId}
</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''">
and create_time between #{params.beginCreateTime} and #{params.endCreateTime}
</if>
<if test="manageTags != null and manageTags != ''">
and bs.manage_tags like concat('%', #{manageTags}, '%')
</if>
</where>
</select>
@ -55,24 +44,24 @@
where fh.id = #{id}
</select>
<insert id="insertScFixHoof" parameterType="ScFixHoof"
useGeneratedKeys="true" keyProperty="id">
INSERT INTO sc_fix_hoof
(sheep_id,
sheepfold,
variety_id,
<if test="comment != null">comment,</if>
<if test="technician != null and technician != ''">technician,</if>
create_by,
create_time)
VALUES
(#{sheepId},
#{sheepfold},
<if test="varietyId != null">#{varietyId},</if>
<if test="comment != null">#{comment},</if>
<if test="technician != null and technician != ''">#{technician},</if>
#{createBy},
#{createTime})
<insert id="insertScFixHoof" parameterType="ScFixHoof" useGeneratedKeys="true" keyProperty="id">
insert into sc_fix_hoof
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="sheepId != null and sheepId != ''">and fh.sheep_id like concat('%', #{sheepId}, '%')</if>
<if test="sheepfold != null">and fh.sheepfold = #{sheepfold}</if>
<if test="comment != null">comment,</if>
<if test="technician != null and technician != ''">technician,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="sheepId != null">#{sheepId},</if>
<if test="sheepfold != null">#{sheepfold},</if>
<if test="comment != null">#{comment},</if>
<if test="technician != null and technician != ''">#{technician},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateScFixHoof" parameterType="ScFixHoof">
@ -80,7 +69,6 @@
<trim prefix="SET" suffixOverrides=",">
<if test="sheepId != null">sheep_id = #{sheepId},</if>
<if test="sheepfold != null">sheepfold = #{sheepfold},</if>
<if test="varietyId != null">variety_id=#{varietyId},</if>
<if test="comment != null">comment = #{comment},</if>
<if test="technician != null and technician != ''">technician = #{technician},</if>
<if test="createBy != null">create_by = #{createBy},</if>
@ -101,6 +89,4 @@
#{id}
</foreach>
</delete>
</mapper>