Java Code Examples for cn.hutool.core.util.IdUtil#createSnowflake()

The following examples show how to use cn.hutool.core.util.IdUtil#createSnowflake() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmsController.java    From hdw-dubbo with Apache License 2.0 6 votes vote down vote up
/**
 * 保存消息信息
 */
@ApiOperation(value = "保存消息信息", notes = "保存消息信息")
@PostMapping("/save")
@RequiresPermissions("sms/sms/save")
public CommonResult save(@Valid @RequestBody SysSms sysSms) {
    try {
        Snowflake snowflake = IdUtil.createSnowflake(1, 1);
        long id = snowflake.nextId();
        sysSms.setId(id);
        sysSms.setCreateTime(new Date());
        sysSms.setCreateUser(ShiroUtil.getUser().getId());
        sysSms.setUpdateTime(new Date());
        sysSms.setUpdateUser(ShiroUtil.getUser().getId());
        smsService.save(sysSms);
        return CommonResult.success("添加成功");
    } catch (Exception e) {
        e.printStackTrace();
        return CommonResult.failed("运行异常,请联系管理员");
    }
}
 
Example 2
Source File: IdConfig.java    From spring-boot-demo with MIT License 4 votes vote down vote up
/**
 * 雪花生成器
 */
@Bean
public Snowflake snowflake() {
    return IdUtil.createSnowflake(1, 1);
}
 
Example 3
Source File: SnowflakeIdFactory.java    From bitchat with Apache License 2.0 4 votes vote down vote up
private SnowflakeIdFactory(Long workerId) {
    SnowflakeConfig config = ConfigFactory.getConfig(SnowflakeConfig.class);
    Long realWorkerId = workerId != null ? workerId : config.workerId();
    this.snowflake = IdUtil.createSnowflake(realWorkerId, config.dataCenterId());
}
 
Example 4
Source File: SmsReceiveMsgService.java    From hdw-dubbo with Apache License 2.0 4 votes vote down vote up
@JmsListener(destination = "hdw-dubbo-sms", containerFactory = "queueJmsListenerContainerFactory", concurrency = "5-10")
public void receiveMsg(String msg) {
    log.info("接收到的数据:" + msg);
    Sms sms = JacksonUtil.toObject(msg, Sms.class);
    if (null != sms) {
        Snowflake snowflake = IdUtil.createSnowflake(1, 1);
        long id = snowflake.nextId();
        SysSms sysSms = new SysSms();
        sysSms.setId(id);
        sysSms.setSmsTypeId(Long.valueOf(sms.getSmsType()));
        sysSms.setTitle(sms.getTitle());
        sysSms.setContent(sms.getContent());
        sysSms.setSmsTime(sms.getSmsTime());
        sysSms.setIntervalTime(sms.getIntervalTime());
        sysSms.setSmsCount(sms.getSmsCount());
        sysSms.setStatus(0);
        sysSmsService.save(sysSms);
        SmsType smsType = smsTypeService.getById(sms.getSmsType());
        if (null != smsType) {
            List<String> userIds = new ArrayList<>();
            if (smsType.getTargetList().contains(",")) {
                String[] targetList = smsType.getTargetList().split(",");
                userIds.addAll(Arrays.asList(targetList));
            } else {
                userIds.add(smsType.getTargetList());
            }
            //保存消息记录
            userIds.forEach(userId -> {
                SmsRecord smsRecord = new SmsRecord();
                smsRecord.setUserId(Long.valueOf(userId));
                smsRecord.setSmsId(sysSms.getId());
                smsRecord.setSmsTime(sms.getSmsTime());
                smsRecord.setStatus(sms.getStatus());
                smsRecordService.save(smsRecord);
                sms.setId(smsRecord.getId().toString());
                //推送消息
                smsPushSocket.sendInfo(userId, sms.toString());
            });
            //更新消息信息
            sysSms.setRealTime(new Date());
            sysSms.setRealCount(1);
            sysSmsService.updateById(sysSms);
        }
    }
}
 
Example 5
Source File: IdConfig.java    From spring-boot-demo with MIT License 4 votes vote down vote up
/**
 * 雪花生成器
 */
@Bean
public Snowflake snowflake() {
    return IdUtil.createSnowflake(1, 1);
}
 
Example 6
Source File: IdConfig.java    From spring-boot-demo with MIT License 4 votes vote down vote up
/**
 * 雪花生成器
 */
@Bean
public Snowflake snowflake() {
    return IdUtil.createSnowflake(1, 1);
}
 
Example 7
Source File: SnowflakeConfig.java    From spring-boot-demo with MIT License 4 votes vote down vote up
@Bean
public Snowflake snowflake(){
    return IdUtil.createSnowflake(1,1);
}
 
Example 8
Source File: SpringBootDemoMongodbApplication.java    From spring-boot-demo with MIT License 4 votes vote down vote up
@Bean
public Snowflake snowflake() {
    return IdUtil.createSnowflake(1, 1);
}