Search in sources :

Example 6 with TbItem

use of cn.exrick.manager.pojo.TbItem in project xmall by Exrick.

the class ItemServiceImpl method addItem.

@Override
public TbItem addItem(ItemDto itemDto) {
    long id = IDUtil.getRandomId();
    TbItem tbItem = DtoUtil.ItemDto2TbItem(itemDto);
    tbItem.setId(id);
    tbItem.setStatus((byte) 1);
    tbItem.setCreated(new Date());
    tbItem.setUpdated(new Date());
    if (tbItem.getImage().isEmpty()) {
        tbItem.setImage("http://ow2h3ee9w.bkt.clouddn.com/nopic.jpg");
    }
    if (tbItemMapper.insert(tbItem) != 1) {
        throw new XmallException("添加商品失败");
    }
    TbItemDesc tbItemDesc = new TbItemDesc();
    tbItemDesc.setItemId(id);
    tbItemDesc.setItemDesc(itemDto.getDetail());
    tbItemDesc.setCreated(new Date());
    tbItemDesc.setUpdated(new Date());
    if (tbItemDescMapper.insert(tbItemDesc) != 1) {
        throw new XmallException("添加商品详情失败");
    }
    // 发送消息同步索引库
    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 7 with TbItem

use of cn.exrick.manager.pojo.TbItem in project xmall by Exrick.

the class ItemServiceImpl method getItemList.

@Override
public DataTablesResult getItemList(int draw, int start, int length, int cid, String search, String orderCol, String orderDir) {
    DataTablesResult result = new DataTablesResult();
    // 分页执行查询返回结果
    PageHelper.startPage(start / length + 1, length);
    List<TbItem> list = tbItemMapper.selectItemByCondition(cid, "%" + search + "%", 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)

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