/**
 * 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.WorkContentCtrlpriceDao;
import com.jeeplus.modules.workcontent.entity.WorkContentCtrlprice;
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 WorkContentCtrlpriceService extends CrudService<WorkContentCtrlpriceDao, WorkContentCtrlprice> implements WorkContentDetailBaseService {

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

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

}