记得上下班打卡 | git大法好,push需谨慎

Commit 66c948e4 authored by zhengfuxin's avatar zhengfuxin

精选商品,后台管理

parent 994ea8bc
......@@ -101,7 +101,7 @@ public class GoblinFrontSelectGoodsController extends BaseController {
* @Description:精选商品保存
* @date 2022/1/4 下午2:49
*/
@PostMapping("create")
/*@PostMapping("create")
@ApiOperation(value = "精选商品保存")
@ResponseBody
public AjaxResult create(@RequestBody GoblinFrontSelectGoodsParam goblinFrontSelectGoodsParam) {
......@@ -115,7 +115,7 @@ public class GoblinFrontSelectGoodsController extends BaseController {
return error("操作失败");
}
}
*/
/**
* @author zhangfuxin
* @Description:精选商品修改
......
package com.liquidnet.client.admin.zhengzai.goblin.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.client.admin.zhengzai.goblin.service.IGoblinFrontSelectGoodsService;
import com.liquidnet.common.cache.redis.util.RedisGoblinUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.entity.GoblinFrontSelectGoods;
......@@ -15,7 +13,6 @@ import com.liquidnet.service.goblin.entity.GoblinGoods;
import com.liquidnet.service.goblin.mapper.GoblinFrontSelectGoodsMapper;
import com.liquidnet.service.goblin.mapper.GoblinGoodsMapper;
import com.liquidnet.service.goblin.param.GoblinFrontSelectGoodsParam;
import com.mongodb.BasicDBObject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
......@@ -76,26 +73,64 @@ public class GoblinFrontSelectGoodsServiceImpl extends ServiceImpl<GoblinFrontSe
}
public boolean update(GoblinFrontSelectGoods goblinFrontSelectGoods){
if(goblinFrontSelectGoods.getMid()>0){
//清空精选商品
goblinFrontSelectGoodsMapper.deleteAll();
//重新创建
String spuIds=goblinFrontSelectGoods.getSpuId();
if(StringUtil.isNotBlank(spuIds)){
String[] spuIdss=spuIds.split(",");
int index=0;
for(String spuId:spuIdss){
index++;
GoblinFrontSelectGoods goblinFrontSelectGoods1=new GoblinFrontSelectGoods();
goblinFrontSelectGoods1.setIndexs(index);
goblinFrontSelectGoods1.setUpdateTime(LocalDateTime.now());
goblinFrontSelectGoods1.setDelTag(0);
goblinFrontSelectGoods1.setCreateTime(LocalDateTime.now());
goblinFrontSelectGoods1.setSelectGoodsId(IDGenerator.nextSnowId());
goblinFrontSelectGoods1.setSpuId(spuId);
goblinFrontSelectGoods1.setOrderType(goblinFrontSelectGoods.getOrderType());
goblinFrontSelectGoodsMapper.insert(goblinFrontSelectGoods1);
}
}
/* if(goblinFrontSelectGoods.getMid()>0){
goblinFrontSelectGoods.setUpdateTime(LocalDateTime.now());
goblinFrontSelectGoodsMapper.updateById(goblinFrontSelectGoods);
}else{
this.create(goblinFrontSelectGoods);
}
}*/
return true;
}
public List getList(){
LambdaQueryWrapper<GoblinFrontSelectGoods> queryWrapper = Wrappers.lambdaQuery(GoblinFrontSelectGoods.class);
queryWrapper.eq(GoblinFrontSelectGoods::getDelTag,0);
List<GoblinFrontSelectGoods> list= goblinFrontSelectGoodsMapper.selectList(queryWrapper);
List<GoblinGoods> goblinGoodsList =new ArrayList<>();
List<GoblinFrontSelectGoodsParam> goodsP =new ArrayList<>();
queryWrapper.orderByAsc(GoblinFrontSelectGoods::getIndexs);
List<GoblinFrontSelectGoods> list= goblinFrontSelectGoodsMapper.selectList(queryWrapper);
String spuIds="";
for(GoblinFrontSelectGoods goblinFrontSelectGoods:list){
String spuids=goblinFrontSelectGoods.getSpuId();
if(StringUtil.isNotBlank(spuids)){
String[] spuIds=spuids.split(",");
for(String id:spuIds){
if(StringUtil.isBlank(spuIds)){
spuIds=goblinFrontSelectGoods.getSpuId();
}else{
spuIds=spuIds+","+goblinFrontSelectGoods.getSpuId();
}
}
if(list.size()>0){
GoblinFrontSelectGoods p=list.get(0);
GoblinFrontSelectGoods a=new GoblinFrontSelectGoods();
a.setOrderType(p.getOrderType());
a.setSelectGoodsId(spuIds);
a.setCreateTime(p.getCreateTime());
a.setDelTag(p.getDelTag());
a.setUpdateTime(p.getUpdateTime());
a.setSpuId(spuIds);
a.setSelectGoodsId("1");
a.setMid(1l);
List<GoblinGoods> goblinGoodsList =new ArrayList<>();
List<GoblinFrontSelectGoodsParam> goodsP =new ArrayList<>();
if(StringUtil.isNotBlank(spuIds)){
String[] dd=spuIds.split(",");
for(String id:dd){
LambdaQueryWrapper<GoblinGoods> queryWrappers = Wrappers.lambdaQuery(GoblinGoods.class);
queryWrappers.ne(GoblinGoods::getDelFlg,"1");
queryWrappers.eq(GoblinGoods::getSpuId,id);
......@@ -104,35 +139,29 @@ public class GoblinFrontSelectGoodsServiceImpl extends ServiceImpl<GoblinFrontSe
goblinGoodsList.add(goodsList.get(0));
}
}
GoblinFrontSelectGoodsParam goblinFrontSelectGoodsParam=new GoblinFrontSelectGoodsParam();
BeanUtils.copyProperties(a,goblinFrontSelectGoodsParam);
goblinFrontSelectGoodsParam.setGoblinGoodsList(goblinGoodsList);
goodsP.add(goblinFrontSelectGoodsParam);
return goodsP;
}
GoblinFrontSelectGoodsParam goblinFrontSelectGoodsParam=new GoblinFrontSelectGoodsParam();
BeanUtils.copyProperties(goblinFrontSelectGoods,goblinFrontSelectGoodsParam);
goblinFrontSelectGoodsParam.setGoblinGoodsList(goblinGoodsList);
goodsP.add(goblinFrontSelectGoodsParam);
}else{
return null;
}
return goodsP;
return null;
}
public boolean online(){
//查询
LambdaQueryWrapper<GoblinFrontSelectGoods> queryWrapper = Wrappers.lambdaQuery(GoblinFrontSelectGoods.class);
queryWrapper.eq(GoblinFrontSelectGoods::getDelTag,0);
queryWrapper.orderByAsc(GoblinFrontSelectGoods::getIndexs);
List<GoblinFrontSelectGoods> list=goblinFrontSelectGoodsMapper.selectList(queryWrapper);
//删除 mogndob
Query query = Query.query(Criteria.where("delTag").is("0"));
mongoTemplate.findAllAndRemove(query, GoblinFrontSelectGoods.class);
if(list.size()>0){
//放入mongodb
GoblinFrontSelectGoods goblinFrontSelectGoods= list.get(0);
GoblinFrontSelectGoods goblinFrontSelectGoods1= mongoTemplate.findOne(Query.query(Criteria.where("selectGoodsId").is(goblinFrontSelectGoods.getSelectGoodsId())), GoblinFrontSelectGoods.class, GoblinFrontSelectGoods.class.getSimpleName());
if(null==goblinFrontSelectGoods1){
for(GoblinFrontSelectGoods goblinFrontSelectGoods:list){
mongoTemplate.save(goblinFrontSelectGoods,GoblinFrontSelectGoods.class.getSimpleName());
}else{
BasicDBObject orderObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(goblinFrontSelectGoods)));
mongoTemplate.getCollection(GoblinFrontSelectGoods.class.getSimpleName()).updateOne(
Query.query(Criteria.where("selectGoodsId").is(goblinFrontSelectGoods.getSelectGoodsId())).getQueryObject(),
orderObject
);
}
redisGoblinUtil.set(GoblinRedisConst.SELECT_GOODS,list);
}
......
......@@ -41,6 +41,10 @@ public class GoblinFrontSelectGoods implements Serializable {
*/
private Integer delTag;
/*顺序
*/
private Integer indexs;
/**
* 创建时间
*/
......
......@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 精选商品
* 精选商品
Mapper 接口
* </p>
*
......@@ -13,5 +13,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @since 2022-01-04
*/
public interface GoblinFrontSelectGoodsMapper extends BaseMapper<GoblinFrontSelectGoods> {
public void deleteAll();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.liquidnet.service.goblin.mapper.GoblinFrontSelectGoodsMapper">
<delete id="deleteAll">
delete from goblin_front_select_goods
</delete>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment