/**
 * 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.alibaba.fastjson.JSONObject;
import com.jeeplus.modules.projectcontentinfo.entity.ProjectContentData;
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.WorkContentContprogram;
import com.jeeplus.modules.workcontent.dao.WorkContentContprogramDao;

/**
 * 合约规划Service
 * @author ssrh
 * @version 2018-06-06
 */
@Service
@Transactional(readOnly = true)
public class WorkContentContprogramService extends CrudService<WorkContentContprogramDao, WorkContentContprogram> implements WorkContentDetailBaseService {

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


    @Override
    @Transactional(readOnly = false)
    public void saveDetails(String detailStr, String projectId, String contentId) {
        JSONObject jsonObject = JSON.parseObject(detailStr);
        ProjectContentData contentData = new ProjectContentData();
        contentData.setId(jsonObject.getString("otherProgram.id"));
        WorkContentContprogram workContentContprogram =jsonObject.toJavaObject(WorkContentContprogram.class);
        workContentContprogram.setOtherProgram(contentData);
        workContentContprogram.setProjectId(projectId);
        workContentContprogram.setContentId(contentId);
        this.save(workContentContprogram);
    }

    public WorkContentContprogram getByContentId(String contentId) {
        return dao.findUniqueByProperty("content_id",contentId);
    }
}