package com.prolog.rdc.tms.controller.basicConfigure;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.basicConfigure.StrategyBusinessMatchingDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.StrategyBusinessPageDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.StrategyBusinessViewDTO;
import com.prolog.rdc.tms.model.vo.basicConfigure.*;
import com.prolog.rdc.tms.service.basicConfigure.StrategyBusinessService;
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;

/**
 * 策略中心-业务规则策略
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author zhangsj
 * @since 2022/7/16 9:39
 */
@RestController
@Api(tags = "策略中心-业务规则策略")
@RequestMapping("strategyBusiness")
public class StrategyBusinessController {

    @Autowired
    private StrategyBusinessService strategyBusinessService;

    @UserLog("分页查询")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/page")
    public RestMessage<Page<StrategyBusinessPageDTO>> queryPageExecute(@RequestBody @Valid StrategyBusinessPageVO strategyBusinessPageVO){
        Page<StrategyBusinessPageDTO> page = strategyBusinessService.queryPageData(strategyBusinessPageVO);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("查看")
    @ApiOperation(value = "查看", notes = "查看")
    @PostMapping("/view")
    public RestMessage<StrategyBusinessViewDTO> viewExecute(@RequestBody @Valid StrategyBusinessViewVO strategyBusinessViewVO){
        StrategyBusinessViewDTO dto = strategyBusinessService.viewData(strategyBusinessViewVO);
        return RestMessage.newInstance(true, "查询成功！", dto);
    }

    @UserLog("新增")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public RestMessage<Object> saveExecute(@RequestBody @Valid StrategyBusinessSaveVO strategyBusinessSaveVO){
        strategyBusinessService.saveData(strategyBusinessSaveVO);
        return RestMessage.newInstance(true, "新增成功！", null);
    }

    @UserLog("修改")
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/update")
    public RestMessage<Object> updateExecute(@RequestBody @Valid StrategyBusinessUpdateVO strategyBusinessUpdateVO){
        strategyBusinessService.updateData(strategyBusinessUpdateVO);
        return RestMessage.newInstance(true, "修改成功！", null);
    }

    @UserLog("停用")
    @ApiOperation(value = "停用", notes = "停用")
    @PostMapping("/disable")
    public RestMessage<Object> disableExecute(@RequestBody List<Long> ids){
        strategyBusinessService.disableData(ids);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("启用")
    @ApiOperation(value = "启用", notes = "启用")
    @PostMapping("/active")
    public RestMessage<Object> activeExecute(@RequestBody List<Long> ids){
        strategyBusinessService.activeData(ids);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("匹配")
    @ApiOperation(value = "匹配", notes = "匹配")
    @PostMapping("/matching")
    public RestMessage<List<StrategyBusinessMatchingDTO>> matchingBusinessExecute(@RequestBody StrategyBusinessMatchingVO businessMatchingVO){
        List<StrategyBusinessMatchingDTO> list = strategyBusinessService.matchingData(businessMatchingVO);
        return RestMessage.newInstance(true, "查询成功！", list);
    }
}
