Compare commits

...

5 Commits

70 changed files with 1015 additions and 283 deletions

View File

@@ -76,6 +76,9 @@ public class SysDeptController extends BaseController
@PostMapping
public AjaxResult add(@Validated @RequestBody SysDept dept)
{
if (!deptService.checkRanchName(dept)){
return error("新增部门'" + dept.getDeptName() + "'失败,牧场名称已存在");
}
if (!deptService.checkDeptNameUnique(dept))
{
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");

View File

@@ -11,7 +11,7 @@ import java.lang.annotation.Target;
*
* @author ruoyi
*/
@Target(ElementType.METHOD)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DataScope

View File

@@ -31,6 +31,10 @@ public class SysDept extends BaseEntity
/** 部门名称 */
private String deptName;
/** 牧场id */
private Long ranchId;
private String ranchName;
/** 显示顺序 */
private Integer orderNum;
@@ -55,6 +59,22 @@ public class SysDept extends BaseEntity
/** 子部门 */
private List<SysDept> children = new ArrayList<SysDept>();
public String getRanchName() {
return ranchName;
}
public void setRanchName(String ranchName) {
this.ranchName = ranchName;
}
public Long getRanchId() {
return ranchId;
}
public void setRanchId(Long ranchId) {
this.ranchId = ranchId;
}
public Long getDeptId()
{
return deptId;

View File

@@ -0,0 +1,36 @@
package com.zhyc.common.core.domain.entity;
import com.zhyc.common.core.domain.BaseEntity;
/**
* 牧场管理对象 da_ranch
*
* @author ruoyi
* @date 2025-07-22
*/
public class SysRanch extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
/** 牧场名称 */
private String ranch;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getRanch() {
return ranch;
}
public void setRanch(String ranch) {
this.ranch = ranch;
}
}

View File

@@ -46,6 +46,7 @@ public class BasSheepController extends BaseController {
return getDataTable(list);
}
//查询耳号列表
@GetMapping("/earNumbers")
public AjaxResult searchEarNumbers(@RequestParam("query") String query) {
try {

View File

@@ -1,6 +1,8 @@
package com.zhyc.module.base.service.impl;
import java.util.List;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.module.base.domain.BasSheep;
import com.zhyc.module.base.mapper.BasSheepMapper;
@@ -51,6 +53,7 @@ public class BasSheepServiceImpl implements IBasSheepService
* @return
*/
@Override
@DataScope(deptAlias = "b", userAlias = "b")
public List<String> searchEarNumbers(String query) {
return basSheepMapper.searchEarNumbers(query);
}

View File

@@ -78,7 +78,8 @@ public class DewormController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody Deworm deworm)
{
System.out.println(deworm);
deworm.setDeptId(getDeptId());
deworm.setUserId(getUserId());
return toAjax(dewormService.insertDeworm(deworm));
}

View File

@@ -77,6 +77,8 @@ public class DiagnosisController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody Diagnosis diagnosis)
{
diagnosis.setDeptId(getDeptId());
diagnosis.setUserId(getUserId());
return toAjax(diagnosisService.insertDiagnosis(diagnosis));
}

View File

@@ -78,6 +78,8 @@ public class DisinfectController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody Disinfect disinfect)
{
disinfect.setDeptId(getDeptId());
disinfect.setUserId(getUserId());
return toAjax(disinfectService.insertDisinfect(disinfect));
}

View File

@@ -79,6 +79,8 @@ public class HealthController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody Health health)
{
health.setDeptId(getDeptId());
health.setUserId(getUserId());
return toAjax(healthService.insertHealth(health));
}

View File

@@ -78,6 +78,8 @@ public class ImmunityController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody Immunity immunity)
{
immunity.setDeptId(getDeptId());
immunity.setUserId(getUserId());
return toAjax(immunityService.insertImmunity(immunity));
}

View File

@@ -78,6 +78,8 @@ public class QuarantineReportController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody QuarantineReport quarantineReport)
{
quarantineReport.setDeptId(getDeptId());
quarantineReport.setUserId(getUserId());
return toAjax(quarantineReportService.insertQuarantineReport(quarantineReport));
}

View File

@@ -84,6 +84,8 @@ public class SwMedicineUsageController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody SwMedicineUsage swMedicineUsage)
{
swMedicineUsage.setDeptId(getDeptId());
swMedicineUsage.setUserId(getUserId());
return toAjax(swMedicineUsageService.insertSwMedicineUsage(swMedicineUsage));
}

View File

@@ -78,6 +78,8 @@ public class TreatmentController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody Treatment treatment)
{
treatment.setDeptId(getDeptId());
treatment.setUserId(getUserId());
return toAjax(treatmentService.insertTreatment(treatment));
}

View File

@@ -54,7 +54,8 @@ public class Deworm extends BaseEntity
@Excel(name = "胎次")
private Long parity;
private Long userId;
private Long deptId;
/** 药品使用记录 */
@Excel(name = "药品使用记录")
@@ -81,4 +82,5 @@ public class Deworm extends BaseEntity
// 排序查询
private String orderByColumn;
private String isAsc;
}

View File

@@ -106,6 +106,9 @@ public class Diagnosis extends BaseEntity
private String orderByColumn;
private String isAsc;
private Long userId;
private Long deptId;
public void setGender(String gender) {
this.gender = gender;
if (gender != null && !gender.trim().isEmpty()) {

View File

@@ -61,6 +61,9 @@ public class Disinfect extends BaseEntity
/** 药品名称用于查询*/
private String mediName;
private Long userId;
private Long deptId;
// 药品使用
private List<SwMedicineUsageDetails> usageDetails;

View File

@@ -69,6 +69,9 @@ public class Health extends BaseEntity
@Excel(name = "备注")
private String comment;
private Long userId;
private Long deptId;
// 药品使用
private List<SwMedicineUsageDetails> usageDetails;

View File

@@ -78,6 +78,9 @@ public class Immunity extends BaseEntity
@Excel(name = "备注")
private String comment;
private Long userId;
private Long deptId;
// 药品使用
private List<SwMedicineUsageDetails> usageDetails;

View File

@@ -98,6 +98,9 @@ public class QuarantineReport extends BaseEntity
@Excel(name = "备注")
private String comment;
private Long userId;
private Long deptId;
public void setGender(String gender) {
this.gender = gender;
this.genderName = Gender.getDescByCode(Integer.valueOf(gender));

View File

@@ -53,6 +53,9 @@ public class SwMedicineUsage extends BaseEntity
@Excel(name = "使用类型",width = 20, needMerge = true)
private String useType;
private Long userId;
private Long deptId;
/** 药品使用记录详情信息 */
@Excel
private List<SwMedicineUsageDetails> swMedicineUsageDetailsList;

View File

@@ -104,6 +104,9 @@ public class Treatment extends BaseEntity
@Excel(name = "药品使用记录id")
private Integer usageId;
private Long userId;
private Long deptId;
// 药品使用
private List<SwMedicineUsageDetails> usageDetails;

View File

@@ -3,6 +3,8 @@ package com.zhyc.module.biosafety.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.common.utils.bean.BeanUtils;
@@ -58,6 +60,7 @@ public class DewormServiceImpl implements IDewormService
* @return 驱虫
*/
@Override
@DataScope(deptAlias = "s", userAlias = "s")
public List<Deworm> selectDewormList(Deworm deworm)
{
String[] sheepNos = null;

View File

@@ -4,6 +4,7 @@ import java.util.Date;
import java.util.List;
import java.util.Objects;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.module.base.domain.BasSheep;
@@ -60,6 +61,7 @@ public class DiagnosisServiceImpl implements IDiagnosisService
* @return 诊疗结果
*/
@Override
@DataScope(deptAlias = "sd", userAlias = "sd")
public List<Diagnosis> selectDiagnosisList(Diagnosis diagnosis)
{
String[] sheepNos = null;

View File

@@ -2,6 +2,8 @@ package com.zhyc.module.biosafety.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.common.utils.bean.BeanUtils;
@@ -59,6 +61,7 @@ public class DisinfectServiceImpl implements IDisinfectService
* @return 消毒记录
*/
@Override
@DataScope(deptAlias = "sd", userAlias = "sd")
public List<Disinfect> selectDisinfectList(Disinfect disinfect)
{
return disinfectMapper.selectDisinfectList(disinfect);

View File

@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.common.utils.bean.BeanUtils;
@@ -62,6 +63,7 @@ public class HealthServiceImpl implements IHealthService
* @return 保健
*/
@Override
@DataScope(deptAlias = "s", userAlias = "s")
public List<Health> selectHealthList(Health health)
{
String[] sheepNos = null;

View File

@@ -2,6 +2,8 @@ package com.zhyc.module.biosafety.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.common.utils.bean.BeanUtils;
@@ -61,6 +63,7 @@ public class ImmunityServiceImpl implements IImmunityService
* @return 免疫
*/
@Override
@DataScope(deptAlias = "s", userAlias = "s")
public List<Immunity> selectImmunityList(Immunity immunity)
{
String[] sheepNos = null;

View File

@@ -2,6 +2,7 @@ package com.zhyc.module.biosafety.service.impl;
import java.util.List;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.module.biosafety.domain.QuarantineItems;
import com.zhyc.module.biosafety.mapper.QuarantineItemsMapper;
import com.zhyc.module.biosafety.service.IQuarantineItemsService;

View File

@@ -2,6 +2,8 @@ package com.zhyc.module.biosafety.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.common.utils.bean.BeanUtils;
@@ -46,6 +48,7 @@ public class QuarantineReportServiceImpl implements IQuarantineReportService
* @return 检疫记录
*/
@Override
@DataScope(deptAlias = "sqr", userAlias = "sqr")
public List<QuarantineReport> selectQuarantineReportList(QuarantineReport quarantineReport)
{
String[] sheepNos = null;

View File

@@ -1,6 +1,8 @@
package com.zhyc.module.biosafety.service.impl;
import java.util.List;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.module.biosafety.service.ISwMedicineUsageService;
@@ -44,6 +46,7 @@ public class SwMedicineUsageServiceImpl implements ISwMedicineUsageService
* @return 药品使用记录
*/
@Override
@DataScope(deptAlias = "smu", userAlias = "smu")
public List<SwMedicineUsage> selectSwMedicineUsageList(SwMedicineUsage swMedicineUsage)
{
String[] sheepNos = null;

View File

@@ -2,6 +2,8 @@ package com.zhyc.module.biosafety.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.common.utils.bean.BeanUtils;
@@ -65,6 +67,7 @@ public class TreatmentServiceImpl implements ITreatmentService
* @return 治疗记录
*/
@Override
@DataScope(deptAlias = "t", userAlias = "t")
public List<Treatment> selectTreatmentList(Treatment treatment)
{
String[] sheepNos = null;

View File

@@ -26,7 +26,9 @@ public class UserPostController {
// 根据岗位编码获取用户
@GetMapping("/getUser")
public AjaxResult getUserPost(String postCode){
List<User> list = userService.getUserListByCode(postCode);
User user = new User();
user.setPostCode(postCode);
List<User> list = userService.getUserListByCode(user);
return AjaxResult.success(list);
}

View File

@@ -0,0 +1,22 @@
package com.zhyc.module.common.domain;
import com.zhyc.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Dept extends BaseEntity {
private Long deptId;
private Long parentId;
private String ancestors;
private String deptName;
private String orderNum;
private String leader;
private String phone;
private String email;
private String status;
private String delFlag;
}

View File

@@ -1,6 +1,7 @@
package com.zhyc.module.common.domain;
import com.zhyc.common.annotation.Excel;
import com.zhyc.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -8,7 +9,7 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Post {
public class Post extends BaseEntity {
/** 岗位序号 */
@Excel(name = "岗位序号", cellType = Excel.ColumnType.NUMERIC)

View File

@@ -1,5 +1,6 @@
package com.zhyc.module.common.domain;
import com.zhyc.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -7,9 +8,10 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
public class User extends BaseEntity {
// 用户id
private String userId;
private Long userId;
private Long deptId;
// 用户名
private String nickName;
// 岗位名称
@@ -17,4 +19,5 @@ public class User {
// 岗位编码
private String postCode;
}

View File

@@ -0,0 +1,15 @@
package com.zhyc.module.common.mapper;
import com.zhyc.module.common.domain.Dept;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface DeptMapper {
/**
* 根据部门ID查询其所属二级部门排除根部门
*/
Dept selectTopSecondLevelDept(Long deptId);
}

View File

@@ -8,5 +8,5 @@ import java.util.List;
@Mapper
public interface UserMapper {
List<User> getUserListByCode(String postCode);
List<User> getUserListByCode(User user);
}

View File

@@ -5,5 +5,5 @@ import com.zhyc.module.common.domain.User;
import java.util.List;
public interface UserService {
List<User> getUserListByCode(String postCode);
List<User> getUserListByCode(User postCode);
}

View File

@@ -1,6 +1,10 @@
package com.zhyc.module.common.service.impl;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.module.common.domain.Dept;
import com.zhyc.module.common.domain.User;
import com.zhyc.module.common.mapper.DeptMapper;
import com.zhyc.module.common.mapper.UserMapper;
import com.zhyc.module.common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -12,9 +16,16 @@ import java.util.List;
public class UserPostServiceImpl implements UserService {
@Autowired
UserMapper userMapper;
@Autowired
DeptMapper deptMapper;
@Override
public List<User> getUserListByCode(String postCode) {
return userMapper.getUserListByCode(postCode);
public List<User> getUserListByCode(User user) {
Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId();
Dept secondLevel = deptMapper.selectTopSecondLevelDept(deptId);
user.setDeptId(secondLevel.getDeptId());
System.out.println(secondLevel);
return userMapper.getUserListByCode(user);
}
}

View File

@@ -9,14 +9,7 @@ import com.zhyc.module.produce.breed.domain.ScBreedPlanGenerate;
import com.zhyc.module.produce.breed.service.IScBreedPlanGenerateService;
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 org.springframework.web.bind.annotation.*;
import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
@@ -54,9 +47,9 @@ public class ScBreedPlanGenerateController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('mating_plan:generate:selectEwe')")
@GetMapping("/selectEwe")
public AjaxResult selectEligibleEwe()
public AjaxResult selectEligibleEwe(@RequestParam(value = "manageTags", required = false) String manageTags)
{
List<Map<String, Object>> eligibleEwe = scBreedPlanGenerateService.selectEligibleEwe();
List<Map<String, Object>> eligibleEwe = scBreedPlanGenerateService.selectEligibleEwe(manageTags);
return success(eligibleEwe);
}
@@ -65,9 +58,9 @@ public class ScBreedPlanGenerateController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('mating_plan:generate:selectRam')")
@GetMapping("/selectRam")
public AjaxResult selectEligibleRam()
public AjaxResult selectEligibleRam(@RequestParam(value = "manageTags", required = false) String manageTags)
{
List<Map<String, Object>> eligibleRam = scBreedPlanGenerateService.selectEligibleRam();
List<Map<String, Object>> eligibleRam = scBreedPlanGenerateService.selectEligibleRam(manageTags);
return success(eligibleRam);
}
@@ -249,4 +242,19 @@ public class ScBreedPlanGenerateController extends BaseController
{
return toAjax(scBreedPlanGenerateService.deleteScBreedPlanGenerateByIds(ids));
}
/**
* 模糊查询母羊耳号列表
*/
@PreAuthorize("@ss.hasPermi('mating_plan:generate:query')") // 根据实际权限修改
@GetMapping("/search_ear_numbers")
public AjaxResult searchEarNumbers(@RequestParam("query") String query) {
try {
List<String> earNumbers = scBreedPlanGenerateService.searchEarNumbers(query);
return success(earNumbers);
} catch (Exception e) {
logger.error("搜索耳号异常", e);
return error("搜索耳号失败:" + e.getMessage());
}
}
}

View File

@@ -239,4 +239,6 @@ public class ScBreedRecordController extends BaseController
List<ScBreedRecord> records = scBreedRecordService.getBreedRecordsByTimeRange(sheepId, startDate, endDate);
return success(records);
}
}

View File

@@ -1,6 +1,8 @@
package com.zhyc.module.produce.breed.domain;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -65,4 +67,15 @@ public class ScBreedPlanGenerate extends BaseEntity
/** 审批意见 */
private String approveRemark;
/** 全部羊耳号列表(用于多耳号查询) */
private List<String> allEarNumbers;
public List<String> getAllEarNumbers() {
return allEarNumbers;
}
public void setAllEarNumbers(List<String> allEarNumbers) {
this.allEarNumbers = allEarNumbers;
}
}

View File

@@ -20,135 +20,133 @@ public class ScBreedRecord extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键ID */
// ===================== 基础主键/关联ID字段 =====================
// 基础关联ID
private Long id;
/** 羊只id */
@Excel(name = "羊只id")
private Long sheepId;
/** 配种公羊id */
@Excel(name = "配种公羊id")
private String ramId;
/** 配种母羊id */
@Excel(name = "配种母羊id")
private String eweId;
/** 技术员 */
@Excel(name = "技术员")
private String technician;
/** 繁殖用药/耗精量 */
@Excel(name = "耗精量")
private String breedDrugs;
/** 配种方式 1-同期发情 2-本交 */
@Excel(name = "配种方式", readConverterExp = "1=同期发情,2=本交")
private Integer breedType;
// ============ 显示字段 ============
/** 母羊耳号 */
// --- 导出及表单顺序 ---
@Excel(name = "耳号")
private String eweManageTags;
private String eweManageTags; // 母羊耳号
/** 母羊品种 */
@Excel(name = "品种")
private String eweVariety;
/** 公羊耳号 */
@Excel(name = "事件类型")
private String eventType = "配种";
@Excel(name = "配种日期", dateFormat = "yyyy-MM-dd")
private Date createTime;
@Excel(name = "配种公羊")
private String ramManageTags;
/** 公羊品种 */
@Excel(name = "配种公羊品种")
private String ramVariety;
/** 胎次 */
@Excel(name = "胎次")
private Integer eweParity;
@Excel(name = "供体母羊")
private String donorEweNo;
@Excel(name = "供体母羊品种")
private String donorEweVariety;
@Excel(name = "供体公羊")
private String donorRamNo;
@Excel(name = "供体公羊品种")
private String donorRamVariety;
@Excel(name = "移胚数")
private Integer embryoCount;
/** 1-同期发情, 2-本交, 3-自然发情, 4-胚胎移植 */
@Excel(name = "配种方式", readConverterExp = "1=同期发情,2=本交,3=自然发情,4=胚胎移植")
private Integer breedType;
@Excel(name = "配种子类型")
private String embryoSubType; // 体内/体外 + 冻胚/鲜胚
/** 月龄 */
@Excel(name = "月龄")
private Integer eweMonthAge;
/** 羊舍名称 */
@Excel(name = "当前羊舍")
private String eweSheepfoldName;
/** 繁育状态 */
@Excel(name = "繁育状态")
private String eweBreedStatus;
/** 是否性控 */
@Excel(name = "是否性控", readConverterExp = "0=否,1=是")
private Integer eweControlled;
/** 羊只备注 */
@Excel(name = "羊只备注")
private String eweComment;
/** 牧场名称 */
@Excel(name = "所在牧场")
private String ranchName;
/** 配种方式显示 */
@Excel(name = "配种方式")
private String matingType;
/** 羊只类别 */
@Excel(name = "配种时羊只类别")
private String sheepType;
/** 配次 */
@Excel(name = "胎次")
private Integer eweParity;
@Excel(name = "孕检记录id")
private Integer pregnancyRecordId;
@Excel(name = "配次")
private Integer matingCount;
/** 发情后配种时间 */
@Excel(name = "发情后配种时间(小时)")
@Excel(name = "发情后配种时间")
private Long timeSincePlanning;
/** 牧场ID */
private Long ranchId;
@Excel(name = "当前羊舍")
private String eweSheepfoldName;
/** 配种计划ID */
private Long planId;
@Excel(name = "技术员")
private String technician;
// ============ 新增孕检相关字段 ============
@Excel(name = "繁殖用药")
private String breedDrugs;
@Excel(name = "羊只备注")
private String eweComment;
@Excel(name = "繁育状态")
private String eweBreedStatus;
/** 孕检日期 */
@Excel(name = "孕检日期")
private Date pregnancyCheckDate;
/** 孕检结果 */
@Excel(name = "孕检结果")
private String pregnancyResult;
/** 孕检方式 */
@Excel(name = "孕检方式")
private String pregnancyWay;
/** 胎数 */
@Excel(name = "胎数")
private Integer fetusCount;
/** 孕检技术员 */
@Excel(name = "孕检技术员")
private String pregnancyTechnician;
/** 孕检备注 */
@Excel(name = "孕检备注")
private String pregnancyRemark;
/** 孕检记录ID */
private Long pregnancyRecordId;
/** 配种到孕检间隔天数 */
@Excel(name = "配种到孕检间隔(天)")
private Integer daysToPregnancyCheck;
/** 是否已孕检 */
@Excel(name = "是否已孕检", readConverterExp = "0=否,1=是")
private Integer isPregnancyChecked;
@Excel(name = "预产日期")
private Date expectedDate;
@Excel(name = "实产日期")
private Date actualLambingDate;
@Excel(name = "配种时产后天数")
private Long daysPostLambing; // 距离上一次产羔
@Excel(name = "配种时泌乳天数")
private Long daysLactation; // 距离上一次孕检且怀孕
@Excel(name = "配种时配后天数")
private Long daysPostMating; // 距离上一次配种
@Excel(name = "上次配种日期")
private Date lastMatingDate;
@Excel(name = "冻精号")
private String frozenSemenNo; // 新增字段:自行输入
@Excel(name = "是否性控", readConverterExp = "0=否,1=是")
private Integer eweControlled;
@Excel(name = "耗精量")
private String spermConsumption;
@Excel(name = "创建人")
private String createBy;
@Excel(name = "创建日期")
private Date createDate;
@Excel(name = "所在牧场")
private String ranchName;
@Excel(name = "备注")
private String comment;
}

View File

@@ -141,7 +141,7 @@ public class ScLambDetail extends BaseEntity
/** 是否留养0-否1-是 */
@Excel(name = "是否留养")
private Integer isRetained;
private Boolean isRetained;
/** 家系 */
@Excel(name = "家系")

View File

@@ -128,4 +128,12 @@ public interface ScBreedPlanGenerateMapper
* @return 结果
*/
public int deleteTempBreedPlanByPlanId(Long planGenerateId);
/**
* 模糊查询母羊耳号列表
*
* @param query 查询关键字
* @return 耳号列表
*/
List<String> searchEarNumbers(@Param("query") String query);
}

View File

@@ -145,4 +145,12 @@ public interface ScBreedRecordMapper
* @return 配种母羊数
*/
Long countMatedEwesByRamId(String ramManageTags);
/**
* 根据受体(母羊)耳号查询最新的冲胚记录信息
* 用于胚胎移植时自动填充供体和移胚数
* @param manageTags 受体母羊耳号
* @return 冲胚记录Map
*/
public Map<String, Object> getFlushRecordByEweNo(@Param("manageTags") String manageTags);
}

View File

@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.zhyc.module.produce.breed.domain.ScBreedPlanGenerate;
import org.springframework.web.bind.annotation.RequestParam;
/**
* 配种计划生成Service接口
@@ -34,14 +35,14 @@ public interface IScBreedPlanGenerateService
*
* @return 符合条件的母羊列表
*/
public List<Map<String, Object>> selectEligibleEwe();
public List<Map<String, Object>> selectEligibleEwe(@RequestParam(value = "manageTags", required = false) String manageTags);
/**
* 筛选符合条件的公羊
*
* @return 符合条件的公羊列表
*/
public List<Map<String, Object>> selectEligibleRam();
public List<Map<String, Object>> selectEligibleRam(@RequestParam(value = "manageTags", required = false) String manageTags);
/**
* 自动生成配种计划
@@ -120,4 +121,12 @@ public interface IScBreedPlanGenerateService
* @return 结果
*/
public int deleteScBreedPlanGenerateById(Long id);
/**
* 模糊查询母羊耳号列表
*
* @param query 查询关键字
* @return 耳号列表
*/
public List<String> searchEarNumbers(String query);
}

View File

@@ -119,4 +119,6 @@ public interface IScBreedRecordService
* @return 配种记录集合
*/
public List<ScBreedRecord> getBreedRecordsByTimeRange(Long sheepId, String startDate, String endDate);
ScBreedRecord getAutomaticBreedMatch(String manageTags);
}

View File

@@ -21,6 +21,7 @@ import org.springframework.util.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.web.bind.annotation.RequestParam;
/**
* 配种计划生成Service业务层处理
@@ -67,7 +68,7 @@ public class ScBreedPlanGenerateServiceImpl implements IScBreedPlanGenerateServi
* @return 符合条件的母羊列表
*/
@Override
public List<Map<String, Object>> selectEligibleEwe()
public List<Map<String, Object>> selectEligibleEwe(@RequestParam(value = "manageTags", required = false) String manageTags)
{
return scBreedPlanGenerateMapper.selectEligibleEwe();
}
@@ -78,7 +79,7 @@ public class ScBreedPlanGenerateServiceImpl implements IScBreedPlanGenerateServi
* @return 符合条件的公羊列表
*/
@Override
public List<Map<String, Object>> selectEligibleRam()
public List<Map<String, Object>> selectEligibleRam(@RequestParam(value = "manageTags", required = false) String manageTags)
{
return scBreedPlanGenerateMapper.selectEligibleRam();
}
@@ -102,7 +103,16 @@ public class ScBreedPlanGenerateServiceImpl implements IScBreedPlanGenerateServi
// 自动生成计划名称:日期+计划类型
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = sdf.format(new Date());
String planTypeName = (planType == 1) ? "同期发情配种计划" : "本交配种计划";
String planTypeName = "";
switch (planType) {
case 1: planTypeName = "供体母羊配种计划"; break;
case 2: planTypeName = "同期发情人工授精计划"; break;
case 3: planTypeName = "本交配种计划"; break;
case 4: planTypeName = "自然发情人工授精计划"; break;
default: planTypeName = "未知配种计划"; break;
}
planName = dateStr + planTypeName;
planGenerate.setPlanName(planName);
@@ -137,21 +147,15 @@ public class ScBreedPlanGenerateServiceImpl implements IScBreedPlanGenerateServi
for (int i = 0; i < eweIds.size(); i++) {
ScBreedPlan breedPlan = new ScBreedPlan();
// 存储公羊ID而不是字符串
breedPlan.setRamId(ramIds.get(ramIndex).toString());
breedPlan.setEweId(eweIds.get(i).toString());
// 根据计划类型设置配种类型:同期发情配种计划->同期发情,本交配种计划->本交
if (planType == 1) {
breedPlan.setBreedType(1L); // 同期发情
} else {
breedPlan.setBreedType(2L); // 本交
}
// 2. 修改:直接使用 planType 作为 breedType (假设一一对应)
// 1=供体母羊配种, 2=同期发情人工授精, 3=本交, 4=自然发情人工授精
breedPlan.setBreedType(Long.valueOf(planType));
// 插入临时配种计划,关联到生成记录
scBreedPlanGenerateMapper.insertTempBreedPlan(planGenerateId, breedPlan);
// 每个公羊配种指定数量的母羊后,切换到下一个公羊
if ((i + 1) % ewesPerRam == 0 && ramIndex < ramIds.size() - 1) {
ramIndex++;
}
@@ -356,10 +360,32 @@ public class ScBreedPlanGenerateServiceImpl implements IScBreedPlanGenerateServi
// 空行
rowNum++;
String typeName = "";
switch (planGenerate.getPlanType()) {
case 1: typeName = "供体母羊配种计划"; break;
case 2: typeName = "同期发情人工授精计划"; break;
case 3: typeName = "本交配种计划"; break;
case 4: typeName = "自然发情人工授精计划"; break;
default: typeName = "未知"; break;
}
// 基本信息
Row infoRow1 = sheet.createRow(rowNum++);
infoRow1.createCell(0).setCellValue("计划类型:");
infoRow1.createCell(1).setCellValue(planGenerate.getPlanType() == 1 ? "同期发情配种计划" : "本交配种计划");
String planTypeNameStr;
Integer type = planGenerate.getPlanType();
if (type != null) {
switch (type) {
case 1: planTypeNameStr = "供体母羊配种计划"; break;
case 2: planTypeNameStr = "同期发情人工授精计划"; break;
case 3: planTypeNameStr = "本交配种计划"; break;
case 4: planTypeNameStr = "自然发情人工授精计划"; break;
default: planTypeNameStr = "未知类型";
}
} else {
planTypeNameStr = "";
}
infoRow1.createCell(1).setCellValue(planTypeNameStr);
infoRow1.createCell(3).setCellValue("计划日期:");
infoRow1.createCell(4).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(planGenerate.getPlanDate()));
@@ -447,14 +473,23 @@ public class ScBreedPlanGenerateServiceImpl implements IScBreedPlanGenerateServi
dataRow.createCell(colNum++).setCellValue(getStringValue(detail, "ram_current_weight"));
// 配种类型
Object breedType = detail.get("breed_type");
Object breedTypeObj = detail.get("breed_type");
String breedTypeName = "未知类型";
if (breedType != null) {
int typeValue = Integer.parseInt(breedType.toString());
breedTypeName = typeValue == 1 ? "同期发情" : (typeValue == 2 ? "本交" : "未知类型");
if (breedTypeObj != null) {
try {
int typeValue = Integer.parseInt(breedTypeObj.toString());
switch (typeValue) {
case 1: breedTypeName = "供体母羊配种"; break;
case 2: breedTypeName = "同期发情人工授精"; break;
case 3: breedTypeName = "本交"; break;
case 4: breedTypeName = "自然发情人工授精"; break;
default: breedTypeName = "未知类型";
}
} catch (NumberFormatException e) {
// ignore
}
}
dataRow.createCell(colNum++).setCellValue(breedTypeName);
dataRow.createCell(colNum++).setCellValue(breedTypeName);
// 应用数据样式
for (int j = 0; j < headers.length; j++) {
if (dataRow.getCell(j) != null) {
@@ -537,4 +572,8 @@ public class ScBreedPlanGenerateServiceImpl implements IScBreedPlanGenerateServi
scBreedPlanGenerateMapper.deleteTempBreedPlanByPlanId(id);
return scBreedPlanGenerateMapper.deleteScBreedPlanGenerateById(id);
}
@Override
public List<String> searchEarNumbers(String query) {
return scBreedPlanGenerateMapper.searchEarNumbers(query);
}
}

View File

@@ -1,5 +1,6 @@
package com.zhyc.module.produce.breed.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.zhyc.common.utils.DateUtils;
@@ -44,31 +45,47 @@ public class ScBreedRecordServiceImpl implements IScBreedRecordService
* @param scBreedRecord 配种记录
* @return 配种记录
*/
// @Override
// public List<ScBreedRecord> selectScBreedRecordList(ScBreedRecord scBreedRecord)
// {
// // 如果查询条件中有耳号需要先转换为ID
// if (StringUtils.isNotEmpty(scBreedRecord.getEweManageTags()))
// {
// Long eweId = scBreedRecordMapper.getSheepIdByManageTags(scBreedRecord.getEweManageTags());
// if (eweId != null)
// {
// scBreedRecord.setEweId(eweId.toString());
// }
// }
//
// if (StringUtils.isNotEmpty(scBreedRecord.getRamManageTags()))
// {
// Long ramId = scBreedRecordMapper.getRamIdByManageTags(scBreedRecord.getRamManageTags());
// if (ramId != null)
// {
// scBreedRecord.setRamId(ramId.toString());
// }
// }
//
// return scBreedRecordMapper.selectScBreedRecordList(scBreedRecord);
// }
@Override
public List<ScBreedRecord> selectScBreedRecordList(ScBreedRecord scBreedRecord)
{
// 如果查询条件中有耳号需要先转换为ID
public List<ScBreedRecord> selectScBreedRecordList(ScBreedRecord scBreedRecord) {
// ... (耳号转ID逻辑保持不变) ...
// 如果查询条件中有耳号需要先转换为ID (注意:供体母羊/公羊是直接存字符串的不需要转ID只有作为受体的eweId需要转)
if (StringUtils.isNotEmpty(scBreedRecord.getEweManageTags()))
{
Long eweId = scBreedRecordMapper.getSheepIdByManageTags(scBreedRecord.getEweManageTags());
if (eweId != null)
{
// 注意这里仅设置eweId用于查询作为受体的记录
// 如果用户想搜"供体母羊"是xxxMapper XML中的 OR 逻辑会处理
scBreedRecord.setEweId(eweId.toString());
}
}
if (StringUtils.isNotEmpty(scBreedRecord.getRamManageTags()))
{
Long ramId = scBreedRecordMapper.getRamIdByManageTags(scBreedRecord.getRamManageTags());
if (ramId != null)
{
scBreedRecord.setRamId(ramId.toString());
}
}
// ...
return scBreedRecordMapper.selectScBreedRecordList(scBreedRecord);
}
/**
* 新增配种记录
*
@@ -172,34 +189,89 @@ public class ScBreedRecordServiceImpl implements IScBreedRecordService
* @param manageTags 母羊管理耳号
* @return 配种计划信息
*/
// @Override
// public Map<String, Object> getLatestBreedPlanByEweTags(String manageTags)
// {
// try {
// // 优先从配种计划生成表获取最新计划
// Map<String, Object> latestPlan = scBreedRecordMapper.getLatestBreedPlanByEweTags(manageTags);
//
// if (latestPlan != null && !latestPlan.isEmpty()) {
// log.info("从配种计划生成表获取到配种计划: {}", latestPlan);
// return latestPlan;
// }
//
// // 如果生成表中没有,则从普通配种计划表获取
// Map<String, Object> normalPlan = scBreedRecordMapper.getBreedPlanByEweTags(manageTags);
// if (normalPlan != null && !normalPlan.isEmpty()) {
// log.info("从配种计划表获取到配种计划: {}", normalPlan);
// return normalPlan;
// }
//
// log.warn("未找到母羊耳号 {} 的配种计划信息", manageTags);
// return null;
//
// } catch (Exception e) {
// log.error("获取配种计划信息时发生异常,母羊耳号: {}", manageTags, e);
// return null;
// }
// }
/**
* 根据母羊耳号获取最新的配种计划信息
* 修改逻辑:优先查配种计划 -> 其次查冲胚记录(作为受体)
*/
@Override
public Map<String, Object> getLatestBreedPlanByEweTags(String manageTags)
{
try {
// 优先从配种计划生成表获取最新计划
// 1. 优先从配种计划生成表获取最新计划 (同期发情/本交等)
Map<String, Object> latestPlan = scBreedRecordMapper.getLatestBreedPlanByEweTags(manageTags);
if (latestPlan != null && !latestPlan.isEmpty()) {
log.info("从配种计划生成表获取到配种计划: {}", latestPlan);
return latestPlan;
}
// 如果生成表中没有,从普通配种计划表获取
// 2. 如果生成表中没有,从普通配种计划表获取
Map<String, Object> normalPlan = scBreedRecordMapper.getBreedPlanByEweTags(manageTags);
if (normalPlan != null && !normalPlan.isEmpty()) {
log.info("从配种计划表获取到配种计划: {}", normalPlan);
return normalPlan;
}
log.warn("未找到母羊耳号 {} 的配种计划信息", manageTags);
// 3. 【新增逻辑】如果都没有,尝试从冲胚记录中查找(该羊是否作为受体)
// 这里的业务逻辑是:如果这只羊在冲胚记录的"受体列表"中,且是最近的操作,则认为它是去做胚胎移植
Map<String, Object> flushRecord = scBreedRecordMapper.getFlushRecordByEweNo(manageTags);
if (flushRecord != null && !flushRecord.isEmpty()) {
log.info("从冲胚记录获取到移植信息: {}", flushRecord);
// 构造一个符合前端预期的Map结构
Map<String, Object> etPlan = new HashMap<>();
etPlan.put("breed_type", 5); // 设定 5 为胚胎移植
etPlan.put("breedType", 5); // 驼峰兼容
etPlan.put("breed_type_name", "胚胎移植");
// 填充冲胚记录带来的数据
etPlan.put("donorEweNo", flushRecord.get("donor_female_no")); // 供体母羊
etPlan.put("donorRamNo", flushRecord.get("donor_male_no")); // 供体公羊
etPlan.put("embryoCount", flushRecord.get("transferred")); // 移胚数
// 拼接配种子类型 (例如: 体内供体 鲜胚)
String subType = "";
if (flushRecord.get("embryo_type") != null) subType += flushRecord.get("embryo_type");
if (flushRecord.get("storage_method") != null) subType += " " + flushRecord.get("storage_method");
etPlan.put("embryoSubType", subType.trim());
return etPlan;
}
log.warn("未找到母羊耳号 {} 的配种或移植计划信息", manageTags);
return null;
} catch (Exception e) {
log.error("获取配种计划信息时发生异常,母羊耳号: {}", manageTags, e);
log.error("获取配种/移植计划信息时发生异常,母羊耳号: {}", manageTags, e);
return null;
}
}
/**
* 同步孕检结果到配种记录
*
@@ -246,47 +318,102 @@ public class ScBreedRecordServiceImpl implements IScBreedRecordService
return scBreedRecordMapper.selectBreedRecordByMatingTime(sheepId, startDate, endDate);
}
// /**
// * 新增配种记录
// *
// * @param scBreedRecord 配种记录
// * @return 结果
// */
// @Override
// public int insertScBreedRecord(ScBreedRecord scBreedRecord)
// {
// // 设置创建时间
// scBreedRecord.setCreateTime(DateUtils.getNowDate());
//
// // 插入配种记录
// int result = scBreedRecordMapper.insertScBreedRecord(scBreedRecord);
//
// // 如果插入成功,同步更新羊只的配种日期
// if (result > 0 && scBreedRecord.getEweId() != null) {
// try {
// Long eweId = Long.parseLong(scBreedRecord.getEweId());
//
//// // 方案1只更新配种日期推荐
//// scBreedRecordMapper.updateSheepMatingDate(
//// eweId,
//// scBreedRecord.getCreateTime(),
//// scBreedRecord.getCreateBy()
//// );
//
//// 方案2同时更新配种日期和配种次数如果需要的话取消下面注释
// scBreedRecordMapper.incrementSheepMatingCount(
// eweId,
// scBreedRecord.getCreateTime(),
// scBreedRecord.getCreateBy()
// );
//
// log.info("同步更新羊只 {} 的配种日期成功", eweId);
// } catch (Exception e) {
// log.error("同步更新羊只配种日期失败", e);
// // 不影响主流程,只记录日志
// }
// }
//
// return result;
// }
/**
* 新增配种记录
*
* @param scBreedRecord 配种记录
* @return 结果
*/
@Override
public int insertScBreedRecord(ScBreedRecord scBreedRecord)
{
// 设置创建时间
scBreedRecord.setCreateTime(DateUtils.getNowDate());
// 插入配种记录
// 如果是胚胎移植(5),且前端没有传移胚数等信息,可以在这里做一次兜底查询
// 但通常前端 form 表单提交时应该已经通过 getLatestBreedPlanByEweTags 填好了
// 插入记录
int result = scBreedRecordMapper.insertScBreedRecord(scBreedRecord);
// 如果插入成功,同步更新羊只的配种日期
// 同步更新羊只的基础信息(配种次数、配种日期
if (result > 0 && scBreedRecord.getEweId() != null) {
try {
Long eweId = Long.parseLong(scBreedRecord.getEweId());
// // 方案1只更新配种日期推荐
// scBreedRecordMapper.updateSheepMatingDate(
// eweId,
// scBreedRecord.getCreateTime(),
// scBreedRecord.getCreateBy()
// );
// 方案2同时更新配种日期和配种次数如果需要的话取消下面注释
scBreedRecordMapper.incrementSheepMatingCount(
eweId,
scBreedRecord.getCreateTime(),
scBreedRecord.getCreateBy()
);
log.info("同步更新羊只 {} 的配种日期成功", eweId);
scBreedRecordMapper.incrementSheepMatingCount(
eweId,
scBreedRecord.getCreateTime(),
scBreedRecord.getCreateBy()
);
} catch (Exception e) {
log.error("同步更新羊只配种日期失败", e);
// 不影响主流程,只记录日志
}
}
return result;
}
@Override
public ScBreedRecord getAutomaticBreedMatch(String manageTags) {
// 1. 尝试从配种计划获取 (breed_type: 1, 2, 3, 4)
Map<String, Object> plan = scBreedRecordMapper.getLatestBreedPlanByEweTags(manageTags);
if (plan != null) {
ScBreedRecord record = new ScBreedRecord();
record.setBreedType(Integer.parseInt(plan.get("breed_type").toString()));
record.setRamManageTags((String) plan.get("ram_manage_tags"));
return record;
}
// 2. 尝试从冲胚记录获取
Map<String, Object> flushRecord = scBreedRecordMapper.getFlushRecordByEweNo(manageTags);
if (flushRecord != null) {
ScBreedRecord record = new ScBreedRecord();
record.setBreedType(5); // 设定 5 为胚胎移植(您可根据实际调整枚举)
record.setEmbryoCount(Integer.parseInt(flushRecord.get("transferred").toString()));
record.setDonorEweNo((String) flushRecord.get("donor_female_no"));
record.setDonorRamNo((String) flushRecord.get("donor_male_no"));
// 根据冲胚记录的存储方式和类型拼接“配种子类型”
record.setEmbryoSubType(flushRecord.get("embryo_type") + " " + flushRecord.get("storage_method"));
return record;
}
return null; // 均未找到
}
}

View File

@@ -109,11 +109,11 @@ public class ScLambingRecordServiceImpl implements IScLambingRecordService {
// 设置默认值
if (lambDetail.getIsRetained() == null) {
lambDetail.setIsRetained(0); // 默认为0
lambDetail.setIsRetained(false); // 默认为0
}
// 验证是否留养值的有效性0-否1-是
if (lambDetail.getIsRetained() != 0 && lambDetail.getIsRetained() != 1) {
if (lambDetail.getIsRetained() != false && lambDetail.getIsRetained() != true) {
throw new RuntimeException("是否留养值无效请使用0或1");
}

View File

@@ -150,9 +150,12 @@
<select id="searchEarNumbers" resultType="java.lang.String">
SELECT DISTINCT manage_tags
FROM bas_sheep
WHERE manage_tags LIKE CONCAT(#{query}, '%')
FROM bas_sheep b
<where>
manage_tags LIKE CONCAT(#{query}, '%')
AND is_delete = 0
${params.dataScope}
</where>
ORDER by manage_tags
LIMIT 50
</select>

View File

@@ -6,18 +6,18 @@
<resultMap type="DaRanch" id="DaRanchResult">
<result property="id" column="id"/>
<result property="ranch" column="ranch"/>
<result property="sysRanch" column="sysRanch"/>
</resultMap>
<sql id="selectDaRanchVo">
select id, ranch
select id, sysRanch
from da_ranch
</sql>
<select id="selectDaRanchList" parameterType="DaRanch" resultMap="DaRanchResult">
<include refid="selectDaRanchVo"/>
<where>
<if test="ranch != null and ranch != ''">and ranch = #{ranch}</if>
<if test="sysRanch != null and sysRanch != ''">and sysRanch = #{sysRanch}</if>
</where>
</select>
@@ -29,17 +29,17 @@
<insert id="insertDaRanch" parameterType="DaRanch" useGeneratedKeys="true" keyProperty="id">
insert into da_ranch
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="ranch != null">ranch,</if>
<if test="sysRanch != null">sysRanch,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="ranch != null">#{ranch},</if>
<if test="sysRanch != null">#{sysRanch},</if>
</trim>
</insert>
<update id="updateDaRanch" parameterType="DaRanch">
update da_ranch
<trim prefix="SET" suffixOverrides=",">
<if test="ranch != null">ranch = #{ranch},</if>
<if test="sysRanch != null">sysRanch = #{sysRanch},</if>
</trim>
where id = #{id}
</update>

View File

@@ -58,6 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and datetime between #{params.beginDatetime} and #{params.endDatetime}
</if>
<if test="technical != null and technical != ''">and technical = #{technical}</if>
${params.dataScope}
</where>
<!-- 基准排序:日期永远第一序,降序 -->
@@ -78,13 +79,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into sw_deworm
(sheep_id, usage_id, variety, sheep_type, gender, month_age,
parity, breed,datetime, technical, comment,
update_by, update_time, create_by, create_time)
update_by, update_time, create_by, create_time,user_id, dept_id)
values
<foreach collection="list" item="d" separator=",">
(#{d.sheepId}, #{d.usageId}, #{d.variety}, #{d.sheepType},
#{d.gender}, #{d.monthAge}, #{d.parity},#{d.breed}, #{d.datetime},
#{d.technical}, #{d.comment},
#{d.updateBy}, #{d.updateTime}, #{d.createBy}, #{d.createTime})
#{d.updateBy}, #{d.updateTime}, #{d.createBy}, #{d.createTime},#{d.userId},#{d.deptId})
</foreach>
</insert>

View File

@@ -69,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="result != null "> and result = #{result}</if>
<if test="treatDay != null "> and treat_day = #{treatDay}</if>
<if test="sheepfoldId != null "> and sd.sheepfold_id = #{sheepfoldId}</if>
${params.dataScope}
</where>
ORDER BY datetime DESC
<choose>
@@ -101,6 +102,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sheepfoldId != null">sheepfold_id,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="userId != null">user_id,</if>
<if test="deptId != null">dept_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="treatId != null">#{treatId},</if>
@@ -118,6 +121,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sheepfoldId != null">#{sheepfoldId},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="userId != null">#{userId},</if>
<if test="deptId != null">#{deptId},</if>
</trim>
</insert>

View File

@@ -43,7 +43,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ds.sheepfold_name
FROM sw_disinfect sd
LEFT JOIN da_sheepfold ds ON ds.id = sd.sheepfold_id
WHERE 1 = 1
<where>1 = 1
<if test="sheepfoldId != null"> AND sd.sheepfold_id = #{sheepfoldId}</if>
<if test="datetime != null"> AND sd.datetime = #{datetime}</if>
<if test="technician != null and technician != ''"> AND sd.technician = #{technician}</if>
@@ -61,6 +61,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND sm.name like concat('%',#{mediName},'%')
)
</if>
${params.dataScope}
</where>
ORDER BY datetime DESC
</select>
@@ -72,12 +74,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDisinfect" parameterType="Disinfect" useGeneratedKeys="true" keyProperty="id">
insert into sw_disinfect
(sheepfold_id, datetime, technician, way, usage_id, ratio, comment, update_by, update_time, create_by, create_time)
(sheepfold_id, datetime, technician, way, usage_id, ratio, comment, update_by, update_time, create_by, create_time, user_id,dept_id)
values
<foreach collection="list" item="d" separator=",">
(#{d.sheepfoldId}, #{d.datetime}, #{d.technician}, #{d.way},
#{d.usageId}, #{d.ratio}, #{d.comment},
#{d.updateBy}, #{d.updateTime}, #{d.createBy}, #{d.createTime})
#{d.updateBy}, #{d.updateTime}, #{d.createBy}, #{d.createTime},#{d.userId},#{d.deptId})
</foreach>
</insert>

View File

@@ -62,6 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
${params.dataScope}
</where>
<!-- 基准排序:日期永远第一序,降序 -->
ORDER BY datetime DESC
@@ -81,13 +82,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into sw_health
(sheep_id, usage_id, variety, sheep_type, gender, month_age,
parity, breed,datetime, technical, comment,
update_by, update_time, create_by, create_time)
update_by, update_time, create_by, create_time,user_id,dept_id)
values
<foreach collection="list" item="d" separator=",">
(#{d.sheepId}, #{d.usageId}, #{d.variety}, #{d.sheepType},
#{d.gender}, #{d.monthAge}, #{d.parity},#{d.breed}, #{d.datetime},
#{d.technical}, #{d.comment},
#{d.updateBy}, #{d.updateTime}, #{d.createBy}, #{d.createTime})
#{d.updateBy}, #{d.updateTime}, #{d.createBy}, #{d.createTime},#{d.userId},#{d.deptId})
</foreach>
</insert>

View File

@@ -60,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
${params.dataScope}
</where>
<!-- 基准排序:日期永远第一序,降序 -->
ORDER BY datetime DESC
@@ -79,13 +80,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into sw_immunity
(sheep_id, usage_id, variety, sheep_type, gender, month_age,
parity, breed,datetime, technical, comment,
update_by, update_time, create_by, create_time)
update_by, update_time, create_by, create_time,user_id,dept_id)
values
<foreach collection="list" item="d" separator=",">
(#{d.sheepId}, #{d.usageId}, #{d.variety}, #{d.sheepType},
#{d.gender}, #{d.monthAge}, #{d.parity},#{d.breed}, #{d.datetime},
#{d.technical}, #{d.comment},
#{d.updateBy}, #{d.updateTime}, #{d.createBy}, #{d.createTime})
#{d.updateBy}, #{d.updateTime}, #{d.createBy}, #{d.createTime},#{d.userId},#{d.deptId})
</foreach>
</insert>

View File

@@ -71,6 +71,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="result != null "> and result = #{result}</if>
<if test="status != null "> and status = #{status}</if>
<if test="sheepType != null and sheepType!= ''"> and sqr.sheep_type=#{sheepType}</if>
${params.dataScope}
</where>
ORDER BY datetime DESC
<choose>
@@ -112,7 +113,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_by,
update_time,
create_by,
create_time
create_time,
user_id,
dept_id
)
VALUES
<foreach collection="list" item="item" separator=",">
@@ -133,7 +136,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.updateBy},
#{item.updateTime},
#{item.createBy},
#{item.createTime}
#{item.createTime},
#{item.userId},
#{item.deptId}
)
</foreach>
</insert>

View File

@@ -111,6 +111,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND sm.name LIKE CONCAT('%', #{name}, '%')
)
</if>
${params.dataScope}
</where>
ORDER BY smu.datetime DESC
</select>
@@ -162,6 +163,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="userId != null">user_id,</if>
<if test="deptId != null">dept_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
@@ -173,6 +176,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">#{updateTime},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="userId != null">#{userId},</if>
<if test="deptId != null">#{deptId},</if>
</trim>
</insert>

View File

@@ -78,6 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="diseaseId != null "> and disease_id = #{diseaseId}</if>
<if test="status != null and status !=''"> and status = #{status}</if>
<if test="veterinary != null and veterinary != ''"> and veterinary = #{veterinary}</if>
${params.dataScope}
</where>
ORDER BY datetime DESC
<choose>
@@ -121,6 +122,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="userId != null">#{user_id},</if>
<if test="deptId != null">#{dept_id},</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="diagId != null">#{diagId},</if>
@@ -144,6 +147,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">#{updateTime},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="userId != null">#{userId},</if>
<if test="deptId != null">#{deptId},</if>
</trim>
</insert>
@@ -152,14 +157,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(diag_id, sheep_id, variety, sheep_type, month_age, gender,
parity, breed, lact_day, gest_day, datetime,
disease_id, disease_pid, veterinary, usage_id,status ,
comment, update_by, update_time, create_by, create_time)
comment, update_by, update_time, create_by, create_time, user_id, dept_id)
values
<foreach collection="list" item="t" separator=",">
(#{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.status}, #{t.comment},
#{t.updateBy}, #{t.updateTime},#{t.createBy}, #{t.createTime})
#{t.updateBy}, #{t.updateTime},#{t.createBy}, #{t.createTime},#{t.userId},#{t.deptId})
</foreach>
</insert>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhyc.module.common.mapper.DeptMapper">
<resultMap type="Dept" id="DeptResult">
<result property="deptId" column="dept_id" />
<result property="deptName" column="dept_name" />
<result property="parentId" column="parent_id" />
<result property="orderNum" column="order_num" />
<result property="leader" column="leader" />
<result property="status" column="status" />
<result property="delFlag" column="del_flag" />
</resultMap>
<select id="selectTopSecondLevelDept" resultMap="DeptResult" parameterType="Long">
SELECT d2.*
FROM sys_dept d1
LEFT JOIN sys_dept d2
ON d2.dept_id = CASE
WHEN d1.ancestors = '0' OR d1.parent_id = 0 THEN d1.dept_id
-- 二级部门逗号只出现1次返回自身ID
WHEN LENGTH(d1.ancestors) - LENGTH(REPLACE(d1.ancestors, ',', '')) = 1
THEN d1.dept_id
-- 三级及以上取第3个值索引2即二级部门ID
ELSE CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(d1.ancestors, ',', 3), ',', -1) AS UNSIGNED)
END
WHERE d1.dept_id = #{deptId}
AND d2.dept_id IS NOT NULL
</select>
</mapper>

View File

@@ -12,14 +12,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<select id="getUserListByCode" resultMap="UserResult">
SELECT u.user_id, nick_name , post_name , post_code
FROM sys_role r
JOIN sys_user_role ur ON r.role_id = ur.role_id
JOIN sys_user u ON ur.user_id = u.user_id
JOIN sys_user_post up ON u.user_id = up.user_id
JOIN sys_post p ON up.post_id = p.post_id
WHERE p.post_code LIKE CONCAT('%', #{postCode}, '%')
AND r.status = 0 and r.del_flag = 0;
</select>
<choose>
<!-- deptId = 0查询所有用户不限制部门 -->
<when test="deptId == 0">
SELECT DISTINCT u.user_id, u.nick_name, p.post_name, p.post_code
FROM sys_user u
JOIN sys_user_post up ON u.user_id = up.user_id
JOIN sys_post p ON up.post_id = p.post_id
WHERE p.post_code LIKE CONCAT('%', #{postCode}, '%')
AND u.status = 0
AND u.del_flag = 0
</when>
<!-- deptId != 0递归查询该部门及所有子部门 -->
<otherwise>
WITH RECURSIVE dept_tree AS (
SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId}
UNION ALL
SELECT d.dept_id
FROM sys_dept d
INNER JOIN dept_tree dt ON d.parent_id = dt.dept_id
)
SELECT DISTINCT u.user_id, u.nick_name, p.post_name, p.post_code
FROM dept_tree dt
JOIN sys_user u ON u.dept_id = dt.dept_id
JOIN sys_user_post up ON u.user_id = up.user_id
JOIN sys_post p ON up.post_id = p.post_id
WHERE p.post_code LIKE CONCAT('%', #{postCode}, '%')
AND u.status = 0
AND u.del_flag = 0
</otherwise>
</choose>
</select>
</mapper>

View File

@@ -77,6 +77,9 @@
left join da_sheepfold dsf on bs.sheepfold_id = dsf.id
where bs.gender = 1
and bs.is_delete = 0
<if test="manageTags != null and manageTags != ''">
and bs.manage_tags like concat('%', #{manageTags}, '%')
</if>
and (bs.status_id = 1 or bs.status_id is null)
and (
(bst.name in ('青年羊', '超龄羊') and (
@@ -109,6 +112,9 @@
left join bas_breed_status bbs on bs.breed_status_id = bbs.id
where bs.gender = 2
and bs.is_delete = 0
<if test="manageTags != null and manageTags != ''">
and bs.manage_tags like concat('%', #{manageTags}, '%')
</if>
and bs.status_id = 1
and (
(bst.name in ('青年羊', '超龄羊') and (
@@ -310,4 +316,13 @@
<delete id="deleteTempBreedPlanByPlanId" parameterType="Long">
delete from sc_breed_plan_temp where plan_generate_id = #{planGenerateId}
</delete>
<!-- 模糊查询耳号列表 -->
<select id="searchEarNumbers" resultType="java.lang.String">
SELECT DISTINCT sf.bs_manage_tags
FROM sheep_file sf
WHERE sf.bs_manage_tags LIKE CONCAT(#{query}, '%')
AND sf.is_delete = 0
ORDER BY sf.bs_manage_tags
LIMIT 50
</select>
</mapper>

View File

@@ -4,6 +4,43 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhyc.module.produce.breed.mapper.ScBreedRecordMapper">
<!-- <resultMap type="ScBreedRecord" id="ScBreedRecordResult">-->
<!-- <result property="id" column="id" />-->
<!-- <result property="sheepId" column="sheep_id" />-->
<!-- <result property="ramId" column="ram_id" />-->
<!-- <result property="eweId" column="ewe_id" />-->
<!-- <result property="technician" column="technician" />-->
<!-- <result property="breedDrugs" column="breed_drugs" />-->
<!-- <result property="breedType" column="breed_type" />-->
<!-- <result property="createBy" column="create_by" / >-->
<!-- <result property="createTime" column="create_time" />-->
<!-- &lt;!&ndash; 显示字段 &ndash;&gt;-->
<!-- <result property="eweManageTags" column="ewe_manage_tags" />-->
<!-- <result property="eweVariety" column="ewe_variety" />-->
<!-- <result property="ramManageTags" column="ram_manage_tags" />-->
<!-- <result property="ramVariety" column="ram_variety" />-->
<!-- <result property="eweParity" column="ewe_parity" />-->
<!-- <result property="eweMonthAge" column="ewe_month_age" />-->
<!-- <result property="eweSheepfoldName" column="ewe_sheepfold_name" />-->
<!-- <result property="eweBreedStatus" column="ewe_breed_status" />-->
<!-- <result property="eweControlled" column="ewe_controlled" />-->
<!-- <result property="eweComment" column="ewe_comment" />-->
<!-- <result property="ranchName" column="ranch_name" />-->
<!-- <result property="matingType" column="mating_type" />-->
<!-- <result property="sheepType" column="sheep_type" />-->
<!-- <result property="matingCount" column="mating_count" />-->
<!-- <result property="timeSincePlanning" column="time_since_planning" />-->
<!-- &lt;!&ndash; 孕检相关字段 &ndash;&gt;-->
<!-- <result property="pregnancyCheckDate" column="pregnancy_check_date" />-->
<!-- <result property="pregnancyResult" column="pregnancy_result" />-->
<!-- <result property="pregnancyWay" column="pregnancy_way" />-->
<!-- <result property="fetusCount" column="fetus_count" />-->
<!-- <result property="pregnancyTechnician" column="pregnancy_technician" />-->
<!-- <result property="pregnancyRemark" column="pregnancy_remark" />-->
<!-- <result property="pregnancyRecordId" column="pregnancy_record_id" />-->
<!-- <result property="daysToPregnancyCheck" column="days_to_pregnancy_check" />-->
<!-- <result property="isPregnancyChecked" column="is_pregnancy_checked" />-->
<!-- </resultMap>-->
<resultMap type="ScBreedRecord" id="ScBreedRecordResult">
<result property="id" column="id" />
<result property="sheepId" column="sheep_id" />
@@ -12,9 +49,14 @@
<result property="technician" column="technician" />
<result property="breedDrugs" column="breed_drugs" />
<result property="breedType" column="breed_type" />
<result property="createBy" column="create_by" />
<result property="frozenSemenNo" column="frozen_semen_no" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<!-- 显示字段 -->
<result property="comment" column="comment" />
<result property="embryoCount" column="embryo_count" />
<result property="donorEweNo" column="donor_ewe" />
<result property="donorRamNo" column="donor_ram" />
<result property="eweManageTags" column="ewe_manage_tags" />
<result property="eweVariety" column="ewe_variety" />
<result property="ramManageTags" column="ram_manage_tags" />
@@ -26,24 +68,26 @@
<result property="eweControlled" column="ewe_controlled" />
<result property="eweComment" column="ewe_comment" />
<result property="ranchName" column="ranch_name" />
<result property="matingType" column="mating_type" />
<result property="sheepType" column="sheep_type" />
<result property="matingCount" column="mating_count" />
<result property="timeSincePlanning" column="time_since_planning" />
<!-- 孕检相关字段 -->
<result property="daysPostLambing" column="days_post_lambing" />
<result property="daysLactation" column="days_lactation" />
<result property="daysPostMating" column="days_post_mating" />
<result property="lastMatingDate" column="last_mating_date" />
<result property="pregnancyCheckDate" column="pregnancy_check_date" />
<result property="pregnancyResult" column="pregnancy_result" />
<result property="pregnancyWay" column="pregnancy_way" />
<result property="fetusCount" column="fetus_count" />
<result property="pregnancyTechnician" column="pregnancy_technician" />
<result property="pregnancyRemark" column="pregnancy_remark" />
<result property="eweParity" column="eweParity" />
<result property="pregnancyRecordId" column="pregnancy_record_id" />
<result property="daysToPregnancyCheck" column="days_to_pregnancy_check" />
<result property="isPregnancyChecked" column="is_pregnancy_checked" />
</resultMap>
</resultMap>
<!-- <sql id="selectScBreedRecordVo">-->
<!-- select-->
<!-- select DISTINCT-->
<!-- br.id,-->
<!-- br.sheep_id,-->
<!-- br.ram_id,-->
@@ -68,7 +112,8 @@
<!-- &#45;&#45; 公羊信息(从视图获取)-->
<!-- ram_view.bs_manage_tags as ram_manage_tags,-->
<!-- ram_view.variety as ram_variety,-->
<!-- &#45;&#45; 配种方式显示(修改:增加3-冲胚、4-自然发情人工授精)-->
<!-- &#45;&#45; 配种方式显示-->
<!-- CASE br.breed_type-->
<!-- WHEN 1 THEN '同期发情'-->
<!-- WHEN 2 THEN '本交'-->
@@ -99,15 +144,15 @@
<!-- from sc_breed_record br-->
<!-- left join sheep_file ewe_view on br.ewe_id = ewe_view.id-->
<!-- left join sheep_file ram_view on br.ram_id = ram_view.id-->
<!-- left join sc_pregnancy_record pr on pr.sheep_id = br.ewe_id-->
<!-- and pr.is_delete = 0-->
<!-- and pr.datetime >= br.create_time-->
<!-- and pr.datetime = (-->
<!-- select min(pr2.datetime)-->
<!-- from sc_pregnancy_record pr2-->
<!-- where pr2.sheep_id = br.ewe_id-->
<!-- and pr2.is_delete = 0-->
<!-- and pr2.datetime >= br.create_time-->
<!-- &#45;&#45; 修复:使用子查询确保只返回一条孕检记录-->
<!-- left join sc_pregnancy_record pr on pr.id = (-->
<!-- select pr2.id-->
<!-- from sc_pregnancy_record pr2-->
<!-- where pr2.sheep_id = br.ewe_id-->
<!-- and pr2.is_delete = 0-->
<!-- and pr2.datetime >= br.create_time-->
<!-- order by pr2.datetime asc, pr2.id asc-->
<!-- limit 1-->
<!-- )-->
<!-- </sql>-->
<sql id="selectScBreedRecordVo">
@@ -119,9 +164,19 @@
br.technician,
br.breed_drugs,
br.breed_type,
br.frozen_sperm_no, -- 冻精号
br.comment,
br.create_by,
br.create_time,
-- 母羊信息(从视图获取)
-- 胚胎移植相关字段 (如果不存表里需要join sc_embryo_flush这里假设存表或已有字段如需Join请参考下方注释)
-- 假设表里已有这些列或者我们通过Join sheep_file 拿(但sheep_file没有donor信息)
-- 这里按照最佳实践应在插入时将Donor信息固化在breed_record表中
br.donor_ewe,
br.donor_ram,
br.embryo_count,
-- 母羊信息
ewe_view.bs_manage_tags as ewe_manage_tags,
ewe_view.variety as ewe_variety,
ewe_view.parity as ewe_parity,
@@ -133,19 +188,51 @@
ewe_view.dr_ranch as ranch_name,
ewe_view.name as sheep_type,
ewe_view.mating_total as mating_count,
-- 公羊信息(从视图获取)
-- 公羊信息
ram_view.bs_manage_tags as ram_manage_tags,
ram_view.variety as ram_variety,
-- 配种方式显示
CASE br.breed_type
WHEN 1 THEN '同期发情'
WHEN 2 THEN '本交'
WHEN 3 THEN '冲胚'
WHEN 4 THEN '自然发情人工授精'
ELSE '未知'
END as mating_type,
-- 发情后配种时间(小时数)
TIMESTAMPDIFF(HOUR, br.create_time, NOW()) as time_since_planning,
-- ================= 计算字段实现 =================
-- 1. 配种时产后天数 (距离上一次产羔: 找最近一次小于配种时间的产羔日期)
DATEDIFF(br.create_time, (
SELECT lambing_date
FROM sheep_file
WHERE id = br.ewe_id
)) as days_post_lambing,
-- 2. 配种时泌乳天数 (距离上一次孕检且怀孕)
DATEDIFF(br.create_time, (
SELECT MAX(pr_sub.datetime)
FROM sc_pregnancy_record pr_sub
WHERE pr_sub.sheep_id = br.ewe_id
AND pr_sub.result = '怀孕'
AND pr_sub.is_delete = 0
AND pr_sub.datetime &lt; br.create_time
)) as days_lactation,
-- 3. 配种时配后天数 (距离上一次配种)
DATEDIFF(br.create_time, (
SELECT MAX(br_sub.create_time)
FROM sc_breed_record br_sub
WHERE br_sub.ewe_id = br.ewe_id
AND br_sub.create_time &lt; br.create_time
)) as days_post_mating,
-- 4. 上次配种日期
(
SELECT MAX(br_sub.create_time)
FROM sc_breed_record br_sub
WHERE br_sub.ewe_id = br.ewe_id
AND br_sub.create_time &lt; br.create_time
) as last_mating_date,
-- ===============================================
-- 孕检相关信息
pr.datetime as pregnancy_check_date,
pr.result as pregnancy_result,
@@ -164,10 +251,10 @@
WHEN pr.id IS NOT NULL THEN 1
ELSE 0
END as is_pregnancy_checked
from sc_breed_record br
left join sheep_file ewe_view on br.ewe_id = ewe_view.id
left join sheep_file ram_view on br.ram_id = ram_view.id
-- 修复:使用子查询确保只返回一条孕检记录
left join sc_pregnancy_record pr on pr.id = (
select pr2.id
from sc_pregnancy_record pr2
@@ -178,6 +265,32 @@
limit 1
)
</sql>
<!-- <select id="selectScBreedRecordList" parameterType="ScBreedRecord" resultMap="ScBreedRecordResult">-->
<!-- <include refid="selectScBreedRecordVo"/>-->
<!-- <where>-->
<!-- <if test="sheepId != null "> and br.sheep_id = #{sheepId}</if>-->
<!-- <if test="ramId != null and ramId != ''"> and br.ram_id = #{ramId}</if>-->
<!-- <if test="eweId != null and eweId != ''"> and br.ewe_id = #{eweId}</if>-->
<!-- <if test="breedType != null"> and br.breed_type = #{breedType}</if>-->
<!-- <if test="technician != null and technician != ''"> and br.technician like concat('%', #{technician}, '%')</if>-->
<!-- <if test="breedDrugs != null and breedDrugs != ''"> and br.breed_drugs like concat('%', #{breedDrugs}, '%')</if>-->
<!-- <if test="createBy != null and createBy != ''"> and br.create_by like concat('%', #{createBy}, '%')</if>-->
<!-- <if test="createTime != null "> and date_format(br.create_time,'%y-%m-%d') = date_format(#{createTime},'%y-%m-%d')</if>-->
<!-- &lt;!&ndash; 新增耳号查询条件 &ndash;&gt;-->
<!-- <if test="eweManageTags != null and eweManageTags != ''"> and ewe_view.bs_manage_tags like concat('%', #{eweManageTags}, '%')</if>-->
<!-- <if test="ramManageTags != null and ramManageTags != ''"> and ram_view.bs_manage_tags like concat('%', #{ramManageTags}, '%')</if>-->
<!-- <if test="eweVariety != null and eweVariety != ''"> and ewe_view.variety like concat('%', #{eweVariety}, '%')</if>-->
<!-- <if test="ramVariety != null and ramVariety != ''"> and ram_view.variety like concat('%', #{ramVariety}, '%')</if>-->
<!-- <if test="ranchId != null"> and ewe_view.ranch_id = #{ranchId}</if>-->
<!-- &lt;!&ndash; 孕检相关查询条件 &ndash;&gt;-->
<!-- <if test="pregnancyResult != null and pregnancyResult != ''"> and pr.result like concat('%', #{pregnancyResult}, '%')</if>-->
<!-- <if test="isPregnancyChecked != null">-->
<!-- <if test="isPregnancyChecked == 1"> and pr.id IS NOT NULL</if>-->
<!-- <if test="isPregnancyChecked == 0"> and pr.id IS NULL</if>-->
<!-- </if>-->
<!-- </where>-->
<!-- order by br.create_time desc-->
<!-- </select>-->
<select id="selectScBreedRecordList" parameterType="ScBreedRecord" resultMap="ScBreedRecordResult">
<include refid="selectScBreedRecordVo"/>
<where>
@@ -185,22 +298,20 @@
<if test="ramId != null and ramId != ''"> and br.ram_id = #{ramId}</if>
<if test="eweId != null and eweId != ''"> and br.ewe_id = #{eweId}</if>
<if test="breedType != null"> and br.breed_type = #{breedType}</if>
<if test="technician != null and technician != ''"> and br.technician like concat('%', #{technician}, '%')</if>
<if test="breedDrugs != null and breedDrugs != ''"> and br.breed_drugs like concat('%', #{breedDrugs}, '%')</if>
<if test="createBy != null and createBy != ''"> and br.create_by like concat('%', #{createBy}, '%')</if>
<if test="createTime != null "> and date_format(br.create_time,'%y-%m-%d') = date_format(#{createTime},'%y-%m-%d')</if>
<!-- 新增耳号查询条件 -->
<if test="eweManageTags != null and eweManageTags != ''"> and ewe_view.bs_manage_tags like concat('%', #{eweManageTags}, '%')</if>
<if test="ramManageTags != null and ramManageTags != ''"> and ram_view.bs_manage_tags like concat('%', #{ramManageTags}, '%')</if>
<if test="eweVariety != null and eweVariety != ''"> and ewe_view.variety like concat('%', #{eweVariety}, '%')</if>
<if test="ramVariety != null and ramVariety != ''"> and ram_view.variety like concat('%', #{ramVariety}, '%')</if>
<if test="ranchId != null"> and ewe_view.ranch_id = #{ranchId}</if>
<!-- 孕检相关查询条件 -->
<if test="pregnancyResult != null and pregnancyResult != ''"> and pr.result like concat('%', #{pregnancyResult}, '%')</if>
<if test="isPregnancyChecked != null">
<if test="isPregnancyChecked == 1"> and pr.id IS NOT NULL</if>
<if test="isPregnancyChecked == 0"> and pr.id IS NULL</if>
<if test="eweManageTags != null and eweManageTags != ''">
and (
ewe_view.bs_manage_tags like concat('%', #{eweManageTags}, '%')
OR br.donor_ewe_no like concat('%', #{eweManageTags}, '%') -- Also search donor
)
</if>
<if test="ramManageTags != null and ramManageTags != ''">
and (
ram_view.bs_manage_tags like concat('%', #{ramManageTags}, '%')
OR br.donor_ram like concat('%', #{ramManageTags}, '%') -- Also search donor
)
</if>
<if test="frozenSemenNo != null and frozenSemenNo != ''"> and br.frozen_sperm_no like concat('%', #{frozenSemenNo}, '%')</if>
</where>
order by br.create_time desc
</select>
@@ -334,6 +445,29 @@
limit 1
</select>
<!-- <insert id="insertScBreedRecord" parameterType="ScBreedRecord" useGeneratedKeys="true" keyProperty="id">-->
<!-- insert into sc_breed_record-->
<!-- <trim prefix="(" suffix=")" suffixOverrides=",">-->
<!-- <if test="sheepId != null">sheep_id,</if>-->
<!-- <if test="ramId != null">ram_id,</if>-->
<!-- <if test="eweId != null">ewe_id,</if>-->
<!-- <if test="technician != null">technician,</if>-->
<!-- <if test="breedDrugs != null">breed_drugs,</if>-->
<!-- <if test="breedType != null">breed_type,</if>-->
<!-- <if test="createBy != null">create_by,</if>-->
<!-- <if test="createTime != null">create_time,</if>-->
<!-- </trim>-->
<!-- <trim prefix="values (" suffix=")" suffixOverrides=",">-->
<!-- <if test="sheepId != null">#{sheepId},</if>-->
<!-- <if test="ramId != null">#{ramId},</if>-->
<!-- <if test="eweId != null">#{eweId},</if>-->
<!-- <if test="technician != null">#{technician},</if>-->
<!-- <if test="breedDrugs != null">#{breedDrugs},</if>-->
<!-- <if test="breedType != null">#{breedType},</if>-->
<!-- <if test="createBy != null">#{createBy},</if>-->
<!-- <if test="createTime != null">#{createTime},</if>-->
<!-- </trim>-->
<!-- </insert>-->
<insert id="insertScBreedRecord" parameterType="ScBreedRecord" useGeneratedKeys="true" keyProperty="id">
insert into sc_breed_record
<trim prefix="(" suffix=")" suffixOverrides=",">
@@ -343,8 +477,13 @@
<if test="technician != null">technician,</if>
<if test="breedDrugs != null">breed_drugs,</if>
<if test="breedType != null">breed_type,</if>
<if test="frozenSemenNo != null">frozen_semen_no,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="comment != null">comment,</if>
<if test="embryoCount != null">embryo_count,</if>
<if test="donorEweNo != null">donor_ewe,</if>
<if test="donorRamNo != null">donor_ram,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="sheepId != null">#{sheepId},</if>
@@ -353,11 +492,31 @@
<if test="technician != null">#{technician},</if>
<if test="breedDrugs != null">#{breedDrugs},</if>
<if test="breedType != null">#{breedType},</if>
<if test="frozenSemenNo != null">#{frozenSemenNo},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="comment != null">#{comment},</if>
<if test="embryoCount != null">#{embryoCount},</if>
<if test="donorEweNo != null">#{donorEweNo},</if>
<if test="donorRamNo != null">#{donorRamNo},</if>
<if test="embryoSubType != null">#{embryoSubType},</if>
</trim>
</insert>
<!-- <update id="updateScBreedRecord" parameterType="ScBreedRecord">-->
<!-- update sc_breed_record-->
<!-- <trim prefix="SET" suffixOverrides=",">-->
<!-- <if test="sheepId != null">sheep_id = #{sheepId},</if>-->
<!-- <if test="ramId != null">ram_id = #{ramId},</if>-->
<!-- <if test="eweId != null">ewe_id = #{eweId},</if>-->
<!-- <if test="technician != null">technician = #{technician},</if>-->
<!-- <if test="breedDrugs != null">breed_drugs = #{breedDrugs},</if>-->
<!-- <if test="breedType != null">breed_type = #{breedType},</if>-->
<!-- <if test="createBy != null">create_by = #{createBy},</if>-->
<!-- <if test="createTime != null">create_time = #{createTime},</if>-->
<!-- </trim>-->
<!-- where id = #{id}-->
<!-- </update>-->
<update id="updateScBreedRecord" parameterType="ScBreedRecord">
update sc_breed_record
<trim prefix="SET" suffixOverrides=",">
@@ -367,12 +526,34 @@
<if test="technician != null">technician = #{technician},</if>
<if test="breedDrugs != null">breed_drugs = #{breedDrugs},</if>
<if test="breedType != null">breed_type = #{breedType},</if>
<if test="frozenSemenNo != null">frozen_semen_no = #{frozenSemenNo},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="comment != null">comment = #{comment},</if>
<if test="embryoCount != null">embryo_count = #{embryoCount},</if>
<if test="donorEweNo != null">donor_ewe = #{donorEweNo},</if>
<if test="donorRamNo != null">donor_ram = #{donorRamNo},</if>
</trim>
where id = #{id}
</update>
<select id="getFlushRecordByEweNo" parameterType="String" resultType="map">
SELECT
transferred,
donor_female_no,
donor_male_no,
embryo_type,
storage_method
FROM sc_embryo_flush
WHERE id = (
-- Assuming linking via recipient tags is complicated,
-- usually this is done by matching a recent flush record
-- For now, this mimics the logic in your ServiceImpl
SELECT id FROM sc_embryo_flush WHERE recipient_list LIKE concat('%', #{manageTags}, '%')
ORDER BY created_at DESC LIMIT 1
)
-- Note: If your sc_embryo_flush structure is different (one row per recipient), adjust accordingly.
-- Based on provided file, it has `recipient_cnt`.
</select>
<delete id="deleteScBreedRecordById" parameterType="Long">
delete from sc_breed_record where id = #{id}
</delete>

View File

@@ -29,7 +29,7 @@
<result property="matingDate" column="mating_date" />
<result property="expectedDate" column="expected_date" />
<result property="lastEventDate" column="last_event_date" />
<result property="ranchName" column="ranch" />
<result property="ranchName" column="sysRanch" />
<result property="daysAfterMating" column="days_after_mating" />
</resultMap>
@@ -54,7 +54,7 @@
sf.breed,
sf.expected_date,
sf.lambing_date as last_event_date,
sf.dr_ranch as ranch,
sf.dr_ranch as sysRanch,
-- 关联配种信息
ram_sf.bs_manage_tags as father_manage_tags,
ram_sf.variety as father_variety,

View File

@@ -1,7 +1,9 @@
package com.zhyc.system.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.zhyc.common.core.domain.entity.SysRanch;
import org.apache.ibatis.annotations.*;
import com.zhyc.common.core.domain.entity.SysDept;
/**
@@ -13,7 +15,7 @@ public interface SysDeptMapper
{
/**
* 查询部门管理数据
*
*
* @param dept 部门信息
* @return 部门信息集合
*/
@@ -21,7 +23,7 @@ public interface SysDeptMapper
/**
* 根据角色ID查询部门树信息
*
*
* @param roleId 角色ID
* @param deptCheckStrictly 部门树选择项是否关联显示
* @return 选中部门列表
@@ -30,7 +32,7 @@ public interface SysDeptMapper
/**
* 根据部门ID查询信息
*
*
* @param deptId 部门ID
* @return 部门信息
*/
@@ -38,7 +40,7 @@ public interface SysDeptMapper
/**
* 根据ID查询所有子部门
*
*
* @param deptId 部门ID
* @return 部门列表
*/
@@ -46,7 +48,7 @@ public interface SysDeptMapper
/**
* 根据ID查询所有子部门正常状态
*
*
* @param deptId 部门ID
* @return 子部门数
*/
@@ -54,7 +56,7 @@ public interface SysDeptMapper
/**
* 是否存在子节点
*
*
* @param deptId 部门ID
* @return 结果
*/
@@ -62,7 +64,7 @@ public interface SysDeptMapper
/**
* 查询部门是否存在用户
*
*
* @param deptId 部门ID
* @return 结果
*/
@@ -70,7 +72,7 @@ public interface SysDeptMapper
/**
* 校验部门名称是否唯一
*
*
* @param deptName 部门名称
* @param parentId 父部门ID
* @return 结果
@@ -79,7 +81,7 @@ public interface SysDeptMapper
/**
* 新增部门信息
*
*
* @param dept 部门信息
* @return 结果
*/
@@ -87,7 +89,7 @@ public interface SysDeptMapper
/**
* 修改部门信息
*
*
* @param dept 部门信息
* @return 结果
*/
@@ -95,14 +97,14 @@ public interface SysDeptMapper
/**
* 修改所在部门正常状态
*
*
* @param deptIds 部门ID组
*/
public void updateDeptStatusNormal(Long[] deptIds);
/**
* 修改子元素关系
*
*
* @param depts 子元素
* @return 结果
*/
@@ -110,9 +112,27 @@ public interface SysDeptMapper
/**
* 删除部门管理信息
*
*
* @param deptId 部门ID
* @return 结果
*/
public int deleteDeptById(Long deptId);
@Insert("insert into da_ranch(ranch) values(#{ranch})")
@Options(useGeneratedKeys = true, keyProperty = "id")
public void insertRanch(SysRanch r);
@Insert("insert into sys_dept_ranch(dept_id,ranch_id) values(#{deptId},#{ranchId})")
void insertRanchDept(@Param("deptId") Long deptId, @Param("ranchId")Long ranchId);
@Select("select * from da_ranch where ranch = #{ranchName}")
SysRanch checkRanchExist(String ranchName);
@Select("select ranch_id from sys_dept_ranch where dept_id = #{deptId}")
Long selectSysRanchDeptById(@Param("deptId") Long deptId);
@Delete("delete from sys_dept_ranch where dept_id=#{deptId}")
void deleteSysRanchDeptById(Long deptId);
@Delete("delete from da_ranch where id= #{ranchId}")
void deleteRanchById(Long ranchId);
}

View File

@@ -91,6 +91,8 @@ public interface ISysDeptService
*/
public boolean checkDeptNameUnique(SysDept dept);
boolean checkRanchName(SysDept dept);
/**
* 校验部门是否有数据权限
*
@@ -121,4 +123,6 @@ public interface ISysDeptService
* @return 结果
*/
public int deleteDeptById(Long deptId);
}

View File

@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import com.zhyc.common.core.domain.entity.SysRanch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhyc.common.annotation.DataScope;
@@ -20,6 +22,7 @@ import com.zhyc.common.utils.spring.SpringUtils;
import com.zhyc.system.mapper.SysDeptMapper;
import com.zhyc.system.mapper.SysRoleMapper;
import com.zhyc.system.service.ISysDeptService;
import org.springframework.transaction.annotation.Transactional;
/**
* 部门管理 服务实现
@@ -182,6 +185,18 @@ public class SysDeptServiceImpl implements ISysDeptService
return UserConstants.UNIQUE;
}
@Override
public boolean checkRanchName(SysDept dept) {
if (!StringUtils.isNull(dept.getRanchName())){
SysRanch ranch = deptMapper.checkRanchExist(dept.getRanchName());
if (ranch!=null){
return false;
}
}
return true;
}
/**
* 校验部门是否有数据权限
*
@@ -209,6 +224,7 @@ public class SysDeptServiceImpl implements ISysDeptService
* @return 结果
*/
@Override
@Transactional
public int insertDept(SysDept dept)
{
SysDept info = deptMapper.selectDeptById(dept.getParentId());
@@ -218,7 +234,15 @@ public class SysDeptServiceImpl implements ISysDeptService
throw new ServiceException("部门停用,不允许新增");
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return deptMapper.insertDept(dept);
int i = deptMapper.insertDept(dept);
if (dept.getRanchName()!=null){
SysRanch sysRanch = new SysRanch();
sysRanch.setRanch(dept.getRanchName());
deptMapper.insertRanch(sysRanch);
deptMapper.insertRanchDept(dept.getDeptId(), sysRanch.getId());
}
return i;
}
/**
@@ -290,6 +314,9 @@ public class SysDeptServiceImpl implements ISysDeptService
@Override
public int deleteDeptById(Long deptId)
{
Long ranchId=deptMapper.selectSysRanchDeptById(deptId);
deptMapper.deleteSysRanchDeptById(deptId);
deptMapper.deleteRanchById(ranchId);
return deptMapper.deleteDeptById(deptId);
}

View File

@@ -20,13 +20,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="ranchName" column="ranch_name"/>
</resultMap>
<!-- 基础字段添加牧场信息 -->
<sql id="selectDeptVo">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
from sys_dept d
</sql>
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num,
d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by,
d.create_time, d.update_by, d.update_time,
r.ranch ranch_name
from sys_dept d
left join sys_dept_ranch dr on d.dept_id = dr.dept_id
left join da_ranch r on dr.ranch_id = r.id
</sql>
<select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where d.del_flag = '0'
@@ -86,8 +95,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDeptVo"/>
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
</select>
<insert id="insertDept" parameterType="SysDept">
<insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
insert into sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="parentId != null and parentId != 0">parent_id,</if>