牧场跟跟部门绑定

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

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

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

@@ -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;
/**
@@ -115,4 +117,22 @@ public interface SysDeptMapper
* @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
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'
@@ -87,7 +96,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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>