| | |
| | | */ |
| | | package org.springblade.modules.discuss.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.modules.discuss.entity.TopicsEntity; |
| | | import org.springblade.modules.discuss.entity.UserPublicEnrollEntity; |
| | | import org.springblade.modules.discuss.entity.UserTopicsEntity; |
| | | import org.springblade.modules.discuss.mapper.UserTopicsMapper; |
| | | import org.springblade.modules.discuss.service.ITopicsService; |
| | | import org.springblade.modules.discuss.service.IUserTopicsService; |
| | | import org.springblade.modules.discuss.vo.UserTopicsVO; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 用户议题报表 服务实现类 |
| | |
| | | */ |
| | | @Service |
| | | public class UserTopicsServiceImpl extends ServiceImpl<UserTopicsMapper, UserTopicsEntity> implements IUserTopicsService { |
| | | @Resource |
| | | private ITopicsService topicsService; |
| | | |
| | | @Override |
| | | public IPage<UserTopicsVO> selectUserTopicsPage(IPage<UserTopicsVO> page, UserTopicsVO userTopics) { |
| | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean batchSave(List<TopicsEntity> topics) { |
| | | List<UserTopicsEntity> objects = new ArrayList<>(); |
| | | for (TopicsEntity topic : topics) { |
| | | UserTopicsEntity userTopicsEntity = new UserTopicsEntity(); |
| | | userTopicsEntity.setUserId(AuthUtil.getUserId()); |
| | | userTopicsEntity.setSelected(topic.getSelected()); |
| | | userTopicsEntity.setTopicsId(topic.getId()); |
| | | userTopicsEntity.setPublicDiscussId(topic.getPublicDiscussId()); |
| | | objects.add(userTopicsEntity); |
| | | if (topic.getOptionRange().equals(0)) { |
| | | if (StringUtils.isBlank(topic.getSelected())) { |
| | | break; |
| | | } |
| | | UserTopicsEntity userTopics = new UserTopicsEntity(); |
| | | userTopics.setTopicsId(Integer.valueOf(topic.getSelected())); |
| | | userTopics.setUserId(AuthUtil.getUserId()); |
| | | userTopics.setPublicDiscussId(topic.getPublicDiscussId()); |
| | | UpdateWrapper<TopicsEntity> objectUpdateWrapper = new UpdateWrapper<>(); |
| | | objectUpdateWrapper.setSql("number = number + 1"); |
| | | objectUpdateWrapper.eq("id", topic.getSelected()); |
| | | topicsService.update(null, objectUpdateWrapper); |
| | | baseMapper.insert(userTopics); |
| | | } else { |
| | | if (StringUtils.isBlank(topic.getSelected())) { |
| | | break; |
| | | } |
| | | JSONArray objects1 = JSON.parseArray(topic.getSelected()); |
| | | List<UserTopicsEntity> objectsTwo = new ArrayList<>(); |
| | | for (Object o : objects1) { |
| | | UserTopicsEntity userTopics = new UserTopicsEntity(); |
| | | userTopics.setTopicsId((Integer) o); |
| | | userTopics.setUserId(AuthUtil.getUserId()); |
| | | userTopics.setPublicDiscussId(topic.getPublicDiscussId()); |
| | | UpdateWrapper<TopicsEntity> objectUpdateWrapper = new UpdateWrapper<>(); |
| | | objectUpdateWrapper.setSql("number = number + 1"); |
| | | objectUpdateWrapper.eq("id", o); |
| | | objectsTwo.add(userTopics); |
| | | topicsService.update(null, objectUpdateWrapper); |
| | | } |
| | | saveOrUpdateBatch(objectsTwo); |
| | | } |
| | | } |
| | | return saveOrUpdateBatch(objects); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Integer getCount(Integer id) { |
| | | List<UserTopicsEntity> list = list(Wrappers.<UserTopicsEntity>lambdaQuery() |
| | | .eq(UserTopicsEntity::getPublicDiscussId, id) |
| | | .groupBy(UserTopicsEntity::getUserId)); |
| | | return list.size(); |
| | | } |
| | | } |