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

The following examples show how to use cn.hutool.core.util.IdUtil#simpleUUID() . 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: AuthController.java    From sk-admin with Apache License 2.0 6 votes vote down vote up
@AnonymousAccess
@ApiOperation("获取验证码")
@GetMapping(value = "/code")
public ResponseEntity<Object> getCode() {
    // 算术类型 https://gitee.com/whvse/EasyCaptcha
    ArithmeticCaptcha captcha = new ArithmeticCaptcha(111, 36);
    // 几位数运算,默认是两位
    captcha.setLen(2);
    // 获取运算的结果
    String result = captcha.text();
    String uuid = properties.getCodeKey() + IdUtil.simpleUUID();
    // 保存
    redisUtils.set(uuid, result, expiration, TimeUnit.MINUTES);
    // 验证码信息
    Map<String, Object> imgResult = new HashMap<String, Object>(2) {{
        put("img", captcha.toBase64());
        put("uuid", uuid);
    }};
    return ResponseEntity.ok(imgResult);
}
 
Example 2
Source File: ExecutorJobHandler.java    From datax-web with MIT License 6 votes vote down vote up
private String generateTemJsonFile(String jobJson) {
    String tmpFilePath;
    String dataXHomePath = SystemUtils.getDataXHomePath();
    if (StringUtils.isNotEmpty(dataXHomePath)) {
        jsonPath = dataXHomePath + DEFAULT_JSON;
    }
    if (!FileUtil.exist(jsonPath)) {
        FileUtil.mkdir(jsonPath);
    }
    tmpFilePath = jsonPath + "jobTmp-" + IdUtil.simpleUUID() + ".conf";
    // 根据json写入到临时本地文件
    try (PrintWriter writer = new PrintWriter(tmpFilePath, "UTF-8")) {
        writer.println(jobJson);
    } catch (FileNotFoundException | UnsupportedEncodingException e) {
        JobLogger.log("JSON 临时文件写入异常:" + e.getMessage());
    }
    return tmpFilePath;
}
 
Example 3
Source File: AttachFileServiceImpl.java    From mall4j with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
public String uploadFile(byte[] bytes,String originalName) throws QiniuException {
	String extName = FileUtil.extName(originalName);
	String fileName =DateUtil.format(new Date(), NORM_MONTH_PATTERN)+ IdUtil.simpleUUID() + "." + extName;


	AttachFile attachFile = new AttachFile();
	attachFile.setFilePath(fileName);
	attachFile.setFileSize(bytes.length);
	attachFile.setFileType(extName);
	attachFile.setUploadTime(new Date());
	attachFileMapper.insert(attachFile);

	String upToken = auth.uploadToken(qiniu.getBucket(),fileName);
    Response response = uploadManager.put(bytes, fileName, upToken);
    Json.parseObject(response.bodyString(),  DefaultPutRet.class);
	return fileName;
}
 
Example 4
Source File: AuthController.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
@AnonymousAccess
@ApiOperation("获取验证码")
@GetMapping(value = "/code")
public ResponseEntity<Object> getCode(){
    // 算术类型 https://gitee.com/whvse/EasyCaptcha
    ArithmeticCaptcha captcha = new ArithmeticCaptcha(111, 36);
    // 几位数运算,默认是两位
    captcha.setLen(2);
    // 获取运算的结果
    String result ="";
    try {
        result = new Double(Double.parseDouble(captcha.text())).intValue()+"";
    }catch (Exception e){
        result = captcha.text();
    }
    String uuid = properties.getCodeKey() + IdUtil.simpleUUID();
    // 保存
    redisUtils.set(uuid, result, expiration, TimeUnit.MINUTES);
    // 验证码信息
    Map<String,Object> imgResult = new HashMap<String,Object>(2){{
        put("img", captcha.toBase64());
        put("uuid", uuid);
    }};
    return ResponseEntity.ok(imgResult);
}
 
Example 5
Source File: QuartzJobServiceImpl.java    From eladmin with Apache License 2.0 6 votes vote down vote up
@Async
@Override
@Transactional(rollbackFor = Exception.class)
public void executionSubJob(String[] tasks) throws InterruptedException {
    for (String id : tasks) {
        QuartzJob quartzJob = findById(Long.parseLong(id));
        // 执行任务
        String uuid = IdUtil.simpleUUID();
        quartzJob.setUuid(uuid);
        // 执行任务
        execution(quartzJob);
        // 获取执行状态,如果执行失败则停止后面的子任务执行
        Boolean result = (Boolean) redisUtils.get(uuid);
        while (result == null) {
            // 休眠5秒,再次获取子任务执行情况
            Thread.sleep(5000);
            result = (Boolean) redisUtils.get(uuid);
        }
        if(!result){
            redisUtils.del(uuid);
            break;
        }
    }
}
 
Example 6
Source File: YamiUserServiceImpl.java    From mall4j with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
@RedisLock(lockName = "insertUser", key = "#appConnect.appId + ':' + #appConnect.bizUserId")
@Caching(evict = {
		@CacheEvict(cacheNames = "yami_user", key = "#appConnect.appId + ':' + #appConnect.bizUserId"),
		@CacheEvict(cacheNames = "AppConnect", key = "#appConnect.appId + ':' + #appConnect.bizUserId")
})
public void insertUserIfNecessary(AppConnect appConnect) {
	// 进入锁后再重新判断一遍用户是否创建
	AppConnect dbAppConnect = appConnectMapper.getByBizUserId(appConnect.getBizUserId(), appConnect.getAppId());
	if(dbAppConnect != null) {
		return;
	}

	String bizUnionId = appConnect.getBizUnionid();
	String userId = null;
	User user;

	if (StrUtil.isNotBlank(bizUnionId)) {
		userId = appConnectMapper.getUserIdByUnionId(bizUnionId);
	}
	if (StrUtil.isBlank(userId)) {
		userId = IdUtil.simpleUUID();
		Date now = new Date();
		user = new User();
		user.setUserId(userId);
		user.setModifyTime(now);
		user.setUserRegtime(now);
		user.setStatus(1);
		user.setNickName(EmojiUtil.toAlias(StrUtil.isBlank(appConnect.getNickName()) ? "" : appConnect.getNickName()));
		user.setPic(appConnect.getImageUrl());
		userMapper.insert(user);
	} else {
		user = userMapper.selectById(userId);
	}

	appConnect.setUserId(user.getUserId());

	appConnectMapper.insert(appConnect);
}
 
Example 7
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 保存用户
 *
 * @param user 用户实体
 * @return 保存成功 {@code true} 保存失败 {@code false}
 */
@Override
public Boolean save(User user) {
	String rawPass = user.getPassword();
	String salt = IdUtil.simpleUUID();
	String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
	user.setPassword(pass);
	user.setSalt(salt);
	return userDao.insert(user) > 0;
}
 
Example 8
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 更新用户
 *
 * @param user 用户实体
 * @param id   主键id
 * @return 更新成功 {@code true} 更新失败 {@code false}
 */
@Override
public Boolean update(User user, Long id) {
	User exist = getUser(id);
	if (StrUtil.isNotBlank(user.getPassword())) {
		String rawPass = user.getPassword();
		String salt = IdUtil.simpleUUID();
		String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
		user.setPassword(pass);
		user.setSalt(salt);
	}
	BeanUtil.copyProperties(user, exist, CopyOptions.create().setIgnoreNullValue(true));
	exist.setLastUpdateTime(new DateTime());
	return userDao.update(exist, id) > 0;
}
 
Example 9
Source File: AuthorizationController.java    From eladmin with Apache License 2.0 5 votes vote down vote up
@ApiOperation("获取验证码")
@AnonymousGetMapping(value = "/code")
public ResponseEntity<Object> getCode() {
    // 获取运算的结果
    Captcha captcha = loginProperties.getCaptcha();
    String uuid = properties.getCodeKey() + IdUtil.simpleUUID();
    // 保存
    redisUtils.set(uuid, captcha.text(), loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES);
    // 验证码信息
    Map<String, Object> imgResult = new HashMap<String, Object>(2) {{
        put("img", captcha.toBase64());
        put("uuid", uuid);
    }};
    return ResponseEntity.ok(imgResult);
}
 
Example 10
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 保存用户
 *
 * @param user 用户实体
 * @return 保存成功 {@code true} 保存失败 {@code false}
 */
@Override
public Boolean save(User user) {
	String rawPass = user.getPassword();
	String salt = IdUtil.simpleUUID();
	String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
	user.setPassword(pass);
	user.setSalt(salt);
	return userDao.insert(user) > 0;
}
 
Example 11
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 更新用户
 *
 * @param user 用户实体
 * @param id   主键id
 * @return 更新成功 {@code true} 更新失败 {@code false}
 */
@Override
public Boolean update(User user, Long id) {
	User exist = getUser(id);
	if (StrUtil.isNotBlank(user.getPassword())) {
		String rawPass = user.getPassword();
		String salt = IdUtil.simpleUUID();
		String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
		user.setPassword(pass);
		user.setSalt(salt);
	}
	BeanUtil.copyProperties(user, exist, CopyOptions.create().setIgnoreNullValue(true));
	exist.setLastUpdateTime(new DateTime());
	return userDao.update(exist, id) > 0;
}
 
Example 12
Source File: SheetController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("preview/{sheetId:\\d+}")
@ApiOperation("Gets a sheet preview link")
public String preview(@PathVariable("sheetId") Integer sheetId) throws UnsupportedEncodingException {
    Sheet sheet = sheetService.getById(sheetId);

    sheet.setSlug(URLEncoder.encode(sheet.getSlug(), StandardCharsets.UTF_8.name()));

    BasePostMinimalDTO sheetMinimalDTO = sheetService.convertToMinimal(sheet);

    String token = IdUtil.simpleUUID();

    // cache preview token
    cacheStore.putAny(token, token, 10, TimeUnit.MINUTES);

    StringBuilder previewUrl = new StringBuilder();

    if (!optionService.isEnabledAbsolutePath()) {
        previewUrl.append(optionService.getBlogBaseUrl());
    }

    previewUrl.append(sheetMinimalDTO.getFullPath())
        .append("?token=")
        .append(token);

    // build preview post url and return
    return previewUrl.toString();
}
 
Example 13
Source File: PostController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping(value = {"preview/{postId:\\d+}", "{postId:\\d+}/preview"})
@ApiOperation("Gets a post preview link")
public String preview(@PathVariable("postId") Integer postId) throws UnsupportedEncodingException {
    Post post = postService.getById(postId);

    post.setSlug(URLEncoder.encode(post.getSlug(), StandardCharsets.UTF_8.name()));

    BasePostMinimalDTO postMinimalDTO = postService.convertToMinimal(post);

    String token = IdUtil.simpleUUID();

    // cache preview token
    cacheStore.putAny(token, token, 10, TimeUnit.MINUTES);

    StringBuilder previewUrl = new StringBuilder();

    if (!optionService.isEnabledAbsolutePath()) {
        previewUrl.append(optionService.getBlogBaseUrl());
    }

    previewUrl.append(postMinimalDTO.getFullPath());

    if (optionService.getPostPermalinkType().equals(PostPermalinkType.ID)) {
        previewUrl.append("&token=")
            .append(token);
    } else {
        previewUrl.append("?token=")
            .append(token);
    }

    // build preview post url and return
    return previewUrl.toString();
}
 
Example 14
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 保存用户
 *
 * @param user 用户实体
 * @return 保存成功 {@code true} 保存失败 {@code false}
 */
@Override
public Boolean save(User user) {
	String rawPass = user.getPassword();
	String salt = IdUtil.simpleUUID();
	String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
	user.setPassword(pass);
	user.setSalt(salt);
	return userDao.insert(user) > 0;
}
 
Example 15
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 更新用户
 *
 * @param user 用户实体
 * @param id   主键id
 * @return 更新成功 {@code true} 更新失败 {@code false}
 */
@Override
public Boolean update(User user, Long id) {
	User exist = getUser(id);
	if (StrUtil.isNotBlank(user.getPassword())) {
		String rawPass = user.getPassword();
		String salt = IdUtil.simpleUUID();
		String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
		user.setPassword(pass);
		user.setSalt(salt);
	}
	BeanUtil.copyProperties(user, exist, CopyOptions.create().setIgnoreNullValue(true));
	exist.setLastUpdateTime(new DateTime());
	return userDao.update(exist, id) > 0;
}