package com.aucma.api.controller;

import com.aucma.api.domain.dto.SAPPortDto;
import com.aucma.api.domain.dto.WERKSDto;
import com.aucma.api.service.ISAPPortService;
import com.aucma.base.domain.BaseDeviceLedger;
import com.aucma.base.domain.BaseMaterialInfo;
import com.aucma.base.domain.BaseOrderInfo;
import com.aucma.base.domain.OrderBomInfo;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author YinQ
 * @create 2023-09-26 14:29
 */
@RestController
@RequestMapping("/sap/port")
public class SAPPortController extends BaseController {

    @Autowired
    private ISAPPortService sapPortService;

    /**
     * 获取SAP物料主数据
     * @param paramMap
     * @return
     */
    @PostMapping("/getSAPMaterialData")
    public AjaxResult getSAPMaterialData(@RequestBody Map paramMap) {
        SAPPortDto sapPortDto = new SAPPortDto();
        sapPortDto.setStartDate(String.valueOf(paramMap.get("NDATE")));
        sapPortDto.setEndDate(String.valueOf(paramMap.get("EDATE")));
        HashMap<String,List<HashMap<String,String>>> werksMap = (HashMap<String,List<HashMap<String,String>>>)paramMap.get("WERKS");
        WERKSDto werksDto = new WERKSDto();
        werksDto.setItem(werksMap.get("item"));
        sapPortDto.setFactoryCodes(werksDto);
        List<BaseMaterialInfo> materialVoList = sapPortService.getSAPMaterialData(sapPortDto);
        return AjaxResult.success(materialVoList);
    }

    /**
     * 获取生产工单
     * @param paramMap
     * @return
     */
    @PostMapping ("/getProduceWorkTickets")
    public AjaxResult getProduceWorkTickets(@RequestBody Map paramMap){
        SAPPortDto sapPortDto = new SAPPortDto();
        sapPortDto.setStartDate(String.valueOf(paramMap.get("NDATE")));
        sapPortDto.setEndDate(String.valueOf(paramMap.get("EDATE")));
        HashMap<String,List<HashMap<String,String>>> werksMap = (HashMap<String,List<HashMap<String,String>>>)paramMap.get("WERKS");
        WERKSDto werksDto = new WERKSDto();
        werksDto.setItem(werksMap.get("item"));
        sapPortDto.setFactoryCodes(werksDto);
        sapPortService.getSapBaseOrderInfo(sapPortDto);
        List<BaseOrderInfo> BaseOrderInfoVoList = sapPortService.getSapBaseOrderInfo(sapPortDto);
        return AjaxResult.success(BaseOrderInfoVoList);
    }

    /**
     * 获取设备台账
     * @param paramMap
     * @return
     */
    @PostMapping("/getDeviceLedger")
    public AjaxResult getdeviceLedger(@RequestBody Map paramMap) {
        SAPPortDto sapPortDto = new SAPPortDto();
        sapPortDto.setStartDate(String.valueOf(paramMap.get("NDATE")));
        sapPortDto.setEndDate(String.valueOf(paramMap.get("EDATE")));
        HashMap<String,List<HashMap<String,String>>> werksMap = (HashMap<String,List<HashMap<String,String>>>)paramMap.get("WERKS");
        WERKSDto werksDto = new WERKSDto();
        werksDto.setItem(werksMap.get("item"));
        sapPortDto.setFactoryCodes(werksDto);
        List<BaseDeviceLedger> BaseDeviceLedgerVoList = sapPortService.getSapDeviceLedgers(sapPortDto);
        return AjaxResult.success(BaseDeviceLedgerVoList);
    }

    /**
     * 获取产品bom信息
     * @param paramMap
     * @return
     */
    @PostMapping("/getBaseBomInfo")
    public AjaxResult getBaseBomInfo(@RequestBody Map paramMap) {
        SAPPortDto sapPortDto = new SAPPortDto();
        sapPortDto.setStartDate(String.valueOf(paramMap.get("NDATE")));
        sapPortDto.setEndDate(String.valueOf(paramMap.get("EDATE")));
        HashMap<String,List<HashMap<String,String>>> werksMap = (HashMap<String,List<HashMap<String,String>>>)paramMap.get("WERKS");
        WERKSDto werksDto = new WERKSDto();
        werksDto.setItem(werksMap.get("item"));
        sapPortDto.setFactoryCodes(werksDto);
        List<OrderBomInfo> BaeeBomVoList = sapPortService.getSapOrderBomInfo(sapPortDto);
        return AjaxResult.success(BaeeBomVoList);
    }


}
