| | |
| | | import com.ruoyi.account.api.dto.CouponListDto; |
| | | import com.ruoyi.account.api.dto.GrantCouponDto; |
| | | import com.ruoyi.account.api.model.TAppCoupon; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.account.api.model.TAppUserCar; |
| | | import com.ruoyi.account.api.model.TAppUserTag; |
| | | import com.ruoyi.account.api.query.ExchangeRecordGoodsQuery; |
| | | import com.ruoyi.account.service.TAppUserService; |
| | | import com.ruoyi.account.service.TAppUserTagService; |
| | | import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient; |
| | | import com.ruoyi.chargingPile.api.model.TChargingGun; |
| | | import com.ruoyi.chargingPile.api.model.TChargingPile; |
| | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | return R.ok(tAppCouponService.pagelist(couponId)); |
| | | } |
| | | |
| | | @Autowired |
| | | private TAppUserTagService appUserTagService; |
| | | @Autowired |
| | | private TAppUserService appUserService; |
| | | /** |
| | | * 后台远程调用 给用户发放优惠券 |
| | | */ |
| | | @PostMapping("/grantCoupon") |
| | | public R grantCoupon(@RequestBody GrantCouponDto dto){ |
| | | List<TAppCoupon> res = new ArrayList<>(); |
| | | for (String s : dto.getUserIds().split(",")) { |
| | | TAppCoupon tAppCoupon = new TAppCoupon(); |
| | | tAppCoupon.setAppUserId(Long.valueOf(s)); |
| | | tAppCoupon.setCouponId(dto.getCouponId()); |
| | | tAppCoupon.setEndTime(dto.getEndTime()); |
| | | tAppCoupon.setWaysToObtain(dto.getWaysToObtain()); |
| | | tAppCoupon.setStatus(1); |
| | | R<TCoupon> couponById = otherClient.getCouponById(Integer.valueOf(s)); |
| | | tAppCoupon.setCouponJson(JSON.toJSONString(couponById.getData())); |
| | | res.add(tAppCoupon); |
| | | switch (dto.getType()){ |
| | | case 1: |
| | | // 根据标签ids 查询用户ids |
| | | List<Long> collect = appUserTagService.list(new QueryWrapper<TAppUserTag>() |
| | | .in("user_tag_id", Arrays.asList(dto.getTags().split(",")))) |
| | | .stream().map(TAppUserTag::getAppUserId).collect(Collectors.toList()); |
| | | for (Long l : collect) { |
| | | TAppCoupon tAppCoupon = new TAppCoupon(); |
| | | tAppCoupon.setAppUserId(l); |
| | | tAppCoupon.setCouponId(dto.getCouponId()); |
| | | tAppCoupon.setEndTime(dto.getEndTime()); |
| | | tAppCoupon.setWaysToObtain(dto.getWaysToObtain()); |
| | | tAppCoupon.setStatus(1); |
| | | res.add(tAppCoupon); |
| | | } |
| | | tAppCouponService.saveBatch(res); |
| | | break; |
| | | case 2: |
| | | // 根据市codes 查询用户ids |
| | | List<Long> collect1 = appUserService.list(new QueryWrapper<TAppUser>() |
| | | .in("city_code", Arrays.asList(dto.getCityCode().split(",")))) |
| | | .stream().map(TAppUser::getId).collect(Collectors.toList()); |
| | | for (Long l : collect1) { |
| | | TAppCoupon tAppCoupon = new TAppCoupon(); |
| | | tAppCoupon.setAppUserId(l); |
| | | tAppCoupon.setCouponId(dto.getCouponId()); |
| | | tAppCoupon.setEndTime(dto.getEndTime()); |
| | | tAppCoupon.setWaysToObtain(dto.getWaysToObtain()); |
| | | tAppCoupon.setStatus(1); |
| | | res.add(tAppCoupon); |
| | | } |
| | | tAppCouponService.saveBatch(res); |
| | | break; |
| | | case 3: |
| | | for (String s : dto.getUserIds().split(",")) { |
| | | TAppCoupon tAppCoupon = new TAppCoupon(); |
| | | tAppCoupon.setAppUserId(Long.valueOf(s)); |
| | | tAppCoupon.setCouponId(dto.getCouponId()); |
| | | tAppCoupon.setEndTime(dto.getEndTime()); |
| | | tAppCoupon.setWaysToObtain(dto.getWaysToObtain()); |
| | | tAppCoupon.setStatus(1); |
| | | res.add(tAppCoupon); |
| | | } |
| | | tAppCouponService.saveBatch(res); |
| | | break; |
| | | } |
| | | tAppCouponService.saveBatch(res); |
| | | |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | } |