Search in sources :

Example 1 with TbItem

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;
}
Also used : CartProduct(cn.exrick.manager.dto.front.CartProduct) Gson(com.google.gson.Gson) TbItem(cn.exrick.manager.pojo.TbItem)

Example 2 with TbItem

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;
}
Also used : PageInfo(com.github.pagehelper.PageInfo) DataTablesResult(cn.exrick.common.pojo.DataTablesResult) TbItem(cn.exrick.manager.pojo.TbItem)

Example 3 with TbItem

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);
}
Also used : XmallException(cn.exrick.common.exception.XmallException) TbItemDesc(cn.exrick.manager.pojo.TbItemDesc) TbItem(cn.exrick.manager.pojo.TbItem) Date(java.util.Date)

Example 4 with TbItem

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;
}
Also used : ItemDto(cn.exrick.manager.dto.ItemDto) TbItemCat(cn.exrick.manager.pojo.TbItemCat) TbItemDesc(cn.exrick.manager.pojo.TbItemDesc) TbItem(cn.exrick.manager.pojo.TbItem)

Example 5 with TbItem

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);
}
Also used : XmallException(cn.exrick.common.exception.XmallException) TbItem(cn.exrick.manager.pojo.TbItem) Date(java.util.Date)

Aggregations

TbItem (cn.exrick.manager.pojo.TbItem)7 XmallException (cn.exrick.common.exception.XmallException)3 TbItemDesc (cn.exrick.manager.pojo.TbItemDesc)3 Date (java.util.Date)3 DataTablesResult (cn.exrick.common.pojo.DataTablesResult)2 PageInfo (com.github.pagehelper.PageInfo)2 ItemDto (cn.exrick.manager.dto.ItemDto)1 CartProduct (cn.exrick.manager.dto.front.CartProduct)1 TbItemCat (cn.exrick.manager.pojo.TbItemCat)1 Gson (com.google.gson.Gson)1