盈利宝dataservice

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!--自己的父项目-->
    <parent>
        <groupId>com.spring</groupId>
        <artifactId>micr-parent</artifactId>
        <version>1.0.0</version>
        <relativePath/>
    </parent>
    <groupId>com.spring</groupId>
    <artifactId>spring-dataservice</artifactId>
    <version>1.0.0</version>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.spring</groupId>
            <artifactId>spring-common</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!--dubbo公共项目依赖-->
        <dependency>
            <groupId>com.spring</groupId>
            <artifactId>spring-api</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!--dubbo起步依赖-->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
        </dependency>
        <!--zookeeper起步依赖-->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-dependencies-zookeeper</artifactId>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

application.yml

#服务名称
spring:
  application:
    name: spring-dataservice
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ylb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
    username: root
    password: 1234

#设置mybatis
mybatis:
  mapper-locations: classpath:/mappers/**/*.xml
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: true

#Dubbo配置
dubbo:
  registry:
    address: zookeeper://localhost:2181
  scan:
    base-packages: com.spring.dataservice.service
  provider:
    timeout: 50000
    retries: 0

#密码的盐
#盐(Salt) 在密码学中,是指通过在密码任意固定位置插入特定的字符串,让散列后的结果和使用原始密码的散列结果不相符,这种过程称之为“加盐”。
ylb:
  config:
    password-salt: fiwsyhrf9wejroi2huio3y4234operw3

resources.mappers.BidInfoMapper.xml

<?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.spring.dataservice.mapper.BidInfoMapper">
  <resultMap id="BaseResultMap" type="com.spring.api.model.BidInfo">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="prod_id" jdbcType="INTEGER" property="prodId" />
    <result column="uid" jdbcType="INTEGER" property="uid" />
    <result column="bid_money" jdbcType="DECIMAL" property="bidMoney" />
    <result column="bid_time" jdbcType="TIMESTAMP" property="bidTime" />
    <result column="bid_status" jdbcType="INTEGER" property="bidStatus" />
  </resultMap>
  <sql id="Base_Column_List">
    id, prod_id, uid, bid_money, bid_time, bid_status
  </sql>
  <!--累计成交金额-->
  <select id="selectSumBidMoney" resultType="java.math.BigDecimal">
    select sum(bid_money) as sumBidMoney from b_bid_info
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from b_bid_info
    where id = #{id,jdbcType=INTEGER}
  </select>
  <!--某个产品的投资记录-->
  <select id="selectByProductId" resultType="com.spring.api.pojo.BidInfoProduct">
      SELECT
          bid.id,
          CONCAT( SUBSTRING( u.phone FROM 1 FOR 3 ), "******", SUBSTRING( u.phone FROM 10 FOR 2 ) ) AS phone,
          DATE_FORMAT( bid.bid_time, "%Y-%m-%d %H:%i:%s" ) AS bidTime,
          bid.bid_money AS bidMoney
      FROM
          b_bid_info bid
          JOIN u_user u ON bid.uid = u.id
      WHERE
          bid.prod_id = #{productId}
      ORDER BY
          bid.bid_time DESC
          LIMIT #{offset},#{rows}
  </select>
  <!--某个产品的投资记录-->
  <select id="selectByProdId" resultMap="BaseResultMap">
    SELECT
	 <include refid="Base_Column_List" />
    FROM
        b_bid_info
    WHERE
	  prod_id = #{productId}  AND bid_status = 1
    ORDER BY  id
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from b_bid_info
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.spring.api.model.BidInfo">
    insert into b_bid_info (id, prod_id, uid, 
      bid_money, bid_time, bid_status
      )
    values (#{id,jdbcType=INTEGER}, #{prodId,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, 
      #{bidMoney,jdbcType=DECIMAL}, #{bidTime,jdbcType=TIMESTAMP}, #{bidStatus,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.spring.api.model.BidInfo">
    insert into b_bid_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="prodId != null">
        prod_id,
      </if>
      <if test="uid != null">
        uid,
      </if>
      <if test="bidMoney != null">
        bid_money,
      </if>
      <if test="bidTime != null">
        bid_time,
      </if>
      <if test="bidStatus != null">
        bid_status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="prodId != null">
        #{prodId,jdbcType=INTEGER},
      </if>
      <if test="uid != null">
        #{uid,jdbcType=INTEGER},
      </if>
      <if test="bidMoney != null">
        #{bidMoney,jdbcType=DECIMAL},
      </if>
      <if test="bidTime != null">
        #{bidTime,jdbcType=TIMESTAMP},
      </if>
      <if test="bidStatus != null">
        #{bidStatus,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.spring.api.model.BidInfo">
    update b_bid_info
    <set>
      <if test="prodId != null">
        prod_id = #{prodId,jdbcType=INTEGER},
      </if>
      <if test="uid != null">
        uid = #{uid,jdbcType=INTEGER},
      </if>
      <if test="bidMoney != null">
        bid_money = #{bidMoney,jdbcType=DECIMAL},
      </if>
      <if test="bidTime != null">
        bid_time = #{bidTime,jdbcType=TIMESTAMP},
      </if>
      <if test="bidStatus != null">
        bid_status = #{bidStatus,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.spring.api.model.BidInfo">
    update b_bid_info
    set prod_id = #{prodId,jdbcType=INTEGER},
      uid = #{uid,jdbcType=INTEGER},
      bid_money = #{bidMoney,jdbcType=DECIMAL},
      bid_time = #{bidTime,jdbcType=TIMESTAMP},
      bid_status = #{bidStatus,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>

resources.mappers.FinanceAccountMapper.xml

<?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.spring.dataservice.mapper.FinanceAccountMapper">
  <resultMap id="BaseResultMap" type="com.spring.api.model.FinanceAccount">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="uid" jdbcType="INTEGER" property="uid" />
    <result column="available_money" jdbcType="DECIMAL" property="availableMoney" />
  </resultMap>
  <sql id="Base_Column_List">
    id, uid, available_money
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from u_finance_account
    where id = #{id,jdbcType=INTEGER}
  </select>
  <!--/*给uid的记录上锁*/-->
  <select id="selectByUidForUpdate" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from u_finance_account
    where uid = #{uid}
    for update
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from u_finance_account
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.spring.api.model.FinanceAccount">
    insert into u_finance_account (id, uid, available_money
      )
    values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{availableMoney,jdbcType=DECIMAL}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.spring.api.model.FinanceAccount">
    insert into u_finance_account
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="uid != null">
        uid,
      </if>
      <if test="availableMoney != null">
        available_money,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="uid != null">
        #{uid,jdbcType=INTEGER},
      </if>
      <if test="availableMoney != null">
        #{availableMoney,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.spring.api.model.FinanceAccount">
    update u_finance_account
    <set>
      <if test="uid != null">
        uid = #{uid,jdbcType=INTEGER},
      </if>
      <if test="availableMoney != null">
        available_money = #{availableMoney,jdbcType=DECIMAL},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.spring.api.model.FinanceAccount">
    update u_finance_account
    set uid = #{uid,jdbcType=INTEGER},
      available_money = #{availableMoney,jdbcType=DECIMAL}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!--更新资金-->
  <update id="updateAvailableMoneyByInvest">
    update   u_finance_account set available_money = available_money - #{money}
    where uid = #{uid} and ( available_money - #{money} >=0 )
  </update>
</mapper>

resources.mappers.IncomeRecordMapper.xml

<?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.spring.dataservice.mapper.IncomeRecordMapper">
  <resultMap id="BaseResultMap" type="com.spring.api.model.IncomeRecord">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="uid" jdbcType="INTEGER" property="uid" />
    <result column="prod_id" jdbcType="INTEGER" property="prodId" />
    <result column="bid_id" jdbcType="INTEGER" property="bidId" />
    <result column="bid_money" jdbcType="DECIMAL" property="bidMoney" />
    <result column="income_date" jdbcType="DATE" property="incomeDate" />
    <result column="income_money" jdbcType="DECIMAL" property="incomeMoney" />
    <result column="income_status" jdbcType="INTEGER" property="incomeStatus" />
  </resultMap>
  <sql id="Base_Column_List">
    id, uid, prod_id, bid_id, bid_money, income_date, income_money, income_status
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from b_income_record
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from b_income_record
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.spring.api.model.IncomeRecord">
    insert into b_income_record (id, uid, prod_id, 
      bid_id, bid_money, income_date, 
      income_money, income_status)
    values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{prodId,jdbcType=INTEGER}, 
      #{bidId,jdbcType=INTEGER}, #{bidMoney,jdbcType=DECIMAL}, #{incomeDate,jdbcType=DATE}, 
      #{incomeMoney,jdbcType=DECIMAL}, #{incomeStatus,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.spring.api.model.IncomeRecord">
    insert into b_income_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="uid != null">
        uid,
      </if>
      <if test="prodId != null">
        prod_id,
      </if>
      <if test="bidId != null">
        bid_id,
      </if>
      <if test="bidMoney != null">
        bid_money,
      </if>
      <if test="incomeDate != null">
        income_date,
      </if>
      <if test="incomeMoney != null">
        income_money,
      </if>
      <if test="incomeStatus != null">
        income_status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="uid != null">
        #{uid,jdbcType=INTEGER},
      </if>
      <if test="prodId != null">
        #{prodId,jdbcType=INTEGER},
      </if>
      <if test="bidId != null">
        #{bidId,jdbcType=INTEGER},
      </if>
      <if test="bidMoney != null">
        #{bidMoney,jdbcType=DECIMAL},
      </if>
      <if test="incomeDate != null">
        #{incomeDate,jdbcType=DATE},
      </if>
      <if test="incomeMoney != null">
        #{incomeMoney,jdbcType=DECIMAL},
      </if>
      <if test="incomeStatus != null">
        #{incomeStatus,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.spring.api.model.IncomeRecord">
    update b_income_record
    <set>
      <if test="uid != null">
        uid = #{uid,jdbcType=INTEGER},
      </if>
      <if test="prodId != null">
        prod_id = #{prodId,jdbcType=INTEGER},
      </if>
      <if test="bidId != null">
        bid_id = #{bidId,jdbcType=INTEGER},
      </if>
      <if test="bidMoney != null">
        bid_money = #{bidMoney,jdbcType=DECIMAL},
      </if>
      <if test="incomeDate != null">
        income_date = #{incomeDate,jdbcType=DATE},
      </if>
      <if test="incomeMoney != null">
        income_money = #{incomeMoney,jdbcType=DECIMAL},
      </if>
      <if test="incomeStatus != null">
        income_status = #{incomeStatus,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.spring.api.model.IncomeRecord">
    update b_income_record
    set uid = #{uid,jdbcType=INTEGER},
      prod_id = #{prodId,jdbcType=INTEGER},
      bid_id = #{bidId,jdbcType=INTEGER},
      bid_money = #{bidMoney,jdbcType=DECIMAL},
      income_date = #{incomeDate,jdbcType=DATE},
      income_money = #{incomeMoney,jdbcType=DECIMAL},
      income_status = #{incomeStatus,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>

resources.mappers.ProductInfoMapper.xml

<?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.spring.dataservice.mapper.ProductInfoMapper">
  <resultMap id="BaseResultMap" type="com.spring.api.model.ProductInfo">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="product_name" jdbcType="VARCHAR" property="productName" />
    <result column="rate" jdbcType="DECIMAL" property="rate" />
    <result column="cycle" jdbcType="INTEGER" property="cycle" />
    <result column="release_time" jdbcType="DATE" property="releaseTime" />
    <result column="product_type" jdbcType="INTEGER" property="productType" />
    <result column="product_no" jdbcType="VARCHAR" property="productNo" />
    <result column="product_money" jdbcType="DECIMAL" property="productMoney" />
    <result column="left_product_money" jdbcType="DECIMAL" property="leftProductMoney" />
    <result column="bid_min_limit" jdbcType="DECIMAL" property="bidMinLimit" />
    <result column="bid_max_limit" jdbcType="DECIMAL" property="bidMaxLimit" />
    <result column="product_status" jdbcType="INTEGER" property="productStatus" />
    <result column="product_full_time" jdbcType="TIMESTAMP" property="productFullTime" />
    <result column="product_desc" jdbcType="VARCHAR" property="productDesc" />
  </resultMap>
  <sql id="Base_Column_List">
    id, product_name, rate, cycle, release_time, product_type, product_no, product_money, 
    left_product_money, bid_min_limit, bid_max_limit, product_status, product_full_time, 
    product_desc
  </sql>
  <!--利率平均值-->
  <select id="selectAvgRate" resultType="java.math.BigDecimal">
    select round(avg(rate),2) as avgRate  from b_product_info
  </select>
  <!--按产品类型分页查询-->
  <select id="selectByTypeLimit" resultMap="BaseResultMap">
     select <include refid="Base_Column_List" />
     from b_product_info
     where product_type = #{ptype}
     order by release_time desc
     limit #{offset},#{rows}
  </select>
  <!--某个产品类型的记录总数-->
  <select id="selectCountByType" resultType="java.lang.Integer">
    select count(id) as nums from b_product_info where product_type = #{ptype}
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from b_product_info
    where id = #{id,jdbcType=INTEGER}
  </select>
  <!--满标的理财列表-->
  <select id="selectFullTimeProducts" resultMap="BaseResultMap">
    SELECT
     <include refid="Base_Column_List" />
    FROM
     b_product_info
    WHERE
     product_status = 1
     AND product_full_time >= #{beginTime}  AND product_full_time &lt; #{endTime}
     order by id
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from b_product_info
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.spring.api.model.ProductInfo">
    insert into b_product_info (id, product_name, rate, 
      cycle, release_time, product_type, 
      product_no, product_money, left_product_money, 
      bid_min_limit, bid_max_limit, product_status, 
      product_full_time, product_desc)
    values (#{id,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR}, #{rate,jdbcType=DECIMAL}, 
      #{cycle,jdbcType=INTEGER}, #{releaseTime,jdbcType=DATE}, #{productType,jdbcType=INTEGER}, 
      #{productNo,jdbcType=VARCHAR}, #{productMoney,jdbcType=DECIMAL}, #{leftProductMoney,jdbcType=DECIMAL}, 
      #{bidMinLimit,jdbcType=DECIMAL}, #{bidMaxLimit,jdbcType=DECIMAL}, #{productStatus,jdbcType=INTEGER}, 
      #{productFullTime,jdbcType=TIMESTAMP}, #{productDesc,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.spring.api.model.ProductInfo">
    insert into b_product_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="productName != null">
        product_name,
      </if>
      <if test="rate != null">
        rate,
      </if>
      <if test="cycle != null">
        cycle,
      </if>
      <if test="releaseTime != null">
        release_time,
      </if>
      <if test="productType != null">
        product_type,
      </if>
      <if test="productNo != null">
        product_no,
      </if>
      <if test="productMoney != null">
        product_money,
      </if>
      <if test="leftProductMoney != null">
        left_product_money,
      </if>
      <if test="bidMinLimit != null">
        bid_min_limit,
      </if>
      <if test="bidMaxLimit != null">
        bid_max_limit,
      </if>
      <if test="productStatus != null">
        product_status,
      </if>
      <if test="productFullTime != null">
        product_full_time,
      </if>
      <if test="productDesc != null">
        product_desc,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="productName != null">
        #{productName,jdbcType=VARCHAR},
      </if>
      <if test="rate != null">
        #{rate,jdbcType=DECIMAL},
      </if>
      <if test="cycle != null">
        #{cycle,jdbcType=INTEGER},
      </if>
      <if test="releaseTime != null">
        #{releaseTime,jdbcType=DATE},
      </if>
      <if test="productType != null">
        #{productType,jdbcType=INTEGER},
      </if>
      <if test="productNo != null">
        #{productNo,jdbcType=VARCHAR},
      </if>
      <if test="productMoney != null">
        #{productMoney,jdbcType=DECIMAL},
      </if>
      <if test="leftProductMoney != null">
        #{leftProductMoney,jdbcType=DECIMAL},
      </if>
      <if test="bidMinLimit != null">
        #{bidMinLimit,jdbcType=DECIMAL},
      </if>
      <if test="bidMaxLimit != null">
        #{bidMaxLimit,jdbcType=DECIMAL},
      </if>
      <if test="productStatus != null">
        #{productStatus,jdbcType=INTEGER},
      </if>
      <if test="productFullTime != null">
        #{productFullTime,jdbcType=TIMESTAMP},
      </if>
      <if test="productDesc != null">
        #{productDesc,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.spring.api.model.ProductInfo">
    update b_product_info
    <set>
      <if test="productName != null">
        product_name = #{productName,jdbcType=VARCHAR},
      </if>
      <if test="rate != null">
        rate = #{rate,jdbcType=DECIMAL},
      </if>
      <if test="cycle != null">
        cycle = #{cycle,jdbcType=INTEGER},
      </if>
      <if test="releaseTime != null">
        release_time = #{releaseTime,jdbcType=DATE},
      </if>
      <if test="productType != null">
        product_type = #{productType,jdbcType=INTEGER},
      </if>
      <if test="productNo != null">
        product_no = #{productNo,jdbcType=VARCHAR},
      </if>
      <if test="productMoney != null">
        product_money = #{productMoney,jdbcType=DECIMAL},
      </if>
      <if test="leftProductMoney != null">
        left_product_money = #{leftProductMoney,jdbcType=DECIMAL},
      </if>
      <if test="bidMinLimit != null">
        bid_min_limit = #{bidMinLimit,jdbcType=DECIMAL},
      </if>
      <if test="bidMaxLimit != null">
        bid_max_limit = #{bidMaxLimit,jdbcType=DECIMAL},
      </if>
      <if test="productStatus != null">
        product_status = #{productStatus,jdbcType=INTEGER},
      </if>
      <if test="productFullTime != null">
        product_full_time = #{productFullTime,jdbcType=TIMESTAMP},
      </if>
      <if test="productDesc != null">
        product_desc = #{productDesc,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.spring.api.model.ProductInfo">
    update b_product_info
    set product_name = #{productName,jdbcType=VARCHAR},
      rate = #{rate,jdbcType=DECIMAL},
      cycle = #{cycle,jdbcType=INTEGER},
      release_time = #{releaseTime,jdbcType=DATE},
      product_type = #{productType,jdbcType=INTEGER},
      product_no = #{productNo,jdbcType=VARCHAR},
      product_money = #{productMoney,jdbcType=DECIMAL},
      left_product_money = #{leftProductMoney,jdbcType=DECIMAL},
      bid_min_limit = #{bidMinLimit,jdbcType=DECIMAL},
      bid_max_limit = #{bidMaxLimit,jdbcType=DECIMAL},
      product_status = #{productStatus,jdbcType=INTEGER},
      product_full_time = #{productFullTime,jdbcType=TIMESTAMP},
      product_desc = #{productDesc,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!--扣除产品剩余可投资金额-->
  <update id="updateLeftProductMoney">
    update b_product_info set left_product_money = left_product_money - #{money}
    where id = #{id} and ( left_product_money - #{money} >=0 )
  </update>
  <!--*更新产品为满标-->
  <update id="updateSelled">
    update  b_product_info set product_status = 1 ,  product_full_time = now()
    where id = #{id}
  </update>
  <!--更新状态-->
  <update id="updateStatus">
    update  b_product_info  set  product_status = #{newStatus} where id = #{id}
  </update>
</mapper>

resources.mappers.RechargeRecordMapper.xml

<?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.spring.dataservice.mapper.RechargeRecordMapper">
  <resultMap id="BaseResultMap" type="com.spring.api.model.RechargeRecord">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="uid" jdbcType="INTEGER" property="uid" />
    <result column="recharge_no" jdbcType="VARCHAR" property="rechargeNo" />
    <result column="recharge_status" jdbcType="INTEGER" property="rechargeStatus" />
    <result column="recharge_money" jdbcType="DECIMAL" property="rechargeMoney" />
    <result column="recharge_time" jdbcType="TIMESTAMP" property="rechargeTime" />
    <result column="recharge_desc" jdbcType="VARCHAR" property="rechargeDesc" />
    <result column="channel" jdbcType="VARCHAR" property="channel" />
  </resultMap>
  <sql id="Base_Column_List">
    id, uid, recharge_no, recharge_status, recharge_money, recharge_time, recharge_desc, 
    channel
  </sql>
  <!--按userId查询充值记录-->
  <select id="selectByUid" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from b_recharge_record
    where uid= #{uid}
    order by recharge_time desc
    limit #{offset},#{rows}
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from b_recharge_record
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from b_recharge_record
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.spring.api.model.RechargeRecord">
    insert into b_recharge_record (id, uid, recharge_no, 
      recharge_status, recharge_money, recharge_time, 
      recharge_desc, channel)
    values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{rechargeNo,jdbcType=VARCHAR}, 
      #{rechargeStatus,jdbcType=INTEGER}, #{rechargeMoney,jdbcType=DECIMAL}, #{rechargeTime,jdbcType=TIMESTAMP}, 
      #{rechargeDesc,jdbcType=VARCHAR}, #{channel,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.spring.api.model.RechargeRecord">
    insert into b_recharge_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="uid != null">
        uid,
      </if>
      <if test="rechargeNo != null">
        recharge_no,
      </if>
      <if test="rechargeStatus != null">
        recharge_status,
      </if>
      <if test="rechargeMoney != null">
        recharge_money,
      </if>
      <if test="rechargeTime != null">
        recharge_time,
      </if>
      <if test="rechargeDesc != null">
        recharge_desc,
      </if>
      <if test="channel != null">
        channel,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="uid != null">
        #{uid,jdbcType=INTEGER},
      </if>
      <if test="rechargeNo != null">
        #{rechargeNo,jdbcType=VARCHAR},
      </if>
      <if test="rechargeStatus != null">
        #{rechargeStatus,jdbcType=INTEGER},
      </if>
      <if test="rechargeMoney != null">
        #{rechargeMoney,jdbcType=DECIMAL},
      </if>
      <if test="rechargeTime != null">
        #{rechargeTime,jdbcType=TIMESTAMP},
      </if>
      <if test="rechargeDesc != null">
        #{rechargeDesc,jdbcType=VARCHAR},
      </if>
      <if test="channel != null">
        #{channel,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.spring.api.model.RechargeRecord">
    update b_recharge_record
    <set>
      <if test="uid != null">
        uid = #{uid,jdbcType=INTEGER},
      </if>
      <if test="rechargeNo != null">
        recharge_no = #{rechargeNo,jdbcType=VARCHAR},
      </if>
      <if test="rechargeStatus != null">
        recharge_status = #{rechargeStatus,jdbcType=INTEGER},
      </if>
      <if test="rechargeMoney != null">
        recharge_money = #{rechargeMoney,jdbcType=DECIMAL},
      </if>
      <if test="rechargeTime != null">
        recharge_time = #{rechargeTime,jdbcType=TIMESTAMP},
      </if>
      <if test="rechargeDesc != null">
        recharge_desc = #{rechargeDesc,jdbcType=VARCHAR},
      </if>
      <if test="channel != null">
        channel = #{channel,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.spring.api.model.RechargeRecord">
    update b_recharge_record
    set uid = #{uid,jdbcType=INTEGER},
      recharge_no = #{rechargeNo,jdbcType=VARCHAR},
      recharge_status = #{rechargeStatus,jdbcType=INTEGER},
      recharge_money = #{rechargeMoney,jdbcType=DECIMAL},
      recharge_time = #{rechargeTime,jdbcType=TIMESTAMP},
      recharge_desc = #{rechargeDesc,jdbcType=VARCHAR},
      channel = #{channel,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>

 resources.mappers.UserMapper.xml

<?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.spring.dataservice.mapper.UserMapper">
  <resultMap id="BaseResultMap" type="com.spring.api.model.User">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="login_password" jdbcType="VARCHAR" property="loginPassword" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="id_card" jdbcType="VARCHAR" property="idCard" />
    <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
    <result column="header_image" jdbcType="VARCHAR" property="headerImage" />
  </resultMap>
  <resultMap id="UserAccountMap" type="com.spring.api.pojo.UserAccountInfo">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="login_password" jdbcType="VARCHAR" property="loginPassword" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="id_card" jdbcType="VARCHAR" property="idCard" />
    <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
    <result column="header_image" jdbcType="VARCHAR" property="headerImage" />
    <result column="available_money" jdbcType="DECIMAL" property="availableMoney" />
  </resultMap>
  <sql id="Base_Column_List">
    id, phone, login_password, name, id_card, add_time, last_login_time, header_image
  </sql>
  <!--注册用户数量-->
  <select id="selectCountUser" resultType="java.lang.Integer">
     select count(id) as ct from u_user
  </select>
  <!--使用手机号查询用户-->
  <select id="selectByPhone" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"></include>
    from  u_user
    where phone = #{phone}
  </select>
  <!--添加记录,获取主键值-->
  <insert id="insertReturnPrimaryKey">
    insert into u_user(phone, login_password,add_time)
    values(#{phone},#{loginPassword},#{addTime})
    <selectKey keyColumn="newId" keyProperty="id" resultType="int" order="AFTER">
       select LAST_INSERT_ID() as newId
    </selectKey>
  </insert>
  <!--登录-->
  <select id="selectLogin" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"></include>
    from u_user
    where phone = #{phone} and  login_password = #{loginPassword}
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from u_user
    where id = #{id,jdbcType=INTEGER}
  </select>
  <!--查询用户信息-->
   <select id="selectUserAccountById" resultMap="UserAccountMap">
    SELECT
        u.*,
        a.available_money
    FROM
        u_user u
        JOIN u_finance_account a ON u.id = a.uid
    WHERE
        u.id = #{uid}
   </select>
  <!--更新实名认证信息-->
  <update id="updateRealname">
    update u_user set name=#{name} , id_card = #{idCard} where phone = #{phone}
  </update>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from u_user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.spring.api.model.User">
    insert into u_user (id, phone, login_password, 
      name, id_card, add_time, 
      last_login_time, header_image)
    values (#{id,jdbcType=INTEGER}, #{phone,jdbcType=VARCHAR}, #{loginPassword,jdbcType=VARCHAR}, 
      #{name,jdbcType=VARCHAR}, #{idCard,jdbcType=VARCHAR}, #{addTime,jdbcType=TIMESTAMP}, 
      #{lastLoginTime,jdbcType=TIMESTAMP}, #{headerImage,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.spring.api.model.User">
    insert into u_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="loginPassword != null">
        login_password,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="idCard != null">
        id_card,
      </if>
      <if test="addTime != null">
        add_time,
      </if>
      <if test="lastLoginTime != null">
        last_login_time,
      </if>
      <if test="headerImage != null">
        header_image,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="loginPassword != null">
        #{loginPassword,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="idCard != null">
        #{idCard,jdbcType=VARCHAR},
      </if>
      <if test="addTime != null">
        #{addTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastLoginTime != null">
        #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
      <if test="headerImage != null">
        #{headerImage,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.spring.api.model.User">
    update u_user
    <set>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="loginPassword != null">
        login_password = #{loginPassword,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="idCard != null">
        id_card = #{idCard,jdbcType=VARCHAR},
      </if>
      <if test="addTime != null">
        add_time = #{addTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastLoginTime != null">
        last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
      <if test="headerImage != null">
        header_image = #{headerImage,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.spring.api.model.User">
    update u_user
    set phone = #{phone,jdbcType=VARCHAR},
      login_password = #{loginPassword,jdbcType=VARCHAR},
      name = #{name,jdbcType=VARCHAR},
      id_card = #{idCard,jdbcType=VARCHAR},
      add_time = #{addTime,jdbcType=TIMESTAMP},
      last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},
      header_image = #{headerImage,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>

DataserviceApplication

package com.spring.dataservice;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//启动Dubbo服务
@EnableDubbo
//Mapper扫描表
@MapperScan(basePackages = "com.spring.dataservice.mapper")
@SpringBootApplication
public class DataserviceApplication {
	public static void main(String[] args) {
		SpringApplication.run(DataserviceApplication.class, args);
	}
}

IncomeServiceImpl

package com.spring.dataservice.service;

import com.spring.api.model.BidInfo;
import com.spring.api.model.IncomeRecord;
import com.spring.api.model.ProductInfo;
import com.spring.api.service.IncomeService;
import com.spring.common.constants.YLBConstant;
import com.spring.dataservice.mapper.BidInfoMapper;
import com.spring.dataservice.mapper.IncomeRecordMapper;
import com.spring.dataservice.mapper.ProductInfoMapper;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Package:com.spring.dataservice.service
 */
@DubboService(interfaceClass = IncomeService.class,version = "1.0")
public class IncomeServiceImpl implements IncomeService {

    @Resource
    private ProductInfoMapper productInfoMapper;

    @Resource
    private BidInfoMapper bidInfoMapper;

    @Resource
    private IncomeRecordMapper incomeMapper;

    /*收益计划*/
    @Transactional(rollbackFor = Exception.class)
    @Override
    public synchronized void generateIncomePlan() {
        //1.获取要处理的理财产品记录
        Date currentDate = new Date();
        Date beginTime = DateUtils.truncate(DateUtils.addDays(currentDate, -1), Calendar.DATE);;
        Date endTime = DateUtils.truncate(currentDate, Calendar.DATE);;
        List<ProductInfo> productInfoList = productInfoMapper.selectFullTimeProducts(beginTime,endTime);
        //2.查询每个理财产品的多个投资记录
        int rows  = 0 ;
        BigDecimal income =  null;
        BigDecimal dayRate = null;
        BigDecimal cycle  = null; //周期
        Date incomeDate  = null;//到期时间
        for(ProductInfo product:productInfoList){
            //日利率
            dayRate = product.getRate().divide(new BigDecimal("360"),10, RoundingMode.HALF_UP)
                      .divide(new BigDecimal("100"),10,RoundingMode.HALF_UP);
            //产品类型不同,周期不同 天 ,月
            if( product.getProductType() == YLBConstant.PRODUCT_TYPE_XINSHOUBAO){  //天为单位
                cycle = new BigDecimal(product.getCycle());
                incomeDate = DateUtils.addDays(product.getProductFullTime(),(1+product.getCycle()));
            } else {
                cycle = new BigDecimal(product.getCycle() * 30);
                incomeDate = DateUtils.addDays(product.getProductFullTime(),(1+ product.getCycle() * 30 ));
            }
            List<BidInfo> bidList  = bidInfoMapper.selectByProdId(product.getId());
            //3.计算每笔投资的 利息 和 到期时间
            for(BidInfo bid : bidList){
                //利息 = 本金  * 周期 * 利率
                income = bid.getBidMoney().multiply(cycle).multiply(dayRate);
                // 创建收益记录
                IncomeRecord incomeRecord = new IncomeRecord();
                incomeRecord.setBidId(bid.getId());
                incomeRecord.setBidMoney(bid.getBidMoney());
                incomeRecord.setIncomeDate(incomeDate);
                incomeRecord.setIncomeStatus(YLBConstant.INCOME_STATUS_PLAN);
                incomeRecord.setProdId(product.getId());
                incomeRecord.setIncomeMoney(income);
                incomeRecord.setUid(bid.getUid());
                incomeMapper.insertSelective(incomeRecord);
            }
            //更新产品的状态
            rows = productInfoMapper.updateStatus(product.getId(),YLBConstant.PRODUCT_STATUS_PLAN);
            if(rows < 1 ){
                throw new RuntimeException("生成收益计划,更新产品状态为2失败");
            }
        }
    }
}

InvestServiceImpl

package com.spring.dataservice.service;

import com.spring.api.model.BidInfo;
import com.spring.api.model.FinanceAccount;
import com.spring.api.model.ProductInfo;
import com.spring.api.pojo.BidInfoProduct;
import com.spring.api.service.InvestService;
import com.spring.common.constants.YLBConstant;
import com.spring.common.util.CommonUtil;
import com.spring.dataservice.mapper.BidInfoMapper;
import com.spring.dataservice.mapper.FinanceAccountMapper;
import com.spring.dataservice.mapper.ProductInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * Package:com.spring.dataservice.service
 */
@DubboService(interfaceClass = InvestService.class, version = "1.0")
public class InvestServiceImpl implements InvestService {
    @Resource
    private BidInfoMapper bidInfoMapper;
    @Resource
    private FinanceAccountMapper accountMapper;
    @Resource
    private ProductInfoMapper productInfoMapper;
    /**
     * 查询某个产品的投资记录
     */
    @Override
    public List<BidInfoProduct> queryBidListByProductId(Integer productId,
                                                        Integer pageNo,
                                                        Integer pageSize) {
        List<BidInfoProduct> bidList = new ArrayList<>();
        if (productId != null && productId > 0) {
            pageNo = CommonUtil.defaultPageNo(pageNo);
            pageSize = CommonUtil.defaultPageSize(pageSize);
            int offset = (pageNo - 1) * pageSize;
            bidList = bidInfoMapper.selectByProductId(productId, offset, pageSize);
        }
        return bidList;
    }
    /*投资理财产品, int 是投资的结果 , 1 投资成功*/
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int investProduct(Integer uid, Integer productId, BigDecimal money) {
        int result = 0;//默认,参数不正确
        int rows = 0;
        //1参数检查
        if ((uid != null && uid > 0) && (productId != null && productId > 0)
                && (money != null && money.intValue() % 100 == 0 && money.intValue() >= 100)) {
            //2.查询账号金额
            FinanceAccount account = accountMapper.selectByUidForUpdate(uid);
            if (account != null) {
                if (CommonUtil.ge(account.getAvailableMoney(), money)) {
                    //资金满足购买要求
                    //3.检查产品是否可以购买
                    ProductInfo productInfo = productInfoMapper.selectByPrimaryKey(productId);
                    if (productInfo != null
                            && productInfo.getProductStatus() == YLBConstant.PRODUCT_STATUS_SELLING) {
                        if (CommonUtil.ge(productInfo.getLeftProductMoney(), money) &&
                                CommonUtil.ge(money, productInfo.getBidMinLimit()) &&
                                CommonUtil.ge(productInfo.getBidMaxLimit(), money)) {
                            //可以购买了 4. 扣除账号资金
                            rows = accountMapper.updateAvailableMoneyByInvest(uid, money);
                            if (rows < 1) {
                                throw new RuntimeException("投资更新账号资金失败");
                            }
                            //5.扣除产品剩余可投资金额
                            rows = productInfoMapper.updateLeftProductMoney(productId, money);
                            if (rows < 1) {
                                throw new RuntimeException("投资更新产品剩余金额失败");
                            }
                            //6.创建投资记录
                            BidInfo bidInfo = new BidInfo();
                            bidInfo.setBidMoney(money);
                            bidInfo.setBidStatus(YLBConstant.INVEST_STATUS_SUCC);
                            bidInfo.setBidTime(new Date());
                            bidInfo.setProdId(productId);
                            bidInfo.setUid(uid);
                            bidInfoMapper.insertSelective(bidInfo);
                            //7.判断产品是否卖完,更新产品是满标状态
                            ProductInfo dbProductInfo = productInfoMapper.selectByPrimaryKey(productId);
                            if( dbProductInfo.getLeftProductMoney().compareTo(new BigDecimal("0")) == 0 ){
                                rows  = productInfoMapper.updateSelled(productId);
                                if( rows < 1 ){
                                    throw new RuntimeException("投资更新产品满标失败");
                                }
                            }
                            //8.最后这是投资成功
                            result = 1;
                        }
                    } else {
                        result = 4;//理财产品不存在
                    }
                } else {
                    result = 3;//资金不足
                }
            } else {
                result = 2;//资金账号不存在
            }
        }
        return result;
    }
}

PlatBaseInfoServiceImpl

package com.spring.dataservice.service;

import com.spring.api.pojo.BaseInfo;
import com.spring.api.service.PlatBaseInfoService;
import com.spring.dataservice.mapper.BidInfoMapper;
import com.spring.dataservice.mapper.ProductInfoMapper;
import com.spring.dataservice.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.math.BigDecimal;
/**
 * Package:com.spring.dataservice.service
 */
@DubboService(interfaceClass = PlatBaseInfoService.class,version = "1.0")
public class PlatBaseInfoServiceImpl implements PlatBaseInfoService {
    //注入Mapper
    @Resource
    private UserMapper userMapper;
    @Resource
    private ProductInfoMapper productInfoMapper;
    @Resource
    private BidInfoMapper bidInfoMapper;
    /*平台基本信息*/
    @Override
    public BaseInfo queryPlatBaseInfo() {
        //获取注册人数, 收益率平均值, 累计成交金额
        int registerUser = userMapper.selectCountUser();
        //收益率平均值
        BigDecimal avgRate = productInfoMapper.selectAvgRate();
        //累计成交金额
        BigDecimal sumBidMoney = bidInfoMapper.selectSumBidMoney();
        BaseInfo baseInfo = new BaseInfo(avgRate,sumBidMoney,registerUser);
        return baseInfo;
    }
}

ProductServiceImpl

package com.spring.dataservice.service;

import com.spring.api.model.ProductInfo;
import com.spring.api.pojo.MultiProduct;
import com.spring.api.service.ProductService;
import com.spring.common.constants.YLBConstant;
import com.spring.common.util.CommonUtil;
import com.spring.dataservice.mapper.ProductInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Package:com.spring.dataservice.service
 */
@DubboService(interfaceClass = ProductService.class,version = "1.0")
public class ProductServiceImpl implements ProductService {
    @Resource
    private ProductInfoMapper productInfoMapper;
    /*按类型分页查询产品*/
    @Override
    public List<ProductInfo> queryByTypeLimit(Integer pType, Integer pageNo, Integer pageSize) {
        List<ProductInfo> productInfos = new ArrayList<>();
        if( pType == 0 || pType == 1 || pType == 2){
            pageNo = CommonUtil.defaultPageNo(pageNo);
            pageSize = CommonUtil.defaultPageSize(pageSize);
            int offset  = (pageNo - 1) * pageSize;
            productInfos = productInfoMapper.selectByTypeLimit(pType, offset, pageSize);
        }
        return productInfos;
    }
    /*某个产品类型的记录总数*/
    @Override
    public Integer queryRecordNumsByType(Integer pType) {
        Integer counts = 0;
        if( pType == 0 || pType == 1 || pType == 2){
            counts  = productInfoMapper.selectCountByType(pType);
        }
        return counts;
    }
    /*首页的多个产品数据*/
    @Override
    public MultiProduct queryIndexPageProducts() {
        MultiProduct result = new MultiProduct();
        //查询新手宝
        List<ProductInfo> xinShouBaoList  = productInfoMapper.selectByTypeLimit(
                                      YLBConstant.PRODUCT_TYPE_XINSHOUBAO,0,1);
        //查询优选
        List<ProductInfo> youXuanList = productInfoMapper.selectByTypeLimit(
                                      YLBConstant.PRODUCT_TYPE_YOUXUAN,0,3 );
        //散标
        List<ProductInfo> sanBiaoList = productInfoMapper.selectByTypeLimit(
                                      YLBConstant.PRODUCT_TYPE_SANBIAO,0,3 );
        result.setXinShouBao(xinShouBaoList);
        result.setYouXuan(youXuanList);
        result.setSanBiao(sanBiaoList);
        return result;
    }
    /** 根据产品id ,查询产品信息 */
    @Override
    public ProductInfo queryById(Integer id) {
        ProductInfo productInfo = null;
        if( id != null && id > 0 ){
            productInfo = productInfoMapper.selectByPrimaryKey(id);
        }
        return productInfo;
    }
}

RechargeServiceImpl 

package com.spring.dataservice.service;

import com.spring.api.model.RechargeRecord;
import com.spring.api.service.RechargeService;
import com.spring.common.util.CommonUtil;
import com.spring.dataservice.mapper.RechargeRecordMapper;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Package:com.spring.dataservice.service
 */
@DubboService(interfaceClass = RechargeService.class,version = "1.0")
public class RechargeServiceImpl implements RechargeService {
    @Resource
    private RechargeRecordMapper rechargeMapper;
    /*根据userID查询它的充值记录*/
    @Override
    public List<RechargeRecord> queryByUid(Integer uid, Integer pageNo, Integer pageSize) {
        List<RechargeRecord> records  = new ArrayList<>();
        if( uid != null && uid > 0 ){
            pageNo  = CommonUtil.defaultPageNo(pageNo);
            pageSize = CommonUtil.defaultPageSize(pageSize);
            int offset = (pageNo -1 ) * pageSize;
            records = rechargeMapper.selectByUid(uid, offset, pageSize);
        }
        return records;
    }
}

UserServiceImpl

package com.spring.dataservice.service;

import com.spring.api.model.FinanceAccount;
import com.spring.api.model.User;
import com.spring.api.pojo.UserAccountInfo;
import com.spring.api.service.UserService;
import com.spring.common.util.CommonUtil;
import com.spring.dataservice.mapper.FinanceAccountMapper;
import com.spring.dataservice.mapper.UserMapper;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;

/**
 * Package:com.spring.dataservice.service
 */
@DubboService(interfaceClass = UserService.class,version = "1.0")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Resource
    private FinanceAccountMapper financeAccountMapper;
    @Value("${ylb.config.password-salt}")
    private String passwordSalt;
    @Override
    public User queryByPhone(String phone) {
        User user = null;
        if(CommonUtil.checkPhone(phone)){
            user = userMapper.selectByPhone(phone);
        }
        return user;
    }
    /*用户注册*/
    @Transactional(rollbackFor = Exception.class)
    @Override
    public synchronized int userRegister(String phone, String password) {
        int result = 0;//默认参数不正确
        if( CommonUtil.checkPhone(phone)
                && (password != null && password.length()==32)){
            //判断手机号在库中是否存在
            User queryUser = userMapper.selectByPhone(phone);
            if(queryUser == null){
                //注册密码的md5二次加密。 给原始的密码加盐(salt)
                String newPassword = DigestUtils.md5Hex( password + passwordSalt);
                //注册u_user
                User user = new User();
                user.setPhone(phone);
                user.setLoginPassword(newPassword);
                user.setAddTime(new Date());
                userMapper.insertReturnPrimaryKey(user);
                //获取主键user.getId()
                FinanceAccount account = new FinanceAccount();
                account.setUid(user.getId());
                account.setAvailableMoney(new BigDecimal("0"));
                financeAccountMapper.insertSelective(account);
                //成功result = 1
                result = 1;
            } else {
                //手机号存在
                result = 2;
            }
        }
        return result;
    }
    /*登录*/
    @Transactional(rollbackFor = Exception.class)
    @Override
    public User userLogin(String phone, String password) {
        User user = null;
        if( CommonUtil.checkPhone(phone) && (password != null && password.length() == 32)) {
            String newPassword = DigestUtils.md5Hex( password + passwordSalt);
            user = userMapper.selectLogin(phone,newPassword);
            //更新最后登录时间
            if( user != null){
                user.setLastLoginTime(new Date());
                userMapper.updateByPrimaryKeySelective(user);
            }
        }
        return user;
    }
    /*更新实名认证信息*/
    @Override
    public boolean modifyRealname(String phone, String name, String idCard) {
        int rows = 0;
        if(!StringUtils.isAnyBlank(phone,name,idCard)){
             rows  = userMapper.updateRealname(phone,name,idCard);
        }
        return rows > 0 ;
    }
    /*获取用户和资金信息*/
    @Override
    public UserAccountInfo queryUserAllInfo(Integer uid) {
        UserAccountInfo info = null;
        if( uid != null && uid > 0 ) {
            info  = userMapper.selectUserAccountById(uid);
        }
        return info ;
    }
    /*查询用户*/
    @Override
    public User queryById(Integer uid) {
        User user = null;
        if( uid != null && uid > 0 ){
            user = userMapper.selectByPrimaryKey(uid);
        }
        return user;
    }
}

mapper.BidInfoMapper

package com.spring.dataservice.mapper;

import com.spring.api.model.BidInfo;
import com.spring.api.pojo.BidInfoProduct;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;

public interface BidInfoMapper {
    /*累计成交金额*/
    BigDecimal selectSumBidMoney();
    /*某个产品的投资记录*/
    List<BidInfoProduct> selectByProductId(@Param("productId") Integer productId,
                                           @Param("offset") int offset,
                                           @Param("rows") Integer rows);
    int deleteByPrimaryKey(Integer id);
    int insert(BidInfo record);
    int insertSelective(BidInfo record);
    BidInfo selectByPrimaryKey(Integer id);
    int updateByPrimaryKeySelective(BidInfo record);
    int updateByPrimaryKey(BidInfo record);
    /*某个产品的投资记录*/
    List<BidInfo> selectByProdId(@Param("productId") Integer productId);
}

mapper.FinanceAccountMapper

package com.spring.dataservice.mapper;

import com.spring.api.model.FinanceAccount;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;

public interface FinanceAccountMapper {
    int deleteByPrimaryKey(Integer id);
    int insert(FinanceAccount record);
    int insertSelective(FinanceAccount record);
    FinanceAccount selectByPrimaryKey(Integer id);
    int updateByPrimaryKeySelective(FinanceAccount record);
    int updateByPrimaryKey(FinanceAccount record);
    /*给uid的记录上锁*/
    FinanceAccount selectByUidForUpdate(@Param("uid") Integer uid);
    /*更新资金*/
    int updateAvailableMoneyByInvest(@Param("uid") Integer uid, @Param("money") BigDecimal money);
}

mapper.IncomeRecordMapper

package com.spring.dataservice.mapper;

import com.spring.api.model.IncomeRecord;

public interface IncomeRecordMapper {
    int deleteByPrimaryKey(Integer id);
    int insert(IncomeRecord record);
    int insertSelective(IncomeRecord record);
    IncomeRecord selectByPrimaryKey(Integer id);
    int updateByPrimaryKeySelective(IncomeRecord record);
    int updateByPrimaryKey(IncomeRecord record);
}

mapper.ProductInfoMapper

package com.spring.dataservice.mapper;

import com.spring.api.model.ProductInfo;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public interface ProductInfoMapper {
    /*利率平均值*/
    BigDecimal selectAvgRate();
    /*按产品类型分页查询*/
    List<ProductInfo> selectByTypeLimit(@Param("ptype") Integer ptype,
                                        @Param("offset") Integer offset,
                                        @Param("rows") Integer rows);
    /*某个产品类型的记录总数*/
    Integer selectCountByType(@Param("ptype") Integer pType);
    int deleteByPrimaryKey(Integer id);
    int insert(ProductInfo record);
    int insertSelective(ProductInfo record);
    ProductInfo selectByPrimaryKey(Integer id);
    int updateByPrimaryKeySelective(ProductInfo record);
    int updateByPrimaryKey(ProductInfo record);
    /*扣除产品剩余可投资金额*/
    int updateLeftProductMoney(@Param("id") Integer productId, @Param("money") BigDecimal money);
    /*更新产品为满标*/
    int updateSelled(@Param("id") Integer productId);
    /*满标的理财列表*/
    List<ProductInfo> selectFullTimeProducts(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime);
    /*更新状态*/
    int updateStatus(@Param("id") Integer id, @Param("newStatus") int newStatus);
}

mapper.RechargeRecordMapper

package com.spring.dataservice.mapper;

import com.spring.api.model.RechargeRecord;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface RechargeRecordMapper {
    int deleteByPrimaryKey(Integer id);
    int insert(RechargeRecord record);
    int insertSelective(RechargeRecord record);
    RechargeRecord selectByPrimaryKey(Integer id);
    int updateByPrimaryKeySelective(RechargeRecord record);
    int updateByPrimaryKey(RechargeRecord record);
    List<RechargeRecord> selectByUid(@Param("uid") Integer uid,
                                     @Param("offset") int offset,
                                     @Param("rows") Integer rows);
}

mapper.UserMapper

package com.spring.dataservice.mapper;

import com.spring.api.model.User;
import com.spring.api.pojo.UserAccountInfo;
import org.apache.ibatis.annotations.Param;

public interface UserMapper {
    //统计注册人数
    int selectCountUser();
    /*使用手机号查询用户*/
    User selectByPhone(@Param("phone") String phone);
    /*添加记录,获取主键值*/
    int insertReturnPrimaryKey(User user);
    int deleteByPrimaryKey(Integer id);
    int insert(User record);
    int insertSelective(User record);
    User selectByPrimaryKey(Integer id);
    int updateByPrimaryKeySelective(User record);
    int updateByPrimaryKey(User record);
    /*登录*/
    User selectLogin(@Param("phone") String phone, @Param("loginPassword") String newPassword);
    /*更新实名认证信息*/
    int updateRealname(@Param("phone") String phone, @Param("name") String name, @Param("idCard") String idCard);
    /*查询用户信息*/
    UserAccountInfo selectUserAccountById(@Param("uid") Integer uid);
}
  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值