INE2 后台管理系统(机构)
一、简介
1、机构作为组织架构的重要配置,也是系统数据权限架构的重要组成;
2、机构树形结构设计,存在父项、子项、孙子项逻辑。
二、表设计
CREATE TABLE `sys_org` (
`sys_client_id` bigint(32) DEFAULT NULL,--集团ID
`sys_org_id` bigint(32) NOT NULL AUTO_INCREMENT,--机构ID
`name` varchar(150) NOT NULL,--名称
`value` varchar(100) DEFAULT NULL,--搜索码
`seq_no` bigint(10) DEFAULT NULL,--序列号
`org_contact_phone` varchar(30) DEFAULT NULL,--联系电话
`org_contact` varchar(30) DEFAULT NULL,--联系人
`org_contact_email` varchar(50) DEFAULT NULL,--联系邮箱
`parent_id` bigint(32) DEFAULT NULL,--父项ID
`all_parent` varchar(200) DEFAULT NULL,--所有父项ID
`active` varchar(1) DEFAULT '1',
`created_by` varchar(32) NOT NULL,
`create_time` datetime NOT NULL,
`updated_by` varchar(32) NOT NULL,
`update_time` datetime NOT NULL,
`description` varchar(100) DEFAULT NULL,
`version` bigint(10) DEFAULT NULL,
`short_name` varchar(150) DEFAULT NULL,
PRIMARY KEY (`sys_org_id`) USING BTREE,
UNIQUE KEY `org_u01` (`name`) USING BTREE,
UNIQUE KEY `org_u02` (`short_name`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8;
三、功能界面
四、功能代码
提供增删改查服务
package com.ine.system.service.impl;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ine.common.base.BaseServiceImpl;
import com.ine.common.base.Const;
import com.ine.common.exception.service.ServiceException;
import com.ine.common.support.DictCombo;
import com.ine.common.util.StringUtils;
import com.ine.system.common.exceptions.SysExceptionEnum;
import com.ine.system.common.log.LogObjectHolder;
import com.ine.system.dao.OrgMapper;
import com.ine.system.model.Org;
import com.ine.system.service.IOrgService;
import com.ine.system.transfer.bo.OrgNode;
import com.ine.system.transfer.form.OrgForm;
import com.ine.system.transfer.query.OrgQuery;
@Transactional
@Service
public class OrgServiceImpl extends BaseServiceImpl<OrgMapper, Org> implements IOrgService {
@Override
public List<OrgNode> listOrgNodes(OrgQuery param) {
return this.baseMapper.listOrgNodes(param);
}
@Override
protected void beforeSave(Org t, boolean isNew) {
if (isNew || isValueChange(t, Const.NAME)) {
t.setValue(StringUtils.getPinYin(t.getName()));
}
if(!Const.ROOT_ID.equals(t.getParent_Id())) {
Org pOrg = getById(t.getParent_Id());
if(pOrg == null) {
throw new ServiceException(SysExceptionEnum.ORG_NOT_EXISTD,t.getName());
}
if(!pOrg.getSys_Client_Id().equals(t.getSys_Client_Id())) {
throw new ServiceException(SysExceptionEnum.ORG_SUB_NOT_EQUAL_PARENT_CLIENT_ERROR);
}
}
}
public Org add(OrgForm orgForm) throws Exception {
Org org = new Org();
BeanUtils.copyProperties(orgForm, org);
saveOrUpdate(org);
LogObjectHolder.me().setN(org);
return org;
}
public Org edit(OrgForm orgForm) throws Exception {
Org org = getById(orgForm.getSys_Org_Id());
if (org != null) {
BeanUtils.copyProperties(orgForm, org);
saveOrUpdate(org);
LogObjectHolder.me().setN(org);
}
return org;
}
public Org getByName(String org_Name) {
QueryWrapper condi = new QueryWrapper<>();
condi.eq("name", org_Name);
return getOne(condi);
}
@Override
public List<DictCombo> refList(Page page, Integer sys_Client_Id, String search, Integer sys_Org_Id) {
return this.baseMapper.refList(page,sys_Client_Id,search,sys_Org_Id);
}
@Override
public void disable(Integer id) {
Org org = getById(id);
if (org == null) {
throw new ServiceException(SysExceptionEnum.ORG_NOT_EXISTD);
}
org.setActive(Const.N.toString());
saveOrUpdate(org);
}
@Override
public void active(Integer id) {
Org org = getById(id);
if (org == null) {
throw new ServiceException(SysExceptionEnum.ORG_NOT_EXISTD);
}
org.setActive(Const.Y.toString());
saveOrUpdate(org);
}
@Override
public OrgNode getOrgNodeById(Integer sys_Org_Id) {
OrgQuery param = new OrgQuery();
param.setSys_Org_Id(sys_Org_Id);
List<OrgNode> nodes = listOrgNodes(param);
if (nodes != null && nodes.size() > 0) {
return nodes.get(0);
}
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ine.system.dao.OrgMapper">
<select id="listOrgNodes" resultType="com.ine.system.transfer.bo.OrgNode">
SELECT T.*,
T.SYS_ORG_ID ID,
C.NAME CLIENT_NAME,
T.NAME ORG_NAME,
T.NAME TEXT,
(CASE WHEN ((SELECT COUNT(1) FROM SYS_ORG M WHERE M.PARENT_ID = T.SYS_ORG_ID AND M.ACTIVE = '1')>0) THEN 0 ELSE 1 END) AS LEAF
FROM SYS_ORG T
INNER JOIN SYS_CLIENT C
ON (C.SYS_CLIENT_ID = T.SYS_CLIENT_ID)
WHERE 1 = 1
<if test="param.org_Name != null and param.org_Name !=''">
AND T.NAME LIKE CONCAT('%',#{param.org_Name,jdbcType=VARCHAR},'%')
</if>
<if test="param.parent_Id != null">
AND T.PARENT_ID = #{param.parent_Id,jdbcType=INTEGER}
</if>
<if test="param.sys_Client_Id != null">
AND T.SYS_CLIENT_ID = #{param.sys_Client_Id,jdbcType=INTEGER}
</if>
<if test="param.sys_Org_Id != null">
AND T.SYS_ORG_ID = #{param.sys_Org_Id,jdbcType=INTEGER}
</if>
<if test="param.active != null">
AND T.ACTIVE = #{param.active,jdbcType=VARCHAR}
</if>
</select>
<select id="refList" resultType="com.ine.common.support.DictCombo">
SELECT T.SYS_ORG_ID ID,
T.NAME NAME
FROM SYS_ORG T
WHERE T.ACTIVE = '1'
<if test="sys_Client_Id != null">
AND T.SYS_CLIENT_ID = #{sys_Client_Id,jdbcType=INTEGER}
</if>
<if test="search != null">
AND ( T.NAME LIKE CONCAT('%',#{search,jdbcType=VARCHAR},'%') )
</if>
<if test="sys_Org_Id != null">
AND T.SYS_ORG_ID = #{sys_Org_Id,jdbcType=INTEGER}
</if>
</select>
</mapper>
~~~~