| | |
| | | package com.yeshi.fanli.service.impl.user.cloud;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.user.cloud.UserCloudGroupMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.cloud.UserCloudGroup;
|
| | | import com.yeshi.fanli.exception.user.cloud.UserCloudGroupException;
|
| | | import com.yeshi.fanli.service.inter.user.cloud.UserCloudGroupService;
|
| | | import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService;
|
| | |
|
| | |
|
| | | @Service
|
| | | public class UserCloudGroupServiceImpl implements UserCloudGroupService {
|
| | |
|
| | | @Resource
|
| | | private UserCloudGroupMapper userCloudGroupMapper;
|
| | |
|
| | | |
| | | @Override
|
| | | @RequestSerializableByKeyService(key = "#uid")
|
| | | public void addCircle(Long uid) {
|
| | | List<UserCloudGroup> list = userCloudGroupMapper.listByUidAndType(uid, UserCloudGroup.TYPE_CIRCLE);
|
| | | if (list != null && list.size() > 0)
|
| | | return;
|
| | | |
| | | UserCloudGroup cloudGroup = new UserCloudGroup();
|
| | | cloudGroup.setUid(uid);
|
| | | cloudGroup.setType(UserCloudGroup.TYPE_CIRCLE);
|
| | | cloudGroup.setState(false);
|
| | | cloudGroup.setCreateTime(new Date());
|
| | | userCloudGroupMapper.insertSelective(cloudGroup);
|
| | | }
|
| | | |
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @RequestSerializableByKeyService(key = "#uid")
|
| | | public void addGroup(Long uid, String groupId, String groupName, int maxNum){
|
| | | List<UserCloudGroup> list = userCloudGroupMapper.listByUidAndType(uid, UserCloudGroup.TYPE_GROUP);
|
| | | if (list != null && list.size() >= maxNum)
|
| | | return;
|
| | | |
| | | boolean exist = false;
|
| | | for (UserCloudGroup userCloudGroup: list) {
|
| | | if (groupId.equals(userCloudGroup.getGroupId())) {
|
| | | exist = true;
|
| | | // 群名字变化
|
| | | if (!groupName.equals(userCloudGroup.getGroupName())) {
|
| | | UserCloudGroup update = new UserCloudGroup();
|
| | | update.setGroupName(groupName);
|
| | | update.setUpdateTime(new Date());
|
| | | userCloudGroupMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | break;
|
| | | } |
| | | }
|
| | | |
| | | if (exist) |
| | | return;
|
| | | |
| | | UserCloudGroup cloudGroup = new UserCloudGroup();
|
| | | cloudGroup.setUid(uid);
|
| | | cloudGroup.setType(UserCloudGroup.TYPE_GROUP);
|
| | | cloudGroup.setState(false);
|
| | | cloudGroup.setCreateTime(new Date());
|
| | | cloudGroup.setGroupId(groupId);
|
| | | cloudGroup.setGroupName(groupName);
|
| | | userCloudGroupMapper.insertSelective(cloudGroup);
|
| | | }
|
| | | |
| | | @Override
|
| | | public void switchCircleState(long uid, boolean state) throws UserCloudGroupException{
|
| | | List<UserCloudGroup> list = userCloudGroupMapper.listByUidAndType(uid, UserCloudGroup.TYPE_CIRCLE);
|
| | | if (list == null || list.size() == 0)
|
| | | throw new UserCloudGroupException(1, "该记录已不存在");
|
| | | |
| | | if (list.get(0).getUid() != uid)
|
| | | throw new UserCloudGroupException(1, "该记录已不存在");
|
| | | |
| | | UserCloudGroup update = new UserCloudGroup();
|
| | | update.setId(list.get(0).getId());
|
| | | update.setState(state);
|
| | | update.setUpdateTime(new Date());
|
| | | userCloudGroupMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public void switchGroupState(long uid, long id, boolean state) throws UserCloudGroupException{
|
| | | UserCloudGroup cloudGroup = userCloudGroupMapper.selectByPrimaryKey(id);
|
| | | if (cloudGroup == null || cloudGroup.getUid() != uid)
|
| | | throw new UserCloudGroupException(1, "该记录已不存在");
|
| | | |
| | | UserCloudGroup update = new UserCloudGroup();
|
| | | update.setId(id);
|
| | | update.setState(state);
|
| | | update.setUpdateTime(new Date());
|
| | | userCloudGroupMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public void deleteGroupByUid(Long uid){
|
| | | userCloudGroupMapper.deleteGroupByUid(uid);
|
| | | }
|
| | | |
| | | @Override
|
| | | public List<UserCloudGroup> listByUid(Long uid) {
|
| | | return userCloudGroupMapper.listByUid(uid);
|
| | | }
|
| | | |
| | | @Override
|
| | | public List<UserCloudGroup> listGroupByUid(Long uid) {
|
| | | return userCloudGroupMapper.listGroupByUid(uid);
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.user.cloud; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.user.cloud.UserCloudGroupMapper; |
| | | import com.yeshi.fanli.entity.bus.user.cloud.UserCloudGroup; |
| | | import com.yeshi.fanli.exception.user.cloud.UserCloudGroupException; |
| | | import com.yeshi.fanli.service.inter.user.cloud.UserCloudGroupService; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService; |
| | | |
| | | |
| | | @Service |
| | | public class UserCloudGroupServiceImpl implements UserCloudGroupService { |
| | | |
| | | @Resource |
| | | private UserCloudGroupMapper userCloudGroupMapper; |
| | | |
| | | |
| | | @Override |
| | | @RequestSerializableByKeyService(key = "#uid") |
| | | public void addCircle(Long uid) { |
| | | List<UserCloudGroup> list = userCloudGroupMapper.listByUidAndType(uid, UserCloudGroup.TYPE_CIRCLE); |
| | | if (list != null && list.size() > 0) |
| | | return; |
| | | |
| | | UserCloudGroup cloudGroup = new UserCloudGroup(); |
| | | cloudGroup.setUid(uid); |
| | | cloudGroup.setType(UserCloudGroup.TYPE_CIRCLE); |
| | | cloudGroup.setState(false); |
| | | cloudGroup.setCreateTime(new Date()); |
| | | userCloudGroupMapper.insertSelective(cloudGroup); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequestSerializableByKeyService(key = "#uid") |
| | | public void addGroup(Long uid, String groupId, String groupName, int maxNum){ |
| | | List<UserCloudGroup> list = userCloudGroupMapper.listByUidAndType(uid, UserCloudGroup.TYPE_GROUP); |
| | | if (list != null && list.size() >= maxNum) |
| | | return; |
| | | |
| | | boolean exist = false; |
| | | for (UserCloudGroup userCloudGroup: list) { |
| | | if (groupId.equals(userCloudGroup.getGroupId())) { |
| | | exist = true; |
| | | // 群名为空 |
| | | if (StringUtil.isNullOrEmpty(groupName)) { |
| | | return; |
| | | } |
| | | |
| | | // 群名字变化 |
| | | if (!groupName.equals(userCloudGroup.getGroupName())) { |
| | | UserCloudGroup update = new UserCloudGroup(); |
| | | update.setGroupName(groupName); |
| | | update.setUpdateTime(new Date()); |
| | | userCloudGroupMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (exist) |
| | | return; |
| | | |
| | | // 群名为空 |
| | | if (StringUtil.isNullOrEmpty(groupName)) { |
| | | groupName = "本群未命名名称"; |
| | | } |
| | | |
| | | UserCloudGroup cloudGroup = new UserCloudGroup(); |
| | | cloudGroup.setUid(uid); |
| | | cloudGroup.setType(UserCloudGroup.TYPE_GROUP); |
| | | cloudGroup.setState(false); |
| | | cloudGroup.setCreateTime(new Date()); |
| | | cloudGroup.setGroupId(groupId); |
| | | cloudGroup.setGroupName(groupName); |
| | | userCloudGroupMapper.insertSelective(cloudGroup); |
| | | } |
| | | |
| | | @Override |
| | | public void switchCircleState(long uid, boolean state) throws UserCloudGroupException{ |
| | | List<UserCloudGroup> list = userCloudGroupMapper.listByUidAndType(uid, UserCloudGroup.TYPE_CIRCLE); |
| | | if (list == null || list.size() == 0) |
| | | throw new UserCloudGroupException(1, "该记录已不存在"); |
| | | |
| | | if (list.get(0).getUid() != uid) |
| | | throw new UserCloudGroupException(1, "该记录已不存在"); |
| | | |
| | | UserCloudGroup update = new UserCloudGroup(); |
| | | update.setId(list.get(0).getId()); |
| | | update.setState(state); |
| | | update.setUpdateTime(new Date()); |
| | | userCloudGroupMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void switchGroupState(long uid, long id, boolean state) throws UserCloudGroupException{ |
| | | UserCloudGroup cloudGroup = userCloudGroupMapper.selectByPrimaryKey(id); |
| | | if (cloudGroup == null || cloudGroup.getUid() != uid) |
| | | throw new UserCloudGroupException(1, "该记录已不存在"); |
| | | |
| | | UserCloudGroup update = new UserCloudGroup(); |
| | | update.setId(id); |
| | | update.setState(state); |
| | | update.setUpdateTime(new Date()); |
| | | userCloudGroupMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteGroup(long uid, long id) throws UserCloudGroupException{ |
| | | UserCloudGroup cloudGroup = userCloudGroupMapper.selectByPrimaryKey(id); |
| | | if (cloudGroup == null || cloudGroup.getUid() != uid) |
| | | throw new UserCloudGroupException(1, "该记录已不存在"); |
| | | |
| | | if (cloudGroup.getUid() != uid) { |
| | | throw new UserCloudGroupException(1, "该群已不存在"); |
| | | } |
| | | userCloudGroupMapper.deleteByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteGroupByUid(Long uid){ |
| | | userCloudGroupMapper.deleteGroupByUid(uid); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserCloudGroup> listByUid(Long uid) { |
| | | return userCloudGroupMapper.listByUid(uid); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserCloudGroup> listGroupByUid(Long uid) { |
| | | return userCloudGroupMapper.listGroupByUid(uid); |
| | | } |
| | | } |