From 62d4c7e8c56592df98d706dfa13684ffbb85ee3f Mon Sep 17 00:00:00 2001 From: lisy <linlangsur163@163.com> Date: 星期一, 10 七月 2023 17:51:32 +0800 Subject: [PATCH] 使用福利:积分商城接口开发 --- cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java | 54 +++++++ cloud-server-account/src/main/java/com/dsh/account/mapper/UserIntegralChangesMapper.java | 16 ++ cloud-server-account/src/main/java/com/dsh/account/mapper/xml/UserIntegralChangesMapper.xml | 8 + cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/MallRequest.java | 25 +++ cloud-server-account/src/main/java/com/dsh/account/web/UserIntegralChangesController.java | 21 +++ cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackageController.java | 2 cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/IntegralDetailsResponse.java | 35 +++++ cloud-server-account/src/main/java/com/dsh/account/service/impl/UserIntegralChangesServiceImpl.java | 99 ++++++++++++++ cloud-server-account/src/main/java/com/dsh/account/entity/UserIntegralChanges.java | 68 +++++++++ cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/PointMallDetailsResponse.java | 52 +++++++ cloud-server-account/src/main/java/com/dsh/account/service/UserIntegralChangesService.java | 19 ++ 11 files changed, 397 insertions(+), 2 deletions(-) diff --git a/cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java b/cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java index cbe0d58..0e5146c 100644 --- a/cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java +++ b/cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java @@ -6,6 +6,7 @@ import com.dsh.account.model.vo.userBenefitDetail.*; import com.dsh.account.service.RechargeRecordsService; import com.dsh.account.service.TAppUserService; +import com.dsh.account.service.UserIntegralChangesService; import com.dsh.account.util.ResultUtil; import com.dsh.account.util.TokenUtil; import io.swagger.annotations.ApiImplicitParam; @@ -41,6 +42,9 @@ @Autowired private RechargeRecordsService rechargeRService; + + @Autowired + private UserIntegralChangesService uicService; private final SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); @@ -210,7 +214,7 @@ */ @ResponseBody @PostMapping("/api/useBenefit/payment") - @ApiOperation(value = "充值中心-支付", tags = {"APP-开始上课"}) + @ApiOperation(value = "充值中心-支付", tags = {"APP-使用福利"}) @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @@ -228,5 +232,53 @@ } + /** + * 积分商城 + */ + @ResponseBody + @PostMapping("/api/useBenefit/integralMallList") + @ApiOperation(value = "积分商城", tags = {"APP-使用福利"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), + }) + public ResultUtil<PointMallDetailsResponse> pointsMallList(MallRequest request){ + try { + Integer userIdFormRedis = tokenUtil.getUserIdFormRedis(); + if(null == userIdFormRedis){ + return ResultUtil.tokenErr(); + } + // TODO: 2023/7/10 积分商品列表查询 + return ResultUtil.success(); + }catch (Exception e){ + return ResultUtil.runErr(); + } + } + + + /** + * 积分明细 + */ + @ResponseBody + @PostMapping("/api/useBenefit/integralMallList") + @ApiOperation(value = "积分明细", tags = {"APP-使用福利"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), + @ApiImplicitParam(value = "年月", name = "yearMonth", required = true, dataType = "string"), + @ApiImplicitParam(value = "记录(1充值 2扣除)", name = "recordId", required = true, dataType = "int"), + }) + public ResultUtil<IntegralDetailsResponse> pointDetails(String yearMonth, Integer recordId){ + try { + Integer userIdFormRedis = tokenUtil.getUserIdFormRedis(); + if(null == userIdFormRedis){ + return ResultUtil.tokenErr(); + } + return ResultUtil.success(uicService.queryUserPointsDetails(yearMonth,recordId,userIdFormRedis)); + }catch (Exception e){ + return ResultUtil.runErr(); + } + } + + + } diff --git a/cloud-server-account/src/main/java/com/dsh/account/entity/UserIntegralChanges.java b/cloud-server-account/src/main/java/com/dsh/account/entity/UserIntegralChanges.java new file mode 100644 index 0000000..7930442 --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/entity/UserIntegralChanges.java @@ -0,0 +1,68 @@ +package com.dsh.account.entity; + +import com.baomidou.mybatisplus.enums.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableName; +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotations.Version; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * <p> + * 用户积分变动记录 + * </p> + * + * @author jqs + * @since 2023-07-10 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("t_user_integral_changes") +public class UserIntegralChanges extends Model<UserIntegralChanges> { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + /** + * 用户id + */ + private Integer appUserId; + /** + * 积分类型(1=赠送积分,2=兑换商品,3=完成课后练习,4=观看教学视频) + */ + private Integer type; + /** + * 历史积分 + */ + private Integer oldIntegral; + /** + * 新积分 + */ + private Integer newIntegral; + /** + * 备注 + */ + private String remark; + /** + * 添加时间 + */ + private Date insertTime; + + + @Override + protected Serializable pkVal() { + return this.id; + } + +} diff --git a/cloud-server-account/src/main/java/com/dsh/account/mapper/UserIntegralChangesMapper.java b/cloud-server-account/src/main/java/com/dsh/account/mapper/UserIntegralChangesMapper.java new file mode 100644 index 0000000..5e9a97d --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/mapper/UserIntegralChangesMapper.java @@ -0,0 +1,16 @@ +package com.dsh.account.mapper; + +import com.dsh.account.entity.UserIntegralChanges; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +/** + * <p> + * 用户积分变动记录 Mapper 接口 + * </p> + * + * @author jqs + * @since 2023-07-10 + */ +public interface UserIntegralChangesMapper extends BaseMapper<UserIntegralChanges> { + +} diff --git a/cloud-server-account/src/main/java/com/dsh/account/mapper/xml/UserIntegralChangesMapper.xml b/cloud-server-account/src/main/java/com/dsh/account/mapper/xml/UserIntegralChangesMapper.xml new file mode 100644 index 0000000..b34ddbc --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/mapper/xml/UserIntegralChangesMapper.xml @@ -0,0 +1,8 @@ +<?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.dsh.account.mapper.UserIntegralChangesMapper"> + + <!-- 开启二级缓存 --> + <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> + +</mapper> diff --git a/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/IntegralDetailsResponse.java b/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/IntegralDetailsResponse.java new file mode 100644 index 0000000..32a6fed --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/IntegralDetailsResponse.java @@ -0,0 +1,35 @@ +package com.dsh.account.model.vo.userBenefitDetail; + + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class IntegralDetailsResponse { + + @ApiModelProperty(value = "可用积分") + private Integer wpGold; + + @ApiModelProperty(value = "记录列表") + private List<IntegralsData> detailList; + + @Data + public static class IntegralsData{ + + @ApiModelProperty(value = "名称") + private String consumeName; + + @ApiModelProperty(value = "时间") + private String consumeTime; + + @ApiModelProperty(value = "金额 例如 -90 ") + private String consumeAmount; + + @ApiModelProperty(value = "1扣减 2增加") + private Integer detailsType; + + } + +} diff --git a/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/MallRequest.java b/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/MallRequest.java new file mode 100644 index 0000000..89eb87c --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/MallRequest.java @@ -0,0 +1,25 @@ +package com.dsh.account.model.vo.userBenefitDetail; + + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class MallRequest { + + @ApiModelProperty(value = "经度") + private String lon; + + @ApiModelProperty(value = "纬度") + private String lat; + + @ApiModelProperty(value = "排序规则 1积分高到低 2积分从低到高 3兑换从高到低") + private Integer rank; + + @ApiModelProperty(value = "商品类型: 1实物 2课包 3门票 4优惠券") + private Integer goodsType; + + @ApiModelProperty(value = "搜索内容") + private String search; + +} diff --git a/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/PointMallDetailsResponse.java b/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/PointMallDetailsResponse.java new file mode 100644 index 0000000..287f537 --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/model/vo/userBenefitDetail/PointMallDetailsResponse.java @@ -0,0 +1,52 @@ +package com.dsh.account.model.vo.userBenefitDetail; + + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +@Data +public class PointMallDetailsResponse { + + @ApiModelProperty(value = "头像") + private String headImg; + + @ApiModelProperty(value = "姓名") + private String name; + + @ApiModelProperty(value = "可用积分") + private Integer integral; + + @ApiModelProperty(value = "商品列表") + private List<Goods> goods; + + + @Data + public static class Goods{ + + @ApiModelProperty(value = "商品id") + private Integer goodId; + + @ApiModelProperty(value = "商品封面图") + private String goodImg; + + @ApiModelProperty(value = "商品名称") + private String goodName; + + @ApiModelProperty(value = "金额") + private BigDecimal amount; + + @ApiModelProperty(value = "积分") + private Integer integral; + + @ApiModelProperty(value = "适用范围: 1 仅限会员 2仅限学员 3全部用户") + private Integer belongsType; + + @ApiModelProperty(value = "商品类型: 1实物 2课包 3门票 4优惠券") + private Integer goodsType; + + } + +} diff --git a/cloud-server-account/src/main/java/com/dsh/account/service/UserIntegralChangesService.java b/cloud-server-account/src/main/java/com/dsh/account/service/UserIntegralChangesService.java new file mode 100644 index 0000000..2e21559 --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/service/UserIntegralChangesService.java @@ -0,0 +1,19 @@ +package com.dsh.account.service; + +import com.baomidou.mybatisplus.service.IService; +import com.dsh.account.entity.UserIntegralChanges; +import com.dsh.account.model.vo.userBenefitDetail.IntegralDetailsResponse; + +/** + * <p> + * 用户积分变动记录 服务类 + * </p> + * + * @author jqs + * @since 2023-07-10 + */ +public interface UserIntegralChangesService extends IService<UserIntegralChanges> { + + IntegralDetailsResponse queryUserPointsDetails(String yearMonth, Integer recordId, Integer userIdFormRedis); + +} diff --git a/cloud-server-account/src/main/java/com/dsh/account/service/impl/UserIntegralChangesServiceImpl.java b/cloud-server-account/src/main/java/com/dsh/account/service/impl/UserIntegralChangesServiceImpl.java new file mode 100644 index 0000000..0280cee --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/service/impl/UserIntegralChangesServiceImpl.java @@ -0,0 +1,99 @@ +package com.dsh.account.service.impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.dsh.account.entity.TAppUser; +import com.dsh.account.entity.UserIntegralChanges; +import com.dsh.account.mapper.TAppUserMapper; +import com.dsh.account.mapper.UserIntegralChangesMapper; +import com.dsh.account.model.vo.userBenefitDetail.IntegralDetailsResponse; +import com.dsh.account.service.UserIntegralChangesService; +import com.dsh.account.util.DateTimeHelper; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * <p> + * 用户积分变动记录 服务实现类 + * </p> + * + * @author jqs + * @since 2023-07-10 + */ +@Service +public class UserIntegralChangesServiceImpl extends ServiceImpl<UserIntegralChangesMapper, UserIntegralChanges> implements UserIntegralChangesService { + + @Resource + private TAppUserMapper tauMapper; + + @Override + public IntegralDetailsResponse queryUserPointsDetails(String yearMonth, Integer recordId, Integer userIdFormRedis) { + IntegralDetailsResponse vo = new IntegralDetailsResponse(); + List<IntegralDetailsResponse.IntegralsData> details = new ArrayList<>(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm"); + + Date monthStart = null; + Date monthEnd = null; + if (StringUtils.hasText(yearMonth)) { + monthStart = DateTimeHelper.getCurrentIdetMouthStart(yearMonth); + monthEnd = DateTimeHelper.getCurrentIdeaMouthEnd(yearMonth); + } else { + monthStart = DateTimeHelper.getCurrentMouthStart(); + monthEnd = DateTimeHelper.getCurrentMouthEnd(); + } + List<UserIntegralChanges> userIntegralChanges = this.baseMapper.selectList(new EntityWrapper<UserIntegralChanges>() + .eq("appUserId",userIdFormRedis ) + .between("insertTime",monthStart,monthEnd) + .orderBy("insertTime",false)); + if (userIntegralChanges.size() > 0 ){ + for (UserIntegralChanges userIntegralChange : userIntegralChanges) { + IntegralDetailsResponse.IntegralsData detail= new IntegralDetailsResponse.IntegralsData(); + switch (userIntegralChange.getType()){ + case 1: + detail.setConsumeAmount("+"+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral())); + detail.setConsumeName("赠送积分"); + detail.setDetailsType(2); + break; + case 2: + detail.setConsumeAmount("-"+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral())); + detail.setConsumeName("兑换商品"); + detail.setDetailsType(1); + break; + case 3: + detail.setConsumeAmount("+"+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral())); + detail.setConsumeName("完成课后练习"); + detail.setDetailsType(2); + break; + case 4: + detail.setConsumeAmount("+"+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral())); + detail.setConsumeTime(simpleDateFormat.format(userIntegralChange.getInsertTime())); + detail.setConsumeName("观看教学视频"); + detail.setDetailsType(2); + break; + default: + break; + } + detail.setConsumeTime(simpleDateFormat.format(userIntegralChange.getInsertTime())); + details.add(detail); + } + if (null != recordId){ + details = details.stream() + .filter(obj -> obj instanceof IntegralDetailsResponse.IntegralsData) + .filter(obj -> Objects.equals(obj.getDetailsType(), recordId)) + .collect(Collectors.toList()); + } + TAppUser tAppUser = tauMapper.selectById(userIdFormRedis); + vo.setWpGold(tAppUser.getIntegral()); + vo.setDetailList(details); + } + return vo; + } +} diff --git a/cloud-server-account/src/main/java/com/dsh/account/web/UserIntegralChangesController.java b/cloud-server-account/src/main/java/com/dsh/account/web/UserIntegralChangesController.java new file mode 100644 index 0000000..fa2d85a --- /dev/null +++ b/cloud-server-account/src/main/java/com/dsh/account/web/UserIntegralChangesController.java @@ -0,0 +1,21 @@ +package com.dsh.account.web; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + * <p> + * 用户积分变动记录 前端控制器 + * </p> + * + * @author jqs + * @since 2023-07-10 + */ +@RestController +@RequestMapping("/user-integral-changes") +public class UserIntegralChangesController { + +} + diff --git a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackageController.java b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackageController.java index 1cc67b4..90843b4 100644 --- a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackageController.java +++ b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackageController.java @@ -53,7 +53,7 @@ */ @ResponseBody @PostMapping("/api/useBenefit/weekLimitedBenefit") - @ApiOperation(value = "使用福利-本周福利限时折扣列表", tags = {"APP-开始上课"}) + @ApiOperation(value = "本周福利-限时折扣列表", tags = {"APP-使用福利"}) @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "discountType",value = "默认显示 限时折扣 (1限时折扣 2赠送课时)") -- Gitblit v1.7.1