package com.prolog.cs.biz.outbound.controller;

import com.prolog.cs.biz.outbound.model.dto.BillDTO;
import com.prolog.cs.biz.outbound.model.dto.BillMergeDTO;
import com.prolog.cs.biz.outbound.model.entity.WaveBillDO;
import com.prolog.cs.biz.outbound.service.BillService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;

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 java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "订单")
@RestController
@RequestMapping("/bill")
public class BillController {

    @Autowired
    private BillService billService;

    @UserLog
    @ApiOperation(value = "更改订单信息")
    @PostMapping("/update")
    public RestMessage<Boolean> updateBills(@RequestBody List<BillDTO> billDTO) {
        return billService.updateBill(billDTO);
    }

    @UserLog
    @ApiOperation(value = "订单查询")
    @PostMapping("/query")
    public RestMessage<Page<WaveBillDO>> query(@RequestBody BillDTO billDTO) {
        return RestMessage.doSuccess(billService.query(billDTO));
    }

    @UserLog
    @ApiOperation(value = "合单查询")
    @PostMapping("/merge/query")
    public RestMessage<List<WaveBillDO>> queryForMerge(@RequestBody BillMergeDTO billMergeDTO) {
        return RestMessage.doSuccess(billService.queryForMerge(billMergeDTO));
    }

    @UserLog
    @ApiOperation(value = "合单")
    @PostMapping("/merge")
    public RestMessage<Boolean> merge(@RequestBody BillMergeDTO billMergeDTO) {
        return RestMessage.doSuccess(billService.merge(billMergeDTO));
    }

    @UserLog
    @ApiOperation(value = "更改波次创建/下发时的订单信息")
    @PostMapping("/wave/update")
    public RestMessage<Boolean> updateWaveBills(@RequestBody List<BillDTO> billDTOs) {
        billService.updateWaveBill(billDTOs);
        return RestMessage.doSuccess(true);
    }
}
