绝大部分页面修改完成
This commit is contained in:
parent
d9d489c1a0
commit
24108fd0e6
@ -1,6 +1,8 @@
|
|||||||
package com.zhyc.module.produce.breed.controller;
|
package com.zhyc.module.produce.breed.controller;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -78,16 +80,35 @@ public class RawSpermRecordController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody RawSpermRecord rawSpermRecord)
|
public AjaxResult add(@RequestBody RawSpermRecord rawSpermRecord)
|
||||||
{
|
{
|
||||||
// 如果传入的是耳号,需要先根据耳号查询羊只ID
|
try {
|
||||||
if (StringUtils.isNotEmpty(rawSpermRecord.getManageTags()) && rawSpermRecord.getSheepId() == null) {
|
// 验证必填字段
|
||||||
Long sheepId = rawSpermRecordService.getSheepIdByManageTags(rawSpermRecord.getManageTags());
|
if (StringUtils.isEmpty(rawSpermRecord.getManageTags())) {
|
||||||
if (sheepId == null) {
|
return error("耳号不能为空");
|
||||||
return error("未找到对应耳号的羊只信息");
|
}
|
||||||
|
if (rawSpermRecord.getPickDate() == null) {
|
||||||
|
return error("采精日期不能为空");
|
||||||
|
}
|
||||||
|
if (rawSpermRecord.getAmount() == null) {
|
||||||
|
return error("采精量不能为空");
|
||||||
}
|
}
|
||||||
rawSpermRecord.setSheepId(sheepId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return toAjax(rawSpermRecordService.insertRawSpermRecord(rawSpermRecord));
|
// 验证耳号对应的羊只是否为公羊
|
||||||
|
Map<String, Object> sheepInfo = rawSpermRecordService.getSheepInfoByManageTags(rawSpermRecord.getManageTags());
|
||||||
|
if (sheepInfo == null) {
|
||||||
|
return error("未找到耳号为[" + rawSpermRecord.getManageTags() + "]的羊只信息,请检查耳号是否正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 安全的类型转换
|
||||||
|
Integer gender = convertToInteger(sheepInfo.get("gender"));
|
||||||
|
if (gender == null || gender != 2) {
|
||||||
|
return error("采精记录只能针对公羊,耳号[" + rawSpermRecord.getManageTags() + "]对应的羊只不是公羊");
|
||||||
|
}
|
||||||
|
|
||||||
|
return toAjax(rawSpermRecordService.insertRawSpermRecord(rawSpermRecord));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("新增采精记录失败", e);
|
||||||
|
return error("新增失败:" + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,16 +119,26 @@ public class RawSpermRecordController extends BaseController
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody RawSpermRecord rawSpermRecord)
|
public AjaxResult edit(@RequestBody RawSpermRecord rawSpermRecord)
|
||||||
{
|
{
|
||||||
// 如果传入的是耳号,需要先根据耳号查询羊只ID
|
try {
|
||||||
if (StringUtils.isNotEmpty(rawSpermRecord.getManageTags()) && rawSpermRecord.getSheepId() == null) {
|
// 如果修改了耳号,需要重新验证
|
||||||
Long sheepId = rawSpermRecordService.getSheepIdByManageTags(rawSpermRecord.getManageTags());
|
if (StringUtils.isNotEmpty(rawSpermRecord.getManageTags())) {
|
||||||
if (sheepId == null) {
|
Map<String, Object> sheepInfo = rawSpermRecordService.getSheepInfoByManageTags(rawSpermRecord.getManageTags());
|
||||||
return error("未找到对应耳号的羊只信息");
|
if (sheepInfo == null) {
|
||||||
}
|
return error("未找到耳号为[" + rawSpermRecord.getManageTags() + "]的羊只信息,请检查耳号是否正确");
|
||||||
rawSpermRecord.setSheepId(sheepId);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return toAjax(rawSpermRecordService.updateRawSpermRecord(rawSpermRecord));
|
// 安全的类型转换
|
||||||
|
Integer gender = convertToInteger(sheepInfo.get("gender"));
|
||||||
|
if (gender == null || gender != 2) {
|
||||||
|
return error("采精记录只能针对公羊,耳号[" + rawSpermRecord.getManageTags() + "]对应的羊只不是公羊");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toAjax(rawSpermRecordService.updateRawSpermRecord(rawSpermRecord));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("修改采精记录失败", e);
|
||||||
|
return error("修改失败:" + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,16 +153,105 @@ public class RawSpermRecordController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据耳号查询羊只信息
|
* 根据耳号查询羊只信息(带性别验证)
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getSheepByManageTags/{manageTags}")
|
@GetMapping("/getSheepByManageTags/{manageTags}")
|
||||||
public AjaxResult getSheepByManageTags(@PathVariable("manageTags") String manageTags)
|
public AjaxResult getSheepByManageTags(@PathVariable("manageTags") String manageTags)
|
||||||
{
|
{
|
||||||
Long sheepId = rawSpermRecordService.getSheepIdByManageTags(manageTags);
|
try {
|
||||||
if (sheepId != null) {
|
Map<String, Object> sheepInfo = rawSpermRecordService.getSheepInfoByManageTags(manageTags);
|
||||||
return success(sheepId);
|
if (sheepInfo != null) {
|
||||||
|
// 安全的类型转换
|
||||||
|
Integer gender = convertToInteger(sheepInfo.get("gender"));
|
||||||
|
// 验证是否为公羊
|
||||||
|
if (gender == null || gender != 2) {
|
||||||
|
return error("该耳号[" + manageTags + "]对应的羊只不是公羊,无法进行采精记录");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造包含消息和数据的返回结果
|
||||||
|
Map<String, Object> resultData = new HashMap<>();
|
||||||
|
resultData.put("sheepInfo", sheepInfo);
|
||||||
|
resultData.put("message", "验证通过,该羊只为公羊");
|
||||||
|
return success(resultData);
|
||||||
|
} else {
|
||||||
|
return error("未找到耳号为[" + manageTags + "]的羊只信息");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("查询羊只信息失败", e);
|
||||||
|
return error("查询失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证羊只是否为公羊
|
||||||
|
*/
|
||||||
|
@GetMapping("/validateRam/{manageTags}")
|
||||||
|
public AjaxResult validateRam(@PathVariable("manageTags") String manageTags)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
boolean isRam = rawSpermRecordService.validateRamGender(manageTags);
|
||||||
|
if (isRam) {
|
||||||
|
return success("该羊只为公羊,可以进行采精记录");
|
||||||
|
} else {
|
||||||
|
return error("该羊只不是公羊,无法进行采精记录");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("验证羊只性别失败", e);
|
||||||
|
return error("验证失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据耳号查询羊只ID(兼容原有接口)
|
||||||
|
*/
|
||||||
|
@GetMapping("/getSheepIdByManageTags/{manageTags}")
|
||||||
|
public AjaxResult getSheepIdByManageTags(@PathVariable("manageTags") String manageTags)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Long sheepId = rawSpermRecordService.getSheepIdByManageTags(manageTags);
|
||||||
|
if (sheepId != null) {
|
||||||
|
return success(sheepId);
|
||||||
|
} else {
|
||||||
|
return error("未找到对应耳号的羊只信息");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("查询羊只ID失败", e);
|
||||||
|
return error("查询失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全的类型转换:将Object转换为Integer
|
||||||
|
*
|
||||||
|
* @param obj 要转换的对象
|
||||||
|
* @return Integer值,如果转换失败返回null
|
||||||
|
*/
|
||||||
|
private Integer convertToInteger(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj instanceof Integer) {
|
||||||
|
return (Integer) obj;
|
||||||
|
} else if (obj instanceof Long) {
|
||||||
|
Long longValue = (Long) obj;
|
||||||
|
// 检查Long值是否在Integer范围内
|
||||||
|
if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) {
|
||||||
|
return longValue.intValue();
|
||||||
|
} else {
|
||||||
|
logger.warn("数值超出Integer范围:" + longValue);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else if (obj instanceof String) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt((String) obj);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
logger.warn("无法将字符串转换为Integer:" + obj);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return error("未找到对应耳号的羊只信息");
|
logger.warn("无法将 " + obj.getClass().getSimpleName() + " 类型转换为Integer");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.zhyc.module.produce.breed.controller;
|
package com.zhyc.module.produce.breed.controller;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
|||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.zhyc.common.annotation.Log;
|
import com.zhyc.common.annotation.Log;
|
||||||
import com.zhyc.common.core.controller.BaseController;
|
import com.zhyc.common.core.controller.BaseController;
|
||||||
@ -18,6 +20,8 @@ import com.zhyc.common.core.domain.AjaxResult;
|
|||||||
import com.zhyc.common.enums.BusinessType;
|
import com.zhyc.common.enums.BusinessType;
|
||||||
import com.zhyc.module.produce.breed.domain.ScDryMilk;
|
import com.zhyc.module.produce.breed.domain.ScDryMilk;
|
||||||
import com.zhyc.module.produce.breed.service.IScDryMilkService;
|
import com.zhyc.module.produce.breed.service.IScDryMilkService;
|
||||||
|
import com.zhyc.module.base.domain.DaSheepfold;
|
||||||
|
import com.zhyc.module.base.service.IDaSheepfoldService;
|
||||||
import com.zhyc.common.utils.poi.ExcelUtil;
|
import com.zhyc.common.utils.poi.ExcelUtil;
|
||||||
import com.zhyc.common.core.page.TableDataInfo;
|
import com.zhyc.common.core.page.TableDataInfo;
|
||||||
|
|
||||||
@ -34,6 +38,9 @@ public class ScDryMilkController extends BaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IScDryMilkService scDryMilkService;
|
private IScDryMilkService scDryMilkService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IDaSheepfoldService daSheepfoldService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询干奶记录列表
|
* 查询干奶记录列表
|
||||||
*/
|
*/
|
||||||
@ -41,9 +48,23 @@ public class ScDryMilkController extends BaseController
|
|||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(ScDryMilk scDryMilk)
|
public TableDataInfo list(ScDryMilk scDryMilk)
|
||||||
{
|
{
|
||||||
startPage();
|
try {
|
||||||
List<ScDryMilk> list = scDryMilkService.selectScDryMilkList(scDryMilk);
|
// 添加调试日志
|
||||||
return getDataTable(list);
|
if (scDryMilk.getManageTags() != null && !scDryMilk.getManageTags().trim().isEmpty()) {
|
||||||
|
logger.info("搜索耳号参数: [{}]", scDryMilk.getManageTags());
|
||||||
|
scDryMilk.setManageTags(scDryMilk.getManageTags().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
startPage();
|
||||||
|
List<ScDryMilk> list = scDryMilkService.selectScDryMilkList(scDryMilk);
|
||||||
|
|
||||||
|
logger.info("查询到干奶记录数量: {}", list.size());
|
||||||
|
|
||||||
|
return getDataTable(list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("查询干奶记录列表失败", e);
|
||||||
|
return getDataTable(new java.util.ArrayList<>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,9 +75,17 @@ public class ScDryMilkController extends BaseController
|
|||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(HttpServletResponse response, ScDryMilk scDryMilk)
|
public void export(HttpServletResponse response, ScDryMilk scDryMilk)
|
||||||
{
|
{
|
||||||
List<ScDryMilk> list = scDryMilkService.selectScDryMilkList(scDryMilk);
|
try {
|
||||||
ExcelUtil<ScDryMilk> util = new ExcelUtil<ScDryMilk>(ScDryMilk.class);
|
if (scDryMilk.getManageTags() != null) {
|
||||||
util.exportExcel(response, list, "干奶记录数据");
|
scDryMilk.setManageTags(scDryMilk.getManageTags().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ScDryMilk> list = scDryMilkService.selectScDryMilkList(scDryMilk);
|
||||||
|
ExcelUtil<ScDryMilk> util = new ExcelUtil<ScDryMilk>(ScDryMilk.class);
|
||||||
|
util.exportExcel(response, list, "干奶记录数据");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("导出干奶记录失败", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +95,49 @@ public class ScDryMilkController extends BaseController
|
|||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||||
{
|
{
|
||||||
return success(scDryMilkService.selectScDryMilkById(id));
|
try {
|
||||||
|
if (id == null) {
|
||||||
|
return error("记录ID不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
ScDryMilk result = scDryMilkService.selectScDryMilkById(id);
|
||||||
|
if (result == null) {
|
||||||
|
return error("记录不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("获取干奶记录详细信息失败,ID: " + id, e);
|
||||||
|
return error("获取记录详细信息失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据耳号查询羊只ID - 新增耳号验证功能
|
||||||
|
*/
|
||||||
|
@GetMapping("/validateEarTag")
|
||||||
|
public AjaxResult validateEarTag(@RequestParam("manageTags") String manageTags)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (manageTags == null || manageTags.trim().isEmpty()) {
|
||||||
|
return error("耳号不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
String cleanTag = manageTags.trim();
|
||||||
|
logger.info("验证耳号: [{}]", cleanTag);
|
||||||
|
|
||||||
|
Long sheepId = scDryMilkService.selectSheepIdByManageTags(cleanTag);
|
||||||
|
if (sheepId == null) {
|
||||||
|
logger.warn("耳号 [{}] 不存在", cleanTag);
|
||||||
|
return error("该耳号不存在,请检查输入");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("验证耳号成功,羊只ID: {}", sheepId);
|
||||||
|
return AjaxResult.success("耳号验证通过", sheepId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("验证耳号失败,耳号: " + manageTags, e);
|
||||||
|
return error("验证耳号时出错: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,6 +151,32 @@ public class ScDryMilkController extends BaseController
|
|||||||
return success(sheepId);
|
return success(sheepId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取羊舍列表 - 用于嵌套选择
|
||||||
|
*/
|
||||||
|
@GetMapping("/sheepfoldList")
|
||||||
|
public AjaxResult getSheepfoldList(@RequestParam(value = "ranchId", required = false) Long ranchId,
|
||||||
|
@RequestParam(value = "sheepfoldTypeId", required = false) Long sheepfoldTypeId)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
DaSheepfold query = new DaSheepfold();
|
||||||
|
if (ranchId != null) {
|
||||||
|
query.setRanchId(ranchId);
|
||||||
|
}
|
||||||
|
if (sheepfoldTypeId != null) {
|
||||||
|
query.setSheepfoldTypeId(sheepfoldTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DaSheepfold> sheepfoldList = daSheepfoldService.selectDaSheepfoldList(query);
|
||||||
|
logger.info("查询羊舍列表,牧场ID: {}, 类型ID: {}, 结果数量: {}", ranchId, sheepfoldTypeId, sheepfoldList.size());
|
||||||
|
|
||||||
|
return success(sheepfoldList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("获取羊舍列表失败", e);
|
||||||
|
return error("获取羊舍列表失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增干奶记录
|
* 新增干奶记录
|
||||||
*/
|
*/
|
||||||
@ -88,7 +185,48 @@ public class ScDryMilkController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody ScDryMilk scDryMilk)
|
public AjaxResult add(@RequestBody ScDryMilk scDryMilk)
|
||||||
{
|
{
|
||||||
return toAjax(scDryMilkService.insertScDryMilk(scDryMilk));
|
try {
|
||||||
|
// 基础参数校验
|
||||||
|
if (scDryMilk == null) {
|
||||||
|
return error("请求参数不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scDryMilk.getManageTags() == null || scDryMilk.getManageTags().trim().isEmpty()) {
|
||||||
|
return error("耳号不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scDryMilk.getDatetime() == null) {
|
||||||
|
return error("干奶日期不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scDryMilk.getStatus() == null) {
|
||||||
|
return error("请选择是否使用乳头封闭剂");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理输入参数
|
||||||
|
scDryMilk.setManageTags(scDryMilk.getManageTags().trim());
|
||||||
|
if (scDryMilk.getTecahnician() != null) {
|
||||||
|
scDryMilk.setTecahnician(scDryMilk.getTecahnician().trim());
|
||||||
|
}
|
||||||
|
if (scDryMilk.getComment() != null) {
|
||||||
|
scDryMilk.setComment(scDryMilk.getComment().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("新增干奶记录,耳号: {}", scDryMilk.getManageTags());
|
||||||
|
|
||||||
|
int result = scDryMilkService.insertScDryMilk(scDryMilk);
|
||||||
|
if (result > 0) {
|
||||||
|
// 重新查询插入的记录,包含自动生成的创建时间
|
||||||
|
ScDryMilk insertedRecord = scDryMilkService.selectScDryMilkById(scDryMilk.getId());
|
||||||
|
logger.info("新增干奶记录成功,记录ID: {}", scDryMilk.getId());
|
||||||
|
return success(insertedRecord);
|
||||||
|
} else {
|
||||||
|
return error("新增失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("新增干奶记录失败", e);
|
||||||
|
return error("新增失败: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,7 +237,39 @@ public class ScDryMilkController extends BaseController
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody ScDryMilk scDryMilk)
|
public AjaxResult edit(@RequestBody ScDryMilk scDryMilk)
|
||||||
{
|
{
|
||||||
return toAjax(scDryMilkService.updateScDryMilk(scDryMilk));
|
try {
|
||||||
|
if (scDryMilk == null) {
|
||||||
|
return error("请求参数不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scDryMilk.getId() == null) {
|
||||||
|
return error("记录ID不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理输入参数
|
||||||
|
if (scDryMilk.getManageTags() != null) {
|
||||||
|
scDryMilk.setManageTags(scDryMilk.getManageTags().trim());
|
||||||
|
}
|
||||||
|
if (scDryMilk.getTecahnician() != null) {
|
||||||
|
scDryMilk.setTecahnician(scDryMilk.getTecahnician().trim());
|
||||||
|
}
|
||||||
|
if (scDryMilk.getComment() != null) {
|
||||||
|
scDryMilk.setComment(scDryMilk.getComment().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("修改干奶记录,ID: {}", scDryMilk.getId());
|
||||||
|
|
||||||
|
int result = scDryMilkService.updateScDryMilk(scDryMilk);
|
||||||
|
if (result > 0) {
|
||||||
|
logger.info("修改干奶记录成功");
|
||||||
|
return success("修改成功");
|
||||||
|
} else {
|
||||||
|
return error("修改失败,记录可能不存在");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("修改干奶记录失败", e);
|
||||||
|
return error("修改失败: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,6 +280,23 @@ public class ScDryMilkController extends BaseController
|
|||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public AjaxResult remove(@PathVariable Long[] ids)
|
public AjaxResult remove(@PathVariable Long[] ids)
|
||||||
{
|
{
|
||||||
return toAjax(scDryMilkService.deleteScDryMilkByIds(ids));
|
try {
|
||||||
|
if (ids == null || ids.length == 0) {
|
||||||
|
return error("删除的记录ID不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("删除干奶记录,IDs: {}", java.util.Arrays.toString(ids));
|
||||||
|
|
||||||
|
int result = scDryMilkService.deleteScDryMilkByIds(ids);
|
||||||
|
if (result > 0) {
|
||||||
|
logger.info("删除干奶记录成功,删除数量: {}", result);
|
||||||
|
return success("删除成功");
|
||||||
|
} else {
|
||||||
|
return error("删除失败,记录可能不存在");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("删除干奶记录失败", e);
|
||||||
|
return error("删除失败: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,12 +76,13 @@ public class ScLambingRecordController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取产羔记录详细信息
|
* 获取产羔记录详细信息(修改:改为获取包含关联信息的详细数据)
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('breed:lambing_records:query')")
|
@PreAuthorize("@ss.hasPermi('breed:lambing_records:query')")
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||||
return success(scLambingRecordService.selectScLambingRecordById(id));
|
// 修改:改为调用详细查询方法,获取包含母羊耳号、公羊耳号等关联信息
|
||||||
|
return success(scLambingRecordService.selectScLambingRecordDetailById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -45,8 +45,22 @@ public class ScPregnancyRecordController extends BaseController
|
|||||||
public TableDataInfo list(ScPregnancyRecord scPregnancyRecord)
|
public TableDataInfo list(ScPregnancyRecord scPregnancyRecord)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
// 添加调试日志
|
||||||
|
if (scPregnancyRecord.getManageTags() != null && !scPregnancyRecord.getManageTags().trim().isEmpty()) {
|
||||||
|
logger.info("搜索耳号参数: [{}]", scPregnancyRecord.getManageTags());
|
||||||
|
// 清理输入参数
|
||||||
|
scPregnancyRecord.setManageTags(scPregnancyRecord.getManageTags().trim());
|
||||||
|
}
|
||||||
|
if (scPregnancyRecord.getTechnician() != null && !scPregnancyRecord.getTechnician().trim().isEmpty()) {
|
||||||
|
logger.info("搜索技术员参数: [{}]", scPregnancyRecord.getTechnician());
|
||||||
|
scPregnancyRecord.setTechnician(scPregnancyRecord.getTechnician().trim());
|
||||||
|
}
|
||||||
|
|
||||||
startPage();
|
startPage();
|
||||||
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord);
|
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord);
|
||||||
|
|
||||||
|
logger.info("查询到孕检记录数量: {}", list.size());
|
||||||
|
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("查询孕检记录列表失败", e);
|
logger.error("查询孕检记录列表失败", e);
|
||||||
@ -63,6 +77,14 @@ public class ScPregnancyRecordController extends BaseController
|
|||||||
public void export(HttpServletResponse response, ScPregnancyRecord scPregnancyRecord)
|
public void export(HttpServletResponse response, ScPregnancyRecord scPregnancyRecord)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
// 清理导出参数
|
||||||
|
if (scPregnancyRecord.getManageTags() != null) {
|
||||||
|
scPregnancyRecord.setManageTags(scPregnancyRecord.getManageTags().trim());
|
||||||
|
}
|
||||||
|
if (scPregnancyRecord.getTechnician() != null) {
|
||||||
|
scPregnancyRecord.setTechnician(scPregnancyRecord.getTechnician().trim());
|
||||||
|
}
|
||||||
|
|
||||||
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord);
|
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord);
|
||||||
ExcelUtil<ScPregnancyRecord> util = new ExcelUtil<ScPregnancyRecord>(ScPregnancyRecord.class);
|
ExcelUtil<ScPregnancyRecord> util = new ExcelUtil<ScPregnancyRecord>(ScPregnancyRecord.class);
|
||||||
util.exportExcel(response, list, "孕检记录数据");
|
util.exportExcel(response, list, "孕检记录数据");
|
||||||
@ -125,13 +147,25 @@ public class ScPregnancyRecordController extends BaseController
|
|||||||
return error("技术员不能为空");
|
return error("技术员不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清理输入参数
|
||||||
|
scPregnancyRecord.setManageTags(scPregnancyRecord.getManageTags().trim());
|
||||||
|
scPregnancyRecord.setResult(scPregnancyRecord.getResult().trim());
|
||||||
|
scPregnancyRecord.setTechnician(scPregnancyRecord.getTechnician().trim());
|
||||||
|
|
||||||
|
if (scPregnancyRecord.getRemark() != null) {
|
||||||
|
scPregnancyRecord.setRemark(scPregnancyRecord.getRemark().trim());
|
||||||
|
}
|
||||||
|
|
||||||
// 如果孕检方式为空,默认设置为B超
|
// 如果孕检方式为空,默认设置为B超
|
||||||
if (scPregnancyRecord.getWay() == null || scPregnancyRecord.getWay().trim().isEmpty()) {
|
if (scPregnancyRecord.getWay() == null || scPregnancyRecord.getWay().trim().isEmpty()) {
|
||||||
scPregnancyRecord.setWay("B超");
|
scPregnancyRecord.setWay("B超");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("新增孕检记录,耳号: {}, 结果: {}", scPregnancyRecord.getManageTags(), scPregnancyRecord.getResult());
|
||||||
|
|
||||||
int result = scPregnancyRecordService.insertScPregnancyRecord(scPregnancyRecord);
|
int result = scPregnancyRecordService.insertScPregnancyRecord(scPregnancyRecord);
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
|
logger.info("新增孕检记录成功,记录ID: {}", scPregnancyRecord.getId());
|
||||||
return success("新增成功");
|
return success("新增成功");
|
||||||
} else {
|
} else {
|
||||||
return error("新增失败");
|
return error("新增失败");
|
||||||
@ -179,8 +213,20 @@ public class ScPregnancyRecordController extends BaseController
|
|||||||
return error("技术员不能为空");
|
return error("技术员不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清理输入参数
|
||||||
|
scPregnancyRecord.setManageTags(scPregnancyRecord.getManageTags().trim());
|
||||||
|
scPregnancyRecord.setResult(scPregnancyRecord.getResult().trim());
|
||||||
|
scPregnancyRecord.setTechnician(scPregnancyRecord.getTechnician().trim());
|
||||||
|
|
||||||
|
if (scPregnancyRecord.getRemark() != null) {
|
||||||
|
scPregnancyRecord.setRemark(scPregnancyRecord.getRemark().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("修改孕检记录,ID: {}, 耳号: {}", scPregnancyRecord.getId(), scPregnancyRecord.getManageTags());
|
||||||
|
|
||||||
int result = scPregnancyRecordService.updateScPregnancyRecord(scPregnancyRecord);
|
int result = scPregnancyRecordService.updateScPregnancyRecord(scPregnancyRecord);
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
|
logger.info("修改孕检记录成功");
|
||||||
return success("修改成功");
|
return success("修改成功");
|
||||||
} else {
|
} else {
|
||||||
return error("修改失败,记录可能不存在");
|
return error("修改失败,记录可能不存在");
|
||||||
@ -207,8 +253,11 @@ public class ScPregnancyRecordController extends BaseController
|
|||||||
return error("删除的记录ID不能为空");
|
return error("删除的记录ID不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("删除孕检记录,IDs: {}", java.util.Arrays.toString(ids));
|
||||||
|
|
||||||
int result = scPregnancyRecordService.deleteScPregnancyRecordByIds(ids);
|
int result = scPregnancyRecordService.deleteScPregnancyRecordByIds(ids);
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
|
logger.info("删除孕检记录成功,删除数量: {}", result);
|
||||||
return success("删除成功");
|
return success("删除成功");
|
||||||
} else {
|
} else {
|
||||||
return error("删除失败,记录可能不存在");
|
return error("删除失败,记录可能不存在");
|
||||||
@ -233,11 +282,16 @@ public class ScPregnancyRecordController extends BaseController
|
|||||||
return error("管理耳号不能为空");
|
return error("管理耳号不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> sheepInfo = scPregnancyRecordService.getSheepByManageTags(manageTags.trim());
|
String cleanTag = manageTags.trim();
|
||||||
|
logger.info("查询羊只信息,耳号: [{}]", cleanTag);
|
||||||
|
|
||||||
|
Map<String, Object> sheepInfo = scPregnancyRecordService.getSheepByManageTags(cleanTag);
|
||||||
if (sheepInfo == null) {
|
if (sheepInfo == null) {
|
||||||
|
logger.warn("未找到耳号 [{}] 对应的羊只信息", cleanTag);
|
||||||
return error("未找到该耳号的羊只信息");
|
return error("未找到该耳号的羊只信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("查询羊只信息成功,羊只ID: {}", sheepInfo.get("id"));
|
||||||
return success(sheepInfo);
|
return success(sheepInfo);
|
||||||
} catch (ServiceException e) {
|
} catch (ServiceException e) {
|
||||||
return error(e.getMessage());
|
return error(e.getMessage());
|
||||||
@ -258,11 +312,16 @@ public class ScPregnancyRecordController extends BaseController
|
|||||||
return error("管理耳号不能为空");
|
return error("管理耳号不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> breedInfo = scPregnancyRecordService.getBreedInfoByManageTags(manageTags.trim());
|
String cleanTag = manageTags.trim();
|
||||||
|
logger.info("查询配种信息,耳号: [{}]", cleanTag);
|
||||||
|
|
||||||
|
Map<String, Object> breedInfo = scPregnancyRecordService.getBreedInfoByManageTags(cleanTag);
|
||||||
if (breedInfo == null) {
|
if (breedInfo == null) {
|
||||||
|
logger.info("未找到耳号 [{}] 对应的配种信息", cleanTag);
|
||||||
return error("未找到该耳号的配种信息");
|
return error("未找到该耳号的配种信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("查询配种信息成功");
|
||||||
return success(breedInfo);
|
return success(breedInfo);
|
||||||
} catch (ServiceException e) {
|
} catch (ServiceException e) {
|
||||||
return error(e.getMessage());
|
return error(e.getMessage());
|
||||||
@ -271,4 +330,30 @@ public class ScPregnancyRecordController extends BaseController
|
|||||||
return error("查询配种信息失败: " + e.getMessage());
|
return error("查询配种信息失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调试接口:测试数据库连接和基础查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/debug/test")
|
||||||
|
public AjaxResult debugTest()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// 测试基础查询
|
||||||
|
ScPregnancyRecord testQuery = new ScPregnancyRecord();
|
||||||
|
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(testQuery);
|
||||||
|
|
||||||
|
logger.info("调试测试 - 总记录数: {}", list.size());
|
||||||
|
|
||||||
|
// 打印前几条记录的耳号信息
|
||||||
|
for (int i = 0; i < Math.min(5, list.size()); i++) {
|
||||||
|
ScPregnancyRecord record = list.get(i);
|
||||||
|
logger.info("调试测试 - 记录{}:ID={}, 耳号={}", i+1, record.getId(), record.getManageTags());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success("调试测试完成,总记录数: " + list.size());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("调试测试失败", e);
|
||||||
|
return error("调试测试失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -20,6 +20,8 @@ import com.zhyc.common.enums.BusinessType;
|
|||||||
import com.zhyc.common.exception.ServiceException;
|
import com.zhyc.common.exception.ServiceException;
|
||||||
import com.zhyc.module.produce.breed.domain.ScSheepDeath;
|
import com.zhyc.module.produce.breed.domain.ScSheepDeath;
|
||||||
import com.zhyc.module.produce.breed.service.IScSheepDeathService;
|
import com.zhyc.module.produce.breed.service.IScSheepDeathService;
|
||||||
|
import com.zhyc.module.biosafety.service.ISwDiseaseService;
|
||||||
|
import com.zhyc.module.biosafety.domain.SwDisease;
|
||||||
import com.zhyc.common.utils.poi.ExcelUtil;
|
import com.zhyc.common.utils.poi.ExcelUtil;
|
||||||
import com.zhyc.common.core.page.TableDataInfo;
|
import com.zhyc.common.core.page.TableDataInfo;
|
||||||
|
|
||||||
@ -36,6 +38,9 @@ public class ScSheepDeathController extends BaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IScSheepDeathService scSheepDeathService;
|
private IScSheepDeathService scSheepDeathService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISwDiseaseService swDiseaseService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询羊只死淘记录列表
|
* 查询羊只死淘记录列表
|
||||||
*/
|
*/
|
||||||
@ -77,6 +82,22 @@ public class ScSheepDeathController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取疾病树形列表
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('sheep_death:death:query')")
|
||||||
|
@GetMapping("/disease/tree")
|
||||||
|
public AjaxResult getDiseaseTree()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
List<SwDisease> diseaseList = swDiseaseService.selectSwDiseaseList(new SwDisease());
|
||||||
|
return success(diseaseList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("获取疾病树形列表失败", e);
|
||||||
|
return error("获取疾病列表失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出羊只死淘记录列表
|
* 导出羊只死淘记录列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.zhyc.module.produce.breed.domain;
|
package com.zhyc.module.produce.breed.domain;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -26,7 +27,7 @@ public class RawSpermRecord extends BaseEntity
|
|||||||
|
|
||||||
/** 羊只ID */
|
/** 羊只ID */
|
||||||
@Excel(name = "羊只ID")
|
@Excel(name = "羊只ID")
|
||||||
private Long sheepId;
|
private Integer sheepId;
|
||||||
|
|
||||||
/** 耳号 */
|
/** 耳号 */
|
||||||
@Excel(name = "耳号")
|
@Excel(name = "耳号")
|
||||||
@ -38,7 +39,7 @@ public class RawSpermRecord extends BaseEntity
|
|||||||
|
|
||||||
/** 月龄 */
|
/** 月龄 */
|
||||||
@Excel(name = "月龄")
|
@Excel(name = "月龄")
|
||||||
private Long monthAge;
|
private Integer monthAge;
|
||||||
|
|
||||||
/** 采精日期 */
|
/** 采精日期 */
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
@ -46,8 +47,8 @@ public class RawSpermRecord extends BaseEntity
|
|||||||
private Date pickDate;
|
private Date pickDate;
|
||||||
|
|
||||||
/** 采精量 */
|
/** 采精量 */
|
||||||
@Excel(name = "采精量")
|
@Excel(name = "采精量(ml)")
|
||||||
private Long amount;
|
private BigDecimal amount;
|
||||||
|
|
||||||
/** 精液密度 */
|
/** 精液密度 */
|
||||||
@Excel(name = "精液密度")
|
@Excel(name = "精液密度")
|
||||||
@ -59,7 +60,7 @@ public class RawSpermRecord extends BaseEntity
|
|||||||
|
|
||||||
/** 是否性控(0否1是) */
|
/** 是否性控(0否1是) */
|
||||||
@Excel(name = "是否性控", readConverterExp = "0=否,1=是")
|
@Excel(name = "是否性控", readConverterExp = "0=否,1=是")
|
||||||
private Long controlled;
|
private Integer controlled;
|
||||||
|
|
||||||
/** 性欲情况 */
|
/** 性欲情况 */
|
||||||
@Excel(name = "性欲情况")
|
@Excel(name = "性欲情况")
|
||||||
@ -77,5 +78,11 @@ public class RawSpermRecord extends BaseEntity
|
|||||||
@Excel(name = "采集备注")
|
@Excel(name = "采集备注")
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
|
/** 阴囊周长(cm) */
|
||||||
|
@Excel(name = "阴囊周长(cm)")
|
||||||
|
private BigDecimal scrotumCircumference;
|
||||||
|
|
||||||
|
/** 精液品质(A/B/C/D级) */
|
||||||
|
@Excel(name = "精液品质", readConverterExp = "A=A级,B=B级,C=C级,D=D级")
|
||||||
|
private String semenQuality;
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.zhyc.module.produce.breed.mapper;
|
package com.zhyc.module.produce.breed.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import com.zhyc.module.produce.breed.domain.RawSpermRecord;
|
import com.zhyc.module.produce.breed.domain.RawSpermRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,5 +66,13 @@ public interface RawSpermRecordMapper
|
|||||||
* @param manageTags 耳号
|
* @param manageTags 耳号
|
||||||
* @return 羊只ID
|
* @return 羊只ID
|
||||||
*/
|
*/
|
||||||
public Long selectSheepIdByManageTags(String manageTags);
|
public Integer selectSheepIdByManageTags(String manageTags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据耳号查询羊只信息(包含ID、性别、月龄、电子耳号等)
|
||||||
|
*
|
||||||
|
* @param manageTags 耳号
|
||||||
|
* @return 羊只信息 Map包含id、gender、monthAge、electronicTags等字段
|
||||||
|
*/
|
||||||
|
public Map<String, Object> selectSheepInfoByManageTags(String manageTags);
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.zhyc.module.produce.breed.service;
|
package com.zhyc.module.produce.breed.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import com.zhyc.module.produce.breed.domain.RawSpermRecord;
|
import com.zhyc.module.produce.breed.domain.RawSpermRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,4 +67,20 @@ public interface IRawSpermRecordService
|
|||||||
* @return 羊只ID
|
* @return 羊只ID
|
||||||
*/
|
*/
|
||||||
public Long getSheepIdByManageTags(String manageTags);
|
public Long getSheepIdByManageTags(String manageTags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据耳号查询羊只信息并验证是否为公羊
|
||||||
|
*
|
||||||
|
* @param manageTags 耳号
|
||||||
|
* @return 羊只信息 Map包含id和gender字段
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getSheepInfoByManageTags(String manageTags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证羊只是否为公羊
|
||||||
|
*
|
||||||
|
* @param manageTags 耳号
|
||||||
|
* @return true-是公羊,false-不是公羊
|
||||||
|
*/
|
||||||
|
public boolean validateRamGender(String manageTags);
|
||||||
}
|
}
|
||||||
@ -44,10 +44,16 @@ public interface IScLambingRecordService {
|
|||||||
public int deleteScLambingRecordById(Long id);
|
public int deleteScLambingRecordById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询产羔记录
|
* 查询产羔记录基础信息
|
||||||
*/
|
*/
|
||||||
public ScLambingRecord selectScLambingRecordById(Long id);
|
public ScLambingRecord selectScLambingRecordById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询产羔记录详细信息(包含关联信息)- 新增方法
|
||||||
|
* 用于修改时获取完整的产羔记录信息,包括母羊耳号、公羊耳号、配种日期等关联字段
|
||||||
|
*/
|
||||||
|
public ScLambingRecord selectScLambingRecordDetailById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询羔羊详情
|
* 查询羔羊详情
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.zhyc.module.produce.breed.service.impl;
|
package com.zhyc.module.produce.breed.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import com.zhyc.common.utils.DateUtils;
|
import com.zhyc.common.utils.DateUtils;
|
||||||
import com.zhyc.common.utils.StringUtils;
|
import com.zhyc.common.utils.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -54,10 +55,37 @@ public class RawSpermRecordServiceImpl implements IRawSpermRecordService
|
|||||||
@Override
|
@Override
|
||||||
public int insertRawSpermRecord(RawSpermRecord rawSpermRecord)
|
public int insertRawSpermRecord(RawSpermRecord rawSpermRecord)
|
||||||
{
|
{
|
||||||
// 如果传入的是耳号,需要先根据耳号查询羊只ID
|
// 如果传入的是耳号,需要先根据耳号查询羊只信息并验证性别
|
||||||
if (StringUtils.isNotEmpty(rawSpermRecord.getManageTags()) && rawSpermRecord.getSheepId() == null) {
|
if (StringUtils.isNotEmpty(rawSpermRecord.getManageTags())) {
|
||||||
Long sheepId = getSheepIdByManageTags(rawSpermRecord.getManageTags());
|
Map<String, Object> sheepInfo = getSheepInfoByManageTags(rawSpermRecord.getManageTags());
|
||||||
|
if (sheepInfo == null) {
|
||||||
|
throw new RuntimeException("未找到耳号为[" + rawSpermRecord.getManageTags() + "]的羊只信息");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 安全的类型转换
|
||||||
|
Integer sheepId = convertToInteger(sheepInfo.get("id"));
|
||||||
|
Integer gender = convertToInteger(sheepInfo.get("gender"));
|
||||||
|
Integer monthAge = convertToInteger(sheepInfo.get("monthAge"));
|
||||||
|
String electronicTags = (String) sheepInfo.get("electronicTags");
|
||||||
|
|
||||||
|
// 关键验证:必须是公羊(gender=2)
|
||||||
|
if (gender == null || gender != 2) {
|
||||||
|
throw new RuntimeException("采精记录只能针对公羊,耳号[" + rawSpermRecord.getManageTags() + "]对应的羊只不是公羊");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置关联信息
|
||||||
rawSpermRecord.setSheepId(sheepId);
|
rawSpermRecord.setSheepId(sheepId);
|
||||||
|
if (rawSpermRecord.getMonthAge() == null && monthAge != null) {
|
||||||
|
rawSpermRecord.setMonthAge(monthAge);
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(rawSpermRecord.getElectronicTags()) && StringUtils.isNotEmpty(electronicTags)) {
|
||||||
|
rawSpermRecord.setElectronicTags(electronicTags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置默认值
|
||||||
|
if (rawSpermRecord.getControlled() == null) {
|
||||||
|
rawSpermRecord.setControlled(0); // 默认不性控
|
||||||
}
|
}
|
||||||
|
|
||||||
rawSpermRecord.setCreateTime(DateUtils.getNowDate());
|
rawSpermRecord.setCreateTime(DateUtils.getNowDate());
|
||||||
@ -73,12 +101,25 @@ public class RawSpermRecordServiceImpl implements IRawSpermRecordService
|
|||||||
@Override
|
@Override
|
||||||
public int updateRawSpermRecord(RawSpermRecord rawSpermRecord)
|
public int updateRawSpermRecord(RawSpermRecord rawSpermRecord)
|
||||||
{
|
{
|
||||||
// 如果传入的是耳号,需要先根据耳号查询羊只ID
|
// 如果修改了耳号,需要重新验证
|
||||||
if (StringUtils.isNotEmpty(rawSpermRecord.getManageTags()) && rawSpermRecord.getSheepId() == null) {
|
if (StringUtils.isNotEmpty(rawSpermRecord.getManageTags())) {
|
||||||
Long sheepId = getSheepIdByManageTags(rawSpermRecord.getManageTags());
|
Map<String, Object> sheepInfo = getSheepInfoByManageTags(rawSpermRecord.getManageTags());
|
||||||
|
if (sheepInfo == null) {
|
||||||
|
throw new RuntimeException("未找到耳号为[" + rawSpermRecord.getManageTags() + "]的羊只信息");
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer sheepId = convertToInteger(sheepInfo.get("id"));
|
||||||
|
Integer gender = convertToInteger(sheepInfo.get("gender"));
|
||||||
|
|
||||||
|
// 验证性别
|
||||||
|
if (gender == null || gender != 2) {
|
||||||
|
throw new RuntimeException("采精记录只能针对公羊,耳号[" + rawSpermRecord.getManageTags() + "]对应的羊只不是公羊");
|
||||||
|
}
|
||||||
|
|
||||||
rawSpermRecord.setSheepId(sheepId);
|
rawSpermRecord.setSheepId(sheepId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawSpermRecord.setUpdateTime(DateUtils.getNowDate());
|
||||||
return rawSpermRecordMapper.updateRawSpermRecord(rawSpermRecord);
|
return rawSpermRecordMapper.updateRawSpermRecord(rawSpermRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +156,68 @@ public class RawSpermRecordServiceImpl implements IRawSpermRecordService
|
|||||||
@Override
|
@Override
|
||||||
public Long getSheepIdByManageTags(String manageTags)
|
public Long getSheepIdByManageTags(String manageTags)
|
||||||
{
|
{
|
||||||
return rawSpermRecordMapper.selectSheepIdByManageTags(manageTags);
|
Integer sheepId = rawSpermRecordMapper.selectSheepIdByManageTags(manageTags);
|
||||||
|
return sheepId != null ? sheepId.longValue() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据耳号查询羊只信息
|
||||||
|
*
|
||||||
|
* @param manageTags 耳号
|
||||||
|
* @return 羊只信息 Map包含id、gender、monthAge、electronicTags等字段
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getSheepInfoByManageTags(String manageTags)
|
||||||
|
{
|
||||||
|
return rawSpermRecordMapper.selectSheepInfoByManageTags(manageTags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证羊只是否为公羊
|
||||||
|
*
|
||||||
|
* @param manageTags 耳号
|
||||||
|
* @return true-是公羊,false-不是公羊
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean validateRamGender(String manageTags)
|
||||||
|
{
|
||||||
|
Map<String, Object> sheepInfo = getSheepInfoByManageTags(manageTags);
|
||||||
|
if (sheepInfo != null) {
|
||||||
|
Integer gender = convertToInteger(sheepInfo.get("gender"));
|
||||||
|
return gender != null && gender == 2; // 公羊gender=2
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全的类型转换:将Object转换为Integer
|
||||||
|
*
|
||||||
|
* @param obj 要转换的对象
|
||||||
|
* @return Integer值,如果转换失败返回null
|
||||||
|
*/
|
||||||
|
private Integer convertToInteger(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj instanceof Integer) {
|
||||||
|
return (Integer) obj;
|
||||||
|
} else if (obj instanceof Long) {
|
||||||
|
Long longValue = (Long) obj;
|
||||||
|
// 检查Long值是否在Integer范围内
|
||||||
|
if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) {
|
||||||
|
return longValue.intValue();
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("数值超出Integer范围:" + longValue);
|
||||||
|
}
|
||||||
|
} else if (obj instanceof String) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt((String) obj);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new RuntimeException("无法将字符串转换为Integer:" + obj);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("无法将 " + obj.getClass().getSimpleName() + " 类型转换为Integer");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,12 +1,14 @@
|
|||||||
package com.zhyc.module.produce.breed.service.impl;
|
package com.zhyc.module.produce.breed.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Date;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.zhyc.module.produce.breed.mapper.ScDryMilkMapper;
|
import com.zhyc.module.produce.breed.mapper.ScDryMilkMapper;
|
||||||
import com.zhyc.module.produce.breed.domain.ScDryMilk;
|
import com.zhyc.module.produce.breed.domain.ScDryMilk;
|
||||||
import com.zhyc.module.produce.breed.service.IScDryMilkService;
|
import com.zhyc.module.produce.breed.service.IScDryMilkService;
|
||||||
import com.zhyc.common.utils.StringUtils;
|
import com.zhyc.common.utils.StringUtils;
|
||||||
|
import com.zhyc.common.utils.DateUtils;
|
||||||
import com.zhyc.common.exception.ServiceException;
|
import com.zhyc.common.exception.ServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,6 +78,12 @@ public class ScDryMilkServiceImpl implements IScDryMilkService
|
|||||||
}
|
}
|
||||||
scDryMilk.setSheepId(String.valueOf(sheepId));
|
scDryMilk.setSheepId(String.valueOf(sheepId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自动设置创建时间(精确到分钟)
|
||||||
|
scDryMilk.setCreateTime(DateUtils.getNowDate());
|
||||||
|
// 如果有获取当前用户的方法,可以设置创建人
|
||||||
|
// scDryMilk.setCreateBy(SecurityUtils.getUsername());
|
||||||
|
|
||||||
return scDryMilkMapper.insertScDryMilk(scDryMilk);
|
return scDryMilkMapper.insertScDryMilk(scDryMilk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +106,12 @@ public class ScDryMilkServiceImpl implements IScDryMilkService
|
|||||||
}
|
}
|
||||||
scDryMilk.setSheepId(String.valueOf(sheepId));
|
scDryMilk.setSheepId(String.valueOf(sheepId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置更新时间
|
||||||
|
scDryMilk.setUpdateTime(DateUtils.getNowDate());
|
||||||
|
// 如果有获取当前用户的方法,可以设置更新人
|
||||||
|
// scDryMilk.setUpdateBy(SecurityUtils.getUsername());
|
||||||
|
|
||||||
return scDryMilkMapper.updateScDryMilk(scDryMilk);
|
return scDryMilkMapper.updateScDryMilk(scDryMilk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -179,13 +179,22 @@ public class ScLambingRecordServiceImpl implements IScLambingRecordService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询产羔记录
|
* 查询产羔记录基础信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ScLambingRecord selectScLambingRecordById(Long id) {
|
public ScLambingRecord selectScLambingRecordById(Long id) {
|
||||||
return scLambingRecordMapper.selectScLambingRecordById(id);
|
return scLambingRecordMapper.selectScLambingRecordById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询产羔记录详细信息(包含关联信息)- 新增方法
|
||||||
|
* 用于修改时获取完整的产羔记录信息,包括母羊耳号、公羊耳号、配种日期等关联字段
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ScLambingRecord selectScLambingRecordDetailById(Long id) {
|
||||||
|
return scLambingRecordMapper.selectScLambingRecordDetailById(id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询羔羊详情
|
* 查询羔羊详情
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.zhyc.module.produce.breed.service.impl;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import com.zhyc.common.utils.DateUtils;
|
import com.zhyc.common.utils.DateUtils;
|
||||||
|
import com.zhyc.common.exception.ServiceException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.zhyc.module.produce.breed.mapper.ScMiscarriageRecordMapper;
|
import com.zhyc.module.produce.breed.mapper.ScMiscarriageRecordMapper;
|
||||||
@ -47,6 +48,7 @@ public class ScMiscarriageRecordServiceImpl implements IScMiscarriageRecordServi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增流产记录
|
* 新增流产记录
|
||||||
|
* 增加性别验证:只允许母羊录入流产记录
|
||||||
*
|
*
|
||||||
* @param scMiscarriageRecord 流产记录
|
* @param scMiscarriageRecord 流产记录
|
||||||
* @return 结果
|
* @return 结果
|
||||||
@ -54,12 +56,16 @@ public class ScMiscarriageRecordServiceImpl implements IScMiscarriageRecordServi
|
|||||||
@Override
|
@Override
|
||||||
public int insertScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord)
|
public int insertScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord)
|
||||||
{
|
{
|
||||||
|
// 验证羊只是否存在及性别
|
||||||
|
validateSheepGender(scMiscarriageRecord.getSheepId());
|
||||||
|
|
||||||
scMiscarriageRecord.setCreateTime(DateUtils.getNowDate());
|
scMiscarriageRecord.setCreateTime(DateUtils.getNowDate());
|
||||||
return scMiscarriageRecordMapper.insertScMiscarriageRecord(scMiscarriageRecord);
|
return scMiscarriageRecordMapper.insertScMiscarriageRecord(scMiscarriageRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改流产记录
|
* 修改流产记录
|
||||||
|
* 增加性别验证:只允许母羊录入流产记录
|
||||||
*
|
*
|
||||||
* @param scMiscarriageRecord 流产记录
|
* @param scMiscarriageRecord 流产记录
|
||||||
* @return 结果
|
* @return 结果
|
||||||
@ -67,6 +73,9 @@ public class ScMiscarriageRecordServiceImpl implements IScMiscarriageRecordServi
|
|||||||
@Override
|
@Override
|
||||||
public int updateScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord)
|
public int updateScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord)
|
||||||
{
|
{
|
||||||
|
// 修改时也需要验证性别(防止前端绕过验证)
|
||||||
|
validateSheepGender(scMiscarriageRecord.getSheepId());
|
||||||
|
|
||||||
return scMiscarriageRecordMapper.updateScMiscarriageRecord(scMiscarriageRecord);
|
return scMiscarriageRecordMapper.updateScMiscarriageRecord(scMiscarriageRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,4 +114,57 @@ public class ScMiscarriageRecordServiceImpl implements IScMiscarriageRecordServi
|
|||||||
{
|
{
|
||||||
return scMiscarriageRecordMapper.selectSheepByManageTags(manageTags);
|
return scMiscarriageRecordMapper.selectSheepByManageTags(manageTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证羊只性别 - 私有方法
|
||||||
|
* 只允许母羊录入流产记录
|
||||||
|
* gender字段:1=母羊,2=公羊
|
||||||
|
*
|
||||||
|
* @param manageTags 管理耳号
|
||||||
|
* @throws ServiceException 如果不是母羊或羊只不存在
|
||||||
|
*/
|
||||||
|
private void validateSheepGender(String manageTags) {
|
||||||
|
if (manageTags == null || manageTags.trim().isEmpty()) {
|
||||||
|
throw new ServiceException("羊只耳号不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询羊只信息
|
||||||
|
Map<String, Object> sheepInfo = scMiscarriageRecordMapper.selectSheepByManageTags(manageTags);
|
||||||
|
|
||||||
|
if (sheepInfo == null || sheepInfo.isEmpty()) {
|
||||||
|
throw new ServiceException("未找到耳号为【" + manageTags + "】的羊只信息,请检查耳号是否正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查性别 - 注意:这里使用gender字段,不是sexType
|
||||||
|
Object genderObj = sheepInfo.get("gender");
|
||||||
|
if (genderObj == null) {
|
||||||
|
throw new ServiceException("该羊只性别信息缺失,无法录入流产记录");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换性别类型
|
||||||
|
Integer gender = null;
|
||||||
|
try {
|
||||||
|
if (genderObj instanceof Integer) {
|
||||||
|
gender = (Integer) genderObj;
|
||||||
|
} else if (genderObj instanceof String) {
|
||||||
|
gender = Integer.valueOf((String) genderObj);
|
||||||
|
} else if (genderObj instanceof Long) {
|
||||||
|
gender = ((Long) genderObj).intValue();
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new ServiceException("该羊只性别信息格式错误,无法录入流产记录");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证是否为母羊 - 1=母羊,2=公羊
|
||||||
|
if (gender == null) {
|
||||||
|
throw new ServiceException("该羊只性别信息为空,无法录入流产记录");
|
||||||
|
} else if (gender == 2) {
|
||||||
|
String variety = sheepInfo.get("variety") != null ? sheepInfo.get("variety").toString() : "未知品种";
|
||||||
|
throw new ServiceException("流产记录只能录入母羊,耳号【" + manageTags + "】对应的是公羊(" + variety + ")");
|
||||||
|
} else if (gender != 1) {
|
||||||
|
throw new ServiceException("该羊只性别信息异常(值:" + gender + "),只允许母羊录入流产记录");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证通过
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
|||||||
Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null;
|
Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null;
|
||||||
scSheepDeath.setSheepId(sheepId);
|
scSheepDeath.setSheepId(sheepId);
|
||||||
|
|
||||||
// 插入死淘记录后,同时更新羊只在群状态为"不在群"(字典值为2)
|
// 插入死淘记录后,同时更新羊只在群状态为"不在群"(状态ID为2)
|
||||||
if (sheepId != null) {
|
if (sheepId != null) {
|
||||||
scSheepDeathMapper.updateSheepStatus(sheepId, "2");
|
scSheepDeathMapper.updateSheepStatus(sheepId, "2");
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
|||||||
Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null;
|
Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null;
|
||||||
scSheepDeath.setSheepId(sheepId);
|
scSheepDeath.setSheepId(sheepId);
|
||||||
|
|
||||||
// 修改死淘记录时,同时更新羊只在群状态为"不在群"(字典值为2)
|
// 修改死淘记录时,同时更新羊只在群状态为"不在群"(状态ID为2)
|
||||||
if (sheepId != null) {
|
if (sheepId != null) {
|
||||||
scSheepDeathMapper.updateSheepStatus(sheepId, "2");
|
scSheepDeathMapper.updateSheepStatus(sheepId, "2");
|
||||||
}
|
}
|
||||||
@ -161,11 +161,11 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
|||||||
@Override
|
@Override
|
||||||
public int deleteScSheepDeathByIds(Long[] ids)
|
public int deleteScSheepDeathByIds(Long[] ids)
|
||||||
{
|
{
|
||||||
// 可选:删除死淘记录前,将对应羊只在群状态改回"在群"
|
// 删除死淘记录前,将对应羊只在群状态改回"在群"
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id);
|
ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id);
|
||||||
if (scSheepDeath != null && scSheepDeath.getSheepId() != null) {
|
if (scSheepDeath != null && scSheepDeath.getSheepId() != null) {
|
||||||
// 恢复羊只在群状态为"在群"(字典值为1)
|
// 恢复羊只在群状态为"在群"(状态ID为1)
|
||||||
scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1");
|
scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,10 +182,10 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
|||||||
@Override
|
@Override
|
||||||
public int deleteScSheepDeathById(Long id)
|
public int deleteScSheepDeathById(Long id)
|
||||||
{
|
{
|
||||||
// 可选:删除死淘记录前,将对应羊只在群状态改回"在群"
|
// 删除死淘记录前,将对应羊只在群状态改回"在群"
|
||||||
ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id);
|
ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id);
|
||||||
if (scSheepDeath != null && scSheepDeath.getSheepId() != null) {
|
if (scSheepDeath != null && scSheepDeath.getSheepId() != null) {
|
||||||
// 恢复羊只在群状态为"在群"(字典值为1)
|
// 恢复羊只在群状态为"在群"(状态ID为1)
|
||||||
scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1");
|
scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,7 @@
|
|||||||
END as mating_type_name,
|
END as mating_type_name,
|
||||||
sf.mating_date,
|
sf.mating_date,
|
||||||
sf.parity,
|
sf.parity,
|
||||||
sf.variety as ram_variety, -- 这里需要根据实际配种公羊信息调整
|
sf.variety as ram_variety,
|
||||||
sf.month_age,
|
sf.month_age,
|
||||||
CASE
|
CASE
|
||||||
WHEN sf.mating_date IS NOT NULL AND smr.datetime IS NOT NULL
|
WHEN sf.mating_date IS NOT NULL AND smr.datetime IS NOT NULL
|
||||||
@ -145,9 +145,15 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<!-- 根据耳号查询羊只信息 -->
|
|
||||||
<select id="selectSheepByManageTags" parameterType="String" resultType="map">
|
<select id="selectSheepByManageTags" parameterType="String" resultType="map">
|
||||||
select bs_manage_tags, variety, parity, month_age, sheepfold_name, dr_ranch
|
select
|
||||||
|
bs_manage_tags,
|
||||||
|
variety,
|
||||||
|
parity,
|
||||||
|
month_age,
|
||||||
|
sheepfold_name,
|
||||||
|
dr_ranch,
|
||||||
|
gender
|
||||||
from sheep_file
|
from sheep_file
|
||||||
where bs_manage_tags = #{manageTags}
|
where bs_manage_tags = #{manageTags}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@ -4,10 +4,10 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.zhyc.module.produce.breed.mapper.RawSpermRecordMapper">
|
<mapper namespace="com.zhyc.module.produce.breed.mapper.RawSpermRecordMapper">
|
||||||
|
|
||||||
<resultMap type="RawSpermRecord" id="RawSpermRecordResult">
|
<resultMap type="com.zhyc.module.produce.breed.domain.RawSpermRecord" id="RawSpermRecordResult">
|
||||||
<result property="id" column="id" />
|
<result property="id" column="id" />
|
||||||
<result property="sheepId" column="sheep_id" />
|
<result property="sheepId" column="sheep_id" />
|
||||||
<result property="manageTags" column="bs_manage_tags" />
|
<result property="manageTags" column="manage_tags" />
|
||||||
<result property="electronicTags" column="electronic_tags" />
|
<result property="electronicTags" column="electronic_tags" />
|
||||||
<result property="monthAge" column="month_age" />
|
<result property="monthAge" column="month_age" />
|
||||||
<result property="pickDate" column="pick_date" />
|
<result property="pickDate" column="pick_date" />
|
||||||
@ -19,95 +19,95 @@
|
|||||||
<result property="info" column="info" />
|
<result property="info" column="info" />
|
||||||
<result property="technician" column="technician" />
|
<result property="technician" column="technician" />
|
||||||
<result property="comment" column="comment" />
|
<result property="comment" column="comment" />
|
||||||
|
<result property="scrotumCircumference" column="scrotum_circumference" />
|
||||||
|
<result property="semenQuality" column="semen_quality" />
|
||||||
<result property="createBy" column="create_by" />
|
<result property="createBy" column="create_by" />
|
||||||
<result property="createTime" column="create_time" />
|
<result property="createTime" column="create_time" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectRawSpermRecordVo">
|
<sql id="selectRawSpermRecordVo">
|
||||||
select
|
select id, sheep_id, manage_tags, electronic_tags, month_age, pick_date, amount,
|
||||||
rsr.id,
|
density, vitallity, controlled, sexual_status, info, technician, comment,
|
||||||
rsr.sheep_id,
|
scrotum_circumference, semen_quality, create_by, create_time
|
||||||
sf.bs_manage_tags,
|
from raw_sperm_record
|
||||||
sf.electronic_tags,
|
|
||||||
sf.month_age,
|
|
||||||
rsr.pick_date,
|
|
||||||
rsr.amount,
|
|
||||||
rsr.density,
|
|
||||||
rsr.vitallity,
|
|
||||||
rsr.controlled,
|
|
||||||
rsr.sexual_status,
|
|
||||||
rsr.info,
|
|
||||||
rsr.technician,
|
|
||||||
rsr.comment,
|
|
||||||
rsr.create_by,
|
|
||||||
rsr.create_time
|
|
||||||
from raw_sperm_record rsr
|
|
||||||
left join sheep_file sf on rsr.sheep_id = sf.id
|
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectRawSpermRecordList" parameterType="RawSpermRecord" resultMap="RawSpermRecordResult">
|
<select id="selectRawSpermRecordList" parameterType="com.zhyc.module.produce.breed.domain.RawSpermRecord" resultMap="RawSpermRecordResult">
|
||||||
<include refid="selectRawSpermRecordVo"/>
|
<include refid="selectRawSpermRecordVo"/>
|
||||||
<where>
|
<where>
|
||||||
<if test="manageTags != null and manageTags != ''"> and sf.bs_manage_tags like concat('%', #{manageTags}, '%')</if>
|
<if test="sheepId != null "> and sheep_id = #{sheepId}</if>
|
||||||
<if test="pickDate != null "> and rsr.pick_date = #{pickDate}</if>
|
<if test="manageTags != null and manageTags != ''"> and manage_tags like concat('%', #{manageTags}, '%')</if>
|
||||||
<if test="amount != null "> and rsr.amount = #{amount}</if>
|
<if test="electronicTags != null and electronicTags != ''"> and electronic_tags like concat('%', #{electronicTags}, '%')</if>
|
||||||
<if test="density != null and density != ''"> and rsr.density = #{density}</if>
|
<if test="monthAge != null "> and month_age = #{monthAge}</if>
|
||||||
<if test="vitallity != null and vitallity != ''"> and rsr.vitallity = #{vitallity}</if>
|
<if test="pickDate != null "> and DATE(pick_date) = DATE(#{pickDate})</if>
|
||||||
<if test="controlled != null "> and rsr.controlled = #{controlled}</if>
|
<if test="amount != null "> and amount = #{amount}</if>
|
||||||
<if test="sexualStatus != null and sexualStatus != ''"> and rsr.sexual_status = #{sexualStatus}</if>
|
<if test="density != null and density != ''"> and density like concat('%', #{density}, '%')</if>
|
||||||
<if test="info != null and info != ''"> and rsr.info = #{info}</if>
|
<if test="vitallity != null and vitallity != ''"> and vitallity like concat('%', #{vitallity}, '%')</if>
|
||||||
<if test="technician != null and technician != ''"> and rsr.technician = #{technician}</if>
|
<if test="controlled != null "> and controlled = #{controlled}</if>
|
||||||
<if test="comment != null and comment != ''"> and rsr.comment = #{comment}</if>
|
<if test="sexualStatus != null and sexualStatus != ''"> and sexual_status like concat('%', #{sexualStatus}, '%')</if>
|
||||||
|
<if test="info != null and info != ''"> and info like concat('%', #{info}, '%')</if>
|
||||||
|
<if test="technician != null and technician != ''"> and technician like concat('%', #{technician}, '%')</if>
|
||||||
|
<if test="comment != null and comment != ''"> and comment like concat('%', #{comment}, '%')</if>
|
||||||
|
<if test="scrotumCircumference != null "> and scrotum_circumference = #{scrotumCircumference}</if>
|
||||||
|
<if test="semenQuality != null and semenQuality != ''"> and semen_quality = #{semenQuality}</if>
|
||||||
</where>
|
</where>
|
||||||
order by rsr.pick_date desc
|
order by pick_date desc, id desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectRawSpermRecordById" parameterType="Long" resultMap="RawSpermRecordResult">
|
<select id="selectRawSpermRecordById" parameterType="Long" resultMap="RawSpermRecordResult">
|
||||||
<include refid="selectRawSpermRecordVo"/>
|
<include refid="selectRawSpermRecordVo"/>
|
||||||
where rsr.id = #{id}
|
where id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 根据耳号查询羊只ID -->
|
<insert id="insertRawSpermRecord" parameterType="com.zhyc.module.produce.breed.domain.RawSpermRecord" useGeneratedKeys="true" keyProperty="id">
|
||||||
<select id="selectSheepIdByManageTags" parameterType="String" resultType="Long">
|
|
||||||
select id from sheep_file where bs_manage_tags = #{manageTags}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<insert id="insertRawSpermRecord" parameterType="RawSpermRecord" useGeneratedKeys="true" keyProperty="id">
|
|
||||||
insert into raw_sperm_record
|
insert into raw_sperm_record
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="sheepId != null">sheep_id,</if>
|
<if test="sheepId != null">sheep_id,</if>
|
||||||
|
<if test="manageTags != null and manageTags != ''">manage_tags,</if>
|
||||||
|
<if test="electronicTags != null and electronicTags != ''">electronic_tags,</if>
|
||||||
|
<if test="monthAge != null">month_age,</if>
|
||||||
<if test="pickDate != null">pick_date,</if>
|
<if test="pickDate != null">pick_date,</if>
|
||||||
<if test="amount != null">amount,</if>
|
<if test="amount != null">amount,</if>
|
||||||
<if test="density != null">density,</if>
|
<if test="density != null and density != ''">density,</if>
|
||||||
<if test="vitallity != null">vitallity,</if>
|
<if test="vitallity != null and vitallity != ''">vitallity,</if>
|
||||||
<if test="controlled != null">controlled,</if>
|
<if test="controlled != null">controlled,</if>
|
||||||
<if test="sexualStatus != null">sexual_status,</if>
|
<if test="sexualStatus != null and sexualStatus != ''">sexual_status,</if>
|
||||||
<if test="info != null">info,</if>
|
<if test="info != null and info != ''">info,</if>
|
||||||
<if test="technician != null">technician,</if>
|
<if test="technician != null and technician != ''">technician,</if>
|
||||||
<if test="comment != null">comment,</if>
|
<if test="comment != null and comment != ''">comment,</if>
|
||||||
<if test="createBy != null">create_by,</if>
|
<if test="scrotumCircumference != null">scrotum_circumference,</if>
|
||||||
|
<if test="semenQuality != null and semenQuality != ''">semen_quality,</if>
|
||||||
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
<if test="createTime != null">create_time,</if>
|
<if test="createTime != null">create_time,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="sheepId != null">#{sheepId},</if>
|
<if test="sheepId != null">#{sheepId},</if>
|
||||||
|
<if test="manageTags != null and manageTags != ''">#{manageTags},</if>
|
||||||
|
<if test="electronicTags != null and electronicTags != ''">#{electronicTags},</if>
|
||||||
|
<if test="monthAge != null">#{monthAge},</if>
|
||||||
<if test="pickDate != null">#{pickDate},</if>
|
<if test="pickDate != null">#{pickDate},</if>
|
||||||
<if test="amount != null">#{amount},</if>
|
<if test="amount != null">#{amount},</if>
|
||||||
<if test="density != null">#{density},</if>
|
<if test="density != null and density != ''">#{density},</if>
|
||||||
<if test="vitallity != null">#{vitallity},</if>
|
<if test="vitallity != null and vitallity != ''">#{vitallity},</if>
|
||||||
<if test="controlled != null">#{controlled},</if>
|
<if test="controlled != null">#{controlled},</if>
|
||||||
<if test="sexualStatus != null">#{sexualStatus},</if>
|
<if test="sexualStatus != null and sexualStatus != ''">#{sexualStatus},</if>
|
||||||
<if test="info != null">#{info},</if>
|
<if test="info != null and info != ''">#{info},</if>
|
||||||
<if test="technician != null">#{technician},</if>
|
<if test="technician != null and technician != ''">#{technician},</if>
|
||||||
<if test="comment != null">#{comment},</if>
|
<if test="comment != null and comment != ''">#{comment},</if>
|
||||||
<if test="createBy != null">#{createBy},</if>
|
<if test="scrotumCircumference != null">#{scrotumCircumference},</if>
|
||||||
|
<if test="semenQuality != null and semenQuality != ''">#{semenQuality},</if>
|
||||||
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||||
<if test="createTime != null">#{createTime},</if>
|
<if test="createTime != null">#{createTime},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateRawSpermRecord" parameterType="RawSpermRecord">
|
<update id="updateRawSpermRecord" parameterType="com.zhyc.module.produce.breed.domain.RawSpermRecord">
|
||||||
update raw_sperm_record
|
update raw_sperm_record
|
||||||
<trim prefix="SET" suffixOverrides=",">
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
<if test="sheepId != null">sheep_id = #{sheepId},</if>
|
<if test="sheepId != null">sheep_id = #{sheepId},</if>
|
||||||
|
<if test="manageTags != null">manage_tags = #{manageTags},</if>
|
||||||
|
<if test="electronicTags != null">electronic_tags = #{electronicTags},</if>
|
||||||
|
<if test="monthAge != null">month_age = #{monthAge},</if>
|
||||||
<if test="pickDate != null">pick_date = #{pickDate},</if>
|
<if test="pickDate != null">pick_date = #{pickDate},</if>
|
||||||
<if test="amount != null">amount = #{amount},</if>
|
<if test="amount != null">amount = #{amount},</if>
|
||||||
<if test="density != null">density = #{density},</if>
|
<if test="density != null">density = #{density},</if>
|
||||||
@ -117,8 +117,8 @@
|
|||||||
<if test="info != null">info = #{info},</if>
|
<if test="info != null">info = #{info},</if>
|
||||||
<if test="technician != null">technician = #{technician},</if>
|
<if test="technician != null">technician = #{technician},</if>
|
||||||
<if test="comment != null">comment = #{comment},</if>
|
<if test="comment != null">comment = #{comment},</if>
|
||||||
<if test="createBy != null">create_by = #{createBy},</if>
|
<if test="scrotumCircumference != null">scrotum_circumference = #{scrotumCircumference},</if>
|
||||||
<if test="createTime != null">create_time = #{createTime},</if>
|
<if test="semenQuality != null">semen_quality = #{semenQuality},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
@ -133,4 +133,19 @@
|
|||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<!-- 根据耳号查询羊只ID -->
|
||||||
|
<select id="selectSheepIdByManageTags" parameterType="String" resultType="Integer">
|
||||||
|
select id from sheep_file where bs_manage_tags = #{manageTags} and is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据耳号查询羊只完整信息(包含ID和性别) -->
|
||||||
|
<select id="selectSheepInfoByManageTags" parameterType="String" resultType="java.util.Map">
|
||||||
|
select id, gender, bs_manage_tags as manageTags, electronic_tags as electronicTags,
|
||||||
|
name, variety, month_age as monthAge
|
||||||
|
from sheep_file
|
||||||
|
where bs_manage_tags = #{manageTags} and is_delete = 0
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@ -67,7 +67,7 @@
|
|||||||
ELSE NULL
|
ELSE NULL
|
||||||
END as days_after_mating
|
END as days_after_mating
|
||||||
from sc_pregnancy_record pr
|
from sc_pregnancy_record pr
|
||||||
left join sheep_file sf on pr.sheep_id = sf.id
|
INNER JOIN sheep_file sf on pr.sheep_id = sf.id
|
||||||
-- 关联配种记录表,获取最新的配种记录
|
-- 关联配种记录表,获取最新的配种记录
|
||||||
left join (
|
left join (
|
||||||
select br1.*
|
select br1.*
|
||||||
@ -85,27 +85,39 @@
|
|||||||
and mating_type.dict_type = 'breed_type' and mating_type.status = '0'
|
and mating_type.dict_type = 'breed_type' and mating_type.status = '0'
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<!-- 重写的查询列表方法 -->
|
||||||
<select id="selectScPregnancyRecordList" parameterType="ScPregnancyRecord" resultMap="ScPregnancyRecordResult">
|
<select id="selectScPregnancyRecordList" parameterType="ScPregnancyRecord" resultMap="ScPregnancyRecordResult">
|
||||||
<include refid="selectScPregnancyRecordVo"/>
|
<include refid="selectScPregnancyRecordVo"/>
|
||||||
<where>
|
<where>
|
||||||
pr.is_delete = 0
|
pr.is_delete = 0
|
||||||
|
|
||||||
|
<!-- 耳号搜索 - 支持多种匹配方式 -->
|
||||||
<if test="manageTags != null and manageTags != ''">
|
<if test="manageTags != null and manageTags != ''">
|
||||||
<choose>
|
<bind name="searchTag" value="manageTags.trim()" />
|
||||||
<when test="manageTags.contains(',')">
|
AND (
|
||||||
and sf.bs_manage_tags in
|
<!-- 精确匹配 -->
|
||||||
<foreach item="tag" collection="manageTags.split(',')" open="(" separator="," close=")">
|
sf.bs_manage_tags = #{searchTag}
|
||||||
#{tag}
|
<!-- 模糊匹配 -->
|
||||||
</foreach>
|
OR sf.bs_manage_tags LIKE CONCAT('%', #{searchTag}, '%')
|
||||||
</when>
|
<!-- 处理逗号分隔的多个耳号 -->
|
||||||
<otherwise>
|
OR FIND_IN_SET(sf.bs_manage_tags, REPLACE(#{searchTag}, ' ', '')) > 0
|
||||||
and sf.bs_manage_tags like concat('%', #{manageTags}, '%')
|
<!-- 反向匹配:输入包含数据库中的耳号 -->
|
||||||
</otherwise>
|
OR #{searchTag} LIKE CONCAT('%', sf.bs_manage_tags, '%')
|
||||||
</choose>
|
)
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="datetime != null">
|
||||||
|
AND DATE(pr.datetime) = DATE(#{datetime})
|
||||||
|
</if>
|
||||||
|
<if test="result != null and result != ''">
|
||||||
|
AND pr.result = #{result}
|
||||||
|
</if>
|
||||||
|
<if test="technician != null and technician != ''">
|
||||||
|
AND pr.technician like concat('%', #{technician}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="way != null and way != ''">
|
||||||
|
AND pr.way = #{way}
|
||||||
</if>
|
</if>
|
||||||
<if test="datetime != null "> and DATE(pr.datetime) = DATE(#{datetime})</if>
|
|
||||||
<if test="result != null and result != ''"> and pr.result = #{result}</if>
|
|
||||||
<if test="technician != null and technician != ''"> and pr.technician like concat('%', #{technician}, '%')</if>
|
|
||||||
<if test="way != null and way != ''"> and pr.way = #{way}</if>
|
|
||||||
</where>
|
</where>
|
||||||
order by pr.create_time desc
|
order by pr.create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@ -145,19 +145,19 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<!-- 更新羊只繁育状态 - 保留原有功能 -->
|
<!-- 更新羊只繁育状态 - 更新基础表 bas_sheep,使用正确的字段名 -->
|
||||||
<update id="updateSheepFileStatus">
|
<update id="updateSheepFileStatus">
|
||||||
UPDATE sheep_file
|
UPDATE bas_sheep
|
||||||
SET breed = #{status},
|
SET breed_status_id = #{status},
|
||||||
update_time = NOW()
|
update_time = NOW()
|
||||||
WHERE id = #{sheepId}
|
WHERE id = #{sheepId}
|
||||||
AND is_delete = 0
|
AND is_delete = 0
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<!-- 新增:更新羊只在群状态 -->
|
<!-- 更新羊只在群状态 - 更新基础表 bas_sheep,使用正确的字段名 -->
|
||||||
<update id="updateSheepStatus">
|
<update id="updateSheepStatus">
|
||||||
UPDATE sheep_file
|
UPDATE bas_sheep
|
||||||
SET status = #{status},
|
SET status_id = #{status},
|
||||||
update_time = NOW()
|
update_time = NOW()
|
||||||
WHERE id = #{sheepId}
|
WHERE id = #{sheepId}
|
||||||
AND is_delete = 0
|
AND is_delete = 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user