羊只档案查询修改

This commit is contained in:
ll
2026-02-04 17:35:48 +08:00
parent fd16c66412
commit 51d1c5d145
6 changed files with 523 additions and 297 deletions

View File

@@ -10,23 +10,18 @@ import com.zhyc.common.enums.BusinessType;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.module.base.domain.SheepFile;
import com.zhyc.module.base.service.ISheepFileService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
* 羊只档案Controller
*
* @author wyt
* * @author wyt
* @date 2025-07-13
*/
@RestController
@@ -52,7 +47,7 @@ public class SheepFileController extends BaseController
Integer pageSize = 10;
if (queryParams != null && !queryParams.isEmpty()) {
// 提取分页参数
// ------------------ 1. 处理分页参数 ------------------
if (queryParams.containsKey("pageNum") && queryParams.get("pageNum") != null) {
try {
pageNum = Integer.parseInt(queryParams.get("pageNum").toString());
@@ -60,7 +55,6 @@ public class SheepFileController extends BaseController
// 使用默认值
}
} else if (queryParams.containsKey("page") && queryParams.get("page") != null) {
// 如果 pageNum 不存在,则尝试使用 page
try {
pageNum = Integer.parseInt(queryParams.get("page").toString());
} catch (NumberFormatException e) {
@@ -68,15 +62,13 @@ public class SheepFileController extends BaseController
}
}
if (queryParams.containsKey("pageSize") && queryParams.get("pageSize") != null) {
try {
pageSize = Integer.parseInt(queryParams.get("pageSize").toString());
} catch (NumberFormatException e) {
// 使用默认值
}
}else if (queryParams.containsKey("limit") && queryParams.get("limit") != null) {
// 如果 pageSize 不存在,则尝试使用 limit
} else if (queryParams.containsKey("limit") && queryParams.get("limit") != null) {
try {
pageSize = Integer.parseInt(queryParams.get("limit").toString());
} catch (NumberFormatException e) {
@@ -84,7 +76,25 @@ public class SheepFileController extends BaseController
}
}
// 提取常规查询参数到 SheepFile 对象
// ------------------ 2. 核心修复:处理 List 多选参数 ------------------
// 使用 parseList 方法兼容处理 List、Array、逗号分隔字符串
sheepFile.setAllEarNumbers(parseList(queryParams.get("allEarNumbers")));
sheepFile.setAllEleEarNumbers(parseList(queryParams.get("allEleEarNumbers")));
sheepFile.setAllBreedingStatus(parseList(queryParams.get("allBreedingStatus")));
sheepFile.setAllSheepTypes(parseList(queryParams.get("allSheepTypes")));
// 性别处理 (需要将 String/Integer 转为 Long)
List<String> genderStrs = parseList(queryParams.get("allGenders"));
if (genderStrs != null && !genderStrs.isEmpty()) {
List<Long> genderLongs = new ArrayList<>();
for (String s : genderStrs) {
Long v = convertToLong(s);
if(v != null) genderLongs.add(v);
}
sheepFile.setAllGenders(genderLongs);
}
// ------------------ 3. 处理常规单值参数 ------------------
if (queryParams.containsKey("bsManageTags") && queryParams.get("bsManageTags") != null) {
sheepFile.setBsManageTags(queryParams.get("bsManageTags").toString());
}
@@ -110,23 +120,17 @@ public class SheepFileController extends BaseController
sheepFile.setBreed(queryParams.get("breed").toString());
}
// 移除已经处理的参数,剩下的作为自定义筛选参数
// ------------------ 4. 提取自定义参数 (排除已处理的键) ------------------
// 定义需要跳过的key防止重复处理
Set<String> processedKeys = new HashSet<>(Arrays.asList(
"pageNum", "pageSize", "page", "limit",
"bsManageTags", "electronicTags", "drRanch", "variety", "name", "gender", "statusId", "breed",
"allEarNumbers", "allEleEarNumbers", "allGenders", "allBreedingStatus", "allSheepTypes"
));
for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
// 跳过常规参数和分页参数
if ("bsManageTags".equals(key) || "electronicTags".equals(key) ||
"drRanch".equals(key) || "variety".equals(key) ||
"name".equals(key) || "gender".equals(key) ||
"statusId".equals(key) || "breed".equals(key) ||
"pageNum".equals(key) || "pageSize".equals(key)) {
continue;
}
// 添加到自定义参数中
if (value != null) {
customParams.put(key, value);
if (!processedKeys.contains(entry.getKey()) && entry.getValue() != null) {
customParams.put(entry.getKey(), entry.getValue());
}
}
}
@@ -139,6 +143,41 @@ public class SheepFileController extends BaseController
return getDataTable(list);
}
/**
* 辅助方法:统一解析各种格式的数组参数
* 支持List, String[] (数组), Object[] (数组), "A,B" (逗号分隔字符串)
*/
private List<String> parseList(Object obj) {
if (obj == null) return null;
List<String> result = new ArrayList<>();
if (obj instanceof List) {
// JSON 传来的通常是 List
for (Object o : (List<?>) obj) {
if (o != null) result.add(o.toString());
}
} else if (obj.getClass().isArray()) {
// 如果是数组
if (obj instanceof Object[]) {
for (Object o : (Object[]) obj) {
if (o != null) result.add(o.toString());
}
} else if (obj instanceof String[]) {
Collections.addAll(result, (String[]) obj);
}
} else if (obj instanceof String) {
// 如果是逗号分隔字符串
String s = (String) obj;
if (StringUtils.isNotBlank(s)) {
String[] split = s.split(",");
Collections.addAll(result, split);
}
}
return result.isEmpty() ? null : result;
}
/**
* 转换对象为Long类型
*/
@@ -186,6 +225,7 @@ public class SheepFileController extends BaseController
// 使用若依框架的工具方法处理参数
switch (key) {
// --- 单值参数 ---
case "bsManageTags":
sheepFile.setBsManageTags(convertToString(value));
break;
@@ -210,6 +250,30 @@ public class SheepFileController extends BaseController
case "breed":
sheepFile.setBreed(convertToString(value));
break;
// --- 新增:处理多选数组参数 ---
// request.getParameterMap 中的值本身就是 String[],可以直接使用
case "allEarNumbers":
sheepFile.setAllEarNumbers(new ArrayList<>(Arrays.asList(values)));
break;
case "allEleEarNumbers":
sheepFile.setAllEleEarNumbers(new ArrayList<>(Arrays.asList(values)));
break;
case "allBreedingStatus":
sheepFile.setAllBreedingStatus(new ArrayList<>(Arrays.asList(values)));
break;
case "allSheepTypes":
sheepFile.setAllSheepTypes(new ArrayList<>(Arrays.asList(values)));
break;
case "allGenders":
List<Long> genderList = new ArrayList<>();
for(String v : values){
Long l = Convert.toLong(v);
if(l != null) genderList.add(l);
}
sheepFile.setAllGenders(genderList);
break;
case "pageNum":
case "pageSize":
// 忽略分页参数
@@ -230,6 +294,14 @@ public class SheepFileController extends BaseController
util.exportExcel(response, list, "羊只档案数据");
}
/**
* 新增:模糊搜索耳号接口 (用于前端下拉框远程搜索)
*/
@GetMapping("/searchEarNumbers")
public AjaxResult searchEarNumbers(@RequestParam("query") String query)
{
return success(sheepFileService.searchEarNumbers(query));
}
/**
* 字符串转换工具方法
@@ -252,15 +324,14 @@ public class SheepFileController extends BaseController
}
/*
* 根据耳号查询是否存在羊舍
* */
* 根据耳号查询是否存在羊舍
* */
@GetMapping("/byNo/{manageTags}")
public AjaxResult byManageTags(@PathVariable String manageTags){
SheepFile sheep=sheepFileService.selectBasSheepByManageTags(manageTags.trim());
return success(sheep);
}
@GetMapping("/stat/sheepType")
public AjaxResult statSheepType() {
return success(sheepFileService.countBySheepType());
@@ -289,43 +360,18 @@ public class SheepFileController extends BaseController
/**
* 新增API获取字段的唯一值列表
*
* 这个API为前端自定义筛选功能提供数据支持
* 当用户选择某个字段进行筛选时,前端调用此接口获取该字段的所有可能值
*
* @param fieldName 字段名(数据库列名)
* @return AjaxResult 包含字段值列表的响应结果
*
* 接口地址GET /sheep_file/sheep_file/field/{fieldName}
*
* 使用示例:
* 前端请求GET /sheep_file/sheep_file/field/bs_manage_tags
* 后端返回:{ "code": 200, "msg": "操作成功", "data": ["AF00001", "AF00002", "AF00003"] }
*
* 安全说明:
* - 使用白名单机制防止SQL注入
* - 只有预定义的字段名可以被查询
*/
@GetMapping("/field/{fieldName}")
public AjaxResult getFieldValues(@PathVariable String fieldName) {
try {
// 调用Service层获取字段唯一值
List<String> fieldValues = sheepFileService.getFieldValues(fieldName);
// 返回成功响应,包含字段值列表
return AjaxResult.success("获取字段值成功", fieldValues);
} catch (IllegalArgumentException e) {
// 处理字段名不合法的异常
// 这种情况通常是因为前端传入了不在白名单中的字段名
return AjaxResult.error("请求的字段名不合法: " + e.getMessage());
} catch (Exception e) {
// 处理其他未知异常
// 记录日志并返回友好的错误信息
logger.error("获取字段值失败,字段名: " + fieldName, e);
return AjaxResult.error("系统错误,获取字段值失败");
}
}
}
}

View File

@@ -8,11 +8,11 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
* 羊只档案对象 sheep_file
*
* @author wyt
* * @author wyt
* @date 2025-07-13
*/
@Data
@@ -29,6 +29,10 @@ public class SheepFile extends BaseEntity
@Excel(name = "管理耳号")
private String bsManageTags;
/** ================= 新增:多选查询字段 ================= */
/** 耳号集合(多选/模糊查询用) */
private List<String> allEarNumbers;
/** 牧场id */
// @Excel(name = "牧场id")
private Long ranchId;
@@ -49,6 +53,10 @@ public class SheepFile extends BaseEntity
@Excel(name = "电子耳号")
private String electronicTags;
/** ================= 新增:多选查询字段 ================= */
/** 电子耳号集合(多选查询用) */
private List<String> allEleEarNumbers;
/** 品种id */
// @Excel(name = "品种id")
private Long varietyId;
@@ -65,14 +73,22 @@ public class SheepFile extends BaseEntity
@Excel(name = "羊只类型")
private String name;
/** ================= 新增:多选查询字段 ================= */
/** 羊只类型集合(多选查询用) */
private List<String> allSheepTypes;
// /** 性别 */
//// @Excel(name = "性别")
// private Long gender;
/** 性别 - 使用字典转换 */
@Excel(name = "性别", dictType = "sheep_gender") // 添加 dictType
@Excel(name = "性别", dictType = "sheep_gender")
private Long gender;
/** ================= 新增:多选查询字段 ================= */
/** 性别集合(多选查询用) */
private List<Long> allGenders;
/** 出生日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "出生日期", width = 30, dateFormat = "yyyy-MM-dd")
@@ -103,7 +119,6 @@ public class SheepFile extends BaseEntity
@Excel(name = "羊只状态", dictType = "sheep_status")
private Long statusId;
/** 断奶体重 */
@Excel(name = "断奶体重")
private Double weaningWeight;
@@ -129,6 +144,10 @@ public class SheepFile extends BaseEntity
@Excel(name = "繁殖状态")
private String breed;
/** ================= 新增:多选查询字段 ================= */
/** 繁殖状态集合(多选查询用) */
private List<String> allBreedingStatus;
/** 父号id */
// @Excel(name = "父号id")
private Long bsFatherId;
@@ -300,6 +319,4 @@ public class SheepFile extends BaseEntity
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "创建日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date createTime;
}
}

View File

@@ -27,13 +27,19 @@ public interface SheepFileMapper
public SheepFile selectSheepFileById(Long id);
/**
* 查询羊只档案列表
* 查询羊只档案列表 (基础查询)
*
* @param sheepFile 羊只档案
* @return 羊只档案集合
*/
public List<SheepFile> selectSheepFileList(SheepFile sheepFile);
/**
* 新增:模糊查询耳号列表(用于下拉框远程搜索)
* @param query 搜索关键字
* @return 匹配的耳号列表
*/
List<String> searchEarNumbers(@Param("query") String query);
/**
* 根据管理耳号查询
@@ -43,11 +49,9 @@ public interface SheepFileMapper
*/
SheepFile selectSheepByManageTags(String tags);
// 在群羊只总数
Long countInGroup();
// 羊只类别分布(按 name 分组)
List<Map<String,Object>> countBySheepType();
@@ -60,52 +64,34 @@ public interface SheepFileMapper
// 泌乳羊胎次分布name = '泌乳羊' 时按 parity 分组)
List<Map<String,Object>> countParityOfLactation();
/**
* 新增方法:获取指定字段的唯一值列表
*
* 这个方法用于查询数据库中某个字段的所有不重复的值
* 主要用于前端筛选条件中的下拉选项数据
*
* @param fieldName 字段名(数据库表中的列名)
* @return 该字段的所有唯一值列表,按字母顺序排序
*
* 使用场景示例:
* - 用户选择"耳号"字段时,返回所有不重复的耳号
* - 用户选择"品种"字段时,返回所有不重复的品种名称
* 获取指定字段的唯一值列表 (配合 XML 中的 selectFieldValues)
*/
List<String> selectFieldValues(String fieldName);
List<String> selectFieldValues(@Param("fieldName") String fieldName);
/**
* 根据复杂条件查询羊只档案列表
*
* @param params 查询参数映射
* @param sheepFile 原有的查询条件(保持兼容)
* @return 羊只档案列表
* 核心修复:根据复杂条件查询羊只档案列表
* 对应 XML 中的 <select id="selectSheepFileListByCondition">
* 必须使用 @Param 注解以便 XML 能正确识别两个参数
*/
List<SheepFile> selectSheepFileListByCondition(
@Param("params") Map<String, Object> params,
@Param("sheepFile") SheepFile sheepFile
);
// 修改:使用 @SelectProvider 并指定 ResultMap
/**
* 保留原有 Provider 方法 (若项目其他地方有用到)
*/
@SelectProvider(type = SheepFileSqlProvider.class, method = "selectByCondition")
@ResultMap("SheepFileResult") // 重要:指定使用 XML 中定义的 ResultMap
@ResultMap("SheepFileResult")
List<SheepFile> selectByCondition(
@Param("sheepFile") SheepFile sheepFile,
@Param("conditions") Map<String, Object> conditions
);
// 修改:获取字段值的方法
@SelectProvider(type = SheepFileSqlProvider.class, method = "selectFieldValues")
List<String> selectFieldValuesByProvider(@Param("fieldName") String fieldName);
/**
* 查询所有公羊gender=2
*
* @return 公羊列表
*/
/**
* 查询所有公羊gender=2
* @return 公羊列表
@@ -118,4 +104,24 @@ public interface SheepFileMapper
* @return 羊只信息
*/
SheepFile selectSheepFileByManageTags(String manageTags);
}
/**
* 新增羊只档案 (对应 XML 中的 insert)
*/
public int insertSheepFile(SheepFile sheepFile);
/**
* 修改羊只档案 (对应 XML 中的 update)
*/
public int updateSheepFile(SheepFile sheepFile);
/**
* 删除羊只档案 (对应 XML 中的 delete)
*/
public int deleteSheepFileById(Long id);
/**
* 批量删除羊只档案 (对应 XML 中的 delete)
*/
public int deleteSheepFileByIds(Long[] ids);
}

View File

@@ -8,28 +8,29 @@ import java.util.Map;
/**
* 羊只档案Service接口
*
* @author wyt
* * @author wyt
* @date 2025-07-13
*/
public interface ISheepFileService
public interface ISheepFileService
{
/**
* 查询羊只档案
*
* @param id 羊只档案主键
* * @param id 羊只档案主键
* @return 羊只档案
*/
public SheepFile selectSheepFileById(Long id);
/**
* 查询羊只档案列表
*
* @param sheepFile 羊只档案
* * @param sheepFile 羊只档案
* @return 羊只档案集合
*/
public List<SheepFile> selectSheepFileList(SheepFile sheepFile);
/**
* 新增:搜索耳号接口
*/
List<String> searchEarNumbers(String query);
SheepFile selectBasSheepByManageTags(String trim);
@@ -41,27 +42,14 @@ public interface ISheepFileService
List<Map<String,Object>> countParityOfLactation();
/**
* 新增方法:获取指定字段的唯一值列表
*
* 这个方法为前端筛选功能提供数据支持
* 当用户选择某个字段进行筛选时,调用此方法获取该字段的所有可能值
*
* @param fieldName 字段名(需要是数据库表中的列名)
* @return 该字段的所有唯一值列表
* @throws IllegalArgumentException 当字段名不在白名单中时抛出异常
*
* 示例用法:
* List<String> earTags = getFieldValues("bs_manage_tags");
* // 返回结果可能是:["AF00001", "AF00002", "AF00003", ...]
* 获取指定字段的唯一值列表
*/
List<String> getFieldValues(String fieldName);
/**
* 根据复杂条件查询羊只档案列表
*
* @param params 查询参数映射
* @param sheepFile 原有的查询条件
* @return 羊只档案列表
* @param params 自定义参数Map (用于动态SQL)
* @param sheepFile 包含List筛选条件的实体对象
*/
List<SheepFile> selectSheepFileListByCondition(
Map<String, Object> params,
@@ -73,4 +61,4 @@ public interface ISheepFileService
@Transactional
int updateSheepFile(SheepFile sheepFile);
}
}

View File

@@ -11,12 +11,12 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;import java.util.Map;
import java.util.List;
import java.util.Map;
/**
* 羊只档案Service业务层处理
*
* @author wyt
* * @author wyt
* @date 2025-07-13
*/
@Service
@@ -24,11 +24,11 @@ public class SheepFileServiceImpl implements ISheepFileService {
@Autowired
private SheepFileMapper sheepFileMapper;
@Autowired
private IBreedRamFileService breedRamFileService;
/**
* 查询羊只档案
*
* @param id 羊只档案主键
* @return 羊只档案
*/
@Override
public SheepFile selectSheepFileById(Long id) {
@@ -37,21 +37,25 @@ public class SheepFileServiceImpl implements ISheepFileService {
/**
* 查询羊只档案列表
*
* @param sheepFile 羊只档案
* @return 羊只档案
*/
@Override
public List<SheepFile> selectSheepFileList(SheepFile sheepFile) {
return sheepFileMapper.selectSheepFileList(sheepFile);
}
/**
* 新增:模糊搜索耳号实现
*/
@Override
public List<String> searchEarNumbers(String query) {
return sheepFileMapper.searchEarNumbers(query);
}
@Override
public SheepFile selectBasSheepByManageTags(String tags) {
return sheepFileMapper.selectSheepByManageTags(tags);
}
@Override
public List<Map<String, Object>> countBySheepType() {
return sheepFileMapper.countBySheepType();
@@ -71,6 +75,7 @@ public class SheepFileServiceImpl implements ISheepFileService {
public List<Map<String, Object>> countParityOfLactation() {
return sheepFileMapper.countParityOfLactation();
}
@Override
public Long countInGroup() { return sheepFileMapper.countInGroup(); }
@@ -84,31 +89,42 @@ public class SheepFileServiceImpl implements ISheepFileService {
throw new IllegalArgumentException("非法的字段名: " + fieldName + ",请检查字段名是否正确");
}
// 第二步:调用新的 Provider 方法
// 注意:这里调用的是 selectFieldValuesByProvider不是 selectFieldValues
return sheepFileMapper.selectFieldValuesByProvider(fieldName);
// 调用Mapper
// 注意:这里假设 Mapper 中有 selectFieldValues 方法
// 如果你的 Mapper XML 中 id 是 selectFieldValues请确保 Mapper 接口一致
return sheepFileMapper.selectFieldValues(fieldName);
}
/**
* 核心修复:复杂条件查询
* 必须调用 Mapper 中对应的 XML 方法 (selectSheepFileListByCondition)
* 并且传递 sheepFile 对象以启用 <foreach> 列表查询
*/
@Override
public List<SheepFile> selectSheepFileListByCondition(Map<String, Object> params, SheepFile sheepFile) {
// 验证并处理参数
// 1. 验证并处理自定义参数 (驼峰转下划线、安全检查)
Map<String, Object> safeConditions = processConditions(params);
// 调用新的 Provider 方法
List<SheepFile> result = sheepFileMapper.selectByCondition(sheepFile, safeConditions);
return result;
// 2. 调用 Mapper
// 这里必须使用与 XML 中 <select id="selectSheepFileListByCondition"> 对应的方法
return sheepFileMapper.selectSheepFileListByCondition(safeConditions, sheepFile);
}
@Override
@Transactional
public int insertSheepFile(SheepFile sheepFile) {
// int rows = sheepFileMapper.insertSheepFile(sheepFile);
// if (rows > 0) { syncToBreedRamFile(sheepFile); }
// return rows;
return 0;
}
@Override
@Transactional
public int updateSheepFile(SheepFile sheepFile) {
// int rows = sheepFileMapper.updateSheepFile(sheepFile);
// if (rows > 0) { syncToBreedRamFile(sheepFile); }
// return rows;
return 0;
}
@@ -126,12 +142,13 @@ public class SheepFileServiceImpl implements ISheepFileService {
String fieldName = entry.getKey();
Object value = entry.getValue();
// 将前端字段名转换为数据库字段名
// 将前端字段名转换为数据库字段名 (例如: fatherManageTags -> father_manage_tags)
// 这对于 XML 中的 ${key} = #{value} 至关重要
String dbFieldName = convertToDbFieldName(fieldName);
// 验证字段名是否安全
if (isValidFieldName(dbFieldName)) {
// 处理值,确保不是 Character 类型
// 处理值
Object safeValue = value;
if (value != null) {
String strValue = value.toString();
@@ -140,23 +157,17 @@ public class SheepFileServiceImpl implements ISheepFileService {
if (strValue.startsWith("GT:") || strValue.startsWith("LT:") ||
strValue.startsWith("GE:") || strValue.startsWith("LE:")) {
String numPart = strValue.substring(3);
// 验证数字部分是否安全(防止 SQL 注入)
// 验证数字部分是否安全
if (isNumeric(numPart)) {
safeValue = strValue;
} else {
// 如果不是数字,忽略这个条件
System.out.println("警告:范围条件的值不是数字: " + fieldName + " = " + strValue);
continue;
}
} else {
// 其他值直接使用字符串
safeValue = strValue;
}
}
safeParams.put(dbFieldName, safeValue);
} else {
// 记录日志
System.out.println("警告:忽略非法字段名: " + fieldName + " -> " + dbFieldName);
}
}
@@ -191,61 +202,17 @@ public class SheepFileServiceImpl implements ISheepFileService {
* 扩展字段名白名单验证
*/
private boolean isValidFieldName(String fieldName) {
// 扩展允许查询的字段白名单
// 字段白名单
String[] allowedFields = {
"id",
"bs_manage_tags", // 管理耳号
"electronic_tags", // 电子耳号
"dr_ranch", // 牧场名称
"sheepfold_name", // 羊舍名称
"variety", // 品种
"family", // 家系
"name", // 羊只类型
"gender", // 性别
"birthday", // 出生日期
"day_age", // 日龄
"month_age", // 月龄
"parity", // 胎次
"birth_weight", // 出生体重
"weaning_date", // 断奶日期
"status_id", // 羊只状态
"weaning_weight", // 断奶体重
"current_weight", // 当前体重
"weaning_day_age", // 断奶日龄
"weaning_daily_gain", // 断奶日增重
"breed", // 繁殖状态
"father_manage_tags", // 父亲耳号
"mother_manage_tags", // 母亲耳号
"receptor_manage_tags", // 受体耳号
"grandfather_manage_tags", // 祖父耳号
"grandmother_manage_tags", // 祖母耳号
"maternal_grandfather_manage_tags", // 外祖父耳号
"maternal_grandmother_manage_tags", // 外祖母耳号
"mating_date", // 配种日期
"mating_type_id", // 配种类型
"preg_date", // 孕检日期
"lambing_date", // 产羔日期
"lambing_day", // 产羔时怀孕天数
"mating_day", // 配后天数
"gestation_day", // 怀孕天数
"expected_date", // 预产日期
"post_lambing_day", // 产后天数
"lactation_day", // 泌乳天数
"anestrous_day", // 空怀天数
"mating_counts", // 配种次数
"mating_total", // 累计配种次数
"miscarriage_counts", // 累计流产次数
"comment", // 备注
"controlled", // 是否性控
"body", // 体况评分
"breast", // 乳房评分
"source", // 入群来源
"source_date", // 入群日期
"source_ranch", // 来源牧场
"update_by", // 修改人
"update_time", // 修改日期
"create_by", // 创建人
"create_time" // 创建日期
"id", "bs_manage_tags", "electronic_tags", "dr_ranch", "sheepfold_name", "variety", "family",
"name", "gender", "birthday", "day_age", "month_age", "parity", "birth_weight", "weaning_date",
"status_id", "weaning_weight", "current_weight", "weaning_day_age", "weaning_daily_gain", "breed",
"father_manage_tags", "mother_manage_tags", "receptor_manage_tags", "grandfather_manage_tags",
"grandmother_manage_tags", "maternal_grandfather_manage_tags", "maternal_grandmother_manage_tags",
"mating_date", "mating_type_id", "preg_date", "lambing_date", "lambing_day", "mating_day",
"gestation_day", "expected_date", "post_lambing_day", "lactation_day", "anestrous_day",
"mating_counts", "mating_total", "miscarriage_counts", "comment", "controlled", "body", "breast",
"source", "source_date", "source_ranch", "update_by", "update_time", "create_by", "create_time"
};
for (String allowedField : allowedFields) {
@@ -257,45 +224,32 @@ public class SheepFileServiceImpl implements ISheepFileService {
return false;
}
@Autowired
private IBreedRamFileService breedRamFileService; // 注入种公羊服务
/**
* 新增羊只档案
*/
/**
* 同步公羊数据到种公羊档案表
*/
private void syncToBreedRamFile(SheepFile sheepFile) {
try {
// 检查是否已存在
BreedRamFile existingRam = breedRamFileService.selectBreedRamFileByOrdinaryEarNumber(
sheepFile.getBsManageTags()
);
if (existingRam != null) {
// 已存在,更新
BreedRamFile updateRam = convertToBreedRamFile(sheepFile);
updateRam.setId(existingRam.getId());
breedRamFileService.updateBreedRamFile(updateRam);
} else {
// 不存在,新增
BreedRamFile newRam = convertToBreedRamFile(sheepFile);
breedRamFileService.insertBreedRamFile(newRam);
}
} catch (Exception e) {
// 记录日志,但不影响主流
e.printStackTrace();
}
}
/**
* 将SheepFile转换为BreedRamFile
*/
private BreedRamFile convertToBreedRamFile(SheepFile sheepFile) {
BreedRamFile breedRamFile = new BreedRamFile();
// 基本信息
breedRamFile.setOrdinaryEarNumber(sheepFile.getBsManageTags());
breedRamFile.setRanchId(sheepFile.getRanchId());
breedRamFile.setRanchName(sheepFile.getDrRanch());
@@ -307,15 +261,13 @@ public class SheepFileServiceImpl implements ISheepFileService {
breedRamFile.setSheepCategory(sheepFile.getName());
breedRamFile.setBirthday(sheepFile.getBirthday());
// 体重相关
breedRamFile.setBirthWeight(BigDecimal.valueOf(sheepFile.getBirthWeight()));
if (sheepFile.getBirthWeight() != null) breedRamFile.setBirthWeight(BigDecimal.valueOf(sheepFile.getBirthWeight()));
breedRamFile.setWeaningDate(sheepFile.getWeaningDate());
breedRamFile.setWeaningDayAge(sheepFile.getWeaningDayAge());
breedRamFile.setWeaningWeight(BigDecimal.valueOf(sheepFile.getWeaningWeight()));
breedRamFile.setWeaningDailyGain(BigDecimal.valueOf(sheepFile.getWeaningDailyGain()));
breedRamFile.setCurrentWeight(BigDecimal.valueOf(sheepFile.getCurrentWeight()));
if (sheepFile.getWeaningWeight() != null) breedRamFile.setWeaningWeight(BigDecimal.valueOf(sheepFile.getWeaningWeight()));
if (sheepFile.getWeaningDailyGain() != null) breedRamFile.setWeaningDailyGain(BigDecimal.valueOf(sheepFile.getWeaningDailyGain()));
if (sheepFile.getCurrentWeight() != null) breedRamFile.setCurrentWeight(BigDecimal.valueOf(sheepFile.getCurrentWeight()));
// 家系信息
breedRamFile.setFatherNumber(sheepFile.getFatherManageTags());
breedRamFile.setMotherNumber(sheepFile.getMotherManageTags());
breedRamFile.setGrandfatherNumber(sheepFile.getGrandfatherManageTags());
@@ -323,7 +275,6 @@ public class SheepFileServiceImpl implements ISheepFileService {
breedRamFile.setMaternalGrandfatherNumber(sheepFile.getMaternalGrandfatherManageTags());
breedRamFile.setMaternalGrandmotherNumber(sheepFile.getMaternalGrandmotherManageTags());
// 审计信息
breedRamFile.setCreateBy(sheepFile.getCreateBy());
breedRamFile.setCreateTime(sheepFile.getCreateTime());
breedRamFile.setUpdateBy(sheepFile.getUpdateBy());
@@ -332,5 +283,4 @@ public class SheepFileServiceImpl implements ISheepFileService {
return breedRamFile;
}
}
}

View File

@@ -1,9 +1,9 @@
<?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.base.mapper.SheepFileMapper">
<resultMap type="SheepFile" id="SheepFileResult">
<result property="id" column="id" />
<result property="bsManageTags" column="bs_manage_tags" />
@@ -79,7 +79,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectSheepFileList" parameterType="SheepFile" resultMap="SheepFileResult">
<include refid="selectSheepFileVo"/>
<where>
<where>
AND (is_delete = 0 OR is_delete IS NULL)
<if test="id != null "> and id = #{id}</if>
<if test="bsManageTags != null and bsManageTags != ''"> and bs_manage_tags = #{bsManageTags}</if>
<if test="drRanch != null and drRanch != ''"> and dr_ranch = #{drRanch}</if>
@@ -90,91 +91,111 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="statusId != null "> and status_id = #{statusId}</if>
<if test="breed != null and breed != ''"> and breed = #{breed}</if>
</where>
ORDER BY id ASC <!-- 修改为升序 -->
ORDER BY id ASC
</select>
<select id="searchEarNumbers" resultType="String">
SELECT DISTINCT bs_manage_tags
FROM sheep_file
WHERE (is_delete = 0 OR is_delete IS NULL)
<if test="query != null and query != ''">
AND bs_manage_tags LIKE CONCAT('%', #{query}, '%')
</if>
ORDER BY bs_manage_tags ASC
LIMIT 20
</select>
<select id="selectSheepFileById" parameterType="Long" resultMap="SheepFileResult">
<include refid="selectSheepFileVo"/>
where id = #{id}
</select>
<select id="selectSheepByManageTags" parameterType="String" resultMap="SheepFileResult">
<include refid="selectSheepFileVo"/>
where bs_manage_tags = #{tags}
</select>
<!-- 在群羊只总数 -->
<select id="countInGroup" resultType="java.lang.Long">
SELECT COUNT(*) FROM sheep_file WHERE status_id = 1
SELECT COUNT(*) FROM sheep_file WHERE status_id = 1 AND (is_delete = 0 OR is_delete IS NULL)
</select>
<!-- 羊只类别分布 -->
<select id="countBySheepType" resultType="java.util.Map">
SELECT name AS name, COUNT(*) AS value
FROM sheep_file
WHERE status_id = 1
WHERE status_id = 1 AND (is_delete = 0 OR is_delete IS NULL)
GROUP BY name
</select>
<!-- 繁育状态分布 -->
<select id="countByBreedStatus" resultType="java.util.Map">
SELECT breed AS name, COUNT(*) AS value
FROM sheep_file
WHERE status_id = 1
WHERE status_id = 1 AND (is_delete = 0 OR is_delete IS NULL)
GROUP BY breed
</select>
<!-- 品种分布 -->
<select id="countByVariety" resultType="java.util.Map">
SELECT variety AS name, COUNT(*) AS value
FROM sheep_file
WHERE status_id = 1
WHERE status_id = 1 AND (is_delete = 0 OR is_delete IS NULL)
GROUP BY variety
</select>
<!-- 泌乳羊胎次分布 -->
<select id="countParityOfLactation" resultType="java.util.Map">
SELECT parity AS name, COUNT(*) AS value
FROM sheep_file
WHERE status_id = 1 AND name = '泌乳羊'
WHERE status_id = 1 AND name = '泌乳羊' AND (is_delete = 0 OR is_delete IS NULL)
GROUP BY parity
ORDER BY parity
</select>
<!--
获取字段唯一值的SQL映射
说明:这个查询使用 ${fieldName} 直接拼接字段名因为MyBatis的#{}不支持列名作为参数
安全性通过Service层的白名单验证来确保fieldName的安全性
-->
<select id="selectFieldValues" parameterType="String" resultType="String">
SELECT
DISTINCT ${fieldName} as field_value
FROM
sheep_file
WHERE
<!-- 过滤空值和NULL值确保返回的数据质量 -->
${fieldName} IS NOT NULL
AND ${fieldName} != ''
AND ${fieldName} != 'null'
ORDER BY
<!-- 按字母顺序排序,方便前端显示 -->
${fieldName} ASC
SELECT DISTINCT ${fieldName} as field_value
FROM sheep_file
WHERE ${fieldName} IS NOT NULL AND ${fieldName} != '' AND ${fieldName} != 'null'
ORDER BY ${fieldName} ASC
</select>
<select id="selectSheepFileListByCondition" parameterType="map" resultMap="SheepFileResult">
<select id="selectSheepFileListByCondition" resultMap="SheepFileResult">
<include refid="selectSheepFileVo"/>
FROM sheep_file
<where>
<!-- 逻辑删除过滤 -->
AND is_delete = 0
AND (is_delete = 0 OR is_delete IS NULL)
<!-- 原有的 SheepFile 条件(保持兼容性) -->
<if test="sheepFile != null">
<if test="sheepFile.bsManageTags != null and sheepFile.bsManageTags != ''">
<if test="sheepFile.allEarNumbers != null and sheepFile.allEarNumbers.size() > 0">
AND bs_manage_tags IN
<foreach collection="sheepFile.allEarNumbers" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="sheepFile.allEleEarNumbers != null and sheepFile.allEleEarNumbers.size() > 0">
AND electronic_tags IN
<foreach collection="sheepFile.allEleEarNumbers" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="sheepFile.allGenders != null and sheepFile.allGenders.size() > 0">
AND gender IN
<foreach collection="sheepFile.allGenders" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="sheepFile.allBreedingStatus != null and sheepFile.allBreedingStatus.size() > 0">
AND breed IN
<foreach collection="sheepFile.allBreedingStatus" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="sheepFile.allSheepTypes != null and sheepFile.allSheepTypes.size() > 0">
AND name IN
<foreach collection="sheepFile.allSheepTypes" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="sheepFile.bsManageTags != null and sheepFile.bsManageTags != '' and (sheepFile.allEarNumbers == null or sheepFile.allEarNumbers.size() == 0)">
AND bs_manage_tags LIKE CONCAT('%', #{sheepFile.bsManageTags}, '%')
</if>
<if test="sheepFile.electronicTags != null and sheepFile.electronicTags != ''">
<if test="sheepFile.electronicTags != null and sheepFile.electronicTags != '' and (sheepFile.allEleEarNumbers == null or sheepFile.allEleEarNumbers.size() == 0)">
AND electronic_tags LIKE CONCAT('%', #{sheepFile.electronicTags}, '%')
</if>
<if test="sheepFile.drRanch != null and sheepFile.drRanch != ''">
@@ -183,23 +204,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sheepFile.variety != null and sheepFile.variety != ''">
AND variety LIKE CONCAT('%', #{sheepFile.variety}, '%')
</if>
<if test="sheepFile.name != null and sheepFile.name != ''">
<if test="sheepFile.name != null and sheepFile.name != '' and (sheepFile.allSheepTypes == null or sheepFile.allSheepTypes.size() == 0)">
AND name LIKE CONCAT('%', #{sheepFile.name}, '%')
</if>
<if test="sheepFile.gender != null">
<if test="sheepFile.gender != null and (sheepFile.allGenders == null or sheepFile.allGenders.size() == 0)">
AND gender = #{sheepFile.gender}
</if>
<if test="sheepFile.statusId != null">
AND status_id = #{sheepFile.statusId}
</if>
<if test="sheepFile.breed != null and sheepFile.breed != ''">
<if test="sheepFile.breed != null and sheepFile.breed != '' and (sheepFile.allBreedingStatus == null or sheepFile.allBreedingStatus.size() == 0)">
AND breed LIKE CONCAT('%', #{sheepFile.breed}, '%')
</if>
</if>
<!-- 动态条件处理 - 使用多个if标签代替复杂的choose -->
<if test="params != null and !params.isEmpty()">
<!-- 空值条件 -->
<foreach collection="params.entrySet()" item="value" index="key">
<if test="value != null and value.toString() == 'IS_NULL'">
AND ${key} IS NULL
@@ -207,12 +226,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="value != null and value.toString() == 'NOT_NULL'">
AND ${key} IS NOT NULL
</if>
</foreach>
<!-- 范围条件 -->
<foreach collection="params.entrySet()" item="value" index="key">
<!-- 显式将 value 转换为字符串 -->
<if test="value != null and value.toString() != null">
<if test="value != null and value.toString() != null and (value.toString().startsWith('GT:') or value.toString().startsWith('LT:') or value.toString().startsWith('GE:') or value.toString().startsWith('LE:'))">
<choose>
<when test="value.toString().startsWith('GT:')">
AND ${key} &gt; #{value.toString().substring(3)}
@@ -228,21 +243,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</when>
</choose>
</if>
</foreach>
<!-- 列表条件 -->
<foreach collection="params.entrySet()" item="value" index="key">
<if test="value != null and value.toString() != null and value.toString().contains(',')">
<if test="value != null and value.toString() != null and value.toString().contains(',') and !value.toString().startsWith('GT:')">
AND ${key} IN
<foreach collection="value.toString().split(',')" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</foreach>
<!-- 模糊查询条件(针对文本字段) -->
<foreach collection="params.entrySet()" item="value" index="key">
<if test="value != null and value.toString() != null">
<if test="value != null and value.toString() != 'IS_NULL' and value.toString() != 'NOT_NULL' and !value.toString().contains(',') and !value.toString().startsWith('GT:') and !value.toString().startsWith('LT:') and !value.toString().startsWith('GE:') and !value.toString().startsWith('LE:')">
<choose>
<when test="key == 'bs_manage_tags' or key == 'electronic_tags' or
key == 'dr_ranch' or key == 'sheepfold_name' or
@@ -253,7 +262,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND ${key} LIKE CONCAT('%', #{value}, '%')
</when>
<otherwise>
<!-- 普通等于条件 -->
AND ${key} = #{value}
</otherwise>
</choose>
@@ -264,23 +272,234 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY id ASC
</select>
<!-- &lt;!&ndash; 查询所有公羊gender=2 &ndash;&gt;-->
<!-- <select id="selectRamList" resultMap="SheepFileResult">-->
<!-- <include refid="selectSheepFileVo"/>-->
<!-- where gender = 2 and (is_delete = 0 or is_delete is null)-->
<!-- order by create_time desc-->
<!-- </select>-->
<!-- 查询所有公羊 -->
<select id="selectRamList" resultMap="SheepFileResult">
SELECT * FROM sheep_file
WHERE gender = 2 AND is_delete = 0
</select>
<!-- 根据管理耳号查询 -->
<select id="selectSheepFileByManageTags" resultMap="SheepFileResult">
SELECT * FROM sheep_file
WHERE bs_manage_tags = #{manageTags} AND is_delete = 0
LIMIT 1
</select>
<insert id="insertSheepFile" parameterType="SheepFile" useGeneratedKeys="true" keyProperty="id">
insert into sheep_file
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="bsManageTags != null">bs_manage_tags,</if>
<if test="ranchId != null">ranch_id,</if>
<if test="drRanch != null">dr_ranch,</if>
<if test="sheepfoldId != null">sheepfold_id,</if>
<if test="sheepfoldName != null">sheepfold_name,</if>
<if test="electronicTags != null">electronic_tags,</if>
<if test="varietyId != null">variety_id,</if>
<if test="variety != null">variety,</if>
<if test="family != null">family,</if>
<if test="name != null">name,</if>
<if test="gender != null">gender,</if>
<if test="birthday != null">birthday,</if>
<if test="dayAge != null">day_age,</if>
<if test="monthAge != null">month_age,</if>
<if test="parity != null">parity,</if>
<if test="birthWeight != null">birth_weight,</if>
<if test="weaningDate != null">weaning_date,</if>
<if test="statusId != null">status_id,</if>
<if test="weaningWeight != null">weaning_weight,</if>
<if test="currentWeight != null">current_weight,</if>
<if test="weaningDayAge != null">weaning_day_age,</if>
<if test="weaningDailyGain != null">weaning_daily_gain,</if>
<if test="breedStatusId != null">breed_status_id,</if>
<if test="breed != null">breed,</if>
<if test="bsFatherId != null">bs_father_id,</if>
<if test="fatherManageTags != null">father_manage_tags,</if>
<if test="bsMotherId != null">bs_mother_id,</if>
<if test="motherManageTags != null">mother_manage_tags,</if>
<if test="receptorId != null">receptor_id,</if>
<if test="receptorManageTags != null">receptor_manage_tags,</if>
<if test="fatherFatherId != null">father_father_id,</if>
<if test="grandfatherManageTags != null">grandfather_manage_tags,</if>
<if test="fatherMotherId != null">father_mother_id,</if>
<if test="grandmotherManageTags != null">grandmother_manage_tags,</if>
<if test="fatherId != null">father_id,</if>
<if test="maternalGrandfatherManageTags != null">maternal_grandfather_manage_tags,</if>
<if test="motherId != null">mother_id,</if>
<if test="maternalGrandmotherManageTags != null">maternal_grandmother_manage_tags,</if>
<if test="matingDate != null">mating_date,</if>
<if test="matingTypeId != null">mating_type_id,</if>
<if test="pregDate != null">preg_date,</if>
<if test="lambingDate != null">lambing_date,</if>
<if test="lambingDay != null">lambing_day,</if>
<if test="matingDay != null">mating_day,</if>
<if test="gestationDay != null">gestation_day,</if>
<if test="expectedDate != null">expected_date,</if>
<if test="postLambingDay != null">post_lambing_day,</if>
<if test="lactationDay != null">lactation_day,</if>
<if test="anestrousDay != null">anestrous_day,</if>
<if test="matingCounts != null">mating_counts,</if>
<if test="matingTotal != null">mating_total,</if>
<if test="miscarriageCounts != null">miscarriage_counts,</if>
<if test="comment != null">comment,</if>
<if test="controlled != null">controlled,</if>
<if test="body != null">body,</if>
<if test="breast != null">breast,</if>
<if test="source != null">source,</if>
<if test="sourceDate != null">source_date,</if>
<if test="sourceRanchId != null">source_ranch_id,</if>
<if test="sourceRanch != null">source_ranch,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="isDelete != null">is_delete,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="bsManageTags != null">#{bsManageTags},</if>
<if test="ranchId != null">#{ranchId},</if>
<if test="drRanch != null">#{drRanch},</if>
<if test="sheepfoldId != null">#{sheepfoldId},</if>
<if test="sheepfoldName != null">#{sheepfoldName},</if>
<if test="electronicTags != null">#{electronicTags},</if>
<if test="varietyId != null">#{varietyId},</if>
<if test="variety != null">#{variety},</if>
<if test="family != null">#{family},</if>
<if test="name != null">#{name},</if>
<if test="gender != null">#{gender},</if>
<if test="birthday != null">#{birthday},</if>
<if test="dayAge != null">#{dayAge},</if>
<if test="monthAge != null">#{monthAge},</if>
<if test="parity != null">#{parity},</if>
<if test="birthWeight != null">#{birthWeight},</if>
<if test="weaningDate != null">#{weaningDate},</if>
<if test="statusId != null">#{statusId},</if>
<if test="weaningWeight != null">#{weaningWeight},</if>
<if test="currentWeight != null">#{currentWeight},</if>
<if test="weaningDayAge != null">#{weaningDayAge},</if>
<if test="weaningDailyGain != null">#{weaningDailyGain},</if>
<if test="breedStatusId != null">#{breedStatusId},</if>
<if test="breed != null">#{breed},</if>
<if test="bsFatherId != null">#{bsFatherId},</if>
<if test="fatherManageTags != null">#{fatherManageTags},</if>
<if test="bsMotherId != null">#{bsMotherId},</if>
<if test="motherManageTags != null">#{motherManageTags},</if>
<if test="receptorId != null">#{receptorId},</if>
<if test="receptorManageTags != null">#{receptorManageTags},</if>
<if test="fatherFatherId != null">#{fatherFatherId},</if>
<if test="grandfatherManageTags != null">#{grandfatherManageTags},</if>
<if test="fatherMotherId != null">#{fatherMotherId},</if>
<if test="grandmotherManageTags != null">#{grandmotherManageTags},</if>
<if test="fatherId != null">#{fatherId},</if>
<if test="maternalGrandfatherManageTags != null">#{maternalGrandfatherManageTags},</if>
<if test="motherId != null">#{motherId},</if>
<if test="maternalGrandmotherManageTags != null">#{maternalGrandmotherManageTags},</if>
<if test="matingDate != null">#{matingDate},</if>
<if test="matingTypeId != null">#{matingTypeId},</if>
<if test="pregDate != null">#{pregDate},</if>
<if test="lambingDate != null">#{lambingDate},</if>
<if test="lambingDay != null">#{lambingDay},</if>
<if test="matingDay != null">#{matingDay},</if>
<if test="gestationDay != null">#{gestationDay},</if>
<if test="expectedDate != null">#{expectedDate},</if>
<if test="postLambingDay != null">#{postLambingDay},</if>
<if test="lactationDay != null">#{lactationDay},</if>
<if test="anestrousDay != null">#{anestrousDay},</if>
<if test="matingCounts != null">#{matingCounts},</if>
<if test="matingTotal != null">#{matingTotal},</if>
<if test="miscarriageCounts != null">#{miscarriageCounts},</if>
<if test="comment != null">#{comment},</if>
<if test="controlled != null">#{controlled},</if>
<if test="body != null">#{body},</if>
<if test="breast != null">#{breast},</if>
<if test="source != null">#{source},</if>
<if test="sourceDate != null">#{sourceDate},</if>
<if test="sourceRanchId != null">#{sourceRanchId},</if>
<if test="sourceRanch != null">#{sourceRanch},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="isDelete != null">#{isDelete},</if>
</trim>
</insert>
<update id="updateSheepFile" parameterType="SheepFile">
update sheep_file
<trim prefix="SET" suffixOverrides=",">
<if test="bsManageTags != null">bs_manage_tags = #{bsManageTags},</if>
<if test="ranchId != null">ranch_id = #{ranchId},</if>
<if test="drRanch != null">dr_ranch = #{drRanch},</if>
<if test="sheepfoldId != null">sheepfold_id = #{sheepfoldId},</if>
<if test="sheepfoldName != null">sheepfold_name = #{sheepfoldName},</if>
<if test="electronicTags != null">electronic_tags = #{electronicTags},</if>
<if test="varietyId != null">variety_id = #{varietyId},</if>
<if test="variety != null">variety = #{variety},</if>
<if test="family != null">family = #{family},</if>
<if test="name != null">name = #{name},</if>
<if test="gender != null">gender = #{gender},</if>
<if test="birthday != null">birthday = #{birthday},</if>
<if test="dayAge != null">day_age = #{dayAge},</if>
<if test="monthAge != null">month_age = #{monthAge},</if>
<if test="parity != null">parity = #{parity},</if>
<if test="birthWeight != null">birth_weight = #{birthWeight},</if>
<if test="weaningDate != null">weaning_date = #{weaningDate},</if>
<if test="statusId != null">status_id = #{statusId},</if>
<if test="weaningWeight != null">weaning_weight = #{weaningWeight},</if>
<if test="currentWeight != null">current_weight = #{currentWeight},</if>
<if test="weaningDayAge != null">weaning_day_age = #{weaningDayAge},</if>
<if test="weaningDailyGain != null">weaning_daily_gain = #{weaningDailyGain},</if>
<if test="breedStatusId != null">breed_status_id = #{breedStatusId},</if>
<if test="breed != null">breed = #{breed},</if>
<if test="bsFatherId != null">bs_father_id = #{bsFatherId},</if>
<if test="fatherManageTags != null">father_manage_tags = #{fatherManageTags},</if>
<if test="bsMotherId != null">bs_mother_id = #{bsMotherId},</if>
<if test="motherManageTags != null">mother_manage_tags = #{motherManageTags},</if>
<if test="receptorId != null">receptor_id = #{receptorId},</if>
<if test="receptorManageTags != null">receptor_manage_tags = #{receptorManageTags},</if>
<if test="fatherFatherId != null">father_father_id = #{fatherFatherId},</if>
<if test="grandfatherManageTags != null">grandfather_manage_tags = #{grandfatherManageTags},</if>
<if test="fatherMotherId != null">father_mother_id = #{fatherMotherId},</if>
<if test="grandmotherManageTags != null">grandmother_manage_tags = #{grandmotherManageTags},</if>
<if test="fatherId != null">father_id = #{fatherId},</if>
<if test="maternalGrandfatherManageTags != null">maternal_grandfather_manage_tags = #{maternalGrandfatherManageTags},</if>
<if test="motherId != null">mother_id = #{motherId},</if>
<if test="maternalGrandmotherManageTags != null">maternal_grandmother_manage_tags = #{maternalGrandmotherManageTags},</if>
<if test="matingDate != null">mating_date = #{matingDate},</if>
<if test="matingTypeId != null">mating_type_id = #{matingTypeId},</if>
<if test="pregDate != null">preg_date = #{pregDate},</if>
<if test="lambingDate != null">lambing_date = #{lambingDate},</if>
<if test="lambingDay != null">lambing_day = #{lambingDay},</if>
<if test="matingDay != null">mating_day = #{matingDay},</if>
<if test="gestationDay != null">gestation_day = #{gestationDay},</if>
<if test="expectedDate != null">expected_date = #{expectedDate},</if>
<if test="postLambingDay != null">post_lambing_day = #{postLambingDay},</if>
<if test="lactationDay != null">lactation_day = #{lactationDay},</if>
<if test="anestrousDay != null">anestrous_day = #{anestrousDay},</if>
<if test="matingCounts != null">mating_counts = #{matingCounts},</if>
<if test="matingTotal != null">mating_total = #{matingTotal},</if>
<if test="miscarriageCounts != null">miscarriage_counts = #{miscarriageCounts},</if>
<if test="comment != null">comment = #{comment},</if>
<if test="controlled != null">controlled = #{controlled},</if>
<if test="body != null">body = #{body},</if>
<if test="breast != null">breast = #{breast},</if>
<if test="source != null">source = #{source},</if>
<if test="sourceDate != null">source_date = #{sourceDate},</if>
<if test="sourceRanchId != null">source_ranch_id = #{sourceRanchId},</if>
<if test="sourceRanch != null">source_ranch = #{sourceRanch},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="isDelete != null">is_delete = #{isDelete},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteSheepFileById" parameterType="Long">
update sheep_file set is_delete = 1 where id = #{id}
</delete>
<delete id="deleteSheepFileByIds" parameterType="String">
update sheep_file set is_delete = 1 where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>