在这其中遇到的问题:
我postman(Raw) object 传的是如下这样的数据:
object :但是我走debug 发现后台是这样的object (数据是map形式) 所以得把object 转化为Map (这里面看似LinkHashMap 但是转化为Map就行):
object转Map:
Map<String, Object> stRiskPermitMap = (Map<String, Object>) object;
第二个问题是:还需要把stRiskPermitMap 转化为相应对象(而这个对象是复杂的里面有List 和一对多关系)但是我发现这样也可以:
Map 转 java相应对象:
StRiskPermitDig stRiskPermitDig = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitDig.class);
@Override
@Transactional
public void batchAppPermit(Object object) {
Map<String, Object> stRiskPermitMap = (Map<String, Object>) object;
Map<String,Object> permit = (Map<String, Object>) stRiskPermitMap.get("permit");
String permitType = (String) permit.get("permitType");
if ("DigWork".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType(permitType);
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitDig stRiskPermitDig = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitDig.class);
stRiskPermitDigService.savePermit(stRiskPermitDig);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("IndustrialFire".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitFire stRiskPermitFire = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitFire.class);
stRiskPermitFireService.savePermit(stRiskPermitFire);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("HighWork".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitHigh stRiskPermitHigh = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitHigh.class);
stRiskPermitHighService.savePermit(stRiskPermitHigh);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("HoistingWork".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitHoisting stRiskPermitHoisting = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitHoisting.class);
stRiskPermitHoistingService.savePermit(stRiskPermitHoisting);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("PipelineOpen".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitOpen stRiskPermitOpen = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitOpen.class);
stRiskPermitOpenService.savePermit(stRiskPermitOpen);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("Photography".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitPhoto stRiskPermitPhoto = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitPhoto.class);
stRiskPermitPhotoService.savePermit(stRiskPermitPhoto);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("RadialWork".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitRay stRiskPermitRay = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitRay.class);
stRiskPermitRayService.savePermit(stRiskPermitRay);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("ConfinedSpace".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitSpace stRiskPermitSpace = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitSpace.class);
stRiskPermitSpaceService.savePermit(stRiskPermitSpace);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("VehicleInboundStation".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitVehicle stRiskPermitVehicle = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitVehicle.class);
stRiskPermitVehicleService.savePermit(stRiskPermitVehicle);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("SafeWork".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitWork stRiskPermitWork = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitWork.class);
stRiskPermitWorkService.savePermit(stRiskPermitWork);
} catch (Exception e) {
e.printStackTrace();
}
}else if ("TemporaryElectricity".equals(permitType)){
StRiskPermit permitNew = new StRiskPermit();
permitNew.setPermitId((String) permit.get("permitId"));
permitNew.setJobId((String) permit.get("jobId"));
permitNew.setApplyTime(new Date());
permitNew.setPermitNumber((String) permit.get("permitNumber"));
permitNew.setPermitType((String) permit.get("permitType"));
permitNew.setVersionId((String) permit.get("versionId"));
permitNew.setUseStatus((String) permit.get("useStatus"));
try {
permitRepositoryNew.save(permitNew);
StRiskPermitElectricity stRiskPermitElectricity = JSONObject.parseObject(JSON.toJSONString(stRiskPermitMap),StRiskPermitElectricity.class);
stRiskPermitElectricityService.savePermit(stRiskPermitElectricity);
} catch (Exception e) {
e.printStackTrace();
}
}
}