package com.template.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.template.annotation.DESRespondSecret;
import com.template.api.SmartAskForLeaveConfigControllerAPI;
import com.template.model.dto.AskConfigDto;
import com.template.model.pojo.SmartAskForLeaveConfig;
import com.template.model.result.CommonResult;
import com.template.services.SmartAskForLeaveConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ceshi
 * @since 2024-05-24
 */
@RestController
@DESRespondSecret
public class SmartAskForLeaveConfigController implements SmartAskForLeaveConfigControllerAPI {

    @Autowired
    SmartAskForLeaveConfigService smartAskForLeaveConfigService;

    @Override
    public CommonResult list() {
        SmartAskForLeaveConfig smartAskForLeaveConfig=smartAskForLeaveConfigService.getList();

        return CommonResult.ok(smartAskForLeaveConfig);

    }

    @Override
    public CommonResult update(AskConfigDto askConfigDto) {
        int id = askConfigDto.getId();
        SmartAskForLeaveConfig ask = smartAskForLeaveConfigService.getById(id);
        if (ObjectUtils.isEmpty(ask)) {
            return CommonResult.fail("不存在该id");
        }
        ask.setConfig(askConfigDto.getConfig());
        boolean update = smartAskForLeaveConfigService.updateById(ask);
        if (update) {
            return CommonResult.ok();
        }else{
            return CommonResult.fail();
        }

    }
}

