package com.lovenav.controller;

import com.lovenav.entity.Config;
import com.lovenav.service.AttachmentService;
import com.lovenav.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class ConfigController {
    //配置文件操作
    @Autowired
    ConfigService configService;
    @Autowired
    AttachmentService attachmentService;
    @RequestMapping("/updateConfig")
    public String updateConfig(Config config){
        Date date=new Date();
        int date1=Integer.valueOf(date.toString());
        config.setUpdatetime(date1);
        if (config==null){
            return "配置文件不能为空！";
        }
        if (configService.updateConfig(config)==1){

            return "更新成功!";
        }
        else if (configService.updateConfig(config)==2){
            return "不存在名称为"+config.getName()+"的配置文件，请先添加！";
        }
        return "更新失败！";
    }
    @RequestMapping("/addConfigString")
    public String addConfig(Config config){
        if (config.getName()==null||config.getValue()==null){
            return "属性值不能为空";
        }else {
            Date date=new Date();
            int date1=Integer.valueOf(date.toString());
            config.setUpdatetime(date1);
            return configService.addConfig(config);
        }

    }
}
