package com.ruoyi.web.controller.business;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.ruoyi.business.domain.*;
import com.ruoyi.business.service.*;
import com.ruoyi.business.utils.EbsUtils;
import com.ruoyi.business.utils.OrderCodeFactory;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.web.service.DictService;
import com.ruoyi.system.service.ISysConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库物料明细Controller
 * 
 * @author tony.wu
 * @date 2022-05-31
 */
@Controller
@RequestMapping("/business/pickingwavegoods")
public class TCkPickingwavegoodsController extends BaseController
{
    private String prefix = "business/pickingwavegoods";

    @Autowired
    private ITCkPickingwavegoodsService tCkPickingwavegoodsService;

    @Autowired
    private ITConveyorStatusService itConveyorStatusService;

    @Autowired
    private ITCkOrderdetailService tCkOrderdetailService;

    @Autowired
    private ITMiStockService tMiStockService;

    @Autowired
    private ITEbsRecordService tEbsRecordService;

    @Autowired
    private ISysConfigService configService;

    @Autowired
    private ITBaseStorageAreaLocationService locationService;

    @Autowired
    private DictService dict;

    @RequiresPermissions("business:pickingwavegoods:view")
    @GetMapping()
    public String pickingwavegoods(ModelMap mmap)
    {
        // 获取当前用户
        SysUser sysUser = ShiroUtils.getCurrentUser();
        mmap.put("sysUser", sysUser);
        mmap.put("tMiStock", new TMiStock());
        return prefix + "/pickingwavegoods";
    }

    /**
     * 查询出库物料明细列表
     */
    @RequiresPermissions("business:pickingwavegoods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TCkPickingwavegoods tCkPickingwavegoods)
    {
        startPage();
        List<TCkPickingwavegoods> list = tCkPickingwavegoodsService.selectTCkPickingwavegoodsList(tCkPickingwavegoods);
        return getDataTable(list);
    }

    /**
     * 导出出库物料明细列表
     */
    @RequiresPermissions("business:pickingwavegoods:export")
    @Log(title = "导出出库物料明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TCkPickingwavegoods tCkPickingwavegoods)
    {
        List<TCkPickingwavegoods> list = tCkPickingwavegoodsService.selectTCkPickingwavegoodsList(tCkPickingwavegoods);
        ExcelUtil<TCkPickingwavegoods> util = new ExcelUtil<TCkPickingwavegoods>(TCkPickingwavegoods.class);
        return util.exportExcel(list, "出库物料明细数据");
    }

    /**
     * 新增出库物料明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出库物料明细
     */
    @RequiresPermissions("business:pickingwavegoods:add")
    @Log(title = "出库物料明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    public AjaxResult addSave(TCkPickingwavegoods tCkPickingwavegoods)
    {
        TMiStock stockForQuery = new TMiStock();
        stockForQuery.setGoodsId(tCkPickingwavegoods.getGoodId());
        stockForQuery.setProduclotid(tCkPickingwavegoods.getProduclotid());
        stockForQuery.setSts("0");

        BigDecimal allNum = tCkPickingwavegoods.getPickingNum();
        List<TMiStock> stocks = tMiStockService.selectTMiStockList(stockForQuery);
        for (TMiStock stock : stocks) {
            if (allNum.compareTo(stock.getShelvesNum()) > 0) {
                stock.setFlag("1");
                tMiStockService.updateTMiStock(stock);
                // 填写库存信息
                TCkPickingwavegoods temp = new TCkPickingwavegoods();
                temp.setGoodId(tCkPickingwavegoods.getGoodId());
                temp.setProduclotid(tCkPickingwavegoods.getProduclotid());
                temp.setGoodsName(stock.getGoodsName());
                temp.setMistockNum(stock.getShelvesNum());
                temp.setPickingNum(stock.getShelvesNum());
                temp.setLocId(stock.getLocationId());
                temp.setProductionDate(stock.getProductionDate());
                temp.setExpiryDate(stock.getExpirationDate());
                temp.setCtl(stock.getCtl());
                temp.setPickingid(OrderCodeFactory.getOrderCode("CK", ""));
                temp.setPutinId(stock.getPutinId());
                temp.setSts("0");
                temp.setOutstatus("0");
                // 获取用户名
                SysUser sysUser = ShiroUtils.getCurrentUser();
                temp.setUserName(sysUser.getUserName());
                temp.setCreateTime(new Date());
                temp.setOutstand(selectOutStand(stock.getLocationId()));
                temp.setCkType("6");
                if (tCkPickingwavegoodsService.insertTCkPickingwavegoods(temp) < 1) {
                    stock.setFlag("0");
                    tMiStockService.updateTMiStock(stock);
                    return error("生成出库任务失败，请重试");
                }
                allNum = allNum.subtract(stock.getShelvesNum());
            } else {
                stock.setFlag("1");
                tMiStockService.updateTMiStock(stock);
                // 填写库存信息
                TCkPickingwavegoods temp = new TCkPickingwavegoods();
                temp.setGoodId(tCkPickingwavegoods.getGoodId());
                temp.setProduclotid(tCkPickingwavegoods.getProduclotid());
                temp.setGoodsName(stock.getGoodsName());
                temp.setMistockNum(stock.getShelvesNum());
                temp.setPickingNum(allNum);
                temp.setLocId(stock.getLocationId());
                temp.setProductionDate(stock.getProductionDate());
                temp.setExpiryDate(stock.getExpirationDate());
                temp.setCtl(stock.getCtl());
                temp.setPickingid(OrderCodeFactory.getOrderCode("CK", ""));
                temp.setPutinId(stock.getPutinId());
                temp.setSts("0");
                temp.setOutstatus("0");
                // 获取用户名
                SysUser sysUser = ShiroUtils.getCurrentUser();
                temp.setUserName(sysUser.getUserName());
                temp.setCreateTime(new Date());
                temp.setOutstand(selectOutStand(stock.getLocationId()));
                temp.setCkType("6");
                if (tCkPickingwavegoodsService.insertTCkPickingwavegoods(temp) < 1) {
                    stock.setFlag("0");
                    tMiStockService.updateTMiStock(stock);
                    return error("生成出库任务失败，请重试");
                }
                break;
            }

        }
        return success("生成出库任务成功");
    }

    /**
     * 判断哪个站台
     * @param locationId 库位编号
     * @return 对应的出库站台
     */
    public String selectOutStand(String locationId){
         TBaseStorageAreaLocation location = locationService.selectTBaseStorageAreaLocationByLocationId(locationId);
         if (location.getAbcId().equals("2")) {
             return "D58700";
         } else if (location.getAbcId().equals("1")) {
             return "D00580";
         }
         return "null";
    }

    /**
     * 修改出库物料明细
     */
    @RequiresPermissions("business:pickingwavegoods:edit")
    @GetMapping("/edit/{pickingid}")
    public String edit(@PathVariable("pickingid") String pickingid, ModelMap mmap)
    {
        TCkPickingwavegoods tCkPickingwavegoods = tCkPickingwavegoodsService.selectTCkPickingwavegoodsByPickingid(pickingid);
        mmap.put("tCkPickingwavegoods", tCkPickingwavegoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存出库物料明细
     */
    @RequiresPermissions("business:pickingwavegoods:edit")
    @Log(title = "出库物料明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TCkPickingwavegoods tCkPickingwavegoods)
    {
        return toAjax(tCkPickingwavegoodsService.updateTCkPickingwavegoods(tCkPickingwavegoods));
    }

    /**
     * 修改出库任务
     */
    @RequiresPermissions("business:pickingwavegoods:edit")
    @Log(title = "出库物料明细", businessType = BusinessType.UPDATE)
    @PostMapping("/updateResult")
    @ResponseBody
    public AjaxResult updateResult(TCkPickingwavegoods tCkPickingwavegoods)
    {
        return toAjax(tCkPickingwavegoodsService.updateGoodsOutResult(tCkPickingwavegoods));
    }

    /**
     * 删除出库物料明细
     */
    @RequiresPermissions("business:pickingwavegoods:remove")
    @Log(title = "出库物料明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tCkPickingwavegoodsService.deleteTCkPickingwavegoodsByPickingids(ids));
    }

    /**
     * 判断站台上的空托盘是否为空，如果不为空，根据托盘号获取出库任务信息
     */
    @RequiresPermissions("business:pickingwavegoods:edit")
    @GetMapping("/queryByCtl")
    @ResponseBody
    public AjaxResult queryByCtl()
    {
        TConveyorStatus tConveyorStatus = new TConveyorStatus();
        // 用户登录IP
        SysUser sysUser = ShiroUtils.getCurrentUser();
        tConveyorStatus.setPcip(ShiroUtils.getIp());

        List<TConveyorStatus> tConveyorStatusList = itConveyorStatusService.selectTConveyorStatusList(tConveyorStatus);
        if (tConveyorStatusList != null && tConveyorStatusList.size() > 0) {
            tConveyorStatus = tConveyorStatusList.get(0);

            // 判断当前站台上的托盘是否为空，不为空时，根据托盘获取出库任务数据
            if (StringUtils.isNotEmpty(tConveyorStatus.getBarcode())) {
                TCkPickingwavegoods tCkPickingwavegoods = new TCkPickingwavegoods();
                // 托盘号
                tCkPickingwavegoods.setCtl(tConveyorStatus.getBarcode());
                // 状态
                tCkPickingwavegoods.setOutstatus("0");
                // 站台号
                tCkPickingwavegoods.setOutstand(tConveyorStatus.getConveryorId());
                // 获取任务列表
                List<TCkPickingwavegoods> tCkPickingwavegoodsList = tCkPickingwavegoodsService.selectTCkPickingwavegoodsList(tCkPickingwavegoods);
                if (tCkPickingwavegoodsList != null && tCkPickingwavegoodsList.size() > 0) {
                    return success(tCkPickingwavegoodsList.get(0));
                }
            }
        }
        return null;
    }

    /**
     * 出库扫码校验
     */
    @Log(title = "出库扫码校验", businessType = BusinessType.UPDATE)
    @PostMapping("/scanGoods")
    @ResponseBody
    public AjaxResult scanGoods(TCkPickingwavegoods tCkPickingwavegoods)
    {
        tCkPickingwavegoods.setOutstatus("3");
        List<TCkPickingwavegoods> waitForScanTaskList = tCkPickingwavegoodsService.selectTCkPickingwavegoodsList(tCkPickingwavegoods);
        if (waitForScanTaskList.size() < 1) {
            return success("0");
        }
        TCkPickingwavegoods scanTask = waitForScanTaskList.get(0);
        scanTask.setOutstatus("4");
        return toAjax(tCkPickingwavegoodsService.updateScanGoodsResult(scanTask));
    }

    /**
     * 回库
     */
    @Log(title = "返库", businessType = BusinessType.UPDATE)
    @PostMapping("/backStock")
    @ResponseBody
    public AjaxResult backStock(TCkPickingwavegoods tCkPickingwavegoods)
    {
        tCkPickingwavegoods.setOutstatus("4");
        List<TCkPickingwavegoods> waitForBackTaskList = tCkPickingwavegoodsService.selectTCkPickingwavegoodsList(tCkPickingwavegoods);
        if (waitForBackTaskList.size() < 1) {
            return success("0");
        }
        TCkPickingwavegoods backTask = waitForBackTaskList.get(0);
        backTask.setOutstatus("2");
        return toAjax(tCkPickingwavegoodsService.updateGoodsOutResult(backTask));
    }

    /**
     * 弹框表格
     */
    @GetMapping("/selEbsAccountName")
    public String table()
    {
        return prefix + "/ebsAccountName";
    }

    /**
     * 获取账户别名
     */
    @RequiresPermissions("business:pickingwavegoods:list")
    @PostMapping("/getEbsAccountName")
    @ResponseBody
    public TableDataInfo getEbsAccountName(EbsAccountName ebsAccountName) throws Exception {
        // 返回分页数据
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        TableDataInfo rspData = new TableDataInfo();
        List<EbsAccountName> ebsAccountNames = new LinkedList<EbsAccountName>();

        // 获取token
        JSONObject token = JSON.parseObject(HttpUtils.httpPostJson(configService.selectConfigByKey("token_ip"), "", ""));
//        tEbsRecordService.insertTEbsRecord(new TEbsRecord("token", 1, "http://10.10.90.193:8899/oauth/token?grant_type=client_credentials",
//                "", JSON.toJSONString(token), "1", "获取token"));
        // 获取账户别名
        String paramsGetEbsAccountName = JSON.toJSONString(createJsonGetEbsAccountName());
        String resultGetEbsAccountName = "";
        try {
            resultGetEbsAccountName = HttpUtils.httpPostJson(configService.selectConfigByKey("ebs_ip"), paramsGetEbsAccountName, token.get("access_token").toString());
        } catch (Exception e) {
//            tEbsRecordService.insertTEbsRecord(new TEbsRecord("getEbsAccountName", 2, "http://10.10.90.193:9000/esb/intergrateService",
//                    paramsGetEbsAccountName, resultGetEbsAccountName, "-1", "获取账户别名"));
            // 接口失败
            return getDataTable(ebsAccountNames);
        }
        System.out.println(resultGetEbsAccountName);
//        tEbsRecordService.insertTEbsRecord(new TEbsRecord("getEbsAccountName", 2, "http://10.10.90.193:9000/esb/intergrateService",
//                paramsGetEbsAccountName, resultGetEbsAccountName, "1", "获取账户别名"));
        JSONObject resultJsonGetEbsAccountName = (JSONObject) JSON.parseObject(resultGetEbsAccountName).get("obj");
        List<JSONObject> dataGetEbsAccountNames = JSON.parseArray(resultJsonGetEbsAccountName.getString("rows"), JSONObject.class);
        for (JSONObject dataEbsAccountName : dataGetEbsAccountNames) {
            EbsAccountName tempName = new EbsAccountName();
            tempName.setDispositionId(dataEbsAccountName.getIntValue("dispositionId"));
            tempName.setDescription(dataEbsAccountName.getString("description"));
            tempName.setSegment1(dataEbsAccountName.getString("segment1"));
            ebsAccountNames.add(tempName);
        }

        rspData.setCode(0);
        rspData.setRows(PageUtils.startPageByList(ebsAccountNames, pageNum, pageSize));
        rspData.setTotal(new PageInfo(ebsAccountNames).getTotal());
        return rspData;
    }

    /**
     * 账户别名出库
     */
    @RequiresPermissions("business:orderdetail:add")
    @Log(title = "账户别名出库", businessType = BusinessType.INSERT)
    @PostMapping("/othersProc")
    @ResponseBody
    public AjaxResult othersProc(TCkOrderdetail tCkOrderdetail) throws Exception {
        // start 检查当前站台是否有正在出库的任务
        TCkPickingwavegoods tCkPickingwavegoods = new TCkPickingwavegoods();
        tCkPickingwavegoods.setOutstand(tCkOrderdetail.getOutStand());
        List<TCkPickingwavegoods> outTaskList = tCkPickingwavegoodsService.selectTCkPickingwavegoodsList(tCkPickingwavegoods);
        if (outTaskList.size() > 0) {
            return error("当前站台有出库任务未结束");
        }
        // end 检查当前站台是否有正在出库的任务
        // start 检查当前库存是否充足(只查合格品)
        TMiStock tMiStock = new TMiStock();
        tMiStock.setGoodsId(tCkOrderdetail.getGoodId());
        tMiStock.setProduclotid(tCkOrderdetail.getPutinId());
        tMiStock.setSts("0");
        List<TMiStock> list = tMiStockService.selectTMiStockOutList(tMiStock);
        if (list.size() > 0) {
            if (list.get(0).getShelvesNum().compareTo(tCkOrderdetail.getPickNum()) >= 0) {// 库存充足
                tCkOrderdetail.setCkId(OrderCodeFactory.getOrderCode("CK", ""));
                tCkOrderdetail.setStatus("0");
                tCkOrderdetail.setAddtime(new Date());
                // 获取用户名
                SysUser sysUser = ShiroUtils.getCurrentUser();
                tCkOrderdetail.setUserName(sysUser.getUserName());
                // 开始账户别名出库
                // 获取token
                JSONObject token = JSON.parseObject(HttpUtils.httpPostJson(configService.selectConfigByKey("token_ip"), "", ""));
//                tEbsRecordService.insertTEbsRecord(new TEbsRecord("token", 1, "http://10.10.90.193:8899/oauth/token?grant_type=client_credentials",
//                        "", JSON.toJSONString(token), "1", "获取token"));
                // 账户别名发放
                List<TMiStock> stockForOthersProc = tMiStockService.selectStock(tMiStock);
                String paramsWmsOthersProc = JSON.toJSONString(createJsonWmsOthersProc(stockForOthersProc.get(0), tCkOrderdetail));
                String resultWmsOthersProc = "";
                try {
                    resultWmsOthersProc = HttpUtils.httpPostJson(configService.selectConfigByKey("ebs_ip"), paramsWmsOthersProc, token.get("access_token").toString());
                } catch (Exception e) {
                    tEbsRecordService.insertTEbsRecord(new TEbsRecord("wmsOthersProc", 2, configService.selectConfigByKey("ebs_ip"),
                            paramsWmsOthersProc, resultWmsOthersProc, "-1", "账户别名发放", list.get(0).getGoodsId(), list.get(0).getGoodsName(), tCkOrderdetail.getPutinId(), tCkOrderdetail.getPickNum()));
                    // 接口失败
                    return error("连接EBS失败");
                }
                System.out.println(resultWmsOthersProc);
                if (!JSON.parseObject(resultWmsOthersProc).getBoolean("success")) {
                    tEbsRecordService.insertTEbsRecord(new TEbsRecord("wmsOthersProc", 2, configService.selectConfigByKey("ebs_ip"),
                            paramsWmsOthersProc, resultWmsOthersProc, "-1", "账户别名发放", list.get(0).getGoodsId(), list.get(0).getGoodsName(), tCkOrderdetail.getPutinId(), tCkOrderdetail.getPickNum()));
                    return error("账户别名发放失败：" + JSON.parseObject(resultWmsOthersProc).getString("msg"));
                }
                JSONObject resultJsonWmsOthersProc = (JSONObject) JSON.parseObject(resultWmsOthersProc).get("obj");
                List<JSONObject> dataWmsOthersProc = JSON.parseArray(resultJsonWmsOthersProc.getString("rows"), JSONObject.class);
                if (!dataWmsOthersProc.get(0).getString("processStatus").equals("PROCESSING")) {
                    tEbsRecordService.insertTEbsRecord(new TEbsRecord("wmsOthersProc", 2, configService.selectConfigByKey("ebs_ip"),
                            paramsWmsOthersProc, resultWmsOthersProc, "-1", "账户别名发放", list.get(0).getGoodsId(), list.get(0).getGoodsName(), tCkOrderdetail.getPutinId(), tCkOrderdetail.getPickNum()));
                    return error(dataWmsOthersProc.get(0).getString("errorMsg"));
                }
                tEbsRecordService.insertTEbsRecord(new TEbsRecord("wmsOthersProc", 2, configService.selectConfigByKey("ebs_ip"),
                        paramsWmsOthersProc, resultWmsOthersProc, "0", "账户别名发放", list.get(0).getGoodsId(), list.get(0).getGoodsName(), tCkOrderdetail.getPutinId(), tCkOrderdetail.getPickNum()));
                if (tCkOrderdetailService.insertTCkOrderdetail(tCkOrderdetail) < 1) {
                    return error("插入出库任务失败");
                }
            } else {// 库存不足
                return error("合格品库存不足");
            }
        }
        // end 检查当前库存是否充足
        return success("创建出库任务成功");
    }

    /**
     * 创建参数Json(获取账户别名)
     * @return
     */
    public JSONObject createJsonGetEbsAccountName() {
        // 创建系统参数
        JSONObject systemParams = new JSONObject();
        systemParams.put("requestId", new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));
        systemParams.put("application", "NT_WMS");
        systemParams.put("sourceSystem", "NT_WMS");
        systemParams.put("targetSystem", "EBS");
        systemParams.put("serviceName", "getEbsAccountName");
        systemParams.put("nonce", 1);
        systemParams.put("timestamp", 1);
        systemParams.put("serviceOperation", "S");
        systemParams.put("serviceVersion", "1.0");
        systemParams.put("token", "fd");

        // 创建查询参数
        JSONObject baseQueryParams = new JSONObject();
        baseQueryParams.put("organizationId", configService.selectConfigByKey("organizationId"));

        // 创建数据
        JSONObject businessData = new JSONObject();

        JSONArray jsonArray = new JSONArray();
        jsonArray.add(businessData);

        JSONObject result = new JSONObject();
        result.put("systemParams", systemParams);
        result.put("baseQueryParams", baseQueryParams);
        result.put("businessData", jsonArray);

        return result;
    }

    /**
     * 创建参数Json(账户别名出库)
     * @return
     */
    public JSONObject createJsonWmsOthersProc(TMiStock stock, TCkOrderdetail order) {
        // 创建系统参数
        JSONObject systemParams = new JSONObject();
        systemParams.put("requestId", new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));
        systemParams.put("application", "NT_WMS");
        systemParams.put("sourceSystem", "NT_WMS");
        systemParams.put("targetSystem", "EBS");
        systemParams.put("serviceName", "wmsOthersProc");
        systemParams.put("nonce", 1);
        systemParams.put("timestamp", 1);
        systemParams.put("serviceOperation", "E");
        systemParams.put("serviceVersion", "1.0");
        systemParams.put("token", "fd");

        // 创建查询参数
        JSONObject baseQueryParams = new JSONObject();
        baseQueryParams.put("organizationId", configService.selectConfigByKey("organizationId"));

        // 创建数据
        JSONObject businessData = new JSONObject();
        businessData.put("transTypeId", 31);
        businessData.put("organizationId", configService.selectConfigByKey("organizationId"));
        businessData.put("itemId", stock.getGoodsTypeid());
        businessData.put("subInventory", stock.getWhseloc());
        businessData.put("locatorId", EbsUtils.LOCATOR_AREA_MAP.get(stock.getWhseloc()));
        businessData.put("transSourceName", order.getSpecification());
        businessData.put("transSourceId", order.getBusinessid());
        businessData.put("transLotNumber", stock.getProduclotid());
        businessData.put("quantity", Math.negateExact(order.getPickNum().intValue()));
        businessData.put("transDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        businessData.put("transUom", stock.getGoodsMeasureId());
        businessData.put("sourceHeaderId", 1);
        businessData.put("sourceLineId", 1);

        JSONArray jsonArray = new JSONArray();
        jsonArray.add(businessData);

        JSONObject result = new JSONObject();
        result.put("systemParams", systemParams);
        result.put("baseQueryParams", baseQueryParams);
        result.put("businessData", jsonArray);

        return result;
    }

    static class EbsAccountName {
        private int dispositionId;
        private String segment1;
        private String description;

        public int getDispositionId() {
            return dispositionId;
        }

        public void setDispositionId(int dispositionId) {
            this.dispositionId = dispositionId;
        }

        public String getSegment1() {
            return segment1;
        }

        public void setSegment1(String segment1) {
            this.segment1 = segment1;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }
    }
}
