use of com.plumdo.form.jpa.Criteria in project plumdo-work by wengwh.
the class FormInstanceResource method updateFormInstance.
@ApiOperation(value = "创建表单模型", notes = "根据传过来的modelRequest信息来创建表单模型")
@ApiImplicitParam(name = "modelRequest", value = "表单模型请求实体modelRequest", required = true, dataType = "FormInstanceRequest")
@RequestMapping(value = "/form-instances/{id}", method = RequestMethod.PUT, produces = "application/json")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED)
public FormInstanceResponse updateFormInstance(@PathVariable Long id, @RequestBody FormInstanceRequest formInstanceRequest) {
FormInstance formInstance = getFormInstanceFromRequest(id);
if (formInstanceRequest.getBusinessKey() != null) {
formInstance.setBusinessKey(formInstanceRequest.getBusinessKey());
}
if (formInstanceRequest.getTenantId() != null) {
formInstance.setTenantId(formInstanceRequest.getTenantId());
}
if (formInstanceRequest.getFormDatas() != null) {
for (FormInstanceData formInstanceData : formInstanceRequest.getFormDatas()) {
Criteria<FormData> criteria = new Criteria<FormData>();
criteria.add(Restrictions.eq("key", formInstanceData.getKey(), false));
criteria.add(Restrictions.eq("formInstance.id", id, false));
FormData oldFormData = formDataRepository.findOne(criteria);
if (oldFormData == null) {
FormData formData = new FormData();
formData.setFormInstance(formInstance);
formData.setKey(formInstanceData.getKey());
formData.setValue(formInstanceData.getValue());
formInstance.addFormData(formData);
} else {
oldFormData.setValue(formInstanceData.getValue());
formInstance.addFormData(oldFormData);
}
}
}
formInstanceRepository.save(formInstance);
return responseFactory.createFormInstanceResponse(formInstance);
}
Aggregations