新增组织机构模块

v1.4.1
Parker 4 years ago
parent 60fa1c3bfc
commit e4c42ca119

@ -0,0 +1,134 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.api.web.system.org;
import org.opsli.api.base.result.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.opsli.api.wrapper.system.org.SysOrgModel;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.api.web.system.org
* @Author: Parker
* @CreateTime: 2020-11-28 18:59:59
* @Description:
*
* API @GetMapping @PostMapping
* Mapping Controller
*
*
*
*
*/
public interface SysOrgRestApi {
/** 标题 */
String TITLE = "组织机构";
@GetMapping("/findTreeLazyByUser")
ResultVo<?> findTreeLazyByUser(String parentId);
@GetMapping("/findTreeLazy")
ResultVo<?> findTreeLazy(String parentId);
@GetMapping("/findGridTree")
ResultVo<?> findGridTree(String parentId);
// ================
/**
*
* @param model
* @return ResultVo
*/
@GetMapping("/get")
ResultVo<SysOrgModel> get(SysOrgModel model);
/**
*
* @param request request
* @return ResultVo
*/
@GetMapping("/findTree")
ResultVo<?> findTree( HttpServletRequest request );
/**
*
* @param model
* @return ResultVo
*/
@PostMapping("/insert")
ResultVo<?> insert(@RequestBody SysOrgModel model);
/**
*
* @param model
* @return ResultVo
*/
@PostMapping("/update")
ResultVo<?> update(@RequestBody SysOrgModel model);
/**
*
* @param id ID
* @return ResultVo
*/
@PostMapping("/del")
ResultVo<?> del(String id);
/**
*
* @param ids ID
* @return ResultVo
*/
@PostMapping("/delAll")
ResultVo<?> delAll(String[] ids);
/**
* Excel
* @param request request
* @param response response
* @return ResultVo
*/
@GetMapping("/exportExcel")
ResultVo<?> exportExcel(HttpServletRequest request, HttpServletResponse response);
/**
* Excel
* @param request request
* @return ResultVo
*/
@GetMapping("/exportImport")
ResultVo<?> excelImport(MultipartHttpServletRequest request);
/**
* Excel
* @param response response
* @return ResultVo
*/
@GetMapping("/exportImport/template")
ResultVo<?> importTemplate(HttpServletResponse response);
}

@ -17,15 +17,14 @@ package org.opsli.api.web.system.user;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.role.RoleModel;
import org.opsli.api.wrapper.system.user.UserInfo;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserOrgRefModel;
import org.opsli.api.wrapper.system.user.UserPassword;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
@ -66,6 +65,20 @@ public interface UserApi {
@GetMapping("/getInfoById")
ResultVo<UserInfo> getInfoById(@RequestParam(name = "userId") String userId);
/**
*
* @return ResultVo
*/
@GetMapping("/getOrg")
ResultVo<UserOrgRefModel> getOrg();
/**
*
* @return ResultVo
*/
@GetMapping("/getOrgByUserId")
ResultVo<UserOrgRefModel> getOrgByUserId(@RequestParam(name = "userId") String userId);
/**
* userId Id
* @param userId Id
@ -118,6 +131,7 @@ public interface UserApi {
ResultVo<?> findPage(
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
UserOrgRefModel org,
HttpServletRequest request
);
@ -212,4 +226,12 @@ public interface UserApi {
//@GetMapping("/queryAllPerms")
ResultVo<List<MenuModel>> getMenuListByUserId(String userId);
/**
*
* @return ResultVo
*/
ResultVo<UserOrgRefModel> getOrgInfoByUserId(String userId);
}

@ -0,0 +1,53 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.api.web.system.user;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.wrapper.system.user.UserOrgRefModel;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.web
* @Author: Parker
* @CreateTime: 2020-09-13 17:40
* @Description: API
*
* API @GetMapping @PostMapping
* Mapping Controller
*
*
*
*
*/
public interface UserOrgRefApi {
/** 标题 */
String TITLE = "组织机构";
/**
*
* @param model userId Id
* @param model roleIds Id
* @return ResultVo
*/
@PostMapping("/setOrg")
ResultVo<?> setOrg(@RequestBody UserOrgRefModel model);
}

@ -0,0 +1,94 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.api.wrapper.system.org;
import java.util.Date;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.validation.ValidationArgs;
import org.opsli.common.annotation.validation.ValidationArgsLenMax;
import org.opsli.common.enums.ValiArgsType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.api.wrapper.system.org
* @Author: Parker
* @CreateTime: 2020-11-28 18:59:59
* @Description:
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SysOrgModel extends ApiWrapper {
/** 父级主键 */
@ApiModelProperty(value = "父级主键")
@ExcelProperty(value = "父级主键", order = 1)
@ExcelInfo
// 验证器
@ValidationArgsLenMax(19)
private String parentId;
/** 组织机构编号 */
@ApiModelProperty(value = "组织机构编号")
@ExcelProperty(value = "组织机构编号", order = 2)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL})
@ValidationArgsLenMax(120)
private String orgCode;
/** 组织机构名称 */
@ApiModelProperty(value = "组织机构名称")
@ExcelProperty(value = "组织机构名称", order = 3)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE})
@ValidationArgsLenMax(120)
private String orgName;
/** 组织机构类型 1-公司 2-部门 3-岗位*/
@ApiModelProperty(value = "组织机构类型")
@ExcelProperty(value = "组织机构类型", order = 4)
@ExcelInfo( dictType = "org_type")
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
@ValidationArgsLenMax(3)
private String orgType;
/** 排序 */
@ApiModelProperty(value = "排序")
@ExcelProperty(value = "排序", order = 5)
@ExcelInfo
// 验证器
@ValidationArgsLenMax(10)
private Integer sortNo;
/** 多租户字段 */
@ApiModelProperty(value = "多租户ID")
@ExcelIgnore
// 验证器
@ValidationArgsLenMax(20)
private String tenantId;
}

@ -0,0 +1,150 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.api.wrapper.system.user;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.validation.ValidationArgs;
import org.opsli.common.annotation.validation.ValidationArgsLenMax;
import org.opsli.common.enums.ValiArgsType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.entity
* @Author: Parker
* @CreateTime: 2020-09-16 17:33
* @Description:
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class UserAndOrgModel extends ApiWrapper {
/** 登录账户 */
@ApiModelProperty(value = "登录账户")
@ExcelIgnore
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL})
@ValidationArgsLenMax(32)
private String username;
/** 登录密码 */
@ApiModelProperty(value = "登录密码")
@ExcelIgnore
// 验证器
@ValidationArgsLenMax(50)
private String password;
/** 盐值,密码秘钥 */
@ApiModelProperty(value = "盐值,密码秘钥")
@ExcelIgnore
// 验证器
@ValidationArgsLenMax(50)
private String secretkey;
/** 是否锁定 */
@ApiModelProperty(value = "是否锁定")
@ExcelIgnore
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
@ValidationArgsLenMax(1)
private Character locked;
/** 真实姓名 */
@ApiModelProperty(value = "真实姓名")
@ExcelProperty(value = "真实姓名", order = 1)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL_WITH_CHINESE})
@ValidationArgsLenMax(50)
private String realName;
/** 手机 */
@ApiModelProperty(value = "手机")
@ExcelProperty(value = "手机", order = 2)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_MOBILE})
private String mobile;
/** 邮箱 */
@ApiModelProperty(value = "邮箱")
@ExcelProperty(value = "邮箱", order = 3)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_EMAIL})
@ValidationArgsLenMax(100)
private String email;
/** 工号 */
@ApiModelProperty(value = "工号")
@ExcelProperty(value = "工号", order = 4)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_GENERAL})
@ValidationArgsLenMax(32)
private String no;
/** 头像 */
@ApiModelProperty(value = "头像")
@ExcelIgnore
// 验证器
@ValidationArgsLenMax(255)
private String avatar;
/** 最后登陆IP */
@ApiModelProperty(value = "最后登陆IP")
@ExcelIgnore
// 验证器
@ValidationArgs(ValiArgsType.IS_IPV4)
private String loginIp;
/** 备注 */
@ApiModelProperty(value = "备注")
@ExcelProperty(value = "备注", order = 5)
@ExcelInfo
// 验证器
@ValidationArgsLenMax(255)
private String remark;
/** 签名 */
@ApiModelProperty(value = "签名")
@ExcelProperty(value = "签名", order = 5)
@ExcelInfo
// 验证器
@ValidationArgsLenMax(255)
private String sign;
/** 多租户字段 */
@ApiModelProperty(value = "多租户ID")
@ExcelIgnore
// 验证器
@ValidationArgsLenMax(20)
private String tenantId;
/** 组织机构 */
@ApiModelProperty(value = "组织机构")
@ExcelIgnore
private UserOrgRefModel org;
}

@ -0,0 +1,75 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.api.wrapper.system.user;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.common.annotation.validation.ValidationArgs;
import org.opsli.common.annotation.validation.ValidationArgsLenMax;
import org.opsli.common.enums.ValiArgsType;
import java.io.Serializable;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.entity
* @Author: Parker
* @CreateTime: 2020-09-16 17:33
* @Description:
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ExcelIgnoreUnannotated
public class UserOrgRefModel implements Serializable {
/** 用户ID */
@ApiModelProperty(value = "用户ID")
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
@ValidationArgsLenMax(50)
private String userId;
@ApiModelProperty(value = "公司")
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
@ValidationArgsLenMax(19)
private String companyId;
@ApiModelProperty(value = "公司名称")
// 验证器
private String companyName;
@ApiModelProperty(value = "部门ID")
// 验证器
@ValidationArgsLenMax(19)
private String departmentId;
@ApiModelProperty(value = "部门名称")
// 验证器
private String departmentName;
@ApiModelProperty(value = "岗位ID")
// 验证器
@ValidationArgsLenMax(19)
private String postId;
@ApiModelProperty(value = "岗位名称")
// 验证器
private String postName;
}

@ -41,7 +41,7 @@ public enum SystemMsg implements BaseMsg {
/**
*
*/
EXCEPTION_ROLE_UNIQUE(20200,"角色编号重复,该角色已存在"),
EXCEPTION_ROLE_UNIQUE(20200,"角色编号重复,该角色已存在"),
EXCEPTION_ROLE_ID_NOT_NULL(20201,"角色Id不可为空"),
EXCEPTION_ROLE_PERMS_ERROR(20202,"角色权限设置失败"),
@ -55,22 +55,26 @@ public enum SystemMsg implements BaseMsg {
EXCEPTION_USER_ROLES_ERROR(20303,"用户角色设置失败"),
EXCEPTION_USER_MENU_NOT_NULL(20304,"用户暂无角色菜单,请设置后登录"),
EXCEPTION_USER_NO_UNIQUE(20305,"该工号已存在"),
EXCEPTION_ORG_NOT_NULL(20306,"组织不可为空"),
EXCEPTION_USER_ORG_ERROR(20307,"用户组织设置失败"),
/**
*
*/
EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"),
EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"),
/**
*
*/
EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在!"),
EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在"),
EXCEPTION_ORG_USE(20501,"组织机构已被引用,不能删除"),
/**
*
*/
EXCEPTION_AREA_UNIQUE(20600,"地域编号重复,已存在"),
EXCEPTION_AREA_UNIQUE(20600,"地域编号重复,已存在"),
;

@ -19,7 +19,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.opsli.modulars.system.area.entity.HasChildren;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.modulars.system.area.entity.SysArea;
import java.util.List;

@ -12,7 +12,7 @@
</where>
</select>
<select id="hasChildren" parameterType="SysArea" resultType="org.opsli.modulars.system.area.entity.HasChildren">
<select id="hasChildren" parameterType="SysArea" resultType="org.opsli.core.base.entity.HasChildren">
select
parent_id as parentId,
count(0) as `count`

@ -16,8 +16,8 @@
package org.opsli.modulars.system.area.service;
import org.opsli.api.wrapper.system.area.SysAreaModel;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
import org.opsli.modulars.system.area.entity.HasChildren;
import org.opsli.modulars.system.area.entity.SysArea;
import java.util.List;

@ -23,11 +23,11 @@ import org.opsli.api.wrapper.system.area.SysAreaModel;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.area.entity.HasChildren;
import org.opsli.modulars.system.area.entity.SysArea;
import org.opsli.modulars.system.area.mapper.SysAreaMapper;
import org.opsli.modulars.system.area.service.ISysAreaService;

@ -35,10 +35,10 @@ import org.opsli.common.annotation.EnableLog;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.utils.HumpUtil;
import org.opsli.core.base.concroller.BaseRestController;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
import org.opsli.modulars.system.area.entity.HasChildren;
import org.opsli.modulars.system.area.entity.SysArea;
import org.opsli.modulars.system.area.service.ISysAreaService;
import org.springframework.web.multipart.MultipartHttpServletRequest;

@ -15,7 +15,6 @@
*/
package org.opsli.modulars.system.login.web;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import io.swagger.annotations.ApiOperation;

@ -0,0 +1,64 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.org.entity;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.core.base.entity.BaseEntity;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.system.org.entity
* @Author: Parker
* @CreateTime: 2020-11-28 18:59:59
* @Description:
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SysOrg extends BaseEntity {
/** 父级主键 */
private String parentId;
/** 组织机构编号 */
private String orgCode;
/** 组织机构名称 */
private String orgName;
/** 组织机构类型: 1-公司 2-部门 3-岗位 */
private String orgType;
/** 排序 */
private Integer sortNo;
// ========================================
/** 逻辑删除字段 */
@TableLogic
private Integer deleted;
/** 多租户字段 */
private String tenantId;
}

@ -0,0 +1,56 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.org.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.modulars.system.org.entity.SysOrg;
import java.util.List;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.system.org.mapper
* @Author: Parker
* @CreateTime: 2020-11-28 18:59:59
* @Description: Mapper
*/
@Mapper
public interface SysOrgMapper extends BaseMapper<SysOrg> {
/**
*
* @return
*/
Integer uniqueVerificationByCode(@Param("ew") Wrapper<SysOrg> wrapper);
/**
*
* @return
*/
List<HasChildren> hasChildren(@Param("ew") Wrapper<SysOrg> wrapper);
/**
*
* @return
*/
Integer hasUse(@Param("ew") Wrapper<SysOrg> wrapper);
}

@ -0,0 +1,48 @@
<?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="org.opsli.modulars.system.org.mapper.SysOrgMapper">
<select id="uniqueVerificationByCode" parameterType="SysOrg" resultType="Integer">
select
count(0)
from
sys_org
<where>
${ew.sqlSegment}
</where>
</select>
<select id="hasChildren" parameterType="SysOrg" resultType="org.opsli.core.base.entity.HasChildren">
select
parent_id as parentId,
count(0) as `count`
from
sys_org
<where>
${ew.sqlSegment}
</where>
</select>
<select id="hasChildren" parameterType="SysOrg" resultType="org.opsli.core.base.entity.HasChildren">
select
parent_id as parentId,
count(0) as `count`
from
sys_org
<where>
${ew.sqlSegment}
</where>
</select>
<select id="hasUse" parameterType="SysOrg" resultType="Integer">
select
count(0)
from
sys_user_org_ref
<where>
${ew.sqlSegment}
</where>
</select>
</mapper>

@ -0,0 +1,43 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.org.service;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
import org.opsli.modulars.system.org.entity.SysOrg;
import org.opsli.api.wrapper.system.org.SysOrgModel;
import java.util.List;
import java.util.Set;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.system.org.service
* @Author: Parker
* @CreateTime: 2020-11-28 18:59:59
* @Description: Service
*/
public interface ISysOrgService extends CrudServiceInterface<SysOrg, SysOrgModel> {
/**
*
* @return
*/
List<HasChildren> hasChildren(Set<String> parentIds);
}

@ -0,0 +1,209 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.org.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.org.SysOrgModel;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.chain.TenantHandler;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.org.entity.SysOrg;
import org.opsli.modulars.system.org.mapper.SysOrgMapper;
import org.opsli.modulars.system.org.service.ISysOrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Set;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.system.org.service.impl
* @Author: Parker
* @CreateTime: 2020-11-28 18:59:59
* @Description: Service Impl
*/
@Service
public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, SysOrgModel>
implements ISysOrgService {
@Autowired(required = false)
private SysOrgMapper mapper;
@Override
@Transactional(rollbackFor = Exception.class)
public SysOrgModel insert(SysOrgModel model) {
if(model == null) return null;
SysOrg entity = super.transformM2T(model);
// 唯一验证
Integer count = this.uniqueVerificationByCode(entity);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_ORG_UNIQUE);
}
// 如果上级ID 为空 则默认为 0
if(StringUtils.isEmpty(model.getParentId())){
model.setParentId("0");
}
return super.insert(model);
}
@Transactional(rollbackFor = Exception.class)
@Override
public SysOrgModel update(SysOrgModel model) {
if(model == null) return null;
SysOrg entity = super.transformM2T(model);
// 唯一验证
Integer count = this.uniqueVerificationByCode(entity);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_ORG_UNIQUE);
}
return super.update(model);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(String id) {
boolean ret;
if(StringUtils.isEmpty(id)){
return false;
}
QueryWrapper<SysOrg> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("org_id", id);
Integer count = mapper.hasUse(queryWrapper);
if(count > 0){
// 组织机构已被引用,不能删除
throw new ServiceException(SystemMsg.EXCEPTION_ORG_USE);
}
ret = super.delete(id);
// 删除子数据
this.deleteByParentId(id);
return ret;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteAll(String[] ids) {
boolean ret;
if(ArrayUtils.isEmpty(ids)){
return false;
}
QueryWrapper<SysOrg> queryWrapper = new QueryWrapper<>();
queryWrapper.in("org_id", Convert.toList(String.class, ids));
Integer count = mapper.hasUse(queryWrapper);
if(count > 0){
// 组织机构已被引用,不能删除
throw new ServiceException(SystemMsg.EXCEPTION_ORG_USE);
}
ret = super.deleteAll(ids);
// 删除子数据
for (String id : ids) {
this.deleteByParentId(id);
}
return ret;
}
/**
*
* @param parentId
* @return
*/
@Transactional(rollbackFor = Exception.class)
public boolean deleteByParentId(String parentId) {
boolean ret = false;
QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysOrg> queryWrapper = queryBuilder.build();
queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
List<SysOrg> menuList = super.findList(queryWrapper);
for (SysOrg sysOrg : menuList) {
super.delete(sysOrg.getId());
// 逐级删除子数据
ret = this.deleteByParentId(sysOrg.getId());
}
return ret;
}
/**
*
* @param entity
* @return
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByCode(SysOrg entity){
QueryWrapper<SysOrg> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq("org_code", entity.getOrgCode())
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0");
// 如果为修改 则跳过当前数据
if(StringUtils.isNotBlank(entity.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, entity.getId());
}
// 租户检测
wrapper = new TenantHandler().handler(super.entityClazz, wrapper);
return mapper.uniqueVerificationByCode(wrapper);
}
/**
*
* @param parentIds
* @return
*/
@Override
@Transactional(readOnly = true)
public List<HasChildren> hasChildren(Set<String> parentIds){
if(CollUtil.isEmpty(parentIds)){
return null;
}
QueryWrapper<SysOrg> wrapper = new QueryWrapper<>();
wrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentIds)
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
.groupBy(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID));
return mapper.hasChildren(wrapper);
}
}

@ -0,0 +1,437 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.org.web;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.web.system.org.SysOrgRestApi;
import org.opsli.api.wrapper.system.org.SysOrgModel;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.utils.HumpUtil;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.concroller.BaseRestController;
import org.opsli.core.base.entity.HasChildren;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
import org.opsli.modulars.system.org.entity.SysOrg;
import org.opsli.modulars.system.org.service.ISysOrgService;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.system.org.web
* @Author: Parker
* @CreateTime: 2020-11-28 18:59:59
* @Description: Controller
*/
@Slf4j
@ApiRestController("/sys/org")
public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel, ISysOrgService>
implements SysOrgRestApi {
/** 显示全部 */
public static final String ORG_ALL = "all";
/** 未分组 */
public static final String ORG_NULL = "org_null";
/**
*
* @return ResultVo
*/
@ApiOperation(value = "获得组织树 懒加载", notes = "获得组织树 懒加载")
@Override
public ResultVo<?> findTreeLazyByUser(String parentId) {
QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysOrg> wrapper = queryBuilder.build();
wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
// 获得用户 对应菜单
List<SysOrg> dataList = IService.findList(wrapper);
List<SysOrgModel> orgModelList = WrapperUtil.transformInstance(dataList, SysOrgModel.class);
// 0 为初始值
if("0".equals(parentId)){
// 显示全部
SysOrgModel orgAll = new SysOrgModel();
orgAll.setId(ORG_ALL);
orgAll.setOrgCode("-2");
orgAll.setOrgName("全部");
orgAll.setOrgType("-2");
orgAll.setParentId("0");
orgAll.setSortNo(-2);
orgModelList.add(orgAll);
// 未分组
SysOrgModel orgNull = new SysOrgModel();
orgNull.setId(ORG_NULL);
orgNull.setOrgCode("-1");
orgNull.setOrgName("未分组");
orgNull.setOrgType("-1");
orgNull.setParentId("0");
orgNull.setSortNo(-1);
orgModelList.add(orgNull);
}
//配置
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
// 自定义属性名 都要默认值的
treeNodeConfig.setWeightKey("sortNo");
treeNodeConfig.setNameKey("orgName");
// 最大递归深度 最多支持4层菜单
treeNodeConfig.setDeep(3);
//转换器
List<Tree<String>> treeNodes = TreeUtil.build(orgModelList, parentId, treeNodeConfig,
(treeNode, tree) -> {
tree.setId(treeNode.getId());
tree.setParentId(treeNode.getParentId());
tree.setWeight(treeNode.getSortNo());
tree.setName(treeNode.getOrgName());
// 扩展属性 ...
// 不是外链 则处理组件
tree.putExtra("orgCode", treeNode.getOrgCode());
tree.putExtra("orgType", treeNode.getOrgType());
tree.putExtra("version", treeNode.getVersion());
tree.putExtra("tenantId", treeNode.getTenantId());
});
Set<String> parentIds = Sets.newHashSet();
for (Tree<String> treeNode : treeNodes) {
parentIds.add(treeNode.getId());
}
// 数据排查是否存在下级
List<HasChildren> hasChildrenList = IService.hasChildren(parentIds);
if(CollUtil.isNotEmpty(hasChildrenList)){
Map<String, Boolean> tmp = Maps.newHashMap();
for (HasChildren hasChildren : hasChildrenList) {
if(hasChildren.getCount() != null && hasChildren.getCount() > 0){
tmp.put(hasChildren.getParentId(), true);
}
}
for (Tree<String> treeNode : treeNodes) {
Boolean tmpFlag = tmp.get(treeNode.getId());
if(tmpFlag != null && tmpFlag){
treeNode.putExtra("hasChildren", true);
}
}
}
return ResultVo.success(treeNodes);
}
/**
*
* @return ResultVo
*/
@ApiOperation(value = "获得组织树 懒加载", notes = "获得组织树 懒加载")
@Override
public ResultVo<?> findTreeLazy(String parentId) {
QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysOrg> wrapper = queryBuilder.build();
wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
// 获得用户 对应菜单
List<SysOrg> dataList = IService.findList(wrapper);
List<SysOrgModel> orgModelList = WrapperUtil.transformInstance(dataList, SysOrgModel.class);
//配置
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
// 自定义属性名 都要默认值的
treeNodeConfig.setWeightKey("sortNo");
treeNodeConfig.setNameKey("orgName");
// 最大递归深度 最多支持4层菜单
treeNodeConfig.setDeep(3);
//转换器
List<Tree<String>> treeNodes = TreeUtil.build(orgModelList, parentId, treeNodeConfig,
(treeNode, tree) -> {
tree.setId(treeNode.getId());
tree.setParentId(treeNode.getParentId());
tree.setWeight(treeNode.getSortNo());
tree.setName(treeNode.getOrgName());
// 扩展属性 ...
// 不是外链 则处理组件
tree.putExtra("orgCode", treeNode.getOrgCode());
tree.putExtra("orgType", treeNode.getOrgType());
tree.putExtra("version", treeNode.getVersion());
tree.putExtra("tenantId", treeNode.getTenantId());
});
Set<String> parentIds = Sets.newHashSet();
for (Tree<String> treeNode : treeNodes) {
parentIds.add(treeNode.getId());
}
// 数据排查是否存在下级
List<HasChildren> hasChildrenList = IService.hasChildren(parentIds);
if(CollUtil.isNotEmpty(hasChildrenList)){
Map<String, Boolean> tmp = Maps.newHashMap();
for (HasChildren hasChildren : hasChildrenList) {
if(hasChildren.getCount() != null && hasChildren.getCount() > 0){
tmp.put(hasChildren.getParentId(), true);
}
}
for (Tree<String> treeNode : treeNodes) {
Boolean tmpFlag = tmp.get(treeNode.getId());
if(tmpFlag != null && tmpFlag){
treeNode.putExtra("hasChildren", true);
}
}
}
return ResultVo.success(treeNodes);
}
/**
*
* @return ResultVo
*/
@ApiOperation(value = "获得组织树", notes = "获得组织树")
@Override
public ResultVo<?> findGridTree(String parentId) {
QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysOrg> wrapper = queryBuilder.build();
wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
// 获得用户 对应菜单
List<SysOrg> dataList = IService.findList(wrapper);
List<SysOrgModel> orgModelList = WrapperUtil.transformInstance(dataList, SysOrgModel.class);
//配置
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
// 自定义属性名 都要默认值的
treeNodeConfig.setWeightKey("sortNo");
treeNodeConfig.setNameKey("orgName");
// 最大递归深度 最多支持4层菜单
treeNodeConfig.setDeep(3);
//转换器
List<Tree<String>> treeNodes = TreeUtil.build(orgModelList, parentId, treeNodeConfig,
(treeNode, tree) -> {
tree.setId(treeNode.getId());
tree.setParentId(treeNode.getParentId());
tree.setWeight(treeNode.getSortNo());
tree.setName(treeNode.getOrgName());
// 扩展属性 ...
// 不是外链 则处理组件
tree.putExtra("orgCode", treeNode.getOrgCode());
tree.putExtra("orgType", treeNode.getOrgType());
tree.putExtra("version", treeNode.getVersion());
tree.putExtra("tenantId", treeNode.getTenantId());
});
return ResultVo.success(treeNodes);
}
// ==============
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "获得单条组织机构", notes = "获得单条组织机构 - ID")
@RequiresPermissions("system_org_select")
@Override
public ResultVo<SysOrgModel> get(SysOrgModel model) {
// 如果系统内部调用 则直接查数据库
if(model != null && model.getIzApi() != null && model.getIzApi()){
model = IService.get(model);
}
return ResultVo.success(model);
}
/**
*
* @return ResultVo
*/
@ApiOperation(value = "获得菜单树", notes = "获得菜单树")
@RequiresPermissions("system_org_select")
@Override
public ResultVo<?> findTree(HttpServletRequest request) {
QueryBuilder<SysOrg> queryBuilder = new WebQueryBuilder<>(SysOrg.class,
request.getParameterMap());
// 获得用户 对应菜单
List<SysOrg> dataList = IService.findList(queryBuilder.build());
//配置
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
// 自定义属性名 都要默认值的
treeNodeConfig.setWeightKey("sortNo");
treeNodeConfig.setNameKey("orgName");
// 最大递归深度 最多支持4层菜单
treeNodeConfig.setDeep(3);
//转换器
List<Tree<String>> treeNodes = TreeUtil.build(dataList, "0", treeNodeConfig,
(treeNode, tree) -> {
tree.setId(treeNode.getId());
tree.setParentId(treeNode.getParentId());
tree.setWeight(treeNode.getSortNo());
tree.setName(treeNode.getOrgName());
// 扩展属性 ...
// 不是外链 则处理组件
tree.putExtra("orgCode", treeNode.getOrgCode());
tree.putExtra("orgType", treeNode.getOrgType());
tree.putExtra("version", treeNode.getVersion());
tree.putExtra("tenantId", treeNode.getTenantId());
});
return ResultVo.success(treeNodes);
}
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "新增组织机构数据", notes = "新增组织机构数据")
@RequiresPermissions("system_org_insert")
@EnableLog
@Override
public ResultVo<?> insert(SysOrgModel model) {
// 演示模式 不允许操作
//super.demoError();
// 调用新增方法
IService.insert(model);
return ResultVo.success("新增组织机构成功");
}
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "修改组织机构数据", notes = "修改组织机构数据")
@RequiresPermissions("system_org_update")
@EnableLog
@Override
public ResultVo<?> update(SysOrgModel model) {
// 演示模式 不允许操作
super.demoError();
// 调用修改方法
IService.update(model);
return ResultVo.success("修改组织机构成功");
}
/**
*
* @param id ID
* @return ResultVo
*/
@ApiOperation(value = "删除组织机构数据", notes = "删除组织机构数据")
@RequiresPermissions("system_org_update")
@EnableLog
@Override
public ResultVo<?> del(String id){
// 演示模式 不允许操作
super.demoError();
IService.delete(id);
return ResultVo.success("删除组织机构成功");
}
/**
*
* @param ids ID
* @return ResultVo
*/
@ApiOperation(value = "批量删除组织机构数据", notes = "批量删除组织机构数据")
@RequiresPermissions("system_org_update")
@EnableLog
@Override
public ResultVo<?> delAll(String[] ids){
// 演示模式 不允许操作
super.demoError();
IService.deleteAll(ids);
return ResultVo.success("批量删除组织机构成功");
}
/**
* Excel
* @param request request
* @param response response
* @return ResultVo
*/
@ApiOperation(value = "导出Excel", notes = "导出Excel")
@RequiresPermissions("system_org_export")
@EnableLog
@Override
public ResultVo<?> exportExcel(HttpServletRequest request, HttpServletResponse response) {
QueryBuilder<SysOrg> queryBuilder = new WebQueryBuilder<>(SysOrg.class, request.getParameterMap());
return super.excelExport(SysOrgRestApi.TITLE, queryBuilder.build(), response);
}
/**
* Excel
* @param request request
* @return ResultVo
*/
@ApiOperation(value = "导入Excel", notes = "导入Excel")
@RequiresPermissions("system_org_import")
@EnableLog
@Override
public ResultVo<?> excelImport(MultipartHttpServletRequest request) {
return super.excelImport(request);
}
/**
* Excel
* @param response response
* @return ResultVo
*/
@ApiOperation(value = "导出Excel模版", notes = "导出Excel模版")
@RequiresPermissions("system_org_import")
@Override
public ResultVo<?> importTemplate(HttpServletResponse response) {
return super.importTemplate(SysOrgRestApi.TITLE, response);
}
}

@ -0,0 +1,92 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.user.entity;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.opsli.api.wrapper.system.user.UserOrgRefModel;
import org.opsli.core.base.entity.BaseEntity;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.entity
* @Author: Parker
* @CreateTime: 2020-09-16 17:33
* @Description:
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SysUserAndOrg extends BaseEntity {
/** 登录账户 */
private String username;
/** 登录密码 */
private String password;
/** 盐值,密码秘钥 */
private String secretKey;
/** 是否锁定 */
private String locked;
/** 真实姓名 */
private String realName;
/** 手机 */
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String mobile;
/** 邮箱 */
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String email;
/** 工号 */
private String no;
/** 头像 */
private String avatar;
/** 最后登陆IP */
private String loginIp;
/** 备注 */
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String remark;
/** 签名 */
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String sign;
/** 组织机构 */
private UserOrgRefModel org;
// ========================================
/** 逻辑删除字段 */
@TableLogic
private Integer deleted;
/** 多租户字段 */
private String tenantId;
}

@ -0,0 +1,49 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.user.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.entity
* @Author: Parker
* @CreateTime: 2020-09-16 17:33
* @Description: -
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SysUserOrgRef implements Serializable {
/** ID */
@TableId
private String id;
/** 用户ID */
private String userId;
/** 组织ID */
private String orgId;
/** 组织类型 */
private String orgType;
}

@ -15,12 +15,15 @@
*/
package org.opsli.modulars.system.user.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.opsli.api.wrapper.system.user.UserPassword;
import org.opsli.modulars.system.menu.entity.SysMenu;
import org.opsli.modulars.system.org.entity.SysOrg;
import org.opsli.modulars.system.user.entity.SysUser;
import org.opsli.modulars.system.user.entity.SysUserAndOrg;
import java.util.List;
@ -97,4 +100,11 @@ public interface UserMapper extends BaseMapper<SysUser> {
* @return
*/
boolean updateAvatar(SysUser entity);
/**
*
* @return
*/
List<SysUserAndOrg> findList(@Param("ew") Wrapper<SysUserAndOrg> wrapper);
}

@ -0,0 +1,34 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.user.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.opsli.modulars.system.user.entity.SysUserOrgRef;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.mapper
* @Author: Parker
* @CreateTime: 2020-09-17 13:01
* @Description: Mapper
*/
@Mapper
public interface UserOrgRefMapper extends BaseMapper<SysUserOrgRef> {
}

@ -3,7 +3,7 @@
<mapper namespace="org.opsli.modulars.system.user.mapper.UserMapper">
<!-- 数据库字段 -->
<sql id="SysDictColumns">
<sql id="columns">
a.id as id,
a.username as username,
@ -27,9 +27,30 @@
a.deleted as deleted
</sql>
<sql id="SysDictJoins">
<sql id="joinsColumns">
,b.org_id as 'org.companyId',
c.org_id as 'org.departmentId',
d.org_id as 'org.postId'
</sql>
<sql id="joins">
left join sys_user_org_ref b on b.user_id = a.id and b.org_type = '1'
left join sys_user_org_ref c on c.user_id = a.id and c.org_type = '2'
left join sys_user_org_ref d on d.user_id = a.id and d.org_type = '3'
</sql>
<select id="findList" parameterType="SysUser" resultType="SysUserAndOrg">
select
<include refid="columns"></include>
<include refid="joinsColumns"></include>
from
sys_user a
<include refid="joins"></include>
<where>
${ew.sqlSegment}
</where>
</select>
<select id="uniqueVerificationByUsername" parameterType="SysUser" resultType="Integer">
select
count(0)

@ -0,0 +1,6 @@
<?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="org.opsli.modulars.system.user.mapper.UserOrgRefMapper">
</mapper>

@ -0,0 +1,39 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.user.service;
import org.opsli.api.wrapper.system.user.UserOrgRefModel;
import java.util.List;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.service
* @Author: Parker
* @CreateTime: 2020-09-17 13:07
* @Description: -
*/
public interface IUserOrgRefService {
/**
*
* @param model
* @return
*/
boolean setOrg(UserOrgRefModel model);
}

@ -15,11 +15,15 @@
*/
package org.opsli.modulars.system.user.service;
import org.apache.poi.ss.formula.functions.T;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.user.UserAndOrgModel;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserPassword;
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
import org.opsli.core.persistence.Page;
import org.opsli.modulars.system.user.entity.SysUser;
import org.opsli.modulars.system.user.entity.SysUserAndOrg;
import java.util.List;
@ -91,4 +95,12 @@ public interface IUserService extends CrudServiceInterface<SysUser, UserModel> {
* @return
*/
boolean updateAvatar(UserModel model);
/**
*
*
* @return Page<T>
*/
Page<SysUserAndOrg, UserAndOrgModel> findPageByCus(Page<SysUserAndOrg,UserAndOrgModel> page);
}

@ -0,0 +1,110 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.user.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.user.UserOrgRefModel;
import org.opsli.common.exception.ServiceException;
import org.opsli.core.utils.OrgUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.user.entity.SysUserOrgRef;
import org.opsli.modulars.system.user.entity.SysUserRoleRef;
import org.opsli.modulars.system.user.mapper.UserOrgRefMapper;
import org.opsli.modulars.system.user.mapper.UserRoleRefMapper;
import org.opsli.modulars.system.user.service.IUserOrgRefService;
import org.opsli.modulars.system.user.service.IUserRoleRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.service
* @Author: Parker
* @CreateTime: 2020-09-16 17:34
* @Description:
*/
@Service
public class UserOrgRefServiceImpl extends ServiceImpl<UserOrgRefMapper, SysUserOrgRef> implements IUserOrgRefService {
@Autowired(required = false)
private UserOrgRefMapper mapper;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean setOrg(UserOrgRefModel model) {
// 非法验证 组织不可为空
if(model == null){
throw new ServiceException(SystemMsg.EXCEPTION_ORG_NOT_NULL);
}
// 删除已有组织
String userIdField = "user_id";
QueryWrapper<SysUserOrgRef> wrapper = new QueryWrapper<>();
wrapper.eq(userIdField, model.getUserId());
super.remove(wrapper);
List<SysUserOrgRef> orgRefs = Lists.newArrayList();
// 设置公司
if(StringUtils.isNotEmpty(model.getCompanyId())){
SysUserOrgRef tmp = new SysUserOrgRef();
tmp.setUserId(model.getUserId());
tmp.setOrgId(model.getCompanyId());
tmp.setOrgType("1");
orgRefs.add(tmp);
}
// 设置部门
if(StringUtils.isNotEmpty(model.getDepartmentId())){
SysUserOrgRef tmp = new SysUserOrgRef();
tmp.setUserId(model.getUserId());
tmp.setOrgId(model.getDepartmentId());
tmp.setOrgType("2");
orgRefs.add(tmp);
}
// 设置岗位
if(StringUtils.isNotEmpty(model.getPostId())){
SysUserOrgRef tmp = new SysUserOrgRef();
tmp.setUserId(model.getUserId());
tmp.setOrgId(model.getPostId());
tmp.setOrgType("3");
orgRefs.add(tmp);
}
boolean saveBatchFlag = super.saveBatch(orgRefs);
// 清空缓存
if(saveBatchFlag){
OrgUtil.refreshMenu(model.getUserId());
}
return true;
}
}

@ -17,8 +17,11 @@ package org.opsli.modulars.system.user.service.impl;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.user.UserAndOrgModel;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserPassword;
import org.opsli.common.constants.MyBatisConstants;
@ -29,10 +32,12 @@ import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.chain.TenantHandler;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.menu.entity.SysMenu;
import org.opsli.modulars.system.user.entity.SysUser;
import org.opsli.modulars.system.user.entity.SysUserAndOrg;
import org.opsli.modulars.system.user.mapper.UserMapper;
import org.opsli.modulars.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
@ -255,6 +260,31 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
sysUser.setAvatar(model.getAvatar());
return mapper.updateAvatar(sysUser);
}
public List<SysUserAndOrg> findListByCus(QueryWrapper<SysUserAndOrg> queryWrapper) {
// 多租户处理
QueryWrapper<SysUserAndOrg> qWrapper = new TenantHandler().handler(SysUserAndOrg.class, queryWrapper);
// 逻辑删除 查询未删除数据
qWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_DELETE_LOGIC),
"0"
);
return mapper.findList(qWrapper);
}
public Page<SysUserAndOrg,UserAndOrgModel> findPageByCus(Page<SysUserAndOrg,UserAndOrgModel> page) {
page.pageHelperBegin();
try{
List<SysUserAndOrg> list = this.findListByCus(page.getQueryWrapper());
PageInfo<SysUserAndOrg> pageInfo = new PageInfo<>(list);
List<UserAndOrgModel> es = WrapperUtil.transformInstance(pageInfo.getList(), UserAndOrgModel.class);
page.instance(pageInfo, es);
} finally {
page.pageHelperEnd();
}
return page;
}
}

@ -0,0 +1,84 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.system.user.web;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.web.system.user.UserOrgRefApi;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserOrgRefModel;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.exception.ServiceException;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.user.service.IUserOrgRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.web
* @Author: Parker
* @CreateTime: 2020-09-13 17:40
* @Description:
*/
@Slf4j
@ApiRestController("/sys/user/org")
public class UserOrgRefRestController implements UserOrgRefApi {
@Value("${opsli.enable-demo}")
private boolean enableDemo;
@Autowired
private IUserOrgRefService iUserOrgRefService;
/**
*
* @param model
* @return ResultVo
*/
@Override
@RequiresPermissions("system_user_setOrg")
public ResultVo<?> setOrg(UserOrgRefModel model) {
// 演示模式 不允许操作
this.demoError();
boolean ret = iUserOrgRefService.setOrg(model);
if(ret){
return ResultVo.success();
}
// 权限设置失败
return ResultVo.error(SystemMsg.EXCEPTION_USER_ORG_ERROR.getCode(),
SystemMsg.EXCEPTION_USER_ORG_ERROR.getMessage()
);
}
/**
*
*/
private void demoError(){
UserModel user = UserUtil.getUser();
// 演示模式 不允许操作 (超级管理员可以操作)
if(enableDemo && !UserUtil.SUPER_ADMIN.equals(user.getUsername())){
throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO);
}
}
}

@ -15,35 +15,46 @@
*/
package org.opsli.modulars.system.user.web;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.web.system.user.UserApi;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.user.UserInfo;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserPassword;
import org.opsli.api.wrapper.system.org.SysOrgModel;
import org.opsli.api.wrapper.system.user.*;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.TokenException;
import org.opsli.common.utils.IPUtil;
import org.opsli.common.utils.HumpUtil;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.concroller.BaseRestController;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.msg.TokenMsg;
import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
import org.opsli.core.utils.OrgUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.org.entity.SysOrg;
import org.opsli.modulars.system.org.service.ISysOrgService;
import org.opsli.modulars.system.org.web.SysOrgRestController;
import org.opsli.modulars.system.user.entity.SysUser;
import org.opsli.modulars.system.user.entity.SysUserAndOrg;
import org.opsli.modulars.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -54,6 +65,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
@ -71,6 +83,8 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
@Value("${opsli.web.upload-path}")
private String basedir;
@Autowired
private ISysOrgService iSysOrgService;
/**
*
@ -112,6 +126,29 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
}
/**
*
* @return ResultVo
*/
@ApiOperation(value = "当前登陆用户组织机构", notes = "当前登陆用户组织机构")
@Override
public ResultVo<UserOrgRefModel> getOrg() {
UserModel user = UserUtil.getUser();
return this.getOrgByUserId(user.getId());
}
/**
*
* @param userId
* @return ResultVo
*/
@ApiOperation(value = "用户组织机构", notes = "用户组织机构")
@Override
public ResultVo<UserOrgRefModel> getOrgByUserId(String userId) {
UserOrgRefModel orgRef = OrgUtil.getOrgByUserId(userId);
return ResultVo.success(orgRef);
}
/**
* userId Id
* @param userId Id
@ -236,14 +273,36 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
@RequiresPermissions("system_user_select")
@Override
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {
QueryBuilder<SysUser> queryBuilder = new WebQueryBuilder<>(SysUser.class, request.getParameterMap());
Page<SysUser, UserModel> page = new Page<>(pageNo, pageSize);
page.setQueryWrapper(queryBuilder.build());
page = IService.findPage(page);
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, UserOrgRefModel org, HttpServletRequest request) {
QueryBuilder<SysUserAndOrg> queryBuilder = new WebQueryBuilder<>(SysUserAndOrg.class, request.getParameterMap());
Page<SysUserAndOrg, UserAndOrgModel> page = new Page<>(pageNo, pageSize);
QueryWrapper<SysUserAndOrg> queryWrapper = queryBuilder.build();
if(org != null){
// 公司ID
if(StringUtils.isNotBlank(org.getCompanyId())){
// 未分组判断
if(SysOrgRestController.ORG_NULL.equals(org.getCompanyId())){
queryWrapper.isNull("b.org_id");
}else{
queryWrapper.eq("b.org_id", org.getCompanyId());
}
}
// 部门ID
if(StringUtils.isNotBlank(org.getDepartmentId())){
queryWrapper.eq("c.org_id", org.getDepartmentId());
}
// 岗位ID
if(StringUtils.isNotBlank(org.getPostId())){
queryWrapper.eq("d.org_id", org.getPostId());
}
}
page.setQueryWrapper(queryWrapper);
page = IService.findPageByCus(page);
// 密码防止分页泄露处理
for (UserModel userModel : page.getList()) {
for (UserAndOrgModel userModel : page.getList()) {
userModel.setSecretkey(null);
userModel.setPassword(null);
}
@ -408,4 +467,71 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
List<MenuModel> menuModelList = IService.getMenuListByUserId(userId);
return ResultVo.success(menuModelList);
}
/**
*
* @param userId
* @return ResultVo
*/
@ApiOperation(value = "用户组织机构", notes = "用户组织机构")
@Override
public ResultVo<UserOrgRefModel> getOrgInfoByUserId(String userId) {
UserOrgRefModel org = null;
// 不写SQL了 直接分页 第一页 取第一条
QueryBuilder<SysUserAndOrg> queryBuilder = new GenQueryBuilder<>();
Page<SysUserAndOrg, UserAndOrgModel> page = new Page<>(1, 1);
QueryWrapper<SysUserAndOrg> queryWrapper = queryBuilder.build();
queryWrapper.eq(
"a.id",
userId
);
page.setQueryWrapper(queryWrapper);
page = IService.findPageByCus(page);
List<UserAndOrgModel> list = page.getList();
if(CollUtil.isNotEmpty(list)){
UserAndOrgModel userAndOrgModel = list.get(0);
if(userAndOrgModel != null){
org = userAndOrgModel.getOrg();
if(org != null){
org.setUserId(userId);
List<String> orgIds = Lists.newArrayListWithCapacity(3);
orgIds.add(org.getCompanyId());
orgIds.add(org.getDepartmentId());
orgIds.add(org.getPostId());
QueryWrapper<SysOrg> orgQueryWrapper = new QueryWrapper<>();
orgQueryWrapper.in(
HumpUtil.humpToUnderline(MyBatisConstants.FIELD_ID),
orgIds);
List<SysOrg> orgList = iSysOrgService.findList(orgQueryWrapper);
if(CollUtil.isNotEmpty(orgList)){
Map<String, SysOrg> tmp = Maps.newHashMap();
for (SysOrg sysOrg : orgList) {
tmp.put(sysOrg.getId(), sysOrg);
}
// 设置 名称
SysOrg company = tmp.get(org.getCompanyId());
if(company != null){
org.setCompanyName(company.getOrgName());
}
SysOrg department = tmp.get(org.getDepartmentId());
if(department != null){
org.setDepartmentName(department.getOrgName());
}
SysOrg post = tmp.get(org.getPostId());
if(post != null){
org.setPostName(post.getOrgName());
}
}
}
}
}
return ResultVo.success(org);
}
}

Loading…
Cancel
Save