Kaynağa Gözat

消息推送

yuliang 5 yıl önce
ebeveyn
işleme
7c8a64adb9

+ 27 - 1
whepi-doc/creatYeWeiHui.sql

@@ -44,4 +44,30 @@ inner join sys_uptown_unit suu on suu.unit_id=suh.unit_id and suu.uptown_id = 12
 
 
 select count(1) FROM sys_uptown_house suh
-inner join sys_uptown_unit suu on suu.unit_id=suh.unit_id and suu.uptown_id = 1238790987234
+inner join sys_uptown_unit suu on suu.unit_id=suh.unit_id and suu.uptown_id = 1238790987234
+
+
+SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
+ALTER DATABASE whepi CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
+
+ALTER TABLE ms_suspected CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+
+
+set character_set_client=utf8mb4;
+
+set character_set_connection=utf8mb4;
+
+set character_set_database=utf8mb4;
+
+set character_set_results=utf8mb4;
+
+set character_set_server=utf8mb4;
+
+set character_set_system=utf8mb4;
+
+ALTER TABLE ms_report CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+ALTER TABLE sys_user_open CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+ALTER TABLE sys_user_role CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+ALTER TABLE sys_uptown CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+ALTER TABLE sys_uptown_home CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+ALTER TABLE sys_uptown_house CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

+ 2 - 0
whepi-web/src/main/java/com/bofeng/StartWhEpi.java

@@ -3,11 +3,13 @@ package com.bofeng;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 @SpringBootApplication(exclude = {
         HibernateJpaAutoConfiguration.class
 })
 //@EnableWeChatConfiguration
+@EnableScheduling
 public class StartWhEpi {
 
     public static void main(String[] args) {

+ 29 - 0
whepi-web/src/main/java/com/bofeng/controller/EpiAdminController.java

@@ -1,15 +1,20 @@
 package com.bofeng.controller;
 
 import com.bofeng.dao.UptownHomeMapper;
+import com.bofeng.dao.UserOpenMapper;
 import com.bofeng.dao.UserRoleMapper;
 import com.bofeng.entity.UptownHome;
+import com.bofeng.entity.UserOpen;
 import com.bofeng.entity.UserRole;
 import com.bofeng.service.EpiAdminService;
+import com.bofeng.service.EpiTemplateMessageService;
+import com.bofeng.service.TemplateMessageService;
 import com.yvan.ModelOps;
 import com.yvan.mvc.Pd;
 import com.yvan.platform.StringUtils;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -25,6 +30,10 @@ public class EpiAdminController {
     private UptownHomeMapper uptownHomeMapper;
     @Autowired
     private UserRoleMapper userRoleMapper;
+    @Autowired
+    private EpiTemplateMessageService epiTemplateMessageService;
+    @Autowired
+    private UserOpenMapper userOpenMapper;
 
     @ApiOperation("升级业委会角色")
     @PostMapping("/whepi/epi/admin/addRole")
@@ -44,4 +53,24 @@ public class EpiAdminController {
         return null;
     }
 
+//    @Scheduled(cron = "0 44 12 * * ?") //每天19点执行一次
+    @Scheduled(cron = "0 0 19 * * ?") //每天19点执行一次
+    public void scheduledTaskByFixedDelay() {
+        System.out.println("==============执行定时任务开始================");
+        Long start = 0L, count = 100L;
+        while (true) {
+            List<UserOpen> userOpens = userOpenMapper.getOpenUser(start, count);
+            int re = 0;
+            for (UserOpen userOpen : userOpens) {
+                re += epiTemplateMessageService.systemSendRemindMessage(userOpen.getUserId(), userOpen.getOpenId());
+            }
+            System.out.println("==============执行定时任务"+re+"================");
+            start += count;
+            if (userOpens == null || userOpens.size()<count) {
+                break;
+            }
+        }
+
+        System.out.println("==============执行定时任务完毕================");
+    }
 }

+ 7 - 0
whepi-web/src/main/java/com/bofeng/dao/UptownHomeMapper.java

@@ -21,4 +21,11 @@ public interface UptownHomeMapper extends BaseMapper<UptownHome> {
 
     @Select("select ur.user_id from sys_uptown_home uh left join sys_user_role ur on ur.property_id = uh.house_id where uh.phone = #{phone} and uh.status = 1")
     Long getUserIdByPhone(@Param("phone") String phone);
+
+    @Select(
+            "select uh.* from sys_uptown_home uh\n" +
+                    "        left join sys_user_role  ur on uh.house_id= ur.property_id\n" +
+                    "        where ur.user_id = #{userId}"
+    )
+    List<UptownHome> getUptownHomeByUserId(@Param("userId") Long userId);
 }

+ 6 - 0
whepi-web/src/main/java/com/bofeng/dao/UserOpenMapper.java

@@ -5,6 +5,7 @@ import com.bofeng.entity.User;
 import com.bofeng.entity.UserOpen;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -23,4 +24,9 @@ public interface UserOpenMapper extends BaseMapper<UserOpen> {
     UserOpen selectByOpenId(@Param("openId") String openId);
 
     List<UserOpen> getAllUser();
+
+    @Select(
+            "select user_id as userId, open_id as openId, nick_name as nickName from sys_user_open limit #{start}, #{count}"
+    )
+    List<UserOpen> getOpenUser(@Param("start") Long start, @Param("count") Long count);
 }

+ 7 - 0
whepi-web/src/main/java/com/bofeng/entity/UserOpen.java

@@ -8,6 +8,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.io.UnsupportedEncodingException;
+
 @Getter
 @Setter
 @TableName("sys_user_open")
@@ -25,6 +27,11 @@ public class UserOpen {
     @ExcelProperty(value = "昵称", index = 0)
     @TableField("nick_name")
     private String nickName;
+    private String getNicName() throws UnsupportedEncodingException {
+        byte[] utf8Bytes = nickName.getBytes("UTF-8");
+        String nickName = new String(utf8Bytes, "UTF-8");
+        return nickName;
+    }
 
     @ExcelProperty(value = "性别", index = 1)
     @TableField("sex_desc")

+ 31 - 15
whepi-web/src/main/java/com/bofeng/service/EpiTemplateMessageService.java

@@ -1,14 +1,18 @@
 package com.bofeng.service;
 
 import com.bofeng.dao.RbMapper;
+import com.bofeng.dao.UptownHomeMapper;
 import com.bofeng.dao.UserOpenMapper;
 import com.bofeng.entity.Uptown;
+import com.bofeng.entity.UptownHome;
 import com.bofeng.entity.UserOpen;
 import com.google.common.collect.Maps;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -21,6 +25,8 @@ public class EpiTemplateMessageService {
     @Autowired
     private TemplateMessageService templateMessageService;
     @Autowired
+    private UptownHomeMapper uptownHomeMapper;
+    @Autowired
     private RbMapper rbMapper;
 
     public int sendUserMessage(Long userId) {
@@ -47,23 +53,33 @@ public class EpiTemplateMessageService {
 
         return 1;
     }
-    //    {{first.DATA}}
-//    项目名称:{{keyword1.DATA}}
-//    任务名称:{{keyword2.DATA}}
-//    完成日期:{{keyword3.DATA}}
-//    指引与文档模版:{{keyword4.DATA}}
-//    指派人:{{keyword5.DATA}}
-//    {{remark.DATA}}
-    public int systemSendRemindMessage(Long userId) {
 
-        UserOpen userOpen = userOpenMapper.selectByUserId(userId);
+    //    {{first.DATA}}
+//    项目名称:{{keyword1.DATA}}                马兵 先生/女士,
+//    任务名称:{{keyword2.DATA}}                项目名称:家园互助平台
+//    完成日期:{{keyword3.DATA}}                任务名称:健康日报 上报
+//    指引与文档模版:{{keyword4.DATA}}           指引与文档模板:无
+//    指派人:{{keyword5.DATA}}                 指派人:系统
+//    {{remark.DATA}}                            家园互助平台提醒您,请及时提交今天的健康日报。
+    public int systemSendRemindMessage(Long userId, String openId) {
+        int re = 0;
         Map<String, String> map = Maps.newHashMap();
-        List<Uptown> uptownList = rbMapper.selectUptown(userId);
-
-        map.put("uptownName", uptownList.get(0).getUptownName());
-        map.put("tagName", "家人");
-//        templateMessageService.sendSysRemindMessage();
-        return 1;
+        List<UptownHome> uptownHomeList = uptownHomeMapper.getUptownHomeByUserId(userId);
+        if (uptownHomeList != null && uptownHomeList.size()>0) {
+            map.put("first", "尊敬的 "+uptownHomeList.get(0).getLinkman()+" 先生/女士,");
+            map.put("keyword1", "家园互助平台");
+            map.put("keyword2", "健康日报 上报");
+            SimpleDateFormat sdf1 =new SimpleDateFormat("yyyy-MM-dd" );
+            Date d1= new Date();
+            String str1 = sdf1.format(d1);
+            map.put("keyword3", str1);
+            map.put("keyword4", "无");
+            map.put("keyword5", "系统");
+            map.put("remark", "    家园互助平台提醒您,请及时提交今天的健康日报。");
+            re = 1;
+        }
+        templateMessageService.sendSysRemindMessage(openId, "", map);
+        return re;
     }
 
 }

+ 5 - 1
whepi-web/src/main/java/com/bofeng/wx/controller/MsReportController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -33,12 +34,15 @@ public class MsReportController {
 
     //添加家人
     @PostMapping("/home/addRibao")
-    public MsReport saveUser(HttpServletRequest request) {
+    public MsReport saveUser(HttpServletRequest request) throws UnsupportedEncodingException {
 
         //初始化今日日报
         Long suspectedId = Conv.NL(request.getParameter("suspectedId"));
         Long userCreate = Conv.NL(request.getParameter("userCreate"));
         String userName = request.getParameter("userName").trim();
+        byte[] utf8Bytes = userName.getBytes("UTF-8");
+        userName = new String(utf8Bytes, "UTF-8");
+
         Integer grender = Conv.NI(request.getParameter("grender"));
         Integer age = Conv.NI(request.getParameter("age"));
         Integer familyStatus = Conv.NI(request.getParameter("familyStatus"));

+ 1 - 0
whepi-web/src/main/resources/application.yml

@@ -64,6 +64,7 @@ spring:
   http:
     encoding:
       charset: utf-8
+      enabled: true
       force: true
     multipart:
        maxFileSize: 2Mb