package com.ruoyi.web.controller.material;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.clMaterial.domain.CYlMaterial;
import com.ruoyi.clMaterial.service.ICYlMaterialService;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.material.domain.CMaterial;
import com.ruoyi.material.domain.cost;
import com.ruoyi.material.domain.material;
import com.ruoyi.material.domain.temp;
import com.ruoyi.materialType.domain.CMaterialType;
import com.ruoyi.materialType.service.ICMaterialTypeService;
import com.ruoyi.web.utils.JDBCBatch;
import org.apache.commons.collections4.ListUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.service.ICMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料管理Controller
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/material/material")
@DataSource(DataSourceType.QUOT)
public class CMaterialController extends BaseController
{
    @Autowired
    private ICMaterialService cMaterialService;

    @Autowired
    private ICYlMaterialService cYlMaterialService;

    @Autowired
    private ICMaterialTypeService cMaterialTypeService;


    /**
     * 查询物料管理列表
     */
    @PreAuthorize("@ss.hasPermi('material:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(CMaterial cMaterial)
    {

        CMaterial A = new CMaterial();
        startPage();
        List<CMaterial> list = cMaterialService.selectCMaterialList(cMaterial);
        return getDataTable(list);
    }

    /**
     * 物料类别列表
     */
    @PreAuthorize("@ss.hasPermi('material:material:list')")
    @GetMapping("/cTypelist")
    public AjaxResult cTypelist(CMaterialType cMaterialType)
    {
        AjaxResult ajax = AjaxResult.success();
/*
        ajax.put("cTypeList", cFactoryService.selectCTypelist());
*/
        ajax.put("cTypeList", cMaterialTypeService.selectCMaterialTypeList(cMaterialType));
        return ajax;
    }

    /**
     * 查询材料管理列表
     */
    @PreAuthorize("@ss.hasPermi('material:material:list')")
    @GetMapping("/clMaterialList")
    public AjaxResult clMaterialList(CYlMaterial cYlMaterial)
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("cmaterials", cYlMaterialService.selectCYlMaterialList(cYlMaterial));
        return ajax;
    }

    /**
     * 导出物料管理列表
     */
    @PreAuthorize("@ss.hasPermi('material:material:export')")
    @Log(title = "物料管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CMaterial cMaterial)
    {
        List<CMaterial> list = cMaterialService.selectCMaterialList(cMaterial);
        ExcelUtil<CMaterial> util = new ExcelUtil<CMaterial>(CMaterial.class);
        util.exportExcel(response, list, "物料管理数据");
    }

    /**
     * 获取物料管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:material:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        CMaterial c = cMaterialService.selectCMaterialByMaterialId(materialId);
        return success(c);
    }

    /**
     * 新增物料管理
     */
    @PreAuthorize("@ss.hasPermi('material:material:add')")
    @Log(title = "物料管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CMaterial cMaterial)
    {
        return toAjax(cMaterialService.insertCMaterial(cMaterial));
    }

    /**
     * 修改物料管理
     */
    @PreAuthorize("@ss.hasPermi('material:material:edit')")
    @Log(title = "物料管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CMaterial cMaterial)
    {
        return toAjax(cMaterialService.updateCMaterial(cMaterial));
    }

    /**
     * 删除物料管理
     */
    @PreAuthorize("@ss.hasPermi('material:material:remove')")
    @Log(title = "物料管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(cMaterialService.deleteCMaterialByMaterialIds(materialIds));
    }

    /**
     * 同步物料材料用量
     */
    @PreAuthorize("@ss.hasPermi('material:material:synchronizeMaterialData')")
    @Log(title = "同步物料材料用量", businessType = BusinessType.UPDATE)
    @PostMapping("/synchronizeUpdate")
    public AjaxResult synchronizeUpdate() throws Exception
    {
        List<temp> templist = cMaterialService.selectTemp();
        List<material> materials = new ArrayList<material>();
        material m = new material();

        List<cost> costs = new ArrayList<cost>();
        cost c = new cost();

        List<List<temp>> averageAssign =  ListUtils.partition(templist, 5000);


        int num = 1;
        int num2 = 1;
        for(List<temp> list:averageAssign){
            for(temp t:list){
                m = new material();
                m.setMaterial_id(num);
                m.setMaterial_xingh(t.getModel_1());
                m.setMaterial_guig(t.getSpec_1());
                m.setMaterial_diany(t.getVoltage_1());
                m.setMaterial_dw(t.getUnit_0());
                m.setMaterial_type_id(t.getType_no());
                materials.add(m);
                num++;

                if("M001".equals(t.getM_id_M001())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M001());
                    c.setCost_cl_qty(t.getName_qty_M001());
                    costs.add(c);num2++;
                }
                if("M002".equals(t.getM_id_M002())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M002());
                    c.setCost_cl_qty(t.getName_qty_M002());
                    costs.add(c);num2++;
                }
                if("M003".equals(t.getM_id_M003())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M003());
                    c.setCost_cl_qty(t.getName_qty_M003());
                    c.setCost_cl_qty_2(t.getName_qty_M003_1());
                    costs.add(c);num2++;
                }
                if("M004".equals(t.getM_id_M004())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M004());
                    c.setCost_cl_qty(t.getName_qty_M004());
                    c.setCost_cl_qty_2(t.getName_qty_M004_1());
                    costs.add(c);num2++;
                }
                if("M005".equals(t.getM_id_M005())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M005());
                    c.setCost_cl_qty(t.getName_qty_M005());
                    c.setCost_cl_qty_2(t.getName_qty_M005_1());
                    costs.add(c);num2++;
                }
                if("M006".equals(t.getM_id_M006())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M006());
                    c.setCost_cl_qty(t.getName_qty_M006());
                    costs.add(c);num2++;
                }
                if("M007".equals(t.getM_id_M007())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M007());
                    c.setCost_cl_qty(t.getName_qty_M007());
                    costs.add(c);num2++;
                }
                if("M008".equals(t.getM_id_M008())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M008());
                    c.setCost_cl_qty(t.getName_qty_M008());
                    costs.add(c);num2++;
                }
                if("M009".equals(t.getM_id_M009())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M009());
                    c.setCost_cl_qty(t.getName_qty_M009());
                    costs.add(c);num2++;
                }
                if("M010".equals(t.getM_id_M010())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M010());
                    c.setCost_cl_qty(t.getName_qty_M010());
                    c.setCost_cl_qty_2(t.getName_qty_M010_1());
                    costs.add(c);num2++;
                }
                if("M011".equals(t.getM_id_M011())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M011());
                    c.setCost_cl_qty(t.getName_qty_M011());
                    costs.add(c);num2++;
                }
                if("M012".equals(t.getM_id_M012())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M012());
                    c.setCost_cl_qty(t.getName_qty_M012());
                    costs.add(c);num2++;
                }
                if("M013".equals(t.getM_id_M013())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M013());
                    c.setCost_cl_qty(t.getName_qty_M013());
                    costs.add(c);num2++;
                }if("M014".equals(t.getM_id_M014())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M014());
                    c.setCost_cl_qty(t.getName_qty_M014());
                    costs.add(c);num2++;
                }if("M015".equals(t.getM_id_M015())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M015());
                    c.setCost_cl_qty(t.getName_qty_M015());
                    costs.add(c);num2++;
                }
                if("M016".equals(t.getM_id_M016())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M016());
                    c.setCost_cl_qty(t.getName_qty_M016());
                    costs.add(c);num2++;
                }
                if("M017".equals(t.getM_id_M017())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M017());
                    c.setCost_cl_qty(t.getName_qty_M017());
                    costs.add(c);num2++;
                }
                if("M018".equals(t.getM_id_M018())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M018());
                    c.setCost_cl_qty(t.getName_qty_M018());
                    costs.add(c);num2++;
                }if("M019".equals(t.getM_id_M019())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M019());
                    c.setCost_cl_qty(t.getName_qty_M019());
                    c.setCost_cl_qty_2(t.getName_qty_M019_1());
                    costs.add(c);num2++;
                }
                if("M020".equals(t.getM_id_M020())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M020());
                    c.setCost_cl_qty(t.getName_qty_M020());
                    costs.add(c);num2++;
                }
                if("M021".equals(t.getM_id_M021())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M021());
                    c.setCost_cl_qty(t.getName_qty_M021());
                    c.setCost_cl_qty_2(t.getName_qty_M021_1());
                    costs.add(c);num2++;
                }
                if("M022".equals(t.getM_id_M022())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M022());
                    c.setCost_cl_qty(t.getName_qty_M022());
                    costs.add(c);num2++;
                }
                if("M023".equals(t.getM_id_M023())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M023());
                    c.setCost_cl_qty(t.getName_qty_M023());
                    costs.add(c);num2++;
                }if("M024".equals(t.getM_id_M024())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M024());
                    c.setCost_cl_qty(t.getName_qty_M024());
                    costs.add(c);num2++;
                }if("M025".equals(t.getM_id_M025())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M025());
                    c.setCost_cl_qty(t.getName_qty_M025());
                    costs.add(c);num2++;
                }
                if("M026".equals(t.getM_id_M026())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M026());
                    c.setCost_cl_qty(t.getName_qty_M026());
                    costs.add(c);num2++;
                }
                if("M027".equals(t.getM_id_M027())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M027());
                    c.setCost_cl_qty(t.getName_qty_M027());
                    costs.add(c);num2++;
                }
                if("M028".equals(t.getM_id_M028())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M028());
                    c.setCost_cl_qty(t.getName_qty_M028());
                    costs.add(c);num2++;
                }
                if("M029".equals(t.getM_id_M029())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M029());
                    c.setCost_cl_qty(t.getName_qty_M029());
                    costs.add(c);num2++;
                }if("M030".equals(t.getM_id_M030())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M030());
                    c.setCost_cl_qty(t.getName_qty_M030());
                    costs.add(c);num2++;
                }if("M031".equals(t.getM_id_M031())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M031());
                    c.setCost_cl_qty(t.getName_qty_M031());
                    costs.add(c);num2++;
                }if("M032".equals(t.getM_id_M032())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M032());
                    c.setCost_cl_qty(t.getName_qty_M032());
                    costs.add(c);num2++;
                }if("M033".equals(t.getM_id_M033())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M033());
                    c.setCost_cl_qty(t.getName_qty_M033());
                    costs.add(c);num2++;
                }if("M034".equals(t.getM_id_M034())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M034());
                    c.setCost_cl_qty(t.getName_qty_M034());
                    costs.add(c);num2++;
                }
                if("M035".equals(t.getM_id_M035())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M035());
                    c.setCost_cl_qty(t.getName_qty_M035());
                    costs.add(c);num2++;
                }if("M036".equals(t.getM_id_M036())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M036());
                    c.setCost_cl_qty(t.getName_qty_M036());
                    costs.add(c);num2++;
                }if("M037".equals(t.getM_id_M037())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M037());
                    c.setCost_cl_qty(t.getName_qty_M037());
                    c.setCost_cl_qty_2(t.getName_qty_M037_1());
                    costs.add(c);num2++;
                }
                if("M038".equals(t.getM_id_M038())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M038());
                    c.setCost_cl_qty(t.getName_qty_M038());
                    costs.add(c);num2++;
                }
                if("M039".equals(t.getM_id_M039())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M039());
                    c.setCost_cl_qty(t.getName_qty_M039());
                    c.setCost_cl_qty_2(t.getName_qty_M039_1());
                    costs.add(c);num2++;
                }
                if("M040".equals(t.getM_id_M040())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M040());
                    c.setCost_cl_qty(t.getName_qty_M040());
                    costs.add(c);num2++;
                }
                if("M041".equals(t.getM_id_M041())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M041());
                    c.setCost_cl_qty(t.getName_qty_M041());
                    costs.add(c);num2++;
                }
                if("M042".equals(t.getM_id_M042())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M042());
                    c.setCost_cl_qty(t.getName_qty_M042());
                    c.setCost_cl_qty_2(t.getName_qty_M042_1());
                    costs.add(c);num2++;
                }
                if("M043".equals(t.getM_id_M043())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M043());
                    c.setCost_cl_qty(t.getName_qty_M043());
                    costs.add(c);num2++;
                }
                if("M044".equals(t.getM_id_M044())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M044());
                    c.setCost_cl_qty(t.getName_qty_M044());
                    costs.add(c);num2++;
                }
                if("M045".equals(t.getM_id_M045())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M045());
                    c.setCost_cl_qty(t.getName_qty_M045());
                    costs.add(c);num2++;
                }
                if("M046".equals(t.getM_id_M046())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M046());
                    c.setCost_cl_qty(t.getName_qty_M046());
                    costs.add(c);num2++;
                }if("M047".equals(t.getM_id_M047())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M047());
                    c.setCost_cl_qty(t.getName_qty_M047());
                    costs.add(c);num2++;
                }if("M048".equals(t.getM_id_M048())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M048());
                    c.setCost_cl_qty(t.getName_qty_M048());
                    c.setCost_cl_qty_2(t.getName_qty_M048_1());
                    costs.add(c);num2++;
                }if("M049".equals(t.getM_id_M049())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M049());
                    c.setCost_cl_qty(t.getName_qty_M049());
                    costs.add(c);num2++;
                }
                if("M050".equals(t.getM_id_M050())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M050());
                    c.setCost_cl_qty(t.getName_qty_M050());
                    costs.add(c);num2++;
                }
                if("M051".equals(t.getM_id_M051())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M051());
                    c.setCost_cl_qty(t.getName_qty_M051());
                    costs.add(c);num2++;
                }
                if("M052".equals(t.getM_id_M052())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M052());
                    c.setCost_cl_qty(t.getName_qty_M052());
                    costs.add(c);num2++;
                }
                if("M053".equals(t.getM_id_M053())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M053());
                    c.setCost_cl_qty(t.getName_qty_M053());
                    costs.add(c);num2++;
                }
                if("M054".equals(t.getM_id_M054())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M054());
                    c.setCost_cl_qty(t.getName_qty_M054());
                    costs.add(c);num2++;
                }if("M055".equals(t.getM_id_M055())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M055());
                    c.setCost_cl_qty(t.getName_qty_M055());
                    costs.add(c);num2++;
                }if("M056".equals(t.getM_id_M056())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M056());
                    c.setCost_cl_qty(t.getName_qty_M056());
                    costs.add(c);num2++;
                }if("M057".equals(t.getM_id_M057())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M057());
                    c.setCost_cl_qty(t.getName_qty_M057());
                    costs.add(c);num2++;
                }if("M058".equals(t.getM_id_M058())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M058());
                    c.setCost_cl_qty(t.getName_qty_M058());
                    costs.add(c);num2++;
                }
                if("M059".equals(t.getM_id_M059())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M059());
                    c.setCost_cl_qty(t.getName_qty_M059());
                    costs.add(c);num2++;
                }
                if("M060".equals(t.getM_id_M060())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M060());
                    c.setCost_cl_qty(t.getName_qty_M060());
                    costs.add(c);num2++;
                }
                if("M061".equals(t.getM_id_M061())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M061());
                    c.setCost_cl_qty(t.getName_qty_M061());
                    costs.add(c);num2++;
                }
                if("M062".equals(t.getM_id_M062())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M062());
                    c.setCost_cl_qty(t.getName_qty_M062());
                    costs.add(c);num2++;
                }
                if("M063".equals(t.getM_id_M063())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M063());
                    c.setCost_cl_qty(t.getName_qty_M063());
                    costs.add(c);num2++;
                }
                if("M064".equals(t.getM_id_M064())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M064());
                    c.setCost_cl_qty(t.getName_qty_M064());
                    costs.add(c);num2++;
                }
                if("M065".equals(t.getM_id_M065())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M065());
                    c.setCost_cl_qty(t.getName_qty_M065());
                    costs.add(c);num2++;
                }
                if("M066".equals(t.getM_id_M066())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M066());
                    c.setCost_cl_qty(t.getName_qty_M066());
                    costs.add(c);num2++;
                }
                if("M067".equals(t.getM_id_M067())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M067());
                    c.setCost_cl_qty(t.getName_qty_M067());
                    costs.add(c);num2++;
                }
                if("M068".equals(t.getM_id_M068())){
                    c = new cost();
                    c.setCost_id(num2);
                    c.setCost_material_id(m.getMaterial_id());
                    c.setCost_cl_id(t.getM_id_M068());
                    c.setCost_cl_qty(t.getName_qty_M068());
                    costs.add(c);num2++;
                }
            }
        }


        System.out.println("materials===================="+materials.size());
        System.out.println("costs======================="+costs.size());

        try {
            JDBCBatch.insertMaterialBatch(materials);
            JDBCBatch.insertCostBatch(costs);
        }catch (Exception e) {
             throw new Exception(e.getMessage(), e);
        }

        return success();
    }
}
