diff --git a/src/main/java/com/peanut/modules/common/controller/MainAdController.java b/src/main/java/com/peanut/modules/common/controller/MainAdController.java new file mode 100644 index 00000000..e50d4806 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/controller/MainAdController.java @@ -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 params){ + int type = params.get("type"); + List adDetail = mainAdService.getAd(type); + return R.ok().put("list",adDetail); + } +} diff --git a/src/main/java/com/peanut/modules/common/dao/MainAdDao.java b/src/main/java/com/peanut/modules/common/dao/MainAdDao.java new file mode 100644 index 00000000..a7b415d2 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/dao/MainAdDao.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/common/entity/MainAdEntity.java b/src/main/java/com/peanut/modules/common/entity/MainAdEntity.java new file mode 100644 index 00000000..e7f20d14 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/entity/MainAdEntity.java @@ -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; + +} diff --git a/src/main/java/com/peanut/modules/common/service/MainAdService.java b/src/main/java/com/peanut/modules/common/service/MainAdService.java new file mode 100644 index 00000000..b9d4aa90 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/service/MainAdService.java @@ -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 { + + List getAd(int type); +} diff --git a/src/main/java/com/peanut/modules/common/service/impl/MainAdServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/MainAdServiceImpl.java new file mode 100644 index 00000000..202a1054 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/service/impl/MainAdServiceImpl.java @@ -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 implements MainAdService { + @Autowired + private ShopProductDao shopProductDao; + + @Override + public List getAd(int type) { + LambdaQueryWrapper mainAdEntityLambdaQueryWrapper = new LambdaQueryWrapper<>(); + mainAdEntityLambdaQueryWrapper.eq(MainAdEntity::getAppType,type); + List mainAdEntities = this.getBaseMapper().selectList(mainAdEntityLambdaQueryWrapper); + for (MainAdEntity m :mainAdEntities){ + if(m.getType()==0){//如果为商品 + ShopProduct shopProduct = shopProductDao.selectById(m.getRelationId()); + m.setShopProduct(shopProduct); + } + } + return mainAdEntities; + } +} diff --git a/src/main/java/com/peanut/modules/master/controller/CourseController.java b/src/main/java/com/peanut/modules/master/controller/CourseController.java index 6d4a911b..31ce8f4e 100644 --- a/src/main/java/com/peanut/modules/master/controller/CourseController.java +++ b/src/main/java/com/peanut/modules/master/controller/CourseController.java @@ -26,7 +26,8 @@ import java.util.Map; @Slf4j @RestController("masterCourse") @RequestMapping("master/course") -public class CourseController { +public class +CourseController { @Autowired private CourseService courseService; diff --git a/src/main/java/com/peanut/modules/master/controller/MainAdController.java b/src/main/java/com/peanut/modules/master/controller/MainAdController.java new file mode 100644 index 00000000..4b2a977e --- /dev/null +++ b/src/main/java/com/peanut/modules/master/controller/MainAdController.java @@ -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 mainAdList = mainAdService.getMainAdList(); + return R.ok().put("list",mainAdList); + } + + @RequestMapping("/getMainAdDetail") + public R getMainAdDetail(@RequestBody Map 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 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); + } + +} diff --git a/src/main/java/com/peanut/modules/master/controller/ShopProductController.java b/src/main/java/com/peanut/modules/master/controller/ShopProductController.java index b3d1ebe4..98ca2481 100644 --- a/src/main/java/com/peanut/modules/master/controller/ShopProductController.java +++ b/src/main/java/com/peanut/modules/master/controller/ShopProductController.java @@ -210,4 +210,10 @@ public class ShopProductController { return shopProductService.unbindProductAndCourse(map.get("productId"),map.get("catalogueId")); } + @RequestMapping("/getProductForApp") + public R getProductForApp(@RequestBody Map map){ + Page 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); + } + } diff --git a/src/main/java/com/peanut/modules/master/service/MainAdService.java b/src/main/java/com/peanut/modules/master/service/MainAdService.java new file mode 100644 index 00000000..66c9381f --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/MainAdService.java @@ -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 { + + List getMainAdList(); + + MainAdEntity getMainAdDetail(int id); +} diff --git a/src/main/java/com/peanut/modules/master/service/ShopProductService.java b/src/main/java/com/peanut/modules/master/service/ShopProductService.java index 081c63df..463a27cd 100644 --- a/src/main/java/com/peanut/modules/master/service/ShopProductService.java +++ b/src/main/java/com/peanut/modules/master/service/ShopProductService.java @@ -57,5 +57,7 @@ public interface ShopProductService extends IService { R unbindProductAndCourse(int productId,int catalogueId); + Page getProductForApp(int type,int page,int limit,String keywords); + R delShopProduct(int productId); } diff --git a/src/main/java/com/peanut/modules/master/service/impl/MainAdServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/MainAdServiceImpl.java new file mode 100644 index 00000000..cbab4aca --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/MainAdServiceImpl.java @@ -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 implements MainAdService { + + @Autowired + private ShopProductDao shopProductDao; + + @Override + public List getMainAdList() { + List 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; + } +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/ShopProductServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/ShopProductServiceImpl.java index c0fbe4a2..2120e70d 100644 --- a/src/main/java/com/peanut/modules/master/service/impl/ShopProductServiceImpl.java +++ b/src/main/java/com/peanut/modules/master/service/impl/ShopProductServiceImpl.java @@ -300,6 +300,24 @@ public class ShopProductServiceImpl extends ServiceImpl 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 wrapper = new LambdaQueryWrapper<>(); + wrapper.exists(sql); + wrapper.like(StringUtils.isNotBlank(keywords),ShopProduct::getProductName,keywords); + Page shopProductPage = this.getBaseMapper().selectPage(new Page<>(page, limit), wrapper); + return shopProductPage; + } + @Override public Map getProductToLabel(Integer productId) { HashMap flag = new HashMap<>(); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 558f513f..78c2dc0a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,7 @@ connection-timeout: 6000000ms spring: # 环境 dev/dev1|test|prod profiles: - active: prod + active: dev1 # jackson时间格式化 jackson: time-zone: GMT+8