package com.admin.web.controller.major;

import com.admin.common.annotation.Log;
import com.admin.common.core.controller.BaseController;
import com.admin.common.core.domain.AjaxResult;
import com.admin.common.core.page.TableDataInfo;
import com.admin.common.enums.BusinessType;
import com.admin.common.utils.poi.ExcelUtil;
import com.admin.major.domain.AdjustResult;
import com.admin.major.domain.dto.AdjustResultDTO;
import com.admin.major.manager.MajorAdjustManager;
import com.admin.major.manager.MajorAuditManager;
import com.admin.major.service.IAdjustResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 分流结果Controller
 * 
 * @author zewei
 * @date 2022-03-26
 */
@RestController
@RequestMapping("/major/adjustResult")
public class AdjustResultController extends BaseController
{
    @Autowired
    private IAdjustResultService adjustResultService;

    @Autowired
    private MajorAdjustManager majorAdjustManager;

    @Autowired
    private MajorAuditManager majorAuditManager;

    /**
     * 查询分流结果列表
     */
    @PreAuthorize("@ss.hasPermi('major:adjustResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdjustResultDTO adjustResult)
    {
        startPage();
//        List<AdjustResult> list = adjustResultService.selectAdjustResultList(adjustResult);
        List<AdjustResultDTO> list = adjustResultService.viewAdjustResult(adjustResult);
        return getDataTable(list);
    }

    /**
     * 导出分流结果列表
     */
    @PreAuthorize("@ss.hasPermi('major:adjustResult:export')")
    @Log(title = "分流结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdjustResultDTO adjustResult)
    {
//        List<AdjustResult> list = adjustResultService.selectAdjustResultList(adjustResult);
        List<AdjustResultDTO> list = adjustResultService.viewAdjustResult(adjustResult);
        ExcelUtil<AdjustResultDTO> util = new ExcelUtil<>(AdjustResultDTO.class);
        util.exportExcel(response, list, "分流结果数据");
    }

    /**
     * 获取分流结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('major:adjustResult:query')")
    @GetMapping(value = "/{studentId}")
    public AjaxResult getInfo(@PathVariable("studentId") String studentId)
    {
        return AjaxResult.success(adjustResultService.selectAdjustResultByStudentId(studentId));
    }

    /**
     * 新增分流结果
     */
    @PreAuthorize("@ss.hasPermi('major:adjustResult:add')")
    @Log(title = "分流结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdjustResult adjustResult)
    {
        return toAjax(adjustResultService.insertAdjustResult(adjustResult));
    }

    /**
     * 修改分流结果
     */
    @PreAuthorize("@ss.hasPermi('major:adjustResult:edit')")
    @Log(title = "分流结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdjustResult adjustResult)
    {
        return toAjax(adjustResultService.updateAdjustResult(adjustResult));
    }

    /**
     * 删除分流结果
     */
    @PreAuthorize("@ss.hasPermi('major:adjustResult:remove')")
    @Log(title = "分流结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{batchIds}")
    public AjaxResult remove(@PathVariable String[] batchIds)
    {
        return toAjax(adjustResultService.deleteAdjustResultByBatchIds(batchIds));
    }

    /**
     * 分流结果
     */
    @PreAuthorize("@ss.hasPermi('major:adjustResult:remove')")
    @Log(title = "分流", businessType = BusinessType.OTHER)
    @PostMapping("/startAdjust")
    public AjaxResult startAdjust(@RequestBody AdjustResult adjustResult)
    {
        majorAdjustManager.adjust(adjustResult.getBatchId(),adjustResult.getCollegeId());
        return toAjax(true);
    }

    /**
     * 分流审批发布
     */
    @PreAuthorize("@ss.hasPermi('major:adjustResult:audit')")
    @Log(title = "分流", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody AdjustResult adjustResult){
        majorAuditManager.audit(adjustResult.getBatchId(),adjustResult.getCollegeId());
        return toAjax(true);
    }
}
