use of com.bc.pmpheep.back.po.PmphGroupMember in project pmph by BCSquad.
the class MigrationStageEight method groupMember.
protected void groupMember() {
// 要迁移的旧库表名
String tableName = "bbs_groupusers";
// 增加new_pk字段
JdbcHelper.addColumn(tableName);
// 取得该表中所有数据
List<Map<String, Object>> maps = JdbcHelper.queryForList(tableName);
// 迁移成功的条目数
int count = 0;
List<Map<String, Object>> excel = new LinkedList<>();
Map<String, Object> result = new LinkedHashMap<>();
int correctCount = 0;
int[] state = { 0, 0, 0, 0 };
StringBuilder reason = new StringBuilder();
StringBuilder dealWith = new StringBuilder();
String sql = "SELECT sysflag FROM sys_user WHERE userid = ?";
String sql2 = "SELECT usertype FROM sys_userext WHERE userid = ?";
/* 开始遍历查询结果 */
for (Map<String, Object> map : maps) {
PmphGroupMember member = new PmphGroupMember();
String groupID = (String) map.get("groupID");
Long groupId = JdbcHelper.getPrimaryKey("bbs_group", "groupID", groupID);
if (null == groupId) {
map.put(SQLParameters.EXCEL_EX_HEADER, "未找到成员所属小组");
excel.add(map);
logger.error("未找到成员所属小组,此结果将被记录在Excel中");
if (state[0] == 0) {
reason.append("未找到成员所属小组。");
dealWith.append("放弃迁移。");
state[0] = 1;
}
continue;
}
String userID = (String) map.get("userID");
Long userId = JdbcHelper.getPrimaryKey("sys_user", "userid", userID);
if (null == userId) {
map.put(SQLParameters.EXCEL_EX_HEADER, "未找到成员在sys_user表中的对应主键");
excel.add(map);
logger.error("未找到成员在sys_user表中的对应主键,此结果将被记录在Excel中");
if (state[1] == 0) {
reason.append("没有查找到组员对应的用户。");
dealWith.append("放弃迁移。");
state[1] = 1;
}
continue;
} else {
member.setUserId(userId);
Integer sysflag = JdbcHelper.getJdbcTemplate().queryForObject(sql, Integer.class, userID);
switch(sysflag) {
case 0:
member.setIsWriter(false);
break;
case 1:
Integer usertype = JdbcHelper.getJdbcTemplate().queryForObject(sql2, Integer.class, userID);
if (usertype != null) {
if (usertype != 2) {
member.setIsWriter(true);
} else {
logger.error("该小组成员为机构用户,放弃迁移。");
continue;
}
} else {
continue;
}
break;
default:
map.put(SQLParameters.EXCEL_EX_HEADER, "小组成员对应的sysflag无法识别");
excel.add(map);
logger.error("小组成员对应的sysflag无法识别,此结果将被记录在Excel中");
if (state[2] == 0) {
reason.append("无法判断小组成员的用户类型。");
dealWith.append("放弃迁移。");
state[2] = 1;
}
continue;
}
}
member.setGroupId(groupId);
/* 是否创建者的判断依据是GUID是否等于groupID */
String guid = map.get("GUID").toString();
if (guid.equals(groupID)) {
member.setIsFounder(true);
} else {
member.setIsFounder(false);
}
String userName = map.get("userName").toString();
if (StringUtil.notEmpty(userName)) {
member.setDisplayName(userName);
} else {
logger.warn("userid为{}的小组成员没有昵称,将以账号名代替", userID);
String query = "SELECT usercode FROM sys_user WHERE userid = ?";
userName = JdbcHelper.getJdbcTemplate().queryForObject(query, String.class, userID);
member.setDisplayName(userName);
}
/* 旧表的isManager和新表的is_admin疑似刚好相反 */
int isManager = (Integer) map.get("isManager");
member.setIsAdmin(isManager == 0);
member = groupMemberService.addPmphGroupMember(member);
long pk = member.getId();
// 更新旧表中new_pk字段
JdbcHelper.updateNewPrimaryKey(tableName, pk, "GUID", guid);
count++;
if (member.getIsFounder()) {
PmphGroup pmphGroup = groupService.getPmphGroupById(groupId);
if (null == pmphGroup) {
map.put(SQLParameters.EXCEL_EX_HEADER, "小组id为:" + groupId + " 的小组没有找到");
excel.add(map);
if (state[3] == 0) {
reason.append("没有找到对应的小组。");
dealWith.append("放弃迁移。");
state[3] = 1;
}
continue;
}
pmphGroup.setFounderId(userId);
groupService.updatePmphGroup(pmphGroup);
}
if (null == map.get("exception")) {
correctCount++;
}
}
if (excel.size() > 0) {
try {
excelHelper.exportFromMaps(excel, "后台小组成员表", "pmph_group_member");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != maps.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "pmph_group_member");
result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "后台小组成员表");
result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, maps.size());
result.put(SQLParameters.EXCEL_HEADER_MIGRATED_DATA, count);
result.put(SQLParameters.EXCEL_HEADER_CORECT_DATA, correctCount);
result.put(SQLParameters.EXCEL_HEADER_TRANSFERED_DATA, count - correctCount);
result.put(SQLParameters.EXCEL_HEADER_NO_MIGRATED_DATA, maps.size() - count);
result.put(SQLParameters.EXCEL_HEADER_EXCEPTION_REASON, reason.toString());
result.put(SQLParameters.EXCEL_HEADER_DEAL_WITH, dealWith.toString());
SQLParameters.STATISTICS_RESULT.add(result);
}
logger.info("'{}'表迁移完成,异常条目数量:{}", tableName, excel.size());
logger.info("原数据库中共有{}条数据,迁移了{}条数据", maps.size(), count);
// 记录信息
Map<String, Object> msg = new HashMap<>();
msg.put("result", "" + tableName + " 表迁移完成" + count + "/" + maps.size());
SQLParameters.STATISTICS.add(msg);
}
use of com.bc.pmpheep.back.po.PmphGroupMember in project pmph by BCSquad.
the class PmphGroupMemberServiceImpl method deletePmphGroupMemberByIds.
@Override
public String deletePmphGroupMemberByIds(Long groupId, Long[] ids, String sessionId) throws CheckedServiceException {
String result = "FAIL";
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "该用户为空");
}
if (!pmphUser.getIsAdmin()) {
if (!isFounderOrisAdmin(groupId, sessionId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有操作权限");
}
}
Long userid = pmphUser.getId();
PmphGroupMemberVO currentUser = pmphGroupMemberDao.getPmphGroupMemberByMemberId(groupId, userid, false);
if (null == ids || ids.length == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "主键不能为空");
} else {
for (Long id : ids) {
PmphGroupMember pmphGroupMember = pmphGroupMemberDao.getPmphGroupMemberById(id);
if (userid == pmphGroupMember.getUserId() && !pmphGroupMember.getIsWriter()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "您无权限删除管理员,请重新选择");
}
if (pmphUser.getIsAdmin() || currentUser.getIsFounder()) {
// 只有小组创建者和超级管理员可以删除小组成员
if (pmphGroupMemberDao.getPmphGroupMemberById(id).getIsFounder()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "小组创建者不能删除,请重新选择");
}
pmphGroupMemberDao.deletePmphGroupMemberById(id);
} else {
// 管理员进入的方法
if (currentUser.getIsAdmin() && (pmphGroupMember.getIsFounder() || pmphGroupMember.getIsAdmin())) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "您无权限删除管理员,请重新选择");
} else {
pmphGroupMemberDao.deletePmphGroupMemberById(id);
}
}
}
result = "SUCCESS";
}
return result;
}
use of com.bc.pmpheep.back.po.PmphGroupMember in project pmph by BCSquad.
the class PmphGroupMemberServiceImpl method addEditorBookGroup.
@Override
public String addEditorBookGroup(Long textbookId, String sessionId) throws CheckedServiceException {
String result = "FAIL";
// 获取用户信息 进行判断用户是否有权限操作
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "该用户为空");
}
// 查询书籍信息
Textbook textbook = textbookService.getTextbookById(textbookId);
// 查询教材信息
Material material = materialService.getMaterialById(textbook.getMaterialId());
// 查询该教材是否存在项目编辑
MaterialProjectEditor materialProjectEditor = materialProjectEditorService.getMaterialProjectEditorByMaterialIdAndUserId(material.getId(), pmphUser.getId());
// 通过书籍id查询所有主编、副主编、编委
List<TextbookDecVO> textbookDecVOs = decPositionService.getTextbookEditorList(textbookId);
List<PmphGroupMember> list = new ArrayList<PmphGroupMember>(textbookDecVOs.size());
// 通过书籍id查询小组
PmphGroup pmphGroup = pmphGroupService.getPmphGroupByTextbookId(textbookId);
// 判断当前教材是否有更新小组的权限
// 小组权限的判断
Long materialId = textbook.getMaterialId();
String myPower = textbookService.listBookPosition(1, 9999, null, "[" + textbookId + "]", null, materialId, sessionId).getRows().get(0).getMyPower();
String groupPower = myPower.substring(6, 7);
if ("1".equals(groupPower)) {
// if(null!=material.getPlanPermission()||null!=material.getProjectPermission()){
// if(!BinaryUtil.getBit(material.getPlanPermission(), 7)||!BinaryUtil.getBit(material.getProjectPermission(), 7)){
// throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
// CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有更新成员权限 ");
// }
// }
// 通过小组id查询小组现有成员
List<PmphGroupMember> pmphGroupMembers = pmphGroupMemberDao.listPmphGroupMembers(pmphGroup.getId());
List<Long> groupUserIdList = new ArrayList<Long>(pmphGroupMembers.size());
for (PmphGroupMember pmphGroupMember : pmphGroupMembers) {
groupUserIdList.add(pmphGroupMember.getUserId());
}
// 通过遍历把不存在的成员添加到list中
for (TextbookDecVO textbookDecVO : textbookDecVOs) {
Long userId = textbookDecVO.getUserId();
if (!groupUserIdList.contains(userId)) {
list.add(new PmphGroupMember(userId, Const.TRUE, textbook.getMaterialId(), textbookId));
}
}
if (CollectionUtil.isEmpty(list)) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.SUCCESS, "小组成员已是最新");
}
pmphGroupMemberService.addPmphGroupMemberOnGroup(pmphGroup.getId(), list, sessionId);
result = "SUCCESS";
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有更新成员权限 ");
}
return result;
}
use of com.bc.pmpheep.back.po.PmphGroupMember in project pmph by BCSquad.
the class PmphGroupMemberServiceImpl method addPmphGroupMemberOnGroup.
@Override
public String addPmphGroupMemberOnGroup(Long groupId, List<PmphGroupMember> pmphGroupMembers, String sessionId) throws CheckedServiceException {
String result = "FAIL";
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
/**
* Textbook textbook=new Textbook();
* if(null!=pmphGroupMembers.get(0).getTextbookId()){
* //查询书籍信息
* textbook=textbookService.getTextbookById(pmphGroupMembers.get(0).getTextbookId());
* }
* Material material=new Material();
* if(null!=pmphGroupMembers.get(0).getMaterialId()){
* //查询教材信息
* material=materialService.getMaterialById(pmphGroupMembers.get(0).getMaterialId());
* }
* //查询该教材是否存在项目编辑
* MaterialProjectEditor materialProjectEditor=materialProjectEditorService.getMaterialProjectEditorByMaterialIdAndUserId(material.getId(), pmphUser.getId());
* ////判断当前教材是否有创建小组的权限
* if (!material.getDirector().equals(pmphUser.getId()) && !textbook.getPlanningEditor().equals(pmphUser.getId())
* && null == materialProjectEditor && !pmphUser.getIsAdmin()) {
* throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
* CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
*
* }
* if (null != material.getPlanPermission()) {
* if (!BinaryUtil.getBit(material.getPlanPermission(), 7)) {
* throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
* CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
* }
* }
* if (null != material.getProjectPermission()) {
* if (!BinaryUtil.getBit(material.getProjectPermission(), 7)) {
* throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
* CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
* }
* }
*/
// 小组权限的判断
Long materialId = pmphGroupMembers.get(0).getMaterialId();
Long textBookId = pmphGroupMembers.get(0).getTextbookId();
String myPower = textbookService.listBookPosition(1, 9999, null, "[" + textBookId + "]", null, materialId, sessionId).getRows().get(0).getMyPower();
String groupPower = myPower.substring(6, 7);
/**
* if (pmphUser.getIsAdmin() || isFounderOrisAdmin(groupId, sessionId)
* ||material.getDirector()==pmphUser.getId()||textbook.getPlanningEditor()==pmphUser.getId()
* ||pmphUser.getId()==materialProjectEditor.getEditorId()) {// 是超级管理员或者该小组的创建人和管理员才可以添加成员
*/
if ("1".equals(groupPower)) {
// 小组权限的判断 end
if (pmphGroupMembers.size() > 0) {
List<Long> writers = new ArrayList<>();
List<Long> pmphs = new ArrayList<>();
for (PmphGroupMember pmphGroupMember : pmphGroupMembers) {
PmphGroupMemberVO groupMember = pmphGroupMemberDao.getPmphGroupMemberByMemberId(groupId, pmphGroupMember.getUserId(), // 查看当前添加人员是否以前在小组中
pmphGroupMember.getIsWriter());
if (ObjectUtil.isNull(groupMember)) {
// 当前人员以前不在小组中
if (null == pmphGroupMember.getUserId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "成员id为空");
}
if (pmphGroupMember.getIsWriter()) {
WriterUser writerUser = writerUserService.get(pmphGroupMember.getUserId());
pmphGroupMember.setDisplayName(writerUser.getRealname());
writers.add(pmphGroupMember.getUserId());
} else {
PmphUser user = pmphUserService.get(pmphGroupMember.getUserId());
pmphGroupMember.setDisplayName(user.getRealname());
pmphs.add(pmphGroupMember.getUserId());
}
pmphGroupMember.setGroupId(groupId);
pmphGroupMemberDao.addPmphGroupMember(pmphGroupMember);
} else {
if (groupMember.getIsDeleted()) {
pmphGroupMember.setGroupId(groupId);
pmphGroupMember.setIsDeleted(false);
pmphGroupMemberDao.update(pmphGroupMember);
if (groupMember.getIsWriter()) {
writers.add(pmphGroupMember.getUserId());
} else {
pmphs.add(pmphGroupMember.getUserId());
}
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户已在小组中,请勿重复添加");
}
}
}
// 向添加的小组成员发送消息
try {
if (!writers.isEmpty()) {
// 向作家用户发送消息
systemMessageService.sendWhenInviteJoinGroup(pmphUser.getRealname(), groupId, writers, (short) 2);
}
if (!pmphs.isEmpty()) {
// 向社内用户发送消息
systemMessageService.sendWhenInviteJoinGroup(pmphUser.getRealname(), groupId, pmphs, (short) 1);
}
} catch (IOException e) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "发送消息失败" + e.getMessage());
}
result = "SUCCESS";
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "参数为空");
}
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
}
return result;
}
use of com.bc.pmpheep.back.po.PmphGroupMember in project pmph by BCSquad.
the class PmphGroupServiceImpl method addPmphGroupOnGroup.
@Override
public PmphGroup addPmphGroupOnGroup(String file, PmphGroup pmphGroup, HttpServletRequest request) throws CheckedServiceException, IOException {
String sessionId = CookiesUtil.getSessionId(request);
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (ObjectUtil.notNull(pmphGroupDao.getPmphGroupByGroupName(pmphGroup.getGroupName()))) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "该小组名称已被使用,请重新输入");
}
// 未上传小组头像时,获取默认小组头像路径
String groupImage = RouteUtil.DEFAULT_GROUP_IMAGE;
if (!StringUtil.isEmpty(file)) {
groupImage = saveFileToMongoDB(file, request);
}
pmphGroup.setGroupImage(groupImage);
pmphGroup.setFounderId(pmphUser.getId());
pmphGroupDao.addPmphGroup(pmphGroup);
if (null != pmphGroup.getId()) {
// 判断是否新增小组成功,如果成功则调用PmphGroupMemberService添加小组成员的方法将创建者添加到小组中
PmphGroupMember pmphGroupMember = new PmphGroupMember();
pmphGroupMember.setGroupId(pmphGroup.getId());
pmphGroupMember.setIsFounder(true);
pmphGroupMember.setUserId(pmphUser.getId());
pmphGroupMember.setDisplayName(pmphUser.getRealname());
pmphGroupMemberService.addPmphGroupMember(pmphGroupMember);
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.OBJECT_NOT_FOUND, "添加小组失败");
}
return pmphGroup;
}
Aggregations