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

Commit 66c948e4 authored by zhengfuxin's avatar zhengfuxin

精选商品,后台管理

parent 994ea8bc
...@@ -101,7 +101,7 @@ public class GoblinFrontSelectGoodsController extends BaseController { ...@@ -101,7 +101,7 @@ public class GoblinFrontSelectGoodsController extends BaseController {
* @Description:精选商品保存 * @Description:精选商品保存
* @date 2022/1/4 下午2:49 * @date 2022/1/4 下午2:49
*/ */
@PostMapping("create") /*@PostMapping("create")
@ApiOperation(value = "精选商品保存") @ApiOperation(value = "精选商品保存")
@ResponseBody @ResponseBody
public AjaxResult create(@RequestBody GoblinFrontSelectGoodsParam goblinFrontSelectGoodsParam) { public AjaxResult create(@RequestBody GoblinFrontSelectGoodsParam goblinFrontSelectGoodsParam) {
...@@ -115,7 +115,7 @@ public class GoblinFrontSelectGoodsController extends BaseController { ...@@ -115,7 +115,7 @@ public class GoblinFrontSelectGoodsController extends BaseController {
return error("操作失败"); return error("操作失败");
} }
} }
*/
/** /**
* @author zhangfuxin * @author zhangfuxin
* @Description:精选商品修改 * @Description:精选商品修改
......
package com.liquidnet.client.admin.zhengzai.goblin.service.impl; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.client.admin.zhengzai.goblin.service.IGoblinFrontSelectGoodsService; import com.liquidnet.client.admin.zhengzai.goblin.service.IGoblinFrontSelectGoodsService;
import com.liquidnet.common.cache.redis.util.RedisGoblinUtil; import com.liquidnet.common.cache.redis.util.RedisGoblinUtil;
import com.liquidnet.commons.lang.util.IDGenerator; import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil; import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.goblin.constant.GoblinRedisConst; import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.entity.GoblinFrontSelectGoods; import com.liquidnet.service.goblin.entity.GoblinFrontSelectGoods;
...@@ -15,7 +13,6 @@ import com.liquidnet.service.goblin.entity.GoblinGoods; ...@@ -15,7 +13,6 @@ import com.liquidnet.service.goblin.entity.GoblinGoods;
import com.liquidnet.service.goblin.mapper.GoblinFrontSelectGoodsMapper; import com.liquidnet.service.goblin.mapper.GoblinFrontSelectGoodsMapper;
import com.liquidnet.service.goblin.mapper.GoblinGoodsMapper; import com.liquidnet.service.goblin.mapper.GoblinGoodsMapper;
import com.liquidnet.service.goblin.param.GoblinFrontSelectGoodsParam; import com.liquidnet.service.goblin.param.GoblinFrontSelectGoodsParam;
import com.mongodb.BasicDBObject;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
...@@ -76,26 +73,64 @@ public class GoblinFrontSelectGoodsServiceImpl extends ServiceImpl<GoblinFrontSe ...@@ -76,26 +73,64 @@ public class GoblinFrontSelectGoodsServiceImpl extends ServiceImpl<GoblinFrontSe
} }
public boolean update(GoblinFrontSelectGoods goblinFrontSelectGoods){ 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()); goblinFrontSelectGoods.setUpdateTime(LocalDateTime.now());
goblinFrontSelectGoodsMapper.updateById(goblinFrontSelectGoods); goblinFrontSelectGoodsMapper.updateById(goblinFrontSelectGoods);
}else{ }else{
this.create(goblinFrontSelectGoods); this.create(goblinFrontSelectGoods);
} }*/
return true; return true;
} }
public List getList(){ public List getList(){
LambdaQueryWrapper<GoblinFrontSelectGoods> queryWrapper = Wrappers.lambdaQuery(GoblinFrontSelectGoods.class); LambdaQueryWrapper<GoblinFrontSelectGoods> queryWrapper = Wrappers.lambdaQuery(GoblinFrontSelectGoods.class);
queryWrapper.eq(GoblinFrontSelectGoods::getDelTag,0); queryWrapper.eq(GoblinFrontSelectGoods::getDelTag,0);
List<GoblinFrontSelectGoods> list= goblinFrontSelectGoodsMapper.selectList(queryWrapper); queryWrapper.orderByAsc(GoblinFrontSelectGoods::getIndexs);
List<GoblinGoods> goblinGoodsList =new ArrayList<>(); List<GoblinFrontSelectGoods> list= goblinFrontSelectGoodsMapper.selectList(queryWrapper);
List<GoblinFrontSelectGoodsParam> goodsP =new ArrayList<>(); String spuIds="";
for(GoblinFrontSelectGoods goblinFrontSelectGoods:list){ for(GoblinFrontSelectGoods goblinFrontSelectGoods:list){
String spuids=goblinFrontSelectGoods.getSpuId(); if(StringUtil.isBlank(spuIds)){
if(StringUtil.isNotBlank(spuids)){ spuIds=goblinFrontSelectGoods.getSpuId();
String[] spuIds=spuids.split(","); }else{
for(String id:spuIds){ 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); LambdaQueryWrapper<GoblinGoods> queryWrappers = Wrappers.lambdaQuery(GoblinGoods.class);
queryWrappers.ne(GoblinGoods::getDelFlg,"1"); queryWrappers.ne(GoblinGoods::getDelFlg,"1");
queryWrappers.eq(GoblinGoods::getSpuId,id); queryWrappers.eq(GoblinGoods::getSpuId,id);
...@@ -104,35 +139,29 @@ public class GoblinFrontSelectGoodsServiceImpl extends ServiceImpl<GoblinFrontSe ...@@ -104,35 +139,29 @@ public class GoblinFrontSelectGoodsServiceImpl extends ServiceImpl<GoblinFrontSe
goblinGoodsList.add(goodsList.get(0)); 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(); }else{
BeanUtils.copyProperties(goblinFrontSelectGoods,goblinFrontSelectGoodsParam); return null;
goblinFrontSelectGoodsParam.setGoblinGoodsList(goblinGoodsList);
goodsP.add(goblinFrontSelectGoodsParam);
} }
return null;
return goodsP;
} }
public boolean online(){ public boolean online(){
//查询 //查询
LambdaQueryWrapper<GoblinFrontSelectGoods> queryWrapper = Wrappers.lambdaQuery(GoblinFrontSelectGoods.class); LambdaQueryWrapper<GoblinFrontSelectGoods> queryWrapper = Wrappers.lambdaQuery(GoblinFrontSelectGoods.class);
queryWrapper.eq(GoblinFrontSelectGoods::getDelTag,0); queryWrapper.eq(GoblinFrontSelectGoods::getDelTag,0);
queryWrapper.orderByAsc(GoblinFrontSelectGoods::getIndexs);
List<GoblinFrontSelectGoods> list=goblinFrontSelectGoodsMapper.selectList(queryWrapper); 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){ if(list.size()>0){
//放入mongodb for(GoblinFrontSelectGoods goblinFrontSelectGoods:list){
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){
mongoTemplate.save(goblinFrontSelectGoods,GoblinFrontSelectGoods.class.getSimpleName()); 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); redisGoblinUtil.set(GoblinRedisConst.SELECT_GOODS,list);
} }
......
...@@ -41,6 +41,10 @@ public class GoblinFrontSelectGoods implements Serializable { ...@@ -41,6 +41,10 @@ public class GoblinFrontSelectGoods implements Serializable {
*/ */
private Integer delTag; private Integer delTag;
/*顺序
*/
private Integer indexs;
/** /**
* 创建时间 * 创建时间
*/ */
......
...@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/** /**
* <p> * <p>
* 精选商品 * 精选商品
Mapper 接口 Mapper 接口
* </p> * </p>
* *
...@@ -13,5 +13,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -13,5 +13,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @since 2022-01-04 * @since 2022-01-04
*/ */
public interface GoblinFrontSelectGoodsMapper extends BaseMapper<GoblinFrontSelectGoods> { 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