use of cn.e3mall.manager.pojo.TbItemDesc in project e3mall by colg-cloud.
the class TbItemController method showItemInfo.
/**
* 根据商品id获取商品详情并返回页面
*/
@GetMapping("/{itemId}")
public String showItemInfo(@PathVariable Long itemId, Model model) {
// 调用服务取商品基本信息
TbItem tbItem = tbItemService.getTbItemById(itemId);
// 把TbItem转换成Item对象
// BeanUtils.copyProperties(tbItem, tbItemDto);// 性能较慢
TbItemDto tbItemDto = new TbItemDto(tbItem);
// 取商品描述信息
TbItemDesc tbItemDesc = tbItemDescService.findById(itemId);
// 把信息传递给页面
model.addAttribute("item", tbItemDto);
model.addAttribute("itemDesc", tbItemDesc);
// 返回逻辑视图
return "item";
}
use of cn.e3mall.manager.pojo.TbItemDesc in project e3mall by colg-cloud.
the class TbItemServiceImpl method addItem.
@Override
public E3Result addItem(TbItem tbItem, String desc) {
// 生成商品id,内部类使用局部变量,定义为final
final long itemId = IDUtils.genItemId();
// 补全tbItem的属性
// 商品状态,1-正常,2-下架,3-删除
tbItem.setId(itemId);
tbItem.setStatus((byte) 1);
tbItem.setCreated(new Date());
tbItem.setUpdated(new Date());
// 向商品表插入数据
tbItemMapper.insert(tbItem);
// 创建一个商品描述表对应的pojo对象
TbItemDesc tbItemDesc = new TbItemDesc();
// 补全属性
tbItemDesc.setItemId(itemId);
tbItemDesc.setItemDesc(desc);
tbItemDesc.setCreated(new Date());
tbItemDesc.setUpdated(new Date());
// 向商品描述表插入数据
tbItemDescMapper.insert(tbItemDesc);
// 发布 "商品添加" 消息
jmsTemplate.send(topicDestination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage textMessage = session.createTextMessage(itemId + "");
return textMessage;
}
});
// 返回成功
return E3Result.ok();
}
use of cn.e3mall.manager.pojo.TbItemDesc in project e3mall by colg-cloud.
the class TbItemServiceImpl method updateItem.
@Override
public E3Result updateItem(Long id, TbItem tbItem, String desc) {
TbItem db_tbItem = tbItemMapper.selectByPrimaryKey(id);
tbItem.setStatus(db_tbItem.getStatus());
tbItem.setCreated(db_tbItem.getCreated());
tbItem.setUpdated(new Date());
tbItemMapper.updateByPrimaryKey(tbItem);
TbItemDesc tbItemDesc = tbItemDescMapper.selectByPrimaryKey(tbItem.getId());
tbItemDesc.setItemDesc(desc);
tbItemDesc.setUpdated(new Date());
tbItemDescMapper.updateByPrimaryKey(tbItemDesc);
// 发布 "商品添加" 消息
jmsTemplate.send(topicDestination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage textMessage = session.createTextMessage(id + "");
return textMessage;
}
});
return E3Result.ok();
}
use of cn.e3mall.manager.pojo.TbItemDesc in project e3mall by colg-cloud.
the class HtmlGenListener method onMessage.
@Override
public void onMessage(Message message) {
try {
// 创建一个模版
// 从消息中取商品id
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
Long itemId = Long.parseLong(text);
// 等待事务提交
Thread.sleep(1000);
// 根据商品id查询商品信息,商品基本信息和商品描述
TbItem tbItem = tbItemService.getTbItemById(itemId);
TbItemDto tbItemDto = new TbItemDto(tbItem);
TbItemDesc tbItemDesc = tbItemDescService.findById(itemId);
// 创建一个数据集,把商品数据封装
Map<String, Object> map = new HashMap<>();
map.put("item", tbItemDto);
map.put("itemDesc", tbItemDesc);
// 加载模版对象
Configuration configuration = freeMarkerConfig.getConfiguration();
Template template = configuration.getTemplate("item.ftl");
// 创建一个输出流,指定输出的目录及文件名
Writer out = new FileWriter(HTML_GEN_PATH + itemId + ".html");
// 生成静态页面
template.process(map, out);
} catch (JMSException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of cn.e3mall.manager.pojo.TbItemDesc in project e3mall by colg-cloud.
the class TbItemDescServiceImpl method findById.
@Override
public TbItemDesc findById(Long itemId) {
// 查询缓存
String key = ITEM_INFO_PRE + ":" + itemId + ":DESC";
try {
String jsonString = jedisClient.get(key);
if (StringUtils.isNotBlank(jsonString)) {
return JSON.parseObject(jsonString, TbItemDesc.class);
}
} catch (Exception e) {
e.printStackTrace();
}
// 查询数据库
TbItemDesc tbItemDesc = tbItemDescMapper.selectByPrimaryKey(itemId);
if (tbItemDesc != null) {
try {
// 添加缓存
jedisClient.set(key, JSON.toJSONString(tbItemDesc));
// 设置缓存过期时间
jedisClient.expire(key, ITEM_INFO_EXPIRE);
} catch (Exception e) {
e.printStackTrace();
}
}
return tbItemDesc;
}
Aggregations