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

Commit 5352a07d authored by zhengfuxin's avatar zhengfuxin

banner 增删改查

parent 4eae69c5
......@@ -44,4 +44,40 @@ public class GoblinFrontBannerController extends BaseController {
}
}
@PostMapping("update")
@ApiOperation(value = "修改banner")
@ResponseBody
public AjaxResult update( @RequestBody GoblinFrontBanner goblinFrontBanner) {
logger.info("修改banner{}", JSON.toJSONString(goblinFrontBanner));
boolean result=goblinFrontBannerService.update(goblinFrontBanner);
if (result ) {
return success("操作成功");
} else {
return error("操作失败");
}
}
@PostMapping("delete")
@ApiOperation(value = "删除banner")
@ResponseBody
public AjaxResult delete( @RequestBody GoblinFrontBanner goblinFrontBanner) {
logger.info("删除banner{}", JSON.toJSONString(goblinFrontBanner));
boolean result=goblinFrontBannerService.delte(goblinFrontBanner.getMid());
if (result ) {
return success("操作成功");
} else {
return error("操作失败");
}
}
@PostMapping("getOne")
@ApiOperation(value = "查看详情")
@ResponseBody
public AjaxResult getOne( @RequestBody GoblinFrontBanner goblinFrontBanner) {
logger.info("修改banner{}", JSON.toJSONString(goblinFrontBanner));
GoblinFrontBanner goblinFrontBanner1=goblinFrontBannerService.getOne(goblinFrontBanner.getMid());
return AjaxResult.success(goblinFrontBanner1);
}
}
package com.liquidnet.client.admin.zhengzai.goblin.service.imp;
import com.alibaba.fastjson.JSON;
import com.liquidnet.client.admin.zhengzai.goblin.service.IGoblinFrontBannerService;
import com.liquidnet.client.admin.zhengzai.kylin.utils.DataUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -8,14 +9,22 @@ import com.liquidnet.common.cache.redis.util.RedisGoblinUtil;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.entity.GoblinFrontBanner;
import com.liquidnet.service.goblin.mapper.GoblinFrontBannerMapper;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo;
import com.mongodb.BasicDBObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.VariableOperators;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.stream.Collectors;
/**
* <p>
......@@ -30,8 +39,6 @@ public class GoblinFrontBannerServiceImpl extends ServiceImpl<GoblinFrontBannerM
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private DataUtils dataUtils;
@Autowired
GoblinFrontBannerMapper goblinFrontBannerMapper;
@Autowired
private RedisDataSourceUtil redisDataSourceUtil;
......@@ -58,5 +65,64 @@ public class GoblinFrontBannerServiceImpl extends ServiceImpl<GoblinFrontBannerM
}
return true;
}
/***
* @author zhangfuxin
* @Description: 修改
* @date 2021/12/27 下午4:03
*/
public boolean update(GoblinFrontBanner goblinFrontBanner){
//数据库修改
goblinFrontBannerMapper.updateById(goblinFrontBanner);
//mongodb修改
BasicDBObject orderObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(goblinFrontBanner)));
mongoTemplate.getCollection(GoblinFrontBanner.class.getSimpleName()).updateOne(
Query.query(Criteria.where("bannerId").is(goblinFrontBanner.getBannerId())).getQueryObject(),
orderObject
);
//redis 修改
if(redisDataSourceUtil.getRedisGoblinUtil().hasKey(GoblinRedisConst.FRONT_BANNER+"0")){
ArrayList<GoblinFrontBanner> list = (ArrayList<GoblinFrontBanner>) redisDataSourceUtil.getRedisGoblinUtil().get(GoblinRedisConst.FRONT_BANNER+0);
list= (ArrayList<GoblinFrontBanner>) list.stream().map(goblinFrontBanner1->{
if(goblinFrontBanner1.getBannerId().equals(goblinFrontBanner.getBannerId())){
return goblinFrontBanner;
}
return goblinFrontBanner1;
}).collect(Collectors.toList());
redisDataSourceUtil.getRedisGoblinUtil().set(GoblinRedisConst.FRONT_BANNER+"0",list);
}
return true;
}
/**
* @author zhangfuxin
* @Description:查看详情
* @date 2021/12/27 下午4:34
*/
public GoblinFrontBanner getOne(Long id){
return goblinFrontBannerMapper.selectById(id);
}
/**
* @author zhangfuxin
* @Description: 删除 banner
* @date 2021/12/27 下午4:36
*/
public boolean delte(Long id){
//数据库
goblinFrontBannerMapper.deleteById(id);
//mongodb 删除
mongoTemplate.remove(Query.query(Criteria.where("mid").is(id)), GoblinFrontBanner.class, GoblinFrontBanner.class.getSimpleName());
//redis 删除
if(redisDataSourceUtil.getRedisGoblinUtil().hasKey(GoblinRedisConst.FRONT_BANNER+"0")){
ArrayList<GoblinFrontBanner> list = (ArrayList<GoblinFrontBanner>) redisDataSourceUtil.getRedisGoblinUtil().get(GoblinRedisConst.FRONT_BANNER+0);
list= (ArrayList<GoblinFrontBanner>) list.stream().map(goblinFrontBanner1->{
if(goblinFrontBanner1.getMid().equals(id)){
return null;
}
return goblinFrontBanner1;
}).collect(Collectors.toList());
redisDataSourceUtil.getRedisGoblinUtil().set(GoblinRedisConst.FRONT_BANNER+"0",list);
}
return true;
}
}
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