4 文件已重命名
24个文件已修改
2个文件已删除
22个文件已添加
| | |
| | | package com.dsh.account.feignclient.competition; |
| | | |
| | | |
| | | import com.dsh.account.feignclient.competition.model.GetStuSourseList; |
| | | import com.dsh.account.feignclient.competition.model.PurchaseRecordVo; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | @FeignClient(value = "mb-cloud-competition") |
| | | public interface DeductionCompetitionsClient { |
| | | @PostMapping("/competition/getCompetitionsDetails") |
| | | public List<PurchaseRecordVo> getStuSourseList(@RequestBody Date startTime, |
| | | @RequestBody Date endTime, |
| | | @RequestBody Integer appUserId); |
| | | List<PurchaseRecordVo> getStuSourseList(GetStuSourseList getStuSourseList); |
| | | |
| | | } |
New file |
| | |
| | | package com.dsh.account.feignclient.competition.model; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/6 9:59 |
| | | */ |
| | | @Data |
| | | public class GetStuSourseList { |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date startTime; |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date endTime; |
| | | private Integer appUserId; |
| | | } |
| | |
| | | package com.dsh.account.feignclient.course; |
| | | |
| | | import com.dsh.account.feignclient.course.model.CourseOfStoreVo; |
| | | import com.dsh.account.feignclient.course.model.StuCourseResp; |
| | | import com.dsh.account.feignclient.course.model.StuWithCoursesListVo; |
| | | import com.dsh.account.feignclient.course.model.StudentOfCourseVo; |
| | | import com.dsh.account.feignclient.course.model.*; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | List<CourseOfStoreVo> getStoreOfCourses(); |
| | | |
| | | @PostMapping("/coursePack/stuOfCourses") |
| | | StuWithCoursesListVo getStuOfCoursesDetails(@RequestBody Integer stuId, |
| | | @RequestBody Integer appUserId); |
| | | StuWithCoursesListVo getStuOfCoursesDetails(GetStuOfCoursesDetails getStuOfCoursesDetails); |
| | | |
| | | @PostMapping("/coursePack/continuingCourse") |
| | | StudentOfCourseVo getStudentCourse(@RequestBody Integer courseId, |
| | | @RequestBody Integer stuId, |
| | | @RequestBody Integer appUserId); |
| | | StudentOfCourseVo getStudentCourse(GetStudentCourse getStudentCourse); |
| | | } |
| | |
| | | |
| | | |
| | | import com.dsh.account.feignclient.competition.model.PurchaseRecordVo; |
| | | import com.dsh.account.feignclient.course.model.GetStuSessionList; |
| | | import com.dsh.account.feignclient.course.model.StuSessionDetailsVo; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | |
| | | |
| | | @PostMapping("/coursePack/sessionNames") |
| | | List<StuSessionDetailsVo> getStuSessionList(@RequestBody Date startTime, |
| | | @RequestBody Date endTime, |
| | | @RequestBody Integer stuId, |
| | | @RequestBody Integer appUserId); |
| | | List<StuSessionDetailsVo> getStuSessionList(GetStuSessionList getStuSessionList); |
| | | |
| | | @PostMapping("/coursePack/paymentCourse") |
| | | public List<PurchaseRecordVo> queryCourseDetails(@RequestBody Date startTime, |
| | | @RequestBody Date endTime, |
| | | @RequestBody Integer stuId, |
| | | @RequestBody Integer appUserId); |
| | | public List<PurchaseRecordVo> queryCourseDetails(GetStuSessionList getStuSessionList); |
| | | |
| | | } |
New file |
| | |
| | | package com.dsh.account.feignclient.course.model; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/6 9:46 |
| | | */ |
| | | @Data |
| | | public class GetStuOfCoursesDetails { |
| | | private Integer stuId; |
| | | private Integer appUserId; |
| | | } |
New file |
| | |
| | | package com.dsh.account.feignclient.course.model; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/6 9:55 |
| | | */ |
| | | @Data |
| | | public class GetStuSessionList { |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date startTime; |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date endTime; |
| | | private Integer stuId; |
| | | private Integer appUserId; |
| | | } |
New file |
| | |
| | | package com.dsh.account.feignclient.course.model; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/6 9:48 |
| | | */ |
| | | @Data |
| | | public class GetStudentCourse { |
| | | private Integer courseId; |
| | | private Integer stuId; |
| | | private Integer appUserId; |
| | | } |
| | |
| | | package com.dsh.account.feignclient.other; |
| | | |
| | | import com.dsh.account.feignclient.course.model.QueryStoreList; |
| | | import com.dsh.account.feignclient.other.model.Store; |
| | | import com.dsh.account.feignclient.other.model.*; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | |
| | |
| | | * @author zhibing.pu |
| | | * @date 2023/6/24 15:54 |
| | | */ |
| | | import com.dsh.account.feignclient.other.model.StoreDetailOfCourse; |
| | | import com.dsh.account.feignclient.other.model.StoreInfo; |
| | | import com.dsh.account.feignclient.other.model.StoreLonLatList; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | public interface StoreClient { |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取门店列表 |
| | | * @return |
| | |
| | | List<Store> queryStoreList(QueryStoreList queryStoreList); |
| | | |
| | | |
| | | |
| | | |
| | | @PostMapping("/storeDetail/courseOfSto") |
| | | public StoreDetailOfCourse getCourseOfStore(@RequestBody Integer storeId); |
| | | StoreDetailOfCourse getCourseOfStore(@RequestBody Integer storeId); |
| | | |
| | | |
| | | @PostMapping("/storeDetail/nearbyStore") |
| | | List<StoreInfo> getAllNearbyStoreList(@RequestBody String longitude, @RequestBody String latitude); |
| | | List<StoreInfo> getAllNearbyStoreList(GetAllNearbyStoreList getAllNearbyStoreList); |
| | | |
| | | |
| | | @PostMapping("/storeDetail/storeOfLonLat") |
| | | public List<StoreLonLatList> getAllStoreLonLats(@RequestBody String longitude, @RequestBody String latitude); |
| | | List<StoreLonLatList> getAllStoreLonLats(GetAllNearbyStoreList getAllNearbyStoreList); |
| | | } |
New file |
| | |
| | | package com.dsh.account.feignclient.other.model; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/6 9:52 |
| | | */ |
| | | @Data |
| | | public class GetAllNearbyStoreList { |
| | | private String longitude; |
| | | private String latitude; |
| | | } |
| | |
| | | import com.dsh.account.feignclient.activity.IntroduceRewardsClient; |
| | | import com.dsh.account.feignclient.activity.UserConponClient; |
| | | import com.dsh.account.feignclient.competition.DeductionCompetitionsClient; |
| | | import com.dsh.account.feignclient.competition.model.GetStuSourseList; |
| | | import com.dsh.account.feignclient.competition.model.PurchaseRecordVo; |
| | | import com.dsh.account.feignclient.course.CancelListClient; |
| | | import com.dsh.account.feignclient.course.CoursePaymentClient; |
| | | import com.dsh.account.feignclient.course.CourseRecordClient; |
| | | import com.dsh.account.feignclient.course.CourseSessionNameClient; |
| | | import com.dsh.account.feignclient.course.model.StuSessionDetailsVo; |
| | | import com.dsh.account.feignclient.course.model.StuWithCoursesListVo; |
| | | import com.dsh.account.feignclient.course.model.StudentOfCourseVo; |
| | | import com.dsh.account.feignclient.course.model.*; |
| | | import com.dsh.account.feignclient.other.NoticeClient; |
| | | import com.dsh.account.feignclient.other.QuestionClient; |
| | | import com.dsh.account.feignclient.other.StoreClient; |
| | | import com.dsh.account.feignclient.other.model.StoreDetailOfCourse; |
| | | import com.dsh.account.feignclient.other.model.StoreInfo; |
| | | import com.dsh.account.feignclient.other.model.StoreLonLatList; |
| | | import com.dsh.account.feignclient.other.model.SysNotice; |
| | | import com.dsh.account.feignclient.other.model.*; |
| | | import com.dsh.account.mapper.TAppUserMapper; |
| | | import com.dsh.account.mapper.TStudentMapper; |
| | | import com.dsh.account.model.vo.classDetails.classInsVo.ClassDetailsInsVo; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | @Service |
| | | public class TStudentServiceImpl extends ServiceImpl<TStudentMapper, TStudent> implements TStudentService { |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private CourseSessionNameClient sessionNameClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private DeductionCompetitionsClient dcttClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private CancelListClient cancelcClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private IntroduceRewardsClient idrClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private CourseRecordClient crClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private CoursePaymentClient couPayClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private UserConponClient userCClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private StoreClient storeClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private NoticeClient noClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private QuestionClient quesClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private TAppUserMapper tauMapper; |
| | | |
| | | @Override |
| | |
| | | ClassDetailsInsVo insVo = new ClassDetailsInsVo(); |
| | | Date localMonthStart = DateTimeHelper.getCurrentMouthStart(); |
| | | Date localMonthEnd = DateTimeHelper.getCurrentMouthEnd(); |
| | | List<StuSessionDetailsVo> stuSessionList = sessionNameClient.getStuSessionList(localMonthStart,localMonthEnd,stuId,userIdFormRedis); |
| | | GetStuSessionList getStuSessionList = new GetStuSessionList(); |
| | | getStuSessionList.setStartTime(localMonthStart); |
| | | getStuSessionList.setEndTime(localMonthEnd); |
| | | getStuSessionList.setStuId(stuId); |
| | | getStuSessionList.setAppUserId(userIdFormRedis); |
| | | List<StuSessionDetailsVo> stuSessionList = sessionNameClient.getStuSessionList(getStuSessionList); |
| | | TStudent tStudent = this.baseMapper.selectById(stuId); |
| | | if (ToolUtil.isNotEmpty(tStudent)){ |
| | | insVo.setStuId(tStudent.getId()); |
| | |
| | | insVo.setStuImage(tStudent.getHeadImg()); |
| | | |
| | | List<PurchaseRecordVo> purchaseRecordVoList = new ArrayList<>(); |
| | | |
| | | List<PurchaseRecordVo> stuSourseList = dcttClient.getStuSourseList(localMonthStart,localMonthEnd,userIdFormRedis); |
| | | GetStuSourseList getStuSourseList = new GetStuSourseList(); |
| | | getStuSourseList.setStartTime(localMonthStart); |
| | | getStuSourseList.setEndTime(localMonthEnd); |
| | | getStuSourseList.setAppUserId(userIdFormRedis); |
| | | List<PurchaseRecordVo> stuSourseList = dcttClient.getStuSourseList(getStuSourseList); |
| | | purchaseRecordVoList.addAll(stuSourseList); |
| | | List<PurchaseRecordVo> cancelCourseList = cancelcClient.getCancelCourseList(localMonthStart,localMonthEnd,stuId,userIdFormRedis); |
| | | purchaseRecordVoList.addAll(cancelCourseList); |
| | | List<PurchaseRecordVo> purchaseRecordVos = sessionNameClient.queryCourseDetails(localMonthStart,localMonthEnd,stuId,userIdFormRedis); |
| | | List<PurchaseRecordVo> purchaseRecordVos = sessionNameClient.queryCourseDetails(getStuSessionList); |
| | | purchaseRecordVoList.addAll(purchaseRecordVos); |
| | | List<TAppUser> tAppUsers = tauMapper.selectList(new QueryWrapper<TAppUser>() |
| | | .eq("referralUserId",userIdFormRedis ) |
| | |
| | | purchaseRecordVoList.addAll(purchaseRecordVos1); |
| | | insVo.setSessionNames(stuSessionList); |
| | | insVo.setDetails(dealDataOfTime(purchaseRecordVoList)); |
| | | StuWithCoursesListVo stuOfCoursesDetails = couPayClient.getStuOfCoursesDetails(stuId, userIdFormRedis); |
| | | GetStuOfCoursesDetails getStuOfCoursesDetails = new GetStuOfCoursesDetails(); |
| | | getStuOfCoursesDetails.setStuId(stuId); |
| | | getStuOfCoursesDetails.setAppUserId(userIdFormRedis); |
| | | StuWithCoursesListVo stuOfCoursesDetails = couPayClient.getStuOfCoursesDetails(getStuOfCoursesDetails); |
| | | insVo.setTotalNums(stuOfCoursesDetails.getTotalNums()); |
| | | insVo.setDeductedNums(stuOfCoursesDetails.getDeductedNums()); |
| | | insVo.setRemainingNums(stuOfCoursesDetails.getRemainingNums()); |
| | |
| | | List<PurchaseRecordVo> purchaseRecordVoList = new ArrayList<>(); |
| | | Date startTime = DateTimeHelper.getCurrentIdetMouthStart(timeRequest.getStartTime()); |
| | | Date endTime = DateTimeHelper.getCurrentIdeaMouthEnd(timeRequest.getEndTime()); |
| | | |
| | | List<PurchaseRecordVo> stuSourseList = dcttClient.getStuSourseList(startTime,endTime,appUserId); |
| | | GetStuSourseList getStuSourseList = new GetStuSourseList(); |
| | | getStuSourseList.setStartTime(startTime); |
| | | getStuSourseList.setEndTime(endTime); |
| | | getStuSourseList.setAppUserId(appUserId); |
| | | List<PurchaseRecordVo> stuSourseList = dcttClient.getStuSourseList(getStuSourseList); |
| | | purchaseRecordVoList.addAll(stuSourseList); |
| | | List<PurchaseRecordVo> cancelCourseList = cancelcClient.getCancelCourseList(startTime,endTime,timeRequest.getStuId(),appUserId); |
| | | purchaseRecordVoList.addAll(cancelCourseList); |
| | | List<PurchaseRecordVo> purchaseRecordVos = sessionNameClient.queryCourseDetails(startTime,endTime,timeRequest.getStuId(),appUserId); |
| | | GetStuSessionList getStuSessionList = new GetStuSessionList(); |
| | | getStuSessionList.setStartTime(startTime); |
| | | getStuSessionList.setEndTime(endTime); |
| | | getStuSessionList.setStuId(timeRequest.getStuId()); |
| | | getStuSessionList.setAppUserId(appUserId); |
| | | List<PurchaseRecordVo> purchaseRecordVos = sessionNameClient.queryCourseDetails(getStuSessionList); |
| | | purchaseRecordVoList.addAll(purchaseRecordVos); |
| | | List<TAppUser> tAppUsers = tauMapper.selectList(new QueryWrapper<TAppUser>() |
| | | .eq("referralUserId",appUserId ) |
| | |
| | | public CourseDetailsOfContinuationResp queryStuOfCourseDetails(Integer lessonId, Integer stuId, Integer appUserId) { |
| | | CourseDetailsOfContinuationResp resp = new CourseDetailsOfContinuationResp(); |
| | | |
| | | StudentOfCourseVo studentCourse = couPayClient.getStudentCourse(lessonId,stuId,appUserId); |
| | | GetStudentCourse getStudentCourse = new GetStudentCourse(); |
| | | getStudentCourse.setCourseId(lessonId); |
| | | getStudentCourse.setStuId(stuId); |
| | | getStudentCourse.setAppUserId(appUserId); |
| | | StudentOfCourseVo studentCourse = couPayClient.getStudentCourse(getStudentCourse); |
| | | |
| | | StoreDetailOfCourse courseOfStore = storeClient.getCourseOfStore(studentCourse.getStoreId()); |
| | | |
| | |
| | | @Override |
| | | public ExploreDatasVo queryIndexOfExplores(LonLatRequest llrequest) { |
| | | ExploreDatasVo datasVo = new ExploreDatasVo(); |
| | | List<StoreInfo> allNearbyStoreList = storeClient.getAllNearbyStoreList(llrequest.getLongitude(),llrequest.getLatitude()); |
| | | List<StoreLonLatList> allStoreLonLats = storeClient.getAllStoreLonLats(llrequest.getLongitude(), llrequest.getLatitude()); |
| | | GetAllNearbyStoreList getAllNearbyStoreList = new GetAllNearbyStoreList(); |
| | | getAllNearbyStoreList.setLongitude(llrequest.getLongitude()); |
| | | getAllNearbyStoreList.setLatitude(llrequest.getLatitude()); |
| | | List<StoreInfo> allNearbyStoreList = storeClient.getAllNearbyStoreList(getAllNearbyStoreList); |
| | | List<StoreLonLatList> allStoreLonLats = storeClient.getAllStoreLonLats(getAllNearbyStoreList); |
| | | datasVo.setStoreLists(allNearbyStoreList); |
| | | datasVo.setLonLatLists(allStoreLonLats); |
| | | return datasVo; |
| | |
| | | <artifactId>swagger-models</artifactId> |
| | | <version>1.5.22</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.apache.shardingsphere</groupId> |
| | | <artifactId>shardingsphere-jdbc-core</artifactId> |
| | | <version>5.2.0</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.apache.httpcomponents</groupId> |
| | | <artifactId>httpclient</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-httpclient</groupId> |
| | | <artifactId>commons-httpclient</artifactId> |
| | | <version>3.1</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.apache.httpcomponents</groupId> |
| | | <artifactId>httpmime</artifactId> |
| | | <version>4.5.2</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | package com.dsh.activity.controller; |
| | | |
| | | import com.dsh.activity.entity.Coupon; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.service.ICouponService; |
| | | import com.dsh.activity.util.ResultUtil; |
| | |
| | | @ApiImplicitParam(value = "1=积分购买,2=注册赠送", name = "distributionMethod", dataType = "int", required = true), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil queryCouponList(@RequestBody Integer distributionMethod){ |
| | | public ResultUtil<List<CouponListVo>> queryCouponList(@RequestBody Integer distributionMethod){ |
| | | if(null == distributionMethod){ |
| | | return ResultUtil.paranErr("distributionMethod"); |
| | | } |
| | |
| | | return ResultUtil.success(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据id获取优惠券信息 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/coupon/queryCouponById") |
| | | public Coupon queryCouponById(@RequestBody Integer id){ |
| | | try { |
| | | Coupon coupon = couponService.getById(id); |
| | | return coupon; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.dsh.activity.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.dsh.activity.entity.Coupon; |
| | | import com.dsh.activity.entity.UserCoupon; |
| | | import com.dsh.activity.feignclient.model.CouponStuAvailableVo; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.service.ICouponService; |
| | | import com.dsh.activity.service.UserCouponService; |
| | | import com.dsh.activity.util.ResultUtil; |
| | | import com.dsh.activity.util.TokenUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Api |
| | | @CrossOrigin |
| | | @RestController |
| | | @RequestMapping("") |
| | | public class UserCouponController { |
| | | |
| | | @Autowired |
| | | private UserCouponService uconService; |
| | | |
| | | @Autowired |
| | | private ICouponService cService; |
| | | |
| | | @Autowired |
| | | private TokenUtil tokenUtil; |
| | | |
| | | @Autowired |
| | | private UserCouponService userCouponService; |
| | | |
| | | |
| | | |
| | | |
| | | private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); |
| | | |
| | | @PostMapping("/userConpon/getStuOfConpons") |
| | | public List<CouponStuAvailableVo> queryUserWithConponList(@RequestBody Integer appUserId){ |
| | | |
| | | List<CouponStuAvailableVo> availableVos = new ArrayList<>(); |
| | | |
| | | List<UserCoupon> list = uconService.list(new QueryWrapper<UserCoupon>() |
| | | .eq("userId", appUserId) |
| | | .eq("status",1)); |
| | | if (list.size() > 0){ |
| | | List<Integer> collect = list.stream().map(UserCoupon::getCouponId).collect(Collectors.toList()); |
| | | List<Coupon> conponList = cService.list(new QueryWrapper<Coupon>() |
| | | .in("id", collect)); |
| | | for (Coupon coupon : conponList) { |
| | | CouponStuAvailableVo availableVo = new CouponStuAvailableVo(); |
| | | availableVo.setConponId(coupon.getId()); |
| | | availableVo.setConponName(coupon.getName()); |
| | | availableVo.setConponType(coupon.getType()); |
| | | Map<String,Object> conponRuleMap = cService.queryConponRuleOfJson(coupon.getId()); |
| | | switch (coupon.getType()){ |
| | | case 1: |
| | | Object conditionalAmount = conponRuleMap.get("conditionalAmount"); |
| | | Object deductionAmount = conponRuleMap.get("deductionAmount"); |
| | | availableVo.setConditionalAmount((double) conditionalAmount); |
| | | availableVo.setAmount((double) deductionAmount); |
| | | break; |
| | | case 2: |
| | | Object amount = conponRuleMap.get("deductionAmount"); |
| | | availableVo.setAmount((double)amount); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | availableVo.setLifespan(format.format(coupon.getEndTime())); |
| | | availableVos.add(availableVo); |
| | | } |
| | | } |
| | | return availableVos; |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/coupon/queryAvailableCouponList") |
| | | @ApiOperation(value = "获取课程支付页面可用优惠券列表", tags = {"APP-课程列表", ""}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "课程id", name = "coursePackageId", dataType = "int", required = true), |
| | | @ApiImplicitParam(value = "支付金额", name = "price", dataType = "double", required = true), |
| | | @ApiImplicitParam(value = "经度", name = "lon", dataType = "string", required = true), |
| | | @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = true), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<List<CouponListVo>> queryAvailableCouponList(@RequestBody Integer coursePackageId, @RequestBody Double price, @RequestBody String lon, @RequestBody String lat){ |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if(null == uid){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | List<CouponListVo> listVos = userCouponService.queryAvailableCouponList(uid, coursePackageId, price, lon, lat); |
| | | return ResultUtil.success(listVos); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据id获取用户优惠券数据 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/queryUserCouponById") |
| | | public UserCoupon queryUserCouponById(@RequestBody Long id){ |
| | | try { |
| | | UserCoupon userCoupon = userCouponService.getById(id); |
| | | return userCoupon; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.baomidou.mybatisplus.extension.activerecord.Model; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | |
| | | /** |
| | | * 开始时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date startTime; |
| | | /** |
| | | * 结束时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date endTime; |
| | | /** |
| | | * 使用范围(1=全国,2=指定城市,3=指定门店) |
| | |
| | | /** |
| | | * 添加时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date insertTime; |
| | | |
| | | |
| | |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.baomidou.mybatisplus.extension.activerecord.Model; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id; |
| | | @TableId(value = "id", type = IdType.INPUT) |
| | | private Long id; |
| | | /** |
| | | * 优惠券id |
| | | */ |
| | |
| | | /** |
| | | * 核销时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date verificationTime; |
| | | /** |
| | | * 领取时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date insertTime; |
| | | |
| | | |
| | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id; |
| | | @TableId(value = "id", type = IdType.INPUT) |
| | | private Long id; |
| | | /** |
| | | * 优惠券id |
| | | */ |
File was renamed from cloud-server-activity/src/main/java/com/dsh/activity/feginClient/account/AppUserClient.java |
| | |
| | | package com.dsh.activity.feginClient.account; |
| | | package com.dsh.activity.feignclient.account; |
| | | |
| | | import com.dsh.activity.feginClient.account.model.AppUser; |
| | | import com.dsh.activity.feignclient.account.model.AppUser; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | |
File was renamed from cloud-server-activity/src/main/java/com/dsh/activity/feginClient/account/StudentClient.java |
| | |
| | | package com.dsh.activity.feginClient.account; |
| | | package com.dsh.activity.feignclient.account; |
| | | |
| | | import com.dsh.activity.feginClient.account.model.Student; |
| | | import com.dsh.activity.feignclient.account.model.Student; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | |
File was renamed from cloud-server-activity/src/main/java/com/dsh/activity/feginClient/account/model/AppUser.java |
| | |
| | | package com.dsh.activity.feginClient.account.model; |
| | | package com.dsh.activity.feignclient.account.model; |
| | | |
| | | import lombok.Data; |
| | | |
File was renamed from cloud-server-activity/src/main/java/com/dsh/activity/feginClient/account/model/Student.java |
| | |
| | | package com.dsh.activity.feginClient.account.model; |
| | | package com.dsh.activity.feignclient.account.model; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
New file |
| | |
| | | package com.dsh.activity.feignclient.course; |
| | | |
| | | import com.dsh.activity.feignclient.course.model.CoursePackage; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/5 9:55 |
| | | */ |
| | | @FeignClient("mb-cloud-course") |
| | | public interface CoursePackageClient { |
| | | |
| | | |
| | | /** |
| | | * 根据id获取课包 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @PostMapping("/coursePackage/queryCoursePackageById") |
| | | CoursePackage queryCoursePackageById(Integer id); |
| | | } |
New file |
| | |
| | | package com.dsh.activity.feignclient.course.model; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/5 9:56 |
| | | */ |
| | | @Data |
| | | public class CoursePackage { |
| | | private Integer id; |
| | | /** |
| | | * 省 |
| | | */ |
| | | private String province; |
| | | /** |
| | | * 省编号 |
| | | */ |
| | | private String provinceCode; |
| | | /** |
| | | * 市 |
| | | */ |
| | | private String city; |
| | | /** |
| | | * 市编号 |
| | | */ |
| | | private String cityCode; |
| | | /** |
| | | * 门店id |
| | | */ |
| | | private Integer storeId; |
| | | /** |
| | | * 课包类型id |
| | | */ |
| | | private Integer coursePackageTypeId; |
| | | /** |
| | | * 课包名称 |
| | | */ |
| | | private String name; |
| | | /** |
| | | * 上课场地id |
| | | */ |
| | | private Integer siteId; |
| | | /** |
| | | * 教练id |
| | | */ |
| | | private Integer coachId; |
| | | /** |
| | | * 最多预约人数 |
| | | */ |
| | | private Integer maxSubscribeNumber; |
| | | /** |
| | | * 上课开始时间 |
| | | */ |
| | | private String classStartTime; |
| | | /** |
| | | * 上课结束时段 |
| | | */ |
| | | private String classEndTime; |
| | | /** |
| | | * 上课周,多个分号分隔 |
| | | */ |
| | | private String classWeeks; |
| | | /** |
| | | * 封面图 |
| | | */ |
| | | private String coverDrawing; |
| | | /** |
| | | * 详情图 |
| | | */ |
| | | private String detailDrawing; |
| | | /** |
| | | * 介绍图 |
| | | */ |
| | | private String introduceDrawing; |
| | | /** |
| | | * 排序 |
| | | */ |
| | | private Integer sort; |
| | | /** |
| | | * 支付方式(1=现金,2=玩湃币) |
| | | */ |
| | | private Integer payType; |
| | | /** |
| | | * 有效天数 |
| | | */ |
| | | private Integer validDays; |
| | | /** |
| | | * 课后练习课程id |
| | | */ |
| | | private Integer courseId; |
| | | /** |
| | | * 课后练习视频介绍 |
| | | */ |
| | | private String introduce; |
| | | /** |
| | | * 完成课后练习获取积分 |
| | | */ |
| | | private Integer integral; |
| | | /** |
| | | * 课程状态(1=未开始,2=进行中,3=已结束,4=已取消) |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * 审核状态(1=待审核,2=已同意,3=已拒绝) |
| | | */ |
| | | private Integer auditStatus; |
| | | /** |
| | | * 审核人id |
| | | */ |
| | | private Integer auditUserId; |
| | | /** |
| | | * 审核备注 |
| | | */ |
| | | private String authRemark; |
| | | /** |
| | | * 状态(1=正常,2=冻结,3=删除) |
| | | */ |
| | | private Integer state; |
| | | /** |
| | | * 添加时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date insertTime; |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.dsh.activity.entity.UserCoupon; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | public interface UserCouponMapper extends BaseMapper<UserCoupon> { |
| | | |
| | | |
| | | /** |
| | | * 获取购买课程可用优惠券列表 |
| | | * @param uid |
| | | * @param storeId |
| | | * @param provinceCode |
| | | * @param cityCode |
| | | * @return |
| | | */ |
| | | List<Map<String, Object>> queryAvailableCouponList(@Param("uid") Integer uid, @Param("storeId") Integer storeId, |
| | | @Param("provinceCode") String provinceCode, @Param("cityCode") String cityCode); |
| | | |
| | | } |
| | |
| | | @ApiModel |
| | | public class CouponListVo { |
| | | @ApiModelProperty("优惠券id") |
| | | private Integer id; |
| | | private Long id; |
| | | @ApiModelProperty("优惠券名称") |
| | | private String name; |
| | | @ApiModelProperty("优惠券类型(1=满减券,2=代金券,3=体验券)") |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.dsh.activity.entity.UserCoupon; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | public interface UserCouponService extends IService<UserCoupon> { |
| | | |
| | | |
| | | /** |
| | | * 获取购买课程可用优惠券列表 |
| | | * @param uid |
| | | * @param coursePackageId |
| | | * @return |
| | | */ |
| | | List<CouponListVo> queryAvailableCouponList(Integer uid, Integer coursePackageId, Double price, String lon, String lat) throws Exception; |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.activity.entity.Coupon; |
| | | import com.dsh.activity.feginClient.account.AppUserClient; |
| | | import com.dsh.activity.feginClient.account.StudentClient; |
| | | import com.dsh.activity.feginClient.account.model.AppUser; |
| | | import com.dsh.activity.feginClient.account.model.Student; |
| | | import com.dsh.activity.feignclient.account.AppUserClient; |
| | | import com.dsh.activity.feignclient.account.StudentClient; |
| | | import com.dsh.activity.feignclient.account.model.AppUser; |
| | | import com.dsh.activity.feignclient.account.model.Student; |
| | | import com.dsh.activity.mapper.CouponMapper; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.service.ICouponService; |
| | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | for (Coupon coupon : list) { |
| | | CouponListVo couponListVo = new CouponListVo(); |
| | | couponListVo.setId(coupon.getId()); |
| | | couponListVo.setId(coupon.getId().longValue()); |
| | | couponListVo.setName(coupon.getName()); |
| | | couponListVo.setType(coupon.getType()); |
| | | couponListVo.setEffectiveTime(sdf.format(coupon.getStartTime()) + "-" + sdf.format(coupon.getEndTime())); |
| | |
| | | couponListVo.setUseCondition("满" + jsonObject.getDouble("num1") + "元可用"); |
| | | couponListVo.setFavorable(jsonObject.getDouble("num2") + "元"); |
| | | } |
| | | if (coupon.getType() == 2) {//满减{"num1":1} |
| | | if (coupon.getType() == 2) {//代金券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(jsonObject.getDouble("num1") + "元"); |
| | |
| | | package com.dsh.activity.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.activity.entity.UserCoupon; |
| | | import com.dsh.activity.feignclient.course.CoursePackageClient; |
| | | import com.dsh.activity.feignclient.course.model.CoursePackage; |
| | | import com.dsh.activity.mapper.UserCouponMapper; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.service.UserCouponService; |
| | | import com.dsh.activity.util.GDMapGeocodingUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCoupon> implements UserCouponService { |
| | | |
| | | @Resource |
| | | private CoursePackageClient coursePackageClient; |
| | | |
| | | @Autowired |
| | | private GDMapGeocodingUtil gdMapGeocodingUtil; |
| | | |
| | | |
| | | /** |
| | | * 获取购买课程可用优惠券列表 |
| | | * @param uid |
| | | * @param coursePackageId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<CouponListVo> queryAvailableCouponList(Integer uid, Integer coursePackageId, Double price, String lon, String lat) throws Exception { |
| | | CoursePackage coursePackage = coursePackageClient.queryCoursePackageById(coursePackageId); |
| | | Integer storeId = coursePackage.getStoreId(); |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(lon, lat); |
| | | String provinceCode = geocode.get("provinceCode"); |
| | | String cityCode = geocode.get("cityCode"); |
| | | List<Map<String, Object>> userCoupons = this.baseMapper.queryAvailableCouponList(uid, storeId, provinceCode, cityCode); |
| | | List<CouponListVo> listVos = new ArrayList<>(); |
| | | for (Map<String, Object> userCoupon : userCoupons) { |
| | | Integer type = Integer.valueOf(userCoupon.get("type").toString()); |
| | | CouponListVo couponListVo = new CouponListVo(); |
| | | couponListVo.setId(Long.valueOf(userCoupon.get("id").toString())); |
| | | couponListVo.setName(userCoupon.get("name").toString()); |
| | | couponListVo.setType(type); |
| | | couponListVo.setEffectiveTime(userCoupon.get("endTime").toString()); |
| | | String content = userCoupon.get("content").toString(); |
| | | if (type == 1) {//满减{"num1":1,"num2":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | if(price.compareTo(num1) <= 0){ |
| | | continue; |
| | | } |
| | | couponListVo.setUseCondition("满" + num1 + "元可用"); |
| | | couponListVo.setFavorable(jsonObject.getDouble("num2") + "元"); |
| | | } |
| | | if (type == 2) {//代金券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | if(price.compareTo(num1) <= 0){ |
| | | continue; |
| | | } |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(num1 + "元"); |
| | | } |
| | | if (type == 3) {//体验券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(jsonObject.getString("num1")); |
| | | } |
| | | listVos.add(couponListVo); |
| | | } |
| | | return listVos; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dsh.activity.util; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.dsh.activity.util.httpClinet.HttpClientUtil; |
| | | import com.dsh.activity.util.httpClinet.HttpResult; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 高德地图的地理编码工具类 |
| | | */ |
| | | @Component |
| | | public class GDMapGeocodingUtil { |
| | | |
| | | private String key = "fb131ad2dbfb3f39d7d37d244b92aa2d"; |
| | | |
| | | |
| | | /** |
| | | * 将行政区域名称转化为坐标 |
| | | * @param province |
| | | * @param city |
| | | * @param county |
| | | * @param address |
| | | * @return |
| | | */ |
| | | public Map<String, Object> geocoding(String province, String city, String county, String address) throws Exception{ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if(ToolUtil.isEmpty(province)){ |
| | | map.put("status", -1); |
| | | map.put("data", "省不能为空"); |
| | | return map; |
| | | } |
| | | if((ToolUtil.isEmpty(city) && ToolUtil.isNotEmpty(county)) || (ToolUtil.isEmpty(city) && ToolUtil.isNotEmpty(address))){ |
| | | map.put("status", -1); |
| | | map.put("data", "市不能为空"); |
| | | return map; |
| | | } |
| | | if((ToolUtil.isEmpty(county) && ToolUtil.isNotEmpty(address))){ |
| | | map.put("status", -1); |
| | | map.put("data", "县/区不能为空"); |
| | | return map; |
| | | } |
| | | |
| | | String url = "https://restapi.amap.com/v3/geocode/geo?key=" + key + "&output=JSON"; |
| | | url += "&address=" + province + (ToolUtil.isNotEmpty(city) ? city : "") + (ToolUtil.isNotEmpty(county) ? county : "") + (ToolUtil.isNotEmpty(address) ? address : ""); |
| | | HttpResult httpResult = HttpClientUtil.pushHttpRequset("GET", url, null, null, "json"); |
| | | JSONObject jsonObject = JSON.parseObject(httpResult.getData()); |
| | | String status = jsonObject.getString("status"); |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | | if(status.equals("1")){ |
| | | JSONArray geocodes = jsonObject.getJSONArray("geocodes"); |
| | | for(int i = 0; i < geocodes.size(); i++){ |
| | | String location = geocodes.getJSONObject(i).getString("location"); |
| | | list.add(location); |
| | | } |
| | | } |
| | | map.put("status", 0); |
| | | map.put("data", list); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | |
| | | public Map<String, Object> geocoding(String address) throws Exception{ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | String url = "https://restapi.amap.com/v3/geocode/geo?key=" + key + "&output=JSON&address=" + address; |
| | | HttpResult httpResult = HttpClientUtil.pushHttpRequset("GET", url, null, null, "json"); |
| | | JSONObject jsonObject = JSON.parseObject(httpResult.getData()); |
| | | String status = jsonObject.getString("status"); |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | | if(status.equals("1")){ |
| | | JSONArray geocodes = jsonObject.getJSONArray("geocodes"); |
| | | for(int i = 0; i < geocodes.size(); i++){ |
| | | String location = geocodes.getJSONObject(i).getString("location"); |
| | | list.add(location); |
| | | } |
| | | } |
| | | map.put("status", 0); |
| | | map.put("data", list); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据经纬度获取行政区域信息 |
| | | * @param lon |
| | | * @param lan |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public Map<String, String> geocode(String lon, String lan) throws Exception{ |
| | | String url = "https://restapi.amap.com/v3/geocode/regeo?key=" + key + "&location=" + lon + "," + lan; |
| | | HttpResult httpResult = HttpClientUtil.pushHttpRequset("GET", url, null, null, "json"); |
| | | JSONObject jsonObject = JSON.parseObject(httpResult.getData()); |
| | | Map<String, String> map = new HashMap<>(); |
| | | |
| | | if(jsonObject.getString("status").equals("1")){ |
| | | JSONObject regeocode = jsonObject.getJSONObject("regeocode"); |
| | | JSONObject addressComponent = regeocode.getJSONObject("addressComponent"); |
| | | String address = regeocode.getString("formatted_address"); |
| | | map.put("address", address); |
| | | String code = addressComponent.getString("adcode"); |
| | | String province = addressComponent.getString("province"); |
| | | String city = addressComponent.getString("city"); |
| | | String district = addressComponent.getString("district"); |
| | | map.put("province", province); |
| | | map.put("provinceCode", code.substring(0, 2) + "0000"); |
| | | map.put("city", city); |
| | | map.put("cityCode", code.substring(0, 4) + "00"); |
| | | map.put("district", district); |
| | | map.put("districtCode", code); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 坐标转换 |
| | | * @param locations 经度和纬度用","分割,经度在前,纬度在后,经纬度小数点后不得超过6位。多个坐标对之间用”|”进行分隔最多支持40对坐标。 |
| | | * @param coordsys 可选值:gps;mapbar;baidu;autonavi(不进行转换) |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public Map<String, String> convert(String locations, String coordsys) throws Exception{ |
| | | String url = "https://restapi.amap.com/v3/assistant/coordinate/convert?locations=" + locations + "&coordsys=" + coordsys + "&output=json&key=" + key; |
| | | HttpResult httpResult = HttpClientUtil.pushHttpRequset("GET", url, null, null, "json"); |
| | | JSONObject jsonObject = JSON.parseObject(httpResult.getData()); |
| | | Map<String, String> map = new HashMap<>(); |
| | | if("1".equals(jsonObject.getString("status"))){ |
| | | map.put("code", jsonObject.getString("infocode"));//"10000" |
| | | map.put("info", jsonObject.getString("info"));//status为0时,info返回错误原;否则返回“OK”。 |
| | | map.put("locations", jsonObject.getString("locations").split(";")[0]);//转换之后的坐标。若有多个坐标,则用 “;”进行区分和间隔 |
| | | }else{ |
| | | map.put("code", jsonObject.getString("infocode")); |
| | | map.put("info", jsonObject.getString("info"));//status为0时,info返回错误原;否则返回“OK”。 |
| | | } |
| | | return map; |
| | | } |
| | | } |
New file |
| | |
| | | /** |
| | | * Copyright (c) 2015-2016, Chill Zhuang 庄骞 (smallchill@163.com). |
| | | * <p> |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * <p> |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * <p> |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package com.dsh.activity.util; |
| | | |
| | | |
| | | |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import java.io.StringWriter; |
| | | import java.lang.reflect.Array; |
| | | import java.math.BigDecimal; |
| | | import java.net.URISyntaxException; |
| | | import java.util.*; |
| | | import java.util.Map.Entry; |
| | | |
| | | /** |
| | | * 高频方法集合类 |
| | | */ |
| | | public class ToolUtil { |
| | | |
| | | /** |
| | | * 获取随机位数的字符串 |
| | | * |
| | | * @author fengshuonan |
| | | * @Date 2017/8/24 14:09 |
| | | */ |
| | | public static String getRandomString(int length) { |
| | | String base = "abcdefghijklmnopqrstuvwxyz0123456789"; |
| | | Random random = new Random(); |
| | | StringBuffer sb = new StringBuffer(); |
| | | for (int i = 0; i < length; i++) { |
| | | int number = random.nextInt(base.length()); |
| | | sb.append(base.charAt(number)); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 判断一个对象是否是时间类型 |
| | | * |
| | | * @author stylefeng |
| | | * @Date 2017/4/18 12:55 |
| | | */ |
| | | public static String dateType(Object o) { |
| | | if (o instanceof Date) { |
| | | return DateUtil.getDay((Date) o); |
| | | } else { |
| | | return o.toString(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取异常的具体信息 |
| | | * |
| | | * @author fengshuonan |
| | | * @Date 2017/3/30 9:21 |
| | | * @version 2.0 |
| | | */ |
| | | public static String getExceptionMsg(Exception e) { |
| | | StringWriter sw = new StringWriter(); |
| | | try { |
| | | e.printStackTrace(new PrintWriter(sw)); |
| | | } finally { |
| | | try { |
| | | sw.close(); |
| | | } catch (IOException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | return sw.getBuffer().toString().replaceAll("\\$", "T"); |
| | | } |
| | | |
| | | /** |
| | | * 比较两个对象是否相等。<br> |
| | | * 相同的条件有两个,满足其一即可:<br> |
| | | * 1. obj1 == null && obj2 == null; 2. obj1.equals(obj2) |
| | | * |
| | | * @param obj1 对象1 |
| | | * @param obj2 对象2 |
| | | * @return 是否相等 |
| | | */ |
| | | public static boolean equals(Object obj1, Object obj2) { |
| | | return (obj1 != null) ? (obj1.equals(obj2)) : (obj2 == null); |
| | | } |
| | | |
| | | /** |
| | | * 计算对象长度,如果是字符串调用其length函数,集合类调用其size函数,数组调用其length属性,其他可遍历对象遍历计算长度 |
| | | * |
| | | * @param obj 被计算长度的对象 |
| | | * @return 长度 |
| | | */ |
| | | public static int length(Object obj) { |
| | | if (obj == null) { |
| | | return 0; |
| | | } |
| | | if (obj instanceof CharSequence) { |
| | | return ((CharSequence) obj).length(); |
| | | } |
| | | if (obj instanceof Collection) { |
| | | return ((Collection<?>) obj).size(); |
| | | } |
| | | if (obj instanceof Map) { |
| | | return ((Map<?, ?>) obj).size(); |
| | | } |
| | | |
| | | int count; |
| | | if (obj instanceof Iterator) { |
| | | Iterator<?> iter = (Iterator<?>) obj; |
| | | count = 0; |
| | | while (iter.hasNext()) { |
| | | count++; |
| | | iter.next(); |
| | | } |
| | | return count; |
| | | } |
| | | if (obj instanceof Enumeration) { |
| | | Enumeration<?> enumeration = (Enumeration<?>) obj; |
| | | count = 0; |
| | | while (enumeration.hasMoreElements()) { |
| | | count++; |
| | | enumeration.nextElement(); |
| | | } |
| | | return count; |
| | | } |
| | | if (obj.getClass().isArray() == true) { |
| | | return Array.getLength(obj); |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | /** |
| | | * 对象中是否包含元素 |
| | | * |
| | | * @param obj 对象 |
| | | * @param element 元素 |
| | | * @return 是否包含 |
| | | */ |
| | | public static boolean contains(Object obj, Object element) { |
| | | if (obj == null) { |
| | | return false; |
| | | } |
| | | if (obj instanceof String) { |
| | | if (element == null) { |
| | | return false; |
| | | } |
| | | return ((String) obj).contains(element.toString()); |
| | | } |
| | | if (obj instanceof Collection) { |
| | | return ((Collection<?>) obj).contains(element); |
| | | } |
| | | if (obj instanceof Map) { |
| | | return ((Map<?, ?>) obj).values().contains(element); |
| | | } |
| | | |
| | | if (obj instanceof Iterator) { |
| | | Iterator<?> iter = (Iterator<?>) obj; |
| | | while (iter.hasNext()) { |
| | | Object o = iter.next(); |
| | | if (equals(o, element)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | if (obj instanceof Enumeration) { |
| | | Enumeration<?> enumeration = (Enumeration<?>) obj; |
| | | while (enumeration.hasMoreElements()) { |
| | | Object o = enumeration.nextElement(); |
| | | if (equals(o, element)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | if (obj.getClass().isArray() == true) { |
| | | int len = Array.getLength(obj); |
| | | for (int i = 0; i < len; i++) { |
| | | Object o = Array.get(obj, i); |
| | | if (equals(o, element)) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 对象是否不为空(新增) |
| | | * |
| | | * @param o String,List,Map,Object[],int[],long[] |
| | | * @return |
| | | */ |
| | | public static boolean isNotEmpty(Object o) { |
| | | return !isEmpty(o); |
| | | } |
| | | |
| | | /** |
| | | * 对象是否为空 |
| | | * |
| | | * @param o String,List,Map,Object[],int[],long[] |
| | | * @return |
| | | */ |
| | | @SuppressWarnings("rawtypes") |
| | | public static boolean isEmpty(Object o) { |
| | | if (o == null) { |
| | | return true; |
| | | } |
| | | if (o instanceof String) { |
| | | if (o.toString().trim().equals("")) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof List) { |
| | | if (((List) o).size() == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof Map) { |
| | | if (((Map) o).size() == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof Set) { |
| | | if (((Set) o).size() == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof Object[]) { |
| | | if (((Object[]) o).length == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof int[]) { |
| | | if (((int[]) o).length == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof long[]) { |
| | | if (((long[]) o).length == 0) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 对象组中是否存在 Empty Object |
| | | * |
| | | * @param os 对象组 |
| | | * @return |
| | | */ |
| | | public static boolean isOneEmpty(Object... os) { |
| | | for (Object o : os) { |
| | | if (isEmpty(o)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 对象组中是否全是 Empty Object |
| | | * |
| | | * @param os |
| | | * @return |
| | | */ |
| | | public static boolean isAllEmpty(Object... os) { |
| | | for (Object o : os) { |
| | | if (!isEmpty(o)) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 是否为数字 |
| | | * |
| | | * @param obj |
| | | * @return |
| | | */ |
| | | public static boolean isNum(Object obj) { |
| | | try { |
| | | Integer.parseInt(obj.toString()); |
| | | } catch (Exception e) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 如果为空, 则调用默认值 |
| | | * |
| | | * @param str |
| | | * @return |
| | | */ |
| | | public static Object getValue(Object str, Object defaultValue) { |
| | | if (isEmpty(str)) { |
| | | return defaultValue; |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 强转->string,并去掉多余空格 |
| | | * |
| | | * @param str |
| | | * @return |
| | | */ |
| | | public static String toStr(Object str) { |
| | | return toStr(str, ""); |
| | | } |
| | | |
| | | /** |
| | | * 强转->string,并去掉多余空格 |
| | | * |
| | | * @param str |
| | | * @param defaultValue |
| | | * @return |
| | | */ |
| | | public static String toStr(Object str, String defaultValue) { |
| | | if (null == str) { |
| | | return defaultValue; |
| | | } |
| | | return str.toString().trim(); |
| | | } |
| | | |
| | | /** |
| | | * 强转->int |
| | | * |
| | | * @param obj |
| | | * @return |
| | | */ |
| | | // public static int toInt(Object value) { |
| | | // return toInt(value, -1); |
| | | // } |
| | | |
| | | /** |
| | | * 强转->int |
| | | * |
| | | * @param obj |
| | | * @param defaultValue |
| | | * @return |
| | | */ |
| | | // public static int toInt(Object value, int defaultValue) { |
| | | // return Convert.toInt(value, defaultValue); |
| | | // } |
| | | |
| | | /** |
| | | * 强转->long |
| | | * |
| | | * @param obj |
| | | * @return |
| | | */ |
| | | // public static long toLong(Object value) { |
| | | // return toLong(value, -1); |
| | | // } |
| | | |
| | | /** |
| | | * 强转->long |
| | | * |
| | | * @param obj |
| | | * @param defaultValue |
| | | * @return |
| | | */ |
| | | // public static long toLong(Object value, long defaultValue) { |
| | | // return Convert.toLong(value, defaultValue); |
| | | // } |
| | | // |
| | | // public static String encodeUrl(String url) { |
| | | // return URLKit.encode(url, CharsetKit.UTF_8); |
| | | // } |
| | | // |
| | | // public static String decodeUrl(String url) { |
| | | // return URLKit.decode(url, CharsetKit.UTF_8); |
| | | // } |
| | | |
| | | /** |
| | | * map的key转为小写 |
| | | * |
| | | * @param map |
| | | * @return Map<String , Object> |
| | | */ |
| | | public static Map<String, Object> caseInsensitiveMap(Map<String, Object> map) { |
| | | Map<String, Object> tempMap = new HashMap<>(); |
| | | for (String key : map.keySet()) { |
| | | tempMap.put(key.toLowerCase(), map.get(key)); |
| | | } |
| | | return tempMap; |
| | | } |
| | | |
| | | /** |
| | | * 获取map中第一个数据值 |
| | | * |
| | | * @param <K> Key的类型 |
| | | * @param <V> Value的类型 |
| | | * @param map 数据源 |
| | | * @return 返回的值 |
| | | */ |
| | | public static <K, V> V getFirstOrNull(Map<K, V> map) { |
| | | V obj = null; |
| | | for (Entry<K, V> entry : map.entrySet()) { |
| | | obj = entry.getValue(); |
| | | if (obj != null) { |
| | | break; |
| | | } |
| | | } |
| | | return obj; |
| | | } |
| | | |
| | | /** |
| | | * 创建StringBuilder对象 |
| | | * |
| | | * @return StringBuilder对象 |
| | | */ |
| | | public static StringBuilder builder(String... strs) { |
| | | final StringBuilder sb = new StringBuilder(); |
| | | for (String str : strs) { |
| | | sb.append(str); |
| | | } |
| | | return sb; |
| | | } |
| | | |
| | | /** |
| | | * 创建StringBuilder对象 |
| | | * |
| | | * @return StringBuilder对象 |
| | | */ |
| | | public static void builder(StringBuilder sb, String... strs) { |
| | | for (String str : strs) { |
| | | sb.append(str); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 去掉指定后缀 |
| | | * |
| | | * @param str 字符串 |
| | | * @param suffix 后缀 |
| | | * @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串 |
| | | */ |
| | | public static String removeSuffix(String str, String suffix) { |
| | | if (isEmpty(str) || isEmpty(suffix)) { |
| | | return str; |
| | | } |
| | | |
| | | if (str.endsWith(suffix)) { |
| | | return str.substring(0, str.length() - suffix.length()); |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | /** |
| | | * 当前时间 |
| | | * |
| | | * @author stylefeng |
| | | * @Date 2017/5/7 21:56 |
| | | */ |
| | | public static String currentTime() { |
| | | return DateUtil.getTime(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 判断是否是windows操作系统 |
| | | * |
| | | * @author stylefeng |
| | | * @Date 2017/5/24 22:34 |
| | | */ |
| | | public static Boolean isWinOs() { |
| | | String os = System.getProperty("os.name"); |
| | | if (os.toLowerCase().startsWith("win")) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取临时目录 |
| | | * |
| | | * @author stylefeng |
| | | * @Date 2017/5/24 22:35 |
| | | */ |
| | | public static String getTempPath() { |
| | | return System.getProperty("java.io.tmpdir"); |
| | | } |
| | | |
| | | /** |
| | | * 把一个数转化为int |
| | | * |
| | | * @author fengshuonan |
| | | * @Date 2017/11/15 下午11:10 |
| | | */ |
| | | public static Integer toInt(Object val) { |
| | | if (val instanceof Double) { |
| | | BigDecimal bigDecimal = new BigDecimal((Double) val); |
| | | return bigDecimal.intValue(); |
| | | } else { |
| | | return Integer.valueOf(val.toString()); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取项目路径 |
| | | */ |
| | | public static String getWebRootPath(String filePath) { |
| | | try { |
| | | String path = ToolUtil.class.getClassLoader().getResource("").toURI().getPath(); |
| | | path = path.replace("/WEB-INF/classes/", ""); |
| | | path = path.replace("/target/classes/", ""); |
| | | path = path.replace("file:/", ""); |
| | | if (ToolUtil.isEmpty(filePath)) { |
| | | return path; |
| | | } else { |
| | | return path + "/" + filePath; |
| | | } |
| | | } catch (URISyntaxException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取文件后缀名 不包含点 |
| | | */ |
| | | public static String getFileSuffix(String fileWholeName) { |
| | | if (ToolUtil.isEmpty(fileWholeName)) { |
| | | return "none"; |
| | | } |
| | | int lastIndexOf = fileWholeName.lastIndexOf("."); |
| | | return fileWholeName.substring(lastIndexOf + 1); |
| | | } |
| | | } |
New file |
| | |
| | | package com.dsh.activity.util.httpClinet; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.client.config.RequestConfig; |
| | | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
| | | import org.apache.http.entity.ContentType; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.apache.http.ssl.SSLContexts; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStream; |
| | | import java.nio.charset.Charset; |
| | | import java.security.KeyStore; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * http工具类 |
| | | */ |
| | | public class HttpClientUtil { |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(HttpClientUtil.class); |
| | | |
| | | private static PoolingHttpClientConnectionManager connectionManager; |
| | | |
| | | |
| | | { |
| | | //1.创建连接池管理器 |
| | | connectionManager = new PoolingHttpClientConnectionManager(60000, |
| | | TimeUnit.MILLISECONDS); |
| | | connectionManager.setMaxTotal(1000); |
| | | connectionManager.setDefaultMaxPerRoute(50); |
| | | } |
| | | |
| | | /** |
| | | * 创建一个httpClient对象 |
| | | */ |
| | | private static CloseableHttpClient getHttpCline(){ |
| | | return HttpClients.custom() |
| | | .setConnectionManager(connectionManager) |
| | | .disableAutomaticRetries() |
| | | .build(); |
| | | } |
| | | |
| | | private static RequestConfig getRequestConfig(){ |
| | | RequestConfig.Builder builder = RequestConfig.custom(); |
| | | builder.setSocketTimeout(60000)//3.1设置客户端等待服务端返回数据的超时时间 |
| | | .setConnectTimeout(30000)//3.2设置客户端发起TCP连接请求的超时时间 |
| | | .setExpectContinueEnabled(true) |
| | | .setConnectionRequestTimeout(30000);//3.3设置客户端从连接池获取链接的超时时间 |
| | | return builder.build(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 创建一个POST请求实例 |
| | | * @param url 请求地址 |
| | | * @param params 请求参数 |
| | | */ |
| | | private static CloseableHttpResponse setPostHttpRequset(String url, Map<String, Object> params, Map<String, String> header, String contentType) throws Exception{ |
| | | HttpPost httpPost = new HttpPost(url); |
| | | httpPost.setConfig(getRequestConfig()); |
| | | if(null != header){ |
| | | for(String key : header.keySet()){ |
| | | httpPost.setHeader(key, header.get(key)); |
| | | } |
| | | } |
| | | List<NameValuePair> list = new ArrayList<>(); |
| | | if(null != params){ |
| | | Set<String> keys = params.keySet(); |
| | | for(String key : keys){ |
| | | list.add(new BasicNameValuePair(key, null == params.get(key) ? null : params.get(key).toString())); |
| | | } |
| | | } |
| | | switch (contentType){ |
| | | case "form": |
| | | httpPost.setEntity(new UrlEncodedFormEntity(list, "UTF-8")); |
| | | break; |
| | | case "json": |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | String s =objectMapper.writeValueAsString(params); |
| | | httpPost.setEntity(new StringEntity(s, ContentType.create(ContentType.APPLICATION_JSON.getMimeType(), Charset.forName("UTF-8")))); |
| | | break; |
| | | } |
| | | return getHttpCline().execute(httpPost); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取get请求实例 |
| | | * @param url 请求地址 |
| | | * @param params 请求参数 |
| | | */ |
| | | private static CloseableHttpResponse setGetHttpRequset(String url, Map<String, Object> params, Map<String, String> header) throws Exception{ |
| | | StringBuffer sb = new StringBuffer(); |
| | | String p = ""; |
| | | if(null != params){ |
| | | Set<String> keys = params.keySet(); |
| | | for(String key : keys){ |
| | | sb.append(key + "=" + params.get(key) + "&"); |
| | | } |
| | | p = "?" + sb.substring(0, sb.length() - 1); |
| | | } |
| | | HttpGet httpGet = new HttpGet(url + p); |
| | | httpGet.setConfig(getRequestConfig()); |
| | | if(null != header){ |
| | | for(String key : header.keySet()){ |
| | | httpGet.setHeader(key, header.get(key)); |
| | | } |
| | | } |
| | | return getHttpCline().execute(httpGet); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发送http请求 |
| | | * @param mothed "GET、POST、PUT、HEAD、DELETE、HEAD、OPTIONS" |
| | | * @param url 请求地址 |
| | | * @param params 请求参数 |
| | | * @param header 请求头 |
| | | * @param contentType 参数请求方式form/json |
| | | * @return |
| | | */ |
| | | public static HttpResult pushHttpRequset(String mothed, String url, Map<String, Object> params, Map<String, String> header, String contentType) throws Exception{ |
| | | String randome = UUID.randomUUID().toString(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); |
| | | logger.info(sdf.format(new Date()) + "----(" + randome + ")请求参数:" + JSON.toJSONString(params)); |
| | | CloseableHttpResponse httpResponse = null; |
| | | switch (mothed){ |
| | | case "GET": |
| | | httpResponse = setGetHttpRequset(url, params, header); |
| | | break; |
| | | case "POST": |
| | | httpResponse = setPostHttpRequset(url, params, header, contentType); |
| | | break; |
| | | } |
| | | int statusCode = httpResponse.getStatusLine().getStatusCode(); |
| | | String content = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); |
| | | logger.info(sdf.format(new Date()) + "----(" + randome + ")返回结果:" + content); |
| | | HttpResult httpResult = HttpResult.getHttpResult(statusCode, content); |
| | | close(httpResponse); |
| | | return httpResult; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发送XML请求 |
| | | * @param url 请求地址 |
| | | * @param xml XML数据 |
| | | * @param header 自定义请求头 |
| | | * @return |
| | | */ |
| | | public static HttpResult pushHttpRequsetXml(String url, String xml, Map<String, String> header) throws Exception{ |
| | | HttpPost httpPost = new HttpPost(url); |
| | | httpPost.setConfig(getRequestConfig()); |
| | | for(String key : header.keySet()){ |
| | | httpPost.setHeader(key, header.get(key)); |
| | | } |
| | | httpPost.setHeader("Content-Type", "application/xml"); |
| | | httpPost.setEntity(new StringEntity(xml, "UTF-8")); |
| | | CloseableHttpResponse httpResponse = getHttpCline().execute(httpPost); |
| | | int statusCode = httpResponse.getStatusLine().getStatusCode(); |
| | | String content = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); |
| | | HttpResult httpResult = HttpResult.getHttpResult(statusCode, content); |
| | | close(httpResponse); |
| | | return httpResult; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 请求https发送XML请求 |
| | | * @param url 接口路径 |
| | | * @param xml 内容 |
| | | * @param header 请求头 |
| | | * @param certPassword 证书密码 |
| | | * @param certPath 证书路径 |
| | | * @param certType 证书类型 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public String pushHttpsRequsetXml(String url, String xml, Map<String, String> header, String certPassword, String certPath, String certType) throws Exception{ |
| | | HttpPost httpPost = new HttpPost(url); |
| | | for(String key : header.keySet()){ |
| | | httpPost.setHeader(key, header.get(key)); |
| | | } |
| | | httpPost.setHeader("Content-Type", "application/xml"); |
| | | httpPost.setEntity(new StringEntity(xml, "UTF-8")); |
| | | CloseableHttpClient httpCline = this.initCert(certPassword, certPath, certType); |
| | | CloseableHttpResponse httpResponse = httpCline.execute(httpPost); |
| | | String content = null; |
| | | if(httpResponse.getStatusLine().getStatusCode() == 200){ |
| | | content = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); |
| | | }else{ |
| | | content = "返回状态码:" + httpResponse.getStatusLine() + "。" + EntityUtils.toString(httpResponse.getEntity()); |
| | | } |
| | | this.close(httpResponse); |
| | | httpCline.close(); |
| | | return content; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 初始化https对象(带证书) |
| | | * @param key 证书密码 |
| | | * @param certPath 证书路径 |
| | | * @param certType 证书类型 |
| | | * @throws Exception |
| | | */ |
| | | private CloseableHttpClient initCert(String key, String certPath, String certType) throws Exception { |
| | | KeyStore keyStore = KeyStore.getInstance(certType); |
| | | InputStream inputStream = new FileInputStream(new File(certPath)); |
| | | try { |
| | | keyStore.load(inputStream, key.toCharArray()); |
| | | } finally { |
| | | inputStream.close(); |
| | | } |
| | | SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, key.toCharArray()).build(); |
| | | SSLConnectionSocketFactory sslsf = |
| | | new SSLConnectionSocketFactory(sslcontext, new String[] {"TLSv1"}, null, |
| | | SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); |
| | | return HttpClients.custom().setSSLSocketFactory(sslsf).build(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 关闭资源 |
| | | */ |
| | | private static void close(CloseableHttpResponse httpResponse){ |
| | | try { |
| | | if(null != httpResponse){ |
| | | EntityUtils.consume(httpResponse.getEntity());//此处高能,通过源码分析,由EntityUtils是否回收HttpEntity |
| | | httpResponse.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | try { |
| | | if(null != httpResponse){ |
| | | httpResponse.close(); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.dsh.activity.util.httpClinet; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * http请求返回封装 |
| | | */ |
| | | @Data |
| | | public class HttpResult { |
| | | /** |
| | | * 返回状态码 |
| | | */ |
| | | private Integer code; |
| | | /** |
| | | * 返回结果 |
| | | */ |
| | | private String data; |
| | | |
| | | /** |
| | | * 返回封装结果 |
| | | * @param code |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public static HttpResult getHttpResult(Integer code, String data){ |
| | | HttpResult httpResult = new HttpResult(); |
| | | httpResult.setCode(code); |
| | | httpResult.setData(data); |
| | | return httpResult; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dsh.config.Sharding_jdbc; |
| | | |
| | | |
| | | /** |
| | | * 数据源 |
| | | * @author pzb |
| | | * @Date 2022/11/21 21:13 |
| | | */ |
| | | public class DatasourceModel { |
| | | private String url; |
| | | private String username; |
| | | private String password; |
| | | private String driverClassName; |
| | | private Integer maxActive; |
| | | private Long maxWait; |
| | | private Integer minIdle; |
| | | private Integer initialSize; |
| | | |
| | | public String getUrl() { |
| | | return url; |
| | | } |
| | | |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | |
| | | public String getUsername() { |
| | | return username; |
| | | } |
| | | |
| | | public void setUsername(String username) { |
| | | this.username = username; |
| | | } |
| | | |
| | | public String getPassword() { |
| | | return password; |
| | | } |
| | | |
| | | public void setPassword(String password) { |
| | | this.password = password; |
| | | } |
| | | |
| | | public String getDriverClassName() { |
| | | return driverClassName; |
| | | } |
| | | |
| | | public void setDriverClassName(String driverClassName) { |
| | | this.driverClassName = driverClassName; |
| | | } |
| | | |
| | | public DatasourceModel getDatasourceModel(){ |
| | | return this; |
| | | } |
| | | |
| | | public Integer getMaxActive() { |
| | | return maxActive; |
| | | } |
| | | |
| | | public void setMaxActive(Integer maxActive) { |
| | | this.maxActive = maxActive; |
| | | } |
| | | |
| | | public Long getMaxWait() { |
| | | return maxWait; |
| | | } |
| | | |
| | | public void setMaxWait(Long maxWait) { |
| | | this.maxWait = maxWait; |
| | | } |
| | | |
| | | public Integer getMinIdle() { |
| | | return minIdle; |
| | | } |
| | | |
| | | public void setMinIdle(Integer minIdle) { |
| | | this.minIdle = minIdle; |
| | | } |
| | | |
| | | public Integer getInitialSize() { |
| | | return initialSize; |
| | | } |
| | | |
| | | public void setInitialSize(Integer initialSize) { |
| | | this.initialSize = initialSize; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dsh.config.Sharding_jdbc; |
| | | |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.PropertySource; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | |
| | | /** |
| | | * 数据源配置 |
| | | * @author pzb |
| | | * @Date 2022/11/21 20:32 |
| | | */ |
| | | @Component |
| | | @PropertySource(value = "classpath:sharding-jdbc.properties") |
| | | @ConfigurationProperties(prefix = "datasource.master0") |
| | | public class Master0DataSource extends DatasourceModel { |
| | | |
| | | } |
New file |
| | |
| | | package com.dsh.config.Sharding_jdbc; |
| | | |
| | | import com.alibaba.druid.pool.DruidDataSource; |
| | | import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory; |
| | | import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; |
| | | import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; |
| | | import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; |
| | | import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; |
| | | import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration; |
| | | import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import javax.sql.DataSource; |
| | | import java.sql.SQLException; |
| | | import java.util.*; |
| | | |
| | | @Configuration |
| | | public class ShardingConfig { |
| | | |
| | | @Autowired |
| | | private Master0DataSource master0DataSource; |
| | | |
| | | |
| | | @Bean |
| | | public DataSource getDataSource(){ |
| | | DataSource dataSource = null; |
| | | try { |
| | | Properties properties = new Properties(); |
| | | properties.setProperty("sql-show", "true"); |
| | | String databaseName = "m_0";//真实数据源名称,多个数据源用逗号区分 |
| | | dataSource = ShardingSphereDataSourceFactory.createDataSource(databaseName, createDataSourceMap(), createShardingRuleConfiguration(), properties); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return dataSource; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 配置多数据源 |
| | | * @return |
| | | */ |
| | | private Map<String, DataSource> createDataSourceMap() { |
| | | Map<String, DataSource> dataSourceMap = new HashMap<>(); |
| | | // 配置第 1 个数据源 |
| | | DruidDataSource dataSource1 = new DruidDataSource(); |
| | | dataSource1.setDriverClassName(master0DataSource.getDriverClassName()); |
| | | dataSource1.setUrl(master0DataSource.getUrl()); |
| | | dataSource1.setUsername(master0DataSource.getUsername()); |
| | | dataSource1.setPassword(master0DataSource.getPassword()); |
| | | dataSource1.setMaxActive(master0DataSource.getMaxActive()); |
| | | dataSource1.setMaxWait(master0DataSource.getMaxWait()); |
| | | dataSource1.setMinIdle(master0DataSource.getMinIdle()); |
| | | dataSource1.setInitialSize(master0DataSource.getInitialSize()); |
| | | dataSourceMap.put("m_0", dataSource1); |
| | | return dataSourceMap; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 分片配置 |
| | | * @return |
| | | */ |
| | | private Collection<RuleConfiguration> createShardingRuleConfiguration() { |
| | | LinkedList<RuleConfiguration> linkedList = new LinkedList(); |
| | | |
| | | //分片规则配置 |
| | | ShardingRuleConfiguration result1 = new ShardingRuleConfiguration(); |
| | | result1.getTables().add(getUserCouponTableRuleConfiguration()); |
| | | Properties props1 = new Properties(); |
| | | props1.setProperty("algorithm-expression", "t_user_coupon$->{userId % 5 + 1}"); |
| | | result1.getShardingAlgorithms().put("t_user_coupon-inline", new AlgorithmConfiguration("INLINE", props1)); |
| | | result1.getKeyGenerators().put("t_user_coupon-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); |
| | | |
| | | //分片规则配置 |
| | | result1.getTables().add(getUserPointsMerchandiseTableRuleConfiguration()); |
| | | Properties props2 = new Properties(); |
| | | props2.setProperty("algorithm-expression", "t_user_points_merchandise$->{userId % 5 + 1}"); |
| | | result1.getShardingAlgorithms().put("t_user_points_merchandise-inline", new AlgorithmConfiguration("INLINE", props2)); |
| | | result1.getKeyGenerators().put("t_user_points_merchandise-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); |
| | | |
| | | linkedList.add(result1); |
| | | |
| | | return linkedList; |
| | | } |
| | | |
| | | /** |
| | | * 分片算法配置 |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration getUserCouponTableRuleConfiguration() { |
| | | ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_user_coupon", "m$->{0}.t_user_coupon->{1..5}");//50 |
| | | result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("userId", "t_user_coupon-inline")); |
| | | result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_user_coupon-snowflake")); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 分片算法配置 |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration getUserPointsMerchandiseTableRuleConfiguration() { |
| | | ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_user_points_merchandise", "m$->{0}.t_user_points_merchandise$->{1..5}");//30 |
| | | result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("userId", "t_user_points_merchandise-inline")); |
| | | result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_user_points_merchandise-snowflake")); |
| | | return result; |
| | | } |
| | | |
| | | } |
| | |
| | | <!-- 开启二级缓存 --> |
| | | <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> |
| | | |
| | | |
| | | |
| | | <select id="queryAvailableCouponList" resultType="map"> |
| | | select |
| | | a.id, |
| | | b.`name`, |
| | | b.type, |
| | | b.content, |
| | | DATE_FORMAT('%y-%M-%d', b.startTime) as startTime, |
| | | DATE_FORMAT('%y-%M-%d', b.endTime) as endTime |
| | | from t_user_coupon a |
| | | left join t_coupon b on (a.couponId = b.id) |
| | | where a.`status` = 1 and b.type != 3 and a.userId = #{uid} and ( |
| | | b.useScope = 1 or (b.useScope = 2 and provinceCode = #{provinceCode} and cityCode = #{cityCode}) |
| | | or (b.useScope = 3 and b.id in (select couponId from t_coupon_store where storeId = #{storeId}))) |
| | | </select> |
| | | </mapper> |
New file |
| | |
| | | datasource.names=master0 |
| | | |
| | | #¿ª·¢»·¾³ |
| | | datasource.master0.type=com.alibaba.druid.pool.DruidDataSource |
| | | datasource.master0.driverClassName=com.mysql.cj.jdbc.Driver |
| | | datasource.master0.url=jdbc:mysql://192.168.110.80:3306/playpai_activity?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai |
| | | datasource.master0.username=root |
| | | datasource.master0.password=123456 |
| | | datasource.master0.maxActive=20 |
| | | datasource.master0.maxWait=60000 |
| | | datasource.master0.minIdle=5 |
| | | datasource.master0.initialSize=2 |
| | | |
| | | #Éú²ú»·¾³ |
| | | #datasource.master0.type=com.alibaba.druid.pool.DruidDataSource |
| | | #datasource.master0.driverClassName=com.mysql.cj.jdbc.Driver |
| | | #datasource.master0.url=jdbc:mysql://110.239.68.140:3306/playpai_activity?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B7 |
| | | #datasource.master0.username=root |
| | | #datasource.master0.password=G4LLlNouAGH1dijbyU&xDo$X |
| | | #datasource.master0.maxActive=200 |
| | | #datasource.master0.maxWait=60000 |
| | | #datasource.master0.minIdle=100 |
| | | #datasource.master0.initialSize=100 |
| | | |
| | | |
| | |
| | | |
| | | //分片规则配置 |
| | | ShardingRuleConfiguration result1 = new ShardingRuleConfiguration(); |
| | | result1.getTables().add(gettCoursePackagePaymentTableRuleConfiguration()); |
| | | result1.getTables().add(getCoursePackagePaymentTableRuleConfiguration()); |
| | | Properties props1 = new Properties(); |
| | | props1.setProperty("algorithm-expression", "t_course_package_payment$->{appUserId % 5 + 1}"); |
| | | result1.getShardingAlgorithms().put("t_course_package_payment-inline", new AlgorithmConfiguration("INLINE", props1)); |
| | |
| | | * 分片算法配置 |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration gettCoursePackagePaymentTableRuleConfiguration() { |
| | | private ShardingTableRuleConfiguration getCoursePackagePaymentTableRuleConfiguration() { |
| | | ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_payment", "m$->{0}.t_course_package_payment$->{1..5}");//50 |
| | | result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("appUserId", "t_course_package_payment-inline")); |
| | | result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_course_package_payment-snowflake")); |
| | |
| | | import com.dsh.course.entity.TCourse; |
| | | import com.dsh.course.entity.TCoursePackageType; |
| | | import com.dsh.course.feignclient.model.ExerciseVideo; |
| | | import com.dsh.course.model.BaseVo; |
| | | import com.dsh.course.model.CoursePackageInfo; |
| | | import com.dsh.course.model.CoursePackageList; |
| | | import com.dsh.course.model.CoursePackageListVo; |
| | | import com.dsh.course.model.*; |
| | | import com.dsh.course.service.TCoursePackageService; |
| | | import com.dsh.course.service.TCoursePackageTypeService; |
| | | import com.dsh.course.service.TCourseService; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public ResultUtil paymentCourse(@RequestBody PaymentCourseVo paymentCourseVo){ |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if(null == uid){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | return coursePackageService.paymentCourse(uid, paymentCourseVo); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dsh.course.controller; |
| | | |
| | | import com.dsh.course.entity.TCoursePackage; |
| | | import com.dsh.course.service.TCoursePackageService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/5 9:58 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("") |
| | | public class CoursePackageController { |
| | | |
| | | @Autowired |
| | | private TCoursePackageService coursePackageService; |
| | | |
| | | |
| | | /** |
| | | * 根据id获取课包 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/coursePackage/queryCoursePackageById") |
| | | public TCoursePackage queryCoursePackageById(@RequestBody Integer id){ |
| | | try { |
| | | TCoursePackage coursePackage = coursePackageService.getById(id); |
| | | return coursePackage; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | |
| | | tCoursePackagePayments.forEach(cou -> { |
| | | CourseHoursType hoursType = new CourseHoursType(); |
| | | hoursType.setCourseConfigId(cou.getId()); |
| | | hoursType.setCourseConfigId(cou.getClassHours()); |
| | | hoursType.setCourseHourNums(cou.getClassHours()); |
| | | typeList.add(hoursType); |
| | | }); |
| | | TCoursePackagePayment tCoursePackagePayment = tCoursePackagePayments.get(0); |
| | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | |
| | | /** |
| | | * 添加时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date insertTime; |
| | | |
| | | } |
| | |
| | | */ |
| | | private Integer classHours; |
| | | /** |
| | | * 原价 |
| | | */ |
| | | private Double originalPrice; |
| | | /** |
| | | * 优惠券id |
| | | */ |
| | | private Long userCouponId; |
| | | /** |
| | | * 现金支付价格 |
| | | */ |
| | | private BigDecimal cashPayment; |
New file |
| | |
| | | package com.dsh.course.feignclient.activity; |
| | | |
| | | import com.dsh.course.feignclient.activity.model.Coupon; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/5 21:06 |
| | | */ |
| | | @FeignClient("mb-cloud-activity") |
| | | public interface CouponClient { |
| | | |
| | | |
| | | /** |
| | | * 根据id获取优惠券 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @PostMapping("/coupon/queryCouponById") |
| | | Coupon queryCouponById(Integer id); |
| | | } |
New file |
| | |
| | | package com.dsh.course.feignclient.activity; |
| | | |
| | | import com.dsh.course.feignclient.activity.model.UserCoupon; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/5 20:54 |
| | | */ |
| | | @FeignClient("mb-cloud-activity") |
| | | public interface UserCouponClient { |
| | | |
| | | |
| | | /** |
| | | * 根据id获取用户优惠券数据 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @PostMapping("/userCoupon/queryUserCouponById") |
| | | UserCoupon queryUserCouponById(Long id); |
| | | } |
New file |
| | |
| | | package com.dsh.course.feignclient.activity.model; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/5 21:06 |
| | | */ |
| | | @Data |
| | | public class Coupon { |
| | | private Integer id; |
| | | /** |
| | | * 优惠券名称 |
| | | */ |
| | | private String name; |
| | | /** |
| | | * 优惠券类型(1=满减券,2=代金券,3=体验券) |
| | | */ |
| | | private Integer type; |
| | | /** |
| | | * 优惠券规则JSON |
| | | */ |
| | | private String content; |
| | | /** |
| | | * 优惠券说明 |
| | | */ |
| | | private String illustrate; |
| | | /** |
| | | * 发放方式(1=积分购买,2=注册赠送,3=自动发券) |
| | | */ |
| | | private Integer distributionMethod; |
| | | /** |
| | | * 兑换方式(1=积分,2=积分+现金) |
| | | */ |
| | | private Integer redemptionMethod; |
| | | /** |
| | | * 所需现金 |
| | | */ |
| | | private BigDecimal cash; |
| | | /** |
| | | * 所属积分 |
| | | */ |
| | | private BigDecimal integral; |
| | | /** |
| | | * 用户人群(1=全部用户,2=年度会员,3=已有学员用户) |
| | | */ |
| | | private Integer userPopulation; |
| | | /** |
| | | * 发放数量 |
| | | */ |
| | | private Integer quantityIssued; |
| | | /** |
| | | * 限领数量 |
| | | */ |
| | | private Integer pickUpQuantity; |
| | | /** |
| | | * 开始时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date startTime; |
| | | /** |
| | | * 结束时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date endTime; |
| | | /** |
| | | * 使用范围(1=全国,2=指定城市,3=指定门店) |
| | | */ |
| | | private Integer useScope; |
| | | /** |
| | | * 省 |
| | | */ |
| | | private String province; |
| | | /** |
| | | * 省编号 |
| | | */ |
| | | private String provinceCode; |
| | | /** |
| | | * 市 |
| | | */ |
| | | private String city; |
| | | /** |
| | | * 市编号 |
| | | */ |
| | | private String cityCode; |
| | | /** |
| | | * 审核状态(1=待审核,2=已通过,3=已拒绝) |
| | | */ |
| | | private Integer auditStatus; |
| | | /** |
| | | * 审核人id |
| | | */ |
| | | private Integer auditUserId; |
| | | /** |
| | | * 审核备注 |
| | | */ |
| | | private String auditRemark; |
| | | /** |
| | | * 状态(1=未开始,2=已开始,3=已结束,4=已取消) |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * 状态(1=正常,2=冻结,3=删除) |
| | | */ |
| | | private Integer state; |
| | | /** |
| | | * 添加时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date insertTime; |
| | | } |
New file |
| | |
| | | package com.dsh.course.feignclient.activity.model; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/5 20:55 |
| | | */ |
| | | @Data |
| | | public class UserCoupon { |
| | | private Long id; |
| | | /** |
| | | * 优惠券id |
| | | */ |
| | | private Integer couponId; |
| | | /** |
| | | * 用户id |
| | | */ |
| | | private Integer userId; |
| | | /** |
| | | * 状态(1=待核销,2=已核销) |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * 核销人员id |
| | | */ |
| | | private Integer verificationUserId; |
| | | /** |
| | | * 核销时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date verificationTime; |
| | | /** |
| | | * 领取时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date insertTime; |
| | | } |
| | |
| | | public class CourseHoursType { |
| | | |
| | | @ApiModelProperty(value = "课时id") |
| | | private Integer courseConfigId; |
| | | private Long courseConfigId; |
| | | |
| | | @ApiModelProperty(value = "课时数") |
| | | private Integer courseHourNums; |
New file |
| | |
| | | package com.dsh.course.model; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/7/5 20:29 |
| | | */ |
| | | @Data |
| | | @ApiModel |
| | | public class PaymentCourseVo { |
| | | @ApiModelProperty(value = "课程id", dataType = "int", required = true) |
| | | private Integer id; |
| | | @ApiModelProperty(value = "支付方式(1=微信,2=支付宝,3=玩湃币)", dataType = "int", required = true) |
| | | private Integer payType; |
| | | @ApiModelProperty(value = "支付金额", dataType = "double", required = true) |
| | | private Double price; |
| | | @ApiModelProperty(value = "课时id", dataType = "int", required = true) |
| | | private Integer coursePackagePaymentConfigId; |
| | | @ApiModelProperty(value = "学员id,多个分号分隔", dataType = "string", required = true) |
| | | private String studentIds; |
| | | @ApiModelProperty(value = "优惠券id", dataType = "long", required = false) |
| | | private Long couponId; |
| | | } |
| | |
| | | import com.dsh.course.model.CoursePackageInfo; |
| | | import com.dsh.course.model.CoursePackageList; |
| | | import com.dsh.course.model.CoursePackageListVo; |
| | | import com.dsh.course.model.PaymentCourseVo; |
| | | import com.dsh.course.util.ResultUtil; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | CoursePackageInfo queryCourseInfo(Integer uid, Integer id, String lon, String lat) throws Exception; |
| | | |
| | | |
| | | /** |
| | | * 课程报名支付 |
| | | * @param uid |
| | | * @param paymentCourseVo |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | ResultUtil paymentCourse(Integer uid, PaymentCourseVo paymentCourseVo) throws Exception; |
| | | } |
| | |
| | | import com.dsh.course.entity.CoursePackagePaymentConfig; |
| | | import com.dsh.course.entity.TCoursePackage; |
| | | import com.dsh.course.entity.TCoursePackageDiscount; |
| | | import com.dsh.course.entity.TCoursePackagePayment; |
| | | import com.dsh.course.feignclient.account.AppUserClient; |
| | | import com.dsh.course.feignclient.account.StudentClient; |
| | | import com.dsh.course.feignclient.account.model.AppUser; |
| | | import com.dsh.course.feignclient.account.model.Student; |
| | | import com.dsh.course.feignclient.activity.CouponClient; |
| | | import com.dsh.course.feignclient.activity.UserCouponClient; |
| | | import com.dsh.course.feignclient.activity.model.Coupon; |
| | | import com.dsh.course.feignclient.activity.model.UserCoupon; |
| | | import com.dsh.course.feignclient.other.StoreClient; |
| | | import com.dsh.course.feignclient.other.model.Store; |
| | | import com.dsh.course.mapper.TCoursePackageMapper; |
| | |
| | | import com.dsh.course.service.TCoursePackageService; |
| | | import com.dsh.course.util.GDMapGeocodingUtil; |
| | | import com.dsh.course.util.GeodesyUtil; |
| | | import com.dsh.course.util.ResultUtil; |
| | | import com.dsh.course.util.ToolUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | |
| | | @Resource |
| | | private UserCouponClient userCouponClient; |
| | | |
| | | @Resource |
| | | private CouponClient couponClient; |
| | | |
| | | |
| | | |
| | |
| | | coursePackageInfo.setStoreAddress(store.getAddress()); |
| | | coursePackageInfo.setLon(store.getLon()); |
| | | coursePackageInfo.setLat(store.getLat()); |
| | | 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(); |
| | | coursePackageInfo.setDistance(wgs84); |
| | | 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(); |
| | | coursePackageInfo.setDistance(wgs84); |
| | | } |
| | | |
| | | String[] split = coursePackage.getClassWeeks().split(";"); |
| | | coursePackageInfo.setWeeks(Arrays.asList(split)); |
| | |
| | | coursePackagePaymentConfigVo.setClassHours(coursePackagePaymentConfig.getClassHours()); |
| | | coursePackagePaymentConfigVo.setPayType(coursePackage.getPayType()); |
| | | coursePackagePaymentConfigVo.setPlayPaiCoin(coursePackagePaymentConfig.getPlayPaiCoin()); |
| | | //会员显示原价和会员价(最低)。非会员显示会员价和支付价(最低) |
| | | //会员显示原价和支付价(会员价)。非会员显示会员价和支付价(最低) |
| | | if(appUser.getIsVip() == 0){//非会员 |
| | | List<TCoursePackageDiscount> list2 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId()) |
| | | .eq("type", 1).eq("auditStatus", 2)); |
| | |
| | | coursePackageInfo.setStudent(studentVo); |
| | | return coursePackageInfo; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 课程包名支付 |
| | | * @param uid |
| | | * @param paymentCourseVo |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil paymentCourse(Integer uid, PaymentCourseVo paymentCourseVo) throws Exception { |
| | | AppUser appUser = appUserClient.queryAppUser(uid); |
| | | CoursePackageInfo coursePackageInfo = queryCourseInfo(uid, paymentCourseVo.getId(), null, null); |
| | | List<CoursePackagePaymentConfigVo> list = coursePackageInfo.getList(); |
| | | |
| | | String[] students = paymentCourseVo.getStudentIds().split(";"); |
| | | for (CoursePackagePaymentConfigVo coursePackagePaymentConfigVo : list) { |
| | | if(paymentCourseVo.getCoursePackagePaymentConfigId().compareTo(coursePackagePaymentConfigVo.getId()) == 0){ |
| | | Integer payType = coursePackagePaymentConfigVo.getPayType(); |
| | | if(payType == 1 && paymentCourseVo.getPayType() == 3){//现金支付 |
| | | return ResultUtil.error("支付方式错误,请刷新后重试"); |
| | | } |
| | | if(payType == 2 && paymentCourseVo.getPayType() != 3){//玩湃币支付 |
| | | return ResultUtil.error("支付方式错误,请刷新后重试"); |
| | | } |
| | | Double paymentPrice = coursePackagePaymentConfigVo.getPaymentPrice();//支付价 |
| | | paymentPrice = new BigDecimal(students.length).multiply(new BigDecimal(paymentPrice)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | Double playPaiCoin = coursePackagePaymentConfigVo.getPlayPaiCoin().doubleValue();//支付币 |
| | | playPaiCoin = new BigDecimal(students.length).multiply(new BigDecimal(playPaiCoin)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | if(payType == 1 && paymentPrice.compareTo(paymentCourseVo.getPrice()) != 0){ |
| | | return ResultUtil.error("支付金额异常,请刷新后重试"); |
| | | } |
| | | if(payType == 2 && playPaiCoin.compareTo(paymentCourseVo.getPrice()) != 0){ |
| | | return ResultUtil.error("支付金额异常,请刷新后重试"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Double price = paymentCourseVo.getPrice();//支付金额 |
| | | |
| | | //校验优惠券 |
| | | Long couponId = paymentCourseVo.getCouponId(); |
| | | if(null != couponId && paymentCourseVo.getPayType() != 3){ |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(couponId); |
| | | if(userCoupon.getStatus() == 2){ |
| | | return ResultUtil.error("优惠券已被核销"); |
| | | } |
| | | Coupon coupon = couponClient.queryCouponById(userCoupon.getCouponId()); |
| | | long time = coupon.getEndTime().getTime(); |
| | | if(System.currentTimeMillis() >= time){ |
| | | return ResultUtil.error("优惠券已过期"); |
| | | } |
| | | if(coupon.getType() == 1){//满减 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | Double num2 = jsonObject.getDouble("num2"); |
| | | if(price.compareTo(num1) <= 0){ |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | |
| | | price = new BigDecimal(price).subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | if(coupon.getType() == 2){//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | if(price.compareTo(num1) <= 0){ |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | price = new BigDecimal(price).subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | } |
| | | |
| | | if(paymentCourseVo.getPayType() == 1){//微信支付 |
| | | |
| | | } |
| | | if(paymentCourseVo.getPayType() == 2){//支付宝支付 |
| | | |
| | | } |
| | | if(paymentCourseVo.getPayType() == 3){//玩湃币支付 |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public ResultUtil weChatPaymentCourse(Integer uid, PaymentCourseVo paymentCourseVo){ |
| | | TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment(); |
| | | // coursePackagePayment |
| | | return ResultUtil.success(); |
| | | } |
| | | } |