package com.rongwei.savecheck.controller;

import com.rongwei.rwcommon.base.R;
import com.rongwei.rwcommon.utils.StringUtils;
import com.rongwei.sfcommon.sys.service.impl.SafeCheckSendNotifyServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * SendNotifyController class
 *
 * @author XH
 * @date 2023/12/15
 */
@RestController
@RequestMapping("/notify")
@Slf4j
public class SafeSendNotifyController {

    @Autowired
    private SafeCheckSendNotifyServiceImpl sendNotifyService;

    @PostMapping("/dangerousDailyNotify")
    public R dangerousNotify(){
        log.info("开始发送每日危险作业处罚提醒");
        sendNotifyService.dangerousDailyNotify();
        return R.ok();
    }


    @PostMapping("/dangerousNotify/{id}")
    public R dangerousTimelyNotify(@PathVariable String id) {
        try {
            log.info("开始即使发送危险作业处罚提醒");
            return sendNotifyService.sendDangerousTimelyNotify(id);
        } catch (Exception e) {
            log.error(StringUtils.spliceErrorMsg(e), e.fillInStackTrace());
            return R.queryError();
        }

    }

    /**
     * 开始生成检查任务提醒
     */
    @PostMapping("/inspection")
    public R inspectionTasks(){
        log.info("开始生成检查任务提醒");
        sendNotifyService.inspectionTasks();
        return R.ok();
    }


    /**
     * 隐患任务整改提醒 系统
     * 定时任务 每天8点
     * @param
     * @return
     * @date 2023/12/20 9:55
     * @author shangmi
     *
     */

    @Scheduled(cron = "0 0 8 ? * *")
    @PostMapping("/rectification/system")
    public R rectificationSystem(){
        log.info("隐患跟踪任务整改提现定时任务！");
        sendNotifyService.rectificationSystem();
        return R.ok();
    }

    /**
     * 隐患任务验证提醒 系统
     * 定时任务 每天8点
     * @param
     * @return
     * @date 2023/12/20 9:55
     * @author shangmi
     *
     */

    @Scheduled(cron = "0 0 8 ? * *")
    @PostMapping("/verify/system")
    public R verifySystem(){
        log.info("隐患跟踪任务整改提醒定时任务！");
        sendNotifyService.verifySystem();
        return R.ok();
    }

    /**
     * 隐患任务确认提醒 系统
     * 定时任务 每天8点
     * @param
     * @return
     * @date 2023/12/20 9:55
     * @author shangmi
     *
     */

    @Scheduled(cron = "0 0 8 ? * *")
    @PostMapping("/affirm/system")
    public R affirmSystem(){
        log.info("隐患跟踪任务整改提醒定时任务！");
        sendNotifyService.affirmSystem();
        return R.ok();
    }

    /**
     * 退回提醒
     * @param
     * @return
     * @date 2023/12/20 9:55
     * @author shangmi
     *
     */

    @PostMapping("/send-back/system")
    public R sendBackSystem(@RequestBody Map<String, String> map){
        log.info("隐患跟踪任务退回时提醒！参数为：{}",map);
        sendNotifyService.sendBackSystem(map);
        return R.ok();
    }


    /**
     * 提交提醒
     * @param
     * @return
     * @date 2023/12/20 9:55
     * @author shangmi
     *
     */

    @PostMapping("/submit/system")
    public R submitSystem(@RequestBody Map<String, String> map){
        log.info("隐患跟踪任务提交时提醒！参数为：{}",map);
        sendNotifyService.submitSystem(map);
        return R.ok();
    }

    @Scheduled(cron = "0 0 7 ? * WED,FRI")
    @PostMapping("/hidden/danger")
    public R hiddenDangerTak(){
        log.info("点巡检隐患任务提醒");
        sendNotifyService.hiddenDangerTask();
        return R.ok();
    }

}
