package com.rongwei.bsserver.sys.controller;


import com.rongwei.bscommon.sys.service.EquOverhaulPlanningTasksService;
import com.rongwei.bscommon.sys.utils.ExceptionUtils;
import com.rongwei.bscommon.sys.utils.FileCheckUtil;
import com.rongwei.rwcommon.base.R;
import com.rongwei.rwcommon.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * <p>
 * 设备子系统——大修计划任务 前端控制器
 * </p>
 *
 * @author fpy
 * @since 2023-12-20
 */
@RestController
@RequestMapping("/equOverhaulPlanningTasks")
@Slf4j
public class EquOverhaulPlanningTasksController {

    @Autowired
    private EquOverhaulPlanningTasksService equOverhaulPlanningTasksService;

    @Autowired
    FileCheckUtil checkUtil;

    /**
     * 检验规则维护导入
     * @return
     */
    @RequestMapping("/importEquOverhaulPlanningTasks")
    @ResponseBody
    public R importEquOverhaulPlanningTasks(@RequestParam MultipartFile file, HttpServletRequest request) throws Exception {
        if (file == null){
            return R.error("文件解析失败");
        }
        String errorMsg = checkUtil.fileCheckDetail(file,"a02f48e0c8024df1980ee5661c72be10");
        if (StringUtils.isNotBlank(errorMsg)){
            return R.error(errorMsg);
        }
        return equOverhaulPlanningTasksService.importEquOverhaulPlanningTasks(file);
    }

    /**
     * 系统每天早上5：00点发送大修任务提醒
     * @return {@link R}
     * @date 2024/1/18 17:16
     * @author shangmi
     *
     */

    @RequestMapping("/sendPlanTaskNotify")
    public R sendPlanTaskNotify(@RequestBody Map<String, Object> parameter,HttpServletResponse response){
        try {
            log.info("进入接口：/equOverhaulPlanningTasks/sendPlanTaskNotify");
            return equOverhaulPlanningTasksService.sendPlanTaskNotify(response);
        }catch (Exception e){
            ExceptionUtils.printExceptionDetail(e,"系统每天早上5：00点发送大修任务提醒失败，异常为：");
            log.info(e.getMessage());
            return R.error(e.getMessage());
        }
    }
}

