记得上下班打卡 | git大法好,push需谨慎

Commit e1683add authored by wanglele's avatar wanglele

兑换码相关

parent 64fb9b10
package com.liquidnet.service.goblin.dto.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -20,6 +23,8 @@ import java.time.LocalDateTime;
@Data
@EqualsAndHashCode(callSuper = false)
@HeadRowHeight(value = 20)//设置表头行高
@ColumnWidth(value = 15)//设置表头行宽
public class GoblinNftExCodeVo implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;
......@@ -44,6 +49,7 @@ public class GoblinNftExCodeVo implements Serializable, Cloneable {
/**
* 兑换码
*/
@ExcelProperty(value = "兑换码", index = 0)//”0“表示excel中的第一列
@ApiModelProperty(position = 12,required = true,value ="兑换码")
private String code;
......@@ -75,6 +81,7 @@ public class GoblinNftExCodeVo implements Serializable, Cloneable {
/**
* 兑换码状态 1 未兑换 2 已兑换
*/
@ExcelProperty(value = "状态", index = 4)//”0“表示excel中的第一列
@ApiModelProperty(position = 17,required = true,value ="兑换码状态 1 未兑换 2 已兑换")
private Integer state;
......@@ -82,6 +89,7 @@ public class GoblinNftExCodeVo implements Serializable, Cloneable {
/**
* 兑换用户id
*/
@ExcelProperty(value = "用户id", index = 4)//”0“表示excel中的第一列
@ApiModelProperty(position = 18,required = true,value ="兑换用户id")
private String redeemUid;
......@@ -123,6 +131,7 @@ public class GoblinNftExCodeVo implements Serializable, Cloneable {
/**
* 兑换生效开始时间
*/
@ExcelProperty(value = "兑换开始时间", index = 2)//”0“表示excel中的第一列
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DateUtil.DATE_FULL_STR)
@ApiModelProperty(position = 24,required = true,value ="兑换生效开始时间")
private LocalDateTime exStartTime;
......@@ -131,6 +140,7 @@ public class GoblinNftExCodeVo implements Serializable, Cloneable {
/**
* 兑换生效结束时间
*/
@ExcelProperty(value = "兑换结束时间", index = 3)//”0“表示excel中的第一列
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DateUtil.DATE_FULL_STR)
@ApiModelProperty(position = 25,required = true,value ="兑换生效结束时间")
private LocalDateTime exStopTime;
......@@ -138,14 +148,12 @@ public class GoblinNftExCodeVo implements Serializable, Cloneable {
/**
* sku名称
*/
@ExcelProperty(value = "藏品名称", index = 1)//”0“表示excel中的第一列
@ApiModelProperty(position = 26,required = true,value ="sku名称")
private String skuName;
private static final GoblinNftExCodeVo obj = new GoblinNftExCodeVo();
public static GoblinNftExCodeVo getNew() {
......
......@@ -4,6 +4,8 @@ import com.github.pagehelper.PageInfo;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo;
import com.liquidnet.service.goblin.param.GoblinNftExCodeParam;
import javax.servlet.http.HttpServletResponse;
public interface IGoblinNftExCodeService {
/**
......@@ -24,4 +26,11 @@ public interface IGoblinNftExCodeService {
* @return
*/
Boolean addAirdrop(GoblinNftExCodeParam goblinNftExCodeParam);
/**
* 兑换码导出
* @param httpServletResponse
* @param goblinNftExCodeParam
*/
void excel(HttpServletResponse httpServletResponse, GoblinNftExCodeParam goblinNftExCodeParam);
}
......@@ -249,6 +249,9 @@ public class GoblinGoodsSku implements Serializable {
private LocalDateTime deletedAt;
private Integer upchain;
/**
* 物流模版id
*/
......
......@@ -6,6 +6,13 @@
<result column="name" property="name" jdbcType="VARCHAR"/>
<result column="unbox" property="unbox" jdbcType="VARCHAR"/>
<result column="hit_ratio" property="hitRatio" jdbcType="DECIMAL"/>
<result column="sku_type" property="sku_type" jdbcType="INTEGER"/>
<result column="status" property="status" jdbcType="VARCHAR"/>
<result column="shelves_status" property="shelves_status" jdbcType="VARCHAR"/>
<result column="sku_appear" property="sku_appear" jdbcType="VARCHAR"/>
<result column="del_flg" property="del_flg" jdbcType="VARCHAR"/>
<result column="soldout_status" property="soldout_status" jdbcType="VARCHAR"/>
<result column="sale_start_time" property="sale_start_time" jdbcType="TIMESTAMP"/>
</resultMap>
<select id="selectSkuLikeName" resultMap="BaseResult">
......@@ -24,7 +31,7 @@
</select>
<select id="selectBySpuIds" resultMap="BaseResult">
select sku_id,hit_ratio,unbox from goblin_goods_sku where
select sku_id,hit_ratio,unbox,sku_type,status,shelves_status,sku_appear,del_flg,soldout_status,sale_start_time from goblin_goods_sku where
spu_id in
<foreach collection="spuIds.split(',')" item="spuId" open="(" separator="," close=")">
#{spuId,jdbcType=VARCHAR}
......
......@@ -13,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
/**
* @Author: wll
* @Description:
......@@ -51,6 +53,14 @@ public class GoblinNftExCodeController {
}
@ApiOperationSupport(order = 4)
@ApiOperation(value = "兑换码导出")
@PostMapping("excel")
public void excel(HttpServletResponse httpServletResponse,@RequestBody GoblinNftExCodeParam goblinNftExCodeParam){
iGoblinNftExCodeService.excel(httpServletResponse,goblinNftExCodeParam);
}
......
package com.liquidnet.service.platform.service.impl.goblin;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExActivityVo;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku;
import com.liquidnet.service.goblin.entity.GoblinNftExCode;
......@@ -16,9 +21,14 @@ import com.liquidnet.service.platform.utils.GoblinRedisUtils;
import com.liquidnet.service.platform.utils.ObjectUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -73,9 +83,7 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
StringBuffer skuIds = new StringBuffer();
StringBuffer acticityIds = new StringBuffer();
for (GoblinNftExCode gnc : goblinNftExCodes) {
if (gnc.getState().equals(2)) {
skuIds.append(gnc.getSkuId()).append(",");
}
skuIds.append(gnc.getSkuId()).append(",");
acticityIds.append(gnc.getActivityId()).append(",");
}
......@@ -160,16 +168,17 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
Integer number = skuMap.get(skuId);
skuMap.put(skuId, number + 1);
}
goblinRedisUtils.removeCode(goblinNftExCode.getCode());
}
if (skuMap.size() > 0) {
for (String key : skuMap.keySet()) {
goblinRedisUtils.incrSkuStock(null,key,skuMap.get(key));
goblinRedisUtils.incrSkuStock(null, key, skuMap.get(key));
}
}
goblinRedisUtils.removeCodes(codes);
// 批量修改
goblinNftExCodeMapper.updateCodes(goblinNftExCodes);
return true;
......@@ -186,5 +195,128 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
return null;
}
@Override
public void excel(HttpServletResponse httpServletResponse, GoblinNftExCodeParam goblinNftExCodeParam) {
// 入参
GoblinNftExCode goblinNftExCode = GoblinNftExCode.getNew();
goblinNftExCode.setCode(goblinNftExCodeParam.getCode());
goblinNftExCode.setActivityId(goblinNftExCodeParam.getActivityId());
goblinNftExCode.setState(goblinNftExCodeParam.getState());
goblinNftExCode.setRedeemUid(goblinNftExCodeParam.getUserId());
goblinNftExCode.setIsDrivi(goblinNftExCodeParam.getIsDrivi());
if (StringUtil.isNotBlank(goblinNftExCodeParam.getSkuName())) {
// 根据藏品名称获取 skuIds
String skuName = goblinNftExCodeParam.getSkuName();
List<GoblinGoodsSku> goblinGoodsSkus = goblinGoodsSkuMapper.selectSkuLikeName(skuName);
if (goblinGoodsSkus.size() <= 0) {
return;
}
StringBuffer skuIds = new StringBuffer();
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkus) {
skuIds.append(goblinGoodsSku.getSkuId()).append(",");
}
goblinNftExCode.setSkuId(skuIds.deleteCharAt(skuIds.length() - 1).toString());
}
PageHelper.startPage(goblinNftExCodeParam.getPageNum(), 20, true);
List<GoblinNftExCode> goblinNftExCodes = goblinNftExCodeMapper.selectGoblinNftCode(goblinNftExCode);
StringBuffer skuIds = new StringBuffer();
StringBuffer acticityIds = new StringBuffer();
for (GoblinNftExCode gnc : goblinNftExCodes) {
if (gnc.getState().equals(2)) {
skuIds.append(gnc.getSkuId()).append(",");
}
acticityIds.append(gnc.getActivityId()).append(",");
}
// 获取返回对象实例
ArrayList<GoblinNftExCodeVo> goblinNftExCodeArrayList = ObjectUtil.getGoblinNftExCodeArrayList();
if (StringUtil.isNotBlank(skuIds)) {
// 批量查询
List<GoblinGoodsSku> goblinGoodsSkus = goblinGoodsSkuMapper.selectBySkuIds(skuIds.toString());
for (GoblinNftExCode gnc : goblinNftExCodes) {
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkus) {
if (gnc.getSkuId().equals(goblinGoodsSku.getSkuId())) {
GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(gnc);
goblinNftExCodeVo.setSkuName(goblinGoodsSku.getName());
goblinNftExCodeArrayList.add(goblinNftExCodeVo);
break;
}
}
}
}
// 根据活动ids 获取兑换活动和sku的关联
List<GoblinNftExSku> goblinNftExSkus = goblinNftExSkuMapper.selectGoblinNftExSkuByActivityIds(acticityIds.toString());
Map<String, List<GoblinNftExSku>> map = new HashMap<>();
for (GoblinNftExSku goblinNftExSku : goblinNftExSkus) {
if (map.get(goblinNftExSku.getActivityId()) == null) {
map.put(goblinNftExSku.getActivityId(), new ArrayList<>());
}
map.get(goblinNftExSku.getActivityId()).add(goblinNftExSku);
}
for (GoblinNftExCodeVo gnc : goblinNftExCodeArrayList) {
List<GoblinNftExSku> goblinNftExSkuList = map.get(gnc.getActivityId());
for (GoblinNftExSku goblinNftExSku : goblinNftExSkuList) {
if (gnc.getSkuId().equals(goblinNftExSku.getSkuId())) {
gnc.setExStartTime(goblinNftExSku.getExStartTime());
gnc.setExStopTime(goblinNftExSku.getExStopTime());
break;
}
}
}
try {
writeExcel(httpServletResponse, goblinNftExCodeArrayList, "活动excel", "sheet1", GoblinNftExCodeVo.class);
} catch (Exception e) {
log.error("导出excel失败!");
}
}
/**
* 导出
*
* @param response
* @param data
* @param fileName
* @param sheetName
* @param clazz
* @throws Exception
*/
public static void writeExcel(HttpServletResponse response, List<? extends Object> data, String fileName,
String sheetName, Class clazz) throws Exception {
// 表头样式
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// 设置表头居中对齐
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// 内容样式
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
// 设置内容靠左对齐
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
HorizontalCellStyleStrategy horizontalCellStyleStrategy =
new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
EasyExcel.write(getOutputStream(fileName, response), clazz).excelType(ExcelTypeEnum.XLSX).sheet(sheetName)
.registerWriteHandler(horizontalCellStyleStrategy).doWrite(data);
}
private static OutputStream getOutputStream(String fileName, HttpServletResponse response) throws Exception {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + "-" + LocalDate.now() + ".xlsx");
return response.getOutputStream();
}
}
......@@ -2,6 +2,7 @@ package com.liquidnet.service.platform.service.impl.goblin;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku;
import com.liquidnet.service.goblin.entity.GoblinNftExCode;
......@@ -72,17 +73,20 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
if (goblinGoodsSku.getUnbox().equals("1")) {
continue;
}
if (goblinGoodsSku.getHitRatio() != null){
// 不能购买的 没库存的 概率是0的 过滤
if (getSkuAllStatusShow(goblinGoodsSku) && goblinRedisUtils.getSkuAllStatusStock(goblinGoodsSku) > 0 && goblinGoodsSku.getHitRatio() != null) {
map.put(goblinGoodsSku.getSkuId(), goblinGoodsSku.getHitRatio());
}
}
}
List<GoblinNftExSku> goblinNftExSkus = new ArrayList<>();
List<GoblinNftExCode> goblinNftExCodes = new ArrayList<>();
// 构建对象
long startr = System.currentTimeMillis();
for (GoblinNftExSkuParam goblinNftExSkuParam : goblinNftExSkuParams) {
GoblinNftExSku goblinNftExSku = new GoblinNftExSku();
......@@ -102,7 +106,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
// 根据sku减库存
int stock = goblinRedisUtils.decrSkuStock(null, key, stockNum);
if (stock < 0) {
goblinRedisUtils.incrSkuStock(null,key,stockNum);
goblinRedisUtils.incrSkuStock(null, key, stockNum);
}
......@@ -144,7 +148,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
// 根据sku减库存
int stock = goblinRedisUtils.decrSkuStock(null, goblinNftExSkuParam.getSkuId(), goblinNftExSkuParam.getExStock());
if (stock < 0) {
goblinRedisUtils.incrSkuStock(null,goblinNftExSkuParam.getSkuId(),goblinNftExSkuParam.getExStock());
goblinRedisUtils.incrSkuStock(null, goblinNftExSkuParam.getSkuId(), goblinNftExSkuParam.getExStock());
}
// 构建兑换码数量
......@@ -184,10 +188,13 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
}
}
log.debug("RDM耗时:ms" , System.currentTimeMillis() - startr);
// 数据库操作
long startm = System.currentTimeMillis();
goblinNftExSkuMapper.addGoblinNftExSkus(goblinNftExSkus);
goblinNftExCodeMapper.addGoblinNftExCodes(goblinNftExCodes);
log.debug("MSQ耗时:ms" , System.currentTimeMillis() - startm);
return true;
}
......@@ -206,7 +213,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
for (String key : map.keySet()) {
if (map.get(key)==null){
if (map.get(key) == null) {
System.out.println(map.get(key));
}
// 概率
......@@ -217,4 +224,23 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
return skuNumMap;
}
// 各种状态下判断藏品是否可以展示
public boolean getSkuAllStatusShow(GoblinGoodsSku info) {
if (
info != null
&& info.getSkuType() == 1
&& info.getStatus().equals("3")
&& info.getShelvesStatus().equals("3")
&& (info.getSkuAppear() == null || info.getSkuAppear().equals("0"))
&& info.getDelFlg().equals("0")
&& info.getUnbox().equals("0")) {
return true;
} else {
return false;
}
}
}
......@@ -9,15 +9,18 @@ import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.dto.GoblinQueueBizIntegralDto;
import com.liquidnet.service.goblin.dto.GoblinStoreMarketDto;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo;
import com.liquidnet.service.goblin.dto.vo.GoblinOrderSkuVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreOrderVo;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Component
......@@ -205,13 +208,29 @@ public class GoblinRedisUtils {
return getRedis().set(key,goblinNftExCodeVo,millisNum);
}
// 获取盲盒下藏品的库存 各种状态下不能算库存的排除掉
public int getSkuAllStatusStock(GoblinGoodsSku info) {
if (
info != null
&& LocalDateTime.now().isAfter(info.getSaleStartTime())
&& (null == info.getSoldoutStatus() || info.getSoldoutStatus().equals("0"))
&& (null == info.getHitRatio() || info.getHitRatio().compareTo(BigDecimal.ZERO) > 0)
) {// 可以返回库存
String rk = GoblinRedisConst.REAL_STOCK_SKU.concat(info.getSkuId());
return (int)getRedis().get(rk);
} else {// 不计入库存
return 0;
}
}
/**
* redis codes主动失效
* @param codes
* @param code
*/
public void removeCodes(List<String> codes) {
getRedis().delList(codes);
public void removeCode(String code) {
getRedis().del(code);
}
/* ---------------------------------------- ---------------------------------------- */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment