package com.benyun.project.third.longxiang.controller;

import com.benyun.framework.web.controller.BaseController;
import com.benyun.framework.web.domain.AjaxResult;
import com.benyun.project.third.byKingdeeConfig.domain.ByKingdeeConfig;
import com.benyun.project.third.byKingdeeConfig.mapper.ByKingdeeConfigMapper;
import com.benyun.project.third.longxiang.service.LongXiangService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/system/kingdee")
@Component("kingdee")
@Slf4j
public class LongXiangController extends BaseController {

    private final String SYS = "LongXiangController.";

    @Autowired
    private LongXiangService longXiangService;

    @Autowired
    private ByKingdeeConfigMapper byKingdeeConfigMapper;


    //销售出库单同步
    @RequestMapping("/orderSync")
    @ResponseBody
    public AjaxResult orderSync() {
        try {
            //销售出库单同步
            longXiangService.createOrder();
            //其他出库单同步
            longXiangService.orderOtherSync();
            //直接调拨单同步
            longXiangService.syncTransferDirect();
        } catch (Exception e) {
            log.error(SYS + "orderSync.error:" + e.getMessage());
        }
        return AjaxResult.success();
    }

    //销售其他出库单同步
    @RequestMapping("/orderOtherSync")
    @ResponseBody
    public AjaxResult orderOtherSync() {
        try {
            return longXiangService.orderOtherSync();
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }


    //金蝶直接调拨单同步到WMS库存
    @RequestMapping("/syncTransferDirect")
    @ResponseBody
    public AjaxResult syncTransferDirect() {

        return longXiangService.syncTransferDirect();
    }

    //商品批量同步   单个商品同步
    @RequestMapping("/skuSync")
    @ResponseBody
    public AjaxResult skuSync() {
        try {
            return longXiangService.skuSync(null);
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }



    //获取omsopen的配置信息
    @RequestMapping("/getOmsOpenConfig")
    @ResponseBody
    public AjaxResult getOmsOpenConfig() {
        try {
            List<ByKingdeeConfig> res = byKingdeeConfigMapper.selectByKingdeeConfigListAll();
            return AjaxResult.success(res);
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }



    //通过金蝶物料id获取物料信息
    @PostMapping("/getKingdeeSkuInfoById")
    @ResponseBody
    public AjaxResult getKingdeeSkuInfoById(String skuId) {
        return longXiangService.getKingdeeSkuInfoById(skuId);
    }


}
