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);
|
List<SysDept> selectDeptDtoList(String delFlag);
|
||||||
|
|
||||||
/**
|
|
||||||
* 维护部门关系表
|
|
||||||
*
|
|
||||||
* @param deptRelation 部门关系
|
|
||||||
* @return 成功、失败
|
|
||||||
*/
|
|
||||||
void insertDeptRelation(SysDeptRelation deptRelation);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除部门关系表数据
|
* 删除部门关系表数据
|
||||||
* @param id 部门ID
|
* @param id 部门ID
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||||
import com.github.pig.admin.common.util.TreeUtil;
|
import com.github.pig.admin.common.util.TreeUtil;
|
||||||
import com.github.pig.admin.mapper.SysDeptMapper;
|
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.dto.DeptTree;
|
||||||
import com.github.pig.admin.model.entity.SysDept;
|
import com.github.pig.admin.model.entity.SysDept;
|
||||||
import com.github.pig.admin.model.entity.SysDeptRelation;
|
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 {
|
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysDeptMapper sysDeptMapper;
|
private SysDeptMapper sysDeptMapper;
|
||||||
|
@Autowired
|
||||||
|
private SysDeptRelationMapper sysDeptRelationMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加信息部门
|
* 添加信息部门
|
||||||
|
@ -41,12 +44,28 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||||
SysDept sysDept = new SysDept();
|
SysDept sysDept = new SysDept();
|
||||||
BeanUtils.copyProperties(dept, sysDept);
|
BeanUtils.copyProperties(dept, sysDept);
|
||||||
this.insert(sysDept);
|
this.insert(sysDept);
|
||||||
|
this.insertDeptRelation(sysDept);
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 维护部门关系
|
||||||
|
* @param sysDept 部门
|
||||||
|
*/
|
||||||
|
private void insertDeptRelation(SysDept sysDept) {
|
||||||
//增加部门关系表
|
//增加部门关系表
|
||||||
SysDeptRelation deptRelation = new SysDeptRelation();
|
SysDeptRelation deptRelation = new SysDeptRelation();
|
||||||
deptRelation.setAncestor(dept.getParentId());
|
deptRelation.setDescendant(sysDept.getParentId());
|
||||||
deptRelation.setDescendant(sysDept.getDeptId());
|
List<SysDeptRelation> deptRelationList = sysDeptRelationMapper.selectList(new EntityWrapper<>(deptRelation));
|
||||||
sysDeptMapper.insertDeptRelation(deptRelation);
|
for (SysDeptRelation sysDeptRelation : deptRelationList) {
|
||||||
return Boolean.TRUE;
|
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());
|
sysDeptMapper.deleteDeptRealtion(sysDept.getDeptId());
|
||||||
//新建部门关系
|
//新建部门关系
|
||||||
SysDeptRelation deptRelation = new SysDeptRelation();
|
this.insertDeptRelation(sysDept);
|
||||||
deptRelation.setAncestor(sysDept.getParentId());
|
|
||||||
deptRelation.setDescendant(sysDept.getDeptId());
|
|
||||||
sysDeptMapper.insertDeptRelation(deptRelation);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,19 +45,4 @@
|
||||||
LEFT JOIN sys_dept_relation dr ON t.dept_id = dr.descendant
|
LEFT JOIN sys_dept_relation dr ON t.dept_id = dr.descendant
|
||||||
WHERE dr.ancestor = 0
|
WHERE dr.ancestor = 0
|
||||||
</select>
|
</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>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue