package com.rongwei.savecheck.controller;


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


@RestController
@RequestMapping("aspRiskSource")
@Slf4j
public class AspRiskSourceController {
    @Autowired
    private AspRiskSourceService aspRiskSourceService;

    /**
     * 导入初始化数据
     *
     * @return
     */
    @GetMapping("/test")
    public R test(@RequestParam Boolean haveJob,String filePath,String category) {
        try {
            aspRiskSourceService.test(haveJob,filePath,category);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(StringUtils.spliceErrorMsg(e), e.fillInStackTrace());
            return R.error();
        }
    }

    /**
     * 定义任务每年的第一天重置 风险源相关数据
     * 定时任务 每天8点
     *
     * @return
     */
    @Scheduled(cron = "1 0 0 1 1 ?")
    @PostMapping("/reset")
    public R resetInfo() {
        log.info("重置风险源相关信息");
        aspRiskSourceService.resetInfo();
        return R.ok();
    }

    @PostMapping("/history/{id}")
    public R updateHistory(@PathVariable("id") String id) {
        log.info("更新风险源历史记录信息");
        return aspRiskSourceService.updateHistory(id);
    }

}
