package com.takensoft.pohangTp.hwaSin.web;

import com.takensoft.pohangTp.hwaSin.service.HwaSinService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;

@Controller
public class HwaSinController {

    private final HwaSinService hwaSinService;

    public HwaSinController(HwaSinService hwaSinService) {
        this.hwaSinService = hwaSinService;
    }

    /**
     * 시간대별 평균 길이 Z축 마모
     *
     * @author 김성훈
     * @since 2024.01.18
     */
    @RequestMapping(value = "/hwaSin/timeZWear.json" , method = RequestMethod.POST)
    public ModelAndView timeZWear (@RequestBody HashMap<String, Object> params) throws Exception {
        String tl_no = null;
        if(params.get("tl_no") != null) {
            tl_no = params.get("tl_no").toString();
        }
        ModelAndView mav = new ModelAndView("jsonView");
        System.out.println("tl_no = " + tl_no);
        mav.addObject("timeZWear", hwaSinService.timeZWear(tl_no));
        return mav;
    }

    /**
     * 월별 평균 길이 Z축 마모
     *
     * @author 김성훈
     * @since 2024.01.18
     */
    @RequestMapping(value = "/hwaSin/monthZWear.json" , method = RequestMethod.POST)
    public ModelAndView monthZWear (@RequestBody HashMap<String, Object> params) throws Exception {
        String tl_no = null;
        if(params.get("tl_no") != null) {
            tl_no = params.get("tl_no").toString();
        }
        ModelAndView mav = new ModelAndView("jsonView");
        System.out.println("tl_no = " + tl_no);
        mav.addObject("monthZWear", hwaSinService.monthZWear(tl_no));
        return mav;
    }

    /**
     * 가동시간에 따른 각 툴별(도구) 길이 Z,X축 마모
     *
     * @author 김성훈
     * @since 2024.01.22
     */
    @RequestMapping(value = "/hwaSin/toolWear.json" , method = RequestMethod.POST)
    public ModelAndView toolWear () throws Exception {
        ModelAndView mav = new ModelAndView("jsonView");
        mav.addObject("toolZWear", hwaSinService.toolZWear());
        mav.addObject("toolXWear", hwaSinService.toolXWear());
        return mav;
    }
}
