Browse Source

获取最近过期的专辑

zouxuan 1 week ago
parent
commit
17f489a8e2

+ 7 - 8
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/UserTenantAlbumRecordController.java

@@ -23,10 +23,7 @@ import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.List;
@@ -110,14 +107,16 @@ public class UserTenantAlbumRecordController extends BaseController {
         return R.defaultR();
     }
 
-
-
-
-
     @ApiOperation(value = "时长")
     @PostMapping("/info")
     public R<List<UserTenantAlbumRecordWrapper.Info>> info(@RequestBody UserTenantAlbumRecordWrapper.InfoQuery infoQuery) {
 
         return R.from(userTenantAlbumRecordService.info(infoQuery));
     }
+
+    @ApiOperation(value = "获取最近一次购买记录")
+    @GetMapping("/lastRecord")
+    public R<UserTenantAlbumRecordWrapper.LastUserTenantAlbumRecord> last(Long tenantAlbumId) {
+        return R.from(userTenantAlbumRecordService.last(sysUserService.getUserId(),tenantAlbumId));
+    }
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/UserTenantAlbumRecordService.java

@@ -95,4 +95,6 @@ public interface UserTenantAlbumRecordService extends IService<UserTenantAlbumRe
     IPage<UserTenantAlbumRecordWrapper.AdminUserTenantAlbumRecord> selectAdminPage(IPage<UserTenantAlbumRecordWrapper.AdminUserTenantAlbumRecord> page, UserTenantAlbumRecordWrapper.UserTenantAlbumRecordQuery query);
 
     List<UserTenantAlbumRecordWrapper.Info> info(UserTenantAlbumRecordWrapper.InfoQuery infoQuery);
+
+    UserTenantAlbumRecordWrapper.LastUserTenantAlbumRecord last(Long userId, Long tenantAlbumId);
 }

+ 41 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserTenantAlbumRecordServiceImpl.java

@@ -26,6 +26,7 @@ import com.yonge.toolset.base.exception.BizException;
 import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 import com.yonge.toolset.utils.date.DateUtil;
 import com.yonge.toolset.utils.obj.ObjectUtil;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -907,6 +908,46 @@ public class UserTenantAlbumRecordServiceImpl extends ServiceImpl<UserTenantAlbu
 
     }
 
+    @Override
+    public UserTenantAlbumRecordWrapper.LastUserTenantAlbumRecord last(Long userId,Long albumId) {
+        //获取最近有效期最近的一条记录,(没过期)
+        UserTenantAlbumRecord record = this.lambdaQuery()
+                .eq(UserTenantAlbumRecord::getUserId, userId)
+                .eq(UserTenantAlbumRecord::getEfficientFlag, true)
+                .eq(albumId != null, UserTenantAlbumRecord::getTenantAlbumId, albumId)
+                .orderByAsc(UserTenantAlbumRecord::getEndTime)
+                .orderByAsc(UserTenantAlbumRecord::getId)
+                .last("limit 1")
+                .one();
+        UserTenantAlbumRecordWrapper.LastUserTenantAlbumRecord lastUserTenantAlbumRecord = new UserTenantAlbumRecordWrapper.LastUserTenantAlbumRecord();
+        Long tenantAlbumId = null;
+        Date endTime = null;
+        if (record != null) {
+            tenantAlbumId = record.getTenantAlbumId();
+            endTime = record.getEndTime();
+        }else {
+            //获取最近一条记录已过期的记录
+            record = this.lambdaQuery()
+                    .eq(UserTenantAlbumRecord::getUserId, userId)
+                    .eq(UserTenantAlbumRecord::getEfficientFlag, false)
+                    .eq(albumId != null, UserTenantAlbumRecord::getTenantAlbumId, albumId)
+                    .orderByDesc(UserTenantAlbumRecord::getEndTime)
+                    .orderByAsc(UserTenantAlbumRecord::getId)
+                    .last("limit 1")
+                    .one();
+            if (record != null) {
+                tenantAlbumId = record.getTenantAlbumId();
+                endTime = record.getEndTime();
+            }
+        }
+        if (tenantAlbumId != null){
+            TenantAlbum tenantAlbum = tenantAlbumService.getById(tenantAlbumId);
+            lastUserTenantAlbumRecord.setTenantAlbumName(tenantAlbum.getName());
+            lastUserTenantAlbumRecord.setEndTime(endTime);
+        }
+        return lastUserTenantAlbumRecord;
+    }
+
 
     private void sendVipDeductionMessage(Long userId, Integer num,PeriodEnum period,String reason,String tenantAlbumName) {
         // 添加VIP时长短信

+ 11 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/UserTenantAlbumRecordWrapper.java

@@ -279,4 +279,15 @@ public class UserTenantAlbumRecordWrapper {
         private Boolean sendMsg;
     }
 
+    @Data
+    public static class LastUserTenantAlbumRecord {
+
+        @ApiModelProperty("机构专辑名称")
+        private String tenantAlbumName;
+
+        @ApiModelProperty("过期时间")
+        private Date endTime;
+
+    }
+
 }