package com.prolog.rdc.tms.controller;

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.BmsProportionBillStrategyDTO;
import com.prolog.rdc.tms.model.vo.BmsProportionStrategyQueryVO;
import com.prolog.rdc.tms.model.vo.BmsProportionStrategyVO;
import com.prolog.rdc.tms.model.vo.StatusUpdate;
import com.prolog.rdc.tms.service.ProportionBillStrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "策略中心-比例计费策略")
@RestController
@RequestMapping("/proportionStrategy")
public class ProportionBillStrategyController {

    @Autowired
    private ProportionBillStrategyService proportionBillStrategyService;

    @UserLog("比例策略分页查询")
    @ApiOperation(value = "比例策略分页查询", notes = "比例策略分页查询")
    @PostMapping("/findList")
    public RestMessage<Page<BmsProportionBillStrategyDTO>> findList(@RequestBody BmsProportionStrategyQueryVO vo) throws Exception {
        Page<BmsProportionBillStrategyDTO> list = proportionBillStrategyService.findList(vo);
        return RestMessage.newInstance(true, "操作成功", list);
    }

    @UserLog("比例策略新增")
    @ApiOperation(value = "比例策略新增", notes = "比例策略新增")
    @PostMapping("/save")
    public RestMessage<Object> save(@RequestBody BmsProportionStrategyVO vo) throws Exception {
        proportionBillStrategyService.save(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("比例策略查询详情")
    @ApiOperation(value = "比例策略查询详情", notes = "比例策略查询详情")
    @PostMapping("/detail")
    public RestMessage<BmsProportionBillStrategyDTO> detail(@RequestParam(value = "id") Long id) throws Exception {
        BmsProportionBillStrategyDTO dto =  proportionBillStrategyService.detail(id);
        return RestMessage.newInstance(true, "操作成功", dto);
    }

    @UserLog("比例策略修改")
    @ApiOperation(value = "比例策略修改", notes = "比例策略修改")
    @PostMapping("/update")
    public RestMessage<Object> update(@RequestBody BmsProportionStrategyVO vo) throws Exception {
        proportionBillStrategyService.update(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("比例策略状态修改")
    @ApiOperation(value = "比例策略状态修改", notes = "比例策略状态修改")
    @PostMapping("/updateStatus")
    public RestMessage<Object> updateStatus(@RequestBody List<StatusUpdate> vo) throws Exception {
        proportionBillStrategyService.updateStatus(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("比例策略删除")
    @ApiOperation(value = "比例策略删除", notes = "比例策略删除")
    @PostMapping("/delete")
    public RestMessage<Object> delete(@RequestBody String[] ids) {
        proportionBillStrategyService.delete(ids);
        return RestMessage.newInstance(true, "操作成功", null);
    }
}