package com.bonus.canteen.core.supply.purchase.controller;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.supply.purchase.domain.param.DrpOrderGoodsPageDTO;
import com.bonus.canteen.core.supply.purchase.domain.param.DrpOrderGoodsSaveDTO;
import com.bonus.canteen.core.supply.purchase.domain.vo.DrpOrderGoodsPageVO;
import com.bonus.canteen.core.supply.purchase.service.DrpOrderGoodsDetailService;
import com.bonus.canteen.core.supply.purchase.service.DrpPuchaseOrderGoodsService;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping({"/api/v1/drp-order-goods"})
@Api(
   value = "gyp_采购订单",
   tags = {"gyp_采购订单"}
)
public class DrpOrderGoodsController extends BaseController {
   @Autowired
   @Lazy
   private DrpPuchaseOrderGoodsService drpPuchaseOrderGoodsService;
   @Autowired
   @Lazy
   private DrpOrderGoodsDetailService drpOrderGoodsDetailService;

   @PostMapping({"/add/save"})
   @ApiOperation("新增/编辑采购订单")
   public AjaxResult addSaveDrpOrderGoods(@RequestBody @Valid DrpOrderGoodsSaveDTO content) {
      return AjaxResult.success(this.drpPuchaseOrderGoodsService.addSaveDrpOrderGoods(content));
   }

   @PostMapping({"/add/commit"})
   @ApiOperation("新增/编辑采购订单提交")
   public AjaxResult addCommitDrpOrderGoods(@RequestBody @Valid DrpOrderGoodsSaveDTO content) {
      return AjaxResult.success(this.drpPuchaseOrderGoodsService.addCommitDrpOrderGoods(content));
   }

   @PostMapping({"/page"})
   @ApiOperation("分页查询采购订单")
   public TableDataInfo getDrpOrderGoodsPage(@RequestBody @Valid DrpOrderGoodsPageDTO content) {
      startPage();
      List<DrpOrderGoodsPageVO> drpOrderGoodsList = this.drpPuchaseOrderGoodsService.getDrpOrderGoodsList(content);
      return getDataTable(drpOrderGoodsList);
   }

   @PostMapping({"/info/{orderGoodsId}"})
   @ApiOperation("查看采购订单详情")
   public AjaxResult getDrpOrderGoodsInfo(@PathVariable("orderGoodsId") String orderGoodsId) {
      return AjaxResult.success(this.drpPuchaseOrderGoodsService.getDrpOrderGoodsInfo(orderGoodsId));
   }

   @PostMapping({"/delete/{orderGoodsId}"})
   @ApiOperation("删除采购订单")
   public AjaxResult deleteDrpOrderGoods(@PathVariable("orderGoodsId") String orderGoodsId) {
      this.drpPuchaseOrderGoodsService.deleteDrpOrderGoods(orderGoodsId);
      return AjaxResult.success();
   }

   @PostMapping({"/detail/list"})
   @ApiOperation("根据采购订单号获取明细信息")
   public AjaxResult getOrderGoodsDetailList(@RequestBody @Valid String orderGoodsId) {
      if (ObjectUtil.isEmpty(orderGoodsId)) {
         throw new ServiceException("采购订单号为空");
      } else {
         return AjaxResult.success(this.drpOrderGoodsDetailService.getDrpOrderGoodsDetailVOListByOrderGoodsId(orderGoodsId));
      }
   }

   @PostMapping({"/cancel/{orderGoodsId}"})
   @ApiOperation("撤销采购订单")
   public AjaxResult cancelPurOrder(@PathVariable("orderGoodsId") String orderGoodsId) {
      this.drpPuchaseOrderGoodsService.cancelPurOrder(orderGoodsId);
      return AjaxResult.success();
   }

//   @PostMapping({"/import/excel"})
//   @ApiOperation("excel导入采购订单功能")
//   public LeResponse<String> importIntoExcel(@RequestParam("file") MultipartFile excel) {
//      if (ObjectUtil.isNull(excel)) {
//         return LeResponse.fail(I18n.getMessage("drp.select-import-file", new Object[0]));
//      } else {
//         this.drpOrderGoodsService.importOrderGoodsExcel(excel);
//         return LeResponse.succ();
//      }
//   }

//   @PostMapping({"/merge/export"})
//   @RequiresAuthentication
//   @ApiOperation("采购订单合并导出")
//   public LeResponse<Object> mergeExport(@RequestBody @Valid LeRequest<List<String>> leRequest, HttpServletResponse response) {
//      this.drpOrderGoodsService.mergeExport((List)leRequest.getContent(), response);
//      return LeResponse.succ();
//   }
}
