Search in sources :

Example 1 with TbItemDesc

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";
}
Also used : TbItemDto(cn.e3mal.item.vo.TbItemDto) TbItemDesc(cn.e3mall.manager.pojo.TbItemDesc) TbItem(cn.e3mall.manager.pojo.TbItem) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with TbItemDesc

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();
}
Also used : TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException) TbItemDesc(cn.e3mall.manager.pojo.TbItemDesc) Date(java.util.Date) MessageCreator(org.springframework.jms.core.MessageCreator) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 3 with TbItemDesc

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();
}
Also used : TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException) TbItemDesc(cn.e3mall.manager.pojo.TbItemDesc) TbItem(cn.e3mall.manager.pojo.TbItem) Date(java.util.Date) MessageCreator(org.springframework.jms.core.MessageCreator) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 4 with TbItemDesc

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();
    }
}
Also used : Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) FileWriter(java.io.FileWriter) JMSException(javax.jms.JMSException) IOException(java.io.IOException) Template(freemarker.template.Template) TbItemDto(cn.e3mal.item.vo.TbItemDto) TbItemDesc(cn.e3mall.manager.pojo.TbItemDesc) TextMessage(javax.jms.TextMessage) TbItem(cn.e3mall.manager.pojo.TbItem) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 5 with TbItemDesc

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;
}
Also used : TbItemDesc(cn.e3mall.manager.pojo.TbItemDesc)

Aggregations

TbItemDesc (cn.e3mall.manager.pojo.TbItemDesc)5 TbItem (cn.e3mall.manager.pojo.TbItem)3 JMSException (javax.jms.JMSException)3 TextMessage (javax.jms.TextMessage)3 TbItemDto (cn.e3mal.item.vo.TbItemDto)2 Date (java.util.Date)2 Message (javax.jms.Message)2 Session (javax.jms.Session)2 MessageCreator (org.springframework.jms.core.MessageCreator)2 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1