package com.rongwei.savecheck.controller;

import com.rongwei.rwcommon.base.R;
import com.rongwei.sfcommon.sys.service.CheckItemsService;
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.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("checkItems")
@Slf4j
public class CheckItemsController {

    @Autowired
    private CheckItemsService checkItemsService;

    /**
     * 设备列表删除验证
     *
     * @param ids
     * @return
     */
    @PostMapping("/deleteValidate")
    public R deleteValidate(@RequestBody List<String> ids) {
        try {
            String warnMes = checkItemsService.deleteValidate(ids);
            Map<String, Object> map = new HashMap<>();
            map.put("warnMes", warnMes);
            return R.ok(map);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    /**
     * 设备定时任务提醒，定时任务每天执行一次，【预计提醒日期】在今天及今天之前的数据，给所有设备管理员角色下的员工提醒（分所属工厂）
     */
    @PostMapping("/reportEquMessage")
    public R reportEquMessage() {
        try {
            checkItemsService.reportEquMessage();
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    @Scheduled(cron = "0 0 3 ? * *")
    @PostMapping("/state")
    public R stateUpdateScheduledTasks() {
        log.info("安全附件定时任务,更改安全附件预警级别");
        return checkItemsService.stateUpdateScheduledTasks();
    }


    @PostMapping("/import")
    public R importExport(@RequestBody Map<String, String> queryParameter) {
        log.info("开始导入安全附件信息");
        return checkItemsService.importExcel(queryParameter);
    }
}
