package com.dgtly.order.controller;

import java.util.List;

import com.dgtly.order.domain.EvaluateDto;
import com.dgtly.order.service.EvaluateService;
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 com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.common.core.page.TableDataInfo;

/**
 * 交货单基础Controller
 * 
 * @author dgtly
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/orderBase/evaluateManage")
public class EvaluateManageController extends BaseController
{
    private String prefix = "order/evaluate";

    @Autowired
    private EvaluateService evaluateServiceservice;

    @RequiresPermissions("orderBase:evaluateManage:view")
    @GetMapping()
    public String base()
    {
        return prefix + "/evaluateList";
    }

    /**
     * 查询交货单基础列表
     */
    @RequiresPermissions("orderBase:evaluateManage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EvaluateDto evaluateDto)
    {
        startPage();
        evaluateDto.setIsDelete("0");
        evaluateDto.setEvaluationStatus("y");
        List<EvaluateDto> list = evaluateServiceservice.selectEvaluateDtoList(evaluateDto);
        return getDataTable(list);
    }

    /**
     * 导出交货单基础列表
     */
    @RequiresPermissions("orderBase:evaluateManage:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EvaluateDto evaluateDto)
    {
        evaluateDto.setIsDelete("0");
        evaluateDto.setEvaluationStatus("y");
        List<EvaluateDto> list = evaluateServiceservice.selectEvaluateDtoList(evaluateDto);
        if(list.size() >= 10000){
            return new AjaxResult(301,"数据大于 10000 条Excel将无法打开，请过滤查询条件");
        }
        ExcelUtil<EvaluateDto> util = new ExcelUtil<EvaluateDto>(EvaluateDto.class);
        return util.exportExcel(list, "评价数据");
    }

    /**
     * 交货单详情
     */
    @GetMapping("/details/{id}")
    public String details(@PathVariable("id") Long id, ModelMap mmap)
    {
        EvaluateDto evaluateDto = evaluateServiceservice.selectEvaluateDtoById(id);
        mmap.put("evaluateDto", evaluateDto);
        return prefix + "/details";
    }

}
