/**
 * 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 org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.modules.workcontent.entity.WorkContentBudget;
import com.jeeplus.modules.workcontent.dao.WorkContentBudgetDao;

/**
 * 结算编审Service
 * @author ssrh
 * @version 2018-06-06
 */
@Service
@Transactional(readOnly = true)
public class WorkContentBudgetService extends CrudService<WorkContentBudgetDao, WorkContentBudget> implements WorkContentDetailBaseService {

	public WorkContentBudget get(String id) {
		return super.get(id);
	}
	
	public List<WorkContentBudget> findList(WorkContentBudget workContentBudget) {
		return super.findList(workContentBudget);
	}
	
	public Page<WorkContentBudget> findPage(Page<WorkContentBudget> page, WorkContentBudget workContentBudget) {
		return super.findPage(page, workContentBudget);
	}
	
	@Transactional(readOnly = false)
	public void save(WorkContentBudget workContentBudget) {
		super.save(workContentBudget);
	}
	
	@Transactional(readOnly = false)
	public void delete(WorkContentBudget workContentBudget) {
		super.delete(workContentBudget);
	}

    @Override
    @Transactional(readOnly = false)
    public void saveDetails(String detailStr, String projectId, String contentId) {
        if(StringUtils.isBlank(detailStr)){
            return;
        }
        List<WorkContentBudget> list = JSON.parseArray(detailStr, WorkContentBudget.class);
        for (WorkContentBudget workContentBudget : list) {
            if(WorkContentBudget.DEL_FLAG_DELETE.equals(workContentBudget.getDelFlag())){
                dao.delete(workContentBudget);
                continue;
            }
            workContentBudget.setContentId(contentId);
            workContentBudget.setProjectId(projectId);
            this.save(workContentBudget);
        }
    }

}