diff --git a/zhyc-common/src/main/java/com/zhyc/common/utils/DateUtils.java b/zhyc-common/src/main/java/com/zhyc/common/utils/DateUtils.java index c95401e..0570896 100644 --- a/zhyc-common/src/main/java/com/zhyc/common/utils/DateUtils.java +++ b/zhyc-common/src/main/java/com/zhyc/common/utils/DateUtils.java @@ -8,6 +8,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneId; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import java.util.Date; import org.apache.commons.lang3.time.DateFormatUtils; diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/1 b/zhyc-module/src/main/java/com/zhyc/module/base/1 new file mode 100644 index 0000000..e69de29 diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepMapper.java b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepMapper.java index 4baaf89..a953f9a 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/BasSheepMapper.java @@ -3,6 +3,7 @@ package com.zhyc.module.base.mapper; import java.util.List; import com.zhyc.module.base.domain.BasSheep; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; /** @@ -11,6 +12,7 @@ import org.apache.ibatis.annotations.Param; * @author ruoyi * @date 2025-07-15 */ +@Mapper public interface BasSheepMapper { /** diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/controller/DiagnosisController.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/controller/DiagnosisController.java index 39149cc..3b7aff6 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/controller/DiagnosisController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/controller/DiagnosisController.java @@ -80,6 +80,17 @@ public class DiagnosisController extends BaseController return toAjax(diagnosisService.insertDiagnosis(diagnosis)); } + /** + * 新增批量诊疗结果 + */ + @PreAuthorize("@ss.hasPermi('diagnosis:diagnosis:add')") + @Log(title = "诊疗结果", businessType = BusinessType.INSERT) + @PostMapping("/adds") + public AjaxResult adds(@RequestBody Diagnosis diagnosis) + { + return toAjax(diagnosisService.insertDiagnosisList(diagnosis)); + } + /** * 修改诊疗结果 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/Diagnosis.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/Diagnosis.java index 6876dda..4280ff2 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/Diagnosis.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/Diagnosis.java @@ -27,6 +27,7 @@ public class Diagnosis extends BaseEntity /** 治疗记录id */ @Excel(name = "治疗记录") private Long treatId; + private Integer[] treatIds; /** 羊只id */ @Excel(name = "羊只耳号") diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/SwMedicineUsage.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/SwMedicineUsage.java index 442d76e..13843e2 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/SwMedicineUsage.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/SwMedicineUsage.java @@ -1,5 +1,7 @@ package com.zhyc.module.biosafety.domain; + +import java.util.Date; import java.util.List; import lombok.AllArgsConstructor; @@ -28,6 +30,18 @@ public class SwMedicineUsage extends BaseEntity @Excel(name = "使用名称") private String name; + /** 羊舍名称 */ + @Excel(name = "使用名称") + private String sheepfoldName; + private Integer sheepfoldId; + /** 耳号 */ + @Excel(name = "耳号") + private String sheepNo; + private Integer sheepId; + /** 使用时间 */ + @Excel(name = "使用时间") + private Date datetime; + /** 使用类型 */ @Excel(name = "使用类型") private String useType; diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/SwMedicineUsageDetails.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/SwMedicineUsageDetails.java index 34e0423..1b67654 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/SwMedicineUsageDetails.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/SwMedicineUsageDetails.java @@ -1,11 +1,14 @@ package com.zhyc.module.biosafety.domain; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import com.zhyc.common.annotation.Excel; import com.zhyc.common.core.domain.BaseEntity; +import java.util.Date; + /** * 药品使用记录详情对象 sw_medicine_usage_details * @@ -46,6 +49,11 @@ public class SwMedicineUsageDetails extends BaseEntity @Excel(name = "使用方法") private String usageId; + /** 使用时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "使用时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date usetime; + /** 生产厂家 */ @Excel(name = "生产厂家") private String manufacturer; diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/Treatment.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/Treatment.java index ae2d1a0..653dc53 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/Treatment.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/Treatment.java @@ -89,6 +89,10 @@ public class Treatment extends BaseEntity /** 兽医 */ @Excel(name = "兽医") private String veterinary; + /** 治疗状态 */ + @Excel(name = "治疗状态") + private String status; + /** 药品使用记录id */ @Excel(name = "药品使用记录id") diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/mapper/TreatmentMapper.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/mapper/TreatmentMapper.java index 643d9a0..1d48767 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/mapper/TreatmentMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/mapper/TreatmentMapper.java @@ -63,4 +63,7 @@ public interface TreatmentMapper public int deleteTreatmentByIds(Long[] ids); int insertTreatmentList(List treatments); + + + List selectTreatmentStatus(Long sheepId); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/IDiagnosisService.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/IDiagnosisService.java index d88f954..8f47fed 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/IDiagnosisService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/IDiagnosisService.java @@ -59,4 +59,6 @@ public interface IDiagnosisService * @return 结果 */ public int deleteDiagnosisById(Long id); + + int insertDiagnosisList(Diagnosis diagnosis); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DewormServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DewormServiceImpl.java index 8972fb3..9e1d867 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DewormServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DewormServiceImpl.java @@ -78,6 +78,7 @@ public class DewormServiceImpl implements IDewormService medicineUsage.setSwMedicineUsageDetailsList(deworm.getUsageDetails()); medicineUsage.setName("羊只驱虫"); medicineUsage.setUseType("1"); + medicineUsage.setDatetime(deworm.getDatetime()); List deworms = new ArrayList<>(); @@ -95,6 +96,8 @@ public class DewormServiceImpl implements IDewormService dew.setGender(String.valueOf(sheepFile.getGender())); dew.setBreed(sheepFile.getBreed()); dew.setParity(sheepFile.getParity()); + + medicineUsage.setSheepId(sheepId); // 获取药品使用记录的id Integer usageId = medicineUsageService.insertSwMedicineUsage(medicineUsage); dew.setUsageId(usageId); diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DiagnosisServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DiagnosisServiceImpl.java index c37895a..8447684 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DiagnosisServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DiagnosisServiceImpl.java @@ -1,5 +1,6 @@ package com.zhyc.module.biosafety.service.impl; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -9,13 +10,18 @@ import com.zhyc.module.base.domain.BasSheep; import com.zhyc.module.base.domain.SheepFile; import com.zhyc.module.base.mapper.BasSheepMapper; import com.zhyc.module.base.mapper.SheepFileMapper; +import com.zhyc.module.biosafety.domain.Treatment; import com.zhyc.module.biosafety.mapper.DiagnosisMapper; +import com.zhyc.module.biosafety.mapper.TreatmentMapper; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.zhyc.module.biosafety.domain.Diagnosis; import com.zhyc.module.biosafety.service.IDiagnosisService; import org.springframework.transaction.annotation.Transactional; + + /** * 诊疗结果Service业务层处理 * @@ -31,6 +37,8 @@ public class DiagnosisServiceImpl implements IDiagnosisService private SheepFileMapper sheepFileMapper; @Autowired private BasSheepMapper sheepMapper; + @Autowired + private TreatmentMapper treatmentMapper; /** * 查询诊疗结果 @@ -75,16 +83,87 @@ public class DiagnosisServiceImpl implements IDiagnosisService String username = SecurityUtils.getLoginUser().getUser().getNickName(); diagnosis.setCreateBy(username); diagnosis.setCreateTime(DateUtils.getNowDate()); - if (!Objects.equals(sheepFile.getSheepfoldId(), diagnosis.getSheepfoldId())){ - BasSheep basSheep = new BasSheep(); - basSheep.setId(diagnosis.getSheepId()); - basSheep.setSheepfoldId(diagnosis.getSheepfoldId()); - sheepMapper.updateBasSheep(basSheep); + + if (diagnosis.getSheepfoldId() != null) + if (!Objects.equals(sheepFile.getSheepfoldId(), diagnosis.getSheepfoldId())) { + BasSheep basSheep = new BasSheep(); + basSheep.setId(diagnosis.getSheepId()); + basSheep.setSheepfoldId(diagnosis.getSheepfoldId()); + sheepMapper.updateBasSheep(basSheep); + } + +// 更改治疗记录的状态 + Treatment treatment = new Treatment(); + treatment.setId(diagnosis.getTreatId()); + if (diagnosis.getResult().equals("0")){ + treatment.setStatus("-1"); + treatmentMapper.updateTreatment(treatment); + }else if (diagnosis.getResult().equals("1")){ + treatment.setStatus("2"); + treatmentMapper.updateTreatment(treatment); } // 转入其他羊舍 return diagnosisMapper.insertDiagnosis(diagnosis); } + + @Override + @Transactional + public int insertDiagnosisList(Diagnosis diagnosis) { + if (diagnosis.getTreatIds() != null && diagnosis.getTreatIds().length > 0){ + for (Integer treatId : diagnosis.getTreatIds()) { + System.out.println(treatId); + Treatment treatment = treatmentMapper.selectTreatmentById(Long.valueOf(treatId)); + System.out.println(treatment); +// BasSheep basSheep = sheepMapper.selectBasSheepById(treatment.getSheepId()); + + Diagnosis diag = new Diagnosis(); + BeanUtils.copyProperties(treatment,diag); + diag.setResult(diagnosis.getResult()); + diag.setParity(String.valueOf(treatment.getParity())); + + + // treatment 和 diagnosis 是你的两个实体对象 + Date start = treatment.getDatetime(); // 已经是 Date + Date end = diagnosis.getDatetime(); // 已经是 Date + diag.setBegindate(start); + diag.setEnddate(end); + long oneDayMillis = 24 * 60 * 60 * 1000L; + long days = (end.getTime() / oneDayMillis) - (start.getTime() / oneDayMillis); + if (days<0){ + days=0; + } + + diag.setTreatDay(days); + diag.setTreatId(treatment.getId()); + + + String username = SecurityUtils.getLoginUser().getUser().getNickName(); + diag.setCreateBy(username); + diag.setCreateTime(DateUtils.getNowDate()); + diagnosisMapper.insertDiagnosis(diag); + treatment.setDiagId(diag.getId()); + + // 更改治疗记录的状态 + if (diagnosis.getResult().equals("0")){ + treatment.setStatus("-1"); + treatmentMapper.updateTreatment(treatment); + }else if (diagnosis.getResult().equals("1")){ + treatment.setStatus("2"); + treatmentMapper.updateTreatment(treatment); + } + if (diagnosis.getSheepfoldId() != null){ + BasSheep basSheep = new BasSheep(); + basSheep.setId(diagnosis.getSheepId()); + basSheep.setSheepfoldId(diagnosis.getSheepfoldId()); + sheepMapper.updateBasSheep(basSheep); + } + } + } + + return 1; + } + /** * 修改诊疗结果 * @@ -130,4 +209,5 @@ public class DiagnosisServiceImpl implements IDiagnosisService { return diagnosisMapper.deleteDiagnosisById(id); } + } diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DisinfectServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DisinfectServiceImpl.java index 9b5286b..8e98bf4 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DisinfectServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/DisinfectServiceImpl.java @@ -79,6 +79,7 @@ public class DisinfectServiceImpl implements IDisinfectService medicineUsage.setSwMedicineUsageDetailsList(disinfect.getUsageDetails()); medicineUsage.setName("羊舍消毒"); medicineUsage.setUseType("3"); + medicineUsage.setDatetime(disinfect.getDatetime()); List disinfects = new ArrayList<>(); @@ -90,6 +91,8 @@ public class DisinfectServiceImpl implements IDisinfectService Disinfect dis = new Disinfect(); BeanUtils.copyProperties(disinfect,dis); dis.setSheepfoldId(sheepfold); + + medicineUsage.setSheepfoldId(sheepfold); // 获取药品使用记录的id Integer usageId = medicineUsageService.insertSwMedicineUsage(medicineUsage); dis.setUsageId(usageId); diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/HealthServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/HealthServiceImpl.java index 9c7cc72..1d5a4e0 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/HealthServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/HealthServiceImpl.java @@ -1,5 +1,6 @@ package com.zhyc.module.biosafety.service.impl; +import java.beans.Transient; import java.util.ArrayList; import java.util.List; import com.zhyc.common.utils.DateUtils; @@ -70,6 +71,7 @@ public class HealthServiceImpl implements IHealthService * @param health 保健 * @return 结果 */ + @Transient @Override public int insertHealth(Health health) { @@ -80,6 +82,7 @@ public class HealthServiceImpl implements IHealthService medicineUsage.setSwMedicineUsageDetailsList(health.getUsageDetails()); medicineUsage.setName("羊只保健"); medicineUsage.setUseType("2"); + medicineUsage.setDatetime(health.getDatetime()); List healths = new ArrayList<>(); health.setCreateBy(username); @@ -96,6 +99,7 @@ public class HealthServiceImpl implements IHealthService heal.setBreed(sheepFile.getBreed()); heal.setParity(sheepFile.getParity()); + medicineUsage.setSheepId(sheepId); // 获取药品使用记录的id Integer usageId = medicineUsageService.insertSwMedicineUsage(medicineUsage); diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/ImmunityServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/ImmunityServiceImpl.java index 613de0a..7649217 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/ImmunityServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/ImmunityServiceImpl.java @@ -82,8 +82,10 @@ public class ImmunityServiceImpl implements IImmunityService medicineUsage.setSwMedicineUsageDetailsList(immunity.getUsageDetails()); medicineUsage.setName("羊只免疫"); medicineUsage.setUseType("0"); + medicineUsage.setDatetime(immunity.getDatetime()); medicineUsage.setCreateBy(username); + List immunities = new ArrayList<>(); immunity.setUpdateBy(username); @@ -101,6 +103,8 @@ public class ImmunityServiceImpl implements IImmunityService imm.setGender(String.valueOf(sheepFile.getGender())); imm.setBreed(sheepFile.getBreed()); imm.setParity(sheepFile.getParity()); + + medicineUsage.setSheepId(sheepId); // 获取药品使用记录的id Integer usageId = medicineUsageService.insertSwMedicineUsage(medicineUsage); diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/TreatmentServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/TreatmentServiceImpl.java index 1cc3711..abb7d57 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/TreatmentServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/TreatmentServiceImpl.java @@ -7,8 +7,10 @@ import com.zhyc.common.utils.SecurityUtils; import com.zhyc.common.utils.bean.BeanUtils; import com.zhyc.module.base.domain.SheepFile; import com.zhyc.module.base.mapper.SheepFileMapper; +import com.zhyc.module.biosafety.domain.Diagnosis; import com.zhyc.module.biosafety.domain.SwMedicineUsage; import com.zhyc.module.biosafety.domain.SwMedicineUsageDetails; +import com.zhyc.module.biosafety.mapper.DiagnosisMapper; import com.zhyc.module.biosafety.mapper.SwMedicineUsageMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -34,6 +36,8 @@ public class TreatmentServiceImpl implements ITreatmentService private SwMedicineUsageMapper medicineUsageMapper; @Autowired private SheepFileMapper sheepFileMapper; + @Autowired + private DiagnosisMapper diagnosisMapper; /** * 查询治疗记录 @@ -47,7 +51,9 @@ public class TreatmentServiceImpl implements ITreatmentService Treatment treatment = treatmentMapper.selectTreatmentById(id); // 获取药品使用记录 SwMedicineUsage swMedicineUsage = medicineUsageService.selectSwMedicineUsageById(treatment.getUsageId()); - treatment.setUsageDetails(swMedicineUsage.getSwMedicineUsageDetailsList()); + if (swMedicineUsage!=null){ + treatment.setUsageDetails(swMedicineUsage.getSwMedicineUsageDetailsList()); + } return treatment; } @@ -79,10 +85,12 @@ public class TreatmentServiceImpl implements ITreatmentService medicineUsage.setSwMedicineUsageDetailsList(treatment.getUsageDetails()); medicineUsage.setName("羊只治疗"); medicineUsage.setUseType("4"); + medicineUsage.setDatetime(treatment.getDatetime()); medicineUsage.setCreateBy(username); medicineUsage.setCreateTime(DateUtils.getNowDate()); // 新增单挑数据 if (treatment.getSheepId()!=null){ + medicineUsage.setSheepId(Math.toIntExact(treatment.getSheepId())); // 药品使用记录 Integer id=medicineUsageService.insertSwMedicineUsage(medicineUsage); // 药品使用记录id @@ -108,6 +116,8 @@ public class TreatmentServiceImpl implements ITreatmentService treat.setParity(sheepFile.getParity()); treat.setLactDay(sheepFile.getLactationDay()); treat.setGestDay(sheepFile.getGestationDay()); + + medicineUsage.setSheepId(Integer.valueOf(sheepId)); // 获取药品使用记录的id Integer usageId = medicineUsageService.insertSwMedicineUsage(medicineUsage); System.out.println(medicineUsage); @@ -172,4 +182,21 @@ public class TreatmentServiceImpl implements ITreatmentService { return treatmentMapper.deleteTreatmentById(id); } + + public void updateTreatmentStatus(Long sheepId) { + List treatments=treatmentMapper.selectTreatmentStatus(sheepId); + Diagnosis diagnosis = new Diagnosis(); + for (Treatment treatment : treatments) { + if (treatment.getDiagId()!=null){ + diagnosis.setId(treatment.getDiagId()); + diagnosis.setResult("-1"); + diagnosisMapper.updateDiagnosis(diagnosis); + if (treatment.getDiagId()!=null){ + Treatment treat = new Treatment(); + treat.setId(treatment.getId()); + treatmentMapper.updateTreatment(treat); + } + } + } + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScMiscarriageRecordController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScMiscarriageRecordController.java new file mode 100644 index 0000000..c09c67c --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScMiscarriageRecordController.java @@ -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 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 list = scMiscarriageRecordService.selectScMiscarriageRecordList(scMiscarriageRecord); + ExcelUtil util = new ExcelUtil(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 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)); + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScPregnancyRecordController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScPregnancyRecordController.java index 08d5cc1..8c4a1fd 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScPregnancyRecordController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScPregnancyRecordController.java @@ -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 list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord); - return getDataTable(list); + try { + startPage(); + List 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 list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord); - ExcelUtil util = new ExcelUtil(ScPregnancyRecord.class); - util.exportExcel(response, list, "孕检记录数据"); + try { + List list = scPregnancyRecordService.selectScPregnancyRecordList(scPregnancyRecord); + ExcelUtil util = new ExcelUtil(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 sheepInfo = scPregnancyRecordService.getSheepByManageTags(manageTags); - return success(sheepInfo); + try { + if (manageTags == null || manageTags.trim().isEmpty()) { + return error("管理耳号不能为空"); + } + + Map 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 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()); + } } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScSheepDeathController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScSheepDeathController.java index cbd1964..1f6997b 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScSheepDeathController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScSheepDeathController.java @@ -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 list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); - return getDataTable(list); + try { + startPage(); + List 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 sheepInfo = scSheepDeathService.selectSheepFileByManageTags(manageTags); - if (sheepInfo != null) { - return success(sheepInfo); - } else { - return error("未找到该耳号对应的羊只信息"); + try { + if (manageTags == null || manageTags.trim().isEmpty()) { + return error("管理耳号不能为空"); + } + + Map 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 list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); - ExcelUtil util = new ExcelUtil(ScSheepDeath.class); - util.exportExcel(response, list, "羊只死淘记录数据"); + try { + List list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); + ExcelUtil util = new ExcelUtil(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()); + } } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScMiscarriageRecord.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScMiscarriageRecord.java new file mode 100644 index 0000000..5cf4b1a --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScMiscarriageRecord.java @@ -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(); + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScPregnancyRecord.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScPregnancyRecord.java index 41bcb5c..0dc61cd 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScPregnancyRecord.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScPregnancyRecord.java @@ -116,4 +116,7 @@ public class ScPregnancyRecord extends BaseEntity @Excel(name = "所在牧场") private String ranchName; + /** 配后天数 */ + @Excel(name = "配后天数") + private Integer daysAfterMating; } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScMiscarriageRecordMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScMiscarriageRecordMapper.java new file mode 100644 index 0000000..700e5b5 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScMiscarriageRecordMapper.java @@ -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 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 selectSheepByManageTags(String manageTags); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScPregnancyRecordMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScPregnancyRecordMapper.java index 4962992..7a16640 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScPregnancyRecordMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScPregnancyRecordMapper.java @@ -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 selectSheepByManageTags(String manageTags); + /** + * 根据耳号获取配种信息 + * + * @param manageTags 耳号 + * @return 配种信息 + */ + public Map selectBreedInfoByManageTags(String manageTags); + /** * 更新羊只基础表中的孕检相关字段 * diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScSheepDeathMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScSheepDeathMapper.java index 980d20d..853ab39 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScSheepDeathMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScSheepDeathMapper.java @@ -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); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScMiscarriageRecordService.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScMiscarriageRecordService.java new file mode 100644 index 0000000..e260f54 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScMiscarriageRecordService.java @@ -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 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 selectSheepByManageTags(String manageTags); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScPregnancyRecordService.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScPregnancyRecordService.java index bc0d2e4..8f89031 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScPregnancyRecordService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScPregnancyRecordService.java @@ -67,4 +67,12 @@ public interface IScPregnancyRecordService * @return 羊只信息 */ public Map getSheepByManageTags(String manageTags); + + /** + * 根据耳号获取配种信息 + * + * @param manageTags 耳号 + * @return 配种信息 + */ + public Map getBreedInfoByManageTags(String manageTags); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScMiscarriageRecordServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScMiscarriageRecordServiceImpl.java new file mode 100644 index 0000000..04e4733 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScMiscarriageRecordServiceImpl.java @@ -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 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 selectSheepByManageTags(String manageTags) + { + return scMiscarriageRecordMapper.selectSheepByManageTags(manageTags); + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScPregnancyRecordServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScPregnancyRecordServiceImpl.java index 5c329c6..e04df0a 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScPregnancyRecordServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScPregnancyRecordServiceImpl.java @@ -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 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 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 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 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 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 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 params = new HashMap<>(); - params.put("sheepId", scPregnancyRecord.getSheepId()); - params.put("pregDate", scPregnancyRecord.getDatetime()); + try { + Map 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); } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java index 12e7afd..df8d0e2 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java @@ -3,11 +3,17 @@ package com.zhyc.module.produce.breed.service.impl; import java.util.List; import java.util.Map; import com.zhyc.common.utils.DateUtils; +import com.zhyc.module.biosafety.domain.Diagnosis; +import com.zhyc.module.biosafety.domain.Treatment; +import com.zhyc.module.biosafety.mapper.DiagnosisMapper; +import com.zhyc.module.biosafety.mapper.TreatmentMapper; +import com.zhyc.module.biosafety.service.impl.TreatmentServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.zhyc.module.produce.breed.mapper.ScSheepDeathMapper; import com.zhyc.module.produce.breed.domain.ScSheepDeath; import com.zhyc.module.produce.breed.service.IScSheepDeathService; +import org.springframework.transaction.annotation.Transactional; /** * 羊只死淘记录Service业务层处理 @@ -20,6 +26,13 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService { @Autowired private ScSheepDeathMapper scSheepDeathMapper; + @Autowired + private DiagnosisMapper diagnosisMapper; + @Autowired + private TreatmentServiceImpl treatmentService; + + + /** * 查询羊只死淘记录 @@ -100,6 +113,7 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService * @return 结果 */ @Override + @Transactional public int insertScSheepDeath(ScSheepDeath scSheepDeath) { // 设置事件类型默认为"死亡" @@ -111,11 +125,20 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) { Map 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); } @@ -132,10 +155,15 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) { Map 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()); return scSheepDeathMapper.updateScSheepDeath(scSheepDeath); } @@ -149,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); } @@ -161,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); } } \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/biosafety/DewormMapper.xml b/zhyc-module/src/main/resources/mapper/biosafety/DewormMapper.xml index 174f8f3..1371396 100644 --- a/zhyc-module/src/main/resources/mapper/biosafety/DewormMapper.xml +++ b/zhyc-module/src/main/resources/mapper/biosafety/DewormMapper.xml @@ -38,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and datetime between #{params.beginDatetime} and #{params.endDatetime} and technical = #{technical} + ORDER BY datetime DESC diff --git a/zhyc-module/src/main/resources/mapper/biosafety/SwMedicineUsageMapper.xml b/zhyc-module/src/main/resources/mapper/biosafety/SwMedicineUsageMapper.xml index f86bdef..f478719 100644 --- a/zhyc-module/src/main/resources/mapper/biosafety/SwMedicineUsageMapper.xml +++ b/zhyc-module/src/main/resources/mapper/biosafety/SwMedicineUsageMapper.xml @@ -7,6 +7,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + @@ -26,12 +31,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select id, name, use_type, update_by, update_time, create_by, create_time from sw_medicine_usage + select smu.id, sheepfold as sheepfold_id,sheep sheep_id,name, datetime,use_type, smu.update_by, smu.update_time, smu.create_by, smu.create_time, + ds.sheepfold_name, + bs.manage_tags sheep_no + from sw_medicine_usage smu + left join da_sheepfold ds on ds.id = smu.sheepfold + left join bas_sheep bs on bs.id = smu.sheep @@ -62,6 +77,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" name, use_type, + sheepfold, + sheep, + datetime, update_by, update_time, create_by, @@ -70,6 +88,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{name}, #{useType}, + #{sheepfoldId}, + #{sheepId}, + #{datetime}, #{updateBy}, #{updateTime}, #{createBy}, @@ -113,9 +134,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - insert into sw_medicine_usage_details( id, medi_usage, medi_id, dosage, unit, usageId, manufacturer, batch_number) values + insert into sw_medicine_usage_details( id, medi_usage, medi_id, dosage, unit, usageId,usetime, manufacturer, batch_number) values - ( #{item.id}, #{item.mediUsage}, #{item.mediId}, #{item.dosage}, #{item.unit}, #{item.usageId}, #{item.manufacturer}, #{item.batchNumber}) + ( #{item.id}, #{item.mediUsage}, #{item.mediId}, #{item.dosage}, #{item.unit}, #{item.usageId}, #{item.usetime},#{item.manufacturer}, #{item.batchNumber}) \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/biosafety/TreatmentMapper.xml b/zhyc-module/src/main/resources/mapper/biosafety/TreatmentMapper.xml index ee496ad..5e07a30 100644 --- a/zhyc-module/src/main/resources/mapper/biosafety/TreatmentMapper.xml +++ b/zhyc-module/src/main/resources/mapper/biosafety/TreatmentMapper.xml @@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -32,7 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select t.id, diag_id, sheep_id, variety, sheep_type, month_age, t.gender, t.parity, breed, lact_day, gest_day, datetime, disease_id, disease_pid, veterinary, usage_id, t.comment, t.update_by, t.update_time, t.create_by, t.create_time, + select t.id, diag_id, sheep_id, variety, sheep_type, month_age, t.gender, t.parity, breed, lact_day, gest_day, datetime, disease_id, disease_pid, veterinary, usage_id,status, t.comment, t.update_by, t.update_time, t.create_by, t.create_time, bs.manage_tags, sd.name disease_name, sd2.name disease_pname @@ -48,14 +49,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and sheep_id = #{sheepId} and datetime between #{params.beginDatetime} and #{params.endDatetime} and disease_id = #{diseaseId} + and status = #{status} and veterinary = #{veterinary} + ORDER BY datetime DESC + insert into sw_treatment @@ -75,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" disease_pid, veterinary, usage_id, + status, comment, update_by, update_time, @@ -97,6 +104,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{diseasePid}, #{veterinary}, #{usageId}, + #{status}, #{comment}, #{updateBy}, #{updateTime}, @@ -109,14 +117,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into sw_treatment (diag_id, sheep_id, variety, sheep_type, month_age, gender, parity, breed, lact_day, gest_day, datetime, - disease_id, disease_pid, veterinary, usage_id, + disease_id, disease_pid, veterinary, usage_id,status , comment, update_by, update_time, create_by, create_time) values (#{t.diagId}, #{t.sheepId}, #{t.variety}, #{t.sheepType}, #{t.monthAge}, #{t.gender}, #{t.parity}, #{t.breed}, #{t.lactDay}, #{t.gestDay}, #{t.datetime}, #{t.diseaseId}, - #{t.diseasePid}, #{t.veterinary},#{t.usageId}, #{t.comment}, + #{t.diseasePid}, #{t.veterinary},#{t.usageId}, #{t.status}, #{t.comment}, #{t.updateBy}, #{t.updateTime},#{t.createBy}, #{t.createTime}) @@ -139,6 +147,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" disease_pid = #{diseasePid}, veterinary = #{veterinary}, usage_id = #{usageId}, + status = #{status}, comment = #{comment}, update_by = #{updateBy}, update_time = #{updateTime}, diff --git a/zhyc-module/src/main/resources/mapper/miscarriage/ScMiscarriageRecordMapper.xml b/zhyc-module/src/main/resources/mapper/miscarriage/ScMiscarriageRecordMapper.xml new file mode 100644 index 0000000..810f299 --- /dev/null +++ b/zhyc-module/src/main/resources/mapper/miscarriage/ScMiscarriageRecordMapper.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + insert into sc_miscarriage_record + + sheep_id, + datetime, + comment, + technician, + reason, + expose_type, + status, + misca_lamb, + create_by, + create_time, + + + #{sheepId}, + #{datetime}, + #{comment}, + #{technician}, + #{reason}, + #{exposeType}, + #{status}, + #{miscaLamb}, + #{createBy}, + #{createTime}, + + + + + update sc_miscarriage_record + + sheep_id = #{sheepId}, + datetime = #{datetime}, + comment = #{comment}, + technician = #{technician}, + reason = #{reason}, + expose_type = #{exposeType}, + status = #{status}, + misca_lamb = #{miscaLamb}, + create_by = #{createBy}, + create_time = #{createTime}, + + where id = #{id} + + + + delete from sc_miscarriage_record where id = #{id} + + + + delete from sc_miscarriage_record where id in + + #{id} + + + + + + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/bodyManage/ScBodyMeasureMapper.xml b/zhyc-module/src/main/resources/mapper/produce/bodyManage/ScBodyMeasureMapper.xml index 5265e5f..7e75d9c 100644 --- a/zhyc-module/src/main/resources/mapper/produce/bodyManage/ScBodyMeasureMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/bodyManage/ScBodyMeasureMapper.xml @@ -102,6 +102,7 @@ and sm.create_time between #{params.beginCreateTime} and #{params.endCreateTime} + ORDER BY sm.create_time DESC @@ -86,7 +102,7 @@ - and pr.datetime = #{datetime} + and DATE(pr.datetime) = DATE(#{datetime}) and pr.result = #{result} and pr.technician like concat('%', #{technician}, '%') and pr.way = #{way} @@ -116,6 +132,28 @@ limit 1 + + + insert into sc_pregnancy_record @@ -153,8 +191,6 @@ technician = #{technician}, way = #{way}, remark = #{remark}, - create_by = #{updateBy}, - create_time = #{updateTime}, where id = #{id} @@ -178,7 +214,6 @@ breed_status_id = #{breedStatusId}, expected_date = #{expectedDate}, gestation_day = #{gestationDay}, - create_time = now() where id = #{sheepId} diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/ScSheepDeathMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/ScSheepDeathMapper.xml index baedeeb..1444e04 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScSheepDeathMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScSheepDeathMapper.xml @@ -44,6 +44,7 @@ and comment = #{comment} and is_delete = #{isDelete} + order by create_time desc - 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 @@ -131,4 +144,23 @@ #{id} + + + + UPDATE sheep_file + SET breed = #{status}, + update_time = NOW() + WHERE id = #{sheepId} + AND is_delete = 0 + + + + + UPDATE sheep_file + SET status = #{status}, + update_time = NOW() + WHERE id = #{sheepId} + AND is_delete = 0 + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScChangeCommentMapper.xml b/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScChangeCommentMapper.xml index e931054..64a5b09 100644 --- a/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScChangeCommentMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScChangeCommentMapper.xml @@ -49,6 +49,7 @@ and scc.create_time between #{params.beginCreateTime} and #{params.endCreateTime} + ORDER BY scc.create_time DESC diff --git a/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScTransitionInfoMapper.xml b/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScTransitionInfoMapper.xml index 78b2c91..66d18ca 100644 --- a/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScTransitionInfoMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/manage_sheep/ScTransitionInfoMapper.xml @@ -67,6 +67,7 @@ and t.create_time between #{params.beginCreateTime} and #{params.endCreateTime} + ORDER BY t.create_time DESC