package com.foreverwin.mesnac.common.controller;

/**
 * @Description TODO
 * @Author zhaojiawei
 * @Since 2021-08-23
 */

import com.foreverwin.mesnac.common.mapper.ReportDataMapper;
import com.foreverwin.mesnac.common.service.ReportDataService;
import com.foreverwin.modular.core.util.CommonMethods;
import com.foreverwin.modular.core.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/REPORT-DATA")
public class ReportDataController {

    @Autowired
    public ReportDataService reportDataService;
    @Autowired
    public ReportDataMapper reportDataMapper;

    /**
     * 查询质量检验任务
     *
     * @param paramMap
     * @return
     */
    @GetMapping("/findInspectionTask")
    public R findInspectionTask(@RequestParam(required = false) Map paramMap) {
        try {
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataService.findInspectionTask(paramMap);
            return R.ok(result);
        } catch (Exception e) {
            return R.failed(e.getMessage());
        }
    }

    /**
     * 查询质量检验任务明细
     *
     * @param paramMap
     * @return
     */
    @GetMapping("/findInspectionTaskDetail")
    public R findInspectionTaskDetail(@RequestParam(required = false) Map paramMap) {
        try {
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataService.findInspectionTaskDetail(paramMap);
            return R.ok(result);
        } catch (Exception e) {
            return R.failed(e.getMessage());
        }
    }

    /**
     * 设备、设备类型负荷率报表
     * 查询设备每日的负荷率
     * @param paramMap
     * @return
     */
    @GetMapping("/findResourceOrResourceTypeLoadRateInfo")
    public R findResourceLoadRateInfo(@RequestParam(required = false) Map paramMap) {
        try {
            List<Map<String, Object>> result = reportDataService.findResourceOrResourceTypeLoadRateInfo(paramMap);
            return R.ok(result);
        } catch (Exception e) {
            return R.failed(e.getMessage());
        }
    }


    /**
     * 设备维修数据统计报表
     *
     * @param paramMap
     * @return
     */
    @GetMapping("/findResourceRepairDataStatInfo")
    public R findResourceRepairDataStatInfo(@RequestParam(required = false) Map paramMap) {
        try {
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataService.findResourceRepairDataStatInfo(paramMap);
            return R.ok(result);
        } catch (Exception e) {
            return R.failed(e.getMessage());
        }
    }

    /**
     * 每日生产状态报表
     *
     * @param paramMap
     * @return
     */
    @GetMapping("/findProductStateInfo")
    public R findProductStateInfo(@RequestParam(required = false) Map paramMap) {
        try {
            List<Map<String, Object>> result = reportDataService.findProductStateInfo(paramMap);
            return R.ok(result);
        } catch (Exception e) {
            return R.failed(e.getMessage());
        }
    }
    /**
     * 每日生产状态报表
     *
     * @param paramMap
     * @return
     */
    @GetMapping("/workShopPassRate")
    public R findWorkShopPassRate(@RequestParam(required = false) Map paramMap) {
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataService.findWorkShopPassRate(paramMap);
            return R.ok(result);
    }

    @GetMapping("/checkUserPassRate")
    public R findCheckUserPassRate(@RequestParam(required = false) Map paramMap) {
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataService.findCheckUserPassRate(paramMap);
            return R.ok(result);
    }

    @GetMapping("/userPassRate")
    public R findUserPassRate(@RequestParam(required = false) Map paramMap) {
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataService.findUserPassRate(paramMap);
            return R.ok(result);
    }

    @GetMapping("/inspectionDetailPassRate")
    public R findInspectionDetailPassRate(@RequestParam(required = false) Map paramMap) {
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataService.findInspectionDetailPassRate(paramMap);
            return R.ok(result);
    }
    @GetMapping("/sectionPassRate")
    public R findSectionPassRate(@RequestParam(required = false) Map paramMap) {
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataService.findSectionPassRate(paramMap);
            return R.ok(result);
    }

    /**
     * 物料流转
     * @param paramMap
     * @return
     */
    @GetMapping("/selectItemMoveData")
    public R selectItemMoveData(@RequestParam(required = false) Map paramMap) {
        try{
            paramMap.put("site", CommonMethods.getSite());
            List<Map<String, Object>> result = reportDataMapper.selectItemMoveData(paramMap);
            return R.ok(result);
        }catch (Exception e){
            return R.failed(e.getMessage());
        }
    }
    /**
     * 物料流转
     * @param
     * @return
     */
    @PostMapping("/doItemMove")
    public R doItemMove(@RequestBody List<String> list) {
        try{
            if (list == null || list.size() < 1){
                return R.ok("物料流转成功");
            }
            String site = CommonMethods.getSite();
            reportDataMapper.doItemMove(site  , list);
            return R.ok("物料流转成功");
        }catch (Exception e){
            return R.failed(e.getMessage());
        }
    }

}
