Compare commits

..

No commits in common. "f33bf937149dd41aaeea43ce888b56ae8dc172f2" and "2fe36ba97d9901db571e829003823c36cb0586fa" have entirely different histories.

11 changed files with 118 additions and 183 deletions

1
.gitignore vendored
View File

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

View File

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

View File

@ -1,14 +1,17 @@
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.*;
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 com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
@ -43,24 +46,6 @@ 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,10 +1,8 @@
package com.zhyc.module.fileManagement.mapper;
import java.util.List;
import java.util.Map;
import com.zhyc.module.fileManagement.domain.BasSheepGroupMapping;
import org.apache.ibatis.annotations.Param;
/**
* 羊只分组关联Mapper接口
*
@ -29,20 +27,6 @@ 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,8 +1,6 @@
package com.zhyc.module.fileManagement.service;
import java.util.List;
import java.util.Map;
import com.zhyc.module.fileManagement.domain.BasSheepGroupMapping;
/**
@ -29,13 +27,6 @@ public interface IBasSheepGroupMappingService
*/
public List<BasSheepGroupMapping> selectBasSheepGroupMappingList(BasSheepGroupMapping basSheepGroupMapping);
/**
* 联表查询羊只分组关联列表支持耳号列表
*/
List<Map<String, Object>> selectBasSheepGroupMappingList(Long sheepId, Long groupId, List<String> bsManageTags);
/**
* 新增羊只分组关联
*
@ -67,4 +58,6 @@ public interface IBasSheepGroupMappingService
* @return 结果
*/
public int deleteBasSheepGroupMappingById(Long id);
}

View File

@ -1,8 +1,6 @@
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;
@ -45,13 +43,6 @@ 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);
}
/**
* 新增羊只分组关联
*
@ -100,4 +91,6 @@ public class BasSheepGroupMappingServiceImpl implements IBasSheepGroupMappingSer
return basSheepGroupMappingMapper.deleteBasSheepGroupMappingById(id);
}
}

View File

@ -5,10 +5,12 @@ 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.produce.manage_sheep.add_sheep.domain.ScAddSheep;
import com.zhyc.module.produce.manage_sheep.add_sheep.service.IScAddSheepService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
@ -33,6 +35,8 @@ public class ScAddSheepController {
@Autowired
private IDaSheepfoldService daSheepfoldMapper;
@Autowired
private IBasSheepVarietyService basSheepVarietyService;
//新增羊只验证
@PreAuthorize("@ss.hasPermi('produce:add_sheep:add')")
@Log(title = "新增", businessType = BusinessType.INSERT)
@ -83,7 +87,12 @@ 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,20 +2,23 @@ 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 {
@ -29,6 +32,9 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
@Autowired
private IBasSheepService basSheepService;
@Autowired
private IBasSheepVarietyService basSheepVarietyService;
@Override
public boolean insertScAddSheep(ScAddSheep scAddSheep) {
// 1. 重复校验
@ -62,6 +68,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
basSheepService.insertBasSheep(bs);
return true;
}
@Override
public List<ScAddSheep> selectScAddSheepList(ScAddSheep scAddSheep) {
return scAddSheepMapper.selectScAddSheepList(scAddSheep);
@ -79,6 +86,7 @@ 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("导入数据不能为空!");
@ -87,50 +95,58 @@ 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 {
/* 1. 羊舍名称 → ID */
// 2. 羊舍名称 ID
if (StringUtils.isNotBlank(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;
Long sheepfoldId = sheepfoldNameToIdMap.get(sheep.getSheepfoldNameExcel());
if (sheepfoldId == null) {
throw new ServiceException("羊舍名称不存在:" + sheep.getSheepfoldNameExcel());
}
sheep.setSheepfold(foldList.get(0).getId().intValue());
sheep.setSheepfold(sheepfoldId.intValue());
}
/* 2. 耳号非空校验 */
// 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. 耳号非空校验
if (StringUtils.isBlank(sheep.getEarNumber())) {
failure++;
failureMsg.append("<br/>第")
.append(i + 1)
.append("行:耳号不能为空");
continue;
throw new ServiceException("耳号不能为空");
}
/* 3. 耳号重复校验(增量导入核心) */
// 5. 耳号重复校验
ScAddSheep exist = scAddSheepMapper.selectByEarNumber(sheep.getEarNumber());
if (exist != null) {
failure++;
failureMsg.append("<br/>第")
.append(i + 1)
.append("行:耳号已存在【")
.append(sheep.getEarNumber())
.append("");
continue;
}
/* 4. 插入或更新 */
if (updateSupport && sheep.getId() != null) {
if (!updateSupport) {
throw new ServiceException("耳号已存在:" + sheep.getEarNumber());
}
sheep.setId(exist.getId());
sheep.setUpdateBy(operName);
updateScAddSheep(sheep);
} else {
@ -140,10 +156,7 @@ 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,13 +66,6 @@ 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,57 +14,13 @@ 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>-->
<!-- </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>
<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>
ORDER BY m.id
</select>
<select id="selectBasSheepGroupMappingById" parameterType="Long" resultMap="BasSheepGroupMappingResult">
<include refid="selectBasSheepGroupMappingVo"/>

View File

@ -6,8 +6,9 @@
<resultMap type="ScFixHoof" id="ScFixHoofResult">
<result property="id" column="id"/>
<result property="sheepId" column="sheep_id"/>
<result property="manageTags" column="manageTags"/>
<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"/>
@ -17,15 +18,19 @@
<sql id="selectScFixHoofVo">
select fh.id,
fh.sheep_id,
bs.manage_tags AS manageTags,
fh.sheepfold,
sf.sheepfold_name as sheepfoldName,
sf.sheepfold_name AS sheepfoldName,
fh.variety_id,
bv.variety AS varietyName,
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">
@ -33,9 +38,15 @@
<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>
@ -44,24 +55,24 @@
where fh.id = #{id}
</select>
<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 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>
<update id="updateScFixHoof" parameterType="ScFixHoof">
@ -69,6 +80,7 @@
<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>
@ -89,4 +101,6 @@
#{id}
</foreach>
</delete>
</mapper>