diff --git a/shuili-admin/src/main/java/com/kms/web/controller/system/SysDeptController.java b/shuili-admin/src/main/java/com/kms/web/controller/system/SysDeptController.java index 85d139d9..865d79c8 100644 --- a/shuili-admin/src/main/java/com/kms/web/controller/system/SysDeptController.java +++ b/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 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 depts = deptService.selectDeptList(new SysDept()); Iterator 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,10 +71,9 @@ public class SysDeptController extends BaseController @SaCheckLogin @GetMapping(value = "/{deptId}") @SaCheckPermission(value = "system:dept:query") - public AjaxResult getInfo(@PathVariable String deptId) - { - SysDept selectDeptById = deptService.get(deptId); - return AjaxResult.success(selectDeptById); + public AjaxResult getInfo(@PathVariable String deptId) { + SysDept selectDeptById = deptService.get(deptId); + return AjaxResult.success(selectDeptById); } /** @@ -86,15 +81,14 @@ 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"; AjaxResult ajax = AjaxResult.success(); ajax.put("logoUrl", uploadFile); return ajax; - } catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); return AjaxResult.error("上传图片异常,请联系管理员"); } @@ -104,8 +98,7 @@ public class SysDeptController extends BaseController * 获取部门下拉树列表 */ @GetMapping("/treeselect") - public AjaxResult treeselect(SysDept dept) - { + public AjaxResult treeselect(SysDept dept) { List 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 depts = deptService.selectDeptList(new SysDept()); AjaxResult ajax = AjaxResult.success(); ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); @@ -130,40 +122,33 @@ 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"); int i = deptService.insertDept(dept); - return toAjax(i>0); + return toAjax(i > 0); } /** - * 修改部门 + * 修改部门 */ @SaCheckLogin @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); + return toAjax(deptService.updateDept(dept) > 0); } /** @@ -173,17 +158,14 @@ 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); + return toAjax(deptService.deleteDeptById(deptId) > 0); } diff --git a/shuili-admin/src/main/java/com/kms/web/controller/system/SysXzqhController.java b/shuili-admin/src/main/java/com/kms/web/controller/system/SysXzqhController.java index 4af32287..52c4c4c9 100644 --- a/shuili-admin/src/main/java/com/kms/web/controller/system/SysXzqhController.java +++ b/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,10 +60,9 @@ public class SysXzqhController extends BaseController } - - @GetMapping("/common") - public AjaxResult common(){ + @ApiOperation("通用行政区划") + public AjaxResult common() { SysUser user = UserUtils.getUser(); String deptId = user.getDeptId(); SysDept sysDept = sysDeptService.getById(deptId); @@ -76,19 +72,20 @@ public class SysXzqhController extends BaseController /*if (userName.equals("admin")) { List 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 queryWrapper = new QueryWrapper<>(); queryWrapper.likeRight("XZQHDM", substring); List list = sysXzqhService.list(queryWrapper); return AjaxResult.success(list); - } else if (xzqh.getLayer()==2) { + } else if (xzqh.getLayer() == 2) { String substring = xzqh.getXzqhdm().substring(0, 4); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.likeRight("XZQHDM", substring); List list = sysXzqhService.list(queryWrapper); return AjaxResult.success(list); - }else { + } else { return AjaxResult.success(xzqh); } } @@ -98,8 +95,7 @@ public class SysXzqhController extends BaseController */ @PostMapping("/list") @ApiOperation("行政区划列表") - public IPage list(@RequestBody SearchParam sp) - { + public IPage list(@RequestBody SearchParam 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 list = sysXzqhService.listByIds(sysXzqh.getIds()); ExcelUtil 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)); } @@ -154,9 +146,8 @@ public class SysXzqhController extends BaseController */ @ApiOperation("行政区划删除") @Log(title = "行政区划删除", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable String[] ids) - { + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable String[] ids) { return toAjax(sysXzqhService.removeByIds(Arrays.asList(ids))); } } diff --git a/shuili-system/src/main/resources/mapper/system/SysDeptMapper.xml b/shuili-system/src/main/resources/mapper/system/SysDeptMapper.xml index 81287bed..e2e89cf6 100644 --- a/shuili-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/shuili-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -1,41 +1,41 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select d.id,d.ip_start,d.ip_end,d.is_download,d.is_comment, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,d.tag, d.del_flag, d.create_uid, d.create_time, d.name, d.pc_logo, d.pc_background, @@ -43,171 +43,173 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from sys_dept d - where d.del_flag = '0' - AND parent_id = #{parentId} - - - AND dept_name like concat('%', #{deptName}, '%') - - - AND dept_name =#{searchValue} - - - AND status = #{status} - - - ${params.dataScope} - order by d.parent_id, d.order_num + AND parent_id = #{parentId} + + + AND dept_name like concat('%', #{deptName}, '%') + + + AND dept_name =#{searchValue} + + + AND status = #{status} + + + ${params.dataScope} + order by d.parent_id, d.order_num + 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 + + + where id = #{id} + + select count(1) from sys_user where id = #{id} and del_flag = '0' + - + - + - + - + - insert into sys_dept( - id, - data_type, - begin_date, - end_date, - ip_end, - ip_start, - is_comment, - is_download, - parent_id, - dept_name, - ancestors, - order_num, - leader, - phone, - email, - status, - tag, - create_uid, - name, - pc_logo, - pc_background, - admin_name, - admin_logo, - xzqh_id, - create_time - )values( - #{id}, - #{dataType}, - #{beginDate}, - #{endDate}, - #{ipEnd}, - #{ipStart}, - #{isComment}, - #{isDownload}, - #{parentId}, - #{deptName}, - #{ancestors}, - #{orderNum}, - #{leader}, - #{phone}, - #{email}, - #{status}, - #{tag}, - #{createUid}, - #{name}, - #{pcLogo}, - #{pcBackground}, - #{adminName}, - #{adminLogo}, - #{xzqhId}, - sysdate() - ) - - - - update sys_dept - - parent_id = #{parentId}, - data_type = #{dataType},begin_date = #{beginDate},end_date = #{endDate}, - dept_name = #{deptName}, - is_comment = #{isComment}, - is_download = #{isDownload}, - ancestors = #{ancestors}, - order_num = #{orderNum}, - leader = #{leader}, - phone = #{phone}, - email = #{email}, - status = #{status}, - tag = #{tag}, - update_uid = #{updateUid}, - name = #{name}, - pc_logo = #{pcLogo}, - pc_background = #{pcBackground}, - admin_name = #{adminName}, - admin_logo = #{adminLogo}, - ip_end = #{ipEnd}, - ip_start = #{ipStart}, - update_time = sysdate() - - where id = #{id} - - - - update sys_dept set ancestors = - - when #{item.id} then #{item.ancestors} - - where id in - - #{item.id} - - - - - update sys_dept a - - a.status = #{status}, - a.update_uid = #{updateUid}, - a.update_time = sysdate() + insert into sys_dept( + id, + data_type, + begin_date, + end_date, + ip_end, + ip_start, + is_comment, + is_download, + parent_id, + dept_name, + ancestors, + order_num, + leader, + phone, + email, + status, + tag, + create_uid, + name, + pc_logo, + pc_background, + admin_name, + admin_logo, + xzqh_id, + create_time + )values( + #{id}, + #{dataType}, + #{beginDate}, + #{endDate}, + #{ipEnd}, + #{ipStart}, + #{isComment}, + #{isDownload}, + #{parentId}, + #{deptName}, + #{ancestors}, + #{orderNum}, + #{leader}, + #{phone}, + #{email}, + #{status}, + #{tag}, + #{createUid}, + #{name}, + #{pcLogo}, + #{pcBackground}, + #{adminName}, + #{adminLogo}, + #{xzqhId}, + sysdate() + ) + + + + update sys_dept + + parent_id = #{parentId}, + data_type = #{dataType},begin_date = #{beginDate},end_date = #{endDate}, + dept_name = #{deptName}, + is_comment = #{isComment}, + xzqh_id = #{xzqhId}, + is_download = #{isDownload}, + ancestors = #{ancestors}, + order_num = #{orderNum}, + leader = #{leader}, + phone = #{phone}, + email = #{email}, + status = #{status}, + tag = #{tag}, + update_uid = #{updateUid}, + name = #{name}, + pc_logo = #{pcLogo}, + pc_background = #{pcBackground}, + admin_name = #{adminName}, + admin_logo = #{adminLogo}, + ip_end = #{ipEnd}, + ip_start = #{ipStart}, + update_time = sysdate() + + where id = #{id} + + + + update sys_dept set ancestors = + + when #{item.id} then #{item.ancestors} + + where id in + + #{item.id} + + + + + update sys_dept a + + a.status = #{status}, + a.update_uid = #{updateUid}, + a.update_time = sysdate() - where FIND_IN_SET(a.id,#{ancestors}) - + where FIND_IN_SET(a.id,#{ancestors}) + - - delete from sys_dept where id = #{id} - + + delete from sys_dept where id = #{id} +