Bläddra i källkod

带消息推送的联采项目写入

ximinghao 1 månad sedan
förälder
incheckning
1291c3323c

+ 104 - 0
src/main/java/com/skyversation/xjcy/bean/Lcxm.java

@@ -0,0 +1,104 @@
+package com.skyversation.xjcy.bean;
+
+import lombok.Data;
+import lombok.Getter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Data
+public class Lcxm {
+   private String cName;
+   private String cPhone;
+   private String cUserType;
+   private String cEnterpriseName;
+   private String cEnterpriseCode;
+   private String cServiceType;
+   private String cSubServiceType;
+   private String cDescribe;
+   /**
+    * 服务大类枚举
+    */
+   @Getter
+   public static enum ServiceCategory {
+
+      BUSINESS_STARTUP(1, "开办一件事"),
+      OVERSEAS_SERVICE(2, "出海服务(联合国采购)"),
+      PARTY_BUILDING(3, "党建服务"),
+      TALENT_SERVICE(4, "人才服务咨询"),
+      HUMAN_RESOURCE_SERVICE(5, "人社服务咨询"),
+      INDUSTRY_POLICY_SERVICE(6, "产业政策服务咨询"),
+      VALUE_ADDED_SERVICE(7, "增值服务咨询(金融、税务、法律)");
+
+      private final int id;
+      private final String name;
+
+      // 静态Map,用于通过编号快速查找枚举实例
+      private static final Map<Integer, ServiceCategory> CATEGORY_MAP = new HashMap<>();
+
+      static {
+         // 初始化Map
+         for (ServiceCategory category : ServiceCategory.values()) {
+            CATEGORY_MAP.put(category.getId(), category);
+         }
+      }
+
+      ServiceCategory(int id, String name) {
+         this.id = id;
+         this.name = name;
+      }
+
+      public int getId() {
+         return id;
+      }
+
+      public String getName() {
+         return name;
+      }
+
+      /**
+       * 通过编号获取枚举实例
+       * @param id 大类编号
+       * @return 对应的枚举实例,如果不存在则返回null
+       */
+      public static ServiceCategory getById(int id) {
+         return CATEGORY_MAP.get(id);
+      }
+
+      /**
+       * 通过编号获取枚举实例(安全版本)
+       * @param id 大类编号
+       * @return 对应的枚举实例,如果不存在则抛出异常
+       * @throws IllegalArgumentException 当编号不存在时
+       */
+      public static ServiceCategory getByIdSafe(int id) {
+         ServiceCategory category = CATEGORY_MAP.get(id);
+         if (category == null) {
+            throw new IllegalArgumentException("无效的服务大类编号: " + id);
+         }
+         return category;
+      }
+
+      /**
+       * 检查编号是否存在
+       * @param id 大类编号
+       * @return 如果存在返回true,否则返回false
+       */
+      public static boolean containsId(int id) {
+         return CATEGORY_MAP.containsKey(id);
+      }
+
+      /**
+       * 获取所有大类的Map副本
+       * @return 所有大类编号到枚举实例的Map
+       */
+      public static Map<Integer, ServiceCategory> getAllCategories() {
+         return new HashMap<>(CATEGORY_MAP);
+      }
+
+      @Override
+      public String toString() {
+         return String.format("%d. %s", id, name);
+      }
+   }
+}

+ 11 - 0
src/main/java/com/skyversation/xjcy/bean/MessageTarget.java

@@ -0,0 +1,11 @@
+package com.skyversation.xjcy.bean;
+
+import lombok.Data;
+
+@Data
+public class MessageTarget implements FromJSON{
+    private Boolean cOpen;
+    private String cUsername;
+    private String cPhone;
+    private String cGroup;
+}

+ 26 - 4
src/main/java/com/skyversation/xjcy/controller/OtherController.java

@@ -4,23 +4,24 @@ import cn.hutool.extra.qrcode.BufferedImageLuminanceSource;
 import com.alibaba.fastjson.JSONObject;
 import com.google.zxing.*;
 import com.google.zxing.common.HybridBinarizer;
+import com.skyversation.xjcy.bean.Lcxm;
 import com.skyversation.xjcy.bean.User;
 import com.skyversation.xjcy.dms.DMSColumn;
 import com.skyversation.xjcy.dms.DMSService;
 import com.skyversation.xjcy.service.AlyOCRService;
 import com.skyversation.xjcy.service.AuthService;
+import com.skyversation.xjcy.service.MessageService;
 import com.skyversation.xjcy.service.WeChatService;
 import com.skyversation.xjcy.util.MessageManage;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.InputStream;
@@ -38,12 +39,14 @@ public class OtherController {
     private final AuthService authService;
     private final DMSService dMSService;
     private final AlyOCRService alyOCRService;
+    private final MessageService messageService;
 
-    public OtherController(WeChatService weChatService, AuthService authService, DMSService dMSService, AlyOCRService alyOCRService) {
+    public OtherController(WeChatService weChatService, AuthService authService, DMSService dMSService, AlyOCRService alyOCRService, MessageService messageService) {
         this.weChatService = weChatService;
         this.authService = authService;
         this.dMSService = dMSService;
         this.alyOCRService = alyOCRService;
+        this.messageService = messageService;
     }
 
     @RequestMapping(value = "/wxacode", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@@ -124,4 +127,23 @@ public class OtherController {
             return MessageManage.error(-1,"解析二维码失败");
         }
     }
+    @PostMapping(value = "/lcxm")
+    public String lcxm(@RequestParam Map<String,String> map, HttpServletRequest request) {
+        String token = request.getHeader("token");
+        if (!authService.checkToken(token)) {return MessageManage.error(-1,"不可用的token");}
+        boolean success = dMSService.insertToDms(map, token, DMSColumn.LCXM);
+        if (success) {
+            String type = map.get("c_service_type");
+            String[] types = type.split(",");
+            String[] readAbleTypes = new String[types.length];
+            for (int i = 0; i < types.length; i++) {
+                readAbleTypes[i] = Lcxm.ServiceCategory.getById(Integer.parseInt(types[i])).getName();
+            }
+            type = String.join(",", readAbleTypes);
+            messageService.noticeLcxm(type,map.get("c_phone"),map.get("c_name"));
+            return MessageManage.successWithNoData("成功");
+        }else {
+            return MessageManage.error(-1,"未知错误");
+        }
+    }
 }

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

@@ -14,7 +14,9 @@ public enum DMSColumn {
     ENTERPRISE_HEALTH("1643","1643"),
     WECHAT_ARTICLE("1599","1544"),
     MESSAGE("1646","1649" ),
-    USER("1579","1524" );
+    USER("1579","1524" ),
+    MESSAGE_TARGET("1661","1671"),
+    LCXM("1660","1669"),;
     @Getter
     private final String id;
     @Getter

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

@@ -87,6 +87,12 @@ public enum DMSQuery {
         public DMSQueryRequest preRequest(LocalDate now) {
             return new DMSQueryRequest();
         }
+    },
+    MESSAGE_TARGET(DMSColumn.MESSAGE_TARGET,MessageTarget.class) {
+        @Override
+        public DMSQueryRequest preRequest(LocalDate now) {
+            return new DMSQueryRequest();
+        }
     };
 
     private final DMSColumn column;

+ 21 - 11
src/main/java/com/skyversation/xjcy/service/AlyPhoneMessageSendService.java

@@ -21,10 +21,15 @@ public class AlyPhoneMessageSendService implements PhoneMessageSendService {
     @Value("${app.aly.message.endpoint}")
     private String endpoint;
 
-    @Value("${app.aly.code.sign}")
+    @Value("${app.aly.message.code.sign}")
     private String codeSign;
-    @Value("${app.aly.code.template-code}")
-    private String templateCode;
+    @Value("${app.aly.message.code.template-code}")
+    private String codeTemplate;
+
+    @Value("${app.aly.message.notice.sign}")
+    private String noticeSign;
+    @Value("${app.aly.message.notice.template-code}")
+    private String noticeTemplate;
 
     public Client createClient() throws Exception {
         Config config = new Config();
@@ -34,19 +39,24 @@ public class AlyPhoneMessageSendService implements PhoneMessageSendService {
         return new Client(config);
     }
     @Override
-    public boolean sendMessage(String phone, String code) {
-        System.out.println(this);
-        System.out.println("通过阿里云服务发送短信");
-        System.out.println("发送到手机号---->"+phone);
-        System.out.println("验证码---->"+ code);
-
+    public boolean sendCode(String phone, String code) {
         JSONObject obj = new JSONObject();
         obj.put("code", code);
+        return send(phone, obj, codeSign, codeTemplate);
+    }
+
+    @Override
+    public boolean sendNotice(String phone, String type) {
+        JSONObject obj = new JSONObject();
+        obj.put("type", type);
+        return send(phone, obj, noticeSign, noticeTemplate);
+    }
 
+    private boolean send(String phone, JSONObject obj, String noticeSign, String noticeTemplate) {
         SendSmsRequest sendSmsRequest = new SendSmsRequest()
                 .setPhoneNumbers(phone)
-                .setSignName(codeSign)
-                .setTemplateCode(templateCode)
+                .setSignName(noticeSign)
+                .setTemplateCode(noticeTemplate)
                 .setTemplateParam(obj.toJSONString());
         try {
             SendSmsResponse sendSmsResponse = createClient().sendSms(sendSmsRequest);

+ 29 - 4
src/main/java/com/skyversation/xjcy/service/MessageService.java

@@ -1,22 +1,26 @@
 package com.skyversation.xjcy.service;
 
-import com.skyversation.xjcy.bean.EnterpriseHealth;
-import com.skyversation.xjcy.bean.Message;
-import com.skyversation.xjcy.bean.User;
+import com.skyversation.xjcy.bean.*;
 import com.skyversation.xjcy.dms.DMSColumn;
+import com.skyversation.xjcy.dms.DMSQuery;
 import com.skyversation.xjcy.dms.DMSService;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 public class MessageService {
     private final DMSService dMSService;
     private final AuthService authService;
+    private final PhoneMessageSendService phoneMessageSendService;
 
-    public MessageService(DMSService dMSService, AuthService authService) {
+    public MessageService(DMSService dMSService, AuthService authService, AlyPhoneMessageSendService alyPhoneMessageSendService) {
         this.dMSService = dMSService;
         this.authService = authService;
+        this.phoneMessageSendService = alyPhoneMessageSendService;
     }
 
     public void sendMessage(Message message) {
@@ -33,4 +37,25 @@ public class MessageService {
         sendMessage(message);
 
     }
+    public void noticeLcxm(String type,String phone,String name){
+        List<MessageTarget> messageTarget = dMSService.query(authService.getTokenOfServiceAccount(), DMSQuery.MESSAGE_TARGET, MessageTarget.class, LocalDate.now());
+        messageTarget.stream()
+                .filter(MessageTarget::getCOpen)
+                .filter(m->"lcxm".equals(m.getCGroup()))
+                .forEach(m->{
+                    if (m.getCPhone()!=null&&!m.getCPhone().isEmpty()){
+                        phoneMessageSendService.sendNotice(m.getCPhone(),type);
+                    }
+                    if (m.getCUsername()!=null&&!m.getCUsername().isEmpty()){
+                        Message message = new Message();
+                        message.setCReaded(false);
+                        message.setCUserName(m.getCUsername());
+                        message.setCTitle("业务诉求");
+                        message.setCContent(String.format("新业务诉求提交:姓名%s,手机号%s,业务类型:%s,需及时跟进处理",name,phone,type));
+                        message.setCTime(LocalDate.now());
+                        sendMessage(message);
+                    }
+                });
+
+    }
 }

+ 2 - 1
src/main/java/com/skyversation/xjcy/service/PhoneMessageSendService.java

@@ -1,5 +1,6 @@
 package com.skyversation.xjcy.service;
 
 public interface PhoneMessageSendService {
-    boolean sendMessage(String phone,String code);
+    boolean sendCode(String phone, String code);
+    boolean sendNotice(String phone, String type);
 }

+ 1 - 1
src/main/java/com/skyversation/xjcy/service/PhoneService.java

@@ -51,7 +51,7 @@ public class PhoneService {
     public boolean sendCode(String phone) {
         String code = generateCode();
         cache.put(phone,code,5,TimeUnit.MINUTES);
-        return phoneMessageSendService.sendMessage(phone,code);
+        return phoneMessageSendService.sendCode(phone,code);
     }
     private boolean checkCode(String phone,String code){
         Object lock = lockPool.computeIfAbsent(phone, k -> new Object());

+ 6 - 3
src/main/resources/application.yml

@@ -39,9 +39,12 @@ app:
     secret: ${ALIBABA_CLOUD_ACCESS_KEY_SECRET:YivC1800cacnEpcS3OSQKIcr5Itgal}
     message:
       endpoint: ${ALIBABA_CLOUD_MESSAGE_ENDPOINT:dysmsapi.aliyuncs.com}
-    code:
-      sign: ${XJCY_ALIBABA_SIGN:上海元以数智科技}
-      template-code: ${XJCY_ALIBABA_CODE_TEMPLATE:SMS_496690245}
+      code:
+        sign: ${XJCY_ALIBABA_SIGN:上海元以数智科技}
+        template-code: ${XJCY_ALIBABA_CODE_TEMPLATE:SMS_496690245}
+      notice:
+        sign: ${XJCY_ALIBABA_SIGN:上海元以数智科技}
+        template-code: ${XJCY_ALIBABA_NOTICE_TEMPLATE:SMS_500695141}
     ocr:
       endpoint: ${ALIBABA_CLOUD_OCR_ENDPOINT:ocr-api.cn-hangzhou.aliyuncs.com}
 ---