44323
2023-11-01 2dda6304029c95e171b2f9e32406eb4600d77ebd
cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackageController.java
@@ -1,16 +1,39 @@
package com.dsh.course.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.entity.CoursePackagePaymentConfig;
import com.dsh.course.entity.TCoursePackage;
import com.dsh.course.model.vo.response.WeekLimitedResponse;
import com.dsh.course.entity.TCoursePackagePayment;
import com.dsh.course.entity.TCoursePackageType;
import com.dsh.course.feignclient.model.StoreOfCourseVo;
import com.dsh.course.feignclient.other.StoreClient;
import com.dsh.course.feignclient.other.model.Store;
import com.dsh.course.model.BaseVo;
import com.dsh.course.model.QueryCoursePackageLists;
import com.dsh.course.model.QueryExamineCoursePackageLists;
import com.dsh.course.model.vo.response.Details;
import com.dsh.course.model.vo.response.ExchangeCoursePackageResponse;
import com.dsh.course.service.ICoursePackagePaymentConfigService;
import com.dsh.course.service.TCoursePackageDiscountService;
import com.dsh.course.service.TCoursePackagePaymentService;
import com.dsh.course.service.TCoursePackageService;
import com.dsh.course.util.PageFactory;
import com.dsh.course.util.ResultUtil;
import com.dsh.course.util.TokenUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.bouncycastle.math.Primes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @author zhibing.pu
@@ -27,9 +50,41 @@
    @Autowired
    private TCoursePackageDiscountService tcpdService;
    @Resource
    private StoreClient storeClient;
    @Resource
    private TCoursePackagePaymentService tcppmenService;
    @Resource
    private ICoursePackagePaymentConfigService icppconfigService;
    @Autowired
    private TokenUtil tokenUtil;
    /**
     * 根据门店ids获取课包ids 根据课包ids 获取购课记录的用户ids
     */
    @ResponseBody
    @PostMapping("/base/coursePackage/getCoursePackageByStoreIds")
    public List<Integer> getCoursePackageByStoreIds(@RequestBody List<Integer> storeIds){
        try {
            // 获取当前课包的ids
            List<Integer> courseIds = coursePackageService.list(new QueryWrapper<TCoursePackage>().in("storeId", storeIds))
                    .stream().map(TCoursePackage::getId).collect(Collectors.toList());
            List<Integer> userIds = tcppmenService.list(new QueryWrapper<TCoursePackagePayment>().in("coursePackageId", courseIds))
                    .stream().map(TCoursePackagePayment::getAppUserId).collect(Collectors.toList());
            return userIds;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 根据id获取课包
@@ -37,7 +92,7 @@
     * @return
     */
    @ResponseBody
    @PostMapping("/coursePackage/queryCoursePackageById")
    @PostMapping("/base/coursePackage/queryCoursePackageById")
    public TCoursePackage queryCoursePackageById(@RequestBody Integer id){
        try {
            TCoursePackage coursePackage = coursePackageService.getById(id);
@@ -48,17 +103,59 @@
        }
    }
    @ResponseBody
    @PostMapping("/base/coursePackage/queryByStoreId")
    public List<TCoursePackage> queryByStoreId(@RequestBody Integer shopId){
        try {
            List<TCoursePackage> shopId1 = coursePackageService.list(new QueryWrapper<TCoursePackage>().eq("storeId", shopId));
            return shopId1;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
    @Autowired
    private TCoursePackagePaymentService packagePaymentService;
    @ResponseBody
    @PostMapping("/base/coursePackage/queryByCode")
    public Integer queryByCode(@RequestBody String code){
        return packagePaymentService.listStoreId(code);
    }
    /**
     * 根据id获取课包
     */
    @ResponseBody
    @PostMapping("/base/coursePackage/getCoursePackageByStoreId")
    public List<TCoursePackage> getCoursePackageByStoreId(@RequestBody Integer storeId){
       return coursePackageService.list(new QueryWrapper<TCoursePackage>().eq("storeId", storeId));
    }
    /**
     * 根据课包类型获取课包
     */
    @ResponseBody
    @PostMapping("/base/coursePackage/getCoursePackageByType/{typeId}/{storeId}")
    public List<TCoursePackage> getCoursePackageByType(@PathVariable("typeId") Integer typeId,@PathVariable("storeId")Integer storeId){
       return coursePackageService.list(new QueryWrapper<TCoursePackage>().eq("coursePackageTypeId", typeId).eq("storeId",storeId));
    }
    /**
     * 本周福利列表
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/weekLimitedBenefit")
    @ApiOperation(value = "使用福利-本周福利限时折扣列表", tags = {"APP-开始上课"})
    @ApiOperation(value = "本周福利-限时折扣列表", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "discountType",value = "默认显示 限时折扣 (1限时折扣 2赠送课时)")
            @ApiImplicitParam(name = "discountType",value = "默认显示 限时折扣 (1限时折扣 2赠送课时)",dataType = "int"),
            @ApiImplicitParam(name = "lon",value = "经度",dataType = "String"),
            @ApiImplicitParam(name = "lat",value = "纬度",dataType = "String"),
    })
    public ResultUtil<WeekLimitedResponse> thisWeeksBenefitList(Integer discountType,String lon,String lat){
    public ResultUtil<List<Details>> thisWeeksBenefitList(Integer discountType, String lon, String lat){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
@@ -70,4 +167,125 @@
        }
    }
    /**
     * 折扣课包详情
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/discountCourseDatas")
    @ApiOperation(value = "本周福利-折扣课包详情", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "coursePackageDiscountId",value = "限时折扣配置id/赠送课时配置id",dataType = "int"),
            @ApiImplicitParam(name = "lon",value = "经度",dataType = "String"),
            @ApiImplicitParam(name = "lat",value = "纬度",dataType = "String"),
    })
    public ResultUtil<ExchangeCoursePackageResponse> discountCourseDatas(Integer coursePackageDiscountId,String lon,String lat){
        try {
            return ResultUtil.success(tcpdService.getWeekFreeCourseDetails(coursePackageDiscountId,lat,lon));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/base/coursePack/courseList")
    public List<StoreOfCourseVo> getStoreOfCourseList(@RequestBody Integer storeId){
        List<StoreOfCourseVo> courseVoList = new ArrayList<>();
        Store store = storeClient.queryStoreById(storeId);
        List<TCoursePackage> list = coursePackageService.list(new QueryWrapper<TCoursePackage>()
                .eq("storeId", storeId)
                .eq("auditStatus",2)
                .eq("state",1));
        if (list.size() >  0){
            for (TCoursePackage coursePackage : list) {
                int count = tcppmenService.count(new QueryWrapper<TCoursePackagePayment>()
                        .eq("coursePackageId",coursePackage.getId()));
                StoreOfCourseVo courseVo = new StoreOfCourseVo();
                courseVo.setCourseId(coursePackage.getId());
                courseVo.setName(coursePackage.getName()+"(" + store.getName() + ")");
                courseVo.setClassStartTime(coursePackage.getClassStartTime() +"-"+ coursePackage.getClassEndTime());
                courseVo.setApplicantsNumber(count);
                List<CoursePackagePaymentConfig> list1 = icppconfigService.list(new QueryWrapper<CoursePackagePaymentConfig>()
                        .eq("coursePackageId",coursePackage.getId()));
//                取价格最低的课时
                CoursePackagePaymentConfig minConfig = list1.stream()
                        .min(Comparator.comparingDouble(CoursePackagePaymentConfig::getCashPayment))
                        .orElse(null);
                if (minConfig != null){
                    courseVo.setClassHours(minConfig.getClassHours());
                    courseVo.setOriginalPrice(minConfig.getCashPayment());
                }
                courseVoList.add(courseVo);
            }
        }
        return courseVoList;
    }
    /**
     * 根据id获取课包
     * @param coursePackConfigId
     * @return
     */
    @ResponseBody
    @PostMapping("/base/coursePackage/queryConfigCoursePackData")
    public CoursePackagePaymentConfig queryConfigCoursePackData(@RequestBody Integer coursePackConfigId){
        return icppconfigService.getById(coursePackConfigId);
    }
    /**
     * 获取课包管理列表数据
     * @param queryCoursePackageLists
     * @return
     */
    @ResponseBody
    @PostMapping("/coursePackage/queryCoursePackageLists")
    public Page<Map<String, Object>> queryCoursePackageLists(@RequestBody QueryCoursePackageLists queryCoursePackageLists){
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(queryCoursePackageLists.getLimit(), queryCoursePackageLists.getOffset(), queryCoursePackageLists.getSort(), queryCoursePackageLists.getOrder());
        Page<Map<String, Object>> mapPage = page.setRecords(coursePackageService.queryCoursePackageLists(page, queryCoursePackageLists));
        return mapPage;
    }
    /**
     * 添加数据
     * @param coursePackage
     * @return
     */
    @ResponseBody
    @PostMapping("/coursePackage/addCoursePackage")
    public Integer addCoursePackage(@RequestBody TCoursePackage coursePackage){
        coursePackage.setNeedNum(coursePackage.getCodeTime());
        return coursePackageService.addCoursePackage(coursePackage);
    }
    /**
     * 修改数据
     * @param coursePackage
     */
    @ResponseBody
    @PostMapping("/coursePackage/updateCoursePackageById")
    public void updateCoursePackageById(@RequestBody TCoursePackage coursePackage){
        coursePackageService.updateCoursePackageById(coursePackage);
    }
    /**
     * 获取课包审核列表
     * @param queryExamineCoursePackageLists
     * @return
     */
    @ResponseBody
    @PostMapping("/coursePackage/queryExamineCoursePackageLists")
    public Page<Map<String, Object>> queryExamineCoursePackageLists(@RequestBody QueryExamineCoursePackageLists queryExamineCoursePackageLists){
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(queryExamineCoursePackageLists.getLimit(), queryExamineCoursePackageLists.getOffset(),
                queryExamineCoursePackageLists.getSort(), queryExamineCoursePackageLists.getOrder());
        Page<Map<String, Object>> mapPage = page.setRecords(coursePackageService.queryExamineCoursePackageLists(page, queryExamineCoursePackageLists));
        return mapPage;
    }
}