@@ -56,9 +56,9 @@ public class AuthService { | |||||
user.put("create_time", PubUtil.checkLastTime(user.getCreate())); | user.put("create_time", PubUtil.checkLastTime(user.getCreate())); | ||||
user.put("sur_party", PartyCache.getInstance().get(us.getPartyId())); | user.put("sur_party", PartyCache.getInstance().get(us.getPartyId())); | ||||
user.put("sur_roles", RoleCache.getInstance().getNamesByIds(UserRoleCache.getInstance().getRoleIdByUP(us.getUserId(), 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) { | } catch (CloneNotSupportedException e) { | ||||
data.put("userInfo", new SwMap()); | |||||
} | } | ||||
return R.success(data); | return R.success(data); | ||||
} | } | ||||
@@ -68,6 +68,20 @@ public class AuthService { | |||||
SwMap userInfo = params.readMap("userInfo"); | SwMap userInfo = params.readMap("userInfo"); | ||||
User user = UserCache.getInstance().get(us.getUserId()); | User user = UserCache.getInstance().get(us.getUserId()); | ||||
user.getData().putAll(userInfo); | 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(); | return R.success(); | ||||
} | } | ||||
@@ -3,6 +3,7 @@ package cc.smtweb.system.bpm.web.login; | |||||
import cc.smtweb.framework.core.cache.redis.RedisManager; | import cc.smtweb.framework.core.cache.redis.RedisManager; | ||||
import cc.smtweb.framework.core.common.SwConsts; | import cc.smtweb.framework.core.common.SwConsts; | ||||
import cc.smtweb.framework.core.common.SwEnum; | 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.exception.BizException; | ||||
import cc.smtweb.framework.core.session.UserSession; | import cc.smtweb.framework.core.session.UserSession; | ||||
import cc.smtweb.system.bpm.web.sys.user.user.User; | 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()); | 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); | |||||
} | |||||
/** | /** | ||||
* 校验密码是否符合规定 | * 校验密码是否符合规定 | ||||
* | * | ||||
@@ -4,6 +4,9 @@ import cc.smtweb.framework.core.annotation.SwCache; | |||||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | import cc.smtweb.framework.core.cache.AbstractEntityCache; | ||||
import cc.smtweb.framework.core.cache.CacheManager; | 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 | * Created by 1 at 2022-07-28 15:24:49 | ||||
* 实体【[用户账号](SYS_USER)】的缓存类 | * 实体【[用户账号](SYS_USER)】的缓存类 | ||||
@@ -63,4 +66,12 @@ public class UserCache extends AbstractEntityCache<User> { | |||||
if (user == null) return ""; | if (user == null) return ""; | ||||
return user.getName(); | 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; | |||||
} | |||||
} | } |
@@ -70,7 +70,7 @@ public class UserHandler { | |||||
partyList.add(userParty); | partyList.add(userParty); | ||||
String roles = row.get("sup_roles").toString(); | 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(",")) { | for (String role_id : roles.split(",")) { | ||||
UserRole userRole = new UserRole(); | UserRole userRole = new UserRole(); | ||||
userRole.init(); | userRole.init(); | ||||
@@ -217,5 +217,25 @@ public class UserHandler { | |||||
}); | }); | ||||
return R.success(); | 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(); | |||||
} | |||||
} | } | ||||
} | } |
@@ -54,4 +54,16 @@ public class UserService extends DynPageService { | |||||
return pageHandler(params, us, TYPE_CUST, handler -> ((UserHandler.UserCustHandler) handler).delAll()); | 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,8 +13,21 @@ window.$swEvent.setup("bpm.sys.user.user.userList", { | |||||
$model.userCard.setFormVal("partyData", $model.userPartyList.data.list.rows); | $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 { | return { | ||||
onBeforeSave, | onBeforeSave, | ||||
batchResetPwd, | |||||
} | } | ||||
} | } | ||||
}); | }); |
@@ -122,6 +122,11 @@ public interface SwEnum { | |||||
public final static String TYPE_DATE = "date"; | public final static String TYPE_DATE = "date"; | ||||
public final static String TYPE_DATETIME = "datetime"; | 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 DataType instance = new DataType(); | ||||
public static DataTypeBean ID = instance.addEnum("id", "ID", "bigint", 0, "long", "Long", Types.BIGINT, "", EditorType.INPUT.value); | 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); | 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); | DataTypeBean dataType = instance.getByValue(value); | ||||
if (dataType == null) return fieldValue; | if (dataType == null) return fieldValue; | ||||
switch (dataType.javaType) { | switch (dataType.javaType) { | ||||
case "long": | |||||
case JAVA_TYPE_LONG: | |||||
return PubUtil.getLongIgnoreErr(fieldValue); | return PubUtil.getLongIgnoreErr(fieldValue); | ||||
case "int": | |||||
case JAVA_TYPE_INT: | |||||
return PubUtil.getIntIgnoreErr(fieldValue); | return PubUtil.getIntIgnoreErr(fieldValue); | ||||
case "boolean": | |||||
case JAVA_TYPE_BOOL: | |||||
return PubUtil.getBool(fieldValue); | return PubUtil.getBool(fieldValue); | ||||
default: | default: | ||||
return fieldValue; | return fieldValue; | ||||
@@ -12,6 +12,7 @@ import cc.smtweb.framework.core.util.PubUtil; | |||||
import lombok.Getter; | import lombok.Getter; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import java.text.MessageFormat; | |||||
import java.util.*; | import java.util.*; | ||||
/** | /** | ||||
@@ -141,10 +142,11 @@ public class EntityDao<T> extends AbstractEntityDao<T> { | |||||
* @param entities PO对象列表 | * @param entities PO对象列表 | ||||
* @return 更新数量 | * @return 更新数量 | ||||
*/ | */ | ||||
public int[] batchInsertEntity(List<T> entities) { | |||||
public int[] batchInsertEntity(Collection<T> entities) { | |||||
return batchInsertEntity(entities, null); | return batchInsertEntity(entities, null); | ||||
} | } | ||||
/** | /** | ||||
* 批量插入单行数据 | * 批量插入单行数据 | ||||
* | * | ||||
@@ -152,7 +154,7 @@ public class EntityDao<T> extends AbstractEntityDao<T> { | |||||
* @param fields 逗号分隔的字段列表 | * @param fields 逗号分隔的字段列表 | ||||
* @return 更新数量 | * @return 更新数量 | ||||
*/ | */ | ||||
public int[] batchInsertEntity(List<T> entities, String fields) { | |||||
public int[] batchInsertEntity(Collection<T> entities, String fields) { | |||||
StringBuilder sql = new StringBuilder(); | StringBuilder sql = new StringBuilder(); | ||||
sql.append("insert into ").append(modelTable.getSchemaTableName()).append("("); | 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); | 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值删除单行数据 | * 根据ID值删除单行数据 | ||||
@@ -3,16 +3,17 @@ package cc.smtweb.framework.core.db; | |||||
import cc.smtweb.framework.core.cache.AbstractCache; | import cc.smtweb.framework.core.cache.AbstractCache; | ||||
import cc.smtweb.framework.core.cache.CacheManager; | import cc.smtweb.framework.core.cache.CacheManager; | ||||
import cc.smtweb.framework.core.common.SwEnum; | 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.common.SwMap; | ||||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | 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.ModelField; | ||||
import cc.smtweb.framework.core.db.vo.ModelLinkName; | import cc.smtweb.framework.core.db.vo.ModelLinkName; | ||||
import cc.smtweb.framework.core.db.vo.ModelTable; | 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.DateUtil; | ||||
import cc.smtweb.framework.core.util.NumberUtil; | import cc.smtweb.framework.core.util.NumberUtil; | ||||
import cc.smtweb.framework.core.util.PubUtil; | |||||
import cc.smtweb.framework.core.util.StringUtil; | import cc.smtweb.framework.core.util.StringUtil; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
@@ -24,6 +25,7 @@ import java.util.*; | |||||
*/ | */ | ||||
public class EntityHelper { | public class EntityHelper { | ||||
private static Map<String, IFormatter> mapFormatter; | private static Map<String, IFormatter> mapFormatter; | ||||
static { | static { | ||||
mapFormatter = new HashMap<>(); | mapFormatter = new HashMap<>(); | ||||
mapFormatter.put(SwEnum.DataType.BOOL.value, value -> { | 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) { | private static String getFieldAlias(Map<String, String> mapFieldAlias, String field) { | ||||
return (mapFieldAlias != null && mapFieldAlias.containsKey(field)) ? mapFieldAlias.get(field) : field; | return (mapFieldAlias != null && mapFieldAlias.containsKey(field)) ? mapFieldAlias.get(field) : field; | ||||
@@ -125,7 +170,7 @@ public class EntityHelper { | |||||
ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ModelTable table = ModelTableCache.getInstance().getByName(tableName); | ||||
if (table == null) return; | if (table == null) return; | ||||
loadBeanLink(table, listData, mapFieldAlias); | loadBeanLink(table, listData, mapFieldAlias); | ||||
for (SwMap bean: listData) { | |||||
for (SwMap bean : listData) { | |||||
setFieldDisplayText(table, bean, mapFieldAlias); | setFieldDisplayText(table, bean, mapFieldAlias); | ||||
} | } | ||||
} | } | ||||
@@ -271,6 +316,7 @@ public class EntityHelper { | |||||
/** | /** | ||||
* bean是否为空 | * bean是否为空 | ||||
* | |||||
* @param bean | * @param bean | ||||
* @return | * @return | ||||
*/ | */ | ||||