package com.prolog.rdc.tms.controller;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.SysGroupCfgHdrDTO;
import com.prolog.rdc.tms.model.vo.SysGroupCfgSaveVO;
import com.prolog.rdc.tms.model.vo.SysGroupCfgVO;
import com.prolog.rdc.tms.service.SysGroupCfgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * 系统调度分组配置控制层
 *
 * @author xyf
 * @since 2022/4/11 12:23
 */
@RestController
@Api(tags = "系统调度分组配置控制层")
@RequestMapping("/sys_group")
public class SysGroupCfgController {

    @Autowired
    private SysGroupCfgService service;

    @UserLog("分组配置查询")
    @ApiOperation(value = "分组配置查询", notes = "分组配置查询")
    @PostMapping("/query")
    public RestMessage<List<SysGroupCfgHdrDTO>> queryGroupCfg(@RequestBody SysGroupCfgVO vo) {
        try {
            List<SysGroupCfgHdrDTO> list = service.queryGroupCfg(vo);
            return RestMessage.newInstance(true, "查询成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("分组配置保存")
    @ApiOperation(value = "分组配置保存", notes = "分组配置保存")
    @PostMapping("/save")
    public RestMessage<Object> saveGroupCfg(@RequestBody List<SysGroupCfgSaveVO> cfgSaveVOS) {
        try {
            service.saveGroupCfg(cfgSaveVOS);
            return RestMessage.newInstance(true, "保存成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("默认分组配置")
    @ApiOperation(value = "默认分组配置", notes = "默认分组配置")
    @PostMapping("/default")
    public RestMessage<Object> defaultGroup(@RequestBody SysGroupCfgVO cfgVO) {
        try {
            service.defaultGroup(cfgVO);
            return RestMessage.newInstance(true, "设置成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("删除分组配置")
    @ApiOperation(value = "删除分组配置", notes = "删除分组配置")
    @PostMapping("/delete")
    public RestMessage<Object> deleteGroup(@RequestBody SysGroupCfgVO cfgVO) {
        try {
            service.deleteGroup(cfgVO);
            return RestMessage.newInstance(true, "删除成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

}
