5个模块重构保存代码:取消自增主键,使用雪花算法
This commit is contained in:
parent
c23d23159a
commit
a17df59f45
@ -86,8 +86,8 @@ public class SysConfigController extends BaseController {
|
||||
if (!configService.checkConfigKeyUnique(config)) {
|
||||
return R.fail("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||
}
|
||||
int insertedRows = configService.insertConfig(config);
|
||||
if (insertedRows != 1) {
|
||||
boolean inserted = configService.insertConfig(config);
|
||||
if (!inserted) {
|
||||
return R.fail("新增参数记录失败!");
|
||||
}
|
||||
return R.ok();
|
||||
|
@ -85,8 +85,8 @@ public class SysDeptController extends BaseController {
|
||||
if (!deptService.checkDeptNameUnique(dept)) {
|
||||
return R.fail("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
||||
}
|
||||
int inserted = deptService.insertDept(dept);
|
||||
if (inserted != 1) {
|
||||
boolean inserted = deptService.insertDept(dept);
|
||||
if (!inserted) {
|
||||
return R.fail("新增部门记录失败!");
|
||||
}
|
||||
return R.ok();
|
||||
|
@ -91,8 +91,8 @@ public class SysDictDataController extends BaseController {
|
||||
@Log(title = "字典数据", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public R<Void> add(@Validated @RequestBody SysDictDataBo dictDataBo) {
|
||||
int insertedRows = dictDataService.insertDictData(dictDataBo);
|
||||
if (insertedRows == 0) {
|
||||
boolean inserted = dictDataService.insertDictData(dictDataBo);
|
||||
if (!inserted) {
|
||||
return R.fail("新增字典数据记录失败!");
|
||||
}
|
||||
return R.ok();
|
||||
|
@ -63,8 +63,8 @@ public class SysNoticeController extends BaseController
|
||||
@PostMapping
|
||||
public R<Void> add(@Validated @RequestBody SysNoticeBo noticeBo)
|
||||
{
|
||||
int insertedRows = noticeService.insertNotice(noticeBo);
|
||||
if (insertedRows != 1) {
|
||||
boolean inserted = noticeService.insertNotice(noticeBo);
|
||||
if (!inserted) {
|
||||
return R.fail("新增通知公告记录失败!");
|
||||
}
|
||||
return R.ok();
|
||||
|
@ -85,8 +85,8 @@ public class SysPostController extends BaseController
|
||||
{
|
||||
return R.fail("新增岗位'" + postBo.getPostName() + "'失败,岗位编码已存在");
|
||||
}
|
||||
int insertedRows = postService.insertPost(postBo);
|
||||
if (insertedRows != 1) {
|
||||
boolean inserted = postService.insertPost(postBo);
|
||||
if (!inserted) {
|
||||
return R.fail("新增岗位记录失败!");
|
||||
}
|
||||
return R.ok();
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import com.mybatisflex.core.keygen.KeyGenerators;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.ruoyi.common.orm.core.domain.BaseEntity;
|
||||
@ -21,11 +19,7 @@ public class SysConfig extends BaseEntity
|
||||
{
|
||||
|
||||
/** 参数主键 */
|
||||
// @Id(keyType = KeyType.Generator, value = KeyGenerators.snowFlakeId) //TODO:ID主键修改为雪花算法
|
||||
// @Id(keyType = KeyType.Generator, value = KeyGenerators.flexId)
|
||||
//@Id
|
||||
//@Excel(name = "参数主键", cellType = ColumnType.NUMERIC)
|
||||
@Id(keyType = KeyType.Auto)
|
||||
@Id
|
||||
private Long configId;
|
||||
|
||||
/** 参数名称 */
|
||||
|
@ -29,7 +29,7 @@ public class SysDept extends BaseEntity
|
||||
{
|
||||
|
||||
/** 部门ID */
|
||||
@Id(keyType = KeyType.Auto)
|
||||
@Id
|
||||
private Long deptId;
|
||||
|
||||
/** 父部门ID */
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -19,7 +18,7 @@ import com.ruoyi.common.orm.core.domain.BaseEntity;
|
||||
public class SysDictData extends BaseEntity
|
||||
{
|
||||
/** 字典编码 */
|
||||
@Id(keyType = KeyType.Auto)
|
||||
@Id
|
||||
private Long dictCode;
|
||||
|
||||
/** 字典排序 */
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -18,7 +17,7 @@ import com.ruoyi.common.orm.core.domain.BaseEntity;
|
||||
public class SysDictType extends BaseEntity
|
||||
{
|
||||
/** 字典主键 */
|
||||
@Id(keyType = KeyType.Auto)
|
||||
@Id
|
||||
private Long dictId;
|
||||
|
||||
/** 字典名称 */
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -18,7 +17,7 @@ import com.ruoyi.common.orm.core.domain.BaseEntity;
|
||||
public class SysNotice extends BaseEntity
|
||||
{
|
||||
/** 公告ID */
|
||||
@Id(keyType = KeyType.Auto)
|
||||
@Id
|
||||
private Long noticeId;
|
||||
|
||||
/** 公告标题 */
|
||||
|
@ -2,21 +2,11 @@ package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
||||
import com.ruoyi.common.orm.core.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 岗位表 sys_post
|
||||
*
|
||||
@ -28,7 +18,7 @@ import java.io.Serial;
|
||||
public class SysPost extends BaseEntity
|
||||
{
|
||||
/** 岗位序号 */
|
||||
@Id(keyType = KeyType.Auto)
|
||||
@Id
|
||||
private Long postId;
|
||||
|
||||
/** 岗位编码 */
|
||||
|
@ -59,9 +59,9 @@ public interface ISysConfigService extends IBaseService<SysConfig>
|
||||
* 新增参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
int insertConfig(SysConfigBo config);
|
||||
boolean insertConfig(SysConfigBo config);
|
||||
|
||||
/**
|
||||
* 修改参数配置
|
||||
|
@ -90,9 +90,9 @@ public interface ISysDeptService extends IBaseService<SysDept>
|
||||
* 新增保存部门信息
|
||||
*
|
||||
* @param deptBo 部门信息
|
||||
* @return 受影响的行数
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
int insertDept(SysDeptBo deptBo);
|
||||
boolean insertDept(SysDeptBo deptBo);
|
||||
|
||||
/**
|
||||
* 修改保存部门信息
|
||||
|
@ -77,9 +77,9 @@ public interface ISysDictDataService extends IBaseService<SysDictData>
|
||||
* 新增保存字典数据信息
|
||||
*
|
||||
* @param dataBo 字典数据信息
|
||||
* @return 结果:受影响的行数
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
int insertDictData(SysDictDataBo dataBo);
|
||||
boolean insertDictData(SysDictDataBo dataBo);
|
||||
|
||||
/**
|
||||
* 修改保存字典数据信息
|
||||
|
@ -43,9 +43,9 @@ public interface ISysNoticeService extends IBaseService<SysNotice>
|
||||
* 新增公告
|
||||
*
|
||||
* @param noticeBo 公告信息
|
||||
* @return 结果:受影响的行数
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
int insertNotice(SysNoticeBo noticeBo);
|
||||
boolean insertNotice(SysNoticeBo noticeBo);
|
||||
|
||||
/**
|
||||
* 修改公告
|
||||
|
@ -98,9 +98,9 @@ public interface ISysPostService extends IBaseService<SysPost>
|
||||
* 新增保存岗位信息
|
||||
*
|
||||
* @param post 岗位信息
|
||||
* @return 结果
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
int insertPost(SysPostBo post);
|
||||
boolean insertPost(SysPostBo post);
|
||||
|
||||
/**
|
||||
* 修改保存岗位信息
|
||||
|
@ -5,8 +5,6 @@ import java.util.List;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.ruoyi.common.core.constant.CacheNames;
|
||||
import com.ruoyi.common.core.core.page.PageDomain;
|
||||
import com.ruoyi.common.core.core.page.TableSupport;
|
||||
import com.ruoyi.common.core.service.ConfigService;
|
||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
@ -40,8 +38,6 @@ import static com.ruoyi.system.domain.table.SysConfigTableDef.SYS_CONFIG;
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysConfigServiceImpl extends BaseServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService, ConfigService {
|
||||
@Resource
|
||||
private SysConfigMapper configMapper;
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
@ -148,19 +144,13 @@ public class SysConfigServiceImpl extends BaseServiceImpl<SysConfigMapper, SysCo
|
||||
* 新增参数配置
|
||||
*
|
||||
* @param configBo 参数配置信息
|
||||
* @return 插入行数
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_CONFIG, key = "#configBo.configKey")
|
||||
@Override
|
||||
public int insertConfig(SysConfigBo configBo) {
|
||||
public boolean insertConfig(SysConfigBo configBo) {
|
||||
SysConfig sysConfig = MapstructUtils.convert(configBo, SysConfig.class);
|
||||
//boolean ret = this.save(sysConfig);
|
||||
//int ret = this.getMapper().insert(sysConfig,false);
|
||||
//return this.getMapper().insertSelective(sysConfig);
|
||||
//return configMapper.insertSelective(sysConfig);
|
||||
int ret=configMapper.insert(sysConfig,false);
|
||||
//boolean saved = this.save(sysConfig);
|
||||
return ret;
|
||||
return this.save(sysConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,10 +244,10 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptMapper, SysDept>
|
||||
* 新增保存部门信息
|
||||
*
|
||||
* @param deptBo 部门信息
|
||||
* @return 受影响的行数
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
@Override
|
||||
public int insertDept(SysDeptBo deptBo) {
|
||||
public boolean insertDept(SysDeptBo deptBo) {
|
||||
SysDeptVo info = selectDeptById(deptBo.getParentId());
|
||||
// 如果父节点不为正常状态,则不允许新增子节点
|
||||
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
||||
@ -256,7 +256,7 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptMapper, SysDept>
|
||||
SysDept dept = MapstructUtils.convert(deptBo, SysDept.class);
|
||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
||||
dept.setDelFlag("0");//0代表存在
|
||||
return deptMapper.insert(dept, false);
|
||||
return this.save(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,14 +172,14 @@ public class SysDictDataServiceImpl extends BaseServiceImpl<SysDictDataMapper, S
|
||||
* 新增保存字典数据信息
|
||||
*
|
||||
* @param dataBo 字典数据信息
|
||||
* @return 结果:受影响的行数
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_DICT, key = "#dataBo.dictType")
|
||||
@Override
|
||||
public int insertDictData(SysDictDataBo dataBo)
|
||||
public boolean insertDictData(SysDictDataBo dataBo)
|
||||
{
|
||||
SysDictData data = MapstructUtils.convert(dataBo, SysDictData.class);
|
||||
return dictDataMapper.insert(data,false);
|
||||
return this.save(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,9 +48,6 @@ import static com.ruoyi.system.domain.table.SysDictTypeTableDef.SYS_DICT_TYPE;
|
||||
@Service
|
||||
public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService, DictService
|
||||
{
|
||||
@Resource
|
||||
private SysDictTypeMapper dictTypeMapper;
|
||||
|
||||
@Resource
|
||||
private ISysDictDataService sysDictDataService;
|
||||
|
||||
@ -204,8 +201,8 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeMapper, S
|
||||
public List<SysDictDataVo> insertDictType(SysDictTypeBo sysDictTypeBo)
|
||||
{
|
||||
SysDictType dict = MapstructUtils.convert(sysDictTypeBo, SysDictType.class);
|
||||
int row = dictTypeMapper.insert(dict,false);
|
||||
if (row > 0)
|
||||
boolean saved = this.save(dict);
|
||||
if (saved)
|
||||
{
|
||||
// 新增 type 下无 data 数据 返回空防止缓存穿透
|
||||
return new ArrayList<>();
|
||||
|
@ -108,13 +108,12 @@ public class SysNoticeServiceImpl extends BaseServiceImpl<SysNoticeMapper, SysNo
|
||||
* 新增公告
|
||||
*
|
||||
* @param noticeBo 公告信息
|
||||
* @return 受影响的行数
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
@Override
|
||||
public int insertNotice(SysNoticeBo noticeBo) {
|
||||
public boolean insertNotice(SysNoticeBo noticeBo) {
|
||||
SysNotice sysNotice = MapstructUtils.convert(noticeBo, SysNotice.class);
|
||||
int ret = noticeMapper.insert(sysNotice, false);
|
||||
return ret;
|
||||
return this.save(sysNotice);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,13 +216,13 @@ public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost>
|
||||
* 新增保存岗位信息
|
||||
*
|
||||
* @param postBo 岗位信息
|
||||
* @return 结果
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
@Override
|
||||
public int insertPost(SysPostBo postBo)
|
||||
public boolean insertPost(SysPostBo postBo)
|
||||
{
|
||||
SysPost sysPost = MapstructUtils.convert(postBo, SysPost.class);
|
||||
return postMapper.insert(sysPost,false);
|
||||
return this.save(sysPost);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user