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);
}
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;
}
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);
}
Aggregations