/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
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;
|
|
/**
|
* 用户议题报表 服务实现类
|
*
|
* @author BladeX
|
* @since 2023-11-22
|
*/
|
@Service
|
public class UserTopicsServiceImpl extends ServiceImpl<UserTopicsMapper, UserTopicsEntity> implements IUserTopicsService {
|
@Resource
|
private ITopicsService topicsService;
|
|
@Override
|
public IPage<UserTopicsVO> selectUserTopicsPage(IPage<UserTopicsVO> page, UserTopicsVO userTopics) {
|
return page.setRecords(baseMapper.selectUserTopicsPage(page, 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 Long getCount(Integer id) {
|
return baseMapper.selectCount(Wrappers.<UserTopicsEntity>lambdaQuery().eq(UserTopicsEntity::getPublicDiscussId, id).groupBy(UserTopicsEntity::getUserId));
|
}
|
}
|