Merge remote-tracking branch 'origin/main'

# Conflicts:
#	zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java
This commit is contained in:
漂泊 2025-08-24 18:25:59 +08:00
commit 80d5e7b248
17 changed files with 1425 additions and 85 deletions

View 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));
}
}

View File

@ -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)
{
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)
{
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);
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());
}
}
}

View File

@ -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)
{
try {
startPage();
List<ScSheepDeath> list = scSheepDeathService.selectScSheepDeathList(scSheepDeath);
return getDataTable(list);
} catch (Exception e) {
logger.error("查询羊只死淘记录列表失败", e);
return getDataTable(new java.util.ArrayList<>());
}
}
/**
@ -54,12 +60,21 @@ public class ScSheepDeathController extends BaseController
@GetMapping("/sheepInfo/{manageTags}")
public AjaxResult getSheepInfo(@PathVariable("manageTags") String manageTags)
{
Map<String, Object> sheepInfo = scSheepDeathService.selectSheepFileByManageTags(manageTags);
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)
{
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());
}
}
}

View File

@ -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();
}
}

View File

@ -116,4 +116,7 @@ public class ScPregnancyRecord extends BaseEntity
@Excel(name = "所在牧场")
private String ranchName;
/** 配后天数 */
@Excel(name = "配后天数")
private Integer daysAfterMating;
}

View File

@ -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);
}

View File

@ -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);
/**
* 更新羊只基础表中的孕检相关字段
*

View File

@ -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,22 @@ 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);
/**
* 新增更新羊只在群状态
*
* @param sheepId 羊只ID
* @param status 在群状态1-在群2-不在群
* @return 更新结果
*/
public int updateSheepStatus(@Param("sheepId") Long sheepId, @Param("status") String status);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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());
// 参数校验
if (scPregnancyRecord.getId() == null) {
throw new ServiceException("记录ID不能为空");
}
// 根据耳号获取羊只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.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,6 +243,7 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService
* @param scPregnancyRecord 孕检记录
*/
private void updateSheepPregnancyStatus(ScPregnancyRecord scPregnancyRecord) {
try {
Map<String, Object> params = new HashMap<>();
params.put("sheepId", scPregnancyRecord.getSheepId());
params.put("pregDate", scPregnancyRecord.getDatetime());
@ -174,5 +266,9 @@ public class ScPregnancyRecordServiceImpl implements IScPregnancyRecordService
}
scPregnancyRecordMapper.updateSheepPregnancyInfo(params);
} catch (Exception e) {
// 记录日志但不影响主流程
System.err.println("更新羊只怀孕状态失败: " + e.getMessage());
}
}
}

View File

@ -124,13 +124,19 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
// 如果有管理耳号查询并设置羊只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);
Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null;
scSheepDeath.setSheepId(sheepId);
// 插入死淘记录后同时更新羊只在群状态为"不在群"字典值为2
if (sheepId != null) {
scSheepDeathMapper.updateSheepStatus(sheepId, "2");
}
}
}
treatmentService.updateTreatmentStatus(scSheepDeath.getSheepId());
scSheepDeath.setCreateTime(DateUtils.getNowDate());
return scSheepDeathMapper.insertScSheepDeath(scSheepDeath);
@ -149,7 +155,13 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
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);
Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null;
scSheepDeath.setSheepId(sheepId);
// 修改死淘记录时同时更新羊只在群状态为"不在群"字典值为2
if (sheepId != null) {
scSheepDeathMapper.updateSheepStatus(sheepId, "2");
}
}
}
scSheepDeath.setUpdateTime(DateUtils.getNowDate());
@ -165,6 +177,15 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
@Override
public int deleteScSheepDeathByIds(Long[] ids)
{
// 可选删除死淘记录前将对应羊只在群状态改回"在群"
for (Long id : ids) {
ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id);
if (scSheepDeath != null && scSheepDeath.getSheepId() != null) {
// 恢复羊只在群状态为"在群"字典值为1
scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1");
}
}
return scSheepDeathMapper.deleteScSheepDeathByIds(ids);
}
@ -177,6 +198,13 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService
@Override
public int deleteScSheepDeathById(Long id)
{
// 可选删除死淘记录前将对应羊只在群状态改回"在群"
ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id);
if (scSheepDeath != null && scSheepDeath.getSheepId() != null) {
// 恢复羊只在群状态为"在群"字典值为1
scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1");
}
return scSheepDeathMapper.deleteScSheepDeathById(id);
}
}

View File

@ -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>

View File

@ -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>

View File

@ -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">
@ -53,9 +54,21 @@
<!-- 根据管理耳号查询sheep_file视图信息 -->
<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,23 @@
#{id}
</foreach>
</delete>
<!-- 更新羊只繁育状态 - 保留原有功能 -->
<update id="updateSheepFileStatus">
UPDATE sheep_file
SET breed = #{status},
update_time = NOW()
WHERE id = #{sheepId}
AND is_delete = 0
</update>
<!-- 新增:更新羊只在群状态 -->
<update id="updateSheepStatus">
UPDATE sheep_file
SET status = #{status},
update_time = NOW()
WHERE id = #{sheepId}
AND is_delete = 0
</update>
</mapper>