package com.ruoyi.web.controller.api;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mall.domain.MallMemberUser;
import com.ruoyi.mall.domain.MemberReportIntelligence;
import com.ruoyi.mall.service.IMallMemberUserService;
import com.ruoyi.mall.service.SlipAlertService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/** 滑档预警*/
@RestController
@RequestMapping("/api/SlipAlert")
public class ApiSlipAlertController {

    @Resource
    IMallMemberUserService mallMemberUserService;
    @Resource
    SlipAlertService slipAlertService;

    /**查询滑档预警 列表
     *
     * @param pageNum 分页
     * @param pageSize 分页大小
     * @param userId  当前用户id
     * @return
     */
    @GetMapping("/getReportList")
    public AjaxResult getReportList(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    @NotNull(message = "getReportList.userId.isnull")Long userId){
        try{//
            MallMemberUser mallMemberUser = mallMemberUserService.selectMallMemberUserById(userId);
            if(null == mallMemberUser || null == mallMemberUser.getMajorScore() || null == mallMemberUser.getCultureScore() ){
                return AjaxResult.error("请先完善 我的-成绩管理 !");
            }
            MemberReportIntelligence param = new MemberReportIntelligence();
            param.setUserId(userId);
            PageHelper.startPage(pageNum, pageSize);
            List<MemberReportIntelligence> memberReportIntelligences = slipAlertService.selectMemberReportIntelligenceList(param, mallMemberUser);
            PageInfo<MemberReportIntelligence> pageInfo = new PageInfo<>(memberReportIntelligences);
            return AjaxResult.success().put("data", pageInfo);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }
}
