소스 검색

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	book-dao/src/main/java/com/book/dao/cps/mapper/UserMapper.java
#	book-dao/src/main/resources/mapper/cps/UserMapper.xml
tianyunperfect 3 년 전
부모
커밋
e4f1f064f4
24개의 변경된 파일946개의 추가작업 그리고 393개의 파일을 삭제
  1. 2 0
      book-dao/src/main/java/com/book/dao/cps/mapper/CustomMapper.java
  2. 5 0
      book-dao/src/main/java/com/book/dao/cps/mapper/UserMapper.java
  3. 22 0
      book-dao/src/main/java/com/book/dao/cps/pojo/Custom.java
  4. 6 0
      book-dao/src/main/resources/mapper/cps/CustomMapper.xml
  5. 404 357
      book-dao/src/main/resources/mapper/cps/UserMapper.xml
  6. 3 1
      book-push/src/main/java/com/book/push/Application.java
  7. 2 2
      book-push/src/main/java/com/book/push/cons/SchemeCons.java
  8. 9 3
      book-push/src/main/java/com/book/push/cons/UrlCons.java
  9. 2 2
      book-push/src/main/java/com/book/push/controller/WxRedirectController.java
  10. 41 27
      book-push/src/main/java/com/book/push/handler/MenuHandler.java
  11. 17 0
      book-push/src/main/java/com/book/push/service/dao/BookService.java
  12. 3 0
      book-push/src/main/java/com/book/push/service/dao/CustomService.java
  13. 4 0
      book-push/src/main/java/com/book/push/service/dao/UserService.java
  14. 27 0
      book-push/src/main/java/com/book/push/service/dao/impl/BookServiceImpl.java
  15. 11 0
      book-push/src/main/java/com/book/push/service/dao/impl/CustomServiceImpl.java
  16. 9 0
      book-push/src/main/java/com/book/push/service/dao/impl/UserServiceImpl.java
  17. 15 0
      book-push/src/main/java/com/book/push/service/push/PushResultListener.java
  18. 12 0
      book-push/src/main/java/com/book/push/service/push/PushService.java
  19. 57 0
      book-push/src/main/java/com/book/push/service/push/impl/PushCustomMessageTask.java
  20. 38 0
      book-push/src/main/java/com/book/push/service/push/impl/PushMessageTask.java
  21. 18 1
      book-push/src/main/java/com/book/push/service/push/impl/PushServiceImpl.java
  22. 21 0
      book-push/src/main/java/com/book/push/service/push/vo/CustomMessage.java
  23. 134 0
      book-push/src/main/java/com/book/push/task/KefuTask.java
  24. 84 0
      book-push/src/main/java/com/book/push/utils/JsonUtils.java

+ 2 - 0
book-dao/src/main/java/com/book/dao/cps/mapper/CustomMapper.java

@@ -22,4 +22,6 @@ public interface CustomMapper {
 
 
     List<Custom> selectListBeforeSendTime();
+
+    List<Custom> selectListBetweenSendTime(Integer from, Integer to);
 }

+ 5 - 0
book-dao/src/main/java/com/book/dao/cps/mapper/UserMapper.java

@@ -4,6 +4,9 @@ import com.book.dao.cps.pojo.User;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+import java.util.Map;
+
 @Repository
 public interface UserMapper {
 
@@ -26,4 +29,6 @@ public interface UserMapper {
     int updateUserKandian(@Param("user") User user, @Param("kandian") int kandian, @Param("freekandian") int freekandian, @Param("updateTime") int updateTime);
 
     User selectByUserId(@Param("openId") String userId);
+
+    List<User> selectListByPushMap(Map map);
 }

+ 22 - 0
book-dao/src/main/java/com/book/dao/cps/pojo/Custom.java

@@ -1,5 +1,6 @@
 package com.book.dao.cps.pojo;
 
+import com.alibaba.druid.support.json.JSONUtils;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -102,5 +103,26 @@ public class Custom implements Serializable {
      */
     private Object createdFrom;
 
+
+
+    @Data
+    public static class UserJson{
+       // "{\"sex\":-1,\"tag\":-1,\"consume\":-1,\"kandian\":-1,\"subscribe_time\":-1,\"all\":\"0\"}"
+        Integer sex;
+        Integer tag;
+        Integer consume;
+        Integer kandian;
+        Integer subscribe_time;
+        String all;
+    }
+    @Data
+    public static class MessageJson{
+        private String type;
+        private String title;
+        private String url;
+        private String image;
+        private String description;
+    }
+
     private static final long serialVersionUID = 1L;
 }

+ 6 - 0
book-dao/src/main/resources/mapper/cps/CustomMapper.xml

@@ -39,6 +39,12 @@
         where sendtime > UNIX_TIMESTAMP(NOW());
 
     </select>
+    <select id="selectListBetweenSendTime" resultMap="BaseResultMap">
+        select *
+        from custom
+        where statue = 'normal'
+          and sendtime between #{from} and #{to};
+    </select>
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
         delete
         from custom

+ 404 - 357
book-dao/src/main/resources/mapper/cps/UserMapper.xml

@@ -1,376 +1,423 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.book.dao.cps.mapper.UserMapper">
-  <resultMap id="BaseResultMap" type="com.book.dao.cps.pojo.User">
-    <id column="id" jdbcType="BIGINT" property="id" />
-    <result column="openid" jdbcType="VARCHAR" property="openid" />
-    <result column="unionid" jdbcType="VARCHAR" property="unionid" />
-    <result column="visitor" jdbcType="VARCHAR" property="visitor" />
-    <result column="nickname" jdbcType="VARCHAR" property="nickname" />
-    <result column="sex" jdbcType="OTHER" property="sex" />
-    <result column="mobile" jdbcType="CHAR" property="mobile" />
-    <result column="avatar" jdbcType="VARCHAR" property="avatar" />
-    <result column="is_subscribe" jdbcType="OTHER" property="isSubscribe" />
-    <result column="subscription_extend" jdbcType="OTHER" property="subscriptionExtend" />
-    <result column="subscribe_time" jdbcType="INTEGER" property="subscribeTime" />
-    <result column="book_category_ids" jdbcType="VARCHAR" property="bookCategoryIds" />
-    <result column="operate_time" jdbcType="INTEGER" property="operateTime" />
-    <result column="is_pay" jdbcType="OTHER" property="isPay" />
-    <result column="kandian" jdbcType="INTEGER" property="kandian" />
-    <result column="free_kandian" jdbcType="INTEGER" property="freeKandian" />
-    <result column="vip_endtime" jdbcType="INTEGER" property="vipEndtime" />
-    <result column="register_ip" jdbcType="VARCHAR" property="registerIp" />
-    <result column="country" jdbcType="VARCHAR" property="country" />
-    <result column="area" jdbcType="VARCHAR" property="area" />
-    <result column="province" jdbcType="VARCHAR" property="province" />
-    <result column="city" jdbcType="VARCHAR" property="city" />
-    <result column="isp" jdbcType="VARCHAR" property="isp" />
-    <result column="channel_id" jdbcType="INTEGER" property="channelId" />
-    <result column="state" jdbcType="OTHER" property="state" />
-    <result column="createtime" jdbcType="INTEGER" property="createtime" />
-    <result column="updatetime" jdbcType="INTEGER" property="updatetime" />
-  </resultMap>
-  <sql id="Base_Column_List">
-    id, openid, unionid, visitor, nickname, sex, mobile, avatar, is_subscribe, subscription_extend, 
+    <resultMap id="BaseResultMap" type="com.book.dao.cps.pojo.User">
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="openid" jdbcType="VARCHAR" property="openid"/>
+        <result column="unionid" jdbcType="VARCHAR" property="unionid"/>
+        <result column="visitor" jdbcType="VARCHAR" property="visitor"/>
+        <result column="nickname" jdbcType="VARCHAR" property="nickname"/>
+        <result column="sex" jdbcType="OTHER" property="sex"/>
+        <result column="mobile" jdbcType="CHAR" property="mobile"/>
+        <result column="avatar" jdbcType="VARCHAR" property="avatar"/>
+        <result column="is_subscribe" jdbcType="OTHER" property="isSubscribe"/>
+        <result column="subscription_extend" jdbcType="OTHER" property="subscriptionExtend"/>
+        <result column="subscribe_time" jdbcType="INTEGER" property="subscribeTime"/>
+        <result column="book_category_ids" jdbcType="VARCHAR" property="bookCategoryIds"/>
+        <result column="operate_time" jdbcType="INTEGER" property="operateTime"/>
+        <result column="is_pay" jdbcType="OTHER" property="isPay"/>
+        <result column="kandian" jdbcType="INTEGER" property="kandian"/>
+        <result column="free_kandian" jdbcType="INTEGER" property="freeKandian"/>
+        <result column="vip_endtime" jdbcType="INTEGER" property="vipEndtime"/>
+        <result column="register_ip" jdbcType="VARCHAR" property="registerIp"/>
+        <result column="country" jdbcType="VARCHAR" property="country"/>
+        <result column="area" jdbcType="VARCHAR" property="area"/>
+        <result column="province" jdbcType="VARCHAR" property="province"/>
+        <result column="city" jdbcType="VARCHAR" property="city"/>
+        <result column="isp" jdbcType="VARCHAR" property="isp"/>
+        <result column="channel_id" jdbcType="INTEGER" property="channelId"/>
+        <result column="state" jdbcType="OTHER" property="state"/>
+        <result column="createtime" jdbcType="INTEGER" property="createtime"/>
+        <result column="updatetime" jdbcType="INTEGER" property="updatetime"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        id, openid, unionid, visitor, nickname, sex, mobile, avatar, is_subscribe, subscription_extend,
     subscribe_time, book_category_ids, operate_time, is_pay, kandian, free_kandian, vip_endtime, 
     register_ip, country, area, province, city, isp, channel_id, `state`, createtime, 
     updatetime
-  </sql>
-  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
-    select 
-    <include refid="Base_Column_List" />
-    from user
-    where id = #{id,jdbcType=BIGINT}
-  </select>
+    </sql>
+    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from user
+        where id = #{id,jdbcType=BIGINT}
+    </select>
     <select id="selectByUser" resultMap="BaseResultMap" parameterType="com.book.dao.cps.pojo.User">
 
         select id from user
-      <trim prefix="WHERE" prefixOverrides="AND | OR">
-        <if test="openid!=null and openid!=''">
-          and openid != #{openid}
-        </if>
-        <if test="mobile!=null and mobile!=''">
-          and mobile != #{mobile}
-        </if>
-        <if test="channel_id!=null and channel_id!=0">
-          and channel_id != #{channel_id}
-        </if>
-
+        <trim prefix="WHERE" prefixOverrides="AND | OR">
+            <if test="openid!=null and openid!=''">
+                and openid != #{openid}
+            </if>
+            <if test="mobile!=null and mobile!=''">
+                and mobile != #{mobile}
+            </if>
+            <if test="channel_id!=null and channel_id!=0">
+                and channel_id != #{channel_id}
+            </if>
 
-      </trim>
 
+        </trim>
 
 
     </select>
     <select id="selectByOpenId" resultMap="BaseResultMap">
-      SELECT * from user WHERE openid = #{openid}
+        SELECT *
+        from user
+        WHERE openid = #{openid}
+    </select>
+    <select id="selectListByPushMap" resultMap="BaseResultMap" parameterType="map">
+        SELECT * FROM user
+        <trim prefix="WHERE" prefixOverrides="AND | OR">
+            <if test="openid!=null and openid!=''">
+                and openid != #{openid}
+            </if>
+            <if test="mobile!=null and mobile!=''">
+                and mobile != #{mobile}
+            </if>
+            <if test="channel_id!=null and channel_id!=0">
+                and channel_id != #{channel_id}
+            </if>
+            <if test="sex!=null and sex!='-1'">
+                and sex != #{sex}
+            </if>
+            <if test="tag!=null and tag!='-1'">
+                and (
+                tag like CONCAT(#{tag}, ',%')
+                or tag like   CONCAT('%,',#{tag})
+                or tag like CONCAT('%,',#{tag}, ',%')
+                )
+            </if>
+            <if test="is_pay!=null and is_pay!='-1'">
+                and is_pay != #{is_pay}
+            </if>
+            <if test="kandian_max!=null and kandian_max!=''">
+                and kandian &lt;= #{kandian_max}
+            </if>
+            <if test="kandian_min!=null and kandian_min!=''">
+                and kandian &gt;= #{kandian_min}
+            </if>
+            <if test="subscribe_time!=null and subscribe_time!='-1'">
+                and subscribe_time &gt;=  #{subscribe_time}
+            </if>
+             and operate_time &lt; (UNIX_TIMESTAMP(NOW()) - 172800)
+
+        </trim>
+
     </select>
-  <select id="selectByUserId" resultMap="BaseResultMap">
-    SELECT * from user WHERE id = #{userId}
-  </select>
-  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
-    delete from user
-    where id = #{id,jdbcType=BIGINT}
-  </delete>
-  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.User" useGeneratedKeys="true">
-    insert into user (openid, unionid, visitor, 
-      nickname, sex, mobile, avatar, 
-      is_subscribe, subscription_extend, subscribe_time, 
-      book_category_ids, operate_time, is_pay, 
-      kandian, free_kandian, vip_endtime, 
-      register_ip, country, area, 
-      province, city, isp, 
-      channel_id, `state`, createtime, 
-      updatetime)
-    values (#{openid,jdbcType=VARCHAR}, #{unionid,jdbcType=VARCHAR}, #{visitor,jdbcType=VARCHAR}, 
-      #{nickname,jdbcType=VARCHAR}, #{sex,jdbcType=OTHER}, #{mobile,jdbcType=CHAR}, #{avatar,jdbcType=VARCHAR}, 
-      #{isSubscribe,jdbcType=OTHER}, #{subscriptionExtend,jdbcType=OTHER}, #{subscribeTime,jdbcType=INTEGER}, 
-      #{bookCategoryIds,jdbcType=VARCHAR}, #{operateTime,jdbcType=INTEGER}, #{isPay,jdbcType=OTHER}, 
-      #{kandian,jdbcType=INTEGER}, #{freeKandian,jdbcType=INTEGER}, #{vipEndtime,jdbcType=INTEGER}, 
-      #{registerIp,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR}, #{area,jdbcType=VARCHAR}, 
-      #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{isp,jdbcType=VARCHAR}, 
-      #{channelId,jdbcType=INTEGER}, #{state,jdbcType=OTHER}, #{createtime,jdbcType=INTEGER}, 
-      #{updatetime,jdbcType=INTEGER})
-  </insert>
-  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.User" useGeneratedKeys="true">
-    insert into user
-    <trim prefix="(" suffix=")" suffixOverrides=",">
-      <if test="openid != null">
-        openid,
-      </if>
-      <if test="unionid != null">
-        unionid,
-      </if>
-      <if test="visitor != null">
-        visitor,
-      </if>
-      <if test="nickname != null">
-        nickname,
-      </if>
-      <if test="sex != null">
-        sex,
-      </if>
-      <if test="mobile != null">
-        mobile,
-      </if>
-      <if test="avatar != null">
-        avatar,
-      </if>
-      <if test="isSubscribe != null">
-        is_subscribe,
-      </if>
-      <if test="subscriptionExtend != null">
-        subscription_extend,
-      </if>
-      <if test="subscribeTime != null">
-        subscribe_time,
-      </if>
-      <if test="bookCategoryIds != null">
-        book_category_ids,
-      </if>
-      <if test="operateTime != null">
-        operate_time,
-      </if>
-      <if test="isPay != null">
-        is_pay,
-      </if>
-      <if test="kandian != null">
-        kandian,
-      </if>
-      <if test="freeKandian != null">
-        free_kandian,
-      </if>
-      <if test="vipEndtime != null">
-        vip_endtime,
-      </if>
-      <if test="registerIp != null">
-        register_ip,
-      </if>
-      <if test="country != null">
-        country,
-      </if>
-      <if test="area != null">
-        area,
-      </if>
-      <if test="province != null">
-        province,
-      </if>
-      <if test="city != null">
-        city,
-      </if>
-      <if test="isp != null">
-        isp,
-      </if>
-      <if test="channelId != null">
-        channel_id,
-      </if>
-      <if test="state != null">
-        `state`,
-      </if>
-      <if test="createtime != null">
-        createtime,
-      </if>
-      <if test="updatetime != null">
-        updatetime,
-      </if>
-    </trim>
-    <trim prefix="values (" suffix=")" suffixOverrides=",">
-      <if test="openid != null">
-        #{openid,jdbcType=VARCHAR},
-      </if>
-      <if test="unionid != null">
-        #{unionid,jdbcType=VARCHAR},
-      </if>
-      <if test="visitor != null">
-        #{visitor,jdbcType=VARCHAR},
-      </if>
-      <if test="nickname != null">
-        #{nickname,jdbcType=VARCHAR},
-      </if>
-      <if test="sex != null">
-        #{sex,jdbcType=OTHER},
-      </if>
-      <if test="mobile != null">
-        #{mobile,jdbcType=CHAR},
-      </if>
-      <if test="avatar != null">
-        #{avatar,jdbcType=VARCHAR},
-      </if>
-      <if test="isSubscribe != null">
-        #{isSubscribe,jdbcType=OTHER},
-      </if>
-      <if test="subscriptionExtend != null">
-        #{subscriptionExtend,jdbcType=OTHER},
-      </if>
-      <if test="subscribeTime != null">
-        #{subscribeTime,jdbcType=INTEGER},
-      </if>
-      <if test="bookCategoryIds != null">
-        #{bookCategoryIds,jdbcType=VARCHAR},
-      </if>
-      <if test="operateTime != null">
-        #{operateTime,jdbcType=INTEGER},
-      </if>
-      <if test="isPay != null">
-        #{isPay,jdbcType=OTHER},
-      </if>
-      <if test="kandian != null">
-        #{kandian,jdbcType=INTEGER},
-      </if>
-      <if test="freeKandian != null">
-        #{freeKandian,jdbcType=INTEGER},
-      </if>
-      <if test="vipEndtime != null">
-        #{vipEndtime,jdbcType=INTEGER},
-      </if>
-      <if test="registerIp != null">
-        #{registerIp,jdbcType=VARCHAR},
-      </if>
-      <if test="country != null">
-        #{country,jdbcType=VARCHAR},
-      </if>
-      <if test="area != null">
-        #{area,jdbcType=VARCHAR},
-      </if>
-      <if test="province != null">
-        #{province,jdbcType=VARCHAR},
-      </if>
-      <if test="city != null">
-        #{city,jdbcType=VARCHAR},
-      </if>
-      <if test="isp != null">
-        #{isp,jdbcType=VARCHAR},
-      </if>
-      <if test="channelId != null">
-        #{channelId,jdbcType=INTEGER},
-      </if>
-      <if test="state != null">
-        #{state,jdbcType=OTHER},
-      </if>
-      <if test="createtime != null">
-        #{createtime,jdbcType=INTEGER},
-      </if>
-      <if test="updatetime != null">
-        #{updatetime,jdbcType=INTEGER},
-      </if>
-    </trim>
-  </insert>
-  <update id="updateByPrimaryKeySelective" parameterType="com.book.dao.cps.pojo.User">
-    update user
-    <set>
-      <if test="openid != null">
-        openid = #{openid,jdbcType=VARCHAR},
-      </if>
-      <if test="unionid != null">
-        unionid = #{unionid,jdbcType=VARCHAR},
-      </if>
-      <if test="visitor != null">
-        visitor = #{visitor,jdbcType=VARCHAR},
-      </if>
-      <if test="nickname != null">
-        nickname = #{nickname,jdbcType=VARCHAR},
-      </if>
-      <if test="sex != null">
-        sex = #{sex,jdbcType=OTHER},
-      </if>
-      <if test="mobile != null">
-        mobile = #{mobile,jdbcType=CHAR},
-      </if>
-      <if test="avatar != null">
-        avatar = #{avatar,jdbcType=VARCHAR},
-      </if>
-      <if test="isSubscribe != null">
-        is_subscribe = #{isSubscribe,jdbcType=OTHER},
-      </if>
-      <if test="subscriptionExtend != null">
-        subscription_extend = #{subscriptionExtend,jdbcType=OTHER},
-      </if>
-      <if test="subscribeTime != null">
-        subscribe_time = #{subscribeTime,jdbcType=INTEGER},
-      </if>
-      <if test="bookCategoryIds != null">
-        book_category_ids = #{bookCategoryIds,jdbcType=VARCHAR},
-      </if>
-      <if test="operateTime != null">
-        operate_time = #{operateTime,jdbcType=INTEGER},
-      </if>
-      <if test="isPay != null">
-        is_pay = #{isPay,jdbcType=OTHER},
-      </if>
-      <if test="kandian != null">
-        kandian = #{kandian,jdbcType=INTEGER},
-      </if>
-      <if test="freeKandian != null">
-        free_kandian = #{freeKandian,jdbcType=INTEGER},
-      </if>
-      <if test="vipEndtime != null">
-        vip_endtime = #{vipEndtime,jdbcType=INTEGER},
-      </if>
-      <if test="registerIp != null">
-        register_ip = #{registerIp,jdbcType=VARCHAR},
-      </if>
-      <if test="country != null">
-        country = #{country,jdbcType=VARCHAR},
-      </if>
-      <if test="area != null">
-        area = #{area,jdbcType=VARCHAR},
-      </if>
-      <if test="province != null">
-        province = #{province,jdbcType=VARCHAR},
-      </if>
-      <if test="city != null">
-        city = #{city,jdbcType=VARCHAR},
-      </if>
-      <if test="isp != null">
-        isp = #{isp,jdbcType=VARCHAR},
-      </if>
-      <if test="channelId != null">
-        channel_id = #{channelId,jdbcType=INTEGER},
-      </if>
-      <if test="state != null">
-        `state` = #{state,jdbcType=OTHER},
-      </if>
-      <if test="createtime != null">
-        createtime = #{createtime,jdbcType=INTEGER},
-      </if>
-      <if test="updatetime != null">
-        updatetime = #{updatetime,jdbcType=INTEGER},
-      </if>
-    </set>
-    where id = #{id,jdbcType=BIGINT}
-  </update>
-  <update id="updateByPrimaryKey" parameterType="com.book.dao.cps.pojo.User">
-    update user
-    set openid = #{openid,jdbcType=VARCHAR},
-      unionid = #{unionid,jdbcType=VARCHAR},
-      visitor = #{visitor,jdbcType=VARCHAR},
-      nickname = #{nickname,jdbcType=VARCHAR},
-      sex = #{sex,jdbcType=OTHER},
-      mobile = #{mobile,jdbcType=CHAR},
-      avatar = #{avatar,jdbcType=VARCHAR},
-      is_subscribe = #{isSubscribe,jdbcType=OTHER},
-      subscription_extend = #{subscriptionExtend,jdbcType=OTHER},
-      subscribe_time = #{subscribeTime,jdbcType=INTEGER},
-      book_category_ids = #{bookCategoryIds,jdbcType=VARCHAR},
-      operate_time = #{operateTime,jdbcType=INTEGER},
-      is_pay = #{isPay,jdbcType=OTHER},
-      kandian = #{kandian,jdbcType=INTEGER},
-      free_kandian = #{freeKandian,jdbcType=INTEGER},
-      vip_endtime = #{vipEndtime,jdbcType=INTEGER},
-      register_ip = #{registerIp,jdbcType=VARCHAR},
-      country = #{country,jdbcType=VARCHAR},
-      area = #{area,jdbcType=VARCHAR},
-      province = #{province,jdbcType=VARCHAR},
-      city = #{city,jdbcType=VARCHAR},
-      isp = #{isp,jdbcType=VARCHAR},
-      channel_id = #{channelId,jdbcType=INTEGER},
-      `state` = #{state,jdbcType=OTHER},
-      createtime = #{createtime,jdbcType=INTEGER},
-      updatetime = #{updatetime,jdbcType=INTEGER}
-    where id = #{id,jdbcType=BIGINT}
-  </update>
+
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+        delete
+        from user
+        where id = #{id,jdbcType=BIGINT}
+    </delete>
+    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.User"
+            useGeneratedKeys="true">
+        insert into user (openid, unionid, visitor,
+                          nickname, sex, mobile, avatar,
+                          is_subscribe, subscription_extend, subscribe_time,
+                          book_category_ids, operate_time, is_pay,
+                          kandian, free_kandian, vip_endtime,
+                          register_ip, country, area,
+                          province, city, isp,
+                          channel_id, `state`, createtime,
+                          updatetime)
+        values (#{openid,jdbcType=VARCHAR}, #{unionid,jdbcType=VARCHAR}, #{visitor,jdbcType=VARCHAR},
+                #{nickname,jdbcType=VARCHAR}, #{sex,jdbcType=OTHER}, #{mobile,jdbcType=CHAR},
+                #{avatar,jdbcType=VARCHAR},
+                #{isSubscribe,jdbcType=OTHER}, #{subscriptionExtend,jdbcType=OTHER}, #{subscribeTime,jdbcType=INTEGER},
+                #{bookCategoryIds,jdbcType=VARCHAR}, #{operateTime,jdbcType=INTEGER}, #{isPay,jdbcType=OTHER},
+                #{kandian,jdbcType=INTEGER}, #{freeKandian,jdbcType=INTEGER}, #{vipEndtime,jdbcType=INTEGER},
+                #{registerIp,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR}, #{area,jdbcType=VARCHAR},
+                #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{isp,jdbcType=VARCHAR},
+                #{channelId,jdbcType=INTEGER}, #{state,jdbcType=OTHER}, #{createtime,jdbcType=INTEGER},
+                #{updatetime,jdbcType=INTEGER})
+    </insert>
+    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.User"
+            useGeneratedKeys="true">
+        insert into user
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="openid != null">
+                openid,
+            </if>
+            <if test="unionid != null">
+                unionid,
+            </if>
+            <if test="visitor != null">
+                visitor,
+            </if>
+            <if test="nickname != null">
+                nickname,
+            </if>
+            <if test="sex != null">
+                sex,
+            </if>
+            <if test="mobile != null">
+                mobile,
+            </if>
+            <if test="avatar != null">
+                avatar,
+            </if>
+            <if test="isSubscribe != null">
+                is_subscribe,
+            </if>
+            <if test="subscriptionExtend != null">
+                subscription_extend,
+            </if>
+            <if test="subscribeTime != null">
+                subscribe_time,
+            </if>
+            <if test="bookCategoryIds != null">
+                book_category_ids,
+            </if>
+            <if test="operateTime != null">
+                operate_time,
+            </if>
+            <if test="isPay != null">
+                is_pay,
+            </if>
+            <if test="kandian != null">
+                kandian,
+            </if>
+            <if test="freeKandian != null">
+                free_kandian,
+            </if>
+            <if test="vipEndtime != null">
+                vip_endtime,
+            </if>
+            <if test="registerIp != null">
+                register_ip,
+            </if>
+            <if test="country != null">
+                country,
+            </if>
+            <if test="area != null">
+                area,
+            </if>
+            <if test="province != null">
+                province,
+            </if>
+            <if test="city != null">
+                city,
+            </if>
+            <if test="isp != null">
+                isp,
+            </if>
+            <if test="channelId != null">
+                channel_id,
+            </if>
+            <if test="state != null">
+                `state`,
+            </if>
+            <if test="createtime != null">
+                createtime,
+            </if>
+            <if test="updatetime != null">
+                updatetime,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="openid != null">
+                #{openid,jdbcType=VARCHAR},
+            </if>
+            <if test="unionid != null">
+                #{unionid,jdbcType=VARCHAR},
+            </if>
+            <if test="visitor != null">
+                #{visitor,jdbcType=VARCHAR},
+            </if>
+            <if test="nickname != null">
+                #{nickname,jdbcType=VARCHAR},
+            </if>
+            <if test="sex != null">
+                #{sex,jdbcType=OTHER},
+            </if>
+            <if test="mobile != null">
+                #{mobile,jdbcType=CHAR},
+            </if>
+            <if test="avatar != null">
+                #{avatar,jdbcType=VARCHAR},
+            </if>
+            <if test="isSubscribe != null">
+                #{isSubscribe,jdbcType=OTHER},
+            </if>
+            <if test="subscriptionExtend != null">
+                #{subscriptionExtend,jdbcType=OTHER},
+            </if>
+            <if test="subscribeTime != null">
+                #{subscribeTime,jdbcType=INTEGER},
+            </if>
+            <if test="bookCategoryIds != null">
+                #{bookCategoryIds,jdbcType=VARCHAR},
+            </if>
+            <if test="operateTime != null">
+                #{operateTime,jdbcType=INTEGER},
+            </if>
+            <if test="isPay != null">
+                #{isPay,jdbcType=OTHER},
+            </if>
+            <if test="kandian != null">
+                #{kandian,jdbcType=INTEGER},
+            </if>
+            <if test="freeKandian != null">
+                #{freeKandian,jdbcType=INTEGER},
+            </if>
+            <if test="vipEndtime != null">
+                #{vipEndtime,jdbcType=INTEGER},
+            </if>
+            <if test="registerIp != null">
+                #{registerIp,jdbcType=VARCHAR},
+            </if>
+            <if test="country != null">
+                #{country,jdbcType=VARCHAR},
+            </if>
+            <if test="area != null">
+                #{area,jdbcType=VARCHAR},
+            </if>
+            <if test="province != null">
+                #{province,jdbcType=VARCHAR},
+            </if>
+            <if test="city != null">
+                #{city,jdbcType=VARCHAR},
+            </if>
+            <if test="isp != null">
+                #{isp,jdbcType=VARCHAR},
+            </if>
+            <if test="channelId != null">
+                #{channelId,jdbcType=INTEGER},
+            </if>
+            <if test="state != null">
+                #{state,jdbcType=OTHER},
+            </if>
+            <if test="createtime != null">
+                #{createtime,jdbcType=INTEGER},
+            </if>
+            <if test="updatetime != null">
+                #{updatetime,jdbcType=INTEGER},
+            </if>
+        </trim>
+    </insert>
+    <update id="updateByPrimaryKeySelective" parameterType="com.book.dao.cps.pojo.User">
+        update user
+        <set>
+            <if test="openid != null">
+                openid = #{openid,jdbcType=VARCHAR},
+            </if>
+            <if test="unionid != null">
+                unionid = #{unionid,jdbcType=VARCHAR},
+            </if>
+            <if test="visitor != null">
+                visitor = #{visitor,jdbcType=VARCHAR},
+            </if>
+            <if test="nickname != null">
+                nickname = #{nickname,jdbcType=VARCHAR},
+            </if>
+            <if test="sex != null">
+                sex = #{sex,jdbcType=OTHER},
+            </if>
+            <if test="mobile != null">
+                mobile = #{mobile,jdbcType=CHAR},
+            </if>
+            <if test="avatar != null">
+                avatar = #{avatar,jdbcType=VARCHAR},
+            </if>
+            <if test="isSubscribe != null">
+                is_subscribe = #{isSubscribe,jdbcType=OTHER},
+            </if>
+            <if test="subscriptionExtend != null">
+                subscription_extend = #{subscriptionExtend,jdbcType=OTHER},
+            </if>
+            <if test="subscribeTime != null">
+                subscribe_time = #{subscribeTime,jdbcType=INTEGER},
+            </if>
+            <if test="bookCategoryIds != null">
+                book_category_ids = #{bookCategoryIds,jdbcType=VARCHAR},
+            </if>
+            <if test="operateTime != null">
+                operate_time = #{operateTime,jdbcType=INTEGER},
+            </if>
+            <if test="isPay != null">
+                is_pay = #{isPay,jdbcType=OTHER},
+            </if>
+            <if test="kandian != null">
+                kandian = #{kandian,jdbcType=INTEGER},
+            </if>
+            <if test="freeKandian != null">
+                free_kandian = #{freeKandian,jdbcType=INTEGER},
+            </if>
+            <if test="vipEndtime != null">
+                vip_endtime = #{vipEndtime,jdbcType=INTEGER},
+            </if>
+            <if test="registerIp != null">
+                register_ip = #{registerIp,jdbcType=VARCHAR},
+            </if>
+            <if test="country != null">
+                country = #{country,jdbcType=VARCHAR},
+            </if>
+            <if test="area != null">
+                area = #{area,jdbcType=VARCHAR},
+            </if>
+            <if test="province != null">
+                province = #{province,jdbcType=VARCHAR},
+            </if>
+            <if test="city != null">
+                city = #{city,jdbcType=VARCHAR},
+            </if>
+            <if test="isp != null">
+                isp = #{isp,jdbcType=VARCHAR},
+            </if>
+            <if test="channelId != null">
+                channel_id = #{channelId,jdbcType=INTEGER},
+            </if>
+            <if test="state != null">
+                `state` = #{state,jdbcType=OTHER},
+            </if>
+            <if test="createtime != null">
+                createtime = #{createtime,jdbcType=INTEGER},
+            </if>
+            <if test="updatetime != null">
+                updatetime = #{updatetime,jdbcType=INTEGER},
+            </if>
+        </set>
+        where id = #{id,jdbcType=BIGINT}
+    </update>
+    <update id="updateByPrimaryKey" parameterType="com.book.dao.cps.pojo.User">
+        update user
+        set openid              = #{openid,jdbcType=VARCHAR},
+            unionid             = #{unionid,jdbcType=VARCHAR},
+            visitor             = #{visitor,jdbcType=VARCHAR},
+            nickname            = #{nickname,jdbcType=VARCHAR},
+            sex                 = #{sex,jdbcType=OTHER},
+            mobile              = #{mobile,jdbcType=CHAR},
+            avatar              = #{avatar,jdbcType=VARCHAR},
+            is_subscribe        = #{isSubscribe,jdbcType=OTHER},
+            subscription_extend = #{subscriptionExtend,jdbcType=OTHER},
+            subscribe_time      = #{subscribeTime,jdbcType=INTEGER},
+            book_category_ids   = #{bookCategoryIds,jdbcType=VARCHAR},
+            operate_time        = #{operateTime,jdbcType=INTEGER},
+            is_pay              = #{isPay,jdbcType=OTHER},
+            kandian             = #{kandian,jdbcType=INTEGER},
+            free_kandian        = #{freeKandian,jdbcType=INTEGER},
+            vip_endtime         = #{vipEndtime,jdbcType=INTEGER},
+            register_ip         = #{registerIp,jdbcType=VARCHAR},
+            country             = #{country,jdbcType=VARCHAR},
+            area                = #{area,jdbcType=VARCHAR},
+            province            = #{province,jdbcType=VARCHAR},
+            city                = #{city,jdbcType=VARCHAR},
+            isp                 = #{isp,jdbcType=VARCHAR},
+            channel_id          = #{channelId,jdbcType=INTEGER},
+            `state`             = #{state,jdbcType=OTHER},
+            createtime          = #{createtime,jdbcType=INTEGER},
+            updatetime          = #{updatetime,jdbcType=INTEGER}
+        where id = #{id,jdbcType=BIGINT}
+    </update>
     <update id="updateUserKandian">
-      update user set kandian=#{kandian},free_kandian=#{freekandian},updatetime=#{updateTime}
-      where id=#{user.id} and kandian &gt;= 0 and free_kandian &gt;= 0
+        update user
+        set kandian=#{kandian},
+            free_kandian=#{freekandian},
+            updatetime=#{updateTime}
+        where id = #{user.id}
+          and kandian = #{user.kandian}
+          and free_kandian = #{user.freeKandian}
     </update>
 </mapper>

+ 3 - 1
book-push/src/main/java/com/book/push/Application.java

@@ -4,13 +4,15 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 
 /**
  * @author win7
  */
 @SpringBootApplication
-//@Slf4j
+@Slf4j
+@EnableScheduling
 @ComponentScan({"com.book.dao","com.book.push"})
 public class Application {
     public static void main(String[] args) {

+ 2 - 2
book-push/src/main/java/com/book/push/cons/SchemeCons.java

@@ -8,7 +8,7 @@ package com.book.push.cons;
  */
 
 public class SchemeCons {
-    public static final String SCHEME_HTTP_PREFIX = "http://";
-    public static final String SCHEME_HTTPS_PREFIX = "https://";
+    public static final String SCHEME_HTTP_PREFIX = "http";
+    public static final String SCHEME_HTTPS_PREFIX = "https";
     public static String default_scheme_prefix = SCHEME_HTTP_PREFIX;
 }

+ 9 - 3
book-push/src/main/java/com/book/push/cons/UrlCons.java

@@ -8,7 +8,13 @@ package com.book.push.cons;
  */
 
 public class UrlCons {
- public static final String OAUTH2_REDIRECT_URL_LOGIN = "%s/wx/redirect/{appid}/login";
- public static final String OAUTH2_REDIRECT_URL_SLIENT = "%s://%s.%s/wx/redirect/{appid}/slient";
- public static final String FRONT_URL = "%s://%s.%s/%s?channelId=%d/userId=%s";
+
+    public static final String OAUTH2_REDIRECT_URL_LOGIN = SchemeCons.default_scheme_prefix + "://" + "%s/wx/redirect/{appid}/login";
+    public static final String OAUTH2_REDIRECT_URL_SLIENT = SchemeCons.default_scheme_prefix + "://" + "%s.%s/wx/redirect/{appid}/slient";
+    public static final String FRONT_URL = SchemeCons.default_scheme_prefix + "://" + "%s.%s/%s?channelId=%d&userId=%s";
+    public static final String MODEL_BOOK = "book";
+
+    public static final String BOOK_URL = SchemeCons.default_scheme_prefix + "://" + "%s.%s/%s?channelId=%d&userId=%d&bookId=%s";
+
+
 }

+ 2 - 2
book-push/src/main/java/com/book/push/controller/WxRedirectController.java

@@ -123,7 +123,7 @@ public class WxRedirectController {
                     Integer platformId = defaultAdminConfig.getPlatformId();
                     String redirect_url = UrlCons.OAUTH2_REDIRECT_URL_SLIENT.replace("{appid}", defaultAdminConfig.getAppid());
                     Ophost menuHost = opHostService.selectById(defaultAdminConfig.getMenuophostId());
-                    redirect_url = String.format(redirect_url,SchemeCons.default_scheme_prefix,appid,menuHost.getHost());
+                    redirect_url = String.format(redirect_url,appid,menuHost.getHost());
 
                     wxOpenService = thirdPartService.getWxOpenServiceByPlatFormId(platformId);
                     String auto2Url = wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(defaultAdminConfig.getAppid()).getOAuth2Service()
@@ -213,7 +213,7 @@ public class WxRedirectController {
 
     private String getFrontUrl(String appid,Ophost ophost, String state, Integer userAdminId, String userId) {
         String host = ophost.getHost();
-        String frontUrl = String.format(UrlCons.FRONT_URL, SchemeCons.default_scheme_prefix,appid,host, state, userAdminId, userId);
+        String frontUrl = String.format(UrlCons.FRONT_URL,appid,host, state, userAdminId, userId);
         return frontUrl;
     }
 }

+ 41 - 27
book-push/src/main/java/com/book/push/handler/MenuHandler.java

@@ -16,14 +16,17 @@ import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage;
 import me.chanjar.weixin.mp.builder.kefu.NewsBuilder;
 import me.chanjar.weixin.open.api.WxOpenMpService;
 import me.chanjar.weixin.open.api.WxOpenService;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
 import org.springframework.stereotype.Component;
 
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import static me.chanjar.weixin.common.api.WxConsts.EventType;
 
@@ -52,16 +55,17 @@ public class MenuHandler extends AbstractHandler {
     private ManageCoverService manageCoverService;
     @Autowired
     private ConfigService configService;
+    @Autowired
+    private BookService bookService;
 
     @Autowired
     private SignMapper signMapper;
+
     @Override
     public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                     Map<String, Object> context, WxMpService weixinService,
                                     WxSessionManager sessionManager) {
-        String msg = String.format("type:%s, event:%s, key:%s",
-                wxMessage.getMsgType(), wxMessage.getEvent(),
-                wxMessage.getEventKey());
+
         if (EventType.VIEW.equals(wxMessage.getEvent())) {
             return null;
         }
@@ -69,13 +73,17 @@ public class MenuHandler extends AbstractHandler {
         User user = userService.selectByOpenId(wxMessage.getFromUser());
         Config config = configService.selectByName(SiteCons.SIGN_KANDIAN);
         int kandian = Integer.valueOf(config.getValue());
-
+        Integer channelId = user.getChannelId();
+        AdminConfig adminConfig = adminConfigService.selectByAdminId(channelId);
 
         Long id = user.getId();
         SignExample example = SignExample.newAndCreateCriteria().andUidEqualTo(id.intValue()).andCreatedateEqualTo(TimeUtil.getCurrentIntDate(TimeUtil.YYYYMMDD)).example();
         Sign sign = signMapper.selectOneByExample(example);
-        pushMessage(user,appid,sign!=null);
-        if (sign==null){
+        if ("1".equals(adminConfig.getSignTip())) {
+
+            pushMessage(user, adminConfig, appid, sign != null);
+        }
+        if (sign == null) {
             sign = new Sign();
             sign.setUid(id.intValue());
             sign.setCreatedate(TimeUtil.getCurrentIntDate(TimeUtil.YYYYMMDD));
@@ -84,73 +92,79 @@ public class MenuHandler extends AbstractHandler {
             signMapper.insert(sign);
 
 
-            addKandian(user,kandian);
+            addKandian(user, kandian);
         }
 
 
+        return msgAfterSing(appid, user.getOpenid());
 
 
+    }
 
+    private WxMpXmlOutMessage msgAfterSing(String appid, String openid) {
+        //todo 签到后回复
 
+        String msg = "<a href=\"weixin://bizmsgmenu?msgmenucontent=签到&msgmenuid=0\">点我签到</a>";
 
 
-        return WxMpXmlOutMessage.TEXT().content(msg)
-                .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
+        WxMpXmlOutTextMessage wxMpXmlOutTextMessage = WxMpXmlOutMessage.TEXT().content(msg)
+                .fromUser(appid).toUser(openid)
                 .build();
+       return wxMpXmlOutTextMessage;
+
     }
 
 
     /**
      * 添加看点
+     *
      * @param user
      * @param kandian
      */
     private void addKandian(User user, int kandian) {
+        //TODO
 
     }
 
 
     /**
      * 签到推送
+     *
      * @param user
-     * @param b 是否已经签到
+     * @param b    是否已经签到
      */
-    private void pushMessage(User user,String appid, boolean b) {
+    private void pushMessage(User user, AdminConfig adminConfig, String appid, boolean b) {
         Long bookId;
-        if (b){
+        if (b) {
             SignRecommand signRecommand = signedRecommendService.selectRandom(user.getSex().toString());
-             bookId = signRecommand.getBookId();
-        }else {
+            bookId = signRecommand.getBookId();
+        } else {
             SignRecommand signRecommand = signRecommendService.selectRandom(user.getSex().toString());
-             bookId = signRecommand.getBookId();
+            bookId = signRecommand.getBookId();
 
         }
         ManageTitle manageTitle = manageTitleService.selectRandom(user.getSex().toString());
         ManageCover manageCover = manageCoverService.selectRandom("1", user.getSex().toString());
-        WxMpKefuMessage.WxArticle  wxArticle = new  WxMpKefuMessage.WxArticle();
+        WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
         wxArticle.setTitle(manageTitle.getTitle());
         wxArticle.setPicUrl(manageCover.getImage());
-        wxArticle.setUrl(createUrl(bookId));
+        wxArticle.setUrl(createUrl(bookId, adminConfig, user));
         WxMpKefuMessage build = new NewsBuilder().toUser(user.getOpenid()).addArticle(wxArticle).build();
 
 
-        Integer channelId = user.getChannelId();
-        AdminConfig adminConfig = adminConfigService.selectByAdminId(channelId);
         Integer platformId = adminConfig.getPlatformId();
         WxOpenService wxOpenService = wxThirdPartService.getWxOpenServiceByPlatFormId(platformId);
         WxOpenMpService wxMpService = wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appid);
-        try {
-            wxMpService.getKefuService().sendKefuMessage(build);
-        } catch (WxErrorException e) {
-            e.printStackTrace();
+        long second = 10 * 60 * 60;
+        pushService.addWxKefuMessagePushTask(wxMpService, build, second, TimeUnit.SECONDS);
 
-            System.out.println("发送失败");
-        }
+        System.out.println("发送失败");
 
     }
 
-    private String createUrl(Long bookId) {
-        return "";
+    private String createUrl(Long bookId, AdminConfig adminConfig, User user) {
+
+        return bookService.createBookUrl(bookId, adminConfig, user);
 
     }
 

+ 17 - 0
book-push/src/main/java/com/book/push/service/dao/BookService.java

@@ -0,0 +1,17 @@
+package com.book.push.service.dao;
+
+import com.book.dao.cps.pojo.AdminConfig;
+import com.book.dao.cps.pojo.User;
+
+/**
+ * created in 2021/8/28
+ * Project: book-store
+ *
+ * @author win7
+ */
+
+public interface BookService {
+
+
+    String createBookUrl(Long bookId, AdminConfig adminConfig, User user);
+}

+ 3 - 0
book-push/src/main/java/com/book/push/service/dao/CustomService.java

@@ -2,6 +2,7 @@ package com.book.push.service.dao;
 
 
 import com.book.dao.cps.pojo.Custom;
+import com.book.push.service.push.vo.CustomMessage;
 
 import java.util.List;
 
@@ -15,5 +16,7 @@ import java.util.List;
 public interface CustomService {
 
      List<Custom> selectListBeforeSendTime();
+     List<Custom> selectListBetweenSendTime(Integer from,Integer to);
+    void update(Custom custom);
 
 }

+ 4 - 0
book-push/src/main/java/com/book/push/service/dao/UserService.java

@@ -5,6 +5,9 @@ import com.book.dao.cps.pojo.AdminConfig;
 import com.book.dao.cps.pojo.User;
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * created in 2021/8/17
  * Project: book-store
@@ -18,4 +21,5 @@ public interface UserService {
      User selectById(Long id);
      User createUserByWxUser(WxMpUser wxMpUser,int channel_id);
      AdminConfig selectAdminConfigByOpenid(String openid);
+     List<User>  selectListByPushMap(Map map);
 }

+ 27 - 0
book-push/src/main/java/com/book/push/service/dao/impl/BookServiceImpl.java

@@ -0,0 +1,27 @@
+package com.book.push.service.dao.impl;
+
+import com.book.dao.cps.pojo.AdminConfig;
+import com.book.dao.cps.pojo.User;
+import com.book.push.cons.UrlCons;
+import com.book.push.service.dao.BookService;
+import com.book.push.service.dao.OpHostService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * created in 2021/8/28
+ * Project: book-store
+ *
+ * @author win7
+ */
+@Service
+public class BookServiceImpl implements BookService {
+
+    @Autowired
+    private OpHostService opHostService;
+    @Override
+    public String createBookUrl(Long bookId, AdminConfig adminConfig, User user) {
+      return   String.format(UrlCons.BOOK_URL,adminConfig.getAppid(),opHostService.selectById(adminConfig.getOphostId()),UrlCons.MODEL_BOOK,
+                adminConfig.getAdminId(),user.getId(),String.valueOf(bookId));
+    }
+}

+ 11 - 0
book-push/src/main/java/com/book/push/service/dao/impl/CustomServiceImpl.java

@@ -23,4 +23,15 @@ public class CustomServiceImpl implements CustomService {
     public List<Custom> selectListBeforeSendTime() {
         return customMapper.selectListBeforeSendTime();
     }
+
+    @Override
+    public List<Custom> selectListBetweenSendTime(Integer from, Integer to) {
+
+        return customMapper.selectListBetweenSendTime(from,to);
+    }
+
+    @Override
+    public void update(Custom custom) {
+        customMapper.updateByPrimaryKey(custom);
+    }
 }

+ 9 - 0
book-push/src/main/java/com/book/push/service/dao/impl/UserServiceImpl.java

@@ -10,6 +10,9 @@ import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * created in 2021/8/17
  * Project: book-store
@@ -69,4 +72,10 @@ public class UserServiceImpl implements UserService {
         AdminConfig adminConfig = adminConfigService.selectByAdminId(channelId);
         return adminConfig;
     }
+
+    @Override
+    public List<User> selectListByPushMap(Map map) {
+
+        return userMapper.selectListByPushMap(map);
+    }
 }

+ 15 - 0
book-push/src/main/java/com/book/push/service/push/PushResultListener.java

@@ -0,0 +1,15 @@
+package com.book.push.service.push;
+
+import com.book.dao.cps.pojo.Custom;
+
+/**
+ * created in 2021/8/29
+ * Project: book-store
+ *
+ * @author win7
+ */
+
+public interface PushResultListener {
+    public void onComplete(Custom custom);
+
+}

+ 12 - 0
book-push/src/main/java/com/book/push/service/push/PushService.java

@@ -1,6 +1,11 @@
 package com.book.push.service.push;
 
 import com.book.push.service.push.vo.BookInfo;
+import com.book.push.service.push.vo.CustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import me.chanjar.weixin.open.api.WxOpenMpService;
+
+import java.util.concurrent.TimeUnit;
 
 /**
  * created in 2021/8/27
@@ -17,4 +22,11 @@ public interface PushService {
 
 
     void addBookPushTask(BookInfo bookInfo, long delay);
+
+
+    void addWxKefuMessagePushTask(WxOpenMpService wxMpService, WxMpKefuMessage wxMpKefuMessage, long delay);
+
+    void addWxKefuMessagePushTask(WxOpenMpService wxMpService, WxMpKefuMessage wxMpKefuMessage, long delay, TimeUnit timeUnit);
+
+    void addCustomMessagePushTask(WxOpenMpService wxMpService, CustomMessage customMessage, long delay, TimeUnit timeUnit);
 }

+ 57 - 0
book-push/src/main/java/com/book/push/service/push/impl/PushCustomMessageTask.java

@@ -0,0 +1,57 @@
+package com.book.push.service.push.impl;
+
+import com.book.dao.cps.pojo.Custom;
+import com.book.push.service.dao.CustomService;
+import com.book.push.service.push.DelayTask;
+import com.book.push.service.push.vo.CustomMessage;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import me.chanjar.weixin.open.api.WxOpenMpService;
+
+import java.util.List;
+
+/**
+ * created in 2021/8/29
+ * Project: book-store
+ *
+ * @author win7
+ */
+
+public class PushCustomMessageTask extends DelayTask<CustomMessage> {
+    private WxOpenMpService wxMpService;
+
+    public PushCustomMessageTask(CustomMessage entity, long timeout) {
+        super(entity, timeout);
+    }
+
+    public PushCustomMessageTask(WxOpenMpService wxMpService, CustomMessage entity, long timeout) {
+
+        super(entity, timeout);
+        this.wxMpService = wxMpService;
+    }
+
+    @Override
+    public void run() {
+        List<WxMpKefuMessage> messageList = entity.getMessageList();
+        int success = 0;
+        int fail = 0;
+        for (int i = 0; i < messageList.size(); i++) {
+            WxMpKefuMessage wxMpKefuMessage = messageList.get(i);
+            try {
+                wxMpService.getKefuService().sendKefuMessage(wxMpKefuMessage);
+                success++;
+            } catch (WxErrorException e) {
+                fail++;
+                System.out.println("客服笑死发送失败:" + wxMpKefuMessage);
+                e.printStackTrace();
+            }
+        }
+        System.out.println("发送成功:" + success + ",失败::" + fail);
+        Custom custom = entity.getCustom();
+        custom.setSuccessNum(success);
+        custom.setFailNum(fail);
+        CustomService customService = entity.getCustomService();
+        customService.update(custom);
+
+    }
+}

+ 38 - 0
book-push/src/main/java/com/book/push/service/push/impl/PushMessageTask.java

@@ -0,0 +1,38 @@
+package com.book.push.service.push.impl;
+
+import com.book.push.service.push.DelayTask;
+import com.book.push.service.push.vo.BookInfo;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import me.chanjar.weixin.open.api.WxOpenMpService;
+
+/**
+ * created in 2021/8/28
+ * Project: book-store
+ *
+ * @author win7
+ */
+
+public class PushMessageTask extends DelayTask<WxMpKefuMessage> {
+    private WxOpenMpService wxMpService;
+
+    public PushMessageTask(WxMpKefuMessage entity, long timeout) {
+        super(entity, timeout);
+    }
+    public PushMessageTask(WxOpenMpService wxMpService,WxMpKefuMessage entity, long timeout) {
+
+        super(entity, timeout);
+        this.wxMpService = wxMpService;
+    }
+
+    @Override
+    public void run() {
+        WxMpKefuMessage wxMpKefuMessage = this.entity;
+        try {
+            wxMpService.getKefuService().sendKefuMessage(wxMpKefuMessage);
+        } catch (WxErrorException e) {
+            System.out.println("客服笑死发送失败:"+ wxMpKefuMessage);
+            e.printStackTrace();
+        }
+    }
+}

+ 18 - 1
book-push/src/main/java/com/book/push/service/push/impl/PushServiceImpl.java

@@ -3,6 +3,9 @@ package com.book.push.service.push.impl;
 import com.book.push.service.push.DelayTask;
 import com.book.push.service.push.PushService;
 import com.book.push.service.push.vo.BookInfo;
+import com.book.push.service.push.vo.CustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import me.chanjar.weixin.open.api.WxOpenMpService;
 import org.springframework.stereotype.Service;
 
 import java.util.concurrent.*;
@@ -14,7 +17,7 @@ import java.util.concurrent.*;
  * @author win7
  */
 @Service
-public abstract class PushServiceImpl implements PushService {
+public  class PushServiceImpl implements PushService {
 
     /**
      * 核心线程数
@@ -92,5 +95,19 @@ public abstract class PushServiceImpl implements PushService {
 
     }
 
+    @Override
+    public void addWxKefuMessagePushTask(WxOpenMpService wxMpService, WxMpKefuMessage wxMpKefuMessage, long delay) {
+        queue.put(new PushMessageTask(wxMpService,wxMpKefuMessage,delay));
+    }
+    @Override
+    public void addWxKefuMessagePushTask(WxOpenMpService wxMpService, WxMpKefuMessage wxMpKefuMessage, long delay, TimeUnit timeUnit) {
+        long nanoTime =  TimeUnit.NANOSECONDS.convert(delay, timeUnit);
+        queue.put(new PushMessageTask(wxMpService,wxMpKefuMessage,nanoTime));
+    }
 
+    @Override
+    public void addCustomMessagePushTask(WxOpenMpService wxMpService, CustomMessage customMessage, long delay, TimeUnit timeUnit) {
+        long nanoTime =  TimeUnit.NANOSECONDS.convert(delay, timeUnit);
+        queue.put(new PushCustomMessageTask(wxMpService,customMessage,nanoTime));
+    }
 }

+ 21 - 0
book-push/src/main/java/com/book/push/service/push/vo/CustomMessage.java

@@ -0,0 +1,21 @@
+package com.book.push.service.push.vo;
+
+import com.book.dao.cps.pojo.Custom;
+import com.book.push.service.dao.CustomService;
+import lombok.Data;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+
+import java.util.List;
+
+/**
+ * created in 2021/8/29
+ * Project: book-store
+ *
+ * @author win7
+ */
+@Data
+public class CustomMessage {
+    private CustomService customService;
+    private Custom custom;
+    private List<WxMpKefuMessage> messageList;
+}

+ 134 - 0
book-push/src/main/java/com/book/push/task/KefuTask.java

@@ -1,5 +1,30 @@
 package com.book.push.task;
 
+import com.book.dao.cps.pojo.AdminConfig;
+import com.book.dao.cps.pojo.Custom;
+import com.book.dao.cps.pojo.User;
+import com.book.dao.utils.DateUtils;
+import com.book.push.service.dao.AdminConfigService;
+import com.book.push.service.dao.CustomService;
+import com.book.push.service.dao.UserService;
+import com.book.push.service.push.PushService;
+import com.book.push.service.push.vo.CustomMessage;
+import com.book.push.service.wx.WxThirdPartService;
+import com.book.push.utils.JsonUtils;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import me.chanjar.weixin.mp.builder.kefu.NewsBuilder;
+import me.chanjar.weixin.open.api.WxOpenMpService;
+import me.chanjar.weixin.open.api.WxOpenService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
 /**
  * created in 2021/8/17
  * Project: book-store
@@ -8,5 +33,114 @@ package com.book.push.task;
  * @author win7
  */
 
+@Component
 public class KefuTask {
+    @Autowired
+    private CustomService customService;
+    @Autowired
+    private AdminConfigService adminConfigService;
+    @Autowired
+    private WxThirdPartService wxThirdPartService;
+    @Autowired
+    private UserService userService;
+    @Autowired
+    private PushService pushService;
+    @Scheduled(fixedRate = 1000 * 60 * 10)
+    public void run() {
+        Integer now = DateUtils.getNow();
+        Integer to = now + (1000 * 60 * 10);
+        List<Custom> customs = customService.selectListBetweenSendTime(now, to);
+        for (Custom custom : customs) {
+            Integer sendtime = custom.getSendtime();
+            Integer delay = sendtime - DateUtils.getNow();
+            Integer adminId = custom.getAdminId();
+            AdminConfig adminConfig = adminConfigService.selectByAdminId(adminId);
+            String appid = adminConfig.getAppid();
+            Integer platformId = adminConfig.getPlatformId();
+            String userJsonStr = custom.getUserJson().toString();
+            userJsonStr = userJsonStr.replace("\\","").substring(1,userJsonStr.length()-1);
+            Custom.UserJson userJson = JsonUtils.getObject(userJsonStr, Custom.UserJson.class);
+            List<User> userList = getListByjson(userJson, adminId);
+            String messageJson = custom.getMessageJson().toString().replace("\\","");
+            messageJson = messageJson.replace("\\","").substring(1,messageJson.length()-1);
+
+            List<Custom.MessageJson> list = JsonUtils.getList(messageJson, Custom.MessageJson.class);
+
+            List<WxMpKefuMessage> messageList = new ArrayList<>();
+            for (User user:userList){
+                NewsBuilder newsBuilder = new NewsBuilder().toUser(user.getOpenid());
+                for (Custom.MessageJson  message:list){
+                    WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
+                    wxArticle.setTitle(message.getTitle());
+                    wxArticle.setPicUrl(message.getImage());
+                    wxArticle.setUrl(message.getUrl());
+                    newsBuilder.addArticle(wxArticle);
+
+                }
+                WxMpKefuMessage kefuMessage = newsBuilder.build();
+                messageList.add(kefuMessage);
+            }
+            custom.setSendNum(messageList.size());
+            WxOpenService wxOpenService = wxThirdPartService.getWxOpenServiceByPlatFormId(platformId);
+            WxOpenMpService wxMpService = wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appid);
+            CustomMessage customMessage = new CustomMessage();
+            customMessage.setCustom(custom);
+            customMessage.setMessageList(messageList);
+            customMessage.setCustomService(customService);
+
+            pushService.addCustomMessagePushTask(wxMpService, customMessage, delay, TimeUnit.SECONDS);
+
+
+        }
+    }
+
+    private List<User> getListByjson(Custom.UserJson userJson, Integer channelId) {
+        // "{\"sex\":-1,\"tag\":-1,\"consume\":-1,\"kandian\":-1,\"subscribe_time\":-1,\"all\":\"0\"}"
+//        "{\"sex\":2,\"mobile_system\":2,\"tag\":8,\"consume\":4,\"kandian\":2,\"subscribe_time\":7,\"all\":\"0\"}"
+
+        Map map = new HashMap<>();
+        map.put("channel_id", channelId);
+        if (!"1".equals(userJson.getAll())) {
+            if (userJson.getKandian() == 1) {
+                map.put("kandian_max", "500");
+            } else if (userJson.getKandian() == 2) {
+                map.put("kandian_max", "2000");
+            } else if (userJson.getKandian() == 3) {
+                map.put("kandian_min", "2000");
+            }
+
+            if (userJson.getSex() != -1) {
+                map.put("sex", userJson.getSex());
+            }
+            if (userJson.getConsume() == 1) {
+                map.put("is_pay", "0");
+            } else if (userJson.getConsume() == 4) {
+                map.put("is_pay", "1");
+            }
+            if (userJson.getTag() != -1) {
+                map.put("tag", userJson.getTag());
+            }
+            if (userJson.getSubscribe_time() != -1) {
+                int subscribeTime = -1;
+                if (userJson.getSubscribe_time() == 6) {
+                    subscribeTime = DateUtils.getNow() - 12 * 60 * 60;
+                } else if (userJson.getSubscribe_time() == 7) {
+                    subscribeTime = DateUtils.getNow() - 24 * 60 * 60;
+                } else if (userJson.getSubscribe_time() == 8) {
+                    subscribeTime = DateUtils.getNow() - 48 * 60 * 60;
+                } else if (userJson.getSubscribe_time() == 9) {
+                    subscribeTime = DateUtils.getNow() - 7 * 24 * 60 * 60;
+                } else if (userJson.getSubscribe_time() == 10) {
+                    subscribeTime = DateUtils.getNow() - 15 * 24 * 60 * 60;
+                }
+                map.put("subscribe_time", subscribeTime);
+            }
+
+        }
+        List<User> users = userService.selectListByPushMap(map);
+        return users;
+
+    }
+
+
 }

+ 84 - 0
book-push/src/main/java/com/book/push/utils/JsonUtils.java

@@ -1,6 +1,12 @@
 package com.book.push.utils;
 
 import com.alibaba.fastjson.JSON;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * created in 2021/8/25
@@ -10,7 +16,85 @@ import com.alibaba.fastjson.JSON;
  */
 
 public class JsonUtils {
+    private static final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
+
+    public JsonUtils() {
+    }
+
+    /**
+     * 转换为json字符串
+     *
+     * @param object 对象
+     * @return {@link String}
+     */
+    public static String toJsonStr(Object object) {
+        return gson.toJson(object);
+    }
+
+
+    /**
+     * 将json字符串 转换为 普通类
+     *
+     * @param jsonStr json str
+     * @param clazz   clazz
+     * @return {@link T}
+     */
+    public static <T> T getObject(String jsonStr, Class<T> clazz) {
+        return gson.fromJson(jsonStr, clazz);
+    }
+
+    /**
+     * 支持泛型等复杂类型
+     * new TypeToken<Result<List<Integer>>>(){}
+     * new TypeToken<List<Map<String, T>>>() {}
+     *
+     * @param jsonString json字符串
+     * @param typeToken  令牌类型
+     * @return {@link T}
+     */
+    public static <T> T getObject(String jsonString, TypeToken typeToken) {
+
+        return gson.fromJson(jsonString, typeToken.getType());
+    }
+
+    /**
+     * 转为数组
+     *
+     * @param jsonString
+     * @param tClass
+     * @param <T>
+     * @return
+     */
+    public static <T> T[] getArray(String jsonString, Class<T> tClass) {
+        return gson.fromJson(jsonString, TypeToken.getArray(tClass).getType());
+    }
+
+    /**
+     * 转为list
+     *
+     * @param jsonString
+     * @param tClass
+     * @param <T>
+     * @return
+     */
+    public static <T> List<T> getList(String jsonString, Class<T> tClass) {
+        return gson.fromJson(jsonString, new TypeToken<List<T>>() {
+        }.getType());
+    }
+
+    /**
+     * json字符串转成map的
+     *
+     * @param gsonString
+     * @return
+     */
+    public static <T> Map<String, T> getMap(String gsonString) {
+        return gson.fromJson(gsonString, new TypeToken<Map<String, T>>() {
+        }.getType());
+    }
+
     public static String toJsonString(Object object) {
         return JSON.toJSONString(object);
     }
+
 }