package com.rongwei.bsserver.sys.controller;


import com.rongwei.bscommon.sys.service.EquBomService;
import com.rongwei.bscommon.sys.service.EquMaintenancePredictivePlanService;
import com.rongwei.bscommon.sys.utils.ExceptionUtils;
import com.rongwei.bsentity.dto.EquBomCopyDto;
import com.rongwei.rwcommon.base.R;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.List;
import java.util.Map;


/**
 * <p>
 * 设备子系统—— 预测性保养计划
 * </p>
 *
 * @author hp
 * @since  2024-10-22
 */
@RestController
@RequestMapping("/equMaintenancePredictivePlan")
public class EquMaintenancePredictivePlanController {

    private static final Logger logger = LoggerFactory.getLogger(EquMaintenancePredictivePlanController.class);

    @Autowired
    private EquMaintenancePredictivePlanService equMaintenancePredictivePlanService;


    /**
     * 生成保养任务记录
     * @param ids
     * @return
     */
    @PostMapping("/generateMaintenanceTask")
    public R updateInventoryReminderStatus(@RequestBody List<String> ids){
        try {
            logger.info("预测性保养计划开始生成保养任务记录");
            R r = equMaintenancePredictivePlanService.generateMaintenanceTask(ids);
            logger.info("预测性保养计划结束生成保养任务记录");
            return r;
        } catch (Exception e) {
            logger.error("预测性保养计划生成保养任务记录失败：{}"+e.getMessage());
        }
        return R.ok();
    }


    /**
     * 每天早上5点
     * @return
     */
    @Scheduled(cron = "0 0 5 1/1 * ? ")
   // @Scheduled(cron = "0/15 * * * * ? ")
    public R updateInventoryReminderStatusCron(){
        try {
            logger.info("开始执行定时任务 测性保养计划开始生成保养任务");
            R r = equMaintenancePredictivePlanService.generateMaintenanceTask(null);
            return r;
        } catch (Exception e) {
            logger.error("预测性保养计划生成保养任务记录失败：{}"+e.getMessage());
        }
        return R.ok();
    }


}

