use of com.bc.pmpheep.service.exception.CheckedServiceException 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;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class PmphGroupServiceImpl method addEditorSelcetionGroup.
@Override
public PmphGroup addEditorSelcetionGroup(String sessionId, List<PmphGroupMember> list, Long textbookId) throws CheckedServiceException {
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (list.size() == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "成员名单为空,更新失败");
}
Textbook textbook = textbookService.getTextbookById(textbookId);
list.get(0).setTextbookId(textbookId);
list.get(0).setMaterialId(textbook.getMaterialId());
// 未上传小组头像时,获取默认小组头像路径
String groupImage = RouteUtil.DEFAULT_GROUP_IMAGE;
PmphGroup pmphGroup = new PmphGroup();
// 查询小组名称是否已存在 不存在直接用书名
if (ObjectUtil.isNull(pmphGroupDao.getPmphGroupByGroupName(textbook.getTextbookName()))) {
pmphGroup.setGroupName(textbook.getTextbookName());
} else {
// 存在则用书名加当前小组总数进行区分
Long count = pmphGroupDao.getPmphGroupCount();
pmphGroup.setGroupName(textbook.getTextbookName() + count);
}
pmphGroup.setGroupImage(groupImage);
pmphGroup.setBookId(textbookId);
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);
// 批量把前台传入的作家用户添加到该小组
pmphGroupMemberService.addPmphGroupMemberOnGroup(pmphGroup.getId(), list, sessionId);
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.OBJECT_NOT_FOUND, "添加小组和成员失败");
}
return pmphGroup;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class PmphGroupServiceImpl method listPmphGroupFile.
@Override
public List<PmphGroupListVO> listPmphGroupFile(PmphGroup pmphGroup, String sessionId) throws CheckedServiceException {
if (null == pmphGroup) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "参数对象为空");
}
// session PmphUser用户验证
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
List<PmphGroupListVO> list = new ArrayList<>();
list = pmphGroupDao.getList(pmphGroup, pmphUser.getId());
for (PmphGroupListVO pmphGroupListVO : list) {
pmphGroupListVO.setGroupImage(RouteUtil.groupImage(pmphGroupListVO.getGroupImage()));
}
return list;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class PmphUserServiceImpl method getListByUsernameAndRealname.
@Override
public PageResult<PmphUserManagerVO> getListByUsernameAndRealname(String name, int number, int size) throws CheckedServiceException {
if (null == name || "".equals(name)) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "模糊查询条件为空");
}
List<PmphUser> pmphUsers = pmphUserDao.getListByUsernameAndRealname(name, (number - 1) * size, size);
PageResult<PmphUserManagerVO> page = new PageResult<>();
page.setFirst(true);
page.setLast(true);
page.setPageNumber(number);
page.setPageSize(size);
if (!pmphUsers.isEmpty()) {
List<PmphUserManagerVO> list = new ArrayList<>();
for (PmphUser user : pmphUsers) {
PmphUserManagerVO userVO = new PmphUserManagerVO();
PmphDepartment department = pmphDepartmentDao.getPmphDepartmentById(user.getDepartmentId());
if (null != department) {
userVO.setDepartmentName(department.getDpName());
}
try {
BeanUtils.copyProperties(userVO, user);
} catch (BeansException ex) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.VO_CONVERSION_FAILED, ex.getMessage());
}
list.add(userVO);
}
page.setRows(list);
}
return page;
}
use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.
the class PmphUserServiceImpl method updatePersonalData.
@Override
public boolean updatePersonalData(HttpServletRequest request, PmphUser pmphUser, String newAvatar) throws IOException {
Long id = pmphUser.getId();
if (null == id) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户ID为空时禁止更新用户");
}
if (!StringUtil.isEmpty(pmphUser.getEmail())) {
if (!ValidatUtil.checkEmail(pmphUser.getEmail())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "邮箱不符合规范");
}
}
if (!StringUtil.isEmpty(pmphUser.getHandphone())) {
if (!ValidatUtil.checkMobileNumber(pmphUser.getHandphone())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "手机号码不符合规范");
}
}
// 头像文件不为空
if (null != newAvatar) {
if (StringUtil.notEmpty(pmphUser.getAvatar())) {
if (pmphUser.getAvatar().contains("/")) {
String avatar = pmphUser.getAvatar();
avatar = avatar.substring(avatar.lastIndexOf("/") + 1, avatar.length());
fileService.remove(avatar);
}
if (pmphUser.getAvatar().contains("\\")) {
String avatar = pmphUser.getAvatar();
avatar = avatar.substring(avatar.lastIndexOf("\\") + 1, avatar.length());
fileService.remove(avatar);
}
}
pmphUser.setAvatar(newAvatar);
}
String avatar = pmphUser.getAvatar();
if (null != avatar && avatar.contains("/")) {
avatar = avatar.substring(avatar.lastIndexOf("/") + 1, avatar.length());
}
if (null != avatar && avatar.contains("\\")) {
avatar = avatar.substring(avatar.lastIndexOf("\\") + 1, avatar.length());
}
if (null != avatar) {
byte[] fileByte = (byte[]) request.getSession(false).getAttribute(avatar);
String fileName = (String) request.getSession(false).getAttribute("fileName_" + avatar);
String noticeId;
// 保存通知文件
InputStream sbs = new ByteArrayInputStream(fileByte);
noticeId = fileService.save(sbs, fileName, ImageType.PMPH_USER_AVATAR, id);
pmphUser.setAvatar(noticeId);
}
pmphUserDao.update(pmphUser);
return true;
}
Aggregations