chore: initialize qiming workspace repository
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.xspaceagi.subscription.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("subscription_plan")
|
||||
public class Plan {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
private BigDecimal firstPrice;
|
||||
|
||||
private Integer period;
|
||||
|
||||
private BigDecimal creditAmount;
|
||||
|
||||
private Integer callLimitCount;
|
||||
|
||||
private Boolean functionOnly;
|
||||
|
||||
private Boolean isHot;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String bizType;
|
||||
|
||||
private String bizId;
|
||||
|
||||
private String groupIds;
|
||||
|
||||
private String extra;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.xspaceagi.subscription.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.xspaceagi.subscription.spec.enums.BizTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("user_subscription")
|
||||
public class UserSubscription {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Long planId;
|
||||
|
||||
private BizTypeEnum bizType;
|
||||
|
||||
private String bizId;
|
||||
|
||||
private Integer period;
|
||||
|
||||
private Date startTime;
|
||||
|
||||
private Date endTime;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Integer callUsedCount;
|
||||
|
||||
private Date nextResetTime;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private String extra;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xspaceagi.subscription.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.subscription.infra.dao.entity.Plan;
|
||||
import com.xspaceagi.subscription.sdk.dto.PlanQueryRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PlanMapper extends BaseMapper<Plan> {
|
||||
|
||||
List<Plan> selectListWithFilters(@Param("query") PlanQueryRequest query);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.xspaceagi.subscription.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.subscription.infra.dao.entity.UserSubscription;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserSubscriptionMapper extends BaseMapper<UserSubscription> {
|
||||
|
||||
@Select("SELECT * FROM user_subscription WHERE user_id = #{userId} AND plan_id = #{planId}")
|
||||
UserSubscription selectByUserIdAndPlanId(@Param("userId") Long userId, @Param("planId") Long planId);
|
||||
|
||||
@Update("UPDATE user_subscription SET end_time = #{endTime}, modified = NOW() WHERE id = #{id}")
|
||||
int updateEndTime(@Param("id") Long id, @Param("endTime") Date endTime);
|
||||
|
||||
@Update("UPDATE user_subscription SET start_time = #{startTime}, end_time = #{endTime}, status = #{status}, modified = NOW() WHERE id = #{id}")
|
||||
int updatePeriod(@Param("id") Long id, @Param("startTime") Date startTime,
|
||||
@Param("endTime") Date endTime, @Param("status") Integer status);
|
||||
|
||||
java.util.Map<String, Object> selectStatsByPlanBiz(@Param("bizType") String bizType,
|
||||
@Param("bizId") String bizId,
|
||||
@Param("todayStart") java.util.Date todayStart,
|
||||
@Param("monthStart") java.util.Date monthStart);
|
||||
|
||||
List<UserSubscription> selectByPlanBiz(@Param("bizType") String bizType,
|
||||
@Param("bizId") String bizId,
|
||||
@Param("offset") int offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
Long countByPlanBiz(@Param("bizType") String bizType,
|
||||
@Param("bizId") String bizId);
|
||||
|
||||
@Update("UPDATE user_subscription SET call_used_count = 0, next_reset_time = #{nextResetTime}, modified = NOW() WHERE id = #{id}")
|
||||
int resetCallCount(@Param("id") Long id, @Param("nextResetTime") Date nextResetTime);
|
||||
|
||||
@Update("UPDATE user_subscription SET call_used_count = call_used_count + #{count}, modified = NOW() WHERE id = #{id}")
|
||||
int incrementCallCount(@Param("id") Long id, @Param("count") Integer count);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.subscription.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.subscription.infra.dao.entity.Plan;
|
||||
|
||||
public interface IPlanService extends IService<Plan> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.subscription.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.subscription.infra.dao.entity.UserSubscription;
|
||||
|
||||
public interface IUserSubscriptionService extends IService<UserSubscription> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.subscription.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.subscription.infra.dao.entity.Plan;
|
||||
import com.xspaceagi.subscription.infra.dao.mapper.PlanMapper;
|
||||
import com.xspaceagi.subscription.infra.dao.service.IPlanService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements IPlanService {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.subscription.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.subscription.infra.dao.entity.UserSubscription;
|
||||
import com.xspaceagi.subscription.infra.dao.mapper.UserSubscriptionMapper;
|
||||
import com.xspaceagi.subscription.infra.dao.service.IUserSubscriptionService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserSubscriptionServiceImpl extends ServiceImpl<UserSubscriptionMapper, UserSubscription> implements IUserSubscriptionService {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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.xspaceagi.subscription.infra.dao.mapper.PlanMapper">
|
||||
|
||||
<select id="selectListWithFilters" resultType="com.xspaceagi.subscription.infra.dao.entity.Plan">
|
||||
SELECT * FROM subscription_plan
|
||||
<where>
|
||||
<if test="query.bizType != null">AND biz_type = #{query.bizType.code}</if>
|
||||
<if test="query.bizId != null">AND biz_id = #{query.bizId}</if>
|
||||
<if test="query.status != null">AND status = #{query.status}</if>
|
||||
<if test="query.keyword != null and query.keyword != ''">
|
||||
AND name LIKE CONCAT('%', #{query.keyword}, '%')
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY sort ASC, id ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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.xspaceagi.subscription.infra.dao.mapper.UserSubscriptionMapper">
|
||||
|
||||
<select id="selectStatsByPlanBiz" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
COUNT(*) AS totalCount,
|
||||
SUM(CASE WHEN us.created >= #{todayStart} THEN 1 ELSE 0 END) AS todayCount,
|
||||
SUM(CASE WHEN us.created >= #{monthStart} THEN 1 ELSE 0 END) AS monthCount
|
||||
FROM user_subscription us
|
||||
INNER JOIN subscription_plan sp ON us.plan_id = sp.id
|
||||
WHERE sp.biz_type = #{bizType} AND sp.biz_id = #{bizId}
|
||||
</select>
|
||||
|
||||
<select id="selectByPlanBiz" resultType="com.xspaceagi.subscription.infra.dao.entity.UserSubscription">
|
||||
SELECT us.*
|
||||
FROM user_subscription us
|
||||
WHERE us.biz_type = #{bizType} AND us.biz_id = #{bizId}
|
||||
ORDER BY us.created DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<select id="countByPlanBiz" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM user_subscription us
|
||||
INNER JOIN subscription_plan sp ON us.plan_id = sp.id
|
||||
WHERE sp.biz_type = #{bizType} AND sp.biz_id = #{bizId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user