浏览代码

老师粉丝查询,统计指标查询

Eric 2 年之前
父节点
当前提交
e72a9e71d1

+ 42 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/TeacherController.java

@@ -1,5 +1,9 @@
 package com.yonge.cooleshow.admin.controller;
 
+import com.yonge.cooleshow.admin.io.request.teacher.TeacherVO;
+import com.yonge.cooleshow.biz.dal.vo.MyFens;
+import com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherWrapper;
+import com.yonge.toolset.base.page.QueryInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -9,6 +13,8 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
 import java.util.stream.Collectors;
 
 import javax.servlet.http.HttpServletResponse;
@@ -17,6 +23,7 @@ import javax.validation.Valid;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -246,4 +253,39 @@ public class TeacherController extends BaseController {
         teacherService.updateStyleVideo(teacherDto.getUserId(), teacherDto.getStyleVideo(), teacherDto.getMessage());
         return succeed();
     }
+
+    /**
+     * 查询老师统计指标
+     * @param userId 老师ID
+     * @return HttpResponseResult<TeacherVO.TeacherStat>
+     */
+    @ApiOperation(value = "详情", notes = "传入id")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "id", paramType = "path", dataType = "long", required = true),
+    })
+    @GetMapping("/stat/{id}")
+    public HttpResponseResult<TeacherVO.TeacherStat> teacherStatInfo(@PathVariable("id") Long userId) {
+
+        // 老师统计指标
+        TeacherWrapper.TeacherStatInfo statInfo = teacherService.findTeacherStatInfoById(userId);
+
+        return succeed(TeacherVO.TeacherStat.from(statInfo.jsonString()));
+    }
+
+    /**
+     * 老师粉丝信息查询
+     * @param query TeacherVO.TeacherFansQuery
+     * @return HttpResponseResult<PageInfo<MyFens>>
+     */
+    @ApiOperation(value = "我的粉丝")
+    @PostMapping(value = "/myFans")
+    public HttpResponseResult<PageInfo<MyFens>> queryMyFans(@RequestBody TeacherVO.TeacherFansQuery query) {
+
+        if (Optional.ofNullable(query.getTeacherId()).orElse(0L) <= 0) {
+            return failed("无效的请求参数");
+        }
+
+        IPage<MyFens> pages = teacherService.queryMyFans(PageUtil.getPage(query), query.getTeacherId());
+        return succeed(PageUtil.pageInfo(pages));
+    }
 }

+ 58 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/io/request/teacher/TeacherVO.java

@@ -0,0 +1,58 @@
+package com.yonge.cooleshow.admin.io.request.teacher;
+
+import com.alibaba.fastjson.JSON;
+import com.yonge.toolset.base.page.QueryInfo;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 老师端统计信息
+ * Created by Eric.Shang on 2022/10/8.
+ */
+public class TeacherVO {
+
+    /**
+     * 老师统计指标信息
+     */
+    @Data
+    @NoArgsConstructor
+    @AllArgsConstructor
+    public static class TeacherStat implements Serializable {
+
+        @ApiModelProperty("星级")
+        private Integer starGrade;
+        @ApiModelProperty("粉丝数")
+        private Integer fansNum;
+        @ApiModelProperty("已上课时")
+        private Integer expTime;
+        @ApiModelProperty("未上课时")
+        private Integer unExpTime;
+        @ApiModelProperty("专辑数 ")
+        private Integer musicAlbumNum;
+        @ApiModelProperty("曲谱数 ")
+        private Integer musicSheetNum;
+        @ApiModelProperty("学生数")
+        private Integer studentNums;
+
+        public static TeacherStat from(String recv) {
+
+            return JSON.parseObject(recv, TeacherStat.class);
+        }
+    }
+
+    /**
+     * 老师粉丝数
+     */
+    @Data
+    @NoArgsConstructor
+    @AllArgsConstructor
+    public static class TeacherFansQuery extends QueryInfo {
+
+        @ApiModelProperty("老师ID")
+        private Long teacherId;
+    }
+}

+ 8 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TeacherService.java

@@ -10,6 +10,7 @@ import com.yonge.cooleshow.biz.dal.entity.Teacher;
 import com.yonge.cooleshow.biz.dal.entity.TeacherStyleVideo;
 import com.yonge.cooleshow.biz.dal.enums.TeacherTagEnum;
 import com.yonge.cooleshow.biz.dal.vo.*;
+import com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherWrapper;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 
 import java.util.List;
@@ -158,4 +159,11 @@ public interface TeacherService extends IService<Teacher> {
      * @return TeacherVo
      */
     TeacherVo findTeacherDetailInfo(Long teacherId);
+
+    /**
+     * 老师统计指标信息
+     * @param userId 用户ID
+     * @return TeacherWrapper.TeacherStatInfo
+     */
+    TeacherWrapper.TeacherStatInfo findTeacherStatInfoById(Long userId);
 }

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

@@ -15,6 +15,7 @@ import javax.annotation.Resource;
 
 import com.google.common.collect.Lists;
 import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
+import com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherWrapper;
 import org.redisson.api.RMap;
 import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
@@ -722,4 +723,45 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
         return teacherInfo;
     }
 
+    /**
+     * 老师统计指标信息
+     *
+     * @param userId 用户ID
+     * @return TeacherWrapper.TeacherStatInfo
+     */
+    @Override
+    public TeacherWrapper.TeacherStatInfo findTeacherStatInfoById(Long userId) {
+
+        TeacherWrapper.TeacherStatInfo wrapper = TeacherWrapper.TeacherStatInfo.builder()
+                .fansNum(0)
+                .studentNums(0)
+                .starGrade(0)
+                .expTime(0)
+                .unExpTime(0)
+                .musicAlbumNum(0)
+                .musicSheetNum(0)
+                .build();
+
+        // 查询老师统计指标
+        TeacherTotal total = totalService.getTotalById(userId);
+        if (Objects.nonNull(total)) {
+
+            wrapper.starGrade(total.getStarGrade().intValue())
+                    .fansNum(total.getFansNum())
+                    .expTime(total.getExpTime())
+                    .unExpTime(total.getUnExpTime())
+                    .musicAlbumNum(total.getMusicAlbumNum())
+                    .musicSheetNum(total.getMusicSheetNum());
+        }
+
+        // 老师学生端人数统计
+        List<Long> teacherIds = Lists.newArrayList(userId);
+        Map<Long, Integer> studentNumsMap = getBaseMapper().selectTeacherStudentNumberStatInfo(teacherIds).stream()
+                .collect(Collectors.toMap(StatGroupWrapper::getId, StatGroupWrapper::getTotal, (o, n) -> n));
+
+        wrapper.setStudentNums(studentNumsMap.getOrDefault(userId, 0));
+
+        return wrapper;
+    }
+
 }

+ 35 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/MyFens.java

@@ -6,8 +6,12 @@ import com.yonge.cooleshow.biz.dal.enums.MK;
 import com.yonge.cooleshow.common.entity.BaseEntity;
 import com.yonge.cooleshow.common.enums.YesOrNoEnum;
 import io.swagger.annotations.ApiModelProperty;
+import org.joda.time.DateTime;
+import org.joda.time.Period;
+import org.joda.time.PeriodType;
 
 import java.util.Date;
+import java.util.Objects;
 
 /**
  * @Author: cy
@@ -15,7 +19,7 @@ import java.util.Date;
  */
 public class MyFens extends BaseEntity {
 
-    @ApiModelProperty("昵称")
+    @ApiModelProperty("用户编号")
     private String userId;
     @ApiModelProperty("昵称")
     private String userName;
@@ -37,6 +41,12 @@ public class MyFens extends BaseEntity {
     @JsonFormat(pattern = MK.TIME_PATTERN, timezone = MK.TIME_ZONE)
     private Date starTime;
 
+    @ApiModelProperty("出生日期")
+    private Date birthdate;
+
+    @ApiModelProperty("出生日期")
+    private Integer age;
+
     public String getSubjectName() {
         return subjectName;
     }
@@ -112,4 +122,28 @@ public class MyFens extends BaseEntity {
     public void setStarTime(Date starTime) {
         this.starTime = starTime;
     }
+
+    public void setGender(GenderEnum gender) {
+        this.gender = gender;
+    }
+
+    public Date getBirthdate() {
+        return birthdate;
+    }
+
+    public void setBirthdate(Date birthdate) {
+        this.birthdate = birthdate;
+    }
+
+    public Integer getAge() {
+        if (Objects.nonNull(getBirthdate())) {
+
+            return new Period(new DateTime(getBirthdate()), DateTime.now(), PeriodType.years()).getYears();
+        }
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
 }

+ 77 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/teacher/TeacherWrapper.java

@@ -0,0 +1,77 @@
+package com.yonge.cooleshow.biz.dal.wrapper.teacher;
+
+import com.alibaba.fastjson.JSON;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * Created by Eric.Shang on 2022/10/8.
+ */
+public class TeacherWrapper {
+
+    /**
+     * 老师统计指标信息
+     */
+    @Data
+    @Builder
+    @NoArgsConstructor
+    @AllArgsConstructor
+    public static class TeacherStatInfo implements Serializable {
+
+        // 星级
+        private Integer starGrade;
+        // 粉丝数
+        private Integer fansNum;
+        // 已上课时
+        private Integer expTime;
+        // 未上课时
+        private Integer unExpTime;
+        // 专辑数
+        private Integer musicAlbumNum;
+        // 曲谱数
+        private Integer musicSheetNum;
+        // 学生数
+        private Integer studentNums;
+
+        public String jsonString() {
+
+            return JSON.toJSONString(this);
+        }
+
+
+        public TeacherStatInfo starGrade(Integer starGrade) {
+            this.starGrade = starGrade;
+            return this;
+        }
+
+        public TeacherStatInfo fansNum(Integer fansNum) {
+            this.fansNum = fansNum;
+            return this;
+        }
+
+        public TeacherStatInfo expTime(Integer expTime) {
+            this.expTime = expTime;
+            return this;
+        }
+
+        public TeacherStatInfo unExpTime(Integer unExpTime) {
+            this.unExpTime = unExpTime;
+            return this;
+        }
+
+        public TeacherStatInfo musicAlbumNum(Integer musicAlbumNum) {
+            this.musicAlbumNum = musicAlbumNum;
+            return this;
+        }
+
+        public TeacherStatInfo musicSheetNum(Integer musicSheetNum) {
+            this.musicSheetNum = musicSheetNum;
+            return this;
+        }
+
+    }
+}

+ 1 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/TeacherMapper.xml

@@ -256,6 +256,7 @@
             u.real_name_ AS realName,
             u.gender_ AS gender,
             u.phone_ AS phone,
+            u.birthdate_ AS birthdate,
             (SELECT group_concat(name_) FROM `subject` WHERE find_in_set(id_,sr.subject_id_)) AS subjectName,
             if(sr.membership_start_time_ &lt;= now() and sr.membership_end_time_ &gt;= now(),1,0) AS isVip
         FROM student_star s