|
|
@@ -15,11 +15,9 @@ import com.cyksj.mapper.manage.coupon.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.CorpCouponSendReq;
|
|
|
import com.cyksj.model.request.CouponActiveReq;
|
|
|
+import com.cyksj.model.request.CouponClassificationReq;
|
|
|
import com.cyksj.model.request.CouponDistributeReq;
|
|
|
-import com.cyksj.model.views.CouponActiveView;
|
|
|
-import com.cyksj.model.views.CouponDistributePopularizeView;
|
|
|
-import com.cyksj.model.views.CouponRecommendView;
|
|
|
-import com.cyksj.model.views.CouponView;
|
|
|
+import com.cyksj.model.views.*;
|
|
|
import com.cyksj.service.corp.msg.CorpEventActionService;
|
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
@@ -27,15 +25,15 @@ import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.Assert;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.constraints.Min;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/*
|
|
|
@@ -71,6 +69,10 @@ public class CouponController {
|
|
|
|
|
|
private final CorpUserAuthMapper corpUserAuthMapper;
|
|
|
|
|
|
+ private final CouponClassificationMapper couponClassificationMapper;
|
|
|
+
|
|
|
+ private final HttpServletRequest request;
|
|
|
+
|
|
|
/**
|
|
|
* 新增优惠券
|
|
|
*/
|
|
|
@@ -151,14 +153,9 @@ public class CouponController {
|
|
|
public Result<SearchResult<CouponDistributePopularizeView>> getRelationList(HttpServletRequest request) {
|
|
|
SearchResult<CouponDistributePopularizeView> search = beanSearcher.search(CouponDistributePopularizeView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
search.getDataList().forEach(data -> {
|
|
|
- List<CouponUser> couponUsers = couponUserMapper.selectList(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getPopularizeId, data.getId()).select(CouponUser::getId, CouponUser::getStatus));
|
|
|
- Optional.ofNullable(couponUsers).ifPresentOrElse(list -> {
|
|
|
- Map<CouponUser.Status, List<CouponUser>> listMap = list.stream().collect(Collectors.groupingBy(CouponUser::getStatus));
|
|
|
- List<CouponUser> used = listMap.get(CouponUser.Status.used);
|
|
|
- data.setUsedNum(used == null ? 0 : used.size());
|
|
|
- }, () -> {
|
|
|
- data.setUsedNum(0);
|
|
|
- });
|
|
|
+ Integer usedNum = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
|
|
|
+ .eq(CouponUser::getPopularizeId, data.getId()).eq(CouponUser::getStatus, CouponUser.Status.used));
|
|
|
+ data.setUsedNum(usedNum);
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
@@ -180,8 +177,13 @@ public class CouponController {
|
|
|
SearchResult<CouponView> search = beanSearcher.search(CouponView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
search.getDataList().forEach(data -> {
|
|
|
data.setRelationNum(couponDistributePopularizeMapper.selectCount(Wrappers.lambdaQuery(CouponDistributePopularize.class).eq(CouponDistributePopularize::getCouponId, data.getId())));
|
|
|
- String str = couponSkuMapper.selectGoodsSkuStr(data.getId());
|
|
|
- data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
+
|
|
|
+ Integer usedNum = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
|
|
|
+ .eq(CouponUser::getCouponId, data.getId()).eq(CouponUser::getStatus, CouponUser.Status.used));
|
|
|
+ data.setUsedNum(usedNum);
|
|
|
+
|
|
|
+ List<GoodsDonSkuView> skuViewList = couponSkuMapper.selectGoodsSkuViewList(data.getId());
|
|
|
+ data.setSkuViewList(skuViewList);
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
@@ -193,18 +195,15 @@ public class CouponController {
|
|
|
public Result<SearchResult<CouponActiveView>> couponActiveList(HttpServletRequest request) {
|
|
|
SearchResult<CouponActiveView> search = beanSearcher.search(CouponActiveView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
search.getDataList().forEach(data -> {
|
|
|
- List<CouponUser> couponUsers = couponUserMapper.selectList(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getCouponActiveId, data.getId()).select(CouponUser::getId, CouponUser::getStatus));
|
|
|
- String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
|
|
|
- data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
- Optional.ofNullable(couponUsers).ifPresentOrElse(list -> {
|
|
|
- data.setReceiptNum(list.size());
|
|
|
- Map<CouponUser.Status, List<CouponUser>> listMap = list.stream().collect(Collectors.groupingBy(CouponUser::getStatus));
|
|
|
- List<CouponUser> used = listMap.get(CouponUser.Status.used);
|
|
|
- data.setUsedNum(used == null ? 0 : used.size());
|
|
|
- }, () -> {
|
|
|
- data.setReceiptNum(0);
|
|
|
- data.setUsedNum(0);
|
|
|
- });
|
|
|
+ Integer usedNum = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
|
|
|
+ .eq(CouponUser::getCouponActiveId, data.getId()).eq(CouponUser::getStatus, CouponUser.Status.used));
|
|
|
+ Integer receiptNum = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
|
|
|
+ .eq(CouponUser::getCouponActiveId, data.getId()));
|
|
|
+ data.setReceiptNum(receiptNum);
|
|
|
+ data.setUsedNum(usedNum);
|
|
|
+
|
|
|
+ List<GoodsDonSkuView> skuViewList = couponSkuMapper.selectGoodsSkuViewList(data.getCouponId());
|
|
|
+ data.setSkuViewList(skuViewList);
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
@@ -252,18 +251,15 @@ public class CouponController {
|
|
|
public Result<SearchResult<CouponRecommendView>> couponRecommendList(HttpServletRequest request) {
|
|
|
SearchResult<CouponRecommendView> search = beanSearcher.search(CouponRecommendView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
search.getDataList().forEach(data -> {
|
|
|
- List<CouponUser> couponUsers = couponUserMapper.selectList(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getRecommendId, data.getId()).select(CouponUser::getId, CouponUser::getStatus));
|
|
|
- String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
|
|
|
- data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
- Optional.ofNullable(couponUsers).ifPresentOrElse(list -> {
|
|
|
- data.setReceiptNum(list.size());
|
|
|
- Map<CouponUser.Status, List<CouponUser>> listMap = list.stream().collect(Collectors.groupingBy(CouponUser::getStatus));
|
|
|
- List<CouponUser> used = listMap.get(CouponUser.Status.used);
|
|
|
- data.setUsedNum(used == null ? 0 : used.size());
|
|
|
- }, () -> {
|
|
|
- data.setReceiptNum(0);
|
|
|
- data.setUsedNum(0);
|
|
|
- });
|
|
|
+ Integer usedNum = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
|
|
|
+ .eq(CouponUser::getRecommendId, data.getId()).eq(CouponUser::getStatus, CouponUser.Status.used));
|
|
|
+ Integer receiptNum = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
|
|
|
+ .eq(CouponUser::getRecommendId, data.getId()));
|
|
|
+ data.setReceiptNum(receiptNum);
|
|
|
+ data.setUsedNum(usedNum);
|
|
|
+
|
|
|
+ List<GoodsDonSkuView> skuViewList = couponSkuMapper.selectGoodsSkuViewList(data.getCouponId());
|
|
|
+ data.setSkuViewList(skuViewList);
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
@@ -319,6 +315,83 @@ public class CouponController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("发放优惠券成功");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增优惠券分类
|
|
|
+ */
|
|
|
+ @PostMapping("/post/classification")
|
|
|
+ public Result<String> saveClassification(@RequestBody @Validated CouponClassification classification) {
|
|
|
+ try {
|
|
|
+ couponClassificationMapper.insert(classification);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+ throw BusinessRuntimeException.getInstance("优惠券名称重复");
|
|
|
+ }
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("新增优惠券成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除优惠券分类
|
|
|
+ */
|
|
|
+ @DeleteMapping("/delete/classification/{classificationId}")
|
|
|
+ public Result<String> deletedClassificationById(@PathVariable Long classificationId) {
|
|
|
+ Integer count = couponMapper.selectCount(Wrappers.lambdaQuery(Coupon.class)
|
|
|
+ .eq(Coupon::getClassificationId, classificationId)
|
|
|
+ .eq(Coupon::getDeleted, true));
|
|
|
+ if (count > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("分类存在优惠券");
|
|
|
+ }
|
|
|
+ couponClassificationMapper.deleteById(classificationId);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("删除优惠券分类成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优惠券转移分类
|
|
|
+ */
|
|
|
+ @PutMapping("/update/coupon/classification")
|
|
|
+ public Result<String> changeCouponClassificationByClassificationId(@RequestBody @Validated CouponClassificationReq req) {
|
|
|
+ Long classificationId = req.getId();
|
|
|
+ Long newClassificationId = req.getNewClassificationId();
|
|
|
+ List<Coupon> coupons = couponMapper.selectList(Wrappers.lambdaQuery(Coupon.class)
|
|
|
+ .eq(Coupon::getClassificationId, classificationId)
|
|
|
+ .eq(Coupon::getDeleted, true)
|
|
|
+ .select(Coupon::getId));
|
|
|
+ if (coupons.isEmpty()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("该分类下无优惠券");
|
|
|
+ }
|
|
|
+ CouponClassification couponClassification = couponClassificationMapper.selectById(newClassificationId);
|
|
|
+ if (couponClassification == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("要转移分类不存在");
|
|
|
+ }
|
|
|
+ couponMapper.update(null, Wrappers.lambdaUpdate(Coupon.class)
|
|
|
+ .set(Coupon::getClassificationId, newClassificationId)
|
|
|
+ .in(Coupon::getId, coupons.stream().map(Coupon::getId).collect(Collectors.toList())));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("转移优惠券分类成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑优惠券分类
|
|
|
+ */
|
|
|
+ @PutMapping("/update/classification")
|
|
|
+ public Result<String> updateClassification(@RequestBody @Validated CouponClassification classification) {
|
|
|
+ Long classificationId = classification.getId();
|
|
|
+ Assert.notNull(classificationId, "分类id为空");
|
|
|
+ CouponClassification couponClassification = couponClassificationMapper.selectById(classificationId);
|
|
|
+ if (couponClassification == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("该分类不存在");
|
|
|
+ }
|
|
|
+ couponClassificationMapper.updateById(classification);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("编辑分类成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优惠券分类列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get/classification")
|
|
|
+ public Result<SearchResult<CouponClassificationView>> classificationView() {
|
|
|
+ SearchResult<CouponClassificationView> search = beanSearcher.search(CouponClassificationView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public String getUnionId(String corpId, String externalUserId) throws Exception {
|
|
|
WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
|
|
|
LambdaQueryWrapper<CorpUserAuth> corpUserAuthWrapper = Wrappers.lambdaQuery(CorpUserAuth.class)
|