ManageController.java 2.35 KB
package com.yoho.rfid.controller;

import com.yoho.rfid.model.ClientConfig;
import com.yoho.rfid.model.ManageCommand;
import com.yoho.rfid.service.ManageService;
import com.yoho.rfid.util.ApiResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by sailing on 2017/11/1.
 */
@Controller
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    @RequestMapping("/getSystemConfig")
    @ResponseBody
    public ApiResponse getSystemConfig(){
        return new ApiResponse.ApiResponseBuilder()
                .data(manageService.showSystemConfig())
                .code(200).message("getSystemConfig success").build();
    }

    @RequestMapping("/sendMail/{command}")
    @ResponseBody
    public ApiResponse sendMail(@PathVariable("command")String command){
        if (StringUtils.isBlank(command)){
            return new ApiResponse.ApiResponseBuilder()
                    .code(400).message("sendMail fail, not support this command").build();
        }
        boolean sendMail;
        switch (command){
            case ManageCommand.openSendMail:
                sendMail = true;
                break;
            case ManageCommand.closeSendMail:
                sendMail = false;
                break;
            default:
                return new ApiResponse.ApiResponseBuilder()
                        .code(400).message("sendMail fail, not support this command").build();

        }
        manageService.sendMail(sendMail);
        return new ApiResponse.ApiResponseBuilder()
                .code(200).message("sendMail success").build();
    }
    
    @RequestMapping("/setBussinessDate")
    @ResponseBody
    public ApiResponse setBussinessDate(@RequestBody ClientConfig clientConfig){
        manageService.doBusinessDate(clientConfig);
        return new ApiResponse.ApiResponseBuilder()
                .code(200).message("setBussinessDate success").build();
    }
    
}