| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jetbrains.annotations.Nullable; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.modules.discuss.entity.PublicDiscussEntity; |
| | | 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.IPublicDiscussService; |
| | | import org.springblade.modules.discuss.service.ITopicsService; |
| | | import org.springblade.modules.discuss.service.IUserTopicsService; |
| | | import org.springblade.modules.discuss.vo.TopicsVO; |
| | | import org.springblade.modules.discuss.vo.UserTopicsVO; |
| | | import org.springblade.modules.district.entity.DistrictEntity; |
| | | import org.springblade.modules.district.service.IDistrictService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 用户议题报表 服务实现类 |
| | |
| | | |
| | | @Override |
| | | public IPage<UserTopicsVO> selectUserTopicsPage(IPage<UserTopicsVO> page, UserTopicsVO userTopics) { |
| | | if (StringUtils.isNotBlank(userTopics.getDistrictId())) { |
| | | List<String> longs = JSON.parseArray(userTopics.getDistrictId()).toJavaList(String.class); |
| | | IDistrictService bean = SpringUtils.getBean(IDistrictService.class); |
| | | List<DistrictEntity> list = bean.list(Wrappers.<DistrictEntity>lambdaQuery().in(DistrictEntity::getId, longs)); |
| | | List<String> collect = list.stream().map(item -> |
| | | item.getAoiCode() |
| | | ).collect(Collectors.toList()); |
| | | if (collect != null) { |
| | | userTopics.setAoiCodeList(collect); |
| | | } |
| | | } |
| | | return page.setRecords(baseMapper.selectUserTopicsPage(page, userTopics)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean batchSave(List<TopicsEntity> topics) { |
| | | public Boolean batchSave(List<TopicsVO> topics) throws Exception { |
| | | // 判断是否一户一票 还是一人一票 |
| | | IPublicDiscussService bean = SpringUtil.getBean(IPublicDiscussService.class); |
| | | PublicDiscussEntity one = bean.getOne(Wrappers.<PublicDiscussEntity>lambdaQuery().eq(PublicDiscussEntity::getArticleId, topics.get(0).getArticleId())); |
| | | // 一户一票 |
| | | if (one.getVoteRestrictions().equals(CommonConstant.NUMBER_ONE)) { |
| | | long count = count(Wrappers.<UserTopicsEntity>lambdaQuery().eq(UserTopicsEntity::getHouseCode, topics.get(0).getHouseCode())); |
| | | if (count > 1) { |
| | | throw new Exception("您的房屋已投票,不能重复投票!"); |
| | | } |
| | | } else { |
| | | // |
| | | long count = count(Wrappers.<UserTopicsEntity>lambdaQuery().eq(UserTopicsEntity::getUserId, AuthUtil.getUserId())); |
| | | if (count > 1) { |
| | | throw new Exception("您的已投票,不能重复投票!"); |
| | | } |
| | | } |
| | | Boolean userTopics = getaBoolean(topics); |
| | | if (userTopics != null) return userTopics; |
| | | return false; |
| | | } |
| | | |
| | | @Nullable |
| | | private Boolean getaBoolean(List<TopicsVO> topics) { |
| | | List<UserTopicsEntity> objects = new ArrayList<>(); |
| | | for (TopicsEntity topic : topics) { |
| | | for (TopicsVO 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.setSelected(topic.getSelected()); |
| | | userTopics.setUserId(AuthUtil.getUserId()); |
| | | userTopics.setPublicDiscussId(topic.getPublicDiscussId()); |
| | | userTopics.setTopicsId(Integer.valueOf(topic.getSelected())); |
| | | userTopics.setArticleId(topic.getArticleId()); |
| | | userTopics.setHouseCode(topic.getHouseCode()); |
| | | userTopics.setSignaturePath(topic.getSignaturePath()); |
| | | UpdateWrapper<TopicsEntity> objectUpdateWrapper = new UpdateWrapper<>(); |
| | | objectUpdateWrapper.setSql("number = number + 1"); |
| | | objectUpdateWrapper.eq("id", topic.getSelected()); |
| | | topicsService.update(null, objectUpdateWrapper); |
| | | baseMapper.insert(userTopics); |
| | | return save(userTopics); |
| | | } else { |
| | | // 多选 |
| | | if (StringUtils.isBlank(topic.getSelected())) { |
| | | break; |
| | | } |
| | |
| | | List<UserTopicsEntity> objectsTwo = new ArrayList<>(); |
| | | for (Object o : objects1) { |
| | | UserTopicsEntity userTopics = new UserTopicsEntity(); |
| | | userTopics.setTopicsId((Integer) o); |
| | | userTopics.setSelected(topic.getSelected()); |
| | | userTopics.setUserId(AuthUtil.getUserId()); |
| | | userTopics.setPublicDiscussId(topic.getPublicDiscussId()); |
| | | userTopics.setArticleId(topic.getArticleId()); |
| | | userTopics.setHouseCode(topic.getHouseCode()); |
| | | userTopics.setTopicsId((Integer) o); |
| | | userTopics.setSignaturePath(topic.getSignaturePath()); |
| | | objectsTwo.add(userTopics); |
| | | UpdateWrapper<TopicsEntity> objectUpdateWrapper = new UpdateWrapper<>(); |
| | | objectUpdateWrapper.setSql("number = number + 1"); |
| | | objectUpdateWrapper.eq("id", o); |
| | | objectsTwo.add(userTopics); |
| | | topicsService.update(null, objectUpdateWrapper); |
| | | } |
| | | saveOrUpdateBatch(objectsTwo); |
| | | return saveBatch(objectsTwo); |
| | | } |
| | | } |
| | | return saveOrUpdateBatch(objects); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Long getCount(Integer id) { |
| | | return baseMapper.selectCount(Wrappers.<UserTopicsEntity>lambdaQuery().eq(UserTopicsEntity::getPublicDiscussId, id).groupBy(UserTopicsEntity::getUserId)); |
| | | public Integer getCount(Integer id) { |
| | | List<UserTopicsEntity> list = list(Wrappers.<UserTopicsEntity>lambdaQuery() |
| | | .eq(UserTopicsEntity::getPublicDiscussId, id) |
| | | .groupBy(UserTopicsEntity::getUserId)); |
| | | return list.size(); |
| | | } |
| | | } |