牧场跟跟部门绑定

This commit is contained in:
2026-01-30 15:50:23 +08:00
parent 086cb43359
commit f0acd149c7
9 changed files with 150 additions and 30 deletions

View File

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

View File

@@ -31,6 +31,10 @@ public class SysDept extends BaseEntity
/** 部门名称 */ /** 部门名称 */
private String deptName; private String deptName;
/** 牧场id */
private Long ranchId;
private String ranchName;
/** 显示顺序 */ /** 显示顺序 */
private Integer orderNum; private Integer orderNum;
@@ -55,6 +59,22 @@ public class SysDept extends BaseEntity
/** 子部门 */ /** 子部门 */
private List<SysDept> children = new ArrayList<SysDept>(); 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() public Long getDeptId()
{ {
return deptId; 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

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

View File

@@ -29,7 +29,7 @@
<result property="matingDate" column="mating_date" /> <result property="matingDate" column="mating_date" />
<result property="expectedDate" column="expected_date" /> <result property="expectedDate" column="expected_date" />
<result property="lastEventDate" column="last_event_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" /> <result property="daysAfterMating" column="days_after_mating" />
</resultMap> </resultMap>
@@ -54,7 +54,7 @@
sf.breed, sf.breed,
sf.expected_date, sf.expected_date,
sf.lambing_date as last_event_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.bs_manage_tags as father_manage_tags,
ram_sf.variety as father_variety, ram_sf.variety as father_variety,

View File

@@ -1,7 +1,9 @@
package com.zhyc.system.mapper; package com.zhyc.system.mapper;
import java.util.List; 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; import com.zhyc.common.core.domain.entity.SysDept;
/** /**
@@ -13,7 +15,7 @@ public interface SysDeptMapper
{ {
/** /**
* 查询部门管理数据 * 查询部门管理数据
* *
* @param dept 部门信息 * @param dept 部门信息
* @return 部门信息集合 * @return 部门信息集合
*/ */
@@ -21,7 +23,7 @@ public interface SysDeptMapper
/** /**
* 根据角色ID查询部门树信息 * 根据角色ID查询部门树信息
* *
* @param roleId 角色ID * @param roleId 角色ID
* @param deptCheckStrictly 部门树选择项是否关联显示 * @param deptCheckStrictly 部门树选择项是否关联显示
* @return 选中部门列表 * @return 选中部门列表
@@ -30,7 +32,7 @@ public interface SysDeptMapper
/** /**
* 根据部门ID查询信息 * 根据部门ID查询信息
* *
* @param deptId 部门ID * @param deptId 部门ID
* @return 部门信息 * @return 部门信息
*/ */
@@ -38,7 +40,7 @@ public interface SysDeptMapper
/** /**
* 根据ID查询所有子部门 * 根据ID查询所有子部门
* *
* @param deptId 部门ID * @param deptId 部门ID
* @return 部门列表 * @return 部门列表
*/ */
@@ -46,7 +48,7 @@ public interface SysDeptMapper
/** /**
* 根据ID查询所有子部门正常状态 * 根据ID查询所有子部门正常状态
* *
* @param deptId 部门ID * @param deptId 部门ID
* @return 子部门数 * @return 子部门数
*/ */
@@ -54,7 +56,7 @@ public interface SysDeptMapper
/** /**
* 是否存在子节点 * 是否存在子节点
* *
* @param deptId 部门ID * @param deptId 部门ID
* @return 结果 * @return 结果
*/ */
@@ -62,7 +64,7 @@ public interface SysDeptMapper
/** /**
* 查询部门是否存在用户 * 查询部门是否存在用户
* *
* @param deptId 部门ID * @param deptId 部门ID
* @return 结果 * @return 结果
*/ */
@@ -70,7 +72,7 @@ public interface SysDeptMapper
/** /**
* 校验部门名称是否唯一 * 校验部门名称是否唯一
* *
* @param deptName 部门名称 * @param deptName 部门名称
* @param parentId 父部门ID * @param parentId 父部门ID
* @return 结果 * @return 结果
@@ -79,7 +81,7 @@ public interface SysDeptMapper
/** /**
* 新增部门信息 * 新增部门信息
* *
* @param dept 部门信息 * @param dept 部门信息
* @return 结果 * @return 结果
*/ */
@@ -87,7 +89,7 @@ public interface SysDeptMapper
/** /**
* 修改部门信息 * 修改部门信息
* *
* @param dept 部门信息 * @param dept 部门信息
* @return 结果 * @return 结果
*/ */
@@ -95,14 +97,14 @@ public interface SysDeptMapper
/** /**
* 修改所在部门正常状态 * 修改所在部门正常状态
* *
* @param deptIds 部门ID组 * @param deptIds 部门ID组
*/ */
public void updateDeptStatusNormal(Long[] deptIds); public void updateDeptStatusNormal(Long[] deptIds);
/** /**
* 修改子元素关系 * 修改子元素关系
* *
* @param depts 子元素 * @param depts 子元素
* @return 结果 * @return 结果
*/ */
@@ -110,9 +112,27 @@ public interface SysDeptMapper
/** /**
* 删除部门管理信息 * 删除部门管理信息
* *
* @param deptId 部门ID * @param deptId 部门ID
* @return 结果 * @return 结果
*/ */
public int deleteDeptById(Long deptId); 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); public boolean checkDeptNameUnique(SysDept dept);
boolean checkRanchName(SysDept dept);
/** /**
* 校验部门是否有数据权限 * 校验部门是否有数据权限
* *
@@ -121,4 +123,6 @@ public interface ISysDeptService
* @return 结果 * @return 结果
*/ */
public int deleteDeptById(Long deptId); public int deleteDeptById(Long deptId);
} }

View File

@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.zhyc.common.core.domain.entity.SysRanch;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.zhyc.common.annotation.DataScope; 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.SysDeptMapper;
import com.zhyc.system.mapper.SysRoleMapper; import com.zhyc.system.mapper.SysRoleMapper;
import com.zhyc.system.service.ISysDeptService; import com.zhyc.system.service.ISysDeptService;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 部门管理 服务实现 * 部门管理 服务实现
@@ -182,6 +185,18 @@ public class SysDeptServiceImpl implements ISysDeptService
return UserConstants.UNIQUE; 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 结果 * @return 结果
*/ */
@Override @Override
@Transactional
public int insertDept(SysDept dept) public int insertDept(SysDept dept)
{ {
SysDept info = deptMapper.selectDeptById(dept.getParentId()); SysDept info = deptMapper.selectDeptById(dept.getParentId());
@@ -218,7 +234,15 @@ public class SysDeptServiceImpl implements ISysDeptService
throw new ServiceException("部门停用,不允许新增"); throw new ServiceException("部门停用,不允许新增");
} }
dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); 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 @Override
public int deleteDeptById(Long deptId) public int deleteDeptById(Long deptId)
{ {
Long ranchId=deptMapper.selectSysRanchDeptById(deptId);
deptMapper.deleteSysRanchDeptById(deptId);
deptMapper.deleteRanchById(ranchId);
return deptMapper.deleteDeptById(deptId); 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="createTime" column="create_time" />
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="ranchName" column="ranch_name"/>
</resultMap> </resultMap>
<!-- 基础字段添加牧场信息 -->
<sql id="selectDeptVo"> <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 select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num,
from sys_dept d d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by,
</sql> 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"> <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
<include refid="selectDeptVo"/> <include refid="selectDeptVo"/>
where d.del_flag = '0' where d.del_flag = '0'
@@ -86,8 +95,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDeptVo"/> <include refid="selectDeptVo"/>
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1 where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
</select> </select>
<insert id="insertDept" parameterType="SysDept">
<insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
insert into sys_dept( insert into sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if> <if test="deptId != null and deptId != 0">dept_id,</if>
<if test="parentId != null and parentId != 0">parent_id,</if> <if test="parentId != null and parentId != 0">parent_id,</if>