Selaa lähdekoodia

个人信息修改、密码修改、密码重置

4.0
yaoq 2 vuotta sitten
vanhempi
commit
c10d065003
9 muutettua tiedostoa jossa 178 lisäystä ja 12 poistoa
  1. +16
    -2
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java
  2. +7
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java
  3. +11
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserCache.java
  4. +21
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserHandler.java
  5. +12
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserService.java
  6. +13
    -0
      smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/user/userList.js
  7. +8
    -3
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  8. +40
    -2
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java
  9. +50
    -4
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java

+ 16
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java Näytä tiedosto

@@ -56,9 +56,9 @@ public class AuthService {
user.put("create_time", PubUtil.checkLastTime(user.getCreate()));
user.put("sur_party", PartyCache.getInstance().get(us.getPartyId()));
user.put("sur_roles", RoleCache.getInstance().getNamesByIds(UserRoleCache.getInstance().getRoleIdByUP(us.getUserId(), us.getPartyId())));
data.put("user", user);
data.put("userInfo", user);
} catch (CloneNotSupportedException e) {
data.put("userInfo", new SwMap());
}
return R.success(data);
}
@@ -68,6 +68,20 @@ public class AuthService {
SwMap userInfo = params.readMap("userInfo");
User user = UserCache.getInstance().get(us.getUserId());
user.getData().putAll(userInfo);
DbEngine.getInstance().findDao(User.ENTITY_NAME).updateEntity(user);
UserCache.getInstance().put(user);
return R.success();
}

@SwPerm()
public R changePwd(@SwBody SwMap params, UserSession us) {
String old_pwd = params.readString("old_pwd");
String new_pwd = params.readString("new_pwd");
User user = UserCache.getInstance().get(us.getUserId());
if (!LoginHelper.verifyPwd(user, old_pwd)) {
return R.error("旧密码错误");
}
LoginHelper.resetUserPwd(user, new_pwd);
return R.success();
}



+ 7
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java Näytä tiedosto

@@ -3,6 +3,7 @@ package cc.smtweb.system.bpm.web.login;
import cc.smtweb.framework.core.cache.redis.RedisManager;
import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.system.bpm.web.sys.user.user.User;
@@ -72,6 +73,12 @@ public class LoginHelper {
return DigestUtils.md5Hex(PWD_SALT + user.getId() + pwd).equals(user.getPwd());
}

public static void resetUserPwd(User user, String pwd) {
user.setPwd(LoginHelper.encodePwd(user.getId(), pwd));
DbEngine.getInstance().findDao(User.ENTITY_NAME).updateEntity(user);
UserCache.getInstance().put(user);
}

/**
* 校验密码是否符合规定
*


+ 11
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserCache.java Näytä tiedosto

@@ -4,6 +4,9 @@ import cc.smtweb.framework.core.annotation.SwCache;
import cc.smtweb.framework.core.cache.AbstractEntityCache;
import cc.smtweb.framework.core.cache.CacheManager;

import java.util.HashSet;
import java.util.Set;

/**
* Created by 1 at 2022-07-28 15:24:49
* 实体【[用户账号](SYS_USER)】的缓存类
@@ -63,4 +66,12 @@ public class UserCache extends AbstractEntityCache<User> {
if (user == null) return "";
return user.getName();
}

public final Set<User> getUserList(Set<Long> ids) {
Set<User> set = new HashSet<>();
ids.forEach(k -> {
set.add(get(k));
});
return set;
}
}

+ 21
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserHandler.java Näytä tiedosto

@@ -70,7 +70,7 @@ public class UserHandler {
partyList.add(userParty);

String roles = row.get("sup_roles").toString();
if(PubUtil.isEmpty(roles)) throw new BizException("用户机构所属角色为空");
if (PubUtil.isEmpty(roles)) throw new BizException("用户机构所属角色为空");
for (String role_id : roles.split(",")) {
UserRole userRole = new UserRole();
userRole.init();
@@ -217,5 +217,25 @@ public class UserHandler {
});
return R.success();
}

public R resetPwd() {
Set<Long> idList = params.readLongSet("ids");
Set<User> userList = UserCache.getInstance().getUserList(idList);
userList.forEach(user -> {
user.setPwd(LoginHelper.encodePwd(user.getId(), SwConsts.DEF_PWD));
});
DbEngine.getInstance().doTrans(new AbsDbWorker() {
@Override
public void work() {
DbEngine.getInstance().findDao(User.ENTITY_NAME).batchUpdateEntity(userList);
}

@Override
public void doAfterDbCommit() {
UserCache.getInstance().putList(userList);
}
});
return R.success();
}
}
}

+ 12
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserService.java Näytä tiedosto

@@ -54,4 +54,16 @@ public class UserService extends DynPageService {
return pageHandler(params, us, TYPE_CUST, handler -> ((UserHandler.UserCustHandler) handler).delAll());
}


/**
* @Author yaoq
* @Date 2022/8/15 16:48
* @Params
* @Return cc.smtweb.framework.core.common.R
* @Description 重置密码
*/
public R resetPwd(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_CUST, handler -> ((UserHandler.UserCustHandler) handler).resetPwd());
}

}

+ 13
- 0
smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/user/userList.js Näytä tiedosto

@@ -13,8 +13,21 @@ window.$swEvent.setup("bpm.sys.user.user.userList", {
$model.userCard.setFormVal("partyData", $model.userPartyList.data.list.rows);
};

const batchResetPwd = () => {
const data = $refs.tbuser.getSelectIds();
if (data.length == 0) {
$$message.notify.warning("请选择要重置的记录!");
return;
}
$$http.post("bpm/user/resetPwd", {ids: data.join(",")}).then((rt) => {
// 8.弹出成功消息
$$message.notify.success("操作成功");
});
};

return {
onBeforeSave,
batchResetPwd,
}
}
});

+ 8
- 3
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java Näytä tiedosto

@@ -122,6 +122,11 @@ public interface SwEnum {
public final static String TYPE_DATE = "date";
public final static String TYPE_DATETIME = "datetime";

public final static String JAVA_TYPE_INT = "int";
public final static String JAVA_TYPE_LONG = "long";
public final static String JAVA_TYPE_STRING = "String";
public final static String JAVA_TYPE_BOOL = "boolean";

public static DataType instance = new DataType();
public static DataTypeBean ID = instance.addEnum("id", "ID", "bigint", 0, "long", "Long", Types.BIGINT, "", EditorType.INPUT.value);
public static DataTypeBean CODE = instance.addEnum("code", "编码", "varchar", 32, "String", "Str", Types.VARCHAR, "", EditorType.INPUT.value);
@@ -168,11 +173,11 @@ public interface SwEnum {
DataTypeBean dataType = instance.getByValue(value);
if (dataType == null) return fieldValue;
switch (dataType.javaType) {
case "long":
case JAVA_TYPE_LONG:
return PubUtil.getLongIgnoreErr(fieldValue);
case "int":
case JAVA_TYPE_INT:
return PubUtil.getIntIgnoreErr(fieldValue);
case "boolean":
case JAVA_TYPE_BOOL:
return PubUtil.getBool(fieldValue);
default:
return fieldValue;


+ 40
- 2
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java Näytä tiedosto

@@ -12,6 +12,7 @@ import cc.smtweb.framework.core.util.PubUtil;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.text.MessageFormat;
import java.util.*;

/**
@@ -141,10 +142,11 @@ public class EntityDao<T> extends AbstractEntityDao<T> {
* @param entities PO对象列表
* @return 更新数量
*/
public int[] batchInsertEntity(List<T> entities) {
public int[] batchInsertEntity(Collection<T> entities) {
return batchInsertEntity(entities, null);
}


/**
* 批量插入单行数据
*
@@ -152,7 +154,7 @@ public class EntityDao<T> extends AbstractEntityDao<T> {
* @param fields 逗号分隔的字段列表
* @return 更新数量
*/
public int[] batchInsertEntity(List<T> entities, String fields) {
public int[] batchInsertEntity(Collection<T> entities, String fields) {
StringBuilder sql = new StringBuilder();

sql.append("insert into ").append(modelTable.getSchemaTableName()).append("(");
@@ -198,6 +200,42 @@ public class EntityDao<T> extends AbstractEntityDao<T> {
return jdbcEngine.batchUpdate(sql.toString(), listParams);
}

public void batchUpdateEntity(Collection<T> list) {
if (PubUtil.isEmpty(list)) return;
batchUpdateEntity(list, null);
}

//批量更新
public void batchUpdateEntity(Collection<T> list, String fields) {
if (PubUtil.isEmpty(list)) return;

List<String> listFields = adjustFields(fields, SwEnum.FieldType.CREATE_TIME.value, SwEnum.FieldType.LAST_TIME.value);
List<String> fieldList = new ArrayList<>();
if (listFields == null) {
for (EntityColumn column : this.columns.values()) {
if (column.getField().getName().equals(modelTable.getIdField())) continue;
fieldList.add(column.getField().getName());
}
} else {
for (String name : listFields) {
if (name.equals(modelTable.getIdField())) continue;
fieldList.add(name);
}
}

String tableName = this.modelTable.getSchemaTableName();
String tableFields = EntityHelper.nameString(fieldList, "=?, ", "=? ");
String tablePks = this.modelTable.getIdField() + " =? ";
String sql = MessageFormat.format("UPDATE {0} SET \n {1}\n WHERE {2}", tableName, tableFields, tablePks);

fieldList.add(this.modelTable.getIdField());
List<Object[]> params = new ArrayList<>(list.size());
list.forEach(k -> {
params.add(EntityHelper.getFieldValueArgs(fieldList, (DefaultEntity) k));
});
DbEngine.getInstance().batchUpdate(sql, params);
}


/**
* 根据ID值删除单行数据


+ 50
- 4
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java Näytä tiedosto

@@ -3,16 +3,17 @@ package cc.smtweb.framework.core.db;
import cc.smtweb.framework.core.cache.AbstractCache;
import cc.smtweb.framework.core.cache.CacheManager;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.exception.SwException;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.cache.ModelTableCache;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.db.vo.ModelField;
import cc.smtweb.framework.core.db.vo.ModelLinkName;
import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.exception.SwException;
import cc.smtweb.framework.core.util.DateUtil;
import cc.smtweb.framework.core.util.NumberUtil;
import cc.smtweb.framework.core.util.PubUtil;
import cc.smtweb.framework.core.util.StringUtil;
import org.apache.commons.lang3.StringUtils;

@@ -24,6 +25,7 @@ import java.util.*;
*/
public class EntityHelper {
private static Map<String, IFormatter> mapFormatter;

static {
mapFormatter = new HashMap<>();
mapFormatter.put(SwEnum.DataType.BOOL.value, value -> {
@@ -44,6 +46,49 @@ public class EntityHelper {
});
}

public static Object[] getFieldValueArgs(List<String> fieldNames, DefaultEntity bean) {
Object[] args = new Object[fieldNames.size()];
fillFieldValueArgs(fieldNames, bean, args);
return args;
}

public static void fillFieldValueArgs(List<String> fieldNames, DefaultEntity bean, Object[] args) {
ModelTable modelEntity = bean.getModelTable();
if (modelEntity == null) return;
//获取实体类字段对象;
int i = 0;
for (String fieldName : fieldNames) {
String fname = fieldName.toLowerCase(); //转换为小写,因此在bean中定义的字段都是小写的;
Object v = bean.getData().get(fname);
String value = v != null ? v.toString() : "";
final ModelField field = modelEntity.findField(fname);
if (field != null) {
if (PubUtil.isEmpty(value) && PubUtil.isNotEmpty(field.getDefaultValue())) {
value = field.getDefaultValue();
}
args[i++] = SwEnum.DataType.getDataValue(field.getDataType(), value);
} else {
args[i++] = v;
}
}
}


public static String nameString(List<String> fieldNameList, String separator, String afterLast) {
StringBuilder returnString = new StringBuilder();
if (fieldNameList.size() < 1) {
return "";
}
int i = 0;
for (; i < fieldNameList.size() - 1; i++) {
returnString.append(fieldNameList.get(i));
returnString.append(separator);
}
returnString.append(fieldNameList.get(i));
returnString.append(afterLast);
return returnString.toString();
}

//获取字段别名
private static String getFieldAlias(Map<String, String> mapFieldAlias, String field) {
return (mapFieldAlias != null && mapFieldAlias.containsKey(field)) ? mapFieldAlias.get(field) : field;
@@ -125,7 +170,7 @@ public class EntityHelper {
ModelTable table = ModelTableCache.getInstance().getByName(tableName);
if (table == null) return;
loadBeanLink(table, listData, mapFieldAlias);
for (SwMap bean: listData) {
for (SwMap bean : listData) {
setFieldDisplayText(table, bean, mapFieldAlias);
}
}
@@ -271,6 +316,7 @@ public class EntityHelper {

/**
* bean是否为空
*
* @param bean
* @return
*/


Ladataan…
Peruuta
Tallenna