import com.iemsoft.framework.cloud.core.tools.JSONTool; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import org.junit.Test; import java.util.*; public class SelectFormTest { Set name = new HashSet<>(Arrays.asList(("综合业务").split("\n"))); @Test public void test(){ String json = "{\"busViewGroupId\":null,\"busViewGroupCode\":null,\"busViewGroupName\":null,\"coBusViewId\":77,\"coBusViewCode\":\"M038\",\"coBusViewName\":\"合肥模塑业务视图\",\"tenantCode\":\"R00005\",\"tenantName\":\"四川长虹模塑科技有限公司合肥分公司\",\"companyCode\":\"8500\",\"companyName\":\"四川长虹模塑科技有限公司合肥分公司\",\"busTypeData\":[{\"busTypeModuleId\":7,\"busTypeModuleName\":\"综合业务\",\"busTypeModuleCode\":\"A000\",\"busType\":[{\"companyBusId\":459719,\"busTypeId\":515,\"busTypeCode\":\"A0000018\",\"busTypeName\":\"个人备用金借款\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459720,\"busTypeId\":517,\"busTypeCode\":\"A0000019\",\"busTypeName\":\"个人备用金还款\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null}]},{\"busTypeModuleId\":17,\"busTypeModuleName\":\"费用业务\",\"busTypeModuleCode\":\"A003\",\"busType\":[{\"companyBusId\":459493,\"busTypeId\":51,\"busTypeCode\":\"A0030001\",\"busTypeName\":\"办公费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459654,\"busTypeId\":57,\"busTypeCode\":\"A0030004\",\"busTypeName\":\"市场支持费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459500,\"busTypeId\":149,\"busTypeCode\":\"A0030008\",\"busTypeName\":\"培训费\",\"busTypeDesc\":\"核算公司按国家相关规定为员工培训教育发生的所有费用,包括培训的差旅费、资料器材费、培训场地费(内部培训)\\n;记账所需单据:发票\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459497,\"busTypeId\":153,\"busTypeCode\":\"A0030010\",\"busTypeName\":\"会务组织费\",\"busTypeDesc\":\"核算公司各平台职能部门组织会议发生的相关费用(不含团代会、党代会)、股东大会相关费用\\n;记账所需单据:发票、合同协议、费用明细清单\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459495,\"busTypeId\":155,\"busTypeCode\":\"A0030011\",\"busTypeName\":\"诉讼费\",\"busTypeDesc\":\"核算公司为办理国内、国外法律咨询及诉讼案件而支付的聘请律师、诉讼费用、咨询费,包括案件受理费、诉讼费、财产保全费、执行费、律师代理费、常年法律顾问费(主要指对公业务)\\n;记账所需单据:发票、合同协议\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459723,\"busTypeId\":161,\"busTypeCode\":\"A0030014\",\"busTypeName\":\"劳动保护费\",\"busTypeDesc\":\"核算公司各部门领用劳保用品的摊销、安全生产奖励、安全生产宣传、职工体检费、工伤等级鉴定费、工伤赔偿费,以及条件艰苦的一线生产工人的防暑降温费等,含作业条件监测费(作业场所内如噪声、粉尘、废气等监测)以及海外政府强制要求为员工按定额或定率缴纳的员工保护费用。\\n;记账所需单据:发票\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459494,\"busTypeId\":165,\"busTypeCode\":\"A0030016\",\"busTypeName\":\"业务活动费\",\"busTypeDesc\":\"核算各单位因工作需要发生的业务活动费用\\n;记账所需单据:发票\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":3715,\"busTypeId\":371,\"busTypeCode\":\"A0030036\",\"busTypeName\":\"差旅费\",\"busTypeDesc\":\"

差旅系统的差旅费。<\\/p>\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459498,\"busTypeId\":509,\"busTypeCode\":\"A0030045\",\"busTypeName\":\"信息咨询费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459501,\"busTypeId\":531,\"busTypeCode\":\"A0030049\",\"busTypeName\":\"工程维修费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459499,\"busTypeId\":543,\"busTypeCode\":\"A0030055\",\"busTypeName\":\"会展费用\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459502,\"busTypeId\":551,\"busTypeCode\":\"A0030057\",\"busTypeName\":\"职工福利费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459505,\"busTypeId\":1283,\"busTypeCode\":\"A0030106\",\"busTypeName\":\"对外技术合作项目费用\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459504,\"busTypeId\":1288,\"busTypeCode\":\"A0030111\",\"busTypeName\":\"样品样机处置费-购置\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459614,\"busTypeId\":1314,\"busTypeCode\":\"A0030122\",\"busTypeName\":\"手机费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459615,\"busTypeId\":1315,\"busTypeCode\":\"A0030123\",\"busTypeName\":\"座机费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459721,\"busTypeId\":1322,\"busTypeCode\":\"A0030130\",\"busTypeName\":\"设备修理费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null},{\"companyBusId\":459722,\"busTypeId\":1331,\"busTypeCode\":\"A0030139\",\"busTypeName\":\"外部批次质量补偿费\",\"busTypeDesc\":\"\",\"busNote\":[],\"busCheckRule\":[],\"accLogic\":[],\"autoState\":2,\"payLogic\":null,\"checkRule\":null,\"accRules\":null}]}],\"linkEqu\":null,\"generalAccount\":null,\"bussSwitch\":{\"companySwitchId\":10,\"companyViewId\":77,\"switchState\":1,\"payFlag\":0},\"existManualAcc\":false}"; Optional.ofNullable(JSONTool.toObj(json, Map.class)) .map(m->(List)m.get("busTypeData")) .orElse(Collections.emptyList()) .stream() .forEach(data->{ if(name.contains(((Map)data).get("busTypeModuleName").toString())){ Map map = ((Map)data); System.out.println( "INSERT INTO `epc_cost_type_100000001_7`(`id`, `type`, `node_name`, `parent_id`, `re_course_code`, `ins_t`, `ins_p`, `upd_t`, `upd_p`, `data_start`, `orderTypeCode`, `sortCode`, `codeId`, `gId`, `isBlock`, `overlook_expend_type`, `bookKeeping`) " + "VALUES ("+map.get("busTypeModuleId")+", '0', '"+map.get("busTypeModuleName")+"', 0, '"+map.get("busTypeModuleId")+"', '2019-03-27 13:44:14', NULL, '2019-03-27 13:44:14', NULL, 0, '"+map.get("busTypeModuleCode")+"', '"+map.get("busTypeModuleCode").toString()+"', "+map.get("busTypeModuleId")+", NULL, '0', 0, '0');" ); } if(ObjectUtil.notEmpty(((Map)data).get("busType"))){ ((List)((Map)data).get("busType")) .stream() .forEach(m->forEach(m, ((Map) data).get("busTypeModuleId"))); } }); } public void forEach(Map map, Object parentId){ if(!name.contains(map.get("busTypeName").toString())){ return; } System.out.println( "INSERT INTO `epc_cost_type_100000001_7`(`id`, `type`, `node_name`, `parent_id`, `re_course_code`, `ins_t`, `ins_p`, `upd_t`, `upd_p`, `data_start`, `orderTypeCode`, `sortCode`, `codeId`, `gId`, `isBlock`, `overlook_expend_type`, `bookKeeping`) " + "VALUES ("+map.get("busTypeId")+", '1', '"+map.get("busTypeName")+"', "+parentId+", '"+map.get("busTypeId")+"', '2019-03-27 13:44:14', NULL, '2019-03-27 13:44:14', NULL, 0, '"+map.get("busTypeCode")+"', '"+map.get("busTypeCode").toString().substring(0, 4)+"', "+map.get("busTypeId")+", NULL, '0', 0, '0');" ); } }