package com.foreverwin.mesnac.anomaly.controller;

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

import com.foreverwin.mesnac.anomaly.service.ReportService;
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")
public class ReportController {

    @Autowired
    public ReportService reportService;

    /**
     * 接口日志表
     * @param map
     * @returnresourceRepair
     */
    @PostMapping("/findIntegrationLog")
    public R findIntegrationLog(@RequestBody(required = false)Map<String, Object> map){
        try{
            return R.ok(reportService.findIntegrationLog(map));
        }catch(Exception e){
            return R.failed(e.getMessage());
        }
    }

    /**
     * 零件加工报表
     * @param map
     * @return
     */
    @PostMapping("/partsManufacturing")
    public R partsManufacturing(@RequestBody(required = false)Map<String, Object> map){
        try{
            return R.ok(reportService.partsManufacturing(map));
        }catch(Exception e){
            return R.failed(e.getMessage());
        }
    }

    /**
     * 余料退回明细表
     * @param item
     * @param itemDescription
     * @return
     */
    @GetMapping("/surplusReturnTable")
    public R surplusReturnTable(String item,String itemDescription){
        try{
            return  R.ok(reportService.surplusReturnTable(item,itemDescription));
        }catch(Exception e){
            return R.failed(e.getMessage());
        }
    }

    /**
     * 设备维修记录报表
     * @param map
     * @return
     */
    @PostMapping("/resourceRepair")
    public R resourceRepair(@RequestBody(required = false)Map map){
        return R.ok(reportService.resourceRepair(map));
    }

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

    /**
     * 质检问题统计表
     * @param paramMap
     * @return
     */
    @PostMapping("/findQualityInspectionReport")
    public R findQualityInspectionReport(@RequestBody(required = false) Map paramMap) {
        try{
            List<Map<String, Object>> result = reportService.findQualityInspectionReport(paramMap);
            return R.ok(result);
        }catch (Exception e){
            return R.failed(e.getMessage());
        }
    }

    /**
     * 异常记录表
     * @param paramMap
     * @return
     */
    @PostMapping("/findAbnormalRecord")
    public R findAbnormalRecord(@RequestBody(required = false) Map paramMap){
        try{
            List<Map<String, Object>> result = reportService.findAbnormalRecord(paramMap);
            return R.ok(result);
        }catch (Exception e){
            return R.failed(e.getMessage());
        }
    }

    /**
     * 工单生产进度报表
     * @param paramMap
     * @return
     */
    @GetMapping("/shopOrderSchedule")
    public R shopOrderSchedule(@RequestParam(required = false) Map paramMap){
        try{
            List<Map<String, Object>> result = reportService.shopOrderSchedule(paramMap);
            return R.ok(result);
        }catch (Exception e){
            return R.failed(e.getMessage());
        }
    }

    @GetMapping("/findOperatorScheduleReport")
    public R findOperatorScheduleReport(@RequestParam(required = false) Map paramMap){
        try{
            return R.ok(reportService.findOperatorScheduleReport(paramMap));
        }catch (Exception e){
            return R.failed(e.getMessage());
        }
    }

    /**
     * 工作令加工进度表
     */
    @GetMapping("/findWorkOrderSchedule")
    public R findWorkOrderSchedule(@RequestParam(required = false) Map paramMap){
        try{
            return R.ok(reportService.findWorkOrderSchedule(paramMap));
        }catch (Exception e){
            return R.failed(e.getMessage());
        }
    }
}
