| | |
| | | package com.ks.vip.pojo.DO; |
| | | |
| | | import com.ks.vip.pojo.Enums.OrderTypeEnum; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | | |
| | |
| | | private Long id; |
| | | |
| | | @Column(name = "o_type") |
| | | private String type; |
| | | private OrderTypeEnum type; |
| | | |
| | | @Column(name = "o_combo_id") |
| | | private Long comboId; |
| | |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getType() { |
| | | public OrderTypeEnum getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(String type) { |
| | | public void setType(OrderTypeEnum type) { |
| | | this.type = type; |
| | | } |
| | | |
| | |
| | | * |
| | | * @param uid |
| | | * @param gradeId |
| | | * @param validDays |
| | | * @param validHours |
| | | * @param orderId |
| | | */ |
| | | public void saveVipCenter(String uid, Long gradeId, Integer validDays, Long orderId); |
| | | public void saveVipCenter(String uid, Long gradeId, Integer validHours, Long orderId); |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | public void delete(Long id); |
| | | |
| | | public void addOrderByWatchVideo(String uid, Long gradeId, Integer validDays) throws VipOrderException; |
| | | public void addOrderByWatchVideo(String uid, Long gradeId, Integer hour) throws VipOrderException; |
| | | |
| | | /** |
| | | * 是否可以 |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | public boolean canAddOrderByWatchVideo(String uid); |
| | | |
| | | } |
| | |
| | | |
| | | import com.ks.lib.common.dao.BaseMapper; |
| | | import com.ks.vip.pojo.DO.VipOrder; |
| | | import com.ks.vip.pojo.Enums.OrderTypeEnum; |
| | | import com.ks.vip.query.VipOrderQuery; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | |
| | | * @param type |
| | | * @return |
| | | */ |
| | | long countByTypeAndUid(@Param("uid") String uid, @Param("type") String type); |
| | | long countByTypeAndUid(@Param("uid") String uid, @Param("type") OrderTypeEnum type); |
| | | |
| | | } |
New file |
| | |
| | | package com.ks.vip.pojo.mybatishandler; |
| | | |
| | | import com.ks.vip.pojo.Enums.OrderTypeEnum; |
| | | import org.apache.ibatis.type.BaseTypeHandler; |
| | | import org.apache.ibatis.type.JdbcType; |
| | | |
| | | import java.sql.CallableStatement; |
| | | import java.sql.PreparedStatement; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | |
| | | |
| | | public class OrderTypeEnumHandler extends BaseTypeHandler<OrderTypeEnum> { |
| | | |
| | | @Override |
| | | public OrderTypeEnum getNullableResult(ResultSet arg0, String arg1) throws SQLException { |
| | | String key = arg0.getString(arg1); |
| | | if (arg0.wasNull()) { |
| | | return null; |
| | | } else { |
| | | return OrderTypeEnum.valueOf(key); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public OrderTypeEnum getNullableResult(ResultSet arg0, int arg1) throws SQLException { |
| | | String key = arg0.getString(arg1); |
| | | if (arg0.wasNull()) { |
| | | return null; |
| | | } else { |
| | | // 根据数据库中的key值,定位SexEnum子类 |
| | | return OrderTypeEnum.valueOf(key); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public OrderTypeEnum getNullableResult(CallableStatement arg0, int arg1) throws SQLException { |
| | | String key = arg0.getString(arg1); |
| | | if (arg0.wasNull()) { |
| | | return null; |
| | | } else { |
| | | // 根据数据库中的key值,定位SexEnum子类 |
| | | return OrderTypeEnum.valueOf(key); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void setNonNullParameter(PreparedStatement arg0, int arg1, OrderTypeEnum arg2, JdbcType arg3) |
| | | throws SQLException { |
| | | arg0.setString(arg1, arg2.name()); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | import com.ks.lijin.query.BaseDaoQuery; |
| | | import com.ks.vip.pojo.Enums.OrderTypeEnum; |
| | | |
| | | import java.util.Date; |
| | | |
| | | public class VipOrderQuery extends BaseDaoQuery { |
| | | |
| | |
| | | //状态 |
| | | public Integer state; |
| | | // 订单类型 |
| | | public String type; |
| | | public OrderTypeEnum type; |
| | | |
| | | //订单创建时间 |
| | | public Date maxCreateTime; |
| | | public Date minCreateTime; |
| | | |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void saveVipCenter(String uid, Long gradeId, Integer validDays, Long orderId) { |
| | | public void saveVipCenter(String uid, Long gradeId, Integer validHours, Long orderId) { |
| | | VipCenterRecord record = new VipCenterRecord(); |
| | | |
| | | VipCenter vipCenter = vipCenterMapper.selectForUpdate(uid); |
| | | if (vipCenter == null) { |
| | | Date startTime = new Date(); |
| | | Date endTime = DateUtil.plusDayDate(validDays, startTime); |
| | | Date endTime = new Date(startTime.getTime() + 1000 * 60 * 60L * validHours); |
| | | |
| | | vipCenter.setUid(uid); |
| | | vipCenter.setGradeId(gradeId); |
| | | vipCenter.setStartTime(startTime); |
| | | vipCenter.setEndTime(DateUtil.plusDayDate(validDays, new Date())); |
| | | vipCenter.setEndTime(endTime); |
| | | vipCenter.setCreateTime(new Date()); |
| | | vipCenterMapper.insertSelective(vipCenter); |
| | | |
| | |
| | | long nowTime = java.lang.System.currentTimeMillis(); |
| | | if (gradeId.longValue() == oldGradeId.longValue() && vipCenter.getEndTime().getTime() > nowTime) { |
| | | // 上次会员还未已结束 |
| | | endTime = DateUtil.plusDayDate(validDays, vipCenter.getEndTime()); |
| | | endTime = new Date(vipCenter.getEndTime().getTime() + 1000 * 60 * 60L * validHours); |
| | | } else { |
| | | startTime = new Date(); |
| | | endTime = DateUtil.plusDayDate(validDays, startTime); |
| | | endTime = new Date(startTime.getTime() + 1000 * 60 * 60L * validHours); |
| | | } |
| | | vipCenter.setStartTime(startTime); |
| | | vipCenter.setEndTime(endTime); |
| | |
| | | } |
| | | |
| | | // 判断订单类型: 首单、续费 |
| | | String orderType = OrderTypeEnum.buyNewly.name(); |
| | | OrderTypeEnum orderType = OrderTypeEnum.buyNewly; |
| | | long count = vipOrderMapper.countByTypeAndUid(t.getUid(), orderType); |
| | | if(count > 0) { |
| | | orderType = OrderTypeEnum.buyRenew.name(); |
| | | orderType = OrderTypeEnum.buyRenew; |
| | | } |
| | | |
| | | // 插入订单信息 |
| | |
| | | |
| | | /** |
| | | * 支付成功更新处理 |
| | | * |
| | | * @param order |
| | | * @return |
| | | */ |
| | |
| | | Integer validDays = vipCombo.getValidDays(); |
| | | |
| | | // 判断订单类型 |
| | | String orderType = OrderTypeEnum.buyNewly.name(); |
| | | OrderTypeEnum orderType = OrderTypeEnum.buyNewly; |
| | | long count = vipOrderMapper.countByTypeAndUid(order.getUid(), orderType); |
| | | if(count > 0) { |
| | | orderType = OrderTypeEnum.buyRenew.name(); |
| | | orderType = OrderTypeEnum.buyRenew; |
| | | } |
| | | |
| | | // order.setThreeOrderId(); TODO |
| | |
| | | vipOrderMapper.updateByPrimaryKeySelective(order); |
| | | |
| | | // 更新等级 |
| | | vipCenterService.saveVipCenter(order.getUid(), vipCombo.getGradeId(), validDays, order.getId() ); |
| | | vipCenterService.saveVipCenter(order.getUid(), vipCombo.getGradeId(), validDays * 24, order.getId()); |
| | | |
| | | return order; |
| | | } |
| | |
| | | import com.ks.vip.service.VipOrederService; |
| | | import org.apache.dubbo.config.annotation.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.DateUtil; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.ParseException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addOrderByWatchVideo(String uid, Long gradeId, Integer validDays) throws VipOrderException { |
| | | public void addOrderByWatchVideo(String uid, Long gradeId, Integer hour) throws VipOrderException { |
| | | if(StringUtil.isNullOrEmpty(uid)){ |
| | | throw new VipOrderException(1, "用户ID不能为空"); |
| | | } |
| | | if(gradeId == null){ |
| | | throw new VipOrderException(1, "等级ID不能为空"); |
| | | } |
| | | if(validDays == null || validDays.longValue() <= 0){ |
| | | throw new VipOrderException(1, "有效天数不能为空"); |
| | | if (hour == null || hour.longValue() <= 0) { |
| | | throw new VipOrderException(1, "有效小时数不能为空"); |
| | | } |
| | | if (!canAddOrderByWatchVideo(uid)) { |
| | | throw new VipOrderException(1, "今日次数已经用完"); |
| | | } |
| | | |
| | | |
| | | // 插入订单信息 唯一性处理TODO |
| | | VipOrder newOrder = new VipOrder(); |
| | | newOrder.setUid(uid); |
| | | newOrder.setType(OrderTypeEnum.watchVideo.name()); |
| | | newOrder.setType(OrderTypeEnum.watchVideo); |
| | | newOrder.setCreateTime(new Date()); |
| | | vipOrderMapper.insertSelective(newOrder); |
| | | |
| | | // 更新等级 |
| | | vipCenterService.saveVipCenter(uid, gradeId, validDays,newOrder.getId() ); |
| | | vipCenterService.saveVipCenter(uid, gradeId, hour, newOrder.getId()); |
| | | } |
| | | |
| | | @Override |
| | | public boolean canAddOrderByWatchVideo(String uid) { |
| | | long now = System.currentTimeMillis(); |
| | | VipOrderQuery vipOrderQuery = new VipOrderQuery(); |
| | | vipOrderQuery.uid = uid; |
| | | vipOrderQuery.type = OrderTypeEnum.watchVideo; |
| | | vipOrderQuery.minCreateTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now, "yyyy-MM-dd"), "yyyy-MM-dd")); |
| | | vipOrderQuery.maxCreateTime = DateUtil.plusDayDate(1, vipOrderQuery.minCreateTime); |
| | | long count = vipOrderMapper.count(vipOrderQuery); |
| | | //TODO 写入配置信息 |
| | | return count < 5; |
| | | } |
| | | } |
| | |
| | | <mapper namespace="com.ks.vip.mapper.VipOrderMapper"> |
| | | <resultMap id="BaseResultMap" type="com.ks.vip.pojo.DO.VipOrder"> |
| | | <id column="o_id" property="id" jdbcType="BIGINT"/> |
| | | <result column="o_type" property="type" jdbcType="VARCHAR"/> |
| | | <result column="o_type" property="type" typeHandler="com.ks.vip.pojo.mybatishandler.OrderTypeEnumHandler"/> |
| | | <result column="o_combo_id" property="comboId" jdbcType="BIGINT"/> |
| | | <result column="o_uid" property="uid" jdbcType="VARCHAR"/> |
| | | <result column="o_three_order_id" property="threeOrderId" jdbcType="VARCHAR"/> |
| | |
| | | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select |
| | | <include refid="Base_Column_List"/>from vip_order where o_id = #{id,jdbcType=BIGINT} |
| | | </select> |
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from vip_order where o_id = #{id,jdbcType=BIGINT}</delete> |
| | | <insert id="insert" parameterType="com.ks.vip.pojo.DO.VipOrder" useGeneratedKeys="true" keyProperty="id">insert into vip_order (o_id,o_type,o_combo_id,o_uid,o_three_order_id,o_pay_money,o_pay_time,o_pay_account,o_pay_way,o_end_time,o_start_time,o_state,o_creator_id,o_create_time,o_updator_id,o_update_time) values (#{id,jdbcType=BIGINT},#{type,jdbcType=VARCHAR},#{comboId,jdbcType=BIGINT},#{uid,jdbcType=VARCHAR},#{threeOrderId,jdbcType=VARCHAR},#{payMoney,jdbcType=DECIMAL},#{payTime,jdbcType=TIMESTAMP},#{payAccount,jdbcType=VARCHAR},#{payWay,jdbcType=VARCHAR},#{endTime,jdbcType=TIMESTAMP},#{startTime,jdbcType=TIMESTAMP},#{state,jdbcType=INTEGER},#{creatorId,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP},#{updatorId,jdbcType=BIGINT},#{updateTime,jdbcType=TIMESTAMP})</insert> |
| | | <insert id="insertSelective" parameterType="com.ks.vip.pojo.DO.VipOrder" useGeneratedKeys="true" keyProperty="id">insert into vip_order |
| | | <delete id="deleteByPrimaryKey" |
| | | parameterType="java.lang.Long">delete from vip_order where o_id = #{id,jdbcType=BIGINT}</delete> |
| | | <insert id="insert" parameterType="com.ks.vip.pojo.DO.VipOrder" useGeneratedKeys="true" |
| | | keyProperty="id">insert into vip_order (o_id,o_type,o_combo_id,o_uid,o_three_order_id,o_pay_money,o_pay_time,o_pay_account,o_pay_way,o_end_time,o_start_time,o_state,o_creator_id,o_create_time,o_updator_id,o_update_time) values (#{id,jdbcType=BIGINT},#{type,jdbcType=VARCHAR},#{comboId,jdbcType=BIGINT},#{uid,jdbcType=VARCHAR},#{threeOrderId,jdbcType=VARCHAR},#{payMoney,jdbcType=DECIMAL},#{payTime,jdbcType=TIMESTAMP},#{payAccount,jdbcType=VARCHAR},#{payWay,jdbcType=VARCHAR},#{endTime,jdbcType=TIMESTAMP},#{startTime,jdbcType=TIMESTAMP},#{state,jdbcType=INTEGER},#{creatorId,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP},#{updatorId,jdbcType=BIGINT},#{updateTime,jdbcType=TIMESTAMP})</insert> |
| | | <insert id="insertSelective" parameterType="com.ks.vip.pojo.DO.VipOrder" useGeneratedKeys="true" keyProperty="id"> |
| | | insert into vip_order |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="id != null">o_id,</if> |
| | | <if test="type != null">o_type,</if> |
| | |
| | | <if test="createTime != null">o_create_time,</if> |
| | | <if test="updatorId != null">o_updator_id,</if> |
| | | <if test="updateTime != null">o_update_time,</if> |
| | | </trim>values |
| | | </trim> |
| | | values |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="id != null">#{id,jdbcType=BIGINT},</if> |
| | | <if test="type != null">#{type,jdbcType=VARCHAR},</if> |
| | |
| | | <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if> |
| | | </trim> |
| | | </insert> |
| | | <update id="updateByPrimaryKey" parameterType="com.ks.vip.pojo.DO.VipOrder">update vip_order set o_type = #{type,jdbcType=VARCHAR},o_combo_id = #{comboId,jdbcType=BIGINT},o_uid = #{uid,jdbcType=VARCHAR},o_three_order_id = #{threeOrderId,jdbcType=VARCHAR},o_pay_money = #{payMoney,jdbcType=DECIMAL},o_pay_time = #{payTime,jdbcType=TIMESTAMP},o_pay_account = #{payAccount,jdbcType=VARCHAR},o_pay_way = #{payWay,jdbcType=VARCHAR},o_end_time = #{endTime,jdbcType=TIMESTAMP},o_start_time = #{startTime,jdbcType=TIMESTAMP},o_state = #{state,jdbcType=INTEGER},o_creator_id = #{creatorId,jdbcType=BIGINT},o_create_time = #{createTime,jdbcType=TIMESTAMP},o_updator_id = #{updatorId,jdbcType=BIGINT},o_update_time = #{updateTime,jdbcType=TIMESTAMP} where o_id = #{id,jdbcType=BIGINT}</update> |
| | | <update id="updateByPrimaryKey" |
| | | parameterType="com.ks.vip.pojo.DO.VipOrder">update vip_order set o_type = #{type,jdbcType=VARCHAR},o_combo_id = #{comboId,jdbcType=BIGINT},o_uid = #{uid,jdbcType=VARCHAR},o_three_order_id = #{threeOrderId,jdbcType=VARCHAR},o_pay_money = #{payMoney,jdbcType=DECIMAL},o_pay_time = #{payTime,jdbcType=TIMESTAMP},o_pay_account = #{payAccount,jdbcType=VARCHAR},o_pay_way = #{payWay,jdbcType=VARCHAR},o_end_time = #{endTime,jdbcType=TIMESTAMP},o_start_time = #{startTime,jdbcType=TIMESTAMP},o_state = #{state,jdbcType=INTEGER},o_creator_id = #{creatorId,jdbcType=BIGINT},o_create_time = #{createTime,jdbcType=TIMESTAMP},o_updator_id = #{updatorId,jdbcType=BIGINT},o_update_time = #{updateTime,jdbcType=TIMESTAMP} where o_id = #{id,jdbcType=BIGINT}</update> |
| | | <update id="updateByPrimaryKeySelective" parameterType="com.ks.vip.pojo.DO.VipOrder">update vip_order |
| | | <set> |
| | | <if test="type != null">o_type=#{type,jdbcType=VARCHAR},</if> |
| | |
| | | <if test="createTime != null">o_create_time=#{createTime,jdbcType=TIMESTAMP},</if> |
| | | <if test="updatorId != null">o_updator_id=#{updatorId,jdbcType=BIGINT},</if> |
| | | <if test="updateTime != null">o_update_time=#{updateTime,jdbcType=TIMESTAMP},</if> |
| | | </set> where o_id = #{id,jdbcType=BIGINT} |
| | | </set> |
| | | where o_id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | |
| | | |
| | |
| | | <if test="query.uid!=null">and o_uid=#{query.uid}</if> |
| | | <if test="query.threeOrderId!=null">and o_three_order_id=#{query.threeOrderId}</if> |
| | | <if test="query.state!=null">and o_state=#{query.state}</if> |
| | | <if test="query.minCreateTime!=null">and o_create_time>=#{query.minCreateTime}</if> |
| | | <if test="query.maxCreateTime!=null">and #{query.maxCreateTime} >o_create_time</if> |
| | | </sql> |
| | | |
| | | |
| | | <select id="listByPage" resultMap="BaseResultMap"> |
| | | select <include refid="Base_Column_List"/> from vip_order |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from vip_order |
| | | where 1=1 |
| | | <include refid="listWhere"/> |
| | | limit #{query.start},#{query.count} |
| | |
| | | |
| | | |
| | | <select id="getByThreeOrderId" resultMap="BaseResultMap"> |
| | | select <include refid="Base_Column_List"/> from vip_order |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from vip_order |
| | | where o_three_order_id=#{query.threeOrderId} |
| | | </select> |
| | | |
| | |
| | | select IFNULL(count(o_id),0) from vip_order |
| | | where o_uid = #{uid} and o_type=#{type} |
| | | </select> |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | </mapper> |