|
|
@@ -9,8 +9,6 @@ import cc.smtweb.framework.core.db.impl.DefaultEntity; |
|
|
|
import cc.smtweb.framework.core.db.jdbc.AbsDbWorker; |
|
|
|
import cc.smtweb.framework.core.db.vo.ModelTable; |
|
|
|
import cc.smtweb.framework.core.mvc.service.AbstractHandler; |
|
|
|
import cc.smtweb.framework.core.util.CommUtil; |
|
|
|
import cc.smtweb.framework.core.util.PubUtil; |
|
|
|
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; |
|
|
|
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageDelHandler; |
|
|
|
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler; |
|
|
@@ -21,6 +19,7 @@ import cc.smtweb.system.bpm.web.sys.user.role.RoleCache; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
/** |
|
|
@@ -28,6 +27,8 @@ import java.util.Set; |
|
|
|
* 区划保存 |
|
|
|
*/ |
|
|
|
public class UserHandler { |
|
|
|
private final static String DS_UserParty = "userPartyList"; |
|
|
|
private final static String DS_UserCard = "userCard"; |
|
|
|
|
|
|
|
public static EntityDao<User> getUserDao() { |
|
|
|
return DbEngine.getInstance().findDao(User.ENTITY_NAME); |
|
|
@@ -48,24 +49,32 @@ public class UserHandler { |
|
|
|
static class UserSaveHandler extends DynPageSaveHandler { |
|
|
|
private UserStatu userStatu; |
|
|
|
private List<UserRole> roleList; |
|
|
|
private List<UserParty> partyList; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected DefaultEntity readBeanFromPage(PageDataset pageDataSet, SwMap data) { |
|
|
|
if (pageDataSet.isCurTable(UserParty.ENTITY_NAME)) { |
|
|
|
roleList = new ArrayList<>(); |
|
|
|
Set<Long> userRoles = data.readLongSet("sup_roles"); |
|
|
|
if (pageDataSet.isCurDataSet(DS_UserCard)) { |
|
|
|
DefaultEntity bean = super.readBeanFromPage(pageDataSet, data); |
|
|
|
if (PubUtil.isEmpty(userRoles)) { |
|
|
|
return bean; |
|
|
|
roleList = new ArrayList<>(); |
|
|
|
partyList = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> rows = data.readListMap("partyData"); |
|
|
|
for (Map<String, Object> row : rows) { |
|
|
|
UserParty userParty = new UserParty(); |
|
|
|
userParty.init(); |
|
|
|
userParty.getData().putAll(row); |
|
|
|
userParty.setUserId(bean.getEntityId()); |
|
|
|
userParty.setEntityId(DbEngine.getInstance().nextId()); |
|
|
|
partyList.add(userParty); |
|
|
|
|
|
|
|
for (String role_id : row.get("sup_roles").toString().split(",")) { |
|
|
|
UserRole userRole = new UserRole(); |
|
|
|
userRole.init(); |
|
|
|
userRole.setEntityId(DbEngine.getInstance().nextId()); |
|
|
|
userRole.setSupId(userParty.getEntityId()); |
|
|
|
userRole.setRoleId(Long.valueOf(role_id)); |
|
|
|
roleList.add(userRole); |
|
|
|
} |
|
|
|
} |
|
|
|
userRoles.forEach(k -> { |
|
|
|
UserRole userRole = new UserRole(); |
|
|
|
userRole.init(); |
|
|
|
userRole.setEntityId(DbEngine.getInstance().nextId()); |
|
|
|
userRole.setSupId(bean.getEntityId()); |
|
|
|
userRole.setRoleId(k); |
|
|
|
roleList.add(userRole); |
|
|
|
}); |
|
|
|
return bean; |
|
|
|
} |
|
|
|
return super.readBeanFromPage(pageDataSet, data); |
|
|
@@ -85,13 +94,18 @@ public class UserHandler { |
|
|
|
if (bean.isNew()) { |
|
|
|
((User) bean).setPwd(LoginHelper.encodePwd(bean.getEntityId(), SwConsts.DEF_PWD)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (bean instanceof UserParty) { |
|
|
|
Set<Long> ur = UserRoleCache.getInstance().getByParty(bean.getEntityId()); |
|
|
|
|
|
|
|
Set<Long> up = UserPartyCache.getInstance().getIdByUser(bean.getEntityId()); |
|
|
|
Set<Long> ur = UserRoleCache.getInstance().getIdByUser(bean.getEntityId()); |
|
|
|
getUserRoleDao().deleteEntity(ur); |
|
|
|
getUserPartyDao().deleteEntity(up); |
|
|
|
getUserRoleDao().batchInsertEntity(roleList); |
|
|
|
getUserPartyDao().batchInsertEntity(partyList); |
|
|
|
|
|
|
|
UserRoleCache.getInstance().removeList(ur); |
|
|
|
UserPartyCache.getInstance().removeList(up); |
|
|
|
UserRoleCache.getInstance().putList(roleList); |
|
|
|
UserPartyCache.getInstance().putList(partyList); |
|
|
|
} |
|
|
|
super.saveBean(bean); |
|
|
|
} |
|
|
@@ -100,6 +114,11 @@ public class UserHandler { |
|
|
|
static class UserDelHandler extends DynPageDelHandler { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void checkBean(PageDataset pageDataSet, long id) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void localDel(long id, ModelTable table) { |
|
|
|
super.localDel(id, table); |
|
|
|
if (table.getName().equals(User.ENTITY_NAME)) { |
|
|
@@ -107,10 +126,6 @@ public class UserHandler { |
|
|
|
getUserPartyDao().deleteEntity(UserPartyCache.getInstance().getIdByUser(id)); |
|
|
|
getUserRoleDao().deleteEntity(UserRoleCache.getInstance().getIdByUser(id)); |
|
|
|
} |
|
|
|
if (table.getName().equals(UserParty.ENTITY_NAME)) { |
|
|
|
getUserPartyDao().deleteEntity(id); |
|
|
|
getUserRoleDao().deleteEntity(UserRoleCache.getInstance().getByParty(id)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -120,10 +135,6 @@ public class UserHandler { |
|
|
|
UserPartyCache.getInstance().removeList(UserPartyCache.getInstance().getIdByUser(id)); |
|
|
|
UserRoleCache.getInstance().removeList(UserRoleCache.getInstance().getIdByUser(id)); |
|
|
|
} |
|
|
|
if (table.getName().equals(UserParty.ENTITY_NAME)) { |
|
|
|
UserPartyCache.getInstance().remove(id); |
|
|
|
UserRoleCache.getInstance().removeList(UserRoleCache.getInstance().getByParty(id)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -135,9 +146,10 @@ public class UserHandler { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void afterQuery(List<SwMap> listData) { |
|
|
|
if (pageDataSet.isCurTable(UserParty.ENTITY_NAME)) { |
|
|
|
if (pageDataSet.isCurDataSet(DS_UserParty)) { |
|
|
|
listData.forEach(sw -> { |
|
|
|
sw.put("sup_roles", RoleCache.getInstance().getNamesByIds(UserRoleCache.getInstance().getRoleByParty(sw.readLong("sup_id")))); |
|
|
|
sw.put("sup_roles", UserRoleCache.getInstance().getRoleByParty(sw.readLong("sup_id"))); |
|
|
|
sw.put("sup_roles_text", RoleCache.getInstance().getNamesByIds(UserRoleCache.getInstance().getRoleByParty(sw.readLong("sup_id")))); |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
@@ -153,15 +165,6 @@ public class UserHandler { |
|
|
|
listHandler.init(params, us); |
|
|
|
return listHandler; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
protected void afterLoadBean(PageDataset dataset, SwMap bean) { |
|
|
|
super.afterLoadBean(dataset, bean); |
|
|
|
if (dataset.isCurTable(UserParty.ENTITY_NAME)) { |
|
|
|
bean.put("sup_roles", CommUtil.getSqlInIds(UserRoleCache.getInstance().getRoleByParty(bean.readLong("sup_id")))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static class UserCustHandler extends AbstractHandler { |
|
|
|