package com.sw.mes.yb.report.controller;

import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.utils.ExcelUtil;
import com.sw.mes.yb.report.service.RecycledMaterialPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@RestController
@RequestMapping("/recycledMaterial")
@Slf4j
@Api(description = "循环料接口")
public class RecycledMaterialController {

    @Autowired
    private RecycledMaterialPlanService recycledMaterialPlanService;

    @ApiOperation(value = "循环料柱状图")
    @GetMapping("/getRecycledData")
    public Result getBadDistributionInfo() {
        List<Map<String, Object>> map = recycledMaterialPlanService.getData();
        return ResultGenerator.success(map);
    }

    @ApiOperation(value = "导入计划产出Excel")
    @PostMapping("/importExcel")
    public Result importExcel(MultipartFile file) {
        String message = recycledMaterialPlanService.importRecycledMaterial(file);
        if (null != message) {
            return ResultGenerator.fail(message);
        } else {
            return ResultGenerator.success();
        }
    }

    @ApiOperation(value = "模板文件下载")
    @PostMapping("/download")
    public void download(HttpServletResponse response) {
        String path = "template/循环料计划产出导入模板.xlsx";
        ExcelUtil.download1(path, response);
    }
}
