This commit is contained in:
wuchunlei
2024-11-26 15:14:44 +08:00
13 changed files with 256 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
package com.peanut.modules.common.controller;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.MainAdEntity;
import com.peanut.modules.common.service.MainAdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController("commonMainAdController")
@RequestMapping("common/mainAd")
public class MainAdController {
@Autowired
private MainAdService mainAdService;
@RequestMapping("/getMainAd")
public R getMainAd(@RequestBody Map<String,Integer> params){
int type = params.get("type");
List<MainAdEntity> adDetail = mainAdService.getAd(type);
return R.ok().put("list",adDetail);
}
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.common.entity.MainAdEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MainAdDao extends BaseMapper<MainAdEntity> {
}

View File

@@ -0,0 +1,37 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("main_ad")
public class MainAdEntity implements Serializable {
@TableId
private Integer id;
private Integer type;
private Integer appType;
private String icon;
private Integer relationId;
private Date createTime;
private Integer state;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private ShopProduct shopProduct;
}

View File

@@ -0,0 +1,11 @@
package com.peanut.modules.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.MainAdEntity;
import java.util.List;
public interface MainAdService extends IService<MainAdEntity> {
List<MainAdEntity> getAd(int type);
}

View File

@@ -0,0 +1,35 @@
package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.MainAdDao;
import com.peanut.modules.common.dao.ShopProductDao;
import com.peanut.modules.common.entity.MainAdEntity;
import com.peanut.modules.common.entity.ShopProduct;
import com.peanut.modules.common.service.MainAdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service("commonMainAdService")
public class MainAdServiceImpl extends ServiceImpl<MainAdDao, MainAdEntity> implements MainAdService {
@Autowired
private ShopProductDao shopProductDao;
@Override
public List<MainAdEntity> getAd(int type) {
LambdaQueryWrapper<MainAdEntity> mainAdEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
mainAdEntityLambdaQueryWrapper.eq(MainAdEntity::getAppType,type);
List<MainAdEntity> mainAdEntities = this.getBaseMapper().selectList(mainAdEntityLambdaQueryWrapper);
for (MainAdEntity m :mainAdEntities){
if(m.getType()==0){//如果为商品
ShopProduct shopProduct = shopProductDao.selectById(m.getRelationId());
m.setShopProduct(shopProduct);
}
}
return mainAdEntities;
}
}

View File

@@ -26,7 +26,8 @@ import java.util.Map;
@Slf4j
@RestController("masterCourse")
@RequestMapping("master/course")
public class CourseController {
public class
CourseController {
@Autowired
private CourseService courseService;

View File

@@ -0,0 +1,53 @@
package com.peanut.modules.master.controller;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.MainAdEntity;
import com.peanut.modules.master.service.MainAdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController("masterMainAdController")
@RequestMapping("master/mainAd")
public class MainAdController {
@Autowired
private MainAdService mainAdService;
@RequestMapping("/getMainAdList")
public R getMainAdList(){
List<MainAdEntity> mainAdList = mainAdService.getMainAdList();
return R.ok().put("list",mainAdList);
}
@RequestMapping("/getMainAdDetail")
public R getMainAdDetail(@RequestBody Map<String,Integer> map){
MainAdEntity mainAdDetail = mainAdService.getMainAdDetail(map.get("id"));
return R.ok().put("detail",mainAdDetail);
}
@RequestMapping("/addMainAd")
public R addMainAd(@RequestBody MainAdEntity mainAdEntity){
mainAdService.getBaseMapper().insert(mainAdEntity);
return R.ok();
}
@RequestMapping("/delMainAd")
public R delMainAd(@RequestBody Map<String,Integer> map){
mainAdService.getBaseMapper().deleteById(map.get("id"));
return R.ok();
}
@RequestMapping("/editMainAd")
public R editMainAd(@RequestBody MainAdEntity mainAdEntity){
mainAdService.getBaseMapper().updateById(mainAdEntity);
return R.ok().put("detail",mainAdEntity);
}
}

View File

@@ -210,4 +210,10 @@ public class ShopProductController {
return shopProductService.unbindProductAndCourse(map.get("productId"),map.get("catalogueId"));
}
@RequestMapping("/getProductForApp")
public R getProductForApp(@RequestBody Map<String,Object> map){
Page<ShopProduct> productForApp = shopProductService.getProductForApp(Integer.valueOf(map.get("type").toString()), Integer.valueOf(map.get("page").toString()), Integer.valueOf(map.get("limit").toString()),map.get("keywords").toString());
return R.ok().put("page",productForApp);
}
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.MainAdEntity;
import java.util.List;
public interface MainAdService extends IService<MainAdEntity> {
List<MainAdEntity> getMainAdList();
MainAdEntity getMainAdDetail(int id);
}

View File

@@ -57,5 +57,7 @@ public interface ShopProductService extends IService<ShopProduct> {
R unbindProductAndCourse(int productId,int catalogueId);
Page<ShopProduct> getProductForApp(int type,int page,int limit,String keywords);
R delShopProduct(int productId);
}

View File

@@ -0,0 +1,40 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.MainAdDao;
import com.peanut.modules.common.dao.ShopProductDao;
import com.peanut.modules.common.entity.MainAdEntity;
import com.peanut.modules.master.service.MainAdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service("masterMainAdService")
public class MainAdServiceImpl extends ServiceImpl<MainAdDao, MainAdEntity> implements MainAdService {
@Autowired
private ShopProductDao shopProductDao;
@Override
public List<MainAdEntity> getMainAdList() {
List<MainAdEntity> list = this.list();
for (MainAdEntity m :list){
if (m.getType()==0){
m.setShopProduct(shopProductDao.selectById(m.getRelationId()));
}
}
return list;
}
@Override
public MainAdEntity getMainAdDetail(int id) {
MainAdEntity info = this.getById(id);
if(info.getType()==0){
info.setShopProduct(shopProductDao.selectById(info.getRelationId()));
}
return info;
}
}

View File

@@ -300,6 +300,24 @@ public class ShopProductServiceImpl extends ServiceImpl<ShopProductDao, ShopProd
return R.ok();
}
@Override
public Page<ShopProduct> getProductForApp(int type, int page, int limit,String keywords) {
String sql = "";
if(type==0){//疯子读书
sql = "select * from shop_product_to_book_market where product_id = shop_product.product_id";
} else if (type==1) {//吴门医述
sql = "select * from shop_product_to_medicine_market where product_id = shop_product.product_id";
}else{
sql = "select * from shop_product_to_sociology_market where product_id = shop_product.product_id";
}
LambdaQueryWrapper<ShopProduct> wrapper = new LambdaQueryWrapper<>();
wrapper.exists(sql);
wrapper.like(StringUtils.isNotBlank(keywords),ShopProduct::getProductName,keywords);
Page<ShopProduct> shopProductPage = this.getBaseMapper().selectPage(new Page<>(page, limit), wrapper);
return shopProductPage;
}
@Override
public Map<String, Object> getProductToLabel(Integer productId) {
HashMap<String, Object> flag = new HashMap<>();

View File

@@ -11,7 +11,7 @@ connection-timeout: 6000000ms
spring:
# 环境 dev/dev1|test|prod
profiles:
active: prod
active: dev1
# jackson时间格式化
jackson:
time-zone: GMT+8