代码优化

v1.4.1
Parker 4 years ago
parent a1d06f73f6
commit 918326632c

@ -57,6 +57,11 @@ public enum MsgArgsType {
/** 租户数据 */
TENANT_DATA,
/** 参数编号 */
OPTION_CODE,
/** 参数数据*/
OPTION_MODEL_DATA,
/** 缓存数据Key */
CACHE_DATA_KEY,
/** 缓存数据Value */

@ -39,6 +39,9 @@ public enum PushSubType {
/** 租户 */
TENANT,
/** 系统数据 */
OPTION,
/** 热点数据 */
HOT_DATA,

@ -30,7 +30,7 @@ import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
* @BelongsPackage: org.opsli.core.cache.pushsub.msgs
* @Author: Parker
* @CreateTime: 2020-09-15 16:50
* @Description:
* @Description:
*/
@Data

@ -29,7 +29,7 @@ import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
* @BelongsPackage: org.opsli.core.cache.pushsub.msgs
* @Author: Parker
* @CreateTime: 2020-09-15 16:50
* @Description:
* @Description:
*/
@Data
@ -51,7 +51,7 @@ public final class MenuMsgFactory extends BaseSubMessage{
jsonObj.put(MsgArgsType.MENU_CODE.toString(), menuModel.getMenuCode());
jsonObj.put(MsgArgsType.MENU_MODEL_DATA.toString(), menuModel);
// 用户
// 菜单
baseSubMessage.build(CHANNEL,PushSubType.MENU.toString(),jsonObj);
return baseSubMessage;
}

@ -52,7 +52,7 @@ public final class OrgMsgFactory extends BaseSubMessage{
jsonObj.put(MsgArgsType.ORG_USER_ID.toString(), orgRefModel.getUserId());
jsonObj.put(MsgArgsType.ORG_USER_DATA.toString(), orgRefModel);
// 用户
// 组织
baseSubMessage.build(CHANNEL,PushSubType.ORG.toString(),jsonObj);
return baseSubMessage;
}

@ -56,7 +56,7 @@ public class MenuUtil {
/**
* userName
* menuCode
* @param menuCode
* @return
*/
@ -118,7 +118,7 @@ public class MenuUtil {
// ============== 刷新缓存 ==============
/**
* -
* -
* @param menu
* @return
*/
@ -130,7 +130,7 @@ public class MenuUtil {
// 计数器
int count = 0;
MenuModel menuModel = CacheUtil.getTimed(MenuModel.class, PREFIX_CODE + menu.getMenuCode());
MenuModel model = CacheUtil.getTimed(MenuModel.class, PREFIX_CODE + menu.getMenuCode());
boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_CODE + menu.getMenuCode());
// 只要不为空 则执行刷新
@ -143,7 +143,7 @@ public class MenuUtil {
}
}
if(menuModel != null){
if(model != null){
count++;
// 先删除
boolean tmp = CacheUtil.del(PREFIX_CODE + menu.getMenuCode());

@ -58,7 +58,6 @@ public class #(data.model.tableName)Model extends ApiWrapper {
#else
@ExcelInfo
#end
// 验证器
#if(column.validateType != null && column.validateType != "")
@ValidationArgs({#(column.validateType)})
#end

@ -46,6 +46,7 @@ public enum SystemMsg implements BaseMsg {
EXCEPTION_ROLE_PERMS_ERROR(20202,"角色权限设置失败"),
/**
*
*/
@ -80,6 +81,11 @@ public enum SystemMsg implements BaseMsg {
*/
EXCEPTION_AREA_UNIQUE(20600,"地域编号重复,已存在"),
/**
*
*/
EXCEPTION_OPTIONS_UNIQUE(20700,"参数编号重复,该角色已存在"),
;
private final int code;

@ -34,15 +34,10 @@ import java.util.List;
@Mapper
public interface SysAreaMapper extends BaseMapper<SysArea> {
/**
*
* @return
*/
Integer uniqueVerificationByCode(@Param("ew") Wrapper<SysArea> wrapper);
/**
*
* @return
* @return List
*/
List<HasChildren> hasChildren(@Param("ew") Wrapper<SysArea> wrapper);

@ -2,15 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.opsli.modulars.system.area.mapper.SysAreaMapper">
<select id="uniqueVerificationByCode" parameterType="SysArea" resultType="Integer">
select
count(0)
from
sys_area
<where>
${ew.sqlSegment}
</where>
</select>
<select id="hasChildren" parameterType="SysArea" resultType="org.opsli.core.base.entity.HasChildren">
select

@ -20,6 +20,7 @@ import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.area.SysAreaModel;
import org.opsli.api.wrapper.system.role.RoleModel;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
@ -27,10 +28,12 @@ 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.area.entity.SysArea;
import org.opsli.modulars.system.area.mapper.SysAreaMapper;
import org.opsli.modulars.system.area.service.ISysAreaService;
import org.opsli.modulars.system.role.entity.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -61,9 +64,8 @@ public class SysAreaServiceImpl extends CrudServiceImpl<SysAreaMapper, SysArea,
return null;
}
SysArea entity = super.transformM2T(model);
// 唯一验证
Integer count = this.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_AREA_UNIQUE);
@ -84,9 +86,8 @@ public class SysAreaServiceImpl extends CrudServiceImpl<SysAreaMapper, SysArea,
return null;
}
SysArea entity = super.transformM2T(model);
// 唯一验证
Integer count = this.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_AREA_UNIQUE);
@ -138,28 +139,33 @@ public class SysAreaServiceImpl extends CrudServiceImpl<SysAreaMapper, SysArea,
return ret;
}
/**
*
* @param entity
* @return
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByCode(SysArea entity){
public Integer uniqueVerificationByCode(SysAreaModel model){
if(model == null){
return null;
}
QueryWrapper<SysArea> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq("area_code", entity.getAreaCode())
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0");
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
.eq("area_code", model.getAreaCode());
// 如果为修改 则跳过当前数据
if(StringUtils.isNotBlank(entity.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, entity.getId());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return mapper.uniqueVerificationByCode(wrapper);
return super.count(wrapper);
}
/**
*
* @param parentIds

@ -29,11 +29,4 @@ import org.opsli.modulars.system.menu.entity.SysMenu;
@Mapper
public interface MenuMapper extends BaseMapper<SysMenu> {
/**
*
* @param entity
* @return
*/
Integer uniqueVerificationByCode(SysMenu entity);
}

@ -2,45 +2,5 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.opsli.modulars.system.menu.mapper.MenuMapper">
<!-- 数据库字段 -->
<sql id="SysRoleColumns">
a.id as id,
a.parent_id as parentId,
a.menu_code as menuCode,
a.menu_name as menuName,
a.icon as icon,
a.type as type,
a.url as url,
a.component as component,
a.redirect as redirect,
a.iz_lock as izLock,
a.hidden as hidden,
a.sort_no as sortNo,
a.create_by as createBy,
a.create_time as createTime,
a.update_by as updateBy,
a.update_time as updateTime,
a.version as version,
a.deleted as deleted
</sql>
<sql id="SysRoleJoins">
</sql>
<select id="uniqueVerificationByCode" parameterType="SysMenu" resultType="Integer">
select
count(0)
from
sys_menu a
where
a.menu_code = #{menuCode}
and a.deleted = 0
<if test="id != null and id != ''">
AND a.id != #{id}
</if>
</select>
</mapper>

@ -19,6 +19,7 @@ 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.StringUtils;
import org.opsli.api.wrapper.system.area.SysAreaModel;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException;
@ -30,6 +31,7 @@ import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.utils.MenuUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.area.entity.SysArea;
import org.opsli.modulars.system.menu.entity.SysMenu;
import org.opsli.modulars.system.menu.mapper.MenuMapper;
import org.opsli.modulars.system.menu.service.IMenuService;
@ -75,9 +77,8 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
return null;
}
SysMenu entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_ROLE_UNIQUE);
@ -98,9 +99,8 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
return null;
}
SysMenu entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_ROLE_UNIQUE);
@ -123,7 +123,6 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
// 删除子数据
this.deleteByParentId(id);
if(ret){
// 清除缓存
this.clearCache(menuModel);
@ -141,7 +140,6 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
super.findList(queryWrapper)
);
// 清除缓存
for (MenuModel menuModel : menuList) {
this.clearCache(menuModel);
@ -156,6 +154,30 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
return ret;
}
/**
*
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByCode(MenuModel model){
if(model == null){
return null;
}
QueryWrapper<SysMenu> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
.eq("menu_code", model.getMenuCode());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return super.count(wrapper);
}
/**
*

@ -34,11 +34,6 @@ import java.util.List;
@Mapper
public interface SysOrgMapper extends BaseMapper<SysOrg> {
/**
*
* @return
*/
Integer uniqueVerificationByCode(@Param("ew") Wrapper<SysOrg> wrapper);
/**
*

@ -2,16 +2,6 @@
<!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,

@ -67,9 +67,8 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
return null;
}
SysOrg entity = super.transformM2T(model);
// 唯一验证
Integer count = this.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_ORG_UNIQUE);
@ -99,9 +98,8 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
return null;
}
SysOrg entity = super.transformM2T(model);
// 唯一验证
Integer count = this.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_ORG_UNIQUE);
@ -223,26 +221,27 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
/**
*
* @param entity
* @param model
* @return
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByCode(SysOrg entity){
public Integer uniqueVerificationByCode(SysOrgModel model){
if(model == null){
return null;
}
QueryWrapper<SysOrg> wrapper = new QueryWrapper<>();
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
.eq("org_code", model.getOrgCode());
// 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());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
// 租户检测
wrapper = new TenantHandler().handler(super.entityClazz, wrapper);
return mapper.uniqueVerificationByCode(wrapper);
return super.count(wrapper);
}

@ -32,11 +32,5 @@ import org.opsli.modulars.system.role.entity.SysRole;
@Mapper
public interface RoleMapper extends BaseMapper<SysRole> {
/**
*
* @param wrapper
* @return
*/
Integer uniqueVerificationByCode(@Param("ew") Wrapper<SysRole> wrapper);
}

@ -2,34 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.opsli.modulars.system.role.mapper.RoleMapper">
<!-- 数据库字段 -->
<sql id="SysRoleColumns">
a.id as id,
a.role_code as roleCode,
a.role_name as roleName,
a.iz_lock as izLock,
a.remark as remark,
a.create_by as createBy,
a.create_time as createTime,
a.update_by as updateBy,
a.update_time as updateTime,
a.version as version,
a.deleted as deleted
</sql>
<sql id="SysRoleJoins">
</sql>
<select id="uniqueVerificationByCode" resultType="Integer">
select
count(0)
from
sys_role
<where>
${ew.sqlSegment}
</where>
</select>
</mapper>

@ -51,9 +51,8 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
return null;
}
SysRole entity = super.transformM2T(model);
// 唯一验证
Integer count = this.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_ROLE_UNIQUE);
@ -69,9 +68,8 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
return null;
}
SysRole entity = super.transformM2T(model);
// 唯一验证
Integer count = this.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_ROLE_UNIQUE);
@ -80,31 +78,34 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
return super.update(model);
}
/**
*
* @param entity
* @return
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByCode(SysRole entity){
public Integer uniqueVerificationByCode(RoleModel model){
if(model == null){
return null;
}
QueryWrapper<SysRole> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq("role_code", entity.getRoleCode())
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0");
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
.eq("role_code", model.getRoleCode());
// 如果为修改 则跳过当前数据
if(StringUtils.isNotBlank(entity.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, entity.getId());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
// 租户检测
wrapper = new TenantHandler().handler(super.entityClazz, wrapper);
return mapper.uniqueVerificationByCode(wrapper);
return super.count(wrapper);
}
}

@ -31,11 +31,5 @@ import org.opsli.modulars.system.tenant.entity.SysTenant;
@Mapper
public interface TenantMapper extends BaseMapper<SysTenant> {
/**
*
* @param entity
* @return
*/
Integer uniqueVerificationByName(SysTenant entity);
}

@ -3,18 +3,4 @@
<mapper namespace="org.opsli.modulars.system.tenant.mapper.TenantMapper">
<select id="uniqueVerificationByName" resultType="Integer">
select
count(0)
from
sys_tenant a
<where>
a.tenant_name = #{tenantName}
and a.deleted = 0
<if test="id != null and id != ''">
and a.id != #{id}
</if>
</where>
</select>
</mapper>

@ -17,13 +17,18 @@ package org.opsli.modulars.system.tenant.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.tenant.TenantModel;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.TenantUtil;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.menu.entity.SysMenu;
import org.opsli.modulars.system.tenant.entity.SysTenant;
import org.opsli.modulars.system.tenant.mapper.TenantMapper;
import org.opsli.modulars.system.tenant.service.ITenantService;
@ -56,9 +61,8 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
return null;
}
SysTenant entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByName(entity);
Integer count = this.uniqueVerificationByName(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_TENANT_UNIQUE);
@ -74,9 +78,8 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
return null;
}
SysTenant entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByName(entity);
Integer count = this.uniqueVerificationByName(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_TENANT_UNIQUE);
@ -177,8 +180,34 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
return ret;
}
/**
*
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByName(TenantModel model){
if(model == null){
return null;
}
QueryWrapper<SysTenant> wrapper = new QueryWrapper<>();
// name 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
.eq("tenant_name", model.getTenantName());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return super.count(wrapper);
}
// ============
/**
*
* @param tenantIds

Loading…
Cancel
Save