Forráskód Böngészése

完善阅读接口

tianyunperfect 3 éve
szülő
commit
84a783551b

+ 1 - 0
book-dao/src/main/java/com/book/dao/VO/BookContentVO.java

@@ -7,4 +7,5 @@ public class BookContentVO {
     Long userId;
     Long bookId;
     Integer contentId;
+    String contentName;
 }

+ 0 - 19
book-dao/src/main/java/com/book/dao/config/BaseConfig.java

@@ -1,19 +0,0 @@
-package com.book.dao.config;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-
-/**
- * created in 2021/8/22
- * Project: book-store
- *
- * @author win7
- */
-
-public class BaseConfig {
- @Bean
- @ConfigurationProperties(prefix = "mybatis.configuration")
- public org.apache.ibatis.session.Configuration configuration(){
-  return new org.apache.ibatis.session.Configuration();
- }
-}

+ 50 - 53
book-dao/src/main/java/com/book/dao/config/CpsDataSourceConfig.java

@@ -1,53 +1,50 @@
-package com.book.dao.config;
-
-
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.mybatis.spring.SqlSessionFactoryBean;
-import org.mybatis.spring.SqlSessionTemplate;
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.jdbc.DataSourceBuilder;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-
-import javax.sql.DataSource;
-
-@Configuration
-@MapperScan(basePackages = "com.book.dao.cps.mapper", sqlSessionTemplateRef = "cpsSqlSessionTemplate")
-public class CpsDataSourceConfig extends BaseConfig{
-
-
-
-    @Bean(name = "cpsDataSource")
-    @ConfigurationProperties(prefix = "spring.datasource.cps")
-    @Primary
-    public DataSource statementDataSource() {
-        return DataSourceBuilder.create().build();
-    }
-
-    @Bean(name = "cpsSqlSessionFactory")
-    @Primary
-    public SqlSessionFactory statementSqlSessionFactory(@Qualifier("cpsDataSource") DataSource dataSource,org.apache.ibatis.session.Configuration configuration) throws Exception {
-        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
-        bean.setDataSource(dataSource);
-        bean.setConfiguration(configuration);
-        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/cps/*.xml"));
-        return bean.getObject();
-    }
-
-    @Bean(name = "cpsTransactionManager")
-    @Primary
-    public DataSourceTransactionManager statementTransactionManager(@Qualifier("cpsDataSource") DataSource dataSource) {
-        return new DataSourceTransactionManager(dataSource);
-    }
-
-    @Bean(name = "cpsSqlSessionTemplate")
-    @Primary
-    public SqlSessionTemplate statementSqlSessionTemplate(@Qualifier("cpsSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
-        return new SqlSessionTemplate(sqlSessionFactory);
-    }
-}
+package com.book.dao.config;
+
+
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+
+import javax.sql.DataSource;
+
+@Configuration
+@MapperScan(basePackages = "com.book.dao.cps.mapper", sqlSessionTemplateRef = "cpsSqlSessionTemplate")
+public class CpsDataSourceConfig{
+
+    @Bean(name = "cpsDataSource")
+    @ConfigurationProperties(prefix = "spring.datasource.cps")
+    @Primary
+    public DataSource statementDataSource() {
+        return DataSourceBuilder.create().build();
+    }
+
+    @Bean(name = "cpsSqlSessionFactory")
+    @Primary
+    public SqlSessionFactory statementSqlSessionFactory(@Qualifier("cpsDataSource") DataSource dataSource) throws Exception {
+        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
+        bean.setDataSource(dataSource);
+        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/cps/*.xml"));
+        return bean.getObject();
+    }
+
+    @Bean(name = "cpsTransactionManager")
+    @Primary
+    public DataSourceTransactionManager statementTransactionManager(@Qualifier("cpsDataSource") DataSource dataSource) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+
+    @Bean(name = "cpsSqlSessionTemplate")
+    @Primary
+    public SqlSessionTemplate statementSqlSessionTemplate(@Qualifier("cpsSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
+        return new SqlSessionTemplate(sqlSessionFactory);
+    }
+}

+ 1 - 2
book-dao/src/main/java/com/book/dao/config/CpsshardDataSourceConfig.java

@@ -25,9 +25,8 @@ public class CpsshardDataSourceConfig {
     }
 
     @Bean(name = "cpsshardSqlSessionFactory")
-    public SqlSessionFactory cpsshardSqlSessionFactory(@Qualifier("cpsshardDataSource") DataSource dataSource,org.apache.ibatis.session.Configuration configuration) throws Exception {
+    public SqlSessionFactory cpsshardSqlSessionFactory(@Qualifier("cpsshardDataSource") DataSource dataSource) throws Exception {
         SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
-        bean.setConfiguration(configuration);
         bean.setDataSource(dataSource);
          bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/cpsshard/*.xml"));
        return bean.getObject();

+ 1 - 2
book-dao/src/main/java/com/book/dao/config/PolarDataSourceConfig.java

@@ -26,10 +26,9 @@ public class PolarDataSourceConfig {
     }
 
     @Bean(name = "polarSqlSessionFactory")
-    public SqlSessionFactory polarSqlSessionFactory(@Qualifier("polarDataSource") DataSource dataSource,org.apache.ibatis.session.Configuration configuration) throws Exception {
+    public SqlSessionFactory polarSqlSessionFactory(@Qualifier("polarDataSource") DataSource dataSource) throws Exception {
         SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
         bean.setDataSource(dataSource);
-        bean.setConfiguration(configuration);
          bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/polar/*.xml"));
        return bean.getObject();
     }

+ 26 - 24
book-dao/src/main/java/com/book/dao/cps/mapper/UserMapper.java

@@ -1,25 +1,27 @@
-package com.book.dao.cps.mapper;
-
-import com.book.dao.cps.pojo.User;
-import org.apache.ibatis.annotations.Param;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public interface UserMapper {
-
-    int deleteByPrimaryKey(@Param("id") Long id);
-
-    int insert(User record);
-
-    int insertSelective(User record);
-
-    User selectByPrimaryKey(@Param("id")Long id);
-
-    int updateByPrimaryKeySelective(User record);
-
-    int updateByPrimaryKey(User record);
-
-    User selectByUser(User user);
-
-    User selectByOpenId(@Param("openid") String openid);
+package com.book.dao.cps.mapper;
+
+import com.book.dao.cps.pojo.User;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface UserMapper {
+
+    int deleteByPrimaryKey(@Param("id") Long id);
+
+    int insert(User record);
+
+    int insertSelective(User record);
+
+    User selectByPrimaryKey(@Param("id") Long id);
+
+    int updateByPrimaryKeySelective(User record);
+
+    int updateByPrimaryKey(User record);
+
+    User selectByUser(User user);
+
+    User selectByOpenId(@Param("openid") String openid);
+
+    int updateUserKandian(@Param("user") User user, @Param("kandian") int kandian, @Param("freekandian") int freekandian, @Param("updateTime") int updateTime);
 }

+ 372 - 368
book-dao/src/main/resources/mapper/cps/UserMapper.xml

@@ -1,369 +1,373 @@
-<?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, 
-    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>
-    <select id="selectByUser" resultType="com.book.dao.cps.pojo.User" 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>
-
-
-
-    </select>
-    <select id="selectByOpenId" resultType="com.book.dao.cps.pojo.User">
-      SELECT * from user WHERE openid = #{openid}
-    </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>
+<?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, 
+    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>
+    <select id="selectByUser" resultType="com.book.dao.cps.pojo.User" 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>
+
+
+
+    </select>
+    <select id="selectByOpenId" resultType="com.book.dao.cps.pojo.User">
+      SELECT * from user WHERE openid = #{openid}
+    </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>
+    <update id="updateUserKandian">
+      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>

+ 0 - 57
book-server/src/main/java/com/book/server/aspect/TxAspect.java

@@ -1,57 +0,0 @@
-package com.book.server.aspect;
-
-import org.aspectj.lang.annotation.Aspect;
-import org.springframework.aop.Advisor;
-import org.springframework.aop.aspectj.AspectJExpressionPointcut;
-import org.springframework.aop.support.DefaultPointcutAdvisor;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.transaction.PlatformTransactionManager;
-import org.springframework.transaction.TransactionDefinition;
-import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
-import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource;
-import org.springframework.transaction.interceptor.TransactionInterceptor;
-
-@Aspect
-@Configuration
-public class TxAspect {
-    private static final String AOP_POINTCUT_EXPRESSION = "execution(* com.book.server.service.*.*(..))";
-
-    @Autowired
-    private PlatformTransactionManager transactionManager;
-
-    @Bean
-    public TransactionInterceptor txAdvice() {
-
-        DefaultTransactionAttribute txAttr_REQUIRED = new DefaultTransactionAttribute();
-        txAttr_REQUIRED.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
-
-        DefaultTransactionAttribute txAttr_REQUIRED_READONLY = new DefaultTransactionAttribute();
-        txAttr_REQUIRED_READONLY.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
-        txAttr_REQUIRED_READONLY.setReadOnly(true);
-
-        NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
-
-        source.addTransactionalMethod("save*", txAttr_REQUIRED);
-        source.addTransactionalMethod("delete*", txAttr_REQUIRED);
-        source.addTransactionalMethod("update*", txAttr_REQUIRED);
-        source.addTransactionalMethod("exec*", txAttr_REQUIRED);
-        source.addTransactionalMethod("set*", txAttr_REQUIRED);
-        source.addTransactionalMethod("get*", txAttr_REQUIRED_READONLY);
-        source.addTransactionalMethod("query*", txAttr_REQUIRED_READONLY);
-        source.addTransactionalMethod("find*", txAttr_REQUIRED_READONLY);
-        source.addTransactionalMethod("list*", txAttr_REQUIRED_READONLY);
-        source.addTransactionalMethod("count*", txAttr_REQUIRED_READONLY);
-        source.addTransactionalMethod("is*", txAttr_REQUIRED_READONLY);
-
-        return new TransactionInterceptor(transactionManager, source);
-    }
-
-    @Bean
-    public Advisor txAdviceAdvisor() {
-        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
-        pointcut.setExpression(AOP_POINTCUT_EXPRESSION);
-        return new DefaultPointcutAdvisor(pointcut, txAdvice());
-    }
-}

+ 0 - 1
book-server/src/main/java/com/book/server/common/util/DateUtils.java

@@ -115,6 +115,5 @@ public class DateUtils {
 
     public static void main(String[] args) {
         System.out.println(DateUtils.getNowSecond());
-        System.out.println(DateUtils.get3DayAgo());
     }
 }

+ 120 - 13
book-server/src/main/java/com/book/server/service/impl/BookServiceImpl.java

@@ -3,6 +3,7 @@ package com.book.server.service.impl;
 
 import com.book.dao.cps.mapper.*;
 import com.book.dao.cps.pojo.*;
+import com.book.dao.cpsshard.entity.Consume;
 import com.book.dao.cpsshard.entity.Recharge;
 import com.book.dao.cpsshard.entity.UserRecentlyRead;
 import com.book.dao.cpsshard.mapper.ConsumeMapper;
@@ -28,9 +29,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.time.LocalDate;
-import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -296,6 +296,7 @@ public class BookServiceImpl implements BookService {
     @Autowired
     private RechargeMapper rechargeMapper;
 
+    @Transactional
     @Override
     public Result<BookContent> getContentByContentId(BookContentVO bookContentVO) {
         BookContent content = null;
@@ -321,31 +322,48 @@ public class BookServiceImpl implements BookService {
                         .andRemainFreeKandianGreaterThan(0)
                         .example();
                 example.orderBy(Recharge.Column.freeEndtime.desc());
-                List<Recharge> recharges = rechargeMapper.selectByExample(example);
+                List<Recharge> freeRecharges = rechargeMapper.selectByExample(example);
                 Integer freeCount = 0;
-                if (recharges != null) {
-                    freeCount = recharges.stream().mapToInt(x -> x.getFreeKandian()).sum();
+                if (freeRecharges != null) {
+                    freeCount = freeRecharges.stream().mapToInt(x -> x.getFreeKandian()).sum();
                 }
                 //免费是否足够
                 if (freeCount > book.getPrice()) {
-                    //扣除一部分免费的 TODO
+                    //扣除一部分免费的
+                    int left = book.getPrice();
+                    for (Recharge recharge : freeRecharges) {
+                        if (left <= recharge.getRemainFreeKandian()) {
+                            subtractFreeRecharge(left, recharge);
+                            break;
+                        } else {
+                            subtractFreeRecharge(recharge.getRemainFreeKandian(), recharge);
+                            left -= recharge.getRemainFreeKandian();
+                        }
+                    }
+                    // 记录到消费表
+                    addConsumer(bookContentVO, book, left, 0);
+                    // 更新免费看点到 user
+                    userMapper.updateUserKandian(user, user.getKandian(), freeCount - book.getPrice(), DateUtils.getNow());
 
                 } else if (user.getKandian() + freeCount > book.getPrice()) { //免费+充值足够
                     Integer left = user.getKandian() + freeCount;
                     if (freeCount != 0) {
-                        left = left - freeCount;
-                        //扣除所有免费 TODO
-
+                        //扣除所有免费
+                        for (Recharge recharge : freeRecharges) {
+                            subtractFreeRecharge(recharge.getRemainFreeKandian(), recharge);
+                        }
                     }
-                    //扣除充值的 TODO
-
+                    //扣除充值的
+                    int kandian = user.getKandian() - (book.getPrice() - freeCount);
 
+                    // 记录到消费表
+                    addConsumer(bookContentVO, book, freeCount, book.getPrice() - freeCount);
+                    // 更新到 user
+                    userMapper.updateUserKandian(user, kandian, 0, DateUtils.getNow());
 
                 } else {
                     return Result.failure(ResultCode.NOMONEY);
                 }
-
-
             }
 
         }
@@ -355,9 +373,98 @@ public class BookServiceImpl implements BookService {
         } else {
             content = getBookContentFromRemote(bookContentVO);
         }
+        // 添加到阅读记录
+        if (content != null) {
+            //之前是否读过
+            UserRecentlyRead userRecentlyRead = userRecentlyReadMapper.selectOneByExample(UserRecentlyReadExample.newAndCreateCriteria()
+                    .andUserIdEqualTo(bookContentVO.getUserId())
+                    .andBookIdEqualTo(bookContentVO.getBookId())
+                    .example());
+            if (userRecentlyRead == null) {
+                userRecentlyReadMapper.insert(UserRecentlyRead.builder()
+                        .userId(bookContentVO.getUserId())
+                        .bookId(book.getId())
+                        .chapterId(Long.valueOf(bookContentVO.getContentId()))
+                        .chapterName(bookContentVO.getContentName())
+                        .createtime(DateUtils.getNow())
+                        .updatetime(DateUtils.getNow())
+                        .bookShelfAdd((byte)0)
+                        .bookShelfFlag((byte)0)
+                        .build());
+            } else {
+                userRecentlyRead.setChapterId(Long.valueOf(bookContentVO.getContentId()));
+                userRecentlyRead.setChapterName(bookContentVO.getContentName());
+                userRecentlyRead.setUpdatetime(DateUtils.getNow());
+                userRecentlyReadMapper.updateByPrimaryKeySelective(userRecentlyRead,
+                        UserRecentlyRead.Column.chapterId,
+                        UserRecentlyRead.Column.chapterName,
+                        UserRecentlyRead.Column.updatetime
+                );
+            }
+
+        }
         return Result.byObject(content);
     }
 
+    /**
+     * 消费记录
+     *
+     * @param bookContentVO
+     * @param book
+     * @param freeKandian
+     * @param kandian
+     */
+    @Transactional
+    void addConsumer(BookContentVO bookContentVO, Book book, int freeKandian, int kandian) {
+        consumeMapper.insert(Consume.builder()
+                .userId(bookContentVO.getUserId())
+                .type("1") // 订购章节
+                .bookId(book.getId())
+                .bookName(book.getName())
+                .chapterId(Long.valueOf(bookContentVO.getContentId()))
+                .chapterName(bookContentVO.getContentName())
+                .ddKandian(kandian)
+                .ddFreeKandian(freeKandian)
+                .createtime(DateUtils.getNow())
+                .updatetime(DateUtils.getNow())
+                .businessLine((byte) 0)
+                .build());
+    }
+
+    /**
+     * 减去多少免费看点
+     *
+     * @param reduceNum 消费多少免费看点
+     * @param recharge
+     */
+    @Transactional
+    void subtractFreeRecharge(int reduceNum, Recharge recharge) {
+        rechargeMapper.updateByExampleSelective(
+                Recharge.builder().remainFreeKandian(recharge.getRemainFreeKandian() - reduceNum).build(),
+                RechargeExample.newAndCreateCriteria()
+                        .andIdEqualTo(recharge.getId())
+                        .andRemainFreeKandianEqualTo(recharge.getRemainFreeKandian()).example(),
+                Recharge.Column.remainFreeKandian
+        );
+    }
+
+    /**
+     * 减去多少充值看点
+     *
+     * @param reduceNum 消费多少看点
+     * @param recharge
+     */
+    @Transactional
+    void subtractRecharge(int reduceNum, Recharge recharge) {
+        rechargeMapper.updateByExampleSelective(
+                Recharge.builder().remainFreeKandian(recharge.getRemainFreeKandian() - reduceNum).build(),
+                RechargeExample.newAndCreateCriteria()
+                        .andIdEqualTo(recharge.getId())
+                        .andRemainFreeKandianEqualTo(recharge.getRemainFreeKandian()).example(),
+                Recharge.Column.remainFreeKandian
+        );
+    }
+
     /**
      * 获取版权方章节内容
      *

+ 1 - 1
book-server/src/main/resources/application-dev.yml

@@ -39,7 +39,7 @@ spring:
     polar:
       type: com.alibaba.druid.pool.DruidDataSource
       driver-class-name: com.mysql.cj.jdbc.Driver
-      jdbc-url: jdbc:mysql://121.41.100.198:3306/polar?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
+      jdbc-url: jdbc:mysql://121.41.100.198:3306/polardb?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
       username: root
       password: root
       #下面为连接池补充设置