if(equipmentID==null)
{
result.setFailed(EQUIPMENT_ID_IS_NULL);
return result;
}
Equipment equipment = equipmentDAO.findById(equipmentID);
if(equipment==null)
{
result.setFailed(EQUIPMENT_NOT_EXIST,equipmentID);
return result;
}
if(algorithmID==null)
{
result.setFailed(DEPRECIATION_ALGORITHM_ID_IS_NULL);
return result;
}
DepAlgorithm depAlgorithm = depAlgorithmDAO.findById(algorithmID);
if(depAlgorithm==null)
{
result.setFailed(DEPRECIATION_ALGORITHM_NOT_EXIST,algorithmID);
return result;
}
try{
/*//检查设备有没有计算器;保证设备计算器的唯一性
DepreciationCaculator caculator = null;
Set<DepreciationCaculator> caculators = equipment.getDepreciationCaculators();
if(caculators!=null&&caculators.size()>0)
caculator = caculators.iterator().next();*/
// 由于equipment是主键,每次设置后会直接覆盖原来的(如果存在),故不需要判断
DepreciationCaculator caculator = new DepreciationCaculator();
caculator.setEquipment(equipment);
caculator.setDepAlgorithm(depAlgorithm);
caculator.setEquipmentId(equipmentID);
BeanUtils.populate(caculator, properties);
Double value = Caculate(equipment,caculator);//计算资产净值
equipment.setPrecentPrice(value);
depreciationCaculatorDAO.merge(caculator);
equipmentDAO.merge(equipment);
LazyDynaBean bean = new LazyDynaBean();
bean.set("presentPrice", value);
result.setSucceed();