parent
60fa1c3bfc
commit
e4c42ca119
@ -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;
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
## 改造微服务时 将Feign 接口写在这里
|
@ -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;
|
||||
|
||||
|
||||
}
|
@ -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> {
|
||||
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue