package com.rongwei.savecheck.controller;

import com.rongwe.scentity.domian.CheckItemContentDo;
import com.rongwei.rwcommon.base.R;
import com.rongwei.sfcommon.sys.service.CheckTemplateItemsService;
import com.rongwei.sfcommon.sys.service.HiddenDangerTrackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * 镁铝自定义Controller
 *
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2020-07-17 09:33:23
 */
@RestController
@RequestMapping("saveCheckApi")
@Slf4j
public class SaveCheckApiController {

    @Autowired
    private CheckTemplateItemsService checkTemplateItemsService;
    @Autowired
    private HiddenDangerTrackService hiddenDangerTrackService;

    /**
     * 检查项修改同步修改最新模板中的检查项
     *
     * @param checkItemContent
     * @return
     */
    @PostMapping("/updateTemplateContent")
    public R updateTemplateContent(@RequestBody CheckItemContentDo checkItemContent) {
        try {
            checkTemplateItemsService.updateTemplateContent(checkItemContent);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }

    /**
     * 任务预警状态设定以及提醒
     *
     * @param map
     * @return
     */
    @PostMapping("/limitedRectificationWarn")
    public R limitedRectificationWarn(@RequestBody Map<String, Object> map) {
        try {
            hiddenDangerTrackService.limitedRectificationWarn();
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }

    /**
     * 任务预警状态设定以及提醒
     *
     * @param dataMap
     * @return
     */
    @PostMapping("/sendMailAfterClose")
    public R sendMailAfterClose(@RequestBody Map<String, Object> dataMap) {
        try {
            hiddenDangerTrackService.sendMailAfterClose(dataMap);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }

    /**
     * 发送邮件给跟踪人
     *
     * @param dataMap
     * @return
     */
    @PostMapping("/sendMailTostalker")
    public R sendMailTostalker(@RequestBody Map<String, Object> dataMap) {
        try {
            hiddenDangerTrackService.sendMailTostalker(dataMap);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }

}
