|
@@ -0,0 +1,90 @@
|
|
|
|
|
+package cn.seecoder.fdroidrepository.Service.ServiceImpl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.Enum.ResultCode;
|
|
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.PO.ComplaintPO;
|
|
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.PO.PostPO;
|
|
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.VO.ComplaintVO;
|
|
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.VO.Response;
|
|
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.VO.search.ComplaintSearchVO;
|
|
|
|
|
+import cn.seecoder.fdroidrepository.Mapper.ComplaintMapper;
|
|
|
|
|
+import cn.seecoder.fdroidrepository.Mapper.PostMapper;
|
|
|
|
|
+import cn.seecoder.fdroidrepository.Service.ComplaintService;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class ComplaintServiceImpl implements ComplaintService {
|
|
|
|
|
+ private final ComplaintMapper complaintMapper;
|
|
|
|
|
+ private final PostMapper postMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Response addComplaint(ComplaintVO complaintVO) {
|
|
|
|
|
+ if (complaintVO == null) {
|
|
|
|
|
+ return Response.buildFailure(ResultCode.ILLEGAL_ARGUMENT.getCode(), ResultCode.ILLEGAL_ARGUMENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ ComplaintPO complaintPO = new ComplaintPO();
|
|
|
|
|
+ BeanUtils.copyProperties(complaintVO, complaintPO);
|
|
|
|
|
+ complaintPO.setHandled(false);
|
|
|
|
|
+ complaintPO.setCreateTime(new Date(System.currentTimeMillis()));
|
|
|
|
|
+ return Response.buildSuccess(complaintMapper.insert(complaintPO));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Response handleComplaint(Integer id, Boolean prove) {
|
|
|
|
|
+ if (id == null || prove == null) {
|
|
|
|
|
+ return Response.buildFailure(ResultCode.ILLEGAL_ARGUMENT.getCode(), ResultCode.ILLEGAL_ARGUMENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ ComplaintPO complaintPO = complaintMapper.selectById(id);
|
|
|
|
|
+ if (complaintPO == null) {
|
|
|
|
|
+ return Response.buildFailure(ResultCode.COMPLAINT_NON_EXIST.getCode(), ResultCode.COMPLAINT_NON_EXIST.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (complaintPO.isHandled()) {
|
|
|
|
|
+ return Response.buildFailure(ResultCode.COMPLAINT_ALREADY_HANDLED.getCode(), ResultCode.COMPLAINT_ALREADY_HANDLED.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ complaintPO.setHandled(true);
|
|
|
|
|
+ complaintMapper.update(complaintPO);
|
|
|
|
|
+ if (prove) {
|
|
|
|
|
+ // 审核人员支持投诉,需要关闭对应的post,并向对应的作者发送消息
|
|
|
|
|
+ PostPO postPO = postMapper.selectById(complaintPO.getPostId());
|
|
|
|
|
+ if (postPO == null) {
|
|
|
|
|
+ return Response.buildFailure(ResultCode.POST_NON_EXIST.getCode(), ResultCode.POST_NON_EXIST.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (postPO.getValid()) {
|
|
|
|
|
+ postPO.setValid(false);
|
|
|
|
|
+ postPO.setUpdateTime(new Date(System.currentTimeMillis()));
|
|
|
|
|
+ postMapper.update(postPO);
|
|
|
|
|
+ // TODO 发送websocket消息
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 审核人员不支持投诉,向投诉者发送信息
|
|
|
|
|
+ // TODO 发送websocket信息
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Response search(ComplaintSearchVO searchVO) {
|
|
|
|
|
+ if (searchVO == null) {
|
|
|
|
|
+ return Response.buildFailure(ResultCode.ILLEGAL_ARGUMENT.getCode(), ResultCode.ILLEGAL_ARGUMENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (searchVO.getPageNum() != null) {
|
|
|
|
|
+ if (searchVO.getPageNum() < 1 || searchVO.getPageSize() == null) {
|
|
|
|
|
+ return Response.buildFailure(ResultCode.ILLEGAL_ARGUMENT.getCode(), ResultCode.ILLEGAL_ARGUMENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ searchVO.setStart((searchVO.getPageNum() - 1) * searchVO.getPageSize());
|
|
|
|
|
+ }
|
|
|
|
|
+ return Response.buildSuccess(complaintMapper.search(searchVO));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Response searchCount(ComplaintSearchVO searchVO) {
|
|
|
|
|
+ if (searchVO == null) {
|
|
|
|
|
+ return Response.buildFailure(ResultCode.ILLEGAL_ARGUMENT.getCode(), ResultCode.ILLEGAL_ARGUMENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return Response.buildSuccess(complaintMapper.searchCount(searchVO));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|