package com.lantone.daqe.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.daqe.dto.GetRegularPageDTO;
import com.lantone.daqe.facade.RegularManagementFacade;
import com.lantone.daqe.vo.AddRegularVO;
import com.lantone.daqe.vo.DelRegularByIdVO;
import com.lantone.daqe.vo.GetRegularPageVO;
import com.lantone.daqe.vo.UpRegularByIdVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
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;

/**
 * @Description: 正则式维护API
 * @author: songxl
 * @time: 2022/3/4 10:39
 */
@RestController
@Api(value = "正则式维护API", tags = { "正则式维护API" })
@RequestMapping("/regularManage")
public class RegularManagementController {

    @Autowired
    private RegularManagementFacade regularManagementFacade;

    @ApiOperation(value = "获取正则式维护分页列表 [by:songxl]", notes = "获取正则式维护分页列表")
    @PostMapping("/getRegularPage")
    public CommonResult<IPage<GetRegularPageDTO>> getRegularPage(@RequestBody GetRegularPageVO getRegularPageVO) {
        return CommonResult.success(regularManagementFacade.getRegularPage(getRegularPageVO));
    }

    @ApiOperation(value = "新增正则式 [by:songxl]", notes = "新增正则式")
    @PostMapping("/addRegular")
    @Transactional
    public CommonResult<Boolean> addRegular(@RequestBody @Valid AddRegularVO addRegularVO) {
        return CommonResult.success(regularManagementFacade.addRegular(addRegularVO));
    }

    @ApiOperation(value = "通过id修改正则式 [by:songxl]", notes = "通过id修改正则式")
    @PostMapping("/upRegularById")
    @Transactional
    public CommonResult<Boolean> upRegularById(@RequestBody @Valid UpRegularByIdVO upRegularByIdVO) {
        return CommonResult.success(regularManagementFacade.upRegularById(upRegularByIdVO));
    }

    @ApiOperation(value = "通过id删除正则式 [by:songxl]", notes = "通过id删除正则式")
    @PostMapping("/delRegularById")
    @Transactional
    public CommonResult<Boolean> delRegularById(@RequestBody @Valid DelRegularByIdVO delRegularByIdVO) {
        return CommonResult.success(regularManagementFacade.delRegularById(delRegularByIdVO));
    }

}