断奶录入问题,断奶查询问题,干奶录入问题,干奶查询问题,死亡录入问题,死亡查询问题

This commit is contained in:
ll
2026-02-01 21:47:56 +08:00
parent 13e0f68289
commit 464126195d
18 changed files with 628 additions and 962 deletions

View File

@@ -1,7 +1,8 @@
package com.zhyc.module.produce.breed.controller; package com.zhyc.module.produce.breed.controller;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.ArrayList;
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;
@@ -27,8 +28,7 @@ import com.zhyc.common.core.page.TableDataInfo;
/** /**
* 干奶记录Controller * 干奶记录Controller
* * * @author ruoyi
* @author ruoyi
* @date 2025-07-15 * @date 2025-07-15
*/ */
@RestController @RestController
@@ -49,24 +49,37 @@ public class ScDryMilkController extends BaseController
public TableDataInfo list(ScDryMilk scDryMilk) public TableDataInfo list(ScDryMilk scDryMilk)
{ {
try { try {
// 添加调试日志 // 兼容逻辑:如果前端传了字符串形式的耳号(如导出或老接口调用)也转为List
if (scDryMilk.getManageTags() != null && !scDryMilk.getManageTags().trim().isEmpty()) { if (scDryMilk.getManageTags() != null && !scDryMilk.getManageTags().trim().isEmpty()) {
logger.info("搜索耳号参数: [{}]", scDryMilk.getManageTags()); if (scDryMilk.getManageTagsList() == null) {
scDryMilk.setManageTags(scDryMilk.getManageTags().trim()); scDryMilk.setManageTagsList(new ArrayList<>());
}
// 支持中文逗号、英文逗号、空格分割
String[] tags = scDryMilk.getManageTags().trim().split("[,\\s]+");
scDryMilk.getManageTagsList().addAll(Arrays.asList(tags));
} }
startPage(); startPage();
List<ScDryMilk> list = scDryMilkService.selectScDryMilkList(scDryMilk); List<ScDryMilk> list = scDryMilkService.selectScDryMilkList(scDryMilk);
logger.info("查询到干奶记录数量: {}", list.size());
return getDataTable(list); return getDataTable(list);
} catch (Exception e) { } catch (Exception e) {
logger.error("查询干奶记录列表失败", e); logger.error("查询干奶记录列表失败", e);
return getDataTable(new java.util.ArrayList<>()); return getDataTable(new ArrayList<>());
} }
} }
/**
* 远程搜索耳号列表
*/
@GetMapping("/searchEarNumbers")
public AjaxResult searchEarNumbers(@RequestParam(value = "query", required = false) String query)
{
if (query == null) query = "";
// 调用Service层
List<String> list = scDryMilkService.selectSheepEarNumberList(query);
return AjaxResult.success(list);
}
/** /**
* 导出干奶记录列表 * 导出干奶记录列表
*/ */
@@ -77,9 +90,9 @@ public class ScDryMilkController extends BaseController
{ {
try { try {
if (scDryMilk.getManageTags() != null) { if (scDryMilk.getManageTags() != null) {
scDryMilk.setManageTags(scDryMilk.getManageTags().trim()); String[] tags = scDryMilk.getManageTags().trim().split("[,\\s]+");
scDryMilk.setManageTagsList(Arrays.asList(tags));
} }
List<ScDryMilk> list = scDryMilkService.selectScDryMilkList(scDryMilk); List<ScDryMilk> list = scDryMilkService.selectScDryMilkList(scDryMilk);
ExcelUtil<ScDryMilk> util = new ExcelUtil<ScDryMilk>(ScDryMilk.class); ExcelUtil<ScDryMilk> util = new ExcelUtil<ScDryMilk>(ScDryMilk.class);
util.exportExcel(response, list, "干奶记录数据"); util.exportExcel(response, list, "干奶记录数据");
@@ -95,86 +108,17 @@ 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)
{ {
try { return success(scDryMilkService.selectScDryMilkById(id));
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());
}
}
/**
* 根据耳号查询羊只ID
*/
@PreAuthorize("@ss.hasPermi('drymilk:drymilk:query')")
@GetMapping(value = "/sheep/{manageTags}")
public AjaxResult getSheepIdByManageTags(@PathVariable("manageTags") String manageTags)
{
Long sheepId = scDryMilkService.selectSheepIdByManageTags(manageTags);
return success(sheepId);
}
/**
* 获取羊舍列表 - 用于嵌套选择
*/ */
@GetMapping("/sheepfoldList") @GetMapping("/sheepfoldList")
public AjaxResult getSheepfoldList(@RequestParam(value = "ranchId", required = false) Long ranchId, public AjaxResult getSheepfoldList(DaSheepfold daSheepfold)
@RequestParam(value = "sheepfoldTypeId", required = false) Long sheepfoldTypeId)
{ {
try { List<DaSheepfold> list = daSheepfoldService.selectDaSheepfoldList(daSheepfold);
DaSheepfold query = new DaSheepfold(); return success(list);
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());
}
} }
/** /**
@@ -186,43 +130,41 @@ public class ScDryMilkController extends BaseController
public AjaxResult add(@RequestBody ScDryMilk scDryMilk) public AjaxResult add(@RequestBody ScDryMilk scDryMilk)
{ {
try { try {
// 基础参数校验 if (scDryMilk == null || scDryMilk.getManageTags() == null) {
if (scDryMilk == null) {
return error("请求参数不能为空");
}
if (scDryMilk.getManageTags() == null || scDryMilk.getManageTags().trim().isEmpty()) {
return error("耳号不能为空"); return error("耳号不能为空");
} }
if (scDryMilk.getDatetime() == null) { // 批量解析耳号
return error("干奶日期不能为空"); String[] tags = scDryMilk.getManageTags().trim().split("[\\s,\n]+");
int successCount = 0;
StringBuilder errorMsg = new StringBuilder();
for (String tag : tags) {
if (tag.isEmpty()) continue;
Long sheepId = scDryMilkService.selectSheepIdByManageTags(tag);
if (sheepId == null) {
errorMsg.append(tag).append("不存在; ");
continue;
} }
if (scDryMilk.getStatus() == null) { ScDryMilk newItem = new ScDryMilk();
return error("请选择是否使用乳头封闭剂"); newItem.setSheepId(String.valueOf(sheepId));
newItem.setDatetime(scDryMilk.getDatetime());
newItem.setStatus(scDryMilk.getStatus());
newItem.setSheepfold(scDryMilk.getSheepfold());
newItem.setTecahnician(scDryMilk.getTecahnician());
newItem.setComment(scDryMilk.getComment());
newItem.setCreateBy(getUsername());
scDryMilkService.insertScDryMilk(newItem);
successCount++;
} }
// 清理输入参数 if (errorMsg.length() > 0) {
scDryMilk.setManageTags(scDryMilk.getManageTags().trim()); return warn("成功录入 " + successCount + " 条。失败详情:" + errorMsg.toString());
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("新增失败");
} }
return success("成功录入 " + successCount + " 条记录");
} catch (Exception e) { } catch (Exception e) {
logger.error("新增干奶记录失败", e); logger.error("新增干奶记录失败", e);
return error("新增失败: " + e.getMessage()); return error("新增失败: " + e.getMessage());
@@ -237,39 +179,7 @@ public class ScDryMilkController extends BaseController
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody ScDryMilk scDryMilk) public AjaxResult edit(@RequestBody ScDryMilk scDryMilk)
{ {
try { return toAjax(scDryMilkService.updateScDryMilk(scDryMilk));
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());
}
} }
/** /**
@@ -280,23 +190,6 @@ public class ScDryMilkController extends BaseController
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) public AjaxResult remove(@PathVariable Long[] ids)
{ {
try { return toAjax(scDryMilkService.deleteScDryMilkByIds(ids));
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());
}
} }
} }

View File

@@ -12,12 +12,12 @@ 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;
import com.zhyc.common.core.domain.AjaxResult; import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType; import com.zhyc.common.enums.BusinessType;
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.service.ISwDiseaseService;
@@ -48,19 +48,35 @@ public class ScSheepDeathController extends BaseController
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(ScSheepDeath scSheepDeath) public TableDataInfo list(ScSheepDeath scSheepDeath)
{ {
try {
startPage(); startPage();
List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath);
return getDataTable(list); return getDataTable(list);
} catch (Exception e) {
logger.error("查询羊只死淘记录列表失败", e);
return getDataTable(new java.util.ArrayList<>());
}
} }
/** /**
* 根据管理耳号查询羊只信息 * 搜索管理耳号(用于下拉提示)
*/ */
@GetMapping("/search/earNo")
public AjaxResult searchEarNo(@RequestParam("query") String query) {
return success(scSheepDeathService.selectDistinctManageTags(query == null ? "" : query));
}
/**
* 搜索技术员(用于下拉提示)
*/
@GetMapping("/search/technician")
public AjaxResult searchTechnician(@RequestParam("query") String query) {
return success(scSheepDeathService.selectDistinctTechnician(query == null ? "" : query));
}
/**
* 搜索处理人(用于下拉提示)
*/
@GetMapping("/search/handler")
public AjaxResult searchHandler(@RequestParam("query") String query) {
return success(scSheepDeathService.selectDistinctHandler(query == null ? "" : query));
}
@PreAuthorize("@ss.hasPermi('sheep_death:death:query')") @PreAuthorize("@ss.hasPermi('sheep_death:death:query')")
@GetMapping("/sheepInfo/{manageTags}") @GetMapping("/sheepInfo/{manageTags}")
public AjaxResult getSheepInfo(@PathVariable("manageTags") String manageTags) public AjaxResult getSheepInfo(@PathVariable("manageTags") String manageTags)
@@ -69,7 +85,6 @@ public class ScSheepDeathController extends BaseController
if (manageTags == null || manageTags.trim().isEmpty()) { if (manageTags == null || manageTags.trim().isEmpty()) {
return error("管理耳号不能为空"); return error("管理耳号不能为空");
} }
Map<String, Object> sheepInfo = scSheepDeathService.selectSheepFileByManageTags(manageTags.trim()); Map<String, Object> sheepInfo = scSheepDeathService.selectSheepFileByManageTags(manageTags.trim());
if (sheepInfo != null) { if (sheepInfo != null) {
return success(sheepInfo); return success(sheepInfo);
@@ -77,172 +92,63 @@ public class ScSheepDeathController extends BaseController
return error("未找到该耳号对应的羊只信息"); return error("未找到该耳号对应的羊只信息");
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("查询羊只信息失败,管理耳号: " + manageTags, e);
return error("查询羊只信息失败: " + e.getMessage()); return error("查询羊只信息失败: " + e.getMessage());
} }
} }
/**
* 获取疾病树形列表
*/
@PreAuthorize("@ss.hasPermi('sheep_death:death:query')") @PreAuthorize("@ss.hasPermi('sheep_death:death:query')")
@GetMapping("/disease/tree") @GetMapping("/disease/tree")
public AjaxResult getDiseaseTree() public AjaxResult getDiseaseTree()
{ {
try {
List<SwDisease> diseaseList = swDiseaseService.selectSwDiseaseList(new SwDisease()); List<SwDisease> diseaseList = swDiseaseService.selectSwDiseaseList(new SwDisease());
return success(diseaseList); return success(diseaseList);
} catch (Exception e) {
logger.error("获取疾病树形列表失败", e);
return error("获取疾病列表失败: " + e.getMessage());
}
} }
/**
* 导出羊只死淘记录列表
*/
@PreAuthorize("@ss.hasPermi('sheep_death:death:export')") @PreAuthorize("@ss.hasPermi('sheep_death:death:export')")
@Log(title = "羊只死淘记录", businessType = BusinessType.EXPORT) @Log(title = "羊只死淘记录", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, ScSheepDeath scSheepDeath) public void export(HttpServletResponse response, ScSheepDeath scSheepDeath)
{ {
try {
List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath);
ExcelUtil<ScSheepDeath> util = new ExcelUtil<ScSheepDeath>(ScSheepDeath.class); ExcelUtil<ScSheepDeath> util = new ExcelUtil<ScSheepDeath>(ScSheepDeath.class);
util.exportExcel(response, list, "羊只死淘记录数据"); util.exportExcel(response, list, "羊只死淘记录数据");
} catch (Exception e) {
logger.error("导出羊只死淘记录失败", e);
// 可以在这里返回错误响应
}
} }
/**
* 获取羊只死淘记录详细信息
*/
@PreAuthorize("@ss.hasPermi('sheep_death:death:query')") @PreAuthorize("@ss.hasPermi('sheep_death:death:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) public AjaxResult getInfo(@PathVariable("id") Long id)
{ {
try { return success(scSheepDeathService.selectScSheepDeathById(id));
if (id == null) {
return error("记录ID不能为空");
} }
ScSheepDeath result = scSheepDeathService.selectScSheepDeathById(id);
if (result == null) {
return error("记录不存在");
}
return success(result);
} catch (Exception e) {
logger.error("获取羊只死淘记录详细信息失败ID: " + id, e);
return error("获取记录详细信息失败: " + e.getMessage());
}
}
/**
* 新增羊只死淘记录
*/
@PreAuthorize("@ss.hasPermi('sheep_death:death:add')") @PreAuthorize("@ss.hasPermi('sheep_death:death:add')")
@Log(title = "羊只死淘记录", businessType = BusinessType.INSERT) @Log(title = "羊只死淘记录", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody ScSheepDeath scSheepDeath) public AjaxResult add(@RequestBody ScSheepDeath scSheepDeath)
{ {
try { try {
// 基础参数校验 if (scSheepDeath == null || scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) {
if (scSheepDeath == null) {
return error("请求参数不能为空");
}
if (scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) {
return error("管理耳号不能为空"); return error("管理耳号不能为空");
} }
return toAjax(scSheepDeathService.insertScSheepDeath(scSheepDeath));
if (scSheepDeath.getDeathDate() == null) {
return error("死淘日期不能为空");
}
int result = scSheepDeathService.insertScSheepDeath(scSheepDeath);
if (result > 0) {
return success("新增成功");
} else {
return error("新增失败");
}
} catch (ServiceException e) {
logger.warn("新增羊只死淘记录业务异常: " + e.getMessage());
return error(e.getMessage());
} catch (Exception e) { } catch (Exception e) {
logger.error("新增羊只死淘记录失败", e);
return error("新增失败: " + e.getMessage()); return error("新增失败: " + e.getMessage());
} }
} }
/**
* 修改羊只死淘记录
*/
@PreAuthorize("@ss.hasPermi('sheep_death:death:edit')") @PreAuthorize("@ss.hasPermi('sheep_death:death:edit')")
@Log(title = "羊只死淘记录", businessType = BusinessType.UPDATE) @Log(title = "羊只死淘记录", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody ScSheepDeath scSheepDeath) public AjaxResult edit(@RequestBody ScSheepDeath scSheepDeath)
{ {
try { return toAjax(scSheepDeathService.updateScSheepDeath(scSheepDeath));
// 基础参数校验
if (scSheepDeath == null) {
return error("请求参数不能为空");
} }
if (scSheepDeath.getId() == null) {
return error("记录ID不能为空");
}
if (scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) {
return error("管理耳号不能为空");
}
if (scSheepDeath.getDeathDate() == null) {
return error("死淘日期不能为空");
}
int result = scSheepDeathService.updateScSheepDeath(scSheepDeath);
if (result > 0) {
return success("修改成功");
} else {
return error("修改失败,记录可能不存在");
}
} catch (ServiceException e) {
logger.warn("修改羊只死淘记录业务异常: " + e.getMessage());
return error(e.getMessage());
} catch (Exception e) {
logger.error("修改羊只死淘记录失败", e);
return error("修改失败: " + e.getMessage());
}
}
/**
* 删除羊只死淘记录
*/
@PreAuthorize("@ss.hasPermi('sheep_death:death:remove')") @PreAuthorize("@ss.hasPermi('sheep_death:death:remove')")
@Log(title = "羊只死淘记录", businessType = BusinessType.DELETE) @Log(title = "羊只死淘记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) public AjaxResult remove(@PathVariable Long[] ids)
{ {
try { return toAjax(scSheepDeathService.deleteScSheepDeathByIds(ids));
if (ids == null || ids.length == 0) {
return error("删除的记录ID不能为空");
}
int result = scSheepDeathService.deleteScSheepDeathByIds(ids);
if (result > 0) {
return success("删除成功");
} else {
return error("删除失败,记录可能不存在");
}
} catch (ServiceException e) {
logger.warn("删除羊只死淘记录业务异常: " + e.getMessage());
return error(e.getMessage());
} catch (Exception e) {
logger.error("删除羊只死淘记录失败", e);
return error("删除失败: " + e.getMessage());
}
} }
} }

View File

@@ -3,17 +3,11 @@ package com.zhyc.module.produce.breed.controller;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.zhyc.common.utils.StringUtils;
import com.zhyc.module.produce.breed.domain.ScWeanRecord; import com.zhyc.module.produce.breed.domain.ScWeanRecord;
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;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhyc.common.annotation.Log; import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController; import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult; import com.zhyc.common.core.domain.AjaxResult;
@@ -24,9 +18,6 @@ import com.zhyc.common.core.page.TableDataInfo;
/** /**
* 断奶记录Controller * 断奶记录Controller
*
* @author zhyc
* @date 2024-01-01
*/ */
@RestController @RestController
@RequestMapping("/Weaning/weaning_record") @RequestMapping("/Weaning/weaning_record")
@@ -45,6 +36,16 @@ public class ScWeanRecordController extends BaseController {
return getDataTable(list); return getDataTable(list);
} }
/**
* 【新增】模糊查询耳号列表 (用于前端下拉框远程搜索)
*/
@PreAuthorize("@ss.hasPermi('Weaning:weaning_record:list')")
@GetMapping("/search_ear_numbers")
public AjaxResult searchEarNumbers(@RequestParam("query") String query) {
List<String> list = scWeanRecordService.searchEarNumbers(query);
return success(list);
}
/** /**
* 导出断奶记录列表 * 导出断奶记录列表
*/ */
@@ -87,7 +88,6 @@ public class ScWeanRecordController extends BaseController {
@Log(title = "断奶记录", businessType = BusinessType.INSERT) @Log(title = "断奶记录", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody ScWeanRecord scWeanRecord) { public AjaxResult add(@RequestBody ScWeanRecord scWeanRecord) {
// 验证耳号是否存在
if (scWeanRecord.getEarNumber() != null) { if (scWeanRecord.getEarNumber() != null) {
Long sheepId = scWeanRecordService.selectSheepIdByEarNumber(scWeanRecord.getEarNumber()); Long sheepId = scWeanRecordService.selectSheepIdByEarNumber(scWeanRecord.getEarNumber());
if (sheepId == null) { if (sheepId == null) {
@@ -95,20 +95,10 @@ public class ScWeanRecordController extends BaseController {
} }
scWeanRecord.setSheepId(sheepId); scWeanRecord.setSheepId(sheepId);
} }
if (scWeanRecord.getSheepId() == null) return error("羊只信息不能为空");
// 验证必要字段 if (scWeanRecord.getDatetime() == null) return error("断奶日期不能为空");
if (scWeanRecord.getSheepId() == null) { if (scWeanRecord.getWeight() == null) return error("断奶重量不能为空");
return error("羊只信息不能为空"); if (scWeanRecord.getStatus() == null) return error("是否留养不能为空");
}
if (scWeanRecord.getDatetime() == null) {
return error("断奶日期不能为空");
}
if (scWeanRecord.getWeight() == null) {
return error("断奶重量不能为空");
}
if (scWeanRecord.getStatus() == null) {
return error("是否留养不能为空");
}
scWeanRecord.setCreateBy(getUsername()); scWeanRecord.setCreateBy(getUsername());
return toAjax(scWeanRecordService.insertScWeanRecord(scWeanRecord)); return toAjax(scWeanRecordService.insertScWeanRecord(scWeanRecord));
@@ -121,32 +111,11 @@ public class ScWeanRecordController extends BaseController {
@Log(title = "断奶记录", businessType = BusinessType.UPDATE) @Log(title = "断奶记录", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody ScWeanRecord scWeanRecord) { public AjaxResult edit(@RequestBody ScWeanRecord scWeanRecord) {
// 验证耳号是否存在
if (scWeanRecord.getEarNumber() != null) { if (scWeanRecord.getEarNumber() != null) {
Long sheepId = scWeanRecordService.selectSheepIdByEarNumber(scWeanRecord.getEarNumber()); Long sheepId = scWeanRecordService.selectSheepIdByEarNumber(scWeanRecord.getEarNumber());
if (sheepId == null) { if (sheepId == null) return error("耳号不存在");
return error("耳号不存在,请检查后重新输入");
}
scWeanRecord.setSheepId(sheepId); scWeanRecord.setSheepId(sheepId);
} }
// 验证必要字段
if (scWeanRecord.getId() == null) {
return error("记录ID不能为空");
}
if (scWeanRecord.getSheepId() == null) {
return error("羊只信息不能为空");
}
if (scWeanRecord.getDatetime() == null) {
return error("断奶日期不能为空");
}
if (scWeanRecord.getWeight() == null) {
return error("断奶重量不能为空");
}
if (scWeanRecord.getStatus() == null) {
return error("是否留养不能为空");
}
return toAjax(scWeanRecordService.updateScWeanRecord(scWeanRecord)); return toAjax(scWeanRecordService.updateScWeanRecord(scWeanRecord));
} }

View File

@@ -1,6 +1,7 @@
package com.zhyc.module.produce.breed.domain; package com.zhyc.module.produce.breed.domain;
import java.util.Date; import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@@ -33,8 +34,8 @@ public class ScDryMilk extends BaseEntity
@Excel(name = "干奶日期", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "干奶日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date datetime; private Date datetime;
/** 是否使用乳头封闭剂 */ /** 是否使用乳头封闭剂 (1:是 0:否) */
@Excel(name = "是否使用乳头封闭剂") @Excel(name = "是否使用乳头封闭剂", readConverterExp = "0=否,1=是")
private Long status; private Long status;
/** 转入羊舍id */ /** 转入羊舍id */
@@ -49,12 +50,15 @@ public class ScDryMilk extends BaseEntity
@Excel(name = "备注") @Excel(name = "备注")
private String comment; private String comment;
// 以下为联表查询字段不存储在sc_dry_milk表中 // --- 联表查询字段 ---
/** 管理耳号 */ /** 管理耳号 (单个) */
@Excel(name = "耳号") @Excel(name = "耳号")
private String manageTags; private String manageTags;
/** 多耳号查询列表 (核心修改:用于接收前端多选的数组) */
private List<String> manageTagsList;
/** 品种 */ /** 品种 */
@Excel(name = "品种") @Excel(name = "品种")
private String variety; private String variety;
@@ -66,6 +70,4 @@ public class ScDryMilk extends BaseEntity
/** 事件类型 */ /** 事件类型 */
@Excel(name = "事件类型") @Excel(name = "事件类型")
private String eventType; private String eventType;
} }

View File

@@ -1,6 +1,7 @@
package com.zhyc.module.produce.breed.domain; package com.zhyc.module.produce.breed.domain;
import java.util.Date; import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
@@ -69,26 +70,34 @@ public class ScSheepDeath extends BaseEntity
@Excel(name = "是否删除(0:未删除 1:已删除)") @Excel(name = "是否删除(0:未删除 1:已删除)")
private Long isDelete; private Long isDelete;
// 以下字段仅用于前端显示,不存储到数据库 // --- 扩展字段 ---
/** 品种 */
/** 品种 (查询显示用) */
@Excel(name = "品种")
private String variety; private String variety;
/** 死亡时羊只类别 */ /** 羊只类型 (原事假类型改为羊只类型查询) */
@Excel(name = "羊只类型")
private String sheepType; private String sheepType;
/** 性别 */ /** 性别 */
@Excel(name = "性别", readConverterExp = "1=母,2=公")
private Integer gender; private Integer gender;
/** 日龄 */ /** 日龄 */
@Excel(name = "日龄")
private Long dayAge; private Long dayAge;
/** 胎次 */ /** 胎次 */
@Excel(name = "胎次")
private Integer parity; private Integer parity;
/** 羊舍 */ /** 羊舍 */
@Excel(name = "羊舍")
private String sheepfoldName; private String sheepfoldName;
/** 繁育状态 */ /** 繁育状态 */
@Excel(name = "繁育状态")
private String breedStatus; private String breedStatus;
/** 死亡时产后天数 */ /** 死亡时产后天数 */
@@ -100,257 +109,124 @@ public class ScSheepDeath extends BaseEntity
/** 死亡时怀孕天数 */ /** 死亡时怀孕天数 */
private Integer gestationDay; private Integer gestationDay;
public void setId(Long id) // 疾病名称
{ private String diseaseTypeName;
this.id = id; private String diseaseSubtypeName;
}
public Long getId() // --- 多选查询条件 ---
{
return id;
}
public void setSheepId(Long sheepId) /** 多选管理耳号列表 */
{ private List<String> manageTagsList;
this.sheepId = sheepId;
}
public Long getSheepId() /** 多选羊只类型列表 */
{ private List<String> sheepTypeList;
return sheepId;
}
public void setManageTags(String manageTags) /** 多选技术员列表 */
{ private List<String> technicianList;
this.manageTags = manageTags;
}
public String getManageTags() /** 多选处理人列表 */
{ private List<String> handlerList;
return manageTags;
}
public void setEventType(String eventType) /** 多选班组列表 */
{ private List<String> workGroupList;
this.eventType = eventType;
}
public String getEventType() // Getter & Setter
{ public void setId(Long id) { this.id = id; }
return eventType; public Long getId() { return id; }
}
public void setDeathDate(Date deathDate) public void setSheepId(Long sheepId) { this.sheepId = sheepId; }
{ public Long getSheepId() { return sheepId; }
this.deathDate = deathDate;
}
public Date getDeathDate() public void setManageTags(String manageTags) { this.manageTags = manageTags; }
{ public String getManageTags() { return manageTags; }
return deathDate;
}
public void setDiseaseTypeId(Long diseaseTypeId) public void setEventType(String eventType) { this.eventType = eventType; }
{ public String getEventType() { return eventType; }
this.diseaseTypeId = diseaseTypeId;
}
public Long getDiseaseTypeId() public void setDeathDate(Date deathDate) { this.deathDate = deathDate; }
{ public Date getDeathDate() { return deathDate; }
return diseaseTypeId;
}
public void setDiseaseSubtypeId(Long diseaseSubtypeId) public void setDiseaseTypeId(Long diseaseTypeId) { this.diseaseTypeId = diseaseTypeId; }
{ public Long getDiseaseTypeId() { return diseaseTypeId; }
this.diseaseSubtypeId = diseaseSubtypeId;
}
public Long getDiseaseSubtypeId() public void setDiseaseSubtypeId(Long diseaseSubtypeId) { this.diseaseSubtypeId = diseaseSubtypeId; }
{ public Long getDiseaseSubtypeId() { return diseaseSubtypeId; }
return diseaseSubtypeId;
}
public void setDisposalDirection(String disposalDirection) public void setDisposalDirection(String disposalDirection) { this.disposalDirection = disposalDirection; }
{ public String getDisposalDirection() { return disposalDirection; }
this.disposalDirection = disposalDirection;
}
public String getDisposalDirection() public void setTechnician(String technician) { this.technician = technician; }
{ public String getTechnician() { return technician; }
return disposalDirection;
}
public void setTechnician(String technician) public void setHandler(String handler) { this.handler = handler; }
{ public String getHandler() { return handler; }
this.technician = technician;
}
public String getTechnician() public void setWorkGroup(String workGroup) { this.workGroup = workGroup; }
{ public String getWorkGroup() { return workGroup; }
return technician;
}
public void setHandler(String handler) public void setComment(String comment) { this.comment = comment; }
{ public String getComment() { return comment; }
this.handler = handler;
}
public String getHandler() public void setIsDelete(Long isDelete) { this.isDelete = isDelete; }
{ public Long getIsDelete() { return isDelete; }
return handler;
}
public void setWorkGroup(String workGroup) public void setVariety(String variety) { this.variety = variety; }
{ public String getVariety() { return variety; }
this.workGroup = workGroup;
}
public String getWorkGroup() public void setSheepType(String sheepType) { this.sheepType = sheepType; }
{ public String getSheepType() { return sheepType; }
return workGroup;
}
public void setComment(String comment) public void setGender(Integer gender) { this.gender = gender; }
{ public Integer getGender() { return gender; }
this.comment = comment;
}
public String getComment() public void setDayAge(Long dayAge) { this.dayAge = dayAge; }
{ public Long getDayAge() { return dayAge; }
return comment;
}
public void setIsDelete(Long isDelete) public void setParity(Integer parity) { this.parity = parity; }
{ public Integer getParity() { return parity; }
this.isDelete = isDelete;
}
public Long getIsDelete() public void setSheepfoldName(String sheepfoldName) { this.sheepfoldName = sheepfoldName; }
{ public String getSheepfoldName() { return sheepfoldName; }
return isDelete;
}
// 以下为仅用于显示的字段的getter/setter public void setBreedStatus(String breedStatus) { this.breedStatus = breedStatus; }
public void setVariety(String variety) public String getBreedStatus() { return breedStatus; }
{
this.variety = variety;
}
public String getVariety() public void setPostLambingDay(Integer postLambingDay) { this.postLambingDay = postLambingDay; }
{ public Integer getPostLambingDay() { return postLambingDay; }
return variety;
}
public void setSheepType(String sheepType) public void setLactationDay(Integer lactationDay) { this.lactationDay = lactationDay; }
{ public Integer getLactationDay() { return lactationDay; }
this.sheepType = sheepType;
}
public String getSheepType() public void setGestationDay(Integer gestationDay) { this.gestationDay = gestationDay; }
{ public Integer getGestationDay() { return gestationDay; }
return sheepType;
}
public void setGender(Integer gender) public String getDiseaseTypeName() { return diseaseTypeName; }
{ public void setDiseaseTypeName(String diseaseTypeName) { this.diseaseTypeName = diseaseTypeName; }
this.gender = gender;
}
public Integer getGender() public String getDiseaseSubtypeName() { return diseaseSubtypeName; }
{ public void setDiseaseSubtypeName(String diseaseSubtypeName) { this.diseaseSubtypeName = diseaseSubtypeName; }
return gender;
}
public void setDayAge(Long dayAge) public List<String> getManageTagsList() { return manageTagsList; }
{ public void setManageTagsList(List<String> manageTagsList) { this.manageTagsList = manageTagsList; }
this.dayAge = dayAge;
}
public Long getDayAge() public List<String> getSheepTypeList() { return sheepTypeList; }
{ public void setSheepTypeList(List<String> sheepTypeList) { this.sheepTypeList = sheepTypeList; }
return dayAge;
}
public void setParity(Integer parity) public List<String> getTechnicianList() { return technicianList; }
{ public void setTechnicianList(List<String> technicianList) { this.technicianList = technicianList; }
this.parity = parity;
}
public Integer getParity() public List<String> getHandlerList() { return handlerList; }
{ public void setHandlerList(List<String> handlerList) { this.handlerList = handlerList; }
return parity;
}
public void setSheepfoldName(String sheepfoldName) public List<String> getWorkGroupList() { return workGroupList; }
{ public void setWorkGroupList(List<String> workGroupList) { this.workGroupList = workGroupList; }
this.sheepfoldName = sheepfoldName;
}
public String getSheepfoldName()
{
return sheepfoldName;
}
public void setBreedStatus(String breedStatus)
{
this.breedStatus = breedStatus;
}
public String getBreedStatus()
{
return breedStatus;
}
public void setPostLambingDay(Integer postLambingDay)
{
this.postLambingDay = postLambingDay;
}
public Integer getPostLambingDay()
{
return postLambingDay;
}
public void setLactationDay(Integer lactationDay)
{
this.lactationDay = lactationDay;
}
public Integer getLactationDay()
{
return lactationDay;
}
public void setGestationDay(Integer gestationDay)
{
this.gestationDay = gestationDay;
}
public Integer getGestationDay()
{
return gestationDay;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId()) .append("id", getId())
.append("sheepId", getSheepId())
.append("manageTags", getManageTags()) .append("manageTags", getManageTags())
.append("eventType", getEventType())
.append("deathDate", getDeathDate()) .append("deathDate", getDeathDate())
.append("diseaseTypeId", getDiseaseTypeId())
.append("diseaseSubtypeId", getDiseaseSubtypeId())
.append("disposalDirection", getDisposalDirection())
.append("technician", getTechnician())
.append("handler", getHandler())
.append("workGroup", getWorkGroup())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("comment", getComment())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("isDelete", getIsDelete())
.toString(); .toString();
} }
} }

View File

@@ -2,6 +2,7 @@ package com.zhyc.module.produce.breed.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhyc.common.annotation.Excel; import com.zhyc.common.annotation.Excel;
import com.zhyc.common.core.domain.BaseEntity; import com.zhyc.common.core.domain.BaseEntity;
@@ -11,9 +12,6 @@ import lombok.NoArgsConstructor;
/** /**
* 断奶记录对象 sc_wean_record * 断奶记录对象 sc_wean_record
*
* @author zhyc
* @date 2024-01-01
*/ */
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@@ -53,46 +51,46 @@ public class ScWeanRecord extends BaseEntity {
@Excel(name = "电子耳号") @Excel(name = "电子耳号")
private String electronicTags; private String electronicTags;
// 关联查询字段 // --- 新增查询字段 ---
/** 耳号 */
/** 多耳号查询列表 */
private List<String> allEarNumbers;
/** 是否在群 (1是 0否) */
private String isInHerd;
/** 羊只类别 (对应 sheep_file 的 breed 字段) */
private String sheepCategory;
// --- 关联查询显示字段 ---
@Excel(name = "耳号") @Excel(name = "耳号")
private String earNumber; private String earNumber;
/** 品种 */
@Excel(name = "品种") @Excel(name = "品种")
private String breed; private String breed;
/** 事件类型 */
@Excel(name = "事件类型") @Excel(name = "事件类型")
private String eventType; private String eventType;
/** 性别 */
@Excel(name = "性别") @Excel(name = "性别")
private String gender; private String gender;
/** 父号 */
@Excel(name = "父号") @Excel(name = "父号")
private String fatherNumber; private String fatherNumber;
/** 母号 */
@Excel(name = "母号") @Excel(name = "母号")
private String motherNumber; private String motherNumber;
/** 月龄 */
@Excel(name = "月龄") @Excel(name = "月龄")
private Integer monthAge; private Integer monthAge;
/** 出生重量 */
@Excel(name = "出生重量") @Excel(name = "出生重量")
private BigDecimal birthWeight; private BigDecimal birthWeight;
/** 羊舍 */
@Excel(name = "羊舍") @Excel(name = "羊舍")
private String sheepPen; private String sheepPen;
/** 繁育状态 */
@Excel(name = "繁育状态") @Excel(name = "繁育状态")
private String breedingStatus; private String breedingStatus;
} }

View File

@@ -2,70 +2,66 @@ package com.zhyc.module.produce.breed.mapper;
import java.util.List; import java.util.List;
import com.zhyc.module.produce.breed.domain.ScDryMilk; import com.zhyc.module.produce.breed.domain.ScDryMilk;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param;
/** /**
* 干奶记录Mapper接口 * 干奶记录Mapper接口
* * * @author ruoyi
* @author ruoyi
* @date 2025-07-15 * @date 2025-07-15
*/ */
@Mapper
public interface ScDryMilkMapper public interface ScDryMilkMapper
{ {
/** /**
* 查询干奶记录 * 查询干奶记录
* * * @param id 干奶记录主键
* @param id 干奶记录主键
* @return 干奶记录 * @return 干奶记录
*/ */
public ScDryMilk selectScDryMilkById(Long id); public ScDryMilk selectScDryMilkById(Long id);
/** /**
* 查询干奶记录列表 * 查询干奶记录列表
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 干奶记录集合 * @return 干奶记录集合
*/ */
public List<ScDryMilk> selectScDryMilkList(ScDryMilk scDryMilk); public List<ScDryMilk> selectScDryMilkList(ScDryMilk scDryMilk);
/**
* 根据耳号查询羊只ID
*
* @param manageTags 管理耳号
* @return 羊只ID
*/
public Long selectSheepIdByManageTags(String manageTags);
/** /**
* 新增干奶记录 * 新增干奶记录
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 结果 * @return 结果
*/ */
public int insertScDryMilk(ScDryMilk scDryMilk); public int insertScDryMilk(ScDryMilk scDryMilk);
/** /**
* 修改干奶记录 * 修改干奶记录
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 结果 * @return 结果
*/ */
public int updateScDryMilk(ScDryMilk scDryMilk); public int updateScDryMilk(ScDryMilk scDryMilk);
/** /**
* 删除干奶记录 * 删除干奶记录
* * * @param id 干奶记录主键
* @param id 干奶记录主键
* @return 结果 * @return 结果
*/ */
public int deleteScDryMilkById(Long id); public int deleteScDryMilkById(Long id);
/** /**
* 批量删除干奶记录 * 批量删除干奶记录
* * * @param ids 需要删除的数据主键集合
* @param ids 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */
public int deleteScDryMilkByIds(Long[] ids); public int deleteScDryMilkByIds(String[] ids);
/**
* 根据耳号查询羊只ID
*/
public Long selectSheepIdByManageTags(String manageTags);
/**
* 远程搜索耳号列表 (新增)
* @param query 搜索关键字
* @return 耳号列表
*/
public List<String> selectSheepEarNumberList(@Param("query") String query);
} }

View File

@@ -2,8 +2,8 @@ package com.zhyc.module.produce.breed.mapper;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.zhyc.module.produce.breed.domain.ScSheepDeath; import com.zhyc.module.produce.breed.domain.ScSheepDeath;
import org.apache.ibatis.annotations.Param;
/** /**
* 羊只死淘记录Mapper接口 * 羊只死淘记录Mapper接口
@@ -29,14 +29,6 @@ public interface ScSheepDeathMapper
*/ */
public List<ScSheepDeath> selectScSheepDeathList(ScSheepDeath scSheepDeath); public List<ScSheepDeath> selectScSheepDeathList(ScSheepDeath scSheepDeath);
/**
* 根据管理耳号查询sheep_file视图信息
*
* @param manageTags 管理耳号
* @return 羊只信息
*/
public Map<String, Object> selectSheepFileByManageTags(String manageTags);
/** /**
* 新增羊只死淘记录 * 新增羊只死淘记录
* *
@@ -70,20 +62,27 @@ public interface ScSheepDeathMapper
public int deleteScSheepDeathByIds(Long[] ids); public int deleteScSheepDeathByIds(Long[] ids);
/** /**
* 更新羊只繁育状态 * 根据管理耳号查询sheep_file视图信息
*
* @param sheepId 羊只ID
* @param status 繁育状态
* @return 更新结果
*/ */
public int updateSheepFileStatus(@Param("sheepId") Long sheepId, @Param("status") String status); public Map<String, Object> selectSheepFileByManageTags(@Param("manageTags") String manageTags);
/** /**
* 新增:更新羊只在群状态 * 更新羊只在群状态
*
* @param sheepId 羊只ID
* @param status 在群状态1-在群2-不在群)
* @return 更新结果
*/ */
public int updateSheepStatus(@Param("sheepId") Long sheepId, @Param("status") String status); public int updateSheepStatus(@Param("sheepId") Long sheepId, @Param("status") String status);
/**
* 远程搜索:管理耳号
*/
public List<String> selectDistinctManageTags(@Param("query") String query);
/**
* 远程搜索:技术员
*/
public List<String> selectDistinctTechnician(@Param("query") String query);
/**
* 远程搜索:处理人
*/
public List<String> selectDistinctHandler(@Param("query") String query);
} }

View File

@@ -2,77 +2,75 @@ package com.zhyc.module.produce.breed.mapper;
import java.util.List; import java.util.List;
import com.zhyc.module.produce.breed.domain.ScWeanRecord; import com.zhyc.module.produce.breed.domain.ScWeanRecord;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param;
/** /**
* 断奶记录Mapper接口 * 断奶记录Mapper接口
* * * @author zhyc
* @author zhyc
* @date 2024-01-01 * @date 2024-01-01
*/ */
@Mapper public interface ScWeanRecordMapper
public interface ScWeanRecordMapper { {
/** /**
* 查询断奶记录 * 查询断奶记录
* * * @param id 断奶记录主键
* @param id 断奶记录主键
* @return 断奶记录 * @return 断奶记录
*/ */
public ScWeanRecord selectScWeanRecordById(Long id); public ScWeanRecord selectScWeanRecordById(Long id);
/** /**
* 查询断奶记录列表 * 查询断奶记录列表
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 断奶记录集合 * @return 断奶记录集合
*/ */
public List<ScWeanRecord> selectScWeanRecordList(ScWeanRecord scWeanRecord); public List<ScWeanRecord> selectScWeanRecordList(ScWeanRecord scWeanRecord);
/** /**
* 新增断奶记录 * 新增断奶记录
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 结果 * @return 结果
*/ */
public int insertScWeanRecord(ScWeanRecord scWeanRecord); public int insertScWeanRecord(ScWeanRecord scWeanRecord);
/** /**
* 修改断奶记录 * 修改断奶记录
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 结果 * @return 结果
*/ */
public int updateScWeanRecord(ScWeanRecord scWeanRecord); public int updateScWeanRecord(ScWeanRecord scWeanRecord);
/** /**
* 删除断奶记录 * 删除断奶记录
* * * @param id 断奶记录主键
* @param id 断奶记录主键
* @return 结果 * @return 结果
*/ */
public int deleteScWeanRecordById(Long id); public int deleteScWeanRecordById(Long id);
/** /**
* 批量删除断奶记录 * 批量删除断奶记录
* * * @param ids 需要删除的数据主键集合
* @param ids 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */
public int deleteScWeanRecordByIds(Long[] ids); public int deleteScWeanRecordByIds(Long[] ids);
/** /**
* 根据耳号查询羊只ID * 根据耳号查询羊只ID
*
* @param earNumber 耳号 * @param earNumber 耳号
* @return 羊只ID * @return 羊只ID
*/ */
public Long selectSheepIdByEarNumber(String earNumber); public Long selectSheepIdByEarNumber(String earNumber);
/** /**
* 根据耳号更新bas_sheep表中的断奶信息 * 更新基础羊只表的断奶信息 (对应XML中的updateBasSheepWeaningInfo)
* * @param scWeanRecord 断奶信息
* @param scWeanRecord 断奶记录
* @return 结果 * @return 结果
*/ */
public int updateBasSheepWeaningInfo(ScWeanRecord scWeanRecord); public int updateBasSheepWeaningInfo(ScWeanRecord scWeanRecord);
/**
* 【新增】模糊查询耳号列表 (用于前端远程搜索)
* @param query 查询关键字
* @return 耳号列表
*/
public List<String> searchEarNumbers(@Param("query") String query);
} }

View File

@@ -5,59 +5,62 @@ import com.zhyc.module.produce.breed.domain.ScDryMilk;
/** /**
* 干奶记录Service接口 * 干奶记录Service接口
* * * @author ruoyi
* @author ruoyi
* @date 2025-07-15 * @date 2025-07-15
*/ */
public interface IScDryMilkService public interface IScDryMilkService
{ {
/** /**
* 查询干奶记录 * 查询干奶记录
* * * @param id 干奶记录主键
* @param id 干奶记录主键
* @return 干奶记录 * @return 干奶记录
*/ */
public ScDryMilk selectScDryMilkById(Long id); public ScDryMilk selectScDryMilkById(Long id);
/** /**
* 查询干奶记录列表 * 查询干奶记录列表
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 干奶记录集合 * @return 干奶记录集合
*/ */
public List<ScDryMilk> selectScDryMilkList(ScDryMilk scDryMilk); public List<ScDryMilk> selectScDryMilkList(ScDryMilk scDryMilk);
Long selectSheepIdByManageTags(String manageTags);
/** /**
* 新增干奶记录 * 新增干奶记录
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 结果 * @return 结果
*/ */
public int insertScDryMilk(ScDryMilk scDryMilk); public int insertScDryMilk(ScDryMilk scDryMilk);
/** /**
* 修改干奶记录 * 修改干奶记录
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 结果 * @return 结果
*/ */
public int updateScDryMilk(ScDryMilk scDryMilk); public int updateScDryMilk(ScDryMilk scDryMilk);
/** /**
* 批量删除干奶记录 * 批量删除干奶记录
* * * @param ids 需要删除的干奶记录主键集合
* @param ids 需要删除的干奶记录主键集合
* @return 结果 * @return 结果
*/ */
public int deleteScDryMilkByIds(Long[] ids); public int deleteScDryMilkByIds(Long[] ids);
/** /**
* 删除干奶记录信息 * 删除干奶记录信息
* * * @param id 干奶记录主键
* @param id 干奶记录主键
* @return 结果 * @return 结果
*/ */
public int deleteScDryMilkById(Long id); public int deleteScDryMilkById(Long id);
/**
* 根据耳号查询羊只ID
*/
public Long selectSheepIdByManageTags(String manageTags);
/**
* 远程搜索耳号列表 (新增方法)
* @param query 搜索关键字
* @return 耳号列表
*/
public List<String> selectSheepEarNumberList(String query);
} }

View File

@@ -28,14 +28,6 @@ public interface IScSheepDeathService
*/ */
public List<ScSheepDeath> selectScSheepDeathList(ScSheepDeath scSheepDeath); public List<ScSheepDeath> selectScSheepDeathList(ScSheepDeath scSheepDeath);
/**
* 根据管理耳号查询sheep_file视图信息
*
* @param manageTags 管理耳号
* @return 羊只信息
*/
public Map<String, Object> selectSheepFileByManageTags(String manageTags);
/** /**
* 新增羊只死淘记录 * 新增羊只死淘记录
* *
@@ -67,4 +59,27 @@ public interface IScSheepDeathService
* @return 结果 * @return 结果
*/ */
public int deleteScSheepDeathById(Long id); public int deleteScSheepDeathById(Long id);
/**
* 根据管理耳号查询sheep_file视图信息
*
* @param manageTags 管理耳号
* @return 羊只信息
*/
public Map<String, Object> selectSheepFileByManageTags(String manageTags);
/**
* 远程搜索:管理耳号
*/
public List<String> selectDistinctManageTags(String query);
/**
* 远程搜索:技术员
*/
public List<String> selectDistinctTechnician(String query);
/**
* 远程搜索:处理人
*/
public List<String> selectDistinctHandler(String query);
} }

View File

@@ -1,69 +1,68 @@
package com.zhyc.module.produce.breed.service; package com.zhyc.module.produce.breed.service;
import java.util.List; import java.util.List;
import com.zhyc.module.produce.breed.domain.ScWeanRecord; import com.zhyc.module.produce.breed.domain.ScWeanRecord;
/** /**
* 断奶记录Service接口 * 断奶记录Service接口
* * * @author zhyc
* @author ruoyi * @date 2024-01-01
* @date 2025-07-13
*/ */
public interface IScWeanRecordService { public interface IScWeanRecordService
{
/** /**
* 查询断奶记录 * 查询断奶记录
* * * @param id 断奶记录主键
* @param id 断奶记录主键
* @return 断奶记录 * @return 断奶记录
*/ */
public ScWeanRecord selectScWeanRecordById(Long id); public ScWeanRecord selectScWeanRecordById(Long id);
/** /**
* 查询断奶记录列表 * 查询断奶记录列表
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 断奶记录集合 * @return 断奶记录集合
*/ */
public List<ScWeanRecord> selectScWeanRecordList(ScWeanRecord scWeanRecord); public List<ScWeanRecord> selectScWeanRecordList(ScWeanRecord scWeanRecord);
/** /**
* 新增断奶记录 * 新增断奶记录
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 结果 * @return 结果
*/ */
public int insertScWeanRecord(ScWeanRecord scWeanRecord); public int insertScWeanRecord(ScWeanRecord scWeanRecord);
/** /**
* 修改断奶记录 * 修改断奶记录
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 结果 * @return 结果
*/ */
public int updateScWeanRecord(ScWeanRecord scWeanRecord); public int updateScWeanRecord(ScWeanRecord scWeanRecord);
/** /**
* 批量删除断奶记录 * 批量删除断奶记录
* * * @param ids 需要删除的断奶记录主键集合
* @param ids 需要删除的断奶记录主键集合
* @return 结果 * @return 结果
*/ */
public int deleteScWeanRecordByIds(Long[] ids); public int deleteScWeanRecordByIds(Long[] ids);
/** /**
* 删除断奶记录信息 * 删除断奶记录信息
* * * @param id 断奶记录主键
* @param id 断奶记录主键
* @return 结果 * @return 结果
*/ */
public int deleteScWeanRecordById(Long id); public int deleteScWeanRecordById(Long id);
/** /**
* 根据耳号查询羊只ID * 根据耳号查询羊只ID
*
* @param earNumber 耳号 * @param earNumber 耳号
* @return 羊只ID * @return 羊只ID
*/ */
public Long selectSheepIdByEarNumber(String earNumber); public Long selectSheepIdByEarNumber(String earNumber);
/**
* 【新增】模糊查询耳号列表
* @param query 查询关键字
* @return 耳号列表
*/
public List<String> searchEarNumbers(String query);
} }

View File

@@ -1,20 +1,16 @@
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 com.zhyc.common.utils.DateUtils;
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.DateUtils;
import com.zhyc.common.exception.ServiceException;
/** /**
* 干奶记录Service业务层处理 * 干奶记录Service业务层处理
* * * @author ruoyi
* @author ruoyi
* @date 2025-07-15 * @date 2025-07-15
*/ */
@Service @Service
@@ -25,8 +21,7 @@ public class ScDryMilkServiceImpl implements IScDryMilkService
/** /**
* 查询干奶记录 * 查询干奶记录
* * * @param id 干奶记录主键
* @param id 干奶记录主键
* @return 干奶记录 * @return 干奶记录
*/ */
@Override @Override
@@ -37,8 +32,7 @@ public class ScDryMilkServiceImpl implements IScDryMilkService
/** /**
* 查询干奶记录列表 * 查询干奶记录列表
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 干奶记录 * @return 干奶记录
*/ */
@Override @Override
@@ -47,90 +41,49 @@ public class ScDryMilkServiceImpl implements IScDryMilkService
return scDryMilkMapper.selectScDryMilkList(scDryMilk); return scDryMilkMapper.selectScDryMilkList(scDryMilk);
} }
/**
* 根据耳号查询羊只ID
*
* @param manageTags 管理耳号
* @return 羊只ID
*/
@Override
public Long selectSheepIdByManageTags(String manageTags)
{
return scDryMilkMapper.selectSheepIdByManageTags(manageTags);
}
/** /**
* 新增干奶记录 * 新增干奶记录
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertScDryMilk(ScDryMilk scDryMilk) public int insertScDryMilk(ScDryMilk scDryMilk)
{ {
// 如果传入的是耳号需要转换为羊只ID
if (StringUtils.isNotEmpty(scDryMilk.getManageTags()) && StringUtils.isEmpty(scDryMilk.getSheepId()))
{
Long sheepId = scDryMilkMapper.selectSheepIdByManageTags(scDryMilk.getManageTags());
if (sheepId == null)
{
throw new ServiceException("未找到对应耳号的羊只信息");
}
scDryMilk.setSheepId(String.valueOf(sheepId));
}
// 自动设置创建时间(精确到分钟)
scDryMilk.setCreateTime(DateUtils.getNowDate()); scDryMilk.setCreateTime(DateUtils.getNowDate());
// 如果有获取当前用户的方法,可以设置创建人
// scDryMilk.setCreateBy(SecurityUtils.getUsername());
return scDryMilkMapper.insertScDryMilk(scDryMilk); return scDryMilkMapper.insertScDryMilk(scDryMilk);
} }
/** /**
* 修改干奶记录 * 修改干奶记录
* * * @param scDryMilk 干奶记录
* @param scDryMilk 干奶记录
* @return 结果 * @return 结果
*/ */
@Override @Override
public int updateScDryMilk(ScDryMilk scDryMilk) public int updateScDryMilk(ScDryMilk scDryMilk)
{ {
// 如果传入的是耳号需要转换为羊只ID
if (StringUtils.isNotEmpty(scDryMilk.getManageTags()) && StringUtils.isEmpty(scDryMilk.getSheepId()))
{
Long sheepId = scDryMilkMapper.selectSheepIdByManageTags(scDryMilk.getManageTags());
if (sheepId == null)
{
throw new ServiceException("未找到对应耳号的羊只信息");
}
scDryMilk.setSheepId(String.valueOf(sheepId));
}
// 设置更新时间
scDryMilk.setUpdateTime(DateUtils.getNowDate());
// 如果有获取当前用户的方法,可以设置更新人
// scDryMilk.setUpdateBy(SecurityUtils.getUsername());
return scDryMilkMapper.updateScDryMilk(scDryMilk); return scDryMilkMapper.updateScDryMilk(scDryMilk);
} }
/** /**
* 批量删除干奶记录 * 批量删除干奶记录
* * * @param ids 需要删除的干奶记录主键
* @param ids 需要删除的干奶记录主键
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteScDryMilkByIds(Long[] ids) public int deleteScDryMilkByIds(Long[] ids)
{ {
return scDryMilkMapper.deleteScDryMilkByIds(ids); // 假设ids是Long数组需要转为String[]传给Mapper或者修改Mapper接收Long[]
// 这里根据Mapper XML通常接收String[]或Array的习惯做个转换
String[] stringIds = new String[ids.length];
for(int i=0;i<ids.length;i++){
stringIds[i] = String.valueOf(ids[i]);
}
return scDryMilkMapper.deleteScDryMilkByIds(stringIds);
} }
/** /**
* 删除干奶记录信息 * 删除干奶记录信息
* * * @param id 干奶记录主键
* @param id 干奶记录主键
* @return 结果 * @return 结果
*/ */
@Override @Override
@@ -138,4 +91,20 @@ public class ScDryMilkServiceImpl implements IScDryMilkService
{ {
return scDryMilkMapper.deleteScDryMilkById(id); return scDryMilkMapper.deleteScDryMilkById(id);
} }
/**
* 根据耳号查询羊只ID
*/
@Override
public Long selectSheepIdByManageTags(String manageTags) {
return scDryMilkMapper.selectSheepIdByManageTags(manageTags);
}
/**
* 远程搜索耳号列表 (新增实现)
*/
@Override
public List<String> selectSheepEarNumberList(String query) {
return scDryMilkMapper.selectSheepEarNumberList(query);
}
} }

View File

@@ -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.utils.bean.BeanUtils;
import com.zhyc.module.biosafety.domain.Diagnosis; import com.zhyc.module.biosafety.domain.Diagnosis;
import com.zhyc.module.biosafety.domain.Treatment; import com.zhyc.module.biosafety.domain.Treatment;
import com.zhyc.module.biosafety.mapper.DiagnosisMapper; import com.zhyc.module.biosafety.mapper.DiagnosisMapper;
@@ -31,134 +32,77 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
@Autowired @Autowired
private TreatmentServiceImpl treatmentService; private TreatmentServiceImpl treatmentService;
/**
* 查询羊只死淘记录
*
* @param id 羊只死淘记录主键
* @return 羊只死淘记录
*/
@Override @Override
public ScSheepDeath selectScSheepDeathById(Long id) public ScSheepDeath selectScSheepDeathById(Long id)
{ {
ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id); return scSheepDeathMapper.selectScSheepDeathById(id);
// 查询时也需要填充显示字段
if (scSheepDeath != null && scSheepDeath.getManageTags() != null) {
Map<String, Object> sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags());
if (sheepInfo != null) {
scSheepDeath.setVariety(sheepInfo.get("variety") != null ? sheepInfo.get("variety").toString() : null);
scSheepDeath.setSheepType(sheepInfo.get("sheepType") != null ? sheepInfo.get("sheepType").toString() : null);
scSheepDeath.setGender(sheepInfo.get("gender") != null ? Integer.valueOf(sheepInfo.get("gender").toString()) : null);
scSheepDeath.setDayAge(sheepInfo.get("dayAge") != null ? Long.valueOf(sheepInfo.get("dayAge").toString()) : null);
scSheepDeath.setParity(sheepInfo.get("parity") != null ? Integer.valueOf(sheepInfo.get("parity").toString()) : null);
scSheepDeath.setSheepfoldName(sheepInfo.get("sheepfoldName") != null ? sheepInfo.get("sheepfoldName").toString() : null);
scSheepDeath.setBreedStatus(sheepInfo.get("breedStatus") != null ? sheepInfo.get("breedStatus").toString() : null);
scSheepDeath.setPostLambingDay(sheepInfo.get("postLambingDay") != null ? Integer.valueOf(sheepInfo.get("postLambingDay").toString()) : null);
scSheepDeath.setLactationDay(sheepInfo.get("lactationDay") != null ? Integer.valueOf(sheepInfo.get("lactationDay").toString()) : null);
scSheepDeath.setGestationDay(sheepInfo.get("gestationDay") != null ? Integer.valueOf(sheepInfo.get("gestationDay").toString()) : null);
}
}
return scSheepDeath;
} }
/**
* 查询羊只死淘记录列表
*
* @param scSheepDeath 羊只死淘记录
* @return 羊只死淘记录
*/
@Override @Override
public List<ScSheepDeath> selectScSheepDeathList(ScSheepDeath scSheepDeath) public List<ScSheepDeath> selectScSheepDeathList(ScSheepDeath scSheepDeath)
{ {
List<ScSheepDeath> list = scSheepDeathMapper.selectScSheepDeathList(scSheepDeath); return scSheepDeathMapper.selectScSheepDeathList(scSheepDeath);
// 为列表中的每条记录填充显示字段
for (ScSheepDeath death : list) {
if (death.getManageTags() != null) {
Map<String, Object> sheepInfo = selectSheepFileByManageTags(death.getManageTags());
if (sheepInfo != null) {
death.setVariety(sheepInfo.get("variety") != null ? sheepInfo.get("variety").toString() : null);
death.setSheepType(sheepInfo.get("sheepType") != null ? sheepInfo.get("sheepType").toString() : null);
death.setGender(sheepInfo.get("gender") != null ? Integer.valueOf(sheepInfo.get("gender").toString()) : null);
death.setDayAge(sheepInfo.get("dayAge") != null ? Long.valueOf(sheepInfo.get("dayAge").toString()) : null);
death.setParity(sheepInfo.get("parity") != null ? Integer.valueOf(sheepInfo.get("parity").toString()) : null);
death.setSheepfoldName(sheepInfo.get("sheepfoldName") != null ? sheepInfo.get("sheepfoldName").toString() : null);
death.setBreedStatus(sheepInfo.get("breedStatus") != null ? sheepInfo.get("breedStatus").toString() : null);
death.setPostLambingDay(sheepInfo.get("postLambingDay") != null ? Integer.valueOf(sheepInfo.get("postLambingDay").toString()) : null);
death.setLactationDay(sheepInfo.get("lactationDay") != null ? Integer.valueOf(sheepInfo.get("lactationDay").toString()) : null);
death.setGestationDay(sheepInfo.get("gestationDay") != null ? Integer.valueOf(sheepInfo.get("gestationDay").toString()) : null);
}
}
}
return list;
} }
/**
* 根据管理耳号查询sheep_file视图信息
*
* @param manageTags 管理耳号
* @return 羊只信息
*/
@Override @Override
public Map<String, Object> selectSheepFileByManageTags(String manageTags) public Map<String, Object> selectSheepFileByManageTags(String manageTags)
{ {
return scSheepDeathMapper.selectSheepFileByManageTags(manageTags); return scSheepDeathMapper.selectSheepFileByManageTags(manageTags);
} }
/**
* 新增羊只死淘记录
*
* @param scSheepDeath 羊只死淘记录
* @return 结果
*/
@Override @Override
@Transactional @Transactional
public int insertScSheepDeath(ScSheepDeath scSheepDeath) public int insertScSheepDeath(ScSheepDeath scSheepDeath)
{ {
// 设置事件类型默认为"死亡" String manageTagsInput = scSheepDeath.getManageTags();
if (scSheepDeath.getEventType() == null || scSheepDeath.getEventType().isEmpty()) { if (manageTagsInput == null || manageTagsInput.trim().isEmpty()) {
scSheepDeath.setEventType("死亡"); return 0;
} }
// 如果有管理耳号查询并设置羊只ID // 支持空格、逗号分隔
if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) { String[] tags = manageTagsInput.split("[\\s,]+");
Map<String, Object> sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags()); int successCount = 0;
for (String tag : tags) {
if (tag == null || tag.trim().isEmpty()) {
continue;
}
ScSheepDeath newRecord = new ScSheepDeath();
BeanUtils.copyProperties(scSheepDeath, newRecord);
newRecord.setManageTags(tag.trim());
newRecord.setId(null);
if (newRecord.getEventType() == null || newRecord.getEventType().isEmpty()) {
newRecord.setEventType("死亡");
}
Map<String, Object> sheepInfo = selectSheepFileByManageTags(newRecord.getManageTags());
if (sheepInfo != null) { if (sheepInfo != null) {
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); newRecord.setSheepId(sheepId);
// 插入死淘记录后,同时更新羊只在群状态为"不在群"状态ID为2
if (sheepId != null) { if (sheepId != null) {
scSheepDeathMapper.updateSheepStatus(sheepId, "2"); scSheepDeathMapper.updateSheepStatus(sheepId, "2");
} treatmentService.updateTreatmentStatus(sheepId);
} }
} }
treatmentService.updateTreatmentStatus(scSheepDeath.getSheepId()); newRecord.setCreateTime(DateUtils.getNowDate());
successCount += scSheepDeathMapper.insertScSheepDeath(newRecord);
scSheepDeath.setCreateTime(DateUtils.getNowDate()); }
return successCount;
return scSheepDeathMapper.insertScSheepDeath(scSheepDeath);
} }
/**
* 修改羊只死淘记录
*
* @param scSheepDeath 羊只死淘记录
* @return 结果
*/
@Override @Override
public int updateScSheepDeath(ScSheepDeath scSheepDeath) public int updateScSheepDeath(ScSheepDeath scSheepDeath)
{ {
// 如果管理耳号发生变化重新查询并设置羊只ID
if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) { if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) {
Map<String, Object> sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags()); Map<String, Object> sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags());
if (sheepInfo != null) { if (sheepInfo != null) {
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);
// 修改死淘记录时,同时更新羊只在群状态为"不在群"状态ID为2
if (sheepId != null) { if (sheepId != null) {
scSheepDeathMapper.updateSheepStatus(sheepId, "2"); scSheepDeathMapper.updateSheepStatus(sheepId, "2");
} }
@@ -168,43 +112,41 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
return scSheepDeathMapper.updateScSheepDeath(scSheepDeath); return scSheepDeathMapper.updateScSheepDeath(scSheepDeath);
} }
/**
* 批量删除羊只死淘记录
*
* @param ids 需要删除的羊只死淘记录主键
* @return 结果
*/
@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) {
// 恢复羊只在群状态为"在群"状态ID为1
scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1"); scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1");
} }
} }
return scSheepDeathMapper.deleteScSheepDeathByIds(ids); return scSheepDeathMapper.deleteScSheepDeathByIds(ids);
} }
/**
* 删除羊只死淘记录信息
*
* @param id 羊只死淘记录主键
* @return 结果
*/
@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) {
// 恢复羊只在群状态为"在群"状态ID为1
scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1"); scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1");
} }
return scSheepDeathMapper.deleteScSheepDeathById(id); return scSheepDeathMapper.deleteScSheepDeathById(id);
} }
// --- 远程搜索实现 ---
@Override
public List<String> selectDistinctManageTags(String query) {
return scSheepDeathMapper.selectDistinctManageTags(query);
}
@Override
public List<String> selectDistinctTechnician(String query) {
return scSheepDeathMapper.selectDistinctTechnician(query);
}
@Override
public List<String> selectDistinctHandler(String query) {
return scSheepDeathMapper.selectDistinctHandler(query);
}
} }

View File

@@ -2,133 +2,123 @@ package com.zhyc.module.produce.breed.service.impl;
import java.util.List; import java.util.List;
import com.zhyc.common.utils.DateUtils; import com.zhyc.common.utils.DateUtils;
import com.zhyc.module.produce.breed.domain.ScWeanRecord;
import com.zhyc.module.produce.breed.mapper.ScWeanRecordMapper;
import com.zhyc.module.produce.breed.service.IScWeanRecordService;
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.ScWeanRecordMapper;
import com.zhyc.module.produce.breed.domain.ScWeanRecord;
import com.zhyc.module.produce.breed.service.IScWeanRecordService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* 断奶记录Service业务层处理 * 断奶记录Service业务层处理
* * * @author zhyc
* @author ruoyi * @date 2024-01-01
* @date 2025-07-13
*/ */
@Service @Service
public class ScWeanRecordServiceImpl implements IScWeanRecordService { public class ScWeanRecordServiceImpl implements IScWeanRecordService
{
@Autowired @Autowired
private ScWeanRecordMapper scWeanRecordMapper; private ScWeanRecordMapper scWeanRecordMapper;
/** /**
* 查询断奶记录 * 查询断奶记录
* * * @param id 断奶记录主键
* @param id 断奶记录主键
* @return 断奶记录 * @return 断奶记录
*/ */
@Override @Override
public ScWeanRecord selectScWeanRecordById(Long id) { public ScWeanRecord selectScWeanRecordById(Long id)
{
return scWeanRecordMapper.selectScWeanRecordById(id); return scWeanRecordMapper.selectScWeanRecordById(id);
} }
/** /**
* 查询断奶记录列表 * 查询断奶记录列表
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 断奶记录 * @return 断奶记录
*/ */
@Override @Override
public List<ScWeanRecord> selectScWeanRecordList(ScWeanRecord scWeanRecord) { public List<ScWeanRecord> selectScWeanRecordList(ScWeanRecord scWeanRecord)
{
return scWeanRecordMapper.selectScWeanRecordList(scWeanRecord); return scWeanRecordMapper.selectScWeanRecordList(scWeanRecord);
} }
/** /**
* 新增断奶记录 * 新增断奶记录
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional
public int insertScWeanRecord(ScWeanRecord scWeanRecord) { public int insertScWeanRecord(ScWeanRecord scWeanRecord)
// 如果前端传递的是耳号需要先获取羊只ID {
if (scWeanRecord.getEarNumber() != null && scWeanRecord.getSheepId() == null) {
Long sheepId = scWeanRecordMapper.selectSheepIdByEarNumber(scWeanRecord.getEarNumber());
if (sheepId != null) {
scWeanRecord.setSheepId(sheepId);
}
}
scWeanRecord.setCreateTime(DateUtils.getNowDate()); scWeanRecord.setCreateTime(DateUtils.getNowDate());
// 1. 插入断奶记录
int rows = scWeanRecordMapper.insertScWeanRecord(scWeanRecord);
// 插入断奶记录 // 2. 同步更新羊只档案中的断奶状态(断奶日期、断奶重、电子耳号等)
int result = scWeanRecordMapper.insertScWeanRecord(scWeanRecord); // 确保 scWeanRecord 中包含 earNumber (Controller中add方法校验过)
if (rows > 0 && scWeanRecord.getEarNumber() != null) {
// 同步更新bas_sheep表中的断奶信息
if (result > 0 && scWeanRecord.getEarNumber() != null) {
scWeanRecordMapper.updateBasSheepWeaningInfo(scWeanRecord); scWeanRecordMapper.updateBasSheepWeaningInfo(scWeanRecord);
} }
return rows;
return result;
} }
/** /**
* 修改断奶记录 * 修改断奶记录
* * * @param scWeanRecord 断奶记录
* @param scWeanRecord 断奶记录
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional
public int updateScWeanRecord(ScWeanRecord scWeanRecord) { public int updateScWeanRecord(ScWeanRecord scWeanRecord)
// 如果前端传递的是耳号需要先获取羊只ID {
if (scWeanRecord.getEarNumber() != null && scWeanRecord.getSheepId() == null) { // 1. 更新断奶记录
Long sheepId = scWeanRecordMapper.selectSheepIdByEarNumber(scWeanRecord.getEarNumber()); int rows = scWeanRecordMapper.updateScWeanRecord(scWeanRecord);
if (sheepId != null) {
scWeanRecord.setSheepId(sheepId);
}
}
// 更新断奶记录 // 2. 同步更新羊只档案信息
int result = scWeanRecordMapper.updateScWeanRecord(scWeanRecord); if (rows > 0 && scWeanRecord.getEarNumber() != null) {
// 同步更新bas_sheep表中的断奶信息
if (result > 0 && scWeanRecord.getEarNumber() != null) {
scWeanRecordMapper.updateBasSheepWeaningInfo(scWeanRecord); scWeanRecordMapper.updateBasSheepWeaningInfo(scWeanRecord);
} }
return rows;
return result;
} }
/** /**
* 批量删除断奶记录 * 批量删除断奶记录
* * * @param ids 需要删除的断奶记录主键
* @param ids 需要删除的断奶记录主键
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteScWeanRecordByIds(Long[] ids) { public int deleteScWeanRecordByIds(Long[] ids)
{
return scWeanRecordMapper.deleteScWeanRecordByIds(ids); return scWeanRecordMapper.deleteScWeanRecordByIds(ids);
} }
/** /**
* 删除断奶记录信息 * 删除断奶记录信息
* * * @param id 断奶记录主键
* @param id 断奶记录主键
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteScWeanRecordById(Long id) { public int deleteScWeanRecordById(Long id)
{
return scWeanRecordMapper.deleteScWeanRecordById(id); return scWeanRecordMapper.deleteScWeanRecordById(id);
} }
/** /**
* 根据耳号查询羊只ID * 根据耳号查询羊只ID
*
* @param earNumber 耳号
* @return 羊只ID
*/ */
@Override @Override
public Long selectSheepIdByEarNumber(String earNumber) { public Long selectSheepIdByEarNumber(String earNumber) {
return scWeanRecordMapper.selectSheepIdByEarNumber(earNumber); return scWeanRecordMapper.selectSheepIdByEarNumber(earNumber);
} }
/**
* 【新增】模糊查询耳号列表 (用于前端远程搜索)
* @param query 查询关键字
* @return 耳号列表
*/
@Override
public List<String> searchEarNumbers(String query) {
return scWeanRecordMapper.searchEarNumbers(query);
}
} }

View File

@@ -14,7 +14,6 @@
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="comment" column="comment" /> <result property="comment" column="comment" />
<!-- 联表查询字段 -->
<result property="manageTags" column="bs_manage_tags" /> <result property="manageTags" column="bs_manage_tags" />
<result property="variety" column="variety" /> <result property="variety" column="variety" />
<result property="sheepfoldName" column="sheepfold_name" /> <result property="sheepfoldName" column="sheepfold_name" />
@@ -33,17 +32,36 @@
<select id="selectScDryMilkList" parameterType="ScDryMilk" resultMap="ScDryMilkResult"> <select id="selectScDryMilkList" parameterType="ScDryMilk" resultMap="ScDryMilkResult">
<include refid="selectScDryMilkVo"/> <include refid="selectScDryMilkVo"/>
<where> <where>
<if test="sheepId != null and sheepId != ''"> and d.sheep_id = #{sheepId}</if> <if test="manageTagsList != null and manageTagsList.size() > 0">
<if test="manageTags != null and manageTags != ''"> and s.bs_manage_tags like concat('%', #{manageTags}, '%')</if> AND s.bs_manage_tags IN
<if test="datetime != null "> and d.datetime = #{datetime}</if> <foreach collection="manageTagsList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="(manageTagsList == null or manageTagsList.size() == 0) and manageTags != null and manageTags != ''">
AND s.bs_manage_tags like concat('%', #{manageTags}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''">
AND d.datetime &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
AND d.datetime &lt;= #{params.endTime}
</if>
<if test="status != null "> and d.status = #{status}</if> <if test="status != null "> and d.status = #{status}</if>
<if test="sheepfold != null "> and d.sheepfold = #{sheepfold}</if> <if test="sheepfold != null "> and d.sheepfold = #{sheepfold}</if>
<if test="tecahnician != null and tecahnician != ''"> and d.tecahnician like concat('%', #{tecahnician}, '%')</if> <if test="tecahnician != null and tecahnician != ''"> and d.tecahnician like concat('%', #{tecahnician}, '%')</if>
<if test="createBy != null and createBy != ''"> and d.create_by = #{createBy}</if>
<if test="createTime != null "> and d.create_time = #{createTime}</if>
<if test="variety != null and variety != ''"> and s.variety like concat('%', #{variety}, '%')</if> <if test="variety != null and variety != ''"> and s.variety like concat('%', #{variety}, '%')</if>
</where> </where>
order by d.create_time desc order by d.datetime desc
</select>
<select id="selectSheepEarNumberList" resultType="String">
SELECT bs_manage_tags
FROM sheep_file
WHERE bs_manage_tags LIKE concat('%', #{query}, '%')
LIMIT 20
</select> </select>
<select id="selectScDryMilkById" parameterType="Long" resultMap="ScDryMilkResult"> <select id="selectScDryMilkById" parameterType="Long" resultMap="ScDryMilkResult">
@@ -51,9 +69,8 @@
where d.id = #{id} where d.id = #{id}
</select> </select>
<!-- 根据耳号查询羊只ID -->
<select id="selectSheepIdByManageTags" parameterType="String" resultType="Long"> <select id="selectSheepIdByManageTags" parameterType="String" resultType="Long">
select id from sheep_file where bs_manage_tags = #{manageTags} select id from sheep_file where bs_manage_tags = #{manageTags} limit 1
</select> </select>
<insert id="insertScDryMilk" parameterType="ScDryMilk" useGeneratedKeys="true" keyProperty="id"> <insert id="insertScDryMilk" parameterType="ScDryMilk" useGeneratedKeys="true" keyProperty="id">

View File

@@ -22,37 +22,121 @@
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="isDelete" column="is_delete" /> <result property="isDelete" column="is_delete" />
<result property="variety" column="variety" />
<result property="sheepType" column="sheep_type_name" />
<result property="gender" column="gender" />
<result property="dayAge" column="day_age" />
<result property="parity" column="parity" />
<result property="sheepfoldName" column="sheepfold_name" />
<result property="breedStatus" column="breed_status" />
<result property="postLambingDay" column="post_lambing_day" />
<result property="lactationDay" column="lactation_day" />
<result property="gestationDay" column="gestation_day" />
</resultMap> </resultMap>
<sql id="selectScSheepDeathVo"> <sql id="selectScSheepDeathVo">
select id, sheep_id, manage_tags, event_type, death_date, disease_type_id, disease_subtype_id, disposal_direction, technician, handler, work_group, create_by, create_time, comment, update_by, update_time, is_delete from sc_sheep_death select d.id, d.sheep_id, d.manage_tags, d.event_type, d.death_date, d.disease_type_id, d.disease_subtype_id,
d.disposal_direction, d.technician, d.handler, d.work_group, d.create_by, d.create_time, d.comment,
d.update_by, d.update_time, d.is_delete,
s.variety, s.name as sheep_type_name, s.gender, s.day_age, s.parity, s.sheepfold_name,
s.breed as breed_status, s.post_lambing_day, s.lactation_day, s.gestation_day
from sc_sheep_death d
left join sheep_file s on d.manage_tags = s.bs_manage_tags
</sql> </sql>
<select id="selectScSheepDeathList" parameterType="ScSheepDeath" resultMap="ScSheepDeathResult"> <select id="selectScSheepDeathList" parameterType="ScSheepDeath" resultMap="ScSheepDeathResult">
<include refid="selectScSheepDeathVo"/> <include refid="selectScSheepDeathVo"/>
<where> <where>
<if test="sheepId != null "> and sheep_id = #{sheepId}</if> <if test="sheepId != null "> and d.sheep_id = #{sheepId}</if>
<if test="manageTags != null and manageTags != ''"> and manage_tags = #{manageTags}</if>
<if test="eventType != null and eventType != ''"> and event_type = #{eventType}</if> <if test="manageTagsList != null and manageTagsList.size() > 0">
<if test="deathDate != null "> and death_date = #{deathDate}</if> AND d.manage_tags IN
<if test="diseaseTypeId != null "> and disease_type_id = #{diseaseTypeId}</if> <foreach collection="manageTagsList" item="tag" open="(" separator="," close=")">
<if test="diseaseSubtypeId != null "> and disease_subtype_id = #{diseaseSubtypeId}</if> #{tag}
<if test="disposalDirection != null and disposalDirection != ''"> and disposal_direction = #{disposalDirection}</if> </foreach>
<if test="technician != null and technician != ''"> and technician = #{technician}</if> </if>
<if test="handler != null and handler != ''"> and handler = #{handler}</if> <if test="(manageTagsList == null or manageTagsList.size() == 0) and manageTags != null and manageTags != ''">
<if test="workGroup != null and workGroup != ''"> and work_group = #{workGroup}</if> and d.manage_tags like concat('%', #{manageTags}, '%')
<if test="comment != null and comment != ''"> and comment = #{comment}</if> </if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
<if test="params.beginDeathDate != null and params.beginDeathDate != '' and params.endDeathDate != null and params.endDeathDate != ''">
and d.death_date between #{params.beginDeathDate} and #{params.endDeathDate}
</if>
<if test="eventType != null and eventType != ''"> and d.event_type = #{eventType}</if>
<if test="diseaseTypeId != null "> and d.disease_type_id = #{diseaseTypeId}</if>
<if test="diseaseSubtypeId != null "> and d.disease_subtype_id = #{diseaseSubtypeId}</if>
<if test="disposalDirection != null and disposalDirection != ''"> and d.disposal_direction = #{disposalDirection}</if>
<if test="technicianList != null and technicianList.size() > 0">
AND d.technician IN
<foreach collection="technicianList" item="tech" open="(" separator="," close=")">
#{tech}
</foreach>
</if>
<if test="(technicianList == null or technicianList.size() == 0) and technician != null and technician != ''">
and d.technician like concat('%', #{technician}, '%')
</if>
<if test="handlerList != null and handlerList.size() > 0">
AND d.handler IN
<foreach collection="handlerList" item="hand" open="(" separator="," close=")">
#{hand}
</foreach>
</if>
<if test="(handlerList == null or handlerList.size() == 0) and handler != null and handler != ''">
and d.handler like concat('%', #{handler}, '%')
</if>
<if test="workGroupList != null and workGroupList.size() > 0">
AND d.work_group IN
<foreach collection="workGroupList" item="grp" open="(" separator="," close=")">
#{grp}
</foreach>
</if>
<if test="(workGroupList == null or workGroupList.size() == 0) and workGroup != null and workGroup != ''">
and d.work_group = #{workGroup}
</if>
<if test="variety != null and variety != ''"> and s.variety like concat('%', #{variety}, '%')</if>
<if test="sheepTypeList != null and sheepTypeList.size() > 0">
AND s.name IN
<foreach collection="sheepTypeList" item="sType" open="(" separator="," close=")">
#{sType}
</foreach>
</if>
<if test="(sheepTypeList == null or sheepTypeList.size() == 0) and sheepType != null and sheepType != ''">
and s.name like concat('%', #{sheepType}, '%')
</if>
</where> </where>
order by create_time desc order by d.create_time desc
</select>
<select id="selectDistinctManageTags" resultType="String">
SELECT DISTINCT manage_tags FROM sc_sheep_death
WHERE manage_tags LIKE concat('%', #{query}, '%')
LIMIT 20
</select>
<select id="selectDistinctTechnician" resultType="String">
SELECT DISTINCT technician FROM sc_sheep_death
WHERE technician LIKE concat('%', #{query}, '%') AND technician IS NOT NULL AND technician != ''
LIMIT 20
</select>
<select id="selectDistinctHandler" resultType="String">
SELECT DISTINCT handler FROM sc_sheep_death
WHERE handler LIKE concat('%', #{query}, '%') AND handler IS NOT NULL AND handler != ''
LIMIT 20
</select> </select>
<select id="selectScSheepDeathById" parameterType="Long" resultMap="ScSheepDeathResult"> <select id="selectScSheepDeathById" parameterType="Long" resultMap="ScSheepDeathResult">
<include refid="selectScSheepDeathVo"/> <include refid="selectScSheepDeathVo"/>
where id = #{id} where d.id = #{id}
</select> </select>
<!-- 根据管理耳号查询sheep_file视图信息 -->
<select id="selectSheepFileByManageTags" parameterType="String" resultType="java.util.Map"> <select id="selectSheepFileByManageTags" parameterType="String" resultType="java.util.Map">
select select
id as sheepId, id as sheepId,
@@ -145,7 +229,6 @@
</foreach> </foreach>
</delete> </delete>
<!-- 更新羊只繁育状态 - 更新基础表 bas_sheep使用正确的字段名 -->
<update id="updateSheepFileStatus"> <update id="updateSheepFileStatus">
UPDATE bas_sheep UPDATE bas_sheep
SET breed_status_id = #{status}, SET breed_status_id = #{status},
@@ -154,7 +237,6 @@
AND is_delete = 0 AND is_delete = 0
</update> </update>
<!-- 更新羊只在群状态 - 更新基础表 bas_sheep使用正确的字段名 -->
<update id="updateSheepStatus"> <update id="updateSheepStatus">
UPDATE bas_sheep UPDATE bas_sheep
SET status_id = #{status}, SET status_id = #{status},

View File

@@ -15,7 +15,7 @@
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="electronicTags" column="electronic_tags" /> <result property="electronicTags" column="electronic_tags" />
<!-- 关联查询的字段 -->
<result property="earNumber" column="bs_manage_tags" /> <result property="earNumber" column="bs_manage_tags" />
<result property="breed" column="variety" /> <result property="breed" column="variety" />
<result property="eventType" column="event_type" /> <result property="eventType" column="event_type" />
@@ -28,7 +28,6 @@
<result property="breedingStatus" column="breed" /> <result property="breedingStatus" column="breed" />
</resultMap> </resultMap>
<!-- 带关联查询的基础SQL -->
<sql id="selectScWeanRecordVo"> <sql id="selectScWeanRecordVo">
select select
wr.id, wr.sheep_id, wr.datetime, wr.weight, wr.status, wr.technician, wr.id, wr.sheep_id, wr.datetime, wr.weight, wr.status, wr.technician,
@@ -40,13 +39,36 @@
left join sheep_file sf on wr.sheep_id = sf.id left join sheep_file sf on wr.sheep_id = sf.id
</sql> </sql>
<!-- 查询断奶记录列表 -->
<select id="selectScWeanRecordList" parameterType="ScWeanRecord" resultMap="ScWeanRecordResult"> <select id="selectScWeanRecordList" parameterType="ScWeanRecord" resultMap="ScWeanRecordResult">
<include refid="selectScWeanRecordVo"/> <include refid="selectScWeanRecordVo"/>
<where> <where>
<if test="sheepId != null "> and wr.sheep_id = #{sheepId}</if> <if test="sheepId != null "> and wr.sheep_id = #{sheepId}</if>
<if test="earNumber != null and earNumber != ''"> and sf.bs_manage_tags like concat('%', #{earNumber}, '%')</if>
<if test="datetime != null "> and wr.datetime = #{datetime}</if> <if test="allEarNumbers != null and allEarNumbers.size() > 0">
AND sf.bs_manage_tags IN
<foreach collection="allEarNumbers" item="ear" open="(" separator="," close=")">
#{ear}
</foreach>
</if>
<if test="(allEarNumbers == null or allEarNumbers.size() == 0) and earNumber != null and earNumber != ''">
and sf.bs_manage_tags like concat('%', #{earNumber}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''">
AND date_format(wr.datetime,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''">
AND date_format(wr.datetime,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
<if test="isInHerd != null and isInHerd != ''">
AND sf.status = #{isInHerd}
</if>
<if test="sheepCategory != null and sheepCategory != ''">
AND sf.breed = #{sheepCategory}
</if>
<if test="weight != null "> and wr.weight = #{weight}</if> <if test="weight != null "> and wr.weight = #{weight}</if>
<if test="status != null "> and wr.status = #{status}</if> <if test="status != null "> and wr.status = #{status}</if>
<if test="technician != null and technician != ''"> and wr.technician like concat('%', #{technician}, '%')</if> <if test="technician != null and technician != ''"> and wr.technician like concat('%', #{technician}, '%')</if>
@@ -59,23 +81,27 @@
<if test="fatherNumber != null and fatherNumber != ''"> and sf.father_manage_tags like concat('%', #{fatherNumber}, '%')</if> <if test="fatherNumber != null and fatherNumber != ''"> and sf.father_manage_tags like concat('%', #{fatherNumber}, '%')</if>
<if test="motherNumber != null and motherNumber != ''"> and sf.mother_manage_tags like concat('%', #{motherNumber}, '%')</if> <if test="motherNumber != null and motherNumber != ''"> and sf.mother_manage_tags like concat('%', #{motherNumber}, '%')</if>
<if test="sheepPen != null and sheepPen != ''"> and sf.sheepfold_name like concat('%', #{sheepPen}, '%')</if> <if test="sheepPen != null and sheepPen != ''"> and sf.sheepfold_name like concat('%', #{sheepPen}, '%')</if>
<if test="breedingStatus != null and breedingStatus != ''"> and sf.breed = #{breedingStatus}</if>
</where> </where>
order by wr.create_time desc order by wr.create_time desc
</select> </select>
<!-- 根据ID查询断奶记录 --> <select id="searchEarNumbers" resultType="String">
SELECT DISTINCT bs_manage_tags
FROM sheep_file
WHERE bs_manage_tags LIKE CONCAT('%', #{query}, '%')
AND is_delete = 0
LIMIT 20
</select>
<select id="selectScWeanRecordById" parameterType="Long" resultMap="ScWeanRecordResult"> <select id="selectScWeanRecordById" parameterType="Long" resultMap="ScWeanRecordResult">
<include refid="selectScWeanRecordVo"/> <include refid="selectScWeanRecordVo"/>
where wr.id = #{id} where wr.id = #{id}
</select> </select>
<!-- 根据耳号查询羊只ID -->
<select id="selectSheepIdByEarNumber" parameterType="String" resultType="Long"> <select id="selectSheepIdByEarNumber" parameterType="String" resultType="Long">
select id from sheep_file where bs_manage_tags = #{earNumber} select id from sheep_file where bs_manage_tags = #{earNumber}
</select> </select>
<!-- 插入断奶记录 -->
<insert id="insertScWeanRecord" parameterType="ScWeanRecord" useGeneratedKeys="true" keyProperty="id"> <insert id="insertScWeanRecord" parameterType="ScWeanRecord" useGeneratedKeys="true" keyProperty="id">
insert into sc_wean_record insert into sc_wean_record
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -102,7 +128,6 @@
</trim> </trim>
</insert> </insert>
<!-- 更新断奶记录 -->
<update id="updateScWeanRecord" parameterType="ScWeanRecord"> <update id="updateScWeanRecord" parameterType="ScWeanRecord">
update sc_wean_record update sc_wean_record
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
@@ -119,23 +144,10 @@
where id = #{id} where id = #{id}
</update> </update>
<!-- 根据耳号更新bas_sheep表中的断奶信息 -->
<update id="updateBasSheepWeaningInfo" parameterType="ScWeanRecord">
update bas_sheep
<trim prefix="SET" suffixOverrides=",">
<if test="datetime != null">weaning_date = #{datetime},</if>
<if test="weight != null">weaning_weight = #{weight},</if>
<if test="electronicTags != null and electronicTags != ''">electronic_tags = #{electronicTags},</if>
</trim>
where manage_tags = #{earNumber}
</update>
<!-- 删除断奶记录 -->
<delete id="deleteScWeanRecordById" parameterType="Long"> <delete id="deleteScWeanRecordById" parameterType="Long">
delete from sc_wean_record where id = #{id} delete from sc_wean_record where id = #{id}
</delete> </delete>
<!-- 批量删除断奶记录 -->
<delete id="deleteScWeanRecordByIds" parameterType="String"> <delete id="deleteScWeanRecordByIds" parameterType="String">
delete from sc_wean_record where id in delete from sc_wean_record where id in
<foreach item="id" collection="array" open="(" separator="," close=")"> <foreach item="id" collection="array" open="(" separator="," close=")">