package com.palmnest.service.estateserve.impl;

import com.palmnest.dao.estateserve.DepositItemInformationFormDao;
import com.palmnest.model.estateserve.DepositItemInformationForm;
import com.palmnest.service.estateserve.DepositItemInformationFormManager;
import com.palmnest.service.impl.GenericManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@Service("depositItemInformationFormManager")
public class DepositItemInformationFormManagerImpl extends GenericManagerImpl<DepositItemInformationForm, Integer>
		implements DepositItemInformationFormManager {


	private DepositItemInformationFormDao depositItemInformationFormDao;

	@Autowired
	public void setDepositItemInformationFormDao(
			DepositItemInformationFormDao depositItemInformationFormDao) {
		this.depositItemInformationFormDao = depositItemInformationFormDao;
		this.dao = depositItemInformationFormDao;
	}

	@Override
	public List<DepositItemInformationForm> getDepositItemInformationFormList(
			Integer serviceTypeInfoId) throws Exception {
		return depositItemInformationFormDao.getDepositItemInformationFormList(serviceTypeInfoId);
	}

	@Override
	public Map<String, Object> saveUpdateDepositItemInformationForm(
			List<DepositItemInformationForm> dInformationFormsList)
			throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			for (DepositItemInformationForm depositItemInformationForm : dInformationFormsList) {
				if (depositItemInformationForm.getId() != null) {
					depositItemInformationFormDao.updateObj(depositItemInformationForm);
				} else {
					depositItemInformationFormDao.save(depositItemInformationForm);
				}
			}
			resultMap.put("flag", true);
			resultMap.put("desc", "操作成功");
		} catch (Exception e) {
			resultMap.put("flag", false);
			resultMap.put("desc", "操作失败");
			log.error("service save,update,delete saveUpdateDepositItemInformationForm error{}", e);
		}
		return resultMap;
	}

}
