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.MaterialPreparationService;
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("/materialPreparation")
@Slf4j
@Api(description = "备料车间在制统计表")
public class MaterialPreparationController {

    @Autowired
    private MaterialPreparationService materialPreparationService;

    @ApiOperation(value = "备料车间在制统计柱状图")
    @GetMapping("/getMaterialData")
    public Result getBadDistributionInfo() {
        List<Map<String, Object>> map = materialPreparationService.getData();
        return ResultGenerator.success(map);
    }

    @ApiOperation(value = "导入管控目标Excel")
    @PostMapping("/importExcel")
    public Result importExcel(MultipartFile file) {
        String message = materialPreparationService.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);
    }
}
