package com.ruoyi.mall.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.mall.domain.MallMemberUser;
import com.ruoyi.mall.domain.MallSchool;
import com.ruoyi.mall.service.IMallMemberUserService;
import com.ruoyi.mall.service.IMallSchoolService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MemberReportIntelligence;
import com.ruoyi.mall.service.IMemberReportIntelligenceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户智能志愿报告Controller
 *
 * @author ruoyi
 * @date 2023-10-28
 */
@RestController
@RequestMapping("/mall/MemberReportIntelligence")
public class MemberReportIntelligenceController extends BaseController
{
    @Autowired
    private IMemberReportIntelligenceService memberReportIntelligenceService;
    @Resource
    private IMallSchoolService schoolService;
    @Resource
    private IMallMemberUserService mallMemberUserService;

    /**
     * 查询用户智能志愿报告列表
     */
    @PreAuthorize("@ss.hasPermi('mall:MemberReportIntelligence:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberReportIntelligence memberReportIntelligence)
    {
        // 获取登陆用户
        LoginUser loginUser = SecurityUtils.getLoginUser();
        // MallSchool school = schoolService.selectMallSchoolBySysUserId(loginUser.getUserId());
        // if (school != null && loginUser.getUserId() != 1) {
        //     memberReportIntelligence.setBindingSchoolId(school.getSchoolId());
        // }

        MallMemberUser sysUserId = mallMemberUserService.selectMallMemberUserBySysUserId(loginUser.getUserId());
        if (sysUserId != null && loginUser.getUserId() != 1) {
            memberReportIntelligence.setIndexUserId(sysUserId.getId());
        }

        startPage();
        List<MemberReportIntelligence> list = memberReportIntelligenceService.selectMemberReportIntelligenceList(memberReportIntelligence);
        return getDataTable(list);
    }

    /**
     * 导出用户智能志愿报告列表
     */
    @PreAuthorize("@ss.hasPermi('mall:MemberReportIntelligence:export')")
    @Log(title = "用户智能志愿报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberReportIntelligence memberReportIntelligence)
    {
        List<MemberReportIntelligence> list = memberReportIntelligenceService.selectMemberReportIntelligenceList(memberReportIntelligence);
        ExcelUtil<MemberReportIntelligence> util = new ExcelUtil<MemberReportIntelligence>(MemberReportIntelligence.class);
        util.exportExcel(response, list, "用户智能志愿报告数据");
    }

    /**
     * 获取用户智能志愿报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:MemberReportIntelligence:query')")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return AjaxResult.success(memberReportIntelligenceService.selectMemberReportIntelligenceByReportId(reportId));
    }

    /**
     * 新增用户智能志愿报告
     */
    @PreAuthorize("@ss.hasPermi('mall:MemberReportIntelligence:add')")
    @Log(title = "用户智能志愿报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberReportIntelligence memberReportIntelligence)
    {
        return toAjax(memberReportIntelligenceService.insertMemberReportIntelligence(memberReportIntelligence));
    }

    /**
     * 修改用户智能志愿报告
     */
    @PreAuthorize("@ss.hasPermi('mall:MemberReportIntelligence:edit')")
    @Log(title = "用户智能志愿报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberReportIntelligence memberReportIntelligence)
    {
        return toAjax(memberReportIntelligenceService.updateMemberReportIntelligence(memberReportIntelligence));
    }

    /**
     * 删除用户智能志愿报告
     */
    @PreAuthorize("@ss.hasPermi('mall:MemberReportIntelligence:remove')")
    @Log(title = "用户智能志愿报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(memberReportIntelligenceService.deleteMemberReportIntelligenceByReportIds(reportIds));
    }
}
