Răsfoiți Sursa

风险记录推送到相关用户

ximinghao 3 luni în urmă
părinte
comite
48bbf4c9a4

+ 21 - 5
src/main/java/com/skyversation/xjcy/Timer.java

@@ -1,15 +1,14 @@
 package com.skyversation.xjcy;
 package com.skyversation.xjcy;
 
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
-import com.skyversation.xjcy.bean.Enterprise;
-import com.skyversation.xjcy.bean.EnterpriseEconomic;
-import com.skyversation.xjcy.bean.LeaseDetail;
+import com.skyversation.xjcy.bean.*;
 import com.skyversation.xjcy.computer.EnterpriseHealthComputer;
 import com.skyversation.xjcy.computer.EnterpriseHealthComputer;
 import com.skyversation.xjcy.dms.DMSColumn;
 import com.skyversation.xjcy.dms.DMSColumn;
 import com.skyversation.xjcy.dms.DMSQuery;
 import com.skyversation.xjcy.dms.DMSQuery;
 import com.skyversation.xjcy.dms.DMSService;
 import com.skyversation.xjcy.dms.DMSService;
 import com.skyversation.xjcy.oauth.AuthService;
 import com.skyversation.xjcy.oauth.AuthService;
 import com.skyversation.xjcy.service.InvestmentPreCountService;
 import com.skyversation.xjcy.service.InvestmentPreCountService;
+import com.skyversation.xjcy.service.MessageService;
 import com.skyversation.xjcy.service.ParkPreCountService;
 import com.skyversation.xjcy.service.ParkPreCountService;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
@@ -20,7 +19,10 @@ import java.time.LocalDateTime;
 import java.time.MonthDay;
 import java.time.MonthDay;
 import java.time.temporal.TemporalField;
 import java.time.temporal.TemporalField;
 import java.util.Arrays;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 
 @Component
 @Component
 //放一些定时器的简单类
 //放一些定时器的简单类
@@ -30,12 +32,14 @@ public class Timer {
     private final InvestmentPreCountService investmentPreCountService;
     private final InvestmentPreCountService investmentPreCountService;
     private final DMSService dMSService;
     private final DMSService dMSService;
     private final AuthService authService;
     private final AuthService authService;
+    private final MessageService messageService;
 
 
-    public Timer(ParkPreCountService parkPreCountService, InvestmentPreCountService investmentPreCountService, DMSService dMSService, AuthService authService) {
+    public Timer(ParkPreCountService parkPreCountService, InvestmentPreCountService investmentPreCountService, DMSService dMSService, AuthService authService, MessageService messageService) {
         this.parkPreCountService = parkPreCountService;
         this.parkPreCountService = parkPreCountService;
         this.investmentPreCountService = investmentPreCountService;
         this.investmentPreCountService = investmentPreCountService;
         this.dMSService = dMSService;
         this.dMSService = dMSService;
         this.authService = authService;
         this.authService = authService;
+        this.messageService = messageService;
     }
     }
 
 
     //@Scheduled(fixedRate = 5000)
     //@Scheduled(fixedRate = 5000)
@@ -51,7 +55,7 @@ public class Timer {
     @PostConstruct
     @PostConstruct
     public void checkEnterpriseHealth(){
     public void checkEnterpriseHealth(){
         LocalDate now = LocalDate.now();
         LocalDate now = LocalDate.now();
-        LocalDateTime actuallyTime = now.minusDays(1).atTime(23,59,59,9999);
+        LocalDateTime actuallyTime = now.minusDays(1).atTime(23,59,59,999999999);
 //        LocalDateTime actuallyTime = LocalDateTime.of(2025,9,30,23,59,59,9999);
 //        LocalDateTime actuallyTime = LocalDateTime.of(2025,9,30,23,59,59,9999);
 
 
         List<Enterprise> enterprises = dMSService.query(authService.getTokenOfServiceAccount(), DMSQuery.ENTERPRISE, Enterprise.class,actuallyTime.toLocalDate());
         List<Enterprise> enterprises = dMSService.query(authService.getTokenOfServiceAccount(), DMSQuery.ENTERPRISE, Enterprise.class,actuallyTime.toLocalDate());
@@ -92,5 +96,17 @@ public class Timer {
                 System.out.println("保存失败");
                 System.out.println("保存失败");
             }
             }
         }
         }
+        List<User> users = dMSService.query(authService.getTokenOfServiceAccount(),DMSQuery.USER_BIND_ENTERPRISE,User.class,actuallyTime.toLocalDate());
+        Map<String, List<User>> userMap = users.stream().filter(u->u.getCGlGs()!=null).collect(Collectors.groupingBy(User::getCGlGs));
+
+        enterpriseHealthComputer.getResults().stream().filter(EnterpriseHealth::isPositive).forEach(e->{
+            String enterpriseCode = e.getCEnterpriseCode();
+            List<User> userList = userMap.get(enterpriseCode);
+            if (userList!=null) {
+                for (User user : userList) {
+                    messageService.sendMessageByEnterpriseHealth(e,actuallyTime,user);
+                }
+            }
+        });
     }
     }
 }
 }

+ 29 - 2
src/main/java/com/skyversation/xjcy/bean/EnterpriseHealth.java

@@ -12,8 +12,6 @@ import java.time.format.DateTimeFormatter;
  * 企业健康计算结果Bean
  * 企业健康计算结果Bean
  */
  */
 @Data
 @Data
-@NoArgsConstructor
-@AllArgsConstructor
 public class EnterpriseHealth {
 public class EnterpriseHealth {
     public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
     public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
     
     
@@ -52,6 +50,16 @@ public class EnterpriseHealth {
      */
      */
     private String cEnterpriseCode;
     private String cEnterpriseCode;
 
 
+    /**
+     * 内部字段:企业名称
+     */
+    private String cEnterpriseName;
+
+    /**
+     * 内部字段:是否正面
+     */
+    private boolean positive;
+
     /**
     /**
      * 应展示时间开始点
      * 应展示时间开始点
      */
      */
@@ -62,6 +70,25 @@ public class EnterpriseHealth {
      */
      */
     private LocalDateTime cShowTimeEnd;
     private LocalDateTime cShowTimeEnd;
 
 
+    public EnterpriseHealth() {}
+
+    public EnterpriseHealth(String title, String describe, int value, LocalDateTime computeTime,
+                            LocalDateTime healthStart, LocalDateTime healthEnd, String cUnifiedSocialCreditCode,
+                            String cEnterpriseName, boolean positive,
+                            LocalDateTime showTimeStart, LocalDateTime showTimeEnd) {
+        this.cTitle = title;
+        this.cDescribe = describe;
+        this.cType = value;
+        this.cComputeTime = computeTime;
+        this.cHealthStartTime = healthStart;
+        this.cHealthEndTime = healthEnd;
+        this.cEnterpriseCode = cUnifiedSocialCreditCode;
+        this.cEnterpriseName = cEnterpriseName;
+        this.positive = positive;
+        this.cShowTimeStart = showTimeStart;
+        this.cShowTimeEnd =showTimeEnd;
+    }
+
     /**
     /**
      * 转换为JSONObject
      * 转换为JSONObject
      * @return JSONObject
      * @return JSONObject

+ 44 - 0
src/main/java/com/skyversation/xjcy/bean/Message.java

@@ -0,0 +1,44 @@
+package com.skyversation.xjcy.bean;
+
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.annotation.JSONField;
+import com.skyversation.xjcy.config.LocalDateFromTimestampDeserializer;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class Message {
+
+    public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd '00:00:00'");
+
+    private String cUserName;    // 用户名
+    @JSONField(deserializeUsing = LocalDateFromTimestampDeserializer.class)
+    private LocalDate cTime;        // 时间
+    private Boolean cReaded;     // 已读
+    private String cTitle;       // 标题
+    private String cContent;     // 正文
+
+
+    /**
+     * 转换为JSONObject
+     * @return JSONObject
+     */
+    public JSONObject toJson() {
+        JSONObject json = new JSONObject();
+        json.put("c_user_name", this.cUserName);
+        json.put("c_time", this.cTime != null ? this.cTime.format(FORMATTER) : null);
+        json.put("c_readed", this.cReaded);
+        json.put("c_title", this.cTitle);
+        json.put("c_content", this.cContent);
+        json.put("title", this.cTitle);
+        json.put("content", this.cUserName);
+        return json;
+    }
+
+}

+ 9 - 0
src/main/java/com/skyversation/xjcy/bean/User.java

@@ -0,0 +1,9 @@
+package com.skyversation.xjcy.bean;
+
+import lombok.Data;
+
+@Data
+public class User implements FromJSON{
+    private String cUsercode;
+    private String cGlGs;
+}

+ 2 - 1
src/main/java/com/skyversation/xjcy/computer/EnterpriseHealthComputer.java

@@ -407,7 +407,8 @@ public class EnterpriseHealthComputer {
             }
             }
         }
         }
         EnterpriseHealth result = new EnterpriseHealth(title, describe, type.getValue(), computeTime,
         EnterpriseHealth result = new EnterpriseHealth(title, describe, type.getValue(), computeTime,
-                healthStart, healthEnd, enterprise.getCUnifiedSocialCreditCode(),showTimeStart,showTimeEnd);
+                healthStart, healthEnd, enterprise.getCUnifiedSocialCreditCode(),enterprise.getCEnterpriseName(),
+                type.isPositive(),showTimeStart,showTimeEnd);
         results.add(result);
         results.add(result);
     }
     }
 
 

+ 3 - 1
src/main/java/com/skyversation/xjcy/dms/DMSColumn.java

@@ -12,7 +12,9 @@ public enum DMSColumn {
     CLUE("1576","1521"),
     CLUE("1576","1521"),
     CLUE_FOLLOW("1577","1522"),
     CLUE_FOLLOW("1577","1522"),
     ENTERPRISE_HEALTH("1643","1643"),
     ENTERPRISE_HEALTH("1643","1643"),
-    WECHAT_ARTICLE("1599","1544");
+    WECHAT_ARTICLE("1599","1544"),
+    MESSAGE("1646","1649" ),
+    USER("1579","1524" );
     @Getter
     @Getter
     private final String id;
     private final String id;
     @Getter
     @Getter

+ 6 - 0
src/main/java/com/skyversation/xjcy/dms/DMSQuery.java

@@ -81,6 +81,12 @@ public enum DMSQuery {
         DMSRequest preRequest(LocalDate now) {
         DMSRequest preRequest(LocalDate now) {
             return new DMSRequest();
             return new DMSRequest();
         }
         }
+    },
+    USER_BIND_ENTERPRISE(DMSColumn.USER,User.class) {
+        @Override
+        public DMSRequest preRequest(LocalDate now) {
+            return new DMSRequest();
+        }
     };
     };
 
 
     private final DMSColumn column;
     private final DMSColumn column;

+ 1 - 1
src/main/java/com/skyversation/xjcy/dms/DMSService.java

@@ -212,7 +212,7 @@ public class DMSService {
             throw new RuntimeException("上传失败");
             throw new RuntimeException("上传失败");
         }
         }
     }
     }
-    public boolean insertToDms(JSONObject objs, String token, DMSColumn column) {
+    public boolean insertToDms(Object objs, String token, DMSColumn column) {
 
 
         MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
         MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
         params.add("modelId",column.getModelId());
         params.add("modelId",column.getModelId());

+ 9 - 1
src/main/java/com/skyversation/xjcy/oauth/AuthService.java

@@ -156,11 +156,19 @@ public class AuthService {
      * @throws RuntimeException 内置账户信息异常
      * @throws RuntimeException 内置账户信息异常
      */
      */
     public String getTokenOfServiceAccount() throws RuntimeException {
     public String getTokenOfServiceAccount() throws RuntimeException {
+        if (account == null) {
+            throw new RuntimeException("无可用账号信息");
+        }
         // 双重检查锁定,确保线程安全
         // 双重检查锁定,确保线程安全
         if (!StringUtils.hasText(cacheToken) || !checkToken(cacheToken)) {
         if (!StringUtils.hasText(cacheToken) || !checkToken(cacheToken)) {
             synchronized (this) {
             synchronized (this) {
                 if (!StringUtils.hasText(cacheToken) || !checkToken(cacheToken)) {
                 if (!StringUtils.hasText(cacheToken) || !checkToken(cacheToken)) {
-                    cacheToken = loginForToken(account);
+                    try {
+                        cacheToken = loginForToken(account);
+                    } catch (RuntimeException e) {
+                        this.account = null;
+                        throw new RuntimeException(e);
+                    }
                 }
                 }
             }
             }
         }
         }

+ 40 - 0
src/main/java/com/skyversation/xjcy/service/MessageService.java

@@ -0,0 +1,40 @@
+package com.skyversation.xjcy.service;
+
+import com.alibaba.fastjson.JSON;
+import com.skyversation.xjcy.bean.EnterpriseHealth;
+import com.skyversation.xjcy.bean.Message;
+import com.skyversation.xjcy.bean.User;
+import com.skyversation.xjcy.dms.DMSColumn;
+import com.skyversation.xjcy.dms.DMSService;
+import com.skyversation.xjcy.oauth.AuthService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+@Service
+public class MessageService {
+    private final DMSService dMSService;
+    private final AuthService authService;
+
+    public MessageService(DMSService dMSService, AuthService authService) {
+        this.dMSService = dMSService;
+        this.authService = authService;
+    }
+
+    public void sendMessage(Message message) {
+        dMSService.insertToDms(message.toJson(),authService.getTokenOfServiceAccount(), DMSColumn.MESSAGE);
+    }
+
+    public void sendMessageByEnterpriseHealth(EnterpriseHealth enterpriseHealth, LocalDateTime time , User user) {
+        Message message = new Message();
+        message.setCTime(time.toLocalDate());
+        message.setCReaded(false);
+        message.setCUserName(user.getCUsercode());
+        message.setCTitle(String.format("【异常企业】%s",enterpriseHealth.getCEnterpriseName()));
+        message.setCContent(String.format("%s存在%s的异常,请关注并了解原因;",enterpriseHealth.getCEnterpriseName(),enterpriseHealth.getCDescribe()));
+        sendMessage(message);
+
+    }
+}