mirror of https://gitee.com/maxjhandsome/pig
fixed: sharding-jdbc 不支持INSERT SELECT 语法
This commit is contained in:
parent
ed5afa1a71
commit
3321330d15
|
@ -24,14 +24,6 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
|||
*/
|
||||
List<SysDept> selectDeptDtoList(String delFlag);
|
||||
|
||||
/**
|
||||
* 维护部门关系表
|
||||
*
|
||||
* @param deptRelation 部门关系
|
||||
* @return 成功、失败
|
||||
*/
|
||||
void insertDeptRelation(SysDeptRelation deptRelation);
|
||||
|
||||
/**
|
||||
* 删除部门关系表数据
|
||||
* @param id 部门ID
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.github.pig.admin.common.util.TreeUtil;
|
||||
import com.github.pig.admin.mapper.SysDeptMapper;
|
||||
import com.github.pig.admin.mapper.SysDeptRelationMapper;
|
||||
import com.github.pig.admin.model.dto.DeptTree;
|
||||
import com.github.pig.admin.model.entity.SysDept;
|
||||
import com.github.pig.admin.model.entity.SysDeptRelation;
|
||||
|
@ -29,6 +30,8 @@ import java.util.List;
|
|||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
|
||||
@Autowired
|
||||
private SysDeptMapper sysDeptMapper;
|
||||
@Autowired
|
||||
private SysDeptRelationMapper sysDeptRelationMapper;
|
||||
|
||||
/**
|
||||
* 添加信息部门
|
||||
|
@ -41,12 +44,28 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||
SysDept sysDept = new SysDept();
|
||||
BeanUtils.copyProperties(dept, sysDept);
|
||||
this.insert(sysDept);
|
||||
this.insertDeptRelation(sysDept);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 维护部门关系
|
||||
* @param sysDept 部门
|
||||
*/
|
||||
private void insertDeptRelation(SysDept sysDept) {
|
||||
//增加部门关系表
|
||||
SysDeptRelation deptRelation = new SysDeptRelation();
|
||||
deptRelation.setAncestor(dept.getParentId());
|
||||
deptRelation.setDescendant(sysDept.getDeptId());
|
||||
sysDeptMapper.insertDeptRelation(deptRelation);
|
||||
return Boolean.TRUE;
|
||||
deptRelation.setDescendant(sysDept.getParentId());
|
||||
List<SysDeptRelation> deptRelationList = sysDeptRelationMapper.selectList(new EntityWrapper<>(deptRelation));
|
||||
for (SysDeptRelation sysDeptRelation : deptRelationList) {
|
||||
sysDeptRelation.setDescendant(sysDept.getDeptId());
|
||||
sysDeptRelationMapper.insert(sysDeptRelation);
|
||||
}
|
||||
//自己也要维护到关系表中
|
||||
SysDeptRelation own = new SysDeptRelation();
|
||||
own.setDescendant(sysDept.getDeptId());
|
||||
own.setAncestor(sysDept.getDeptId());
|
||||
sysDeptRelationMapper.insert(own);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,10 +98,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||
//删除部门关系
|
||||
sysDeptMapper.deleteDeptRealtion(sysDept.getDeptId());
|
||||
//新建部门关系
|
||||
SysDeptRelation deptRelation = new SysDeptRelation();
|
||||
deptRelation.setAncestor(sysDept.getParentId());
|
||||
deptRelation.setDescendant(sysDept.getDeptId());
|
||||
sysDeptMapper.insertDeptRelation(deptRelation);
|
||||
this.insertDeptRelation(sysDept);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,19 +45,4 @@
|
|||
LEFT JOIN sys_dept_relation dr ON t.dept_id = dr.descendant
|
||||
WHERE dr.ancestor = 0
|
||||
</select>
|
||||
|
||||
<!--维护部门关系-->
|
||||
<insert id="insertDeptRelation">
|
||||
INSERT INTO sys_dept_relation (ancestor, descendant) SELECT
|
||||
dt.ancestor,
|
||||
#{descendant}
|
||||
FROM
|
||||
sys_dept_relation dt
|
||||
WHERE
|
||||
dt.descendant = #{ancestor}
|
||||
UNION ALL
|
||||
SELECT
|
||||
#{descendant},
|
||||
#{descendant}
|
||||
</insert>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue