package com.dsh.account.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.dsh.account.entity.TAppUser;
|
import com.dsh.account.entity.TStudent;
|
import com.dsh.account.feignclient.activity.IntroduceRewardsClient;
|
import com.dsh.account.feignclient.competition.DeductionCompetitionsClient;
|
import com.dsh.account.feignclient.competition.model.PurchaseRecordVo;
|
import com.dsh.account.feignclient.course.CancelListClient;
|
import com.dsh.account.feignclient.course.CourseSessionNameClient;
|
import com.dsh.account.feignclient.course.model.StuSessionDetailsVo;
|
import com.dsh.account.mapper.TAppUserMapper;
|
import com.dsh.account.mapper.TStudentMapper;
|
import com.dsh.account.model.vo.classDetails.classInsVo.ClassDetailsInsVo;
|
import com.dsh.account.model.vo.classDetails.classInsVo.StuDetailsReq;
|
import com.dsh.account.service.TStudentService;
|
import com.dsh.account.util.DateTimeHelper;
|
import com.dsh.account.util.ToolUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 学员信息 服务实现类
|
* </p>
|
*
|
* @author administrator
|
* @since 2023-06-14
|
*/
|
@Service
|
public class TStudentServiceImpl extends ServiceImpl<TStudentMapper, TStudent> implements TStudentService {
|
|
@Autowired
|
private CourseSessionNameClient sessionNameClient;
|
|
@Autowired
|
private DeductionCompetitionsClient dcttClient;
|
|
@Autowired
|
private CancelListClient cancelcClient;
|
|
@Autowired
|
private IntroduceRewardsClient idrClient;
|
|
@Autowired
|
private TAppUserMapper tauMapper;
|
|
@Override
|
public void addStuOfAppUser(StuDetailsReq stu,Integer appUserId) {
|
TStudent student = new TStudent();
|
student.setAppUserId(appUserId);
|
student.setName(stu.getName());
|
student.setHeadImg(stu.getHeadImg());
|
student.setPhone(ToolUtil.isNotEmpty(stu.getPhone()) ? stu.getPhone() : "");
|
student.setSex(stu.getSex());
|
student.setIdCard(ToolUtil.isNotEmpty(stu.getIdCard())?stu.getIdCard() : "");
|
student.setBirthday(new Date(stu.getBirthday()));
|
student.setHeight(stu.getHeight());
|
student.setWeight(stu.getWeight());
|
BigDecimal bigDecimal = BigDecimal.valueOf(stu.getWeight());
|
BigDecimal multiply = bigDecimal.subtract(BigDecimal.valueOf(stu.getHeight())).multiply(bigDecimal.subtract(BigDecimal.valueOf(stu.getHeight())));
|
multiply.setScale(2);
|
student.setBmi(multiply.doubleValue());
|
student.setInsertTime(new Date());
|
student.setState(1);
|
this.baseMapper.insert(student);
|
}
|
|
@Override
|
public ClassDetailsInsVo querySessionDetailsDt(Integer userIdFormRedis, Integer lessonId, Integer stuId) {
|
ClassDetailsInsVo insVo = new ClassDetailsInsVo();
|
Date localMonthStart = DateTimeHelper.getCurrentMouthStart();
|
Date localMonthEnd = DateTimeHelper.getCurrentMouthEnd();
|
List<StuSessionDetailsVo> stuSessionList = sessionNameClient.getStuSessionList(localMonthStart,localMonthEnd,stuId,userIdFormRedis);
|
TStudent tStudent = this.baseMapper.selectById(stuId);
|
if (ToolUtil.isNotEmpty(tStudent)){
|
insVo.setStuId(tStudent.getId());
|
insVo.setStuName(tStudent.getName());
|
insVo.setStuImage(tStudent.getHeadImg());
|
|
List<PurchaseRecordVo> purchaseRecordVoList = new ArrayList<>();
|
|
List<PurchaseRecordVo> stuSourseList = dcttClient.getStuSourseList(localMonthStart,localMonthEnd,userIdFormRedis);
|
purchaseRecordVoList.addAll(stuSourseList);
|
List<PurchaseRecordVo> cancelCourseList = cancelcClient.getCancelCourseList(localMonthStart,localMonthEnd,stuId,userIdFormRedis);
|
purchaseRecordVoList.addAll(cancelCourseList);
|
List<PurchaseRecordVo> purchaseRecordVos = sessionNameClient.queryCourseDetails(localMonthStart,localMonthEnd,stuId,userIdFormRedis);
|
purchaseRecordVoList.addAll(purchaseRecordVos);
|
List<TAppUser> tAppUsers = tauMapper.selectList(new QueryWrapper<TAppUser>()
|
.eq("referralUserId",userIdFormRedis )
|
.between("insertTime",localMonthStart ,localMonthEnd));
|
List<Integer> userIds = tAppUsers.stream().map(TAppUser::getId).collect(Collectors.toList());
|
List<PurchaseRecordVo> purchaseRecordVos1 = idrClient.queryAppUsersofIntroduce(localMonthStart, localMonthEnd, userIds);
|
purchaseRecordVoList.addAll(purchaseRecordVos1);
|
insVo.setSessionNames(stuSessionList);
|
insVo.setDetails(dealDataOfTime(purchaseRecordVoList));
|
|
insVo.setTotalNums(0);
|
insVo.setDeductedNums(0);
|
insVo.setRemainingNums(0);
|
insVo.setDeductionClassHours(0);
|
}
|
|
return insVo;
|
}
|
|
|
public static List<PurchaseRecordVo> dealDataOfTime(List<PurchaseRecordVo> purchaseRecords) {
|
Collections.sort(purchaseRecords, new Comparator<PurchaseRecordVo>() {
|
@Override
|
public int compare(PurchaseRecordVo record1, PurchaseRecordVo record2) {
|
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd HH:mm");
|
Date date1 = null;
|
Date date2 = null;
|
try {
|
date1 = dateFormat.parse(record1.getPurchaseTime());
|
date2 = dateFormat.parse(record2.getPurchaseTime());
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
// 倒序排序
|
return date2.compareTo(date1);
|
}
|
});
|
return purchaseRecords;
|
}
|
|
|
// public static List<String> dealDataOfTime(List<String> timeStrings) {
|
// Collections.sort(timeStrings, new Comparator<String>() {
|
// @Override
|
// public int compare(String time1, String time2) {
|
// String[] parts1 = time1.split(" ");
|
// String[] parts2 = time2.split(" ");
|
// String[] dateParts1 = parts1[0].split("-");
|
// String[] dateParts2 = parts2[0].split("-");
|
// String[] timeParts1 = parts1[1].split(":");
|
// String[] timeParts2 = parts2[1].split(":");
|
// int month1 = Integer.parseInt(dateParts1[0]);
|
// int day1 = Integer.parseInt(dateParts1[1]);
|
// int hour1 = Integer.parseInt(timeParts1[0]);
|
// int minute1 = Integer.parseInt(timeParts1[1]);
|
// int month2 = Integer.parseInt(dateParts2[0]);
|
// int day2 = Integer.parseInt(dateParts2[1]);
|
// int hour2 = Integer.parseInt(timeParts2[0]);
|
// int minute2 = Integer.parseInt(timeParts2[1]);
|
// // 倒序排序
|
// if (month1 != month2) {
|
// return month2 - month1;
|
// } else if (day1 != day2) {
|
// return day2 - day1;
|
// } else if (hour1 != hour2) {
|
// return hour2 - hour1;
|
// } else {
|
// return minute2 - minute1;
|
// }
|
// }
|
// });
|
// return timeStrings;
|
// }
|
}
|