public static JsonResponse addProduceRecord( ProduceRecords data, MaterialRecords[] materialRecord) { for (MaterialRecords mr : materialRecord) { Materials material = mr.material; if (material.id == null && material.name != null) { Materials temp = Materials.find("name=?", material.name).first(); if (temp != null) { mr.material = temp; } else { material.createAt = DateUtils.getNowDate(); material.save(); } } mr.produceRecord = data; mr.save(); } if (data.batch.id == null) { if (data.batch.product.productId != null) { Batchs batch = Batchs.find("product_id=? and batchNo is null", data.batch.product.productId).first(); if (batch == null) { data.batch.orderSource = 1; // 内销 data.batch.save(); } else { data.batch = batch; } } } if (data.batch.id != null && data.batch.product.productId != null) { data.batch.save(); } data.save(); return new JsonResponse(0, "生产记录已更新成功"); }