use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class PmphGroupServiceImpl method updatePmphGroupOnGroup.
@Override
public PmphGroup updatePmphGroupOnGroup(String file, PmphGroup pmphGroup, HttpServletRequest request) throws CheckedServiceException, IOException {
String sessionId = CookiesUtil.getSessionId(request);
if (null == pmphGroup) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "参数对象不能为空");
}
if (null == pmphGroup.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "小组id不能为空");
}
PmphGroup group = pmphGroupDao.getPmphGroupByGroupName(pmphGroup.getGroupName());
if (ObjectUtil.notNull(group)) {
if (!pmphGroup.getId().equals(group.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "小组名称重复");
}
}
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (pmphUser.getIsAdmin() || pmphGroupMemberService.isFounderOrisAdmin(pmphGroup.getId(), sessionId)) {
// 超级管理员与小组创建者、管理者才能修改小组信息
if (!StringUtil.isEmpty(file)) {
Long id = pmphGroup.getId();
PmphGroup pmphGroupOld = getPmphGroupById(id);
if (null != pmphGroupOld && null != pmphGroupOld.getGroupImage() && !"".equals(pmphGroupOld.getGroupImage()) && !RouteUtil.DEFAULT_USER_AVATAR.equals(pmphGroupOld.getGroupImage())) {
fileService.remove(pmphGroupOld.getGroupImage());
}
String newGroupImage = saveFileToMongoDB(file, request);
pmphGroup.setGroupImage(newGroupImage);
}
pmphGroupDao.updatePmphGroup(pmphGroup);
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
}
return pmphGroup;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class PmphGroupServiceImpl method listPmphGroup.
/**
* @introduction 根据小组名称模糊查询获取当前用户的小组
* @author Mryang
* @createDate 2017年9月20日 下午4:45:48
* @param pmphGroup
* @return List<PmphGroupListVO>
* @throws CheckedServiceException
*/
@Override
public List<PmphGroupListVO> listPmphGroup(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<>();
if (pmphUser.getIsAdmin()) {
list = pmphGroupDao.listPmphGroup(pmphGroup.getGroupName());
for (PmphGroupListVO pmphGroupListVO : list) {
pmphGroupListVO.setGroupImage(RouteUtil.groupImage(pmphGroupListVO.getGroupImage()));
}
} else {
list = pmphGroupDao.getList(pmphGroup, pmphUser.getId());
for (PmphGroupListVO pmphGroupListVO : list) {
pmphGroupListVO.setGroupImage(RouteUtil.groupImage(pmphGroupListVO.getGroupImage()));
}
}
for (PmphGroupListVO pmphGroupListVO : list) {
PmphGroupMemberVO user = pmphGroupMemberService.getPmphGroupMemberByMemberId(pmphGroupListVO.getId(), pmphUser.getId(), false);
if (ObjectUtil.isNull(user)) {
pmphGroupListVO.setIsMember(false);
} else {
pmphGroupListVO.setIsMember(true);
}
}
return list;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class PmphGroupServiceImpl method deletePmphGroupById.
/**
* @param PmphGroup
* @return 影响行数
* @throws CheckedServiceException
*/
@Override
public String deletePmphGroupById(PmphGroup pmphGroup, 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() || pmphGroupMemberService.isFounder(pmphGroup.getId(), sessionId)) {
// 超级管理员与小组创建者才有权利删除小组
if (null == pmphGroup.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "主键为空");
}
PmphGroup group = pmphGroupDao.getPmphGroupById(pmphGroup.getId());
// 获取该小组的文件
List<PmphGroupFile> pmphGroupFiles = pmphGroupFileService.listPmphGroupFileByGroupId(pmphGroup.getId());
Long[] ids = new Long[pmphGroupFiles.size()];
for (int i = 0; i < pmphGroupFiles.size(); i++) {
PmphGroupFile pmphGroupFile = pmphGroupFiles.get(i);
ids[i] = pmphGroupFile.getId();
}
// 删除小组
int num = pmphGroupDao.deletePmphGroupById(pmphGroup.getId());
if (num > 0) {
if (ArrayUtil.isNotEmpty(ids)) {
// 判断该小组是否有文件
// 删除小组文件
pmphGroupFileService.deletePmphGroupFileById(pmphGroup.getId(), ids, sessionId);
}
if (!RouteUtil.DEFAULT_GROUP_IMAGE.equals(group.getGroupImage())) {
// 解散小组时删除小组头像
fileService.remove(group.getGroupImage());
}
// 删除小组消息
pmphGroupMessageService.deletePmphGroupMessageByGroupId(pmphGroup.getId());
// 删除小组成员
result = pmphGroupMemberService.deletePmphGroupMemberOnGroup(pmphGroup.getId());
}
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
}
return result;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class PmphUserServiceImpl method identity.
@Override
public PmphIdentity identity(String sessionId) throws CheckedServiceException {
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.NULL_PARAM, "用户为空!");
}
Long id = pmphUser.getId();
PmphIdentity identity = new PmphIdentity(pmphUser.getId(), pmphUser.getUsername(), pmphUser.getRealname());
identity.setIsAdmin(pmphUser.getIsAdmin());
identity.setIsDirector(pmphUser.getIsDirector());
List<PmphUser> list = new ArrayList<>();
list = pmphUserDao.isEditor(id);
if (!list.isEmpty()) {
identity.setIsEditor(true);
}
list = pmphUserDao.isOpts(id);
if (!list.isEmpty()) {
identity.setIsOpts(true);
}
return identity;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class PmphUserServiceImpl method updatePmphUserOfBack.
@Override
public String updatePmphUserOfBack(PmphUserManagerVO pmphUserManagerVO) throws CheckedServiceException {
PmphUser username = pmphUserDao.get(pmphUserManagerVO.getId());
if (!username.getUsername().equals(pmphUserManagerVO.getUsername())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户账号不相同");
}
if (ObjectUtil.isNull(pmphUserManagerVO.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户ID为空时禁止更新用户");
}
if (StringUtil.strLength(pmphUserManagerVO.getUsername()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户名需要小于20字符");
}
if (StringUtil.strLength(pmphUserManagerVO.getRealname()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "姓名需要小于20字符");
}
if (!StringUtil.isEmpty(pmphUserManagerVO.getHandphone())) {
if (!ValidatUtil.checkMobileNumber(pmphUserManagerVO.getHandphone())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "电话格式不正确");
}
}
if (!StringUtil.isEmpty(pmphUserManagerVO.getEmail())) {
if (!ValidatUtil.checkEmail(pmphUserManagerVO.getEmail())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "邮箱格式不正确");
}
}
if (StringUtil.isEmpty(pmphUserManagerVO.getRealname())) {
pmphUserManagerVO.setRealname(pmphUserManagerVO.getUsername());
}
int num = pmphUserDao.updatePmphUserOfBack(pmphUserManagerVO);
String result = "FAIL";
if (num > 0) {
pmphUserRoleDao.deletePmphUserRoleByUserId(pmphUserManagerVO.getId());
String pmphRoles = pmphUserManagerVO.getRoleIds();
if (!StringUtil.isEmpty(pmphRoles)) {
String[] roleIds = pmphRoles.split(",");
for (String roleId : roleIds) {
PmphUserRole pmphUserRole = new PmphUserRole(pmphUserManagerVO.getId(), Long.valueOf(roleId));
pmphUserRoleDao.addPmphUserRole(pmphUserRole);
}
}
result = "SUCCESS";
}
return result;
}
Aggregations