牧场跟跟部门绑定
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user