Search in sources :

Example 1 with Item

use of cn.e3mall.common.base.entity.Item in project e3mall by colg-cloud.

the class ItemServiceImpl method updateItem.

@Override
public E3Result updateItem(Long itemId, Item item, String desc, Long itemParamId, String paramData) {
    Date now = new Date();
    // 修改商品
    Item dbItem = itemMapper.selectByPrimaryKey(itemId);
    item.setStatus(dbItem.getStatus()).setCreated(dbItem.getCreated()).setUpdated(now);
    itemMapper.updateByPrimaryKeySelective(item);
    // 修改商品详情
    ItemDesc itemDesc = itemDescMapper.selectByPrimaryKey(itemId);
    if (itemDesc != null) {
        itemDesc.setItemDesc(desc).setUpdated(now);
        itemDescMapper.updateByPrimaryKeySelective(itemDesc);
    } else {
        itemDesc = new ItemDesc(itemId, now, now, desc);
        itemDescMapper.insertSelective(itemDesc);
    }
    // 修改商品规格参数
    ItemParamItem itemParamItem = itemParamItemMapper.selectByPrimaryKey(itemParamId);
    if (itemParamItem != null) {
        itemParamItem.setParamData(paramData).setUpdated(now);
        itemParamItemMapper.updateByPrimaryKeySelective(itemParamItem);
    } else {
        itemParamItem = new ItemParamItem(itemId, now, now, paramData);
        itemParamItemMapper.insertSelective(itemParamItem);
    }
    // 发送 activemq 消息; 同步solr索引库, 生成静态页面
    sendMsg(destinationChangeItem, itemId);
    // 缓存同步, 删除缓存中对应的数据; 下次查询时会先查询数据库再添加到缓存
    jedisClient.del(itemInfoPre + ":" + itemId + ":base");
    jedisClient.del(itemInfoPre + ":" + itemId + ":desc");
    return E3Result.ok(item);
}
Also used : Item(cn.e3mall.common.base.entity.Item) ItemParamItem(cn.e3mall.common.base.entity.ItemParamItem) ItemParamItem(cn.e3mall.common.base.entity.ItemParamItem) ItemDesc(cn.e3mall.common.base.entity.ItemDesc) Date(java.util.Date)

Example 2 with Item

use of cn.e3mall.common.base.entity.Item in project e3mall by colg-cloud.

the class ItemController method showItemInfo.

@RequestMapping("/{itemId}")
public String showItemInfo(@PathVariable Long itemId, Model model) {
    // 获取商品信息
    Item item = itemService.getTbItemById(itemId);
    // 获取商品描述
    ItemDesc itemDesc = itemDescService.findById(itemId);
    // 获取商品规格参数
    // 传递到页面
    model.addAttribute("item", item);
    model.addAttribute("itemDesc", itemDesc);
    return "index";
}
Also used : Item(cn.e3mall.common.base.entity.Item) ItemDesc(cn.e3mall.common.base.entity.ItemDesc) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Item

use of cn.e3mall.common.base.entity.Item in project e3mall by colg-cloud.

the class HtmlGenMessageListener method onMessage.

@Override
public void onMessage(Message message) {
    // 休眠一秒, 防止事务未提交
    ThreadUtil.sleep(1000);
    try {
        String text = ((TextMessage) message).getText();
        log.info("activemq 接收消息: {}; 生成html静态页面", text);
        long itemId = Long.parseLong(text);
        // 获取商品信息
        Item item = itemService.getTbItemById(itemId);
        // 获取商品描述
        ItemDesc itemDesc = itemDescService.findById(itemId);
        // 封装数据集
        Dict data = Dict.create().set("item", item).set("itemDesc", itemDesc);
        // 指定文件输出路径
        String filepath = htmlGenDir + itemId + ".html";
        Writer out = new FileWriter(filepath);
        // 加载模版文件, 生成静态文件
        freeMarkerConfig.getConfiguration().getTemplate("index.ftl").process(data, out);
        log.info("输出路径: {}", filepath);
    } catch (JMSException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TemplateException e) {
        e.printStackTrace();
    }
}
Also used : Item(cn.e3mall.common.base.entity.Item) TemplateException(freemarker.template.TemplateException) ItemDesc(cn.e3mall.common.base.entity.ItemDesc) Dict(cn.hutool.core.lang.Dict) FileWriter(java.io.FileWriter) JMSException(javax.jms.JMSException) IOException(java.io.IOException) TextMessage(javax.jms.TextMessage) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 4 with Item

use of cn.e3mall.common.base.entity.Item in project e3mall by colg-cloud.

the class ItemServiceImpl method getTbItemById.

@Override
public Item getTbItemById(Long id) {
    /*
         * colg  [使用前缀对redis中的key进行分类]
         *  1. 第一层: 表名
         *  2. 第二层: 主键
         *  3. 第三层: 业务
         */
    // 查询缓存
    String key = itemInfoPre + ":" + id + ":base";
    String result = jedisClient.get(key);
    if (StrUtil.isNotEmpty(result)) {
        log.info("从 redis 获取的商品信息: {}", result);
        return JSON.parseObject(result, Item.class);
    }
    // 查询数据库
    Item item = itemMapper.selectByPrimaryKey(id);
    // 保存到缓存
    jedisClient.set(key, JSON.toJSONString(item));
    jedisClient.expire(key, expireSeconds);
    return item;
}
Also used : Item(cn.e3mall.common.base.entity.Item) ItemParamItem(cn.e3mall.common.base.entity.ItemParamItem)

Example 5 with Item

use of cn.e3mall.common.base.entity.Item in project e3mall by colg-cloud.

the class PageHelperTest method testPageHelper.

@SuppressWarnings("resource")
@Test
public void testPageHelper() {
    ItemMapper itemMapper = applicationContext.getBean(ItemMapper.class);
    // 执行sql语句之前设置分页信息, 使用PageHelper的startPage方法
    PageHelper.startPage(1, 10, "updated DESC");
    // 执行查询
    List<Item> list = itemMapper.selectAll();
    // 取分页信息
    PageInfo<Item> pageInfo = new PageInfo<>(list);
    log.info("总记录数: {}", pageInfo.getTotal());
    log.info("总页数: {}", pageInfo.getPages());
    log.info("每页的数量: {}", pageInfo.getPageSize());
    log.info("当前页: {}", pageInfo.getPageNum());
    log.info("当前页的数量: {}", pageInfo.getSize());
    log.info("------------------------------------------------------------------------------------------");
    Page<?> page = (Page<?>) list;
    log.info("总记录数: {}", page.getTotal());
    log.info("总页数: {}", page.getPages());
    log.info("每页的数量: {}", page.getPageSize());
    log.info("当前页: {}", page.getPageNum());
    log.info("当前页的数量: {}", page.size());
}
Also used : Item(cn.e3mall.common.base.entity.Item) PageInfo(com.github.pagehelper.PageInfo) ItemMapper(cn.e3mall.manager.dao.ItemMapper) Page(com.github.pagehelper.Page) BaseTest(cn.e3mall.manager.service.BaseTest) Test(org.junit.Test)

Aggregations

Item (cn.e3mall.common.base.entity.Item)5 ItemDesc (cn.e3mall.common.base.entity.ItemDesc)3 ItemParamItem (cn.e3mall.common.base.entity.ItemParamItem)2 ItemMapper (cn.e3mall.manager.dao.ItemMapper)1 BaseTest (cn.e3mall.manager.service.BaseTest)1 Dict (cn.hutool.core.lang.Dict)1 Page (com.github.pagehelper.Page)1 PageInfo (com.github.pagehelper.PageInfo)1 TemplateException (freemarker.template.TemplateException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 Date (java.util.Date)1 JMSException (javax.jms.JMSException)1 TextMessage (javax.jms.TextMessage)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1