feat:报告点赞接口
This commit is contained in:
@@ -3,6 +3,7 @@ package com.adc.da.report.controller;
|
|||||||
import com.adc.da.report.eo.ReportLogBook;
|
import com.adc.da.report.eo.ReportLogBook;
|
||||||
import com.adc.da.report.service.IReportLogBookService;
|
import com.adc.da.report.service.IReportLogBookService;
|
||||||
import com.adc.da.report.vo.DeleteParamRequestVO;
|
import com.adc.da.report.vo.DeleteParamRequestVO;
|
||||||
|
import com.adc.da.report.vo.ReportDetailThumbUpVo;
|
||||||
import com.adc.da.report.vo.ReportLogPageVO;
|
import com.adc.da.report.vo.ReportLogPageVO;
|
||||||
import com.adc.da.util.http.ResponseMessage;
|
import com.adc.da.util.http.ResponseMessage;
|
||||||
import com.adc.da.util.http.Result;
|
import com.adc.da.util.http.Result;
|
||||||
@@ -110,4 +111,37 @@ public class ReportLogBookController {
|
|||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param reportId
|
||||||
|
* @return com.adc.da.util.http.ResponseMessage
|
||||||
|
* @author bu
|
||||||
|
* @date 2023-05-08
|
||||||
|
* @description 根据报告id和当前登录用户id获取点赞数
|
||||||
|
*/
|
||||||
|
@GetMapping("/getThumbUpCount")
|
||||||
|
@ApiOperation(value = "获取点赞数和当前用户点赞记录")
|
||||||
|
public ResponseMessage getThumbUpCount(String reportId){
|
||||||
|
|
||||||
|
//根据报告id和当前登录用户id获取点赞数
|
||||||
|
ReportDetailThumbUpVo result = reportLogBookService.getThumbUpCount(reportId);
|
||||||
|
return Result.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param reportId
|
||||||
|
* @return com.adc.da.util.http.ResponseMessage
|
||||||
|
* @author bu
|
||||||
|
* @date 2023-05-08
|
||||||
|
* @description 根据报告id和当前登录用户id获取点赞数
|
||||||
|
*/
|
||||||
|
@GetMapping("/thumbUpOrDown")
|
||||||
|
@ApiOperation(value = "点赞或者取消点赞")
|
||||||
|
public ResponseMessage thumbUpOrDown(String reportId){
|
||||||
|
|
||||||
|
//根据报告id和当前登录用户id获取点赞数
|
||||||
|
ReportDetailThumbUpVo result = reportLogBookService.thumbUpOrDown(reportId);
|
||||||
|
return Result.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package com.adc.da.report.eo;
|
package com.adc.da.report.eo;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -16,9 +18,10 @@ import java.util.Date;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@TableName("report_log_book")
|
@TableName("report_log_book")
|
||||||
|
@Accessors(chain = true)
|
||||||
public class ReportLogBook {
|
public class ReportLogBook {
|
||||||
|
|
||||||
@TableId("id")
|
@TableId(value = "id", type = IdType.INPUT)
|
||||||
private String id;
|
private String id;
|
||||||
/**
|
/**
|
||||||
* 报告id
|
* 报告id
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.adc.da.report.service;
|
|||||||
|
|
||||||
import com.adc.da.report.eo.ReportLogBook;
|
import com.adc.da.report.eo.ReportLogBook;
|
||||||
import com.adc.da.report.vo.DeleteParamRequestVO;
|
import com.adc.da.report.vo.DeleteParamRequestVO;
|
||||||
|
import com.adc.da.report.vo.ReportDetailThumbUpVo;
|
||||||
import com.adc.da.report.vo.ReportLogPageVO;
|
import com.adc.da.report.vo.ReportLogPageVO;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
|
||||||
@@ -24,4 +25,20 @@ public interface IReportLogBookService {
|
|||||||
void saveOrUpdateSingle(ReportLogBook reportLogBook);
|
void saveOrUpdateSingle(ReportLogBook reportLogBook);
|
||||||
|
|
||||||
void deleteById(DeleteParamRequestVO deleteParamVO);
|
void deleteById(DeleteParamRequestVO deleteParamVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取点赞数
|
||||||
|
*
|
||||||
|
* @param reportId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReportDetailThumbUpVo getThumbUpCount(String reportId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点赞或者取消点赞
|
||||||
|
*
|
||||||
|
* @param reportId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReportDetailThumbUpVo thumbUpOrDown(String reportId);
|
||||||
}
|
}
|
||||||
|
|||||||
+60
@@ -1,12 +1,15 @@
|
|||||||
package com.adc.da.report.service.impl;
|
package com.adc.da.report.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.adc.da.login.util.UserUtils;
|
||||||
import com.adc.da.report.dao.mysql.ReportLogBookDao;
|
import com.adc.da.report.dao.mysql.ReportLogBookDao;
|
||||||
import com.adc.da.report.eo.ReportLogBook;
|
import com.adc.da.report.eo.ReportLogBook;
|
||||||
import com.adc.da.report.service.IReportLogBookService;
|
import com.adc.da.report.service.IReportLogBookService;
|
||||||
import com.adc.da.report.vo.DeleteParamRequestVO;
|
import com.adc.da.report.vo.DeleteParamRequestVO;
|
||||||
|
import com.adc.da.report.vo.ReportDetailThumbUpVo;
|
||||||
import com.adc.da.report.vo.ReportLogPageVO;
|
import com.adc.da.report.vo.ReportLogPageVO;
|
||||||
import com.adc.da.util.utils.StringUtils;
|
import com.adc.da.util.utils.StringUtils;
|
||||||
|
import com.adc.da.util.utils.UUID;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -14,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,4 +111,60 @@ public class IReportLogBookServiceImpl extends ServiceImpl<ReportLogBookDao, Rep
|
|||||||
// reportLog.setDel(YesOrNoEnum.YES.getValue());
|
// reportLog.setDel(YesOrNoEnum.YES.getValue());
|
||||||
// baseMapper.update(reportLog,wrapper);
|
// baseMapper.update(reportLog,wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReportDetailThumbUpVo getThumbUpCount(String reportId) {
|
||||||
|
//查找是否有点赞记录
|
||||||
|
ReportLogBook entity = findThumbUpLog(reportId);
|
||||||
|
ReportDetailThumbUpVo reportDetailThumbUpVo = new ReportDetailThumbUpVo();
|
||||||
|
if (entity != null) {
|
||||||
|
reportDetailThumbUpVo.setLogId(entity.getId());
|
||||||
|
}
|
||||||
|
//计算已有点赞数
|
||||||
|
Integer count = thumbUpCount(reportId);
|
||||||
|
reportDetailThumbUpVo.setThumbUpCount(count);
|
||||||
|
return reportDetailThumbUpVo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer thumbUpCount(String reportId) {
|
||||||
|
return query().eq("report_id", reportId)
|
||||||
|
.eq("type", 3).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReportLogBook findThumbUpLog(String reportId) {
|
||||||
|
return query().eq("report_id", reportId)
|
||||||
|
.eq("user_id", UserUtils.getUserId())
|
||||||
|
.eq("type", 3).one();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String thumbUp(String reportId) {
|
||||||
|
ReportLogBook reportLogBook = new ReportLogBook();
|
||||||
|
reportLogBook.setReportId(reportId)
|
||||||
|
.setId(UUID.randomUUID10())
|
||||||
|
.setType(3)
|
||||||
|
.setUserId(UserUtils.getUserId())
|
||||||
|
.setUpdateTime(new Date());
|
||||||
|
save(reportLogBook);
|
||||||
|
return reportLogBook.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void thumbDown(String logId) {
|
||||||
|
removeById(logId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReportDetailThumbUpVo thumbUpOrDown(String reportId) {
|
||||||
|
ReportLogBook entity = findThumbUpLog(reportId);
|
||||||
|
ReportDetailThumbUpVo reportDetailThumbUpVo = new ReportDetailThumbUpVo();
|
||||||
|
if (entity == null) {
|
||||||
|
String logId = thumbUp(reportId);
|
||||||
|
reportDetailThumbUpVo.setLogId(logId);
|
||||||
|
} else {
|
||||||
|
thumbDown(entity.getId());
|
||||||
|
}
|
||||||
|
//计算已有点赞数
|
||||||
|
Integer count = thumbUpCount(reportId);
|
||||||
|
reportDetailThumbUpVo.setThumbUpCount(count);
|
||||||
|
return reportDetailThumbUpVo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.adc.da.report.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: CaiHaohan
|
||||||
|
* @Date: 2023/5/8 15:37
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ReportDetailThumbUpVo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志记录id
|
||||||
|
*/
|
||||||
|
private String logId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点赞数
|
||||||
|
*/
|
||||||
|
private Integer thumbUpCount;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user