Search in sources :

Example 1 with TbItemDesc

use of cn.exrick.manager.pojo.TbItemDesc 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);
    // 发送消息同步索引库
    try {
        sendRefreshESMessage("add", id);
    } catch (Exception e) {
        log.error("同步索引出错");
    }
    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) XmallException(cn.exrick.common.exception.XmallException)

Example 2 with TbItemDesc

use of cn.exrick.manager.pojo.TbItemDesc 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 3 with TbItemDesc

use of cn.exrick.manager.pojo.TbItemDesc 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("添加商品详情失败");
    }
    // 发送消息同步索引库
    try {
        sendRefreshESMessage("add", id);
    } catch (Exception e) {
        log.error("同步索引出错");
    }
    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) XmallException(cn.exrick.common.exception.XmallException)

Aggregations

TbItem (cn.exrick.manager.pojo.TbItem)3 TbItemDesc (cn.exrick.manager.pojo.TbItemDesc)3 XmallException (cn.exrick.common.exception.XmallException)2 Date (java.util.Date)2 ItemDto (cn.exrick.manager.dto.ItemDto)1 TbItemCat (cn.exrick.manager.pojo.TbItemCat)1