package com.zhongzheng.controller.order;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.common.utils.SecurityUtils;
import com.zhongzheng.modules.order.bo.*;
import com.zhongzheng.modules.order.service.IOrderBillGoodsService;
import com.zhongzheng.modules.order.service.IOrderBillSheetService;
import com.zhongzheng.modules.order.vo.OrderBillGoodsVo;
import com.zhongzheng.modules.order.vo.OrderBillSheetVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 订单计费单Controller
 *
 * @author hjl
 * @date 2021-11-09
 */
@Api(value = "订单计费单控制器", tags = {"订单计费单管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/order/sheet")
public class OrderBillSheetController extends BaseController {

    private final IOrderBillSheetService iOrderBillSheetService;

    private final IOrderBillGoodsService iOrderBillGoodsService;

    /**
     * 查询订单计费单列表
     */
    @ApiOperation("查询订单计费单列表")
    @PreAuthorize("@ss.hasPermi('system:sheet:list')")
    @GetMapping("/list")
    public TableDataInfo<OrderBillSheetVo> list(OrderBillSheetQueryBo bo) {
        startPage();
        List<OrderBillSheetVo> list = iOrderBillSheetService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出订单计费单列表
     */
    /*@ApiOperation("导出订单计费单列表")
    @PreAuthorize("@ss.hasPermi('system:sheet:export')")
    @Log(title = "订单计费单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<OrderBillSheetVo> export(OrderBillSheetQueryBo bo) {
        List<OrderBillSheetVo> list = iOrderBillSheetService.queryList(bo);
        ExcelUtil<OrderBillSheetVo> util = new ExcelUtil<OrderBillSheetVo>(OrderBillSheetVo.class);
        return util.exportExcel(list, "订单计费单");
    }*/

    /**
     * 获取订单计费单详细信息
     */
    @ApiOperation("获取订单计费单详细信息")
    @PreAuthorize("@ss.hasPermi('system:sheet:query')")
    @GetMapping("/{sheetId}")
    public AjaxResult<OrderBillSheetVo> getInfo(@PathVariable("sheetId" ) Long sheetId) {
        return AjaxResult.success(iOrderBillSheetService.queryById(sheetId));
    }

    /**
     * 新增订单计费单
     */
    @ApiOperation("新增订单计费单")
    @PreAuthorize("@ss.hasPermi('system:sheet:add')")
    @Log(title = "订单计费单", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@RequestBody OrderBillSheetAddBo bo) {
        bo.setCreateBy(SecurityUtils.getUsername());
        return AjaxResult.success(iOrderBillSheetService.placeBillOrder(bo));
    }

    /**
     * 修改订单计费单
     */
   /* @ApiOperation("修改订单计费单")
    @PreAuthorize("@ss.hasPermi('system:sheet:edit')")
    @Log(title = "订单计费单", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody OrderBillSheetEditBo bo) {
        return toAjax(iOrderBillSheetService.updateByEditBo(bo) ? 1 : 0);
    }*/

    /**
     * 删除订单计费单
     */
   /* @ApiOperation("删除订单计费单")
    @PreAuthorize("@ss.hasPermi('system:sheet:remove')")
    @Log(title = "订单计费单" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{sheetIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] sheetIds) {
        return toAjax(iOrderBillSheetService.deleteWithValidByIds(Arrays.asList(sheetIds), true) ? 1 : 0);
    }*/

    /**
     * 查询订单计费单商品列表
     */
    @ApiOperation("查询计费单商品详情")
    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/goods")
    public AjaxResult<OrderBillGoodsVo> goods(OrderBillGoodsQueryBo bo) {
        return AjaxResult.success(iOrderBillGoodsService.selectDetail(bo));
    }

    /**
     * 修改订单计费单商品
     */
    @ApiOperation("修改订单计费单商品")
    @PreAuthorize("@ss.hasPermi('system:goods:edit')")
    @Log(title = "订单计费单商品", businessType = BusinessType.UPDATE)
    @PostMapping("/goods/edit")
    public AjaxResult<Void> edit(@RequestBody OrderBillGoodsEditBo bo) {
        return toAjax(iOrderBillGoodsService.updateByEditBo(bo) ? 1 : 0);
    }
}
