|
@@ -0,0 +1,111 @@
|
|
|
|
+package com.dragon.tj.portal.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.dragon.tj.portal.auth.common.constants.Role;
|
|
|
|
+import com.dragon.tj.portal.auth.model.LoginUser;
|
|
|
|
+import com.dragon.tj.portal.auth.util.SecurityUtils;
|
|
|
|
+import com.dragon.tj.portal.common.constants.CommonConstants;
|
|
|
|
+import com.dragon.tj.portal.entity.CommentDetailInfo;
|
|
|
|
+import com.dragon.tj.portal.entity.CommentInfo;
|
|
|
|
+import com.dragon.tj.portal.entity.PageParam;
|
|
|
|
+import com.dragon.tj.portal.mapper.CommentDetailMapper;
|
|
|
|
+import com.dragon.tj.portal.mapper.CommentInfoMapper;
|
|
|
|
+import com.dragon.tj.portal.service.CommentService;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class CommentServiceImpl implements CommentService {
|
|
|
|
+
|
|
|
|
+ private final CommentInfoMapper commentInfoMapper;
|
|
|
|
+ private final CommentDetailMapper commentDetailMapper;
|
|
|
|
+
|
|
|
|
+ public CommentServiceImpl(CommentInfoMapper commentInfoMapper, CommentDetailMapper commentDetailMapper) {
|
|
|
|
+ this.commentInfoMapper = commentInfoMapper;
|
|
|
|
+ this.commentDetailMapper = commentDetailMapper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * CRUD
|
|
|
|
+ * */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public int add(CommentInfo commentInfo, LoginUser loginUser) {
|
|
|
|
+ commentInfo.setCreateUser(loginUser.getUsername());
|
|
|
|
+ commentInfo.setCreateUserIdcard(loginUser.getIdCard());
|
|
|
|
+ commentInfo.setCreateOrgCode(loginUser.getOrgCode());
|
|
|
|
+ commentInfo.setCreateOrgName(loginUser.getUser().getOrgName());
|
|
|
|
+ int insert = commentInfoMapper.insert(commentInfo);
|
|
|
|
+ if (insert > 0) {
|
|
|
|
+ CommentDetailInfo detailInfo = new CommentDetailInfo();
|
|
|
|
+ detailInfo.setCommentId(commentInfo.getId())
|
|
|
|
+ .setContent(commentInfo.getContent())
|
|
|
|
+ .setCreateUserIdcard(commentInfo.getCreateUserIdcard())
|
|
|
|
+ .setCreateUser(commentInfo.getCreateUser())
|
|
|
|
+ .setCreateOrgCode(commentInfo.getCreateOrgCode())
|
|
|
|
+ .setCreateOrgName(commentInfo.getCreateOrgName())
|
|
|
|
+ .setCreateTime(commentInfo.getCreateTime());
|
|
|
|
+ commentDetailMapper.insert(detailInfo);
|
|
|
|
+ }
|
|
|
|
+ return insert;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Page<CommentInfo> search(PageParam<CommentInfo> pageParam) {
|
|
|
|
+ CommentInfo commentInfo = pageParam.getParams();
|
|
|
|
+ Page<CommentInfo> rowPage = new Page<>(pageParam.getPage(), pageParam.getSize());
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<CommentInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+
|
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
|
+ if (!loginUser.getPermissions().contains(Role.ADMIN)) {
|
|
|
|
+ queryWrapper.eq(StringUtils.isNotEmpty(loginUser.getIdCard()),
|
|
|
|
+ CommentInfo::getCreateUserIdcard, loginUser.getIdCard());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ queryWrapper.eq(commentInfo.getDelFlag() != null,
|
|
|
|
+ CommentInfo::getDelFlag, commentInfo.getDelFlag());
|
|
|
|
+
|
|
|
|
+ // 内容
|
|
|
|
+ queryWrapper.like(StringUtils.isNotEmpty(commentInfo.getContent()),
|
|
|
|
+ CommentInfo::getContent, commentInfo.getContent());
|
|
|
|
+
|
|
|
|
+ queryWrapper.orderByDesc(CommentInfo::getCreateTime);
|
|
|
|
+
|
|
|
|
+ return commentInfoMapper.selectPage(rowPage, queryWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Page<CommentDetailInfo> detailSearch(PageParam<CommentDetailInfo> pageParam) {
|
|
|
|
+ Page<CommentDetailInfo> rowPage = new Page<>(pageParam.getPage(), pageParam.getSize());
|
|
|
|
+
|
|
|
|
+ CommentDetailInfo detailParam = pageParam.getParams();
|
|
|
|
+ LambdaQueryWrapper<CommentDetailInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(CommentDetailInfo::getDelFlag, CommonConstants.NO);
|
|
|
|
+ queryWrapper.eq(CommentDetailInfo::getCommentId, detailParam.getCommentId());
|
|
|
|
+ queryWrapper.orderByAsc(CommentDetailInfo::getCreateTime);
|
|
|
|
+
|
|
|
|
+ return commentDetailMapper.selectPage(rowPage, queryWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public int detailAdd(CommentDetailInfo detailInfo, LoginUser loginUser) {
|
|
|
|
+ detailInfo.setCreateUserIdcard(loginUser.getIdCard())
|
|
|
|
+ .setCreateUser(loginUser.getUsername())
|
|
|
|
+ .setCreateOrgCode(loginUser.getOrgCode())
|
|
|
|
+ .setCreateOrgName(loginUser.getUser().getOrgName());
|
|
|
|
+ int insert = commentDetailMapper.insert(detailInfo);
|
|
|
|
+ if (insert > 0) {
|
|
|
|
+ CommentInfo commentInfo = new CommentInfo();
|
|
|
|
+ commentInfo.setId(detailInfo.getCommentId());
|
|
|
|
+ commentInfo.setUpdateTime(LocalDateTime.now());
|
|
|
|
+ commentInfoMapper.updateById(commentInfo);
|
|
|
|
+ }
|
|
|
|
+ return insert;
|
|
|
|
+ }
|
|
|
|
+}
|