use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class WriterRoleServiceImpl method addRoleResource.
@Override
public Integer addRoleResource(Long roleId, List<Long> permissionIds) throws CheckedServiceException {
// 添加时先删除当前权限
deleteRoleResourceByRoleId(roleId);
if (ObjectUtil.isNull(roleId) || permissionIds.size() < 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.ROLE_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "角色ID或资源ID为空时禁止新增");
}
List<WriterRolePermission> lists = new ArrayList<WriterRolePermission>();
WriterRolePermission writerRolePermission;
for (Long permissionId : permissionIds) {
writerRolePermission = new WriterRolePermission();
writerRolePermission.setRoleId(roleId);
writerRolePermission.setPermissionId(permissionId);
lists.add(writerRolePermission);
}
return roleDao.addRoleResource(lists);
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class WriterUserCertificationServiceImpl method updateWriterUserCertificationProgressByUserId.
@Override
public Integer updateWriterUserCertificationProgressByUserId(Short progress, Long[] userIds, HttpServletRequest request) throws CheckedServiceException, Exception {
String sessionId = CookiesUtil.getSessionId(request);
PmphUser pmphuser = SessionUtil.getPmphUserBySessionId(sessionId);
List<WriterUserCertification> writerUserCertifications = this.getWriterUserCertificationByUserIds(userIds);
if (ObjectUtil.isNull(progress)) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
Integer count = 0;
List<WriterUserCertification> wUserCertifications = new ArrayList<WriterUserCertification>(writerUserCertifications.size());
List<WriterUser> writerUsers = new ArrayList<>();
for (WriterUserCertification writerUserCertification : writerUserCertifications) {
if (Const.WRITER_PROGRESS_0 == writerUserCertification.getProgress()) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户信息未提交,不能审核");
}
if (Const.WRITER_PROGRESS_2 == writerUserCertification.getProgress() || Const.WRITER_PROGRESS_3 == writerUserCertification.getProgress()) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "已审核的用户不能再次审核");
}
wUserCertifications.add(new WriterUserCertification(writerUserCertification.getUserId(), progress));
writerUsers.add(new WriterUser(writerUserCertification.getUserId()));
}
if (CollectionUtil.isNotEmpty(wUserCertifications)) {
// 教师审核通过的同时修改普通用户级别为教师
count = writerUserCertificationDao.updateWriterUserCertificationProgressByUserId(wUserCertifications);
List<WriterUser> list = writerUserService.getWriterUserRankList(writerUsers);
for (WriterUser writerUser : list) {
// 当级别为0并且是通过的时候修改
if (0 == writerUser.getRank() && 3 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setRank(1);
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(true);
writerUserService.updateWriterUserRank(wrs);
}
// 当级别为0并且是退回的时候修改
} else if (0 == writerUser.getRank() && 2 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(false);
writerUserService.updateWriterUser(wrs);
}
// 当级别为1并且是通过的时候修改
} else if (1 == writerUser.getRank() && 3 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(true);
writerUserService.updateWriterUserRank(wrs);
}
// 当级别为1并且是退回的时候修改
} else if (1 == writerUser.getRank() && 2 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(false);
writerUserService.updateWriterUser(wrs);
}
// 当级别为2并且是通过的时候修改
} else if (2 == writerUser.getRank() && 3 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(true);
writerUserService.updateWriterUserRank(wrs);
}
// 当级别为2并且是退回的时候修改
} else if (2 == writerUser.getRank() && 2 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(false);
writerUserService.updateWriterUser(wrs);
}
// 当级别为3并且是通过的时候修改
} else if (3 == writerUser.getRank() && 3 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(true);
writerUserService.updateWriterUserRank(wrs);
}
// 当级别为2并且是退回的时候修改
} else if (3 == writerUser.getRank() && 2 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(false);
writerUserService.updateWriterUser(wrs);
}
}
}
}
// 认证通过或退回的推送消息
Boolean isPass = null;
if (2 == progress) {
isPass = false;
}
if (3 == progress) {
isPass = true;
}
if (null != isPass) {
List<Long> teacherIds = new ArrayList<>();
for (int i = 0; i < userIds.length; i++) {
teacherIds.add(userIds[0]);
}
// 获取用户认证类型和认证人
List<WriterUser> users = writerUserService.getWriterUserList(userIds);
for (WriterUser writerUser : users) {
if (1 == writerUser.getAuthUserType()) {
// 社内用户
PmphUser pmphUser = pmphUserService.get(writerUser.getAuthUserId());
systemMessageService.sendWhenTeacherCertificationAudit(pmphUser.getRealname(), teacherIds, isPass);
}
if (2 == writerUser.getAuthUserType()) {
// 学校机构用户
OrgUser orgUsers = orgUserService.getOrgUserById(writerUser.getAuthUserId());
Org org = orgService.getOrgById(orgUsers.getOrgId());
systemMessageService.sendWhenTeacherCertificationAudit(org.getOrgName(), teacherIds, isPass);
}
}
}
return count;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class WriterUserServiceImpl method addWriterUserOfBack.
@Override
public String addWriterUserOfBack(WriterUser writerUser) throws CheckedServiceException {
WriterUser username = writerUserDao.getUsername(writerUser.getUsername());
if (username != null) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户代码已存在");
}
if (StringUtil.strLength(writerUser.getUsername()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户名需要小于20字符");
}
if (StringUtil.strLength(writerUser.getRealname()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "姓名需要小于20字符");
}
if (!StringUtil.isEmpty(writerUser.getHandphone())) {
if (!ValidatUtil.checkMobileNumber(writerUser.getHandphone())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "电话格式不正确");
}
}
if (!StringUtil.isEmpty(writerUser.getEmail())) {
if (!ValidatUtil.checkEmail(writerUser.getEmail())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "邮箱格式不正确");
}
}
if (StringUtil.isEmpty(writerUser.getUsername())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户名为空");
}
if (StringUtil.isEmpty(writerUser.getRealname())) {
writerUser.setRealname(writerUser.getUsername());
}
if (!StringUtil.isEmpty(writerUser.getNote())) {
if (StringUtil.strLength(writerUser.getNote()) > 100) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "备注需要小于100字符");
}
}
// 后台添加用户设置默认密码为123456
writerUser.setPassword(new DesRun("", Const.DEFAULT_PASSWORD).enpsw);
writerUser.setNickname(writerUser.getUsername());
// 后台添加新用户时,设置为默认头像
writerUser.setAvatar(RouteUtil.DEFAULT_USER_AVATAR);
writerUserDao.add(writerUser);
Long num = writerUser.getId();
String result = "FAIL";
if (num > 0) {
WriterProfile writerProfile = new WriterProfile();
writerProfile.setUserId(num);
writerProfileDao.addWriterProfile(writerProfile);
result = "SUCCESS";
}
return result;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class SystemMessageService method sendWhenInviteJoinGroup.
/**
* 任意用户被邀请进入小组 向被邀请人发出
*
* @author Mryang
* @createDate 2017年11月17日 下午2:16:36
* @param inviterName
* 邀请人名字
* @param groupId
* 小组id
* @param invitedPersonIds
* 被邀请人ids
* @param invitedPersonType
* 被邀请人类型: 1=社内用户/2=作家/3=机构用户
* @throws CheckedServiceException
* @throws IOException
*/
public void sendWhenInviteJoinGroup(String inviterName, Long groupId, List<Long> invitedPersonIds, short invitedPersonType) throws CheckedServiceException, IOException {
if (StringUtils.isEmpty(inviterName)) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "邀请人为空");
}
if (null == invitedPersonIds || invitedPersonIds.size() == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "被邀请人为空");
}
// 获取小组
PmphGroup pmphGroup = pmphGroupService.getPmphGroupById(groupId);
if (null == pmphGroup) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "小组不存在");
}
String msgContent = "您被[<font color='red'>" + inviterName + "</font>]邀请加入[<font color='red'>" + pmphGroup.getGroupName() + "]</font>小组";
// 存入消息主体
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 组装消息和消息对象
List<UserMessage> userMessageList = new ArrayList<UserMessage>(invitedPersonIds.size());
List<String> userIds = new ArrayList<String>(invitedPersonIds.size());
for (Long id : invitedPersonIds) {
UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), id, invitedPersonType, null);
userMessageList.add(userMessage);
userIds.add(invitedPersonType + "_" + id);
}
// 发送消息
userMessageService.addUserMessageBatch(userMessageList);
// websocket推送页面消息
WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class SystemMessageService method sendWhenTeacherCertificationAudit.
/**
* 教师认证审 向教师用户发送消息
*
* @author Mryang
* @createDate 2017年11月17日 下午2:52:53
* @param auditorOrgName
* 认证机构名称,如:首都医科大学,如是人卫社认证的审核,则为:人民卫生出版社
* @param teacherIds
* 教师ids
* @param isPass
* true 通过/false 退回
* @throws CheckedServiceException
* @throws IOException
*/
public void sendWhenTeacherCertificationAudit(String auditorOrgName, List<Long> teacherIds, boolean isPass) throws CheckedServiceException, IOException {
if (StringUtils.isEmpty(auditorOrgName)) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "审核机构为空");
}
if (null == teacherIds || teacherIds.size() == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "认证的教师为空");
}
// 存入消息主体
// 退回
String msgContent = "抱歉,您提交的教师认证资料已被[<font color='red'>" + auditorOrgName + "</font>]管理员退回,请您核对后重试";
if (isPass) {
// 通过
msgContent = "恭喜!您提交的教师认证资料已通过[<font color='red'>" + auditorOrgName + "</font>]管理员审核";
}
// 存入消息主体
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 组装消息和消息对象
List<UserMessage> userMessageList = new ArrayList<UserMessage>(teacherIds.size());
List<String> userIds = new ArrayList<String>(teacherIds.size());
// 发送消息
for (Long id : teacherIds) {
UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), id, new Short("2"), null);
userMessageList.add(userMessage);
userIds.add("2_" + id);
}
userMessageService.addUserMessageBatch(userMessageList);
// websocket推送页面消息
WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
Aggregations