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

import com.prolog.cs.biz.outbound.model.BillSortRuleVO;
import com.prolog.cs.biz.outbound.model.dto.BillSortRuleDto;
import com.prolog.cs.biz.outbound.service.BillSortRuleService;
import com.prolog.cs.biz.outbound.utils.MyExcelExportUtil;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author
 * @date 2022/7/22   19:30
 */
@Slf4j
@Api(tags = "订单排序规则")
@RestController
@RequestMapping("/rule")
public class BillSortRuleController {

    @Resource
    private BillSortRuleService billSortRuleService;

    @UserLog
    @ApiOperation(value = "查询订单排序规则集合")
    @PostMapping("/queryBillSortRuleList")
    public RestMessage<List<BillSortRuleVO>> queryBillSortRuleList(@RequestBody BillSortRuleVO billSortRuleVO) {
        return RestMessage.success("操作成功", billSortRuleService.queryBillSortRuleList(billSortRuleVO));
    }

    @UserLog
    @ApiOperation(value = "保存订单排序规则")
    @PostMapping("/saveBillSortRule")
    public RestMessage<Boolean> saveBillSortRule(@RequestBody BillSortRuleDto billSortRuleDto) {
        Boolean result = billSortRuleService.saveBillSortRule(billSortRuleDto);
        return RestMessage.doSuccess(result);
    }

    @ResponseBody
    @ApiOperation(value = "导出订单排序规则集合")
    @PostMapping("/export")
    public void exportBillSortRule(HttpServletResponse response) {
        try {
            BillSortRuleVO billSortRuleVO = new BillSortRuleVO();
            List<BillSortRuleVO> result = billSortRuleService.queryBillSortRuleList(billSortRuleVO);
            MyExcelExportUtil.exportExcel(result,BillSortRuleDto.class,"订单规则基本信息","订单规则基本信息",response);
        } catch (Exception e) {
            log.info("订单排序规则导出失败");
        }
    }
}
