cn.hutool.core.date.DateTime Java Examples

The following examples show how to use cn.hutool.core.date.DateTime. 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: DataInitTest.java    From spring-boot-demo with MIT License 6 votes vote down vote up
private User createUser(boolean isAdmin) {
    User user = new User();
    user.setId(snowflake.nextId());
    user.setUsername(isAdmin ? "admin" : "user");
    user.setNickname(isAdmin ? "管理员" : "普通用户");
    user.setPassword(encoder.encode("123456"));
    user.setBirthday(DateTime.of("1994-11-22", "yyyy-MM-dd")
            .getTime());
    user.setEmail((isAdmin ? "admin" : "user") + "@xkcoding.com");
    user.setPhone(isAdmin ? "17300000000" : "17300001111");
    user.setSex(1);
    user.setStatus(1);
    user.setCreateTime(DateUtil.current(false));
    user.setUpdateTime(DateUtil.current(false));
    userDao.save(user);
    return user;
}
 
Example #2
Source File: DataInitTest.java    From spring-boot-demo with MIT License 6 votes vote down vote up
private User createUser(boolean isAdmin) {
    User user = new User();
    user.setId(snowflake.nextId());
    user.setUsername(isAdmin ? "admin" : "user");
    user.setNickname(isAdmin ? "管理员" : "普通用户");
    user.setPassword(encoder.encode("123456"));
    user.setBirthday(DateTime.of("1994-11-22", "yyyy-MM-dd")
            .getTime());
    user.setEmail((isAdmin ? "admin" : "user") + "@xkcoding.com");
    user.setPhone(isAdmin ? "17300000000" : "17300001111");
    user.setSex(1);
    user.setStatus(1);
    user.setCreateTime(DateUtil.current(false));
    user.setUpdateTime(DateUtil.current(false));
    userDao.save(user);
    return user;
}
 
Example #3
Source File: DataInitTest.java    From spring-boot-demo with MIT License 6 votes vote down vote up
private User createUser(boolean isAdmin) {
    User user = new User();
    user.setId(snowflake.nextId());
    user.setUsername(isAdmin ? "admin" : "user");
    user.setNickname(isAdmin ? "管理员" : "普通用户");
    user.setPassword(encoder.encode("123456"));
    user.setBirthday(DateTime.of("1994-11-22", "yyyy-MM-dd")
            .getTime());
    user.setEmail((isAdmin ? "admin" : "user") + "@xkcoding.com");
    user.setPhone(isAdmin ? "17300000000" : "17300001111");
    user.setSex(1);
    user.setStatus(1);
    user.setCreateTime(DateUtil.current(false));
    user.setUpdateTime(DateUtil.current(false));
    userDao.save(user);
    return user;
}
 
Example #4
Source File: AutoBackLog.java    From Jpom with MIT License 6 votes vote down vote up
private static void checkProject(ProjectInfoModel projectInfoModel, ProjectInfoModel.JavaCopyItem javaCopyItem) {
    File file = javaCopyItem == null ? new File(projectInfoModel.getLog()) : projectInfoModel.getLog(javaCopyItem);
    if (!file.exists()) {
        return;
    }
    long len = file.length();
    if (len > MAX_SIZE.getSize()) {
        try {
            AbstractProjectCommander.getInstance().backLog(projectInfoModel, javaCopyItem);
        } catch (Exception ignored) {
        }
    }
    // 清理过期的文件
    File logFile = javaCopyItem == null ? projectInfoModel.getLogBack() : projectInfoModel.getLogBack(javaCopyItem);
    DateTime nowTime = DateTime.now();
    List<File> files = FileUtil.loopFiles(logFile, pathname -> {
        DateTime dateTime = DateUtil.date(pathname.lastModified());
        long days = DateUtil.betweenDay(dateTime, nowTime, false);
        long saveDays = AgentExtConfigBean.getInstance().getLogSaveDays();
        return days > saveDays;
    });
    files.forEach(FileUtil::del);
}
 
Example #5
Source File: NodeWelcomeController.java    From Jpom with MIT License 6 votes vote down vote up
private PageResult<SystemMonitorLog> getList(String time, long millis) {
    long endTime = System.currentTimeMillis();
    long startTime = endTime - TimeUnit.MINUTES.toMillis(30);
    if (StrUtil.isNotEmpty(time)) {
        //  处理时间
        List<String> list = StrSpliter.splitTrim(time, "~", true);
        DateTime startDate = DateUtil.parseDateTime(list.get(0));
        startTime = startDate.getTime();
        DateTime endDate = DateUtil.parseDateTime(list.get(1));
        if (startDate.equals(endDate) || StrUtil.equalsAny("00:00:00", endDate.toString(DatePattern.NORM_TIME_FORMAT), startDate.toString(DatePattern.NORM_TIME_FORMAT))) {
            endDate = DateUtil.endOfDay(endDate);
        }
        endTime = endDate.getTime();
    }
    int count = (int) ((endTime - startTime) / millis);
    NodeModel node = getNode();
    // 开启了节点信息采集
    Page pageObj = new Page(1, count);
    pageObj.addOrder(new Order("monitorTime", Direction.DESC));
    Entity entity = Entity.create();
    entity.set("nodeId", node.getId());

    entity.set(" MONITORTIME", ">= " + startTime);
    entity.set("MONITORTIME", "<= " + endTime);
    return dbSystemMonitorLogService.listPage(entity, pageObj);
}
 
Example #6
Source File: BaseServerController.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 处理分页的时间字段
 *
 * @param page    分页
 * @param entity  条件
 * @param colName 字段名称
 */
protected void doPage(Page page, Entity entity, String colName) {
    String time = getParameter("time");
    colName = colName.toUpperCase();
    page.addOrder(new Order(colName, Direction.DESC));
    // 时间
    if (StrUtil.isNotEmpty(time)) {
        String[] val = StrUtil.split(time, "~");
        if (val.length == 2) {
            DateTime startDateTime = DateUtil.parse(val[0], DatePattern.NORM_DATETIME_FORMAT);
            entity.set(colName, ">= " + startDateTime.getTime());

            DateTime endDateTime = DateUtil.parse(val[1], DatePattern.NORM_DATETIME_FORMAT);
            if (startDateTime.equals(endDateTime)) {
                endDateTime = DateUtil.endOfDay(endDateTime);
            }
            // 防止字段重复
            entity.set(colName + " ", "<= " + endDateTime.getTime());
        }
    }
}
 
Example #7
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试保存
 */
@Test
public void saveUser() {
    String salt = IdUtil.fastSimpleUUID();
    User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    int i = userMapper.saveUser(user);
    Assert.assertEquals(1, i);
}
 
Example #8
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试保存
 */
@Test
public void saveUser() {
    String salt = IdUtil.fastSimpleUUID();
    User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    int i = userMapper.saveUser(user);
    Assert.assertEquals(1, i);
}
 
Example #9
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试通用Mapper - 保存
 */
@Test
public void testInsert() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    userMapper.insertUseGeneratedKeys(testSave3);
    Assert.assertNotNull(testSave3.getId());
    log.debug("【测试主键回写#testSave3.getId()】= {}", testSave3.getId());
}
 
Example #10
Source File: ExtractDialog.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
private void initData() {
	archivePath = AppConfig.appPath + "tmpData/" + DateTime.now().toString("yyyyMMddHHmmss");
	archiveFiles = WinRarUtil.unRar(archiveExt, archiveData, archivePath);
	if (archiveFiles == null) {
		logger.error("解压失败");
		alert("压缩文件解压失败");
		return;
	}

}
 
Example #11
Source File: UserDaoTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试保存
 */
@Test
public void testSave() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).build();
    userDao.save(testSave3);

    Assert.assertNotNull(testSave3.getId());
    Optional<User> byId = userDao.findById(testSave3.getId());
    Assert.assertTrue(byId.isPresent());
    log.debug("【byId】= {}", byId.get());
}
 
Example #12
Source File: UserDaoTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 初始化10条数据
 */
private void initData() {
    List<User> userList = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        String salt = IdUtil.fastSimpleUUID();
        int index = 3 + i;
        User user = User.builder().name("testSave" + index).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + index + "@xkcoding.com").phoneNumber("1730000000" + index).status(1).lastLoginTime(new DateTime()).build();
        userList.add(user);
    }
    userDao.saveAll(userList);
}
 
Example #13
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void saveUser() {
    String salt = IdUtil.fastSimpleUUID();
    User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();

    user = userService.saveUser(user);
    Assert.assertTrue(ObjectUtil.isNotNull(user.getId()));
    log.debug("【user】= {}", user);
}
 
Example #14
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void saveUserList() {
    List<User> users = Lists.newArrayList();
    for (int i = 5; i < 15; i++) {
        String salt = IdUtil.fastSimpleUUID();
        User user = User.builder().name("testSave" + i).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + i + "@xkcoding.com").phoneNumber("1730000000" + i).status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
        users.add(user);
    }
    userService.saveUserList(users);
    Assert.assertTrue(userService.getUserList().size() > 2);
}
 
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;
}
 
Example #16
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试Mybatis-Plus 新增
 */
@Test
public void testSave() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).build();
    boolean save = userService.save(testSave3);
    Assert.assertTrue(save);
    log.debug("【测试id回显#testSave3.getId()】= {}", testSave3.getId());
}
 
Example #17
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试Mybatis-Plus 批量新增
 */
@Test
public void testSaveList() {
    List<User> userList = Lists.newArrayList();
    for (int i = 4; i < 14; i++) {
        String salt = IdUtil.fastSimpleUUID();
        User user = User.builder().name("testSave" + i).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + i + "@xkcoding.com").phoneNumber("1730000000" + i).status(1).lastLoginTime(new DateTime()).build();
        userList.add(user);
    }
    boolean batch = userService.saveBatch(userList);
    Assert.assertTrue(batch);
    List<Long> ids = userList.stream().map(User::getId).collect(Collectors.toList());
    log.debug("【userList#ids】= {}", ids);
}
 
Example #18
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试Mybatis-Plus 批量新增
 */
@Test
public void testSaveList() {
    List<User> userList = Lists.newArrayList();
    for (int i = 4; i < 14; i++) {
        String salt = IdUtil.fastSimpleUUID();
        User user = User.builder().name("testSave" + i).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + i + "@xkcoding.com").phoneNumber("1730000000" + i).status(1).lastLoginTime(new DateTime()).build();
        userList.add(user);
    }
    boolean batch = userService.saveBatch(userList);
    Assert.assertTrue(batch);
    List<Long> ids = userList.stream().map(User::getId).collect(Collectors.toList());
    log.debug("【userList#ids】= {}", ids);
}
 
Example #19
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试通用Mapper - 保存
 */
@Test
public void testInsert() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    userMapper.insertUseGeneratedKeys(testSave3);
    Assert.assertNotNull(testSave3.getId());
    log.debug("【测试主键回写#testSave3.getId()】= {}", testSave3.getId());
}
 
Example #20
Source File: UserDaoTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试保存
 */
@Test
public void testSave() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).build();
    userDao.save(testSave3);

    Assert.assertNotNull(testSave3.getId());
    Optional<User> byId = userDao.findById(testSave3.getId());
    Assert.assertTrue(byId.isPresent());
    log.debug("【byId】= {}", byId.get());
}
 
Example #21
Source File: UserDaoTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 初始化10条数据
 */
private void initData() {
    List<User> userList = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        String salt = IdUtil.fastSimpleUUID();
        int index = 3 + i;
        User user = User.builder().name("testSave" + index).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + index + "@xkcoding.com").phoneNumber("1730000000" + index).status(1).lastLoginTime(new DateTime()).build();
        userList.add(user);
    }
    userDao.saveAll(userList);
}
 
Example #22
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void saveUser() {
    String salt = IdUtil.fastSimpleUUID();
    User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();

    user = userService.saveUser(user);
    Assert.assertTrue(ObjectUtil.isNotNull(user.getId()));
    log.debug("【user】= {}", user);
}
 
Example #23
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void saveUserList() {
    List<User> users = Lists.newArrayList();
    for (int i = 5; i < 15; i++) {
        String salt = IdUtil.fastSimpleUUID();
        User user = User.builder().name("testSave" + i).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + i + "@xkcoding.com").phoneNumber("1730000000" + i).status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
        users.add(user);
    }
    userService.saveUserList(users);
    Assert.assertTrue(userService.getUserList().size() > 2);
}
 
Example #24
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 #25
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试Mybatis-Plus 新增
 */
@Test
public void testSave() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).build();
    boolean save = userService.save(testSave3);
    Assert.assertTrue(save);
    log.debug("【测试id回显#testSave3.getId()】= {}", testSave3.getId());
}
 
Example #26
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试Mybatis-Plus 批量新增
 */
@Test
public void testSaveList() {
    List<User> userList = Lists.newArrayList();
    for (int i = 4; i < 14; i++) {
        String salt = IdUtil.fastSimpleUUID();
        User user = User.builder().name("testSave" + i).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + i + "@xkcoding.com").phoneNumber("1730000000" + i).status(1).lastLoginTime(new DateTime()).build();
        userList.add(user);
    }
    boolean batch = userService.saveBatch(userList);
    Assert.assertTrue(batch);
    List<Long> ids = userList.stream().map(User::getId).collect(Collectors.toList());
    log.debug("【userList#ids】= {}", ids);
}
 
Example #27
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试保存
 */
@Test
public void saveUser() {
    String salt = IdUtil.fastSimpleUUID();
    User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    int i = userMapper.saveUser(user);
    Assert.assertEquals(1, i);
}
 
Example #28
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试通用Mapper - 保存
 */
@Test
public void testInsert() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    userMapper.insertUseGeneratedKeys(testSave3);
    Assert.assertNotNull(testSave3.getId());
    log.debug("【测试主键回写#testSave3.getId()】= {}", testSave3.getId());
}
 
Example #29
Source File: StringUtil.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 指定时间的下一个刻度
 *
 * @return String
 */
public static String getNextScaleTime(String time, Long millis) {
    DateTime dateTime = DateUtil.parseTime(time);
    if (millis == null) {
        millis = 30 * 1000L;
    }
    DateTime newTime = dateTime.offsetNew(DateField.SECOND, (int) (millis / 1000));
    return DateUtil.formatTime(newTime);
}
 
Example #30
Source File: ExtractDialog.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
private void initData() {
	archivePath = AppConfig.appPath + "tmpData/" + DateTime.now().toString("yyyyMMddHHmmss");
	archiveFiles = WinRarUtil.unRar(archiveExt, archiveData, archivePath);
	if (archiveFiles == null) {
		logger.error("解压失败");
		alert("压缩文件解压失败");
		return;
	}

}