qrs преди 4 дни
родител
ревизия
ae4150a561

+ 1 - 24
alien-store/src/main/java/shop/alien/store/controller/UserViolationController.java

@@ -44,39 +44,16 @@ public class UserViolationController {
     @ApiOperation("举报")
     @ApiOperationSupport(order = 1)
     @PostMapping("/reporting")
-    public R<String> reporting(@RequestBody LifeUserViolation lifeuserViolation) throws IOException, InterruptedException {
+    public R<String> reporting(@RequestBody LifeUserViolation lifeuserViolation) throws Exception  {
         log.info("UserViolationController.reporting?lifeuserViolation={}", lifeuserViolation.toString());
         int reporting = lifeUserViolationService.reporting(lifeuserViolation);
         if (0 == reporting) {
             return R.fail("举报失败");
         } else {
-            if (lifeuserViolation.getReportContextType().equals("4") || lifeuserViolation.getReportContextType().equals("5")) {
-                LifeNotice lifeNotice = getLifeNotice(lifeuserViolation);
-                lifeNoticeMapper.insert(lifeNotice);
-            }
             return R.data("举报成功");
         }
     }
 
-    private static LifeNotice getLifeNotice(LifeUserViolation lifeuserViolation) throws JsonProcessingException {
-        JSONObject data = JwtUtil.getCurrentUserInfo();
-        String phoneId = null;
-        if (data != null) {
-            phoneId = data.getString("phone");
-        }
-        LifeNotice lifeNotice = new LifeNotice();
-        lifeNotice.setSenderId("system");
-        lifeNotice.setReceiverId("user_" + phoneId);
-        lifeNotice.setBusinessId(lifeuserViolation.getId());
-        lifeNotice.setTitle("举报通知");
-        JSONObject jsonObject = new JSONObject();
-        jsonObject.put("title", "平台已受理");
-        jsonObject.put("message", "平台已受理,感谢您的反馈!");
-        lifeNotice.setContext(jsonObject.toJSONString());
-        lifeNotice.setNoticeType(1);
-        return lifeNotice;
-    }
-
     @ApiOperation("举报结果")
     @ApiOperationSupport(order = 2)
     @GetMapping("/reportListByUserId")

+ 1 - 1
alien-store/src/main/java/shop/alien/store/service/LifeUserViolationService.java

@@ -19,7 +19,7 @@ import java.util.Map;
  */
 public interface LifeUserViolationService extends IService<LifeUserViolation> {
 
-    int reporting(LifeUserViolation lifeuserViolation);
+    int reporting(LifeUserViolation lifeuserViolation) throws Exception ;
 
     Map<String, Object> reportListByUserId(String userId);
 

+ 45 - 2
alien-store/src/main/java/shop/alien/store/service/impl/LifeUserViolationServiceImpl.java

@@ -1,11 +1,13 @@
 package shop.alien.store.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.google.common.collect.Lists;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
@@ -17,9 +19,12 @@ import shop.alien.entity.store.dto.LifeUserViolationDto;
 import shop.alien.entity.store.excelVo.LifeUserViolationExcelVO;
 import shop.alien.entity.store.excelVo.util.ExcelGenerator;
 import shop.alien.entity.store.vo.LifeUserViolationVo;
+import shop.alien.entity.store.vo.WebsocketVo;
 import shop.alien.mapper.*;
+import shop.alien.store.config.WebSocketProcess;
 import shop.alien.store.service.*;
 import shop.alien.store.util.FunctionMagic;
+import shop.alien.util.common.JwtUtil;
 
 import java.io.IOException;
 import java.time.Instant;
@@ -63,6 +68,8 @@ public class LifeUserViolationServiceImpl extends ServiceImpl<LifeUserViolationM
 
     private final LifeNoticeMapper lifeNoticeMapper;
 
+    private final WebSocketProcess webSocketProcess;
+
     @Value("${spring.web.resources.excel-path}")
     private String excelPath;
 
@@ -73,8 +80,44 @@ public class LifeUserViolationServiceImpl extends ServiceImpl<LifeUserViolationM
     private String fileUrl;
 
     @Override
-    public int reporting(LifeUserViolation lifeuserViolation) {
-        return lifeUserViolationMapper.insert(lifeuserViolation);
+    public int reporting(LifeUserViolation lifeuserViolation) throws Exception  {
+        int result = lifeUserViolationMapper.insert(lifeuserViolation);
+        if (result > 0) {
+            if (lifeuserViolation.getReportContextType().equals("4") || lifeuserViolation.getReportContextType().equals("5")) {
+                String phoneId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getString("userType") + "_" + JwtUtil.getCurrentUserInfo().getString("phone");
+
+                LifeNotice lifeNotice = getLifeNotice(lifeuserViolation);
+                lifeNoticeMapper.insert(lifeNotice);
+
+                WebsocketVo websocketVo = new WebsocketVo();
+                websocketVo.setSenderId("system");
+                websocketVo.setReceiverId(phoneId);
+                websocketVo.setCategory("notice");
+                websocketVo.setNoticeType("1");
+                websocketVo.setText(com.alibaba.fastjson2.JSONObject.from(lifeNotice).toJSONString());
+                webSocketProcess.sendMessage(phoneId, com.alibaba.fastjson2.JSONObject.from(lifeNotice).toJSONString());
+            }
+        }
+        return result;
+    }
+
+    private static LifeNotice getLifeNotice(LifeUserViolation lifeuserViolation)  {
+        JSONObject data = JwtUtil.getCurrentUserInfo();
+        String phoneId = null;
+        if (data != null) {
+            phoneId = data.getString("phone");
+        }
+        LifeNotice lifeNotice = new LifeNotice();
+        lifeNotice.setSenderId("system");
+        lifeNotice.setReceiverId("user_" + phoneId);
+        lifeNotice.setBusinessId(lifeuserViolation.getId());
+        lifeNotice.setTitle("举报通知");
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("title", "平台已受理");
+        jsonObject.put("message", "平台已受理,感谢您的反馈!");
+        lifeNotice.setContext(jsonObject.toJSONString());
+        lifeNotice.setNoticeType(1);
+        return lifeNotice;
     }
 
     @Override