/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.workcontent.service;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.workcontent.dao.WorkContentInvestmentCostDao;
import com.jeeplus.modules.workcontent.entity.WorkContentInvestmentCost;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;

/**
 * 工程费用Service
 * @author ssrh
 * @version 2018-06-05
 */
@Service
@Transactional(readOnly = true)
public class WorkContentInvestmentCostService extends CrudService<WorkContentInvestmentCostDao, WorkContentInvestmentCost> implements WorkContentDetailBaseService{

	public WorkContentInvestmentCost get(String id) {
		return super.get(id);
	}
	
	public List<WorkContentInvestmentCost> findList(WorkContentInvestmentCost workContentInvestmentCost) {
		return super.findList(workContentInvestmentCost);
	}
	
	public Page<WorkContentInvestmentCost> findPage(Page<WorkContentInvestmentCost> page, WorkContentInvestmentCost workContentInvestmentCost) {
		return super.findPage(page, workContentInvestmentCost);
	}
	
	@Transactional(readOnly = false)
	public void save(WorkContentInvestmentCost workContentInvestmentCost) {
		super.save(workContentInvestmentCost);
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkContentInvestmentCost workContentInvestmentCost) {
		super.delete(workContentInvestmentCost);
	}
	
    @Override
    @Transactional(readOnly = false)
    public void saveDetails(String detailStr, String projectId, String contentId) {
	    if(StringUtils.isBlank(detailStr)){
	        return;
        }
        List<WorkContentInvestmentCost> investmentCostList = JSON.parseArray(detailStr, WorkContentInvestmentCost.class);
        for (WorkContentInvestmentCost investmentCost : investmentCostList) {
            if(WorkContentInvestmentCost.DEL_FLAG_DELETE.equals(investmentCost.getDelFlag())){
                dao.delete(investmentCost);
                continue;
            }
            investmentCost.setContentId(contentId);
            investmentCost.setProjectId(projectId);
            this.save(investmentCost);
        }
    }

}