Browse Source

新增部门管理模块

master
牧羊人 4 years ago
parent
commit
08e4854e52
10 changed files with 557 additions and 1 deletions
  1. +6
    -0
      src/main/java/com/taauav/front/controller/UserDataStatisticsController.java
  2. +114
    -0
      src/main/java/com/taauav/front/controller/UserDepController.java
  3. +1
    -1
      src/main/java/com/taauav/front/controller/UserInspectController.java
  4. +5
    -0
      src/main/java/com/taauav/front/entity/UserAdmin.java
  5. +51
    -0
      src/main/java/com/taauav/front/entity/UserDep.java
  6. +16
    -0
      src/main/java/com/taauav/front/mapper/UserDepMapper.java
  7. +5
    -0
      src/main/java/com/taauav/front/mapper/UserDepMapper.xml
  8. +71
    -0
      src/main/java/com/taauav/front/service/IUserDepService.java
  9. +213
    -0
      src/main/java/com/taauav/front/service/impl/UserDepServiceImpl.java
  10. +75
    -0
      src/main/java/com/taauav/front/vo/UserDepListVo.java

+ 6
- 0
src/main/java/com/taauav/front/controller/UserDataStatisticsController.java View File

@@ -233,6 +233,12 @@ public class UserDataStatisticsController {
return null;
}

/**
* 获取上个月时间
*
* @param month
* @return
*/
public String getLastMonth(Integer month) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
Date date = new Date();

+ 114
- 0
src/main/java/com/taauav/front/controller/UserDepController.java View File

@@ -0,0 +1,114 @@
package com.taauav.front.controller;


import com.taauav.admin.entity.SysCity;
import com.taauav.common.bean.Response;
import com.taauav.common.constant.PermissionConstants;
import com.taauav.front.entity.UserDep;
import com.taauav.front.service.IUserDepService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
* <p>
* 部门管理表 前端控制器
* </p>
*
* @author 鲲鹏
* @since 2020-05-25
*/
@RestController
@RequestMapping("/front/userdep")
public class UserDepController extends FrontBaseController {
@Autowired
private IUserDepService userDepService;
@Autowired
private Response response;

private static final String controllerName = "userdep";

/**
* 部门列表
*
* @return
*/
@PostMapping("/index")
// @RequiresPermissions(controllerName + ":" + PermissionConstants.LIST_PERMISSION)
public Response index() {
return userDepService.getList();
}

/**
* 添加机构
*
* @param entity 实体对象
* @param bindingResult
* @return
*/
@PostMapping("/add")
// @RequiresPermissions(controllerName + ":" + PermissionConstants.ADD_PERMISSION)
public Response add(@RequestBody @Valid UserDep entity, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
String message = bindingResult.getFieldError().getDefaultMessage();
return response.failure(message);
}
return userDepService.add(entity);
}

/**
* 获取机构详情
*
* @param id 机构ID
* @return
*/
@GetMapping("/info")
// @RequiresPermissions(controllerName + ":" + PermissionConstants.EDIT_PERMISSION)
public Response info(Integer id) {
return userDepService.info(id);
}

/**
* 编辑机构
*
* @param entity 实体对象
* @param bindingResult
* @return
*/
@PostMapping("/edit")
// @RequiresPermissions(controllerName + ":" + PermissionConstants.EDIT_PERMISSION)
public Response edit(@RequestBody @Valid UserDep entity, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
String message = bindingResult.getFieldError().getDefaultMessage();
return response.failure(message);
}
return userDepService.edit(entity);
}

/**
* 删除机构
*
* @param id 机构ID
* @return
*/
@PostMapping("/drop")
// @RequiresPermissions(controllerName + ":" + PermissionConstants.REMOVE_PERMISSION)
public Response drop(Integer id) {
return userDepService.delete(id);
}

/**
* 设置状态
*
* @param entity 实体对象
* @return
*/
@PostMapping("/setStatus")
// @RequiresPermissions(controllerName + ":" + PermissionConstants.STATUS_PERMISSION)
public Response setStatus(@RequestBody UserDep entity) {
return userDepService.setStatus(entity);
}
}

+ 1
- 1
src/main/java/com/taauav/front/controller/UserInspectController.java View File

@@ -32,7 +32,7 @@ public class UserInspectController {
private static final String controllerName = "userinspect";

@PostMapping("/addTask")
@RequiresPermissions(controllerName + ":" + PermissionConstants.ADD_PERMISSION)
// @RequiresPermissions(controllerName + ":" + PermissionConstants.ADD_PERMISSION)
public Response addTask(@RequestBody @Valid TauvInspect inspect, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
List<FieldError> errorList = bindingResult.getFieldErrors();

+ 5
- 0
src/main/java/com/taauav/front/entity/UserAdmin.java View File

@@ -63,6 +63,11 @@ public class UserAdmin extends Entity {
*/
private String company;

/**
* 部门ID
*/
private Integer depId;

/**
* 头像
*/

+ 51
- 0
src/main/java/com/taauav/front/entity/UserDep.java View File

@@ -0,0 +1,51 @@
package com.taauav.front.entity;

import java.time.LocalDateTime;

import com.taauav.common.domain.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* <p>
* 部门管理表
* </p>
*
* @author 鲲鹏
* @since 2020-05-25
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class UserDep extends Entity {

private static final long serialVersionUID = 1L;

/**
* 部门名称
*/
private String name;

/**
* 直接上级ID
*/
private Integer pid;

/**
* 部门层级
*/
private Integer level;

/**
* 有无子节点:1有 2无
*/
private Integer hasChild;

/**
* 排序
*/
private Integer sort;


}

+ 16
- 0
src/main/java/com/taauav/front/mapper/UserDepMapper.java View File

@@ -0,0 +1,16 @@
package com.taauav.front.mapper;

import com.taauav.front.entity.UserDep;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
* <p>
* 部门管理表 Mapper 接口
* </p>
*
* @author 鲲鹏
* @since 2020-05-25
*/
public interface UserDepMapper extends BaseMapper<UserDep> {

}

+ 5
- 0
src/main/java/com/taauav/front/mapper/UserDepMapper.xml View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.taauav.front.mapper.UserDepMapper">

</mapper>

+ 71
- 0
src/main/java/com/taauav/front/service/IUserDepService.java View File

@@ -0,0 +1,71 @@
package com.taauav.front.service;

import com.taauav.admin.entity.SysCity;
import com.taauav.common.bean.Response;
import com.taauav.common.service.IBaseService;
import com.taauav.front.entity.UserDep;
import com.baomidou.mybatisplus.extension.service.IService;
import com.taauav.front.vo.UserDepListVo;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
* <p>
* 部门管理表 服务类
* </p>
*
* @author 鲲鹏
* @since 2020-05-25
*/
public interface IUserDepService extends IBaseService<UserDep> {

/**
* 获取部门列表
*
* @return
*/
Response getList();

/**
* 添加部门
*
* @param entity 实体对象
* @return
*/
Response add(UserDep entity);

/**
* 获取机构详情
*
* @param id 机构ID
* @return
*/
Response info(Integer id);

/**
* 编辑机构
*
* @param entity 实体对象
* @return
*/
Response edit(UserDep entity);

/**
* 删除机构
*
* @param id 机构ID
* @return
*/
Response delete(Integer id);

/**
* 设置状态
*
* @param entity 实体对象
* @return
*/
Response setStatus(UserDep entity);

}

+ 213
- 0
src/main/java/com/taauav/front/service/impl/UserDepServiceImpl.java View File

@@ -0,0 +1,213 @@
package com.taauav.front.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.taauav.common.bean.Response;
import com.taauav.common.service.impl.BaseServiceImpl;
import com.taauav.common.util.DateUtil;
import com.taauav.common.util.ShiroUtils;
import com.taauav.front.entity.UserDep;
import com.taauav.front.mapper.UserDepMapper;
import com.taauav.front.service.IUserAdminService;
import com.taauav.front.service.IUserDepService;
import com.taauav.front.vo.UserDepListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.Validator;
import java.util.*;

/**
* <p>
* 部门管理表 服务实现类
* </p>
*
* @author 鲲鹏
* @since 2020-05-25
*/
@Service
public class UserDepServiceImpl extends BaseServiceImpl<UserDepMapper, UserDep> implements IUserDepService {

@Resource
private Response response;
@Autowired
private UserDepMapper userDepMapper;
@Resource
private Validator validator;
@Autowired
private IUserAdminService adminService;

/**
* 获取部门数据
*
* @return
*/
@Override
public Response getList() {
// 获取子级
List<UserDepListVo> userDepListVoList = this.getChildCityList(0);
return response.success(userDepListVoList);
}

/**
* 获取子级部门列表
*
* @param pid 上级ID
* @return
*/
public List<UserDepListVo> getChildCityList(Integer pid) {
QueryWrapper<UserDep> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("pid", pid);
queryWrapper.eq("mark", 1);
queryWrapper.orderByAsc("sort");
List<UserDep> userDepList = userDepMapper.selectList(queryWrapper);
List<UserDepListVo> userDepListVoList = new ArrayList<>();
if (!userDepList.isEmpty()) {
userDepList.forEach(item -> {
UserDepListVo userDepListVo = new UserDepListVo();
// 拷贝属性
BeanUtils.copyProperties(item, userDepListVo);
// 判断是否有子级
List<UserDepListVo> childrenList = this.getChildCityList(item.getId());
if (!childrenList.isEmpty()) {
userDepListVo.setChildrenList(childrenList);
userDepListVo.setHasChildren(true);
} else {
userDepListVo.setHasChildren(false);
}
userDepListVoList.add(userDepListVo);
});
}
return userDepListVoList;
}

/**
* 添加部门
*
* @param entity 实体对象
* @return
*/
@Override
public Response add(UserDep entity) {
if (entity == null) {
return response.failure("实体对象不能为空");
}
if (entity.getPid() == null) {
entity.setLevel(1);
} else {
UserDep userDep = userDepMapper.selectById(entity.getPid());
if (userDep != null) {
entity.setLevel(userDep.getLevel() + 1);
}
}
entity.setCreateTime(DateUtil.now());
entity.setCreateUser(ShiroUtils.getAdminId());
int result = userDepMapper.insert(entity);
if (result == 0) {
return response.failure("添加失败");
}
return response.success("添加成功");
}

/**
* 获取机构详情
*
* @param id 机构ID
* @return
*/
@Override
public Response info(Integer id) {
if (id == null) {
return response.failure("机构ID不存在");
}
UserDep entity = this.getById(id);
if (entity == null) {
return response.failure("机构信息不存在");
}
return response.success(entity);
}

/**
* 编辑机构
*
* @param entity 实体对象
* @return
*/
@Override
public Response edit(UserDep entity) {
if (entity == null || entity.getId() == null) {
return response.failure("实体对象不能为空");
}
// 同名不给添加
QueryWrapper<UserDep> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", entity.getName());
queryWrapper.eq("level", entity.getLevel());
queryWrapper.eq("mark", 1);
UserDep userDep = userDepMapper.selectOne(queryWrapper);
if (userDep != null) {
return response.failure("同级已存在该部门名称");
}
entity.setUpdateUser(ShiroUtils.getAdminId());
entity.setUpdateTime(DateUtil.now());
boolean result = this.updateById(entity);
if (!result) {
return response.failure("编辑失败");
}
return response.success("编辑成功");
}

/**
* 删除机构
*
* @param id 机构ID
* @return
*/
@Override
public Response delete(Integer id) {
if (id == null) {
return response.failure("机构ID不存在");
}
UserDep entity = userDepMapper.selectById(id);
if (entity == null) {
return response.failure("机构信息不存在");
}
// 校验是否存在子级
QueryWrapper<UserDep> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("pid", entity.getId());
queryWrapper.eq("mark", 1);
Integer count = userDepMapper.selectCount(queryWrapper);
if (count > 0) {
return response.failure("存在子级,无法删除");
}
entity.setUpdateUser(ShiroUtils.getAdminId());
entity.setUpdateTime(DateUtil.now());
entity.setMark(0);
boolean result = this.updateById(entity);
if (!result) {
return response.failure("删除失败");
}
return response.success("删除成功");
}

/**
* 设置状态
*
* @param entity 实体对象
* @return
*/
@Override
public Response setStatus(UserDep entity) {
if (entity.getId() == null) {
return response.failure("设备ID不存在");
}
if (entity.getStatus() == null || entity.getStatus() <= 0) {
return response.failure("状态不存在");
}
int result = userDepMapper.updateById(entity);
if (result == 0) {
return response.failure("设置失败");
}
return response.success("设置成功");
}
}

+ 75
- 0
src/main/java/com/taauav/front/vo/UserDepListVo.java View File

@@ -0,0 +1,75 @@
package com.taauav.front.vo;

import com.taauav.common.domain.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.List;

/**
* <p>
* 部门管理表
* </p>
*
* @author 鲲鹏
* @since 2020-05-25
*/
@Data
public class UserDepListVo {

private static final long serialVersionUID = 1L;

/**
* 部门ID
*/
private Integer id;

/**
* 部门名称
*/
private String name;

/**
* 直接上级ID
*/
private Integer pid;

/**
* 部门层级
*/
private Integer level;

/**
* 有无子节点:1有 2无
*/
private Integer hasChild;

/**
* 部门主管
*/
private Integer manager;

/**
* 排序
*/
private Integer sort;

/**
* 状态
*/
private Integer status;

/**
* 是否有子级
*/
boolean hasChildren;


/**
* 子级城市
*/
List<UserDepListVo> childrenList;


}

Loading…
Cancel
Save