yshop1.5版本新增秒杀功能,手机端新增H5支付,修复其他bug,导出最新sql

This commit is contained in:
hupeng
2019-12-17 18:48:13 +08:00
parent cf6c875062
commit 4a18e76373
45 changed files with 1673 additions and 194 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>yshop</artifactId>
<groupId>co.yixiang</groupId>
<version>1.4</version>
<version>1.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -20,12 +20,12 @@
<dependency>
<groupId>co.yixiang</groupId>
<artifactId>yshop-logging</artifactId>
<version>1.4</version>
<version>1.5</version>
</dependency>
<dependency>
<groupId>co.yixiang</groupId>
<artifactId>yshop-mp</artifactId>
<version>1.4</version>
<version>1.5</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,153 @@
package co.yixiang.modules.activity.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Date;
/**
* @author xuwenbo
* @date 2019-12-14
*/
@Entity
@Data
@Table(name="yx_store_seckill")
public class YxStoreSeckill implements Serializable {
// 商品秒杀产品表id
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
// 商品id
@Column(name = "product_id",nullable = false)
private Integer productId;
// 推荐图
@Column(name = "image",nullable = false)
@NotBlank(message = "请上传产品图片")
private String image;
// 轮播图
@Column(name = "images",nullable = false)
@NotBlank(message = "请上传产品轮播图")
private String images;
// 活动标题
@Column(name = "title",nullable = false)
@NotBlank(message = "请输入产品标题")
private String title;
// 简介
@Column(name = "info",nullable = false)
@NotBlank(message = "请输入秒杀简介")
private String info;
// 价格
@Column(name = "price",nullable = false)
@NotNull(message = "秒杀价必填")
@Min(value = 0,message = "秒杀价必须大于0")
private BigDecimal price;
// 成本
@Column(name = "cost",nullable = false)
@NotNull(message = "成本价必填")
@Min(value = 0,message = "成本价必须大于0")
private BigDecimal cost;
// 原价
@Column(name = "ot_price",nullable = false)
@NotNull(message = "原价必填")
@Min(value = 0,message = "原价必须大于0")
private BigDecimal otPrice;
// 返多少积分
@Column(name = "give_integral",nullable = false)
private BigDecimal giveIntegral;
// 排序
@Column(name = "sort",nullable = false)
@NotNull(message = "排序必填")
private Integer sort;
// 库存
@Column(name = "stock",nullable = false)
@NotNull(message = "库存必填")
private Integer stock;
// 销量
@Column(name = "sales",nullable = false)
@NotNull(message = "销量必填")
private Integer sales;
// 单位名
@Column(name = "unit_name",nullable = false)
@NotBlank(message = "单位名不能为空")
private String unitName;
// 邮费
@Column(name = "postage",nullable = false)
@NotNull(message = "邮费必填")
private BigDecimal postage;
// 内容
@Column(name = "description")
private String description;
// 开始时间
@Column(name = "start_time",nullable = false)
private Integer startTime;
// 结束时间
@Column(name = "stop_time",nullable = false)
private Integer stopTime;
@NotNull(message = "开始时间不能为空")
private Date startTimeDate;
@NotNull(message = "结束时间不能为空")
private Date endTimeDate;
// 添加时间
@Column(name = "add_time",nullable = false)
private String addTime;
// 产品状态
@Column(name = "status",nullable = false)
@NotNull(message = "活动状态必须选择")
private Integer status;
// 是否包邮
@Column(name = "is_postage",nullable = false)
@NotNull(message = "包邮状态必须选择")
private Integer isPostage;
// 热门推荐
@Column(name = "is_hot",insertable = false)
private Integer isHot;
// 删除 0未删除1已删除
@Column(name = "is_del",insertable = false)
private Integer isDel;
// 最多秒杀几个
@Column(name = "num",nullable = false)
@NotNull(message = "限购必填")
@Min(value = 1,message = "限购必须大于0")
private Integer num;
// 显示
@Column(name = "is_show",nullable = false)
private Integer isShow;
public void copy(YxStoreSeckill source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -0,0 +1,12 @@
package co.yixiang.modules.activity.repository;
import co.yixiang.modules.activity.domain.YxStoreSeckill;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author xuwenbo
* @date 2019-12-14
*/
public interface YxStoreSeckillRepository extends JpaRepository<YxStoreSeckill, Integer>, JpaSpecificationExecutor {
}

View File

@ -46,7 +46,6 @@ public class YxStoreCombinationController {
@PutMapping(value = "/yxStoreCombination")
@PreAuthorize("hasAnyRole('ADMIN','YXSTORECOMBINATION_ALL','YXSTORECOMBINATION_EDIT')")
public ResponseEntity update(@Validated @RequestBody YxStoreCombination resources){
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
if(ObjectUtil.isNotNull(resources.getStartTimeDate())){
resources.setStartTime(OrderUtil.
dateToTimestamp(resources.getStartTimeDate()));

View File

@ -0,0 +1,73 @@
package co.yixiang.modules.activity.rest;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.exception.BadRequestException;
import co.yixiang.modules.activity.domain.YxStoreSeckill;
import co.yixiang.modules.activity.service.YxStoreSeckillService;
import co.yixiang.modules.activity.service.dto.YxStoreSeckillQueryCriteria;
import co.yixiang.utils.OrderUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
/**
* @author xuwenbo
* @date 2019-12-14
*/
@Api(tags = "秒杀管理")
@RestController
@RequestMapping("api")
public class YxStoreSeckillController {
@Autowired
private YxStoreSeckillService yxStoreSeckillService;
@Log("查询YxStoreSeckill")
@ApiOperation(value = "查询YxStoreSeckill")
@GetMapping(value = "/yxStoreSeckill")
@PreAuthorize("hasAnyRole('ADMIN','YXSTORESECKILL_ALL','YXSTORESECKILL_SELECT')")
public ResponseEntity getYxStoreSeckills(YxStoreSeckillQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(yxStoreSeckillService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("修改YxStoreSeckill")
@ApiOperation(value = "修改YxStoreSeckill")
@PutMapping(value = "/yxStoreSeckill")
@PreAuthorize("hasAnyRole('ADMIN','YXSTORESECKILL_ALL','YXSTORESECKILL_EDIT')")
public ResponseEntity update(@Validated @RequestBody YxStoreSeckill resources){
if(ObjectUtil.isNotNull(resources.getStartTimeDate())){
resources.setStartTime(OrderUtil.
dateToTimestamp(resources.getStartTimeDate()));
}
if(ObjectUtil.isNotNull(resources.getEndTimeDate())){
resources.setStopTime(OrderUtil.
dateToTimestamp(resources.getEndTimeDate()));
}
if(ObjectUtil.isNull(resources.getId())){
resources.setAddTime(String.valueOf(OrderUtil.getSecondTimestampTwo()));
return new ResponseEntity(yxStoreSeckillService.create(resources),HttpStatus.CREATED);
}else{
yxStoreSeckillService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
}
@Log("删除YxStoreSeckill")
@ApiOperation(value = "删除YxStoreSeckill")
@DeleteMapping(value = "/yxStoreSeckill/{id}")
@PreAuthorize("hasAnyRole('ADMIN','YXSTORESECKILL_ALL','YXSTORESECKILL_DELETE')")
public ResponseEntity delete(@PathVariable Integer id){
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
yxStoreSeckillService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
}

View File

@ -0,0 +1,66 @@
package co.yixiang.modules.activity.service;
import co.yixiang.modules.activity.domain.YxStoreSeckill;
import co.yixiang.modules.activity.service.dto.YxStoreSeckillDTO;
import co.yixiang.modules.activity.service.dto.YxStoreSeckillQueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
/**
* @author xuwenbo
* @date 2019-12-14
*/
//@CacheConfig(cacheNames = "yxStoreSeckill")
public interface YxStoreSeckillService {
/**
* 查询数据分页
* @param criteria
* @param pageable
* @return
*/
//@Cacheable
Map<String,Object> queryAll(YxStoreSeckillQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria
* @return
*/
//@Cacheable
List<YxStoreSeckillDTO> queryAll(YxStoreSeckillQueryCriteria criteria);
/**
* 根据ID查询
* @param id
* @return
*/
//@Cacheable(key = "#p0")
YxStoreSeckillDTO findById(Integer id);
/**
* 创建
* @param resources
* @return
*/
//@CacheEvict(allEntries = true)
YxStoreSeckillDTO create(YxStoreSeckill resources);
/**
* 编辑
* @param resources
*/
//@CacheEvict(allEntries = true)
void update(YxStoreSeckill resources);
/**
* 删除
* @param id
*/
//@CacheEvict(allEntries = true)
void delete(Integer id);
}

View File

@ -0,0 +1,98 @@
package co.yixiang.modules.activity.service.dto;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Date;
/**
* @author xuwenbo
* @date 2019-12-14
*/
@Data
public class YxStoreSeckillDTO implements Serializable {
// 商品秒杀产品表id
private Integer id;
// 商品id
private Integer productId;
// 推荐图
private String image;
// 轮播图
private String images;
// 活动标题
private String title;
// 简介
private String info;
// 价格
private BigDecimal price;
// 成本
private BigDecimal cost;
// 原价
private BigDecimal otPrice;
// 返多少积分
private BigDecimal giveIntegral;
// 排序
private Integer sort;
// 库存
private Integer stock;
// 销量
private Integer sales;
// 单位名
private String unitName;
// 邮费
private BigDecimal postage;
// 内容
private String description;
// 开始时间
private Integer startTime;
// 结束时间
private Integer stopTime;
// 添加时间
private String addTime;
// 产品状态
private Integer status;
// 是否包邮
private Integer isPostage;
// 热门推荐
private Integer isHot;
// 删除 0未删除1已删除
private Integer isDel;
// 最多秒杀几个
private Integer num;
// 显示
private Integer isShow;
private Date startTimeDate;
private Date endTimeDate;
private String statusStr;
}

View File

@ -0,0 +1,17 @@
package co.yixiang.modules.activity.service.dto;
import lombok.Data;
import java.math.BigDecimal;
import co.yixiang.annotation.Query;
/**
* @author xuwenbo
* @date 2019-12-14
*/
@Data
public class YxStoreSeckillQueryCriteria{
// 模糊
@Query(type = Query.Type.INNER_LIKE)
private String title;
}

View File

@ -0,0 +1,100 @@
package co.yixiang.modules.activity.service.impl;
import co.yixiang.modules.activity.domain.YxStoreSeckill;
import co.yixiang.utils.OrderUtil;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.modules.activity.repository.YxStoreSeckillRepository;
import co.yixiang.modules.activity.service.YxStoreSeckillService;
import co.yixiang.modules.activity.service.dto.YxStoreSeckillDTO;
import co.yixiang.modules.activity.service.dto.YxStoreSeckillQueryCriteria;
import co.yixiang.modules.activity.service.mapper.YxStoreSeckillMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.LinkedHashMap;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import co.yixiang.utils.PageUtil;
import co.yixiang.utils.QueryHelp;
import java.util.List;
import java.util.Map;
/**
* @author xuwenbo
* @date 2019-12-14
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxStoreSeckillServiceImpl implements YxStoreSeckillService {
@Autowired
private YxStoreSeckillRepository yxStoreSeckillRepository;
@Autowired
private YxStoreSeckillMapper yxStoreSeckillMapper;
@Override
public Map<String,Object> queryAll(YxStoreSeckillQueryCriteria criteria, Pageable pageable){
Page<YxStoreSeckill> page = yxStoreSeckillRepository.findAll((root, criteriaQuery, criteriaBuilder) ->
QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
List<YxStoreSeckillDTO> storeSeckillDTOS = yxStoreSeckillMapper
.toDto(page.getContent());
int nowTime = OrderUtil.getSecondTimestampTwo();
for (YxStoreSeckillDTO storeSeckillDTO : storeSeckillDTOS){
if(storeSeckillDTO.getStatus() > 0){
if(storeSeckillDTO.getStartTime() > nowTime){
storeSeckillDTO.setStatusStr("活动未开始");
}else if(storeSeckillDTO.getStopTime() < nowTime){
storeSeckillDTO.setStatusStr("活动已结束");
}else if(storeSeckillDTO.getStopTime() > nowTime && storeSeckillDTO.getStartTime() < nowTime){
storeSeckillDTO.setStatusStr("正在进行中");
}
}else {
storeSeckillDTO.setStatusStr("关闭");
}
}
Map<String,Object> map = new LinkedHashMap<>(2);
map.put("content",storeSeckillDTOS);
map.put("totalElements",page.getTotalElements());
return map;
}
@Override
public List<YxStoreSeckillDTO> queryAll(YxStoreSeckillQueryCriteria criteria){
return yxStoreSeckillMapper.toDto(yxStoreSeckillRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
public YxStoreSeckillDTO findById(Integer id) {
Optional<YxStoreSeckill> yxStoreSeckill = yxStoreSeckillRepository.findById(id);
ValidationUtil.isNull(yxStoreSeckill,"YxStoreSeckill","id",id);
return yxStoreSeckillMapper.toDto(yxStoreSeckill.get());
}
@Override
@Transactional(rollbackFor = Exception.class)
public YxStoreSeckillDTO create(YxStoreSeckill resources) {
return yxStoreSeckillMapper.toDto(yxStoreSeckillRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(YxStoreSeckill resources) {
Optional<YxStoreSeckill> optionalYxStoreSeckill = yxStoreSeckillRepository.findById(resources.getId());
ValidationUtil.isNull( optionalYxStoreSeckill,"YxStoreSeckill","id",resources.getId());
YxStoreSeckill yxStoreSeckill = optionalYxStoreSeckill.get();
yxStoreSeckill.copy(resources);
yxStoreSeckillRepository.save(yxStoreSeckill);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Integer id) {
yxStoreSeckillRepository.deleteById(id);
}
}

View File

@ -0,0 +1,16 @@
package co.yixiang.modules.activity.service.mapper;
import co.yixiang.mapper.EntityMapper;
import co.yixiang.modules.activity.domain.YxStoreSeckill;
import co.yixiang.modules.activity.service.dto.YxStoreSeckillDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author xuwenbo
* @date 2019-12-14
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface YxStoreSeckillMapper extends EntityMapper<YxStoreSeckillDTO, YxStoreSeckill> {
}

View File

@ -89,7 +89,6 @@ public class YxStoreOrderController {
criteria.setRefundStatus(0);
break;
case "1":
System.out.println(orderStatus);
criteria.setIsDel(0);
criteria.setPaid(1);
criteria.setStatus(0);

View File

@ -18,7 +18,7 @@ public interface YxStoreOrderService {
Map<String,Object> chartCount();
String orderType(int id,int pinkId,int combinationId);
String orderType(int id,int pinkId,int combinationId,int seckillId);
void refund(YxStoreOrder resources);

View File

@ -148,7 +148,7 @@ public class YxStoreOrderServiceImpl implements YxStoreOrderService {
}
@Override
public String orderType(int id,int pinkId, int combinationId) {
public String orderType(int id,int pinkId, int combinationId,int seckillId) {
String str = "[普通订单]";
if(pinkId > 0 || combinationId > 0){
YxStorePink storePink = storePinkRepository.findByOrderIdKey(id);
@ -171,6 +171,8 @@ public class YxStoreOrderServiceImpl implements YxStoreOrderService {
}
}
}else if(seckillId > 0){
str = "[秒杀订单]";
}
return str;
}
@ -211,7 +213,8 @@ public class YxStoreOrderServiceImpl implements YxStoreOrderService {
yxStoreOrderDTO.setPayTypeName(payTypeName);
yxStoreOrderDTO.setPinkName(orderType(yxStoreOrder.getId()
,yxStoreOrder.getPinkId(),yxStoreOrder.getCombinationId()));
,yxStoreOrder.getPinkId(),yxStoreOrder.getCombinationId()
,yxStoreOrder.getSeckillId()));
List<StoreOrderCartInfo> cartInfos = yxStoreOrderCartInfoRepository
.findByOid(yxStoreOrder.getId());