/*
 * Copyright [2022] [https://www.baiduc.com]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.baiduc.com
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.baiduc.com
 */
package vip.xiaonuo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javafx.concurrent.Worker;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import vip.xiaonuo.erp.entity.ErpBdOrg;
import vip.xiaonuo.erp.entity.caigou.*;
import vip.xiaonuo.erp.entity.kucun.*;
import vip.xiaonuo.erp.mapper.ErpBdOrgMapper;
import vip.xiaonuo.purchase.entity.PurchaseContract;
import vip.xiaonuo.purchase.entity.PurchaseOrder;
import vip.xiaonuo.purchase.entity.PurchasePay;
import vip.xiaonuo.purchase.entity.PurchasePrice;
import vip.xiaonuo.purchase.mapper.PurchaseContractMapper;
import vip.xiaonuo.purchase.mapper.PurchaseOrderMapper;
import vip.xiaonuo.purchase.mapper.PurchasePayMapper;
import vip.xiaonuo.purchase.mapper.PurchasePriceMapper;
import vip.xiaonuo.warehouse.entity.*;
import vip.xiaonuo.warehouse.mapper.*;

import java.util.Date;
import java.util.List;

/**
 * 主测试类
 *
 * @author xuyuxiang
 * @date 2022/9/17 17:09
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class KuCunTest {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private ErpBdOrgMapper erpBdOrgMapper;
    @Autowired
    private WarehouseIncomStockMapper incomStockMapper;
    @Autowired
    private WarehouseOutStockMapper outStockMapper;
    @Autowired
    private WarehouseStockMapper stockMapper;
    @Autowired
    private WarehouseStockDetailMapper stockDetailMapper;
    @Autowired
    private WarehouseStockSecondMapper stockSecondMapper;

    @Test
    public void test() {
        Date date = DateUtil.beginOfDay(new Date());  // 获取当前日期
        // 构建URL，使用格式化的日期
        ResponseEntity<List<YuanCaiLiaoKuCun>> response = restTemplate.exchange(
                "http://127.0.0.1:9200/erp-kucun/getYuanCaiLiaoCunLiang?date=",
                HttpMethod.GET,
                null,
                new ParameterizedTypeReference<List<YuanCaiLiaoKuCun>>() {
                }
        );
        List<YuanCaiLiaoKuCun> forObjects = response.getBody();
        System.out.println(forObjects);
        for (YuanCaiLiaoKuCun forObject : forObjects) {
            ErpBdOrg forgid = erpBdOrgMapper.selectOne(new QueryWrapper<ErpBdOrg>().eq("forgid", forObject.getFSTOCKORGID()));
            if (ObjectUtil.isEmpty(forgid))
                continue;
            WarehouseStock warehouseStock = new WarehouseStock();
            if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                warehouseStock.setMaterial(String.format("%.2f",forObject.getFBASEQTY()));
            }
            if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                warehouseStock.setFinishProduce(String.format("%.2f",forObject.getFBASEQTY()));
            }
            if ("五金库".equals(forObject.getFNAME())){
                warehouseStock.setLowValue(String.format("%.2f",forObject.getFBASEQTY()));
            }
            if ("包材库".equals(forObject.getFNAME())){
                warehouseStock.setPackageMaterial(String.format("%.2f",forObject.getFBASEQTY()));
            }
            if (forObject.getFnumber().equals("10020002")){
                warehouseStock.setLanolin(String.format("%.2f",forObject.getFBASEQTY()));
            }
            warehouseStock.setCreateTime(forObject.getFUPDATETIME());
            warehouseStock.setOrgId(forgid.getOrgId());
            stockMapper.insert(warehouseStock);

            WarehouseStockDetail warehouseStockDetail = new WarehouseStockDetail();
            if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                warehouseStockDetail.setMaterialCode(0);
            }else if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                warehouseStockDetail.setMaterialCode(1);
            }else if ("五金库".equals(forObject.getFNAME())){
                warehouseStockDetail.setMaterialCode(3);
            }else if ("包材库".equals(forObject.getFNAME())){
                warehouseStockDetail.setMaterialCode(4);
            }else if (forObject.getFnumber().equals("10020002")){
                warehouseStockDetail.setMaterialCode(5);
            }
            warehouseStockDetail.setOrgId(forgid.getOrgId());
//            warehouseStockDetail.setMaterialCode(forObject.getFMATERIALID());
            warehouseStockDetail.setMaterialName(forObject.getWuLiaoName());
            warehouseStockDetail.setMaterialNumber(String.format("%.2f",forObject.getFBASEQTY()));
            warehouseStockDetail.setStockName(forObject.getFNAME());
            warehouseStockDetail.setCreateTime(forObject.getFUPDATETIME());
            stockDetailMapper.insert(warehouseStockDetail);
        }
    }
    @Test
    public void test2() {
        //成品半成品
        ResponseEntity<List<ChengPinRuKu>> response1 = restTemplate.exchange(
                "http://127.0.0.1:9200/erp-kucun/getChengPinDangRi?date=",
                HttpMethod.GET,
                null,
                new ParameterizedTypeReference<List<ChengPinRuKu>>() {}
        );
        List<ChengPinRuKu> forObjects1= response1.getBody();
        System.out.println(forObjects1);
        for (ChengPinRuKu forObject : forObjects1) {

            ErpBdOrg forgid = erpBdOrgMapper.selectOne(new QueryWrapper<ErpBdOrg>().eq("forgid", forObject.getFSTOCKORGID()));
            if (ObjectUtil.isEmpty(forgid))
                continue;
            WarehouseIncomStock warehouseIncomStock  = new WarehouseIncomStock();
            if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                warehouseIncomStock.setMaterial(String.format("%.2f",forObject.getFREALQTY()));
            }
            if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                warehouseIncomStock.setFinishProduce(String.format("%.2f",forObject.getFREALQTY()));
            }
            if ("五金库".equals(forObject.getFNAME())){
                warehouseIncomStock.setLowValue(String.format("%.2f",forObject.getFREALQTY()));
            }
            if ("包材库".equals(forObject.getFNAME())){
                warehouseIncomStock.setPackageMaterial(String.format("%.2f",forObject.getFREALQTY()));
            }
            if (forObject.getFnumber().equals("10020002")){
                warehouseIncomStock.setLanolin(String.format("%.2f",forObject.getFREALQTY()));
            }

            warehouseIncomStock.setCreateTime(forObject.getFDATE());
            warehouseIncomStock.setOrgId(forgid.getOrgId());
            incomStockMapper.insert(warehouseIncomStock);

            List<WarehouseStockDetail> warehouseStockDetails = stockDetailMapper.selectList(new QueryWrapper<WarehouseStockDetail>()
                    .eq("org_id", forgid.getOrgId()).eq("material_name", forObject.getWuLiaoName())
                    .between("create_time",DateUtil.beginOfDay(forObject.getFDATE()),DateUtil.endOfDay(forObject.getFDATE())));
            if (ObjectUtil.isEmpty(warehouseStockDetails)){
                WarehouseStockDetail warehouseStockDetail = new WarehouseStockDetail();
                if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                    warehouseStockDetail.setMaterialCode(0);
                }
                if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(1);
                }
                if ("五金库".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(3);
                }
                if ("包材库".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(4);
                }
                if (forObject.getFnumber().equals("10020002")){
                    warehouseStockDetail.setMaterialCode(5);
                }
                warehouseStockDetail.setOrgId(forgid.getOrgId());
                warehouseStockDetail.setMaterialName(forObject.getWuLiaoName());
                warehouseStockDetail.setIncomeNumber(String.format("%.2f",forObject.getFREALQTY()));
                warehouseStockDetail.setStockName(forObject.getFNAME());
                warehouseStockDetail.setCreateTime(forObject.getFDATE());
                stockDetailMapper.insert(warehouseStockDetail);
            }else {
                WarehouseStockDetail warehouseStockDetail = warehouseStockDetails.get(0);
                if (warehouseStockDetail.getIncomeNumber() ==null){
                    warehouseStockDetail.setIncomeNumber(String.format("%.2f",forObject.getFREALQTY()));
                }else {
                    warehouseStockDetail.setIncomeNumber(String.format("%.2f",forObject.getFREALQTY() + Double.parseDouble(warehouseStockDetail.getIncomeNumber())));
                }
                stockDetailMapper.updateById(warehouseStockDetail);
            }
        }
    }

    @Test
    public void test3() {
        ResponseEntity<List<ChenPinChuKu>> response1 = restTemplate.exchange(
                "http://127.0.0.1:9200/erp-kucun/getChengPinChuKu?date=",
                HttpMethod.GET,
                null,
                new ParameterizedTypeReference<List<ChenPinChuKu>>() {}
        );
        List<ChenPinChuKu> forObjects1 = response1.getBody();
        System.out.println(forObjects1);

        for (ChenPinChuKu forObject : forObjects1) {

            ErpBdOrg forgid = erpBdOrgMapper.selectOne(new QueryWrapper<ErpBdOrg>().eq("forgid", forObject.getFSTOCKORGID()));
            if (ObjectUtil.isEmpty(forgid))
                continue;
            WarehouseOutStock warehouseIncomStock  = new WarehouseOutStock();
            if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                warehouseIncomStock.setMaterial(String.format("%.2f",forObject.getFSALUNITQTY()));
            }
            if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                warehouseIncomStock.setFinishProduce(String.format("%.2f",forObject.getFSALUNITQTY()));
            }
            if ("五金库".equals(forObject.getFNAME())){
                warehouseIncomStock.setLowValue(String.format("%.2f",forObject.getFSALUNITQTY()));
            }
            if ("包材库".equals(forObject.getFNAME())){
                warehouseIncomStock.setPackageMaterial(String.format("%.2f",forObject.getFSALUNITQTY()));
            }
            if (forObject.getFnumber().equals("10020002")){
                warehouseIncomStock.setLanolin(String.format("%.2f",forObject.getFSALUNITQTY()));
            }

            warehouseIncomStock.setCreateTime(forObject.getFDATE());
            warehouseIncomStock.setOrgId(forgid.getOrgId());
            outStockMapper.insert(warehouseIncomStock);

            List<WarehouseStockDetail> warehouseStockDetails = stockDetailMapper.selectList(new QueryWrapper<WarehouseStockDetail>()
                    .eq("org_id", forgid.getOrgId()).eq("material_name", forObject.getWuLiaoName())
                    .between("create_time",DateUtil.beginOfDay(forObject.getFDATE()),DateUtil.endOfDay(forObject.getFDATE())));
            if (ObjectUtil.isEmpty(warehouseStockDetails)){
                WarehouseStockDetail warehouseStockDetail = new WarehouseStockDetail();
                if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                    warehouseStockDetail.setMaterialCode(0);
                }
                if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(1);
                }
                if ("五金库".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(3);
                }
                if ("包材库".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(4);
                }
                if (forObject.getFnumber().equals("10020002")){
                    warehouseStockDetail.setMaterialCode(5);
                }
                warehouseStockDetail.setOrgId(forgid.getOrgId());
                warehouseStockDetail.setMaterialName(forObject.getWuLiaoName());
                warehouseStockDetail.setOutNumber(String.format("%.2f",forObject.getFSALUNITQTY()));
                warehouseStockDetail.setStockName(forObject.getFNAME());
                warehouseStockDetail.setCreateTime(forObject.getFDATE());
                stockDetailMapper.insert(warehouseStockDetail);
            }else {
                WarehouseStockDetail warehouseStockDetail = warehouseStockDetails.get(0);
                if (warehouseStockDetail.getOutNumber() ==null){
                    warehouseStockDetail.setOutNumber(String.format("%.2f",forObject.getFSALUNITQTY()));
                }else {
                    warehouseStockDetail.setOutNumber(String.format("%.2f",forObject.getFSALUNITQTY() + Double.parseDouble(warehouseStockDetail.getOutNumber())));
                }
                stockDetailMapper.updateById(warehouseStockDetail);
            }
        }
    }
    @Test
    public void test4() {
        ResponseEntity<List<WuLiaoKuMingXi>> response = restTemplate.exchange(
                "http://127.0.0.1:9200/erp-kucun/getWuLiaoMingXi?date=",
                HttpMethod.GET,
                null,
                new ParameterizedTypeReference<List<WuLiaoKuMingXi>>() {}
        );
        List<WuLiaoKuMingXi> forObjects = response.getBody();
        for (WuLiaoKuMingXi forObject : forObjects) {

            ErpBdOrg forgid = erpBdOrgMapper.selectOne(new QueryWrapper<ErpBdOrg>().eq("forgid", forObject.getFSTOCKORGID()));
            if (ObjectUtil.isEmpty(forgid))
                continue;
            WarehouseIncomStock warehouseIncomStock  = new WarehouseIncomStock();
            if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                warehouseIncomStock.setMaterial(String.format("%.2f",forObject.getFINSTOCKQTY()));
            }
            if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                warehouseIncomStock.setFinishProduce(String.format("%.2f",forObject.getFINSTOCKQTY()));
            }
            if ("五金库".equals(forObject.getFNAME())){
                warehouseIncomStock.setLowValue(String.format("%.2f",forObject.getFINSTOCKQTY()));
            }
            if ("包材库".equals(forObject.getFNAME())){
                warehouseIncomStock.setPackageMaterial(String.format("%.2f",forObject.getFINSTOCKQTY()));
            }
            if (forObject.getFnumber().equals("10020002")){
                warehouseIncomStock.setLanolin(String.format("%.2f",forObject.getFINSTOCKQTY()));
            }
//
            warehouseIncomStock.setCreateTime(forObject.getFDATE());
            warehouseIncomStock.setOrgId(forgid.getOrgId());
            incomStockMapper.insert(warehouseIncomStock);
//
            List<WarehouseStockDetail> warehouseStockDetails = stockDetailMapper.selectList(new QueryWrapper<WarehouseStockDetail>()
                    .eq("org_id", forgid.getOrgId()).eq("material_name", forObject.getWuLiaoName())
                    .between("create_time",DateUtil.beginOfDay(forObject.getFDATE()),DateUtil.endOfDay(forObject.getFDATE())));

            if (ObjectUtil.isEmpty(warehouseStockDetails)){
                WarehouseStockDetail warehouseStockDetail = new WarehouseStockDetail();
                if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                    warehouseStockDetail.setMaterialCode(0);
                }
                if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(1);
                }
                if ("五金库".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(3);
                }
                if ("包材库".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(4);
                }
                if (forObject.getFnumber().equals("10020002")){
                    warehouseStockDetail.setMaterialCode(5);
                }
                warehouseStockDetail.setOrgId(forgid.getOrgId());
                warehouseStockDetail.setMaterialName(forObject.getWuLiaoName());
                warehouseStockDetail.setIncomeNumber(String.format("%.2f",forObject.getFINSTOCKQTY()));
                warehouseStockDetail.setStockName(forObject.getFNAME());
                warehouseStockDetail.setMaterialNumber((String.format("%.2f",forObject.getFSTOCKBASEQTY())));
                warehouseStockDetail.setCreateTime(forObject.getFDATE());
                warehouseStockDetail.setMaterialCheck(String.format("%.2f",forObject.getDaiJian()));
                stockDetailMapper.insert(warehouseStockDetail);
            }else {
                WarehouseStockDetail warehouseStockDetail = warehouseStockDetails.get(0);
                if (warehouseStockDetail.getIncomeNumber() ==null){
                    warehouseStockDetail.setIncomeNumber(String.format("%.2f",forObject.getFINSTOCKQTY()));
                }else {
                    warehouseStockDetail.setIncomeNumber(String.format("%.2f",forObject.getFINSTOCKQTY() + Double.parseDouble(warehouseStockDetail.getIncomeNumber())));
                }

                if (warehouseStockDetail.getMaterialCheck() ==null){
                    warehouseStockDetail.setMaterialCheck(String.format("%.2f",forObject.getDaiJian()));
                }else {
                    warehouseStockDetail.setMaterialCheck(String.format("%.2f",forObject.getDaiJian() + Double.parseDouble(warehouseStockDetail.getMaterialCheck())));
                }
                stockDetailMapper.updateById(warehouseStockDetail);
            }

            WarehouseStockSecond warehouseStockSecond = new WarehouseStockSecond();
            if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                warehouseStockSecond.setMaterialType(0);
            }
            if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                warehouseStockSecond.setMaterialType(1);
            }
            if ("五金库".equals(forObject.getFNAME())){
                warehouseStockSecond.setMaterialType(3);
            }
            if ("包材库".equals(forObject.getFNAME())){
                warehouseStockSecond.setMaterialType(4);
            }
            if (forObject.getFnumber().equals("10020002")){
                warehouseStockSecond.setMaterialType(5);
            }
            warehouseStockSecond.setIncomeNumber(String.format("%.2f",forObject.getFINSTOCKQTY()));
            warehouseStockSecond.setIncomeMoney(String.format("%.2f",forObject.getFBILLAMOUNTLC()));
            warehouseStockSecond.setCreateTime(forObject.getFDATE());
            warehouseStockSecond.setOrgId(forgid.getOrgId());
            warehouseStockSecond.setStock(String.format("%.2f",forObject.getFSTOCKBASEQTY()));
            stockSecondMapper.insert(warehouseStockSecond);
        }
    }

    @Test
    public void test5() {
        // 构建URL，使用格式化的日期
        ResponseEntity<List<YuanCaiLiaoKuCun>> response = restTemplate.exchange(
                "http://127.0.0.1:9200/erp-kucun/getYuanCaiLiaoCunLiang?date=",
                HttpMethod.GET,
                null,
                new ParameterizedTypeReference<List<YuanCaiLiaoKuCun>>() {
                }
        );
        List<YuanCaiLiaoKuCun> forObjects = response.getBody();

        for (YuanCaiLiaoKuCun forObject : forObjects) {
            ErpBdOrg forgid = erpBdOrgMapper.selectOne(new QueryWrapper<ErpBdOrg>().eq("forgid", forObject.getFSTOCKORGID()));
            if (ObjectUtil.isEmpty(forgid))
                continue;
            List<WarehouseStockDetail> warehouseStockDetails = stockDetailMapper.selectList(new QueryWrapper<WarehouseStockDetail>()
                    .eq("org_id", forgid.getOrgId()).eq("material_name", forObject.getWuLiaoName())
                    .between("create_time",DateUtil.beginOfDay(forObject.getFUPDATETIME()),DateUtil.endOfDay(forObject.getFUPDATETIME())));
            if (ObjectUtil.isNotEmpty(warehouseStockDetails)){
                WarehouseStockDetail warehouseStockDetail = warehouseStockDetails.get(0);
                if (warehouseStockDetail.getMaterialNumber() !=null){
                    warehouseStockDetail.setMaterialNumber(String.format("%.2f",forObject.getFBASEQTY()+Double.parseDouble(warehouseStockDetail.getMaterialNumber())));
                }else {
                    warehouseStockDetail.setMaterialNumber(String.format("%.2f",forObject.getFBASEQTY()));
                }

               stockDetailMapper.updateById(warehouseStockDetail);
            }else {
                WarehouseStockDetail warehouseStockDetail = new WarehouseStockDetail();
                if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                    warehouseStockDetail.setMaterialCode(0);
                }
                if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(1);
                }
                if ("五金库".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(3);
                }
                if ("包材库".equals(forObject.getFNAME())){
                    warehouseStockDetail.setMaterialCode(4);
                }
                if (forObject.getFnumber().equals("10020002")){
                    warehouseStockDetail.setMaterialCode(5);
                }
                warehouseStockDetail.setOrgId(forgid.getOrgId());
                warehouseStockDetail.setMaterialNumber(String.format("%.2f",forObject.getFBASEQTY()));
                warehouseStockDetail.setMaterialName(forObject.getWuLiaoName());
                warehouseStockDetail.setStockName(forObject.getFNAME());
                warehouseStockDetail.setCreateTime(forObject.getFUPDATETIME());
                stockDetailMapper.insert(warehouseStockDetail);
            }

            List<WarehouseStockSecond> warehouseStockSecondList = stockSecondMapper.selectList(new QueryWrapper<WarehouseStockSecond>()
                    .eq("org_id", forgid.getOrgId()).eq("material_type", getWuLiaoNamber(forObject.getWuLiaoName(),forObject.getFnumber()))
                    .between("create_time",DateUtil.beginOfDay(forObject.getFUPDATETIME()),DateUtil.endOfDay(forObject.getFUPDATETIME())));
            if (ObjectUtil.isNotEmpty(warehouseStockSecondList)){
                WarehouseStockSecond warehouseStockSecond = warehouseStockSecondList.get(0);
                if (warehouseStockSecond.getStock() !=null){
                    warehouseStockSecond.setStock(String.format("%.2f",forObject.getFBASEQTY()+Double.parseDouble(warehouseStockSecond.getStock())));
                }else {
                    warehouseStockSecond.setStock(String.format("%.2f",forObject.getFBASEQTY()));
                }
                warehouseStockSecond.setStock(String.format("%.2f",forObject.getFBASEQTY()));
                stockSecondMapper.updateById(warehouseStockSecond);
            }else {
                WarehouseStockSecond warehouseStockSecond = new WarehouseStockSecond();
                if (("原料库".equals(forObject.getFNAME()) || "高科原料仓库".equals(forObject.getFNAME())) && !forObject.getFnumber().equals("10020002")){
                    warehouseStockSecond.setMaterialType(0);
                }
                if ("成品库".equals(forObject.getFNAME()) || "成品库CW".equals(forObject.getFNAME())){
                    warehouseStockSecond.setMaterialType(1);
                }
                if ("五金库".equals(forObject.getFNAME())){
                    warehouseStockSecond.setMaterialType(3);
                }
                if ("包材库".equals(forObject.getFNAME())){
                    warehouseStockSecond.setMaterialType(4);
                }
                if (forObject.getFnumber().equals("10020002")){
                    warehouseStockSecond.setMaterialType(5);
                }
                warehouseStockSecond.setOrgId(forgid.getOrgId());
                warehouseStockSecond.setStock(String.format("%.2f",forObject.getFBASEQTY()));
                warehouseStockSecond.setCreateTime(forObject.getFUPDATETIME());
                stockSecondMapper.insert(warehouseStockSecond);
            }
        }
    }

    private Object getWuLiaoNamber(String wuLiaoName ,String fnumber) {
        if (("原料库".equals(wuLiaoName) || "高科原料仓库".equals(wuLiaoName)) && !fnumber.equals("10020002")){
           return 0;
        }
        if ("成品库".equals(wuLiaoName) || "成品库CW".equals(wuLiaoName)){
            return 1;
        }
        if ("五金库".equals(wuLiaoName)){
            return 3;
        }
        if ("包材库".equals(wuLiaoName)){
           return 4;
        }
        if (fnumber.equals("10020002")){
            return 5;
        }
        return 6;

    }


}
