项目组织机构
This commit is contained in:
parent
4442da6b79
commit
82e5fd5d8a
@ -132,6 +132,9 @@ public class SystemUser implements Serializable {
|
||||
@ApiModelProperty(value = "新用户和供应商的总公司sn")
|
||||
private String headquartersSn;
|
||||
|
||||
@ApiModelProperty(value = "星纵-项目组织机构id")
|
||||
private Long xzProjectOrgId;
|
||||
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "角色ID")
|
||||
private java.lang.Long roleId;
|
||||
|
||||
@ -1,27 +1,22 @@
|
||||
package com.zhgd.xmgl.modules.xz.controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.zhgd.jeecg.common.api.vo.Result;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import com.zhgd.xmgl.modules.xz.entity.XzProjectOrg;
|
||||
import com.zhgd.xmgl.modules.xz.service.IXzProjectOrgService;
|
||||
|
||||
import org.simpleframework.xml.core.Validate;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.simpleframework.xml.core.Validate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@ -36,93 +31,99 @@ import org.springframework.web.bind.annotation.*;
|
||||
@Slf4j
|
||||
@Api(tags = "星纵-项目组织机构相关Api")
|
||||
public class XzProjectOrgController {
|
||||
@Autowired
|
||||
private IXzProjectOrgService xzProjectOrgService;
|
||||
@Autowired
|
||||
private IXzProjectOrgService xzProjectOrgService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页列表查询星纵-项目组织机构信息", notes = "分页列表查询星纵-项目组织机构信息", httpMethod = "GET")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "pageNo", value = "第几页", paramType = "query", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页显示条数", paramType = "query", required = true, dataType = "Integer"),
|
||||
})
|
||||
@GetMapping(value = "/page")
|
||||
public Result<IPage<XzProjectOrg>> queryPageList(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
|
||||
return Result.success(xzProjectOrgService.queryPageList(paramMap));
|
||||
}
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页列表查询星纵-项目组织机构信息", notes = "分页列表查询星纵-项目组织机构信息", httpMethod = "GET")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "pageNo", value = "第几页", paramType = "query", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页显示条数", paramType = "query", required = true, dataType = "Integer"),
|
||||
})
|
||||
@GetMapping(value = "/page")
|
||||
public Result<IPage<XzProjectOrg>> queryPageList(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
|
||||
return Result.success(xzProjectOrgService.queryPageList(paramMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "列表查询星纵-项目组织机构信息", notes = "列表查询星纵-项目组织机构信息", httpMethod = "GET")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<List<XzProjectOrg>> queryList(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
|
||||
return Result.success(xzProjectOrgService.queryList(paramMap));
|
||||
}
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "列表查询星纵-项目组织机构信息", notes = "列表查询星纵-项目组织机构信息", httpMethod = "GET")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<List<XzProjectOrg>> queryList(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
|
||||
return Result.success(xzProjectOrgService.queryList(paramMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param xzProjectOrg
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加星纵-项目组织机构信息", notes = "添加星纵-项目组织机构信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<XzProjectOrg> add(@RequestBody @Validate XzProjectOrg xzProjectOrg) {
|
||||
xzProjectOrgService.add(xzProjectOrg);
|
||||
return Result.ok();
|
||||
}
|
||||
@ApiOperation(value = "树形列表查询星纵-项目组织机构信息", notes = "树形列表查询星纵-项目组织机构信息", httpMethod = "GET")
|
||||
@GetMapping(value = "tree/list")
|
||||
public Result<List<XzProjectOrg>> treeList(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
|
||||
return Result.success(xzProjectOrgService.treeList(paramMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param xzProjectOrg
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "编辑星纵-项目组织机构信息", notes = "编辑星纵-项目组织机构信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/edit")
|
||||
public Result<XzProjectOrg> edit(@RequestBody XzProjectOrg xzProjectOrg) {
|
||||
xzProjectOrgService.edit(xzProjectOrg);
|
||||
return Result.ok();
|
||||
}
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param xzProjectOrg
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加星纵-项目组织机构信息", notes = "添加星纵-项目组织机构信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<XzProjectOrg> add(@RequestBody @Validate XzProjectOrg xzProjectOrg) {
|
||||
xzProjectOrgService.add(xzProjectOrg);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除星纵-项目组织机构信息", notes = "删除星纵-项目组织机构信息", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "id", value = "星纵-项目组织机构ID", paramType = "body", required = true, dataType = "String", example = "{\"id\":\"1\"}")
|
||||
@PostMapping(value = "/delete")
|
||||
public Result<XzProjectOrg> delete(@ApiIgnore @RequestBody HashMap<String, Object> map) {
|
||||
xzProjectOrgService.delete(MapUtils.getString(map, "id"));
|
||||
return Result.ok();
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param xzProjectOrg
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "编辑星纵-项目组织机构信息", notes = "编辑星纵-项目组织机构信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/edit")
|
||||
public Result<XzProjectOrg> edit(@RequestBody XzProjectOrg xzProjectOrg) {
|
||||
xzProjectOrgService.edit(xzProjectOrg);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "通过id查询星纵-项目组织机构信息", notes = "通过id查询星纵-项目组织机构信息", httpMethod = "GET")
|
||||
@ApiImplicitParam(name = "id", value = "星纵-项目组织机构ID", paramType = "query", required = true, dataType = "Integer")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<XzProjectOrg> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<XzProjectOrg> result = new Result<XzProjectOrg>();
|
||||
XzProjectOrg xzProjectOrg = xzProjectOrgService.getById(id);
|
||||
if (xzProjectOrg == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
result.setResult(xzProjectOrg);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除星纵-项目组织机构信息", notes = "删除星纵-项目组织机构信息", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "id", value = "星纵-项目组织机构ID", paramType = "body", required = true, dataType = "String", example = "{\"id\":\"1\"}")
|
||||
@PostMapping(value = "/delete")
|
||||
public Result<XzProjectOrg> delete(@ApiIgnore @RequestBody HashMap<String, Object> map) {
|
||||
xzProjectOrgService.delete(MapUtils.getString(map, "id"));
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "通过id查询星纵-项目组织机构信息", notes = "通过id查询星纵-项目组织机构信息", httpMethod = "GET")
|
||||
@ApiImplicitParam(name = "id", value = "星纵-项目组织机构ID", paramType = "query", required = true, dataType = "Integer")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<XzProjectOrg> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<XzProjectOrg> result = new Result<XzProjectOrg>();
|
||||
XzProjectOrg xzProjectOrg = xzProjectOrgService.getById(id);
|
||||
if (xzProjectOrg == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
result.setResult(xzProjectOrg);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
package com.zhgd.xmgl.modules.xz.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 星纵-项目组织机构
|
||||
@ -78,7 +79,7 @@ public class XzProjectOrg implements Serializable {
|
||||
*/
|
||||
@Excel(name = "部门状态(0正常 1停用)", width = 15)
|
||||
@ApiModelProperty(value = "部门状态(0正常 1停用)")
|
||||
private java.lang.String status;
|
||||
private java.lang.Integer status;
|
||||
/**
|
||||
* 创建时间 yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
@ -95,4 +96,9 @@ public class XzProjectOrg implements Serializable {
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "更新时间 yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date updateTime;
|
||||
private String projectSn;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<XzProjectOrg> children;
|
||||
|
||||
}
|
||||
|
||||
@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@Mapper
|
||||
public interface XzProjectOrgMapper extends BaseMapper<XzProjectOrg> {
|
||||
|
||||
void deleteChildren(String id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
<?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.zhgd.xmgl.modules.xz.mapper.XzProjectOrgMapper">
|
||||
<delete id="deleteChildren">
|
||||
delete
|
||||
from xz_project_org
|
||||
where find_in_set(#{id}, ancestors)
|
||||
</delete>
|
||||
</mapper>
|
||||
|
||||
@ -24,4 +24,6 @@ public interface IXzProjectOrgService extends IService<XzProjectOrg> {
|
||||
void edit(XzProjectOrg xzProjectOrg);
|
||||
|
||||
void delete(String id);
|
||||
|
||||
List<XzProjectOrg> treeList(HashMap<String, Object> paramMap);
|
||||
}
|
||||
|
||||
@ -1,24 +1,30 @@
|
||||
package com.zhgd.xmgl.modules.xz.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.xmgl.modules.xz.entity.XzProjectOrg;
|
||||
import com.zhgd.xmgl.modules.xz.mapper.XzProjectOrgMapper;
|
||||
import com.zhgd.xmgl.modules.xz.service.IXzProjectOrgService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zhgd.jeecg.common.system.query.QueryGenerator;
|
||||
import com.zhgd.xmgl.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.jeecg.common.system.query.QueryGenerator;
|
||||
import com.zhgd.xmgl.modules.stuff.entity.StuffType;
|
||||
import com.zhgd.xmgl.modules.xz.entity.XzProjectOrg;
|
||||
import com.zhgd.xmgl.modules.xz.mapper.XzProjectOrgMapper;
|
||||
import com.zhgd.xmgl.modules.xz.service.IXzProjectOrgService;
|
||||
import com.zhgd.xmgl.util.PageUtil;
|
||||
import com.zhgd.xmgl.util.RefUtil;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.sql.Struct;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.zhgd.xmgl.util.RefUtil;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description: 星纵-项目组织机构
|
||||
@ -61,16 +67,33 @@ public class XzProjectOrgServiceImpl extends ServiceImpl<XzProjectOrgMapper, XzP
|
||||
@Override
|
||||
public void add(XzProjectOrg xzProjectOrg) {
|
||||
xzProjectOrg.setId(null);
|
||||
XzProjectOrg pOrg = xzProjectOrgMapper.selectOne(new LambdaQueryWrapper<XzProjectOrg>()
|
||||
.eq(XzProjectOrg::getId, xzProjectOrg.getParentId()));
|
||||
if (pOrg != null) {
|
||||
xzProjectOrg.setAncestors(pOrg.getAncestors() + "," + pOrg.getId());
|
||||
boolean top = xzProjectOrg.getParentId() == null || xzProjectOrg.getParentId() == 0;
|
||||
if (top) {
|
||||
xzProjectOrg.setParentId(0L);
|
||||
xzProjectOrg.setAncestors("0");
|
||||
} else {
|
||||
XzProjectOrg pOrg = xzProjectOrgMapper.selectOne(new LambdaQueryWrapper<XzProjectOrg>()
|
||||
.eq(XzProjectOrg::getId, xzProjectOrg.getParentId()));
|
||||
if (Objects.equals(pOrg.getStatus(), 1)) {
|
||||
throw new OpenAlertException("部门状态为停用,无法添加下级");
|
||||
}
|
||||
if (pOrg != null) {
|
||||
xzProjectOrg.setAncestors(pOrg.getAncestors() + "," + pOrg.getId());
|
||||
}
|
||||
}
|
||||
baseMapper.insert(xzProjectOrg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(XzProjectOrg xzProjectOrg) {
|
||||
List<XzProjectOrg> cOrgs = xzProjectOrgMapper.selectList(new LambdaQueryWrapper<XzProjectOrg>()
|
||||
.eq(XzProjectOrg::getParentId, xzProjectOrg.getId())
|
||||
.eq(XzProjectOrg::getStatus, 0)
|
||||
);
|
||||
if (CollUtil.isNotEmpty(cOrgs)) {
|
||||
throw new OpenAlertException("该部门有下级部门未停用,不能停用");
|
||||
}
|
||||
xzProjectOrg.setAncestors(null);
|
||||
baseMapper.updateById(xzProjectOrg);
|
||||
}
|
||||
|
||||
@ -80,8 +103,50 @@ public class XzProjectOrgServiceImpl extends ServiceImpl<XzProjectOrgMapper, XzP
|
||||
if (xzProjectOrg == null) {
|
||||
throw new OpenAlertException("未找到对应实体");
|
||||
}
|
||||
List<XzProjectOrg> xzProjectOrgs = xzProjectOrgMapper.selectList(new LambdaQueryWrapper<XzProjectOrg>()
|
||||
.eq(XzProjectOrg::getParentId, id));
|
||||
if (CollUtil.isNotEmpty(xzProjectOrgs)) {
|
||||
throw new OpenAlertException("该部门有下级部门,无法删除");
|
||||
}
|
||||
baseMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<XzProjectOrg> treeList(HashMap<String, Object> paramMap) {
|
||||
Integer status = MapUtils.getInteger(paramMap, "status");
|
||||
String deptName = MapUtils.getString(paramMap, "deptName");
|
||||
String projectSn = MapUtils.getString(paramMap, "projectSn");
|
||||
if (StrUtil.isBlank(projectSn)) {
|
||||
throw new OpenAlertException("projectSn不能为空");
|
||||
}
|
||||
List<XzProjectOrg> allList = queryList(paramMap);
|
||||
List<XzProjectOrg> treeList = null;
|
||||
if (status != null || StrUtil.isNotBlank(deptName)) {
|
||||
//有查询条件,不组装tree
|
||||
treeList = allList;
|
||||
} else {
|
||||
//组装tree
|
||||
//获取父节点
|
||||
treeList = allList.stream()
|
||||
.filter(m -> m.getParentId() == 0)
|
||||
.peek(m -> m.setChildren(getChildren(m, allList)))//peek:执行类似map,但操作之后的数据并不返回到Stream中
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return treeList;
|
||||
}
|
||||
|
||||
private List<XzProjectOrg> getChildren(XzProjectOrg st, List<XzProjectOrg> allList) {
|
||||
List<XzProjectOrg> list = allList.stream()
|
||||
.filter(m -> Objects.equals(m.getParentId(), st.getId()))
|
||||
.peek(m -> m.setChildren(getChildren(m, allList)))
|
||||
.collect(Collectors.toList());
|
||||
list.sort((o1, o2) -> {
|
||||
if (o1.getOrderNum() == null || o2.getOrderNum() == null) {
|
||||
return 0;
|
||||
}
|
||||
return o1.getOrderNum().compareTo(o2.getOrderNum());
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user