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.BmsTimeBillStrategyDTO;
import com.prolog.rdc.tms.model.vo.BmsTimeStrategyQueryVO;
import com.prolog.rdc.tms.model.vo.BmsTimeStrategyVO;
import com.prolog.rdc.tms.model.vo.StatusUpdate;
import com.prolog.rdc.tms.service.TimeBillStrategyService;
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("/timeStrategy")
public class TimeBillStrategyController {

    @Autowired
    private TimeBillStrategyService timeBillStrategyService;

    @UserLog("时间计费策略分页查询")
    @ApiOperation(value = "时间计费策略分页查询", notes = "时间计费策略分页查询")
    @PostMapping("/findList")
    public RestMessage<Page<BmsTimeBillStrategyDTO>> findList(@RequestBody BmsTimeStrategyQueryVO vo) throws Exception {
        Page<BmsTimeBillStrategyDTO> list = timeBillStrategyService.findList(vo);
        return RestMessage.newInstance(true, "操作成功", list);
    }

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

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

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

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

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