use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class OrgUserServiceImpl method updateOrgUserOfBack.
@Override
public String updateOrgUserOfBack(OrgAndOrgUserVO orgAndOrgUserVO) throws CheckedServiceException {
OrgUser username = orgUserDao.getOrgUserById(orgAndOrgUserVO.getId());
if (!username.getUsername().equals(orgAndOrgUserVO.getUsername())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "机构代码不相同");
}
if (ObjectUtil.isNull(orgAndOrgUserVO.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "主键为空");
}
if (StringUtil.strLength(orgAndOrgUserVO.getUsername()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户名不能超过20个字符");
}
if (StringUtil.isEmpty(orgAndOrgUserVO.getUsername())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "机构代码不能为空");
}
if (StringUtil.strLength(orgAndOrgUserVO.getRealname()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "管理员姓名不能超过20个字符");
}
if (StringUtil.strLength(orgAndOrgUserVO.getNote()) > 100) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "备注不能超过100个字符");
}
if (!StringUtil.isEmpty(orgAndOrgUserVO.getEmail())) {
if (!ValidatUtil.checkEmail(orgAndOrgUserVO.getEmail())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "邮箱不符合规范");
}
}
if (!StringUtil.isEmpty(orgAndOrgUserVO.getHandphone())) {
if (!ValidatUtil.checkMobileNumber(orgAndOrgUserVO.getHandphone())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "手机号码不符合规范");
}
}
if (StringUtil.isEmpty(orgAndOrgUserVO.getOrgName())) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.ILLEGAL_PARAM, "机构名称为空");
}
if (StringUtil.strLength(orgAndOrgUserVO.getOrgName()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.ILLEGAL_PARAM, "机构名称过长");
}
// 通过id查询机构用户来判断该机构名称是否被使用或者用户名等于数据库的机构
Org orgname = orgDao.getOrgById(orgAndOrgUserVO.getOrgId());
if (!orgname.getOrgName().equals(orgAndOrgUserVO.getOrgName())) {
if (orgDao.getOrgByOrgName(orgAndOrgUserVO.getOrgName()).size() > 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.ILLEGAL_PARAM, "该机构名称已被使用,请重新输入");
}
}
Org org = new Org();
org.setId(orgAndOrgUserVO.getOrgId());
org.setOrgName(orgAndOrgUserVO.getOrgName());
org.setOrgTypeId(orgAndOrgUserVO.getOrgTypeId());
org.setAreaId(orgAndOrgUserVO.getAreaId());
if (ObjectUtil.notNull(org)) {
orgDao.updateOrg(org);
}
OrgUser orgUser = new OrgUser();
orgUser.setId(orgAndOrgUserVO.getId());
if (StringUtil.isEmpty(orgAndOrgUserVO.getRealname())) {
orgUser.setRealname(orgAndOrgUserVO.getUsername());
} else {
orgUser.setRealname(orgAndOrgUserVO.getRealname());
}
orgUser.setIsDisabled(orgAndOrgUserVO.getIsDisabled());
orgUser.setHandphone(orgAndOrgUserVO.getHandphone());
orgUser.setEmail(orgAndOrgUserVO.getEmail());
orgUser.setAddress(orgAndOrgUserVO.getNote());
String result = "FAIL";
if (ObjectUtil.notNull(orgUser)) {
// 返回的影响行数,如果不是影响0行就是添加成功
int count = orgUserDao.updateOrgUser(orgUser);
if (count > 0) {
result = "SUCCESS";
}
}
return result;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class OrgUserServiceImpl method updateOrgUserProgressById.
@Override
public Integer updateOrgUserProgressById(Integer progress, List<Long> orgUserIds) throws CheckedServiceException, IOException {
if (CollectionUtil.isEmpty(orgUserIds) || ObjectUtil.isNull(progress)) {
throw new CheckedServiceException(CheckedExceptionBusiness.SCHOOL_ADMIN_CHECK, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
List<OrgUser> orgUserList = orgUserDao.getOrgUserByIds(orgUserIds);
Integer count = 0;
if (CollectionUtil.isNotEmpty(orgUserList)) {
List<OrgUser> orgUsers = new ArrayList<OrgUser>(orgUserList.size());
for (OrgUser orgUser : orgUserList) {
if (Const.ORG_USER_PROGRESS_1 == orgUser.getProgress() || Const.ORG_USER_PROGRESS_2 == orgUser.getProgress()) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "已审核的用户不能再次审核");
}
orgUsers.add(new OrgUser(orgUser.getId(), progress));
}
if (CollectionUtil.isNotEmpty(orgUsers)) {
count = orgUserDao.updateOrgUserProgressById(orgUsers);
}
}
Boolean isPass = null;
if (1 == progress) {
isPass = true;
}
if (2 == progress) {
isPass = false;
}
if (null != isPass) {
// 推送机构认证审核信息
systemMessageService.sendWhenManagerCertificationAudit(orgUserIds, isPass);
}
return count;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class UserMessageServiceImpl method getUserMessageById.
@Override
public Map<String, Object> getUserMessageById(Long userMsgId) {
Map<String, Object> resultMap = new HashMap<String, Object>();
if (ObjectUtil.isNull(userMsgId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "消息ID为空!");
}
UserMessage userMessage = userMessageDao.getUserMessageById(userMsgId);
if (ObjectUtil.isNull(userMessage)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户消息对象为空!");
}
String realName = null;
if (Const.SENDER_TYPE_0 == userMessage.getSenderType() || Const.SENDER_TYPE_1 == userMessage.getSenderType()) {
PmphUser pmphUser = pmphUserService.get(userMessage.getSenderId());
realName = pmphUser.getRealname();
}
if (Const.SENDER_TYPE_2 == userMessage.getSenderType()) {
WriterUser writerUser = writerUserService.get(userMessage.getSenderId());
realName = writerUser.getRealname();
}
if (Const.SENDER_TYPE_3 == userMessage.getSenderType()) {
OrgUser orgUser = orgUserService.getOrgUserById(userMessage.getSenderId());
realName = orgUser.getRealname();
}
// 主键ID
resultMap.put("msgId", userMessage.getId());
// 标题
resultMap.put("title", userMessage.getTitle());
// 发送者
resultMap.put("senderName", realName);
// 发送时间
resultMap.put("senderDate", userMessage.getGmtCreate());
// 获取消息内容
Message message = messageService.get(userMessage.getMsgId());
if (ObjectUtil.notNull(message)) {
// throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE,
// CheckedExceptionResult.NULL_PARAM, "消息对象为空!");
// 内容
resultMap.put("content", message.getContent());
List<MessageAttachment> messageAttachments = messageAttachmentService.getMessageAttachmentByMsgId(message.getId());
if (CollectionUtil.isNotEmpty(messageAttachments)) {
for (MessageAttachment mAttachment : messageAttachments) {
String attachmentId = mAttachment.getAttachment();
mAttachment.setAttachment(Const.FILE_DOWNLOAD + attachmentId);
}
}
// 内容附件
resultMap.put("MessageAttachment", messageAttachments);
}
return resultMap;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class UserMessageServiceImpl method saveFileToMongoDB.
/**
* <pre>
* 功能描述:保存文件到MongoDB
* 使用示范:
*
* @param files 临时文件路径
* @param msgId messageId
* @throws CheckedServiceException
* </pre>
*/
private void saveFileToMongoDB(HttpServletRequest request, String[] files, String msgId) throws IOException {
// 添加附件到MongoDB表中
if (ArrayUtil.isNotEmpty(files)) {
for (int i = 0; i < files.length; i++) {
byte[] fileByte = (byte[]) request.getSession(false).getAttribute(files[i]);
String fileName = (String) request.getSession(false).getAttribute("fileName_" + files[i]);
InputStream sbs = new ByteArrayInputStream(fileByte);
String gridFSFileId = fileService.save(sbs, fileName, FileType.MSG_FILE, CastUtil.castLong(msgId));
if (StringUtil.isEmpty(gridFSFileId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.FILE_UPLOAD_FAILED, "文件上传失败!");
}
// 保存对应数据
MessageAttachment mAttachment = messageAttachmentService.addMessageAttachment(new MessageAttachment(msgId, gridFSFileId, fileName));
if (ObjectUtil.isNull(mAttachment.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "MessageAttachment对象保存失败!");
}
// String localFile = files[i];
// String fileDirectory =
// localFile.substring(0, localFile.lastIndexOf(File.separatorChar));
// FileUtil.delete(fileDirectory);// 删除本地临时文件
}
}
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class UserMessageServiceImpl method addOrUpdateUserMessage.
@Override
public Integer addOrUpdateUserMessage(HttpServletRequest request, Message message, String title, Integer sendType, String orgIds, Long senderId, String userIds, String bookIds, boolean isSave, String[] files, String sessionId) throws CheckedServiceException, IOException {
if (ObjectUtil.isNull(sendType)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "发送对象未选择,请选择!");
}
if (title.length() > 50) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "消息标题不能超过50个字");
}
// 如果 补发不进行消息插入
if (isSave) {
// MongoDB 消息插入
message = messageService.add(message);
}
if (StringUtil.isEmpty(message.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
}
// 发送者id
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "操作人为空!");
}
// 是否为补发消息设置(发送者ID)
Long senderUserId;
if (ObjectUtil.isNull(senderId)) {
// 新发消息,发送者Id为登陆用户ID
senderUserId = pmphUser.getId();
} else {
// 补发消息,发送者Id为当前补发消息的发送者ID
senderUserId = senderId;
}
// 装储存数据
List<UserMessage> userMessageList = new ArrayList<UserMessage>();
// 1 发送给学校管理员 //2 所有人
if (Const.SEND_OBJECT_1.intValue() == sendType.intValue() || Const.SEND_OBJECT_2.intValue() == sendType.intValue()) {
if (StringUtil.isEmpty(orgIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "参数错误!");
}
String[] orgIds1 = StringUtil.str2StrArray(orgIds);
List<Long> orgIds2 = new ArrayList<Long>(orgIds1.length);
for (String id : orgIds1) {
if (StringUtil.notEmpty(id)) {
orgIds2.add(Long.parseLong(id));
}
}
List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(orgIds2);
// 机构用户
for (OrgUser orgUser : orgUserList) {
userMessageList.add(new UserMessage(message.getId(), title, Const.MSG_TYPE_1, senderUserId, Const.SENDER_TYPE_1, orgUser.getId(), Const.RECEIVER_TYPE_3, 0L));
}
// 作家用户
if (Const.SEND_OBJECT_2.intValue() == sendType.intValue()) {
List<WriterUser> writerUserList = writerUserService.getWriterUserListByOrgIds(orgIds2);
for (WriterUser writerUser : writerUserList) {
userMessageList.add(new UserMessage(message.getId(), title, Const.MSG_TYPE_1, senderUserId, Const.SENDER_TYPE_1, writerUser.getId(), Const.RECEIVER_TYPE_2, 0L));
}
}
}
// 3 指定用户
if (Const.SEND_OBJECT_3.intValue() == sendType.intValue()) {
if (StringUtil.isEmpty(userIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "没有选中发送人!");
}
String[] ids = StringUtil.str2StrArray(userIds);
for (String id : ids) {
if (StringUtil.notEmpty(id)) {
String userType = id.split("_")[0];
String userId = id.split("_")[1];
if (StringUtil.notEmpty(userId) && StringUtil.isNumeric(userId)) {
userMessageList.add(new UserMessage(message.getId(), title, Const.MSG_TYPE_1, senderUserId, Const.SENDER_TYPE_1, Long.parseLong(userId), new Short(userType), 0L));
}
}
}
}
// 4 发送给教材所有报名者
if (Const.SEND_OBJECT_4.intValue() == sendType.intValue()) {
if (StringUtil.isEmpty(bookIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "书籍为空!");
}
String[] ids = StringUtil.str2StrArray(bookIds);
List<Long> userIdList = decPositionService.listDecPositionsByTextbookIds(ids);
for (Long userId : userIdList) {
userMessageList.add(new UserMessage(message.getId(), title, Const.MSG_TYPE_1, senderUserId, Const.SENDER_TYPE_1, userId, Const.RECEIVER_TYPE_2, 0L));
}
// 获取到书籍id然后根据书籍id在dec_position表中获取到申报表id根据申报表id在declaration表中获取作家id放入userMessage的接收人中
}
// 如果是补发,进入下面操作 进行已发人员筛出
if (!isSave) {
// 查询当前消息内容
Message msg = messageService.get(message.getId());
if (ObjectUtil.notNull(msg)) {
message.setContent(msg.getContent());
}
List<UserMessage> temp = new ArrayList<UserMessage>();
// 已经发送的人员列表
List<UserMessage> sendedList = userMessageDao.getMessageByMsgId(message.getId());
// 已发送消息是否撤回
Boolean isWithdraw = false;
for (UserMessage userMessage : userMessageList) {
// 没有发送
boolean flag = false;
for (UserMessage uMessage : sendedList) {
if (!isWithdraw) {
if (uMessage.getIsWithdraw()) {
// 判断消息是否撤回
isWithdraw = true;
}
}
if (userMessage.getReceiverId().longValue() == uMessage.getReceiverId().longValue() && userMessage.getReceiverType().shortValue() == uMessage.getReceiverType().shortValue()) {
flag = true;
break;
}
}
if (!flag) {
temp.add(userMessage);
}
}
userMessageList = temp;
// 补发,取消撤回当前已发送的消息
if (isWithdraw) {
this.updateCancelToWithdraw(message.getId());
}
}
// 插入消息发送对象数据
if (CollectionUtil.isNotEmpty(userMessageList)) {
userMessageDao.addUserMessageBatch(userMessageList);
}
// websocket发送的id集合
List<String> websocketUserIds = new ArrayList<String>();
for (UserMessage userMessage : userMessageList) {
websocketUserIds.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
}
// webscokt发送消息
if (CollectionUtil.isNotEmpty(websocketUserIds)) {
WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_1, senderUserId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, title, message.getContent(), DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
// 添加附件到MongoDB表中
saveFileToMongoDB(request, files, message.getId());
}
return userMessageList.size();
}
Aggregations