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