Commit d5fef55e authored by 赵啸非's avatar 赵啸非

更新证书状态

parent f5daab5e
package com.mortals.xhx.daemon.task;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.LicenseStatusEnum;
import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.license.model.LicenseEntity;
import com.mortals.xhx.module.license.model.LicenseQuery;
import com.mortals.xhx.module.license.service.LicenseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* 同步用户,唯一标识为用户名。
*/
......@@ -19,11 +27,25 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
@Autowired
private UserService userService;
@Autowired
private LicenseService licenseService;
@Override
public void excuteTask(ITask task) throws AppException {
log.info("同步用户任务");
userService.refreshUser();
//更新证书有效期
List<LicenseEntity> licenseEntities = licenseService.find(new LicenseQuery());
for (LicenseEntity licenseEntity : licenseEntities) {
Date endTime = licenseEntity.getEndTime();
if (DateUtil.compare(new Date(), endTime) > 0) {
licenseEntity.setLicenseStatus(LicenseStatusEnum.过期.getValue());
licenseService.update(licenseEntity);
}
}
}
......
......@@ -3,6 +3,7 @@ package com.mortals.xhx.module.license.service.impl;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.code.LicenseStatusEnum;
import lombok.Getter;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -56,12 +57,22 @@ public class LicenseServiceImpl extends AbstractCRUDServiceImpl<LicenseDao, Lice
entity.setLicensePriPath(priPath);
}
updateLicenseStatus(entity);
super.saveBefore(entity, context);
}
@Override
protected void updateBefore(LicenseEntity entity, Context context) throws AppException {
entity.setLicenseCode(String.format("mac=%s|ip=%s",entity.getMac(),entity.getIp()));
updateLicenseStatus(entity);
super.updateBefore(entity, context);
}
private void updateLicenseStatus(LicenseEntity entity) {
Date endTime = entity.getEndTime();
if (DateUtil.compare(new Date(), endTime) > 0) {
entity.setLicenseStatus(LicenseStatusEnum.过期.getValue());
}
}
}
\ No newline at end of file
......@@ -60,7 +60,9 @@ Content-Type: application/json
"taketimeEnd": "2023-04-01"
}
###controoler 测试
POST {{baseUrl}}/resource/refreshUrl
Accept: application/json
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment