This commit is contained in:
wangjinlei
2024-05-30 14:32:28 +08:00
parent f8d98dda1b
commit cda9eb9ae7
5 changed files with 37 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Data
@TableName("course_catalogue")
@@ -48,4 +49,10 @@ public class CourseCatalogueEntity{
*/
@TableField(exist = false)
private int completion;
/**
* 存在的商品列表
*/
@TableField(exist = false)
private List<ShopProduct> productList;
}

View File

@@ -69,6 +69,12 @@ public class CourseController {
return R.ok().put("catalogues",courseCatalogues);
}
@RequestMapping("/createProductForCatalogue")
public R createProductForCatalogue(@RequestBody Map<String,Integer> map){
int id = map.get("id");
return courseCatalogueService.createProductForCatalogue(id);
}
@RequestMapping("/addCourseCatalogue")
public R addCourseCatalogue(@RequestBody CourseCatalogueEntity courseCatalogue){
courseCatalogueService.addCourseCatalogue(courseCatalogue);

View File

@@ -13,4 +13,6 @@ public interface CourseCatalogueService extends IService<CourseCatalogueEntity>
R delCourseCatalogue(int id);
void addCourseCatalogue(CourseCatalogueEntity courseCatalogue);
R createProductForCatalogue(int id);
}

View File

@@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@@ -70,6 +71,19 @@ public class CourseCatalogueServiceImpl extends ServiceImpl<CourseCatalogueDao,
}
@Override
public R createProductForCatalogue(int id) {
//check
CourseCatalogueEntity byId = this.getById(id);
if(byId.getType()!=1){
return R.error("普通类型的课程才可以生成商品");
}
if(byId.getFee().compareTo(BigDecimal.ZERO)==0||byId.getHalfFee().compareTo(BigDecimal.ZERO)==0){
return R.error("价格异常");
}
createProduct(byId);
return R.ok();
}
private void createProduct(CourseCatalogueEntity courseCatalogue){
CourseEntity courseEntity = courseDao.selectById(courseCatalogue.getCourseId());

View File

@@ -74,6 +74,14 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
courseEntityPage = this.getBaseMapper().selectPage(new Page<>(page, limit), wrapper);
for (CourseEntity c:courseEntityPage.getRecords()){
List<CourseCatalogueEntity> courseCatalogueEntities = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>().eq(CourseCatalogueEntity::getCourseId, c.getId()).orderByAsc(CourseCatalogueEntity::getSort));
for (CourseCatalogueEntity co : courseCatalogueEntities){
MPJLambdaWrapper<ShopProductCourseEntity> shopProductCourseEntityMPJLambdaWrapper = new MPJLambdaWrapper<>();
shopProductCourseEntityMPJLambdaWrapper.selectAll(ShopProduct.class);
shopProductCourseEntityMPJLambdaWrapper.leftJoin(ShopProduct.class,ShopProduct::getProductId,ShopProductCourseEntity::getProductId);
shopProductCourseEntityMPJLambdaWrapper.eq(ShopProductCourseEntity::getCatalogueId,co.getId());
List<ShopProduct> shopProducts = shopProductCourseDao.selectJoinList(ShopProduct.class, shopProductCourseEntityMPJLambdaWrapper);
co.setProductList(shopProducts);
}
c.setCourseCatalogueEntityList(courseCatalogueEntities);
}
return courseEntityPage;