package com.yida.data.user.controller;

import cc.mrbird.febs.common.redis.service.RedisService;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ModuleName;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.constant.CachePrefixConstant;
import com.yida.data.common.core.entity.system.enums.OperationLogTypeEnum;
import com.yida.data.common.core.entity.user.EduStudentApply;
import com.yida.data.common.core.entity.user.EduStudentApplyFor;
import com.yida.data.log.annotation.OperationLog;
import com.yida.data.user.dto.ListStudentApplyDTO;
import com.yida.data.user.dto.ListStudentApplyForDTO;
import com.yida.data.user.service.EduStudentApplyForService;
import com.yida.data.user.service.EduStudentApplyService;
import com.yida.data.user.vo.StudentApplyImportProgressVO;
import com.yida.data.user.vo.StudentApplyStatusVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "交易-学生应用关系")
@RequiredArgsConstructor
@RequestMapping("/transaction/studentApplyFor")
@RestController
public class EduStudentApplyForController {

    private final EduStudentApplyForService eduStudentApplyForService;

    private final RedisService redisService;

    @ApiOperation("分页查询申请学生开通应用")
    @GetMapping("/listStudentApplyFor")
    public ResultBean<IPage<EduStudentApplyFor>> listApply(ListStudentApplyForDTO dto) {
        Page<EduStudentApplyFor> page = new Page<>();
        page.setCurrent(dto.getPageNum());
        page.setSize(dto.getPageSize());
        return ResultBean.buildSuccess(eduStudentApplyForService.listStudentApplyFor(dto, page));
    }


    @ApiOperation("查询申请详情")
    @GetMapping("/getStudentApplyFor")
    public ResultBean<EduStudentApplyFor> getStudentApplyFor(@RequestParam("studentId") Long studentId,
        @RequestParam("applyCode") String applyCode) {
        return ResultBean.buildSuccess(eduStudentApplyForService.getByStudentId(studentId, applyCode));
    }


    @ApiOperation("学生申请开通应用")
    @GetMapping("/saveStudentApplyFor")
    @OperationLog(module = ModuleName.STUDENT, methods = "学生申请开通应用", type = OperationLogTypeEnum.INSERT)
    public ResultBean insertApplyFor(@RequestParam("studentId") Long studentId, @RequestParam("applyCode") String applyCode) {
        EduStudentApplyFor eduStudentApplyFor = new EduStudentApplyFor();
        eduStudentApplyFor.setStudentId(studentId);
        eduStudentApplyFor.setApplyCode(applyCode);
        eduStudentApplyForService.saveStudentApplyFor(eduStudentApplyFor);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("处理申请")
    @GetMapping("/dealApplyFor")
    @OperationLog(module = ModuleName.STUDENT, methods = "处理申请", type = OperationLogTypeEnum.UPDATE)
    public ResultBean dealApplyFor(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
        eduStudentApplyForService.dealApplyFor(id, status);
        return ResultBean.buildSuccess();
    }
}
