package com.ho.business.controller;

import com.ho.business.entity.OneClickSequentialControl;
import com.ho.business.service.OneClickSequentialControlService;
import com.ho.business.vo.req.oneClickSequentialControl.OneClickSequentialControlAddReq;
import com.ho.business.vo.req.oneClickSequentialControl.OneClickSequentialControlDeleteReq;
import com.ho.business.vo.req.oneClickSequentialControl.OneClickSequentialControlQueryReq;
import com.ho.business.vo.resp.colCount.ColCountResp;
import com.ho.business.vo.resp.oneClickSequentialControl.OneClickSequentialControlResp;
import com.ho.common.tools.annotation.LogAnnotation;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.exception.DataResult;
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 javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = ContextConstant.BUSINESS + "oneClickSequentialControl")
@Api(tags = "一键顺控")
public class OneClickSequentialControlController {

    @Autowired
    OneClickSequentialControlService controlService;

    @PostMapping("list")
    @ApiOperation(value = "查询一键顺控配置值")
    public DataResult<List<OneClickSequentialControl>> list(@RequestBody OneClickSequentialControlQueryReq vo) {
        List<OneClickSequentialControl> list = controlService.getListByParam(vo,"1");
        return DataResult.success(list);
    }

    @PostMapping("groupList")
    @ApiOperation(value = "查询一键顺控配置值(策略总览页面使用)")
    public DataResult<List<OneClickSequentialControlResp>> groupList(@RequestBody OneClickSequentialControlQueryReq vo) {
        List<OneClickSequentialControlResp> groupList = controlService.getGroupList(vo);
        return DataResult.success(groupList);
    }

    @PostMapping("add")
    @ApiOperation(value = "新增一键顺控配置值")
    @LogAnnotation(title = "一键顺控配置值", action = "新增一键顺控配置值")
    public DataResult add(@RequestBody @Valid OneClickSequentialControlAddReq vo) {
        controlService.addBatch(vo);
        return DataResult.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "更新一键顺控配置值")
    @LogAnnotation(title = "一键顺控配置值", action = "更新一键顺控配置值")
    public DataResult<ColCountResp> update(@RequestBody @Valid OneClickSequentialControlAddReq vo) {
        controlService.updateBatch(vo);
        return DataResult.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除一键顺控配置值")
    @LogAnnotation(title = "一键顺控配置值", action = "删除一键顺控配置值")
    public DataResult<ColCountResp> delete(@RequestBody OneClickSequentialControlDeleteReq vo) {
        controlService.deleteByIds(vo.getIds());
        return DataResult.success();
    }
}
