use of cn.exrick.manager.pojo.TbItem in project xmall by Exrick.
the class CartServiceImpl method addCart.
@Override
public int addCart(long userId, long itemId, int num) {
// hash: "key:用户id" field:"商品id" value:"商品信息"
Boolean hexists = jedisClient.hexists(CART_PRE + ":" + userId, itemId + "");
// 如果存在数量相加
if (hexists) {
String json = jedisClient.hget(CART_PRE + ":" + userId, itemId + "");
if (json != null) {
CartProduct cartProduct = new Gson().fromJson(json, CartProduct.class);
cartProduct.setProductNum(cartProduct.getProductNum() + num);
jedisClient.hset(CART_PRE + ":" + userId, itemId + "", new Gson().toJson(cartProduct));
} else {
return 0;
}
return 1;
}
// 如果不存在,根据商品id取商品信息
TbItem item = itemMapper.selectByPrimaryKey(itemId);
if (item == null) {
return 0;
}
CartProduct cartProduct = DtoUtil.TbItem2CartProduct(item);
cartProduct.setProductNum((long) num);
cartProduct.setChecked("1");
jedisClient.hset(CART_PRE + ":" + userId, itemId + "", new Gson().toJson(cartProduct));
return 1;
}
use of cn.exrick.manager.pojo.TbItem in project xmall by Exrick.
the class ItemServiceImpl method getItemSearchList.
@Override
public DataTablesResult getItemSearchList(int draw, int start, int length, int cid, String search, String minDate, String maxDate, String orderCol, String orderDir) {
DataTablesResult result = new DataTablesResult();
// 分页执行查询返回结果
PageHelper.startPage(start / length + 1, length);
List<TbItem> list = tbItemMapper.selectItemByMultiCondition(cid, "%" + search + "%", minDate, maxDate, orderCol, orderDir);
PageInfo<TbItem> pageInfo = new PageInfo<>(list);
result.setRecordsFiltered((int) pageInfo.getTotal());
result.setRecordsTotal(getAllItemCount().getRecordsTotal());
result.setDraw(draw);
result.setData(list);
return result;
}
use of cn.exrick.manager.pojo.TbItem in project xmall by Exrick.
the class ItemServiceImpl method updateItem.
@Override
public TbItem updateItem(Long id, ItemDto itemDto) {
TbItem oldTbItem = getNormalItemById(id);
TbItem tbItem = DtoUtil.ItemDto2TbItem(itemDto);
if (tbItem.getImage().isEmpty()) {
tbItem.setImage(oldTbItem.getImage());
}
tbItem.setId(id);
tbItem.setStatus(oldTbItem.getStatus());
tbItem.setCreated(oldTbItem.getCreated());
tbItem.setUpdated(new Date());
if (tbItemMapper.updateByPrimaryKey(tbItem) != 1) {
throw new XmallException("更新商品失败");
}
TbItemDesc tbItemDesc = new TbItemDesc();
tbItemDesc.setItemId(id);
tbItemDesc.setItemDesc(itemDto.getDetail());
tbItemDesc.setUpdated(new Date());
tbItemDesc.setCreated(oldTbItem.getCreated());
if (tbItemDescMapper.updateByPrimaryKey(tbItemDesc) != 1) {
throw new XmallException("更新商品详情失败");
}
// 同步缓存
deleteProductDetRedis(id);
// 发送消息同步索引库
sendRefreshESMessage("add", id);
return getNormalItemById(id);
}
use of cn.exrick.manager.pojo.TbItem in project xmall by Exrick.
the class ItemServiceImpl method getItemById.
@Override
public ItemDto getItemById(Long id) {
ItemDto itemDto = new ItemDto();
TbItem tbItem = tbItemMapper.selectByPrimaryKey(id);
itemDto = DtoUtil.TbItem2ItemDto(tbItem);
TbItemCat tbItemCat = tbItemCatMapper.selectByPrimaryKey(itemDto.getCid());
itemDto.setCname(tbItemCat.getName());
TbItemDesc tbItemDesc = tbItemDescMapper.selectByPrimaryKey(id);
itemDto.setDetail(tbItemDesc.getItemDesc());
return itemDto;
}
use of cn.exrick.manager.pojo.TbItem in project xmall by Exrick.
the class ItemServiceImpl method alertItemState.
@Override
public TbItem alertItemState(Long id, Integer state) {
TbItem tbMember = getNormalItemById(id);
tbMember.setStatus(state.byteValue());
tbMember.setUpdated(new Date());
if (tbItemMapper.updateByPrimaryKey(tbMember) != 1) {
throw new XmallException("修改商品状态失败");
}
return getNormalItemById(id);
}
Aggregations