package com.bonus.canteen.core.drp.controller;

import com.bonus.canteen.core.drp.api.DrpAuthorityApi;
import com.bonus.canteen.core.drp.dto.AndroidSearchMaterialDTO;
import com.bonus.canteen.core.drp.service.AndroidInventoryService;
import com.bonus.canteen.core.drp.vo.AndroidSearchMaterialVO;
import com.bonus.canteen.core.drp.vo.DrpListSupplierVO;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.houqin.utils.LeRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import lombok.Generated;
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;
import java.util.Map;

@RestController
@RequestMapping({"/api/v1/android/inventory"})
@Api(
   value = "gyp-电子秤设备接口",
   tags = {"gyp-电子秤设备接口"}
)
public class AndroidInventoryController {
   @Generated
   private static final Logger log = LoggerFactory.getLogger(AndroidInventoryController.class);
   @Autowired
   @Lazy
   private AndroidInventoryService androidInventoryService;
   @Autowired
   @Lazy
   private DrpAuthorityApi drpAuthorityApi;

   @PostMapping({"/search/material"})
   @ApiOperation("电子秤/手持机-根据原料名称模糊查询原料配置信息")
   public AjaxResult searchMaterial(@RequestBody @Valid LeRequest<AndroidSearchMaterialDTO> leRequest, @RequestHeader Map<String, String> headers) {
      log.info("***[电子秤/手持机]_根据原料名称模糊查询原料配置信息**************");
      AndroidSearchMaterialDTO dto = (AndroidSearchMaterialDTO)leRequest.getContent();
      dto.setAreaId(this.drpAuthorityApi.getAreaIdByDeviceSn(headers));
      return new AjaxResult(10000, "成功", this.androidInventoryService.searchMaterial(dto));
   }


   @PostMapping({"/list/supplier"})
   @ApiOperation("电子秤/手持机-供应商列表")
   public AjaxResult androidListSupplier(@RequestHeader Map<String, String> headers) {
      log.info("***[电子秤/手持机]_供应商列表**************");
      Long areaId = this.drpAuthorityApi.getAreaIdByDeviceSn(headers);
      return new AjaxResult(10000, "成功", this.androidInventoryService.androidListSupplier(areaId));
   }

}
