diff --git a/zhyc-common/src/main/java/com/zhyc/common/annotation/Excel.java b/zhyc-common/src/main/java/com/zhyc/common/annotation/Excel.java index e9d66a7..47402dc 100644 --- a/zhyc-common/src/main/java/com/zhyc/common/annotation/Excel.java +++ b/zhyc-common/src/main/java/com/zhyc/common/annotation/Excel.java @@ -33,6 +33,11 @@ public @interface Excel */ public String dateFormat() default ""; + /** + * 数字格式, 如: 0.00 + */ + public String numFormat() default ""; // 新增数字格式属性 + /** * 如果是字典类型,请设置字典的type值 (如: sys_user_sex) */ 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-common/src/main/java/com/zhyc/common/utils/poi/ExcelUtil.java b/zhyc-common/src/main/java/com/zhyc/common/utils/poi/ExcelUtil.java index d595cee..35269b0 100644 --- a/zhyc-common/src/main/java/com/zhyc/common/utils/poi/ExcelUtil.java +++ b/zhyc-common/src/main/java/com/zhyc/common/utils/poi/ExcelUtil.java @@ -88,7 +88,7 @@ import com.zhyc.common.utils.reflect.ReflectUtils; /** * Excel相关处理 - * + * * @author ruoyi */ public class ExcelUtil @@ -307,7 +307,7 @@ public class ExcelUtil /** * 对excel表单默认第一个索引名转换成list - * + * * @param is 输入流 * @return 转换后集合 */ @@ -318,7 +318,7 @@ public class ExcelUtil /** * 对excel表单默认第一个索引名转换成list - * + * * @param is 输入流 * @param titleNum 标题占用行数 * @return 转换后集合 @@ -344,7 +344,7 @@ public class ExcelUtil /** * 对excel表单指定表格索引名转换成list - * + * * @param sheetName 表格索引名 * @param titleNum 标题占用行数 * @param is 输入流 @@ -527,7 +527,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param list 导出数据集合 * @param sheetName 工作表的名称 * @return 结果 @@ -539,7 +539,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param list 导出数据集合 * @param sheetName 工作表的名称 * @param title 标题 @@ -553,7 +553,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param response 返回数据 * @param list 导出数据集合 * @param sheetName 工作表的名称 @@ -566,7 +566,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param response 返回数据 * @param list 导出数据集合 * @param sheetName 工作表的名称 @@ -583,7 +583,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param sheetName 工作表的名称 * @return 结果 */ @@ -594,7 +594,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param sheetName 工作表的名称 * @param title 标题 * @return 结果 @@ -607,7 +607,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param sheetName 工作表的名称 * @return 结果 */ @@ -618,7 +618,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @param sheetName 工作表的名称 * @param title 标题 * @return 结果 @@ -633,7 +633,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @return 结果 */ public void exportExcel(HttpServletResponse response) @@ -655,7 +655,7 @@ public class ExcelUtil /** * 对list数据源将其里面的数据导入到excel表单 - * + * * @return 结果 */ public AjaxResult exportExcel() @@ -723,7 +723,7 @@ public class ExcelUtil /** * 填充excel数据 - * + * * @param index 序号 * @param row 单元格行 */ @@ -821,7 +821,7 @@ public class ExcelUtil /** * 创建表格样式 - * + * * @param wb 工作薄对象 * @return 样式列表 */ @@ -876,7 +876,7 @@ public class ExcelUtil /** * 根据Excel注解创建表格头样式 - * + * * @param wb 工作薄对象 * @return 自定义样式列表 */ @@ -912,7 +912,7 @@ public class ExcelUtil /** * 根据Excel注解创建表格列样式 - * + * * @param wb 工作薄对象 * @return 自定义样式列表 */ @@ -944,7 +944,7 @@ public class ExcelUtil /** * 根据Excel注解创建表格列样式 - * + * * @param styles 自定义样式列表 * @param field 属性列信息 * @param excel 注解信息 @@ -1007,7 +1007,7 @@ public class ExcelUtil /** * 设置单元格信息 - * + * * @param value 单元格值 * @param attr 注解相关 * @param cell 单元格信息 @@ -1142,7 +1142,6 @@ public class ExcelUtil sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column)); } } - cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText()))); // 用于读取对象中的属性 Object value = getTargetValue(vo, field, attr); @@ -1150,14 +1149,33 @@ public class ExcelUtil String readConverterExp = attr.readConverterExp(); String separator = attr.separator(); String dictType = attr.dictType(); - if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) + String numFormat = attr.numFormat(); // 获取数字格式 + + // 创建单元格样式 + CellStyle cellStyle = wb.createCellStyle(); + cellStyle.cloneStyleFrom(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", + attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText()))); + + // 处理日期格式 + if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value) && value instanceof Date) { - cell.getCellStyle().setDataFormat(this.wb.getCreationHelper().createDataFormat().getFormat(dateFormat)); - cell.setCellValue(parseDateToStr(dateFormat, value)); + DataFormat format = wb.createDataFormat(); + cellStyle.setDataFormat(format.getFormat(dateFormat)); + cell.setCellValue((Date) value); + cell.setCellStyle(cellStyle); + } + // 处理数字格式 + else if (StringUtils.isNotEmpty(numFormat) && StringUtils.isNotNull(value) && value instanceof Number) + { + DataFormat format = wb.createDataFormat(); + cellStyle.setDataFormat(format.getFormat(numFormat)); + cell.setCellValue(((Number) value).doubleValue()); + cell.setCellStyle(cellStyle); } else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) { cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator)); + cell.setCellStyle(cellStyle); } else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value)) { @@ -1167,20 +1185,32 @@ public class ExcelUtil sysDictMap.put(dictType + value, lable); } cell.setCellValue(sysDictMap.get(dictType + value)); + cell.setCellStyle(cellStyle); } else if (value instanceof BigDecimal && -1 != attr.scale()) { cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue()); + cell.setCellStyle(cellStyle); } else if (!attr.handler().equals(ExcelHandlerAdapter.class)) { cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell)); + cell.setCellStyle(cellStyle); } else { // 设置列类型 setCellVo(value, attr, cell); + // 对于日期类型,确保应用日期格式 + if (value instanceof Date && StringUtils.isNotEmpty(dateFormat)) { + DataFormat format = wb.createDataFormat(); + CellStyle dateStyle = wb.createCellStyle(); + dateStyle.cloneStyleFrom(cell.getCellStyle()); + dateStyle.setDataFormat(format.getFormat(dateFormat)); + cell.setCellStyle(dateStyle); + } } + addStatisticsData(column, Convert.toStr(value), attr); } } @@ -1193,7 +1223,7 @@ public class ExcelUtil /** * 设置 POI XSSFSheet 单元格提示或选择框 - * + * * @param sheet 表单 * @param textlist 下拉框显示的内容 * @param promptContent 提示内容 @@ -1203,7 +1233,7 @@ public class ExcelUtil * @param endCol 结束列 */ public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, - int firstCol, int endCol) + int firstCol, int endCol) { DataValidationHelper helper = sheet.getDataValidationHelper(); DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1"); @@ -1230,7 +1260,7 @@ public class ExcelUtil /** * 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框). - * + * * @param sheet 要设置的sheet. * @param textlist 下拉框显示的内容 * @param promptContent 提示内容 @@ -1254,7 +1284,7 @@ public class ExcelUtil DataValidationHelper helper = sheet.getDataValidationHelper(); // 加载下拉列表内容 DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data"); - // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列 + // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列 CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); // 数据有效性对象 DataValidation dataValidation = helper.createValidation(constraint, regions); @@ -1282,7 +1312,7 @@ public class ExcelUtil /** * 解析导出值 0=男,1=女,2=未知 - * + * * @param propertyValue 参数值 * @param converterExp 翻译注解 * @param separator 分隔符 @@ -1319,7 +1349,7 @@ public class ExcelUtil /** * 反向解析值 男=0,女=1,未知=2 - * + * * @param propertyValue 参数值 * @param converterExp 翻译注解 * @param separator 分隔符 @@ -1356,7 +1386,7 @@ public class ExcelUtil /** * 解析字典值 - * + * * @param dictValue 字典值 * @param dictType 字典类型 * @param separator 分隔符 @@ -1369,7 +1399,7 @@ public class ExcelUtil /** * 反向解析值字典值 - * + * * @param dictLabel 字典标签 * @param dictType 字典类型 * @param separator 分隔符 @@ -1382,7 +1412,7 @@ public class ExcelUtil /** * 数据处理器 - * + * * @param value 数据值 * @param excel 数据注解 * @return @@ -1458,7 +1488,7 @@ public class ExcelUtil /** * 获取下载路径 - * + * * @param filename 文件名称 */ public String getAbsoluteFile(String filename) @@ -1474,7 +1504,7 @@ public class ExcelUtil /** * 获取bean中的属性值 - * + * * @param vo 实体对象 * @param field 字段 * @param excel 注解 @@ -1506,7 +1536,7 @@ public class ExcelUtil /** * 以类的属性的get方法方法形式获取值 - * + * * @param o * @param name * @return value @@ -1649,7 +1679,7 @@ public class ExcelUtil /** * 创建工作表 - * + * * @param sheetNo sheet数量 * @param index 序号 */ @@ -1666,7 +1696,7 @@ public class ExcelUtil /** * 获取单元格值 - * + * * @param row 获取的行 * @param column 获取单元格列号 * @return 单元格值 @@ -1726,7 +1756,7 @@ public class ExcelUtil /** * 判断是否是空行 - * + * * @param row 判断的行 * @return */ @@ -1754,7 +1784,7 @@ public class ExcelUtil * @param workbook 工作簿对象 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData */ - public static Map> getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook) + public static Map > getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook) { Map> sheetIndexPicMap = new HashMap<>(); List pictures = workbook.getAllPictures(); @@ -1807,7 +1837,7 @@ public class ExcelUtil /** * 格式化不同类型的日期对象 - * + * * @param dateFormat 日期格式 * @param val 被格式化的日期对象 * @return 格式化后的日期字符 @@ -1873,7 +1903,7 @@ public class ExcelUtil /** * 获取对象的子列表方法 - * + * * @param name 名称 * @param pojoClass 类对象 * @return 子列表方法 @@ -1894,4 +1924,4 @@ public class ExcelUtil } return method; } -} +} \ No newline at end of file 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/dairyProducts/controller/NpMilkProdClassesController.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpMilkProdClassesController.java index 32e7db8..da0cde1 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpMilkProdClassesController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpMilkProdClassesController.java @@ -58,10 +58,12 @@ public class NpMilkProdClassesController extends BaseController { public void export(HttpServletResponse response, @RequestParam(required = false) Date datetimeStart, @RequestParam(required = false) Date datetimeEnd, - @RequestParam(required = false) String manageEarNos, + @RequestParam(required = false) String manageEarNo, @RequestParam(required = false) String factory, @RequestParam(required = false) Integer classes) { - List list = npMilkProdClassesService.selectNpMilkProdClassesList(datetimeStart, datetimeEnd, manageEarNos, factory, classes); + List list = npMilkProdClassesService.selectNpMilkProdClassesList( + datetimeStart, datetimeEnd, manageEarNo, factory, classes); + ExcelUtil util = new ExcelUtil<>(NpMilkProdClasses.class); util.exportExcel(response, list, "班次产奶数据"); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpSheepMilkAnalysisController.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpSheepMilkAnalysisController.java index 3e4f07a..bce4136 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpSheepMilkAnalysisController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/NpSheepMilkAnalysisController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; /** + * 奶产量分析控制器 * 只保留:分页列表(只读) + 单条查询 + 导出 */ @RestController @@ -29,13 +30,13 @@ public class NpSheepMilkAnalysisController extends BaseController { */ @GetMapping("/list") public TableDataInfo list(NpSheepMilkAnalysis analysis) { - startPage(); // 使用 PageHelper 分页(注意 service 中第一个 DB 调用是 distinct sheep id) + startPage(); // 使用PageHelper分页(注意service中第一个DB调用是distinct sheep id) List list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisList(analysis); return getDataTable(list); } /** - * 获取单个分析记录详细信息(按 sheepId) + * 获取单个分析记录详细信息(按sheepId) */ @GetMapping(value = "/{sheepId}") public AjaxResult getInfo(@PathVariable("sheepId") String sheepId) { @@ -44,13 +45,13 @@ public class NpSheepMilkAnalysisController extends BaseController { /** * 导出奶产量分析记录(Excel) - * 支持 manageEarTag 与 screenDays 两个查询条件 + * 支持manageEarTag与screenDays两个查询条件 */ @Log(title = "奶产量分析 导出", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(NpSheepMilkAnalysis analysis) { - List list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisList(analysis); + List list = npSheepMilkAnalysisService.selectNpSheepMilkAnalysisForExport(analysis); ExcelUtil util = new ExcelUtil<>(NpSheepMilkAnalysis.class); return util.exportExcel(list, "羊奶产量分析数据"); } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java index b0563fe..db13670 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/controller/XzParityCorrectionController.java @@ -19,12 +19,13 @@ import com.zhyc.common.enums.BusinessType; import com.zhyc.module.dairyProducts.domain.XzParityCorrection; import com.zhyc.module.dairyProducts.service.IXzParityCorrectionService; import com.zhyc.common.utils.poi.ExcelUtil; +import com.zhyc.common.core.page.TableDataInfo; /** * 胎次校正Controller - * + * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ @RestController @RequestMapping("/parityCorrection/parityCorrection") @@ -37,20 +38,12 @@ public class XzParityCorrectionController extends BaseController * 查询胎次校正列表 */ @PreAuthorize("@ss.hasPermi('parityCorrection:parityCorrection:list')") -// @GetMapping("/list") -// public TableDataInfo list(XzParityCorrection xzParityCorrection) -// { -// startPage(); -// List list = xzParityCorrectionService.selectXzParityCorrectionList(xzParityCorrection); -// return getDataTable(list); -// } - /** - * 获取全部胎次校正(无需分页,供下拉/列表直接显示) - */ - @GetMapping("/listAll") - public AjaxResult listAll(XzParityCorrection xzParityCorrection){ + @GetMapping("/list") + public TableDataInfo list(XzParityCorrection xzParityCorrection) + { + startPage(); List list = xzParityCorrectionService.selectXzParityCorrectionList(xzParityCorrection); - return success(list); // 直接返回数组 + return getDataTable(list); } /** @@ -103,7 +96,7 @@ public class XzParityCorrectionController extends BaseController */ @PreAuthorize("@ss.hasPermi('parityCorrection:parityCorrection:remove')") @Log(title = "胎次校正", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") + @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(xzParityCorrectionService.deleteXzParityCorrectionByIds(ids)); diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpMilkProdClasses.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpMilkProdClasses.java index 19e2ce9..43d388d 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpMilkProdClasses.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpMilkProdClasses.java @@ -15,7 +15,7 @@ public class NpMilkProdClasses implements Serializable { private Date updateTime; // 更新时间 @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "日期") + @Excel(name = "日期", dateFormat = "yyyy-MM-dd") // 添加日期格式 private Date datetime; @Excel(name = "管理耳号") @@ -33,10 +33,10 @@ public class NpMilkProdClasses implements Serializable { @Excel(name = "班次") private Integer classes; - @Excel(name = "班次产奶量") + @Excel(name = "班次产奶量", numFormat = "0.00") private Double milk; - @Excel(name = "班次校正奶量") + @Excel(name = "班次校正奶量", numFormat = "0.00") private Double correctedMilk; private String sheepId; diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpSheepMilkAnalysis.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpSheepMilkAnalysis.java index 0573a0d..84cedc0 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpSheepMilkAnalysis.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/NpSheepMilkAnalysis.java @@ -1,78 +1,141 @@ package com.zhyc.module.dairyProducts.domain; +import com.zhyc.common.annotation.Excel; import java.util.Date; public class NpSheepMilkAnalysis { // 唯一键(可用于前端 row-key) + @Excel(name = "羊只ID") private String sheepId; // 耳号(从 sheep_file.bs_manage_tags) + @Excel(name = "耳号") private String manageEarTag; + @Excel(name = "品种") private String variety; // 最高校正胎次的挤奶开始时间 & 干奶时间 + @Excel(name = "挤奶开始时间", dateFormat = "yyyy-MM-dd") private Date milkingStartTime; + + @Excel(name = "干奶时间", dateFormat = "yyyy-MM-dd") private Date dryEndTime; // 挤奶天数(该胎次) + @Excel(name = "挤奶天数") private Integer milkingDays; // 前端传入的筛选天数(screenDays) + @Excel(name = "筛选天数") private Integer screenDays; // 分析天数(若你有不同命名,可忽略) private Integer analysisDays; // 校正后最大胎次(即校正奶量之和最大的胎次) + @Excel(name = "校正后最大胎次") private Integer maxParity; // 最高校正胎次区间内的系统奶量与校正奶量(按筛选窗口) + @Excel(name = "系统奶量合计") private Double sumSystemMilk; + + @Excel(name = "校正奶量合计") private Double sumCorrectedMilk; - // 校正日平均奶量(按 min(挤奶天数, 筛选天数)) + // 校正日平均奶量(按min(挤奶天数,筛选天数)) + @Excel(name = "校正日平均奶量") private Double avgCorrectedDaily; // 各胎次总奶量(校正) + @Excel(name = "胎次1总奶量") private Double sumParity1Milk; + + @Excel(name = "胎次2总奶量") private Double sumParity2Milk; + + @Excel(name = "胎次3总奶量") private Double sumParity3Milk; + + @Excel(name = "胎次4总奶量") private Double sumParity4Milk; // 各胎次日平均(按规则) + @Excel(name = "胎次1日平均") private Double avgParity1Daily; + + @Excel(name = "胎次2日平均") private Double avgParity2Daily; + + @Excel(name = "胎次3日平均") private Double avgParity3Daily; + + @Excel(name = "胎次4日平均") private Double avgParity4Daily; // 泌乳天数(sheep_file.lactation_day) + @Excel(name = "泌乳天数") private Integer lactationDays; - // 过去 7 / 14 / 30 日平均(系统奶量) + // 过去7/14/30日平均(系统奶量) + @Excel(name = "过去7日均奶量") private Double avgLast7Milk; - private Double avgLast7Corrected; // = avgLast7Milk * weightCoefficient (默认 1.0) + + @Excel(name = "校正过去7日均") + private Double avgLast7Corrected; + + @Excel(name = "过去14日均奶量") private Double avgLast14Milk; + + @Excel(name = "过去30日均奶量") private Double avgLast30Milk; - // 羊只基础信息(来自 sheep_file) + // 羊只基础信息(来自sheep_file) + @Excel(name = "羊只类别") private String sheepCategory; + + @Excel(name = "生日", dateFormat = "yyyy-MM-dd") private Date birthday; - private Integer parity; // 当前胎次 + + @Excel(name = "当前胎次") + private Integer parity; + + @Excel(name = "月龄") private Integer monthAge; + + @Excel(name = "当前体重") private Double currentWeight; + + @Excel(name = "繁育状态") private String breedStatus; + + @Excel(name = "父号") private String fatherManageTags; + + @Excel(name = "母号") private String motherManageTags; + + @Excel(name = "牧场") private String ranchName; + + @Excel(name = "家系") private String family; // 母亲相关字段(由已计算的母亲分析结果中取值) + @Excel(name = "母亲挤奶天数") private Integer motherMilkingDays; + + @Excel(name = "母亲校正奶量合计") private Double motherSumCorrected; + + @Excel(name = "母亲校正后最大胎次") private Integer motherMaxParity; + + @Excel(name = "母亲校正日平均奶量") private Double motherAvgCorrectedDaily; + @Excel(name = "最后更新时间", dateFormat = "yyyy-MM-dd") private Date lastUpdate; // getters and setters @@ -195,4 +258,4 @@ public class NpSheepMilkAnalysis { public Date getLastUpdate() { return lastUpdate; } public void setLastUpdate(Date lastUpdate) { this.lastUpdate = lastUpdate; } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java index d877065..9c14456 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/domain/XzParityCorrection.java @@ -1,20 +1,16 @@ package com.zhyc.module.dairyProducts.domain; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +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; /** * 胎次校正对象 xz_parity_correction - * + * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ -@Data -@NoArgsConstructor -@AllArgsConstructor public class XzParityCorrection extends BaseEntity { private static final long serialVersionUID = 1L; @@ -30,4 +26,42 @@ public class XzParityCorrection extends BaseEntity @Excel(name = "系数") private Double coef; + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setParity(Integer parity) + { + this.parity = parity; + } + + public Integer getParity() + { + return parity; + } + + public void setCoef(Double coef) + { + this.coef = coef; + } + + public Double getCoef() + { + return coef; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("parity", getParity()) + .append("coef", getCoef()) + .toString(); + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/NpSheepMilkAnalysisMapper.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/NpSheepMilkAnalysisMapper.java index 002e009..1e35d56 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/NpSheepMilkAnalysisMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/NpSheepMilkAnalysisMapper.java @@ -9,7 +9,7 @@ import java.util.Map; public interface NpSheepMilkAnalysisMapper { /** - * 按筛选天数 screenDays 统计并返回所有羊只的奶产量分析 + * 按筛选天数screenDays统计并返回所有羊只的奶产量分析 */ List selectAnalysisForExport(@Param("screenDays") Integer screenDays); @@ -33,4 +33,9 @@ public interface NpSheepMilkAnalysisMapper { */ List> selectMilkRecordsBySheepId(@Param("sheepId") String sheepId); -} + /** + * 导出奶产量分析记录 + */ + List selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis); + +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java index d2f4654..3d9cf45 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/mapper/XzParityCorrectionMapper.java @@ -2,20 +2,18 @@ package com.zhyc.module.dairyProducts.mapper; import java.util.List; import com.zhyc.module.dairyProducts.domain.XzParityCorrection; -import org.apache.ibatis.annotations.Mapper; /** * 胎次校正Mapper接口 - * + * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ -@Mapper -public interface XzParityCorrectionMapper +public interface XzParityCorrectionMapper { /** * 查询胎次校正 - * + * * @param id 胎次校正主键 * @return 胎次校正 */ @@ -23,7 +21,7 @@ public interface XzParityCorrectionMapper /** * 查询胎次校正列表 - * + * * @param xzParityCorrection 胎次校正 * @return 胎次校正集合 */ @@ -31,7 +29,7 @@ public interface XzParityCorrectionMapper /** * 新增胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -39,7 +37,7 @@ public interface XzParityCorrectionMapper /** * 修改胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -47,7 +45,7 @@ public interface XzParityCorrectionMapper /** * 删除胎次校正 - * + * * @param id 胎次校正主键 * @return 结果 */ @@ -55,7 +53,7 @@ public interface XzParityCorrectionMapper /** * 批量删除胎次校正 - * + * * @param ids 需要删除的数据主键集合 * @return 结果 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/INpSheepMilkAnalysisService.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/INpSheepMilkAnalysisService.java index 8760789..5dded5c 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/INpSheepMilkAnalysisService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/INpSheepMilkAnalysisService.java @@ -9,4 +9,9 @@ public interface INpSheepMilkAnalysisService { List selectNpSheepMilkAnalysisList(NpSheepMilkAnalysis analysis); -} + /** + * 导出奶产量分析记录 + */ + List selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis); + +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java index d5c9ce2..8246bdd 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/IXzParityCorrectionService.java @@ -1,20 +1,19 @@ package com.zhyc.module.dairyProducts.service; import java.util.List; - import com.zhyc.module.dairyProducts.domain.XzParityCorrection; /** * 胎次校正Service接口 - * + * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ -public interface IXzParityCorrectionService +public interface IXzParityCorrectionService { /** * 查询胎次校正 - * + * * @param id 胎次校正主键 * @return 胎次校正 */ @@ -22,7 +21,7 @@ public interface IXzParityCorrectionService /** * 查询胎次校正列表 - * + * * @param xzParityCorrection 胎次校正 * @return 胎次校正集合 */ @@ -30,7 +29,7 @@ public interface IXzParityCorrectionService /** * 新增胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -38,7 +37,7 @@ public interface IXzParityCorrectionService /** * 修改胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -46,7 +45,7 @@ public interface IXzParityCorrectionService /** * 批量删除胎次校正 - * + * * @param ids 需要删除的胎次校正主键集合 * @return 结果 */ @@ -54,7 +53,7 @@ public interface IXzParityCorrectionService /** * 删除胎次校正信息 - * + * * @param id 胎次校正主键 * @return 结果 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/NpSheepMilkAnalysisServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/NpSheepMilkAnalysisServiceImpl.java index 161a381..7100ca4 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/NpSheepMilkAnalysisServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/NpSheepMilkAnalysisServiceImpl.java @@ -19,7 +19,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi @Autowired private NpSheepMilkAnalysisMapper npSheepMilkAnalysisMapper; - // 将 Rec 定义为静态内部类 + // 将Rec定义为静态内部类 private static class Rec { LocalDate date; double systemMilk; @@ -27,7 +27,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi int parity; } - // 将 ParityStat 定义为静态内部类 + // 将ParityStat定义为静态内部类 private static class ParityStat { int parity; double sumCorrected; @@ -85,7 +85,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi continue; } - // 使用静态内部类 Rec + // 使用静态内部类Rec List recs = new ArrayList<>(); for (Map r : records) { Rec rr = new Rec(); @@ -98,7 +98,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi Map> byParity = recs.stream().collect(Collectors.groupingBy(r -> r.parity)); - // 使用静态内部类 ParityStat + // 使用静态内部类ParityStat List parityStats = new ArrayList<>(); for (Map.Entry> e : byParity.entrySet()) { List list = e.getValue(); @@ -142,7 +142,7 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi double sumParity3 = parityStats.stream().filter(p -> p.parity == 3).mapToDouble(p -> p.sumCorrected).sum(); double sumParity4 = parityStats.stream().filter(p -> p.parity == 4).mapToDouble(p -> p.sumCorrected).sum(); - // 你之前的 computeParityAvg 方法里没实现,保留调用0 + // 你之前的computeParityAvg方法里没实现,保留调用0 double avgP1 = computeParityAvg(parityStats, 1, screenDays); double avgP2 = computeParityAvg(parityStats, 2, screenDays); double avgP3 = computeParityAvg(parityStats, 3, screenDays); @@ -219,6 +219,12 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi return resultList; } + @Override + public List selectNpSheepMilkAnalysisForExport(NpSheepMilkAnalysis analysis) { + // 直接调用Mapper的导出方法,避免复杂的业务逻辑 + return npSheepMilkAnalysisMapper.selectNpSheepMilkAnalysisForExport(analysis); + } + private static Date convertToDate(Object obj) { if (obj == null) return null; if (obj instanceof Date) { @@ -283,4 +289,4 @@ public class NpSheepMilkAnalysisServiceImpl implements INpSheepMilkAnalysisServi } return (count > 0) ? (sum / count) : 0.0; } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzDryMatterCorrectionServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzDryMatterCorrectionServiceImpl.java index 4bf9fb2..88894c8 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzDryMatterCorrectionServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzDryMatterCorrectionServiceImpl.java @@ -44,29 +44,62 @@ public class XzDryMatterCorrectionServiceImpl implements IXzDryMatterCorrectionS } /** - * 新增干物质校正 - * - * @param xzDryMatterCorrection 干物质校正 - * @return 结果 + * 新增干物质校正 - 添加默认值和重复校验 */ @Override public int insertXzDryMatterCorrection(XzDryMatterCorrection xzDryMatterCorrection) { + // 设置干物质标准默认值为18(如果未提供) + if (xzDryMatterCorrection.getStandard() == null) { + xzDryMatterCorrection.setStandard(18.0); + } + + // 检查同年月同厂区是否已存在 + if (isDuplicateRecord(xzDryMatterCorrection)) { + throw new RuntimeException("该厂区在同一年月已存在记录,不能重复添加"); + } + return xzDryMatterCorrectionMapper.insertXzDryMatterCorrection(xzDryMatterCorrection); } /** - * 修改干物质校正 - * - * @param xzDryMatterCorrection 干物质校正 - * @return 结果 + * 修改干物质校正 - 添加重复校验 */ @Override public int updateXzDryMatterCorrection(XzDryMatterCorrection xzDryMatterCorrection) { + // 检查同年月同厂区是否已存在(排除当前记录) + if (isDuplicateRecord(xzDryMatterCorrection)) { + throw new RuntimeException("该厂区在同一年月已存在记录,不能重复添加"); + } + return xzDryMatterCorrectionMapper.updateXzDryMatterCorrection(xzDryMatterCorrection); } + + /** + * 检查是否存在重复记录(同年月同厂区) + */ + private boolean isDuplicateRecord(XzDryMatterCorrection xzDryMatterCorrection) { + // 查询相同年月和厂区的记录 + XzDryMatterCorrection query = new XzDryMatterCorrection(); + query.setDatetime(xzDryMatterCorrection.getDatetime()); + query.setFactory(xzDryMatterCorrection.getFactory()); + + List existingRecords = xzDryMatterCorrectionMapper.selectXzDryMatterCorrectionList(query); + + // 如果是更新操作,需要排除当前记录 + if (xzDryMatterCorrection.getId() != null) { + return existingRecords.stream() + .anyMatch(record -> + !record.getId().equals(xzDryMatterCorrection.getId()) + ); + } + + // 如果是新增操作,只要存在记录就返回true + return !existingRecords.isEmpty(); + } + /** * 批量删除干物质校正 * diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java index 49f5731..caff850 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzParityCorrectionServiceImpl.java @@ -1,28 +1,27 @@ package com.zhyc.module.dairyProducts.service.impl; import java.util.List; - -import com.zhyc.module.dairyProducts.mapper.XzParityCorrectionMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.zhyc.module.dairyProducts.mapper.XzParityCorrectionMapper; import com.zhyc.module.dairyProducts.domain.XzParityCorrection; import com.zhyc.module.dairyProducts.service.IXzParityCorrectionService; /** * 胎次校正Service业务层处理 - * + * * @author ruoyi - * @date 2025-07-14 + * @date 2025-08-24 */ @Service -public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService +public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService { @Autowired private XzParityCorrectionMapper xzParityCorrectionMapper; /** * 查询胎次校正 - * + * * @param id 胎次校正主键 * @return 胎次校正 */ @@ -34,7 +33,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 查询胎次校正列表 - * + * * @param xzParityCorrection 胎次校正 * @return 胎次校正 */ @@ -46,7 +45,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 新增胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -58,7 +57,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 修改胎次校正 - * + * * @param xzParityCorrection 胎次校正 * @return 结果 */ @@ -70,7 +69,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 批量删除胎次校正 - * + * * @param ids 需要删除的胎次校正主键 * @return 结果 */ @@ -82,7 +81,7 @@ public class XzParityCorrectionServiceImpl implements IXzParityCorrectionService /** * 删除胎次校正信息 - * + * * @param id 胎次校正主键 * @return 结果 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzWegihCorrectionServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzWegihCorrectionServiceImpl.java index 7869c42..c27e6df 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzWegihCorrectionServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/dairyProducts/service/impl/XzWegihCorrectionServiceImpl.java @@ -1,7 +1,10 @@ package com.zhyc.module.dairyProducts.service.impl; +import java.util.Date; import java.util.List; +import java.util.stream.Collectors; +import com.zhyc.common.exception.ServiceException; import com.zhyc.module.dairyProducts.domain.XzWegihCorrection; import com.zhyc.module.dairyProducts.mapper.XzWegihCorrectionMapper; import com.zhyc.module.dairyProducts.service.IXzWegihCorrectionService; @@ -44,27 +47,60 @@ public class XzWegihCorrectionServiceImpl implements IXzWegihCorrectionService return xzWegihCorrectionMapper.selectXzWegihCorrectionList(xzWegihCorrection); } + /** + * 检查是否已存在相同日期和厂区的记录 + * @param datetime 日期 + * @param factory 厂区 + * @param excludeId 需要排除的ID(用于更新操作时排除自身) + * @return 如果存在返回true,否则返回false + */ + private boolean existsSameDateAndFactory(Date datetime, String factory, Long excludeId) { + // 创建一个查询条件对象 + XzWegihCorrection query = new XzWegihCorrection(); + query.setDatetime(datetime); + query.setFactory(factory); + + // 查询符合条件的记录 + List existingRecords = xzWegihCorrectionMapper.selectXzWegihCorrectionList(query); + + // 如果有需要排除的ID(更新操作),则过滤掉自身 + if (excludeId != null) { + existingRecords = existingRecords.stream() + .filter(record -> !record.getId().equals(excludeId)) + .collect(Collectors.toList()); + } + + // 如果找到记录,返回true + return !existingRecords.isEmpty(); + } + /** * 新增称重校正 - * - * @param xzWegihCorrection 称重校正 - * @return 结果 */ @Override public int insertXzWegihCorrection(XzWegihCorrection xzWegihCorrection) { + // 新增前检查是否已存在相同日期和厂区的记录 + if (existsSameDateAndFactory(xzWegihCorrection.getDatetime(), xzWegihCorrection.getFactory(), null)) { + // 抛出异常,提示用户已存在相同记录 + throw new ServiceException("已存在相同日期和厂区的记录,请勿重复添加"); + } + return xzWegihCorrectionMapper.insertXzWegihCorrection(xzWegihCorrection); } /** * 修改称重校正 - * - * @param xzWegihCorrection 称重校正 - * @return 结果 */ @Override public int updateXzWegihCorrection(XzWegihCorrection xzWegihCorrection) { + // 更新前检查是否已存在相同日期和厂区的记录(排除自身) + if (existsSameDateAndFactory(xzWegihCorrection.getDatetime(), xzWegihCorrection.getFactory(), xzWegihCorrection.getId())) { + // 抛出异常,提示用户已存在相同记录 + throw new ServiceException("已存在相同日期和厂区的记录,无法修改"); + } + return xzWegihCorrectionMapper.updateXzWegihCorrection(xzWegihCorrection); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedListController.java b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedListController.java index 446327d..db39029 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedListController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedListController.java @@ -1,15 +1,12 @@ package com.zhyc.module.feed.controller; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Arrays; +import java.util.Comparator; import java.util.List; -import java.util.Map; import javax.servlet.http.HttpServletResponse; -import com.zhyc.module.feed.domain.SgFeedPlan; -import com.zhyc.module.feed.domain.SgFormulaManagement; -import com.zhyc.module.feed.service.ISgFeedPlanService; -import com.zhyc.module.feed.service.ISgFormulaManagementService; +import com.zhyc.module.feed.service.impl.SgFeedListServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -41,19 +38,12 @@ import com.zhyc.common.core.page.TableDataInfo; public class SgFeedListController extends BaseController { private final ISgFeedListService sgFeedListService; - private final ISgFormulaManagementService sgFormulaManagementService; - - private final ISgFeedPlanService sgFeedPlanService; - - private final Map sgFeedListMap = new HashMap<>(); public static boolean refresh = true; @Autowired - public SgFeedListController(ISgFeedListService sgFeedListService, ISgFormulaManagementService sgFormulaManagementService, ISgFeedPlanService sgFeedPlanService) { + public SgFeedListController(ISgFeedListService sgFeedListService) { this.sgFeedListService = sgFeedListService; - this.sgFormulaManagementService = sgFormulaManagementService; - this.sgFeedPlanService = sgFeedPlanService; } /** @@ -68,26 +58,26 @@ public class SgFeedListController extends BaseController { 当配方管理表出现更新 或 饲喂计划表出现增删改时会将refresh置为true 通知此处进行刷新 */ if (refresh) { - SyncFeedList(); + sgFeedListService.SyncFeedList(); refresh = false; } startPage(); List list = sgFeedListService.selectSgFeedListList(sgFeedList); // 用 map 中已有的数据替换 list 中的元素 List replacedList = new ArrayList<>(); - for (SgFeedList item : list) { - String key = item.getFormulaId() + "_" + item.getFormulaBatchId(); - // 从缓存中取出完整对象 - SgFeedList itemInCache = sgFeedListMap.getOrDefault(key, item); - // 将数据库查询的基本信息替换掉缓存中去除的内容 - 前端展示与修改需要 - itemInCache.setId(item.getId()); - itemInCache.setFormulaBatchId(item.getFormulaBatchId()); - itemInCache.setFormulaId(item.getFormulaId()); - itemInCache.setZookeeper(item.getZookeeper()); - itemInCache.setDeployDate(item.getDeployDate()); - // 替换为 map 中的对象 - replacedList.add(itemInCache); - } + for (SgFeedList item : list) { + String key = item.getFormulaId() + "_" + item.getFormulaBatchId() + "_" + item.getDeployDate(); + // 从缓存中取出完整对象 + SgFeedList itemInCache = SgFeedListServiceImpl.getSgFeedListMap().getOrDefault(key, item); + // 将数据库查询的基本信息替换掉缓存中去除的内容 - 前端展示与修改需要 + itemInCache.setId(item.getId()); + itemInCache.setFormulaBatchId(item.getFormulaBatchId()); + itemInCache.setFormulaId(item.getFormulaId()); + itemInCache.setZookeeper(item.getZookeeper()); + itemInCache.setDeployDate(item.getDeployDate()); + // 替换为 map 中的对象 + replacedList.add(itemInCache); + } return getDataTable(replacedList); } @@ -129,6 +119,7 @@ public class SgFeedListController extends BaseController { @Log(title = "配料清单", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody SgFeedList sgFeedList) { + return toAjax(sgFeedListService.updateSgFeedList(sgFeedList)); } @@ -143,94 +134,4 @@ public class SgFeedListController extends BaseController { return toAjax(sgFeedListService.deleteSgFeedListByIds(ids)); } - - public void SyncFeedList() { - // 清空旧缓存 - sgFeedListMap.clear(); - // 获取配方管理和现有配料清单内容 - List formulaManagementList = sgFormulaManagementService.selectSgFormulaManagementList(new SgFormulaManagement()); - List feedLists = sgFeedListService.selectSgFeedListList(new SgFeedList()); - // 将最新查询的配料清单加入缓存 - for (SgFeedList sgFeedList : feedLists) { - sgFeedListMap.put(sgFeedList.getFormulaId() + "_" + sgFeedList.getFormulaBatchId(), sgFeedList); - } - // 与新的配方管理列表同步 - 如果配料清单没有对应数据则加入 - for (SgFormulaManagement sgFormulaManagement : formulaManagementList) { - // 匹配 但忽略模板配方 - if (sgFormulaManagement.getFormulaId() != null && sgFormulaManagement.getBatchId() != null && !sgFormulaManagement.getBatchId().equals("0")) { - // 查询当前配方管理项是否存在现有配料计划中 (不论是否存在都要设置,因为缓存被清空,存在则更新,不存在则插入) - boolean isExist = sgFeedListMap.containsKey(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId()); - // 标志位 : 如果当前配方不在饲喂计划中则不生成配量清单 - boolean isPlan = true; - // 设置缓存对象具体值 - SgFeedList sgFeedList = new SgFeedList(); - sgFeedList.setFormulaId(sgFormulaManagement.getFormulaId()); - sgFeedList.setFormulaBatchId(sgFormulaManagement.getBatchId()); - sgFeedList.setFormulaList(sgFormulaManagement.getSgFormulaList()); - sgFeedList.setRootFormula(sgFormulaManagement); - - - // 从饲喂计划列表中查出对应值(饲喂量需要计划中的比例计算) - SgFeedPlan rootPlanQuery = new SgFeedPlan(); - rootPlanQuery.setFormulaId(sgFormulaManagement.getFormulaId()); - rootPlanQuery.setBatchId(sgFormulaManagement.getBatchId()); - List sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(rootPlanQuery); - // 为空则标识当前配方不在饲喂计划中 && 不在缓存中设置 - if (sgFeedPlans.isEmpty()) { - isPlan = false; - } else { - // rootPlan中存储的是该配方批号的总量 - SgFeedPlan rootPlan = computePlanTotal(sgFeedPlans); - - // 将计划实体对象设置到配料清单中 - sgFeedList.setRootPlan(rootPlan); - - // 完整的配料清单对象加入缓存 - sgFeedListMap.put(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId(), sgFeedList); - } - - // 不存在则插入 - if (!isExist && isPlan) { - sgFeedListService.insertSgFeedList(sgFeedList); - } - } - } - } - - /** - * 计算某个配方某个批次的总和值 - * - * @param sgFeedPlans 配方计划列表 - * @return 各个值总和 - */ - private static SgFeedPlan computePlanTotal(List sgFeedPlans) { - SgFeedPlan rootPlan = new SgFeedPlan(); - if (!sgFeedPlans.isEmpty()) { - int sheepCountTotal = 0; - double sheepDailySize = 0.0; - double planFeedMorningSize = 0.0; - double planFeedNoonSize = 0.0; - double planFeedAfternoonSize = 0.0; - double planFeedTotalSize = 0.0; - for (SgFeedPlan sgFeedPlan : sgFeedPlans) { - sheepCountTotal += sgFeedPlan.getSheepCount(); - sheepDailySize += sgFeedPlan.getPlanDailySize(); - planFeedMorningSize += sgFeedPlan.getPlanMorningSize(); - planFeedNoonSize += sgFeedPlan.getPlanNoonSize(); - planFeedAfternoonSize += sgFeedPlan.getPlanAfternoonSize(); - planFeedTotalSize += sgFeedPlan.getPlanFeedTotal(); - } - - rootPlan.setSheepCount(sheepCountTotal); - rootPlan.setPlanDailySize(sheepDailySize); - rootPlan.setPlanMorningSize(planFeedMorningSize); - rootPlan.setPlanNoonSize(planFeedNoonSize); - rootPlan.setPlanAfternoonSize(planFeedAfternoonSize); - rootPlan.setPlanFeedTotal(planFeedTotalSize); - - // 设置计划日期 - rootPlan.setPlanDate(sgFeedPlans.get(0).getPlanDate()); - } - return rootPlan; - } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedStatisticController.java b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedStatisticController.java new file mode 100644 index 0000000..de0334f --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgFeedStatisticController.java @@ -0,0 +1,129 @@ +package com.zhyc.module.feed.controller; + +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import com.zhyc.common.utils.uuid.UUID; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; +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.feed.domain.SgFeedStatistic; +import com.zhyc.module.feed.service.ISgFeedStatisticService; +import com.zhyc.common.utils.poi.ExcelUtil; +import com.zhyc.common.core.page.TableDataInfo; + +/** + * 饲喂量统计Controller + * + * @author HashMap + * @date 2025-08-23 + */ +@RestController +@RequestMapping("/feed/FeedStatistic") +@Transactional(rollbackFor = Exception.class) +public class SgFeedStatisticController extends BaseController { + private final ISgFeedStatisticService sgFeedStatisticService; + + + + public SgFeedStatisticController(ISgFeedStatisticService sgFeedStatisticService) { + this.sgFeedStatisticService = sgFeedStatisticService; + } + + /** + * 查询饲喂量统计列表 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:list')") + @GetMapping("/list") + public TableDataInfo list(SgFeedStatistic sgFeedStatistic) { + startPage(); + List list = sgFeedStatisticService.selectSgFeedStatisticList(sgFeedStatistic); + return getDataTable(list); + } + + /** + * 导出饲喂量统计列表 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:export')") + @Log(title = "饲喂量统计", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SgFeedStatistic sgFeedStatistic) { + List list = sgFeedStatisticService.selectSgFeedStatisticList(sgFeedStatistic); + ExcelUtil util = new ExcelUtil<>(SgFeedStatistic.class); + util.exportExcel(response, list, "饲喂量统计数据"); + } + + /** + * 获取饲喂量统计详细信息 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") String id) { + return success(sgFeedStatisticService.selectSgFeedStatisticById(id)); + } + + /** + * 新增饲喂量统计 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:add')") + @Log(title = "饲喂量统计", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SgFeedStatistic sgFeedStatistic) { + if (null == sgFeedStatistic.getFormulaId() && null == sgFeedStatistic.getFormulaBatchId()) { + throw new RuntimeException("ERROR: 数据为空"); + } + List isExist = sgFeedStatisticService.selectSgFeedStatisticList(sgFeedStatistic); + if (null != isExist && !isExist.isEmpty()) { + throw new RuntimeException("WARNING: 数据重复"); + } + // 设定唯一标识符主键 + sgFeedStatistic.setId(UUID.randomUUID().toString()); + /* + * 初始化数据 + * 弃用: 此处不再需要初始化,前端选定批号后会触发预载, 此处再初始化会覆盖前端后续的自定义数据 + */ + // sgFeedStatisticService.getInitSgFeedStatistic(sgFeedStatistic); + return toAjax(sgFeedStatisticService.insertSgFeedStatistic(sgFeedStatistic)); + } + + /** + * 修改饲喂量统计 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:edit')") + @Log(title = "饲喂量统计", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SgFeedStatistic sgFeedStatistic) { + return toAjax(sgFeedStatisticService.updateSgFeedStatistic(sgFeedStatistic)); + } + + /** + * 删除饲喂量统计 + */ + @PreAuthorize("@ss.hasPermi('feed:FeedStatistic:remove')") + @Log(title = "饲喂量统计", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable String[] ids) { + return toAjax(sgFeedStatisticService.deleteSgFeedStatisticByIds(ids)); + } + + @GetMapping("/init") + public TableDataInfo getInitData(SgFeedStatistic sgFeedStatistic){ + sgFeedStatisticService.getInitSgFeedStatistic(sgFeedStatistic); + // 兼容写法 - 实际只是为了返回一个 sgFeedStatistic + List list = new ArrayList<>(); + list.add(sgFeedStatistic); + return getDataTable(list); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedList.java b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedList.java index 0b3c61b..41ca828 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedList.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedList.java @@ -53,6 +53,8 @@ public class SgFeedList extends BaseEntity private List formulaList; + private List planList; + @Override public String toString() { diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedStatistic.java b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedStatistic.java new file mode 100644 index 0000000..2cdc21e --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFeedStatistic.java @@ -0,0 +1,98 @@ +package com.zhyc.module.feed.domain; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.zhyc.module.base.domain.DaSheepfold; +import lombok.Getter; +import lombok.Setter; +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; + +import java.util.Date; +import java.util.List; + +/** + * 饲喂量统计对象 sg_feed_statistic + * + * @author HashMap + * @date 2025-08-23 + */ +@Setter +@Getter +public class SgFeedStatistic extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * UUID + */ + private String id; + + /** + * 配方编号 + */ + @Excel(name = "配方编号") + private String formulaId; + + /** + * 配方批号 + */ + @Excel(name = "配方批号") + private String formulaBatchId; + + /** + * 羊只数量 + */ + @Excel(name = "羊只数量") + private Long sheepFoldCount; + + /** + * 青贮损耗比例 + */ + @Excel(name = "青贮损耗比例") + private String silageLossRate; + + /** + * 总饲喂量 + */ + @Excel(name = "总饲喂量") + private Double feedTotalSize; + + /** + * 日均饲喂量 + */ + @Excel(name = "日均饲喂量") + private Double feedDailySize; + + /** + * 配方列表 + */ + @Excel(name = "配方列表") + private List materialList; + + /** + * 羊舍列表 + */ + @Excel(name = "羊舍列表") + private List sheepFoldList; + + @Excel(name = "日期") + @JsonFormat(pattern = "yyyy-MM-dd") + private Date feedDate; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("formulaId", getFormulaId()) + .append("formulaBatchId", getFormulaBatchId()) + .append("sheepFoldCount", getSheepFoldCount()) + .append("silageLossRate", getSilageLossRate()) + .append("feedTotalSize", getFeedTotalSize()) + .append("feedDailySize", getFeedDailySize()) + .append("materialList", getMaterialList()) + .append("sheepFoldList", getSheepFoldList()) + .toString(); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFormulaList.java b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFormulaList.java index 03ab542..aac1fc9 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFormulaList.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgFormulaList.java @@ -39,14 +39,25 @@ public class SgFormulaList extends BaseEntity @Excel(name = "比例") private Long ratio; - /** 颗粒原料 */ + /** + * 颗粒原料 + * 当前不局限于 "是否颗粒原料" 而且多种类型的标识符 + */ @Excel(name = "颗粒原料") private String isGranular; - /** 补饲 */ + /** + * 补饲 + * 当前用作饲喂类型标识 + */ @Excel(name = "补饲") private String isSupplement; + /** + * 添加量 - 供其他一些统计模块使用 + */ + private Double feedSize; + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedListMapper.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedListMapper.java index 47e837c..b80e580 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedListMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedListMapper.java @@ -60,4 +60,7 @@ public interface SgFeedListMapper * @return 结果 */ int deleteSgFeedListByIds(Long[] ids); + + // 清空所有 + int deleteAll(); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedStatisticMapper.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedStatisticMapper.java new file mode 100644 index 0000000..abee631 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgFeedStatisticMapper.java @@ -0,0 +1,63 @@ +package com.zhyc.module.feed.mapper; + +import java.util.List; +import com.zhyc.module.feed.domain.SgFeedStatistic; +import org.apache.ibatis.annotations.Mapper; + +/** + * 饲喂量统计Mapper接口 + * + * @author HashMap + * @date 2025-08-23 + */ +@Mapper +public interface SgFeedStatisticMapper +{ + /** + * 查询饲喂量统计 + * + * @param id 饲喂量统计主键 + * @return 饲喂量统计 + */ + SgFeedStatistic selectSgFeedStatisticById(String id); + + /** + * 查询饲喂量统计列表 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 饲喂量统计集合 + */ + List selectSgFeedStatisticList(SgFeedStatistic sgFeedStatistic); + + /** + * 新增饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + int insertSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + /** + * 修改饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + int updateSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + /** + * 删除饲喂量统计 + * + * @param id 饲喂量统计主键 + * @return 结果 + */ + int deleteSgFeedStatisticById(String id); + + /** + * 批量删除饲喂量统计 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + int deleteSgFeedStatisticByIds(String[] ids); +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/DaSheepfoldHandler.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/DaSheepfoldHandler.java new file mode 100644 index 0000000..af89abc --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/DaSheepfoldHandler.java @@ -0,0 +1,38 @@ +package com.zhyc.module.feed.mapper.TypeHandler; + +import com.alibaba.fastjson2.JSON; +import com.zhyc.module.base.domain.DaSheepfold; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +@MappedTypes(List.class) +public class DaSheepfoldHandler extends BaseTypeHandler> { + @Override + public void setNonNullParameter(PreparedStatement ps, int i, + List parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, JSON.toJSONString(parameter)); + } + + @Override + public List getNullableResult(ResultSet rs, String columnName) throws SQLException { + return JSON.parseArray(rs.getString(columnName), DaSheepfold.class); + } + + @Override + public List getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + return JSON.parseArray(rs.getString(columnIndex), DaSheepfold.class); + } + + @Override + public List getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + return JSON.parseArray(cs.getString(columnIndex), DaSheepfold.class); + } +} + diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/JsonTypeHandler.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/JsonTypeHandler.java new file mode 100644 index 0000000..dd0d22f --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/JsonTypeHandler.java @@ -0,0 +1,42 @@ +package com.zhyc.module.feed.mapper.TypeHandler; + +import com.alibaba.fastjson2.JSON; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class JsonTypeHandler extends BaseTypeHandler { + private final Class type; + + public JsonTypeHandler(Class type) { + this.type = type; + } + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, JSON.toJSONString(parameter)); + } + + @Override + public T getNullableResult(ResultSet rs, String columnName) throws SQLException { + String json = rs.getString(columnName); + return JSON.parseObject(json, type); + } + + @Override + public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + String json = rs.getString(columnIndex); + return JSON.parseObject(json, type); + } + + @Override + public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + String json = cs.getString(columnIndex); + return JSON.parseObject(json, type); + } +} + diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/SgFormulaListHandler.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/SgFormulaListHandler.java new file mode 100644 index 0000000..10d857b --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/TypeHandler/SgFormulaListHandler.java @@ -0,0 +1,37 @@ +package com.zhyc.module.feed.mapper.TypeHandler; + +import com.alibaba.fastjson2.JSON; +import com.zhyc.module.feed.domain.SgFormulaList; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +@MappedTypes(List.class) +public class SgFormulaListHandler extends BaseTypeHandler> { + @Override + public void setNonNullParameter(PreparedStatement ps, int i, + List parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, JSON.toJSONString(parameter)); + } + + @Override + public List getNullableResult(ResultSet rs, String columnName) throws SQLException { + return JSON.parseArray(rs.getString(columnName), SgFormulaList.class); + } + + @Override + public List getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + return JSON.parseArray(rs.getString(columnIndex), SgFormulaList.class); + } + + @Override + public List getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + return JSON.parseArray(cs.getString(columnIndex), SgFormulaList.class); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedListService.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedListService.java index b293d84..b3c5a5f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedListService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedListService.java @@ -1,6 +1,7 @@ package com.zhyc.module.feed.service; import java.util.List; + import com.zhyc.module.feed.domain.SgFeedList; /** @@ -9,8 +10,7 @@ import com.zhyc.module.feed.domain.SgFeedList; * @author HashMap * @date 2025-08-19 */ -public interface ISgFeedListService -{ +public interface ISgFeedListService { /** * 查询配料清单 * @@ -58,4 +58,6 @@ public interface ISgFeedListService * @return 结果 */ int deleteSgFeedListById(Long id); + + void SyncFeedList(); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedStatisticService.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedStatisticService.java new file mode 100644 index 0000000..9bdad7a --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgFeedStatisticService.java @@ -0,0 +1,65 @@ +package com.zhyc.module.feed.service; + +import java.util.List; +import com.zhyc.module.feed.domain.SgFeedStatistic; + +/** + * 饲喂量统计Service接口 + * + * @author HashMap + * @date 2025-08-23 + */ +public interface ISgFeedStatisticService +{ + /** + * 查询饲喂量统计 + * + * @param id 饲喂量统计主键 + * @return 饲喂量统计 + */ + SgFeedStatistic selectSgFeedStatisticById(String id); + + /** + * 查询饲喂量统计列表 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 饲喂量统计集合 + */ + List selectSgFeedStatisticList(SgFeedStatistic sgFeedStatistic); + + /** + * 新增饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + int insertSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + /** + * 修改饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + int updateSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + /** + * 批量删除饲喂量统计 + * + * @param ids 需要删除的饲喂量统计主键集合 + * @return 结果 + */ + int deleteSgFeedStatisticByIds(String[] ids); + + /** + * 删除饲喂量统计信息 + * + * @param id 饲喂量统计主键 + * @return 结果 + */ + int deleteSgFeedStatisticById(String id); + + void getInitSgFeedStatistic(SgFeedStatistic sgFeedStatistic); + + +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedListServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedListServiceImpl.java index 704d45d..894ff47 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedListServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedListServiceImpl.java @@ -1,7 +1,12 @@ package com.zhyc.module.feed.service.impl; -import java.util.List; +import java.util.*; +import com.zhyc.module.feed.domain.SgFeedPlan; +import com.zhyc.module.feed.domain.SgFormulaManagement; +import com.zhyc.module.feed.service.ISgFeedPlanService; +import com.zhyc.module.feed.service.ISgFormulaManagementService; +import lombok.Getter; import org.springframework.stereotype.Service; import com.zhyc.module.feed.mapper.SgFeedListMapper; import com.zhyc.module.feed.domain.SgFeedList; @@ -14,12 +19,23 @@ import com.zhyc.module.feed.service.ISgFeedListService; * @date 2025-08-19 */ @Service -public class SgFeedListServiceImpl implements ISgFeedListService -{ +public class SgFeedListServiceImpl implements ISgFeedListService { private final SgFeedListMapper sgFeedListMapper; + private final ISgFormulaManagementService sgFormulaManagementService; + private final ISgFeedPlanService sgFeedPlanService; + @Getter + private final static Map sgFeedListMap = new HashMap<>(); - public SgFeedListServiceImpl(SgFeedListMapper sgFeedListMapper) { + public SgFeedListServiceImpl(SgFeedListMapper sgFeedListMapper, ISgFormulaManagementService sgFormulaManagementService, ISgFeedPlanService sgFeedPlanService) { this.sgFeedListMapper = sgFeedListMapper; + this.sgFormulaManagementService = sgFormulaManagementService; + this.sgFeedPlanService = sgFeedPlanService; + // 构造时将数据库初始数据写入缓存 + List feedListsFromDataBase = this.selectSgFeedListList(new SgFeedList()); + for (SgFeedList sgFeedListItem : feedListsFromDataBase) { + String key = sgFeedListItem.getFormulaId() + "_" + sgFeedListItem.getFormulaBatchId() + "_" + sgFeedListItem.getDeployDate(); + sgFeedListMap.put(key, sgFeedListItem); + } } /** @@ -29,8 +45,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 配料清单 */ @Override - public SgFeedList selectSgFeedListById(Long id) - { + public SgFeedList selectSgFeedListById(Long id) { return sgFeedListMapper.selectSgFeedListById(id); } @@ -41,8 +56,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 配料清单 */ @Override - public List selectSgFeedListList(SgFeedList sgFeedList) - { + public List selectSgFeedListList(SgFeedList sgFeedList) { return sgFeedListMapper.selectSgFeedListList(sgFeedList); } @@ -53,8 +67,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 结果 */ @Override - public int insertSgFeedList(SgFeedList sgFeedList) - { + public int insertSgFeedList(SgFeedList sgFeedList) { return sgFeedListMapper.insertSgFeedList(sgFeedList); } @@ -65,8 +78,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 结果 */ @Override - public int updateSgFeedList(SgFeedList sgFeedList) - { + public int updateSgFeedList(SgFeedList sgFeedList) { return sgFeedListMapper.updateSgFeedList(sgFeedList); } @@ -77,8 +89,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 结果 */ @Override - public int deleteSgFeedListByIds(Long[] ids) - { + public int deleteSgFeedListByIds(Long[] ids) { return sgFeedListMapper.deleteSgFeedListByIds(ids); } @@ -89,8 +100,166 @@ public class SgFeedListServiceImpl implements ISgFeedListService * @return 结果 */ @Override - public int deleteSgFeedListById(Long id) - { + public int deleteSgFeedListById(Long id) { return sgFeedListMapper.deleteSgFeedListById(id); } + + public void SyncFeedList_old() { + // 清空旧缓存 + sgFeedListMap.clear(); + // 获取配方管理和现有配料清单内容 + List formulaManagementList = sgFormulaManagementService.selectSgFormulaManagementList(new SgFormulaManagement()); + List feedLists = this.selectSgFeedListList(new SgFeedList()); + // 将最新查询的配料清单加入缓存 + for (SgFeedList sgFeedList : feedLists) { + sgFeedListMap.put(sgFeedList.getFormulaId() + "_" + sgFeedList.getFormulaBatchId(), sgFeedList); + } + // 与新的配方管理列表同步 - 如果配料清单没有对应数据则加入 + for (SgFormulaManagement sgFormulaManagement : formulaManagementList) { + // 匹配 但忽略模板配方 + if (sgFormulaManagement.getFormulaId() != null && sgFormulaManagement.getBatchId() != null && !sgFormulaManagement.getBatchId().equals("0")) { + // 查询当前配方管理项是否存在现有配料计划中 (不论是否存在都要设置,因为缓存被清空,存在则更新,不存在则插入) + boolean isExist = sgFeedListMap.containsKey(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId()); + // 标志位 : 如果当前配方不在饲喂计划中则不生成配量清单 + boolean isPlan = true; + // 设置缓存对象具体值 + SgFeedList sgFeedList = new SgFeedList(); + sgFeedList.setFormulaId(sgFormulaManagement.getFormulaId()); + sgFeedList.setFormulaBatchId(sgFormulaManagement.getBatchId()); + sgFeedList.setFormulaList(sgFormulaManagement.getSgFormulaList()); + sgFeedList.setRootFormula(sgFormulaManagement); + + + // 从饲喂计划列表中查出对应值(饲喂量需要计划中的比例计算) + SgFeedPlan rootPlanQuery = new SgFeedPlan(); + rootPlanQuery.setFormulaId(sgFormulaManagement.getFormulaId()); + rootPlanQuery.setBatchId(sgFormulaManagement.getBatchId()); + List sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(rootPlanQuery); + // 为空则标识当前配方不在饲喂计划中 && 不在缓存中设置 + if (sgFeedPlans.isEmpty()) { + isPlan = false; + } else { + // rootPlan中存储的是该配方批号的总量 + SgFeedPlan rootPlan = computePlanTotal(sgFeedPlans); + + // 将计划实体对象设置到配料清单中 + sgFeedList.setRootPlan(rootPlan); + + // 完整的配料清单对象加入缓存 + sgFeedListMap.put(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId(), sgFeedList); + } + + // 不存在则插入 + if (!isExist && isPlan) { + this.insertSgFeedList(sgFeedList); + } + } + } + } + + public void SyncFeedList() { + HashMap cacheTemp = new HashMap<>(sgFeedListMap); + // 清空旧缓存 + sgFeedListMap.clear(); + List sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(new SgFeedPlan()); + List> planGroups = new ArrayList<>(); + List currentFeedPlan = new ArrayList<>(); + if (!sgFeedPlans.isEmpty()) { + String currentFormulaId = sgFeedPlans.get(0).getFormulaId(); + String currentBatchId = sgFeedPlans.get(0).getBatchId(); + Date currentDate = sgFeedPlans.get(0).getPlanDate(); + // 对饲喂计划进行分组 + for (SgFeedPlan sgFeedPlan : sgFeedPlans) { + if (sgFeedPlan.getBatchId() != null && !sgFeedPlan.getBatchId().equals("0")) { + if (sgFeedPlan.getFormulaId().equals(currentFormulaId) && sgFeedPlan.getBatchId().equals(currentBatchId) && sgFeedPlan.getPlanDate().equals(currentDate)) { + currentFeedPlan.add(sgFeedPlan); + } else { + currentDate = sgFeedPlan.getPlanDate(); + currentBatchId = sgFeedPlan.getBatchId(); + currentFormulaId = sgFeedPlan.getFormulaId(); + planGroups.add(currentFeedPlan); + currentFeedPlan = new ArrayList<>(); + // 立即插入否则会丢失该元素 + currentFeedPlan.add(sgFeedPlan); + } + } + } + // 插入最后一个列表 - 否则该列表会丢失 + planGroups.add(currentFeedPlan); + // 注册数据 - 每一个List为一个清单 + for (List sgFeedPlanList : planGroups) { + SgFeedList sgFeedList = new SgFeedList(); + // 计算饲喂总和 + SgFeedPlan rootPlan = computePlanTotal(sgFeedPlanList); + sgFeedList.setRootPlan(rootPlan); + sgFeedList.setPlanList(sgFeedPlanList); + // 写入信息 + sgFeedList.setFormulaId(sgFeedPlanList.get(0).getFormulaId()); + sgFeedList.setFormulaBatchId(sgFeedPlanList.get(0).getBatchId()); + sgFeedList.setDeployDate(sgFeedPlanList.get(0).getPlanDate()); + // 写入配方管理信息 + SgFormulaManagement formulaManagementQuery = new SgFormulaManagement(); + formulaManagementQuery.setFormulaId(sgFeedList.getFormulaId()); + formulaManagementQuery.setBatchId(sgFeedList.getFormulaBatchId()); + List formulaManagements = sgFormulaManagementService.selectSgFormulaManagementList(formulaManagementQuery); + if (!formulaManagements.isEmpty()) { + sgFeedList.setRootFormula(formulaManagements.get(0)); + sgFeedList.setFormulaList(formulaManagements.get(0).getSgFormulaList()); + } + String cacheKey = sgFeedList.getFormulaId() + "_" + sgFeedList.getFormulaBatchId() + "_" + sgFeedList.getDeployDate(); + // 从就缓存中查找,如果存在则更新可修改的值 + if (cacheTemp.containsKey(cacheKey)) { + SgFeedList cacheItem = cacheTemp.get(cacheKey); + sgFeedList.setZookeeper(cacheItem.getZookeeper()); + } + sgFeedListMap.put(cacheKey, sgFeedList); + } + + List toDataBase = new ArrayList<>(sgFeedListMap.values()); + // 清空再写入 + this.sgFeedListMapper.deleteAll(); + // 处理结果写入数据库 + for (SgFeedList recordItem : toDataBase) { + this.insertSgFeedList(recordItem); + } + } + } + + /** + * 计算某个配方某个批次的总和值 + * + * @param sgFeedPlans 配方计划列表 + * @return 各个值总和 + */ + private static SgFeedPlan computePlanTotal(List sgFeedPlans) { + SgFeedPlan rootPlan = new SgFeedPlan(); + if (!sgFeedPlans.isEmpty()) { + int sheepCountTotal = 0; + double sheepDailySize = 0.0; + double planFeedMorningSize = 0.0; + double planFeedNoonSize = 0.0; + double planFeedAfternoonSize = 0.0; + double planFeedTotalSize = 0.0; + for (SgFeedPlan sgFeedPlan : sgFeedPlans) { + sheepCountTotal += sgFeedPlan.getSheepCount(); + sheepDailySize += sgFeedPlan.getPlanDailySize(); + planFeedMorningSize += sgFeedPlan.getPlanMorningSize(); + planFeedNoonSize += sgFeedPlan.getPlanNoonSize(); + planFeedAfternoonSize += sgFeedPlan.getPlanAfternoonSize(); + planFeedTotalSize += sgFeedPlan.getPlanFeedTotal(); + } + rootPlan.setFormulaId(sgFeedPlans.get(0).getFormulaId()); + rootPlan.setBatchId(sgFeedPlans.get(0).getBatchId()); + rootPlan.setSheepCount(sheepCountTotal); + rootPlan.setPlanDailySize(sheepDailySize); + rootPlan.setPlanMorningSize(planFeedMorningSize); + rootPlan.setPlanNoonSize(planFeedNoonSize); + rootPlan.setPlanAfternoonSize(planFeedAfternoonSize); + rootPlan.setPlanFeedTotal(planFeedTotalSize); + + // 设置计划日期 + rootPlan.setPlanDate(sgFeedPlans.get(0).getPlanDate()); + } + return rootPlan; + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedStatisticServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedStatisticServiceImpl.java new file mode 100644 index 0000000..b82d0b4 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgFeedStatisticServiceImpl.java @@ -0,0 +1,176 @@ +package com.zhyc.module.feed.service.impl; + +import java.util.List; +import java.util.stream.Collectors; + +import com.zhyc.module.base.domain.DaSheepfold; +import com.zhyc.module.feed.domain.SgFeedList; +import com.zhyc.module.feed.domain.SgFeedPlan; +import com.zhyc.module.feed.domain.SgFormulaList; +import com.zhyc.module.feed.service.ISgFeedListService; +import com.zhyc.module.feed.service.ISgFeedPlanService; +import org.springframework.stereotype.Service; +import com.zhyc.module.feed.mapper.SgFeedStatisticMapper; +import com.zhyc.module.feed.domain.SgFeedStatistic; +import com.zhyc.module.feed.service.ISgFeedStatisticService; + +/** + * 饲喂量统计Service业务层处理 + * + * @author HashMap + * @date 2025-08-23 + */ +@Service +public class SgFeedStatisticServiceImpl implements ISgFeedStatisticService { + private final SgFeedStatisticMapper sgFeedStatisticMapper; + + private final ISgFeedListService sgFeedListService; + private final ISgFeedPlanService sgFeedPlanService; + + public SgFeedStatisticServiceImpl(SgFeedStatisticMapper sgFeedStatisticMapper, ISgFeedListService sgFeedListService, ISgFeedPlanService sgFeedPlanService) { + this.sgFeedStatisticMapper = sgFeedStatisticMapper; + this.sgFeedListService = sgFeedListService; + this.sgFeedPlanService = sgFeedPlanService; + } + + /** + * 查询饲喂量统计 + * + * @param id 饲喂量统计主键 + * @return 饲喂量统计 + */ + @Override + public SgFeedStatistic selectSgFeedStatisticById(String id) { + return sgFeedStatisticMapper.selectSgFeedStatisticById(id); + } + + /** + * 查询饲喂量统计列表 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 饲喂量统计 + */ + @Override + public List selectSgFeedStatisticList(SgFeedStatistic sgFeedStatistic) { + return sgFeedStatisticMapper.selectSgFeedStatisticList(sgFeedStatistic); + } + + /** + * 新增饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + @Override + public int insertSgFeedStatistic(SgFeedStatistic sgFeedStatistic) { + return sgFeedStatisticMapper.insertSgFeedStatistic(sgFeedStatistic); + } + + /** + * 修改饲喂量统计 + * + * @param sgFeedStatistic 饲喂量统计 + * @return 结果 + */ + @Override + public int updateSgFeedStatistic(SgFeedStatistic sgFeedStatistic) { + return sgFeedStatisticMapper.updateSgFeedStatistic(sgFeedStatistic); + } + + /** + * 批量删除饲喂量统计 + * + * @param ids 需要删除的饲喂量统计主键 + * @return 结果 + */ + @Override + public int deleteSgFeedStatisticByIds(String[] ids) { + return sgFeedStatisticMapper.deleteSgFeedStatisticByIds(ids); + } + + /** + * 删除饲喂量统计信息 + * + * @param id 饲喂量统计主键 + * @return 结果 + */ + @Override + public int deleteSgFeedStatisticById(String id) { + return sgFeedStatisticMapper.deleteSgFeedStatisticById(id); + } + + /** + * 向待插入数据表单提供数据预载服务 + * + * @param sgFeedStatistic 待填充的初始化数据 + * @author ShiHan Wang + */ + @Override + public void getInitSgFeedStatistic(SgFeedStatistic sgFeedStatistic) { + // 1. 查找饲料清单 + SgFeedList sgFeedListQuery = new SgFeedList(); + sgFeedListQuery.setFormulaId(sgFeedStatistic.getFormulaId()); + sgFeedListQuery.setFormulaBatchId(sgFeedStatistic.getFormulaBatchId()); + + List feedLists = sgFeedListService.selectSgFeedListList(sgFeedListQuery); + + if (!feedLists.isEmpty()) { + // 刷新缓存 + sgFeedListService.SyncFeedList(); + + // 从缓存获取完整配方清单 + String cacheKey = sgFeedStatistic.getFormulaId() + "_" + sgFeedStatistic.getFormulaBatchId() + "_" + sgFeedStatistic.getFeedDate(); + SgFeedList sgFeedList = SgFeedListServiceImpl.getSgFeedListMap().get(cacheKey); + + if (sgFeedList != null && sgFeedList.getFormulaList() != null) { + // 并行流式计算 提高性能 + sgFeedList.getFormulaList().parallelStream().forEach(item -> { + double ratio = item.getRatio() / 100.0; + double feedSize = sgFeedList.getRootPlan().getPlanMorningSize() * ratio + + sgFeedList.getRootPlan().getPlanNoonSize() * ratio + + sgFeedList.getRootPlan().getPlanAfternoonSize() * ratio; + item.setFeedSize(feedSize); + }); + + // 统计总和 + double totalFeedSize = sgFeedList.getFormulaList() + .parallelStream() + .mapToDouble(SgFormulaList::getFeedSize) + .sum(); + sgFeedStatistic.setMaterialList(sgFeedList.getFormulaList()); + sgFeedStatistic.setFeedTotalSize(totalFeedSize); + } else { + throw new RuntimeException("WARNING: 原料数据为空"); + } + } + + // 2. 查找饲喂计划并填充羊舍信息 + SgFeedPlan sgFeedPlanQuery = new SgFeedPlan(); + sgFeedPlanQuery.setFormulaId(sgFeedStatistic.getFormulaId()); + sgFeedPlanQuery.setBatchId(sgFeedStatistic.getFormulaBatchId()); + sgFeedPlanQuery.setPlanDate(sgFeedStatistic.getFeedDate()); + List sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(sgFeedPlanQuery); + + if (!sgFeedPlans.isEmpty()) { + // 并行计算提高查询性能 + List sheepfolds = sgFeedPlans.parallelStream() + .map(plan -> { + DaSheepfold sheepfold = new DaSheepfold(); + sheepfold.setId((long) plan.getSheepHouseId()); + return sheepfold; + }) + .collect(Collectors.toList()); + + long sheepCount = sgFeedPlans.parallelStream() + .mapToLong(SgFeedPlan::getSheepCount) + .sum(); + sgFeedStatistic.setSheepFoldList(sheepfolds); + sgFeedStatistic.setSheepFoldCount(sheepCount); + // 计算日均饲喂量 + sgFeedStatistic.setFeedDailySize(sgFeedStatistic.getFeedTotalSize() / sgFeedStatistic.getSheepFoldCount()); + } else { + throw new RuntimeException("WARNING: 不存在该计划"); + } + } + +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/bodyManage/domain/ScBreastRating.java b/zhyc-module/src/main/java/com/zhyc/module/produce/bodyManage/domain/ScBreastRating.java index 872bf26..4eda878 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/bodyManage/domain/ScBreastRating.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/bodyManage/domain/ScBreastRating.java @@ -31,7 +31,7 @@ public class ScBreastRating extends BaseEntity { */ private String sheepId; - @Excel(name = "羊只id") + @Excel(name = "管理耳号") private String manageTags; /** 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/java/com/zhyc/module/produce/manage_sheep/domain/ScChangeComment.java b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/domain/ScChangeComment.java index 8e1b0cb..5db6214 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/domain/ScChangeComment.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/domain/ScChangeComment.java @@ -27,7 +27,7 @@ public class ScChangeComment extends BaseEntity { * 羊只id */ private String sheepId; - + @Excel(name = "管理耳号") private String manageTags; /** 羊舍 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java new file mode 100644 index 0000000..307ac92 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java @@ -0,0 +1,117 @@ +package com.zhyc.module.sale.controller; + +import java.util.List; +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.RequestParam; +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.sale.domain.SxSheepSale; +import com.zhyc.module.sale.service.ISxSheepSaleService; +import com.zhyc.common.utils.poi.ExcelUtil; +import com.zhyc.common.core.page.TableDataInfo; + +/** + * 羊只销售记录Controller + * + * @author ruoyi + * @date 2025-08-19 + */ +@RestController +@RequestMapping("/saleRecord/saleRecord") +public class SxSheepSaleController extends BaseController { + @Autowired + private ISxSheepSaleService sxSheepSaleService; + + /** + * 查询羊只销售记录列表 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:list')") + @GetMapping("/list") + public TableDataInfo list(SxSheepSale sxSheepSale) { + startPage(); + List list = sxSheepSaleService.selectSxSheepSaleList(sxSheepSale); + return getDataTable(list); + } + + /** + * 导出羊只销售记录列表 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:export')") + @Log(title = "羊只销售记录", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SxSheepSale sxSheepSale) { + List list = sxSheepSaleService.selectSxSheepSaleList(sxSheepSale); + ExcelUtil util = new ExcelUtil(SxSheepSale.class); + util.exportExcel(response, list, "羊只销售记录数据"); + } + + /** + * 获取羊只销售记录详细信息 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) { + SxSheepSale sxSheepSale = sxSheepSaleService.selectSxSheepSaleById(id); + // 将数据库中的逗号分隔的耳号字符串转换为列表 + if (sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) { + sxSheepSale.setBsManageTagsList(java.util.Arrays.asList(sxSheepSale.getBsManageTags().split(","))); + } + return success(sxSheepSale); + } + + /** + * 新增羊只销售记录 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:add')") + @Log(title = "羊只销售记录", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SxSheepSale sxSheepSale) { + return toAjax(sxSheepSaleService.insertSxSheepSale(sxSheepSale)); + } + + /** + * 修改羊只销售记录 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:edit')") + @Log(title = "羊只销售记录", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SxSheepSale sxSheepSale) { + return toAjax(sxSheepSaleService.updateSxSheepSale(sxSheepSale)); + } + + /** + * 删除羊只销售记录 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:remove')") + @Log(title = "羊只销售记录", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(sxSheepSaleService.deleteSxSheepSaleByIds(ids)); + } + + /** + * 【新增】根据耳号查询羊只信息 + */ + @PreAuthorize("@ss.hasPermi('saleRecord:saleRecord:add')" + "|| @ss.hasPermi('saleRecord:saleRecord:edit')") + @GetMapping("/getSheepInfo") + public AjaxResult getSheepInfo(@RequestParam String bsManageTags) { + // 调用Service方法查询信息 + SxSheepSale sheepInfo = sxSheepSaleService.selectSheepInfoByTag(bsManageTags); + if (sheepInfo == null) { + return AjaxResult.error("未找到耳号为 [" + bsManageTags + "] 的羊只信息"); + } + return AjaxResult.success(sheepInfo); + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomerExport.java b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomerExport.java new file mode 100644 index 0000000..a7d8833 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomerExport.java @@ -0,0 +1,49 @@ +package com.zhyc.module.sale.domain; + +import com.zhyc.common.annotation.Excel; + +public class SxCustomerExport { + @Excel(name = "客户名称") + private String name; + + @Excel(name = "客户电话") + private String phone; + + @Excel(name = "客户地址") + private String fullAddress; + + @Excel(name = "备注") + private String remark; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getFullAddress() { + return fullAddress; + } + + public void setFullAddress(String fullAddress) { + this.fullAddress = fullAddress; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java new file mode 100644 index 0000000..aab27dc --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java @@ -0,0 +1,545 @@ +package com.zhyc.module.sale.domain; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +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; + +/** + * 羊只销售记录对象 sx_sheep_sale + * + * @author ruoyi + * @date 2025-08-19 + */ +public class SxSheepSale extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** 主键ID */ + private Long id; + + /** 耳号 */ + @Excel(name = "耳号") + private String bsManageTags; + + /** 羊舍ID(当时销售的羊舍) */ + @Excel(name = "羊舍ID", readConverterExp = "当=时销售的羊舍") + private Long sheepfoldId; + + /** 品种快照 */ + @Excel(name = "品种快照") + private String variety; + + /** 羊只类别快照 */ + @Excel(name = "羊只类别快照") + private String sheepName; + + /** 性别快照 */ + @Excel(name = "性别快照") + private String gender; + + /** 月龄快照 */ + @Excel(name = "月龄快照") + private Long monthAge; + + /** 胎次快照 */ + @Excel(name = "胎次快照") + private Long parity; + + /** 繁育状态快照 */ + @Excel(name = "繁育状态快照") + private String breed; + + /** 产后天数快照 */ + @Excel(name = "产后天数快照") + private Long postLambingDay; + + /** 泌乳天数快照 */ + @Excel(name = "泌乳天数快照") + private Long lactationDay; + + /** 怀孕天数快照 */ + @Excel(name = "怀孕天数快照") + private Long lambingDay; + + /** 事件类型 */ + @Excel(name = "事件类型") + private String eventType; + + /** 销售日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "销售日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date saleDate; + + /** 计价方式 */ + @Excel(name = "计价方式") + private String pricingMethod; + + /** 单价 */ + @Excel(name = "单价") + private BigDecimal unitPrice; + + /** 总价(自动计算) */ + @Excel(name = "总价", readConverterExp = "自=动计算") + private BigDecimal totalPrice; + + /** 总体重(按体重时输入) */ + @Excel(name = "总体重", readConverterExp = "按=体重时输入") + private BigDecimal totalWeight; + + /** 平均体重(自动) */ + @Excel(name = "平均体重", readConverterExp = "自=动") + private BigDecimal avgWeight; + + /** 平均单只价格(自动) */ + @Excel(name = "平均单只价格", readConverterExp = "自=动") + private BigDecimal avgPricePerSheep; + + /** 销售类别(dict_type = sale_type) */ + @Excel(name = "销售类别", readConverterExp = "d=ict_type,==,s=ale_type") + private String saleType; + + /** 疾病类型(dict_type = disea_type) */ + @Excel(name = "疾病类型", readConverterExp = "d=ict_type,==,d=isea_type") + private String diseaseType; + + /** 次要原因 */ + @Excel(name = "次要原因") + private String secondaryReason; + + /** 班组(dict_type = group) */ + @Excel(name = "班组", readConverterExp = "d=ict_type,==,g=roup") + private String groupCode; + + /** 客户ID(sx_customer.id) */ + @Excel(name = "客户ID", readConverterExp = "s=x_customer.id") + private Long customerId; + + /** 销售人员ID(sys_user.id) */ + @Excel(name = "销售人员ID", readConverterExp = "s=ys_user.id") + private Long salesPersonId; + + /** 检疫证号 */ + @Excel(name = "检疫证号") + private String quarantineNo; + + /** 审批编号 */ + @Excel(name = "审批编号") + private String approvalNo; + + /** 技术员ID(sys_user.id) */ + @Excel(name = "技术员ID", readConverterExp = "s=ys_user.id") + private Long technicianId; + + /** 处理人ID(sys_user.id) */ + @Excel(name = "处理人ID", readConverterExp = "s=ys_user.id") + private Long handlerId; + + /** 创建人ID(sys_user.id) */ + @Excel(name = "创建人ID", readConverterExp = "s=ys_user.id") + private Long createdBy; + + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date createdAt; + + // 【新增】非数据库字段:用于前端展示和选择羊舍后传递多个耳号 + private List bsManageTagsList; + + // 【新增】非数据库字段:客户名称(从客户表查询) + private String customerName; + // 【新增】非数据库字段:客户电话 + private String customerPhone; + // 【新增】非数据库字段:客户地址 + private String customerAddress; + // 【新增】非数据库字段:销售人员姓名 + private String salesPersonName; + // 【新增】非数据库字段:技术员姓名 + private String technicianName; + // 【新增】非数据库字段:处理人姓名 + private String handlerName; + // 【新增】非数据库字段:创建人姓名 + private String createdByName; + // 【新增】非数据库字段:羊舍名称 + private String sheepfoldName; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setBsManageTags(String bsManageTags) { + this.bsManageTags = bsManageTags; + } + + public String getBsManageTags() { + return bsManageTags; + } + + public void setSheepfoldId(Long sheepfoldId) { + this.sheepfoldId = sheepfoldId; + } + + public Long getSheepfoldId() { + return sheepfoldId; + } + + public void setVariety(String variety) { + this.variety = variety; + } + + public String getVariety() { + return variety; + } + + public void setSheepName(String sheepName) { + this.sheepName = sheepName; + } + + public String getSheepName() { + return sheepName; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getGender() { + return gender; + } + + public void setMonthAge(Long monthAge) { + this.monthAge = monthAge; + } + + public Long getMonthAge() { + return monthAge; + } + + public void setParity(Long parity) { + this.parity = parity; + } + + public Long getParity() { + return parity; + } + + public void setBreed(String breed) { + this.breed = breed; + } + + public String getBreed() { + return breed; + } + + public void setPostLambingDay(Long postLambingDay) { + this.postLambingDay = postLambingDay; + } + + public Long getPostLambingDay() { + return postLambingDay; + } + + public void setLactationDay(Long lactationDay) { + this.lactationDay = lactationDay; + } + + public Long getLactationDay() { + return lactationDay; + } + + public void setLambingDay(Long lambingDay) { + this.lambingDay = lambingDay; + } + + public Long getLambingDay() { + return lambingDay; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public String getEventType() { + return eventType; + } + + public void setSaleDate(Date saleDate) { + this.saleDate = saleDate; + } + + public Date getSaleDate() { + return saleDate; + } + + public void setPricingMethod(String pricingMethod) { + this.pricingMethod = pricingMethod; + } + + public String getPricingMethod() { + return pricingMethod; + } + + public void setUnitPrice(BigDecimal unitPrice) { + this.unitPrice = unitPrice; + } + + public BigDecimal getUnitPrice() { + return unitPrice; + } + + public void setTotalPrice(BigDecimal totalPrice) { + this.totalPrice = totalPrice; + } + + public BigDecimal getTotalPrice() { + return totalPrice; + } + + public void setTotalWeight(BigDecimal totalWeight) { + this.totalWeight = totalWeight; + } + + public BigDecimal getTotalWeight() { + return totalWeight; + } + + public void setAvgWeight(BigDecimal avgWeight) { + this.avgWeight = avgWeight; + } + + public BigDecimal getAvgWeight() { + return avgWeight; + } + + public void setAvgPricePerSheep(BigDecimal avgPricePerSheep) { + this.avgPricePerSheep = avgPricePerSheep; + } + + public BigDecimal getAvgPricePerSheep() { + return avgPricePerSheep; + } + + public void setSaleType(String saleType) { + this.saleType = saleType; + } + + public String getSaleType() { + return saleType; + } + + public void setDiseaseType(String diseaseType) { + this.diseaseType = diseaseType; + } + + public String getDiseaseType() { + return diseaseType; + } + + public void setSecondaryReason(String secondaryReason) { + this.secondaryReason = secondaryReason; + } + + public String getSecondaryReason() { + return secondaryReason; + } + + public void setGroupCode(String groupCode) { + this.groupCode = groupCode; + } + + public String getGroupCode() { + return groupCode; + } + + public void setCustomerId(Long customerId) { + this.customerId = customerId; + } + + public Long getCustomerId() { + return customerId; + } + + public void setSalesPersonId(Long salesPersonId) { + this.salesPersonId = salesPersonId; + } + + public Long getSalesPersonId() { + return salesPersonId; + } + + public void setQuarantineNo(String quarantineNo) { + this.quarantineNo = quarantineNo; + } + + public String getQuarantineNo() { + return quarantineNo; + } + + public void setApprovalNo(String approvalNo) { + this.approvalNo = approvalNo; + } + + public String getApprovalNo() { + return approvalNo; + } + + public void setTechnicianId(Long technicianId) { + this.technicianId = technicianId; + } + + public Long getTechnicianId() { + return technicianId; + } + + public void setHandlerId(Long handlerId) { + this.handlerId = handlerId; + } + + public Long getHandlerId() { + return handlerId; + } + + public void setCreatedBy(Long createdBy) { + this.createdBy = createdBy; + } + + public Long getCreatedBy() { + return createdBy; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getCreatedAt() { + return createdAt; + } + + // 【新增】getter 和 setter 方法 + public List getBsManageTagsList() { + return bsManageTagsList; + } + + public void setBsManageTagsList(List bsManageTagsList) { + this.bsManageTagsList = bsManageTagsList; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getCustomerPhone() { + return customerPhone; + } + + public void setCustomerPhone(String customerPhone) { + this.customerPhone = customerPhone; + } + + public String getCustomerAddress() { + return customerAddress; + } + + public void setCustomerAddress(String customerAddress) { + this.customerAddress = customerAddress; + } + + public String getSalesPersonName() { + return salesPersonName; + } + + public void setSalesPersonName(String salesPersonName) { + this.salesPersonName = salesPersonName; + } + + public String getTechnicianName() { + return technicianName; + } + + public void setTechnicianName(String technicianName) { + this.technicianName = technicianName; + } + + public String getHandlerName() { + return handlerName; + } + + public void setHandlerName(String handlerName) { + this.handlerName = handlerName; + } + + public String getCreatedByName() { + return createdByName; + } + + public void setCreatedByName(String createdByName) { + this.createdByName = createdByName; + } + + public String getSheepfoldName() { + return sheepfoldName; + } + + public void setSheepfoldName(String sheepfoldName) { + this.sheepfoldName = sheepfoldName; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("bsManageTags", getBsManageTags()) + .append("sheepfoldId", getSheepfoldId()) + .append("variety", getVariety()) + .append("sheepName", getSheepName()) + .append("gender", getGender()) + .append("monthAge", getMonthAge()) + .append("parity", getParity()) + .append("breed", getBreed()) + .append("postLambingDay", getPostLambingDay()) + .append("lactationDay", getLactationDay()) + .append("lambingDay", getLambingDay()) + .append("eventType", getEventType()) + .append("saleDate", getSaleDate()) + .append("pricingMethod", getPricingMethod()) + .append("unitPrice", getUnitPrice()) + .append("totalPrice", getTotalPrice()) + .append("totalWeight", getTotalWeight()) + .append("avgWeight", getAvgWeight()) + .append("avgPricePerSheep", getAvgPricePerSheep()) + .append("saleType", getSaleType()) + .append("diseaseType", getDiseaseType()) + .append("secondaryReason", getSecondaryReason()) + .append("groupCode", getGroupCode()) + .append("customerId", getCustomerId()) + .append("salesPersonId", getSalesPersonId()) + .append("quarantineNo", getQuarantineNo()) + .append("approvalNo", getApprovalNo()) + .append("technicianId", getTechnicianId()) + .append("handlerId", getHandlerId()) + .append("createdBy", getCreatedBy()) + .append("createdAt", getCreatedAt()) + .append("remark", getRemark()) + .append("customerName", getCustomerName()) + .append("customerPhone", getCustomerPhone()) + .append("customerAddress", getCustomerAddress()) + .append("salesPersonName", getSalesPersonName()) + .append("technicianName", getTechnicianName()) + .append("handlerName", getHandlerName()) + .append("createdByName", getCreatedByName()) + .append("sheepfoldName", getSheepfoldName()) + .toString(); + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/mapper/SxSheepSaleMapper.java b/zhyc-module/src/main/java/com/zhyc/module/sale/mapper/SxSheepSaleMapper.java new file mode 100644 index 0000000..8b6788f --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/mapper/SxSheepSaleMapper.java @@ -0,0 +1,68 @@ +package com.zhyc.module.sale.mapper; + +import java.util.List; +import com.zhyc.module.sale.domain.SxSheepSale; +import org.apache.ibatis.annotations.Param; + +/** + * 羊只销售记录Mapper接口 + * + * @author ruoyi + * @date 2025-08-19 + */ +public interface SxSheepSaleMapper { + /** + * 查询羊只销售记录 + * + * @param id 羊只销售记录主键 + * @return 羊只销售记录 + */ + public SxSheepSale selectSxSheepSaleById(Long id); + + /** + * 查询羊只销售记录列表 + * + * @param sxSheepSale 羊只销售记录 + * @return 羊只销售记录集合 + */ + public List selectSxSheepSaleList(SxSheepSale sxSheepSale); + + /** + * 新增羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + public int insertSxSheepSale(SxSheepSale sxSheepSale); + + /** + * 修改羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + public int updateSxSheepSale(SxSheepSale sxSheepSale); + + /** + * 删除羊只销售记录 + * + * @param id 羊只销售记录主键 + * @return 结果 + */ + public int deleteSxSheepSaleById(Long id); + + /** + * 批量删除羊只销售记录 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSxSheepSaleByIds(Long[] ids); + + /** + * 【新增】从sheep_file视图查询羊只信息 + * @param bsManageTags 耳号 + * @return 羊只信息 (只包含视图中的字段) + */ + public SxSheepSale selectSheepInfoByTag(@Param("bsManageTags") String bsManageTags); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/service/ISxSheepSaleService.java b/zhyc-module/src/main/java/com/zhyc/module/sale/service/ISxSheepSaleService.java new file mode 100644 index 0000000..bbdc73a --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/service/ISxSheepSaleService.java @@ -0,0 +1,67 @@ +package com.zhyc.module.sale.service; + +import java.util.List; +import com.zhyc.module.sale.domain.SxSheepSale; + +/** + * 羊只销售记录Service接口 + * + * @author ruoyi + * @date 2025-08-19 + */ +public interface ISxSheepSaleService { + /** + * 查询羊只销售记录 + * + * @param id 羊只销售记录主键 + * @return 羊只销售记录 + */ + public SxSheepSale selectSxSheepSaleById(Long id); + + /** + * 查询羊只销售记录列表 + * + * @param sxSheepSale 羊只销售记录 + * @return 羊只销售记录集合 + */ + public List selectSxSheepSaleList(SxSheepSale sxSheepSale); + + /** + * 新增羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + public int insertSxSheepSale(SxSheepSale sxSheepSale); + + /** + * 修改羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + public int updateSxSheepSale(SxSheepSale sxSheepSale); + + /** + * 批量删除羊只销售记录 + * + * @param ids 需要删除的羊只销售记录主键集合 + * @return 结果 + */ + public int deleteSxSheepSaleByIds(Long[] ids); + + /** + * 删除羊只销售记录信息 + * + * @param id 羊只销售记录主键 + * @return 结果 + */ + public int deleteSxSheepSaleById(Long id); + + /** + * 【新增】根据耳号查询羊只信息 + * @param bsManageTags 耳号 + * @return 羊只信息 + */ + public SxSheepSale selectSheepInfoByTag(String bsManageTags); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java new file mode 100644 index 0000000..2c47d5c --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java @@ -0,0 +1,194 @@ +package com.zhyc.module.sale.service.impl; + +import java.util.List; +import java.math.BigDecimal; +import java.math.RoundingMode; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.zhyc.module.sale.mapper.SxSheepSaleMapper; +import com.zhyc.module.sale.domain.SxSheepSale; +import com.zhyc.module.sale.service.ISxSheepSaleService; + +/** + * 羊只销售记录Service业务层处理 + * + * @author ruoyi + * @date 2025-08-19 + */ +@Service +public class SxSheepSaleServiceImpl implements ISxSheepSaleService { + @Autowired + private SxSheepSaleMapper sxSheepSaleMapper; + + /** + * 查询羊只销售记录 + * + * @param id 羊只销售记录主键 + * @return 羊只销售记录 + */ + @Override + public SxSheepSale selectSxSheepSaleById(Long id) { + return sxSheepSaleMapper.selectSxSheepSaleById(id); + } + + /** + * 查询羊只销售记录列表 + * + * @param sxSheepSale 羊只销售记录 + * @return 羊只销售记录 + */ + @Override + public List selectSxSheepSaleList(SxSheepSale sxSheepSale) { + return sxSheepSaleMapper.selectSxSheepSaleList(sxSheepSale); + } + + /** + * 新增羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + @Override + public int insertSxSheepSale(SxSheepSale sxSheepSale) { + // 1. 业务验证 (例如:销售日期不能为空,淘汰销售必须填写疾病类型等) + validateSalesFields(sxSheepSale); + + // 2. 自动计算逻辑 + calculateSalesFields(sxSheepSale); + + // 3. 设置默认事件类型 + if (sxSheepSale.getEventType() == null) { + sxSheepSale.setEventType("销售"); + } + + // 4. 处理耳号列表(多个耳号用逗号分隔) + if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { + sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList())); + } + + // 5. 调用Mapper插入数据 + return sxSheepSaleMapper.insertSxSheepSale(sxSheepSale); + } + + /** + * 修改羊只销售记录 + * + * @param sxSheepSale 羊只销售记录 + * @return 结果 + */ + @Override + public int updateSxSheepSale(SxSheepSale sxSheepSale) { + // 1. 业务验证 + validateSalesFields(sxSheepSale); + + // 2. 自动计算逻辑 + calculateSalesFields(sxSheepSale); + + // 3. 处理耳号列表(多个耳号用逗号分隔) + if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { + sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList())); + } + + // 4. 调用Mapper更新数据 + return sxSheepSaleMapper.updateSxSheepSale(sxSheepSale); + } + + /** + * 批量删除羊只销售记录 + * + * @param ids 需要删除的羊只销售记录主键 + * @return 结果 + */ + @Override + public int deleteSxSheepSaleByIds(Long[] ids) { + return sxSheepSaleMapper.deleteSxSheepSaleByIds(ids); + } + + /** + * 删除羊只销售记录信息 + * + * @param id 羊只销售记录主键 + * @return 结果 + */ + @Override + public int deleteSxSheepSaleById(Long id) { + return sxSheepSaleMapper.deleteSxSheepSaleById(id); + } + + /** + * 【新增】根据耳号查询羊只信息 + */ + @Override + public SxSheepSale selectSheepInfoByTag(String bsManageTags) { + return sxSheepSaleMapper.selectSheepInfoByTag(bsManageTags); + } + + /** + * 【新增】自动计算总价、平均体重、平均单只价格 + */ + private void calculateSalesFields(SxSheepSale sxSheepSale) { + String pricingMethod = sxSheepSale.getPricingMethod(); + BigDecimal unitPrice = sxSheepSale.getUnitPrice(); + + // 获取羊只数量 + int sheepCount = 1; + if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { + sheepCount = sxSheepSale.getBsManageTagsList().size(); + } else if (sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) { + // 如果前端没有传递列表,但有逗号分隔的字符串,也计算数量 + sheepCount = sxSheepSale.getBsManageTags().split(",").length; + } + + if ("按个体".equals(pricingMethod)) { + // 总价 = 单价 * 数量 + if (unitPrice != null) { + sxSheepSale.setTotalPrice(unitPrice.multiply(new BigDecimal(sheepCount))); + } + // 平均单只价格就是单价 + sxSheepSale.setAvgPricePerSheep(unitPrice); + + } else if ("按体重".equals(pricingMethod)) { + BigDecimal totalWeight = sxSheepSale.getTotalWeight(); + // 总价 = 单价 * 总重量 + if (unitPrice != null && totalWeight != null) { + sxSheepSale.setTotalPrice(unitPrice.multiply(totalWeight)); + } + // 平均体重 = 总重量 / 数量 + if (totalWeight != null && sheepCount > 0) { + sxSheepSale.setAvgWeight(totalWeight.divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP)); + } + // 平均单只价格 = 总价 / 数量 + if (sxSheepSale.getTotalPrice() != null && sheepCount > 0) { + sxSheepSale.setAvgPricePerSheep(sxSheepSale.getTotalPrice().divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP)); + } + } + // 可以添加其他计价方式的逻辑 + } + + /** + * 【新增】业务字段验证 + */ + private void validateSalesFields(SxSheepSale sxSheepSale) { + // 验证销售日期不能为空 + if (sxSheepSale.getSaleDate() == null) { + throw new RuntimeException("销售日期不能为空!"); + } + + String saleType = sxSheepSale.getSaleType(); + // 如果销售类别是"淘汰销售"或"淘汰屠宰",则疾病类型和班组不能为空 + if ("淘汰销售".equals(saleType) || "淘汰屠宰".equals(saleType)) { + if (sxSheepSale.getDiseaseType() == null) { + throw new RuntimeException("淘汰销售或淘汰屠宰必须选择疾病类型!"); + } + if (sxSheepSale.getGroupCode() == null) { + throw new RuntimeException("淘汰销售或淘汰屠宰必须选择班组!"); + } + } + // 如果疾病类型是"病残羊",则次要原因不能为空 + if ("病残羊".equals(sxSheepSale.getDiseaseType())) { + if (sxSheepSale.getSecondaryReason() == null || sxSheepSale.getSecondaryReason().trim().isEmpty()) { + throw new RuntimeException("疾病类型为病残羊时,必须填写次要原因!"); + } + } + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/stock/controller/WzStockInController.java b/zhyc-module/src/main/java/com/zhyc/module/stock/controller/WzStockInController.java index 6705202..4eef0ae 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/stock/controller/WzStockInController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/stock/controller/WzStockInController.java @@ -47,6 +47,7 @@ public class WzStockInController extends BaseController { startPage(); List list = wzStockInService.selectWzStockInList(wzStockIn); + logger.debug(wzStockIn.toString()); return getDataTable(list); } diff --git a/zhyc-module/src/main/resources/mapper/biosafety/DewormMapper.xml b/zhyc-module/src/main/resources/mapper/biosafety/DewormMapper.xml index 174f8f3..9efa115 100644 --- a/zhyc-module/src/main/resources/mapper/biosafety/DewormMapper.xml +++ b/zhyc-module/src/main/resources/mapper/biosafety/DewormMapper.xml @@ -35,9 +35,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and sheep_id = #{sheepId} + and bs.manage_tags like concat('%',#{sheepNo},'%') and datetime between #{params.beginDatetime} and #{params.endDatetime} and technical = #{technical} + ORDER BY datetime DESC - + select s.id, datetime, sheep_id, usage_id, variety, sheep_type, s.gender, month_age, s.parity, breed, technical, + s.comment, s.update_by, s.update_time, s.create_by, s.create_time, + bs.manage_tags sheep_no + from sw_health s + left join bas_sheep bs on s.sheep_id = bs.id + and datetime = #{datetime} + and bs.manage_tags like concat('%',#{sheepNo},'%') + and datetime between #{params.beginDatetime} and #{params.endDatetime} and technical = #{technical} + ORDER BY datetime DESC - + select s.id, datetime, sheep_id, usage_id, variety, sheep_type, s.gender, month_age, s.parity, breed, technical, + s.comment, s.update_by, s.update_time, s.create_by, s.create_time, + bs.manage_tags sheep_no + from sw_immunity s + left join bas_sheep bs on s.sheep_id = bs.id and sheep_id = #{sheepId} and sheep_type = #{sheepType} + and bs.manage_tags like concat('%',#{sheepNo},'%') 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..2ee56a2 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 @@ -43,19 +44,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + insert into sw_treatment @@ -75,6 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" disease_pid, veterinary, usage_id, + status, comment, update_by, update_time, @@ -97,6 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{diseasePid}, #{veterinary}, #{usageId}, + #{status}, #{comment}, #{updateBy}, #{updateTime}, @@ -109,14 +125,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 +155,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/dairyProducts/NpSheepMilkAnalysisMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/NpSheepMilkAnalysisMapper.xml index 8069e16..af77171 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/NpSheepMilkAnalysisMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/NpSheepMilkAnalysisMapper.xml @@ -4,7 +4,7 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + - - + - + - + + + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml index eb20ee1..0fd5b29 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml @@ -13,17 +13,18 @@ + SELECT - id, - datetime, - factory, - content, - standard, - CASE - WHEN standard = 0 OR standard IS NULL THEN NULL - ELSE content / standard - END AS coefficient + id, + datetime, + factory, + content, + COALESCE(standard, 18) as standard, + CASE + WHEN standard = 0 OR standard IS NULL THEN NULL + ELSE ROUND(content / standard, 2) + END AS coefficient FROM xz_dry_matter_correction diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/XzParityCorrectionMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/XzParityCorrectionMapper.xml index 9cf78ff..c9101f6 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/XzParityCorrectionMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/XzParityCorrectionMapper.xml @@ -1,9 +1,9 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -16,12 +16,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + + + + and formula_id = #{formulaId} + and formula_batch_id = #{formulaBatchId} + and silage_loss_rate = #{silageLossRate} + + + + + + + insert into sg_feed_statistic + + id, + formula_id, + formula_batch_id, + sheep_fold_count, + silage_loss_rate, + feed_total_size, + feed_daily_size, + material_list, + sheep_fold_list, + feed_date, + + + #{id}, + #{formulaId}, + #{formulaBatchId}, + #{sheepFoldCount}, + #{silageLossRate}, + #{feedTotalSize}, + #{feedDailySize}, +# 写入操作需要手动指定 TypeHandler 参数 + #{materialList, typeHandler=com.zhyc.module.feed.mapper.TypeHandler.SgFormulaListHandler}, + #{sheepFoldList, typeHandler=com.zhyc.module.feed.mapper.TypeHandler.DaSheepfoldHandler}, + #{feedDate}, + + + + + update sg_feed_statistic + + formula_id = #{formulaId}, + formula_batch_id = #{formulaBatchId}, + sheep_fold_count = #{sheepFoldCount}, + silage_loss_rate = #{silageLossRate}, + feed_total_size = #{feedTotalSize}, + feed_daily_size = #{feedDailySize}, + material_list = #{materialList, typeHandler=com.zhyc.module.feed.mapper.TypeHandler.SgFormulaListHandler}, + sheep_fold_list = #{sheepFoldList, typeHandler=com.zhyc.module.feed.mapper.TypeHandler.DaSheepfoldHandler}, + feed_date = #{feedDate}, + + where id = #{id} + + + + delete from sg_feed_statistic where id = #{id} + + + + delete from sg_feed_statistic where id in + + #{id} + + + \ No newline at end of file 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 + + where bs_manage_tags = #{bsManageTags} + + + + + + + + insert into sx_sheep_sale + + bs_manage_tags, + sheepfold_id, + variety, + sheep_name, + gender, + month_age, + parity, + breed, + post_lambing_day, + lactation_day, + lambing_day, + event_type, + sale_date, + pricing_method, + unit_price, + total_price, + total_weight, + avg_weight, + avg_price_per_sheep, + sale_type, + disease_type, + secondary_reason, + group_code, + customer_id, + sales_person_id, + quarantine_no, + approval_no, + technician_id, + handler_id, + created_by, + created_at, + remark, + + + #{bsManageTags}, + #{sheepfoldId}, + #{variety}, + #{sheepName}, + #{gender}, + #{monthAge}, + #{parity}, + #{breed}, + #{postLambingDay}, + #{lactationDay}, + #{lambingDay}, + #{eventType}, + #{saleDate}, + #{pricingMethod}, + #{unitPrice}, + #{totalPrice}, + #{totalWeight}, + #{avgWeight}, + #{avgPricePerSheep}, + #{saleType}, + #{diseaseType}, + #{secondaryReason}, + #{groupCode}, + #{customerId}, + #{salesPersonId}, + #{quarantineNo}, + #{approvalNo}, + #{technicianId}, + #{handlerId}, + #{createdBy}, + #{createdAt}, + #{remark}, + + + + + update sx_sheep_sale + + bs_manage_tags = #{bsManageTags}, + sheepfold_id = #{sheepfoldId}, + variety = #{variety}, + sheep_name = #{sheepName}, + gender = #{gender}, + month_age = #{monthAge}, + parity = #{parity}, + breed = #{breed}, + post_lambing_day = #{postLambingDay}, + lactation_day = #{lactationDay}, + lambing_day = #{lambingDay}, + event_type = #{eventType}, + sale_date = #{saleDate}, + pricing_method = #{pricingMethod}, + unit_price = #{unitPrice}, + total_price = #{totalPrice}, + total_weight = #{totalWeight}, + avg_weight = #{avgWeight}, + avg_price_per_sheep = #{avgPricePerSheep}, + sale_type = #{saleType}, + disease_type = #{diseaseType}, + secondary_reason = #{secondaryReason}, + group_code = #{groupCode}, + customer_id = #{customerId}, + sales_person_id = #{salesPersonId}, + quarantine_no = #{quarantineNo}, + approval_no = #{approvalNo}, + technician_id = #{technicianId}, + handler_id = #{handlerId}, + created_by = #{createdBy}, + created_at = #{createdAt}, + remark = #{remark}, + + where id = #{id} + + + + delete from sx_sheep_sale where id = #{id} + + + + delete from sx_sheep_sale where id in + + #{id} + + + + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/stock/WzMaterialsManagementMapper.xml b/zhyc-module/src/main/resources/mapper/stock/WzMaterialsManagementMapper.xml index d2347c4..7caa4fd 100644 --- a/zhyc-module/src/main/resources/mapper/stock/WzMaterialsManagementMapper.xml +++ b/zhyc-module/src/main/resources/mapper/stock/WzMaterialsManagementMapper.xml @@ -26,7 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and material_name like concat('%', #{materialName}, '%') - and production_date between #{params.beginProductionDate} and #{params.endProductionDate} + and production_date between #{params.beginProductionDate} and #{params.endProductionDate} + and production_date = #{productionDate} diff --git a/zhyc-module/src/main/resources/mapper/stock/WzStockInMapper.xml b/zhyc-module/src/main/resources/mapper/stock/WzStockInMapper.xml index 55c5c1e..d472047 100644 --- a/zhyc-module/src/main/resources/mapper/stock/WzStockInMapper.xml +++ b/zhyc-module/src/main/resources/mapper/stock/WzStockInMapper.xml @@ -41,6 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and business_type = #{businessType} and repository_name like concat('%', #{repositoryName}, '%') and material_name like concat('%', #{materialName}, '%') + and doc_date = #{docDate}