去掉id next

This commit is contained in:
sxu 2025-03-21 10:16:12 +08:00
parent 1a49cce3da
commit e208e55147
8 changed files with 472 additions and 473 deletions

View File

@ -1,53 +1,53 @@
package com.bonus.common.core.utils.id;
import com.google.common.base.Preconditions;
import java.time.LocalDateTime;
import java.time.ZoneId;
public class Id {
private static final long EPOCH = LocalDateTime.of(2021, 12, 29, 9, 2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
private static final long SEQUENCE_BITS = 12L;
private static final long WORKER_ID_BITS = 10L;
static final long WORKER_ID_MAX_VALUE = 1024L;
private static final long SEQUENCE_MASK = 4095L;
private static final long WORKER_ID_LEFT_SHIFT_BITS = 12L;
private static final long TIMESTAMP_LEFT_SHIFT_BITS = 22L;
static Long WORKER_ID;
private static long SEQUENCE;
private static long LAST_TIME;
public Id(Long workerId) {
WORKER_ID = workerId;
}
public static long next() {
return nextKey();
}
public static String nextString() {
return String.valueOf(next());
}
private static synchronized long nextKey() {
long currentMillis = System.currentTimeMillis();
Preconditions.checkState(LAST_TIME <= currentMillis, "Clock is moving backwards, last time is %d milliseconds, current time is %d milliseconds", LAST_TIME, currentMillis);
if (LAST_TIME == currentMillis) {
if (0L == (SEQUENCE = SEQUENCE + 1L & 4095L)) {
currentMillis = waitUntilNextTime(currentMillis);
}
} else {
SEQUENCE = 0L;
}
LAST_TIME = currentMillis;
return currentMillis - EPOCH << 22 | WORKER_ID << 12 | SEQUENCE;
}
private static long waitUntilNextTime(final long lastTime) {
long time;
for(time = System.currentTimeMillis(); time <= lastTime; time = System.currentTimeMillis()) {
}
return time;
}
}
//package com.bonus.common.core.utils.id;
//
//import com.google.common.base.Preconditions;
//import java.time.LocalDateTime;
//import java.time.ZoneId;
//
//public class Id {
// private static final long EPOCH = LocalDateTime.of(2021, 12, 29, 9, 2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
// private static final long SEQUENCE_BITS = 12L;
// private static final long WORKER_ID_BITS = 10L;
// static final long WORKER_ID_MAX_VALUE = 1024L;
// private static final long SEQUENCE_MASK = 4095L;
// private static final long WORKER_ID_LEFT_SHIFT_BITS = 12L;
// private static final long TIMESTAMP_LEFT_SHIFT_BITS = 22L;
// static Long WORKER_ID;
// private static long SEQUENCE;
// private static long LAST_TIME;
//
// public Id(Long workerId) {
// WORKER_ID = workerId;
// }
//
// public static long next() {
// return nextKey();
// }
//
// public static String nextString() {
// return String.valueOf(next());
// }
//
// private static synchronized long nextKey() {
// long currentMillis = System.currentTimeMillis();
// Preconditions.checkState(LAST_TIME <= currentMillis, "Clock is moving backwards, last time is %d milliseconds, current time is %d milliseconds", LAST_TIME, currentMillis);
// if (LAST_TIME == currentMillis) {
// if (0L == (SEQUENCE = SEQUENCE + 1L & 4095L)) {
// currentMillis = waitUntilNextTime(currentMillis);
// }
// } else {
// SEQUENCE = 0L;
// }
//
// LAST_TIME = currentMillis;
// return currentMillis - EPOCH << 22 | WORKER_ID << 12 | SEQUENCE;
// }
//
// private static long waitUntilNextTime(final long lastTime) {
// long time;
// for(time = System.currentTimeMillis(); time <= lastTime; time = System.currentTimeMillis()) {
// }
//
// return time;
// }
//}

View File

@ -1,123 +1,123 @@
package com.bonus.common.core.utils.id;
import cn.hutool.core.text.CharSequenceUtil;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.UUID;
@Component
@ConditionalOnClass({StringRedisTemplate.class})
@EnableConfigurationProperties({IdProperties.class})
@ConditionalOnProperty(
prefix = "id",
name = {"enabled"},
havingValue = "true",
matchIfMissing = true
)
public class IdWorkConfiguration {
private static final Logger log = LoggerFactory.getLogger(IdWorkConfiguration.class);
private final IdProperties idProperties;
public IdWorkConfiguration(StringRedisTemplate redisTemplate, IdProperties idProperties) throws IOException {
this.idProperties = idProperties;
Long workerId = this.getLocalWorkId();
try {
while(workerId == null) {
Long newWorkId = redisTemplate.opsForValue().increment(idProperties.getKey(), 1L);
this.saveLocalWorkId(String.valueOf(newWorkId));
workerId = this.getLocalWorkId();
}
} catch (Throwable var5) {
log.error("获取workID失败", var5);
throw var5;
}
if (workerId > 1024L) {
throw new RuntimeException("超过最大启动实例");
} else {
Id.WORKER_ID = workerId;
}
}
private void saveLocalWorkId(String workId) throws IOException {
File workIdHome = this.getWorkIdHome();
String var10002 = String.valueOf(workIdHome.getAbsoluteFile());
FileUtils.writeStringToFile(new File(var10002 + "/" + String.valueOf(UUID.randomUUID()) + ".lock"), workId, StandardCharsets.UTF_8);
}
private File getWorkIdHome() {
String workHome = this.idProperties.getWorkspace();
if (CharSequenceUtil.isBlank(workHome)) {
workHome = FileUtils.getUserDirectoryPath() + "/.workId/";
}
String var10002 = CharSequenceUtil.removeSuffix(workHome, "/");
return new File(var10002 + "/" + this.idProperties.getKey());
}
private Long getLocalWorkId() throws IOException {
File workIdHome = this.getWorkIdHome();
if (!workIdHome.exists()) {
return null;
}
Collection<File> files = FileUtils.listFiles(workIdHome, new String[]{"lock"}, false);
if (CollectionUtils.isEmpty(files)) {
return null;
}
for (File file : files) {
FileChannel channel = null;
FileLock fileLock = null;
try {
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
channel = randomAccessFile.getChannel();
fileLock = channel.tryLock();
if (fileLock != null) { // 成功获取文件锁
Long workId = Long.valueOf(randomAccessFile.readLine());
releaseResourcesOnShutdown(channel);
return workId;
}
} catch (IOException e) {
log.error("Error accessing workId file", e);
} finally {
if (fileLock == null && channel != null) {
try {
channel.close();
} catch (IOException e) {
log.error("Failed to close file channel", e);
}
}
}
}
return null;
}
private void releaseResourcesOnShutdown(FileChannel channel) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
channel.close();
} catch (IOException e) {
log.error("Release WorkId file lock error", e);
}
}));
}
}
//package com.bonus.common.core.utils.id;
//
//import cn.hutool.core.text.CharSequenceUtil;
//import org.apache.commons.io.FileUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.io.File;
//import java.io.IOException;
//import java.io.RandomAccessFile;
//import java.nio.channels.FileChannel;
//import java.nio.channels.FileLock;
//import java.nio.charset.StandardCharsets;
//import java.util.Collection;
//import java.util.UUID;
//
//@Component
//@ConditionalOnClass({StringRedisTemplate.class})
//@EnableConfigurationProperties({IdProperties.class})
//@ConditionalOnProperty(
// prefix = "id",
// name = {"enabled"},
// havingValue = "true",
// matchIfMissing = true
//)
//public class IdWorkConfiguration {
// private static final Logger log = LoggerFactory.getLogger(IdWorkConfiguration.class);
// private final IdProperties idProperties;
//
// public IdWorkConfiguration(StringRedisTemplate redisTemplate, IdProperties idProperties) throws IOException {
// this.idProperties = idProperties;
// Long workerId = this.getLocalWorkId();
//
// try {
// while(workerId == null) {
// Long newWorkId = redisTemplate.opsForValue().increment(idProperties.getKey(), 1L);
// this.saveLocalWorkId(String.valueOf(newWorkId));
// workerId = this.getLocalWorkId();
// }
// } catch (Throwable var5) {
// log.error("获取workID失败", var5);
// throw var5;
// }
//
// if (workerId > 1024L) {
// throw new RuntimeException("超过最大启动实例");
// } else {
// Id.WORKER_ID = workerId;
// }
// }
//
// private void saveLocalWorkId(String workId) throws IOException {
// File workIdHome = this.getWorkIdHome();
// String var10002 = String.valueOf(workIdHome.getAbsoluteFile());
// FileUtils.writeStringToFile(new File(var10002 + "/" + String.valueOf(UUID.randomUUID()) + ".lock"), workId, StandardCharsets.UTF_8);
// }
//
// private File getWorkIdHome() {
// String workHome = this.idProperties.getWorkspace();
// if (CharSequenceUtil.isBlank(workHome)) {
// workHome = FileUtils.getUserDirectoryPath() + "/.workId/";
// }
//
// String var10002 = CharSequenceUtil.removeSuffix(workHome, "/");
// return new File(var10002 + "/" + this.idProperties.getKey());
// }
//
// private Long getLocalWorkId() throws IOException {
// File workIdHome = this.getWorkIdHome();
// if (!workIdHome.exists()) {
// return null;
// }
//
// Collection<File> files = FileUtils.listFiles(workIdHome, new String[]{"lock"}, false);
// if (CollectionUtils.isEmpty(files)) {
// return null;
// }
//
// for (File file : files) {
// FileChannel channel = null;
// FileLock fileLock = null;
//
// try {
// RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
// channel = randomAccessFile.getChannel();
// fileLock = channel.tryLock();
//
// if (fileLock != null) { // 成功获取文件锁
// Long workId = Long.valueOf(randomAccessFile.readLine());
// releaseResourcesOnShutdown(channel);
// return workId;
// }
// } catch (IOException e) {
// log.error("Error accessing workId file", e);
// } finally {
// if (fileLock == null && channel != null) {
// try {
// channel.close();
// } catch (IOException e) {
// log.error("Failed to close file channel", e);
// }
// }
// }
// }
// return null;
// }
//
// private void releaseResourcesOnShutdown(FileChannel channel) {
// Runtime.getRuntime().addShutdownHook(new Thread(() -> {
// try {
// channel.close();
// } catch (IOException e) {
// log.error("Release WorkId file lock error", e);
// }
// }));
// }
//}

View File

@ -1,10 +1,10 @@
package com.bonus.system.config;
import com.bonus.common.core.utils.id.IdWorkConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({IdWorkConfiguration.class})
public class CommonConfiguration {
}
//package com.bonus.system.config;
//
//import com.bonus.common.core.utils.id.IdWorkConfiguration;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Import;
//
//@Configuration
//@Import({IdWorkConfiguration.class})
//public class CommonConfiguration {
//}

View File

@ -1,112 +1,112 @@
package com.bonus.system.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.bonus.common.log.enums.OperaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.system.domain.AllocArea;
import com.bonus.system.service.IAllocAreaService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.page.TableDataInfo;
/**
* 区域Controller
*
* @author xsheng
* @date 2025-02-18
*/
@Api(tags = "区域接口")
@RestController
@RequestMapping("/alloc_area")
public class AllocAreaController extends BaseController {
@Autowired
private IAllocAreaService sysAllocAreaService;
/**
* 查询区域列表
*/
@ApiOperation(value = "查询区域列表")
@RequiresPermissions("system:area:list")
@GetMapping("/list")
public TableDataInfo list(AllocArea sysAllocArea) {
startPage();
List<AllocArea> list = sysAllocAreaService.selectAllocAreaList(sysAllocArea);
return getDataTable(list);
}
/**
* 导出区域列表
*/
@ApiOperation(value = "导出区域列表")
@RequiresPermissions("system:area:export")
@SysLog(title = "区域", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出区域")
@PostMapping("/export")
public void export(HttpServletResponse response, AllocArea sysAllocArea) {
List<AllocArea> list = sysAllocAreaService.selectAllocAreaList(sysAllocArea);
ExcelUtil<AllocArea> util = new ExcelUtil<AllocArea>(AllocArea.class);
util.exportExcel(response, list, "区域数据");
}
/**
* 获取区域详细信息
*/
@ApiOperation(value = "获取区域详细信息")
@RequiresPermissions("system:area:query")
@GetMapping(value = "/{areaId}")
public AjaxResult getInfo(@PathVariable("areaId") Long areaId) {
return success(sysAllocAreaService.selectAllocAreaByAreaId(areaId));
}
/**
* 新增区域
*/
@ApiOperation(value = "新增区域")
@RequiresPermissions("system:area:add")
@SysLog(title = "区域", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增区域")
@PostMapping
public AjaxResult add(@RequestBody AllocArea sysAllocArea) {
try {
return toAjax(sysAllocAreaService.insertAllocArea(sysAllocArea));
} catch (Exception e) {
return error("系统错误, " + e.getMessage());
}
}
/**
* 修改区域
*/
@ApiOperation(value = "修改区域")
@RequiresPermissions("system:area:edit")
@SysLog(title = "区域", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改区域")
@PostMapping("/edit")
public AjaxResult edit(@RequestBody AllocArea sysAllocArea) {
try {
return toAjax(sysAllocAreaService.updateAllocArea(sysAllocArea));
} catch (Exception e) {
return error("系统错误, " + e.getMessage());
}
}
/**
* 删除区域
*/
@ApiOperation(value = "删除区域")
@RequiresPermissions("system:area:remove")
@SysLog(title = "区域", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除区域")
@PostMapping("/del/{areaIds}")
public AjaxResult remove(@PathVariable Long[] areaIds) {
return toAjax(sysAllocAreaService.deleteAllocAreaByAreaIds(areaIds));
}
}
//package com.bonus.system.controller;
//
//import java.util.List;
//import javax.servlet.http.HttpServletResponse;
//import com.bonus.common.log.enums.OperaType;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import com.bonus.common.log.annotation.SysLog;
//import com.bonus.common.security.annotation.RequiresPermissions;
//import com.bonus.system.domain.AllocArea;
//import com.bonus.system.service.IAllocAreaService;
//import com.bonus.common.core.web.controller.BaseController;
//import com.bonus.common.core.web.domain.AjaxResult;
//import com.bonus.common.core.utils.poi.ExcelUtil;
//import com.bonus.common.core.web.page.TableDataInfo;
//
///**
// * 区域Controller
// *
// * @author xsheng
// * @date 2025-02-18
// */
//@Api(tags = "区域接口")
//@RestController
//@RequestMapping("/alloc_area")
//public class AllocAreaController extends BaseController {
// @Autowired
// private IAllocAreaService sysAllocAreaService;
//
// /**
// * 查询区域列表
// */
// @ApiOperation(value = "查询区域列表")
// @RequiresPermissions("system:area:list")
// @GetMapping("/list")
// public TableDataInfo list(AllocArea sysAllocArea) {
// startPage();
// List<AllocArea> list = sysAllocAreaService.selectAllocAreaList(sysAllocArea);
// return getDataTable(list);
// }
//
// /**
// * 导出区域列表
// */
// @ApiOperation(value = "导出区域列表")
// @RequiresPermissions("system:area:export")
// @SysLog(title = "区域", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出区域")
// @PostMapping("/export")
// public void export(HttpServletResponse response, AllocArea sysAllocArea) {
// List<AllocArea> list = sysAllocAreaService.selectAllocAreaList(sysAllocArea);
// ExcelUtil<AllocArea> util = new ExcelUtil<AllocArea>(AllocArea.class);
// util.exportExcel(response, list, "区域数据");
// }
//
// /**
// * 获取区域详细信息
// */
// @ApiOperation(value = "获取区域详细信息")
// @RequiresPermissions("system:area:query")
// @GetMapping(value = "/{areaId}")
// public AjaxResult getInfo(@PathVariable("areaId") Long areaId) {
// return success(sysAllocAreaService.selectAllocAreaByAreaId(areaId));
// }
//
// /**
// * 新增区域
// */
// @ApiOperation(value = "新增区域")
// @RequiresPermissions("system:area:add")
// @SysLog(title = "区域", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增区域")
// @PostMapping
// public AjaxResult add(@RequestBody AllocArea sysAllocArea) {
// try {
// return toAjax(sysAllocAreaService.insertAllocArea(sysAllocArea));
// } catch (Exception e) {
// return error("系统错误, " + e.getMessage());
// }
// }
//
// /**
// * 修改区域
// */
// @ApiOperation(value = "修改区域")
// @RequiresPermissions("system:area:edit")
// @SysLog(title = "区域", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改区域")
// @PostMapping("/edit")
// public AjaxResult edit(@RequestBody AllocArea sysAllocArea) {
// try {
// return toAjax(sysAllocAreaService.updateAllocArea(sysAllocArea));
// } catch (Exception e) {
// return error("系统错误, " + e.getMessage());
// }
// }
//
// /**
// * 删除区域
// */
// @ApiOperation(value = "删除区域")
// @RequiresPermissions("system:area:remove")
// @SysLog(title = "区域", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除区域")
// @PostMapping("/del/{areaIds}")
// public AjaxResult remove(@PathVariable Long[] areaIds) {
// return toAjax(sysAllocAreaService.deleteAllocAreaByAreaIds(areaIds));
// }
//}

View File

@ -1,60 +1,60 @@
package com.bonus.system.service;
import java.util.List;
import com.bonus.system.domain.AllocArea;
/**
* 区域Service接口
*
* @author xsheng
* @date 2025-02-18
*/
public interface IAllocAreaService {
/**
* 查询区域
*
* @param areaId 区域主键
* @return 区域
*/
public AllocArea selectAllocAreaByAreaId(Long areaId);
/**
* 查询区域列表
*
* @param sysAllocArea 区域
* @return 区域集合
*/
public List<AllocArea> selectAllocAreaList(AllocArea sysAllocArea);
/**
* 新增区域
*
* @param sysAllocArea 区域
* @return 结果
*/
public int insertAllocArea(AllocArea sysAllocArea);
/**
* 修改区域
*
* @param sysAllocArea 区域
* @return 结果
*/
public int updateAllocArea(AllocArea sysAllocArea);
/**
* 批量删除区域
*
* @param areaIds 需要删除的区域主键集合
* @return 结果
*/
public int deleteAllocAreaByAreaIds(Long[] areaIds);
/**
* 删除区域信息
*
* @param areaId 区域主键
* @return 结果
*/
public int deleteAllocAreaByAreaId(Long areaId);
}
//package com.bonus.system.service;
//
//import java.util.List;
//import com.bonus.system.domain.AllocArea;
//
///**
// * 区域Service接口
// *
// * @author xsheng
// * @date 2025-02-18
// */
//public interface IAllocAreaService {
// /**
// * 查询区域
// *
// * @param areaId 区域主键
// * @return 区域
// */
// public AllocArea selectAllocAreaByAreaId(Long areaId);
//
// /**
// * 查询区域列表
// *
// * @param sysAllocArea 区域
// * @return 区域集合
// */
// public List<AllocArea> selectAllocAreaList(AllocArea sysAllocArea);
//
// /**
// * 新增区域
// *
// * @param sysAllocArea 区域
// * @return 结果
// */
// public int insertAllocArea(AllocArea sysAllocArea);
//
// /**
// * 修改区域
// *
// * @param sysAllocArea 区域
// * @return 结果
// */
// public int updateAllocArea(AllocArea sysAllocArea);
//
// /**
// * 批量删除区域
// *
// * @param areaIds 需要删除的区域主键集合
// * @return 结果
// */
// public int deleteAllocAreaByAreaIds(Long[] areaIds);
//
// /**
// * 删除区域信息
// *
// * @param areaId 区域主键
// * @return 结果
// */
// public int deleteAllocAreaByAreaId(Long areaId);
//}

View File

@ -1,109 +1,109 @@
package com.bonus.system.service.impl;
import java.util.List;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.id.Id;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.system.mapper.AllocAreaMapper;
import com.bonus.system.domain.AllocArea;
import com.bonus.system.service.IAllocAreaService;
/**
* 区域Service业务层处理
*
* @author xsheng
* @date 2025-02-18
*/
@Service
public class AllocAreaServiceImpl implements IAllocAreaService {
@Autowired
private AllocAreaMapper allocAreaMapper;
/**
* 查询区域
*
* @param areaId 区域主键
* @return 区域
*/
@Override
public AllocArea selectAllocAreaByAreaId(Long areaId) {
return allocAreaMapper.selectAllocAreaByAreaId(areaId);
}
/**
* 查询区域列表
*
* @param sysAllocArea 区域
* @return 区域
*/
@Override
public List<AllocArea> selectAllocAreaList(AllocArea sysAllocArea) {
return allocAreaMapper.selectAllocAreaList(sysAllocArea);
}
/**
* 新增区域
*
* @param allocArea 区域
* @return 结果
*/
@Override
public int insertAllocArea(AllocArea allocArea) {
allocArea.setCreateTime(DateUtils.getNowDate());
try {
//增加根公司的处理
if (allocArea.getParentId() == null) {
allocArea.setParentId(0L);
allocArea.setAncestors("0");
allocArea.setStatus("0");//默认启用
} else {
AllocArea info = allocAreaMapper.selectAllocAreaByAreaId(allocArea.getParentId());
allocArea.setAncestors(info.getAncestors() + "," + allocArea.getParentId());
}
allocArea.setAreaId(Id.next());
return allocAreaMapper.insertAllocArea(allocArea);
} catch (Exception e) {
throw new ServiceException("新增区域错误" + e.getMessage());
}
}
/**
* 修改区域
*
* @param sysAllocArea 区域
* @return 结果
*/
@Override
public int updateAllocArea(AllocArea sysAllocArea) {
sysAllocArea.setUpdateTime(DateUtils.getNowDate());
try {
return allocAreaMapper.updateAllocArea(sysAllocArea);
} catch (Exception e) {
throw new ServiceException("错误信息描述");
}
}
/**
* 批量删除区域
*
* @param areaIds 需要删除的区域主键
* @return 结果
*/
@Override
public int deleteAllocAreaByAreaIds(Long[] areaIds) {
return allocAreaMapper.deleteAllocAreaByAreaIds(areaIds);
}
/**
* 删除区域信息
*
* @param areaId 区域主键
* @return 结果
*/
@Override
public int deleteAllocAreaByAreaId(Long areaId) {
return allocAreaMapper.deleteAllocAreaByAreaId(areaId);
}
}
//package com.bonus.system.service.impl;
//
//import java.util.List;
//import com.bonus.common.core.exception.ServiceException;
//import com.bonus.common.core.utils.DateUtils;
//import com.bonus.common.core.utils.id.Id;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import com.bonus.system.mapper.AllocAreaMapper;
//import com.bonus.system.domain.AllocArea;
//import com.bonus.system.service.IAllocAreaService;
//
///**
// * 区域Service业务层处理
// *
// * @author xsheng
// * @date 2025-02-18
// */
//@Service
//public class AllocAreaServiceImpl implements IAllocAreaService {
// @Autowired
// private AllocAreaMapper allocAreaMapper;
//
// /**
// * 查询区域
// *
// * @param areaId 区域主键
// * @return 区域
// */
// @Override
// public AllocArea selectAllocAreaByAreaId(Long areaId) {
// return allocAreaMapper.selectAllocAreaByAreaId(areaId);
// }
//
// /**
// * 查询区域列表
// *
// * @param sysAllocArea 区域
// * @return 区域
// */
// @Override
// public List<AllocArea> selectAllocAreaList(AllocArea sysAllocArea) {
// return allocAreaMapper.selectAllocAreaList(sysAllocArea);
// }
//
// /**
// * 新增区域
// *
// * @param allocArea 区域
// * @return 结果
// */
// @Override
// public int insertAllocArea(AllocArea allocArea) {
// allocArea.setCreateTime(DateUtils.getNowDate());
// try {
// //增加根公司的处理
// if (allocArea.getParentId() == null) {
// allocArea.setParentId(0L);
// allocArea.setAncestors("0");
// allocArea.setStatus("0");//默认启用
// } else {
// AllocArea info = allocAreaMapper.selectAllocAreaByAreaId(allocArea.getParentId());
// allocArea.setAncestors(info.getAncestors() + "," + allocArea.getParentId());
// }
// allocArea.setAreaId(Id.next());
// return allocAreaMapper.insertAllocArea(allocArea);
// } catch (Exception e) {
// throw new ServiceException("新增区域错误" + e.getMessage());
// }
// }
//
// /**
// * 修改区域
// *
// * @param sysAllocArea 区域
// * @return 结果
// */
// @Override
// public int updateAllocArea(AllocArea sysAllocArea) {
// sysAllocArea.setUpdateTime(DateUtils.getNowDate());
// try {
// return allocAreaMapper.updateAllocArea(sysAllocArea);
// } catch (Exception e) {
// throw new ServiceException("错误信息描述");
// }
// }
//
// /**
// * 批量删除区域
// *
// * @param areaIds 需要删除的区域主键
// * @return 结果
// */
// @Override
// public int deleteAllocAreaByAreaIds(Long[] areaIds) {
// return allocAreaMapper.deleteAllocAreaByAreaIds(areaIds);
// }
//
// /**
// * 删除区域信息
// *
// * @param areaId 区域主键
// * @return 结果
// */
// @Override
// public int deleteAllocAreaByAreaId(Long areaId) {
// return allocAreaMapper.deleteAllocAreaByAreaId(areaId);
// }
//}

View File

@ -4,7 +4,6 @@ import java.util.*;
import java.util.stream.Collectors;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.id.Id;
import com.bonus.common.core.web.domain.BaseEntity;
import com.bonus.config.SystemConfig;
import com.bonus.system.api.domain.*;

View File

@ -9,7 +9,6 @@ import com.bonus.common.core.utils.SpringUtils;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.utils.bean.BeanValidators;
import com.bonus.common.core.utils.encryption.Sm4Utils;
import com.bonus.common.core.utils.id.Id;
import com.bonus.common.core.utils.sms.SmsUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.domain.BaseEntity;
@ -360,9 +359,9 @@ public class SysUserServiceImpl implements ISysUserService {
@Override
@Transactional(rollbackFor = Exception.class)
public int insertUser(SysUser user) {
user.setCustId(Id.next());
// 新增用户信息
int rows = userMapper.insertUser(user);
user.setCustId(user.getUserId());
// 新增用户岗位关联
insertUserPost(user);
// 新增用户与角色管理
@ -378,8 +377,9 @@ public class SysUserServiceImpl implements ISysUserService {
*/
@Override
public boolean registerUser(SysUser user) {
user.setCustId(Id.next());
return userMapper.insertUser(user) > 0;
int count = userMapper.insertUser(user);
user.setCustId(user.getUserId());
return count > 0;
}
/**
@ -585,7 +585,7 @@ public class SysUserServiceImpl implements ISysUserService {
String password = configService.selectConfigByKey("sys.user.initPassword");
user.setPassword(SecurityUtils.encryptPassword(password));
user.setCreateBy(operName);
user.setCustId(Id.next());
user.setCustId(user.getUserId());
userMapper.insertUser(user);
successNum++;
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");