package com.rongwei.bsserver.sys.controller;


import com.rongwei.bscommon.sys.service.EquOverhaulInventoryService;
import com.rongwei.bscommon.sys.utils.ExceptionUtils;
import com.rongwei.rwcommon.base.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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;

/**
 * <p>
 * 设备子系统——备品备件库存 前端控制器
 * </p>
 *
 * @author zdz
 * @since 2023-11-22
 */
@RestController
@RequestMapping("/equOverhaulInventory")
public class EquOverhaulInventoryController {

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

    @Autowired
    private EquOverhaulInventoryService equOverhaulInventoryService;

    /**
     * 系统每个小时更新一次库存数据
     * @return
     */
    @RequestMapping("/initializeInventory")
    public R initializeInventory(){
        try {
            logger.info("系统自动根据创新的库存数据更新到平台库存数据表...");
            equOverhaulInventoryService.initializeInventory();
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e,"系统每个小时更新一次库存数据异常:");
        }
        return R.ok();
    }

    /**
     * 系统每个小时更新一次提醒状态
     * @param map
     * @return
     */
    @RequestMapping("/updateInventoryReminderStatus")
    public R updateInventoryReminderStatus(@RequestBody Map<String,Object> map){
        try {
            logger.info("系统自动根据安全库存信息、过期信息自动更新提醒状态...");
            equOverhaulInventoryService.updateInventoryReminderStatus();
        } catch (Exception e) {
            ExceptionUtils.printExceptionDetail(e,"系统每个小时更新一次提醒状态异常:");
        }
        return R.ok();
    }

}

