parent
15f2c82bd7
commit
cdf0ebe536
@ -0,0 +1,77 @@
|
|||||||
|
package com.cyl.manager.act.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.cyl.manager.act.convert.CouponActivityConvert;
|
||||||
|
import com.cyl.manager.act.domain.entity.CouponActivity;
|
||||||
|
import com.cyl.manager.act.domain.query.CouponActivityQuery;
|
||||||
|
import com.cyl.manager.act.service.CouponActivityService;
|
||||||
|
import com.cyl.manager.act.domain.vo.CouponActivityVO;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
/**
|
||||||
|
* 优惠券活动表Controller
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
* @date 2024-03-22
|
||||||
|
*/
|
||||||
|
@Api(description ="优惠券活动表接口列表")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/act/couponActivity")
|
||||||
|
public class CouponActivityController extends BaseController {
|
||||||
|
@Autowired
|
||||||
|
private CouponActivityService service;
|
||||||
|
@Autowired
|
||||||
|
private CouponActivityConvert convert;
|
||||||
|
|
||||||
|
@ApiOperation("查询优惠券活动表列表")
|
||||||
|
@PostMapping("/list")
|
||||||
|
public ResponseEntity<Page<CouponActivityVO>> list(@RequestBody CouponActivityQuery query, Pageable page) {
|
||||||
|
return ResponseEntity.ok(service.selectList(query, page));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("获取优惠券活动表详细信息")
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
|
public ResponseEntity<CouponActivity> getInfo(@PathVariable("id") Long id) {
|
||||||
|
return ResponseEntity.ok(service.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("新增优惠券活动表")
|
||||||
|
@Log(title = "优惠券活动表", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<Integer> add(@RequestBody CouponActivity couponActivity) {
|
||||||
|
return ResponseEntity.ok(service.insert(couponActivity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("修改优惠券活动表")
|
||||||
|
@Log(title = "优惠券活动表", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public ResponseEntity<Integer> edit(@RequestBody CouponActivity couponActivity) {
|
||||||
|
return ResponseEntity.ok(service.update(couponActivity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除优惠券活动表")
|
||||||
|
@Log(title = "优惠券活动表", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Integer> remove(@PathVariable Long id) {
|
||||||
|
return ResponseEntity.ok(service.deleteById(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
package com.cyl.manager.act.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.cyl.manager.act.convert.MemberCouponConvert;
|
||||||
|
import com.cyl.manager.act.domain.entity.MemberCoupon;
|
||||||
|
import com.cyl.manager.act.domain.query.MemberCouponQuery;
|
||||||
|
import com.cyl.manager.act.service.MemberCouponService;
|
||||||
|
import com.cyl.manager.act.domain.vo.MemberCouponVO;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
/**
|
||||||
|
* 用户领券记录Controller
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
* @date 2024-03-22
|
||||||
|
*/
|
||||||
|
@Api(description ="用户领券记录接口列表")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/act/memberCoupon")
|
||||||
|
public class MemberCouponController extends BaseController {
|
||||||
|
@Autowired
|
||||||
|
private MemberCouponService service;
|
||||||
|
@Autowired
|
||||||
|
private MemberCouponConvert convert;
|
||||||
|
|
||||||
|
@ApiOperation("查询用户领券记录列表")
|
||||||
|
@PostMapping("/list")
|
||||||
|
public ResponseEntity<Page<MemberCouponVO>> list(@RequestBody MemberCouponQuery query, Pageable page) {
|
||||||
|
return ResponseEntity.ok(service.selectList(query, page));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("获取用户领券记录详细信息")
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
|
public ResponseEntity<MemberCoupon> getInfo(@PathVariable("id") Long id) {
|
||||||
|
return ResponseEntity.ok(service.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("新增用户领券记录")
|
||||||
|
@Log(title = "用户领券记录", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<Integer> add(@RequestBody MemberCoupon memberCoupon) {
|
||||||
|
return ResponseEntity.ok(service.insert(memberCoupon));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("修改用户领券记录")
|
||||||
|
@Log(title = "用户领券记录", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public ResponseEntity<Integer> edit(@RequestBody MemberCoupon memberCoupon) {
|
||||||
|
return ResponseEntity.ok(service.update(memberCoupon));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除用户领券记录")
|
||||||
|
@Log(title = "用户领券记录", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Integer> remove(@PathVariable Long id) {
|
||||||
|
return ResponseEntity.ok(service.deleteById(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.cyl.manager.act.convert;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import com.cyl.manager.act.domain.entity.CouponActivity;
|
||||||
|
import com.cyl.manager.act.domain.vo.CouponActivityVO;
|
||||||
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
* 优惠券活动表 DO <=> DTO <=> VO / BO / Query
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface CouponActivityConvert {
|
||||||
|
|
||||||
|
List<CouponActivityVO> dos2vos(List<CouponActivity> list);
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.cyl.manager.act.convert;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import com.cyl.manager.act.domain.entity.MemberCoupon;
|
||||||
|
import com.cyl.manager.act.domain.vo.MemberCouponVO;
|
||||||
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
* 用户领券记录 DO <=> DTO <=> VO / BO / Query
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface MemberCouponConvert {
|
||||||
|
|
||||||
|
List<MemberCouponVO> dos2vos(List<MemberCoupon> list);
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package com.cyl.manager.act.domain.query;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.Data;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券活动表 查询 对象
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
*/
|
||||||
|
@ApiModel(description="优惠券活动表 查询 对象")
|
||||||
|
@Data
|
||||||
|
public class CouponActivityQuery {
|
||||||
|
@ApiModelProperty("活动名称 精确匹配")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@ApiModelProperty("使用范围 1全场通用 2指定商品可用 3指定商品不可用 精确匹配")
|
||||||
|
private Integer useScope;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty("1免费兑换 2积分兑换 精确匹配")
|
||||||
|
private Integer couponType;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package com.cyl.manager.act.domain.query;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.Data;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户领券记录 查询 对象
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
*/
|
||||||
|
@ApiModel(description="用户领券记录 查询 对象")
|
||||||
|
@Data
|
||||||
|
public class MemberCouponQuery {
|
||||||
|
@ApiModelProperty("活动id 精确匹配")
|
||||||
|
private Long couponActivityId;
|
||||||
|
|
||||||
|
@ApiModelProperty("用户id 精确匹配")
|
||||||
|
private Long memberId;
|
||||||
|
|
||||||
|
@ApiModelProperty("0未使用 1已使用 精确匹配")
|
||||||
|
private Integer useStatus;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package com.cyl.manager.act.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.cyl.manager.act.domain.entity.CouponActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券活动表Mapper接口
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
*/
|
||||||
|
public interface CouponActivityMapper extends BaseMapper<CouponActivity> {
|
||||||
|
/**
|
||||||
|
* 查询优惠券活动表列表
|
||||||
|
*
|
||||||
|
* @param couponActivity 优惠券活动表
|
||||||
|
* @return 优惠券活动表集合
|
||||||
|
*/
|
||||||
|
List<CouponActivity> selectByEntity(CouponActivity couponActivity);
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package com.cyl.manager.act.mapper;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.cyl.manager.act.domain.entity.MemberCoupon;
|
||||||
|
import com.cyl.manager.act.domain.vo.CouponActivityVO;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户领券记录Mapper接口
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
*/
|
||||||
|
public interface MemberCouponMapper extends BaseMapper<MemberCoupon> {
|
||||||
|
/**
|
||||||
|
* 查询用户领券记录列表
|
||||||
|
*
|
||||||
|
* @param memberCoupon 用户领券记录
|
||||||
|
* @return 用户领券记录集合
|
||||||
|
*/
|
||||||
|
List<MemberCoupon> selectByEntity(MemberCoupon memberCoupon);
|
||||||
|
|
||||||
|
List<CouponActivityVO> countUseCoupon(@Param("couponIds") Collection<Long> couponIds);
|
||||||
|
}
|
||||||
@ -0,0 +1,149 @@
|
|||||||
|
package com.cyl.manager.act.service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.cyl.manager.act.domain.entity.MemberCoupon;
|
||||||
|
import com.cyl.manager.act.domain.vo.CouponActivityVO;
|
||||||
|
import com.cyl.manager.act.mapper.MemberCouponMapper;
|
||||||
|
import com.cyl.manager.pms.domain.entity.Product;
|
||||||
|
import com.cyl.manager.pms.mapper.ProductMapper;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.cyl.manager.act.mapper.CouponActivityMapper;
|
||||||
|
import com.cyl.manager.act.domain.entity.CouponActivity;
|
||||||
|
import com.cyl.manager.act.domain.query.CouponActivityQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券活动表Service业务层处理
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CouponActivityService {
|
||||||
|
@Autowired
|
||||||
|
private CouponActivityMapper couponActivityMapper;
|
||||||
|
@Autowired
|
||||||
|
private MemberCouponMapper memberCouponMapper;
|
||||||
|
@Autowired
|
||||||
|
private ProductMapper productMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询优惠券活动表
|
||||||
|
*
|
||||||
|
* @param id 优惠券活动表主键
|
||||||
|
* @return 优惠券活动表
|
||||||
|
*/
|
||||||
|
public CouponActivity selectById(Long id) {
|
||||||
|
return couponActivityMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询优惠券活动表列表
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @param page 分页条件
|
||||||
|
* @return 优惠券活动表
|
||||||
|
*/
|
||||||
|
public Page<CouponActivityVO> selectList(CouponActivityQuery query, Pageable page) {
|
||||||
|
PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
|
||||||
|
QueryWrapper<CouponActivity> qw = new QueryWrapper<>();
|
||||||
|
String title = query.getTitle();
|
||||||
|
if (!StringUtils.isEmpty(title)) {
|
||||||
|
qw.like("title", "%".concat(title.trim()).concat("%"));
|
||||||
|
}
|
||||||
|
Integer useScope = query.getUseScope();
|
||||||
|
if (useScope != null) {
|
||||||
|
qw.eq("use_scope", useScope);
|
||||||
|
}
|
||||||
|
Integer couponType = query.getCouponType();
|
||||||
|
if (couponType != null) {
|
||||||
|
qw.eq("coupon_type", couponType);
|
||||||
|
}
|
||||||
|
List<CouponActivity> list = couponActivityMapper.selectList(qw);
|
||||||
|
if (CollectionUtil.isEmpty(list)) {
|
||||||
|
return new PageImpl<>(Collections.emptyList(), page, 0);
|
||||||
|
}
|
||||||
|
long total = ((com.github.pagehelper.Page) list).getTotal();
|
||||||
|
List<CouponActivityVO> resList = new ArrayList<>();
|
||||||
|
//查找已使用张数
|
||||||
|
Map<Long, Integer> useCountMap = memberCouponMapper.countUseCoupon((list.stream().map(it -> it.getId()).collect(Collectors.toSet())))
|
||||||
|
.stream().collect(Collectors.toMap(it -> it.getId(), it -> it.getUseCount()));
|
||||||
|
Set<Long> productIds = new HashSet<>();
|
||||||
|
list.stream().filter(it -> Arrays.asList(2, 3).contains(it.getUseScope()) && StringUtils.isNotEmpty(it.getProductIds()))
|
||||||
|
.forEach(it -> {
|
||||||
|
productIds.addAll(Arrays.stream(it.getProductIds().split(",")).map(item -> Long.parseLong(item)).collect(Collectors.toSet()));
|
||||||
|
});
|
||||||
|
//查找商品列表
|
||||||
|
Map<Long, Product> productMap = new HashMap<>();
|
||||||
|
if (productIds.size() > 0) {
|
||||||
|
productMap = productMapper.selectBatchIds(productIds).stream().collect(Collectors.toMap(it->it.getId(),it->it));
|
||||||
|
}
|
||||||
|
for (CouponActivity couponActivity : list) {
|
||||||
|
CouponActivityVO vo = new CouponActivityVO();
|
||||||
|
BeanUtils.copyProperties(couponActivity,vo);
|
||||||
|
Integer integer = useCountMap.get(couponActivity.getId());
|
||||||
|
vo.setUseCount(integer == null ? 0 : integer);
|
||||||
|
if (Arrays.asList(2, 3).contains(couponActivity.getUseScope()) && StringUtils.isNotEmpty(couponActivity.getProductIds())){
|
||||||
|
List<Product> products = new ArrayList<>();
|
||||||
|
for (String s : couponActivity.getProductIds().split(",")) {
|
||||||
|
Product product = productMap.get(Long.parseLong(s));
|
||||||
|
if (product != null) {
|
||||||
|
products.add(product);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vo.setProductList(products);
|
||||||
|
}
|
||||||
|
resList.add(vo);
|
||||||
|
}
|
||||||
|
return new PageImpl<>(resList, page, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增优惠券活动表
|
||||||
|
*
|
||||||
|
* @param couponActivity 优惠券活动表
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insert(CouponActivity couponActivity) {
|
||||||
|
couponActivity.setLeftCount(couponActivity.getTotalCount());
|
||||||
|
couponActivity.setCreateTime(LocalDateTime.now());
|
||||||
|
return couponActivityMapper.insert(couponActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改优惠券活动表
|
||||||
|
*
|
||||||
|
* @param couponActivity 优惠券活动表
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int update(CouponActivity couponActivity) {
|
||||||
|
CouponActivity dbActivity = couponActivityMapper.selectById(couponActivity.getId());
|
||||||
|
if (dbActivity==null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
couponActivity.setLeftCount(dbActivity.getLeftCount());
|
||||||
|
couponActivity.setUpdateTime(LocalDateTime.now());
|
||||||
|
return couponActivityMapper.updateById(couponActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除优惠券活动表信息
|
||||||
|
*
|
||||||
|
* @param id 优惠券活动表主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteById(Long id) {
|
||||||
|
return couponActivityMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
package com.cyl.manager.act.service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.cyl.manager.act.domain.vo.MemberCouponVO;
|
||||||
|
import com.cyl.manager.ums.domain.entity.Member;
|
||||||
|
import com.cyl.manager.ums.mapper.MemberMapper;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.cyl.manager.act.mapper.MemberCouponMapper;
|
||||||
|
import com.cyl.manager.act.domain.entity.MemberCoupon;
|
||||||
|
import com.cyl.manager.act.domain.query.MemberCouponQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户领券记录Service业务层处理
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author zcc
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MemberCouponService {
|
||||||
|
@Autowired
|
||||||
|
private MemberCouponMapper memberCouponMapper;
|
||||||
|
@Autowired
|
||||||
|
private MemberMapper memberMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户领券记录
|
||||||
|
*
|
||||||
|
* @param id 用户领券记录主键
|
||||||
|
* @return 用户领券记录
|
||||||
|
*/
|
||||||
|
public MemberCoupon selectById(Long id) {
|
||||||
|
return memberCouponMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户领券记录列表
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @param page 分页条件
|
||||||
|
* @return 用户领券记录
|
||||||
|
*/
|
||||||
|
public Page<MemberCouponVO> selectList(MemberCouponQuery query, Pageable page) {
|
||||||
|
|
||||||
|
PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
|
||||||
|
QueryWrapper<MemberCoupon> qw = new QueryWrapper<>();
|
||||||
|
Long couponActivityId = query.getCouponActivityId();
|
||||||
|
if (couponActivityId != null) {
|
||||||
|
qw.eq("coupon_activity_id", couponActivityId);
|
||||||
|
}
|
||||||
|
Long memberId = query.getMemberId();
|
||||||
|
if (memberId != null) {
|
||||||
|
qw.eq("member_id", memberId);
|
||||||
|
}
|
||||||
|
Integer useStatus = query.getUseStatus();
|
||||||
|
if (useStatus != null) {
|
||||||
|
qw.eq("use_status", useStatus);
|
||||||
|
}
|
||||||
|
List<MemberCoupon> list = memberCouponMapper.selectList(qw);
|
||||||
|
|
||||||
|
long total = ((com.github.pagehelper.Page) list).getTotal();
|
||||||
|
if (total < 1) {
|
||||||
|
return new PageImpl<>(Collections.emptyList(), page, total);
|
||||||
|
}
|
||||||
|
List<MemberCouponVO> resList = new ArrayList<>();
|
||||||
|
Set<Long> memberIds = list.stream().map(it -> it.getMemberId()).collect(Collectors.toSet());
|
||||||
|
Map<Long, Member> memberMap = memberMapper.selectList(new QueryWrapper<Member>().in("id", memberIds))
|
||||||
|
.stream().collect(Collectors.toMap(it -> it.getId(), it -> it));
|
||||||
|
for (MemberCoupon it : list) {
|
||||||
|
MemberCouponVO vo = new MemberCouponVO();
|
||||||
|
BeanUtils.copyProperties(it, vo);
|
||||||
|
Member member = memberMap.get(it.getMemberId());
|
||||||
|
if (member != null) {
|
||||||
|
vo.setNickname(member.getNickname());
|
||||||
|
vo.setPhone(member.getPhoneHidden());
|
||||||
|
vo.setAvatar(member.getAvatar());
|
||||||
|
}
|
||||||
|
resList.add(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PageImpl<>(resList, page, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增用户领券记录
|
||||||
|
*
|
||||||
|
* @param memberCoupon 用户领券记录
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insert(MemberCoupon memberCoupon) {
|
||||||
|
memberCoupon.setCreateTime(LocalDateTime.now());
|
||||||
|
return memberCouponMapper.insert(memberCoupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户领券记录
|
||||||
|
*
|
||||||
|
* @param memberCoupon 用户领券记录
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int update(MemberCoupon memberCoupon) {
|
||||||
|
return memberCouponMapper.updateById(memberCoupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户领券记录信息
|
||||||
|
*
|
||||||
|
* @param id 用户领券记录主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteById(Long id) {
|
||||||
|
return memberCouponMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.cyl.manager.act.mapper.CouponActivityMapper">
|
||||||
|
|
||||||
|
<resultMap type="CouponActivity" id="CouponActivityResult">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="title" column="title"/>
|
||||||
|
<result property="useScope" column="use_scope"/>
|
||||||
|
<result property="productIds" column="product_ids"/>
|
||||||
|
<result property="totalCount" column="total_count"/>
|
||||||
|
<result property="leftCount" column="left_count"/>
|
||||||
|
<result property="userLimit" column="user_limit"/>
|
||||||
|
<result property="couponAmount" column="coupon_amount"/>
|
||||||
|
<result property="minAmount" column="min_amount"/>
|
||||||
|
<result property="useIntegral" column="use_integral"/>
|
||||||
|
<result property="couponType" column="coupon_type"/>
|
||||||
|
<result property="beginTime" column="begin_time"/>
|
||||||
|
<result property="endTime" column="end_time"/>
|
||||||
|
<result property="createTime" column="create_time"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectCouponActivityVo">
|
||||||
|
select id, title, use_scope, product_ids, total_count, left_count, user_limit, coupon_amount, min_amount, use_integral, coupon_type, begin_time, end_time, create_time from act_coupon_activity
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectByEntity" parameterType="CouponActivity" resultMap="CouponActivityResult">
|
||||||
|
<include refid="selectCouponActivityVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="title != null and title != ''"> and title = #{title}</if>
|
||||||
|
<if test="useScope != null "> and use_scope = #{useScope}</if>
|
||||||
|
<if test="productIds != null and productIds != ''"> and product_ids = #{productIds}</if>
|
||||||
|
<if test="totalCount != null "> and total_count = #{totalCount}</if>
|
||||||
|
<if test="leftCount != null "> and left_count = #{leftCount}</if>
|
||||||
|
<if test="userLimit != null "> and user_limit = #{userLimit}</if>
|
||||||
|
<if test="couponAmount != null "> and coupon_amount = #{couponAmount}</if>
|
||||||
|
<if test="minAmount != null "> and min_amount = #{minAmount}</if>
|
||||||
|
<if test="useIntegral != null "> and use_integral = #{useIntegral}</if>
|
||||||
|
<if test="couponType != null "> and coupon_type = #{couponType}</if>
|
||||||
|
<if test="beginTime != null "> and begin_time = #{beginTime}</if>
|
||||||
|
<if test="endTime != null "> and end_time = #{endTime}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.cyl.manager.act.mapper.MemberCouponMapper">
|
||||||
|
|
||||||
|
<resultMap type="MemberCoupon" id="MemberCouponResult">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="couponActivityId" column="coupon_activity_id"/>
|
||||||
|
<result property="memberId" column="member_id"/>
|
||||||
|
<result property="title" column="title"/>
|
||||||
|
<result property="useScope" column="use_scope"/>
|
||||||
|
<result property="productIds" column="product_ids"/>
|
||||||
|
<result property="couponAmount" column="coupon_amount"/>
|
||||||
|
<result property="minAmount" column="min_amount"/>
|
||||||
|
<result property="useIntegral" column="use_integral"/>
|
||||||
|
<result property="couponType" column="coupon_type"/>
|
||||||
|
<result property="beginTime" column="begin_time"/>
|
||||||
|
<result property="endTime" column="end_time"/>
|
||||||
|
<result property="useStatus" column="use_status"/>
|
||||||
|
<result property="orderId" column="order_id"/>
|
||||||
|
<result property="useTime" column="use_time"/>
|
||||||
|
<result property="createTime" column="create_time"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectMemberCouponVo">
|
||||||
|
select id, coupon_activity_id, member_id, title, use_scope, product_ids, coupon_amount, min_amount, use_integral, coupon_type, begin_time, end_time, use_status, order_id, use_time, create_time from act_member_coupon
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectByEntity" parameterType="MemberCoupon" resultMap="MemberCouponResult">
|
||||||
|
<include refid="selectMemberCouponVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="couponActivityId != null "> and coupon_activity_id = #{couponActivityId}</if>
|
||||||
|
<if test="memberId != null "> and member_id = #{memberId}</if>
|
||||||
|
<if test="title != null and title != ''"> and title = #{title}</if>
|
||||||
|
<if test="useScope != null "> and use_scope = #{useScope}</if>
|
||||||
|
<if test="productIds != null and productIds != ''"> and product_ids = #{productIds}</if>
|
||||||
|
<if test="couponAmount != null "> and coupon_amount = #{couponAmount}</if>
|
||||||
|
<if test="minAmount != null "> and min_amount = #{minAmount}</if>
|
||||||
|
<if test="useIntegral != null "> and use_integral = #{useIntegral}</if>
|
||||||
|
<if test="couponType != null "> and coupon_type = #{couponType}</if>
|
||||||
|
<if test="beginTime != null "> and begin_time = #{beginTime}</if>
|
||||||
|
<if test="endTime != null "> and end_time = #{endTime}</if>
|
||||||
|
<if test="useStatus != null "> and use_status = #{useStatus}</if>
|
||||||
|
<if test="orderId != null "> and order_id = #{orderId}</if>
|
||||||
|
<if test="useTime != null "> and use_time = #{useTime}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
<select id="countUseCoupon" resultType="com.cyl.manager.act.domain.vo.CouponActivityVO">
|
||||||
|
select coupon_activity_id as id,count(1) as useCount
|
||||||
|
from act_member_coupon
|
||||||
|
where coupon_activity_id in
|
||||||
|
<foreach collection="couponIds" close=")" index="index" item="item" open="(" separator=",">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
and use_status = 1
|
||||||
|
group by coupon_activity_id
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in new issue