-- 分类增加组织数据升级
-- 升级主数据分类字段为0的都设置为基本分类标准下待分类
 update T_BD_material set fgroupId = 1 where fgroupid =0;
 update T_BD_supplier set fgroupId = 1 where fgroupid =0;
 update T_BD_customer set fgroupId = 1 where fgroupid =0;
 
-- 升级分类标准关系表中未存在基本分类标准分类关系的主数据 新增一条数据基本分类标准关系，如果没有分类，会取预置分类配【待分类】（id为1）
INSERT INTO T_BD_MaterialGroupDetail (FID,FMaterialID,FSTANDARDID, FGROUPID) select fid,fid,730148448254487552,fgroupid from T_BD_Material where not exists(select fid from T_BD_MaterialGroupDetail where T_BD_Material.fid = T_BD_MaterialGroupDetail.fMaterialid) and fgroupid >0;

INSERT INTO T_BD_SupplierGroupDetail (FID,FSupplierID,FSTANDARDID, FGROUPID) select fid,fid,716529547008326656,fgroupid from T_BD_Supplier where not exists(select fid from T_BD_SupplierGroupDetail where T_BD_Supplier.fid = T_BD_SupplierGroupDetail.fSupplierid) and fgroupid >0;
 
INSERT INTO T_BD_CustomerGroupDetail (FID,FCustomerID,FSTANDARDID, FGROUPID) select fid,fid,712984405228187648,fgroupid from T_BD_Customer where not exists(select fid from T_BD_CustomerGroupDetail where T_BD_Customer.fid = T_BD_CustomerGroupDetail.fCustomerid) and fgroupid >0;
 
-- 升级所有分类创建组织为对应分类标准的创建组织
update  t_bd_materialgroup  set fcreateorgid = (select fcreateorgid from t_bd_mtgroupstandard gs where fstandardid =gs.fid)where fcreateorgid =0 and exists(select fcreateorgid from t_bd_mtgroupstandard gs where fstandardid =gs.fid);
update  T_bd_suppliergroup  set fcreateorgid = (select fcreateorgid from t_bd_spgroupstandard gs where fstandardid =gs.fid)where fcreateorgid =0 and exists(select fcreateorgid from t_bd_spgroupstandard gs where fstandardid =gs.fid);
update  T_bd_customergroup  set fcreateorgid = (select fcreateorgid from t_bd_csgroupstandard gs where fstandardid =gs.fid)where fcreateorgid =0 and exists(select fcreateorgid from t_bd_csgroupstandard gs where fstandardid =gs.fid);
 
-- 升级所有关系表中组织为对应分类的创建组织
update  t_bd_materialgroupdetail set fcreateorgid = (select fcreateorgid from t_bd_materialgroup gs where fgroupid =gs.fid)where fcreateorgid =0 and exists(select fcreateorgid from t_bd_materialgroup gs where fgroupid =gs.fid);
update  T_bd_SupplierGroupDetail set fcreateorgid = (select fcreateorgid from T_bd_suppliergroup gs where fgroupid =gs.fid)where fcreateorgid =0 and exists(select fcreateorgid from T_bd_suppliergroup gs where fgroupid =gs.fid);
update  T_bd_CustomerGroupDetail set fcreateorgid = (select fcreateorgid from T_bd_customergroup gs where fgroupid =gs.fid)where fcreateorgid =0 and exists(select fcreateorgid from T_bd_customergroup gs where fgroupid =gs.fid);