package com.sooka.apply.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.sooka.apply.domain.IntRecord;
import com.sooka.apply.service.IIntRecordService;
import com.sooka.common.annotation.Log;
import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
import com.sooka.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 政数局 -- 我的审批Controller
 *
 * @author limeng
 * @date 2022-10-19
 */
@Controller
@RequestMapping("/apply/approval")
public class ApprovalController extends BaseController {

    private String prefix = "apply/approval";

    @Autowired
    private IIntRecordService intRecordService;

    @RequiresPermissions("apply:approval:view")
    @GetMapping()
    public String approval()
    {
        return prefix + "/approval";
    }

    /**
     * 查询我的审批
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IntRecord intRecord)
    {
        //只查政数局待审批的数据
        intRecord.setStatus("3");
        startPage();
        List<IntRecord> list = intRecordService.selectIntRecordList(intRecord);
        return getDataTable(list);
    }

    /**
     * 导出我的审批
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IntRecord intRecord)
    {
        List<IntRecord> list = intRecordService.selectIntRecordList(intRecord);
        ExcelUtil<IntRecord> util = new ExcelUtil<IntRecord>(IntRecord.class);
        return util.exportExcel(list, "approval");
    }

    /**
     * 审批页面
     */
    @GetMapping("/approval/{id}")
    public String approval(@PathVariable("id") String id, ModelMap mmap)
    {
        IntRecord intRecord = intRecordService.selectIntRecordById(id);
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(intRecord.getIntDetailedList()));
        mmap.put("intRecord", intRecord);
        mmap.put("intDetailedList", jsonArray);
        return prefix + "/approvalDetail";
    }
}
