use of com.bc.pmpheep.back.po.PmphGroupMessage in project pmph by BCSquad.
the class PmphGroupMessageServiceImpl method deletePmphGroupMessageById.
/**
* @param id
* @return 影响行数
* @throws CheckedServiceException
* @throws IOException
*/
@Override
public String deletePmphGroupMessageById(Long id, String sessionId) throws CheckedServiceException, IOException {
if (null == id) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "主键为空");
}
PmphGroupMessage pmphGroupMessage = pmphGroupMessageDao.getPmphGroupMessageById(id);
Long groupId = pmphGroupMessage.getGroupId();
int num = pmphGroupMessageDao.deletePmphGroupMessageById(id);
if (num > 0) {
// 删除成功 撤销消息
WebScocketMessage webScocketMessage = new WebScocketMessage();
webScocketMessage.setId(String.valueOf(id));
webScocketMessage.setGroupId(groupId);
webScocketMessage.setSendType(Const.SEND_MSG_TYPE_1);
List<PmphGroupMemberVO> list = pmphGroupMemberService.listPmphGroupMember(groupId, sessionId);
List<String> ids = new ArrayList<String>();
for (PmphGroupMemberVO groupMemberVO : list) {
String tempId = (groupMemberVO.getIsWriter() ? "2" : "1") + "_" + groupMemberVO.getUserId();
ids.add(tempId);
}
handler.sendWebSocketMessageToUser(ids, webScocketMessage);
}
return "SUCCESS";
}
use of com.bc.pmpheep.back.po.PmphGroupMessage in project pmph by BCSquad.
the class MigrationStageEight method groupMessage.
protected void groupMessage() {
// 要迁移的旧库表名
String tableName = "bbs_discuss";
// 增加new_pk字段
JdbcHelper.addColumn(tableName);
/* 取得PmphGroupMember对应旧表的所有数据 */
// 取得该表中所有数据
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 };
StringBuilder reason = new StringBuilder();
StringBuilder dealWith = new StringBuilder();
String sql = "SELECT new_pk FROM bbs_groupusers WHERE groupID = ? AND userID = ?";
/* 以下开始遍历旧表数据,根据相应规则进行数据转换 */
for (Map<String, Object> map : maps) {
PmphGroupMessage groupMessage = new PmphGroupMessage();
String groupID = (String) map.get("groupID");
Long groupId = JdbcHelper.getPrimaryKey("bbs_group", "groupID", groupID);
/* 如果消息没有对应的小组id,则小组可能已被删除,这里应该打印并记录(待完成) */
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;
}
groupMessage.setGroupId(groupId);
/* 新库member_id是pmph_group_member的主键,这里需要转换 */
String userID = (String) map.get("userID");
Long memberId = JdbcHelper.getJdbcTemplate().queryForObject(sql, Long.class, groupID, userID);
if (null == memberId) {
map.put(SQLParameters.EXCEL_EX_HEADER, "未找到消息对应成员");
excel.add(map);
logger.error("未找到消息对应成员,此结果将被记录在Excel中");
if (state[1] == 0) {
reason.append("没有找到消息所对应的小组成员。");
dealWith.append("放弃迁移。");
state[1] = 1;
}
continue;
}
groupMessage.setMemberId(memberId);
String content = (String) map.get("content");
groupMessage.setMsgContent(content);
String createtime = map.get("createtime").toString();
groupMessage.setGmtCreate(Timestamp.valueOf(createtime));
String id = (String) map.get("ID");
groupMessage = groupMessageService.addPmphGroupMessage(groupMessage);
long pk = groupMessage.getId();
// 更新旧表中new_pk字段
JdbcHelper.updateNewPrimaryKey(tableName, pk, "ID", id);
count++;
if (null == map.get("exception")) {
correctCount++;
}
}
if (excel.size() > 0) {
try {
excelHelper.exportFromMaps(excel, "后台小组消息表", "pmph_group_message");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != maps.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "pmph_group_message");
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.PmphGroupMessage in project pmph by BCSquad.
the class PmphGroupMessageServiceImpl method addGroupMessage.
@Override
public String addGroupMessage(String msgConrent, Long groupId, String sessionId, Short senderType) throws CheckedServiceException, IOException {
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
Long userId = pmphUser.getId();
PmphGroupMemberVO pmphGroupMemberVO = pmphGroupMemberService.getPmphGroupMemberByMemberId(groupId, userId, // 获取后台用户
false);
if (ObjectUtil.isNull(pmphGroupMemberVO)) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "您不是该小组成员,无法与其他成员对话或上传小组文件。");
}
PmphGroupMessage pmphGroupMessage;
if (senderType == 0) {
pmphGroupMessage = new PmphGroupMessage(groupId, 0L, msgConrent);
} else {
pmphGroupMessage = new PmphGroupMessage(groupId, pmphGroupMemberVO.getId(), msgConrent);
}
pmphGroupMessageDao.addPmphGroupMessage(pmphGroupMessage);
pmphGroupMessage = pmphGroupMessageDao.getPmphGroupMessageById(pmphGroupMessage.getId());
// 将该条消息创建时间作为最后一条消息时间放入该小组中
PmphGroup pmphGroup = new PmphGroup();
pmphGroup.setId(groupId);
pmphGroup.setGmtLastMessage(pmphGroupMessage.getGmtCreate());
pmphGroupDao.updatePmphGroup(pmphGroup);
// 进行推送消息步骤1.查询接收人的id 2.进行推送
List<PmphGroupMemberVO> list = pmphGroupMemberService.listPmphGroupMember(groupId, sessionId);
List<String> ids = new ArrayList<String>();
for (PmphGroupMemberVO groupMemberVO : list) {
String tempId = (groupMemberVO.getIsWriter() ? "2" : "1") + "_" + groupMemberVO.getUserId();
ids.add(tempId);
}
WebScocketMessage webScocketMessage = new WebScocketMessage(String.valueOf(pmphGroupMessage.getId()), Const.MSG_TYPE_3, userId, pmphGroupMemberVO.getDisplayName(), senderType, Const.SEND_MSG_TYPE_0, null, null, msgConrent, pmphGroupMessage.getGmtCreate());
webScocketMessage.setGroupId(groupId);
webScocketMessage.setSenderIcon(pmphGroupMemberVO.getAvatar());
handler.sendWebSocketMessageToUser(ids, webScocketMessage);
return "SUCCESS";
}
Aggregations