| | |
| | | package com.dsh.course.service.impl; |
| | | |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.course.entity.CoursePackageOrderStudent; |
| | | import com.dsh.course.mapper.CoursePackageOrderStudentMapper; |
| | | import com.dsh.course.entity.*; |
| | | import com.dsh.course.feignclient.model.RecordAppoint; |
| | | import com.dsh.course.feignclient.other.StoreClient; |
| | | import com.dsh.course.feignclient.other.model.Store; |
| | | import com.dsh.course.mapper.*; |
| | | import com.dsh.course.service.ICoursePackageOrderStudentService; |
| | | import com.dsh.course.service.ICoursePackageSchedulingService; |
| | | import com.dsh.course.util.DateTimeHelper; |
| | | import com.dsh.course.util.DateUtil; |
| | | import com.dsh.course.util.ToolUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | */ |
| | | @Service |
| | | public class CoursePackageOrderStudentServiceImpl extends ServiceImpl<CoursePackageOrderStudentMapper, CoursePackageOrderStudent> implements ICoursePackageOrderStudentService { |
| | | |
| | | |
| | | @Resource |
| | | private CoursePackageStudentMapper cpsMapper; |
| | | |
| | | @Resource |
| | | private CancelledClassesMapper cacMapper; |
| | | |
| | | @Autowired |
| | | private ICoursePackageSchedulingService coursePackageSchedulingService; |
| | | |
| | | @Resource |
| | | private TCoursePackageMapper tcpmapper; |
| | | |
| | | @Resource |
| | | private StoreClient stoClient; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<RecordAppoint> obtainStuClassDetails(Integer stuId, Integer appUserId, Integer pageNum) { |
| | | List<RecordAppoint> recordVoList = new ArrayList<>(); |
| | | List<CoursePackageOrderStudent> tCoursePackagePayments = this.baseMapper.selectList(new QueryWrapper<CoursePackageOrderStudent>() |
| | | .eq("studentId", stuId) |
| | | .eq("appUserId", appUserId) |
| | | .eq("status", 1) |
| | | .orderByDesc("insertTime")); |
| | | |
| | | List<Integer> ids = new ArrayList<>(); |
| | | for (CoursePackageOrderStudent tCoursePackagePayment : tCoursePackagePayments) { |
| | | ids.add(tCoursePackagePayment.getCoursePackageId()); |
| | | } |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd"); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm"); |
| | | if (tCoursePackagePayments.size() > 0) { |
| | | |
| | | // int pageNum = 1; // 页码 |
| | | int pageSize = 10; // 每页记录数 |
| | | Page<CoursePackageStudent> page = new Page<>(pageNum, pageSize); |
| | | IPage<CoursePackageStudent> coursePackageStudentPage = cpsMapper.selectPage(page, new QueryWrapper<CoursePackageStudent>() |
| | | .in("coursePackageId", ids) |
| | | .eq("studentId", stuId) |
| | | .eq("appUserId", appUserId) |
| | | .eq("reservationStatus", 1)); |
| | | List<CoursePackageStudent> coursePackageStudent1 = coursePackageStudentPage.getRecords(); |
| | | |
| | | |
| | | if (ToolUtil.isNotEmpty(coursePackageStudent1) && coursePackageStudent1.size() > 0) { |
| | | TCoursePackage coursePackage = new TCoursePackage(); |
| | | Integer coursePackageId = -1; |
| | | for (CoursePackageStudent coursePackageStudent : coursePackageStudent1) { |
| | | RecordAppoint recordVo = new RecordAppoint(); |
| | | recordVo.setCoursePackageId(coursePackageStudent.getCoursePackageId()); |
| | | |
| | | if (!coursePackageStudent.getCoursePackageId().equals(coursePackageId)) { |
| | | coursePackage = tcpmapper.selectById(coursePackageStudent.getCoursePackageId()); |
| | | coursePackageId = coursePackageStudent.getCoursePackageId(); |
| | | } |
| | | |
| | | recordVo.setSid(Arrays.asList(coursePackage.getStoreId())); |
| | | List<Integer> rid = stoClient.querySiteId(coursePackage.getStoreId()); |
| | | recordVo.setRid(rid); |
| | | recordVo.setUserId(appUserId); |
| | | recordVo.setSiteId(coursePackage.getSiteId()); |
| | | List<Integer> ids1 = getIds(coursePackage.getSiteId()); |
| | | recordVo.setIds(ids1); |
| | | |
| | | recordVo.setCoursePackageName(coursePackage.getName()); |
| | | for (CoursePackageOrderStudent tCoursePackagePayment : tCoursePackagePayments) { |
| | | if (Objects.equals(coursePackageStudent.getCoursePackageId(), tCoursePackagePayment.getCoursePackageId())) { |
| | | recordVo.setCourseHours(tCoursePackagePayment.getTotalClassHours()); |
| | | } |
| | | } |
| | | |
| | | |
| | | CoursePackageScheduling byId = coursePackageSchedulingService.getById(coursePackageStudent.getCoursePackageSchedulingId()); |
| | | if (byId == null) { |
| | | continue; |
| | | } |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String dateString1 = sdf.format(byId.getClassDate()); |
| | | String dateString2 = sdf.format(byId.getEndDate()); |
| | | |
| | | |
| | | recordVo.setTimeFrame(dateString1 + "-" + dateString2.substring(11)); |
| | | |
| | | Store store = stoClient.queryStoreById(coursePackage.getStoreId()); |
| | | recordVo.setStoreNameAddr(store.getName() + store.getAddress()); |
| | | recordVo.setCourseStuRecordId(coursePackageStudent.getId()); |
| | | String classWeeks = coursePackage.getClassWeeks(); |
| | | String[] split = classWeeks.split(";"); |
| | | List<String> integerList = Arrays.asList(split); |
| | | String weekOfDate = DateTimeHelper.getWeekOfDate(new Date()); |
| | | if (integerList.contains(weekOfDate)) { |
| | | String dat = simpleDateFormat.format(byId.getClassDate()) + " " + dateString1.substring(11); |
| | | |
| | | Date start = null; |
| | | try { |
| | | start = format.parse(dat); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | //已取消 |
| | | if (byId.getStatus() == 4) { |
| | | recordVo.setStatus(4); |
| | | } else if (coursePackageStudent.getSignInOrNot() == 2) { |
| | | //已请假 |
| | | recordVo.setStatus(5); |
| | | } else if (start.after(new Date())) { |
| | | //待上课 |
| | | recordVo.setStatus(1); |
| | | } |
| | | else { |
| | | CancelledClasses cancelledClasses = cacMapper.selectOne(new QueryWrapper<CancelledClasses>() |
| | | .eq("coursePackageSchedulingId", byId.getId()).last("limit 1")); |
| | | if (ToolUtil.isNotEmpty(cancelledClasses)) { |
| | | recordVo.setStatus(3); |
| | | // 消课 到课状态0 旷课 |
| | | if (coursePackageStudent.getSignInOrNot() == 0) { |
| | | recordVo.setStatus(6); |
| | | } |
| | | |
| | | } else { |
| | | Date now = new Date(); |
| | | if (now.after(byId.getClassDate()) && now.before(byId.getEndDate())) { |
| | | recordVo.setStatus(2); |
| | | } else { |
| | | recordVo.setStatus(3); |
| | | |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | recordVo.setStatus(1); |
| | | } |
| | | recordVoList.add(recordVo); |
| | | } |
| | | |
| | | } else { |
| | | } |
| | | |
| | | } |
| | | |
| | | return recordVoList; |
| | | } |
| | | |
| | | |
| | | |
| | | public List<Integer> getIds(Integer siteId) { |
| | | HttpRequest httpRequest = HttpRequest.get("https://try.daowepark.com/v7/user_api/general/get_space_area?space_id=" + siteId); |
| | | HttpResponse execute = httpRequest.execute(); |
| | | String body = execute.body(); |
| | | JSONObject jsonObject = JSONObject.parseObject(body); |
| | | Object data = jsonObject.get("data"); |
| | | JSONArray array = JSONArray.parseArray(data.toString()); |
| | | List<Integer> ids = new ArrayList<>(); |
| | | for (Object o : array) { |
| | | JSONObject jsonObject1 = JSONObject.parseObject(o.toString()); |
| | | Object id = jsonObject1.get("id"); |
| | | Integer integer = Integer.valueOf(id.toString()); |
| | | ids.add(integer); |
| | | } |
| | | return ids; |
| | | |
| | | } |
| | | } |