Browse Source

fix: 修复部门行政规划不能修改问题

master_tdsql
hxh 9 months ago
parent
commit
7999eea7aa
  1. 60
      shuili-admin/src/main/java/com/kms/web/controller/system/SysDeptController.java
  2. 29
      shuili-admin/src/main/java/com/kms/web/controller/system/SysXzqhController.java
  3. 4
      shuili-system/src/main/resources/mapper/system/SysDeptMapper.xml

60
shuili-admin/src/main/java/com/kms/web/controller/system/SysDeptController.java

@ -11,6 +11,7 @@ import com.shuili.common.core.domain.entity.SysDept;
import com.shuili.common.enums.BusinessType;
import com.shuili.common.utils.FastDfsUtil;
import com.shuili.common.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
@ -27,8 +28,7 @@ import java.util.List;
*/
@RestController
@RequestMapping("/system/dept")
public class SysDeptController extends BaseController
{
public class SysDeptController extends BaseController {
@Autowired
private SysDeptService deptService;
@ -41,8 +41,7 @@ public class SysDeptController extends BaseController
@SaCheckLogin
@GetMapping("/list")
@SaCheckPermission(value = "system:dept:list")
public AjaxResult list(SysDept dept)
{
public AjaxResult list(SysDept dept) {
List<SysDept> depts = deptService.selectDeptList(dept);
return AjaxResult.success(depts);
}
@ -53,16 +52,13 @@ public class SysDeptController extends BaseController
@SaCheckLogin
@GetMapping("/list/exclude/{deptId}")
@SaCheckPermission(value = "system:dept:list")
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) String deptId)
{
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) String deptId) {
List<SysDept> depts = deptService.selectDeptList(new SysDept());
Iterator<SysDept> it = depts.iterator();
while (it.hasNext())
{
while (it.hasNext()) {
SysDept d = (SysDept) it.next();
if (d.getId().equals(deptId)
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
{
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")) {
it.remove();
}
}
@ -75,8 +71,7 @@ public class SysDeptController extends BaseController
@SaCheckLogin
@GetMapping(value = "/{deptId}")
@SaCheckPermission(value = "system:dept:query")
public AjaxResult getInfo(@PathVariable String deptId)
{
public AjaxResult getInfo(@PathVariable String deptId) {
SysDept selectDeptById = deptService.get(deptId);
return AjaxResult.success(selectDeptById);
}
@ -86,8 +81,7 @@ public class SysDeptController extends BaseController
*/
@SaCheckLogin
@PostMapping("/uploadLogo")
public AjaxResult uploadLogo(@RequestParam("avatarfile") MultipartFile file)
{
public AjaxResult uploadLogo(@RequestParam("avatarfile") MultipartFile file) {
try {
String uploadFile = fastUtil.uploadFile(file);
// String uploadFile = "group1/M00/05/27/wKgBFGCvaeiAPWu5AADSPy2Q2g0276.jpg";
@ -104,8 +98,7 @@ public class SysDeptController extends BaseController
* 获取部门下拉树列表
*/
@GetMapping("/treeselect")
public AjaxResult treeselect(SysDept dept)
{
public AjaxResult treeselect(SysDept dept) {
List<SysDept> depts = deptService.selectDeptList(dept);
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
}
@ -114,8 +107,7 @@ public class SysDeptController extends BaseController
* 加载对应角色部门列表树
*/
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") String roleId)
{
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") String roleId) {
List<SysDept> depts = deptService.selectDeptList(new SysDept());
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
@ -130,10 +122,8 @@ public class SysDeptController extends BaseController
@Log(title = "部门管理", businessType = BusinessType.INSERT)
@SaCheckPermission(value = "system:dept:add")
@PostMapping
public AjaxResult add(@Validated @RequestBody SysDept dept)
{
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
public AjaxResult add(@Validated @RequestBody SysDept dept) {
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
dept.setParentId("100");
@ -148,19 +138,14 @@ public class SysDeptController extends BaseController
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
@SaCheckPermission(value = "system:dept:edit")
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysDept dept)
{
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
@ApiOperation("部门修改")
public AjaxResult edit(@Validated @RequestBody SysDept dept) {
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
else if (dept.getParentId().equals(dept.getId()))
{
} else if (dept.getParentId().equals(dept.getId())) {
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
}
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
&& deptService.selectNormalChildrenDeptById(dept.getId()) > 0)
{
} else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
&& deptService.selectNormalChildrenDeptById(dept.getId()) > 0) {
return AjaxResult.error("该部门包含未停用的子部门!");
}
return toAjax(deptService.updateDept(dept) > 0);
@ -173,14 +158,11 @@ public class SysDeptController extends BaseController
@Log(title = "部门管理", businessType = BusinessType.DELETE)
@SaCheckPermission(value = "system:dept:remove")
@DeleteMapping("/{deptId}")
public AjaxResult remove(@PathVariable String deptId)
{
if (deptService.hasChildByDeptId(deptId))
{
public AjaxResult remove(@PathVariable String deptId) {
if (deptService.hasChildByDeptId(deptId)) {
return AjaxResult.error("存在下级部门,不允许删除");
}
if (deptService.checkDeptExistUser(deptId))
{
if (deptService.checkDeptExistUser(deptId)) {
return AjaxResult.error("部门存在用户,不允许删除");
}
return toAjax(deptService.deleteDeptById(deptId) > 0);

29
shuili-admin/src/main/java/com/kms/web/controller/system/SysXzqhController.java

@ -25,8 +25,6 @@ import java.util.Arrays;
import java.util.List;
/**
* 行政区划Controller
*
@ -36,8 +34,7 @@ import java.util.List;
@RestController
@RequestMapping("/xzqh/xzqh")
@Api(tags = "行政区划")
public class SysXzqhController extends BaseController
{
public class SysXzqhController extends BaseController {
@Autowired
private SysXzqhService sysXzqhService;
@ -63,9 +60,8 @@ public class SysXzqhController extends BaseController
}
@GetMapping("/common")
@ApiOperation("通用行政区划")
public AjaxResult common() {
SysUser user = UserUtils.getUser();
String deptId = user.getDeptId();
@ -76,7 +72,8 @@ public class SysXzqhController extends BaseController
/*if (userName.equals("admin")) {
List<SysXzqh> list = sysXzqhService.list();
return AjaxResult.success(list);
}else */if (xzqh.getLayer()==1) {
}else */
if (xzqh.getLayer() == 1) {
String substring = xzqh.getXzqhdm().substring(0, 2);
QueryWrapper<SysXzqh> queryWrapper = new QueryWrapper<>();
queryWrapper.likeRight("XZQHDM", substring);
@ -98,8 +95,7 @@ public class SysXzqhController extends BaseController
*/
@PostMapping("/list")
@ApiOperation("行政区划列表")
public IPage list(@RequestBody SearchParam<SysXzqh> sp)
{
public IPage list(@RequestBody SearchParam<SysXzqh> sp) {
return sysXzqhService.selectPage(sp);
}
@ -109,8 +105,7 @@ public class SysXzqhController extends BaseController
@Log(title = "行政区划导出", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ApiOperation("行政区划导出")
public AjaxResult export(@RequestBody SysXzqh sysXzqh)
{
public AjaxResult export(@RequestBody SysXzqh sysXzqh) {
List<SysXzqh> list = sysXzqhService.listByIds(sysXzqh.getIds());
ExcelUtil<SysXzqh> util = new ExcelUtil<>(SysXzqh.class);
return util.exportExcel(list, "xzqh");
@ -121,8 +116,7 @@ public class SysXzqhController extends BaseController
*/
@ApiOperation(" 行政区划详情")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id)
{
public AjaxResult getInfo(@PathVariable("id") String id) {
return AjaxResult.success(sysXzqhService.getById(id));
}
@ -132,8 +126,7 @@ public class SysXzqhController extends BaseController
@Log(title = "行政区划新增", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("行政区划新增")
public AjaxResult add(@RequestBody SysXzqh sysXzqh)
{
public AjaxResult add(@RequestBody SysXzqh sysXzqh) {
BaseEntityUtils.preInsert(sysXzqh);
return toAjax(sysXzqhService.save(sysXzqh));
}
@ -144,8 +137,7 @@ public class SysXzqhController extends BaseController
@ApiOperation("行政区划修改")
@Log(title = "行政区划修改", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SysXzqh sysXzqh)
{
public AjaxResult edit(@RequestBody SysXzqh sysXzqh) {
return toAjax(sysXzqhService.updateById(sysXzqh));
}
@ -155,8 +147,7 @@ public class SysXzqhController extends BaseController
@ApiOperation("行政区划删除")
@Log(title = "行政区划删除", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable String[] ids)
{
public AjaxResult remove(@PathVariable String[] ids) {
return toAjax(sysXzqhService.removeByIds(Arrays.asList(ids)));
}
}

4
shuili-system/src/main/resources/mapper/system/SysDeptMapper.xml

@ -68,7 +68,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from sys_dept d
left join sys_role_dept rd on d.id = rd.dept_id
where rd.role_id = #{roleId}
and d.id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.id = rd.dept_id and rd.role_id = #{roleId})
and d.id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.id = rd.dept_id and
rd.role_id = #{roleId})
order by d.parent_id, d.order_num
</select>
@ -162,6 +163,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
data_type = #{dataType},begin_date = #{beginDate},end_date = #{endDate},
<if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
<if test="isComment != null and isComment != ''">is_comment = #{isComment},</if>
<if test="xzqhId != null and xzqhId != ''">xzqh_id = #{xzqhId},</if>
<if test="isDownload != null and isDownload != ''">is_download = #{isDownload},</if>
<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
<if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>

Loading…
Cancel
Save