完善了死亡部分代码,优化了孕检模块,新建了流产模块
This commit is contained in:
parent
c11faeeace
commit
fdd18ba1d3
0
zhyc-module/src/main/java/com/zhyc/module/base/1
Normal file
0
zhyc-module/src/main/java/com/zhyc/module/base/1
Normal file
@ -0,0 +1,134 @@
|
||||
package com.zhyc.module.produce.breed.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.zhyc.common.annotation.Log;
|
||||
import com.zhyc.common.core.controller.BaseController;
|
||||
import com.zhyc.common.core.domain.AjaxResult;
|
||||
import com.zhyc.common.enums.BusinessType;
|
||||
import com.zhyc.module.produce.breed.domain.ScMiscarriageRecord;
|
||||
import com.zhyc.module.produce.breed.service.IScMiscarriageRecordService;
|
||||
import com.zhyc.common.utils.poi.ExcelUtil;
|
||||
import com.zhyc.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 流产记录Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-08-23
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/miscarriage/miscarriage")
|
||||
public class ScMiscarriageRecordController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IScMiscarriageRecordService scMiscarriageRecordService;
|
||||
|
||||
/**
|
||||
* 查询流产记录列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('miscarriage:miscarriage:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ScMiscarriageRecord scMiscarriageRecord)
|
||||
{
|
||||
startPage();
|
||||
List<ScMiscarriageRecord> list = scMiscarriageRecordService.selectScMiscarriageRecordList(scMiscarriageRecord);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出流产记录列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('miscarriage:miscarriage:export')")
|
||||
@Log(title = "流产记录", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ScMiscarriageRecord scMiscarriageRecord)
|
||||
{
|
||||
List<ScMiscarriageRecord> list = scMiscarriageRecordService.selectScMiscarriageRecordList(scMiscarriageRecord);
|
||||
ExcelUtil<ScMiscarriageRecord> util = new ExcelUtil<ScMiscarriageRecord>(ScMiscarriageRecord.class);
|
||||
util.exportExcel(response, list, "流产记录数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流产记录详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('miscarriage:miscarriage:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(scMiscarriageRecordService.selectScMiscarriageRecordById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据耳号查询羊只信息
|
||||
*/
|
||||
@GetMapping(value = "/sheep/{manageTags}")
|
||||
public AjaxResult getSheepInfo(@PathVariable("manageTags") String manageTags)
|
||||
{
|
||||
Map<String, Object> sheepInfo = scMiscarriageRecordService.selectSheepByManageTags(manageTags);
|
||||
return success(sheepInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流产原因字典
|
||||
*/
|
||||
@GetMapping("/reasonOptions")
|
||||
public AjaxResult getReasonOptions()
|
||||
{
|
||||
// 返回流产原因选项
|
||||
return success(new String[]{
|
||||
"利斯特氏菌病",
|
||||
"子宫积脓",
|
||||
"布鲁氏菌",
|
||||
"弧菌性流产传染性流产",
|
||||
"未知",
|
||||
"滴虫病",
|
||||
"细螺旋体病",
|
||||
"霉菌性流产"
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增流产记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('miscarriage:miscarriage:add')")
|
||||
@Log(title = "流产记录", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ScMiscarriageRecord scMiscarriageRecord)
|
||||
{
|
||||
return toAjax(scMiscarriageRecordService.insertScMiscarriageRecord(scMiscarriageRecord));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改流产记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('miscarriage:miscarriage:edit')")
|
||||
@Log(title = "流产记录", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ScMiscarriageRecord scMiscarriageRecord)
|
||||
{
|
||||
return toAjax(scMiscarriageRecordService.updateScMiscarriageRecord(scMiscarriageRecord));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流产记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('miscarriage:miscarriage:remove')")
|
||||
@Log(title = "流产记录", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(scMiscarriageRecordService.deleteScMiscarriageRecordByIds(ids));
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,7 @@ import com.zhyc.common.annotation.Log;
|
||||
import com.zhyc.common.core.controller.BaseController;
|
||||
import com.zhyc.common.core.domain.AjaxResult;
|
||||
import com.zhyc.common.enums.BusinessType;
|
||||
import com.zhyc.common.exception.ServiceException;
|
||||
import com.zhyc.module.produce.breed.domain.ScPregnancyRecord;
|
||||
import com.zhyc.module.produce.breed.service.IScPregnancyRecordService;
|
||||
import com.zhyc.common.utils.poi.ExcelUtil;
|
||||
@ -43,9 +44,14 @@ public class ScPregnancyRecordController extends BaseController
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ScPregnancyRecord scPregnancyRecord)
|
||||
{
|
||||
startPage();
|
||||
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord);
|
||||
return getDataTable(list);
|
||||
try {
|
||||
startPage();
|
||||
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord);
|
||||
return getDataTable(list);
|
||||
} catch (Exception e) {
|
||||
logger.error("查询孕检记录列表失败", e);
|
||||
return getDataTable(new java.util.ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,9 +62,13 @@ public class ScPregnancyRecordController extends BaseController
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ScPregnancyRecord scPregnancyRecord)
|
||||
{
|
||||
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord);
|
||||
ExcelUtil<ScPregnancyRecord> util = new ExcelUtil<ScPregnancyRecord>(ScPregnancyRecord.class);
|
||||
util.exportExcel(response, list, "孕检记录数据");
|
||||
try {
|
||||
List<ScPregnancyRecord> list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord);
|
||||
ExcelUtil<ScPregnancyRecord> util = new ExcelUtil<ScPregnancyRecord>(ScPregnancyRecord.class);
|
||||
util.exportExcel(response, list, "孕检记录数据");
|
||||
} catch (Exception e) {
|
||||
logger.error("导出孕检记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +78,21 @@ public class ScPregnancyRecordController extends BaseController
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(scPregnancyRecordService.selectScPregnancyRecordById(id));
|
||||
try {
|
||||
if (id == null) {
|
||||
return error("记录ID不能为空");
|
||||
}
|
||||
|
||||
ScPregnancyRecord result = scPregnancyRecordService.selectScPregnancyRecordById(id);
|
||||
if (result == null) {
|
||||
return error("记录不存在");
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取孕检记录详细信息失败,ID: " + id, e);
|
||||
return error("获取记录详细信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +103,46 @@ public class ScPregnancyRecordController extends BaseController
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ScPregnancyRecord scPregnancyRecord)
|
||||
{
|
||||
return toAjax(scPregnancyRecordService.insertScPregnancyRecord(scPregnancyRecord));
|
||||
try {
|
||||
// 基础参数校验
|
||||
if (scPregnancyRecord == null) {
|
||||
return error("请求参数不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getManageTags() == null || scPregnancyRecord.getManageTags().trim().isEmpty()) {
|
||||
return error("管理耳号不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getDatetime() == null) {
|
||||
return error("孕检日期不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getResult() == null || scPregnancyRecord.getResult().trim().isEmpty()) {
|
||||
return error("孕检结果不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getTechnician() == null || scPregnancyRecord.getTechnician().trim().isEmpty()) {
|
||||
return error("技术员不能为空");
|
||||
}
|
||||
|
||||
// 如果孕检方式为空,默认设置为B超
|
||||
if (scPregnancyRecord.getWay() == null || scPregnancyRecord.getWay().trim().isEmpty()) {
|
||||
scPregnancyRecord.setWay("B超");
|
||||
}
|
||||
|
||||
int result = scPregnancyRecordService.insertScPregnancyRecord(scPregnancyRecord);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +153,45 @@ public class ScPregnancyRecordController extends BaseController
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ScPregnancyRecord scPregnancyRecord)
|
||||
{
|
||||
return toAjax(scPregnancyRecordService.updateScPregnancyRecord(scPregnancyRecord));
|
||||
try {
|
||||
// 基础参数校验
|
||||
if (scPregnancyRecord == null) {
|
||||
return error("请求参数不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getId() == null) {
|
||||
return error("记录ID不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getManageTags() == null || scPregnancyRecord.getManageTags().trim().isEmpty()) {
|
||||
return error("管理耳号不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getDatetime() == null) {
|
||||
return error("孕检日期不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getResult() == null || scPregnancyRecord.getResult().trim().isEmpty()) {
|
||||
return error("孕检结果不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getTechnician() == null || scPregnancyRecord.getTechnician().trim().isEmpty()) {
|
||||
return error("技术员不能为空");
|
||||
}
|
||||
|
||||
int result = scPregnancyRecordService.updateScPregnancyRecord(scPregnancyRecord);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +202,24 @@ public class ScPregnancyRecordController extends BaseController
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(scPregnancyRecordService.deleteScPregnancyRecordByIds(ids));
|
||||
try {
|
||||
if (ids == null || ids.length == 0) {
|
||||
return error("删除的记录ID不能为空");
|
||||
}
|
||||
|
||||
int result = scPregnancyRecordService.deleteScPregnancyRecordByIds(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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,7 +228,47 @@ public class ScPregnancyRecordController extends BaseController
|
||||
@GetMapping("/getSheepByManageTags")
|
||||
public AjaxResult getSheepByManageTags(@RequestParam("manageTags") String manageTags)
|
||||
{
|
||||
Map<String, Object> sheepInfo = scPregnancyRecordService.getSheepByManageTags(manageTags);
|
||||
return success(sheepInfo);
|
||||
try {
|
||||
if (manageTags == null || manageTags.trim().isEmpty()) {
|
||||
return error("管理耳号不能为空");
|
||||
}
|
||||
|
||||
Map<String, Object> sheepInfo = scPregnancyRecordService.getSheepByManageTags(manageTags.trim());
|
||||
if (sheepInfo == null) {
|
||||
return error("未找到该耳号的羊只信息");
|
||||
}
|
||||
|
||||
return success(sheepInfo);
|
||||
} catch (ServiceException e) {
|
||||
return error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("查询羊只信息失败,管理耳号: " + manageTags, e);
|
||||
return error("查询羊只信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据耳号获取配种信息
|
||||
*/
|
||||
@GetMapping("/getBreedInfoByManageTags")
|
||||
public AjaxResult getBreedInfoByManageTags(@RequestParam("manageTags") String manageTags)
|
||||
{
|
||||
try {
|
||||
if (manageTags == null || manageTags.trim().isEmpty()) {
|
||||
return error("管理耳号不能为空");
|
||||
}
|
||||
|
||||
Map<String, Object> breedInfo = scPregnancyRecordService.getBreedInfoByManageTags(manageTags.trim());
|
||||
if (breedInfo == null) {
|
||||
return error("未找到该耳号的配种信息");
|
||||
}
|
||||
|
||||
return success(breedInfo);
|
||||
} catch (ServiceException e) {
|
||||
return error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("查询配种信息失败,管理耳号: " + manageTags, e);
|
||||
return error("查询配种信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,7 @@ import com.zhyc.common.annotation.Log;
|
||||
import com.zhyc.common.core.controller.BaseController;
|
||||
import com.zhyc.common.core.domain.AjaxResult;
|
||||
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.service.IScSheepDeathService;
|
||||
import com.zhyc.common.utils.poi.ExcelUtil;
|
||||
@ -42,9 +43,14 @@ public class ScSheepDeathController extends BaseController
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ScSheepDeath scSheepDeath)
|
||||
{
|
||||
startPage();
|
||||
List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath);
|
||||
return getDataTable(list);
|
||||
try {
|
||||
startPage();
|
||||
List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath);
|
||||
return getDataTable(list);
|
||||
} catch (Exception e) {
|
||||
logger.error("查询羊只死淘记录列表失败", e);
|
||||
return getDataTable(new java.util.ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,11 +60,20 @@ public class ScSheepDeathController extends BaseController
|
||||
@GetMapping("/sheepInfo/{manageTags}")
|
||||
public AjaxResult getSheepInfo(@PathVariable("manageTags") String manageTags)
|
||||
{
|
||||
Map<String, Object> sheepInfo = scSheepDeathService.selectSheepFileByManageTags(manageTags);
|
||||
if (sheepInfo != null) {
|
||||
return success(sheepInfo);
|
||||
} else {
|
||||
return error("未找到该耳号对应的羊只信息");
|
||||
try {
|
||||
if (manageTags == null || manageTags.trim().isEmpty()) {
|
||||
return error("管理耳号不能为空");
|
||||
}
|
||||
|
||||
Map<String, Object> sheepInfo = scSheepDeathService.selectSheepFileByManageTags(manageTags.trim());
|
||||
if (sheepInfo != null) {
|
||||
return success(sheepInfo);
|
||||
} else {
|
||||
return error("未找到该耳号对应的羊只信息");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("查询羊只信息失败,管理耳号: " + manageTags, e);
|
||||
return error("查询羊只信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,9 +85,14 @@ public class ScSheepDeathController extends BaseController
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ScSheepDeath scSheepDeath)
|
||||
{
|
||||
List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath);
|
||||
ExcelUtil<ScSheepDeath> util = new ExcelUtil<ScSheepDeath>(ScSheepDeath.class);
|
||||
util.exportExcel(response, list, "羊只死淘记录数据");
|
||||
try {
|
||||
List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath);
|
||||
ExcelUtil<ScSheepDeath> util = new ExcelUtil<ScSheepDeath>(ScSheepDeath.class);
|
||||
util.exportExcel(response, list, "羊只死淘记录数据");
|
||||
} catch (Exception e) {
|
||||
logger.error("导出羊只死淘记录失败", e);
|
||||
// 可以在这里返回错误响应
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +102,21 @@ public class ScSheepDeathController extends BaseController
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(scSheepDeathService.selectScSheepDeathById(id));
|
||||
try {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +127,33 @@ public class ScSheepDeathController extends BaseController
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ScSheepDeath scSheepDeath)
|
||||
{
|
||||
return toAjax(scSheepDeathService.insertScSheepDeath(scSheepDeath));
|
||||
try {
|
||||
// 基础参数校验
|
||||
if (scSheepDeath == null) {
|
||||
return error("请求参数不能为空");
|
||||
}
|
||||
|
||||
if (scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) {
|
||||
return error("管理耳号不能为空");
|
||||
}
|
||||
|
||||
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) {
|
||||
logger.error("新增羊只死淘记录失败", e);
|
||||
return error("新增失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +164,37 @@ public class ScSheepDeathController extends BaseController
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ScSheepDeath scSheepDeath)
|
||||
{
|
||||
return toAjax(scSheepDeathService.updateScSheepDeath(scSheepDeath));
|
||||
try {
|
||||
// 基础参数校验
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,6 +205,23 @@ public class ScSheepDeathController extends BaseController
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(scSheepDeathService.deleteScSheepDeathByIds(ids));
|
||||
try {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,308 @@
|
||||
package com.zhyc.module.produce.breed.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.zhyc.common.annotation.Excel;
|
||||
import com.zhyc.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 流产记录对象 sc_miscarriage_record
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-08-23
|
||||
*/
|
||||
public class ScMiscarriageRecord extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 羊只id */
|
||||
private String sheepId;
|
||||
|
||||
/** 事件日期 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "事件日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date datetime;
|
||||
|
||||
/** 备注 */
|
||||
@Excel(name = "备注")
|
||||
private String comment;
|
||||
|
||||
/** 技术员 */
|
||||
@Excel(name = "技术员")
|
||||
private String technician;
|
||||
|
||||
/** 流产原因 */
|
||||
@Excel(name = "流产原因")
|
||||
private String reason;
|
||||
|
||||
/** 是否见胎 (1-是, 2-复检无胎, 3-返情) */
|
||||
@Excel(name = "是否见胎", readConverterExp = "1=是,2=复检无胎,3=返情")
|
||||
private Long exposeType;
|
||||
|
||||
/** 是否列胎次 (1-是, 0-否) */
|
||||
@Excel(name = "是否列胎次", readConverterExp = "1=是,0=否")
|
||||
private Long status;
|
||||
|
||||
/** 流产羔羊数 */
|
||||
@Excel(name = "流产羔羊数")
|
||||
private Long miscaLamb;
|
||||
|
||||
// 以下是关联查询字段,不存储到数据库
|
||||
/** 管理耳号 */
|
||||
@Excel(name = "耳号")
|
||||
private String bsManageTags;
|
||||
|
||||
/** 品种 */
|
||||
@Excel(name = "品种")
|
||||
private String variety;
|
||||
|
||||
/** 事件类型 */
|
||||
@Excel(name = "事件类型")
|
||||
private String eventType = "流产";
|
||||
|
||||
/** 配种类型ID */
|
||||
private Integer matingTypeId;
|
||||
|
||||
/** 配种类型 */
|
||||
@Excel(name = "配种类型")
|
||||
private String matingTypeName;
|
||||
|
||||
/** 配种日期 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "配种日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date matingDate;
|
||||
|
||||
/** 胎次 */
|
||||
@Excel(name = "胎次")
|
||||
private Integer parity;
|
||||
|
||||
/** 配种公羊品种 */
|
||||
@Excel(name = "配种公羊品种")
|
||||
private String ramVariety;
|
||||
|
||||
/** 月龄 */
|
||||
@Excel(name = "月龄")
|
||||
private Long monthAge;
|
||||
|
||||
/** 流产时怀孕天数 */
|
||||
@Excel(name = "流产时怀孕天数")
|
||||
private Integer pregnantDays;
|
||||
|
||||
/** 当前羊舍 */
|
||||
@Excel(name = "当前羊舍")
|
||||
private String sheepfoldName;
|
||||
|
||||
/** 所在牧场 */
|
||||
@Excel(name = "所在牧场")
|
||||
private String drRanch;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setSheepId(String sheepId)
|
||||
{
|
||||
this.sheepId = sheepId;
|
||||
}
|
||||
|
||||
public String getSheepId()
|
||||
{
|
||||
return sheepId;
|
||||
}
|
||||
|
||||
public void setDatetime(Date datetime)
|
||||
{
|
||||
this.datetime = datetime;
|
||||
}
|
||||
|
||||
public Date getDatetime()
|
||||
{
|
||||
return datetime;
|
||||
}
|
||||
|
||||
public void setComment(String comment)
|
||||
{
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getComment()
|
||||
{
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setTechnician(String technician)
|
||||
{
|
||||
this.technician = technician;
|
||||
}
|
||||
|
||||
public String getTechnician()
|
||||
{
|
||||
return technician;
|
||||
}
|
||||
|
||||
public void setReason(String reason)
|
||||
{
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public String getReason()
|
||||
{
|
||||
return reason;
|
||||
}
|
||||
|
||||
public void setExposeType(Long exposeType)
|
||||
{
|
||||
this.exposeType = exposeType;
|
||||
}
|
||||
|
||||
public Long getExposeType()
|
||||
{
|
||||
return exposeType;
|
||||
}
|
||||
|
||||
public void setStatus(Long status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setMiscaLamb(Long miscaLamb)
|
||||
{
|
||||
this.miscaLamb = miscaLamb;
|
||||
}
|
||||
|
||||
public Long getMiscaLamb()
|
||||
{
|
||||
return miscaLamb;
|
||||
}
|
||||
|
||||
public String getBsManageTags() {
|
||||
return bsManageTags;
|
||||
}
|
||||
|
||||
public void setBsManageTags(String bsManageTags) {
|
||||
this.bsManageTags = bsManageTags;
|
||||
}
|
||||
|
||||
public String getVariety() {
|
||||
return variety;
|
||||
}
|
||||
|
||||
public void setVariety(String variety) {
|
||||
this.variety = variety;
|
||||
}
|
||||
|
||||
public String getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public void setEventType(String eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public Integer getMatingTypeId() {
|
||||
return matingTypeId;
|
||||
}
|
||||
|
||||
public void setMatingTypeId(Integer matingTypeId) {
|
||||
this.matingTypeId = matingTypeId;
|
||||
}
|
||||
|
||||
public String getMatingTypeName() {
|
||||
return matingTypeName;
|
||||
}
|
||||
|
||||
public void setMatingTypeName(String matingTypeName) {
|
||||
this.matingTypeName = matingTypeName;
|
||||
}
|
||||
|
||||
public Date getMatingDate() {
|
||||
return matingDate;
|
||||
}
|
||||
|
||||
public void setMatingDate(Date matingDate) {
|
||||
this.matingDate = matingDate;
|
||||
}
|
||||
|
||||
public Integer getParity() {
|
||||
return parity;
|
||||
}
|
||||
|
||||
public void setParity(Integer parity) {
|
||||
this.parity = parity;
|
||||
}
|
||||
|
||||
public String getRamVariety() {
|
||||
return ramVariety;
|
||||
}
|
||||
|
||||
public void setRamVariety(String ramVariety) {
|
||||
this.ramVariety = ramVariety;
|
||||
}
|
||||
|
||||
public Long getMonthAge() {
|
||||
return monthAge;
|
||||
}
|
||||
|
||||
public void setMonthAge(Long monthAge) {
|
||||
this.monthAge = monthAge;
|
||||
}
|
||||
|
||||
public Integer getPregnantDays() {
|
||||
return pregnantDays;
|
||||
}
|
||||
|
||||
public void setPregnantDays(Integer pregnantDays) {
|
||||
this.pregnantDays = pregnantDays;
|
||||
}
|
||||
|
||||
public String getSheepfoldName() {
|
||||
return sheepfoldName;
|
||||
}
|
||||
|
||||
public void setSheepfoldName(String sheepfoldName) {
|
||||
this.sheepfoldName = sheepfoldName;
|
||||
}
|
||||
|
||||
public String getDrRanch() {
|
||||
return drRanch;
|
||||
}
|
||||
|
||||
public void setDrRanch(String drRanch) {
|
||||
this.drRanch = drRanch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("sheepId", getSheepId())
|
||||
.append("datetime", getDatetime())
|
||||
.append("comment", getComment())
|
||||
.append("technician", getTechnician())
|
||||
.append("reason", getReason())
|
||||
.append("exposeType", getExposeType())
|
||||
.append("status", getStatus())
|
||||
.append("miscaLamb", getMiscaLamb())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("bsManageTags", getBsManageTags())
|
||||
.append("variety", getVariety())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@ -116,4 +116,7 @@ public class ScPregnancyRecord extends BaseEntity
|
||||
@Excel(name = "所在牧场")
|
||||
private String ranchName;
|
||||
|
||||
/** 配后天数 */
|
||||
@Excel(name = "配后天数")
|
||||
private Integer daysAfterMating;
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
package com.zhyc.module.produce.breed.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.zhyc.module.produce.breed.domain.ScMiscarriageRecord;
|
||||
|
||||
/**
|
||||
* 流产记录Mapper接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-08-23
|
||||
*/
|
||||
public interface ScMiscarriageRecordMapper
|
||||
{
|
||||
/**
|
||||
* 查询流产记录
|
||||
*
|
||||
* @param id 流产记录主键
|
||||
* @return 流产记录
|
||||
*/
|
||||
public ScMiscarriageRecord selectScMiscarriageRecordById(Long id);
|
||||
|
||||
/**
|
||||
* 查询流产记录列表
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 流产记录集合
|
||||
*/
|
||||
public List<ScMiscarriageRecord> selectScMiscarriageRecordList(ScMiscarriageRecord scMiscarriageRecord);
|
||||
|
||||
/**
|
||||
* 新增流产记录
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord);
|
||||
|
||||
/**
|
||||
* 修改流产记录
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord);
|
||||
|
||||
/**
|
||||
* 删除流产记录
|
||||
*
|
||||
* @param id 流产记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteScMiscarriageRecordById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除流产记录
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteScMiscarriageRecordByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根据耳号查询羊只信息
|
||||
*
|
||||
* @param manageTags 管理耳号
|
||||
* @return 羊只信息
|
||||
*/
|
||||
public Map<String, Object> selectSheepByManageTags(String manageTags);
|
||||
}
|
||||
@ -2,6 +2,7 @@ package com.zhyc.module.produce.breed.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.zhyc.module.produce.breed.domain.ScPregnancyRecord;
|
||||
|
||||
/**
|
||||
@ -68,6 +69,14 @@ public interface ScPregnancyRecordMapper
|
||||
*/
|
||||
public Map<String, Object> selectSheepByManageTags(String manageTags);
|
||||
|
||||
/**
|
||||
* 根据耳号获取配种信息
|
||||
*
|
||||
* @param manageTags 耳号
|
||||
* @return 配种信息
|
||||
*/
|
||||
public Map<String, Object> selectBreedInfoByManageTags(String manageTags);
|
||||
|
||||
/**
|
||||
* 更新羊只基础表中的孕检相关字段
|
||||
*
|
||||
|
||||
@ -2,6 +2,7 @@ package com.zhyc.module.produce.breed.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.zhyc.module.produce.breed.domain.ScSheepDeath;
|
||||
|
||||
/**
|
||||
@ -67,4 +68,13 @@ public interface ScSheepDeathMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteScSheepDeathByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 更新羊只状态
|
||||
*
|
||||
* @param sheepId 羊只ID
|
||||
* @param status 状态
|
||||
* @return 更新结果
|
||||
*/
|
||||
public int updateSheepFileStatus(@Param("sheepId") Long sheepId, @Param("status") String status);
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
package com.zhyc.module.produce.breed.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.zhyc.module.produce.breed.domain.ScMiscarriageRecord;
|
||||
|
||||
/**
|
||||
* 流产记录Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-08-23
|
||||
*/
|
||||
public interface IScMiscarriageRecordService
|
||||
{
|
||||
/**
|
||||
* 查询流产记录
|
||||
*
|
||||
* @param id 流产记录主键
|
||||
* @return 流产记录
|
||||
*/
|
||||
public ScMiscarriageRecord selectScMiscarriageRecordById(Long id);
|
||||
|
||||
/**
|
||||
* 查询流产记录列表
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 流产记录集合
|
||||
*/
|
||||
public List<ScMiscarriageRecord> selectScMiscarriageRecordList(ScMiscarriageRecord scMiscarriageRecord);
|
||||
|
||||
/**
|
||||
* 新增流产记录
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord);
|
||||
|
||||
/**
|
||||
* 修改流产记录
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord);
|
||||
|
||||
/**
|
||||
* 批量删除流产记录
|
||||
*
|
||||
* @param ids 需要删除的流产记录主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteScMiscarriageRecordByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除流产记录信息
|
||||
*
|
||||
* @param id 流产记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteScMiscarriageRecordById(Long id);
|
||||
|
||||
/**
|
||||
* 根据耳号查询羊只信息
|
||||
*
|
||||
* @param manageTags 管理耳号
|
||||
* @return 羊只信息
|
||||
*/
|
||||
public Map<String, Object> selectSheepByManageTags(String manageTags);
|
||||
}
|
||||
@ -67,4 +67,12 @@ public interface IScPregnancyRecordService
|
||||
* @return 羊只信息
|
||||
*/
|
||||
public Map<String, Object> getSheepByManageTags(String manageTags);
|
||||
|
||||
/**
|
||||
* 根据耳号获取配种信息
|
||||
*
|
||||
* @param manageTags 耳号
|
||||
* @return 配种信息
|
||||
*/
|
||||
public Map<String, Object> getBreedInfoByManageTags(String manageTags);
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
package com.zhyc.module.produce.breed.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.zhyc.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.zhyc.module.produce.breed.mapper.ScMiscarriageRecordMapper;
|
||||
import com.zhyc.module.produce.breed.domain.ScMiscarriageRecord;
|
||||
import com.zhyc.module.produce.breed.service.IScMiscarriageRecordService;
|
||||
|
||||
/**
|
||||
* 流产记录Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-08-23
|
||||
*/
|
||||
@Service
|
||||
public class ScMiscarriageRecordServiceImpl implements IScMiscarriageRecordService
|
||||
{
|
||||
@Autowired
|
||||
private ScMiscarriageRecordMapper scMiscarriageRecordMapper;
|
||||
|
||||
/**
|
||||
* 查询流产记录
|
||||
*
|
||||
* @param id 流产记录主键
|
||||
* @return 流产记录
|
||||
*/
|
||||
@Override
|
||||
public ScMiscarriageRecord selectScMiscarriageRecordById(Long id)
|
||||
{
|
||||
return scMiscarriageRecordMapper.selectScMiscarriageRecordById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流产记录列表
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 流产记录
|
||||
*/
|
||||
@Override
|
||||
public List<ScMiscarriageRecord> selectScMiscarriageRecordList(ScMiscarriageRecord scMiscarriageRecord)
|
||||
{
|
||||
return scMiscarriageRecordMapper.selectScMiscarriageRecordList(scMiscarriageRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增流产记录
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord)
|
||||
{
|
||||
scMiscarriageRecord.setCreateTime(DateUtils.getNowDate());
|
||||
return scMiscarriageRecordMapper.insertScMiscarriageRecord(scMiscarriageRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改流产记录
|
||||
*
|
||||
* @param scMiscarriageRecord 流产记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateScMiscarriageRecord(ScMiscarriageRecord scMiscarriageRecord)
|
||||
{
|
||||
return scMiscarriageRecordMapper.updateScMiscarriageRecord(scMiscarriageRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除流产记录
|
||||
*
|
||||
* @param ids 需要删除的流产记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteScMiscarriageRecordByIds(Long[] ids)
|
||||
{
|
||||
return scMiscarriageRecordMapper.deleteScMiscarriageRecordByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流产记录信息
|
||||
*
|
||||
* @param id 流产记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteScMiscarriageRecordById(Long id)
|
||||
{
|
||||
return scMiscarriageRecordMapper.deleteScMiscarriageRecordById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据耳号查询羊只信息
|
||||
*
|
||||
* @param manageTags 管理耳号
|
||||
* @return 羊只信息
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> selectSheepByManageTags(String manageTags)
|
||||
{
|
||||
return scMiscarriageRecordMapper.selectSheepByManageTags(manageTags);
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.zhyc.common.utils.DateUtils;
|
||||
import com.zhyc.common.exception.ServiceException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -56,24 +57,50 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insertScPregnancyRecord(ScPregnancyRecord scPregnancyRecord)
|
||||
{
|
||||
// 参数校验
|
||||
if (scPregnancyRecord.getManageTags() == null || scPregnancyRecord.getManageTags().trim().isEmpty()) {
|
||||
throw new ServiceException("管理耳号不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getDatetime() == null) {
|
||||
throw new ServiceException("孕检日期不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getResult() == null || scPregnancyRecord.getResult().trim().isEmpty()) {
|
||||
throw new ServiceException("孕检结果不能为空");
|
||||
}
|
||||
|
||||
// 根据耳号获取羊只信息并验证
|
||||
Map<String, Object> sheepInfo = scPregnancyRecordMapper.selectSheepByManageTags(scPregnancyRecord.getManageTags().trim());
|
||||
if (sheepInfo == null) {
|
||||
throw new ServiceException("管理耳号[" + scPregnancyRecord.getManageTags() + "]对应的羊只不存在");
|
||||
}
|
||||
|
||||
Long sheepId = sheepInfo.get("id") != null ? Long.valueOf(sheepInfo.get("id").toString()) : null;
|
||||
if (sheepId == null) {
|
||||
throw new ServiceException("无法获取羊只ID,请检查数据完整性");
|
||||
}
|
||||
scPregnancyRecord.setSheepId(sheepId);
|
||||
|
||||
// 验证孕检结果和胎儿数量的一致性
|
||||
validatePregnancyResult(scPregnancyRecord);
|
||||
|
||||
// 设置默认值
|
||||
scPregnancyRecord.setCreateTime(DateUtils.getNowDate());
|
||||
scPregnancyRecord.setIsDelete(0);
|
||||
|
||||
// 根据耳号获取羊只ID
|
||||
if (scPregnancyRecord.getManageTags() != null) {
|
||||
Map<String, Object> sheepInfo = scPregnancyRecordMapper.selectSheepByManageTags(scPregnancyRecord.getManageTags());
|
||||
if (sheepInfo != null && sheepInfo.get("id") != null) {
|
||||
scPregnancyRecord.setSheepId(Long.valueOf(sheepInfo.get("id").toString()));
|
||||
}
|
||||
// 如果孕检方式为空,默认设置为B超
|
||||
if (scPregnancyRecord.getWay() == null || scPregnancyRecord.getWay().trim().isEmpty()) {
|
||||
scPregnancyRecord.setWay("B超");
|
||||
}
|
||||
|
||||
int result = scPregnancyRecordMapper.insertScPregnancyRecord(scPregnancyRecord);
|
||||
|
||||
// 如果孕检结果为怀孕,更新羊只基础表相关字段
|
||||
if ("怀孕".equals(scPregnancyRecord.getResult()) && scPregnancyRecord.getSheepId() != null) {
|
||||
if ("怀孕".equals(scPregnancyRecord.getResult()) && result > 0) {
|
||||
updateSheepPregnancyStatus(scPregnancyRecord);
|
||||
}
|
||||
|
||||
@ -87,29 +114,67 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int updateScPregnancyRecord(ScPregnancyRecord scPregnancyRecord)
|
||||
{
|
||||
scPregnancyRecord.setUpdateTime(DateUtils.getNowDate());
|
||||
|
||||
// 根据耳号获取羊只ID
|
||||
if (scPregnancyRecord.getManageTags() != null) {
|
||||
Map<String, Object> sheepInfo = scPregnancyRecordMapper.selectSheepByManageTags(scPregnancyRecord.getManageTags());
|
||||
if (sheepInfo != null && sheepInfo.get("id") != null) {
|
||||
scPregnancyRecord.setSheepId(Long.valueOf(sheepInfo.get("id").toString()));
|
||||
}
|
||||
// 参数校验
|
||||
if (scPregnancyRecord.getId() == null) {
|
||||
throw new ServiceException("记录ID不能为空");
|
||||
}
|
||||
|
||||
if (scPregnancyRecord.getManageTags() == null || scPregnancyRecord.getManageTags().trim().isEmpty()) {
|
||||
throw new ServiceException("管理耳号不能为空");
|
||||
}
|
||||
|
||||
// 根据耳号获取羊只信息并验证
|
||||
Map<String, Object> sheepInfo = scPregnancyRecordMapper.selectSheepByManageTags(scPregnancyRecord.getManageTags().trim());
|
||||
if (sheepInfo == null) {
|
||||
throw new ServiceException("管理耳号[" + scPregnancyRecord.getManageTags() + "]对应的羊只不存在");
|
||||
}
|
||||
|
||||
Long sheepId = sheepInfo.get("id") != null ? Long.valueOf(sheepInfo.get("id").toString()) : null;
|
||||
if (sheepId == null) {
|
||||
throw new ServiceException("无法获取羊只ID,请检查数据完整性");
|
||||
}
|
||||
scPregnancyRecord.setSheepId(sheepId);
|
||||
|
||||
// 验证孕检结果和胎儿数量的一致性
|
||||
validatePregnancyResult(scPregnancyRecord);
|
||||
|
||||
scPregnancyRecord.setUpdateTime(DateUtils.getNowDate());
|
||||
|
||||
int result = scPregnancyRecordMapper.updateScPregnancyRecord(scPregnancyRecord);
|
||||
|
||||
// 如果孕检结果为怀孕,更新羊只基础表相关字段
|
||||
if ("怀孕".equals(scPregnancyRecord.getResult()) && scPregnancyRecord.getSheepId() != null) {
|
||||
if ("怀孕".equals(scPregnancyRecord.getResult()) && result > 0) {
|
||||
updateSheepPregnancyStatus(scPregnancyRecord);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证孕检结果和胎儿数量的一致性
|
||||
*
|
||||
* @param scPregnancyRecord 孕检记录
|
||||
*/
|
||||
private void validatePregnancyResult(ScPregnancyRecord scPregnancyRecord) {
|
||||
String result = scPregnancyRecord.getResult();
|
||||
Integer fetusCount = scPregnancyRecord.getFetusCount();
|
||||
|
||||
if ("怀孕".equals(result)) {
|
||||
if (fetusCount == null || fetusCount <= 0) {
|
||||
throw new ServiceException("孕检结果为怀孕时,胎儿数量必须填写且大于0");
|
||||
}
|
||||
if (fetusCount > 10) {
|
||||
throw new ServiceException("胎儿数量不能超过10个");
|
||||
}
|
||||
} else if ("未孕".equals(result) || "流产".equals(result)) {
|
||||
// 未孕或流产时,胎儿数量应为0或null
|
||||
scPregnancyRecord.setFetusCount(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除孕检记录
|
||||
*
|
||||
@ -117,8 +182,12 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteScPregnancyRecordByIds(Long[] ids)
|
||||
{
|
||||
if (ids == null || ids.length == 0) {
|
||||
throw new ServiceException("删除的记录ID不能为空");
|
||||
}
|
||||
return scPregnancyRecordMapper.deleteScPregnancyRecordByIds(ids);
|
||||
}
|
||||
|
||||
@ -129,8 +198,12 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteScPregnancyRecordById(Long id)
|
||||
{
|
||||
if (id == null) {
|
||||
throw new ServiceException("删除的记录ID不能为空");
|
||||
}
|
||||
return scPregnancyRecordMapper.deleteScPregnancyRecordById(id);
|
||||
}
|
||||
|
||||
@ -143,7 +216,25 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService
|
||||
@Override
|
||||
public Map<String, Object> getSheepByManageTags(String manageTags)
|
||||
{
|
||||
return scPregnancyRecordMapper.selectSheepByManageTags(manageTags);
|
||||
if (manageTags == null || manageTags.trim().isEmpty()) {
|
||||
throw new ServiceException("管理耳号不能为空");
|
||||
}
|
||||
return scPregnancyRecordMapper.selectSheepByManageTags(manageTags.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据耳号获取配种信息
|
||||
*
|
||||
* @param manageTags 耳号
|
||||
* @return 配种信息
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getBreedInfoByManageTags(String manageTags)
|
||||
{
|
||||
if (manageTags == null || manageTags.trim().isEmpty()) {
|
||||
throw new ServiceException("管理耳号不能为空");
|
||||
}
|
||||
return scPregnancyRecordMapper.selectBreedInfoByManageTags(manageTags.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,27 +243,32 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService
|
||||
* @param scPregnancyRecord 孕检记录
|
||||
*/
|
||||
private void updateSheepPregnancyStatus(ScPregnancyRecord scPregnancyRecord) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("sheepId", scPregnancyRecord.getSheepId());
|
||||
params.put("pregDate", scPregnancyRecord.getDatetime());
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("sheepId", scPregnancyRecord.getSheepId());
|
||||
params.put("pregDate", scPregnancyRecord.getDatetime());
|
||||
|
||||
// 设置繁育状态为怀孕状态(假设怀孕状态ID为2)
|
||||
params.put("breedStatusId", 2);
|
||||
// 设置繁育状态为怀孕状态(假设怀孕状态ID为2)
|
||||
params.put("breedStatusId", 2);
|
||||
|
||||
// 计算预产日期(羊的妊娠期大约150天)
|
||||
if (scPregnancyRecord.getDatetime() != null) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(scPregnancyRecord.getDatetime());
|
||||
cal.add(Calendar.DAY_OF_YEAR, 150);
|
||||
params.put("expectedDate", cal.getTime());
|
||||
// 计算预产日期(羊的妊娠期大约150天)
|
||||
if (scPregnancyRecord.getDatetime() != null) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(scPregnancyRecord.getDatetime());
|
||||
cal.add(Calendar.DAY_OF_YEAR, 150);
|
||||
params.put("expectedDate", cal.getTime());
|
||||
}
|
||||
|
||||
// 计算怀孕天数
|
||||
if (scPregnancyRecord.getDatetime() != null) {
|
||||
long days = (System.currentTimeMillis() - scPregnancyRecord.getDatetime().getTime()) / (1000 * 60 * 60 * 24);
|
||||
params.put("gestationDay", (int) days);
|
||||
}
|
||||
|
||||
scPregnancyRecordMapper.updateSheepPregnancyInfo(params);
|
||||
} catch (Exception e) {
|
||||
// 记录日志但不影响主流程
|
||||
System.err.println("更新羊只怀孕状态失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 计算怀孕天数
|
||||
if (scPregnancyRecord.getDatetime() != null) {
|
||||
long days = (System.currentTimeMillis() - scPregnancyRecord.getDatetime().getTime()) / (1000 * 60 * 60 * 24);
|
||||
params.put("gestationDay", (int) days);
|
||||
}
|
||||
|
||||
scPregnancyRecordMapper.updateSheepPregnancyInfo(params);
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,13 @@
|
||||
package com.zhyc.module.produce.breed.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.zhyc.common.utils.DateUtils;
|
||||
import com.zhyc.common.exception.ServiceException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.zhyc.module.produce.breed.mapper.ScSheepDeathMapper;
|
||||
import com.zhyc.module.produce.breed.domain.ScSheepDeath;
|
||||
import com.zhyc.module.produce.breed.service.IScSheepDeathService;
|
||||
@ -33,19 +36,7 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
||||
ScSheepDeath scSheepDeath = 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);
|
||||
}
|
||||
fillSheepDisplayInfo(scSheepDeath);
|
||||
}
|
||||
return scSheepDeath;
|
||||
}
|
||||
@ -63,24 +54,33 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
||||
// 为列表中的每条记录填充显示字段
|
||||
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);
|
||||
}
|
||||
fillSheepDisplayInfo(death);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充羊只显示信息(提取公共方法避免重复代码)
|
||||
*
|
||||
* @param scSheepDeath 死淘记录对象
|
||||
*/
|
||||
private void fillSheepDisplayInfo(ScSheepDeath scSheepDeath) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据管理耳号查询sheep_file视图信息
|
||||
*
|
||||
@ -100,23 +100,55 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insertScSheepDeath(ScSheepDeath scSheepDeath)
|
||||
{
|
||||
// 参数校验
|
||||
if (scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) {
|
||||
throw new ServiceException("管理耳号不能为空");
|
||||
}
|
||||
|
||||
// 设置事件类型默认为"死亡"
|
||||
if (scSheepDeath.getEventType() == null || scSheepDeath.getEventType().isEmpty()) {
|
||||
scSheepDeath.setEventType("死亡");
|
||||
}
|
||||
|
||||
// 如果有管理耳号,查询并设置羊只ID
|
||||
if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) {
|
||||
Map<String, Object> sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags());
|
||||
if (sheepInfo != null) {
|
||||
scSheepDeath.setSheepId(sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null);
|
||||
}
|
||||
// 查询羊只信息并验证是否存在
|
||||
Map<String, Object> sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags().trim());
|
||||
if (sheepInfo == null) {
|
||||
throw new ServiceException("管理耳号[" + scSheepDeath.getManageTags() + "]对应的羊只不存在");
|
||||
}
|
||||
|
||||
// 获取羊只ID
|
||||
Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null;
|
||||
if (sheepId == null) {
|
||||
throw new ServiceException("无法获取羊只ID,请检查数据完整性");
|
||||
}
|
||||
scSheepDeath.setSheepId(sheepId);
|
||||
|
||||
// 检查该羊只是否已经有死淘记录
|
||||
ScSheepDeath existingDeath = new ScSheepDeath();
|
||||
existingDeath.setSheepId(sheepId);
|
||||
existingDeath.setIsDelete(0L); // 只查询未删除的记录
|
||||
List<ScSheepDeath> existingList = scSheepDeathMapper.selectScSheepDeathList(existingDeath);
|
||||
if (!existingList.isEmpty()) {
|
||||
throw new ServiceException("该羊只已存在死淘记录,不能重复添加");
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
scSheepDeath.setCreateTime(DateUtils.getNowDate());
|
||||
return scSheepDeathMapper.insertScSheepDeath(scSheepDeath);
|
||||
scSheepDeath.setIsDelete(0L);
|
||||
|
||||
// 插入死淘记录
|
||||
int result = scSheepDeathMapper.insertScSheepDeath(scSheepDeath);
|
||||
|
||||
if (result > 0) {
|
||||
// 更新羊只状态为已死淘/已淘汰
|
||||
String newStatus = "死亡".equals(scSheepDeath.getEventType()) ? "已死淘" : "已淘汰";
|
||||
updateSheepStatus(sheepId, newStatus);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,18 +158,91 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int updateScSheepDeath(ScSheepDeath scSheepDeath)
|
||||
{
|
||||
// 如果管理耳号发生变化,重新查询并设置羊只ID
|
||||
if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) {
|
||||
Map<String, Object> sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags());
|
||||
if (sheepInfo != null) {
|
||||
scSheepDeath.setSheepId(sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null);
|
||||
// 参数校验
|
||||
if (scSheepDeath.getId() == null) {
|
||||
throw new ServiceException("记录ID不能为空");
|
||||
}
|
||||
|
||||
if (scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) {
|
||||
throw new ServiceException("管理耳号不能为空");
|
||||
}
|
||||
|
||||
// 获取原记录
|
||||
ScSheepDeath originalRecord = scSheepDeathMapper.selectScSheepDeathById(scSheepDeath.getId());
|
||||
if (originalRecord == null) {
|
||||
throw new ServiceException("原记录不存在");
|
||||
}
|
||||
|
||||
// 查询新的羊只信息并验证是否存在
|
||||
Map<String, Object> sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags().trim());
|
||||
if (sheepInfo == null) {
|
||||
throw new ServiceException("管理耳号[" + scSheepDeath.getManageTags() + "]对应的羊只不存在");
|
||||
}
|
||||
|
||||
Long newSheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null;
|
||||
if (newSheepId == null) {
|
||||
throw new ServiceException("无法获取羊只ID,请检查数据完整性");
|
||||
}
|
||||
|
||||
// 如果更换了羊只,需要检查新羊只是否已有死淘记录
|
||||
if (!newSheepId.equals(originalRecord.getSheepId())) {
|
||||
ScSheepDeath checkDeath = new ScSheepDeath();
|
||||
checkDeath.setSheepId(newSheepId);
|
||||
checkDeath.setIsDelete(0L);
|
||||
List<ScSheepDeath> existingList = scSheepDeathMapper.selectScSheepDeathList(checkDeath);
|
||||
// 排除当前记录
|
||||
existingList = existingList.stream()
|
||||
.filter(death -> !death.getId().equals(scSheepDeath.getId()))
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
if (!existingList.isEmpty()) {
|
||||
throw new ServiceException("新的羊只已存在其他死淘记录");
|
||||
}
|
||||
}
|
||||
|
||||
scSheepDeath.setSheepId(newSheepId);
|
||||
scSheepDeath.setUpdateTime(DateUtils.getNowDate());
|
||||
return scSheepDeathMapper.updateScSheepDeath(scSheepDeath);
|
||||
|
||||
int result = scSheepDeathMapper.updateScSheepDeath(scSheepDeath);
|
||||
|
||||
if (result > 0) {
|
||||
// 如果更换了羊只,需要更新状态
|
||||
if (!newSheepId.equals(originalRecord.getSheepId())) {
|
||||
// 恢复原羊只状态(根据业务逻辑决定恢复到什么状态)
|
||||
updateSheepStatus(originalRecord.getSheepId(), "正常");
|
||||
|
||||
// 设置新羊只状态
|
||||
String newStatus = "死亡".equals(scSheepDeath.getEventType()) ? "已死淘" : "已淘汰";
|
||||
updateSheepStatus(newSheepId, newStatus);
|
||||
} else if (!originalRecord.getEventType().equals(scSheepDeath.getEventType())) {
|
||||
// 羊只没变,但事件类型改变,更新状态
|
||||
String newStatus = "死亡".equals(scSheepDeath.getEventType()) ? "已死淘" : "已淘汰";
|
||||
updateSheepStatus(newSheepId, newStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新羊只状态
|
||||
*
|
||||
* @param sheepId 羊只ID
|
||||
* @param status 新状态
|
||||
*/
|
||||
private void updateSheepStatus(Long sheepId, String status) {
|
||||
try {
|
||||
// 直接通过现有mapper更新sheep_file表的状态
|
||||
// 这里需要在ScSheepDeathMapper中添加一个更新sheep_file状态的方法
|
||||
scSheepDeathMapper.updateSheepFileStatus(sheepId, status);
|
||||
} catch (Exception e) {
|
||||
// 记录日志但不影响主流程,因为死淘记录已经保存成功
|
||||
System.err.println("更新羊只状态失败: " + e.getMessage());
|
||||
// 在实际项目中应该使用日志框架记录
|
||||
// log.error("更新羊只状态失败, sheepId: {}, status: {}, error: {}", sheepId, status, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,9 +252,34 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteScSheepDeathByIds(Long[] ids)
|
||||
{
|
||||
return scSheepDeathMapper.deleteScSheepDeathByIds(ids);
|
||||
if (ids == null || ids.length == 0) {
|
||||
throw new ServiceException("删除的记录ID不能为空");
|
||||
}
|
||||
|
||||
// 获取要删除的记录,用于恢复羊只状态
|
||||
List<ScSheepDeath> toDeleteRecords = new ArrayList<>();
|
||||
for (Long id : ids) {
|
||||
ScSheepDeath record = scSheepDeathMapper.selectScSheepDeathById(id);
|
||||
if (record != null) {
|
||||
toDeleteRecords.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
int result = scSheepDeathMapper.deleteScSheepDeathByIds(ids);
|
||||
|
||||
if (result > 0) {
|
||||
// 恢复对应羊只的状态
|
||||
for (ScSheepDeath record : toDeleteRecords) {
|
||||
if (record.getSheepId() != null) {
|
||||
updateSheepStatus(record.getSheepId(), "正常"); // 或者根据业务需要设置其他状态
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,8 +289,23 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteScSheepDeathById(Long id)
|
||||
{
|
||||
return scSheepDeathMapper.deleteScSheepDeathById(id);
|
||||
if (id == null) {
|
||||
throw new ServiceException("删除的记录ID不能为空");
|
||||
}
|
||||
|
||||
// 获取要删除的记录
|
||||
ScSheepDeath record = scSheepDeathMapper.selectScSheepDeathById(id);
|
||||
|
||||
int result = scSheepDeathMapper.deleteScSheepDeathById(id);
|
||||
|
||||
if (result > 0 && record != null && record.getSheepId() != null) {
|
||||
// 恢复羊只状态
|
||||
updateSheepStatus(record.getSheepId(), "正常"); // 或者根据业务需要设置其他状态
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,155 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zhyc.module.produce.breed.mapper.ScMiscarriageRecordMapper">
|
||||
|
||||
<resultMap type="ScMiscarriageRecord" id="ScMiscarriageRecordResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="sheepId" column="sheep_id" />
|
||||
<result property="datetime" column="datetime" />
|
||||
<result property="comment" column="comment" />
|
||||
<result property="technician" column="technician" />
|
||||
<result property="reason" column="reason" />
|
||||
<result property="exposeType" column="expose_type" />
|
||||
<result property="status" column="status" />
|
||||
<result property="miscaLamb" column="misca_lamb" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<!-- 关联查询字段 -->
|
||||
<result property="bsManageTags" column="bs_manage_tags" />
|
||||
<result property="variety" column="variety" />
|
||||
<result property="matingTypeId" column="mating_type_id" />
|
||||
<result property="matingTypeName" column="mating_type_name" />
|
||||
<result property="matingDate" column="mating_date" />
|
||||
<result property="parity" column="parity" />
|
||||
<result property="ramVariety" column="ram_variety" />
|
||||
<result property="monthAge" column="month_age" />
|
||||
<result property="pregnantDays" column="pregnant_days" />
|
||||
<result property="sheepfoldName" column="sheepfold_name" />
|
||||
<result property="drRanch" column="dr_ranch" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectScMiscarriageRecordVo">
|
||||
select
|
||||
smr.id,
|
||||
smr.sheep_id,
|
||||
smr.datetime,
|
||||
smr.comment,
|
||||
smr.technician,
|
||||
smr.reason,
|
||||
smr.expose_type,
|
||||
smr.status,
|
||||
smr.misca_lamb,
|
||||
smr.create_by,
|
||||
smr.create_time,
|
||||
sf.bs_manage_tags,
|
||||
sf.variety,
|
||||
sf.mating_type_id,
|
||||
CASE sf.mating_type_id
|
||||
WHEN 1 THEN '人工授精'
|
||||
WHEN 2 THEN '自然配种'
|
||||
WHEN 3 THEN '胚胎移植'
|
||||
ELSE '未知'
|
||||
END as mating_type_name,
|
||||
sf.mating_date,
|
||||
sf.parity,
|
||||
sf.variety as ram_variety, -- 这里需要根据实际配种公羊信息调整
|
||||
sf.month_age,
|
||||
CASE
|
||||
WHEN sf.mating_date IS NOT NULL AND smr.datetime IS NOT NULL
|
||||
THEN DATEDIFF(smr.datetime, sf.mating_date)
|
||||
ELSE NULL
|
||||
END as pregnant_days,
|
||||
sf.sheepfold_name,
|
||||
sf.dr_ranch
|
||||
from sc_miscarriage_record smr
|
||||
left join sheep_file sf on smr.sheep_id = sf.bs_manage_tags
|
||||
</sql>
|
||||
|
||||
<select id="selectScMiscarriageRecordList" parameterType="ScMiscarriageRecord" resultMap="ScMiscarriageRecordResult">
|
||||
<include refid="selectScMiscarriageRecordVo"/>
|
||||
<where>
|
||||
<if test="sheepId != null and sheepId != ''"> and smr.sheep_id = #{sheepId}</if>
|
||||
<if test="bsManageTags != null and bsManageTags != ''"> and sf.bs_manage_tags like concat('%', #{bsManageTags}, '%')</if>
|
||||
<if test="datetime != null"> and smr.datetime = #{datetime}</if>
|
||||
<if test="comment != null and comment != ''"> and smr.comment like concat('%', #{comment}, '%')</if>
|
||||
<if test="technician != null and technician != ''"> and smr.technician like concat('%', #{technician}, '%')</if>
|
||||
<if test="reason != null and reason != ''"> and smr.reason = #{reason}</if>
|
||||
<if test="exposeType != null"> and smr.expose_type = #{exposeType}</if>
|
||||
<if test="status != null"> and smr.status = #{status}</if>
|
||||
<if test="miscaLamb != null"> and smr.misca_lamb = #{miscaLamb}</if>
|
||||
<if test="variety != null and variety != ''"> and sf.variety like concat('%', #{variety}, '%')</if>
|
||||
</where>
|
||||
order by smr.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectScMiscarriageRecordById" parameterType="Long" resultMap="ScMiscarriageRecordResult">
|
||||
<include refid="selectScMiscarriageRecordVo"/>
|
||||
where smr.id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertScMiscarriageRecord" parameterType="ScMiscarriageRecord" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into sc_miscarriage_record
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="sheepId != null">sheep_id,</if>
|
||||
<if test="datetime != null">datetime,</if>
|
||||
<if test="comment != null">comment,</if>
|
||||
<if test="technician != null">technician,</if>
|
||||
<if test="reason != null">reason,</if>
|
||||
<if test="exposeType != null">expose_type,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="miscaLamb != null">misca_lamb,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="sheepId != null">#{sheepId},</if>
|
||||
<if test="datetime != null">#{datetime},</if>
|
||||
<if test="comment != null">#{comment},</if>
|
||||
<if test="technician != null">#{technician},</if>
|
||||
<if test="reason != null">#{reason},</if>
|
||||
<if test="exposeType != null">#{exposeType},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="miscaLamb != null">#{miscaLamb},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateScMiscarriageRecord" parameterType="ScMiscarriageRecord">
|
||||
update sc_miscarriage_record
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="sheepId != null">sheep_id = #{sheepId},</if>
|
||||
<if test="datetime != null">datetime = #{datetime},</if>
|
||||
<if test="comment != null">comment = #{comment},</if>
|
||||
<if test="technician != null">technician = #{technician},</if>
|
||||
<if test="reason != null">reason = #{reason},</if>
|
||||
<if test="exposeType != null">expose_type = #{exposeType},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="miscaLamb != null">misca_lamb = #{miscaLamb},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteScMiscarriageRecordById" parameterType="Long">
|
||||
delete from sc_miscarriage_record where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteScMiscarriageRecordByIds" parameterType="String">
|
||||
delete from sc_miscarriage_record where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 根据耳号查询羊只信息 -->
|
||||
<select id="selectSheepByManageTags" parameterType="String" resultType="map">
|
||||
select bs_manage_tags, variety, parity, month_age, sheepfold_name, dr_ranch
|
||||
from sheep_file
|
||||
where bs_manage_tags = #{manageTags}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -16,8 +16,6 @@
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="create_by" />
|
||||
<result property="updateTime" column="create_time" />
|
||||
<!-- 关联羊只信息字段 -->
|
||||
<result property="variety" column="variety" />
|
||||
<result property="monthAge" column="month_age" />
|
||||
@ -32,6 +30,7 @@
|
||||
<result property="expectedDate" column="expected_date" />
|
||||
<result property="lastEventDate" column="last_event_date" />
|
||||
<result property="ranchName" column="ranch" />
|
||||
<result property="daysAfterMating" column="days_after_mating" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectScPregnancyRecordVo">
|
||||
@ -46,8 +45,6 @@
|
||||
pr.remark,
|
||||
pr.create_by,
|
||||
pr.create_time,
|
||||
pr.create_by,
|
||||
pr.create_time,
|
||||
sf.bs_manage_tags as manage_tags,
|
||||
sf.variety,
|
||||
sf.month_age,
|
||||
@ -55,18 +52,37 @@
|
||||
sf.mating_counts,
|
||||
sf.sheepfold_name,
|
||||
sf.breed,
|
||||
sf.father_manage_tags,
|
||||
father_sf.variety as father_variety,
|
||||
mating_type.dict_label as mating_type_name,
|
||||
sf.mating_date,
|
||||
sf.expected_date,
|
||||
sf.lambing_date as last_event_date,
|
||||
r.ranch as ranch
|
||||
sf.dr_ranch as ranch,
|
||||
-- 关联配种信息
|
||||
ram_sf.bs_manage_tags as father_manage_tags,
|
||||
ram_sf.variety as father_variety,
|
||||
mating_type.dict_label as mating_type_name,
|
||||
COALESCE(br.create_time, sf.mating_date) as mating_date,
|
||||
-- 计算配后天数:孕检日期 - 配种日期
|
||||
CASE
|
||||
WHEN COALESCE(br.create_time, sf.mating_date) IS NOT NULL
|
||||
THEN DATEDIFF(pr.datetime, COALESCE(br.create_time, sf.mating_date))
|
||||
ELSE NULL
|
||||
END as days_after_mating
|
||||
from sc_pregnancy_record pr
|
||||
left join sheep_file sf on pr.sheep_id = sf.id
|
||||
left join sys_dict_data mating_type on sf.mating_type_id = mating_type.dict_value and mating_type.dict_type = 'breed_type' and mating_type.status = '0'
|
||||
left join da_ranch r on sf.ranch_id = r.id
|
||||
left join sheep_file father_sf on sf.bs_father_id = father_sf.id
|
||||
-- 关联配种记录表,获取最新的配种记录
|
||||
left join (
|
||||
select br1.*
|
||||
from sc_breed_record br1
|
||||
inner join (
|
||||
select ewe_id, max(create_time) as max_time
|
||||
from sc_breed_record
|
||||
group by ewe_id
|
||||
) br2 on br1.ewe_id = br2.ewe_id and br1.create_time = br2.max_time
|
||||
) br on sf.id = br.ewe_id
|
||||
-- 关联公羊信息
|
||||
left join sheep_file ram_sf on br.ram_id = ram_sf.id
|
||||
-- 关联配种类型字典
|
||||
left join sys_dict_data mating_type on sf.mating_type_id = mating_type.dict_value
|
||||
and mating_type.dict_type = 'breed_type' and mating_type.status = '0'
|
||||
</sql>
|
||||
|
||||
<select id="selectScPregnancyRecordList" parameterType="ScPregnancyRecord" resultMap="ScPregnancyRecordResult">
|
||||
@ -86,7 +102,7 @@
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="datetime != null "> and pr.datetime = #{datetime}</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>
|
||||
@ -116,6 +132,28 @@
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<!-- 根据耳号获取配种信息 -->
|
||||
<select id="selectBreedInfoByManageTags" parameterType="String" resultType="map">
|
||||
SELECT
|
||||
sf.bs_manage_tags as manageTags,
|
||||
-- 从配种记录表获取公羊耳号
|
||||
ram_sf.bs_manage_tags as fatherManageTags,
|
||||
ram_sf.variety as fatherVariety,
|
||||
br.create_time as matingDate,
|
||||
mating_type.dict_label as matingTypeName,
|
||||
br.technician as breedTechnician,
|
||||
br.create_time as breedCreateTime
|
||||
FROM sheep_file sf
|
||||
LEFT JOIN sc_breed_record br ON sf.id = br.ewe_id
|
||||
LEFT JOIN sheep_file ram_sf ON br.ram_id = ram_sf.id
|
||||
LEFT JOIN sys_dict_data mating_type ON sf.mating_type_id = mating_type.dict_value
|
||||
AND mating_type.dict_type = 'breed_type' AND mating_type.status = '0'
|
||||
WHERE sf.bs_manage_tags = #{manageTags}
|
||||
AND sf.is_delete = 0
|
||||
ORDER BY br.create_time DESC
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<insert id="insertScPregnancyRecord" parameterType="ScPregnancyRecord" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into sc_pregnancy_record
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
@ -153,8 +191,6 @@
|
||||
<if test="technician != null">technician = #{technician},</if>
|
||||
<if test="way != null">way = #{way},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="updateBy != null">create_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">create_time = #{updateTime},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
@ -178,7 +214,6 @@
|
||||
<if test="breedStatusId != null">breed_status_id = #{breedStatusId},</if>
|
||||
<if test="expectedDate != null">expected_date = #{expectedDate},</if>
|
||||
<if test="gestationDay != null">gestation_day = #{gestationDay},</if>
|
||||
create_time = now()
|
||||
</set>
|
||||
where id = #{sheepId}
|
||||
</update>
|
||||
|
||||
@ -44,6 +44,7 @@
|
||||
<if test="comment != null and comment != ''"> and comment = #{comment}</if>
|
||||
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectScSheepDeathById" parameterType="Long" resultMap="ScSheepDeathResult">
|
||||
@ -51,11 +52,23 @@
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<!-- 根据管理耳号查询sheep_file视图信息 -->
|
||||
<!-- 根据管理耳号查询sheep_file视图信息 - 修复:删除不存在的status字段 -->
|
||||
<select id="selectSheepFileByManageTags" parameterType="String" resultType="java.util.Map">
|
||||
select id as sheepId, variety, name as sheepType, gender, day_age as dayAge, parity, sheepfold_name as sheepfoldName, breed as breedStatus, post_lambing_day as postLambingDay, lactation_day as lactationDay, gestation_day as gestationDay
|
||||
select
|
||||
id as sheepId,
|
||||
variety,
|
||||
name as sheepType,
|
||||
gender,
|
||||
day_age as dayAge,
|
||||
parity,
|
||||
sheepfold_name as sheepfoldName,
|
||||
breed as breedStatus,
|
||||
post_lambing_day as postLambingDay,
|
||||
lactation_day as lactationDay,
|
||||
gestation_day as gestationDay
|
||||
from sheep_file
|
||||
where bs_manage_tags = #{manageTags} and is_delete = 0
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insertScSheepDeath" parameterType="ScSheepDeath" useGeneratedKeys="true" keyProperty="id">
|
||||
@ -131,4 +144,14 @@
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 更新羊只状态 - 根据实际的sheep_file表结构调整字段名 -->
|
||||
<update id="updateSheepFileStatus">
|
||||
UPDATE sheep_file
|
||||
SET breed = #{status},
|
||||
update_time = NOW()
|
||||
WHERE id = #{sheepId}
|
||||
AND is_delete = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Loading…
x
Reference in New Issue
Block a user