123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package com.qxgmat.service.inline;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.AbstractService;
- import com.nuliji.tools.exception.ParameterException;
- import com.nuliji.tools.exception.SystemException;
- import com.nuliji.tools.mybatis.Example;
- import com.qxgmat.data.constants.enums.module.CourseModule;
- import com.qxgmat.data.constants.enums.status.DirectionStatus;
- import com.qxgmat.data.dao.CourseNoMapper;
- import com.qxgmat.data.dao.CoursePackageMapper;
- import com.qxgmat.data.dao.entity.Course;
- import com.qxgmat.data.dao.entity.CourseNo;
- import com.qxgmat.data.dao.entity.CoursePackage;
- import com.qxgmat.data.relation.CoursePackageRelationMapper;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.List;
- import java.util.stream.Collectors;
- @Service
- public class CoursePackageService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(CoursePackageService.class);
- @Resource
- private CoursePackageMapper coursePackageMapper;
- @Resource
- private CoursePackageRelationMapper coursePackageRelationMapper;
- public Page<CoursePackage> listAdmin(int page, int size,String keyword, String order, DirectionStatus direction){
- Example example = new Example(CoursePackage.class);
- if(keyword != null){
- example.and(
- example.createCriteria()
- .andLike("title", "%"+keyword+"%")
- );
- }
- if(order == null || order.isEmpty()) order = "id";
- switch(direction){
- case ASC:
- example.orderBy(order).asc();
- break;
- case DESC:
- default:
- example.orderBy(order).desc();
- }
- return select(coursePackageMapper, example, page, size);
- }
- public Page<CoursePackage> list(int page, int size, Integer structId, Boolean isSpecial, String order, DirectionStatus direction){
- Example example = new Example(CoursePackage.class);
- if(structId != null){
- example.and(
- example.createCriteria()
- .orEqualTo("structId", structId)
- );
- }
- if (isSpecial != null){
- example.and(
- example.createCriteria()
- .orEqualTo("isSpecial", isSpecial ? 1: 0)
- );
- }
- if(order == null || order.isEmpty()) order = "id";
- if (direction != null){
- switch(direction){
- case ASC:
- example.orderBy(order).asc();
- break;
- case DESC:
- default:
- example.orderBy(order).desc();
- }
- } else {
- example.orderBy(order).desc();
- }
- return select(coursePackageMapper, example, page, size);
- }
- /**
- * 查找符合课程列表的套餐
- * @param ids
- * @return
- */
- public CoursePackage combineCourse(Collection ids){
- if (ids==null || ids.size() == 0) return null;
- List<CoursePackage> all = select(coursePackageMapper);
- for(CoursePackage p : all){
- if(ids.containsAll(Arrays.stream(p.getCourseIds()).collect(Collectors.toList()))){
- return p;
- }
- }
- return null;
- }
- /**
- * 累加购买记录
- * @param sale
- */
- public void accumulation(Integer packageId, int sale){
- coursePackageRelationMapper.accumulation(packageId, sale);
- }
- public CoursePackage add(CoursePackage coursePackage){
- int result = insert(coursePackageMapper, coursePackage);
- coursePackage = one(coursePackageMapper, coursePackage.getId());
- if(coursePackage == null){
- throw new SystemException("套餐添加失败");
- }
- return coursePackage;
- }
- public CoursePackage edit(CoursePackage coursePackage){
- CoursePackage in = one(coursePackageMapper, coursePackage.getId());
- if(in == null){
- throw new ParameterException("套餐不存在");
- }
- int result = update(coursePackageMapper, coursePackage);
- return coursePackage;
- }
- public boolean delete(Number id){
- CoursePackage in = one(coursePackageMapper, id);
- if(in == null){
- throw new ParameterException("套餐不存在");
- }
- int result = delete(coursePackageMapper, id);
- return result > 0;
- }
- public CoursePackage get(Number id){
- CoursePackage in = one(coursePackageMapper, id);
- if(in == null){
- throw new ParameterException("套餐不存在");
- }
- return in;
- }
- public Page<CoursePackage> select(int page, int pageSize){
- return select(coursePackageMapper, page, pageSize);
- }
- public Page<CoursePackage> select(Integer[] ids){
- return page(()->select(coursePackageMapper, ids), 1, ids.length);
- }
- public List<CoursePackage> select(Collection ids){
- return select(coursePackageMapper, ids);
- }
- }
|