唯一验证优化

v1.4.1
Parker 4 years ago
parent 4f8d0f7fb4
commit 1ae0f06ddc

@ -34,7 +34,7 @@ import org.opsli.api.wrapper.system.options.OptionsModel;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.api.web.sys.options
* @BelongsPackage: org.opsli.api.web.system.options
* @Author: Parker
* @CreateTime: 2021-02-07 18:24:38

@ -33,7 +33,7 @@ import org.springframework.format.annotation.DateTimeFormat;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.api.wrapper.sys.options
* @BelongsPackage: org.opsli.api.wrapper.system.options
* @Author: Parker
* @CreateTime: 2021-02-07 18:24:38

@ -18,7 +18,6 @@ package org.opsli.modulars.creater.column.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.opsli.modulars.creater.column.entity.CreaterTableColumn;
import org.opsli.modulars.creater.table.entity.CreaterTable;
/**
@ -30,11 +29,6 @@ import org.opsli.modulars.creater.table.entity.CreaterTable;
@Mapper
public interface TableColumnMapper extends BaseMapper<CreaterTableColumn> {
/**
*
* @param entity
* @return
*/
Integer uniqueVerificationByFieldName(CreaterTableColumn entity);
}

@ -3,18 +3,4 @@
<mapper namespace="org.opsli.modulars.creater.column.mapper.TableColumnMapper">
<select id="uniqueVerificationByFieldName" resultType="Integer">
select
count(0)
from
creater_table_column a
<where>
a.field_name = #{fieldName}
and table_id = #{tableId}
<if test="id != null and id != ''">
and a.id != #{id}
</if>
</where>
</select>
</mapper>

@ -17,13 +17,13 @@ package org.opsli.modulars.creater.column.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.opsli.core.utils.ValidationUtil;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.creater.exception.CreaterException;
import org.opsli.core.creater.msg.CreaterMsg;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.utils.ValidationUtil;
import org.opsli.modulars.creater.column.entity.CreaterTableColumn;
import org.opsli.modulars.creater.column.mapper.TableColumnMapper;
import org.opsli.modulars.creater.column.service.ITableColumnService;
@ -58,9 +58,8 @@ public class TableColumnServiceImpl extends CrudServiceImpl<TableColumnMapper, C
return null;
}
CreaterTableColumn entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByFieldName(entity);
Integer count = this.uniqueVerificationByFieldName(model);
if(count != null && count > 0){
// 重复
throw new CreaterException(CreaterMsg.EXCEPTION_TABLE_COLUMN_FIELD_NAME_REPEAT);
@ -88,8 +87,7 @@ public class TableColumnServiceImpl extends CrudServiceImpl<TableColumnMapper, C
ValidationUtil.verify(model);
// 唯一验证
CreaterTableColumn entity = super.transformM2T(model);
Integer count = mapper.uniqueVerificationByFieldName(entity);
Integer count = this.uniqueVerificationByFieldName(model);
if(count != null && count > 0){
// 重复
throw new CreaterException(CreaterMsg.EXCEPTION_TABLE_COLUMN_FIELD_NAME_REPEAT);
@ -121,9 +119,8 @@ public class TableColumnServiceImpl extends CrudServiceImpl<TableColumnMapper, C
return null;
}
CreaterTableColumn entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByFieldName(entity);
Integer count = this.uniqueVerificationByFieldName(model);
if(count != null && count > 0){
// 重复
throw new CreaterException(CreaterMsg.EXCEPTION_TABLE_COLUMN_FIELD_NAME_REPEAT);
@ -172,6 +169,33 @@ public class TableColumnServiceImpl extends CrudServiceImpl<TableColumnMapper, C
}
}
}
// ========================
/**
*
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByFieldName(CreaterTableColumnModel model){
if(model == null){
return null;
}
QueryWrapper<CreaterTableColumn> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq("table_id", model.getTableId())
.eq("field_name", model.getFieldName());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return super.count(wrapper);
}
}

@ -31,12 +31,6 @@ import java.util.List;
@Mapper
public interface TableMapper extends BaseMapper<CreaterTable> {
/**
*
* @param entity
* @return
*/
Integer uniqueVerificationByTableName(CreaterTable entity);
/**
*

@ -3,19 +3,6 @@
<mapper namespace="org.opsli.modulars.creater.table.mapper.TableMapper">
<select id="uniqueVerificationByTableName" resultType="Integer">
select
count(0)
from
creater_table a
<where>
a.table_name = #{tableName}
<if test="id != null and id != ''">
and a.id != #{id}
</if>
</where>
</select>
<select id="findAllByTableName" resultType="String">
select
table_name AS tableName

@ -17,6 +17,9 @@ package org.opsli.modulars.creater.table.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.service.impl.CrudServiceImpl;
@ -67,9 +70,8 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
return null;
}
CreaterTable entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByTableName(entity);
Integer count = this.uniqueVerificationByTableName(model);
if(count != null && count > 0){
// 重复
throw new CreaterException(CreaterMsg.EXCEPTION_TABLE_NAME_REPEAT);
@ -94,9 +96,8 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
return null;
}
CreaterTable entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByTableName(entity);
Integer count = this.uniqueVerificationByTableName(model);
if(count != null && count > 0){
// 重复
throw new CreaterException(CreaterMsg.EXCEPTION_TABLE_NAME_REPEAT);
@ -250,6 +251,32 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
this.insertAny(createrTableModel);
}
}
// =======================
/**
*
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByTableName(CreaterTableModel model){
if(model == null){
return null;
}
QueryWrapper<CreaterTable> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq("table_name", model.getTableName());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return super.count(wrapper);
}
}

@ -20,20 +20,18 @@ 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.enums.DictType;
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.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;
@ -153,7 +151,7 @@ public class SysAreaServiceImpl extends CrudServiceImpl<SysAreaMapper, SysArea,
QueryWrapper<SysArea> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("area_code", model.getAreaCode());
// 重复校验排除自身
@ -180,7 +178,7 @@ public class SysAreaServiceImpl extends CrudServiceImpl<SysAreaMapper, SysArea,
QueryWrapper<SysArea> wrapper = new QueryWrapper<>();
wrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentIds)
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.groupBy(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID));
return mapper.hasChildren(wrapper);

@ -29,11 +29,5 @@ import org.opsli.modulars.system.dict.entity.SysDictDetail;
@Mapper
public interface DictDetailMapper extends BaseMapper<SysDictDetail> {
/**
*
* @param entity
* @return
*/
Integer uniqueVerificationByNameOrValue(SysDictDetail entity);
}

@ -29,11 +29,5 @@ import org.opsli.modulars.system.dict.entity.SysDict;
@Mapper
public interface DictMapper extends BaseMapper<SysDict> {
/**
*
* @param entity
* @return
*/
Integer uniqueVerificationByCode(SysDict entity);
}

@ -2,44 +2,4 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.opsli.modulars.system.dict.mapper.DictDetailMapper">
<!-- 数据库字段 -->
<sql id="SysDictDetailColumns">
a.id as id,
a.type_id as typeId,
a.type_code as typeCode,
a.dict_name as dictName,
a.dict_value as dictValue,
a.iz_lock as izLock,
a.sort_no as sortNo,
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="SysDictDetailJoins">
</sql>
<select id="uniqueVerificationByNameOrValue" parameterType="SysDictDetail" resultType="Integer">
select count(0)
from sys_dict_detail a
where
(
a.dict_name = #{dictName}
or
a.dict_value = #{dictValue}
)
and a.type_code = #{typeCode}
and a.deleted = 0
<if test="id != null and id != ''">
and a.id != #{id}
</if>
</select>
</mapper>

@ -2,35 +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.dict.mapper.DictMapper">
<!-- 数据库字段 -->
<sql id="SysDictColumns">
a.id as id,
a.type_code as dictTypeCode,
a.type_name as dictTypeName,
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="SysDictJoins">
</sql>
<select id="uniqueVerificationByCode" parameterType="SysDict" resultType="Integer">
select count(0)
from sys_dict a
where
a.type_code = #{typeCode}
and a.deleted = 0
<if test="id != null and id != ''">
AND a.id != #{id}
</if>
</select>
</mapper>

@ -24,6 +24,7 @@ import org.opsli.api.wrapper.system.dict.DictDetailModel;
import org.opsli.api.wrapper.system.dict.DictModel;
import org.opsli.api.wrapper.system.dict.DictWrapper;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.core.base.service.impl.CrudServiceImpl;
@ -72,9 +73,8 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
@Override
public DictDetailModel insert(DictDetailModel model) {
SysDictDetail entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByNameOrValue(entity);
Integer count = this.uniqueVerificationByNameOrValue(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_DICT_DETAIL_UNIQUE);
@ -116,9 +116,8 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
@Override
public DictDetailModel update(DictDetailModel model) {
SysDictDetail entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByNameOrValue(entity);
Integer count = this.uniqueVerificationByNameOrValue(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_DICT_DETAIL_UNIQUE);
@ -397,6 +396,35 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
}
/**
*
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByNameOrValue(DictDetailModel model){
if(model == null){
return null;
}
QueryWrapper<SysDictDetail> wrapper = new QueryWrapper<>();
// name 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("type_code", model.getTypeCode());
// 名称 或者 Val 重复
wrapper.and(wra ->
wra.eq("dict_name",
model.getDictName()).or().eq("dict_value", model.getDictValue()));
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return super.count(wrapper);
}
// ================
/**

@ -15,9 +15,12 @@
*/
package org.opsli.modulars.system.dict.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.dict.DictDetailModel;
import org.opsli.api.wrapper.system.dict.DictModel;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.modulars.system.SystemMsg;
@ -54,9 +57,8 @@ public class DictServiceImpl extends CrudServiceImpl<DictMapper, SysDict, DictMo
return null;
}
SysDict entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_DICT_UNIQUE);
@ -72,9 +74,8 @@ public class DictServiceImpl extends CrudServiceImpl<DictMapper, SysDict, DictMo
return null;
}
SysDict entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByCode(entity);
Integer count = this.uniqueVerificationByCode(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_DICT_UNIQUE);
@ -156,6 +157,33 @@ public class DictServiceImpl extends CrudServiceImpl<DictMapper, SysDict, DictMo
// 删除自身数据
return super.deleteAll(models);
}
// ==============================
/**
*
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByCode(DictModel model){
if(model == null){
return null;
}
QueryWrapper<SysDict> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("type_code", model.getTypeCode());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return super.count(wrapper);
}
}

@ -19,9 +19,9 @@ 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.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.core.base.service.impl.CrudServiceImpl;
@ -31,7 +31,6 @@ 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;
@ -167,7 +166,7 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
QueryWrapper<SysMenu> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("menu_code", model.getMenuCode());
// 重复校验排除自身

@ -27,7 +27,7 @@ import org.opsli.core.base.entity.BaseEntity;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.sys.options.entity
* @BelongsPackage: org.opsli.modulars.system.options.entity
* @Author: Parker
* @CreateTime: 2021-02-07 18:24:38
* @Description:

@ -27,7 +27,7 @@ import org.opsli.modulars.system.options.entity.SysOptions;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.sys.options.mapper
* @BelongsPackage: org.opsli.modulars.system.options.mapper
* @Author: Parker
* @CreateTime: 2021-02-07 18:24:38

@ -1,6 +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.sys.options.mapper.SysOptionsMapper">
<mapper namespace="org.opsli.modulars.system.options.mapper.SysOptionsMapper">

@ -28,7 +28,7 @@ import org.opsli.api.wrapper.system.options.OptionsModel;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.sys.options.service
* @BelongsPackage: org.opsli.modulars.system.options.service
* @Author: Parker
* @CreateTime: 2021-02-07 18:24:38

@ -42,7 +42,7 @@ import java.util.List;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.sys.options.service.impl
* @BelongsPackage: org.opsli.modulars.system.options.service.impl
* @Author: Parker
* @CreateTime: 2021-02-07 18:24:38

@ -46,7 +46,7 @@ import java.lang.reflect.Method;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.sys.options.web
* @BelongsPackage: org.opsli.modulars.system.options.web
* @CreateTime: 2021-02-07 18:24:38
* @Description: Controller
*

@ -23,6 +23,7 @@ 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.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.core.base.entity.HasChildren;
@ -230,7 +231,7 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
return null;
}
QueryWrapper<SysOrg> wrapper = new QueryWrapper<>();
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("org_code", model.getOrgCode());
// 重复校验排除自身
@ -259,7 +260,7 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
QueryWrapper<SysOrg> wrapper = new QueryWrapper<>();
wrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentIds)
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.groupBy(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID));
return mapper.hasChildren(wrapper);

@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.role.RoleModel;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.persistence.querybuilder.chain.TenantHandler;
@ -91,7 +92,7 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
QueryWrapper<SysRole> wrapper = new QueryWrapper<>();
// code 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("role_code", model.getRoleCode());
// 重复校验排除自身

@ -20,15 +20,14 @@ 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.enums.DictType;
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;
@ -194,7 +193,7 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
QueryWrapper<SysTenant> wrapper = new QueryWrapper<>();
// name 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0")
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("tenant_name", model.getTenantName());
// 重复校验排除自身

@ -37,20 +37,6 @@ import java.util.List;
@Mapper
public interface UserMapper extends BaseMapper<SysUser> {
/**
* -
* @param entity
* @return
*/
Integer uniqueVerificationByUsername(SysUser entity);
/**
* -
* @param entity
* @return
*/
Integer uniqueVerificationByNo(SysUser entity);
/**
* ID

@ -51,33 +51,6 @@
</where>
</select>
<select id="uniqueVerificationByUsername" parameterType="SysUser" resultType="Integer">
select
count(0)
from
sys_user a
where
a.username = #{username}
and a.deleted = 0
<if test="id != null and id != ''">
AND a.id != #{id}
</if>
</select>
<select id="uniqueVerificationByNo" parameterType="SysUser" resultType="Integer">
select
count(0)
from
sys_user a
where
a.no = #{no}
and a.deleted = 0
<if test="id != null and id != ''">
AND a.id != #{id}
</if>
</select>
<select id="queryAllPerms" resultType="String">
select
a.menu_code

@ -19,15 +19,16 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
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;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.common.utils.WrapperUtil;
@ -71,15 +72,14 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
return null;
}
SysUser entity = super.transformM2T(model);
// 唯一验证
Integer count = mapper.uniqueVerificationByUsername(entity);
Integer count = this.uniqueVerificationByName(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_USER_UNIQUE);
}
// 唯一验证 - 工号
count = mapper.uniqueVerificationByNo(entity);
count = this.uniqueVerificationByNo(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_USER_NO_UNIQUE);
@ -102,6 +102,14 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
);
}
// 如果手机号有变化 则强制覆盖手机号
if(StringUtils.isNotEmpty(model.getMobile())){
UpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("mobile", null);
updateWrapper.eq("mobile", model.getMobile());
this.update(updateWrapper);
}
return super.insert(model);
}
@ -112,20 +120,21 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
return null;
}
SysUser entity = super.transformM2T(model);
// 唯一验证 - 用户名
Integer count = mapper.uniqueVerificationByUsername(entity);
Integer count = this.uniqueVerificationByName(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_USER_UNIQUE);
}
// 唯一验证 - 工号
count = mapper.uniqueVerificationByNo(entity);
count = this.uniqueVerificationByNo(model);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_USER_NO_UNIQUE);
}
UserModel userModel = super.get(model);
// 防止非法操作 - 不允许直接操控到 关键数据
// 需要注意的是 不要轻易改修改策略
model.setUsername(null);
@ -133,9 +142,16 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
model.setSecretkey(null);
model.setLoginIp(null);
UserModel userModel = super.get(model);
UserModel update = super.update(model);
if(update != null){
// 如果手机号有变化 则强制覆盖手机号
if(!StringUtils.equals(userModel.getMobile(), update.getMobile())){
UpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("mobile", null);
updateWrapper.eq("mobile", update.getMobile());
this.update(updateWrapper);
}
// 刷新用户缓存
this.clearCache(Collections.singletonList(userModel));
}
@ -444,6 +460,54 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
/**
*
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByNo(UserModel model){
if(model == null){
return null;
}
QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
// no 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("no", model.getNo());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return super.count(wrapper);
}
/**
*
* @param model model
* @return Integer
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByName(UserModel model){
if(model == null){
return null;
}
QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
// name 唯一
wrapper.eq(MyBatisConstants.FIELD_DELETE_LOGIC, DictType.NO_YES_NO.getCode())
.eq("username", model.getUsername());
// 重复校验排除自身
if(StringUtils.isNotEmpty(model.getId())){
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
return super.count(wrapper);
}
// ==================
/**

Loading…
Cancel
Save