Home > Back-end >  Attributes cannot be the same judgment, have better writing???????
Attributes cannot be the same judgment, have better writing???????

Time:01-31

Cannot determine three attribute value in the database duplicate of the same properties of the sum of the three properties, how to determine or other writing, consult general bosses practical developing how to write?


//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 Duplicate=medicineService. FindDuplicate (medicine) getFactoryid (), and medicine. The getName (), medicine, getSpecs (), medicine, getMedicine_no (), medicine, getShort_name ());
//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 Duplicate=medicineService. FindDuplicate (medicine) getFactoryid (), and medicine. The getName (), medicine, getSpecs (), medicine, getMedicine_no (), medicine, getShort_name (), medicine, getId ());
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 ();
}
  • Related