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

Commit ee9eb5ce authored by 胡佳晨's avatar 胡佳晨

提交 积分商品 首页接口

parent e1ab3c53
package com.liquidnet.service.stone.service;
import com.github.pagehelper.PageInfo;
import com.liquidnet.service.stone.vo.StoneItemListVo;
import java.util.List;
/**
* <p>
* 积分物品表 服务类
......@@ -11,4 +16,6 @@ package com.liquidnet.service.stone.service;
*/
public interface IStoneScoreItemsService {
PageInfo<List<StoneItemListVo>> itemList(Integer page, Integer size);
}
package com.liquidnet.service.stone.vo;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.service.stone.entity.StoneScoreItems;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@ApiModel
public class StoneItemListVo implements Serializable, Cloneable {
/**
* id
*/
@ApiModelProperty(value = "id", example = "1")
private String itemId;
/**
* 积分物品封面图
*/
@ApiModelProperty(value = "积分物品封面图", example = "http://xxxxx.png")
private String img;
/**
* 积分物品名称
*/
@ApiModelProperty(value = "积分物品名称", example = "测试券")
private String targetTitle;
/**
* 目标类型[1-券|1x-商品维度|2x-演出维度]
*/
@ApiModelProperty(value = "目标类型[1-券|1x-商品维度|2x-演出维度]", example = "1")
private Integer type;
/**
* 积分
*/
@ApiModelProperty(value = "积分", example = "100.00")
private Integer score;
/**
* 价格
*/
@ApiModelProperty(value = "价格", example = "0.00")
private BigDecimal price;
/**
* 状态状态[-999-全部|-1-删除|0-未上架|1-已上架|2-定时上架|7-已下架|8-售罄]
*/
@ApiModelProperty(value = "状态状态[-999-全部|-1-删除|0-未上架|1-已上架|2-定时上架|7-已下架|8-售罄]", example = "1")
private Integer status;
private static final StoneItemListVo obj = new StoneItemListVo();
public static StoneItemListVo getNew() {
try {
return (StoneItemListVo) obj.clone();
} catch (CloneNotSupportedException e) {
return new StoneItemListVo();
}
}
public StoneItemListVo copy(StoneScoreItems source) {
if (null == source) return this;
this.setItemId(source.getItemId());
this.setImg(source.getImg());
this.setTargetTitle(source.getTargetTitle());
this.setType(source.getType());
this.setScore(source.getScore().intValue());
this.setPrice(source.getPrice());
LocalDateTime now = LocalDateTime.now();
if (source.getStatus() == 2) {
if (now.isAfter(source.getStartTime())) {//未上架
this.setStatus(2);
} else if (now.isBefore(source.getEndTime())) {//已下架
this.setStatus(7);
} else {
this.setStatus(1);//上架中
// if (source.getGeneralSurplus()<=0) {
// this.setStatus(8);//售罄
// } else {
// this.setStatus(1);//上架中
// }
}
}else{
this.setStatus(source.getStatus());
}
return this;
}
}
......@@ -57,7 +57,7 @@ public class ItemServiceImpl implements IItemService {
} else if (status == 7) {//已下架
queryWrapper.eq(StoneScoreItems::getStatus, 7).or().eq(StoneScoreItems::getStatus, 2).lt(StoneScoreItems::getEndTime, now);
} else if (status == 1) {
queryWrapper.eq(StoneScoreItems::getStatus, 1).or().lt(StoneScoreItems::getStartTime, now).gt(StoneScoreItems::getEndTime, now);
queryWrapper.eq(StoneScoreItems::getStatus, 1).or().eq(StoneScoreItems::getStatus, 2).lt(StoneScoreItems::getStartTime, now).gt(StoneScoreItems::getEndTime, now);
}
}
}
......@@ -105,8 +105,8 @@ public class ItemServiceImpl implements IItemService {
mongoUtils.itemUpdateById(redisData);
//redis
redisUtils.setItemData(data.getItemId(), redisData);
//修改 List
redisUtils.updateItemDataList(redisData);
// //修改 List
// redisUtils.updateItemDataList(redisData);
if (result <= 0) {
return "修改失败";
......@@ -143,8 +143,8 @@ public class ItemServiceImpl implements IItemService {
mongoUtils.itemCreate(data);
//redis
redisUtils.setItemData(data.getItemId(), data);
//修改 List
redisUtils.addItemDataList(data);
// //修改 List
// redisUtils.addItemDataList(data);
if (count <= 0) {
return "创建失败";
}
......@@ -169,8 +169,8 @@ public class ItemServiceImpl implements IItemService {
mongoUtils.itemUpdateById(data);
//redis
redisUtils.setItemData(data.getItemId(), data);
//修改 List
redisUtils.updateItemDataList(data);
// //修改 List
// redisUtils.updateItemDataList(data);
if (count <= 0) {
return "修改失败";
}
......
......@@ -62,17 +62,17 @@ public class StoneMongoUtils {
return result;
}
/**
* 查询 积分物品 列表
*
* @return
*/
public List<StoneScoreItems> itemList() {
Query query = Query.query(Criteria.where("status").ne(-1));
List<StoneScoreItems> voList = mongoTemplate.find(query.with(Sort.by(Sort.Direction.DESC, "createdAt")).limit(40),
StoneScoreItems.class, StoneScoreItems.class.getSimpleName());
return voList;
}
// /**
// * 查询 积分物品 列表
// *
// * @return
// */
// public List<StoneScoreItems> itemList() {
// Query query = Query.query(Criteria.where("status").ne(-1));
// List<StoneScoreItems> voList = mongoTemplate.find(query.with(Sort.by(Sort.Direction.DESC, "createdAt")).limit(40),
// StoneScoreItems.class, StoneScoreItems.class.getSimpleName());
// return voList;
// }
/**
* 创建 用户积分
......
......@@ -81,66 +81,66 @@ public class StoneRedisUtils {
}
/**
* 修改 积分物品 缓存list
*
* @param data
*/
public void updateItemDataList(StoneScoreItems data) {
String redisKey = StoneConstant.ITEM_LIST;
Object obj = redisUtil.get(redisKey);
List<StoneScoreItems> dataList;
if (obj == null) {
dataList = mongoUtils.itemList();
} else {
dataList = (List<StoneScoreItems>) obj;
}
for (int i = 0; i < dataList.size(); i++) {
StoneScoreItems items = dataList.get(i);
if (items.getItemId().equals(data.getItemId())) {
dataList.set(i, items);
break;
}
}
redisUtil.set(redisKey, dataList);
}
// /**
// * 修改 积分物品 缓存list
// *
// * @param data
// */
// public void updateItemDataList(StoneScoreItems data) {
// String redisKey = StoneConstant.ITEM_LIST;
// Object obj = redisUtil.get(redisKey);
// List<StoneScoreItems> dataList;
// if (obj == null) {
// dataList = mongoUtils.itemList();
// } else {
// dataList = (List<StoneScoreItems>) obj;
// }
// for (int i = 0; i < dataList.size(); i++) {
// StoneScoreItems items = dataList.get(i);
// if (items.getItemId().equals(data.getItemId())) {
// dataList.set(i, items);
// break;
// }
// }
// redisUtil.set(redisKey, dataList);
// }
/**
* 添加 积分物品 缓存list
*
* @param data
*/
public void addItemDataList(StoneScoreItems data) {
String redisKey = StoneConstant.ITEM_LIST;
Object obj = redisUtil.get(redisKey);
List<StoneScoreItems> dataList;
if (obj == null) {
dataList = mongoUtils.itemList();
} else {
dataList = (List<StoneScoreItems>) obj;
}
dataList.add(0, data);
if (dataList.size() > 40) {
int size = dataList.size() - 40;
for (int i = 0; i < size; i++) {
dataList.remove(40);
}
}
redisUtil.set(redisKey, dataList);
}
// /**
// * 添加 积分物品 缓存list
// *
// * @param data
// */
// public void addItemDataList(StoneScoreItems data) {
// String redisKey = StoneConstant.ITEM_LIST;
// Object obj = redisUtil.get(redisKey);
// List<StoneScoreItems> dataList;
// if (obj == null) {
// dataList = mongoUtils.itemList();
// } else {
// dataList = (List<StoneScoreItems>) obj;
// }
// dataList.add(0, data);
// if (dataList.size() > 40) {
// int size = dataList.size() - 40;
// for (int i = 0; i < size; i++) {
// dataList.remove(40);
// }
// }
// redisUtil.set(redisKey, dataList);
// }
/**
* 设置 积分物品 缓存list
*/
public List<StoneScoreItems> getItemDataList() {
String redisKey = StoneConstant.ITEM_LIST;
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return mongoUtils.itemList();
} else {
return (List<StoneScoreItems>) obj;
}
}
// /**
// * 设置 积分物品 缓存list
// */
// public List<StoneScoreItems> getItemDataList() {
// String redisKey = StoneConstant.ITEM_LIST;
// Object obj = redisUtil.get(redisKey);
// if (obj == null) {
// return mongoUtils.itemList();
// } else {
// return (List<StoneScoreItems>) obj;
// }
// }
/**
* 设置 用户积分 缓存
......
......@@ -12,6 +12,9 @@ public class StoneScoreListDto implements Cloneable {
*/
// @ApiModelProperty(required = false, value = "昵称", example = "宇航员Marinda")
private String nickName;
/**
* 头像
*/
private String avatar;
/**
* 手机号
......
package com.liquidnet.service.stone.service.impl;
import com.github.pagehelper.PageInfo;
import com.liquidnet.service.base.UserPathDto;
import com.liquidnet.service.stone.entity.StoneScoreItems;
import com.liquidnet.service.stone.service.IStoneScoreItemsService;
import com.liquidnet.service.stone.util.ObjectUtils;
import com.liquidnet.service.stone.util.StoneMongoUtils;
import com.liquidnet.service.stone.util.StoneRedisUtils;
import com.liquidnet.service.stone.vo.StoneItemListVo;
import io.netty.util.internal.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* <p>
......@@ -12,6 +27,43 @@ import org.springframework.stereotype.Service;
* @since 2021-10-19
*/
@Service
@Slf4j
public class StoneScoreItemsServiceImpl implements IStoneScoreItemsService {
@Autowired
private StoneRedisUtils redisUtils;
@Autowired
private StoneMongoUtils mongoUtils;
@Override
public PageInfo<List<StoneItemListVo>> itemList(Integer page, Integer size) {
PageInfo<List<StoneItemListVo>> mPageInfo;
size = 40;
if (page == null || page == 1 || page == 0) {
page = 1;
}
List<StoneScoreItems> voList;
HashMap<String, Object> info = mongoUtils.itemListPage(page, size);
try {
voList = (List<StoneScoreItems>) info.get("total");
} catch (Exception e) {
voList = new ArrayList();
}
long count = (long) info.get("data");
List<StoneItemListVo> returnVoList = ObjectUtils.getStoneItemListVoArrayList();
for (int i = 0; i < voList.size(); i++) {
StoneScoreItems vo = voList.get(i);
// vo.setGeneralSurplus(redisUtils.getStoneGeneralSurplus(vo.getItemId()));
StoneItemListVo returnVo = StoneItemListVo.getNew().copy(vo);
returnVoList.add(returnVo);
}
mPageInfo = new PageInfo(returnVoList);
mPageInfo.setTotal(count);
log.info(UserPathDto.setData("积分商品列表", "", voList));
return mPageInfo;
}
}
package com.liquidnet.service.stone.util;
import com.liquidnet.service.stone.vo.StoneItemListVo;
import java.util.ArrayList;
public class ObjectUtils {
private static final ArrayList<StoneItemListVo> stoneItemListVoArrayList = new ArrayList<>();
public static ArrayList<StoneItemListVo> getStoneItemListVoArrayList() {
return (ArrayList<StoneItemListVo>) stoneItemListVoArrayList.clone();
}
}
package com.liquidnet.service.stone.util;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.stone.entity.StoneScoreItems;
import com.liquidnet.service.stone.vo.StoneUserVo;
import com.mongodb.client.result.UpdateResult;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
......@@ -13,6 +16,8 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
@Component
......@@ -21,16 +26,6 @@ public class StoneMongoUtils {
@Autowired
private MongoTemplate mongoTemplate;
/**
* 创建 积分物品
*
* @param data
* @return
*/
public Object itemCreate(StoneScoreItems data) {
return mongoTemplate.insert(data, StoneScoreItems.class.getSimpleName());
}
/**
* 获取 积分物品
*
......@@ -56,16 +51,37 @@ public class StoneMongoUtils {
return result;
}
// /**
// * 查询 积分物品 列表
// *
// * @return
// */
// public List<StoneScoreItems> itemList() {
// Query query = Query.query(Criteria.where("status").ne(-1));
// List<StoneScoreItems> voList = mongoTemplate.find(query.with(Sort.by(Sort.Direction.DESC, "createdAt")).limit(40),
// StoneScoreItems.class, StoneScoreItems.class.getSimpleName());
// return voList;
// }
/**
* 查询 积分物品 列表
* 查询 积分物品 列表分页
*
* @return
*/
public List<StoneScoreItems> itemList() {
Query query = Query.query(Criteria.where("status").ne(-1));
List<StoneScoreItems> voList = mongoTemplate.find(query.with(Sort.by(Sort.Direction.DESC, "createdAt")).limit(40),
StoneScoreItems.class, StoneScoreItems.class.getSimpleName());
return voList;
public HashMap<String, Object> itemListPage(int page, int size) {
LocalDateTime now = LocalDateTime.now();
HashMap<String, Object> info = CollectionUtil.mapStringObject();
// 排序 分页
Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdAt"));
//条件
Query query = Query.query(Criteria.where("status").is(1).orOperator(Criteria.where("status").is(2).and("startTime").lt(now).and("endTime").gt(now)));
// 查询总数
long count = mongoTemplate.count(query, StoneScoreItems.class, StoneScoreItems.class.getSimpleName());
query.with(pageable);
List<StoneScoreItems> voList = mongoTemplate.find(query, StoneScoreItems.class, StoneScoreItems.class.getSimpleName());
info.put("total", count);
info.put("data", voList);
return info;
}
/**
......
......@@ -110,66 +110,66 @@ public class StoneRedisUtils {
}
/**
* 修改 积分物品 缓存list
*
* @param data
*/
public void updateItemDataList(StoneScoreItems data) {
String redisKey = StoneConstant.ITEM_LIST;
Object obj = redisUtil.get(redisKey);
List<StoneScoreItems> dataList;
if (obj == null) {
dataList = mongoUtils.itemList();
} else {
dataList = (List<StoneScoreItems>) obj;
}
for (int i = 0; i < dataList.size(); i++) {
StoneScoreItems items = dataList.get(i);
if (items.getItemId().equals(data.getItemId())) {
dataList.set(i, items);
break;
}
}
redisUtil.set(redisKey, dataList);
}
/**
* 添加 积分物品 缓存list
*
* @param data
*/
public void addItemDataList(StoneScoreItems data) {
String redisKey = StoneConstant.ITEM_LIST;
Object obj = redisUtil.get(redisKey);
List<StoneScoreItems> dataList;
if (obj == null) {
dataList = mongoUtils.itemList();
} else {
dataList = (List<StoneScoreItems>) obj;
}
dataList.add(0, data);
if (dataList.size() > 40) {
int size = dataList.size() - 40;
for (int i = 0; i < size; i++) {
dataList.remove(40);
}
}
redisUtil.set(redisKey, dataList);
}
/**
* 设置 积分物品 缓存list
*/
public List<StoneScoreItems> getItemDataList() {
String redisKey = StoneConstant.ITEM_LIST;
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return mongoUtils.itemList();
} else {
return (List<StoneScoreItems>) obj;
}
}
// /**
// * 修改 积分物品 缓存list
// *
// * @param data
// */
// public void updateItemDataList(StoneScoreItems data) {
// String redisKey = StoneConstant.ITEM_LIST;
// Object obj = redisUtil.get(redisKey);
// List<StoneScoreItems> dataList;
// if (obj == null) {
// dataList = mongoUtils.itemList();
// } else {
// dataList = (List<StoneScoreItems>) obj;
// }
// for (int i = 0; i < dataList.size(); i++) {
// StoneScoreItems items = dataList.get(i);
// if (items.getItemId().equals(data.getItemId())) {
// dataList.set(i, items);
// break;
// }
// }
// redisUtil.set(redisKey, dataList);
// }
// /**
// * 添加 积分物品 缓存list
// *
// * @param data
// */
// public void addItemDataList(StoneScoreItems data) {
// String redisKey = StoneConstant.ITEM_LIST;
// Object obj = redisUtil.get(redisKey);
// List<StoneScoreItems> dataList;
// if (obj == null) {
// dataList = mongoUtils.itemList();
// } else {
// dataList = (List<StoneScoreItems>) obj;
// }
// dataList.add(0, data);
// if (dataList.size() > 40) {
// int size = dataList.size() - 40;
// for (int i = 0; i < size; i++) {
// dataList.remove(40);
// }
// }
// redisUtil.set(redisKey, dataList);
// }
// /**
// * 设置 积分物品 缓存list
// */
// public List<StoneScoreItems> getItemDataList() {
// String redisKey = StoneConstant.ITEM_LIST;
// Object obj = redisUtil.get(redisKey);
// if (obj == null) {
// return mongoUtils.itemList();
// } else {
// return (List<StoneScoreItems>) obj;
// }
// }
/**
* 设置 用户积分 缓存
......
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