use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class BaseProxyHandler method init.
/**
* 连接成功 初始化
*
* @param session 会话
* @param attributes 属性
* @throws URISyntaxException 异常
* @throws IOException IO
*/
protected void init(WebSocketSession session, Map<String, Object> attributes) throws URISyntaxException, IOException {
boolean init = (boolean) attributes.getOrDefault("init", false);
if (init) {
return;
}
NodeModel nodeModel = (NodeModel) attributes.get("nodeInfo");
UserModel userInfo = (UserModel) attributes.get("userInfo");
if (nodeModel != null) {
Object[] parameters = this.getParameters(attributes);
String url = NodeForward.getSocketUrl(nodeModel, nodeUrl, userInfo, parameters);
// 连接节点
ProxySession proxySession = new ProxySession(url, session);
session.getAttributes().put("proxySession", proxySession);
}
attributes.put("init", true);
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class OutGivingRun method startRun.
/**
* 开始异步执行分发任务
*
* @param id 分发id
* @param file 文件
* @param userModel 操作的用户
* @param unzip 解压
*/
public static void startRun(String id, File file, UserModel userModel, boolean unzip) {
OutGivingServer outGivingServer = SpringUtil.getBean(OutGivingServer.class);
OutGivingModel item = outGivingServer.getByKey(id);
Objects.requireNonNull(item, "不存在分发");
AfterOpt afterOpt = ObjectUtil.defaultIfNull(EnumUtil.likeValueOf(AfterOpt.class, item.getAfterOpt()), AfterOpt.No);
//
List<OutGivingNodeProject> outGivingNodeProjects = item.outGivingNodeProjectList();
// 开启线程
if (afterOpt == AfterOpt.Order_Restart || afterOpt == AfterOpt.Order_Must_Restart) {
ThreadUtil.execute(() -> {
// 截取睡眠时间
int sleepTime = ObjectUtil.defaultIfNull(item.getIntervalTime(), 10);
//
boolean cancel = false;
for (OutGivingNodeProject outGivingNodeProject : outGivingNodeProjects) {
if (cancel) {
String userId = userModel == null ? JpomApplication.SYSTEM_ID : userModel.getId();
OutGivingItemRun.updateStatus(null, id, outGivingNodeProject, OutGivingNodeProject.Status.Cancel, "前一个节点分发失败,取消分发", userId);
} else {
OutGivingItemRun outGivingRun = new OutGivingItemRun(item, outGivingNodeProject, file, userModel, unzip);
OutGivingNodeProject.Status status = outGivingRun.call();
if (status != OutGivingNodeProject.Status.Ok) {
if (afterOpt == AfterOpt.Order_Must_Restart) {
// 完整重启,不再继续剩余的节点项目
cancel = true;
}
}
// 休眠x秒 等待之前项目正常启动
ThreadUtil.sleep(sleepTime, TimeUnit.SECONDS);
}
}
});
} else if (afterOpt == AfterOpt.Restart || afterOpt == AfterOpt.No) {
outGivingNodeProjects.forEach(outGivingNodeProject -> ThreadUtil.execAsync(new OutGivingItemRun(item, outGivingNodeProject, file, userModel, unzip)));
} else {
//
throw new IllegalArgumentException("Not implemented " + afterOpt.getDesc());
}
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class BaseDbService method updateById.
/**
* update by id with data
*
* @param info data
* @param whereConsumer 查询条件回调
* @return 影响的行数
*/
public int updateById(T info, Consumer<Entity> whereConsumer) {
// check id
String id = info.getId();
Assert.hasText(id, "不能执行:error");
// def modify time
info.setModifyTimeMillis(ObjectUtil.defaultIfNull(info.getModifyTimeMillis(), SystemClock.now()));
// remove create time
Long createTimeMillis = info.getCreateTimeMillis();
info.setCreateTimeMillis(null);
// fill modify user
if (info instanceof BaseUserModifyDbModel) {
BaseUserModifyDbModel modifyDbModel = (BaseUserModifyDbModel) info;
UserModel userModel = BaseServerController.getUserModel();
if (userModel != null) {
modifyDbModel.setModifyUser(ObjectUtil.defaultIfNull(modifyDbModel.getModifyUser(), userModel.getId()));
}
}
//
Entity entity = this.dataBeanToEntity(info);
//
entity.remove(StrUtil.format("`{}`", Const.ID_STR));
//
Entity where = new Entity();
where.set(Const.ID_STR, id);
if (whereConsumer != null) {
whereConsumer.accept(where);
}
int update = super.update(entity, where);
// backtrack
info.setCreateTimeMillis(createTimeMillis);
return update;
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class UserInfoController method updatePwd.
/**
* 修改密码
*
* @param oldPwd 旧密码
* @param newPwd 新密码
* @return json
*/
@RequestMapping(value = "updatePwd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String updatePwd(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空") String oldPwd, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空") String newPwd) {
Assert.state(!StrUtil.equals(oldPwd, newPwd), "新旧密码一致");
UserModel userName = getUser();
Assert.state(!userName.isDemoUser(), "当前账户为演示账号,不支持修改密码");
try {
UserModel userModel = userService.simpleLogin(userName.getId(), oldPwd);
Assert.notNull(userModel, "旧密码不正确!");
Assert.state(ObjectUtil.defaultIfNull(userModel.getPwdErrorCount(), 0) <= 0, "当前账号被锁定中,不能修改密码");
userService.updatePwd(userName.getId(), newPwd);
// 如果修改成功,则销毁会话
getSession().invalidate();
return JsonMessage.getString(200, "修改密码成功!");
} catch (Exception e) {
DefaultSystemLog.getLog().error(e.getMessage(), e);
return JsonMessage.getString(500, "系统异常:" + e.getMessage());
}
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class UserListController method addUser.
/**
* 编辑用户
*
* @param type 操作类型
* @return String
*/
@PostMapping(value = "edit", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String addUser(String type) {
//
boolean create = StrUtil.equals(type, "add");
UserModel userModel = this.parseUser(create);
if (create) {
userService.insert(userModel);
} else {
UserModel model = userService.getByKey(userModel.getId());
Assert.notNull(model, "不存在对应的用户");
boolean systemUser = userModel.isSystemUser();
if (!systemUser) {
Assert.state(!model.isSuperSystemUser(), "不能取消超级管理员的权限");
}
UserModel optUser = getUser();
if (StrUtil.equals(model.getId(), optUser.getId())) {
Assert.state(optUser.isSuperSystemUser(), "不能修改自己的信息");
}
userService.update(userModel);
}
//
String workspace = getParameter("workspace");
JSONArray jsonArray = JSONArray.parseArray(workspace);
List<String> workspaceList = jsonArray.toJavaList(String.class);
userBindWorkspaceService.updateUserWorkspace(userModel.getId(), workspaceList);
return JsonMessage.getString(200, "操作成功");
}
Aggregations