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

import com.bonus.canteen.core.supply.purchase.domain.param.DrpSupplierQueryDTO;
import com.bonus.canteen.core.supply.purchase.domain.vo.DrpSupplierMainInfoVO;
import com.bonus.canteen.core.supply.purchase.domain.vo.DrpSupplierVO;
import com.bonus.canteen.core.supply.purchase.service.DrpPurchaseSupplierService;
import com.bonus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"/api/v1/drpsupplier"})
@Api(
   value = "gyp_供应商信息管理",
   tags = {"gyp_供应商信息管理"}
)
public class DrpSupplierController {
   private static final Logger log = LoggerFactory.getLogger(DrpSupplierController.class);
   @Autowired
   @Lazy
   private DrpPurchaseSupplierService drpPurchaseSupplierService;
//   @Autowired
//   @Lazy
//   private DrpAuthorityApi drpAuthorityApi;
//   @Autowired
//   @Lazy
//   private DrpMenuMaterialSupplierService drpMenuMaterialSupplierService;
//   @Autowired
//   @Lazy
//   private DrpStagingService drpStagingService;
//   @Autowired
//   @Lazy
//   private ExportApi exportApi;
//
//   @RequiresPermissions({"drp:supplier:insert"})
//   @PostMapping({"/add"})
//   @RequiresAuthentication
//   @ApiOperation("新增供应商信息")
//   public LeResponse<?> addDrpSupplier(@RequestBody @Valid LeRequest<DrpSupplierAddDTO> leRequest) {
//      DrpSupplierAddDTO content = (DrpSupplierAddDTO)leRequest.getContent();
//      this.drpSupplierService.addDrpSupplier(content);
//      return LeResponse.succ();
//   }
//
//   @PostMapping({"/page"})
//   @RequiresAuthentication
//   @ApiOperation("分页获取供应商信息")
//   public LeResponse<Page<DrpSupplierPageVO>> getDrpSupplierPage(@RequestBody LeRequest<DrpSupplierPageDTO> leRequest) {
//      DrpSupplierPageDTO content = (DrpSupplierPageDTO)leRequest.getContent();
//      content.setAreaIdList(this.drpAuthorityApi.authAreaList(content.getAreaIdList()));
//      Page<DrpSupplierPageVO> resultPage = this.drpSupplierService.getDrpSupplierPage(content);
//      return LeResponse.succ(resultPage);
//   }
//
//   @RequiresPermissions({"drp:supplier:update"})
//   @PostMapping({"/edit"})
//   @RequiresAuthentication
//   @ApiOperation("修改供应商信息")
//   public LeResponse<?> editDrpSupplier(@RequestBody @Valid LeRequest<DrpSupplierEditDTO> leRequest) {
//      DrpSupplierEditDTO content = (DrpSupplierEditDTO)leRequest.getContent();
//      this.drpSupplierService.editDrpSupplier(content);
//      return LeResponse.succ();
//   }
//
//   @PostMapping({"/remove/{supplierId}"})
//   @RequiresGuest
//   @ApiOperation("删除供应商信息")
//   @RequiresPermissions({"drp:supplier:delete"})
//   public LeResponse<?> removeBySupplierId(@PathVariable Long supplierId) {
//      this.drpSupplierService.removeBySupplierId(supplierId);
//      return LeResponse.succ();
//   }
//
//   @RequiresPermissions({"drp:supplier:status"})
//   @PostMapping({"/edit/status"})
//   @RequiresAuthentication
//   @ApiOperation("变更供应商状态")
//   public LeResponse<?> editDrpSupplierStatus(@RequestBody @Valid LeRequest<DrpSupplierEditStatusDTO> leRequest) {
//      DrpSupplierEditStatusDTO content = (DrpSupplierEditStatusDTO)leRequest.getContent();
//      this.drpSupplierService.editDrpSupplierStatus(content);
//      return LeResponse.succ();
//   }

   @PostMapping({"/list/supplier"})
   @ApiOperation("查询供应商集合")
   public AjaxResult listSupplier(@RequestBody DrpSupplierQueryDTO content) {
      List<DrpSupplierVO> resultList = this.drpPurchaseSupplierService.listSupplier(content);
      return AjaxResult.success(resultList);
   }
//
//   @PostMapping({"/list/supplierByMaterialId"})
//   @RequiresAuthentication
//   @ApiOperation("根据原料或类别查询供应商集合")
//   public LeResponse<Map<Long, List<DrpSupplierVO>>> supplierByMaterialId(@RequestBody LeRequest<DrpSupplierDTO> leRequest) {
//      return LeResponse.succ(this.drpSupplierService.supplierByMaterialId((DrpSupplierDTO)leRequest.getContent()));
//   }
//
//   @PostMapping({"/comparise/supplier/qualification"})
//   @RequiresAuthentication
//   @ApiOperation("供应商资质对比表")
//   public PageVO<DrpCompariseSupplierQualificationPageVO> compariseSupplierQualification(@RequestBody LeRequest<DrpCompariseSupplierQualificationPageDTO> leRequest) {
//      DrpCompariseSupplierQualificationPageDTO content = (DrpCompariseSupplierQualificationPageDTO)leRequest.getContent();
//      content.setAreaIdList(this.drpAuthorityApi.authAreaList(content.getAreaIdList()));
//      PageMethod.startPage(content);
//      List<DrpCompariseSupplierQualificationPageVO> resultList = this.drpSupplierService.compariseSupplierQualification(content);
//      return PageVO.of(resultList);
//   }
//
//   @PostMapping({"/supply/statistics"})
//   @RequiresAuthentication
//   @ApiOperation("供应商供货情况统计")
//   public PageVO<DrpSupplyStatisticsPageVO> supplyStatistics(@RequestBody LeRequest<DrpSupplyStatisticsPageDTO> leRequest) {
//      DrpSupplyStatisticsPageDTO content = (DrpSupplyStatisticsPageDTO)leRequest.getContent();
//      content.setAreaIdList(this.drpAuthorityApi.authAreaList(content.getAreaIdList()));
//      PageMethod.startPage(content);
//      List<DrpSupplyStatisticsPageVO> resultList = this.drpSupplierService.supplyStatistics(content);
//      return PageVO.of(resultList);
//   }

   @PostMapping({"/get/main/info/{supplierId}"})
   @ApiOperation("获取供应商主要信息接口")
   public DrpSupplierMainInfoVO getMainInfoById(@PathVariable("supplierId") Long supplierId) {
      return this.drpPurchaseSupplierService.getMainInfoById(supplierId);
   }
//
//   @PostMapping({"/getMaterialSupplierPage"})
//   @RequiresAuthentication
//   @ApiOperation("获取原料供应商分页")
//   public PageVO<DrpMaterialSupplierVO> getMaterialSupplier(@RequestBody LeRequest<DrpMaterialInfoDTO> leRequest) {
//      DrpMaterialInfoDTO content = (DrpMaterialInfoDTO)leRequest.getContent();
//      content.setAreaIdList(this.drpAuthorityApi.authAreaList(content.getAreaIdList()));
//      return PageVO.of(this.drpSupplierService.getMaterialSupplier(content));
//   }
//
//   @PostMapping({"/bidMaterialSupplier"})
//   @RequiresAuthentication
//   @ApiOperation("原料绑定供应商")
//   public void bidMaterialSupplier(@RequestBody LeRequest<DrpBidMaterialSupplierDTO> leRequest) {
//      this.drpSupplierService.bidMaterialSupplier((DrpBidMaterialSupplierDTO)leRequest.getContent());
//   }
//
//   @PostMapping({"/getMaterialSupplierByMaterialId"})
//   @RequiresAuthentication
//   @ApiOperation("采购订单获取原料供应商")
//   public List<DrpMaterialSupplierVO> getMaterialSupplierByMaterialId(@RequestBody LeRequest<List<Long>> leRequest) {
//      return this.drpSupplierService.getMaterialSupplierByMaterialId((List)leRequest.getContent());
//   }
//
//   @PostMapping({"/list/supplier/new"})
//   public PageVO<DrpSupplierVO> listSupplierNew(@RequestBody LeRequest<DrpSupplierQueryDTO> request) {
//      DrpSupplierQueryDTO content = (DrpSupplierQueryDTO)request.getContent();
//      content.setAreaIdList(this.drpAuthorityApi.authAreaList(content.getAreaIdList()));
//      return PageVO.of(this.drpSupplierService.listSupplierNew(content));
//   }
//
//   @PostMapping({"/warning"})
//   @RequiresAuthentication
//   @ApiOperation("供应商端-预警信息")
//   public PageVO<DrpInventoryWarningPageVO> inventorySupplierWarning(@RequestBody @Valid LeRequest<DrpInventoryWarningPageDTO> leRequest) {
//      DrpInventoryWarningPageDTO content = (DrpInventoryWarningPageDTO)leRequest.getContent();
//      content.setSupplierId(this.drpAuthorityApi.listSupplierAuthority());
//      content.setWarningTypeList(DrpWarnTypeEnum.supplierWarnTypeList());
//      return PageVO.of(this.drpStagingService.inventoryWarning(content));
//   }
//
//   @PostMapping({"/checkSupplierMaterialCert"})
//   @RequiresAuthentication
//   @ApiOperation("检查供应商是否具备货品资质")
//   public LeResponse<List<DrpSupplierMaterialCertVO>> checkSupplierMaterialCert(@RequestBody @Valid LeRequest<DrpSupplierMaterialCertDTO> leRequest) {
//      DrpSupplierMaterialCertDTO content = (DrpSupplierMaterialCertDTO)leRequest.getContent();
//      return LeResponse.succ(this.drpMenuMaterialSupplierService.checkSupplierMaterialCert(content));
//   }
//
//   @ApiOperation("货品供应商导出")
//   @PostMapping({"/export/materialSupplier"})
//   @RequiresGuest
//   public LeResponse<Object> exportMaterial(@RequestBody LeRequest<DrpMaterialInfoDTO> leRequest) {
//      try {
//         DrpMaterialInfoDTO content = (DrpMaterialInfoDTO)leRequest.getContent();
//         if (!ObjectUtil.isNull(content.getConfigType()) && !ObjectUtil.equal(content.getConfigType(), 1)) {
//            this.exportApi.startExcelExportTaskByPage(content.getCanteenName() + "-类别供应商", content.getCanteenName(), DrpCategorySupplierExportVO.class, (List)null, content, (Object)null, () -> {
//               return PageVO.of(this.drpSupplierService.getMaterialSupplier((DrpMaterialInfoDTO)leRequest.getContent()));
//            }, (x) -> {
//               return (DrpCategorySupplierExportVO)BeanUtil.copyProperties(x, DrpCategorySupplierExportVO.class, new String[0]);
//            });
//         } else {
//            this.exportApi.startExcelExportTaskByPage(content.getCanteenName() + "-货品供应商", content.getCanteenName(), DrpMaterialSupplierExportVO.class, (List)null, content, (Object)null, () -> {
//               return PageVO.of(this.drpSupplierService.getMaterialSupplier((DrpMaterialInfoDTO)leRequest.getContent()));
//            }, (x) -> {
//               return (DrpMaterialSupplierExportVO)BeanUtil.copyProperties(x, DrpMaterialSupplierExportVO.class, new String[0]);
//            });
//         }
//
//         return LeResponse.succ();
//      } catch (Throwable var3) {
//         throw var3;
//      }
//   }
}
