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

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

提交 积分商品增加 字段 simpleType 区别于 TYPE字段 用作局 类别分组

parent ac5ae395
......@@ -2,17 +2,22 @@ package com.liquidnet.service.stone.constant;
public class StoneConstant {
//ctx
private static final String CTX="stone:";
private static final String CTX = "stone:";
//user
public static final String USER=CTX.concat("user:");
public static final String USER = CTX.concat("user:");
//item
public static final String ITEM=CTX.concat("item:");
public static final String ITEM = CTX.concat("item:");
//logsList 积分日志列表
public static final String LOGS_LIST=ITEM.concat("logs:list:");
public static final String LOGS_LIST = ITEM.concat("logs:list:");
//orderList 积分订单列表
public static final String ORDER_LIST=ITEM.concat("order:list:");
public static final String ORDER_LIST = ITEM.concat("order:list:");
//orderList 积分订单列表
public static final String ORDER_DETAILS=ITEM.concat("order:details:");
public static final String ORDER_DETAILS = ITEM.concat("order:details:");
//商品列表
public static final String ITEM_LIST = ITEM.concat("list");
//商品列表分类
public static final String ITEM_LIST_SIMPLE = ITEM.concat("list:simpleType:");
//剩余库存
public static final String SURPLUS_GENERAL = ":surplusGeneral";
......
......@@ -21,6 +21,8 @@ public interface IStoneScoreItemsService {
PageInfo<List<StoneItemListVo>> itemList(Integer page, Integer size);
PageInfo<List<StoneItemListVo>> itemListSimpleType(Integer simpleType ,Integer page, Integer size);
ResponseDto<StoneScoreItemVo> itemDetails(String itemId);
}
......@@ -158,6 +158,7 @@ public class ItemServiceImpl implements IItemService {
if (count <= 0) {
return "创建失败";
}
redisUtils.delList(param.getSimpleType().toString());
return "创建成功";
}
......@@ -191,6 +192,7 @@ public class ItemServiceImpl implements IItemService {
if (count <= 0) {
return "修改失败";
}
redisUtils.delList(param.getSimpleType().toString());
return "修改成功";
}
......
......@@ -102,4 +102,16 @@ public class StoneRedisUtils {
}
}
/**
* 删除 积分商品列表缓存
*
* @param simpleType
*/
public void delList(String simpleType) {
String redisKey = StoneConstant.ITEM_LIST;
String redisSimpleKey = StoneConstant.ITEM_LIST_SIMPLE.concat(simpleType);
redisDataSourceUtil.getRedisStoneUtil().del(redisKey);
redisDataSourceUtil.getRedisStoneUtil().del(redisSimpleKey);
}
}
......@@ -31,6 +31,13 @@ public class StoneItemController {
return ResponseDto.success(stoneScoreItemsService.itemList(page, 40));
}
@GetMapping("list/simpleType")
@ApiOperation("积分商品列表(simpleType)")
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<PageInfo<List<StoneItemListVo>>> itemListSimpleType(@RequestParam("page") @Valid Integer page, @RequestParam("simpleType") @Valid Integer simpleType) {
return ResponseDto.success(stoneScoreItemsService.itemListSimpleType(simpleType, page, 40));
}
@GetMapping("details")
@ApiOperation("积分商品详情")
@ApiResponse(code = 200, message = "接口返回对象参数")
......
......@@ -46,15 +46,57 @@ public class StoneScoreItemsServiceImpl implements IStoneScoreItemsService {
page = 1;
}
List<StoneScoreItems> voList;
HashMap<String, Object> info = mongoUtils.itemListPage(page, size);
try {
voList = (List<StoneScoreItems>) info.get("data");
} catch (Exception e) {
voList = new ArrayList();
e.printStackTrace();
long count;
if (page == 1) {
voList = redisUtils.getList();
count = voList.size();
} else {
HashMap<String, Object> info = mongoUtils.itemListPage(page, size, null);
try {
voList = (List<StoneScoreItems>) info.get("data");
} catch (Exception e) {
voList = new ArrayList();
e.printStackTrace();
}
count = 40 + (long) info.get("total");
}
List<StoneItemListVo> returnVoList = ObjectUtils.getStoneItemListVoArrayList();
for (int i = 0; i < voList.size(); i++) {
StoneScoreItems vo = voList.get(i);
StoneItemListVo returnVo = StoneItemListVo.getNew().copy(vo);
returnVoList.add(returnVo);
}
long count = (long) info.get("total");
mPageInfo = new PageInfo(returnVoList);
mPageInfo.setTotal(count);
log.info(UserPathDto.setData("积分商品列表", "", voList));
return mPageInfo;
}
@Override
public PageInfo<List<StoneItemListVo>> itemListSimpleType(Integer simpleType, Integer page, Integer size) {
PageInfo<List<StoneItemListVo>> mPageInfo;
size = 40;
if (page == null || page == 1 || page == 0) {
page = 1;
}
List<StoneScoreItems> voList;
long count;
if (page == 1) {
voList = redisUtils.getListSimple(simpleType.toString());
count = voList.size();
} else {
HashMap<String, Object> info = mongoUtils.itemListPage(page, size, simpleType.toString());
try {
voList = (List<StoneScoreItems>) info.get("data");
} catch (Exception e) {
voList = new ArrayList();
e.printStackTrace();
}
count = 40 + (long) info.get("total");
}
List<StoneItemListVo> returnVoList = ObjectUtils.getStoneItemListVoArrayList();
for (int i = 0; i < voList.size(); i++) {
......@@ -99,7 +141,7 @@ public class StoneScoreItemsServiceImpl implements IStoneScoreItemsService {
} else {
limitStatus = 1;
}
StoneScoreItemVo vo = StoneScoreItemVo.getNew().copy(data,scoreStatus,limitStatus);
StoneScoreItemVo vo = StoneScoreItemVo.getNew().copy(data, scoreStatus, limitStatus);
return ResponseDto.success(vo);
}
}
......@@ -46,13 +46,17 @@ public class StoneMongoUtils {
*
* @return
*/
public HashMap<String, Object> itemListPage(int page, int size) {
LocalDateTime now = LocalDateTime.now();
public HashMap<String, Object> itemListPage(int page, int size, String simpleType) {
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(new Criteria().orOperator(Criteria.where("status").is(1),Criteria.where("status").is(2).and("startTime").lte(now).and("endTime").gte(now)));
Criteria criteria = new Criteria().orOperator(Criteria.where("status").is(1), Criteria.where("status").is(2).and("startTime").lte(now).and("endTime").gte(now));
if (simpleType != null) {
criteria.and("simpleType").is(simpleType);
}
Query query = Query.query(criteria);
// 查询总数
long count = mongoTemplate.count(query, StoneScoreItems.class, StoneScoreItems.class.getSimpleName());
query.with(pageable);
......@@ -80,7 +84,7 @@ public class StoneMongoUtils {
*/
public StoneUserVo userGet(String uid) {
Query query = Query.query(Criteria.where("uid").is(uid));
StoneUserVo vo = mongoTemplate.findOne(query, StoneUserVo.class,StoneUserVo.class.getSimpleName());
StoneUserVo vo = mongoTemplate.findOne(query, StoneUserVo.class, StoneUserVo.class.getSimpleName());
return vo;
}
......@@ -109,13 +113,14 @@ public class StoneMongoUtils {
/**
* 获取 用户积分日志 列表
*
* @param uid
* @param page
* @param size
* @return
*/
public HashMap<String, Object> logList(String uid,int page, int size) {
LocalDateTime now = LocalDateTime.now();
public HashMap<String, Object> logList(String uid, 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"));
......@@ -143,13 +148,14 @@ public class StoneMongoUtils {
/**
* 获取 用户订单 列表
*
* @param uid
* @param page
* @param size
* @return
*/
public HashMap<String, Object> orderList(String uid,int page, int size) {
LocalDateTime now = LocalDateTime.now();
public HashMap<String, Object> orderList(String uid, 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"));
......
......@@ -9,6 +9,7 @@ import com.liquidnet.service.stone.vo.StoneUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
......@@ -19,6 +20,39 @@ public class StoneRedisUtils {
@Autowired
private StoneMongoUtils mongoUtils;
public List<StoneScoreItems> getList() {
try {
String redisKey = StoneConstant.ITEM_LIST;
Object obj = redisUtil.get(redisKey);
if (obj == null) {
List<StoneScoreItems> list = (List<StoneScoreItems>) mongoUtils.itemListPage(1, 40, null).get("data");
redisUtil.set(redisKey, list);
return list;
} else {
return (List<StoneScoreItems>) obj;
}
}catch (Exception e){
return new ArrayList();
}
}
public List<StoneScoreItems> getListSimple(String simpleType) {
try {
String redisKey = StoneConstant.ITEM_LIST_SIMPLE.concat(simpleType);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
List<StoneScoreItems> list = (List<StoneScoreItems>) mongoUtils.itemListPage(1, 40, simpleType).get("data");
redisUtil.set(redisKey, list);
return list;
} else {
return (List<StoneScoreItems>) obj;
}
}catch (Exception e){
return new ArrayList();
}
}
/**
* 获取 积分物品 剩余库存
*
......@@ -202,7 +236,7 @@ public class StoneRedisUtils {
Object obj = redisUtil.get(redisKey);
if (obj == null) {
List<StoneScoreLogs> getLogsList = (List<StoneScoreLogs>) mongoUtils.logList(uid, 1, 40).get("data");
redisUtil.set(redisKey,getLogsList);
redisUtil.set(redisKey, getLogsList);
return getLogsList;
} else {
return (List<StoneScoreLogs>) obj;
......@@ -314,12 +348,12 @@ public class StoneRedisUtils {
}
public boolean lockUid(String uid){
public boolean lockUid(String uid) {
String redisKey = StoneConstant.LOCK.concat(uid);
return redisUtil.lock(uid,1,1);
return redisUtil.lock(uid, 1, 1);
}
public void unLockUid(String uid){
public void unLockUid(String uid) {
String redisKey = StoneConstant.LOCK.concat(uid);
redisUtil.uLock(redisKey);
}
......
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