| | |
| | | import com.dsh.course.model.vo.response.Details; |
| | | import com.dsh.course.model.vo.response.ExchangeCoursePackageResponse; |
| | | import com.dsh.course.service.TCoursePackageDiscountService; |
| | | import com.dsh.course.util.DateTimeHelper; |
| | | import com.dsh.course.util.LocalDateTimeUtils; |
| | | import com.dsh.course.util.StrUtils; |
| | | import com.dsh.course.util.*; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | List<Details> list = new ArrayList<>(); |
| | | |
| | | QueryWrapper<TCoursePackageDiscount> tCoursePackageDiscountQueryWrapper = new QueryWrapper<>(); |
| | | tCoursePackageDiscountQueryWrapper.eq("auditStatus", 2); |
| | | tCoursePackageDiscountQueryWrapper.eq("auditStatus", 2).eq("status", 1); |
| | | List<TCoursePackageDiscount> tCoursePackageDiscounts = new ArrayList<>(); |
| | | int weekStr = LocalDateTimeUtils.getWeekStr(); |
| | | if (null == discountType || discountType == 1) { |
| | |
| | | if (tCoursePackageDiscounts.size() > 0) { |
| | | for (TCoursePackageDiscount tCoursePackageDiscount : tCoursePackageDiscounts) { |
| | | TCoursePackage coursePackage = tcpMapper.selectById(tCoursePackageDiscount.getCoursePackageId()); |
| | | // 判断预约人数是否已满 |
| | | Integer maxSubscribeNumber = coursePackage.getMaxSubscribeNumber(); |
| | | Integer integer = tcppMapper.selectCount(new QueryWrapper<TCoursePackagePayment>() |
| | | .eq("appUserId",appUserId ) |
| | | .eq("status",1)); |
| | | if (integer >= maxSubscribeNumber){ |
| | | if (coursePackage.getState() == 2) { |
| | | continue; |
| | | } |
| | | // 判断预约人数是否已满 |
| | | // Integer maxSubscribeNumber = coursePackage.getMaxSubscribeNumber(); |
| | | // Integer integer = tcppMapper.selectCount(new QueryWrapper<TCoursePackagePayment>() |
| | | // .eq("appUserId",appUserId ) |
| | | // .eq("status",1)); |
| | | // if (integer >= maxSubscribeNumber){ |
| | | // continue; |
| | | // } |
| | | try { |
| | | JSONArray jsonArray = JSON.parseArray(tCoursePackageDiscount.getContent()); |
| | | JSONObject jsonObject = jsonArray.getJSONObject(0); |
| | |
| | | Date parse2 = null; |
| | | String startDate = jsonObject.getString("startDate"); |
| | | String endDate = jsonObject.getString("endDate"); |
| | | String startTime = jsonObject.getString("startTime"); |
| | | String endTime = jsonObject.getString("endTime"); |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); |
| | | String currentTime = sdf.format(new Date()); |
| | | |
| | | boolean isWithinTimeRange = false; |
| | | try { |
| | | Date currentTimeDate = sdf.parse(currentTime); |
| | | Date startTimeDate = sdf.parse(startTime); |
| | | Date endTimeDate = sdf.parse(endTime); |
| | | |
| | | if (currentTimeDate.after(startTimeDate) && currentTimeDate.before(endTimeDate)) { |
| | | isWithinTimeRange = true; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | parse1 = simpleDateFormat.parse(startDate); |
| | | parse2 = simpleDateFormat.parse(endDate); |
| | |
| | | resde.setDate(localTime); |
| | | resde.setOriginalPrice(paymentConfig.getCashPayment()); |
| | | resde.setDiscountPrice(cashPayment); |
| | | resde.setStatus(1); |
| | | if (isWithinTimeRange) { |
| | | resde.setStatus(1); |
| | | } else { |
| | | resde.setStatus(2); |
| | | } |
| | | GetDistanceVo distanceVo = new GetDistanceVo(); |
| | | distanceVo.setLatitude(lat); |
| | | distanceVo.setLongitude(lon); |
| | | distanceVo.setStoreId(coursePackage.getStoreId()); |
| | | String s = sreClient.calculateDistance(distanceVo); |
| | | resde.setStoreDistance(s); |
| | | |
| | | |
| | | list.add(resde); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | }else { |
| | | } else { |
| | | tCoursePackageDiscountQueryWrapper.eq("type", 4); |
| | | tCoursePackageDiscounts = this.baseMapper.selectList(tCoursePackageDiscountQueryWrapper); |
| | | if (tCoursePackageDiscounts.size() > 0) { |
| | | for (TCoursePackageDiscount tCoursePackageDiscount : tCoursePackageDiscounts) { |
| | | TCoursePackage coursePackage = tcpMapper.selectById(tCoursePackageDiscount.getCoursePackageId()); |
| | | if (coursePackage.getState() == 2) { |
| | | continue; |
| | | } |
| | | |
| | | // 判断预约人数是否已满 |
| | | Integer maxSubscribeNumber = coursePackage.getMaxSubscribeNumber(); |
| | | Integer integer = tcppMapper.selectCount(new QueryWrapper<TCoursePackagePayment>() |
| | | .eq("appUserId",appUserId ) |
| | | .eq("status",1)); |
| | | if (integer >= maxSubscribeNumber){ |
| | | .eq("appUserId", appUserId) |
| | | .eq("status", 1)); |
| | | if (integer >= maxSubscribeNumber) { |
| | | continue; |
| | | } |
| | | try { |
| | |
| | | Date parse2 = null; |
| | | String startDate = jsonObject.getString("startDate"); |
| | | String endDate = jsonObject.getString("endDate"); |
| | | String startTime = jsonObject.getString("startTime"); |
| | | String endTime = jsonObject.getString("endTime"); |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); |
| | | String currentTime = sdf.format(new Date()); |
| | | |
| | | boolean isWithinTimeRange = false; |
| | | try { |
| | | Date currentTimeDate = sdf.parse(currentTime); |
| | | Date startTimeDate = sdf.parse(startTime); |
| | | Date endTimeDate = sdf.parse(endTime); |
| | | |
| | | if (currentTimeDate.after(startTimeDate) && currentTimeDate.before(endTimeDate)) { |
| | | isWithinTimeRange = true; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | parse1 = simpleDateFormat.parse(startDate); |
| | | parse2 = simpleDateFormat.parse(endDate); |
| | |
| | | CoursePackagePaymentConfig paymentConfig = cppcMapper.selectById(tCoursePackageDiscount.getCoursePackagePaymentConfigId()); |
| | | resde.setCourseHours(paymentConfig.getClassHours()); |
| | | resde.setDonateHours(cashPayment); |
| | | resde.setCoin(paymentConfig.getPlayPaiCoin()); |
| | | resde.setDataTime("今日"); |
| | | resde.setDate(localTime); |
| | | resde.setOriginalPrice(paymentConfig.getCashPayment()); |
| | | resde.setStatus(1); |
| | | if (isWithinTimeRange) { |
| | | resde.setStatus(1); |
| | | } else { |
| | | resde.setStatus(2); |
| | | |
| | | } |
| | | GetDistanceVo distanceVo = new GetDistanceVo(); |
| | | distanceVo.setLatitude(lat); |
| | | distanceVo.setLongitude(lon); |
| | |
| | | resde.setCourseHours(paymentConfig.getClassHours()); |
| | | resde.setDonateHours(cashPayment); |
| | | String weekOfDate = ""; |
| | | resde.setCoin(paymentConfig.getPlayPaiCoin()); |
| | | if (weekStr != 7 && tempDate.equals(tomorrowDate)) { |
| | | weekOfDate = "明日"; |
| | | } else { |
| | |
| | | } |
| | | } |
| | | } |
| | | System.out.println("list"+list); |
| | | System.out.println("list" + list); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public ExchangeCoursePackageResponse getWeekFreeCourseDetails(Integer coursePackageDiscountId,String lat,String lon) { |
| | | public ExchangeCoursePackageResponse getWeekFreeCourseDetails(Integer coursePackageDiscountId, String lat, String lon) { |
| | | ExchangeCoursePackageResponse packageResponse = new ExchangeCoursePackageResponse(); |
| | | TCoursePackageDiscount coursePackageDiscount = this.baseMapper.selectById(coursePackageDiscountId); |
| | | Integer coursePackageId = coursePackageDiscount.getCoursePackageId(); |
| | | packageResponse.setCoursePackageDiscountId(coursePackageId); |
| | | |
| | | TCoursePackage coursePackage = tcpMapper.selectById(coursePackageId); |
| | | |
| | | packageResponse.setType(coursePackage.getType()); |
| | | packageResponse.setCoverDrawing(coursePackage.getCoverDrawing()); |
| | | packageResponse.setIntroduceDrawing(coursePackage.getIntroduceDrawing()); |
| | | packageResponse.setCoursePackageName(coursePackage.getName()); |
| | | packageResponse.setDetailDrawing(coursePackage.getDetailDrawing()); |
| | | // packageResponse.setPayType(coursePackage.getPayType()); |
| | | |
| | | |
| | | if (coursePackage.getType() == 2) { |
| | | Date startTime = coursePackage.getStartTime(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); |
| | | String formattedDate = sdf.format(startTime); |
| | | |
| | | Date endTime = coursePackage.getEndTime(); |
| | | String formattedDate1 = sdf.format(endTime); |
| | | |
| | | packageResponse.setHoliTime(formattedDate + "-" + formattedDate1); |
| | | |
| | | } |
| | | Store store = sreClient.queryStoreById(coursePackage.getStoreId()); |
| | | packageResponse.setStoreNameAddr(store.getName() +"(" +store.getAddress()+")"); |
| | | packageResponse.setStoreNameAddr(store.getName() + "(" + store.getAddress() + ")"); |
| | | GetDistanceVo distanceVo = new GetDistanceVo(); |
| | | |
| | | distanceVo.setLatitude(lat); |
| | | distanceVo.setLongitude(lon); |
| | | distanceVo.setStoreId(coursePackage.getStoreId()); |
| | | String s = sreClient.calculateDistance(distanceVo); |
| | | packageResponse.setDistance(Double.valueOf(s)); |
| | | if (coursePackageDiscount.getType() == 1 || coursePackageDiscount.getType() == 2){ |
| | | |
| | | if (ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)) { |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat()); |
| | | double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | packageResponse.setDistance(wgs84); |
| | | } |
| | | |
| | | // distanceVo.setLatitude(lat); |
| | | // distanceVo.setLongitude(lon); |
| | | // distanceVo.setStoreId(coursePackage.getStoreId()); |
| | | // String s = sreClient.calculateDistance(distanceVo); |
| | | // |
| | | // |
| | | // packageResponse.setDistance(Double.valueOf(s)); |
| | | if (coursePackageDiscount.getType() == 1 || coursePackageDiscount.getType() == 2) { |
| | | return packageResponse; |
| | | } |
| | | JSONArray jsonArray = JSON.parseArray(coursePackageDiscount.getContent()); |
| | | JSONObject jsonObject = jsonArray.getJSONObject(0); |
| | | CoursePackagePaymentConfig paymentConfig = cppcMapper.selectById(coursePackageDiscount.getCoursePackagePaymentConfigId()); |
| | | if (coursePackageDiscount.getType() == 3){ |
| | | if (coursePackageDiscount.getType() == 3 || coursePackageDiscount.getType() == 4) { |
| | | Double cashPayment = jsonObject.getDouble("cashPayment"); |
| | | |
| | | if (ToolUtil.isNotEmpty(paymentConfig.getCashPayment()) && paymentConfig.getCashPayment() > 0 && ToolUtil.isNotEmpty(paymentConfig.getPlayPaiCoin()) && paymentConfig.getPlayPaiCoin() > 0) { |
| | | packageResponse.setPayType(3); |
| | | } else if (ToolUtil.isNotEmpty(paymentConfig.getCashPayment()) && paymentConfig.getCashPayment() > 0) { |
| | | packageResponse.setPayType(1); |
| | | } else if (ToolUtil.isNotEmpty(paymentConfig.getPlayPaiCoin()) && paymentConfig.getPlayPaiCoin() > 0) { |
| | | packageResponse.setPayType(2); |
| | | } |
| | | |
| | | packageResponse.setClassHours(paymentConfig.getClassHours()); |
| | | packageResponse.setCostPrice(paymentConfig.getCashPayment()); |
| | | packageResponse.setDiscountPrice(cashPayment); |
| | | }else { |
| | | if (paymentConfig.getPlayPaiCoin() != null) { |
| | | packageResponse.setWanpaiGold(paymentConfig.getPlayPaiCoin()); |
| | | } |
| | | if (cashPayment != null) { |
| | | packageResponse.setDiscountPrice(cashPayment); |
| | | |
| | | } else { |
| | | packageResponse.setDiscountPrice(paymentConfig.getCashPayment()); |
| | | // packageResponse.setCostPrice(null); |
| | | } |
| | | Integer cashPayment1 = jsonObject.getInteger("hour"); |
| | | packageResponse.setFreeClassHours(cashPayment1); |
| | | } else { |
| | | packageResponse.setClassHours(paymentConfig.getClassHours()); |
| | | |
| | | Integer cashPayment = jsonObject.getInteger("hour"); |
| | |
| | | packageResponse.setCostPrice(paymentConfig.getCashPayment()); |
| | | TCoursePackageDiscount coursePackageDiscount1 = this.baseMapper.selectOne(new QueryWrapper<TCoursePackageDiscount>() |
| | | .eq("type", 1) |
| | | .eq("coursePackageId",coursePackage.getId())); |
| | | .eq("coursePackageId", coursePackage.getId())); |
| | | String content = coursePackageDiscount1.getContent(); |
| | | JSONObject jsonObject1 = JSON.parseObject(content); |
| | | Double vipPrice = jsonObject1.getDouble("num1"); |
| | |
| | | packageResponse.setWanpaiGold(paymentConfig.getPlayPaiCoin()); |
| | | } |
| | | String[] split = coursePackage.getClassWeeks().split(";"); |
| | | if (split.length > 0){ |
| | | if (split.length > 0) { |
| | | StringBuilder courWeeks = new StringBuilder("每"); |
| | | for (String integer : split) { |
| | | courWeeks.append(integer).append("、"); |
| | | } |
| | | if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == '、'){ |
| | | if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == '、') { |
| | | courWeeks.deleteCharAt(courWeeks.length() - 1); |
| | | } |
| | | packageResponse.setWeekTime(courWeeks.toString()); |
| | | } |
| | | packageResponse.setTime(coursePackage.getClassStartTime()+"-"+coursePackage.getClassEndTime()); |
| | | |
| | | String classStartTime = coursePackage.getClassStartTime(); |
| | | String classEndTime = coursePackage.getClassEndTime(); |
| | | ArrayList<String> classTime = new ArrayList<>(); |
| | | String[] split4 = classStartTime.split(","); |
| | | String[] split3 = classEndTime.split(","); |
| | | if (ToolUtil.isNotEmpty(classStartTime)) { |
| | | for (int i = 0; i < split4.length; i++) { |
| | | String s = split4[i].substring(0, 5) + "-" + split3[i].substring(0, 5); |
| | | classTime.add(s); |
| | | } |
| | | } |
| | | |
| | | String classTimeAsString = String.join(" | ", classTime); |
| | | |
| | | |
| | | packageResponse.setTime(classTimeAsString); |
| | | |
| | | return packageResponse; |
| | | } |
| | | |
| | | @Override |
| | | public List<DiscountList> queryDiscountList(QueryDiscountList queryDiscountList) { |
| | | Page<DiscountList> discountListPage = new Page<>(queryDiscountList.getOffset(), queryDiscountList.getLimit()); |
| | | List<DiscountList> discountLists = this.baseMapper.queryDiscountList(discountListPage, queryDiscountList.getPCode(), queryDiscountList.getCCode(), queryDiscountList.getName(), queryDiscountList.getType(), queryDiscountList.getIds()); |
| | | for (DiscountList discountList : discountLists) { |
| | | List<TCoursePackageDiscount> tCoursePackageDiscounts = this.baseMapper.selectList(new LambdaQueryWrapper<TCoursePackageDiscount>().eq(TCoursePackageDiscount::getCoursePackageId, discountList.getCourseId()).eq(TCoursePackageDiscount::getAuditStatus,2).orderByAsc(TCoursePackageDiscount::getType)); |
| | | long count = tCoursePackageDiscounts.stream().filter(e -> e.getStatus().equals(2)).count(); |
| | | if(count>0){ |
| | | discountList.setStatus(2); |
| | | }else { |
| | | discountList.setStatus(1); |
| | | } |
| | | String type=""; |
| | | for (int i = 0; i < tCoursePackageDiscounts.size(); i++) { |
| | | if(tCoursePackageDiscounts.get(i).getType()==1){ |
| | | type += "会员折扣、"; |
| | | }else if(tCoursePackageDiscounts.get(i).getType()==3){ |
| | | type += "限时折扣、"; |
| | | }else if(tCoursePackageDiscounts.get(i).getType()==4){ |
| | | type += "赠送课时、"; |
| | | } |
| | | } |
| | | if(type.length()>0){ |
| | | type = type.substring(0,type.length()-1); |
| | | } |
| | | discountList.setType(type); |
| | | } |
| | | return discountLists; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String a ="1312dsad132"; |
| | | a = a.substring(0,a.length()-1); |
| | | System.out.println(a); |
| | | } |
| | | @Override |
| | | public List<DiscountList> queryDiscountListAudit(QueryDiscountList queryDiscountList) { |
| | | Page<DiscountList> discountListPage = new Page<>(queryDiscountList.getOffset(), queryDiscountList.getLimit()); |
| | | List<DiscountList> discountLists = this.baseMapper.queryDiscountListAudit(discountListPage, queryDiscountList.getPCode(), queryDiscountList.getCCode(), queryDiscountList.getName(), queryDiscountList.getType(), queryDiscountList.getIds()); |
| | | List<DiscountList> discountLists = this.baseMapper.queryDiscountListAudit(discountListPage, |
| | | queryDiscountList.getPCode(), |
| | | queryDiscountList.getCCode(), |
| | | queryDiscountList.getName(), |
| | | queryDiscountList.getType(), |
| | | queryDiscountList.getIds()); |
| | | for (DiscountList discountList : discountLists) { |
| | | List<TCoursePackageDiscount> tCoursePackageDiscounts = this.baseMapper.selectList(new LambdaQueryWrapper<TCoursePackageDiscount>().eq(TCoursePackageDiscount::getCoursePackageId, discountList.getCourseId()).ne(TCoursePackageDiscount::getAuditStatus,2).orderByAsc(TCoursePackageDiscount::getType)); |
| | | long count = tCoursePackageDiscounts.stream().filter(e -> e.getAuditStatus().equals(2)).count(); |
| | | if(count>0){ |
| | | discountList.setStatus(2); |
| | | }else { |
| | | discountList.setStatus(1); |
| | | } |
| | | String type=""; |
| | | List<TCoursePackageDiscount> tCoursePackageDiscounts = this.baseMapper |
| | | .selectList(new LambdaQueryWrapper<TCoursePackageDiscount>() |
| | | .eq(TCoursePackageDiscount::getCoursePackageId, discountList.getCourseId()) |
| | | .ne(TCoursePackageDiscount::getAuditStatus, 2) |
| | | .orderByAsc(TCoursePackageDiscount::getType)); |
| | | // long count = tCoursePackageDiscounts.stream() |
| | | // .filter(e -> e.getAuditStatus().equals(2)).count(); |
| | | // if(count>0){ |
| | | // discountList.setStatus(2); |
| | | // }else { |
| | | // discountList.setStatus(1); |
| | | // } |
| | | String type = ""; |
| | | for (int i = 0; i < tCoursePackageDiscounts.size(); i++) { |
| | | if(tCoursePackageDiscounts.get(i).getType()==1){ |
| | | if (tCoursePackageDiscounts.get(i).getType() == 1) { |
| | | type += "会员折扣、"; |
| | | }else if(tCoursePackageDiscounts.get(i).getType()==3){ |
| | | } else if (tCoursePackageDiscounts.get(i).getType() == 2) { |
| | | type += "续课优惠、"; |
| | | } else if (tCoursePackageDiscounts.get(i).getType() == 3) { |
| | | type += "限时折扣、"; |
| | | }else if(tCoursePackageDiscounts.get(i).getType()==4){ |
| | | } else if (tCoursePackageDiscounts.get(i).getType() == 4) { |
| | | type += "赠送课时、"; |
| | | } |
| | | } |
| | | if(type.length()>0){ |
| | | type = type.substring(0,type.length()-1); |
| | | if (type.length() > 0) { |
| | | type = type.substring(0, type.length() - 1); |
| | | } |
| | | discountList.setType(type); |
| | | } |
| | | return discountLists; |
| | | } |
| | | |
| | | @Override |
| | | public List<DiscountList> queryDiscountList(QueryDiscountList queryDiscountList) { |
| | | Page<DiscountList> discountListPage = new Page<>(queryDiscountList.getOffset(), queryDiscountList.getLimit()); |
| | | List<Integer> ids = queryDiscountList.getIds(); |
| | | if (ids.size() == 0) { |
| | | ids.add(-1); |
| | | queryDiscountList.setIds(ids); |
| | | } |
| | | List<DiscountList> discountLists = this.baseMapper.queryDiscountList(discountListPage, |
| | | queryDiscountList.getPCode(), queryDiscountList.getCCode(), |
| | | queryDiscountList.getName(), queryDiscountList.getType(), queryDiscountList.getIds()); |
| | | for (DiscountList discountList : discountLists) { |
| | | List<TCoursePackageDiscount> tCoursePackageDiscounts = this.baseMapper.selectList |
| | | (new LambdaQueryWrapper<TCoursePackageDiscount>() |
| | | .eq(TCoursePackageDiscount::getCoursePackageId, |
| | | discountList.getCourseId()) |
| | | .orderByAsc(TCoursePackageDiscount::getType)); |
| | | |
| | | String type = ""; |
| | | for (int i = 0; i < tCoursePackageDiscounts.size(); i++) { |
| | | if (tCoursePackageDiscounts.get(i).getType() == 1) { |
| | | type += "会员折扣、"; |
| | | } else if (tCoursePackageDiscounts.get(i).getType() == 2) { |
| | | type += "续课优惠、"; |
| | | } else if (tCoursePackageDiscounts.get(i).getType() == 3) { |
| | | type += "限时折扣、"; |
| | | } else if (tCoursePackageDiscounts.get(i).getType() == 4) { |
| | | type += "赠送课时、"; |
| | | } |
| | | } |
| | | if (type.length() > 0) { |
| | | type = type.substring(0, type.length() - 1); |
| | | } |
| | | discountList.setType(type); |
| | | } |
| | | return discountLists; |
| | | } |
| | | |
| | | private static boolean isDateWithinRange(Date date, Date startTime, Date endTime) { |
| | | return date.after(startTime) && date.before(endTime); |