diff --git a/.gitignore b/.gitignore index ed8368a..7feea44 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/zhyc-module/pom.xml b/zhyc-module/pom.xml index a3a00b5..78bc63d 100644 --- a/zhyc-module/pom.xml +++ b/zhyc-module/pom.xml @@ -23,6 +23,10 @@ 1.18.38 provided + + org.projectlombok + lombok + \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/fileManagement/controller/BasSheepGroupMappingController.java b/zhyc-module/src/main/java/com/zhyc/module/fileManagement/controller/BasSheepGroupMappingController.java index b1d3417..99aac40 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/fileManagement/controller/BasSheepGroupMappingController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/fileManagement/controller/BasSheepGroupMappingController.java @@ -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 earList = null; + if (StringUtils.hasText(bsManageTags)) { + earList = Arrays.asList(bsManageTags.split("[,,\\s]+")); + } + startPage(); + List> list = basSheepGroupMappingService + .selectBasSheepGroupMappingList(sheepId, groupId, earList); + return getDataTable(list); + } + + /** * 导出羊只分组关联列表 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/fileManagement/mapper/BasSheepGroupMappingMapper.java b/zhyc-module/src/main/java/com/zhyc/module/fileManagement/mapper/BasSheepGroupMappingMapper.java index f38bf34..d919e95 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/fileManagement/mapper/BasSheepGroupMappingMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/fileManagement/mapper/BasSheepGroupMappingMapper.java @@ -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 selectBasSheepGroupMappingList(BasSheepGroupMapping basSheepGroupMapping); + + /** + * 联表查询羊只分组关联列表(支持耳号列表) + */ + List> selectBasSheepGroupMappingList( + @Param("sheepId") Long sheepId, + @Param("groupId") Long groupId, + @Param("bsManageTags") List bsManageTags + ); + + + + + /** * 新增羊只分组关联 * diff --git a/zhyc-module/src/main/java/com/zhyc/module/fileManagement/service/IBasSheepGroupMappingService.java b/zhyc-module/src/main/java/com/zhyc/module/fileManagement/service/IBasSheepGroupMappingService.java index febb461..0c543e4 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/fileManagement/service/IBasSheepGroupMappingService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/fileManagement/service/IBasSheepGroupMappingService.java @@ -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 selectBasSheepGroupMappingList(BasSheepGroupMapping basSheepGroupMapping); + + /** + * 联表查询羊只分组关联列表(支持耳号列表) + */ + List> selectBasSheepGroupMappingList(Long sheepId, Long groupId, List bsManageTags); + + /** * 新增羊只分组关联 * @@ -58,6 +67,4 @@ public interface IBasSheepGroupMappingService * @return 结果 */ public int deleteBasSheepGroupMappingById(Long id); - - } diff --git a/zhyc-module/src/main/java/com/zhyc/module/fileManagement/service/impl/BasSheepGroupMappingServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/fileManagement/service/impl/BasSheepGroupMappingServiceImpl.java index d428848..f119bed 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/fileManagement/service/impl/BasSheepGroupMappingServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/fileManagement/service/impl/BasSheepGroupMappingServiceImpl.java @@ -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> selectBasSheepGroupMappingList( + Long sheepId, Long groupId, List bsManageTags) { + return basSheepGroupMappingMapper.selectBasSheepGroupMappingList(sheepId, groupId, bsManageTags); + } + /** * 新增羊只分组关联 * @@ -91,6 +100,4 @@ public class BasSheepGroupMappingServiceImpl implements IBasSheepGroupMappingSer return basSheepGroupMappingMapper.deleteBasSheepGroupMappingById(id); } - - } diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/add_sheep/controller/ScAddSheepController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/add_sheep/controller/ScAddSheepController.java index 7f9c07a..07d8261 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/add_sheep/controller/ScAddSheepController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/add_sheep/controller/ScAddSheepController.java @@ -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, "羊只信息"); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/add_sheep/service/impl/ScAddSheepServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/add_sheep/service/impl/ScAddSheepServiceImpl.java index 7d6b1db..95e5e72 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/add_sheep/service/impl/ScAddSheepServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/add_sheep/service/impl/ScAddSheepServiceImpl.java @@ -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 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 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 varietyNameToIdMap = basSheepVarietyService - .selectBasSheepVarietyList(new BasSheepVariety()) - .stream() - .collect(Collectors.toMap( - BasSheepVariety::getVariety, - BasSheepVariety::getId, - (existing, replacement) -> existing // 保留第一个 - )); - - Map 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 foldList = daSheepfoldMapper.selectDaSheepfoldList(param); + + if (foldList == null || foldList.isEmpty()) { + failure++; + failureMsg.append("
第") + .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("
第") + .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("
第") + .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("
第").append(i + 1).append("行:").append(e.getMessage()); + failureMsg.append("
第") + .append(i + 1) + .append("行:") + .append(e.getMessage()); } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/trans_group/domain/ScTransGroup.java b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/trans_group/domain/ScTransGroup.java index bee29eb..5c23503 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/trans_group/domain/ScTransGroup.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/trans_group/domain/ScTransGroup.java @@ -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; /** * 转群原因描述 用于导出 diff --git a/zhyc-module/src/main/resources/mapper/fileManagement/BasSheepGroupMappingMapper.xml b/zhyc-module/src/main/resources/mapper/fileManagement/BasSheepGroupMappingMapper.xml index ef8d1de..f67f033 100644 --- a/zhyc-module/src/main/resources/mapper/fileManagement/BasSheepGroupMappingMapper.xml +++ b/zhyc-module/src/main/resources/mapper/fileManagement/BasSheepGroupMappingMapper.xml @@ -14,13 +14,57 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select id, sheep_id, group_id from bas_sheep_group_mapping - + + 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 + + AND m.sheep_id = #{sheepId} + AND m.group_id = #{groupId} + + AND s.bs_manage_tags IN + + #{bsManageTag} + + + ORDER BY m.id + + + + + + @@ -38,15 +33,9 @@ and sheep_id = #{sheepId} and sheepfold = #{sheepfold} - - and fh.variety_id = #{varietyId} - and create_time between #{params.beginCreateTime} and #{params.endCreateTime} - - and bs.manage_tags like concat('%', #{manageTags}, '%') - @@ -55,24 +44,24 @@ where fh.id = #{id} - - INSERT INTO sc_fix_hoof - (sheep_id, - sheepfold, - variety_id, - comment, - technician, - create_by, - create_time) - VALUES - (#{sheepId}, - #{sheepfold}, - #{varietyId}, - #{comment}, - #{technician}, - #{createBy}, - #{createTime}) + + insert into sc_fix_hoof + + and fh.sheep_id like concat('%', #{sheepId}, '%') + and fh.sheepfold = #{sheepfold} + comment, + technician, + create_by, + create_time, + + + #{sheepId}, + #{sheepfold}, + #{comment}, + #{technician}, + #{createBy}, + #{createTime}, + @@ -80,7 +69,6 @@ sheep_id = #{sheepId}, sheepfold = #{sheepfold}, - variety_id=#{varietyId}, comment = #{comment}, technician = #{technician}, create_by = #{createBy}, @@ -101,6 +89,4 @@ #{id} - - \ No newline at end of file