Browse Source

feat:教师端课酬

Joburgess 4 years ago
parent
commit
b4033a9c61

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleTeacherSalaryDao.java

@@ -552,7 +552,7 @@ public interface CourseScheduleTeacherSalaryDao extends BaseDAO<Long, CourseSche
 	 * @param year:
 	 * @return java.util.List<java.util.Map<java.lang.String,java.math.BigDecimal>>
 	 */
-	List<Map<String, BigDecimal>> teacherIncomeStat(@Param("teacherId") Integer teacherId,
+	List<LocalDateBigDecimalMapDto> teacherIncomeStat(@Param("teacherId") Integer teacherId,
 													@Param("year") Integer year,
 													@Param("month") Integer month);
 

+ 51 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/LocalDateBigDecimalMapDto.java

@@ -0,0 +1,51 @@
+package com.ym.mec.biz.dal.dto;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.Date;
+
+/**
+ * @Author Joburgess
+ * @Date 2021/4/21 0021
+ */
+public class LocalDateBigDecimalMapDto {
+
+    private Date date;
+
+    private String dateStr;
+
+    private BigDecimal amount;
+
+    public LocalDateBigDecimalMapDto(Date date, String dateStr, BigDecimal amount) {
+        this.date = date;
+        this.dateStr = dateStr;
+        this.amount = amount;
+    }
+
+    public LocalDateBigDecimalMapDto() {
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public String getDateStr() {
+        return dateStr;
+    }
+
+    public void setDateStr(String dateStr) {
+        this.dateStr = dateStr;
+    }
+
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount) {
+        this.amount = amount;
+    }
+}

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleTeacherSalaryService.java

@@ -282,7 +282,7 @@ public interface CourseScheduleTeacherSalaryService extends BaseService<Long, Co
      * @param year:
      * @return java.util.Map<java.lang.String,java.math.BigDecimal>
      */
-    Map<String, BigDecimal> teacherIncomeStat(Integer teacherId, Integer year, Integer month);
+    List<LocalDateBigDecimalMapDto> teacherIncomeStat(Integer teacherId, Integer year, Integer month);
 
     /**
      * @describe 推送查看今日收入提醒

+ 34 - 12
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleTeacherSalaryServiceImpl.java

@@ -2147,22 +2147,44 @@ public class CourseScheduleTeacherSalaryServiceImpl extends BaseServiceImpl<Long
     }
 
     @Override
-    public Map<String, BigDecimal> teacherIncomeStat(Integer teacherId, Integer year, Integer month) {
-        List<Map<String, BigDecimal>> monthIncomeMapList = courseScheduleTeacherSalaryDao.teacherIncomeStat(teacherId, year, month);
-        Map<String, BigDecimal> monthIncomeMap = MapUtil.convertIntegerMap(monthIncomeMapList);
-        LocalDate now = LocalDate.now();
-        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
+    public List<LocalDateBigDecimalMapDto> teacherIncomeStat(Integer teacherId, Integer year, Integer month) {
+        List<LocalDateBigDecimalMapDto> monthIncomeMapList = courseScheduleTeacherSalaryDao.teacherIncomeStat(teacherId, year, month);
+        if(CollectionUtils.isEmpty(monthIncomeMapList)){
+            return monthIncomeMapList;
+        }
+
+        if(Objects.isNull(month)){
+            Set<String> months = monthIncomeMapList.stream().map(e -> DateUtil.dateToString(e.getDate(), "yyyy-MM")).collect(Collectors.toSet());
 
-        LocalDate startDate = LocalDate.of(year, 1, 1);
-        while (startDate.compareTo(now)<=0&&year.equals(startDate.get(ChronoField.YEAR))){
-            String monthStr = dateFormatter.format(startDate);
-            if(!monthIncomeMap.containsKey(monthStr)){
-                monthIncomeMap.put(monthStr, BigDecimal.ZERO);
+            LocalDate now = LocalDate.now();
+            DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
+
+            LocalDate startDate = LocalDate.of(year, Objects.isNull(month)?1:month, 1);
+            while (startDate.compareTo(now)<=0&&year.equals(startDate.get(ChronoField.YEAR))){
+                String dateStr = dateFormatter.format(startDate);
+                if(!months.contains(dateStr)){
+                    monthIncomeMapList.add(new LocalDateBigDecimalMapDto(Date.from(startDate.atStartOfDay(DateUtil.zoneId).toInstant()), dateStr, BigDecimal.ZERO));
+                }
+                startDate = startDate.plusMonths(1);
+            }
+        }else{
+            Set<String> dates = monthIncomeMapList.stream().map(e -> DateUtil.dateToString(e.getDate(), "yyyy-MM-dd")).collect(Collectors.toSet());
+
+            LocalDate now = LocalDate.now();
+
+            LocalDate startDate = LocalDate.of(year, Objects.isNull(month)?1:month, 1);
+            while (startDate.compareTo(now)<=0&&year.equals(startDate.get(ChronoField.YEAR))){
+                String dateStr = DateUtil.dateFormatter.format(startDate);
+                if(!dates.contains(dateStr)){
+                    monthIncomeMapList.add(new LocalDateBigDecimalMapDto(Date.from(startDate.atStartOfDay(DateUtil.zoneId).toInstant()), dateStr, BigDecimal.ZERO));
+                }
+                startDate = startDate.plusDays(1);
             }
-            startDate = startDate.plusMonths(1);
         }
 
-        return monthIncomeMap;
+        monthIncomeMapList.sort(Comparator.comparing(LocalDateBigDecimalMapDto::getDate));
+
+        return monthIncomeMapList;
     }
 
     @Override

+ 17 - 4
mec-biz/src/main/resources/config/mybatis/CourseScheduleTeacherSalaryMapper.xml

@@ -1102,10 +1102,17 @@
 			</if>
 	</select>
 
-	<select id="teacherIncomeStat" resultType="map">
+	<select id="teacherIncomeStat" resultType="com.ym.mec.biz.dal.dto.LocalDateBigDecimalMapDto">
 		SELECT
-			DATE_FORMAT( cs.class_date_, '%Y-%m' ) AS 'key',
-			SUM( csts.actual_salary_ ) AS 'value'
+			<if test="month==null">
+				CONCAT(DATE_FORMAT( cs.class_date_, '%Y-%m' ), '-01') date,
+				CONCAT(DATE_FORMAT( cs.class_date_, '%Y-%m' )) dateStr,
+			</if>
+			<if test="month!=null">
+				DATE_FORMAT( cs.class_date_, '%Y-%m-%d' ) date,
+				DATE_FORMAT( cs.class_date_, '%Y-%m-%d' ) dateStr,
+			</if>
+			SUM( csts.actual_salary_ ) amount
 		FROM
 			course_schedule_teacher_salary csts
 				LEFT JOIN course_schedule cs ON csts.course_schedule_id_ = cs.id_
@@ -1121,7 +1128,13 @@
 				AND MONTH(cs.class_date_) = #{month}
 			</if>
 		  AND csts.settlement_time_ IS NOT NULL
-		GROUP BY MONTH(cs.class_date_)
+		GROUP BY
+			<if test="month==null">
+				MONTH(cs.class_date_)
+			</if>
+			<if test="month!=null">
+				DATE_FORMAT( cs.class_date_, '%Y-%m-%d' )
+			</if>
 	</select>
 
     <select id="getTodayHasCourseTeacherIds" resultType="int">