//new changes to walk the same interface
@ RequestMapping ("/medic ")
Public Object save (@ Valid Medicine Medicine) {
//Medicine Medicine=getFromJson (Medicine. Class);
If (medicine. GetId ()==null) {
/* if (medicineService findByFactoryid (medicine. GetFactoryid ())==null) {
Return Rets. Failure (" the manufacturer does not exist ");
} */
If (medicine. GetFactoryid ()==null | | factoryService. Get (medicine) getFactoryid ())==null) {
Return Rets. Failure (" the manufacturer does not exist ");
}
List
//use java8 new features to intercept the filter way, more return Boolean and count
If (duplicate) stream (). The filter (Medicine - & gt; (Medicine. GetFactoryid () + Medicine. The getName () + Medicine. GetSpecs ()). The equals (Medicine) getFactoryid () + Medicine. The getName () + Medicine. GetSpecs ())). The count () & gt; 0 {
Return Rets. Failure (" the drug has been in the hospital exists ");
} else if (duplicate) stream ()) filter (Medicine - & gt; Medicine. GetMedicine_no (.) the equals (Medicine. GetMedicine_no ())). The count () & gt; 0 {
Return Rets. Failure (" the number already exists ");
} else if (duplicate) stream ()) filter (Medicine - & gt; Medicine. GetShort_name (.) the equals (Medicine. GetShort_name ())). The count () & gt; 0 {
Return Rets. Failure (" the existing ");
}
Medicine medicineinsert=medicineService. Insert (Medicine);
PriceService. UpdatePriceMedicine (medicineinsert. GetCreateBy (), medicineinsert. GetId ());
} else {
List
If (medicineService. Get (medicine) getId ())==null) {
Return Rets. Failure (" the drug does not exist ");
}
If (factoryService. Get (medicine) getFactoryid ())==null) {
Return Rets. Failure (" the manufacturer does not exist ");
}
If (duplicate) stream (). The filter (Medicine - & gt; (Medicine. GetFactoryid () + Medicine. The getName () + Medicine. GetSpecs ()). The equals (Medicine) getFactoryid () + Medicine. The getName () + Medicine. GetSpecs ())). The count () & gt; 0 {
Return Rets. Failure (" the drug has been in the hospital exists ");
} else if (duplicate) stream ()) filter (Medicine - & gt; Medicine. GetMedicine_no (.) the equals (Medicine. GetMedicine_no ())). The count () & gt; 0 {
Return Rets. Failure (" the number already exists ");
} else if (duplicate) stream ()) filter (Medicine - & gt; Medicine. GetShort_name (.) the equals (Medicine. GetShort_name ())). The count () & gt; 0 {
Return Rets. Failure (" the existing ");
}
MedicineService. Update (medicine);
}
Return Rets. Success ();
}