部门管理

This commit is contained in:
TinyAnts 2022-06-07 11:11:59 +08:00
parent e4e040eb23
commit f36c8ac05d
12 changed files with 477 additions and 7 deletions

View File

@ -5,7 +5,7 @@
"dev": "vite",
"build": "vite build && ./release.sh",
"preview": "vite preview",
"lint": "eslint --fix --ext .ts,.tsx,.vue,.js,.jsx src/",
"lint": "eslint ./src/App.vue",
"prettier": "prettier --write src"
},
"dependencies": {

View File

@ -0,0 +1,89 @@
package com.hxkj.admin.controller.system;
import com.alibaba.fastjson.JSONArray;
import com.hxkj.admin.service.ISystemDeptService;
import com.hxkj.admin.validate.system.SystemDeptParam;
import com.hxkj.admin.vo.system.SystemDeptVo;
import com.hxkj.common.core.AjaxResult;
import com.hxkj.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
/**
* 系统部门管理
*/
@RestController
@RequestMapping("api/system/dept")
public class SystemDeptController {
@Resource
ISystemDeptService iSystemDeptService;
/**
* 部门列表
*
* @author fzr
* @return Object
*/
@GetMapping("/list")
public Object list(@RequestParam Map<String, String> params) {
JSONArray list = iSystemDeptService.lists(params);
return AjaxResult.success(list);
}
/**
* 部门详情
*
* @author fzr
* @param id 主键
* @return Object
*/
@GetMapping("/detail")
public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
SystemDeptVo vo = iSystemDeptService.detail(id);
return AjaxResult.success(vo);
}
/**
* 部门新增
*
* @author fzr
* @param systemDeptParam 参数
* @return Object
*/
@PostMapping("/add")
public Object add(@Validated(value = SystemDeptParam.create.class) @RequestBody SystemDeptParam systemDeptParam) {
iSystemDeptService.add(systemDeptParam);
return AjaxResult.success();
}
/**
* 部门编辑
*
* @author fzr
* @param systemDeptParam 参数
* @return Object
*/
@PostMapping("/edit")
public Object edit(@Validated(value = SystemDeptParam.update.class) @RequestBody SystemDeptParam systemDeptParam) {
iSystemDeptService.edit(systemDeptParam);
return AjaxResult.success();
}
/**
* 部门删除
*
* @author fzr
* @param systemDeptParam 参数
* @return Object
*/
@PostMapping("/del")
public Object del(@Validated(value = SystemDeptParam.delete.class) @RequestBody SystemDeptParam systemDeptParam) {
iSystemDeptService.del(systemDeptParam.getId());
return AjaxResult.success();
}
}

View File

@ -0,0 +1,26 @@
package com.hxkj.admin.controller.system;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("api/post")
public class SystemPostController {
public Object list() {
return null;
}
public Object add() {
return null;
}
public Object edit() {
return null;
}
public Object del() {
return null;
}
}

View File

@ -0,0 +1,58 @@
package com.hxkj.admin.service;
import com.alibaba.fastjson.JSONArray;
import com.hxkj.admin.validate.system.SystemDeptParam;
import com.hxkj.admin.validate.system.SystemMenuParam;
import com.hxkj.admin.vo.system.SystemDeptVo;
import com.hxkj.admin.vo.system.SystemMenuVo;
import java.util.Map;
/**
* 系统部门服务接口类
*/
public interface ISystemDeptService {
/**
* 部门列表
*
* @author fzr
* @param params 搜索参数
* @return JSONArray
*/
JSONArray lists(Map<String, String> params);
/**
* 部门详情
*
* @author fzr
* @param id 主键
* @return SysMenu
*/
SystemDeptVo detail(Integer id);
/**
* 部门新增
*
* @author fzr
* @param systemDeptParam 参数
*/
void add(SystemDeptParam systemDeptParam);
/**
* 部门编辑
*
* @author fzr
* @param systemDeptParam 参数
*/
void edit(SystemDeptParam systemDeptParam);
/**
* 部门删除
*
* @author fzr
* @param id 主键
*/
void del(Integer id);
}

View File

@ -38,7 +38,7 @@ public interface ISystemMenuService {
SystemMenuVo detail(Integer id);
/**
* 新增菜单
* 菜单新增
*
* @author fzr
* @param systemMenuParam 参数
@ -46,7 +46,7 @@ public interface ISystemMenuService {
void add(SystemMenuParam systemMenuParam);
/**
* 编辑菜单
* 菜单编辑
*
* @author fzr
* @param systemMenuParam 参数
@ -54,7 +54,7 @@ public interface ISystemMenuService {
void edit(SystemMenuParam systemMenuParam);
/**
* 删除菜单
* 菜单删除
*
* @author fzr
* @param id 主键

View File

@ -37,7 +37,7 @@ public interface ISystemRoleService {
SystemRoleVo detail(Integer id);
/**
* 新增角色
* 角色新增
*
* @author fzr
* @param systemRoleParam 参数
@ -45,7 +45,7 @@ public interface ISystemRoleService {
void add(SystemRoleParam systemRoleParam);
/**
* 更新角色
* 角色更新
*
* @author fzr
* @param systemRoleParam 参数
@ -53,7 +53,7 @@ public interface ISystemRoleService {
void edit(SystemRoleParam systemRoleParam);
/**
* 删除角色
* 角色删除
*
* @author fzr
* @param id 主键参数

View File

@ -0,0 +1,179 @@
package com.hxkj.admin.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.hxkj.admin.service.ISystemDeptService;
import com.hxkj.admin.validate.system.SystemDeptParam;
import com.hxkj.admin.vo.system.SystemDeptVo;
import com.hxkj.common.entity.system.SystemDept;
import com.hxkj.common.mapper.system.SystemDeptMapper;
import com.hxkj.common.utils.ArrayUtil;
import com.hxkj.common.utils.TimeUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Service
public class SystemDeptServiceImpl implements ISystemDeptService {
@Resource
SystemDeptMapper systemDeptMapper;
/**
* 部门列表
*
* @author fzr
* @param params 搜索参数
* @return JSONArray
*/
@Override
public JSONArray lists(Map<String, String> params) {
QueryWrapper<SystemDept> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("is_delete", 0);
queryWrapper.orderByAsc(Arrays.asList("sort", "id"));
queryWrapper.select(SystemDept.class, info ->
!info.getColumn().equals("is_delete") &&
!info.getColumn().equals("delete_time"));
systemDeptMapper.setSearch(queryWrapper, params, new String[]{
"like:name:str",
"=:isStop:int"
});
List<SystemDept> systemDeptList = systemDeptMapper.selectList(queryWrapper);
List<SystemDeptVo> lists = new ArrayList<>();
for (SystemDept systemDept : systemDeptList) {
SystemDeptVo vo = new SystemDeptVo();
BeanUtils.copyProperties(systemDept, vo);
vo.setCreateTime(TimeUtil.timestampToDate(systemDept.getCreateTime()));
vo.setUpdateTime(TimeUtil.timestampToDate(systemDept.getUpdateTime()));
lists.add(vo);
}
JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(lists));
return ArrayUtil.listToTree(jsonArray, "id", "pid", "children");
}
/**
* 部门详情
*
* @author fzr
* @param id 主键
* @return SystemDeptVo
*/
@Override
public SystemDeptVo detail(Integer id) {
SystemDept systemDept = systemDeptMapper.selectOne(
new QueryWrapper<SystemDept>()
.select(SystemDept.class, info ->
!info.getColumn().equals("is_delete") &&
!info.getColumn().equals("delete_time"))
.eq("id", id)
.eq("is_delete", 0)
.last("limit 1"));
Assert.notNull(systemDept, "部门已不存在!");
SystemDeptVo vo = new SystemDeptVo();
BeanUtils.copyProperties(systemDept, vo);
vo.setCreateTime(TimeUtil.timestampToDate(systemDept.getCreateTime()));
vo.setUpdateTime(TimeUtil.timestampToDate(systemDept.getUpdateTime()));
return vo;
}
/**
* 部门新增
*
* @author fzr
* @param systemDeptParam 参数
*/
@Override
public void add(SystemDeptParam systemDeptParam) {
if (systemDeptParam.getPid() == 0) {
SystemDept systemDept = systemDeptMapper.selectOne(
new QueryWrapper<SystemDept>()
.select("id,pid,name")
.eq("pid", 0)
.eq("is_delete", 0)
.last("limit 1"));
Assert.isNull(systemDept, "顶级部门只允许有一个");
}
SystemDept model = new SystemDept();
model.setPid(systemDeptParam.getPid());
model.setName(systemDeptParam.getName());
model.setDuty(systemDeptParam.getDuty());
model.setMobile(systemDeptParam.getMobile());
model.setSort(systemDeptParam.getSort());
model.setIsStop(systemDeptParam.getIsStop());
model.setIsDelete(0);
model.setCreateTime(System.currentTimeMillis() / 1000);
model.setUpdateTime(System.currentTimeMillis() / 1000);
systemDeptMapper.insert(model);
}
/**
* 部门编辑
*
* @author fzr
* @param systemDeptParam 参数
*/
@Override
public void edit(SystemDeptParam systemDeptParam) {
SystemDept model = systemDeptMapper.selectOne(
new QueryWrapper<SystemDept>()
.select(SystemDept.class, info ->
!info.getColumn().equals("is_delete") &&
!info.getColumn().equals("delete_time"))
.eq("id", systemDeptParam.getId())
.eq("is_delete", 0)
.last("limit 1"));
Assert.notNull(model, "部门不存在");
Assert.isFalse((model.getPid() == 0 && systemDeptParam.getPid() > 0), "顶级部门不能修改上级");
Assert.isFalse(systemDeptParam.getId().equals(systemDeptParam.getPid()), "上级部门不能是自己");
model.setPid(systemDeptParam.getPid());
model.setName(systemDeptParam.getName());
model.setDuty(systemDeptParam.getDuty());
model.setMobile(systemDeptParam.getMobile());
model.setSort(systemDeptParam.getSort());
model.setIsStop(systemDeptParam.getIsStop());
model.setUpdateTime(System.currentTimeMillis() / 1000);
systemDeptMapper.updateById(model);
}
/**
* 部门删除
*
* @author fzr
* @param id 主键
*/
@Override
public void del(Integer id) {
SystemDept model = systemDeptMapper.selectOne(
new QueryWrapper<SystemDept>()
.select("id,pid,name")
.eq("id", id)
.eq("is_delete", 0)
.last("limit 1"));
Assert.notNull(model, "部门不存在");
Assert.isFalse((model.getPid() == 0), "顶级部门不能删除");
model.setIsDelete(1);
model.setDeleteTime(System.currentTimeMillis() / 1000);
systemDeptMapper.updateById(model);
}
}

View File

@ -0,0 +1,49 @@
package com.hxkj.admin.validate.system;
import com.hxkj.common.validator.annotation.IDMust;
import com.hxkj.common.validator.annotation.IntegerContains;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
/**
* 系统部门参数
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class SystemDeptParam {
public interface create{}
public interface update{}
public interface delete{}
@IDMust(message = "id参数必传且需大于0", groups = {update.class, delete.class})
private Integer id;
@NotNull(message = "pid参数缺失", groups = {create.class, update.class})
@DecimalMin(value = "0", message = "上级值不能少于0", groups = {create.class, update.class})
private Integer pid;
@NotNull(message = "name参数缺失", groups = {create.class, update.class})
@Length(min = 1, max = 100, message = "部门名称必须在1~100个字符内", groups = {create.class, update.class})
private String name;
@Length(min = 1, max = 30, message = "负责人名称必须在1~30个字符内", groups = {create.class, update.class})
private String duty;
@Length(min = 11, max = 11, message = "手机号只能为11位", groups = {create.class, update.class})
@Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误", groups = {create.class, update.class})
private String mobile;
@NotNull(message = "请选择状态", groups = {create.class, update.class})
@IntegerContains(values = {0, 1}, groups = {create.class, update.class})
private Integer isStop;
private Integer sort;
}

View File

@ -10,6 +10,8 @@ import java.io.Serializable;
@Data
public class SystemAuthVo implements Serializable {
private static final long serialVersionUID = 1L;
private String path;
private Object auth;

View File

@ -0,0 +1,25 @@
package com.hxkj.admin.vo.system;
import lombok.Data;
import java.io.Serializable;
/**
* 部门Vo
*/
@Data
public class SystemDeptVo implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private Integer pid;
private String name;
private String duty;
private String mobile;
private Integer sort;
private Integer isStop;
private String createTime;
private String updateTime;
}

View File

@ -0,0 +1,30 @@
package com.hxkj.common.entity.system;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serializable;
/**
* 系统岗位实体
*/
@Data
public class SystemDept implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value="id", type= IdType.AUTO)
private Integer id;
private Integer pid;
private String name;
private String duty;
private String mobile;
private Integer sort;
private Integer isStop;
private Integer isDelete;
private Long createTime;
private Long updateTime;
private Long deleteTime;
}

View File

@ -0,0 +1,12 @@
package com.hxkj.common.mapper.system;
import com.hxkj.common.core.basics.IBaseMapper;
import com.hxkj.common.entity.system.SystemDept;
import org.apache.ibatis.annotations.Mapper;
/**
* 系统岗位
*/
@Mapper
public interface SystemDeptMapper extends IBaseMapper<SystemDept> {
}