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

Commit 59c8975a authored by wanglele's avatar wanglele

新增批量空投

parent 7bdddf17
package com.liquidnet.service.goblin.dto.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class GoblinNftExCodeFetchExcelVo {
@ExcelProperty(index = 0,value = "手机号")
String phone;
}
...@@ -5,6 +5,7 @@ import com.liquidnet.service.base.ResponseDto; ...@@ -5,6 +5,7 @@ import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo; import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo;
import com.liquidnet.service.goblin.dto.vo.PageInfoVo; import com.liquidnet.service.goblin.dto.vo.PageInfoVo;
import com.liquidnet.service.goblin.param.GoblinNftExCodeParam; import com.liquidnet.service.goblin.param.GoblinNftExCodeParam;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -35,4 +36,12 @@ public interface IGoblinNftExCodeService { ...@@ -35,4 +36,12 @@ public interface IGoblinNftExCodeService {
* @param goblinNftExCodeParam * @param goblinNftExCodeParam
*/ */
void excel(HttpServletResponse httpServletResponse, GoblinNftExCodeParam goblinNftExCodeParam); void excel(HttpServletResponse httpServletResponse, GoblinNftExCodeParam goblinNftExCodeParam);
/**
* 批量发送空投
* @param file
* @param activityId
* @return
*/
ResponseDto<Boolean> addAirdrops(MultipartFile file, String activityId);
} }
...@@ -76,4 +76,12 @@ public interface GoblinNftExCodeMapper extends BaseMapper<GoblinNftExCode> { ...@@ -76,4 +76,12 @@ public interface GoblinNftExCodeMapper extends BaseMapper<GoblinNftExCode> {
* @return * @return
*/ */
int updateCodeAdminUid(GoblinNftExCode goblinNftExCode); int updateCodeAdminUid(GoblinNftExCode goblinNftExCode);
/**
* 根据活动id获取可用的兑换码
* @param activityId
* @return
*/
List<GoblinNftExCode> selectCodeAvailableByActivityId(@Param("activityId") String activityId);
} }
...@@ -80,14 +80,14 @@ ...@@ -80,14 +80,14 @@
<if test="state != null"> <if test="state != null">
<choose> <choose>
<when test="state == 1"> <when test="state == 1">
and gnec.sku_id = gnes.sku_id and (now() BETWEEN gnes.ex_start_time and gnes.ex_stop_time) and and (now() BETWEEN gnes.ex_start_time and gnes.ex_stop_time) and
gnec.state =1 gnec.state =1
</when> </when>
<when test="state == 2"> <when test="state == 2">
and gnec.state = 2 and gnec.state = 2
</when> </when>
<when test="state == 3"> <when test="state == 3">
and gnec.sku_id = gnes.sku_id and (((now() &gt; gnes.ex_stop_time) AND gnec.state = 1) || and (((now() &gt; gnes.ex_stop_time) AND gnec.state = 1) ||
gnec.state = 3) gnec.state = 3)
</when> </when>
</choose> </choose>
...@@ -113,9 +113,26 @@ ...@@ -113,9 +113,26 @@
</if> </if>
</select> </select>
<select id="selectCodeAvailableByActivityId" resultMap="BeseResult">
select DISTINCT gnec.code,
gnec.code_id,
gnec.sku_id,
gnec.box_sku_id,
gnec.activity_id,
gnec.state,
gnec.redeem_uid,
gnec.redeem_at,
gnec.admin_uid,
gnec.created_at
from goblin_nft_ex_code gnec
inner join goblin_nft_ex_sku gnes
on gnec.sku_id = gnes.sku_id and gnec.activity_id = #{activityId,jdbcType=VARCHAR} and
gnec.state = 1 and (now() BETWEEN gnes.ex_start_time and gnes.ex_stop_time)
</select>
<select id="selectGoblinNftCodeCount" parameterType="com.liquidnet.service.goblin.entity.GoblinNftExCode" <select id="selectGoblinNftCodeCount" parameterType="com.liquidnet.service.goblin.entity.GoblinNftExCode"
resultType="java.lang.Integer"> resultType="java.lang.Integer">
select count(DISTINCT gnec.code) select count(DISTINCT gnec.code)
from goblin_nft_ex_code gnec inner join goblin_nft_ex_sku gnes from goblin_nft_ex_code gnec inner join goblin_nft_ex_sku gnes
on on
gnec.sku_id = gnes.sku_id gnec.sku_id = gnes.sku_id
......
package com.liquidnet.service.platform.controller.goblin.code;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeFetchExcelVo;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class CodeDataListener extends AnalysisEventListener<GoblinNftExCodeFetchExcelVo> {
// 返回的数据集合
List<String> phones = new ArrayList<>();
@Override
public void invoke(GoblinNftExCodeFetchExcelVo fetchExcel, AnalysisContext analysisContext) {
phones.add(fetchExcel.getPhone());
}
/**
* 在转换异常 获取其他异常下会调用本接口。抛出异常则停止读取。如果这里不抛出异常则 继续读取下一行。
*
* @param exception
* @param context
* @throws Exception
*/
@Override
public void onException(Exception exception, AnalysisContext context) {
log.error("解析失败,但是继续解析下一行:{}", exception.getMessage());
// 如果是某一个单元格的转换异常 能获取到具体行号
// 如果要获取头的信息 配合invokeHeadMap使用
if (exception instanceof ExcelDataConvertException) {
ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception;
log.error("第{}行,第{}列解析异常", excelDataConvertException.getRowIndex(),
excelDataConvertException.getColumnIndex());
}
}
/**
* 所有数据解析完成了 都会来调用
*
* @param analysisContext
*/
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
/**
* 返回数据
* @return
*/
public List<String> getData(){
return phones;
}
/**
* 设置读取的数据集合
*
* @param phones 设置读取的数据集合
**/
public void setDatas(List<String> phones) {
this.phones = phones;
}
}
...@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -35,36 +36,38 @@ public class GoblinNftExCodeController { ...@@ -35,36 +36,38 @@ public class GoblinNftExCodeController {
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@ApiOperation(value = "根据nft兑换活动获取兑换码") @ApiOperation(value = "根据nft兑换活动获取兑换码")
@PostMapping("selectCodePageList") @PostMapping("selectCodePageList")
public ResponseDto<PageInfoVo> selectCodePageList(@RequestBody GoblinNftExCodeParam goblinNftExCodeParam){ public ResponseDto<PageInfoVo> selectCodePageList(@RequestBody GoblinNftExCodeParam goblinNftExCodeParam) {
return ResponseDto.success(iGoblinNftExCodeService.selectCodePageList(goblinNftExCodeParam)); return ResponseDto.success(iGoblinNftExCodeService.selectCodePageList(goblinNftExCodeParam));
} }
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "兑换码主动失效") @ApiOperation(value = "兑换码主动失效")
@PostMapping("defDrivLoseCodes/{codeIds}") @PostMapping("defDrivLoseCodes/{codeIds}")
public ResponseDto<Boolean> defDrivLoseCode(@PathVariable("codeIds")String codeIds){ public ResponseDto<Boolean> defDrivLoseCode(@PathVariable("codeIds") String codeIds) {
return ResponseDto.success(iGoblinNftExCodeService.defDrivLoseCode(codeIds)); return ResponseDto.success(iGoblinNftExCodeService.defDrivLoseCode(codeIds));
} }
@ApiOperationSupport(order = 3) @ApiOperationSupport(order = 3)
@ApiOperation(value = "空投发送") @ApiOperation(value = "空投发送")
@PostMapping("addAirdrop") @PostMapping("addAirdrop")
public ResponseDto<Boolean> addAirdrop(@RequestBody GoblinNftExCodeParam goblinNftExCodeParam){ public ResponseDto<Boolean> addAirdrop(@RequestBody GoblinNftExCodeParam goblinNftExCodeParam) {
return iGoblinNftExCodeService.addAirdrop(goblinNftExCodeParam); return iGoblinNftExCodeService.addAirdrop(goblinNftExCodeParam);
} }
@ApiOperationSupport(order = 4) @ApiOperationSupport(order = 4)
@ApiOperation(value = "兑换码导出") @ApiOperation(value = "excel空投批量发送")
@PostMapping("excel") @PostMapping("addAirdrops/{activityId}")
public void excel(HttpServletResponse httpServletResponse,@RequestBody GoblinNftExCodeParam goblinNftExCodeParam){ public ResponseDto<Boolean> addAirdrops(MultipartFile file,@PathVariable("activityId")String activityId) {
iGoblinNftExCodeService.excel(httpServletResponse,goblinNftExCodeParam); return iGoblinNftExCodeService.addAirdrops(file,activityId);
} }
@ApiOperationSupport(order = 5)
@ApiOperation(value = "兑换码导出")
@PostMapping("excel")
public void excel(HttpServletResponse httpServletResponse, @RequestBody GoblinNftExCodeParam goblinNftExCodeParam) {
iGoblinNftExCodeService.excel(httpServletResponse, goblinNftExCodeParam);
}
} }
package com.liquidnet.service.platform.service.impl.goblin; package com.liquidnet.service.platform.service.impl.goblin;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.fasterxml.jackson.annotation.JsonFormat; import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.*; import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.adam.dto.AdamUserInfoDto; import com.liquidnet.service.adam.dto.AdamUserInfoDto;
import com.liquidnet.service.adam.entity.AdamUser;
import com.liquidnet.service.adam.mapper.AdamUserMapper; import com.liquidnet.service.adam.mapper.AdamUserMapper;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.dto.vo.CodeExcelVo; import com.liquidnet.service.goblin.dto.vo.CodeExcelVo;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExActivityVo; import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeFetchExcelVo;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo; import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo;
import com.liquidnet.service.goblin.dto.vo.PageInfoVo; import com.liquidnet.service.goblin.dto.vo.PageInfoVo;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku; import com.liquidnet.service.goblin.entity.GoblinGoodsSku;
...@@ -25,9 +28,11 @@ import com.liquidnet.service.goblin.mapper.GoblinNftExCodeMapper; ...@@ -25,9 +28,11 @@ import com.liquidnet.service.goblin.mapper.GoblinNftExCodeMapper;
import com.liquidnet.service.goblin.mapper.GoblinNftExSkuMapper; import com.liquidnet.service.goblin.mapper.GoblinNftExSkuMapper;
import com.liquidnet.service.goblin.param.GoblinNftExCodeParam; import com.liquidnet.service.goblin.param.GoblinNftExCodeParam;
import com.liquidnet.service.goblin.service.IGoblinNftExCodeService; import com.liquidnet.service.goblin.service.IGoblinNftExCodeService;
import com.liquidnet.service.platform.controller.goblin.code.CodeDataListener;
import com.liquidnet.service.platform.utils.GoblinRedisUtils; import com.liquidnet.service.platform.utils.GoblinRedisUtils;
import com.liquidnet.service.platform.utils.ObjectUtil; import com.liquidnet.service.platform.utils.ObjectUtil;
import com.sun.org.apache.xpath.internal.operations.Bool; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -36,9 +41,12 @@ import org.springframework.stereotype.Service; ...@@ -36,9 +41,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import sun.rmi.log.LogInputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -312,18 +320,26 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService { ...@@ -312,18 +320,26 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
List<GoblinNftExSku> goblinNftExSkus = goblinNftExSkuMapper.selectGoblinNftExSkuByActivityIds(acticityIds.toString()); List<GoblinNftExSku> goblinNftExSkus = goblinNftExSkuMapper.selectGoblinNftExSkuByActivityIds(acticityIds.toString());
ArrayList<CodeExcelVo> codeExcelVoArrayList = ObjectUtil.getCodeExcelVoArrayList(); ArrayList<CodeExcelVo> codeExcelVoArrayList = ObjectUtil.getCodeExcelVoArrayList();
for (GoblinNftExCodeVo gnc : goblinNftExCodeArrayList) {
LocalDateTime now = LocalDateTime.now();
for (GoblinNftExCodeVo gnc : goblinNftExCodeArrayList) {
for (GoblinNftExSku goblinNftExSku : goblinNftExSkus) { for (GoblinNftExSku goblinNftExSku : goblinNftExSkus) {
if (gnc.getActivityId().equals(goblinNftExSku.getActivityId())) { if (gnc.getActivityId().equals(goblinNftExSku.getActivityId())) {
if (StringUtil.isNotBlank(gnc.getBoxSkuId()) && gnc.getSkuId().equals(goblinNftExSku.getSkuId())) { if (StringUtil.isNotBlank(gnc.getBoxSkuId()) && gnc.getSkuId().equals(goblinNftExSku.getSkuId())) {
gnc.setExStartTime(goblinNftExSku.getExStartTime()); gnc.setExStartTime(goblinNftExSku.getExStartTime());
gnc.setExStopTime(goblinNftExSku.getExStopTime()); gnc.setExStopTime(goblinNftExSku.getExStopTime());
if (now.isAfter(goblinNftExSku.getExStopTime())) {
gnc.setState(3);
}
break; break;
} else { } else {
if (gnc.getSkuId().equals(goblinNftExSku.getSkuId())) { if (gnc.getSkuId().equals(goblinNftExSku.getSkuId())) {
gnc.setExStartTime(goblinNftExSku.getExStartTime()); gnc.setExStartTime(goblinNftExSku.getExStartTime());
gnc.setExStopTime(goblinNftExSku.getExStopTime()); gnc.setExStopTime(goblinNftExSku.getExStopTime());
if (now.isAfter(goblinNftExSku.getExStopTime())) {
gnc.setState(3);
}
break; break;
} }
} }
...@@ -364,6 +380,28 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService { ...@@ -364,6 +380,28 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
} }
@Override
public ResponseDto<Boolean> addAirdrops(MultipartFile file, String activityId) {
try{
CodeDataListener codeDataListener = new CodeDataListener();
// https://alibaba-easyexcel.github.io/quickstart/read.html
ExcelReader excelReader = EasyExcelFactory.read(file.getInputStream(), GoblinNftExCodeFetchExcelVo.class, codeDataListener).headRowNumber(0).build();
excelReader.readAll();
List<String> phones = codeDataListener.getData();
// 根据活动id获取可用兑换码
List<GoblinNftExCode> goblinNftExCodes = goblinNftExCodeMapper.selectCodeAvailableByActivityId(activityId);
if (goblinNftExCodes.size() < phones.size()){
return ResponseDto.failure("可用兑换码不足!");
}
}catch (Exception e){
e.printStackTrace();
}
return null;
}
/** /**
* 导出 * 导出
......
...@@ -99,42 +99,48 @@ public class GoblinNftExCodeTaskServiceImpl implements IGoblinNftExCodeTaskServi ...@@ -99,42 +99,48 @@ public class GoblinNftExCodeTaskServiceImpl implements IGoblinNftExCodeTaskServi
case "1": case "1":
// 获取盲盒 sku-->库存 // 获取盲盒 sku-->库存
for (GoblinNftExCodeTaskRelation goblinNftExCodeTaskRelation : goblinNftExCodeTaskRelations) { for (GoblinNftExCodeTaskRelation goblinNftExCodeTaskRelation : goblinNftExCodeTaskRelations) {
if (goblinNftExCodeTaskRelation.getTaskId().equals(goblinNftExCodeTask.getTaskId())) { if (goblinNftExCodeTaskRelation.getTaskId().equals(goblinNftExCodeTask.getTaskId()) && goblinNftExCodeTaskRelation.getStock() > 0) {
if (goblinNftExCodeTaskRelation.getStock() > 0) { for (int j = 0; j < goblinNftExCodeTaskRelation.getStock(); j++) {
for (int j = 0; j < goblinNftExCodeTaskRelation.getStock(); j++) { GoblinNftExCode goblinNftExCode = GoblinNftExCode.getNew();
GoblinNftExCode goblinNftExCode = GoblinNftExCode.getNew(); goblinNftExCode.setCodeId(IDGenerator.nextSnowId());
goblinNftExCode.setCodeId(IDGenerator.nextSnowId()); goblinNftExCode.setActivityId(goblinNftExCodeTask.getActivityId());
goblinNftExCode.setActivityId(goblinNftExCodeTask.getActivityId()); // 兑换码
// 兑换码 // 样例 2978-6496-9269-0694-XX
// 样例 2978-6496-9269-0694-XX String code = IDGenerator.createCode(3, 4, true);
String code = IDGenerator.createCode(3, 4, true); goblinNftExCode.setCode(code);
goblinNftExCode.setCode(code); goblinNftExCode.setBoxSkuId(goblinNftExCodeTaskRelation.getSkuId());
goblinNftExCode.setBoxSkuId(goblinNftExCodeTaskRelation.getSkuId()); goblinNftExCode.setState(1);
goblinNftExCode.setState(1); goblinNftExCode.setCreatedAt(now);
goblinNftExCode.setCreatedAt(now); goblinNftExCode.setSkuId(goblinNftExCodeTask.getSkuId());
goblinNftExCode.setSkuId(goblinNftExCodeTask.getSkuId());
// 赋值额外属性
// 赋值额外属性 GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(goblinNftExCode);
GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(goblinNftExCode); goblinNftExCodeVo.setExLimit(goblinNftExCodeTask.getExLimit());
goblinNftExCodeVo.setExLimit(goblinNftExCodeTask.getExLimit()); goblinNftExCodeVo.setExStartTime(goblinNftExCodeTask.getExStartTime());
goblinNftExCodeVo.setExStartTime(goblinNftExCodeTask.getExStartTime()); goblinNftExCodeVo.setExStopTime(goblinNftExCodeTask.getExStopTime());
goblinNftExCodeVo.setExStopTime(goblinNftExCodeTask.getExStopTime()); goblinNftExCodeVo.setStoreId(goblinNftExCodeTask.getStoreId());
goblinNftExCodeVo.setStoreId(goblinNftExCodeTask.getStoreId()); goblinNftExCodeVo.setSpuId(goblinNftExCodeTask.getSpuId());
goblinNftExCodeVo.setSpuId(goblinNftExCodeTask.getSpuId()); goblinNftExCodeVo.setUnBox(goblinNftExCodeTask.getUnbox());
goblinNftExCodeVo.setUnBox(goblinNftExCodeTask.getUnbox());
LocalDateTime exStopTime = goblinNftExCodeTask.getExStopTime();
LocalDateTime exStopTime = goblinNftExCodeTask.getExStopTime(); // 时间差 以秒表示
// 时间差 以秒表示 long millisNum = Duration.between(LocalDateTime.now(), exStopTime).toMillis();
long millisNum = Duration.between(LocalDateTime.now(), exStopTime).toMillis(); // redis 存储
// redis 存储 goblinRedisUtils.addCode(code, goblinNftExCodeVo, millisNum);
goblinRedisUtils.addCode(code, goblinNftExCodeVo, millisNum);
goblinNftExCodes.add(goblinNftExCode);
goblinNftExCodes.add(goblinNftExCode);
}
} }
if (goblinNftExCodeTaskHashMap.get(goblinNftExCodeTask.getSkuId()) == null) { if (goblinNftExCodeTaskHashMap.get(goblinNftExCodeTask.getSkuId()) == null) {
goblinNftExCodeTaskHashMap.put(goblinNftExCodeTaskRelation.getSkuId(), goblinNftExCodeTask); goblinNftExCodeTaskHashMap.put(goblinNftExCodeTaskRelation.getSkuId(), goblinNftExCodeTask);
} else {
GoblinNftExCodeTask nftExCodeTask = goblinNftExCodeTaskHashMap.get(goblinNftExCodeTask.getSkuId());
LocalDateTime exStartTime = nftExCodeTask.getExStartTime();
LocalDateTime exStopTime = nftExCodeTask.getExStopTime();
// 时间比较
} }
} }
} }
...@@ -178,6 +184,12 @@ public class GoblinNftExCodeTaskServiceImpl implements IGoblinNftExCodeTaskServi ...@@ -178,6 +184,12 @@ public class GoblinNftExCodeTaskServiceImpl implements IGoblinNftExCodeTaskServi
GoblinNftExCodeTask nftExCodeTask = goblinNftExCodeTaskHashMap.get(goblinNftExCodeTask.getSkuId()); GoblinNftExCodeTask nftExCodeTask = goblinNftExCodeTaskHashMap.get(goblinNftExCodeTask.getSkuId());
if (nftExCodeTask == null) { if (nftExCodeTask == null) {
goblinNftExCodeTaskHashMap.put(goblinNftExCodeTask.getSkuId(), goblinNftExCodeTask); goblinNftExCodeTaskHashMap.put(goblinNftExCodeTask.getSkuId(), goblinNftExCodeTask);
} else {
GoblinNftExCodeTask nftExCodeTaskCurrent = goblinNftExCodeTaskHashMap.get(goblinNftExCodeTask.getSkuId());
LocalDateTime exStartTime = nftExCodeTaskCurrent.getExStartTime();
LocalDateTime exStopTime = nftExCodeTaskCurrent.getExStopTime();
// 时间比较
} }
} }
} }
...@@ -228,8 +240,7 @@ public class GoblinNftExCodeTaskServiceImpl implements IGoblinNftExCodeTaskServi ...@@ -228,8 +240,7 @@ public class GoblinNftExCodeTaskServiceImpl implements IGoblinNftExCodeTaskServi
public static void main(String[] args) { public static void main(String[] args) {
LocalDateTime exStopTime = LocalDateTime.parse("2024-06-26 19:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // "2019-06-26 19:00:00"; LocalDateTime exStopTime = LocalDateTime.parse("2024-06-26 19:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // "2019-06-26 19:00:00";
LocalDateTime rdExStopTime = LocalDateTime.parse("2066-06-26 19:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // "2019-06-26 19:00:00"; LocalDateTime rdExStopTime = LocalDateTime.parse("2066-06-26 19:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // "2019-06-26 19:00:00";
if (exStopTime.isBefore(rdExStopTime)){ if (exStopTime.isBefore(rdExStopTime)) {
} }
} }
......
...@@ -271,7 +271,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -271,7 +271,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
objectMap2.put("stock", 100); objectMap2.put("stock", 100);
mapMap.put("3", objectMap2); mapMap.put("3", objectMap2);
Map<String, Integer> stockMap = new HashMap<>(); Map<String, Integer> stockMap = new HashMap<>();
getStock(10, new BigDecimal(60), mapMap, stockMap); getStock(120, new BigDecimal(60), mapMap, stockMap);
System.out.println("kkk"); System.out.println("kkk");
} }
...@@ -288,18 +288,21 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -288,18 +288,21 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
return; return;
} }
// 单个sku ---> 当前循环权重
HashMap<String, BigDecimal> bigDecimalHashMap = CollectionUtil.mapStringBigDecimal();
int subNumber = 0; int subNumber = 0;
for (String key : mapMap.keySet()) { for (String key : mapMap.keySet()) {
Object stock = mapMap.get(key).get("stock"); Object stock = mapMap.get(key).get("stock");
Object hitRatio = mapMap.get(key).get("hitRatio"); Object hitRatio = mapMap.get(key).get("hitRatio");
if (Integer.valueOf(stock.toString()) < 0) { if (Integer.valueOf(stock.toString()) <= 0) {
continue; continue;
} }
// BigDecimal bigDecimal = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP))).setScale(0, BigDecimal.ROUND_HALF_UP); BigDecimal bigDecimal = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP)));
bigDecimalHashMap.put(key, bigDecimal);
// 要减去的库存 // 要减去的库存
int subStock = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP))).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); int subStock = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP))).setScale(0, BigDecimal.ROUND_UP).intValue();
if (subStock > Integer.valueOf(stock.toString())) { if (subStock > Integer.valueOf(stock.toString())) {
subNumber += Integer.valueOf(stock.toString()); subNumber += Integer.valueOf(stock.toString());
...@@ -320,6 +323,30 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -320,6 +323,30 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
} }
} }
if (subNumber > exStock) {
int usNumber = subNumber - exStock;
ArrayList<String> skuIdList = CollectionUtil.arrayListString();
for (int k = 0; k < usNumber; k++) {
String subKey = "";
double maxValue = Double.MAX_VALUE;
for (String key : bigDecimalHashMap.keySet()) {
if (skuIdList.contains(key)) {
continue;
}
Double compare = Double.valueOf(bigDecimalHashMap.get(key).toString());
if (maxValue > compare) {
maxValue = compare;
subKey = key;
}
}
Integer stock = stockMap.get(subKey);
stockMap.put(subKey, stock - 1);
skuIdList.add(subKey);
}
return;
}
exStock -= subNumber; exStock -= subNumber;
if (exStock > 0) { if (exStock > 0) {
for (String key : mapMap.keySet()) { for (String key : mapMap.keySet()) {
......
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