package com.rongwei.bsserver.sys.controller;

import com.rongwei.bscommon.sys.service.EquipmentSendNotifyService;
import com.rongwei.bscommon.sys.utils.ExceptionUtils;
import com.rongwei.bsentity.dto.IdGeneralDTO;
import com.rongwei.rwcommon.base.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author shangmi
 * @title EquipmentSendNotifyController
 * @date 2024/1/18 16:03
 * @description 设备提醒
 */
@RestController
@RequestMapping("/send-notify")
@Slf4j
public class EquipmentSendNotifyController {

    @Autowired
    private EquipmentSendNotifyService sendNotifyService;


    /**
     * 根据任务ID发送保养 提醒
     *
     * @param idGeneralDTO 保养任务ID
     * @return {@link R}
     * @date 2024/1/18 17:16
     * @author shangmi
     */

    @PostMapping("/maintainCreateTaskNotify")
    public R maintainCreateTaskNotify(@RequestBody IdGeneralDTO idGeneralDTO) {
        try {
            log.info("进入接口：/send-notify/maintainCreateTaskNotify;入参为：{}", idGeneralDTO);
            return sendNotifyService.maintainCreateTaskNotify(idGeneralDTO.getId());
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e, "发送消息提醒失败，异常为：");
            log.info(e.getMessage());
            return R.error(e.getMessage());
        }
    }




    /**
     * 根据任务ID发送验收 提醒
     *
     * @param idGeneralDTO 保养任务ID
     * @return {@link R}
     * @date 2024/1/18 17:16
     * @author shangmi
     */

    @PostMapping("/maintainVerifyTaskNotify")
    public R maintainVerifyTaskNotify(@RequestBody IdGeneralDTO idGeneralDTO) {
        try {
            log.info("进入接口：/send-notify/maintainVerifyTaskNotify;入参为：{}", idGeneralDTO);
            return sendNotifyService.maintainVerifyTaskNotify(idGeneralDTO.getId());
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e, "发送消息提醒失败，异常为：");
            log.info(e.getMessage());
            return R.error(e.getMessage());
        }
    }



    /**
     * 根据润滑任务ID发送验收 提醒
     *
     * @param parameter 润滑任务ID
     * @return {@link R}
     * @date 2024/1/18 17:16
     * @author shangmi
     */

    @RequestMapping("/sendLubricationTaskNotifyByIds")
    public R sendLubricationTaskNotifyByIds(@RequestBody Map<String, Object> parameter) {
        try {
            log.info("进入接口：/send-notify/sendLubricationTaskNotifyByIds;入参任务taskIds为：{}", parameter);
            return sendNotifyService.sendLubricationTaskNotifyByIds(parameter);
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e, "发送润滑任务消息提醒失败，异常为：");
            log.info(e.getMessage());
            return R.error(e.getMessage());
        }
    }



    /**
     * 设备部位重复故障问题提醒 repeatEquipmentFaultNotify
     *
     * @return
     */
    @PostMapping("/deviceRepeatedlyFailsNotify")
    public R repeatEquipmentFaultNotify() {
        try {
            log.info("进入接口：/send-notify/deviceRepeatedlyFailsNotify;");
            return sendNotifyService.deviceRepeatedlyFailsNotify();
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e, "发送消息提醒失败，异常为：");
            log.info(e.getMessage());
            return R.error(e.getMessage());
        }
    }


    /**
     * 故障停机提醒
     *
     * @param parameter
     * @return
     */
    @RequestMapping("/faultstopremind")
    public void faultStopRemind(@RequestBody Map<String, String> parameter) {
        try {
            log.info("进入接口：/send-notify/faultStopRemind;入参任务taskIds为：{}", parameter);
            sendNotifyService.sendFaultStopRemind(parameter);
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e, "发送故障停机提醒失败，异常为：");
            log.info(e.getMessage());
        }
    }



    /**
     * 保养/润滑跨月未完成提醒
     *
     * @return {@link R}
     * @date 2024/1/30 15:08
     * @author shangmi
     */
    @Scheduled(cron = "0 0 4 * * 1,3 ")
    @PostMapping("/previousUnfinishedTaskNotify")
    public R previousUnfinishedTaskNotify() {
        try {
            log.info("进入接口：/send-notify/previousUnfinishedTaskNotify;入参为：无");
            return sendNotifyService.previousUnfinishedTaskNotify();
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e, "发送消息提醒失败，异常为：");
            log.info(e.getMessage());
            return R.error(e.getMessage());
        }
    }

    /**
     * 保养/润滑月末未完成提醒
     *
     * @return {@link R}
     * @date 2024/1/30 15:08
     * @author shangmi
     */
    @Scheduled(cron = "0 10 4 25/1 * ? ")
    @PostMapping("/endUnfinishedTaskNotify")
    public R endUnfinishedTaskNotify() {
        try {
            log.info("进入接口：/send-notify/previousUnfinishedTaskNotify;入参为：无");
            return sendNotifyService.endUnfinishedTaskNotify();
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e, "发送消息提醒失败，异常为：");
            log.info(e.getMessage());
            return R.error(e.getMessage());
        }
    }


}
