use of com.ngtesting.platform.entity.TestRelationOrgGroupUser in project ngtesting-platform by aaronchen2k.
the class RelationOrgGroupUserServiceImpl method listRelations.
private List<TestRelationOrgGroupUser> listRelations(Long orgId, Long orgGroupId, Long userId) {
DetachedCriteria dc2 = DetachedCriteria.forClass(TestRelationOrgGroupUser.class);
if (orgId != null) {
dc2.add(Restrictions.eq("orgId", orgId));
}
// 以下2个条件只会有一个
if (orgGroupId != null) {
dc2.add(Restrictions.eq("orgGroupId", orgGroupId));
}
if (userId != null) {
dc2.add(Restrictions.eq("userId", userId));
}
dc2.add(Restrictions.eq("deleted", Boolean.FALSE));
dc2.add(Restrictions.eq("disabled", Boolean.FALSE));
dc2.addOrder(Order.asc("id"));
List<TestRelationOrgGroupUser> relations = findAllByCriteria(dc2);
return relations;
}
use of com.ngtesting.platform.entity.TestRelationOrgGroupUser in project ngtesting-platform by aaronchen2k.
the class RelationOrgGroupUserServiceImpl method listRelationsByGroup.
@Override
public List<RelationOrgGroupUserVo> listRelationsByGroup(Long orgId, Long orgGroupId) {
List<TestUser> allUsers = listAllOrgUsers(orgId);
List<TestRelationOrgGroupUser> relations;
if (orgGroupId == null) {
relations = new LinkedList<>();
} else {
relations = listRelations(orgId, orgGroupId, null);
}
List<RelationOrgGroupUserVo> vos = new LinkedList<>();
for (TestUser user : allUsers) {
RelationOrgGroupUserVo vo = genVo(orgId, orgGroupId, user.getId());
vo.setSelected(false);
vo.setSelecting(false);
for (TestRelationOrgGroupUser po : relations) {
if (po.getUserId().longValue() == user.getId().longValue() && po.getOrgGroupId().longValue() == orgGroupId.longValue()) {
vo.setSelected(true);
vo.setSelecting(true);
}
}
vos.add(vo);
}
return vos;
}
use of com.ngtesting.platform.entity.TestRelationOrgGroupUser in project ngtesting-platform by aaronchen2k.
the class RelationOrgGroupUserServiceImpl method listRelationsByUser.
@Override
public List<RelationOrgGroupUserVo> listRelationsByUser(Long orgId, Long userId) {
List<TestOrgGroup> allOrgGroups = listAllOrgGroups(orgId);
List<TestRelationOrgGroupUser> relations;
if (userId == null) {
relations = new LinkedList<>();
} else {
relations = listRelations(orgId, null, userId);
}
List<RelationOrgGroupUserVo> vos = new LinkedList<>();
for (TestOrgGroup orgGroup : allOrgGroups) {
RelationOrgGroupUserVo vo = genVo(orgId, orgGroup.getId(), userId);
vo.setSelected(false);
vo.setSelecting(false);
for (TestRelationOrgGroupUser po : relations) {
if (po.getOrgGroupId() == orgGroup.getId() && po.getUserId() == userId) {
vo.setSelected(true);
vo.setSelecting(true);
}
}
vos.add(vo);
}
return vos;
}
use of com.ngtesting.platform.entity.TestRelationOrgGroupUser in project ngtesting-platform by aaronchen2k.
the class RelationOrgGroupUserServiceImpl method getRelationOrgGroupUser.
private TestRelationOrgGroupUser getRelationOrgGroupUser(Long orgGroupId, Long userId) {
DetachedCriteria dc = DetachedCriteria.forClass(TestRelationOrgGroupUser.class);
dc.add(Restrictions.eq("orgGroupId", orgGroupId));
dc.add(Restrictions.eq("userId", userId));
dc.addOrder(Order.asc("id"));
List<TestRelationOrgGroupUser> ls = findAllByCriteria(dc);
if (ls.size() == 0) {
return null;
}
return ls.get(0);
}
use of com.ngtesting.platform.entity.TestRelationOrgGroupUser in project ngtesting-platform by aaronchen2k.
the class RelationOrgGroupUserServiceImpl method saveRelations.
@Override
public boolean saveRelations(List<RelationOrgGroupUserVo> orgGroupUserVos) {
if (orgGroupUserVos == null) {
return false;
}
for (Object obj : orgGroupUserVos) {
RelationOrgGroupUserVo vo = JSON.parseObject(JSON.toJSONString(obj), RelationOrgGroupUserVo.class);
if (vo.getSelecting() != vo.getSelected()) {
// 变化了
TestRelationOrgGroupUser relationOrgGroupUser = this.getRelationOrgGroupUser(vo.getOrgGroupId(), vo.getUserId());
if (vo.getSelecting() && relationOrgGroupUser == null) {
// 勾选
relationOrgGroupUser = new TestRelationOrgGroupUser(vo.getOrgId(), vo.getOrgGroupId(), vo.getUserId());
saveOrUpdate(relationOrgGroupUser);
} else if (relationOrgGroupUser != null) {
// 取消
getDao().delete(relationOrgGroupUser);
}
}
}
return true;
}
Aggregations